@tsparticles/shape-image 3.0.0-alpha.1 → 3.0.0-beta.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.
Files changed (95) hide show
  1. package/README.md +16 -12
  2. package/browser/GifUtils/ByteStream.js +44 -0
  3. package/browser/GifUtils/Constants.js +2 -0
  4. package/browser/GifUtils/Enums/DisposalMethod.js +1 -0
  5. package/browser/GifUtils/Types/ApplicationExtension.js +1 -0
  6. package/browser/GifUtils/Types/Frame.js +1 -0
  7. package/browser/GifUtils/Types/GIF.js +1 -0
  8. package/browser/GifUtils/Types/GIFDataHeaders.js +1 -0
  9. package/browser/GifUtils/Types/GIFProgressCallbackFunction.js +1 -0
  10. package/browser/GifUtils/Types/PlainTextData.js +1 -0
  11. package/browser/GifUtils/Utils.js +324 -0
  12. package/browser/ImageDrawer.js +122 -58
  13. package/browser/ImagePreloader.js +33 -0
  14. package/browser/Options/Classes/Preload.js +29 -0
  15. package/browser/Options/Interfaces/IPreload.js +1 -0
  16. package/browser/Utils.js +35 -9
  17. package/browser/index.js +43 -3
  18. package/browser/package.json +1 -0
  19. package/browser/types.js +1 -0
  20. package/cjs/GifUtils/ByteStream.js +48 -0
  21. package/cjs/GifUtils/Constants.js +5 -0
  22. package/cjs/GifUtils/Enums/DisposalMethod.js +2 -0
  23. package/cjs/GifUtils/Types/ApplicationExtension.js +2 -0
  24. package/cjs/GifUtils/Types/Frame.js +2 -0
  25. package/cjs/GifUtils/Types/GIF.js +2 -0
  26. package/cjs/GifUtils/Types/GIFDataHeaders.js +2 -0
  27. package/cjs/GifUtils/Types/GIFProgressCallbackFunction.js +2 -0
  28. package/cjs/GifUtils/Types/PlainTextData.js +2 -0
  29. package/cjs/GifUtils/Utils.js +329 -0
  30. package/cjs/ImageDrawer.js +125 -72
  31. package/cjs/ImagePreloader.js +37 -0
  32. package/cjs/Options/Classes/Preload.js +33 -0
  33. package/cjs/Options/Interfaces/IPreload.js +2 -0
  34. package/cjs/Utils.js +66 -52
  35. package/cjs/index.js +43 -14
  36. package/cjs/package.json +1 -0
  37. package/cjs/types.js +2 -0
  38. package/esm/GifUtils/ByteStream.js +44 -0
  39. package/esm/GifUtils/Constants.js +2 -0
  40. package/esm/GifUtils/Enums/DisposalMethod.js +1 -0
  41. package/esm/GifUtils/Types/ApplicationExtension.js +1 -0
  42. package/esm/GifUtils/Types/Frame.js +1 -0
  43. package/esm/GifUtils/Types/GIF.js +1 -0
  44. package/esm/GifUtils/Types/GIFDataHeaders.js +1 -0
  45. package/esm/GifUtils/Types/GIFProgressCallbackFunction.js +1 -0
  46. package/esm/GifUtils/Types/PlainTextData.js +1 -0
  47. package/esm/GifUtils/Utils.js +324 -0
  48. package/esm/ImageDrawer.js +122 -58
  49. package/esm/ImagePreloader.js +33 -0
  50. package/esm/Options/Classes/Preload.js +29 -0
  51. package/esm/Options/Interfaces/IPreload.js +1 -0
  52. package/esm/Utils.js +35 -9
  53. package/esm/index.js +43 -3
  54. package/esm/package.json +1 -0
  55. package/esm/types.js +1 -0
  56. package/package.json +19 -6
  57. package/report.html +4 -4
  58. package/tsparticles.shape.image.js +676 -73
  59. package/tsparticles.shape.image.min.js +1 -1
  60. package/tsparticles.shape.image.min.js.LICENSE.txt +1 -8
  61. package/types/GifUtils/ByteStream.d.ts +11 -0
  62. package/types/GifUtils/Constants.d.ts +2 -0
  63. package/types/GifUtils/Enums/DisposalMethod.d.ts +10 -0
  64. package/types/GifUtils/Types/ApplicationExtension.d.ts +5 -0
  65. package/types/GifUtils/Types/Frame.d.ts +19 -0
  66. package/types/GifUtils/Types/GIF.d.ts +16 -0
  67. package/types/GifUtils/Types/GIFDataHeaders.d.ts +9 -0
  68. package/types/GifUtils/Types/GIFProgressCallbackFunction.d.ts +2 -0
  69. package/types/GifUtils/Types/PlainTextData.d.ts +11 -0
  70. package/types/GifUtils/Utils.d.ts +4 -0
  71. package/types/IImageShape.d.ts +2 -1
  72. package/types/ImageDrawer.d.ts +9 -9
  73. package/types/ImagePreloader.d.ts +10 -0
  74. package/types/Options/Classes/Preload.d.ts +12 -0
  75. package/types/Options/Interfaces/IPreload.d.ts +8 -0
  76. package/types/Utils.d.ts +16 -6
  77. package/types/index.d.ts +2 -2
  78. package/types/types.d.ts +17 -0
  79. package/umd/GifUtils/ByteStream.js +58 -0
  80. package/umd/GifUtils/Constants.js +15 -0
  81. package/umd/GifUtils/Enums/DisposalMethod.js +12 -0
  82. package/umd/GifUtils/Types/ApplicationExtension.js +12 -0
  83. package/umd/GifUtils/Types/Frame.js +12 -0
  84. package/umd/GifUtils/Types/GIF.js +12 -0
  85. package/umd/GifUtils/Types/GIFDataHeaders.js +12 -0
  86. package/umd/GifUtils/Types/GIFProgressCallbackFunction.js +12 -0
  87. package/umd/GifUtils/Types/PlainTextData.js +12 -0
  88. package/umd/GifUtils/Utils.js +339 -0
  89. package/umd/ImageDrawer.js +124 -60
  90. package/umd/ImagePreloader.js +47 -0
  91. package/umd/Options/Classes/Preload.js +43 -0
  92. package/umd/Options/Interfaces/IPreload.js +12 -0
  93. package/umd/Utils.js +37 -10
  94. package/umd/index.js +44 -4
  95. 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.js"], 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_js_1 = require("./GifUtils/Utils.js");
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
- console.error(`Error tsParticles - loading image: ${image.source}`);
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_js_1.decodeGIF)(image.source);
56
+ image.gifLoopCount = (0, Utils_js_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
- console.error("Error tsParticles - Image not found");
75
+ (0, engine_1.getLogger)().error(`${engine_1.errorPrefix} Image not found`);
56
76
  image.error = true;
57
77
  }
58
- if (!image.error) {
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
- var _a, _b, _c;
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
- data: Object.assign(Object.assign({}, image), { svgData: svgColoredData }),
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: (_c = imageData.replaceColor) !== null && _c !== void 0 ? _c : imageData.replace_color,
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 = Object.assign(Object.assign({}, image), { error: false, loading: true });
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.js", "./ImageDrawer.js", "./ImagePreloader.js", "@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 ImageDrawer_1 = require("./ImageDrawer");
14
- async function loadImageShape(engine) {
15
- await engine.addShape(["image", "images"], new ImageDrawer_1.ImageDrawer());
13
+ const Utils_js_1 = require("./Utils.js");
14
+ const ImageDrawer_js_1 = require("./ImageDrawer.js");
15
+ const ImagePreloader_js_1 = require("./ImagePreloader.js");
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_js_1.loadGifImage : data.replaceColor ? Utils_js_1.downloadSvgImage : Utils_js_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_js_1.ImagePreloaderPlugin(engine);
54
+ await engine.addPlugin(preloader, refresh);
55
+ await engine.addShape(["image", "images"], new ImageDrawer_js_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
+ });