@tsparticles/plugin-hex-color 3.7.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ [![banner](https://particles.js.org/images/banner3.png)](https://particles.js.org)
2
+
3
+ # tsParticles Hex Color Plugin
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/plugin-hex-color/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-hex-color)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/plugin-hex-color.svg)](https://www.npmjs.com/package/@tsparticles/plugin-hex-color)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/plugin-hex-color)](https://www.npmjs.com/package/@tsparticles/plugin-hex-color) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/tsparticles/tsparticles) plugin for adding the hex 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.hexColor.min.js` file will export the function to load the plugin:
18
+
19
+ ```text
20
+ loadHexColorPlugin
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 loadHexColorPlugin();
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-hex-color
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ $ yarn add @tsparticles/plugin-hex-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 { loadHexColorPlugin } = require("@tsparticles/plugin-hex-color");
59
+
60
+ (async () => {
61
+ await loadHexColorPlugin();
62
+ })();
63
+ ```
64
+
65
+ or
66
+
67
+ ```javascript
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadHexColorPlugin } from "@tsparticles/plugin-hex-color";
70
+
71
+ (async () => {
72
+ await loadHexColorPlugin();
73
+ })();
74
+ ```
@@ -0,0 +1,44 @@
1
+ var RgbIndexes;
2
+ (function (RgbIndexes) {
3
+ RgbIndexes[RgbIndexes["r"] = 1] = "r";
4
+ RgbIndexes[RgbIndexes["g"] = 2] = "g";
5
+ RgbIndexes[RgbIndexes["b"] = 3] = "b";
6
+ RgbIndexes[RgbIndexes["a"] = 4] = "a";
7
+ })(RgbIndexes || (RgbIndexes = {}));
8
+ const shorthandHexRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, hexRadix = 16, defaultAlpha = 1, alphaFactor = 0xff;
9
+ export class HexColorManager {
10
+ constructor() {
11
+ this.key = "hex";
12
+ this.stringPrefix = "#";
13
+ }
14
+ handleColor(color) {
15
+ return this._parseString(color.value);
16
+ }
17
+ handleRangeColor(color) {
18
+ return this._parseString(color.value);
19
+ }
20
+ parseString(input) {
21
+ return this._parseString(input);
22
+ }
23
+ _parseString(hexColor) {
24
+ if (typeof hexColor !== "string") {
25
+ return;
26
+ }
27
+ if (!hexColor?.startsWith(this.stringPrefix)) {
28
+ return;
29
+ }
30
+ const hexFixed = hexColor.replace(shorthandHexRegex, (_, r, g, b, a) => {
31
+ return r + r + g + g + b + b + (a !== undefined ? a + a : "");
32
+ }), result = hexRegex.exec(hexFixed);
33
+ return result
34
+ ? {
35
+ a: result[RgbIndexes.a] !== undefined
36
+ ? parseInt(result[RgbIndexes.a], hexRadix) / alphaFactor
37
+ : defaultAlpha,
38
+ b: parseInt(result[RgbIndexes.b], hexRadix),
39
+ g: parseInt(result[RgbIndexes.g], hexRadix),
40
+ r: parseInt(result[RgbIndexes.r], hexRadix),
41
+ }
42
+ : undefined;
43
+ }
44
+ }
@@ -0,0 +1,6 @@
1
+ import { assertValidVersion } from "@tsparticles/engine";
2
+ import { HexColorManager } from "./HexColorManager.js";
3
+ export async function loadHexColorPlugin(engine, refresh = true) {
4
+ assertValidVersion(engine, "3.7.0");
5
+ await engine.addColorManager(new HexColorManager(), refresh);
6
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HexColorManager = void 0;
4
+ var RgbIndexes;
5
+ (function (RgbIndexes) {
6
+ RgbIndexes[RgbIndexes["r"] = 1] = "r";
7
+ RgbIndexes[RgbIndexes["g"] = 2] = "g";
8
+ RgbIndexes[RgbIndexes["b"] = 3] = "b";
9
+ RgbIndexes[RgbIndexes["a"] = 4] = "a";
10
+ })(RgbIndexes || (RgbIndexes = {}));
11
+ const shorthandHexRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, hexRadix = 16, defaultAlpha = 1, alphaFactor = 0xff;
12
+ class HexColorManager {
13
+ constructor() {
14
+ this.key = "hex";
15
+ this.stringPrefix = "#";
16
+ }
17
+ handleColor(color) {
18
+ return this._parseString(color.value);
19
+ }
20
+ handleRangeColor(color) {
21
+ return this._parseString(color.value);
22
+ }
23
+ parseString(input) {
24
+ return this._parseString(input);
25
+ }
26
+ _parseString(hexColor) {
27
+ if (typeof hexColor !== "string") {
28
+ return;
29
+ }
30
+ if (!hexColor?.startsWith(this.stringPrefix)) {
31
+ return;
32
+ }
33
+ const hexFixed = hexColor.replace(shorthandHexRegex, (_, r, g, b, a) => {
34
+ return r + r + g + g + b + b + (a !== undefined ? a + a : "");
35
+ }), result = hexRegex.exec(hexFixed);
36
+ return result
37
+ ? {
38
+ a: result[RgbIndexes.a] !== undefined
39
+ ? parseInt(result[RgbIndexes.a], hexRadix) / alphaFactor
40
+ : defaultAlpha,
41
+ b: parseInt(result[RgbIndexes.b], hexRadix),
42
+ g: parseInt(result[RgbIndexes.g], hexRadix),
43
+ r: parseInt(result[RgbIndexes.r], hexRadix),
44
+ }
45
+ : undefined;
46
+ }
47
+ }
48
+ exports.HexColorManager = HexColorManager;
package/cjs/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadHexColorPlugin = loadHexColorPlugin;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ const HexColorManager_js_1 = require("./HexColorManager.js");
6
+ async function loadHexColorPlugin(engine, refresh = true) {
7
+ (0, engine_1.assertValidVersion)(engine, "3.7.0");
8
+ await engine.addColorManager(new HexColorManager_js_1.HexColorManager(), refresh);
9
+ }
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
@@ -0,0 +1,44 @@
1
+ var RgbIndexes;
2
+ (function (RgbIndexes) {
3
+ RgbIndexes[RgbIndexes["r"] = 1] = "r";
4
+ RgbIndexes[RgbIndexes["g"] = 2] = "g";
5
+ RgbIndexes[RgbIndexes["b"] = 3] = "b";
6
+ RgbIndexes[RgbIndexes["a"] = 4] = "a";
7
+ })(RgbIndexes || (RgbIndexes = {}));
8
+ const shorthandHexRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, hexRadix = 16, defaultAlpha = 1, alphaFactor = 0xff;
9
+ export class HexColorManager {
10
+ constructor() {
11
+ this.key = "hex";
12
+ this.stringPrefix = "#";
13
+ }
14
+ handleColor(color) {
15
+ return this._parseString(color.value);
16
+ }
17
+ handleRangeColor(color) {
18
+ return this._parseString(color.value);
19
+ }
20
+ parseString(input) {
21
+ return this._parseString(input);
22
+ }
23
+ _parseString(hexColor) {
24
+ if (typeof hexColor !== "string") {
25
+ return;
26
+ }
27
+ if (!hexColor?.startsWith(this.stringPrefix)) {
28
+ return;
29
+ }
30
+ const hexFixed = hexColor.replace(shorthandHexRegex, (_, r, g, b, a) => {
31
+ return r + r + g + g + b + b + (a !== undefined ? a + a : "");
32
+ }), result = hexRegex.exec(hexFixed);
33
+ return result
34
+ ? {
35
+ a: result[RgbIndexes.a] !== undefined
36
+ ? parseInt(result[RgbIndexes.a], hexRadix) / alphaFactor
37
+ : defaultAlpha,
38
+ b: parseInt(result[RgbIndexes.b], hexRadix),
39
+ g: parseInt(result[RgbIndexes.g], hexRadix),
40
+ r: parseInt(result[RgbIndexes.r], hexRadix),
41
+ }
42
+ : undefined;
43
+ }
44
+ }
package/esm/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { assertValidVersion } from "@tsparticles/engine";
2
+ import { HexColorManager } from "./HexColorManager.js";
3
+ export async function loadHexColorPlugin(engine, refresh = true) {
4
+ assertValidVersion(engine, "3.7.0");
5
+ await engine.addColorManager(new HexColorManager(), refresh);
6
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/package.json ADDED
@@ -0,0 +1,108 @@
1
+ {
2
+ "name": "@tsparticles/plugin-hex-color",
3
+ "version": "3.7.0",
4
+ "description": "tsParticles hex 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/hexColor"
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.hexColor.min.js",
86
+ "unpkg": "tsparticles.plugin.hexColor.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.7.0"
104
+ },
105
+ "publishConfig": {
106
+ "access": "public"
107
+ }
108
+ }