@novely/particles 0.2.0 → 0.3.0
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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{tsParticles as c}from"tsparticles-engine";import{loadSlim as f}from"tsparticles-slim";var u=!1,d=Symbol(),y=t=>(t.autoPlay||=!0,t.fullScreen||={enable:!0,zIndex:2},t),C=(()=>{let t=0;return()=>`np-${t++}`})(),O=t=>{let
|
|
1
|
+
import{tsParticles as c}from"tsparticles-engine";import{loadSlim as f}from"tsparticles-slim";var u=!1,d=Symbol(),y=t=>(t.autoPlay||=!0,t.fullScreen||={enable:!0,zIndex:2},t),C=(()=>{let t=0;return()=>`np-${t++}`})(),O=t=>{let e=async({get:s,goingBack:n,preview:a})=>{if(a)return;u||(await f(c),u=!0);let r=s(!0);r.clear(()=>{let l=r.data().instance;l&&(l.destroy(),r.data({}))});let i=r.data(),o=i.options===t;if(o&&i.instance||o&&n)return;let p=C(),m=await c.set(p,r.element,y(t));r.data({instance:m,options:t})};return e.callOnlyLatest=e.skipClearOnGoingBack=!0,e.id=d,e.key="particles",e},P=()=>{let t=({get:e,preview:s})=>{if(s)return;let n=e(!0),a=n.data().instance;a&&a.destroy(),n.delete()};return t.callOnlyLatest=!0,t.id=d,t.key="particles",t};export{P as hide,O as particles};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/particles.ts"],"sourcesContent":["import type { RecursivePartial, IOptions, Container } from 'tsparticles-engine';\nimport type { CustomHandler } from '@novely/core';\n\nimport { tsParticles } from 'tsparticles-engine';\nimport { loadSlim } from 'tsparticles-slim';\n\nlet loaded = false;\n\nconst ID = Symbol();\n\ntype ParticlesOptions = RecursivePartial<IOptions>;\n\nconst withDefault = (options: ParticlesOptions) => {\n\toptions.autoPlay ||= true;\n\toptions.fullScreen ||= { enable: true, zIndex: 2 };\n\n\treturn options;\n};\n\nconst createUniqId = (() => {\n\tlet c = 0;\n\n\treturn () => {\n\t\treturn `np-${c++}`;\n\t}\n})();\n\nconst particles = (options: ParticlesOptions): CustomHandler => {\n\tconst handler: CustomHandler = async (get, goingBack, preview) => {\n\t\tif (preview) return;\n\n\t\tif (!loaded) {\n\t\t\t/**\n\t\t\t * Load `tsParticles` in case it's not loaded\n\t\t\t */\n\t\t\tawait loadSlim(tsParticles);\n\t\t\t/**\n\t\t\t * Do not load it later\n\t\t\t */\n\t\t\tloaded = true;\n\t\t}\n\n\t\tconst layer = get(true);\n\n\t\t/**\n\t\t * Remove previous instance\n\t\t */\n\t\tlayer.clear(() => {\n\t\t\t/**\n\t\t\t * Get the instance\n\t\t\t */\n\t\t\tconst instance = layer.data().instance as Container;\n\n\t\t\tif (!instance) return;\n\n\t\t\t/**\n\t\t\t * Destroy the instance\n\t\t\t */\n\t\t\tinstance.destroy();\n\n\t\t\t/**\n\t\t\t * Empty the `data`\n\t\t\t */\n\t\t\tlayer.data({});\n\t\t});\n\n\t\tconst data = layer.data();\n\t\tconst optionsEqual = data.options === options;\n\n\t\t/**\n\t\t * Skip re-rendering if:\n\t\t * 1) Options has not changed and instance is present\n\t\t * 2) Options has not changed and we are goingBack\n\t\t */\n\t\tif (optionsEqual && Boolean(data.instance)) return;\n\t\tif (optionsEqual && goingBack) return;\n\n\t\tconst id = createUniqId();\n\n\t\t/**\n\t\t * Use element\n\t\t */\n\t\tconst instance = await tsParticles.set(id, layer.element, withDefault(options))\n\n\t\t/**\n\t\t * Set the instance\n\t\t */\n\t\tlayer.data({ instance, options });\n\t};\n\n\thandler.callOnlyLatest = handler.skipClearOnGoingBack = true;\n\thandler.id = ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nconst hide = () => {\n\tconst handler: CustomHandler = (get,
|
|
1
|
+
{"version":3,"sources":["../src/particles.ts"],"sourcesContent":["import type { RecursivePartial, IOptions, Container } from 'tsparticles-engine';\nimport type { CustomHandler } from '@novely/core';\n\nimport { tsParticles } from 'tsparticles-engine';\nimport { loadSlim } from 'tsparticles-slim';\n\nlet loaded = false;\n\nconst ID = Symbol();\n\ntype ParticlesOptions = RecursivePartial<IOptions>;\n\nconst withDefault = (options: ParticlesOptions) => {\n\toptions.autoPlay ||= true;\n\toptions.fullScreen ||= { enable: true, zIndex: 2 };\n\n\treturn options;\n};\n\nconst createUniqId = (() => {\n\tlet c = 0;\n\n\treturn () => {\n\t\treturn `np-${c++}`;\n\t}\n})();\n\nconst particles = (options: ParticlesOptions): CustomHandler => {\n\tconst handler: CustomHandler = async ({ get, goingBack, preview }) => {\n\t\tif (preview) return;\n\n\t\tif (!loaded) {\n\t\t\t/**\n\t\t\t * Load `tsParticles` in case it's not loaded\n\t\t\t */\n\t\t\tawait loadSlim(tsParticles);\n\t\t\t/**\n\t\t\t * Do not load it later\n\t\t\t */\n\t\t\tloaded = true;\n\t\t}\n\n\t\tconst layer = get(true);\n\n\t\t/**\n\t\t * Remove previous instance\n\t\t */\n\t\tlayer.clear(() => {\n\t\t\t/**\n\t\t\t * Get the instance\n\t\t\t */\n\t\t\tconst instance = layer.data().instance as Container;\n\n\t\t\tif (!instance) return;\n\n\t\t\t/**\n\t\t\t * Destroy the instance\n\t\t\t */\n\t\t\tinstance.destroy();\n\n\t\t\t/**\n\t\t\t * Empty the `data`\n\t\t\t */\n\t\t\tlayer.data({});\n\t\t});\n\n\t\tconst data = layer.data();\n\t\tconst optionsEqual = data.options === options;\n\n\t\t/**\n\t\t * Skip re-rendering if:\n\t\t * 1) Options has not changed and instance is present\n\t\t * 2) Options has not changed and we are goingBack\n\t\t */\n\t\tif (optionsEqual && Boolean(data.instance)) return;\n\t\tif (optionsEqual && goingBack) return;\n\n\t\tconst id = createUniqId();\n\n\t\t/**\n\t\t * Use element\n\t\t */\n\t\tconst instance = await tsParticles.set(id, layer.element, withDefault(options))\n\n\t\t/**\n\t\t * Set the instance\n\t\t */\n\t\tlayer.data({ instance, options });\n\t};\n\n\thandler.callOnlyLatest = handler.skipClearOnGoingBack = true;\n\thandler.id = ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nconst hide = () => {\n\tconst handler: CustomHandler = ({ get, preview }) => {\n\t\tif (preview) return;\n\n\t\tconst layer = get(true);\n\n\t\t/**\n\t\t * Get the instance\n\t\t */\n\t\tconst instance = layer.data().instance as Container;\n\n\t\t/**\n\t\t * Destroy it\n\t\t */\n\t\tif (instance) instance.destroy();\n\n\t\t/**\n\t\t * Delete the layer\n\t\t */\n\t\tlayer.delete();\n\t};\n\n\thandler.callOnlyLatest = true;\n\thandler.id = ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nexport { particles, hide };\n"],"mappings":"AAGA,OAAS,eAAAA,MAAmB,qBAC5B,OAAS,YAAAC,MAAgB,mBAEzB,IAAIC,EAAS,GAEPC,EAAK,OAAO,EAIZC,EAAeC,IACpBA,EAAQ,WAAa,GACrBA,EAAQ,aAAe,CAAE,OAAQ,GAAM,OAAQ,CAAE,EAE1CA,GAGFC,GAAgB,IAAM,CAC3B,IAAIC,EAAI,EAER,MAAO,IACC,MAAMA,GAAG,EAElB,GAAG,EAEGC,EAAaH,GAA6C,CAC/D,IAAMI,EAAyB,MAAO,CAAE,IAAAC,EAAK,UAAAC,EAAW,QAAAC,CAAQ,IAAM,CACrE,GAAIA,EAAS,OAERV,IAIJ,MAAMD,EAASD,CAAW,EAI1BE,EAAS,IAGV,IAAMW,EAAQH,EAAI,EAAI,EAKtBG,EAAM,MAAM,IAAM,CAIjB,IAAMC,EAAWD,EAAM,KAAK,EAAE,SAEzBC,IAKLA,EAAS,QAAQ,EAKjBD,EAAM,KAAK,CAAC,CAAC,EACd,CAAC,EAED,IAAME,EAAOF,EAAM,KAAK,EAClBG,EAAeD,EAAK,UAAYV,EAQtC,GADIW,GAAwBD,EAAK,UAC7BC,GAAgBL,EAAW,OAE/B,IAAMM,EAAKX,EAAa,EAKlBQ,EAAW,MAAMd,EAAY,IAAIiB,EAAIJ,EAAM,QAAST,EAAYC,CAAO,CAAC,EAK9EQ,EAAM,KAAK,CAAE,SAAAC,EAAU,QAAAT,CAAQ,CAAC,CACjC,EAEA,OAAAI,EAAQ,eAAiBA,EAAQ,qBAAuB,GACxDA,EAAQ,GAAKN,EACbM,EAAQ,IAAM,YAEPA,CACR,EAEMS,EAAO,IAAM,CAClB,IAAMT,EAAyB,CAAC,CAAE,IAAAC,EAAK,QAAAE,CAAQ,IAAM,CACpD,GAAIA,EAAS,OAEb,IAAMC,EAAQH,EAAI,EAAI,EAKhBI,EAAWD,EAAM,KAAK,EAAE,SAK1BC,GAAUA,EAAS,QAAQ,EAK/BD,EAAM,OAAO,CACd,EAEA,OAAAJ,EAAQ,eAAiB,GACzBA,EAAQ,GAAKN,EACbM,EAAQ,IAAM,YAEPA,CACR","names":["tsParticles","loadSlim","loaded","ID","withDefault","options","createUniqId","c","particles","handler","get","goingBack","preview","layer","instance","data","optionsEqual","id","hide"]}
|