@tsparticles/shape-image 3.0.0-alpha.1 → 3.0.0-beta.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/README.md +16 -12
- package/browser/GifUtils/ByteStream.js +44 -0
- package/browser/GifUtils/Constants.js +2 -0
- package/browser/GifUtils/Enums/DisposalMethod.js +1 -0
- package/browser/GifUtils/Types/ApplicationExtension.js +1 -0
- package/browser/GifUtils/Types/Frame.js +1 -0
- package/browser/GifUtils/Types/GIF.js +1 -0
- package/browser/GifUtils/Types/GIFDataHeaders.js +1 -0
- package/browser/GifUtils/Types/GIFProgressCallbackFunction.js +1 -0
- package/browser/GifUtils/Types/PlainTextData.js +1 -0
- package/browser/GifUtils/Utils.js +324 -0
- package/browser/ImageDrawer.js +122 -58
- package/browser/ImagePreloader.js +33 -0
- package/browser/Options/Classes/Preload.js +29 -0
- package/browser/Options/Interfaces/IPreload.js +1 -0
- package/browser/Utils.js +35 -9
- package/browser/index.js +42 -2
- package/browser/types.js +1 -0
- package/cjs/GifUtils/ByteStream.js +48 -0
- package/cjs/GifUtils/Constants.js +5 -0
- package/cjs/GifUtils/Enums/DisposalMethod.js +2 -0
- package/cjs/GifUtils/Types/ApplicationExtension.js +2 -0
- package/cjs/GifUtils/Types/Frame.js +2 -0
- package/cjs/GifUtils/Types/GIF.js +2 -0
- package/cjs/GifUtils/Types/GIFDataHeaders.js +2 -0
- package/cjs/GifUtils/Types/GIFProgressCallbackFunction.js +2 -0
- package/cjs/GifUtils/Types/PlainTextData.js +2 -0
- package/cjs/GifUtils/Utils.js +329 -0
- package/cjs/ImageDrawer.js +124 -71
- package/cjs/ImagePreloader.js +37 -0
- package/cjs/Options/Classes/Preload.js +33 -0
- package/cjs/Options/Interfaces/IPreload.js +2 -0
- package/cjs/Utils.js +66 -52
- package/cjs/index.js +42 -13
- package/cjs/types.js +2 -0
- package/esm/GifUtils/ByteStream.js +44 -0
- package/esm/GifUtils/Constants.js +2 -0
- package/esm/GifUtils/Enums/DisposalMethod.js +1 -0
- package/esm/GifUtils/Types/ApplicationExtension.js +1 -0
- package/esm/GifUtils/Types/Frame.js +1 -0
- package/esm/GifUtils/Types/GIF.js +1 -0
- package/esm/GifUtils/Types/GIFDataHeaders.js +1 -0
- package/esm/GifUtils/Types/GIFProgressCallbackFunction.js +1 -0
- package/esm/GifUtils/Types/PlainTextData.js +1 -0
- package/esm/GifUtils/Utils.js +324 -0
- package/esm/ImageDrawer.js +122 -58
- package/esm/ImagePreloader.js +33 -0
- package/esm/Options/Classes/Preload.js +29 -0
- package/esm/Options/Interfaces/IPreload.js +1 -0
- package/esm/Utils.js +35 -9
- package/esm/index.js +42 -2
- package/esm/types.js +1 -0
- package/package.json +6 -5
- package/report.html +4 -4
- package/tsparticles.shape.image.js +676 -73
- package/tsparticles.shape.image.min.js +1 -1
- package/tsparticles.shape.image.min.js.LICENSE.txt +1 -8
- package/types/GifUtils/ByteStream.d.ts +11 -0
- package/types/GifUtils/Constants.d.ts +2 -0
- package/types/GifUtils/Enums/DisposalMethod.d.ts +10 -0
- package/types/GifUtils/Types/ApplicationExtension.d.ts +5 -0
- package/types/GifUtils/Types/Frame.d.ts +19 -0
- package/types/GifUtils/Types/GIF.d.ts +16 -0
- package/types/GifUtils/Types/GIFDataHeaders.d.ts +9 -0
- package/types/GifUtils/Types/GIFProgressCallbackFunction.d.ts +2 -0
- package/types/GifUtils/Types/PlainTextData.d.ts +11 -0
- package/types/GifUtils/Utils.d.ts +4 -0
- package/types/IImageShape.d.ts +2 -1
- package/types/ImageDrawer.d.ts +9 -9
- package/types/ImagePreloader.d.ts +10 -0
- package/types/Options/Classes/Preload.d.ts +12 -0
- package/types/Options/Interfaces/IPreload.d.ts +8 -0
- package/types/Utils.d.ts +15 -5
- package/types/index.d.ts +2 -2
- package/types/types.d.ts +17 -0
- package/umd/GifUtils/ByteStream.js +58 -0
- package/umd/GifUtils/Constants.js +15 -0
- package/umd/GifUtils/Enums/DisposalMethod.js +12 -0
- package/umd/GifUtils/Types/ApplicationExtension.js +12 -0
- package/umd/GifUtils/Types/Frame.js +12 -0
- package/umd/GifUtils/Types/GIF.js +12 -0
- package/umd/GifUtils/Types/GIFDataHeaders.js +12 -0
- package/umd/GifUtils/Types/GIFProgressCallbackFunction.js +12 -0
- package/umd/GifUtils/Types/PlainTextData.js +12 -0
- package/umd/GifUtils/Utils.js +339 -0
- package/umd/ImageDrawer.js +122 -58
- package/umd/ImagePreloader.js +47 -0
- package/umd/Options/Classes/Preload.js +43 -0
- package/umd/Options/Interfaces/IPreload.js +12 -0
- package/umd/Utils.js +37 -10
- package/umd/index.js +43 -3
- package/umd/types.js +12 -0
|
@@ -0,0 +1,12 @@
|
|
|
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"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/Utils.js
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "./GifUtils/Utils"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.replaceImageColor = exports.downloadSvgImage = exports.loadImage = void 0;
|
|
12
|
+
exports.replaceImageColor = exports.downloadSvgImage = exports.loadGifImage = exports.loadImage = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const Utils_1 = require("./GifUtils/Utils");
|
|
14
15
|
const currentColorRegex = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d.]+%?\))|currentcolor/gi;
|
|
15
16
|
function replaceColorSvg(imageShape, color, opacity) {
|
|
16
17
|
const { svgData } = imageShape;
|
|
@@ -37,13 +38,32 @@
|
|
|
37
38
|
image.element = undefined;
|
|
38
39
|
image.error = true;
|
|
39
40
|
image.loading = false;
|
|
40
|
-
|
|
41
|
+
(0, engine_1.getLogger)().error(`${engine_1.errorPrefix} loading image: ${image.source}`);
|
|
41
42
|
resolve();
|
|
42
43
|
});
|
|
43
44
|
img.src = image.source;
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
exports.loadImage = loadImage;
|
|
48
|
+
async function loadGifImage(image) {
|
|
49
|
+
if (image.type !== "gif") {
|
|
50
|
+
await loadImage(image);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
image.loading = true;
|
|
54
|
+
try {
|
|
55
|
+
image.gifData = await (0, Utils_1.decodeGIF)(image.source);
|
|
56
|
+
image.gifLoopCount = (0, Utils_1.getGIFLoopAmount)(image.gifData) ?? 0;
|
|
57
|
+
if (image.gifLoopCount === 0) {
|
|
58
|
+
image.gifLoopCount = Infinity;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
image.error = true;
|
|
63
|
+
}
|
|
64
|
+
image.loading = false;
|
|
65
|
+
}
|
|
66
|
+
exports.loadGifImage = loadGifImage;
|
|
47
67
|
async function downloadSvgImage(image) {
|
|
48
68
|
if (image.type !== "svg") {
|
|
49
69
|
await loadImage(image);
|
|
@@ -52,23 +72,26 @@
|
|
|
52
72
|
image.loading = true;
|
|
53
73
|
const response = await fetch(image.source);
|
|
54
74
|
if (!response.ok) {
|
|
55
|
-
|
|
75
|
+
(0, engine_1.getLogger)().error(`${engine_1.errorPrefix} Image not found`);
|
|
56
76
|
image.error = true;
|
|
57
77
|
}
|
|
58
|
-
|
|
78
|
+
else {
|
|
59
79
|
image.svgData = await response.text();
|
|
60
80
|
}
|
|
61
81
|
image.loading = false;
|
|
62
82
|
}
|
|
63
83
|
exports.downloadSvgImage = downloadSvgImage;
|
|
64
84
|
function replaceImageColor(image, imageData, color, particle) {
|
|
65
|
-
|
|
66
|
-
const svgColoredData = replaceColorSvg(image, color, (_b = (_a = particle.opacity) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 1), imageRes = {
|
|
85
|
+
const svgColoredData = replaceColorSvg(image, color, particle.opacity?.value ?? 1), imageRes = {
|
|
67
86
|
color,
|
|
68
|
-
|
|
87
|
+
gif: imageData.gif,
|
|
88
|
+
data: {
|
|
89
|
+
...image,
|
|
90
|
+
svgData: svgColoredData,
|
|
91
|
+
},
|
|
69
92
|
loaded: false,
|
|
70
93
|
ratio: imageData.width / imageData.height,
|
|
71
|
-
replaceColor:
|
|
94
|
+
replaceColor: imageData.replaceColor,
|
|
72
95
|
source: imageData.src,
|
|
73
96
|
};
|
|
74
97
|
return new Promise((resolve) => {
|
|
@@ -81,7 +104,11 @@
|
|
|
81
104
|
});
|
|
82
105
|
img.addEventListener("error", async () => {
|
|
83
106
|
domUrl.revokeObjectURL(url);
|
|
84
|
-
const img2 =
|
|
107
|
+
const img2 = {
|
|
108
|
+
...image,
|
|
109
|
+
error: false,
|
|
110
|
+
loading: true,
|
|
111
|
+
};
|
|
85
112
|
await loadImage(img2);
|
|
86
113
|
imageRes.loaded = true;
|
|
87
114
|
imageRes.element = img2.element;
|
package/umd/index.js
CHANGED
|
@@ -4,15 +4,55 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./ImageDrawer"], factory);
|
|
7
|
+
define(["require", "exports", "./Utils", "./ImageDrawer", "./ImagePreloader", "@tsparticles/engine"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.loadImageShape = void 0;
|
|
13
|
+
const Utils_1 = require("./Utils");
|
|
13
14
|
const ImageDrawer_1 = require("./ImageDrawer");
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const ImagePreloader_1 = require("./ImagePreloader");
|
|
16
|
+
const engine_1 = require("@tsparticles/engine");
|
|
17
|
+
function addLoadImageToEngine(engine) {
|
|
18
|
+
if (engine.loadImage) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
engine.loadImage = async (data) => {
|
|
22
|
+
if (!data.name && !data.src) {
|
|
23
|
+
throw new Error(`${engine_1.errorPrefix} no image source provided`);
|
|
24
|
+
}
|
|
25
|
+
if (!engine.images) {
|
|
26
|
+
engine.images = [];
|
|
27
|
+
}
|
|
28
|
+
if (engine.images.find((t) => t.name === data.name || t.source === data.src)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const image = {
|
|
33
|
+
gif: data.gif ?? false,
|
|
34
|
+
name: data.name ?? data.src,
|
|
35
|
+
source: data.src,
|
|
36
|
+
type: data.src.substring(data.src.length - 3),
|
|
37
|
+
error: false,
|
|
38
|
+
loading: true,
|
|
39
|
+
replaceColor: data.replaceColor,
|
|
40
|
+
ratio: data.width && data.height ? data.width / data.height : undefined,
|
|
41
|
+
};
|
|
42
|
+
engine.images.push(image);
|
|
43
|
+
const imageFunc = data.gif ? Utils_1.loadGifImage : data.replaceColor ? Utils_1.downloadSvgImage : Utils_1.loadImage;
|
|
44
|
+
await imageFunc(image);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new Error(`${engine_1.errorPrefix} ${data.name ?? data.src} not found`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function loadImageShape(engine, refresh = true) {
|
|
52
|
+
addLoadImageToEngine(engine);
|
|
53
|
+
const preloader = new ImagePreloader_1.ImagePreloaderPlugin(engine);
|
|
54
|
+
await engine.addPlugin(preloader, refresh);
|
|
55
|
+
await engine.addShape(["image", "images"], new ImageDrawer_1.ImageDrawer(engine), refresh);
|
|
16
56
|
}
|
|
17
57
|
exports.loadImageShape = loadImageShape;
|
|
18
58
|
});
|
package/umd/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|