@tsparticles/plugin-oklch-color 3.6.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.
@@ -0,0 +1,158 @@
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
+ * v3.6.0
8
+ */
9
+ /*
10
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
11
+ * This devtool is neither made for production nor for readable output files.
12
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
13
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
14
+ * or disable the default devtool with "devtool: false".
15
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
16
+ */
17
+ (function webpackUniversalModuleDefinition(root, factory) {
18
+ if(typeof exports === 'object' && typeof module === 'object')
19
+ module.exports = factory(require("@tsparticles/engine"));
20
+ else if(typeof define === 'function' && define.amd)
21
+ define(["@tsparticles/engine"], factory);
22
+ else {
23
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
24
+ for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
25
+ }
26
+ })(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => {
27
+ return /******/ (() => { // webpackBootstrap
28
+ /******/ "use strict";
29
+ /******/ var __webpack_modules__ = ({
30
+
31
+ /***/ "./dist/browser/LchColorManager.js":
32
+ /*!*****************************************!*\
33
+ !*** ./dist/browser/LchColorManager.js ***!
34
+ \*****************************************/
35
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
36
+
37
+ 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 _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils.js */ \"./dist/browser/utils.js\");\n\n\nclass LchColorManager {\n constructor() {\n this.key = \"color\";\n this.stringPrefix = \"lch\";\n }\n handleColor(color) {\n const colorValue = color.value,\n lchColor = colorValue.lch ?? color.value;\n if (lchColor.l !== undefined && lchColor.c !== undefined && lchColor.h !== undefined) {\n return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.lchToRgb)(lchColor);\n }\n }\n handleRangeColor(color) {\n const colorValue = color.value,\n lchColor = colorValue.lch ?? color.value;\n if (lchColor.l !== undefined && lchColor.c !== undefined && lchColor.h !== undefined) {\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 }\n parseString(input) {\n const isLch = input.startsWith(\"lch\");\n if (!isLch) {\n return;\n }\n const regex = /lch\\(\\s*(\\d+(\\.\\d+)?)%\\s+(\\d+(\\.\\d+)?)\\s+(\\d+(\\.\\d+)?)(?:\\s*\\/\\s*(0|1|0?\\.\\d+|\\d{1,3}%))?\\s*\\)/i,\n result = regex.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]),\n h: parseFloat(result[indexes.h]),\n l: parseFloat(result[indexes.l])\n }) : undefined;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-oklch-color/./dist/browser/LchColorManager.js?");
38
+
39
+ /***/ }),
40
+
41
+ /***/ "./dist/browser/OklchColorManager.js":
42
+ /*!*******************************************!*\
43
+ !*** ./dist/browser/OklchColorManager.js ***!
44
+ \*******************************************/
45
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
46
+
47
+ 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 _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils.js */ \"./dist/browser/utils.js\");\n\n\nclass OklchColorManager {\n constructor() {\n this.key = \"color\";\n this.stringPrefix = \"oklch\";\n }\n handleColor(color) {\n const colorValue = color.value,\n oklchColor = colorValue.oklch ?? color.value;\n if (oklchColor.l !== undefined && oklchColor.c !== undefined && oklchColor.h !== undefined) {\n return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.oklchToRgb)(oklchColor);\n }\n }\n handleRangeColor(color) {\n const colorValue = color.value,\n oklchColor = colorValue.oklch ?? color.value;\n if (oklchColor.l !== undefined && oklchColor.c !== undefined && oklchColor.h !== undefined) {\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 }\n parseString(input) {\n const isOklch = input.startsWith(\"oklch\");\n if (!isOklch) {\n return;\n }\n const regex = /oklch\\(\\s*(\\d+(\\.\\d+)?)%\\s+(\\d+(\\.\\d+)?)\\s+(\\d+(\\.\\d+)?)(°)?(?:\\s*\\/\\s*(0|1|0?\\.\\d+|\\d{1,3}%))?\\s*\\)/i,\n result = regex.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]),\n h: parseFloat(result[indexes.h]),\n l: parseFloat(result[indexes.l])\n }) : undefined;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-oklch-color/./dist/browser/OklchColorManager.js?");
48
+
49
+ /***/ }),
50
+
51
+ /***/ "./dist/browser/index.js":
52
+ /*!*******************************!*\
53
+ !*** ./dist/browser/index.js ***!
54
+ \*******************************/
55
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
56
+
57
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadOklchColorPlugin: () => (/* binding */ loadOklchColorPlugin)\n/* harmony export */ });\n/* harmony import */ var _LchColorManager_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./LchColorManager.js */ \"./dist/browser/LchColorManager.js\");\n/* harmony import */ var _OklchColorManager_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OklchColorManager.js */ \"./dist/browser/OklchColorManager.js\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\n\n\nfunction loadOklchColorPlugin() {\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.addColorManager)(new _OklchColorManager_js__WEBPACK_IMPORTED_MODULE_1__.OklchColorManager());\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.addColorManager)(new _LchColorManager_js__WEBPACK_IMPORTED_MODULE_2__.LchColorManager());\n return Promise.resolve();\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-oklch-color/./dist/browser/index.js?");
58
+
59
+ /***/ }),
60
+
61
+ /***/ "./dist/browser/utils.js":
62
+ /*!*******************************!*\
63
+ !*** ./dist/browser/utils.js ***!
64
+ \*******************************/
65
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
66
+
67
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ getStyleFromOklch: () => (/* binding */ getStyleFromOklch),\n/* harmony export */ lchToRgb: () => (/* binding */ lchToRgb),\n/* harmony export */ lchaToRgba: () => (/* binding */ lchaToRgba),\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/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nconst rgbFactor = 255,\n fullDegree = 360;\nfunction lchToRgb(lch) {\n const l = lch.l / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.percentDenominator,\n c = lch.c,\n h = lch.h / fullDegree,\n result = {\n r: 0,\n g: 0,\n b: 0\n };\n result.r = Math.floor(l * rgbFactor);\n result.g = Math.floor(c * rgbFactor);\n result.b = Math.floor(h * rgbFactor);\n return result;\n}\nfunction lchaToRgba(lcha) {\n return {\n a: lcha.a,\n ...lchToRgb(lcha)\n };\n}\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 h = oklch.h / fullDegree,\n result = {\n r: 0,\n g: 0,\n b: 0\n };\n result.r = Math.floor(l * rgbFactor);\n result.g = Math.floor(c * rgbFactor);\n result.b = Math.floor(h * rgbFactor);\n return result;\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}` : \"\";\n return `oklch(${l}%, ${c}%, ${h}°${alpha})`;\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-oklch-color/./dist/browser/utils.js?");
68
+
69
+ /***/ }),
70
+
71
+ /***/ "@tsparticles/engine":
72
+ /*!*********************************************************************************************************************************!*\
73
+ !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
74
+ \*********************************************************************************************************************************/
75
+ /***/ ((module) => {
76
+
77
+ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
78
+
79
+ /***/ })
80
+
81
+ /******/ });
82
+ /************************************************************************/
83
+ /******/ // The module cache
84
+ /******/ var __webpack_module_cache__ = {};
85
+ /******/
86
+ /******/ // The require function
87
+ /******/ function __webpack_require__(moduleId) {
88
+ /******/ // Check if module is in cache
89
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
90
+ /******/ if (cachedModule !== undefined) {
91
+ /******/ return cachedModule.exports;
92
+ /******/ }
93
+ /******/ // Create a new module (and put it into the cache)
94
+ /******/ var module = __webpack_module_cache__[moduleId] = {
95
+ /******/ // no module.id needed
96
+ /******/ // no module.loaded needed
97
+ /******/ exports: {}
98
+ /******/ };
99
+ /******/
100
+ /******/ // Execute the module function
101
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
102
+ /******/
103
+ /******/ // Return the exports of the module
104
+ /******/ return module.exports;
105
+ /******/ }
106
+ /******/
107
+ /************************************************************************/
108
+ /******/ /* webpack/runtime/compat get default export */
109
+ /******/ (() => {
110
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
111
+ /******/ __webpack_require__.n = (module) => {
112
+ /******/ var getter = module && module.__esModule ?
113
+ /******/ () => (module['default']) :
114
+ /******/ () => (module);
115
+ /******/ __webpack_require__.d(getter, { a: getter });
116
+ /******/ return getter;
117
+ /******/ };
118
+ /******/ })();
119
+ /******/
120
+ /******/ /* webpack/runtime/define property getters */
121
+ /******/ (() => {
122
+ /******/ // define getter functions for harmony exports
123
+ /******/ __webpack_require__.d = (exports, definition) => {
124
+ /******/ for(var key in definition) {
125
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
126
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
127
+ /******/ }
128
+ /******/ }
129
+ /******/ };
130
+ /******/ })();
131
+ /******/
132
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
133
+ /******/ (() => {
134
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
135
+ /******/ })();
136
+ /******/
137
+ /******/ /* webpack/runtime/make namespace object */
138
+ /******/ (() => {
139
+ /******/ // define __esModule on exports
140
+ /******/ __webpack_require__.r = (exports) => {
141
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
142
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
143
+ /******/ }
144
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
145
+ /******/ };
146
+ /******/ })();
147
+ /******/
148
+ /************************************************************************/
149
+ /******/
150
+ /******/ // startup
151
+ /******/ // Load entry module and return exports
152
+ /******/ // This entry module can't be inlined because the eval devtool is used.
153
+ /******/ var __webpack_exports__ = __webpack_require__("./dist/browser/index.js");
154
+ /******/
155
+ /******/ return __webpack_exports__;
156
+ /******/ })()
157
+ ;
158
+ });
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.plugin.oklchColor.min.js.LICENSE.txt */
2
+ !function(e,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],o);else{var r="object"==typeof exports?o(require("@tsparticles/engine")):o(e.window);for(var t in r)("object"==typeof exports?exports:e)[t]=r[t]}}(this,(e=>(()=>{var o={303:o=>{o.exports=e}},r={};function t(e){var a=r[e];if(void 0!==a)return a.exports;var n=r[e]={exports:{}};return o[e](n,n.exports,t),n.exports}t.d=(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},t.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};t.r(a),t.d(a,{loadOklchColorPlugin:()=>h});var n=t(303);const l=255,i=360;function s(e){const o=e.l/n.percentDenominator,r=e.c,t=e.h/i,a={r:0,g:0,b:0};return a.r=Math.floor(o*l),a.g=Math.floor(r*l),a.b=Math.floor(t*l),a}function c(e){const o=e.l/n.percentDenominator,r=e.c/n.percentDenominator,t=e.h/i,a={r:0,g:0,b:0};return a.r=Math.floor(o*l),a.g=Math.floor(r*l),a.b=Math.floor(t*l),a}class d{constructor(){this.key="color",this.stringPrefix="lch"}handleColor(e){const o=e.value.lch??e.value;if(void 0!==o.l&&void 0!==o.c&&void 0!==o.h)return s(o)}handleRangeColor(e){const o=e.value.lch??e.value;if(void 0!==o.l&&void 0!==o.c&&void 0!==o.h)return s({l:(0,n.getRangeValue)(o.l),c:(0,n.getRangeValue)(o.c),h:(0,n.getRangeValue)(o.h)})}parseString(e){if(!e.startsWith("lch"))return;const o=/lch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i.exec(e),r=1,t=3,a=5,l=7;return o?{a:(i={a:o[l]?(0,n.parseAlpha)(o[l]):1,c:parseFloat(o[t]),h:parseFloat(o[a]),l:parseFloat(o[r])}).a,...s(i)}:void 0;var i}}class u{constructor(){this.key="color",this.stringPrefix="oklch"}handleColor(e){const o=e.value.oklch??e.value;if(void 0!==o.l&&void 0!==o.c&&void 0!==o.h)return c(o)}handleRangeColor(e){const o=e.value.oklch??e.value;if(void 0!==o.l&&void 0!==o.c&&void 0!==o.h)return c({l:(0,n.getRangeValue)(o.l),c:(0,n.getRangeValue)(o.c),h:(0,n.getRangeValue)(o.h)})}parseString(e){if(!e.startsWith("oklch"))return;const o=/oklch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(°)?(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i.exec(e),r=1,t=3,a=5,l=7;return o?{a:(i={a:o[l]?(0,n.parseAlpha)(o[l]):1,c:parseFloat(o[t]),h:parseFloat(o[a]),l:parseFloat(o[r])}).a,...c(i)}:void 0;var i}}function h(){return(0,n.addColorManager)(new u),(0,n.addColorManager)(new d),Promise.resolve()}return a})()));
@@ -0,0 +1 @@
1
+ /*! tsParticles OKLCH Color Plugin v3.6.0 by Matteo Bruni */
@@ -0,0 +1,9 @@
1
+ import { type IColor, type IColorManager, type IRangeColor, type IRgb, type IRgba } from "@tsparticles/engine";
2
+ export declare class LchColorManager implements IColorManager {
3
+ readonly key: string;
4
+ readonly stringPrefix: string;
5
+ constructor();
6
+ handleColor(color: IColor): IRgb | undefined;
7
+ handleRangeColor(color: IRangeColor): IRgb | undefined;
8
+ parseString(input: string): IRgba | undefined;
9
+ }
@@ -0,0 +1,9 @@
1
+ import { type IColor, type IColorManager, type IRangeColor, type IRgb, type IRgba } from "@tsparticles/engine";
2
+ export declare class OklchColorManager implements IColorManager {
3
+ readonly key: string;
4
+ readonly stringPrefix: string;
5
+ constructor();
6
+ handleColor(color: IColor): IRgb | undefined;
7
+ handleRangeColor(color: IRangeColor): IRgb | undefined;
8
+ parseString(input: string): IRgba | undefined;
9
+ }
@@ -0,0 +1 @@
1
+ export declare function loadOklchColorPlugin(): Promise<void>;
@@ -0,0 +1,6 @@
1
+ import { type ILch, type ILcha, type IOklch, type IOklcha, type IRgb, type IRgba } from "@tsparticles/engine";
2
+ export declare function lchToRgb(lch: ILch): IRgb;
3
+ export declare function lchaToRgba(lcha: ILcha): IRgba;
4
+ export declare function oklchToRgb(oklch: IOklch): IRgb;
5
+ export declare function oklchaToRgba(oklcha: IOklcha): IRgba;
6
+ export declare function getStyleFromOklch(color: IOklch, opacity?: number): string;
@@ -0,0 +1,58 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine", "./utils.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LchColorManager = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const utils_js_1 = require("./utils.js");
15
+ class LchColorManager {
16
+ constructor() {
17
+ this.key = "color";
18
+ this.stringPrefix = "lch";
19
+ }
20
+ handleColor(color) {
21
+ const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
22
+ if (lchColor.l !== undefined && lchColor.c !== undefined && lchColor.h !== undefined) {
23
+ return (0, utils_js_1.lchToRgb)(lchColor);
24
+ }
25
+ }
26
+ handleRangeColor(color) {
27
+ const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
28
+ if (lchColor.l !== undefined && lchColor.c !== undefined && lchColor.h !== undefined) {
29
+ return (0, utils_js_1.lchToRgb)({
30
+ l: (0, engine_1.getRangeValue)(lchColor.l),
31
+ c: (0, engine_1.getRangeValue)(lchColor.c),
32
+ h: (0, engine_1.getRangeValue)(lchColor.h),
33
+ });
34
+ }
35
+ }
36
+ parseString(input) {
37
+ const isLch = input.startsWith("lch");
38
+ if (!isLch) {
39
+ return;
40
+ }
41
+ const regex = /lch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i, result = regex.exec(input), indexes = {
42
+ l: 1,
43
+ c: 3,
44
+ h: 5,
45
+ a: 7,
46
+ }, defaultAlpha = 1;
47
+ return result
48
+ ? (0, utils_js_1.lchaToRgba)({
49
+ a: result[indexes.a] ? (0, engine_1.parseAlpha)(result[indexes.a]) : defaultAlpha,
50
+ c: parseFloat(result[indexes.c]),
51
+ h: parseFloat(result[indexes.h]),
52
+ l: parseFloat(result[indexes.l]),
53
+ })
54
+ : undefined;
55
+ }
56
+ }
57
+ exports.LchColorManager = LchColorManager;
58
+ });
@@ -0,0 +1,58 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine", "./utils.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OklchColorManager = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const utils_js_1 = require("./utils.js");
15
+ class OklchColorManager {
16
+ constructor() {
17
+ this.key = "color";
18
+ this.stringPrefix = "oklch";
19
+ }
20
+ handleColor(color) {
21
+ const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
22
+ if (oklchColor.l !== undefined && oklchColor.c !== undefined && oklchColor.h !== undefined) {
23
+ return (0, utils_js_1.oklchToRgb)(oklchColor);
24
+ }
25
+ }
26
+ handleRangeColor(color) {
27
+ const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
28
+ if (oklchColor.l !== undefined && oklchColor.c !== undefined && oklchColor.h !== undefined) {
29
+ return (0, utils_js_1.oklchToRgb)({
30
+ l: (0, engine_1.getRangeValue)(oklchColor.l),
31
+ c: (0, engine_1.getRangeValue)(oklchColor.c),
32
+ h: (0, engine_1.getRangeValue)(oklchColor.h),
33
+ });
34
+ }
35
+ }
36
+ parseString(input) {
37
+ const isOklch = input.startsWith("oklch");
38
+ if (!isOklch) {
39
+ return;
40
+ }
41
+ const regex = /oklch\(\s*(\d+(\.\d+)?)%\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)(°)?(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i, result = regex.exec(input), indexes = {
42
+ l: 1,
43
+ c: 3,
44
+ h: 5,
45
+ a: 7,
46
+ }, defaultAlpha = 1;
47
+ return result
48
+ ? (0, utils_js_1.oklchaToRgba)({
49
+ a: result[indexes.a] ? (0, engine_1.parseAlpha)(result[indexes.a]) : defaultAlpha,
50
+ c: parseFloat(result[indexes.c]),
51
+ h: parseFloat(result[indexes.h]),
52
+ l: parseFloat(result[indexes.l]),
53
+ })
54
+ : undefined;
55
+ }
56
+ }
57
+ exports.OklchColorManager = OklchColorManager;
58
+ });
package/umd/index.js ADDED
@@ -0,0 +1,21 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./LchColorManager.js", "./OklchColorManager.js", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.loadOklchColorPlugin = loadOklchColorPlugin;
13
+ const LchColorManager_js_1 = require("./LchColorManager.js");
14
+ const OklchColorManager_js_1 = require("./OklchColorManager.js");
15
+ const engine_1 = require("@tsparticles/engine");
16
+ function loadOklchColorPlugin() {
17
+ (0, engine_1.addColorManager)(new OklchColorManager_js_1.OklchColorManager());
18
+ (0, engine_1.addColorManager)(new LchColorManager_js_1.LchColorManager());
19
+ return Promise.resolve();
20
+ }
21
+ });
package/umd/utils.js ADDED
@@ -0,0 +1,49 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.lchToRgb = lchToRgb;
13
+ exports.lchaToRgba = lchaToRgba;
14
+ exports.oklchToRgb = oklchToRgb;
15
+ exports.oklchaToRgba = oklchaToRgba;
16
+ exports.getStyleFromOklch = getStyleFromOklch;
17
+ const engine_1 = require("@tsparticles/engine");
18
+ const rgbFactor = 255, fullDegree = 360;
19
+ function lchToRgb(lch) {
20
+ const l = lch.l / engine_1.percentDenominator, c = lch.c, h = lch.h / fullDegree, result = { r: 0, g: 0, b: 0 };
21
+ result.r = Math.floor(l * rgbFactor);
22
+ result.g = Math.floor(c * rgbFactor);
23
+ result.b = Math.floor(h * rgbFactor);
24
+ return result;
25
+ }
26
+ function lchaToRgba(lcha) {
27
+ return {
28
+ a: lcha.a,
29
+ ...lchToRgb(lcha),
30
+ };
31
+ }
32
+ function oklchToRgb(oklch) {
33
+ const l = oklch.l / engine_1.percentDenominator, c = oklch.c / engine_1.percentDenominator, h = oklch.h / fullDegree, result = { r: 0, g: 0, b: 0 };
34
+ result.r = Math.floor(l * rgbFactor);
35
+ result.g = Math.floor(c * rgbFactor);
36
+ result.b = Math.floor(h * rgbFactor);
37
+ return result;
38
+ }
39
+ function oklchaToRgba(oklcha) {
40
+ return {
41
+ a: oklcha.a,
42
+ ...oklchToRgb(oklcha),
43
+ };
44
+ }
45
+ function getStyleFromOklch(color, opacity) {
46
+ const { l, c, h } = color, alpha = opacity !== undefined ? `, ${opacity}` : "";
47
+ return `oklch(${l}%, ${c}%, ${h}°${alpha})`;
48
+ }
49
+ });