@novely/particles 0.8.1 → 0.10.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/README.md CHANGED
@@ -1,32 +1,31 @@
1
1
  # @novely/particles
2
2
 
3
- Эффект частиц на основе ts-particles
3
+ Particles effect based on [ts-particles](https://particles.js.org/).
4
4
 
5
- ## Использование
5
+ ## Usage
6
6
 
7
7
  ```ts
8
8
  import { showParticles, hideParticles } from '@novely/particles';
9
9
 
10
10
  const snow = {
11
- // Смотрите больше здесь
12
11
  // @see https://particles.js.org/
13
12
  ...
14
13
  };
15
14
 
16
- engine.withStory({
15
+ engine.script({
17
16
  start: [
18
17
  /**
19
- * Показывает частицы
18
+ * Will show particles
20
19
  */
21
20
  engine.action.custom(showParticles(snow)),
22
21
  /**
23
- * Скрывает частицы
22
+ * Will hide particles
24
23
  */
25
24
  engine.action.custom(hideParticles()),
26
25
  ]
27
26
  });
28
27
  ```
29
28
 
30
- ## Дополнительная информация
29
+ ## Additional Info
31
30
 
32
- CSS `zIndex` слоя с частицами - 2.
31
+ CSS `zIndex` of layer with particles is `2`.
@@ -0,0 +1,2 @@
1
+ var o=!1,u=Symbol(),O=t=>(t.autoPlay||=!0,t.fullScreen||={enable:!0,zIndex:2},t),C=function(t){let e=async({clear:r,data:a,getDomNodes:i,paused:p,flags:{goingBack:P,preview:y}})=>{if(y)return;let{loadSlim:d,tsParticles:n}=await this.getParticles();o||(await d(n),o=!0);let{element:f}=i(!0);r(()=>{let{instance:s}=a();s&&(s.destroy(),a({}))});let l=a(),c=l.options===t,m=!!l.instance;if(c&&m||c&&P)return;(async()=>{let s=await n.load({element:f,options:O(t)}),h=p.subscribe(S=>{if(s)try{S?s.pause():s.play()}catch{}});a({instance:s,options:t,unsubscribe:h})})()};return e.callOnlyLatest=e.skipClearOnGoingBack=!0,e.id=u,e.key="particles",e},g=()=>{let t=({data:e,remove:r,flags:{preview:a}})=>{if(a)return;let{instance:i}=e();i&&i.destroy(),r()};return t.callOnlyLatest=!0,t.id=u,t.key="particles",t};export{C as a,g as b};
2
+ //# sourceMappingURL=chunk-3TCQC3JF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/particles.ts"],"sourcesContent":["import type { CustomHandler } from '@novely/core';\nimport type { Container, IOptions, RecursivePartial } from '@tsparticles/engine';\n\nlet loaded = false;\n\nconst PARTICLES_ID = Symbol();\n\ntype ParticlesOptions = RecursivePartial<IOptions>;\n\ntype Data = {\n\tinstance?: Container;\n\tunsubscribe?: () => void;\n\toptions?: ParticlesOptions;\n};\n\ntype TSParticles = {\n\ttsParticles: typeof import('@tsparticles/engine').tsParticles;\n\tloadSlim: typeof import('@tsparticles/slim').loadSlim;\n};\n\ntype TSParticlesGetter = () => Promise<TSParticles>;\n\ntype ParticlesThis = {\n\tgetParticles: TSParticlesGetter;\n};\n\nconst withDefault = (options: ParticlesOptions) => {\n\toptions.autoPlay ||= true;\n\toptions.fullScreen ||= { enable: true, zIndex: 2 };\n\n\treturn options;\n};\n\nconst showParticles = function (this: ParticlesThis, options: ParticlesOptions): CustomHandler {\n\tconst handler: CustomHandler = async ({ clear, data, getDomNodes, paused, flags: { goingBack, preview } }) => {\n\t\tif (preview) return;\n\n\t\tconst { loadSlim, tsParticles } = await this.getParticles();\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 { element } = getDomNodes(true);\n\n\t\t/**\n\t\t * Remove previous instance\n\t\t */\n\t\tclear(() => {\n\t\t\t/**\n\t\t\t * Get the instance\n\t\t\t */\n\t\t\tconst { instance } = data<Data>();\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\tdata({});\n\t\t});\n\n\t\tconst _data = data<Data>();\n\n\t\tconst optionsEqual = _data.options === options;\n\t\tconst instancePresent = Boolean(_data.instance);\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 && instancePresent) return;\n\t\tif (optionsEqual && goingBack) return;\n\n\t\t/**\n\t\t * We can not wait until particles is loaded\n\t\t */\n\t\tconst load = async () => {\n\t\t\tconst instance = await tsParticles.load({\n\t\t\t\telement: element,\n\t\t\t\toptions: withDefault(options),\n\t\t\t});\n\n\t\t\tconst unsubscribe = paused.subscribe((paused) => {\n\t\t\t\tif (!instance) return;\n\n\t\t\t\ttry {\n\t\t\t\t\tif (paused) {\n\t\t\t\t\t\tinstance.pause();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tinstance.play()\n\t\t\t\t\t}\n\t\t\t\t} catch {};\n\t\t\t});\n\n\t\t\tdata<Data>({ instance, options, unsubscribe });\n\t\t};\n\n\t\t/**\n\t\t * Should be safe because in restore only latest is called, and when playing it is not expected to change frequently\n\t\t */\n\t\tvoid load();\n\t};\n\n\thandler.callOnlyLatest = handler.skipClearOnGoingBack = true;\n\thandler.id = PARTICLES_ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nconst hideParticles = () => {\n\tconst handler: CustomHandler = ({ data, remove, flags: { preview } }) => {\n\t\tif (preview) return;\n\n\t\t/**\n\t\t * Get the instance\n\t\t */\n\t\tconst { instance } = data<Data>();\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\tremove();\n\t};\n\n\thandler.callOnlyLatest = true;\n\thandler.id = PARTICLES_ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nexport { showParticles, hideParticles };\n"],"mappings":"AAGA,IAAIA,EAAS,GAEPC,EAAe,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AAE,QAAAV,CAAQ,CAAE,IAAM,CACxE,GAAIA,EAAS,OAKb,GAAM,CAAE,SAAAI,CAAS,EAAIR,EAAW,EAK5BQ,GAAUA,EAAS,QAAQ,EAK/BM,EAAO,CACR,EAEA,OAAAhB,EAAQ,eAAiB,GACzBA,EAAQ,GAAKJ,EACbI,EAAQ,IAAM,YAEPA,CACR","names":["loaded","PARTICLES_ID","withDefault","options","showParticles","handler","clear","data","getDomNodes","paused","goingBack","preview","loadSlim","tsParticles","element","instance","_data","optionsEqual","instancePresent","unsubscribe","hideParticles","remove"]}
@@ -0,0 +1,2 @@
1
+ var o=!1,u=Symbol(),S=t=>(t.autoPlay||=!0,t.fullScreen||={enable:!0,zIndex:2},t),b=function(t){let e=async({clear:r,data:a,getDomNodes:i,paused:p,flags:{goingBack:P,preview:y}})=>{if(y)return;let{loadSlim:d,tsParticles:n}=await this.getParticles();o||(await d(n),o=!0);let{element:f}=i(!0);r(()=>{let{instance:s}=a();s&&(s.destroy(),a({}))});let l=a(),c=l.options===t,m=!!l.instance;if(c&&m||c&&P)return;(async()=>{let s=await n.load({element:f,options:S(t)}),C=p.subscribe(h=>{if(s)try{h?s.pause():s.play()}catch{}});a({instance:s,options:t})})()};return e.callOnlyLatest=e.skipClearOnGoingBack=!0,e.id=u,e.key="particles",e},g=()=>{let t=({data:e,remove:r,flags:{preview:a}})=>{if(a)return;let{instance:i}=e();i&&i.destroy(),r()};return t.callOnlyLatest=!0,t.id=u,t.key="particles",t};export{b as a,g as b};
2
+ //# sourceMappingURL=chunk-BBH2GOY7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/particles.ts"],"sourcesContent":["import type { CustomHandler } from '@novely/core';\nimport type { Container, IOptions, RecursivePartial } from '@tsparticles/engine';\n\nlet loaded = false;\n\nconst PARTICLES_ID = Symbol();\n\ntype ParticlesOptions = RecursivePartial<IOptions>;\n\ntype Data = {\n\tinstance?: Container;\n\tunsubscribe?: () => void;\n\toptions?: ParticlesOptions;\n};\n\ntype TSParticles = {\n\ttsParticles: typeof import('@tsparticles/engine').tsParticles;\n\tloadSlim: typeof import('@tsparticles/slim').loadSlim;\n};\n\ntype TSParticlesGetter = () => Promise<TSParticles>;\n\ntype ParticlesThis = {\n\tgetParticles: TSParticlesGetter;\n};\n\nconst withDefault = (options: ParticlesOptions) => {\n\toptions.autoPlay ||= true;\n\toptions.fullScreen ||= { enable: true, zIndex: 2 };\n\n\treturn options;\n};\n\nconst showParticles = function (this: ParticlesThis, options: ParticlesOptions): CustomHandler {\n\tconst handler: CustomHandler = async ({ clear, data, getDomNodes, paused, flags: { goingBack, preview } }) => {\n\t\tif (preview) return;\n\n\t\tconst { loadSlim, tsParticles } = await this.getParticles();\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 { element } = getDomNodes(true);\n\n\t\t/**\n\t\t * Remove previous instance\n\t\t */\n\t\tclear(() => {\n\t\t\t/**\n\t\t\t * Get the instance\n\t\t\t */\n\t\t\tconst { instance } = data<Data>();\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\tdata({});\n\t\t});\n\n\t\tconst _data = data<Data>();\n\n\t\tconst optionsEqual = _data.options === options;\n\t\tconst instancePresent = Boolean(_data.instance);\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 && instancePresent) return;\n\t\tif (optionsEqual && goingBack) return;\n\n\t\t/**\n\t\t * We can not wait until particles is loaded\n\t\t */\n\t\tconst load = async () => {\n\t\t\tconst instance = await tsParticles.load({\n\t\t\t\telement: element,\n\t\t\t\toptions: withDefault(options),\n\t\t\t});\n\n\t\t\tconst unsub = paused.subscribe((paused) => {\n\t\t\t\tif (!instance) return;\n\n\t\t\t\ttry {\n\t\t\t\t\tif (paused) {\n\t\t\t\t\t\tinstance.pause();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tinstance.play()\n\t\t\t\t\t}\n\t\t\t\t} catch {};\n\t\t\t});\n\n\t\t\tdata<Data>({ instance, options });\n\t\t};\n\n\t\t/**\n\t\t * Should be safe because in restore only latest is called, and when playing it is not expected to change frequently\n\t\t */\n\t\tvoid load();\n\t};\n\n\thandler.callOnlyLatest = handler.skipClearOnGoingBack = true;\n\thandler.id = PARTICLES_ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nconst hideParticles = () => {\n\tconst handler: CustomHandler = ({ data, remove, flags: { preview } }) => {\n\t\tif (preview) return;\n\n\t\t/**\n\t\t * Get the instance\n\t\t */\n\t\tconst { instance } = data<Data>();\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\tremove();\n\t};\n\n\thandler.callOnlyLatest = true;\n\thandler.id = PARTICLES_ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nexport { showParticles, hideParticles };\n"],"mappings":"AAGA,IAAIA,EAAS,GAEPC,EAAe,OAAO,EAqBtBC,EAAeC,IACpBA,EAAQ,WAAa,GACrBA,EAAQ,aAAe,CAAE,OAAQ,GAAM,OAAQ,CAAE,EAE1CA,GAGFC,EAAgB,SAA+BD,EAA0C,CAC9F,IAAME,EAAyB,MAAO,CAAE,MAAAC,EAAO,KAAAC,EAAM,YAAAC,EAAa,OAAAC,EAAQ,MAAO,CAAE,UAAAC,EAAW,QAAAC,CAAQ,CAAE,IAAM,CAC7G,GAAIA,EAAS,OAEb,GAAM,CAAE,SAAAC,EAAU,YAAAC,CAAY,EAAI,MAAM,KAAK,aAAa,EAErDb,IAIJ,MAAMY,EAASC,CAAW,EAI1Bb,EAAS,IAGV,GAAM,CAAE,QAAAc,CAAQ,EAAIN,EAAY,EAAI,EAKpCF,EAAM,IAAM,CAIX,GAAM,CAAE,SAAAS,CAAS,EAAIR,EAAW,EAE3BQ,IAKLA,EAAS,QAAQ,EAKjBR,EAAK,CAAC,CAAC,EACR,CAAC,EAED,IAAMS,EAAQT,EAAW,EAEnBU,EAAeD,EAAM,UAAYb,EACjCe,EAAkB,EAAQF,EAAM,SAQtC,GADIC,GAAgBC,GAChBD,GAAgBP,EAAW,QAKlB,SAAY,CACxB,IAAMK,EAAW,MAAMF,EAAY,KAAK,CACvC,QAASC,EACT,QAASZ,EAAYC,CAAO,CAC7B,CAAC,EAEKgB,EAAQV,EAAO,UAAWA,GAAW,CAC1C,GAAKM,EAEL,GAAI,CACCN,EACHM,EAAS,MAAM,EAEfA,EAAS,KAAK,CAEhB,MAAQ,CAAC,CACV,CAAC,EAEDR,EAAW,CAAE,SAAAQ,EAAU,QAAAZ,CAAQ,CAAC,CACjC,GAKU,CACX,EAEA,OAAAE,EAAQ,eAAiBA,EAAQ,qBAAuB,GACxDA,EAAQ,GAAKJ,EACbI,EAAQ,IAAM,YAEPA,CACR,EAEMe,EAAgB,IAAM,CAC3B,IAAMf,EAAyB,CAAC,CAAE,KAAAE,EAAM,OAAAc,EAAQ,MAAO,CAAE,QAAAV,CAAQ,CAAE,IAAM,CACxE,GAAIA,EAAS,OAKb,GAAM,CAAE,SAAAI,CAAS,EAAIR,EAAW,EAK5BQ,GAAUA,EAAS,QAAQ,EAK/BM,EAAO,CACR,EAEA,OAAAhB,EAAQ,eAAiB,GACzBA,EAAQ,GAAKJ,EACbI,EAAQ,IAAM,YAEPA,CACR","names":["loaded","PARTICLES_ID","withDefault","options","showParticles","handler","clear","data","getDomNodes","paused","goingBack","preview","loadSlim","tsParticles","element","instance","_data","optionsEqual","instancePresent","unsub","hideParticles","remove"]}
@@ -0,0 +1,2 @@
1
+ var u=!1,p=Symbol(),S=t=>(t.autoPlay||=!0,t.fullScreen||={enable:!0,zIndex:2},t),C=function(t){let e=async({clear:n,data:i,getDomNodes:a,paused:P,flags:{goingBack:y,preview:d}})=>{if(d)return;let{loadSlim:f,tsParticles:l}=await this.getParticles();u||(await f(l),u=!0);let{element:m}=a(!0);n(()=>{let{instance:s,unsubscribe:r}=i();s&&(s.destroy(),r&&r(),i({}))});let c=i(),o=c.options===t,b=!!c.instance;if(o&&b||o&&y)return;(async()=>{let s=await l.load({element:m,options:S(t)}),r=P.subscribe(h=>{if(s)try{h?s.pause():s.play()}catch{}});i({instance:s,options:t,unsubscribe:r})})()};return e.callOnlyLatest=e.skipClearOnGoingBack=!0,e.id=p,e.key="particles",e},g=()=>{let t=({data:e,remove:n,flags:{preview:i}})=>{if(i)return;let{instance:a}=e();a&&a.destroy(),n()};return t.callOnlyLatest=!0,t.id=p,t.key="particles",t};export{C as a,g as b};
2
+ //# sourceMappingURL=chunk-IURPYEZG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/particles.ts"],"sourcesContent":["import type { CustomHandler } from '@novely/core';\nimport type { Container, IOptions, RecursivePartial } from '@tsparticles/engine';\n\nlet loaded = false;\n\nconst PARTICLES_ID = Symbol();\n\ntype ParticlesOptions = RecursivePartial<IOptions>;\n\ntype Data = {\n\tinstance?: Container;\n\tunsubscribe?: () => void;\n\toptions?: ParticlesOptions;\n};\n\ntype TSParticles = {\n\ttsParticles: typeof import('@tsparticles/engine').tsParticles;\n\tloadSlim: typeof import('@tsparticles/slim').loadSlim;\n};\n\ntype TSParticlesGetter = () => Promise<TSParticles>;\n\ntype ParticlesThis = {\n\tgetParticles: TSParticlesGetter;\n};\n\nconst withDefault = (options: ParticlesOptions) => {\n\toptions.autoPlay ||= true;\n\toptions.fullScreen ||= { enable: true, zIndex: 2 };\n\n\treturn options;\n};\n\nconst showParticles = function (this: ParticlesThis, options: ParticlesOptions): CustomHandler {\n\tconst handler: CustomHandler = async ({ clear, data, getDomNodes, paused, flags: { goingBack, preview } }) => {\n\t\tif (preview) return;\n\n\t\tconst { loadSlim, tsParticles } = await this.getParticles();\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 { element } = getDomNodes(true);\n\n\t\t// Remove previous instance\n\t\tclear(() => {\n\t\t\t// Get the instance\n\t\t\tconst { instance, unsubscribe } = data<Data>();\n\n\t\t\tif (!instance) return;\n\n\t\t\t// Destroy the instance\n\t\t\tinstance.destroy();\n\n\t\t\t// Unsubscribe from 'paused' listener\n\t\t\tif (unsubscribe) {\n\t\t\t\tunsubscribe();\n\t\t\t}\n\n\t\t\t// Empty the `data`\n\t\t\tdata({});\n\t\t});\n\n\t\tconst _data = data<Data>();\n\n\t\tconst optionsEqual = _data.options === options;\n\t\tconst instancePresent = Boolean(_data.instance);\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 && instancePresent) return;\n\t\tif (optionsEqual && goingBack) return;\n\n\t\t/**\n\t\t * We can not wait until particles is loaded\n\t\t */\n\t\tconst load = async () => {\n\t\t\tconst instance = await tsParticles.load({\n\t\t\t\telement: element,\n\t\t\t\toptions: withDefault(options),\n\t\t\t});\n\n\t\t\tconst unsubscribe = paused.subscribe((paused) => {\n\t\t\t\tif (!instance) return;\n\n\t\t\t\ttry {\n\t\t\t\t\tif (paused) {\n\t\t\t\t\t\tinstance.pause();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tinstance.play()\n\t\t\t\t\t}\n\t\t\t\t} catch {};\n\t\t\t});\n\n\t\t\tdata<Data>({ instance, options, unsubscribe });\n\t\t};\n\n\t\t/**\n\t\t * Should be safe because in restore only latest is called, and when playing it is not expected to change frequently\n\t\t */\n\t\tvoid load();\n\t};\n\n\thandler.callOnlyLatest = handler.skipClearOnGoingBack = true;\n\thandler.id = PARTICLES_ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nconst hideParticles = () => {\n\tconst handler: CustomHandler = ({ data, remove, flags: { preview } }) => {\n\t\tif (preview) return;\n\n\t\t/**\n\t\t * Get the instance\n\t\t */\n\t\tconst { instance } = data<Data>();\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\tremove();\n\t};\n\n\thandler.callOnlyLatest = true;\n\thandler.id = PARTICLES_ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nexport { showParticles, hideParticles };\n"],"mappings":"AAGA,IAAIA,EAAS,GAEPC,EAAe,OAAO,EAqBtBC,EAAeC,IACpBA,EAAQ,WAAa,GACrBA,EAAQ,aAAe,CAAE,OAAQ,GAAM,OAAQ,CAAE,EAE1CA,GAGFC,EAAgB,SAA+BD,EAA0C,CAC9F,IAAME,EAAyB,MAAO,CAAE,MAAAC,EAAO,KAAAC,EAAM,YAAAC,EAAa,OAAAC,EAAQ,MAAO,CAAE,UAAAC,EAAW,QAAAC,CAAQ,CAAE,IAAM,CAC7G,GAAIA,EAAS,OAEb,GAAM,CAAE,SAAAC,EAAU,YAAAC,CAAY,EAAI,MAAM,KAAK,aAAa,EAErDb,IAIJ,MAAMY,EAASC,CAAW,EAI1Bb,EAAS,IAGV,GAAM,CAAE,QAAAc,CAAQ,EAAIN,EAAY,EAAI,EAGpCF,EAAM,IAAM,CAEX,GAAM,CAAE,SAAAS,EAAU,YAAAC,CAAY,EAAIT,EAAW,EAExCQ,IAGLA,EAAS,QAAQ,EAGbC,GACHA,EAAY,EAIbT,EAAK,CAAC,CAAC,EACR,CAAC,EAED,IAAMU,EAAQV,EAAW,EAEnBW,EAAeD,EAAM,UAAYd,EACjCgB,EAAkB,EAAQF,EAAM,SAQtC,GADIC,GAAgBC,GAChBD,GAAgBR,EAAW,QAKlB,SAAY,CACxB,IAAMK,EAAW,MAAMF,EAAY,KAAK,CACvC,QAASC,EACT,QAASZ,EAAYC,CAAO,CAC7B,CAAC,EAEKa,EAAcP,EAAO,UAAWA,GAAW,CAChD,GAAKM,EAEL,GAAI,CACCN,EACHM,EAAS,MAAM,EAEfA,EAAS,KAAK,CAEhB,MAAQ,CAAC,CACV,CAAC,EAEDR,EAAW,CAAE,SAAAQ,EAAU,QAAAZ,EAAS,YAAAa,CAAY,CAAC,CAC9C,GAKU,CACX,EAEA,OAAAX,EAAQ,eAAiBA,EAAQ,qBAAuB,GACxDA,EAAQ,GAAKJ,EACbI,EAAQ,IAAM,YAEPA,CACR,EAEMe,EAAgB,IAAM,CAC3B,IAAMf,EAAyB,CAAC,CAAE,KAAAE,EAAM,OAAAc,EAAQ,MAAO,CAAE,QAAAV,CAAQ,CAAE,IAAM,CACxE,GAAIA,EAAS,OAKb,GAAM,CAAE,SAAAI,CAAS,EAAIR,EAAW,EAK5BQ,GAAUA,EAAS,QAAQ,EAK/BM,EAAO,CACR,EAEA,OAAAhB,EAAQ,eAAiB,GACzBA,EAAQ,GAAKJ,EACbI,EAAQ,IAAM,YAEPA,CACR","names":["loaded","PARTICLES_ID","withDefault","options","showParticles","handler","clear","data","getDomNodes","paused","goingBack","preview","loadSlim","tsParticles","element","instance","unsubscribe","_data","optionsEqual","instancePresent","hideParticles","remove"]}
@@ -0,0 +1,2 @@
1
+ var o=!1,u=Symbol(),S=t=>(t.autoPlay||=!0,t.fullScreen||={enable:!0,zIndex:2},t),g=function(t){let e=async({clear:r,data:a,getDomNodes:i,paused:p,flags:{goingBack:P,preview:y}})=>{if(y)return;let{loadSlim:d,tsParticles:n}=await this.getParticles();o||(await d(n),o=!0);let{element:f}=i(!0);r(()=>{let{instance:s}=a();s&&(s.destroy(),a({}))});let l=a(),c=l.options===t,m=!!l.instance;if(c&&m||c&&P)return;(async()=>{let s=await n.load({element:f,options:S(t)}),C=p.subscribe(h=>{if(s)try{h?s.pause():s.play()}catch{}});a({instance:s,options:t})})()};return e.callOnlyLatest=e.skipClearOnGoingBack=!0,e.id=u,e.key="particles",e},D=()=>{let t=({data:e,remove:r,flags:{preview:a}})=>{if(a)return;let{instance:i}=e();i&&i.destroy(),r()};return t.callOnlyLatest=!0,t.id=u,t.key="particles",t};export{g as a,D as b};
2
+ //# sourceMappingURL=chunk-M4JDNZCD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/particles.ts"],"sourcesContent":["import type { CustomHandler } from '@novely/core';\nimport type { Container, IOptions, RecursivePartial } from '@tsparticles/engine';\n\nlet loaded = false;\n\nconst PARTICLES_ID = Symbol();\n\ntype ParticlesOptions = RecursivePartial<IOptions>;\n\ntype Data = {\n\tinstance?: Container;\n\toptions?: ParticlesOptions;\n};\n\ntype TSParticles = {\n\ttsParticles: typeof import('@tsparticles/engine').tsParticles;\n\tloadSlim: typeof import('@tsparticles/slim').loadSlim;\n};\n\ntype TSParticlesGetter = () => Promise<TSParticles>;\n\ntype ParticlesThis = {\n\tgetParticles: TSParticlesGetter;\n};\n\nconst withDefault = (options: ParticlesOptions) => {\n\toptions.autoPlay ||= true;\n\toptions.fullScreen ||= { enable: true, zIndex: 2 };\n\n\treturn options;\n};\n\nconst showParticles = function (this: ParticlesThis, options: ParticlesOptions): CustomHandler {\n\tconst handler: CustomHandler = async ({ clear, data, getDomNodes, paused, flags: { goingBack, preview } }) => {\n\t\tif (preview) return;\n\n\t\tconst { loadSlim, tsParticles } = await this.getParticles();\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 { element } = getDomNodes(true);\n\n\t\t/**\n\t\t * Remove previous instance\n\t\t */\n\t\tclear(() => {\n\t\t\t/**\n\t\t\t * Get the instance\n\t\t\t */\n\t\t\tconst { instance } = data<Data>();\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\tdata({});\n\t\t});\n\n\t\tconst _data = data<Data>();\n\n\t\tconst optionsEqual = _data.options === options;\n\t\tconst instancePresent = Boolean(_data.instance);\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 && instancePresent) return;\n\t\tif (optionsEqual && goingBack) return;\n\n\t\t/**\n\t\t * We can not wait until particles is loaded\n\t\t */\n\t\tconst load = async () => {\n\t\t\tconst instance = await tsParticles.load({\n\t\t\t\telement: element,\n\t\t\t\toptions: withDefault(options),\n\t\t\t});\n\n\t\t\tconst unsub = paused.subscribe((paused) => {\n\t\t\t\tif (!instance) return;\n\n\t\t\t\ttry {\n\t\t\t\t\tif (paused) {\n\t\t\t\t\t\tinstance.pause();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tinstance.play()\n\t\t\t\t\t}\n\t\t\t\t} catch {};\n\t\t\t});\n\n\t\t\tdata<Data>({ instance, options });\n\t\t};\n\n\t\t/**\n\t\t * Should be safe because in restore only latest is called, and when playing it is not expected to change frequently\n\t\t */\n\t\tvoid load();\n\t};\n\n\thandler.callOnlyLatest = handler.skipClearOnGoingBack = true;\n\thandler.id = PARTICLES_ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nconst hideParticles = () => {\n\tconst handler: CustomHandler = ({ data, remove, flags: { preview } }) => {\n\t\tif (preview) return;\n\n\t\t/**\n\t\t * Get the instance\n\t\t */\n\t\tconst { instance } = data<Data>();\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\trem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ACxDA,EAAQ,GAAKJ,EACbI,EAAQ,IAAM,YAEPA,CACR,EAEMe,EAAgB,IAAM,CAC3B,IAAMf,EAAyB,CAAC,CAAE,KAAAE,EAAM,OAAAc,EAAQ,MAAO,CAAE,QAAAV,CAAQ,CAAE,IAAM,CACxE,GAAIA,EAAS,OAKb,GAAM,CAAE,SAAAI,CAAS,EAAIR,EAAW,EAK5BQ,GAAUA,EAAS,QAAQ,EAK/BM,EAAO,CACR,EAEA,OAAAhB,EAAQ,eAAiB,GACzBA,EAAQ,GAAKJ,EACbI,EAAQ,IAAM,YAEPA,CACR","names":["loaded","PARTICLES_ID","withDefault","options","showParticles","handler","clear","data","getDomNodes","paused","goingBack","preview","loadSlim","tsParticles","element","instance","_data","optionsEqual","instancePresent","unsub","hideParticles","remove"]}
@@ -0,0 +1,2 @@
1
+ var u=!1,p=Symbol(),S=t=>(t.autoPlay||=!0,t.fullScreen||={enable:!0,zIndex:2},t),C=function(t){let e=async({clear:n,data:i,getDomNodes:a,paused:P,flags:{goingBack:y,preview:d}})=>{if(d)return;let{loadSlim:f,tsParticles:l}=await this.getParticles();u||(await f(l),u=!0);let{element:m}=a(!0);n(()=>{let{instance:s,unsubscribe:r}=i();s&&(s.destroy(),r&&r(),i({}))});let c=i(),o=c.options===t,b=!!c.instance;if(o&&b||o&&y)return;(async()=>{let s=await l.load({element:m,options:S(t)}),r=P.subscribe(h=>{if(s)try{h?s.pause():s.play()}catch{}});i({instance:s,options:t,unsubscribe:r})})()};return e.callOnlyLatest=e.skipClearOnGoingBack=!0,e.id=p,e.key="particles",e},g=()=>{let t=({data:e,remove:n,flags:{preview:i}})=>{if(i)return;let{instance:a}=e();a&&a.destroy(),n()};return t.callOnlyLatest=!0,t.id=p,t.key="particles",t};export{C as a,g as b};
2
+ //# sourceMappingURL=chunk-MIBR7ULU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/particles.ts"],"sourcesContent":["import type { CustomHandler } from '@novely/core';\nimport type { Container, IOptions, RecursivePartial } from '@tsparticles/engine';\n\nlet loaded = false;\n\nconst PARTICLES_ID = Symbol();\n\ntype ParticlesOptions = RecursivePartial<IOptions>;\n\ntype Data = {\n\tinstance?: Container;\n\tunsubscribe?: () => void;\n\toptions?: ParticlesOptions;\n};\n\ntype TSParticles = {\n\ttsParticles: typeof import('@tsparticles/engine').tsParticles;\n\tloadSlim: typeof import('@tsparticles/slim').loadSlim;\n};\n\ntype TSParticlesGetter = () => Promise<TSParticles>;\n\ntype ParticlesThis = {\n\tgetParticles: TSParticlesGetter;\n};\n\nconst withDefault = (options: ParticlesOptions) => {\n\toptions.autoPlay ||= true;\n\toptions.fullScreen ||= { enable: true, zIndex: 2 };\n\n\treturn options;\n};\n\nconst showParticles = function (this: ParticlesThis, options: ParticlesOptions): CustomHandler {\n\tconst handler: CustomHandler = async ({ clear, data, getDomNodes, paused, flags: { goingBack, preview } }) => {\n\t\tif (preview) return;\n\n\t\tconst { loadSlim, tsParticles } = await this.getParticles();\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 { element } = getDomNodes(true);\n\n\t\t// Remove previous instance\n\t\tclear(() => {\n\t\t\t// Get the instance\n\t\t\tconst { instance, unsubscribe } = data<Data>();\n\n\t\t\tif (!instance) return;\n\n\t\t\t// Destroy the instance\n\t\t\tinstance.destroy();\n\n\t\t\t// Unsubscribe from 'paused' listener\n\t\t\tif (unsubscribe) {\n\t\t\t\tunsubscribe();\n\t\t\t}\n\n\t\t\t// Empty the `data`\n\t\t\tdata({});\n\t\t});\n\n\t\tconst _data = data<Data>();\n\n\t\tconst optionsEqual = _data.options === options;\n\t\tconst instancePresent = Boolean(_data.instance);\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 && instancePresent) return;\n\t\tif (optionsEqual && goingBack) return;\n\n\t\t/**\n\t\t * We can not wait until particles is loaded\n\t\t */\n\t\tconst load = async () => {\n\t\t\tconst instance = await tsParticles.load({\n\t\t\t\telement: element,\n\t\t\t\toptions: withDefault(options),\n\t\t\t});\n\n\t\t\tconst unsubscribe = paused.subscribe((paused) => {\n\t\t\t\tif (!instance) return;\n\n\t\t\t\ttry {\n\t\t\t\t\tif (paused) {\n\t\t\t\t\t\tinstance.pause();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tinstance.play();\n\t\t\t\t\t}\n\t\t\t\t} catch {}\n\t\t\t});\n\n\t\t\tdata<Data>({ instance, options, unsubscribe });\n\t\t};\n\n\t\t/**\n\t\t * Should be safe because in restore only latest is called, and when playing it is not expected to change frequently\n\t\t */\n\t\tvoid load();\n\t};\n\n\thandler.callOnlyLatest = handler.skipClearOnGoingBack = true;\n\thandler.id = PARTICLES_ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nconst hideParticles = () => {\n\tconst handler: CustomHandler = ({ data, remove, flags: { preview } }) => {\n\t\tif (preview) return;\n\n\t\t/**\n\t\t * Get the instance\n\t\t */\n\t\tconst { instance } = data<Data>();\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\tremove();\n\t};\n\n\thandler.callOnlyLatest = true;\n\thandler.id = PARTICLES_ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nexport { showParticles, hideParticles };\n"],"mappings":"AAGA,IAAIA,EAAS,GAEPC,EAAe,OAAO,EAqBtBC,EAAeC,IACpBA,EAAQ,WAAa,GACrBA,EAAQ,aAAe,CAAE,OAAQ,GAAM,OAAQ,CAAE,EAE1CA,GAGFC,EAAgB,SAA+BD,EAA0C,CAC9F,IAAME,EAAyB,MAAO,CAAE,MAAAC,EAAO,KAAAC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,EAAQ,eAAiB,GACzBA,EAAQ,GAAKJ,EACbI,EAAQ,IAAM,YAEPA,CACR","names":["loaded","PARTICLES_ID","withDefault","options","showParticles","handler","clear","data","getDomNodes","paused","goingBack","preview","loadSlim","tsParticles","element","instance","unsubscribe","_data","optionsEqual","instancePresent","hideParticles","remove"]}