@tsparticles/shape-image 4.0.0-beta.9 → 4.0.1
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/browser/browser.js +5 -0
- package/browser/index.js +7 -11
- package/browser/index.lazy.js +69 -0
- package/cjs/browser.js +5 -0
- package/cjs/index.js +7 -11
- package/cjs/index.lazy.js +69 -0
- package/esm/browser.js +5 -0
- package/esm/index.js +7 -11
- package/esm/index.lazy.js +69 -0
- package/package.json +9 -2
- package/report.html +4949 -94
- package/tsparticles.shape.image.js +851 -317
- package/tsparticles.shape.image.min.js +1 -2
- package/types/GifUtils/ByteStream.d.ts +2 -1
- package/types/browser.d.ts +1 -0
- package/types/index.lazy.d.ts +2 -0
- package/137.min.js +0 -1
- package/687.min.js +0 -1
- package/928.min.js +0 -1
- package/969.min.js +0 -1
- package/dist_browser_GifUtils_Utils_js.js +0 -70
- package/dist_browser_ImageDrawer_js.js +0 -30
- package/dist_browser_ImagePreloaderInstance_js.js +0 -30
- package/dist_browser_ImagePreloader_js.js +0 -40
package/browser/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { shapeTypes } from "./Utils.js";
|
|
1
|
+
import { downloadSvgImage, loadImage, shapeTypes } from "./Utils.js";
|
|
2
|
+
import { ImageDrawer } from "./ImageDrawer.js";
|
|
3
|
+
import { ImagePreloaderPlugin } from "./ImagePreloader.js";
|
|
4
|
+
import { loadGifImage } from "./GifUtils/Utils.js";
|
|
2
5
|
const extLength = 3;
|
|
3
6
|
function addLoadImageToEngine(engine) {
|
|
4
7
|
engine.getImages ??= (container) => {
|
|
@@ -37,15 +40,12 @@ function addLoadImageToEngine(engine) {
|
|
|
37
40
|
engine.images.set(container, containerImages);
|
|
38
41
|
let imageFunc;
|
|
39
42
|
if (data.gif) {
|
|
40
|
-
const { loadGifImage } = await import("./GifUtils/Utils.js");
|
|
41
43
|
imageFunc = (img) => loadGifImage(img, { colorSpace: "srgb" });
|
|
42
44
|
}
|
|
43
45
|
else if (data.replaceColor) {
|
|
44
|
-
const { downloadSvgImage } = await import("./Utils.js");
|
|
45
46
|
imageFunc = downloadSvgImage;
|
|
46
47
|
}
|
|
47
48
|
else {
|
|
48
|
-
const { loadImage } = await import("./Utils.js");
|
|
49
49
|
imageFunc = loadImage;
|
|
50
50
|
}
|
|
51
51
|
await imageFunc(image);
|
|
@@ -56,14 +56,10 @@ function addLoadImageToEngine(engine) {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
export async function loadImageShape(engine) {
|
|
59
|
-
engine.checkVersion("4.0.
|
|
60
|
-
await engine.pluginManager.register(
|
|
61
|
-
const { ImagePreloaderPlugin } = await import("./ImagePreloader.js");
|
|
59
|
+
engine.checkVersion("4.0.1");
|
|
60
|
+
await engine.pluginManager.register(e => {
|
|
62
61
|
addLoadImageToEngine(e);
|
|
63
62
|
e.pluginManager.addPlugin(new ImagePreloaderPlugin(e));
|
|
64
|
-
e.pluginManager.addShape(shapeTypes,
|
|
65
|
-
const { ImageDrawer } = await import("./ImageDrawer.js");
|
|
66
|
-
return new ImageDrawer(e, container);
|
|
67
|
-
});
|
|
63
|
+
e.pluginManager.addShape(shapeTypes, container => Promise.resolve(new ImageDrawer(e, container)));
|
|
68
64
|
});
|
|
69
65
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { shapeTypes } from "./Utils.js";
|
|
2
|
+
const extLength = 3;
|
|
3
|
+
function addLoadImageToEngine(engine) {
|
|
4
|
+
engine.getImages ??= (container) => {
|
|
5
|
+
engine.images ??= new Map();
|
|
6
|
+
let images = engine.images.get(container);
|
|
7
|
+
if (!images) {
|
|
8
|
+
images = [];
|
|
9
|
+
engine.images.set(container, images);
|
|
10
|
+
}
|
|
11
|
+
return images;
|
|
12
|
+
};
|
|
13
|
+
engine.loadImage ??= async (container, data) => {
|
|
14
|
+
if (!engine.getImages) {
|
|
15
|
+
throw new Error("No images collection found");
|
|
16
|
+
}
|
|
17
|
+
if (!data.name && !data.src) {
|
|
18
|
+
throw new Error("No image source provided");
|
|
19
|
+
}
|
|
20
|
+
engine.images ??= new Map();
|
|
21
|
+
const containerImages = engine.getImages(container);
|
|
22
|
+
if (containerImages.some((t) => t.name === data.name || t.source === data.src)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const image = {
|
|
27
|
+
gif: data.gif,
|
|
28
|
+
name: data.name ?? data.src,
|
|
29
|
+
source: data.src,
|
|
30
|
+
type: data.src.substring(data.src.length - extLength),
|
|
31
|
+
error: false,
|
|
32
|
+
loading: true,
|
|
33
|
+
replaceColor: data.replaceColor,
|
|
34
|
+
ratio: data.width && data.height ? data.width / data.height : undefined,
|
|
35
|
+
};
|
|
36
|
+
containerImages.push(image);
|
|
37
|
+
engine.images.set(container, containerImages);
|
|
38
|
+
let imageFunc;
|
|
39
|
+
if (data.gif) {
|
|
40
|
+
const { loadGifImage } = await import("./GifUtils/Utils.js");
|
|
41
|
+
imageFunc = (img) => loadGifImage(img, { colorSpace: "srgb" });
|
|
42
|
+
}
|
|
43
|
+
else if (data.replaceColor) {
|
|
44
|
+
const { downloadSvgImage } = await import("./Utils.js");
|
|
45
|
+
imageFunc = downloadSvgImage;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const { loadImage } = await import("./Utils.js");
|
|
49
|
+
imageFunc = loadImage;
|
|
50
|
+
}
|
|
51
|
+
await imageFunc(image);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new Error(`${data.name ?? data.src} not found`);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export async function loadImageShape(engine) {
|
|
59
|
+
engine.checkVersion("4.0.1");
|
|
60
|
+
await engine.pluginManager.register(async (e) => {
|
|
61
|
+
const { ImagePreloaderPlugin } = await import("./ImagePreloader.js");
|
|
62
|
+
addLoadImageToEngine(e);
|
|
63
|
+
e.pluginManager.addPlugin(new ImagePreloaderPlugin(e));
|
|
64
|
+
e.pluginManager.addShape(shapeTypes, async (container) => {
|
|
65
|
+
const { ImageDrawer } = await import("./ImageDrawer.js");
|
|
66
|
+
return new ImageDrawer(e, container);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
package/cjs/browser.js
ADDED
package/cjs/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { shapeTypes } from "./Utils.js";
|
|
1
|
+
import { downloadSvgImage, loadImage, shapeTypes } from "./Utils.js";
|
|
2
|
+
import { ImageDrawer } from "./ImageDrawer.js";
|
|
3
|
+
import { ImagePreloaderPlugin } from "./ImagePreloader.js";
|
|
4
|
+
import { loadGifImage } from "./GifUtils/Utils.js";
|
|
2
5
|
const extLength = 3;
|
|
3
6
|
function addLoadImageToEngine(engine) {
|
|
4
7
|
engine.getImages ??= (container) => {
|
|
@@ -37,15 +40,12 @@ function addLoadImageToEngine(engine) {
|
|
|
37
40
|
engine.images.set(container, containerImages);
|
|
38
41
|
let imageFunc;
|
|
39
42
|
if (data.gif) {
|
|
40
|
-
const { loadGifImage } = await import("./GifUtils/Utils.js");
|
|
41
43
|
imageFunc = (img) => loadGifImage(img, { colorSpace: "srgb" });
|
|
42
44
|
}
|
|
43
45
|
else if (data.replaceColor) {
|
|
44
|
-
const { downloadSvgImage } = await import("./Utils.js");
|
|
45
46
|
imageFunc = downloadSvgImage;
|
|
46
47
|
}
|
|
47
48
|
else {
|
|
48
|
-
const { loadImage } = await import("./Utils.js");
|
|
49
49
|
imageFunc = loadImage;
|
|
50
50
|
}
|
|
51
51
|
await imageFunc(image);
|
|
@@ -56,14 +56,10 @@ function addLoadImageToEngine(engine) {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
export async function loadImageShape(engine) {
|
|
59
|
-
engine.checkVersion("4.0.
|
|
60
|
-
await engine.pluginManager.register(
|
|
61
|
-
const { ImagePreloaderPlugin } = await import("./ImagePreloader.js");
|
|
59
|
+
engine.checkVersion("4.0.1");
|
|
60
|
+
await engine.pluginManager.register(e => {
|
|
62
61
|
addLoadImageToEngine(e);
|
|
63
62
|
e.pluginManager.addPlugin(new ImagePreloaderPlugin(e));
|
|
64
|
-
e.pluginManager.addShape(shapeTypes,
|
|
65
|
-
const { ImageDrawer } = await import("./ImageDrawer.js");
|
|
66
|
-
return new ImageDrawer(e, container);
|
|
67
|
-
});
|
|
63
|
+
e.pluginManager.addShape(shapeTypes, container => Promise.resolve(new ImageDrawer(e, container)));
|
|
68
64
|
});
|
|
69
65
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { shapeTypes } from "./Utils.js";
|
|
2
|
+
const extLength = 3;
|
|
3
|
+
function addLoadImageToEngine(engine) {
|
|
4
|
+
engine.getImages ??= (container) => {
|
|
5
|
+
engine.images ??= new Map();
|
|
6
|
+
let images = engine.images.get(container);
|
|
7
|
+
if (!images) {
|
|
8
|
+
images = [];
|
|
9
|
+
engine.images.set(container, images);
|
|
10
|
+
}
|
|
11
|
+
return images;
|
|
12
|
+
};
|
|
13
|
+
engine.loadImage ??= async (container, data) => {
|
|
14
|
+
if (!engine.getImages) {
|
|
15
|
+
throw new Error("No images collection found");
|
|
16
|
+
}
|
|
17
|
+
if (!data.name && !data.src) {
|
|
18
|
+
throw new Error("No image source provided");
|
|
19
|
+
}
|
|
20
|
+
engine.images ??= new Map();
|
|
21
|
+
const containerImages = engine.getImages(container);
|
|
22
|
+
if (containerImages.some((t) => t.name === data.name || t.source === data.src)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const image = {
|
|
27
|
+
gif: data.gif,
|
|
28
|
+
name: data.name ?? data.src,
|
|
29
|
+
source: data.src,
|
|
30
|
+
type: data.src.substring(data.src.length - extLength),
|
|
31
|
+
error: false,
|
|
32
|
+
loading: true,
|
|
33
|
+
replaceColor: data.replaceColor,
|
|
34
|
+
ratio: data.width && data.height ? data.width / data.height : undefined,
|
|
35
|
+
};
|
|
36
|
+
containerImages.push(image);
|
|
37
|
+
engine.images.set(container, containerImages);
|
|
38
|
+
let imageFunc;
|
|
39
|
+
if (data.gif) {
|
|
40
|
+
const { loadGifImage } = await import("./GifUtils/Utils.js");
|
|
41
|
+
imageFunc = (img) => loadGifImage(img, { colorSpace: "srgb" });
|
|
42
|
+
}
|
|
43
|
+
else if (data.replaceColor) {
|
|
44
|
+
const { downloadSvgImage } = await import("./Utils.js");
|
|
45
|
+
imageFunc = downloadSvgImage;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const { loadImage } = await import("./Utils.js");
|
|
49
|
+
imageFunc = loadImage;
|
|
50
|
+
}
|
|
51
|
+
await imageFunc(image);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new Error(`${data.name ?? data.src} not found`);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export async function loadImageShape(engine) {
|
|
59
|
+
engine.checkVersion("4.0.1");
|
|
60
|
+
await engine.pluginManager.register(async (e) => {
|
|
61
|
+
const { ImagePreloaderPlugin } = await import("./ImagePreloader.js");
|
|
62
|
+
addLoadImageToEngine(e);
|
|
63
|
+
e.pluginManager.addPlugin(new ImagePreloaderPlugin(e));
|
|
64
|
+
e.pluginManager.addShape(shapeTypes, async (container) => {
|
|
65
|
+
const { ImageDrawer } = await import("./ImageDrawer.js");
|
|
66
|
+
return new ImageDrawer(e, container);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
package/esm/browser.js
ADDED
package/esm/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { shapeTypes } from "./Utils.js";
|
|
1
|
+
import { downloadSvgImage, loadImage, shapeTypes } from "./Utils.js";
|
|
2
|
+
import { ImageDrawer } from "./ImageDrawer.js";
|
|
3
|
+
import { ImagePreloaderPlugin } from "./ImagePreloader.js";
|
|
4
|
+
import { loadGifImage } from "./GifUtils/Utils.js";
|
|
2
5
|
const extLength = 3;
|
|
3
6
|
function addLoadImageToEngine(engine) {
|
|
4
7
|
engine.getImages ??= (container) => {
|
|
@@ -37,15 +40,12 @@ function addLoadImageToEngine(engine) {
|
|
|
37
40
|
engine.images.set(container, containerImages);
|
|
38
41
|
let imageFunc;
|
|
39
42
|
if (data.gif) {
|
|
40
|
-
const { loadGifImage } = await import("./GifUtils/Utils.js");
|
|
41
43
|
imageFunc = (img) => loadGifImage(img, { colorSpace: "srgb" });
|
|
42
44
|
}
|
|
43
45
|
else if (data.replaceColor) {
|
|
44
|
-
const { downloadSvgImage } = await import("./Utils.js");
|
|
45
46
|
imageFunc = downloadSvgImage;
|
|
46
47
|
}
|
|
47
48
|
else {
|
|
48
|
-
const { loadImage } = await import("./Utils.js");
|
|
49
49
|
imageFunc = loadImage;
|
|
50
50
|
}
|
|
51
51
|
await imageFunc(image);
|
|
@@ -56,14 +56,10 @@ function addLoadImageToEngine(engine) {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
export async function loadImageShape(engine) {
|
|
59
|
-
engine.checkVersion("4.0.
|
|
60
|
-
await engine.pluginManager.register(
|
|
61
|
-
const { ImagePreloaderPlugin } = await import("./ImagePreloader.js");
|
|
59
|
+
engine.checkVersion("4.0.1");
|
|
60
|
+
await engine.pluginManager.register(e => {
|
|
62
61
|
addLoadImageToEngine(e);
|
|
63
62
|
e.pluginManager.addPlugin(new ImagePreloaderPlugin(e));
|
|
64
|
-
e.pluginManager.addShape(shapeTypes,
|
|
65
|
-
const { ImageDrawer } = await import("./ImageDrawer.js");
|
|
66
|
-
return new ImageDrawer(e, container);
|
|
67
|
-
});
|
|
63
|
+
e.pluginManager.addShape(shapeTypes, container => Promise.resolve(new ImageDrawer(e, container)));
|
|
68
64
|
});
|
|
69
65
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { shapeTypes } from "./Utils.js";
|
|
2
|
+
const extLength = 3;
|
|
3
|
+
function addLoadImageToEngine(engine) {
|
|
4
|
+
engine.getImages ??= (container) => {
|
|
5
|
+
engine.images ??= new Map();
|
|
6
|
+
let images = engine.images.get(container);
|
|
7
|
+
if (!images) {
|
|
8
|
+
images = [];
|
|
9
|
+
engine.images.set(container, images);
|
|
10
|
+
}
|
|
11
|
+
return images;
|
|
12
|
+
};
|
|
13
|
+
engine.loadImage ??= async (container, data) => {
|
|
14
|
+
if (!engine.getImages) {
|
|
15
|
+
throw new Error("No images collection found");
|
|
16
|
+
}
|
|
17
|
+
if (!data.name && !data.src) {
|
|
18
|
+
throw new Error("No image source provided");
|
|
19
|
+
}
|
|
20
|
+
engine.images ??= new Map();
|
|
21
|
+
const containerImages = engine.getImages(container);
|
|
22
|
+
if (containerImages.some((t) => t.name === data.name || t.source === data.src)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const image = {
|
|
27
|
+
gif: data.gif,
|
|
28
|
+
name: data.name ?? data.src,
|
|
29
|
+
source: data.src,
|
|
30
|
+
type: data.src.substring(data.src.length - extLength),
|
|
31
|
+
error: false,
|
|
32
|
+
loading: true,
|
|
33
|
+
replaceColor: data.replaceColor,
|
|
34
|
+
ratio: data.width && data.height ? data.width / data.height : undefined,
|
|
35
|
+
};
|
|
36
|
+
containerImages.push(image);
|
|
37
|
+
engine.images.set(container, containerImages);
|
|
38
|
+
let imageFunc;
|
|
39
|
+
if (data.gif) {
|
|
40
|
+
const { loadGifImage } = await import("./GifUtils/Utils.js");
|
|
41
|
+
imageFunc = (img) => loadGifImage(img, { colorSpace: "srgb" });
|
|
42
|
+
}
|
|
43
|
+
else if (data.replaceColor) {
|
|
44
|
+
const { downloadSvgImage } = await import("./Utils.js");
|
|
45
|
+
imageFunc = downloadSvgImage;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const { loadImage } = await import("./Utils.js");
|
|
49
|
+
imageFunc = loadImage;
|
|
50
|
+
}
|
|
51
|
+
await imageFunc(image);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new Error(`${data.name ?? data.src} not found`);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export async function loadImageShape(engine) {
|
|
59
|
+
engine.checkVersion("4.0.1");
|
|
60
|
+
await engine.pluginManager.register(async (e) => {
|
|
61
|
+
const { ImagePreloaderPlugin } = await import("./ImagePreloader.js");
|
|
62
|
+
addLoadImageToEngine(e);
|
|
63
|
+
e.pluginManager.addPlugin(new ImagePreloaderPlugin(e));
|
|
64
|
+
e.pluginManager.addShape(shapeTypes, async (container) => {
|
|
65
|
+
const { ImageDrawer } = await import("./ImageDrawer.js");
|
|
66
|
+
return new ImageDrawer(e, container);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/shape-image",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "tsParticles image shape",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -55,10 +55,17 @@
|
|
|
55
55
|
"require": "./cjs/index.js",
|
|
56
56
|
"default": "./esm/index.js"
|
|
57
57
|
},
|
|
58
|
+
"./lazy": {
|
|
59
|
+
"types": "./types/index.lazy.d.ts",
|
|
60
|
+
"browser": "./browser/index.lazy.js",
|
|
61
|
+
"import": "./esm/index.lazy.js",
|
|
62
|
+
"require": "./cjs/index.lazy.js",
|
|
63
|
+
"default": "./esm/index.lazy.js"
|
|
64
|
+
},
|
|
58
65
|
"./package.json": "./package.json"
|
|
59
66
|
},
|
|
60
67
|
"peerDependencies": {
|
|
61
|
-
"@tsparticles/engine": "4.0.
|
|
68
|
+
"@tsparticles/engine": "4.0.1"
|
|
62
69
|
},
|
|
63
70
|
"publishConfig": {
|
|
64
71
|
"access": "public"
|