@tsparticles/plugin-oklab-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/273.min.js +2 -0
- package/273.min.js.LICENSE.txt +1 -0
- package/LICENSE +21 -0
- package/README.md +74 -0
- package/browser/OklabColorManager.js +52 -0
- package/browser/index.js +7 -0
- package/browser/package.json +1 -0
- package/browser/utils.js +36 -0
- package/cjs/OklabColorManager.js +52 -0
- package/cjs/index.js +7 -0
- package/cjs/package.json +1 -0
- package/cjs/utils.js +36 -0
- package/dist_browser_OklabColorManager_js.js +40 -0
- package/esm/OklabColorManager.js +52 -0
- package/esm/index.js +7 -0
- package/esm/package.json +1 -0
- package/esm/utils.js +36 -0
- package/package.json +109 -0
- package/report.html +40 -0
- package/tsparticles.plugin.oklabColor.js +317 -0
- package/tsparticles.plugin.oklabColor.min.js +2 -0
- package/tsparticles.plugin.oklabColor.min.js.LICENSE.txt +1 -0
- package/types/OklabColorManager.d.ts +9 -0
- package/types/index.d.ts +2 -0
- package/types/utils.d.ts +4 -0
- package/umd/OklabColorManager.js +66 -0
- package/umd/index.js +54 -0
- package/umd/utils.js +51 -0
package/273.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 273.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_plugin_oklab_color=this.webpackChunk_tsparticles_plugin_oklab_color||[]).push([[273],{273(a,s,e){e.d(s,{OklabColorManager:()=>k});var t=e(303);const l={L:1,a:.3963377774,b:.2158037573},r={L:1,a:-.1055613458,b:-.0638541728},n={L:1,a:-.0894841775,b:-1.291485548},o={l:4.0767416621,m:-3.3077115913,s:.2309699292},b={l:-1.2684380046,m:2.6097574011,s:-.3413193965},c={l:-.0041960863,m:-.7034186147,s:1.707614701},i=2.4,u=.0031308,h=12.92,p=.055,x=1.055;function d(a){const s=a.l/t.percentDenominator,e=a.aAxis,d=a.bAxis,g=(l.L*s+l.a*e+l.b*d)**3,k=(r.L*s+r.a*e+r.b*d)**3,A=(n.L*s+n.a*e+n.b*d)**3,O=o.l*g+o.m*k+o.s*A,m=b.l*g+b.m*k+b.s*A,v=c.l*g+c.m*k+c.s*A,w=a=>{return Math.round((0,t.clamp)((s=a)<=u?h*s:x*Math.pow(s,t.inverseFactorNumerator/i)-p,0,1)*t.rgbMax);var s};return{r:w(O),g:w(m),b:w(v)}}const g=/oklab\(\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="oklab"}accepts(a){return a.startsWith("oklab")}handleColor(a){const s=a.value.oklab??a.value;if(Object.hasOwn(s,"l")&&Object.hasOwn(s,"aAxis")&&Object.hasOwn(s,"bAxis"))return d(s)}handleRangeColor(a){const s=a.value.oklab??a.value;if(Object.hasOwn(s,"l")&&Object.hasOwn(s,"aAxis")&&Object.hasOwn(s,"bAxis"))return d({l:(0,t.getRangeValue)(s.l),aAxis:(0,t.getRangeValue)(s.aAxis),bAxis:(0,t.getRangeValue)(s.bAxis)})}parseString(a){if(!this.accepts(a))return;const s=g.exec(a),e=1,l=3,r=5,n=7;return s?{a:(o={a:s[n]?(0,t.parseAlpha)(s[n]):1,l:parseFloat(s[e]??"0"),aAxis:parseFloat(s[l]??"0"),bAxis:parseFloat(s[r]??"0")}).a,...d(o)}:void 0;var o}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles OKLAB 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
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles OKLAB Color Plugin
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-oklab-color)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/plugin-oklab-color)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/plugin-oklab-color) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/tsparticles/tsparticles) plugin for adding the OKLAB 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.oklabColor.min.js` file will export the function to load the plugin:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
loadOklabColorPlugin
|
|
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 loadOklabColorPlugin();
|
|
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-oklab-color
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add @tsparticles/plugin-oklab-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 { loadOklabColorPlugin } = require("@tsparticles/plugin-oklab-color");
|
|
59
|
+
|
|
60
|
+
(async () => {
|
|
61
|
+
await loadOklabColorPlugin();
|
|
62
|
+
})();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
or
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
69
|
+
import { loadOklabColorPlugin } from "@tsparticles/plugin-oklab-color";
|
|
70
|
+
|
|
71
|
+
(async () => {
|
|
72
|
+
await loadOklabColorPlugin();
|
|
73
|
+
})();
|
|
74
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
|
|
2
|
+
import { oklabToRgb, oklabaToRgba } from "./utils.js";
|
|
3
|
+
const oklabRegex = /oklab\(\s*(\d+(\.\d+)?)%\s+(-?\d+(\.\d+)?)\s+(-?\d+(\.\d+)?)(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;
|
|
4
|
+
export class OklabColorManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.key = "oklab";
|
|
7
|
+
}
|
|
8
|
+
accepts(input) {
|
|
9
|
+
return input.startsWith("oklab");
|
|
10
|
+
}
|
|
11
|
+
handleColor(color) {
|
|
12
|
+
const colorValue = color.value, oklabColor = colorValue.oklab ?? color.value;
|
|
13
|
+
if (!Object.hasOwn(oklabColor, "l") ||
|
|
14
|
+
!Object.hasOwn(oklabColor, "aAxis") ||
|
|
15
|
+
!Object.hasOwn(oklabColor, "bAxis")) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
return oklabToRgb(oklabColor);
|
|
19
|
+
}
|
|
20
|
+
handleRangeColor(color) {
|
|
21
|
+
const colorValue = color.value, oklabColor = colorValue.oklab ?? color.value;
|
|
22
|
+
if (!Object.hasOwn(oklabColor, "l") ||
|
|
23
|
+
!Object.hasOwn(oklabColor, "aAxis") ||
|
|
24
|
+
!Object.hasOwn(oklabColor, "bAxis")) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
return oklabToRgb({
|
|
28
|
+
l: getRangeValue(oklabColor.l),
|
|
29
|
+
aAxis: getRangeValue(oklabColor.aAxis),
|
|
30
|
+
bAxis: getRangeValue(oklabColor.bAxis),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
parseString(input) {
|
|
34
|
+
if (!this.accepts(input)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const result = oklabRegex.exec(input), indexes = {
|
|
38
|
+
l: 1,
|
|
39
|
+
aAxis: 3,
|
|
40
|
+
bAxis: 5,
|
|
41
|
+
a: 7,
|
|
42
|
+
}, defaultAlpha = 1;
|
|
43
|
+
return result
|
|
44
|
+
? oklabaToRgba({
|
|
45
|
+
a: result[indexes.a] ? parseAlpha(result[indexes.a]) : defaultAlpha,
|
|
46
|
+
l: parseFloat(result[indexes.l] ?? "0"),
|
|
47
|
+
aAxis: parseFloat(result[indexes.aAxis] ?? "0"),
|
|
48
|
+
bAxis: parseFloat(result[indexes.bAxis] ?? "0"),
|
|
49
|
+
})
|
|
50
|
+
: undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/browser/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/browser/utils.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { clamp, 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
|
+
OFFSET: 0.055,
|
|
15
|
+
SCALE: 1.055,
|
|
16
|
+
}, minSrgbValue = 0, maxSrgbValue = 1;
|
|
17
|
+
export function oklabToRgb(oklab) {
|
|
18
|
+
const L = oklab.l / percentDenominator, a = oklab.aAxis, b = oklab.bAxis, 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);
|
|
21
|
+
return {
|
|
22
|
+
r: toSrgbFixed(rLinear),
|
|
23
|
+
g: toSrgbFixed(gLinear),
|
|
24
|
+
b: toSrgbFixed(bLinear),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function oklabaToRgba(oklaba) {
|
|
28
|
+
return {
|
|
29
|
+
a: oklaba.a,
|
|
30
|
+
...oklabToRgb(oklaba),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function getStyleFromOklab(color, opacity) {
|
|
34
|
+
const { l, aAxis, bAxis } = color, alpha = opacity !== undefined ? ` / ${opacity.toString()}` : "";
|
|
35
|
+
return `oklab(${l.toString()}% ${aAxis.toString()} ${bAxis.toString()}${alpha})`;
|
|
36
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
|
|
2
|
+
import { oklabToRgb, oklabaToRgba } from "./utils.js";
|
|
3
|
+
const oklabRegex = /oklab\(\s*(\d+(\.\d+)?)%\s+(-?\d+(\.\d+)?)\s+(-?\d+(\.\d+)?)(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;
|
|
4
|
+
export class OklabColorManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.key = "oklab";
|
|
7
|
+
}
|
|
8
|
+
accepts(input) {
|
|
9
|
+
return input.startsWith("oklab");
|
|
10
|
+
}
|
|
11
|
+
handleColor(color) {
|
|
12
|
+
const colorValue = color.value, oklabColor = colorValue.oklab ?? color.value;
|
|
13
|
+
if (!Object.hasOwn(oklabColor, "l") ||
|
|
14
|
+
!Object.hasOwn(oklabColor, "aAxis") ||
|
|
15
|
+
!Object.hasOwn(oklabColor, "bAxis")) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
return oklabToRgb(oklabColor);
|
|
19
|
+
}
|
|
20
|
+
handleRangeColor(color) {
|
|
21
|
+
const colorValue = color.value, oklabColor = colorValue.oklab ?? color.value;
|
|
22
|
+
if (!Object.hasOwn(oklabColor, "l") ||
|
|
23
|
+
!Object.hasOwn(oklabColor, "aAxis") ||
|
|
24
|
+
!Object.hasOwn(oklabColor, "bAxis")) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
return oklabToRgb({
|
|
28
|
+
l: getRangeValue(oklabColor.l),
|
|
29
|
+
aAxis: getRangeValue(oklabColor.aAxis),
|
|
30
|
+
bAxis: getRangeValue(oklabColor.bAxis),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
parseString(input) {
|
|
34
|
+
if (!this.accepts(input)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const result = oklabRegex.exec(input), indexes = {
|
|
38
|
+
l: 1,
|
|
39
|
+
aAxis: 3,
|
|
40
|
+
bAxis: 5,
|
|
41
|
+
a: 7,
|
|
42
|
+
}, defaultAlpha = 1;
|
|
43
|
+
return result
|
|
44
|
+
? oklabaToRgba({
|
|
45
|
+
a: result[indexes.a] ? parseAlpha(result[indexes.a]) : defaultAlpha,
|
|
46
|
+
l: parseFloat(result[indexes.l] ?? "0"),
|
|
47
|
+
aAxis: parseFloat(result[indexes.aAxis] ?? "0"),
|
|
48
|
+
bAxis: parseFloat(result[indexes.bAxis] ?? "0"),
|
|
49
|
+
})
|
|
50
|
+
: undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/cjs/index.js
ADDED
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
package/cjs/utils.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { clamp, 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
|
+
OFFSET: 0.055,
|
|
15
|
+
SCALE: 1.055,
|
|
16
|
+
}, minSrgbValue = 0, maxSrgbValue = 1;
|
|
17
|
+
export function oklabToRgb(oklab) {
|
|
18
|
+
const L = oklab.l / percentDenominator, a = oklab.aAxis, b = oklab.bAxis, 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);
|
|
21
|
+
return {
|
|
22
|
+
r: toSrgbFixed(rLinear),
|
|
23
|
+
g: toSrgbFixed(gLinear),
|
|
24
|
+
b: toSrgbFixed(bLinear),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function oklabaToRgba(oklaba) {
|
|
28
|
+
return {
|
|
29
|
+
a: oklaba.a,
|
|
30
|
+
...oklabToRgb(oklaba),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function getStyleFromOklab(color, opacity) {
|
|
34
|
+
const { l, aAxis, bAxis } = color, alpha = opacity !== undefined ? ` / ${opacity.toString()}` : "";
|
|
35
|
+
return `oklab(${l.toString()}% ${aAxis.toString()} ${bAxis.toString()}${alpha})`;
|
|
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.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_oklab_color"] = this["webpackChunk_tsparticles_plugin_oklab_color"] || []).push([["dist_browser_OklabColorManager_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/OklabColorManager.js"
|
|
21
|
+
/*!*******************************************!*\
|
|
22
|
+
!*** ./dist/browser/OklabColorManager.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 */ OklabColorManager: () => (/* binding */ OklabColorManager)\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 oklabRegex = /oklab\\(\\s*(\\d+(\\.\\d+)?)%\\s+(-?\\d+(\\.\\d+)?)\\s+(-?\\d+(\\.\\d+)?)(?:\\s*\\/\\s*(0|1|0?\\.\\d+|\\d{1,3}%))?\\s*\\)/i;\nclass OklabColorManager {\n constructor() {\n this.key = \"oklab\";\n }\n accepts(input) {\n return input.startsWith(\"oklab\");\n }\n handleColor(color) {\n const colorValue = color.value,\n oklabColor = colorValue.oklab ?? color.value;\n if (!Object.hasOwn(oklabColor, \"l\") || !Object.hasOwn(oklabColor, \"aAxis\") || !Object.hasOwn(oklabColor, \"bAxis\")) {\n return;\n }\n return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.oklabToRgb)(oklabColor);\n }\n handleRangeColor(color) {\n const colorValue = color.value,\n oklabColor = colorValue.oklab ?? color.value;\n if (!Object.hasOwn(oklabColor, \"l\") || !Object.hasOwn(oklabColor, \"aAxis\") || !Object.hasOwn(oklabColor, \"bAxis\")) {\n return;\n }\n return (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.oklabToRgb)({\n l: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(oklabColor.l),\n aAxis: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(oklabColor.aAxis),\n bAxis: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(oklabColor.bAxis)\n });\n }\n parseString(input) {\n if (!this.accepts(input)) {\n return;\n }\n const result = oklabRegex.exec(input),\n indexes = {\n l: 1,\n aAxis: 3,\n bAxis: 5,\n a: 7\n },\n defaultAlpha = 1;\n return result ? (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.oklabaToRgba)({\n a: result[indexes.a] ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.parseAlpha)(result[indexes.a]) : defaultAlpha,\n l: parseFloat(result[indexes.l] ?? \"0\"),\n aAxis: parseFloat(result[indexes.aAxis] ?? \"0\"),\n bAxis: parseFloat(result[indexes.bAxis] ?? \"0\")\n }) : undefined;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-oklab-color/./dist/browser/OklabColorManager.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 */ getStyleFromOklab: () => (/* binding */ getStyleFromOklab),\n/* harmony export */ oklabToRgb: () => (/* binding */ oklabToRgb),\n/* harmony export */ oklabaToRgba: () => (/* binding */ oklabaToRgba)\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 OFFSET: 0.055,\n SCALE: 1.055\n },\n minSrgbValue = 0,\n maxSrgbValue = 1;\nfunction oklabToRgb(oklab) {\n const L = oklab.l / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.percentDenominator,\n a = oklab.aAxis,\n b = oklab.bAxis,\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 oklabaToRgba(oklaba) {\n return {\n a: oklaba.a,\n ...oklabToRgb(oklaba)\n };\n}\nfunction getStyleFromOklab(color, opacity) {\n const {\n l,\n aAxis,\n bAxis\n } = color,\n alpha = opacity !== undefined ? ` / ${opacity.toString()}` : \"\";\n return `oklab(${l.toString()}% ${aAxis.toString()} ${bAxis.toString()}${alpha})`;\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-oklab-color/./dist/browser/utils.js?\n}");
|
|
37
|
+
|
|
38
|
+
/***/ }
|
|
39
|
+
|
|
40
|
+
}]);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getRangeValue, parseAlpha, } from "@tsparticles/engine";
|
|
2
|
+
import { oklabToRgb, oklabaToRgba } from "./utils.js";
|
|
3
|
+
const oklabRegex = /oklab\(\s*(\d+(\.\d+)?)%\s+(-?\d+(\.\d+)?)\s+(-?\d+(\.\d+)?)(?:\s*\/\s*(0|1|0?\.\d+|\d{1,3}%))?\s*\)/i;
|
|
4
|
+
export class OklabColorManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.key = "oklab";
|
|
7
|
+
}
|
|
8
|
+
accepts(input) {
|
|
9
|
+
return input.startsWith("oklab");
|
|
10
|
+
}
|
|
11
|
+
handleColor(color) {
|
|
12
|
+
const colorValue = color.value, oklabColor = colorValue.oklab ?? color.value;
|
|
13
|
+
if (!Object.hasOwn(oklabColor, "l") ||
|
|
14
|
+
!Object.hasOwn(oklabColor, "aAxis") ||
|
|
15
|
+
!Object.hasOwn(oklabColor, "bAxis")) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
return oklabToRgb(oklabColor);
|
|
19
|
+
}
|
|
20
|
+
handleRangeColor(color) {
|
|
21
|
+
const colorValue = color.value, oklabColor = colorValue.oklab ?? color.value;
|
|
22
|
+
if (!Object.hasOwn(oklabColor, "l") ||
|
|
23
|
+
!Object.hasOwn(oklabColor, "aAxis") ||
|
|
24
|
+
!Object.hasOwn(oklabColor, "bAxis")) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
return oklabToRgb({
|
|
28
|
+
l: getRangeValue(oklabColor.l),
|
|
29
|
+
aAxis: getRangeValue(oklabColor.aAxis),
|
|
30
|
+
bAxis: getRangeValue(oklabColor.bAxis),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
parseString(input) {
|
|
34
|
+
if (!this.accepts(input)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const result = oklabRegex.exec(input), indexes = {
|
|
38
|
+
l: 1,
|
|
39
|
+
aAxis: 3,
|
|
40
|
+
bAxis: 5,
|
|
41
|
+
a: 7,
|
|
42
|
+
}, defaultAlpha = 1;
|
|
43
|
+
return result
|
|
44
|
+
? oklabaToRgba({
|
|
45
|
+
a: result[indexes.a] ? parseAlpha(result[indexes.a]) : defaultAlpha,
|
|
46
|
+
l: parseFloat(result[indexes.l] ?? "0"),
|
|
47
|
+
aAxis: parseFloat(result[indexes.aAxis] ?? "0"),
|
|
48
|
+
bAxis: parseFloat(result[indexes.bAxis] ?? "0"),
|
|
49
|
+
})
|
|
50
|
+
: undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/esm/index.js
ADDED
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/esm/utils.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { clamp, 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
|
+
OFFSET: 0.055,
|
|
15
|
+
SCALE: 1.055,
|
|
16
|
+
}, minSrgbValue = 0, maxSrgbValue = 1;
|
|
17
|
+
export function oklabToRgb(oklab) {
|
|
18
|
+
const L = oklab.l / percentDenominator, a = oklab.aAxis, b = oklab.bAxis, 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);
|
|
21
|
+
return {
|
|
22
|
+
r: toSrgbFixed(rLinear),
|
|
23
|
+
g: toSrgbFixed(gLinear),
|
|
24
|
+
b: toSrgbFixed(bLinear),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function oklabaToRgba(oklaba) {
|
|
28
|
+
return {
|
|
29
|
+
a: oklaba.a,
|
|
30
|
+
...oklabToRgb(oklaba),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function getStyleFromOklab(color, opacity) {
|
|
34
|
+
const { l, aAxis, bAxis } = color, alpha = opacity !== undefined ? ` / ${opacity.toString()}` : "";
|
|
35
|
+
return `oklab(${l.toString()}% ${aAxis.toString()} ${bAxis.toString()}${alpha})`;
|
|
36
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsparticles/plugin-oklab-color",
|
|
3
|
+
"version": "4.0.0-alpha.0",
|
|
4
|
+
"description": "tsParticles OKLAB 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/oklabColor"
|
|
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.oklabColor.min.js",
|
|
86
|
+
"unpkg": "tsparticles.plugin.oklabColor.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
|
+
}
|