@tsparticles/plugin-hsv-color 3.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/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/HsvColorManager.js +150 -0
- package/browser/index.js +5 -0
- package/cjs/HsvColorManager.js +163 -0
- package/cjs/index.js +9 -0
- package/esm/HsvColorManager.js +150 -0
- package/esm/index.js +5 -0
- package/package.json +91 -0
- package/report.html +39 -0
- package/tsparticles.plugin.hsvColor.js +280 -0
- package/tsparticles.plugin.hsvColor.min.js +2 -0
- package/tsparticles.plugin.hsvColor.min.js.LICENSE.txt +8 -0
- package/types/HsvColorManager.d.ts +18 -0
- package/types/index.d.ts +1 -0
- package/umd/HsvColorManager.js +173 -0
- package/umd/index.js +19 -0
|
@@ -0,0 +1,280 @@
|
|
|
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.0.0-alpha.0
|
|
8
|
+
*/
|
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
11
|
+
module.exports = factory(require("@tsparticles/engine"));
|
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
|
13
|
+
define(["@tsparticles/engine"], factory);
|
|
14
|
+
else {
|
|
15
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
|
|
16
|
+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
17
|
+
}
|
|
18
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
|
|
19
|
+
return /******/ (() => { // webpackBootstrap
|
|
20
|
+
/******/ "use strict";
|
|
21
|
+
/******/ var __webpack_modules__ = ({
|
|
22
|
+
|
|
23
|
+
/***/ 533:
|
|
24
|
+
/***/ ((module) => {
|
|
25
|
+
|
|
26
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
|
|
27
|
+
|
|
28
|
+
/***/ })
|
|
29
|
+
|
|
30
|
+
/******/ });
|
|
31
|
+
/************************************************************************/
|
|
32
|
+
/******/ // The module cache
|
|
33
|
+
/******/ var __webpack_module_cache__ = {};
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // The require function
|
|
36
|
+
/******/ function __webpack_require__(moduleId) {
|
|
37
|
+
/******/ // Check if module is in cache
|
|
38
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
39
|
+
/******/ if (cachedModule !== undefined) {
|
|
40
|
+
/******/ return cachedModule.exports;
|
|
41
|
+
/******/ }
|
|
42
|
+
/******/ // Create a new module (and put it into the cache)
|
|
43
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
44
|
+
/******/ // no module.id needed
|
|
45
|
+
/******/ // no module.loaded needed
|
|
46
|
+
/******/ exports: {}
|
|
47
|
+
/******/ };
|
|
48
|
+
/******/
|
|
49
|
+
/******/ // Execute the module function
|
|
50
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
51
|
+
/******/
|
|
52
|
+
/******/ // Return the exports of the module
|
|
53
|
+
/******/ return module.exports;
|
|
54
|
+
/******/ }
|
|
55
|
+
/******/
|
|
56
|
+
/************************************************************************/
|
|
57
|
+
/******/ /* webpack/runtime/define property getters */
|
|
58
|
+
/******/ (() => {
|
|
59
|
+
/******/ // define getter functions for harmony exports
|
|
60
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
61
|
+
/******/ for(var key in definition) {
|
|
62
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
63
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
64
|
+
/******/ }
|
|
65
|
+
/******/ }
|
|
66
|
+
/******/ };
|
|
67
|
+
/******/ })();
|
|
68
|
+
/******/
|
|
69
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
70
|
+
/******/ (() => {
|
|
71
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
72
|
+
/******/ })();
|
|
73
|
+
/******/
|
|
74
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
75
|
+
/******/ (() => {
|
|
76
|
+
/******/ // define __esModule on exports
|
|
77
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
78
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
79
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
80
|
+
/******/ }
|
|
81
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
82
|
+
/******/ };
|
|
83
|
+
/******/ })();
|
|
84
|
+
/******/
|
|
85
|
+
/************************************************************************/
|
|
86
|
+
var __webpack_exports__ = {};
|
|
87
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
88
|
+
(() => {
|
|
89
|
+
// ESM COMPAT FLAG
|
|
90
|
+
__webpack_require__.r(__webpack_exports__);
|
|
91
|
+
|
|
92
|
+
// EXPORTS
|
|
93
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
94
|
+
"loadHsvColorPlugin": () => (/* binding */ loadHsvColorPlugin)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
98
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
99
|
+
;// CONCATENATED MODULE: ./dist/browser/HsvColorManager.js
|
|
100
|
+
|
|
101
|
+
function rgbToHsv(rgb) {
|
|
102
|
+
const rgbPercent = {
|
|
103
|
+
r: rgb.r / 255,
|
|
104
|
+
g: rgb.g / 255,
|
|
105
|
+
b: rgb.b / 255
|
|
106
|
+
},
|
|
107
|
+
xMax = Math.max(rgbPercent.r, rgbPercent.g, rgbPercent.b),
|
|
108
|
+
xMin = Math.min(rgbPercent.r, rgbPercent.g, rgbPercent.b),
|
|
109
|
+
v = xMax,
|
|
110
|
+
c = xMax - xMin;
|
|
111
|
+
let h = 0;
|
|
112
|
+
if (v === rgbPercent.r) {
|
|
113
|
+
h = 60 * ((rgbPercent.g - rgbPercent.b) / c);
|
|
114
|
+
} else if (v === rgbPercent.g) {
|
|
115
|
+
h = 60 * (2 + (rgbPercent.b - rgbPercent.r) / c);
|
|
116
|
+
} else if (v === rgbPercent.b) {
|
|
117
|
+
h = 60 * (4 + (rgbPercent.r - rgbPercent.g) / c);
|
|
118
|
+
}
|
|
119
|
+
const s = !v ? 0 : c / v;
|
|
120
|
+
return {
|
|
121
|
+
h,
|
|
122
|
+
s: s * 100,
|
|
123
|
+
v: v * 100
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function rgbaToHsva(rgba) {
|
|
127
|
+
return Object.assign({
|
|
128
|
+
a: rgba.a
|
|
129
|
+
}, rgbToHsv(rgba));
|
|
130
|
+
}
|
|
131
|
+
function getStyleFromHsv(color, opacity) {
|
|
132
|
+
return getStyleFromHsl(hsvToHsl(color), opacity);
|
|
133
|
+
}
|
|
134
|
+
function hslToHsv(hsl) {
|
|
135
|
+
const l = hsl.l / 100,
|
|
136
|
+
sl = hsl.s / 100,
|
|
137
|
+
v = l + sl * Math.min(l, 1 - l),
|
|
138
|
+
sv = !v ? 0 : 2 * (1 - l / v);
|
|
139
|
+
return {
|
|
140
|
+
h: hsl.h,
|
|
141
|
+
s: sv * 100,
|
|
142
|
+
v: v * 100
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function hslaToHsva(hsla) {
|
|
146
|
+
return Object.assign({
|
|
147
|
+
a: hsla.a
|
|
148
|
+
}, hslToHsv(hsla));
|
|
149
|
+
}
|
|
150
|
+
function hsvToHsl(hsv) {
|
|
151
|
+
const v = hsv.v / 100,
|
|
152
|
+
sv = hsv.s / 100,
|
|
153
|
+
l = v * (1 - sv / 2),
|
|
154
|
+
sl = l === 0 || l === 1 ? 0 : (v - l) / Math.min(l, 1 - l);
|
|
155
|
+
return {
|
|
156
|
+
h: hsv.h,
|
|
157
|
+
l: l * 100,
|
|
158
|
+
s: sl * 100
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function hsvaToHsla(hsva) {
|
|
162
|
+
return Object.assign({
|
|
163
|
+
a: hsva.a
|
|
164
|
+
}, hsvToHsl(hsva));
|
|
165
|
+
}
|
|
166
|
+
function hsvToRgb(hsv) {
|
|
167
|
+
const result = {
|
|
168
|
+
b: 0,
|
|
169
|
+
g: 0,
|
|
170
|
+
r: 0
|
|
171
|
+
},
|
|
172
|
+
hsvPercent = {
|
|
173
|
+
h: hsv.h / 60,
|
|
174
|
+
s: hsv.s / 100,
|
|
175
|
+
v: hsv.v / 100
|
|
176
|
+
},
|
|
177
|
+
c = hsvPercent.v * hsvPercent.s,
|
|
178
|
+
x = c * (1 - Math.abs(hsvPercent.h % 2 - 1));
|
|
179
|
+
let tempRgb;
|
|
180
|
+
if (hsvPercent.h >= 0 && hsvPercent.h <= 1) {
|
|
181
|
+
tempRgb = {
|
|
182
|
+
r: c,
|
|
183
|
+
g: x,
|
|
184
|
+
b: 0
|
|
185
|
+
};
|
|
186
|
+
} else if (hsvPercent.h > 1 && hsvPercent.h <= 2) {
|
|
187
|
+
tempRgb = {
|
|
188
|
+
r: x,
|
|
189
|
+
g: c,
|
|
190
|
+
b: 0
|
|
191
|
+
};
|
|
192
|
+
} else if (hsvPercent.h > 2 && hsvPercent.h <= 3) {
|
|
193
|
+
tempRgb = {
|
|
194
|
+
r: 0,
|
|
195
|
+
g: c,
|
|
196
|
+
b: x
|
|
197
|
+
};
|
|
198
|
+
} else if (hsvPercent.h > 3 && hsvPercent.h <= 4) {
|
|
199
|
+
tempRgb = {
|
|
200
|
+
r: 0,
|
|
201
|
+
g: x,
|
|
202
|
+
b: c
|
|
203
|
+
};
|
|
204
|
+
} else if (hsvPercent.h > 4 && hsvPercent.h <= 5) {
|
|
205
|
+
tempRgb = {
|
|
206
|
+
r: x,
|
|
207
|
+
g: 0,
|
|
208
|
+
b: c
|
|
209
|
+
};
|
|
210
|
+
} else if (hsvPercent.h > 5 && hsvPercent.h <= 6) {
|
|
211
|
+
tempRgb = {
|
|
212
|
+
r: c,
|
|
213
|
+
g: 0,
|
|
214
|
+
b: x
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
if (tempRgb) {
|
|
218
|
+
const m = hsvPercent.v - c;
|
|
219
|
+
result.r = Math.floor((tempRgb.r + m) * 255);
|
|
220
|
+
result.g = Math.floor((tempRgb.g + m) * 255);
|
|
221
|
+
result.b = Math.floor((tempRgb.b + m) * 255);
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
function hsvaToRgba(hsva) {
|
|
226
|
+
return Object.assign({
|
|
227
|
+
a: hsva.a
|
|
228
|
+
}, hsvToRgb(hsva));
|
|
229
|
+
}
|
|
230
|
+
class HsvColorManager {
|
|
231
|
+
constructor() {
|
|
232
|
+
this.key = "hsv";
|
|
233
|
+
this.stringPrefix = "hsv";
|
|
234
|
+
}
|
|
235
|
+
handleColor(color) {
|
|
236
|
+
var _a;
|
|
237
|
+
const colorValue = color.value,
|
|
238
|
+
hsvColor = (_a = colorValue.hsv) !== null && _a !== void 0 ? _a : color.value;
|
|
239
|
+
if (hsvColor.h !== undefined && hsvColor.v !== undefined) {
|
|
240
|
+
return hsvToRgb(hsvColor);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
handleRangeColor(color) {
|
|
244
|
+
var _a;
|
|
245
|
+
const colorValue = color.value,
|
|
246
|
+
hsvColor = (_a = colorValue.hsv) !== null && _a !== void 0 ? _a : color.value;
|
|
247
|
+
if (hsvColor.h !== undefined && hsvColor.v !== undefined) {
|
|
248
|
+
return hsvToRgb({
|
|
249
|
+
h: (0,engine_root_window_.getRangeValue)(hsvColor.h),
|
|
250
|
+
s: (0,engine_root_window_.getRangeValue)(hsvColor.s),
|
|
251
|
+
v: (0,engine_root_window_.getRangeValue)(hsvColor.v)
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
parseString(input) {
|
|
256
|
+
if (!input.startsWith("hsv")) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const regex = /hsva?\(\s*(\d+)°\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.%]+)\s*)?\)/i,
|
|
260
|
+
result = regex.exec(input);
|
|
261
|
+
return result ? hsvaToRgba({
|
|
262
|
+
a: result.length > 4 ? (0,engine_root_window_.parseAlpha)(result[5]) : 1,
|
|
263
|
+
h: parseInt(result[1], 10),
|
|
264
|
+
s: parseInt(result[2], 10),
|
|
265
|
+
v: parseInt(result[3], 10)
|
|
266
|
+
}) : undefined;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
function loadHsvColorPlugin() {
|
|
273
|
+
(0,engine_root_window_.addColorManager)(new HsvColorManager());
|
|
274
|
+
}
|
|
275
|
+
})();
|
|
276
|
+
|
|
277
|
+
/******/ return __webpack_exports__;
|
|
278
|
+
/******/ })()
|
|
279
|
+
;
|
|
280
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.plugin.hsvColor.min.js.LICENSE.txt */
|
|
2
|
+
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],r);else{var t="object"==typeof exports?r(require("@tsparticles/engine")):r(e.window);for(var o in t)("object"==typeof exports?exports:e)[o]=t[o]}}(this,(e=>(()=>{"use strict";var r={533:r=>{r.exports=e}},t={};function o(e){var n=t[e];if(void 0!==n)return n.exports;var s=t[e]={exports:{}};return r[e](s,s.exports,o),s.exports}o.d=(e,r)=>{for(var t in r)o.o(r,t)&&!o.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},o.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{loadHsvColorPlugin:()=>s});var e=o(533);function r(e){const r={b:0,g:0,r:0},t=e.h/60,o=e.s/100,n=e.v/100,s=n*o,a=s*(1-Math.abs(t%2-1));let i;if(t>=0&&t<=1?i={r:s,g:a,b:0}:t>1&&t<=2?i={r:a,g:s,b:0}:t>2&&t<=3?i={r:0,g:s,b:a}:t>3&&t<=4?i={r:0,g:a,b:s}:t>4&&t<=5?i={r:a,g:0,b:s}:t>5&&t<=6&&(i={r:s,g:0,b:a}),i){const e=n-s;r.r=Math.floor(255*(i.r+e)),r.g=Math.floor(255*(i.g+e)),r.b=Math.floor(255*(i.b+e))}return r}class t{constructor(){this.key="hsv",this.stringPrefix="hsv"}handleColor(e){var t;const o=null!==(t=e.value.hsv)&&void 0!==t?t:e.value;if(void 0!==o.h&&void 0!==o.v)return r(o)}handleRangeColor(t){var o;const n=null!==(o=t.value.hsv)&&void 0!==o?o:t.value;if(void 0!==n.h&&void 0!==n.v)return r({h:(0,e.getRangeValue)(n.h),s:(0,e.getRangeValue)(n.s),v:(0,e.getRangeValue)(n.v)})}parseString(t){if(!t.startsWith("hsv"))return;const o=/hsva?\(\s*(\d+)°\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.%]+)\s*)?\)/i.exec(t);return o?(n={a:o.length>4?(0,e.parseAlpha)(o[5]):1,h:parseInt(o[1],10),s:parseInt(o[2],10),v:parseInt(o[3],10)},Object.assign({a:n.a},r(n))):void 0;var n}}function s(){(0,e.addColorManager)(new t)}})(),n})()));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IColor, IColorManager, IHsl, IHsla, IHsv, IHsva, IRangeColor, IRgb, IRgba } from "@tsparticles/engine";
|
|
2
|
+
export declare function rgbToHsv(rgb: IRgb): IHsv;
|
|
3
|
+
export declare function rgbaToHsva(rgba: IRgba): IHsva;
|
|
4
|
+
export declare function getStyleFromHsv(color: IHsv, opacity?: number): string;
|
|
5
|
+
export declare function hslToHsv(hsl: IHsl): IHsv;
|
|
6
|
+
export declare function hslaToHsva(hsla: IHsla): IHsva;
|
|
7
|
+
export declare function hsvToHsl(hsv: IHsv): IHsl;
|
|
8
|
+
export declare function hsvaToHsla(hsva: IHsva): IHsla;
|
|
9
|
+
export declare function hsvToRgb(hsv: IHsv): IRgb;
|
|
10
|
+
export declare function hsvaToRgba(hsva: IHsva): IRgba;
|
|
11
|
+
export declare class HsvColorManager implements IColorManager {
|
|
12
|
+
readonly key: string;
|
|
13
|
+
readonly stringPrefix: string;
|
|
14
|
+
constructor();
|
|
15
|
+
handleColor(color: IColor): IRgb | undefined;
|
|
16
|
+
handleRangeColor(color: IRangeColor): IRgb | undefined;
|
|
17
|
+
parseString(input: string): IRgba | undefined;
|
|
18
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadHsvColorPlugin(): void;
|
|
@@ -0,0 +1,173 @@
|
|
|
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.HsvColorManager = exports.hsvaToRgba = exports.hsvToRgb = exports.hsvaToHsla = exports.hsvToHsl = exports.hslaToHsva = exports.hslToHsv = exports.getStyleFromHsv = exports.rgbaToHsva = exports.rgbToHsv = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
function rgbToHsv(rgb) {
|
|
15
|
+
const rgbPercent = {
|
|
16
|
+
r: rgb.r / 255,
|
|
17
|
+
g: rgb.g / 255,
|
|
18
|
+
b: rgb.b / 255,
|
|
19
|
+
}, xMax = Math.max(rgbPercent.r, rgbPercent.g, rgbPercent.b), xMin = Math.min(rgbPercent.r, rgbPercent.g, rgbPercent.b), v = xMax, c = xMax - xMin;
|
|
20
|
+
let h = 0;
|
|
21
|
+
if (v === rgbPercent.r) {
|
|
22
|
+
h = 60 * ((rgbPercent.g - rgbPercent.b) / c);
|
|
23
|
+
}
|
|
24
|
+
else if (v === rgbPercent.g) {
|
|
25
|
+
h = 60 * (2 + (rgbPercent.b - rgbPercent.r) / c);
|
|
26
|
+
}
|
|
27
|
+
else if (v === rgbPercent.b) {
|
|
28
|
+
h = 60 * (4 + (rgbPercent.r - rgbPercent.g) / c);
|
|
29
|
+
}
|
|
30
|
+
const s = !v ? 0 : c / v;
|
|
31
|
+
return {
|
|
32
|
+
h,
|
|
33
|
+
s: s * 100,
|
|
34
|
+
v: v * 100,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.rgbToHsv = rgbToHsv;
|
|
38
|
+
function rgbaToHsva(rgba) {
|
|
39
|
+
return Object.assign({ a: rgba.a }, rgbToHsv(rgba));
|
|
40
|
+
}
|
|
41
|
+
exports.rgbaToHsva = rgbaToHsva;
|
|
42
|
+
function getStyleFromHsv(color, opacity) {
|
|
43
|
+
return (0, engine_1.getStyleFromHsl)(hsvToHsl(color), opacity);
|
|
44
|
+
}
|
|
45
|
+
exports.getStyleFromHsv = getStyleFromHsv;
|
|
46
|
+
function hslToHsv(hsl) {
|
|
47
|
+
const l = hsl.l / 100, sl = hsl.s / 100, v = l + sl * Math.min(l, 1 - l), sv = !v ? 0 : 2 * (1 - l / v);
|
|
48
|
+
return {
|
|
49
|
+
h: hsl.h,
|
|
50
|
+
s: sv * 100,
|
|
51
|
+
v: v * 100,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.hslToHsv = hslToHsv;
|
|
55
|
+
function hslaToHsva(hsla) {
|
|
56
|
+
return Object.assign({ a: hsla.a }, hslToHsv(hsla));
|
|
57
|
+
}
|
|
58
|
+
exports.hslaToHsva = hslaToHsva;
|
|
59
|
+
function hsvToHsl(hsv) {
|
|
60
|
+
const v = hsv.v / 100, sv = hsv.s / 100, l = v * (1 - sv / 2), sl = l === 0 || l === 1 ? 0 : (v - l) / Math.min(l, 1 - l);
|
|
61
|
+
return {
|
|
62
|
+
h: hsv.h,
|
|
63
|
+
l: l * 100,
|
|
64
|
+
s: sl * 100,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
exports.hsvToHsl = hsvToHsl;
|
|
68
|
+
function hsvaToHsla(hsva) {
|
|
69
|
+
return Object.assign({ a: hsva.a }, hsvToHsl(hsva));
|
|
70
|
+
}
|
|
71
|
+
exports.hsvaToHsla = hsvaToHsla;
|
|
72
|
+
function hsvToRgb(hsv) {
|
|
73
|
+
const result = { b: 0, g: 0, r: 0 }, hsvPercent = {
|
|
74
|
+
h: hsv.h / 60,
|
|
75
|
+
s: hsv.s / 100,
|
|
76
|
+
v: hsv.v / 100,
|
|
77
|
+
}, c = hsvPercent.v * hsvPercent.s, x = c * (1 - Math.abs((hsvPercent.h % 2) - 1));
|
|
78
|
+
let tempRgb;
|
|
79
|
+
if (hsvPercent.h >= 0 && hsvPercent.h <= 1) {
|
|
80
|
+
tempRgb = {
|
|
81
|
+
r: c,
|
|
82
|
+
g: x,
|
|
83
|
+
b: 0,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
else if (hsvPercent.h > 1 && hsvPercent.h <= 2) {
|
|
87
|
+
tempRgb = {
|
|
88
|
+
r: x,
|
|
89
|
+
g: c,
|
|
90
|
+
b: 0,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
else if (hsvPercent.h > 2 && hsvPercent.h <= 3) {
|
|
94
|
+
tempRgb = {
|
|
95
|
+
r: 0,
|
|
96
|
+
g: c,
|
|
97
|
+
b: x,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
else if (hsvPercent.h > 3 && hsvPercent.h <= 4) {
|
|
101
|
+
tempRgb = {
|
|
102
|
+
r: 0,
|
|
103
|
+
g: x,
|
|
104
|
+
b: c,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
else if (hsvPercent.h > 4 && hsvPercent.h <= 5) {
|
|
108
|
+
tempRgb = {
|
|
109
|
+
r: x,
|
|
110
|
+
g: 0,
|
|
111
|
+
b: c,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
else if (hsvPercent.h > 5 && hsvPercent.h <= 6) {
|
|
115
|
+
tempRgb = {
|
|
116
|
+
r: c,
|
|
117
|
+
g: 0,
|
|
118
|
+
b: x,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (tempRgb) {
|
|
122
|
+
const m = hsvPercent.v - c;
|
|
123
|
+
result.r = Math.floor((tempRgb.r + m) * 255);
|
|
124
|
+
result.g = Math.floor((tempRgb.g + m) * 255);
|
|
125
|
+
result.b = Math.floor((tempRgb.b + m) * 255);
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
exports.hsvToRgb = hsvToRgb;
|
|
130
|
+
function hsvaToRgba(hsva) {
|
|
131
|
+
return Object.assign({ a: hsva.a }, hsvToRgb(hsva));
|
|
132
|
+
}
|
|
133
|
+
exports.hsvaToRgba = hsvaToRgba;
|
|
134
|
+
class HsvColorManager {
|
|
135
|
+
constructor() {
|
|
136
|
+
this.key = "hsv";
|
|
137
|
+
this.stringPrefix = "hsv";
|
|
138
|
+
}
|
|
139
|
+
handleColor(color) {
|
|
140
|
+
var _a;
|
|
141
|
+
const colorValue = color.value, hsvColor = (_a = colorValue.hsv) !== null && _a !== void 0 ? _a : color.value;
|
|
142
|
+
if (hsvColor.h !== undefined && hsvColor.v !== undefined) {
|
|
143
|
+
return hsvToRgb(hsvColor);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
handleRangeColor(color) {
|
|
147
|
+
var _a;
|
|
148
|
+
const colorValue = color.value, hsvColor = (_a = colorValue.hsv) !== null && _a !== void 0 ? _a : color.value;
|
|
149
|
+
if (hsvColor.h !== undefined && hsvColor.v !== undefined) {
|
|
150
|
+
return hsvToRgb({
|
|
151
|
+
h: (0, engine_1.getRangeValue)(hsvColor.h),
|
|
152
|
+
s: (0, engine_1.getRangeValue)(hsvColor.s),
|
|
153
|
+
v: (0, engine_1.getRangeValue)(hsvColor.v),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
parseString(input) {
|
|
158
|
+
if (!input.startsWith("hsv")) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const regex = /hsva?\(\s*(\d+)°\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.%]+)\s*)?\)/i, result = regex.exec(input);
|
|
162
|
+
return result
|
|
163
|
+
? hsvaToRgba({
|
|
164
|
+
a: result.length > 4 ? (0, engine_1.parseAlpha)(result[5]) : 1,
|
|
165
|
+
h: parseInt(result[1], 10),
|
|
166
|
+
s: parseInt(result[2], 10),
|
|
167
|
+
v: parseInt(result[3], 10),
|
|
168
|
+
})
|
|
169
|
+
: undefined;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.HsvColorManager = HsvColorManager;
|
|
173
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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", "./HsvColorManager", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadHsvColorPlugin = void 0;
|
|
13
|
+
const HsvColorManager_1 = require("./HsvColorManager");
|
|
14
|
+
const engine_1 = require("@tsparticles/engine");
|
|
15
|
+
function loadHsvColorPlugin() {
|
|
16
|
+
(0, engine_1.addColorManager)(new HsvColorManager_1.HsvColorManager());
|
|
17
|
+
}
|
|
18
|
+
exports.loadHsvColorPlugin = loadHsvColorPlugin;
|
|
19
|
+
});
|