@tsparticles/plugin-emitters-shape-canvas 3.0.0-beta.4
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 +79 -0
- package/browser/EmittersCanvasShape.js +91 -0
- package/browser/EmittersCanvasShapeGenerator.js +9 -0
- package/browser/Options/Classes/EmittersCanvasShapeOptions.js +33 -0
- package/browser/Options/Classes/PixelsOptions.js +13 -0
- package/browser/Options/Classes/TextFontOptions.js +29 -0
- package/browser/Options/Classes/TextLinesOptions.js +17 -0
- package/browser/Options/Classes/TextOptions.js +23 -0
- package/browser/Options/Interfaces/IEmittersCanvasShapeOptions.js +1 -0
- package/browser/Options/Interfaces/IPixelsOptions.js +1 -0
- package/browser/Options/Interfaces/ITextFontOptions.js +1 -0
- package/browser/Options/Interfaces/ITextLinesOptions.js +1 -0
- package/browser/Options/Interfaces/ITextOptions.js +1 -0
- package/browser/index.js +7 -0
- package/browser/package.json +1 -0
- package/browser/types.js +1 -0
- package/browser/utils.js +84 -0
- package/cjs/EmittersCanvasShape.js +95 -0
- package/cjs/EmittersCanvasShapeGenerator.js +13 -0
- package/cjs/Options/Classes/EmittersCanvasShapeOptions.js +37 -0
- package/cjs/Options/Classes/PixelsOptions.js +17 -0
- package/cjs/Options/Classes/TextFontOptions.js +33 -0
- package/cjs/Options/Classes/TextLinesOptions.js +21 -0
- package/cjs/Options/Classes/TextOptions.js +27 -0
- package/cjs/Options/Interfaces/IEmittersCanvasShapeOptions.js +2 -0
- package/cjs/Options/Interfaces/IPixelsOptions.js +2 -0
- package/cjs/Options/Interfaces/ITextFontOptions.js +2 -0
- package/cjs/Options/Interfaces/ITextLinesOptions.js +2 -0
- package/cjs/Options/Interfaces/ITextOptions.js +2 -0
- package/cjs/index.js +11 -0
- package/cjs/package.json +1 -0
- package/cjs/types.js +2 -0
- package/cjs/utils.js +90 -0
- package/esm/EmittersCanvasShape.js +91 -0
- package/esm/EmittersCanvasShapeGenerator.js +9 -0
- package/esm/Options/Classes/EmittersCanvasShapeOptions.js +33 -0
- package/esm/Options/Classes/PixelsOptions.js +13 -0
- package/esm/Options/Classes/TextFontOptions.js +29 -0
- package/esm/Options/Classes/TextLinesOptions.js +17 -0
- package/esm/Options/Classes/TextOptions.js +23 -0
- package/esm/Options/Interfaces/IEmittersCanvasShapeOptions.js +1 -0
- package/esm/Options/Interfaces/IPixelsOptions.js +1 -0
- package/esm/Options/Interfaces/ITextFontOptions.js +1 -0
- package/esm/Options/Interfaces/ITextLinesOptions.js +1 -0
- package/esm/Options/Interfaces/ITextOptions.js +1 -0
- package/esm/index.js +7 -0
- package/esm/package.json +1 -0
- package/esm/types.js +1 -0
- package/esm/utils.js +84 -0
- package/package.json +109 -0
- package/report.html +39 -0
- package/tsparticles.plugin.emitters.shape.canvas.js +452 -0
- package/tsparticles.plugin.emitters.shape.canvas.min.js +2 -0
- package/tsparticles.plugin.emitters.shape.canvas.min.js.LICENSE.txt +1 -0
- package/types/EmittersCanvasShape.d.ts +13 -0
- package/types/EmittersCanvasShapeGenerator.d.ts +6 -0
- package/types/Options/Classes/EmittersCanvasShapeOptions.d.ts +15 -0
- package/types/Options/Classes/PixelsOptions.d.ts +7 -0
- package/types/Options/Classes/TextFontOptions.d.ts +11 -0
- package/types/Options/Classes/TextLinesOptions.d.ts +8 -0
- package/types/Options/Classes/TextOptions.d.ts +12 -0
- package/types/Options/Interfaces/IEmittersCanvasShapeOptions.d.ts +12 -0
- package/types/Options/Interfaces/IPixelsOptions.d.ts +3 -0
- package/types/Options/Interfaces/ITextFontOptions.d.ts +7 -0
- package/types/Options/Interfaces/ITextLinesOptions.d.ts +4 -0
- package/types/Options/Interfaces/ITextOptions.d.ts +8 -0
- package/types/index.d.ts +2 -0
- package/types/types.d.ts +12 -0
- package/types/utils.d.ts +6 -0
- package/umd/EmittersCanvasShape.js +105 -0
- package/umd/EmittersCanvasShapeGenerator.js +23 -0
- package/umd/Options/Classes/EmittersCanvasShapeOptions.js +47 -0
- package/umd/Options/Classes/PixelsOptions.js +27 -0
- package/umd/Options/Classes/TextFontOptions.js +43 -0
- package/umd/Options/Classes/TextLinesOptions.js +31 -0
- package/umd/Options/Classes/TextOptions.js +37 -0
- package/umd/Options/Interfaces/IEmittersCanvasShapeOptions.js +12 -0
- package/umd/Options/Interfaces/IPixelsOptions.js +12 -0
- package/umd/Options/Interfaces/ITextFontOptions.js +12 -0
- package/umd/Options/Interfaces/ITextLinesOptions.js +12 -0
- package/umd/Options/Interfaces/ITextOptions.js +12 -0
- package/umd/index.js +21 -0
- package/umd/types.js +12 -0
- package/umd/utils.js +100 -0
|
@@ -0,0 +1,452 @@
|
|
|
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-beta.4
|
|
8
|
+
*/
|
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
11
|
+
module.exports = factory(require("@tsparticles/plugin-emitters"), require("@tsparticles/engine"));
|
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
|
13
|
+
define(["@tsparticles/plugin-emitters", "@tsparticles/engine"], factory);
|
|
14
|
+
else {
|
|
15
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/plugin-emitters"), require("@tsparticles/engine")) : factory(root["window"], root["window"]);
|
|
16
|
+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
17
|
+
}
|
|
18
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__68__, __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
|
+
/***/ 68:
|
|
31
|
+
/***/ ((module) => {
|
|
32
|
+
|
|
33
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__68__;
|
|
34
|
+
|
|
35
|
+
/***/ })
|
|
36
|
+
|
|
37
|
+
/******/ });
|
|
38
|
+
/************************************************************************/
|
|
39
|
+
/******/ // The module cache
|
|
40
|
+
/******/ var __webpack_module_cache__ = {};
|
|
41
|
+
/******/
|
|
42
|
+
/******/ // The require function
|
|
43
|
+
/******/ function __webpack_require__(moduleId) {
|
|
44
|
+
/******/ // Check if module is in cache
|
|
45
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
46
|
+
/******/ if (cachedModule !== undefined) {
|
|
47
|
+
/******/ return cachedModule.exports;
|
|
48
|
+
/******/ }
|
|
49
|
+
/******/ // Create a new module (and put it into the cache)
|
|
50
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
51
|
+
/******/ // no module.id needed
|
|
52
|
+
/******/ // no module.loaded needed
|
|
53
|
+
/******/ exports: {}
|
|
54
|
+
/******/ };
|
|
55
|
+
/******/
|
|
56
|
+
/******/ // Execute the module function
|
|
57
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
58
|
+
/******/
|
|
59
|
+
/******/ // Return the exports of the module
|
|
60
|
+
/******/ return module.exports;
|
|
61
|
+
/******/ }
|
|
62
|
+
/******/
|
|
63
|
+
/************************************************************************/
|
|
64
|
+
/******/ /* webpack/runtime/define property getters */
|
|
65
|
+
/******/ (() => {
|
|
66
|
+
/******/ // define getter functions for harmony exports
|
|
67
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
68
|
+
/******/ for(var key in definition) {
|
|
69
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
70
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
71
|
+
/******/ }
|
|
72
|
+
/******/ }
|
|
73
|
+
/******/ };
|
|
74
|
+
/******/ })();
|
|
75
|
+
/******/
|
|
76
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
77
|
+
/******/ (() => {
|
|
78
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
79
|
+
/******/ })();
|
|
80
|
+
/******/
|
|
81
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
82
|
+
/******/ (() => {
|
|
83
|
+
/******/ // define __esModule on exports
|
|
84
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
85
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
86
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
87
|
+
/******/ }
|
|
88
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
89
|
+
/******/ };
|
|
90
|
+
/******/ })();
|
|
91
|
+
/******/
|
|
92
|
+
/************************************************************************/
|
|
93
|
+
var __webpack_exports__ = {};
|
|
94
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
95
|
+
(() => {
|
|
96
|
+
// ESM COMPAT FLAG
|
|
97
|
+
__webpack_require__.r(__webpack_exports__);
|
|
98
|
+
|
|
99
|
+
// EXPORTS
|
|
100
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
101
|
+
loadEmittersShapeCanvas: () => (/* binding */ loadEmittersShapeCanvas)
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/plugin-emitters","commonjs2":"@tsparticles/plugin-emitters","amd":"@tsparticles/plugin-emitters","root":"window"}
|
|
105
|
+
var plugin_emitters_root_window_ = __webpack_require__(68);
|
|
106
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
107
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
108
|
+
;// CONCATENATED MODULE: ./dist/browser/utils.js
|
|
109
|
+
|
|
110
|
+
function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
111
|
+
const imageData = ctx.getImageData(0, 0, size.width, size.height).data;
|
|
112
|
+
if (clear) {
|
|
113
|
+
ctx.clearRect(0, 0, size.width, size.height);
|
|
114
|
+
}
|
|
115
|
+
const pixels = [];
|
|
116
|
+
for (let i = 0; i < imageData.length; i += offset) {
|
|
117
|
+
const idx = i / offset,
|
|
118
|
+
pos = {
|
|
119
|
+
x: idx % size.width,
|
|
120
|
+
y: Math.floor(idx / size.width)
|
|
121
|
+
};
|
|
122
|
+
if (!pixels[pos.y]) {
|
|
123
|
+
pixels[pos.y] = [];
|
|
124
|
+
}
|
|
125
|
+
pixels[pos.y][pos.x] = {
|
|
126
|
+
r: imageData[i],
|
|
127
|
+
g: imageData[i + 1],
|
|
128
|
+
b: imageData[i + 2],
|
|
129
|
+
a: imageData[i + 3] / 255
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
pixels,
|
|
134
|
+
width: Math.min(...pixels.map(row => row.length)),
|
|
135
|
+
height: pixels.length
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function getImageData(src, offset) {
|
|
139
|
+
const image = new Image();
|
|
140
|
+
image.crossOrigin = "Anonymous";
|
|
141
|
+
const p = new Promise((resolve, reject) => {
|
|
142
|
+
image.onerror = reject;
|
|
143
|
+
image.onload = () => {
|
|
144
|
+
const canvas = document.createElement("canvas");
|
|
145
|
+
canvas.width = image.width;
|
|
146
|
+
canvas.height = image.height;
|
|
147
|
+
const context = canvas.getContext("2d");
|
|
148
|
+
if (!context) {
|
|
149
|
+
return reject(new Error(`${engine_root_window_.errorPrefix} Could not get canvas context`));
|
|
150
|
+
}
|
|
151
|
+
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
152
|
+
resolve(getCanvasImageData(context, canvas, offset));
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
image.src = src;
|
|
156
|
+
return p;
|
|
157
|
+
}
|
|
158
|
+
function getTextData(textOptions, offset, fill) {
|
|
159
|
+
const canvas = document.createElement("canvas"),
|
|
160
|
+
context = canvas.getContext("2d"),
|
|
161
|
+
{
|
|
162
|
+
font,
|
|
163
|
+
text,
|
|
164
|
+
lines: linesOptions,
|
|
165
|
+
color
|
|
166
|
+
} = textOptions;
|
|
167
|
+
if (!text || !context) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const lines = text.split(linesOptions.separator),
|
|
171
|
+
fontSize = (0,engine_root_window_.isNumber)(font.size) ? `${font.size}px` : font.size,
|
|
172
|
+
linesData = [];
|
|
173
|
+
let maxWidth = 0,
|
|
174
|
+
totalHeight = 0;
|
|
175
|
+
for (const line of lines) {
|
|
176
|
+
context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
|
|
177
|
+
const measure = context.measureText(line),
|
|
178
|
+
lineData = {
|
|
179
|
+
measure,
|
|
180
|
+
text: line,
|
|
181
|
+
height: measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent,
|
|
182
|
+
width: measure.width
|
|
183
|
+
};
|
|
184
|
+
maxWidth = Math.max(maxWidth || 0, lineData.width);
|
|
185
|
+
totalHeight += lineData.height + linesOptions.spacing;
|
|
186
|
+
linesData.push(lineData);
|
|
187
|
+
}
|
|
188
|
+
canvas.width = maxWidth;
|
|
189
|
+
canvas.height = totalHeight;
|
|
190
|
+
let currentHeight = 0;
|
|
191
|
+
for (const line of linesData) {
|
|
192
|
+
context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
|
|
193
|
+
if (fill) {
|
|
194
|
+
context.fillStyle = color;
|
|
195
|
+
context.fillText(line.text, 0, currentHeight + line.measure.actualBoundingBoxAscent);
|
|
196
|
+
} else {
|
|
197
|
+
context.strokeStyle = color;
|
|
198
|
+
context.strokeText(line.text, 0, currentHeight + line.measure.actualBoundingBoxAscent);
|
|
199
|
+
}
|
|
200
|
+
currentHeight += line.height + linesOptions.spacing;
|
|
201
|
+
}
|
|
202
|
+
return getCanvasImageData(context, canvas, offset);
|
|
203
|
+
}
|
|
204
|
+
;// CONCATENATED MODULE: ./dist/browser/EmittersCanvasShape.js
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class EmittersCanvasShape extends plugin_emitters_root_window_.EmitterShapeBase {
|
|
209
|
+
constructor(position, size, fill, options) {
|
|
210
|
+
super(position, size, fill, options);
|
|
211
|
+
const filter = options.filter;
|
|
212
|
+
let filterFunc = pixel => pixel.a > 0;
|
|
213
|
+
if (filter !== undefined) {
|
|
214
|
+
if ((0,engine_root_window_.isString)(filter)) {
|
|
215
|
+
if (Object.hasOwn(window, filter)) {
|
|
216
|
+
const wndFilter = window[filter];
|
|
217
|
+
if ((0,engine_root_window_.isFunction)(wndFilter)) {
|
|
218
|
+
filterFunc = wndFilter;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
filterFunc = filter;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
this.filter = filterFunc;
|
|
226
|
+
this.scale = options.scale;
|
|
227
|
+
this.pixelData = {
|
|
228
|
+
pixels: [],
|
|
229
|
+
height: 0,
|
|
230
|
+
width: 0
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
async init() {
|
|
234
|
+
let pixelData;
|
|
235
|
+
const options = this.options,
|
|
236
|
+
selector = options.selector,
|
|
237
|
+
pixels = options.pixels,
|
|
238
|
+
image = options.image,
|
|
239
|
+
element = options.element,
|
|
240
|
+
text = options.text,
|
|
241
|
+
offset = pixels.offset;
|
|
242
|
+
if (image) {
|
|
243
|
+
const url = image.src;
|
|
244
|
+
if (!url) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
pixelData = await getImageData(url, offset);
|
|
248
|
+
} else if (text) {
|
|
249
|
+
const data = getTextData(text, offset, this.fill);
|
|
250
|
+
if (!data) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
pixelData = data;
|
|
254
|
+
} else if (element || selector) {
|
|
255
|
+
const canvas = element || selector && document.querySelector(selector);
|
|
256
|
+
if (!canvas) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const context = canvas.getContext("2d");
|
|
260
|
+
if (!context) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
pixelData = getCanvasImageData(context, canvas, offset);
|
|
264
|
+
}
|
|
265
|
+
if (!pixelData) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
this.pixelData = pixelData;
|
|
269
|
+
}
|
|
270
|
+
async randomPosition() {
|
|
271
|
+
const {
|
|
272
|
+
height,
|
|
273
|
+
width
|
|
274
|
+
} = this.pixelData,
|
|
275
|
+
data = this.pixelData,
|
|
276
|
+
position = this.position,
|
|
277
|
+
scale = this.scale;
|
|
278
|
+
const positionOffset = {
|
|
279
|
+
x: position.x - width * scale / 2,
|
|
280
|
+
y: position.y - height * scale / 2
|
|
281
|
+
};
|
|
282
|
+
for (let i = 0; i < 100; i++) {
|
|
283
|
+
const nextIndex = Math.floor((0,engine_root_window_.getRandom)() * width * height),
|
|
284
|
+
pixelPos = {
|
|
285
|
+
x: nextIndex % width,
|
|
286
|
+
y: Math.floor(nextIndex / width)
|
|
287
|
+
},
|
|
288
|
+
pixel = data.pixels[pixelPos.y][pixelPos.x],
|
|
289
|
+
shouldCreateParticle = this.filter(pixel);
|
|
290
|
+
if (!shouldCreateParticle) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
position: {
|
|
295
|
+
x: pixelPos.x * scale + positionOffset.x,
|
|
296
|
+
y: pixelPos.y * scale + positionOffset.y
|
|
297
|
+
},
|
|
298
|
+
color: {
|
|
299
|
+
...pixel
|
|
300
|
+
},
|
|
301
|
+
opacity: pixel.a
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
resize(position, size) {
|
|
307
|
+
super.resize(position, size);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/PixelsOptions.js
|
|
311
|
+
class PixelsOptions {
|
|
312
|
+
constructor() {
|
|
313
|
+
this.offset = 4;
|
|
314
|
+
}
|
|
315
|
+
load(data) {
|
|
316
|
+
if (!data) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (data.offset !== undefined) {
|
|
320
|
+
this.offset = data.offset;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/TextFontOptions.js
|
|
325
|
+
class TextFontOptions {
|
|
326
|
+
constructor() {
|
|
327
|
+
this.family = "Verdana";
|
|
328
|
+
this.size = 32;
|
|
329
|
+
this.style = "";
|
|
330
|
+
this.variant = "";
|
|
331
|
+
this.weight = "";
|
|
332
|
+
}
|
|
333
|
+
load(data) {
|
|
334
|
+
if (!data) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (data.family !== undefined) {
|
|
338
|
+
this.family = data.family;
|
|
339
|
+
}
|
|
340
|
+
if (data.size !== undefined) {
|
|
341
|
+
this.size = data.size;
|
|
342
|
+
}
|
|
343
|
+
if (data.style !== undefined) {
|
|
344
|
+
this.style = data.style;
|
|
345
|
+
}
|
|
346
|
+
if (data.variant !== undefined) {
|
|
347
|
+
this.variant = data.variant;
|
|
348
|
+
}
|
|
349
|
+
if (data.weight !== undefined) {
|
|
350
|
+
this.weight = data.weight;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/TextLinesOptions.js
|
|
355
|
+
class TextLinesOptions {
|
|
356
|
+
constructor() {
|
|
357
|
+
this.separator = "\n";
|
|
358
|
+
this.spacing = 0;
|
|
359
|
+
}
|
|
360
|
+
load(data) {
|
|
361
|
+
if (!data) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (data.separator !== undefined) {
|
|
365
|
+
this.separator = data.separator;
|
|
366
|
+
}
|
|
367
|
+
if (data.spacing !== undefined) {
|
|
368
|
+
this.spacing = data.spacing;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/TextOptions.js
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
class TextOptions {
|
|
376
|
+
constructor() {
|
|
377
|
+
this.color = "#000000";
|
|
378
|
+
this.font = new TextFontOptions();
|
|
379
|
+
this.lines = new TextLinesOptions();
|
|
380
|
+
this.text = "";
|
|
381
|
+
}
|
|
382
|
+
load(data) {
|
|
383
|
+
if (!data) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (data.color !== undefined) {
|
|
387
|
+
this.color = data.color;
|
|
388
|
+
}
|
|
389
|
+
this.font.load(data.font);
|
|
390
|
+
this.lines.load(data.lines);
|
|
391
|
+
if (data.text !== undefined) {
|
|
392
|
+
this.text = data.text;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmittersCanvasShapeOptions.js
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
class EmittersCanvasShapeOptions {
|
|
400
|
+
constructor() {
|
|
401
|
+
this.filter = pixel => pixel.a > 0;
|
|
402
|
+
this.pixels = new PixelsOptions();
|
|
403
|
+
this.scale = 1;
|
|
404
|
+
this.selector = "";
|
|
405
|
+
this.text = new TextOptions();
|
|
406
|
+
}
|
|
407
|
+
load(data) {
|
|
408
|
+
if (!data) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (data.element !== undefined) {
|
|
412
|
+
this.element = data.element;
|
|
413
|
+
}
|
|
414
|
+
if (data.filter !== undefined) {
|
|
415
|
+
this.filter = data.filter;
|
|
416
|
+
}
|
|
417
|
+
this.pixels.load(data.pixels);
|
|
418
|
+
if (data.scale !== undefined) {
|
|
419
|
+
this.scale = data.scale;
|
|
420
|
+
}
|
|
421
|
+
if (data.selector !== undefined) {
|
|
422
|
+
this.selector = data.selector;
|
|
423
|
+
}
|
|
424
|
+
if (data.image !== undefined) {
|
|
425
|
+
this.image = data.image;
|
|
426
|
+
}
|
|
427
|
+
this.text.load(data.text);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
;// CONCATENATED MODULE: ./dist/browser/EmittersCanvasShapeGenerator.js
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
class EmittersCanvasShapeGenerator {
|
|
434
|
+
generate(position, size, fill, options) {
|
|
435
|
+
const shapeOptions = new EmittersCanvasShapeOptions();
|
|
436
|
+
shapeOptions.load(options);
|
|
437
|
+
return new EmittersCanvasShape(position, size, fill, shapeOptions);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
441
|
+
|
|
442
|
+
async function loadEmittersShapeCanvas(engine, refresh = true) {
|
|
443
|
+
const emittersEngine = engine;
|
|
444
|
+
emittersEngine.addEmitterShapeGenerator && emittersEngine.addEmitterShapeGenerator("canvas", new EmittersCanvasShapeGenerator());
|
|
445
|
+
await emittersEngine.refresh(refresh);
|
|
446
|
+
}
|
|
447
|
+
})();
|
|
448
|
+
|
|
449
|
+
/******/ return __webpack_exports__;
|
|
450
|
+
/******/ })()
|
|
451
|
+
;
|
|
452
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.plugin.emitters.shape.canvas.min.js.LICENSE.txt */
|
|
2
|
+
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/plugin-emitters","@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine")):e(t.window,t.window);for(var s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(this,((t,e)=>(()=>{"use strict";var i={533:t=>{t.exports=e},68:e=>{e.exports=t}},s={};function o(t){var e=s[t];if(void 0!==e)return e.exports;var r=s[t]={exports:{}};return i[t](r,r.exports,o),r.exports}o.d=(t,e)=>{for(var i in e)o.o(e,i)&&!o.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{o.r(r),o.d(r,{loadEmittersShapeCanvas:()=>f});var t=o(68),e=o(533);function i(t,e,i,s=!0){const o=t.getImageData(0,0,e.width,e.height).data;s&&t.clearRect(0,0,e.width,e.height);const r=[];for(let t=0;t<o.length;t+=i){const s=t/i,n={x:s%e.width,y:Math.floor(s/e.width)};r[n.y]||(r[n.y]=[]),r[n.y][n.x]={r:o[t],g:o[t+1],b:o[t+2],a:o[t+3]/255}}return{pixels:r,width:Math.min(...r.map((t=>t.length))),height:r.length}}class s extends t.EmitterShapeBase{constructor(t,i,s,o){super(t,i,s,o);const r=o.filter;let n=t=>t.a>0;if(void 0!==r)if((0,e.isString)(r)){if(Object.hasOwn(window,r)){const t=window[r];(0,e.isFunction)(t)&&(n=t)}}else n=r;this.filter=n,this.scale=o.scale,this.pixelData={pixels:[],height:0,width:0}}async init(){let t;const s=this.options,o=s.selector,r=s.pixels,n=s.image,a=s.element,l=s.text,c=r.offset;if(n){const s=n.src;if(!s)return;t=await function(t,s){const o=new Image;o.crossOrigin="Anonymous";const r=new Promise(((t,r)=>{o.onerror=r,o.onload=()=>{const n=document.createElement("canvas");n.width=o.width,n.height=o.height;const a=n.getContext("2d");if(!a)return r(new Error(`${e.errorPrefix} Could not get canvas context`));a.drawImage(o,0,0,o.width,o.height,0,0,n.width,n.height),t(i(a,n,s))}}));return o.src=t,r}(s,c)}else if(l){const s=function(t,s,o){const r=document.createElement("canvas"),n=r.getContext("2d"),{font:a,text:l,lines:c,color:h}=t;if(!l||!n)return;const d=l.split(c.separator),f=(0,e.isNumber)(a.size)?`${a.size}px`:a.size,p=[];let u=0,g=0;for(const t of d){n.font=`${a.style||""} ${a.variant||""} ${a.weight||""} ${f} ${a.family}`;const e=n.measureText(t),i={measure:e,text:t,height:e.actualBoundingBoxAscent+e.actualBoundingBoxDescent,width:e.width};u=Math.max(u||0,i.width),g+=i.height+c.spacing,p.push(i)}r.width=u,r.height=g;let x=0;for(const t of p)n.font=`${a.style||""} ${a.variant||""} ${a.weight||""} ${f} ${a.family}`,o?(n.fillStyle=h,n.fillText(t.text,0,x+t.measure.actualBoundingBoxAscent)):(n.strokeStyle=h,n.strokeText(t.text,0,x+t.measure.actualBoundingBoxAscent)),x+=t.height+c.spacing;return i(n,r,s)}(l,c,this.fill);if(!s)return;t=s}else if(a||o){const e=a||o&&document.querySelector(o);if(!e)return;const s=e.getContext("2d");if(!s)return;t=i(s,e,c)}t&&(this.pixelData=t)}async randomPosition(){const{height:t,width:i}=this.pixelData,s=this.pixelData,o=this.position,r=this.scale,n=o.x-i*r/2,a=o.y-t*r/2;for(let o=0;o<100;o++){const o=Math.floor((0,e.getRandom)()*i*t),l={x:o%i,y:Math.floor(o/i)},c=s.pixels[l.y][l.x];if(this.filter(c))return{position:{x:l.x*r+n,y:l.y*r+a},color:{...c},opacity:c.a}}return null}resize(t,e){super.resize(t,e)}}class n{constructor(){this.offset=4}load(t){t&&void 0!==t.offset&&(this.offset=t.offset)}}class a{constructor(){this.family="Verdana",this.size=32,this.style="",this.variant="",this.weight=""}load(t){t&&(void 0!==t.family&&(this.family=t.family),void 0!==t.size&&(this.size=t.size),void 0!==t.style&&(this.style=t.style),void 0!==t.variant&&(this.variant=t.variant),void 0!==t.weight&&(this.weight=t.weight))}}class l{constructor(){this.separator="\n",this.spacing=0}load(t){t&&(void 0!==t.separator&&(this.separator=t.separator),void 0!==t.spacing&&(this.spacing=t.spacing))}}class c{constructor(){this.color="#000000",this.font=new a,this.lines=new l,this.text=""}load(t){t&&(void 0!==t.color&&(this.color=t.color),this.font.load(t.font),this.lines.load(t.lines),void 0!==t.text&&(this.text=t.text))}}class h{constructor(){this.filter=t=>t.a>0,this.pixels=new n,this.scale=1,this.selector="",this.text=new c}load(t){t&&(void 0!==t.element&&(this.element=t.element),void 0!==t.filter&&(this.filter=t.filter),this.pixels.load(t.pixels),void 0!==t.scale&&(this.scale=t.scale),void 0!==t.selector&&(this.selector=t.selector),void 0!==t.image&&(this.image=t.image),this.text.load(t.text))}}class d{generate(t,e,i,o){const r=new h;return r.load(o),new s(t,e,i,r)}}async function f(t,e=!0){const i=t;i.addEmitterShapeGenerator&&i.addEmitterShapeGenerator("canvas",new d),await i.refresh(e)}})(),r})()));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Emitters Shape Canvas Plugin v3.0.0-beta.4 by Matteo Bruni */
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EmitterShapeBase, type IRandomPositionData } from "@tsparticles/plugin-emitters";
|
|
2
|
+
import { type ICoordinates, type IDimension, type IRgba } from "@tsparticles/engine";
|
|
3
|
+
import type { CanvasPixelData } from "./types";
|
|
4
|
+
import type { EmittersCanvasShapeOptions } from "./Options/Classes/EmittersCanvasShapeOptions.js";
|
|
5
|
+
export declare class EmittersCanvasShape extends EmitterShapeBase<EmittersCanvasShapeOptions> {
|
|
6
|
+
filter: (pixel: IRgba) => boolean;
|
|
7
|
+
pixelData: CanvasPixelData;
|
|
8
|
+
scale: number;
|
|
9
|
+
constructor(position: ICoordinates, size: IDimension, fill: boolean, options: EmittersCanvasShapeOptions);
|
|
10
|
+
init(): Promise<void>;
|
|
11
|
+
randomPosition(): Promise<IRandomPositionData | null>;
|
|
12
|
+
resize(position: ICoordinates, size: IDimension): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ICoordinates, type IDimension } from "@tsparticles/engine";
|
|
2
|
+
import type { IEmitterShape, IEmitterShapeGenerator } from "@tsparticles/plugin-emitters";
|
|
3
|
+
import type { IEmittersCanvasShapeOptions } from "./Options/Interfaces/IEmittersCanvasShapeOptions.js";
|
|
4
|
+
export declare class EmittersCanvasShapeGenerator implements IEmitterShapeGenerator<IEmittersCanvasShapeOptions> {
|
|
5
|
+
generate(position: ICoordinates, size: IDimension, fill: boolean, options: IEmittersCanvasShapeOptions): IEmitterShape;
|
|
6
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IOptionLoader, IRgba, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { IEmittersCanvasShapeOptions } from "../Interfaces/IEmittersCanvasShapeOptions.js";
|
|
3
|
+
import { PixelsOptions } from "./PixelsOptions.js";
|
|
4
|
+
import { TextOptions } from "./TextOptions.js";
|
|
5
|
+
export declare class EmittersCanvasShapeOptions implements IEmittersCanvasShapeOptions, IOptionLoader<IEmittersCanvasShapeOptions> {
|
|
6
|
+
element?: HTMLCanvasElement;
|
|
7
|
+
filter: string | ((pixel: IRgba) => boolean);
|
|
8
|
+
image?: HTMLImageElement;
|
|
9
|
+
pixels: PixelsOptions;
|
|
10
|
+
scale: number;
|
|
11
|
+
selector: string;
|
|
12
|
+
text: TextOptions;
|
|
13
|
+
constructor();
|
|
14
|
+
load(data?: RecursivePartial<IEmittersCanvasShapeOptions> | undefined): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { IPixelsOptions } from "../Interfaces/IPixelsOptions.js";
|
|
3
|
+
export declare class PixelsOptions implements IPixelsOptions, IOptionLoader<IPixelsOptions> {
|
|
4
|
+
offset: number;
|
|
5
|
+
constructor();
|
|
6
|
+
load(data?: RecursivePartial<IPixelsOptions> | undefined): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ITextFontOptions } from "../Interfaces/ITextFontOptions.js";
|
|
3
|
+
export declare class TextFontOptions implements ITextFontOptions, IOptionLoader<ITextFontOptions> {
|
|
4
|
+
family: string;
|
|
5
|
+
size: string | number;
|
|
6
|
+
style: string;
|
|
7
|
+
variant: string;
|
|
8
|
+
weight: string;
|
|
9
|
+
constructor();
|
|
10
|
+
load(data?: RecursivePartial<ITextFontOptions> | undefined): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ITextLinesOptions } from "../Interfaces/ITextLinesOptions.js";
|
|
3
|
+
export declare class TextLinesOptions implements ITextLinesOptions, IOptionLoader<ITextLinesOptions> {
|
|
4
|
+
separator: string;
|
|
5
|
+
spacing: number;
|
|
6
|
+
constructor();
|
|
7
|
+
load(data?: RecursivePartial<ITextLinesOptions> | undefined): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ITextOptions } from "../Interfaces/ITextOptions.js";
|
|
3
|
+
import { TextFontOptions } from "./TextFontOptions.js";
|
|
4
|
+
import { TextLinesOptions } from "./TextLinesOptions.js";
|
|
5
|
+
export declare class TextOptions implements ITextOptions, IOptionLoader<ITextOptions> {
|
|
6
|
+
color: string;
|
|
7
|
+
font: TextFontOptions;
|
|
8
|
+
lines: TextLinesOptions;
|
|
9
|
+
text: string;
|
|
10
|
+
constructor();
|
|
11
|
+
load(data?: RecursivePartial<ITextOptions> | undefined): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IPixelsOptions } from "./IPixelsOptions.js";
|
|
2
|
+
import type { IRgba } from "@tsparticles/engine";
|
|
3
|
+
import type { ITextOptions } from "./ITextOptions.js";
|
|
4
|
+
export interface IEmittersCanvasShapeOptions {
|
|
5
|
+
element?: HTMLCanvasElement;
|
|
6
|
+
filter: string | ((pixel: IRgba) => boolean);
|
|
7
|
+
image?: HTMLImageElement;
|
|
8
|
+
pixels: IPixelsOptions;
|
|
9
|
+
scale: number;
|
|
10
|
+
selector: string;
|
|
11
|
+
text: ITextOptions;
|
|
12
|
+
}
|
package/types/index.d.ts
ADDED
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IRgba } from "@tsparticles/engine";
|
|
2
|
+
export type CanvasPixelData = {
|
|
3
|
+
height: number;
|
|
4
|
+
pixels: IRgba[][];
|
|
5
|
+
width: number;
|
|
6
|
+
};
|
|
7
|
+
export type TextLineData = {
|
|
8
|
+
height: number;
|
|
9
|
+
measure: TextMetrics;
|
|
10
|
+
text: string;
|
|
11
|
+
width: number;
|
|
12
|
+
};
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CanvasPixelData } from "./types.js";
|
|
2
|
+
import type { IDimension } from "@tsparticles/engine";
|
|
3
|
+
import type { TextOptions } from "./Options/Classes/TextOptions.js";
|
|
4
|
+
export declare function getCanvasImageData(ctx: CanvasRenderingContext2D, size: IDimension, offset: number, clear?: boolean): CanvasPixelData;
|
|
5
|
+
export declare function getImageData(src: string, offset: number): Promise<CanvasPixelData>;
|
|
6
|
+
export declare function getTextData(textOptions: TextOptions, offset: number, fill: boolean): CanvasPixelData | undefined;
|