UNPKG

@tsparticles/shape-text

Version:
2 lines 2.21 kB
/*! For license information please see tsparticles.shape.text.min.js.LICENSE.txt */ !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 i in o)("object"==typeof exports?exports:e)[i]=o[i]}}(this,(e=>(()=>{var t={303:t=>{t.exports=e}},o={};function i(e){var r=o[e];if(void 0!==r)return r.exports;var n=o[e]={exports:{}};return t[e](n,n.exports,i),n.exports}i.d=(e,t)=>{for(var o in t)i.o(t,o)&&!i.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};i.r(r),i.d(r,{loadTextShape:()=>l});var n=i(303);function a(e,t,o,i,r,n){const a={x:-(t.length*o*.5),y:.5*o},s=2*o;n?e.fillText(t,a.x,a.y+s*r):e.strokeText(t,a.x,a.y+s*r)}class s{constructor(){this.validTypes=["text","character","char","multiline-text"]}draw(e){!function(e){const{context:t,particle:o,radius:i,opacity:r}=e,s=o.shapeData;if(!s)return;const l=s.value;if(void 0===l)return;void 0===o.text&&(o.text=(0,n.itemFromSingleOrMultiple)(l,o.randomIndexData));const p=o.text,c=s.style??"",d=s.weight??"400",f=2*Math.round(i),u=s.font??"Verdana",x=o.shapeFill,y=p?.split("\n");if(y){t.font=`${c} ${d} ${f}px "${u}"`,t.globalAlpha=r;for(let e=0;e<y.length;e++)a(t,y[e],i,0,e,x);t.globalAlpha=1}}(e)}async init(e){const t=e.actualOptions,{validTypes:o}=this;if(o.find((e=>(0,n.isInArray)(e,t.particles.shape.type)))){const e=o.map((e=>t.particles.shape.options[e])).find((e=>!!e)),i=[];(0,n.executeOnSingleOrMultiple)(e,(e=>{i.push((0,n.loadFont)(e.font,e.weight))})),await Promise.all(i)}}particleInit(e,t){if(!t.shape||!this.validTypes.includes(t.shape))return;const o=t.shapeData;if(void 0===o)return;const i=o.value;void 0!==i&&(t.text=(0,n.itemFromSingleOrMultiple)(i,t.randomIndexData))}}async function l(e,t=!0){e.checkVersion("3.9.1"),await e.addShape(new s,t)}return r})()));