"use strict";(globalThis.webpackChunkwordpress_particles=globalThis.webpackChunkwordpress_particles||[]).push([[6230],{6230:(t,e,i)=>{i.r(e),i.d(e,{loadCanvasMaskPlugin:()=>w});class s{constructor(){this.color=!0,this.opacity=!1}load(t){t&&(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}var o=i(4684);class n{constructor(){this.filter=t=>t.a>0,this.offset=4}load(t){if(t){if(void 0!==t.filter)if((0,o.HD)(t.filter)){if(Object.hasOwn(window,t.filter)){const e=window[t.filter];(0,o.mf)(e)&&(this.filter=e)}}else this.filter=t.filter;void 0!==t.offset&&(this.offset=t.offset)}}}class a{constructor(){this.src=""}load(t){t&&void 0!==t.src&&(this.src=t.src)}}class r{constructor(){this.family="sans-serif",this.size=100}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=10}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 r,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.enable=!1,this.override=new s,this.pixels=new n,this.position={x:50,y:50},this.scale=1}load(t){t&&(void 0!==t.element&&t.element instanceof HTMLCanvasElement&&(this.element=t.element),void 0!==t.enable&&(this.enable=t.enable),t.image&&(this.image||(this.image=new a),this.image.load(t.image)),this.pixels.load(t.pixels),t.position&&(this.position={x:t.position.x??this.position.x,y:t.position.y??this.position.y}),this.override.load(t.override),void 0!==t.scale&&(this.scale=t.scale),void 0!==t.selector&&(this.selector=t.selector),t.text&&(this.text||(this.text=new c),this.text.load(t.text)))}}var d=i(5302),f=i(8264);function g(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 n=[];for(let t=0;t<o.length;t+=i){const s=t/i,a={x:s%e.width,y:Math.floor(s/e.width)};n[a.y]||(n[a.y]=[]),n[a.y][a.x]={r:o[t],g:o[t+1],b:o[t+2],a:o[t+3]/255}}return{pixels:n,width:Math.min(...n.map((t=>t.length))),height:n.length}}const u=t=>[...Array(t).keys()];class p{constructor(t,e){this._container=t,this._engine=e}async init(){const t=this._container,e=t.actualOptions.canvasMask;if(!e?.enable)return;let i={pixels:[],height:0,width:0};const s=e.pixels.offset;if(e.image){const t=e.image.src;if(!t)return;i=await function(t,e){const i=new Image;i.crossOrigin="Anonymous";const s=new Promise(((t,s)=>{i.onerror=s,i.onload=()=>{const o=document.createElement("canvas");o.width=i.width,o.height=i.height;const n=o.getContext("2d");if(!n)return s(new Error(`${f.gK} Could not get canvas context`));n.drawImage(i,0,0,i.width,i.height,0,0,o.width,o.height),t(g(n,o,e))}}));return i.src=t,s}(t,s)}else if(e.text){const t=function(t,e){const i=document.createElement("canvas"),s=i.getContext("2d"),{font:n,text:a,lines:r,color:l}=t;if(!a||!s)return;const c=a.split(r.separator),h=(0,o.hj)(n.size)?`${n.size}px`:n.size,d=[];let f=0,u=0;for(const t of c){s.font=`${n.style||""} ${n.variant||""} ${n.weight||""} ${h} ${n.family}`;const e=s.measureText(t),i={measure:e,text:t,height:e.actualBoundingBoxAscent+e.actualBoundingBoxDescent,width:e.width};f=Math.max(f||0,i.width),u+=i.height+r.spacing,d.push(i)}i.width=f,i.height=u;let p=0;for(const t of d)s.font=`${n.style||""} ${n.variant||""} ${n.weight||""} ${h} ${n.family}`,s.fillStyle=l,s.fillText(t.text,0,p+t.measure.actualBoundingBoxAscent),p+=t.height+r.spacing;return g(s,i,e)}(e.text,s);if(!t)return;i=t}else if(e.element||e.selector){const t=e.element||e.selector&&document.querySelector(e.selector);if(!t)return;const o=t.getContext("2d");if(!o)return;i=g(o,t,s)}!function(t,e,i,s,o,n){const{height:a,width:r}=e,l=a*r,c=function(t){for(let e=t.length-1;e>=0;e--){const i=Math.floor((0,d.sZ)()*e);[t[e],t[i]]=[t[i],t[e]]}return t}(u(l)),h=Math.min(l,t.actualOptions.particles.number.value),f=t.canvas.size;let g=0;const p=f.width*i.x/100-r*s/2,v=f.height*i.y/100-a*s/2;for(;g<h&&c.length;){const i=c.pop()||0,a={x:i%r,y:Math.floor(i/r)},l=e.pixels[a.y][a.x];if(n(l)){const e={x:a.x*s+p,y:a.y*s+v},i={};o.color&&(i.color={value:l}),o.opacity&&(i.opacity={value:l.a}),t.particles.addParticle(e,i),g++}}}(t,i,e.position,e.scale,e.override,e.pixels.filter)}}class v{constructor(t){this.id="canvasMask",this._engine=t}getPlugin(t){return new p(t,this._engine)}loadOptions(t,e){if(!this.needsPlugin(t)&&!this.needsPlugin(e))return;let i=t.canvasMask;void 0===i?.load&&(t.canvasMask=i=new h),i.load(e?.canvasMask)}needsPlugin(t){return t?.canvasMask?.enable??!1}}async function w(t,e=!0){await t.addPlugin(new v(t),e)}}}]);