@tsparticles/plugin-lch-color 4.0.0-alpha.0

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/904.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 904.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_plugin_lch_color=this.webpackChunk_tsparticles_plugin_lch_color||[]).push([[904],{904(a,e,t){t.d(e,{LchColorManager:()=>k});var c=t(303);const s=255,r=.95047,l=1,n=1.08883,h=216/24389,o=24389/27,u=16,i=116,p=500,d=200,g={x:3.2404542,y:-1.5371385,z:-.4985314},O={x:-.969266,y:1.8760108,z:.041556},b={x:.0556434,y:-.2040259,z:1.0572252},v=2.4,w=.0031308,_=12.92,x=1.055,y=.055;function j(a){const e=a.l,t=a.c,j=(0,c.degToRad)(a.h),z=t*Math.cos(j),k=t*Math.sin(j),C=(e+u)/i,M=C+z/p,R=C-k/d,f=M**3,F=R**3,V=(f>h?f:(i*M-u)/o)*r,m=(e>o*h?C**3:e/o)*l,A=(F>h?F:(i*R-u)/o)*n,L=g.x*V+g.y*m+g.z*A,N=O.x*V+O.y*m+O.z*A,S=b.x*V+b.y*m+b.z*A,T=a=>{return Math.round((0,c.clamp)((e=a)<=w?_*e:x*Math.pow(e,c.inverseFactorNumerator/v)-y,0,1)*s);var e};return{r:T(L),g:T(N),b:T(S)}}const z=/lch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;class k{constructor(){this.key="lch"}accepts(a){return a.startsWith("lch")}handleColor(a){const e=a.value.lch??a.value;if(Object.hasOwn(e,"l")||Object.hasOwn(e,"c")||Object.hasOwn(e,"h"))return j(e)}handleRangeColor(a){const e=a.value.lch??a.value;if(Object.hasOwn(e,"l")||Object.hasOwn(e,"c")||Object.hasOwn(e,"h"))return j({l:(0,c.getRangeValue)(e.l),c:(0,c.getRangeValue)(e.c),h:(0,c.getRangeValue)(e.h)})}parseString(a){if(!this.accepts(a))return;const e=z.exec(a),t=1,s=3,r=5,l=7;return e?{a:(n={a:e[l]?(0,c.parseAlpha)(e[l]):1,c:parseFloat(e[s]??"0"),h:parseFloat(e[r]??"0"),l:parseFloat(e[t]??"0")}).a,...j(n)}:void 0;var n}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles LCH Color Plugin v4.0.0-alpha.0 by Matteo Bruni */
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ [![banner](https://particles.js.org/images/banner3.png)](https://particles.js.org)
2
+
3
+ # tsParticles LCH Color Plugin
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/plugin-lch-color/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-lch-color)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/plugin-lch-color.svg)](https://www.npmjs.com/package/@tsparticles/plugin-lch-color)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/plugin-lch-color)](https://www.npmjs.com/package/@tsparticles/plugin-lch-color) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/tsparticles/tsparticles) plugin for adding the LCH color support.
10
+
11
+ ## How to use it
12
+
13
+ ### CDN / Vanilla JS / jQuery
14
+
15
+ The CDN/Vanilla version JS has one required file in vanilla configuration:
16
+
17
+ Including the `tsparticles.plugin.lchColor.min.js` file will export the function to load the plugin:
18
+
19
+ ```text
20
+ loadLchColorPlugin
21
+ ```
22
+
23
+ ### Usage
24
+
25
+ Once the scripts are loaded you can set up `tsParticles` and the plugin like this:
26
+
27
+ ```javascript
28
+ (async () => {
29
+ await loadLchColorPlugin();
30
+
31
+ await tsParticles.load({
32
+ id: "tsparticles",
33
+ options: {
34
+ /* options */
35
+ },
36
+ });
37
+ })();
38
+ ```
39
+
40
+ ### ESM / CommonJS
41
+
42
+ This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
43
+
44
+ ```shell
45
+ $ npm install @tsparticles/plugin-lch-color
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ $ yarn add @tsparticles/plugin-lch-color
52
+ ```
53
+
54
+ Then you need to import it in the app, like this:
55
+
56
+ ```javascript
57
+ const { tsParticles } = require("@tsparticles/engine");
58
+ const { loadLchColorPlugin } = require("@tsparticles/plugin-lch-color");
59
+
60
+ (async () => {
61
+ await loadLchColorPlugin();
62
+ })();
63
+ ```
64
+
65
+ or
66
+
67
+ ```javascript
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadLchColorPlugin } from "@tsparticles/plugin-lch-color";
70
+
71
+ (async () => {
72
+ await loadLchColorPlugin();
73
+ })();
74
+ ```
@@ -0,0 +1,48 @@
1
+ import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
2
+ import { lchToRgb, lchaToRgba } from "./utils.js";
3
+ const lchRegex = /lch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;
4
+ export class LchColorManager {
5
+ constructor() {
6
+ this.key = "lch";
7
+ }
8
+ accepts(input) {
9
+ return input.startsWith("lch");
10
+ }
11
+ handleColor(color) {
12
+ const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
13
+ if (!Object.hasOwn(lchColor, "l") && !Object.hasOwn(lchColor, "c") && !Object.hasOwn(lchColor, "h")) {
14
+ return;
15
+ }
16
+ return lchToRgb(lchColor);
17
+ }
18
+ handleRangeColor(color) {
19
+ const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
20
+ if (!Object.hasOwn(lchColor, "l") && !Object.hasOwn(lchColor, "c") && !Object.hasOwn(lchColor, "h")) {
21
+ return;
22
+ }
23
+ return lchToRgb({
24
+ l: getRangeValue(lchColor.l),
25
+ c: getRangeValue(lchColor.c),
26
+ h: getRangeValue(lchColor.h),
27
+ });
28
+ }
29
+ parseString(input) {
30
+ if (!this.accepts(input)) {
31
+ return;
32
+ }
33
+ const result = lchRegex.exec(input), indexes = {
34
+ l: 1,
35
+ c: 3,
36
+ h: 5,
37
+ a: 7,
38
+ }, defaultAlpha = 1;
39
+ return result
40
+ ? lchaToRgba({
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"),
45
+ })
46
+ : undefined;
47
+ }
48
+ }
@@ -0,0 +1,7 @@
1
+ export function loadLchColorPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { LchColorManager } = await import("./LchColorManager.js");
5
+ e.addColorManager(new LchColorManager());
6
+ });
7
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
@@ -0,0 +1,54 @@
1
+ import { clamp, degToRad, inverseFactorNumerator, } from "@tsparticles/engine";
2
+ const RGB = {
3
+ MAX: 255,
4
+ }, WHITE_POINT_D65 = {
5
+ X: 0.95047,
6
+ Y: 1.0,
7
+ Z: 1.08883,
8
+ }, CIE = {
9
+ LAB_EPSILON_NUMERATOR: 216,
10
+ LAB_EPSILON_DENOMINATOR: 24389,
11
+ LAB_KAPPA_NUMERATOR: 24389,
12
+ LAB_KAPPA_DENOMINATOR: 27,
13
+ LAB_L_OFFSET: 16,
14
+ LAB_L_SCALE: 116,
15
+ LAB_A_SCALE: 500,
16
+ LAB_B_SCALE: 200,
17
+ }, LAB = {
18
+ EPSILON: CIE.LAB_EPSILON_NUMERATOR / CIE.LAB_EPSILON_DENOMINATOR,
19
+ KAPPA: CIE.LAB_KAPPA_NUMERATOR / CIE.LAB_KAPPA_DENOMINATOR,
20
+ L_OFFSET: CIE.LAB_L_OFFSET,
21
+ L_SCALE: CIE.LAB_L_SCALE,
22
+ A_SCALE: CIE.LAB_A_SCALE,
23
+ B_SCALE: CIE.LAB_B_SCALE,
24
+ }, XYZ_TO_LINEAR_RGB = {
25
+ r: { x: 3.2404542, y: -1.5371385, z: -0.4985314 },
26
+ g: { x: -0.969266, y: 1.8760108, z: 0.041556 },
27
+ b: { x: 0.0556434, y: -0.2040259, z: 1.0572252 },
28
+ }, SRGB = {
29
+ GAMMA: 2.4,
30
+ LINEAR_THRESHOLD: 0.0031308,
31
+ LINEAR_SCALE: 12.92,
32
+ SCALE: 1.055,
33
+ OFFSET: 0.055,
34
+ }, minSrgbValue = 0, maxSrgbValue = 1;
35
+ export function lchToRgb(lch) {
36
+ const L = lch.l, C = lch.c, hRad = degToRad(lch.h), a = C * Math.cos(hRad), b = C * Math.sin(hRad), fy = (L + LAB.L_OFFSET) / LAB.L_SCALE, fx = fy + a / LAB.A_SCALE, fz = fy - b / LAB.B_SCALE, cubic = 3, fx3 = fx ** cubic, fz3 = fz ** cubic, xr = fx3 > LAB.EPSILON ? fx3 : (LAB.L_SCALE * fx - LAB.L_OFFSET) / LAB.KAPPA, yr = L > LAB.KAPPA * LAB.EPSILON ? fy ** cubic : L / LAB.KAPPA, zr = fz3 > LAB.EPSILON ? fz3 : (LAB.L_SCALE * fz - LAB.L_OFFSET) / LAB.KAPPA, X = xr * WHITE_POINT_D65.X, Y = yr * WHITE_POINT_D65.Y, Z = zr * WHITE_POINT_D65.Z, rLinear = XYZ_TO_LINEAR_RGB.r.x * X + XYZ_TO_LINEAR_RGB.r.y * Y + XYZ_TO_LINEAR_RGB.r.z * Z, gLinear = XYZ_TO_LINEAR_RGB.g.x * X + XYZ_TO_LINEAR_RGB.g.y * Y + XYZ_TO_LINEAR_RGB.g.z * Z, bLinear = XYZ_TO_LINEAR_RGB.b.x * X + XYZ_TO_LINEAR_RGB.b.y * Y + XYZ_TO_LINEAR_RGB.b.z * Z, toSrgb = (x) => x <= SRGB.LINEAR_THRESHOLD
37
+ ? SRGB.LINEAR_SCALE * x
38
+ : SRGB.SCALE * Math.pow(x, inverseFactorNumerator / SRGB.GAMMA) - SRGB.OFFSET, toSrgbFixed = num => Math.round(clamp(toSrgb(num), minSrgbValue, maxSrgbValue) * RGB.MAX);
39
+ return {
40
+ r: toSrgbFixed(rLinear),
41
+ g: toSrgbFixed(gLinear),
42
+ b: toSrgbFixed(bLinear),
43
+ };
44
+ }
45
+ export function lchaToRgba(lcha) {
46
+ return {
47
+ a: lcha.a,
48
+ ...lchToRgb(lcha),
49
+ };
50
+ }
51
+ export function getStyleFromLch(color, opacity) {
52
+ const { l, c, h } = color, alpha = opacity !== undefined ? `/ ${opacity.toString()}` : "";
53
+ return `lch(${l.toString()}%, ${c.toString()}%, ${h.toString()}°${alpha})`;
54
+ }
@@ -0,0 +1,48 @@
1
+ import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
2
+ import { lchToRgb, lchaToRgba } from "./utils.js";
3
+ const lchRegex = /lch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;
4
+ export class LchColorManager {
5
+ constructor() {
6
+ this.key = "lch";
7
+ }
8
+ accepts(input) {
9
+ return input.startsWith("lch");
10
+ }
11
+ handleColor(color) {
12
+ const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
13
+ if (!Object.hasOwn(lchColor, "l") && !Object.hasOwn(lchColor, "c") && !Object.hasOwn(lchColor, "h")) {
14
+ return;
15
+ }
16
+ return lchToRgb(lchColor);
17
+ }
18
+ handleRangeColor(color) {
19
+ const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
20
+ if (!Object.hasOwn(lchColor, "l") && !Object.hasOwn(lchColor, "c") && !Object.hasOwn(lchColor, "h")) {
21
+ return;
22
+ }
23
+ return lchToRgb({
24
+ l: getRangeValue(lchColor.l),
25
+ c: getRangeValue(lchColor.c),
26
+ h: getRangeValue(lchColor.h),
27
+ });
28
+ }
29
+ parseString(input) {
30
+ if (!this.accepts(input)) {
31
+ return;
32
+ }
33
+ const result = lchRegex.exec(input), indexes = {
34
+ l: 1,
35
+ c: 3,
36
+ h: 5,
37
+ a: 7,
38
+ }, defaultAlpha = 1;
39
+ return result
40
+ ? lchaToRgba({
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"),
45
+ })
46
+ : undefined;
47
+ }
48
+ }
package/cjs/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export function loadLchColorPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { LchColorManager } = await import("./LchColorManager.js");
5
+ e.addColorManager(new LchColorManager());
6
+ });
7
+ }
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
package/cjs/utils.js ADDED
@@ -0,0 +1,54 @@
1
+ import { clamp, degToRad, inverseFactorNumerator, } from "@tsparticles/engine";
2
+ const RGB = {
3
+ MAX: 255,
4
+ }, WHITE_POINT_D65 = {
5
+ X: 0.95047,
6
+ Y: 1.0,
7
+ Z: 1.08883,
8
+ }, CIE = {
9
+ LAB_EPSILON_NUMERATOR: 216,
10
+ LAB_EPSILON_DENOMINATOR: 24389,
11
+ LAB_KAPPA_NUMERATOR: 24389,
12
+ LAB_KAPPA_DENOMINATOR: 27,
13
+ LAB_L_OFFSET: 16,
14
+ LAB_L_SCALE: 116,
15
+ LAB_A_SCALE: 500,
16
+ LAB_B_SCALE: 200,
17
+ }, LAB = {
18
+ EPSILON: CIE.LAB_EPSILON_NUMERATOR / CIE.LAB_EPSILON_DENOMINATOR,
19
+ KAPPA: CIE.LAB_KAPPA_NUMERATOR / CIE.LAB_KAPPA_DENOMINATOR,
20
+ L_OFFSET: CIE.LAB_L_OFFSET,
21
+ L_SCALE: CIE.LAB_L_SCALE,
22
+ A_SCALE: CIE.LAB_A_SCALE,
23
+ B_SCALE: CIE.LAB_B_SCALE,
24
+ }, XYZ_TO_LINEAR_RGB = {
25
+ r: { x: 3.2404542, y: -1.5371385, z: -0.4985314 },
26
+ g: { x: -0.969266, y: 1.8760108, z: 0.041556 },
27
+ b: { x: 0.0556434, y: -0.2040259, z: 1.0572252 },
28
+ }, SRGB = {
29
+ GAMMA: 2.4,
30
+ LINEAR_THRESHOLD: 0.0031308,
31
+ LINEAR_SCALE: 12.92,
32
+ SCALE: 1.055,
33
+ OFFSET: 0.055,
34
+ }, minSrgbValue = 0, maxSrgbValue = 1;
35
+ export function lchToRgb(lch) {
36
+ const L = lch.l, C = lch.c, hRad = degToRad(lch.h), a = C * Math.cos(hRad), b = C * Math.sin(hRad), fy = (L + LAB.L_OFFSET) / LAB.L_SCALE, fx = fy + a / LAB.A_SCALE, fz = fy - b / LAB.B_SCALE, cubic = 3, fx3 = fx ** cubic, fz3 = fz ** cubic, xr = fx3 > LAB.EPSILON ? fx3 : (LAB.L_SCALE * fx - LAB.L_OFFSET) / LAB.KAPPA, yr = L > LAB.KAPPA * LAB.EPSILON ? fy ** cubic : L / LAB.KAPPA, zr = fz3 > LAB.EPSILON ? fz3 : (LAB.L_SCALE * fz - LAB.L_OFFSET) / LAB.KAPPA, X = xr * WHITE_POINT_D65.X, Y = yr * WHITE_POINT_D65.Y, Z = zr * WHITE_POINT_D65.Z, rLinear = XYZ_TO_LINEAR_RGB.r.x * X + XYZ_TO_LINEAR_RGB.r.y * Y + XYZ_TO_LINEAR_RGB.r.z * Z, gLinear = XYZ_TO_LINEAR_RGB.g.x * X + XYZ_TO_LINEAR_RGB.g.y * Y + XYZ_TO_LINEAR_RGB.g.z * Z, bLinear = XYZ_TO_LINEAR_RGB.b.x * X + XYZ_TO_LINEAR_RGB.b.y * Y + XYZ_TO_LINEAR_RGB.b.z * Z, toSrgb = (x) => x <= SRGB.LINEAR_THRESHOLD
37
+ ? SRGB.LINEAR_SCALE * x
38
+ : SRGB.SCALE * Math.pow(x, inverseFactorNumerator / SRGB.GAMMA) - SRGB.OFFSET, toSrgbFixed = num => Math.round(clamp(toSrgb(num), minSrgbValue, maxSrgbValue) * RGB.MAX);
39
+ return {
40
+ r: toSrgbFixed(rLinear),
41
+ g: toSrgbFixed(gLinear),
42
+ b: toSrgbFixed(bLinear),
43
+ };
44
+ }
45
+ export function lchaToRgba(lcha) {
46
+ return {
47
+ a: lcha.a,
48
+ ...lchToRgb(lcha),
49
+ };
50
+ }
51
+ export function getStyleFromLch(color, opacity) {
52
+ const { l, c, h } = color, alpha = opacity !== undefined ? `/ ${opacity.toString()}` : "";
53
+ return `lch(${l.toString()}%, ${c.toString()}%, ${h.toString()}°${alpha})`;
54
+ }
@@ -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.0
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_lch_color"] = this["webpackChunk_tsparticles_plugin_lch_color"] || []).push([["dist_browser_LchColorManager_js"],{
19
+
20
+ /***/ "./dist/browser/LchColorManager.js"
21
+ /*!*****************************************!*\
22
+ !*** ./dist/browser/LchColorManager.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 */ LchColorManager: () => (/* binding */ LchColorManager)\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 lchRegex = /lch\\(\\s*(\\d+(\\.\\d+)?)%\\s+(\\d+(\\.\\d+)?)\\s+(\\d+(\\.\\d+)?)(?:\\s*\\/\\s*(0|1|0?\\.\\d+|\\d{1,3}%))?\\s*\\)/i;\nclass LchColorManager {\n constructor() {\n this.key = \"lch\";\n }\n accepts(input) {\n return input.startsWith(\"lch\");\n }\n handleColor(color) {\n const colorValue = color.value,\n lchColor = colorValue.lch ?? color.value;\n if (!Object.hasOwn(lchColor, \"l\") && !Object.hasOwn(lchColor, \"c\") && !Object.hasOwn(lchColor, \"h\")) {\n return;\n }\n return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.lchToRgb)(lchColor);\n }\n handleRangeColor(color) {\n const colorValue = color.value,\n lchColor = colorValue.lch ?? color.value;\n if (!Object.hasOwn(lchColor, \"l\") && !Object.hasOwn(lchColor, \"c\") && !Object.hasOwn(lchColor, \"h\")) {\n return;\n }\n return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.lchToRgb)({\n l: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(lchColor.l),\n c: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(lchColor.c),\n h: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(lchColor.h)\n });\n }\n parseString(input) {\n if (!this.accepts(input)) {\n return;\n }\n const result = lchRegex.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__.lchaToRgba)({\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-lch-color/./dist/browser/LchColorManager.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 */ getStyleFromLch: () => (/* binding */ getStyleFromLch),\n/* harmony export */ lchToRgb: () => (/* binding */ lchToRgb),\n/* harmony export */ lchaToRgba: () => (/* binding */ lchaToRgba)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst RGB = {\n MAX: 255\n },\n WHITE_POINT_D65 = {\n X: 0.95047,\n Y: 1.0,\n Z: 1.08883\n },\n CIE = {\n LAB_EPSILON_NUMERATOR: 216,\n LAB_EPSILON_DENOMINATOR: 24389,\n LAB_KAPPA_NUMERATOR: 24389,\n LAB_KAPPA_DENOMINATOR: 27,\n LAB_L_OFFSET: 16,\n LAB_L_SCALE: 116,\n LAB_A_SCALE: 500,\n LAB_B_SCALE: 200\n },\n LAB = {\n EPSILON: CIE.LAB_EPSILON_NUMERATOR / CIE.LAB_EPSILON_DENOMINATOR,\n KAPPA: CIE.LAB_KAPPA_NUMERATOR / CIE.LAB_KAPPA_DENOMINATOR,\n L_OFFSET: CIE.LAB_L_OFFSET,\n L_SCALE: CIE.LAB_L_SCALE,\n A_SCALE: CIE.LAB_A_SCALE,\n B_SCALE: CIE.LAB_B_SCALE\n },\n XYZ_TO_LINEAR_RGB = {\n r: {\n x: 3.2404542,\n y: -1.5371385,\n z: -0.4985314\n },\n g: {\n x: -0.969266,\n y: 1.8760108,\n z: 0.041556\n },\n b: {\n x: 0.0556434,\n y: -0.2040259,\n z: 1.0572252\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 lchToRgb(lch) {\n const L = lch.l,\n C = lch.c,\n hRad = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.degToRad)(lch.h),\n a = C * Math.cos(hRad),\n b = C * Math.sin(hRad),\n fy = (L + LAB.L_OFFSET) / LAB.L_SCALE,\n fx = fy + a / LAB.A_SCALE,\n fz = fy - b / LAB.B_SCALE,\n cubic = 3,\n fx3 = fx ** cubic,\n fz3 = fz ** cubic,\n xr = fx3 > LAB.EPSILON ? fx3 : (LAB.L_SCALE * fx - LAB.L_OFFSET) / LAB.KAPPA,\n yr = L > LAB.KAPPA * LAB.EPSILON ? fy ** cubic : L / LAB.KAPPA,\n zr = fz3 > LAB.EPSILON ? fz3 : (LAB.L_SCALE * fz - LAB.L_OFFSET) / LAB.KAPPA,\n X = xr * WHITE_POINT_D65.X,\n Y = yr * WHITE_POINT_D65.Y,\n Z = zr * WHITE_POINT_D65.Z,\n rLinear = XYZ_TO_LINEAR_RGB.r.x * X + XYZ_TO_LINEAR_RGB.r.y * Y + XYZ_TO_LINEAR_RGB.r.z * Z,\n gLinear = XYZ_TO_LINEAR_RGB.g.x * X + XYZ_TO_LINEAR_RGB.g.y * Y + XYZ_TO_LINEAR_RGB.g.z * Z,\n bLinear = XYZ_TO_LINEAR_RGB.b.x * X + XYZ_TO_LINEAR_RGB.b.y * Y + XYZ_TO_LINEAR_RGB.b.z * Z,\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) * RGB.MAX);\n return {\n r: toSrgbFixed(rLinear),\n g: toSrgbFixed(gLinear),\n b: toSrgbFixed(bLinear)\n };\n}\nfunction lchaToRgba(lcha) {\n return {\n a: lcha.a,\n ...lchToRgb(lcha)\n };\n}\nfunction getStyleFromLch(color, opacity) {\n const {\n l,\n c,\n h\n } = color,\n alpha = opacity !== undefined ? `/ ${opacity.toString()}` : \"\";\n return `lch(${l.toString()}%, ${c.toString()}%, ${h.toString()}°${alpha})`;\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-lch-color/./dist/browser/utils.js?\n}");
37
+
38
+ /***/ }
39
+
40
+ }]);
@@ -0,0 +1,48 @@
1
+ import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
2
+ import { lchToRgb, lchaToRgba } from "./utils.js";
3
+ const lchRegex = /lch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;
4
+ export class LchColorManager {
5
+ constructor() {
6
+ this.key = "lch";
7
+ }
8
+ accepts(input) {
9
+ return input.startsWith("lch");
10
+ }
11
+ handleColor(color) {
12
+ const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
13
+ if (!Object.hasOwn(lchColor, "l") && !Object.hasOwn(lchColor, "c") && !Object.hasOwn(lchColor, "h")) {
14
+ return;
15
+ }
16
+ return lchToRgb(lchColor);
17
+ }
18
+ handleRangeColor(color) {
19
+ const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
20
+ if (!Object.hasOwn(lchColor, "l") && !Object.hasOwn(lchColor, "c") && !Object.hasOwn(lchColor, "h")) {
21
+ return;
22
+ }
23
+ return lchToRgb({
24
+ l: getRangeValue(lchColor.l),
25
+ c: getRangeValue(lchColor.c),
26
+ h: getRangeValue(lchColor.h),
27
+ });
28
+ }
29
+ parseString(input) {
30
+ if (!this.accepts(input)) {
31
+ return;
32
+ }
33
+ const result = lchRegex.exec(input), indexes = {
34
+ l: 1,
35
+ c: 3,
36
+ h: 5,
37
+ a: 7,
38
+ }, defaultAlpha = 1;
39
+ return result
40
+ ? lchaToRgba({
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"),
45
+ })
46
+ : undefined;
47
+ }
48
+ }
package/esm/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export function loadLchColorPlugin(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { LchColorManager } = await import("./LchColorManager.js");
5
+ e.addColorManager(new LchColorManager());
6
+ });
7
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/esm/utils.js ADDED
@@ -0,0 +1,54 @@
1
+ import { clamp, degToRad, inverseFactorNumerator, } from "@tsparticles/engine";
2
+ const RGB = {
3
+ MAX: 255,
4
+ }, WHITE_POINT_D65 = {
5
+ X: 0.95047,
6
+ Y: 1.0,
7
+ Z: 1.08883,
8
+ }, CIE = {
9
+ LAB_EPSILON_NUMERATOR: 216,
10
+ LAB_EPSILON_DENOMINATOR: 24389,
11
+ LAB_KAPPA_NUMERATOR: 24389,
12
+ LAB_KAPPA_DENOMINATOR: 27,
13
+ LAB_L_OFFSET: 16,
14
+ LAB_L_SCALE: 116,
15
+ LAB_A_SCALE: 500,
16
+ LAB_B_SCALE: 200,
17
+ }, LAB = {
18
+ EPSILON: CIE.LAB_EPSILON_NUMERATOR / CIE.LAB_EPSILON_DENOMINATOR,
19
+ KAPPA: CIE.LAB_KAPPA_NUMERATOR / CIE.LAB_KAPPA_DENOMINATOR,
20
+ L_OFFSET: CIE.LAB_L_OFFSET,
21
+ L_SCALE: CIE.LAB_L_SCALE,
22
+ A_SCALE: CIE.LAB_A_SCALE,
23
+ B_SCALE: CIE.LAB_B_SCALE,
24
+ }, XYZ_TO_LINEAR_RGB = {
25
+ r: { x: 3.2404542, y: -1.5371385, z: -0.4985314 },
26
+ g: { x: -0.969266, y: 1.8760108, z: 0.041556 },
27
+ b: { x: 0.0556434, y: -0.2040259, z: 1.0572252 },
28
+ }, SRGB = {
29
+ GAMMA: 2.4,
30
+ LINEAR_THRESHOLD: 0.0031308,
31
+ LINEAR_SCALE: 12.92,
32
+ SCALE: 1.055,
33
+ OFFSET: 0.055,
34
+ }, minSrgbValue = 0, maxSrgbValue = 1;
35
+ export function lchToRgb(lch) {
36
+ const L = lch.l, C = lch.c, hRad = degToRad(lch.h), a = C * Math.cos(hRad), b = C * Math.sin(hRad), fy = (L + LAB.L_OFFSET) / LAB.L_SCALE, fx = fy + a / LAB.A_SCALE, fz = fy - b / LAB.B_SCALE, cubic = 3, fx3 = fx ** cubic, fz3 = fz ** cubic, xr = fx3 > LAB.EPSILON ? fx3 : (LAB.L_SCALE * fx - LAB.L_OFFSET) / LAB.KAPPA, yr = L > LAB.KAPPA * LAB.EPSILON ? fy ** cubic : L / LAB.KAPPA, zr = fz3 > LAB.EPSILON ? fz3 : (LAB.L_SCALE * fz - LAB.L_OFFSET) / LAB.KAPPA, X = xr * WHITE_POINT_D65.X, Y = yr * WHITE_POINT_D65.Y, Z = zr * WHITE_POINT_D65.Z, rLinear = XYZ_TO_LINEAR_RGB.r.x * X + XYZ_TO_LINEAR_RGB.r.y * Y + XYZ_TO_LINEAR_RGB.r.z * Z, gLinear = XYZ_TO_LINEAR_RGB.g.x * X + XYZ_TO_LINEAR_RGB.g.y * Y + XYZ_TO_LINEAR_RGB.g.z * Z, bLinear = XYZ_TO_LINEAR_RGB.b.x * X + XYZ_TO_LINEAR_RGB.b.y * Y + XYZ_TO_LINEAR_RGB.b.z * Z, toSrgb = (x) => x <= SRGB.LINEAR_THRESHOLD
37
+ ? SRGB.LINEAR_SCALE * x
38
+ : SRGB.SCALE * Math.pow(x, inverseFactorNumerator / SRGB.GAMMA) - SRGB.OFFSET, toSrgbFixed = num => Math.round(clamp(toSrgb(num), minSrgbValue, maxSrgbValue) * RGB.MAX);
39
+ return {
40
+ r: toSrgbFixed(rLinear),
41
+ g: toSrgbFixed(gLinear),
42
+ b: toSrgbFixed(bLinear),
43
+ };
44
+ }
45
+ export function lchaToRgba(lcha) {
46
+ return {
47
+ a: lcha.a,
48
+ ...lchToRgb(lcha),
49
+ };
50
+ }
51
+ export function getStyleFromLch(color, opacity) {
52
+ const { l, c, h } = color, alpha = opacity !== undefined ? `/ ${opacity.toString()}` : "";
53
+ return `lch(${l.toString()}%, ${c.toString()}%, ${h.toString()}°${alpha})`;
54
+ }
package/package.json ADDED
@@ -0,0 +1,109 @@
1
+ {
2
+ "name": "@tsparticles/plugin-lch-color",
3
+ "version": "4.0.0-alpha.0",
4
+ "description": "tsParticles LCH color plugin",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/tsparticles/tsparticles.git",
9
+ "directory": "plugins/colors/lchColor"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "tsparticles-plugin"
64
+ ],
65
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
66
+ "license": "MIT",
67
+ "bugs": {
68
+ "url": "https://github.com/tsparticles/tsparticles/issues"
69
+ },
70
+ "funding": [
71
+ {
72
+ "type": "github",
73
+ "url": "https://github.com/sponsors/matteobruni"
74
+ },
75
+ {
76
+ "type": "github",
77
+ "url": "https://github.com/sponsors/tsparticles"
78
+ },
79
+ {
80
+ "type": "buymeacoffee",
81
+ "url": "https://www.buymeacoffee.com/matteobruni"
82
+ }
83
+ ],
84
+ "sideEffects": false,
85
+ "jsdelivr": "tsparticles.plugin.lchColor.min.js",
86
+ "unpkg": "tsparticles.plugin.lchColor.min.js",
87
+ "browser": "browser/index.js",
88
+ "main": "cjs/index.js",
89
+ "module": "esm/index.js",
90
+ "types": "types/index.d.ts",
91
+ "exports": {
92
+ ".": {
93
+ "types": "./types/index.d.ts",
94
+ "browser": "./browser/index.js",
95
+ "import": "./esm/index.js",
96
+ "require": "./cjs/index.js",
97
+ "umd": "./umd/index.js",
98
+ "default": "./cjs/index.js"
99
+ },
100
+ "./package.json": "./package.json"
101
+ },
102
+ "dependencies": {
103
+ "@tsparticles/engine": "4.0.0-alpha.0"
104
+ },
105
+ "publishConfig": {
106
+ "access": "public"
107
+ },
108
+ "type": "module"
109
+ }