@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.
- package/LICENSE +21 -0
- package/README.md +74 -0
- package/browser/LchColorManager.js +44 -0
- package/browser/OklchColorManager.js +44 -0
- package/browser/index.js +8 -0
- package/browser/package.json +1 -0
- package/browser/utils.js +32 -0
- package/cjs/LchColorManager.js +48 -0
- package/cjs/OklchColorManager.js +48 -0
- package/cjs/index.js +11 -0
- package/cjs/package.json +1 -0
- package/cjs/utils.js +39 -0
- package/esm/LchColorManager.js +44 -0
- package/esm/OklchColorManager.js +44 -0
- package/esm/index.js +8 -0
- package/esm/package.json +1 -0
- package/esm/utils.js +32 -0
- package/package.json +108 -0
- package/report.html +39 -0
- package/tsparticles.plugin.oklchColor.js +158 -0
- package/tsparticles.plugin.oklchColor.min.js +2 -0
- package/tsparticles.plugin.oklchColor.min.js.LICENSE.txt +1 -0
- package/types/LchColorManager.d.ts +9 -0
- package/types/OklchColorManager.d.ts +9 -0
- package/types/index.d.ts +1 -0
- package/types/utils.d.ts +6 -0
- package/umd/LchColorManager.js +58 -0
- package/umd/OklchColorManager.js +58 -0
- package/umd/index.js +21 -0
- package/umd/utils.js +49 -0
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
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles OKLCH Color Plugin
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-oklch-color)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/plugin-oklch-color)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/plugin-oklch-color) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/tsparticles/tsparticles) plugin for adding the OKLCH 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.oklchColor.min.js` file will export the function to load the plugin:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
loadOklchColorPlugin
|
|
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 loadOklchColorPlugin();
|
|
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-oklch-color
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add @tsparticles/plugin-oklch-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 { loadOklchColorPlugin } = require("@tsparticles/plugin-oklch-color");
|
|
59
|
+
|
|
60
|
+
(async () => {
|
|
61
|
+
await loadOklchColorPlugin();
|
|
62
|
+
})();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
or
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
69
|
+
import { loadOklchColorPlugin } from "@tsparticles/plugin-oklch-color";
|
|
70
|
+
|
|
71
|
+
(async () => {
|
|
72
|
+
await loadOklchColorPlugin();
|
|
73
|
+
})();
|
|
74
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
|
|
2
|
+
import { lchToRgb, lchaToRgba } from "./utils.js";
|
|
3
|
+
export class LchColorManager {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.key = "color";
|
|
6
|
+
this.stringPrefix = "lch";
|
|
7
|
+
}
|
|
8
|
+
handleColor(color) {
|
|
9
|
+
const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
|
|
10
|
+
if (lchColor.l !== undefined && lchColor.c !== undefined && lchColor.h !== undefined) {
|
|
11
|
+
return lchToRgb(lchColor);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
handleRangeColor(color) {
|
|
15
|
+
const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
|
|
16
|
+
if (lchColor.l !== undefined && lchColor.c !== undefined && lchColor.h !== undefined) {
|
|
17
|
+
return lchToRgb({
|
|
18
|
+
l: getRangeValue(lchColor.l),
|
|
19
|
+
c: getRangeValue(lchColor.c),
|
|
20
|
+
h: getRangeValue(lchColor.h),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
parseString(input) {
|
|
25
|
+
const isLch = input.startsWith("lch");
|
|
26
|
+
if (!isLch) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
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 = {
|
|
30
|
+
l: 1,
|
|
31
|
+
c: 3,
|
|
32
|
+
h: 5,
|
|
33
|
+
a: 7,
|
|
34
|
+
}, defaultAlpha = 1;
|
|
35
|
+
return result
|
|
36
|
+
? lchaToRgba({
|
|
37
|
+
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]),
|
|
41
|
+
})
|
|
42
|
+
: undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
|
|
2
|
+
import { oklchToRgb, oklchaToRgba } from "./utils.js";
|
|
3
|
+
export class OklchColorManager {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.key = "color";
|
|
6
|
+
this.stringPrefix = "oklch";
|
|
7
|
+
}
|
|
8
|
+
handleColor(color) {
|
|
9
|
+
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
10
|
+
if (oklchColor.l !== undefined && oklchColor.c !== undefined && oklchColor.h !== undefined) {
|
|
11
|
+
return oklchToRgb(oklchColor);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
handleRangeColor(color) {
|
|
15
|
+
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
16
|
+
if (oklchColor.l !== undefined && oklchColor.c !== undefined && oklchColor.h !== undefined) {
|
|
17
|
+
return oklchToRgb({
|
|
18
|
+
l: getRangeValue(oklchColor.l),
|
|
19
|
+
c: getRangeValue(oklchColor.c),
|
|
20
|
+
h: getRangeValue(oklchColor.h),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
parseString(input) {
|
|
25
|
+
const isOklch = input.startsWith("oklch");
|
|
26
|
+
if (!isOklch) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
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 = {
|
|
30
|
+
l: 1,
|
|
31
|
+
c: 3,
|
|
32
|
+
h: 5,
|
|
33
|
+
a: 7,
|
|
34
|
+
}, defaultAlpha = 1;
|
|
35
|
+
return result
|
|
36
|
+
? oklchaToRgba({
|
|
37
|
+
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]),
|
|
41
|
+
})
|
|
42
|
+
: undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LchColorManager } from "./LchColorManager.js";
|
|
2
|
+
import { OklchColorManager } from "./OklchColorManager.js";
|
|
3
|
+
import { addColorManager } from "@tsparticles/engine";
|
|
4
|
+
export function loadOklchColorPlugin() {
|
|
5
|
+
addColorManager(new OklchColorManager());
|
|
6
|
+
addColorManager(new LchColorManager());
|
|
7
|
+
return Promise.resolve();
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/browser/utils.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { percentDenominator, } from "@tsparticles/engine";
|
|
2
|
+
const rgbFactor = 255, fullDegree = 360;
|
|
3
|
+
export function lchToRgb(lch) {
|
|
4
|
+
const l = lch.l / percentDenominator, c = lch.c, h = lch.h / fullDegree, result = { r: 0, g: 0, b: 0 };
|
|
5
|
+
result.r = Math.floor(l * rgbFactor);
|
|
6
|
+
result.g = Math.floor(c * rgbFactor);
|
|
7
|
+
result.b = Math.floor(h * rgbFactor);
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
export function lchaToRgba(lcha) {
|
|
11
|
+
return {
|
|
12
|
+
a: lcha.a,
|
|
13
|
+
...lchToRgb(lcha),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
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
|
+
export function oklchaToRgba(oklcha) {
|
|
24
|
+
return {
|
|
25
|
+
a: oklcha.a,
|
|
26
|
+
...oklchToRgb(oklcha),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function getStyleFromOklch(color, opacity) {
|
|
30
|
+
const { l, c, h } = color, alpha = opacity !== undefined ? `, ${opacity}` : "";
|
|
31
|
+
return `oklch(${l}%, ${c}%, ${h}°${alpha})`;
|
|
32
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LchColorManager = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
class LchColorManager {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.key = "color";
|
|
9
|
+
this.stringPrefix = "lch";
|
|
10
|
+
}
|
|
11
|
+
handleColor(color) {
|
|
12
|
+
const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
|
|
13
|
+
if (lchColor.l !== undefined && lchColor.c !== undefined && lchColor.h !== undefined) {
|
|
14
|
+
return (0, utils_js_1.lchToRgb)(lchColor);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
handleRangeColor(color) {
|
|
18
|
+
const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
|
|
19
|
+
if (lchColor.l !== undefined && lchColor.c !== undefined && lchColor.h !== undefined) {
|
|
20
|
+
return (0, utils_js_1.lchToRgb)({
|
|
21
|
+
l: (0, engine_1.getRangeValue)(lchColor.l),
|
|
22
|
+
c: (0, engine_1.getRangeValue)(lchColor.c),
|
|
23
|
+
h: (0, engine_1.getRangeValue)(lchColor.h),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
parseString(input) {
|
|
28
|
+
const isLch = input.startsWith("lch");
|
|
29
|
+
if (!isLch) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
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 = {
|
|
33
|
+
l: 1,
|
|
34
|
+
c: 3,
|
|
35
|
+
h: 5,
|
|
36
|
+
a: 7,
|
|
37
|
+
}, defaultAlpha = 1;
|
|
38
|
+
return result
|
|
39
|
+
? (0, utils_js_1.lchaToRgba)({
|
|
40
|
+
a: result[indexes.a] ? (0, engine_1.parseAlpha)(result[indexes.a]) : defaultAlpha,
|
|
41
|
+
c: parseFloat(result[indexes.c]),
|
|
42
|
+
h: parseFloat(result[indexes.h]),
|
|
43
|
+
l: parseFloat(result[indexes.l]),
|
|
44
|
+
})
|
|
45
|
+
: undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.LchColorManager = LchColorManager;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OklchColorManager = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
class OklchColorManager {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.key = "color";
|
|
9
|
+
this.stringPrefix = "oklch";
|
|
10
|
+
}
|
|
11
|
+
handleColor(color) {
|
|
12
|
+
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
13
|
+
if (oklchColor.l !== undefined && oklchColor.c !== undefined && oklchColor.h !== undefined) {
|
|
14
|
+
return (0, utils_js_1.oklchToRgb)(oklchColor);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
handleRangeColor(color) {
|
|
18
|
+
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
19
|
+
if (oklchColor.l !== undefined && oklchColor.c !== undefined && oklchColor.h !== undefined) {
|
|
20
|
+
return (0, utils_js_1.oklchToRgb)({
|
|
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
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
parseString(input) {
|
|
28
|
+
const isOklch = input.startsWith("oklch");
|
|
29
|
+
if (!isOklch) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
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 = {
|
|
33
|
+
l: 1,
|
|
34
|
+
c: 3,
|
|
35
|
+
h: 5,
|
|
36
|
+
a: 7,
|
|
37
|
+
}, defaultAlpha = 1;
|
|
38
|
+
return result
|
|
39
|
+
? (0, utils_js_1.oklchaToRgba)({
|
|
40
|
+
a: result[indexes.a] ? (0, engine_1.parseAlpha)(result[indexes.a]) : defaultAlpha,
|
|
41
|
+
c: parseFloat(result[indexes.c]),
|
|
42
|
+
h: parseFloat(result[indexes.h]),
|
|
43
|
+
l: parseFloat(result[indexes.l]),
|
|
44
|
+
})
|
|
45
|
+
: undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.OklchColorManager = OklchColorManager;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadOklchColorPlugin = loadOklchColorPlugin;
|
|
4
|
+
const LchColorManager_js_1 = require("./LchColorManager.js");
|
|
5
|
+
const OklchColorManager_js_1 = require("./OklchColorManager.js");
|
|
6
|
+
const engine_1 = require("@tsparticles/engine");
|
|
7
|
+
function loadOklchColorPlugin() {
|
|
8
|
+
(0, engine_1.addColorManager)(new OklchColorManager_js_1.OklchColorManager());
|
|
9
|
+
(0, engine_1.addColorManager)(new LchColorManager_js_1.LchColorManager());
|
|
10
|
+
return Promise.resolve();
|
|
11
|
+
}
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
package/cjs/utils.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lchToRgb = lchToRgb;
|
|
4
|
+
exports.lchaToRgba = lchaToRgba;
|
|
5
|
+
exports.oklchToRgb = oklchToRgb;
|
|
6
|
+
exports.oklchaToRgba = oklchaToRgba;
|
|
7
|
+
exports.getStyleFromOklch = getStyleFromOklch;
|
|
8
|
+
const engine_1 = require("@tsparticles/engine");
|
|
9
|
+
const rgbFactor = 255, fullDegree = 360;
|
|
10
|
+
function lchToRgb(lch) {
|
|
11
|
+
const l = lch.l / engine_1.percentDenominator, c = lch.c, h = lch.h / fullDegree, result = { r: 0, g: 0, b: 0 };
|
|
12
|
+
result.r = Math.floor(l * rgbFactor);
|
|
13
|
+
result.g = Math.floor(c * rgbFactor);
|
|
14
|
+
result.b = Math.floor(h * rgbFactor);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
function lchaToRgba(lcha) {
|
|
18
|
+
return {
|
|
19
|
+
a: lcha.a,
|
|
20
|
+
...lchToRgb(lcha),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function oklchToRgb(oklch) {
|
|
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) {
|
|
31
|
+
return {
|
|
32
|
+
a: oklcha.a,
|
|
33
|
+
...oklchToRgb(oklcha),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function getStyleFromOklch(color, opacity) {
|
|
37
|
+
const { l, c, h } = color, alpha = opacity !== undefined ? `, ${opacity}` : "";
|
|
38
|
+
return `oklch(${l}%, ${c}%, ${h}°${alpha})`;
|
|
39
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
|
|
2
|
+
import { lchToRgb, lchaToRgba } from "./utils.js";
|
|
3
|
+
export class LchColorManager {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.key = "color";
|
|
6
|
+
this.stringPrefix = "lch";
|
|
7
|
+
}
|
|
8
|
+
handleColor(color) {
|
|
9
|
+
const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
|
|
10
|
+
if (lchColor.l !== undefined && lchColor.c !== undefined && lchColor.h !== undefined) {
|
|
11
|
+
return lchToRgb(lchColor);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
handleRangeColor(color) {
|
|
15
|
+
const colorValue = color.value, lchColor = colorValue.lch ?? color.value;
|
|
16
|
+
if (lchColor.l !== undefined && lchColor.c !== undefined && lchColor.h !== undefined) {
|
|
17
|
+
return lchToRgb({
|
|
18
|
+
l: getRangeValue(lchColor.l),
|
|
19
|
+
c: getRangeValue(lchColor.c),
|
|
20
|
+
h: getRangeValue(lchColor.h),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
parseString(input) {
|
|
25
|
+
const isLch = input.startsWith("lch");
|
|
26
|
+
if (!isLch) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
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 = {
|
|
30
|
+
l: 1,
|
|
31
|
+
c: 3,
|
|
32
|
+
h: 5,
|
|
33
|
+
a: 7,
|
|
34
|
+
}, defaultAlpha = 1;
|
|
35
|
+
return result
|
|
36
|
+
? lchaToRgba({
|
|
37
|
+
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]),
|
|
41
|
+
})
|
|
42
|
+
: undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
|
|
2
|
+
import { oklchToRgb, oklchaToRgba } from "./utils.js";
|
|
3
|
+
export class OklchColorManager {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.key = "color";
|
|
6
|
+
this.stringPrefix = "oklch";
|
|
7
|
+
}
|
|
8
|
+
handleColor(color) {
|
|
9
|
+
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
10
|
+
if (oklchColor.l !== undefined && oklchColor.c !== undefined && oklchColor.h !== undefined) {
|
|
11
|
+
return oklchToRgb(oklchColor);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
handleRangeColor(color) {
|
|
15
|
+
const colorValue = color.value, oklchColor = colorValue.oklch ?? color.value;
|
|
16
|
+
if (oklchColor.l !== undefined && oklchColor.c !== undefined && oklchColor.h !== undefined) {
|
|
17
|
+
return oklchToRgb({
|
|
18
|
+
l: getRangeValue(oklchColor.l),
|
|
19
|
+
c: getRangeValue(oklchColor.c),
|
|
20
|
+
h: getRangeValue(oklchColor.h),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
parseString(input) {
|
|
25
|
+
const isOklch = input.startsWith("oklch");
|
|
26
|
+
if (!isOklch) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
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 = {
|
|
30
|
+
l: 1,
|
|
31
|
+
c: 3,
|
|
32
|
+
h: 5,
|
|
33
|
+
a: 7,
|
|
34
|
+
}, defaultAlpha = 1;
|
|
35
|
+
return result
|
|
36
|
+
? oklchaToRgba({
|
|
37
|
+
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]),
|
|
41
|
+
})
|
|
42
|
+
: undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LchColorManager } from "./LchColorManager.js";
|
|
2
|
+
import { OklchColorManager } from "./OklchColorManager.js";
|
|
3
|
+
import { addColorManager } from "@tsparticles/engine";
|
|
4
|
+
export function loadOklchColorPlugin() {
|
|
5
|
+
addColorManager(new OklchColorManager());
|
|
6
|
+
addColorManager(new LchColorManager());
|
|
7
|
+
return Promise.resolve();
|
|
8
|
+
}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/esm/utils.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { percentDenominator, } from "@tsparticles/engine";
|
|
2
|
+
const rgbFactor = 255, fullDegree = 360;
|
|
3
|
+
export function lchToRgb(lch) {
|
|
4
|
+
const l = lch.l / percentDenominator, c = lch.c, h = lch.h / fullDegree, result = { r: 0, g: 0, b: 0 };
|
|
5
|
+
result.r = Math.floor(l * rgbFactor);
|
|
6
|
+
result.g = Math.floor(c * rgbFactor);
|
|
7
|
+
result.b = Math.floor(h * rgbFactor);
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
export function lchaToRgba(lcha) {
|
|
11
|
+
return {
|
|
12
|
+
a: lcha.a,
|
|
13
|
+
...lchToRgb(lcha),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
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
|
+
export function oklchaToRgba(oklcha) {
|
|
24
|
+
return {
|
|
25
|
+
a: oklcha.a,
|
|
26
|
+
...oklchToRgb(oklcha),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function getStyleFromOklch(color, opacity) {
|
|
30
|
+
const { l, c, h } = color, alpha = opacity !== undefined ? `, ${opacity}` : "";
|
|
31
|
+
return `oklch(${l}%, ${c}%, ${h}°${alpha})`;
|
|
32
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsparticles/plugin-oklch-color",
|
|
3
|
+
"version": "3.6.0",
|
|
4
|
+
"description": "tsParticles OKLCH 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/oklchColor"
|
|
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.oklchColor.min.js",
|
|
86
|
+
"unpkg": "tsparticles.plugin.oklchColor.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": "^3.6.0"
|
|
104
|
+
},
|
|
105
|
+
"publishConfig": {
|
|
106
|
+
"access": "public"
|
|
107
|
+
}
|
|
108
|
+
}
|