@tsparticles/plugin-oklch-color 3.9.1 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/599.min.js +2 -0
- package/599.min.js.LICENSE.txt +1 -0
- package/browser/OklchColorManager.js +19 -15
- package/browser/index.js +6 -6
- package/browser/utils.js +25 -21
- package/cjs/OklchColorManager.js +24 -24
- package/cjs/index.js +6 -9
- package/cjs/utils.js +27 -30
- package/dist_browser_OklchColorManager_js.js +40 -0
- package/esm/OklchColorManager.js +19 -15
- package/esm/index.js +6 -6
- package/esm/utils.js +25 -21
- package/package.json +4 -3
- package/report.html +5 -4
- package/tsparticles.plugin.oklchColor.js +209 -50
- package/tsparticles.plugin.oklchColor.min.js +1 -1
- package/tsparticles.plugin.oklchColor.min.js.LICENSE.txt +1 -1
- package/types/OklchColorManager.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/utils.d.ts +1 -3
- package/umd/OklchColorManager.js +19 -15
- package/umd/index.js +41 -7
- package/umd/utils.js +24 -22
- package/browser/LchColorManager.js +0 -44
- package/cjs/LchColorManager.js +0 -48
- package/esm/LchColorManager.js +0 -44
- package/types/LchColorManager.d.ts +0 -9
- package/umd/LchColorManager.js +0 -58
package/599.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 599.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_plugin_oklch_color=this.webpackChunk_tsparticles_plugin_oklch_color||[]).push([[599],{599(a,e,t){t.d(e,{OklchColorManager:()=>O});var s=t(303);const c={L:1,a:.3963377774,b:.2158037573},r={L:1,a:-.1055613458,b:-.0638541728},l={L:1,a:-.0894841775,b:-1.291485548},n={l:4.0767416621,m:-3.3077115913,s:.2309699292},o={l:-1.2684380046,m:2.6097574011,s:-.3413193965},h={l:-.0041960863,m:-.7034186147,s:1.707614701},u=2.4,i=.0031308,p=12.92,b=1.055,d=.055;function g(a){const e=a.l/s.percentDenominator,t=a.c/s.percentDenominator,g=(0,s.degToRad)(a.h),k=t*Math.cos(g),O=t*Math.sin(g),m=(c.L*e+c.a*k+c.b*O)**3,v=(r.L*e+r.a*k+r.b*O)**3,w=(l.L*e+l.a*k+l.b*O)**3,_=n.l*m+n.m*v+n.s*w,j=o.l*m+o.m*v+o.s*w,L=h.l*m+h.m*v+h.s*w,M=a=>{return Math.round((0,s.clamp)((e=a)<=i?p*e:b*Math.pow(e,s.inverseFactorNumerator/u)-d,0,1)*s.rgbMax);var e};return{r:M(_),g:M(j),b:M(L)}}const k=/oklch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(°)?(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;class O{constructor(){this.key="oklch"}accepts(a){return a.startsWith("oklch")}handleColor(a){const e=a.value.oklch??a.value;if(Object.hasOwn(e,"l")||Object.hasOwn(e,"c")||Object.hasOwn(e,"h"))return g(e)}handleRangeColor(a){const e=a.value.oklch??a.value;if(Object.hasOwn(e,"l")||Object.hasOwn(e,"c")||Object.hasOwn(e,"h"))return g({l:(0,s.getRangeValue)(e.l),c:(0,s.getRangeValue)(e.c),h:(0,s.getRangeValue)(e.h)})}parseString(a){if(!this.accepts(a))return;const e=k.exec(a),t=1,c=3,r=5,l=7;return e?{a:(n={a:e[l]?(0,s.parseAlpha)(e[l]):1,c:parseFloat(e[c]??"0"),h:parseFloat(e[r]??"0"),l:parseFloat(e[t]??"0")}).a,...g(n)}:void 0;var n}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles OKLCH Color Plugin v4.0.0-alpha.1 by Matteo Bruni */
|
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
|
|
2
2
|
import { oklchToRgb, oklchaToRgba } from "./utils.js";
|
|
3
|
+
const oklchRegex = /oklch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(°)?(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;
|
|
3
4
|
export class OklchColorManager {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.key = "oklch";
|
|
6
|
-
|
|
7
|
+
}
|
|
8
|
+
accepts(input) {
|
|
9
|
+
return input.startsWith("oklch");
|
|
7
10
|
}
|
|
8
11
|
handleColor(color) {
|
|
9
12
|
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
10
|
-
if (oklchColor
|
|
11
|
-
return
|
|
13
|
+
if (!Object.hasOwn(oklchColor, "l") && !Object.hasOwn(oklchColor, "c") && !Object.hasOwn(oklchColor, "h")) {
|
|
14
|
+
return;
|
|
12
15
|
}
|
|
16
|
+
return oklchToRgb(oklchColor);
|
|
13
17
|
}
|
|
14
18
|
handleRangeColor(color) {
|
|
15
19
|
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
16
|
-
if (oklchColor
|
|
17
|
-
return
|
|
18
|
-
l: getRangeValue(oklchColor.l),
|
|
19
|
-
c: getRangeValue(oklchColor.c),
|
|
20
|
-
h: getRangeValue(oklchColor.h),
|
|
21
|
-
});
|
|
20
|
+
if (!Object.hasOwn(oklchColor, "l") && !Object.hasOwn(oklchColor, "c") && !Object.hasOwn(oklchColor, "h")) {
|
|
21
|
+
return;
|
|
22
22
|
}
|
|
23
|
+
return oklchToRgb({
|
|
24
|
+
l: getRangeValue(oklchColor.l),
|
|
25
|
+
c: getRangeValue(oklchColor.c),
|
|
26
|
+
h: getRangeValue(oklchColor.h),
|
|
27
|
+
});
|
|
23
28
|
}
|
|
24
29
|
parseString(input) {
|
|
25
|
-
|
|
26
|
-
if (!isOklch) {
|
|
30
|
+
if (!this.accepts(input)) {
|
|
27
31
|
return;
|
|
28
32
|
}
|
|
29
|
-
const
|
|
33
|
+
const result = oklchRegex.exec(input), indexes = {
|
|
30
34
|
l: 1,
|
|
31
35
|
c: 3,
|
|
32
36
|
h: 5,
|
|
@@ -35,9 +39,9 @@ export class OklchColorManager {
|
|
|
35
39
|
return result
|
|
36
40
|
? oklchaToRgba({
|
|
37
41
|
a: result[indexes.a] ? parseAlpha(result[indexes.a]) : defaultAlpha,
|
|
38
|
-
c: parseFloat(result[indexes.c]),
|
|
39
|
-
h: parseFloat(result[indexes.h]),
|
|
40
|
-
l: parseFloat(result[indexes.l]),
|
|
42
|
+
c: parseFloat(result[indexes.c] ?? "0"),
|
|
43
|
+
h: parseFloat(result[indexes.h] ?? "0"),
|
|
44
|
+
l: parseFloat(result[indexes.l] ?? "0"),
|
|
41
45
|
})
|
|
42
46
|
: undefined;
|
|
43
47
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export function loadOklchColorPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.1");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { OklchColorManager } = await import("./OklchColorManager.js");
|
|
5
|
+
e.addColorManager(new OklchColorManager());
|
|
6
|
+
});
|
|
7
7
|
}
|
package/browser/utils.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { percentDenominator, } from "@tsparticles/engine";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
1
|
+
import { clamp, degToRad, inverseFactorNumerator, percentDenominator, rgbMax, } from "@tsparticles/engine";
|
|
2
|
+
const OKLAB_LMS = {
|
|
3
|
+
l: { L: 1, a: 0.3963377774, b: 0.2158037573 },
|
|
4
|
+
m: { L: 1, a: -0.1055613458, b: -0.0638541728 },
|
|
5
|
+
s: { L: 1, a: -0.0894841775, b: -1.291485548 },
|
|
6
|
+
}, LMS_TO_LINEAR_RGB = {
|
|
7
|
+
r: { l: 4.0767416621, m: -3.3077115913, s: 0.2309699292 },
|
|
8
|
+
g: { l: -1.2684380046, m: 2.6097574011, s: -0.3413193965 },
|
|
9
|
+
b: { l: -0.0041960863, m: -0.7034186147, s: 1.707614701 },
|
|
10
|
+
}, SRGB = {
|
|
11
|
+
GAMMA: 2.4,
|
|
12
|
+
LINEAR_THRESHOLD: 0.0031308,
|
|
13
|
+
LINEAR_SCALE: 12.92,
|
|
14
|
+
SCALE: 1.055,
|
|
15
|
+
OFFSET: 0.055,
|
|
16
|
+
}, minSrgbValue = 0, maxSrgbValue = 1;
|
|
17
|
+
export function oklchToRgb(oklch) {
|
|
18
|
+
const L = oklch.l / percentDenominator, C = oklch.c / percentDenominator, hRad = degToRad(oklch.h), a = C * Math.cos(hRad), b = C * Math.sin(hRad), l_ = OKLAB_LMS.l.L * L + OKLAB_LMS.l.a * a + OKLAB_LMS.l.b * b, m_ = OKLAB_LMS.m.L * L + OKLAB_LMS.m.a * a + OKLAB_LMS.m.b * b, s_ = OKLAB_LMS.s.L * L + OKLAB_LMS.s.a * a + OKLAB_LMS.s.b * b, cubic = 3, l = l_ ** cubic, m = m_ ** cubic, s = s_ ** cubic, rLinear = LMS_TO_LINEAR_RGB.r.l * l + LMS_TO_LINEAR_RGB.r.m * m + LMS_TO_LINEAR_RGB.r.s * s, gLinear = LMS_TO_LINEAR_RGB.g.l * l + LMS_TO_LINEAR_RGB.g.m * m + LMS_TO_LINEAR_RGB.g.s * s, bLinear = LMS_TO_LINEAR_RGB.b.l * l + LMS_TO_LINEAR_RGB.b.m * m + LMS_TO_LINEAR_RGB.b.s * s, toSrgb = (x) => x <= SRGB.LINEAR_THRESHOLD
|
|
19
|
+
? SRGB.LINEAR_SCALE * x
|
|
20
|
+
: SRGB.SCALE * Math.pow(x, inverseFactorNumerator / SRGB.GAMMA) - SRGB.OFFSET, toSrgbFixed = num => Math.round(clamp(toSrgb(num), minSrgbValue, maxSrgbValue) * rgbMax);
|
|
11
21
|
return {
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
r: toSrgbFixed(rLinear),
|
|
23
|
+
g: toSrgbFixed(gLinear),
|
|
24
|
+
b: toSrgbFixed(bLinear),
|
|
14
25
|
};
|
|
15
26
|
}
|
|
16
|
-
export function oklchToRgb(oklch) {
|
|
17
|
-
const l = oklch.l / percentDenominator, c = oklch.c / percentDenominator, h = oklch.h / fullDegree, result = { r: 0, g: 0, b: 0 };
|
|
18
|
-
result.r = Math.floor(l * rgbFactor);
|
|
19
|
-
result.g = Math.floor(c * rgbFactor);
|
|
20
|
-
result.b = Math.floor(h * rgbFactor);
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
27
|
export function oklchaToRgba(oklcha) {
|
|
24
28
|
return {
|
|
25
29
|
a: oklcha.a,
|
|
@@ -27,6 +31,6 @@ export function oklchaToRgba(oklcha) {
|
|
|
27
31
|
};
|
|
28
32
|
}
|
|
29
33
|
export function getStyleFromOklch(color, opacity) {
|
|
30
|
-
const { l, c, h } = color, alpha = opacity !== undefined ?
|
|
31
|
-
return `oklch(${l}
|
|
34
|
+
const { l, c, h } = color, alpha = opacity !== undefined ? ` / ${opacity.toString()}` : "";
|
|
35
|
+
return `oklch(${l.toString()}% ${c.toString()}% ${h.toString()}°${alpha})`;
|
|
32
36
|
}
|
package/cjs/OklchColorManager.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const utils_js_1 = require("./utils.js");
|
|
6
|
-
class OklchColorManager {
|
|
1
|
+
import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
|
|
2
|
+
import { oklchToRgb, oklchaToRgba } from "./utils.js";
|
|
3
|
+
const oklchRegex = /oklch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(°)?(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;
|
|
4
|
+
export class OklchColorManager {
|
|
7
5
|
constructor() {
|
|
8
6
|
this.key = "oklch";
|
|
9
|
-
|
|
7
|
+
}
|
|
8
|
+
accepts(input) {
|
|
9
|
+
return input.startsWith("oklch");
|
|
10
10
|
}
|
|
11
11
|
handleColor(color) {
|
|
12
12
|
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
13
|
-
if (oklchColor
|
|
14
|
-
return
|
|
13
|
+
if (!Object.hasOwn(oklchColor, "l") && !Object.hasOwn(oklchColor, "c") && !Object.hasOwn(oklchColor, "h")) {
|
|
14
|
+
return;
|
|
15
15
|
}
|
|
16
|
+
return oklchToRgb(oklchColor);
|
|
16
17
|
}
|
|
17
18
|
handleRangeColor(color) {
|
|
18
19
|
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
19
|
-
if (oklchColor
|
|
20
|
-
return
|
|
21
|
-
l: (0, engine_1.getRangeValue)(oklchColor.l),
|
|
22
|
-
c: (0, engine_1.getRangeValue)(oklchColor.c),
|
|
23
|
-
h: (0, engine_1.getRangeValue)(oklchColor.h),
|
|
24
|
-
});
|
|
20
|
+
if (!Object.hasOwn(oklchColor, "l") && !Object.hasOwn(oklchColor, "c") && !Object.hasOwn(oklchColor, "h")) {
|
|
21
|
+
return;
|
|
25
22
|
}
|
|
23
|
+
return oklchToRgb({
|
|
24
|
+
l: getRangeValue(oklchColor.l),
|
|
25
|
+
c: getRangeValue(oklchColor.c),
|
|
26
|
+
h: getRangeValue(oklchColor.h),
|
|
27
|
+
});
|
|
26
28
|
}
|
|
27
29
|
parseString(input) {
|
|
28
|
-
|
|
29
|
-
if (!isOklch) {
|
|
30
|
+
if (!this.accepts(input)) {
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
|
-
const
|
|
33
|
+
const result = oklchRegex.exec(input), indexes = {
|
|
33
34
|
l: 1,
|
|
34
35
|
c: 3,
|
|
35
36
|
h: 5,
|
|
36
37
|
a: 7,
|
|
37
38
|
}, defaultAlpha = 1;
|
|
38
39
|
return result
|
|
39
|
-
?
|
|
40
|
-
a: result[indexes.a] ?
|
|
41
|
-
c: parseFloat(result[indexes.c]),
|
|
42
|
-
h: parseFloat(result[indexes.h]),
|
|
43
|
-
l: parseFloat(result[indexes.l]),
|
|
40
|
+
? oklchaToRgba({
|
|
41
|
+
a: result[indexes.a] ? parseAlpha(result[indexes.a]) : defaultAlpha,
|
|
42
|
+
c: parseFloat(result[indexes.c] ?? "0"),
|
|
43
|
+
h: parseFloat(result[indexes.h] ?? "0"),
|
|
44
|
+
l: parseFloat(result[indexes.l] ?? "0"),
|
|
44
45
|
})
|
|
45
46
|
: undefined;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
exports.OklchColorManager = OklchColorManager;
|
package/cjs/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
engine.checkVersion("3.9.1");
|
|
8
|
-
await engine.addColorManager(new OklchColorManager_js_1.OklchColorManager(), refresh);
|
|
9
|
-
await engine.addColorManager(new LchColorManager_js_1.LchColorManager(), refresh);
|
|
1
|
+
export function loadOklchColorPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.1");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { OklchColorManager } = await import("./OklchColorManager.js");
|
|
5
|
+
e.addColorManager(new OklchColorManager());
|
|
6
|
+
});
|
|
10
7
|
}
|
package/cjs/utils.js
CHANGED
|
@@ -1,39 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
function
|
|
1
|
+
import { clamp, degToRad, inverseFactorNumerator, percentDenominator, rgbMax, } from "@tsparticles/engine";
|
|
2
|
+
const OKLAB_LMS = {
|
|
3
|
+
l: { L: 1, a: 0.3963377774, b: 0.2158037573 },
|
|
4
|
+
m: { L: 1, a: -0.1055613458, b: -0.0638541728 },
|
|
5
|
+
s: { L: 1, a: -0.0894841775, b: -1.291485548 },
|
|
6
|
+
}, LMS_TO_LINEAR_RGB = {
|
|
7
|
+
r: { l: 4.0767416621, m: -3.3077115913, s: 0.2309699292 },
|
|
8
|
+
g: { l: -1.2684380046, m: 2.6097574011, s: -0.3413193965 },
|
|
9
|
+
b: { l: -0.0041960863, m: -0.7034186147, s: 1.707614701 },
|
|
10
|
+
}, SRGB = {
|
|
11
|
+
GAMMA: 2.4,
|
|
12
|
+
LINEAR_THRESHOLD: 0.0031308,
|
|
13
|
+
LINEAR_SCALE: 12.92,
|
|
14
|
+
SCALE: 1.055,
|
|
15
|
+
OFFSET: 0.055,
|
|
16
|
+
}, minSrgbValue = 0, maxSrgbValue = 1;
|
|
17
|
+
export function oklchToRgb(oklch) {
|
|
18
|
+
const L = oklch.l / percentDenominator, C = oklch.c / percentDenominator, hRad = degToRad(oklch.h), a = C * Math.cos(hRad), b = C * Math.sin(hRad), l_ = OKLAB_LMS.l.L * L + OKLAB_LMS.l.a * a + OKLAB_LMS.l.b * b, m_ = OKLAB_LMS.m.L * L + OKLAB_LMS.m.a * a + OKLAB_LMS.m.b * b, s_ = OKLAB_LMS.s.L * L + OKLAB_LMS.s.a * a + OKLAB_LMS.s.b * b, cubic = 3, l = l_ ** cubic, m = m_ ** cubic, s = s_ ** cubic, rLinear = LMS_TO_LINEAR_RGB.r.l * l + LMS_TO_LINEAR_RGB.r.m * m + LMS_TO_LINEAR_RGB.r.s * s, gLinear = LMS_TO_LINEAR_RGB.g.l * l + LMS_TO_LINEAR_RGB.g.m * m + LMS_TO_LINEAR_RGB.g.s * s, bLinear = LMS_TO_LINEAR_RGB.b.l * l + LMS_TO_LINEAR_RGB.b.m * m + LMS_TO_LINEAR_RGB.b.s * s, toSrgb = (x) => x <= SRGB.LINEAR_THRESHOLD
|
|
19
|
+
? SRGB.LINEAR_SCALE * x
|
|
20
|
+
: SRGB.SCALE * Math.pow(x, inverseFactorNumerator / SRGB.GAMMA) - SRGB.OFFSET, toSrgbFixed = num => Math.round(clamp(toSrgb(num), minSrgbValue, maxSrgbValue) * rgbMax);
|
|
18
21
|
return {
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
r: toSrgbFixed(rLinear),
|
|
23
|
+
g: toSrgbFixed(gLinear),
|
|
24
|
+
b: toSrgbFixed(bLinear),
|
|
21
25
|
};
|
|
22
26
|
}
|
|
23
|
-
function
|
|
24
|
-
const l = oklch.l / engine_1.percentDenominator, c = oklch.c / engine_1.percentDenominator, h = oklch.h / fullDegree, result = { r: 0, g: 0, b: 0 };
|
|
25
|
-
result.r = Math.floor(l * rgbFactor);
|
|
26
|
-
result.g = Math.floor(c * rgbFactor);
|
|
27
|
-
result.b = Math.floor(h * rgbFactor);
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
function oklchaToRgba(oklcha) {
|
|
27
|
+
export function oklchaToRgba(oklcha) {
|
|
31
28
|
return {
|
|
32
29
|
a: oklcha.a,
|
|
33
30
|
...oklchToRgb(oklcha),
|
|
34
31
|
};
|
|
35
32
|
}
|
|
36
|
-
function getStyleFromOklch(color, opacity) {
|
|
37
|
-
const { l, c, h } = color, alpha = opacity !== undefined ?
|
|
38
|
-
return `oklch(${l}
|
|
33
|
+
export function getStyleFromOklch(color, opacity) {
|
|
34
|
+
const { l, c, h } = color, alpha = opacity !== undefined ? ` / ${opacity.toString()}` : "";
|
|
35
|
+
return `oklch(${l.toString()}% ${c.toString()}% ${h.toString()}°${alpha})`;
|
|
39
36
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v4.0.0-alpha.1
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_plugin_oklch_color"] = this["webpackChunk_tsparticles_plugin_oklch_color"] || []).push([["dist_browser_OklchColorManager_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/OklchColorManager.js"
|
|
21
|
+
/*!*******************************************!*\
|
|
22
|
+
!*** ./dist/browser/OklchColorManager.js ***!
|
|
23
|
+
\*******************************************/
|
|
24
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
|
+
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ OklchColorManager: () => (/* binding */ OklchColorManager)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils.js */ \"./dist/browser/utils.js\");\n\n\nconst oklchRegex = /oklch\\(\\s*(\\d+(\\.\\d+)?)%\\s+(\\d+(\\.\\d+)?)\\s+(\\d+(\\.\\d+)?)(°)?(?:\\s*\\/\\s*(0|1|0?\\.\\d+|\\d{1,3}%))?\\s*\\)/i;\nclass OklchColorManager {\n constructor() {\n this.key = \"oklch\";\n }\n accepts(input) {\n return input.startsWith(\"oklch\");\n }\n handleColor(color) {\n const colorValue = color.value,\n oklchColor = colorValue.oklch ?? color.value;\n if (!Object.hasOwn(oklchColor, \"l\") && !Object.hasOwn(oklchColor, \"c\") && !Object.hasOwn(oklchColor, \"h\")) {\n return;\n }\n return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.oklchToRgb)(oklchColor);\n }\n handleRangeColor(color) {\n const colorValue = color.value,\n oklchColor = colorValue.oklch ?? color.value;\n if (!Object.hasOwn(oklchColor, \"l\") && !Object.hasOwn(oklchColor, \"c\") && !Object.hasOwn(oklchColor, \"h\")) {\n return;\n }\n return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.oklchToRgb)({\n l: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(oklchColor.l),\n c: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(oklchColor.c),\n h: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(oklchColor.h)\n });\n }\n parseString(input) {\n if (!this.accepts(input)) {\n return;\n }\n const result = oklchRegex.exec(input),\n indexes = {\n l: 1,\n c: 3,\n h: 5,\n a: 7\n },\n defaultAlpha = 1;\n return result ? (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.oklchaToRgba)({\n a: result[indexes.a] ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.parseAlpha)(result[indexes.a]) : defaultAlpha,\n c: parseFloat(result[indexes.c] ?? \"0\"),\n h: parseFloat(result[indexes.h] ?? \"0\"),\n l: parseFloat(result[indexes.l] ?? \"0\")\n }) : undefined;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-oklch-color/./dist/browser/OklchColorManager.js?\n}");
|
|
27
|
+
|
|
28
|
+
/***/ },
|
|
29
|
+
|
|
30
|
+
/***/ "./dist/browser/utils.js"
|
|
31
|
+
/*!*******************************!*\
|
|
32
|
+
!*** ./dist/browser/utils.js ***!
|
|
33
|
+
\*******************************/
|
|
34
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
35
|
+
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ getStyleFromOklch: () => (/* binding */ getStyleFromOklch),\n/* harmony export */ oklchToRgb: () => (/* binding */ oklchToRgb),\n/* harmony export */ oklchaToRgba: () => (/* binding */ oklchaToRgba)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst OKLAB_LMS = {\n l: {\n L: 1,\n a: 0.3963377774,\n b: 0.2158037573\n },\n m: {\n L: 1,\n a: -0.1055613458,\n b: -0.0638541728\n },\n s: {\n L: 1,\n a: -0.0894841775,\n b: -1.291485548\n }\n },\n LMS_TO_LINEAR_RGB = {\n r: {\n l: 4.0767416621,\n m: -3.3077115913,\n s: 0.2309699292\n },\n g: {\n l: -1.2684380046,\n m: 2.6097574011,\n s: -0.3413193965\n },\n b: {\n l: -0.0041960863,\n m: -0.7034186147,\n s: 1.707614701\n }\n },\n SRGB = {\n GAMMA: 2.4,\n LINEAR_THRESHOLD: 0.0031308,\n LINEAR_SCALE: 12.92,\n SCALE: 1.055,\n OFFSET: 0.055\n },\n minSrgbValue = 0,\n maxSrgbValue = 1;\nfunction oklchToRgb(oklch) {\n const L = oklch.l / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.percentDenominator,\n C = oklch.c / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.percentDenominator,\n hRad = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.degToRad)(oklch.h),\n a = C * Math.cos(hRad),\n b = C * Math.sin(hRad),\n l_ = OKLAB_LMS.l.L * L + OKLAB_LMS.l.a * a + OKLAB_LMS.l.b * b,\n m_ = OKLAB_LMS.m.L * L + OKLAB_LMS.m.a * a + OKLAB_LMS.m.b * b,\n s_ = OKLAB_LMS.s.L * L + OKLAB_LMS.s.a * a + OKLAB_LMS.s.b * b,\n cubic = 3,\n l = l_ ** cubic,\n m = m_ ** cubic,\n s = s_ ** cubic,\n rLinear = LMS_TO_LINEAR_RGB.r.l * l + LMS_TO_LINEAR_RGB.r.m * m + LMS_TO_LINEAR_RGB.r.s * s,\n gLinear = LMS_TO_LINEAR_RGB.g.l * l + LMS_TO_LINEAR_RGB.g.m * m + LMS_TO_LINEAR_RGB.g.s * s,\n bLinear = LMS_TO_LINEAR_RGB.b.l * l + LMS_TO_LINEAR_RGB.b.m * m + LMS_TO_LINEAR_RGB.b.s * s,\n toSrgb = x => x <= SRGB.LINEAR_THRESHOLD ? SRGB.LINEAR_SCALE * x : SRGB.SCALE * Math.pow(x, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.inverseFactorNumerator / SRGB.GAMMA) - SRGB.OFFSET,\n toSrgbFixed = num => Math.round((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.clamp)(toSrgb(num), minSrgbValue, maxSrgbValue) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rgbMax);\n return {\n r: toSrgbFixed(rLinear),\n g: toSrgbFixed(gLinear),\n b: toSrgbFixed(bLinear)\n };\n}\nfunction oklchaToRgba(oklcha) {\n return {\n a: oklcha.a,\n ...oklchToRgb(oklcha)\n };\n}\nfunction getStyleFromOklch(color, opacity) {\n const {\n l,\n c,\n h\n } = color,\n alpha = opacity !== undefined ? ` / ${opacity.toString()}` : \"\";\n return `oklch(${l.toString()}% ${c.toString()}% ${h.toString()}°${alpha})`;\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-oklch-color/./dist/browser/utils.js?\n}");
|
|
37
|
+
|
|
38
|
+
/***/ }
|
|
39
|
+
|
|
40
|
+
}]);
|
package/esm/OklchColorManager.js
CHANGED
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
|
|
2
2
|
import { oklchToRgb, oklchaToRgba } from "./utils.js";
|
|
3
|
+
const oklchRegex = /oklch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(°)?(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;
|
|
3
4
|
export class OklchColorManager {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.key = "oklch";
|
|
6
|
-
|
|
7
|
+
}
|
|
8
|
+
accepts(input) {
|
|
9
|
+
return input.startsWith("oklch");
|
|
7
10
|
}
|
|
8
11
|
handleColor(color) {
|
|
9
12
|
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
10
|
-
if (oklchColor
|
|
11
|
-
return
|
|
13
|
+
if (!Object.hasOwn(oklchColor, "l") && !Object.hasOwn(oklchColor, "c") && !Object.hasOwn(oklchColor, "h")) {
|
|
14
|
+
return;
|
|
12
15
|
}
|
|
16
|
+
return oklchToRgb(oklchColor);
|
|
13
17
|
}
|
|
14
18
|
handleRangeColor(color) {
|
|
15
19
|
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
16
|
-
if (oklchColor
|
|
17
|
-
return
|
|
18
|
-
l: getRangeValue(oklchColor.l),
|
|
19
|
-
c: getRangeValue(oklchColor.c),
|
|
20
|
-
h: getRangeValue(oklchColor.h),
|
|
21
|
-
});
|
|
20
|
+
if (!Object.hasOwn(oklchColor, "l") && !Object.hasOwn(oklchColor, "c") && !Object.hasOwn(oklchColor, "h")) {
|
|
21
|
+
return;
|
|
22
22
|
}
|
|
23
|
+
return oklchToRgb({
|
|
24
|
+
l: getRangeValue(oklchColor.l),
|
|
25
|
+
c: getRangeValue(oklchColor.c),
|
|
26
|
+
h: getRangeValue(oklchColor.h),
|
|
27
|
+
});
|
|
23
28
|
}
|
|
24
29
|
parseString(input) {
|
|
25
|
-
|
|
26
|
-
if (!isOklch) {
|
|
30
|
+
if (!this.accepts(input)) {
|
|
27
31
|
return;
|
|
28
32
|
}
|
|
29
|
-
const
|
|
33
|
+
const result = oklchRegex.exec(input), indexes = {
|
|
30
34
|
l: 1,
|
|
31
35
|
c: 3,
|
|
32
36
|
h: 5,
|
|
@@ -35,9 +39,9 @@ export class OklchColorManager {
|
|
|
35
39
|
return result
|
|
36
40
|
? oklchaToRgba({
|
|
37
41
|
a: result[indexes.a] ? parseAlpha(result[indexes.a]) : defaultAlpha,
|
|
38
|
-
c: parseFloat(result[indexes.c]),
|
|
39
|
-
h: parseFloat(result[indexes.h]),
|
|
40
|
-
l: parseFloat(result[indexes.l]),
|
|
42
|
+
c: parseFloat(result[indexes.c] ?? "0"),
|
|
43
|
+
h: parseFloat(result[indexes.h] ?? "0"),
|
|
44
|
+
l: parseFloat(result[indexes.l] ?? "0"),
|
|
41
45
|
})
|
|
42
46
|
: undefined;
|
|
43
47
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export function loadOklchColorPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.1");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { OklchColorManager } = await import("./OklchColorManager.js");
|
|
5
|
+
e.addColorManager(new OklchColorManager());
|
|
6
|
+
});
|
|
7
7
|
}
|
package/esm/utils.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { percentDenominator, } from "@tsparticles/engine";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
1
|
+
import { clamp, degToRad, inverseFactorNumerator, percentDenominator, rgbMax, } from "@tsparticles/engine";
|
|
2
|
+
const OKLAB_LMS = {
|
|
3
|
+
l: { L: 1, a: 0.3963377774, b: 0.2158037573 },
|
|
4
|
+
m: { L: 1, a: -0.1055613458, b: -0.0638541728 },
|
|
5
|
+
s: { L: 1, a: -0.0894841775, b: -1.291485548 },
|
|
6
|
+
}, LMS_TO_LINEAR_RGB = {
|
|
7
|
+
r: { l: 4.0767416621, m: -3.3077115913, s: 0.2309699292 },
|
|
8
|
+
g: { l: -1.2684380046, m: 2.6097574011, s: -0.3413193965 },
|
|
9
|
+
b: { l: -0.0041960863, m: -0.7034186147, s: 1.707614701 },
|
|
10
|
+
}, SRGB = {
|
|
11
|
+
GAMMA: 2.4,
|
|
12
|
+
LINEAR_THRESHOLD: 0.0031308,
|
|
13
|
+
LINEAR_SCALE: 12.92,
|
|
14
|
+
SCALE: 1.055,
|
|
15
|
+
OFFSET: 0.055,
|
|
16
|
+
}, minSrgbValue = 0, maxSrgbValue = 1;
|
|
17
|
+
export function oklchToRgb(oklch) {
|
|
18
|
+
const L = oklch.l / percentDenominator, C = oklch.c / percentDenominator, hRad = degToRad(oklch.h), a = C * Math.cos(hRad), b = C * Math.sin(hRad), l_ = OKLAB_LMS.l.L * L + OKLAB_LMS.l.a * a + OKLAB_LMS.l.b * b, m_ = OKLAB_LMS.m.L * L + OKLAB_LMS.m.a * a + OKLAB_LMS.m.b * b, s_ = OKLAB_LMS.s.L * L + OKLAB_LMS.s.a * a + OKLAB_LMS.s.b * b, cubic = 3, l = l_ ** cubic, m = m_ ** cubic, s = s_ ** cubic, rLinear = LMS_TO_LINEAR_RGB.r.l * l + LMS_TO_LINEAR_RGB.r.m * m + LMS_TO_LINEAR_RGB.r.s * s, gLinear = LMS_TO_LINEAR_RGB.g.l * l + LMS_TO_LINEAR_RGB.g.m * m + LMS_TO_LINEAR_RGB.g.s * s, bLinear = LMS_TO_LINEAR_RGB.b.l * l + LMS_TO_LINEAR_RGB.b.m * m + LMS_TO_LINEAR_RGB.b.s * s, toSrgb = (x) => x <= SRGB.LINEAR_THRESHOLD
|
|
19
|
+
? SRGB.LINEAR_SCALE * x
|
|
20
|
+
: SRGB.SCALE * Math.pow(x, inverseFactorNumerator / SRGB.GAMMA) - SRGB.OFFSET, toSrgbFixed = num => Math.round(clamp(toSrgb(num), minSrgbValue, maxSrgbValue) * rgbMax);
|
|
11
21
|
return {
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
r: toSrgbFixed(rLinear),
|
|
23
|
+
g: toSrgbFixed(gLinear),
|
|
24
|
+
b: toSrgbFixed(bLinear),
|
|
14
25
|
};
|
|
15
26
|
}
|
|
16
|
-
export function oklchToRgb(oklch) {
|
|
17
|
-
const l = oklch.l / percentDenominator, c = oklch.c / percentDenominator, h = oklch.h / fullDegree, result = { r: 0, g: 0, b: 0 };
|
|
18
|
-
result.r = Math.floor(l * rgbFactor);
|
|
19
|
-
result.g = Math.floor(c * rgbFactor);
|
|
20
|
-
result.b = Math.floor(h * rgbFactor);
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
27
|
export function oklchaToRgba(oklcha) {
|
|
24
28
|
return {
|
|
25
29
|
a: oklcha.a,
|
|
@@ -27,6 +31,6 @@ export function oklchaToRgba(oklcha) {
|
|
|
27
31
|
};
|
|
28
32
|
}
|
|
29
33
|
export function getStyleFromOklch(color, opacity) {
|
|
30
|
-
const { l, c, h } = color, alpha = opacity !== undefined ?
|
|
31
|
-
return `oklch(${l}
|
|
34
|
+
const { l, c, h } = color, alpha = opacity !== undefined ? ` / ${opacity.toString()}` : "";
|
|
35
|
+
return `oklch(${l.toString()}% ${c.toString()}% ${h.toString()}°${alpha})`;
|
|
32
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/plugin-oklch-color",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "tsParticles OKLCH color plugin",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -100,9 +100,10 @@
|
|
|
100
100
|
"./package.json": "./package.json"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@tsparticles/engine": "
|
|
103
|
+
"@tsparticles/engine": "4.0.0-alpha.1"
|
|
104
104
|
},
|
|
105
105
|
"publishConfig": {
|
|
106
106
|
"access": "public"
|
|
107
|
-
}
|
|
107
|
+
},
|
|
108
|
+
"type": "module"
|
|
108
109
|
}
|