@novely/particles 0.1.0 → 0.2.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.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { SingleOrMultiple, RecursivePartial, IOptions } from 'tsparticles-engine';
1
+ import { RecursivePartial, IOptions } from 'tsparticles-engine';
2
2
  import { CustomHandler } from '@novely/core';
3
3
 
4
- type SingleParticlesOptions = RecursivePartial<IOptions>;
5
- type ParticlesOptions = SingleOrMultiple<SingleParticlesOptions>;
4
+ type ParticlesOptions = RecursivePartial<IOptions>;
6
5
  declare const particles: (options: ParticlesOptions) => CustomHandler;
7
6
  declare const hide: () => CustomHandler;
8
7
 
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
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 e=async(r,p)=>{o||(await d(s),o=!0);let a=r("particles");a.clear(()=>{let l=a.data().instance;l&&(l.destroy(),a.data({}))});let n=a.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));a.data({instance:u,options:t})};return e.callOnlyLatest=e.skipClearOnGoingBack=!0,e},y=()=>t=>{let e=t("particles"),r=e.data().instance;r&&r.destroy(),e.delete()};export{y as hide,m as particles};
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 r=async(s,a,n)=>{if(n)return;u||(await f(c),u=!0);let e=s(!0);e.clear(()=>{let l=e.data().instance;l&&(l.destroy(),e.data({}))});let i=e.data(),o=i.options===t;if(o&&i.instance||o&&a)return;let p=C(),m=await c.set(p,e.element,y(t));e.data({instance:m,options:t})};return r.callOnlyLatest=r.skipClearOnGoingBack=!0,r.id=d,r.key="particles",r},P=()=>{let t=(r,s,a)=>{if(a)return;let n=r(!0),e=n.data().instance;e&&e.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 { 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 * 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 = handler.skipClearOnGoingBack = 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,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,eAAiBA,EAAQ,qBAAuB,GAEjDA,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"]}
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,MAAOC,EAAKC,EAAWC,IAAY,CACjE,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,CAACC,EAAKS,EAAGP,IAAY,CACnD,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","_"]}
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
1
  {
2
- "name": "@novely/particles",
3
- "description": "Particles Action",
4
- "version": "0.1.0",
5
- "type": "module",
6
- "sideEffects": false,
7
- "types": "./dist/index.d.ts",
8
- "main": "./dist/index.js",
9
- "module": "./dist/index.js",
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "scripts": {
14
- "dev": "tsup --watch",
15
- "build": "tsup --dts"
16
- },
17
- "dependencies": {
18
- "@novely/core": "workspace:*",
19
- "tsparticles-engine": "^2.9.3",
20
- "tsparticles-slim": "^2.9.3"
21
- },
22
- "devDependencies": {
23
- "tsup": "^6.6.0",
24
- "typescript": "^4.9.5"
25
- },
26
- "peerDependencies": {
27
- "@novely/core": "*",
28
- "tsparticles-engine": "^2.9.3",
29
- "tsparticles-slim": "^2.9.3"
30
- },
31
- "license": "ISC",
32
- "bugs": {
33
- "url": "https://github.com/yhdgms1/novely/issues"
34
- },
35
- "homepage": "https://github.com/yhdgms1/novely/tree/main/packages/particles",
36
- "keywords": [
37
- "ts-particles",
38
- "particles",
39
- "novely"
40
- ],
41
- "author": {
42
- "name": "Artemiy Schukin",
43
- "url": "https://github.com/yhdgms1"
44
- },
45
- "contributors": [],
46
- "repository": {
47
- "type": "git",
48
- "url": "git+https://github.com/yhdgms1/novely.git"
49
- },
50
- "files": [
51
- "dist/*"
52
- ]
2
+ "name": "@novely/particles",
3
+ "description": "Particles Action",
4
+ "version": "0.2.0",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "types": "./dist/index.d.ts",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "scripts": {
14
+ "dev": "tsup --watch",
15
+ "build": "tsup --dts"
16
+ },
17
+ "dependencies": {
18
+ "@novely/core": "workspace:*",
19
+ "tsparticles-engine": "^2.10.1",
20
+ "tsparticles-slim": "^2.10.1"
21
+ },
22
+ "devDependencies": {
23
+ "tsup": "^8.0.0",
24
+ "typescript": "^5.2.2"
25
+ },
26
+ "peerDependencies": {
27
+ "@novely/core": "*",
28
+ "tsparticles-engine": "^2.9.3",
29
+ "tsparticles-slim": "^2.9.3"
30
+ },
31
+ "license": "ISC",
32
+ "bugs": {
33
+ "url": "https://github.com/yhdgms1/novely/issues"
34
+ },
35
+ "homepage": "https://github.com/yhdgms1/novely/tree/main/packages/particles",
36
+ "keywords": [
37
+ "ts-particles",
38
+ "particles",
39
+ "novely"
40
+ ],
41
+ "author": {
42
+ "name": "Artemiy Schukin",
43
+ "url": "https://github.com/yhdgms1"
44
+ },
45
+ "contributors": [],
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/yhdgms1/novely.git"
49
+ },
50
+ "files": [
51
+ "dist/*"
52
+ ]
53
53
  }