Skip to content

Commit

Permalink
🐛 fix(utilities): token() now successfully manipulates mode and alpha…
Browse files Browse the repository at this point in the history
… options (feat #209)

feat #209
  • Loading branch information
prjctimg committed Jul 22, 2024
1 parent d06c99e commit 94be262
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/utilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
isArray,
neq,
or,
lt,
gt,
take,
give,
max,
Expand Down Expand Up @@ -373,7 +373,6 @@ function token(color, options = undefined) {
? color?.filter((a) => eq(typeof a, "number"))
: undefined,
// if the color is an array just take the values whilst optionally omitting the colorspace (if specified)

// step 2 get the alpha

// check if the alpha channel is explicitly specified else cast 1 as the default
Expand All @@ -399,14 +398,15 @@ function token(color, options = undefined) {
color = y
? (() => {
let z = {};
for (const [k, v] of entries(x)) {
z[v] = y[k];
for (const k of x) {
z[k] = y[x.indexOf(k)];
}

and(eq(y?.length, 4), (z["alpha"] = y[3]));
return z;
})()
: color;

console.log(color);
// convert the color to a target mode if it is specified

/*
Expand All @@ -422,38 +422,34 @@ function token(color, options = undefined) {
*/

function c2col() {
if (eq(srcMode, and(or("rgb", "lrgb")))) {
if (and(normalizeRgb, eq(srcMode, and(or("rgb", "lrgb"))))) {
/**
* Normalize the color back to the rgb gamut supported by culori
* @type {boolean}
* */
var s = x.some((c) => lt(1, Math.abs(color[c])));
var s = x.some((c) => gt(Math.abs(color[c]), 1));

if (s)
if (s) {
for (const [k, v] of x) {
color[v] = y[k] / 255;

Check warning

Code scanning / CodeQL

Prototype-polluting assignment Medium

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
}
}
}

color = cnv(targetMode);
let j = [];
if (eq(kind, "obj")) {
// dont add alpha channel if true
or(and(omitAlpha, delete color?.alpha), j);
or(and(omitMode, delete color?.mode));
}
if (eq(kind, "arr")) {
// if true, remove the

for (const [k, v] of x) {
j[k] = color[v];
omitMode ? color : (color["mode"] = targetMode);
omitAlpha ? color : (color["alpha"] = z);
return color;
} else if (eq(kind, "arr")) {
let j = [];
for (const k of x) {
j[x.indexOf(k)] = color[k];
}
omitAlpha ? j.pop() : j;
omitMode ? j.unshift(targetMode) : j;
color = j;
}

return color;
omitAlpha ? j : j.push(z);
omitMode ? j : j.unshift(targetMode);
return j;
}
}

function c2num() {
Expand Down

0 comments on commit 94be262

Please sign in to comment.