@novely/particles 0.3.0 → 0.4.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 +4 -8
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +50 -52
package/README.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
# @novely/particles
|
|
2
2
|
|
|
3
|
-
Эффект частиц
|
|
4
|
-
|
|
5
|
-
## Требования
|
|
6
|
-
|
|
7
|
-
Для работы эффектов требуется установить [tsparticles-engine](https://www.npmjs.com/package/tsparticles-engine) и [tsparticles-slim](https://www.npmjs.com/package/tsparticles-slim)
|
|
3
|
+
Эффект частиц на основе ts-particles
|
|
8
4
|
|
|
9
5
|
## Использование
|
|
10
6
|
|
|
11
7
|
```ts
|
|
12
|
-
import {
|
|
8
|
+
import { showParticles, hideParticles } from '@novely/particles';
|
|
13
9
|
|
|
14
10
|
const snow = {
|
|
15
11
|
// Смотрите больше здесь
|
|
@@ -22,11 +18,11 @@ engine.withStory({
|
|
|
22
18
|
/**
|
|
23
19
|
* Показывает частицы
|
|
24
20
|
*/
|
|
25
|
-
engine.action.custom(
|
|
21
|
+
engine.action.custom(showParticles(snow)),
|
|
26
22
|
/**
|
|
27
23
|
* Скрывает частицы
|
|
28
24
|
*/
|
|
29
|
-
engine.action.custom(
|
|
25
|
+
engine.action.custom(hideParticles()),
|
|
30
26
|
]
|
|
31
27
|
});
|
|
32
28
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { RecursivePartial, IOptions } from 'tsparticles
|
|
1
|
+
import { RecursivePartial, IOptions } from '@tsparticles/engine';
|
|
2
2
|
import { CustomHandler } from '@novely/core';
|
|
3
3
|
|
|
4
4
|
type ParticlesOptions = RecursivePartial<IOptions>;
|
|
5
|
-
declare const
|
|
6
|
-
declare const
|
|
5
|
+
declare const showParticles: (options: ParticlesOptions) => CustomHandler;
|
|
6
|
+
declare const hideParticles: () => CustomHandler;
|
|
7
7
|
|
|
8
|
-
export {
|
|
8
|
+
export { hideParticles, showParticles };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{tsParticles as
|
|
1
|
+
import{tsParticles as u}from"@tsparticles/engine";import{loadSlim as y}from"@tsparticles/slim";var d=!1,m=Symbol(),f=t=>(t.autoPlay||=!0,t.fullScreen||={enable:!0},t),P=(()=>{let t=0;return()=>`np-${t++}`})(),C=t=>{let e=async({get:i,goingBack:a,preview:n})=>{if(n)return;d||(await y(u),d=!0);let r=i(!0);r.clear(()=>{let c=r.data().instance;c&&(c.destroy(),r.data({}))});let o=r.data(),l=o.options===t;if(l&&o.instance||l&&a)return;let p=P(),s=await u.load({id:p,element:r.element,options:f(t)});s&&s.canvas.element&&s.canvas.element.style.setProperty("z-index","2"),r.data({instance:s,options:t})};return e.callOnlyLatest=e.skipClearOnGoingBack=!0,e.id=m,e.key="particles",e},O=()=>{let t=({get:e,preview:i})=>{if(i)return;let a=e(!0),n=a.data().instance;n&&n.destroy(),a.remove()};return t.callOnlyLatest=!0,t.id=m,t.key="particles",t};export{O as hideParticles,C as showParticles};
|
|
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
|
|
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 };\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 showParticles = (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.load({\n\t\t\tid: id,\n\t\t\telement: layer.element,\n\t\t\toptions: withDefault(options)\n\t\t});\n\n\t\tif (instance && instance.canvas.element) {\n\t\t\tinstance.canvas.element.style.setProperty('z-index', '2')\n\t\t}\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 hideParticles = () => {\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.remove();\n\t};\n\n\thandler.callOnlyLatest = true;\n\thandler.id = ID;\n\thandler.key = 'particles';\n\n\treturn handler;\n};\n\nexport { showParticles, hideParticles };\n"],"mappings":"AAGA,OAAS,eAAAA,MAAmB,sBAC5B,OAAS,YAAAC,MAAgB,oBAEzB,IAAIC,EAAS,GAEPC,EAAK,OAAO,EAIZC,EAAeC,IACpBA,EAAQ,WAAa,GACrBA,EAAQ,aAAe,CAAE,OAAQ,EAAK,EAE/BA,GAGFC,GAAgB,IAAM,CAC3B,IAAIC,EAAI,EAER,MAAO,IACC,MAAMA,GAAG,EAElB,GAAG,EAEGC,EAAiBH,GAA6C,CACnE,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,KAAK,CACvC,GAAIiB,EACJ,QAASJ,EAAM,QACf,QAAST,EAAYC,CAAO,CAC7B,CAAC,EAEGS,GAAYA,EAAS,OAAO,SAC/BA,EAAS,OAAO,QAAQ,MAAM,YAAY,UAAW,GAAG,EAMzDD,EAAM,KAAK,CAAE,SAAAC,EAAU,QAAAT,CAAQ,CAAC,CACjC,EAEA,OAAAI,EAAQ,eAAiBA,EAAQ,qBAAuB,GACxDA,EAAQ,GAAKN,EACbM,EAAQ,IAAM,YAEPA,CACR,EAEMS,EAAgB,IAAM,CAC3B,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","showParticles","handler","get","goingBack","preview","layer","instance","data","optionsEqual","id","hideParticles"]}
|
package/package.json
CHANGED
|
@@ -1,53 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
]
|
|
53
|
-
}
|
|
2
|
+
"name": "@novely/particles",
|
|
3
|
+
"description": "Particles Action",
|
|
4
|
+
"version": "0.4.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
|
+
"dependencies": {
|
|
14
|
+
"@tsparticles/engine": "~3.3.0",
|
|
15
|
+
"@tsparticles/slim": "~3.3.0",
|
|
16
|
+
"@novely/core": "0.33.1"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"tsup": "^8.0.2",
|
|
20
|
+
"typescript": "^5.4.5"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@novely/core": "*"
|
|
24
|
+
},
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/yhdgms1/novely/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/yhdgms1/novely/tree/main/packages/particles",
|
|
30
|
+
"keywords": [
|
|
31
|
+
"ts-particles",
|
|
32
|
+
"particles",
|
|
33
|
+
"novely"
|
|
34
|
+
],
|
|
35
|
+
"author": {
|
|
36
|
+
"name": "Artemiy Schukin",
|
|
37
|
+
"url": "https://github.com/yhdgms1"
|
|
38
|
+
},
|
|
39
|
+
"contributors": [],
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/yhdgms1/novely.git"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist/*"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"dev": "tsup --watch --dts",
|
|
49
|
+
"build": "tsup --dts"
|
|
50
|
+
}
|
|
51
|
+
}
|