@novely/particles 0.0.1 → 0.0.2

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 CHANGED
@@ -1,2 +1,2 @@
1
- import{tsParticles as r}from"tsparticles-engine";import{loadSlim as l}from"tsparticles-slim";var i=!1,n=t=>(t.autoPlay||=!0,t.fullScreen||={enable:!0,zIndex:2},t),c=t=>async a=>{i||(await l(r),i=!0);let e=a("particles");e.data().instance&&(e.data().instance.destroy(),e.data({}));let s=await r.load("particles",Array.isArray(t)?t.map(n):n(t));e.data({instance:s})},o=()=>t=>{let a=t("particles"),e=a.data().instance;e&&e.destroy(),a.delete()};export{o as hide,c as particles};
1
+ import{tsParticles as s}from"tsparticles-engine";import{loadSlim as d}from"tsparticles-slim";var o=!1,c=t=>(t.autoPlay||=!0,t.fullScreen||={enable:!0,zIndex:2},t),m=t=>{let a=async(r,p)=>{o||(await d(s),o=!0);let e=r("particles");e.skipClearOnGoingBack(!0),e.clear(()=>{let l=e.data().instance;l&&(l.destroy(),e.data({}))});let n=e.data(),i=n.options===t;if(i&&Boolean(n.instance)||i&&p)return;let u=await s.load("particles",Array.isArray(t)?t.map(c):c(t));e.data({instance:u,options:t})};return a.callOnlyLatest=!0,a},y=()=>t=>{let a=t("particles"),r=a.data().instance;r&&r.destroy(),a.delete()};export{y as hide,m 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 { SingleOrMultiple, 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\ntype SingleParticlesOptions = RecursivePartial<IOptions>;\ntype ParticlesOptions = SingleOrMultiple<SingleParticlesOptions>;\n\nconst withDefault = (options: SingleParticlesOptions) => {\n options.autoPlay ||= true;\n options.fullScreen ||= { enable: true, zIndex: 2 };\n\n return options;\n}\n\nconst particles = (options: ParticlesOptions): CustomHandler => {\n return async (get) => {\n if (!loaded) {\n /**\n * Load `tsParticles` in case it is not loaded\n */\n await loadSlim(tsParticles);\n /**\n * Do not load it later\n */\n loaded = true;\n }\n\n const layer = get('particles');\n\n /**\n * Remove previous instance\n */\n\n if (layer.data().instance) {\n /**\n * Get the instance\n */\n const instance = layer.data().instance as Container;\n\n /**\n * Destroy the instance\n */\n instance.destroy();\n\n /**\n * Empty the `data`\n */\n layer.data({});\n }\n\n const instance = await tsParticles.load('particles', Array.isArray(options) ? options.map(withDefault) : withDefault(options));\n\n /**\n * Set the instance\n */\n layer.data({ instance });\n }\n}\n\nconst hide = (): CustomHandler => {\n return (get) => {\n const layer = get('particles');\n\n /**\n * Get the instance\n */\n const instance = layer.data().instance as Container;\n\n /**\n * Destroy it\n */\n if (instance) instance.destroy();\n\n /**\n * Delete the layer\n */\n layer.delete();\n }\n}\n\nexport { particles, hide }"],"mappings":"AAGA,OAAS,eAAAA,MAAmB,qBAC5B,OAAS,YAAAC,MAAgB,mBAEzB,IAAIC,EAAS,GAKPC,EAAeC,IACnBA,EAAQ,WAAa,GACrBA,EAAQ,aAAe,CAAE,OAAQ,GAAM,OAAQ,CAAE,EAE1CA,GAGHC,EAAaD,GACV,MAAOE,GAAQ,CACfJ,IAIH,MAAMD,EAASD,CAAW,EAI1BE,EAAS,IAGX,IAAMK,EAAQD,EAAI,WAAW,EAMzBC,EAAM,KAAK,EAAE,WAIEA,EAAM,KAAK,EAAE,SAKrB,QAAQ,EAKjBA,EAAM,KAAK,CAAC,CAAC,GAGf,IAAMC,EAAW,MAAMR,EAAY,KAAK,YAAa,MAAM,QAAQI,CAAO,EAAIA,EAAQ,IAAID,CAAW,EAAIA,EAAYC,CAAO,CAAC,EAK7HG,EAAM,KAAK,CAAE,SAAAC,CAAS,CAAC,CACzB,EAGIC,EAAO,IACHH,GAAQ,CACd,IAAMC,EAAQD,EAAI,WAAW,EAKvBE,EAAWD,EAAM,KAAK,EAAE,SAK1BC,GAAUA,EAAS,QAAQ,EAK/BD,EAAM,OAAO,CACf","names":["tsParticles","loadSlim","loaded","withDefault","options","particles","get","layer","instance","hide"]}
1
+ {"version":3,"sources":["../src/particles.ts"],"sourcesContent":["import type { SingleOrMultiple, 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\ntype SingleParticlesOptions = RecursivePartial<IOptions>;\ntype ParticlesOptions = SingleOrMultiple<SingleParticlesOptions>;\n\nconst withDefault = (options: SingleParticlesOptions) => {\n options.autoPlay ||= true;\n options.fullScreen ||= { enable: true, zIndex: 2 };\n\n return options;\n}\n\nconst particles = (options: ParticlesOptions): CustomHandler => {\n const handler: CustomHandler = async (get, goingBack) => {\n if (!loaded) {\n /**\n * Load `tsParticles` in case it's not loaded\n */\n await loadSlim(tsParticles);\n /**\n * Do not load it later\n */\n loaded = true;\n }\n\n const layer = get('particles');\n\n /**\n * When `clear` when `goingBack`, do not call the `destroy` method\n */\n layer.skipClearOnGoingBack(true);\n\n /**\n * Remove previous instance\n */\n layer.clear(() => {\n /**\n * Get the instance\n */\n const instance = layer.data().instance as Container;\n\n if (!instance) return;\n\n /**\n * Destroy the instance\n */\n instance.destroy();\n\n /**\n * Empty the `data`\n */\n layer.data({});\n });\n\n const data = layer.data();\n const optionsEqual = data.options === options;\n\n /**\n * Skip re-rendering if:\n * 1) Options has not changed and instance is present\n * 2) Options has not changed and we are goingBack\n */\n if (optionsEqual && Boolean(data.instance)) return;\n if (optionsEqual && goingBack) return;\n\n const instance = await tsParticles.load('particles', Array.isArray(options) ? options.map(withDefault) : withDefault(options));\n\n /**\n * Set the instance\n */\n layer.data({ instance, options });\n }\n\n handler.callOnlyLatest = true;\n\n return handler;\n}\n\nconst hide = (): CustomHandler => {\n return (get) => {\n const layer = get('particles');\n\n /**\n * Get the instance\n */\n const instance = layer.data().instance as Container;\n\n /**\n * Destroy it\n */\n if (instance) instance.destroy();\n\n /**\n * Delete the layer\n */\n layer.delete();\n }\n}\n\nexport { particles, hide }"],"mappings":"AAGA,OAAS,eAAAA,MAAmB,qBAC5B,OAAS,YAAAC,MAAgB,mBAEzB,IAAIC,EAAS,GAKPC,EAAeC,IACnBA,EAAQ,WAAa,GACrBA,EAAQ,aAAe,CAAE,OAAQ,GAAM,OAAQ,CAAE,EAE1CA,GAGHC,EAAaD,GAA6C,CAC9D,IAAME,EAAyB,MAAOC,EAAKC,IAAc,CAClDN,IAIH,MAAMD,EAASD,CAAW,EAI1BE,EAAS,IAGX,IAAMO,EAAQF,EAAI,WAAW,EAK7BE,EAAM,qBAAqB,EAAI,EAK/BA,EAAM,MAAM,IAAM,CAIhB,IAAMC,EAAWD,EAAM,KAAK,EAAE,SAEzBC,IAKLA,EAAS,QAAQ,EAKjBD,EAAM,KAAK,CAAC,CAAC,EACf,CAAC,EAED,IAAME,EAAOF,EAAM,KAAK,EAClBG,EAAeD,EAAK,UAAYP,EAQtC,GADIQ,GAAgB,QAAQD,EAAK,QAAQ,GACrCC,GAAgBJ,EAAW,OAE/B,IAAME,EAAW,MAAMV,EAAY,KAAK,YAAa,MAAM,QAAQI,CAAO,EAAIA,EAAQ,IAAID,CAAW,EAAIA,EAAYC,CAAO,CAAC,EAK7HK,EAAM,KAAK,CAAE,SAAAC,EAAU,QAAAN,CAAQ,CAAC,CAClC,EAEA,OAAAE,EAAQ,eAAiB,GAElBA,CACT,EAEMO,EAAO,IACHN,GAAQ,CACd,IAAME,EAAQF,EAAI,WAAW,EAKvBG,EAAWD,EAAM,KAAK,EAAE,SAK1BC,GAAUA,EAAS,QAAQ,EAK/BD,EAAM,OAAO,CACf","names":["tsParticles","loadSlim","loaded","withDefault","options","particles","handler","get","goingBack","layer","instance","data","optionsEqual","hide"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novely/particles",
3
3
  "description": "Particles Action",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "types": "./dist/index.d.ts",