tsparticles-shape-image
Advanced tools
Comparing version 2.0.0-alpha.3 to 2.0.0-alpha.4
@@ -1,8 +0,5 @@ | ||
import type { Container, IImage, IParticle, IShapeDrawer, Particle } from "tsparticles-core"; | ||
interface ContainerImage { | ||
id: string; | ||
images: IImage[]; | ||
} | ||
import type { Container, IParticle, IShapeDrawer, Particle } from "tsparticles-engine"; | ||
import { ContainerImage, IImage } from "./Utils"; | ||
export declare class ImageDrawer implements IShapeDrawer { | ||
images: ContainerImage[]; | ||
#private; | ||
constructor(); | ||
@@ -14,2 +11,3 @@ getSidesCount(): number; | ||
destroy(): void; | ||
private initShape; | ||
private loadImageShape; | ||
@@ -19,2 +17,1 @@ draw(context: CanvasRenderingContext2D, particle: IParticle, radius: number, opacity: number): void; | ||
} | ||
export {}; |
@@ -10,6 +10,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { downloadSvgImage, isInArray, loadImage, replaceColorSvg } from "tsparticles-core"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
}; | ||
var _images; | ||
import { downloadSvgImage, loadImage, replaceColorSvg, } from "./Utils"; | ||
export class ImageDrawer { | ||
constructor() { | ||
this.images = []; | ||
_images.set(this, void 0); | ||
__classPrivateFieldSet(this, _images, []); | ||
} | ||
@@ -20,5 +35,5 @@ getSidesCount() { | ||
getImages(container) { | ||
const containerImages = this.images.filter((t) => t.id === container.id); | ||
if (!containerImages.length) { | ||
this.images.push({ | ||
const containerImages = __classPrivateFieldGet(this, _images).find((t) => t.id === container.id); | ||
if (!containerImages) { | ||
__classPrivateFieldGet(this, _images).push({ | ||
id: container.id, | ||
@@ -30,3 +45,3 @@ images: [], | ||
else { | ||
return containerImages[0]; | ||
return containerImages; | ||
} | ||
@@ -39,10 +54,13 @@ } | ||
init(container) { | ||
const options = container.options; | ||
const shapeOptions = options.particles.shape; | ||
return this.initShape(container, shapeOptions); | ||
} | ||
destroy() { | ||
__classPrivateFieldSet(this, _images, []); | ||
} | ||
initShape(container, shapeOptions) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const options = container.options; | ||
const shapeOptions = options.particles.shape; | ||
if (!isInArray("image", shapeOptions.type) && !isInArray("images", shapeOptions.type)) { | ||
return; | ||
} | ||
const imageOptions = (_a = shapeOptions.options["images"]) !== null && _a !== void 0 ? _a : shapeOptions.options["image"]; | ||
const imageOptions = (_a = shapeOptions.options["image"]) !== null && _a !== void 0 ? _a : shapeOptions.options["images"]; | ||
if (imageOptions instanceof Array) { | ||
@@ -60,10 +78,7 @@ const promises = []; | ||
} | ||
destroy() { | ||
this.images = []; | ||
} | ||
loadImageShape(container, imageShape) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const imagePromise = imageShape.replaceColor ? downloadSvgImage(imageShape.src) : loadImage(imageShape.src); | ||
const image = yield imagePromise; | ||
const imageFunc = imageShape.replaceColor ? downloadSvgImage : loadImage; | ||
const image = yield imageFunc(imageShape.src); | ||
if (image) { | ||
@@ -103,3 +118,3 @@ this.addImage(container, image); | ||
var _a, _b, _c, _d, _e; | ||
if (!(particle.shape === "image" || particle.shape === "images")) { | ||
if (particle.shape !== "image" && particle.shape !== "images") { | ||
return; | ||
@@ -172,1 +187,2 @@ } | ||
} | ||
_images = new WeakMap(); |
@@ -1,1 +0,2 @@ | ||
export {}; | ||
import type { Main } from "tsparticles-engine"; | ||
export declare function loadImageShape(tsParticles: Main): void; |
@@ -1,3 +0,6 @@ | ||
import { loadShape } from "./shape"; | ||
import { tsParticles } from "tsparticles-core"; | ||
loadShape(tsParticles); | ||
import { ImageDrawer } from "./ImageDrawer"; | ||
export function loadImageShape(tsParticles) { | ||
const imageDrawer = new ImageDrawer(); | ||
tsParticles.addShape("image", imageDrawer); | ||
tsParticles.addShape("images", imageDrawer); | ||
} |
{ | ||
"name": "tsparticles-shape-image", | ||
"version": "2.0.0-alpha.3", | ||
"version": "2.0.0-alpha.4", | ||
"description": "tsParticles Image shape", | ||
@@ -41,11 +41,11 @@ "homepage": "https://particles.js.org/", | ||
}, | ||
"main": "shape.js", | ||
"main": "index.js", | ||
"jsdelivr": "tsparticles.shape.image.min.js", | ||
"unpkg": "tsparticles.shape.image.min.js", | ||
"browser": "shape.js", | ||
"module": "shape.js", | ||
"types": "shape.d.ts", | ||
"browser": "index.js", | ||
"module": "index.js", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"tsparticles-core": "^2.0.0-alpha.0" | ||
"tsparticles-engine": "^2.0.0-alpha.4" | ||
} | ||
} |
@@ -7,14 +7,14 @@ /*! | ||
* How to use? : Check the GitHub README | ||
* v2.0.0-alpha.3 | ||
* v2.0.0-alpha.4 | ||
*/ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(require("tsparticles-core")); | ||
module.exports = factory(require("tsparticles-engine")); | ||
else if(typeof define === 'function' && define.amd) | ||
define(["tsparticles-core"], factory); | ||
define(["tsparticles-engine"], factory); | ||
else { | ||
var a = typeof exports === 'object' ? factory(require("tsparticles-core")) : factory(root["window"]); | ||
var a = typeof exports === 'object' ? factory(require("tsparticles-engine")) : factory(root["window"]); | ||
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; | ||
} | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE__646__) { | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE__414__) { | ||
return /******/ (() => { // webpackBootstrap | ||
@@ -24,3 +24,3 @@ /******/ "use strict"; | ||
/***/ 73: | ||
/***/ 731: | ||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | ||
@@ -31,5 +31,10 @@ | ||
// EXTERNAL MODULE: external {"commonjs":"tsparticles-core","commonjs2":"tsparticles-core","amd":"tsparticles-core","root":"window"} | ||
var external_commonjs_tsparticles_core_commonjs2_tsparticles_core_amd_tsparticles_core_root_window_ = __webpack_require__(646); | ||
;// CONCATENATED MODULE: ./dist/ImageDrawer.js | ||
// EXPORTS | ||
__webpack_require__.d(__webpack_exports__, { | ||
"loadImageShape": () => /* binding */ loadImageShape | ||
}); | ||
// EXTERNAL MODULE: external {"commonjs":"tsparticles-engine","commonjs2":"tsparticles-engine","amd":"tsparticles-engine","root":"window"} | ||
var external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_ = __webpack_require__(414); | ||
;// CONCATENATED MODULE: ./dist/Utils.js | ||
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) { | ||
@@ -68,5 +73,116 @@ function adopt(value) { | ||
function loadImage(source) { | ||
return new Promise((resolve, reject) => { | ||
if (!source) { | ||
reject("Error tsParticles - No image.src"); | ||
return; | ||
} | ||
const image = { | ||
source: source, | ||
type: source.substr(source.length - 3) | ||
}; | ||
const img = new Image(); | ||
img.addEventListener("load", () => { | ||
image.element = img; | ||
resolve(image); | ||
}); | ||
img.addEventListener("error", () => { | ||
reject(`Error tsParticles - loading image: ${source}`); | ||
}); | ||
img.src = source; | ||
}); | ||
} | ||
function downloadSvgImage(source) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!source) { | ||
throw new Error("Error tsParticles - No image.src"); | ||
} | ||
const image = { | ||
source: source, | ||
type: source.substr(source.length - 3) | ||
}; | ||
if (image.type !== "svg") { | ||
return loadImage(source); | ||
} | ||
const response = yield fetch(image.source); | ||
if (!response.ok) { | ||
throw new Error("Error tsParticles - Image not found"); | ||
} | ||
image.svgData = yield response.text(); | ||
return image; | ||
}); | ||
} | ||
function replaceColorSvg(image, color, opacity) { | ||
if (!image.svgData) { | ||
return ""; | ||
} | ||
const svgXml = image.svgData; | ||
const rgbHex = /#([0-9A-F]{3,6})/gi; | ||
return svgXml.replace(rgbHex, () => (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getStyleFromHsl)(color, opacity)); | ||
} | ||
;// CONCATENATED MODULE: ./dist/ImageDrawer.js | ||
var ImageDrawer_awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { | ||
return value instanceof P ? value : new P(function (resolve) { | ||
resolve(value); | ||
}); | ||
} | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function rejected(value) { | ||
try { | ||
step(generator["throw"](value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function step(result) { | ||
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); | ||
} | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __classPrivateFieldSet = undefined && undefined.__classPrivateFieldSet || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
}; | ||
var __classPrivateFieldGet = undefined && undefined.__classPrivateFieldGet || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
}; | ||
var _images; | ||
class ImageDrawer { | ||
constructor() { | ||
this.images = []; | ||
_images.set(this, void 0); | ||
__classPrivateFieldSet(this, _images, []); | ||
} | ||
@@ -79,12 +195,13 @@ | ||
getImages(container) { | ||
const containerImages = this.images.filter(t => t.id === container.id); | ||
const containerImages = __classPrivateFieldGet(this, _images).find(t => t.id === container.id); | ||
if (!containerImages.length) { | ||
this.images.push({ | ||
if (!containerImages) { | ||
__classPrivateFieldGet(this, _images).push({ | ||
id: container.id, | ||
images: [] | ||
}); | ||
return this.getImages(container); | ||
} else { | ||
return containerImages[0]; | ||
return containerImages; | ||
} | ||
@@ -99,13 +216,16 @@ } | ||
init(container) { | ||
var _a; | ||
const options = container.options; | ||
const shapeOptions = options.particles.shape; | ||
return this.initShape(container, shapeOptions); | ||
} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const options = container.options; | ||
const shapeOptions = options.particles.shape; | ||
destroy() { | ||
__classPrivateFieldSet(this, _images, []); | ||
} | ||
if (!(0,external_commonjs_tsparticles_core_commonjs2_tsparticles_core_amd_tsparticles_core_root_window_.isInArray)("image", shapeOptions.type) && !(0,external_commonjs_tsparticles_core_commonjs2_tsparticles_core_amd_tsparticles_core_root_window_.isInArray)("images", shapeOptions.type)) { | ||
return; | ||
} | ||
initShape(container, shapeOptions) { | ||
var _a; | ||
const imageOptions = (_a = shapeOptions.options["images"]) !== null && _a !== void 0 ? _a : shapeOptions.options["image"]; | ||
return ImageDrawer_awaiter(this, void 0, void 0, function* () { | ||
const imageOptions = (_a = shapeOptions.options["image"]) !== null && _a !== void 0 ? _a : shapeOptions.options["images"]; | ||
@@ -126,11 +246,7 @@ if (imageOptions instanceof Array) { | ||
destroy() { | ||
this.images = []; | ||
} | ||
loadImageShape(container, imageShape) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return ImageDrawer_awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const imagePromise = imageShape.replaceColor ? (0,external_commonjs_tsparticles_core_commonjs2_tsparticles_core_amd_tsparticles_core_root_window_.downloadSvgImage)(imageShape.src) : (0,external_commonjs_tsparticles_core_commonjs2_tsparticles_core_amd_tsparticles_core_root_window_.loadImage)(imageShape.src); | ||
const image = yield imagePromise; | ||
const imageFunc = imageShape.replaceColor ? downloadSvgImage : loadImage; | ||
const image = yield imageFunc(imageShape.src); | ||
@@ -180,3 +296,3 @@ if (image) { | ||
if (!(particle.shape === "image" || particle.shape === "images")) { | ||
if (particle.shape !== "image" && particle.shape !== "images") { | ||
return; | ||
@@ -197,3 +313,3 @@ } | ||
if (image.svgData !== undefined && imageData.replaceColor && color) { | ||
const svgColoredData = (0,external_commonjs_tsparticles_core_commonjs2_tsparticles_core_amd_tsparticles_core_root_window_.replaceColorSvg)(image, color, particle.opacity.value); | ||
const svgColoredData = replaceColorSvg(image, color, particle.opacity.value); | ||
const svg = new Blob([svgColoredData], { | ||
@@ -223,3 +339,3 @@ type: "image/svg+xml" | ||
domUrl.revokeObjectURL(url); | ||
(0,external_commonjs_tsparticles_core_commonjs2_tsparticles_core_amd_tsparticles_core_root_window_.loadImage)(imageData.src).then(img2 => { | ||
loadImage(imageData.src).then(img2 => { | ||
const pImage = particle.image; | ||
@@ -261,5 +377,6 @@ | ||
} | ||
;// CONCATENATED MODULE: ./dist/shape.js | ||
_images = new WeakMap(); | ||
;// CONCATENATED MODULE: ./dist/index.js | ||
function loadShape(tsParticles) { | ||
function loadImageShape(tsParticles) { | ||
const imageDrawer = new ImageDrawer(); | ||
@@ -269,13 +386,9 @@ tsParticles.addShape("image", imageDrawer); | ||
} | ||
;// CONCATENATED MODULE: ./dist/index.js | ||
loadShape(external_commonjs_tsparticles_core_commonjs2_tsparticles_core_amd_tsparticles_core_root_window_.tsParticles); | ||
/***/ }), | ||
/***/ 646: | ||
/***/ 414: | ||
/***/ ((module) => { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE__646__; | ||
module.exports = __WEBPACK_EXTERNAL_MODULE__414__; | ||
@@ -310,2 +423,19 @@ /***/ }) | ||
/************************************************************************/ | ||
/******/ /* webpack/runtime/define property getters */ | ||
/******/ (() => { | ||
/******/ // define getter functions for harmony exports | ||
/******/ __webpack_require__.d = (exports, definition) => { | ||
/******/ for(var key in definition) { | ||
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | ||
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | ||
/******/ } | ||
/******/ } | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/hasOwnProperty shorthand */ | ||
/******/ (() => { | ||
/******/ __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop) | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/make namespace object */ | ||
@@ -326,5 +456,5 @@ /******/ (() => { | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(73); | ||
/******/ return __webpack_require__(731); | ||
/******/ })() | ||
; | ||
}); |
@@ -1,2 +0,2 @@ | ||
/*! tsParticles Image Shape v2.0.0-alpha.3 by Matteo Bruni */ | ||
!function(e,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o(require("tsparticles-core"));else if("function"==typeof define&&define.amd)define(["tsparticles-core"],o);else{var t="object"==typeof exports?o(require("tsparticles-core")):o(e.window);for(var i in t)("object"==typeof exports?exports:e)[i]=t[i]}}(this,(function(e){return(()=>{"use strict";var o={73:(e,o,t)=>{t.r(o);var i=t(646),a=function(e,o,t,i){return new(t||(t=Promise))((function(a,r){function l(e){try{s(i.next(e))}catch(e){r(e)}}function n(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var o;e.done?a(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(l,n)}s((i=i.apply(e,o||[])).next())}))};class r{constructor(){this.images=[]}getSidesCount(){return 12}getImages(e){const o=this.images.filter((o=>o.id===e.id));return o.length?o[0]:(this.images.push({id:e.id,images:[]}),this.getImages(e))}addImage(e,o){const t=this.getImages(e);null==t||t.images.push(o)}init(e){var o;return a(this,void 0,void 0,(function*(){const t=e.options.particles.shape;if(!(0,i.isInArray)("image",t.type)&&!(0,i.isInArray)("images",t.type))return;const a=null!==(o=t.options.images)&&void 0!==o?o:t.options.image;if(a instanceof Array){const o=[];for(const t of a)o.push(this.loadImageShape(e,t));yield Promise.allSettled(o)}else yield this.loadImageShape(e,a)}))}destroy(){this.images=[]}loadImageShape(e,o){return a(this,void 0,void 0,(function*(){try{const t=o.replaceColor?(0,i.downloadSvgImage)(o.src):(0,i.loadImage)(o.src),a=yield t;a&&this.addImage(e,a)}catch(e){console.warn(`tsParticles error - ${o.src} not found`)}}))}draw(e,o,t,i){var a,r;if(!e)return;const l=o.image,n=null===(a=null==l?void 0:l.data)||void 0===a?void 0:a.element;if(!n)return;const s=null!==(r=null==l?void 0:l.ratio)&&void 0!==r?r:1,c={x:-t,y:-t};(null==l?void 0:l.data.svgData)&&(null==l?void 0:l.replaceColor)||(e.globalAlpha=i),e.drawImage(n,c.x,c.y,2*t,2*t/s),(null==l?void 0:l.data.svgData)&&(null==l?void 0:l.replaceColor)||(e.globalAlpha=1)}loadShape(e){var o,t,a,r,l;if("image"!==e.shape&&"images"!==e.shape)return;const n=e.container,s=this.getImages(n).images,c=e.shapeData,d=null!==(o=s.find((e=>e.source===c.src)))&&void 0!==o?o:s[0],u=e.getFillColor();let g;if(!d)return;if(void 0!==d.svgData&&c.replaceColor&&u){const o=(0,i.replaceColorSvg)(d,u,e.opacity.value),a=new Blob([o],{type:"image/svg+xml"}),r=URL||window.URL||window.webkitURL||window,l=r.createObjectURL(a),n=new Image;g={data:d,ratio:c.width/c.height,replaceColor:null!==(t=c.replaceColor)&&void 0!==t?t:c.replace_color,source:c.src},n.addEventListener("load",(()=>{const o=e.image;o&&(o.loaded=!0,d.element=n),r.revokeObjectURL(l)})),n.addEventListener("error",(()=>{r.revokeObjectURL(l),(0,i.loadImage)(c.src).then((o=>{const t=e.image;t&&(d.element=null==o?void 0:o.element,t.loaded=!0)}))})),n.src=l}else g={data:d,loaded:!0,ratio:c.width/c.height,replaceColor:null!==(a=c.replaceColor)&&void 0!==a?a:c.replace_color,source:c.src};g.ratio||(g.ratio=1);const p={image:g,fill:null!==(r=c.fill)&&void 0!==r?r:e.fill,close:null!==(l=c.close)&&void 0!==l?l:e.close};e.image=p.image,e.fill=p.fill,e.close=p.close}}!function(e){const o=new r;e.addShape("image",o),e.addShape("images",o)}(i.tsParticles)},646:o=>{o.exports=e}},t={};function i(e){if(t[e])return t[e].exports;var a=t[e]={exports:{}};return o[e](a,a.exports,i),a.exports}return i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i(73)})()})); | ||
/*! tsParticles Image Shape v2.0.0-alpha.4 by Matteo Bruni */ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("tsparticles-engine"));else if("function"==typeof define&&define.amd)define(["tsparticles-engine"],t);else{var o="object"==typeof exports?t(require("tsparticles-engine")):t(e.window);for(var r in o)("object"==typeof exports?exports:e)[r]=o[r]}}(this,(function(e){return(()=>{"use strict";var t={731:(e,t,o)=>{o.r(t),o.d(t,{loadImageShape:()=>p});var r=o(414),n=function(e,t,o,r){return new(o||(o=Promise))((function(n,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))};function i(e){return new Promise(((t,o)=>{if(!e)return void o("Error tsParticles - No image.src");const r={source:e,type:e.substr(e.length-3)},n=new Image;n.addEventListener("load",(()=>{r.element=n,t(r)})),n.addEventListener("error",(()=>{o("Error tsParticles - loading image: "+e)})),n.src=e}))}function a(e){return n(this,void 0,void 0,(function*(){if(!e)throw new Error("Error tsParticles - No image.src");const t={source:e,type:e.substr(e.length-3)};if("svg"!==t.type)return i(e);const o=yield fetch(t.source);if(!o.ok)throw new Error("Error tsParticles - Image not found");return t.svgData=yield o.text(),t}))}var s,l=function(e,t,o,r){return new(o||(o=Promise))((function(n,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},c=function(e,t,o){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");return t.set(e,o),o},d=function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)};class u{constructor(){s.set(this,void 0),c(this,s,[])}getSidesCount(){return 12}getImages(e){const t=d(this,s).find((t=>t.id===e.id));return t||(d(this,s).push({id:e.id,images:[]}),this.getImages(e))}addImage(e,t){const o=this.getImages(e);null==o||o.images.push(t)}init(e){const t=e.options.particles.shape;return this.initShape(e,t)}destroy(){c(this,s,[])}initShape(e,t){var o;return l(this,void 0,void 0,(function*(){const r=null!==(o=t.options.image)&&void 0!==o?o:t.options.images;if(r instanceof Array){const t=[];for(const o of r)t.push(this.loadImageShape(e,o));yield Promise.allSettled(t)}else yield this.loadImageShape(e,r)}))}loadImageShape(e,t){return l(this,void 0,void 0,(function*(){try{const o=t.replaceColor?a:i,r=yield o(t.src);r&&this.addImage(e,r)}catch(e){console.warn(`tsParticles error - ${t.src} not found`)}}))}draw(e,t,o,r){var n,i;if(!e)return;const a=t.image,s=null===(n=null==a?void 0:a.data)||void 0===n?void 0:n.element;if(!s)return;const l=null!==(i=null==a?void 0:a.ratio)&&void 0!==i?i:1,c={x:-o,y:-o};(null==a?void 0:a.data.svgData)&&(null==a?void 0:a.replaceColor)||(e.globalAlpha=r),e.drawImage(s,c.x,c.y,2*o,2*o/l),(null==a?void 0:a.data.svgData)&&(null==a?void 0:a.replaceColor)||(e.globalAlpha=1)}loadShape(e){var t,o,n,a,s;if("image"!==e.shape&&"images"!==e.shape)return;const l=e.container,c=this.getImages(l).images,d=e.shapeData,u=null!==(t=c.find((e=>e.source===d.src)))&&void 0!==t?t:c[0],p=e.getFillColor();let f;if(!u)return;if(void 0!==u.svgData&&d.replaceColor&&p){const t=function(e,t,o){return e.svgData?e.svgData.replace(/#([0-9A-F]{3,6})/gi,(()=>(0,r.getStyleFromHsl)(t,o))):""}(u,p,e.opacity.value),n=new Blob([t],{type:"image/svg+xml"}),a=URL||window.URL||window.webkitURL||window,s=a.createObjectURL(n),l=new Image;f={data:u,ratio:d.width/d.height,replaceColor:null!==(o=d.replaceColor)&&void 0!==o?o:d.replace_color,source:d.src},l.addEventListener("load",(()=>{const t=e.image;t&&(t.loaded=!0,u.element=l),a.revokeObjectURL(s)})),l.addEventListener("error",(()=>{a.revokeObjectURL(s),i(d.src).then((t=>{const o=e.image;o&&(u.element=null==t?void 0:t.element,o.loaded=!0)}))})),l.src=s}else f={data:u,loaded:!0,ratio:d.width/d.height,replaceColor:null!==(n=d.replaceColor)&&void 0!==n?n:d.replace_color,source:d.src};f.ratio||(f.ratio=1);const g={image:f,fill:null!==(a=d.fill)&&void 0!==a?a:e.fill,close:null!==(s=d.close)&&void 0!==s?s:e.close};e.image=g.image,e.fill=g.fill,e.close=g.close}}function p(e){const t=new u;e.addShape("image",t),e.addShape("images",t)}s=new WeakMap},414:t=>{t.exports=e}},o={};function r(e){if(o[e])return o[e].exports;var n=o[e]={exports:{}};return t[e](n,n.exports,r),n.exports}return r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(731)})()})); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
306057
666
3
+ Addedtsparticles-engine@2.12.0(transitive)
- Removedtsparticles-core@^2.0.0-alpha.0