@mar7th/firework 1.0.0 → 1.0.1
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 +163 -0
- package/advanced-guide.html +1 -0
- package/api-download.html +1 -0
- package/demo.html +1 -0
- package/guide.html +12 -0
- package/index.html +1 -0
- package/package.json +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# SparkFireworks
|
|
2
|
+
|
|
3
|
+
一个轻量的网页烟花模拟器和烟花效果库,支持可视化调参、内置预设、CDN 直接引入、npm 安装以及高级脚本自定义粒子。
|
|
4
|
+
|
|
5
|
+
## 在线与源码
|
|
6
|
+
|
|
7
|
+
- npm: <https://www.npmjs.com/package/@mar7th/firework>
|
|
8
|
+
- Gitee: <https://gitee.com/march7th-online/firework-yoimiya>
|
|
9
|
+
|
|
10
|
+
## 安装
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @mar7th/firework
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 使用
|
|
17
|
+
|
|
18
|
+
### ESM
|
|
19
|
+
|
|
20
|
+
```html
|
|
21
|
+
<canvas id="fireworks" style="width:100vw;height:100vh;display:block"></canvas>
|
|
22
|
+
|
|
23
|
+
<script type="module">
|
|
24
|
+
import SparkFireworks from "@mar7th/firework";
|
|
25
|
+
|
|
26
|
+
const fireworks = SparkFireworks.create("fireworks", {
|
|
27
|
+
particleCount: 220,
|
|
28
|
+
colorStart: "#ffd166",
|
|
29
|
+
colorEnd: "#ef476f",
|
|
30
|
+
enableTrails: true
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
fireworks.launchRandom();
|
|
34
|
+
</script>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### CDN
|
|
38
|
+
|
|
39
|
+
unpkg:
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<script type="module">
|
|
43
|
+
import SparkFireworks from "https://unpkg.com/@mar7th/firework@1.0.0/dist-lib/spark-fireworks.js";
|
|
44
|
+
|
|
45
|
+
const fireworks = SparkFireworks.create("fireworks", {
|
|
46
|
+
autoLaunch: true
|
|
47
|
+
});
|
|
48
|
+
</script>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
jsDelivr:
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<script type="module">
|
|
55
|
+
import SparkFireworks from "https://cdn.jsdelivr.net/npm/@mar7th/firework@1.0.0/dist-lib/spark-fireworks.js";
|
|
56
|
+
|
|
57
|
+
const fireworks = SparkFireworks.create("fireworks", {
|
|
58
|
+
autoLaunch: true
|
|
59
|
+
});
|
|
60
|
+
</script>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
UMD:
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<canvas id="fireworks" style="width:100vw;height:100vh;display:block"></canvas>
|
|
67
|
+
<script src="https://cdn.jsdelivr.net/npm/@mar7th/firework@1.0.0/dist-lib/spark-fireworks.umd.cjs"></script>
|
|
68
|
+
<script>
|
|
69
|
+
const fireworks = SparkFireworks.create("fireworks", {
|
|
70
|
+
autoLaunch: true,
|
|
71
|
+
autoLaunchIntervalSeconds: 1
|
|
72
|
+
});
|
|
73
|
+
</script>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 常用 API
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
const fireworks = SparkFireworks.create(canvasOrId, configOrOptions);
|
|
80
|
+
|
|
81
|
+
fireworks.launch(x, y);
|
|
82
|
+
fireworks.launchRandom();
|
|
83
|
+
fireworks.startAutoPlay(seconds);
|
|
84
|
+
fireworks.stopAutoPlay();
|
|
85
|
+
fireworks.setConfig({ particleCount: 300 });
|
|
86
|
+
fireworks.destroy();
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`create` 的第一个参数可以是 canvas 元素,也可以是 canvas 的 id。第二个参数可以直接传配置,也可以传完整 options:
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
SparkFireworks.create("fireworks", {
|
|
93
|
+
config: {
|
|
94
|
+
explosionShape: "heart",
|
|
95
|
+
particleCount: 300
|
|
96
|
+
},
|
|
97
|
+
onFpsChange(fps) {
|
|
98
|
+
console.log("FPS", fps);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
更完整的 API 说明见 [docs/api-guide.md](docs/api-guide.md)。
|
|
104
|
+
|
|
105
|
+
## 高级脚本
|
|
106
|
+
|
|
107
|
+
高级模式允许你通过 `createParticles(canvasData)` 完全控制粒子的生成方式。高级模式下所有参数均以脚本设置为准,页面设置可能被覆盖不生效。
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
SparkFireworks.create("fireworks", {
|
|
111
|
+
advancedMode: true,
|
|
112
|
+
createParticles(canvasData) {
|
|
113
|
+
return {
|
|
114
|
+
config: {
|
|
115
|
+
gravity: 0.08,
|
|
116
|
+
enableTrails: true
|
|
117
|
+
},
|
|
118
|
+
particles: [
|
|
119
|
+
{
|
|
120
|
+
x: canvasData.x,
|
|
121
|
+
y: canvasData.y,
|
|
122
|
+
vx: 2,
|
|
123
|
+
vy: -3,
|
|
124
|
+
size: 4,
|
|
125
|
+
life: 90,
|
|
126
|
+
startColor: "#ffd166",
|
|
127
|
+
endColor: "#ef476f"
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 本地开发
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
npm install
|
|
139
|
+
npm run dev
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
构建页面和库文件:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
npm run build
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
只构建库文件:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npm run build:lib
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
构建产物:
|
|
155
|
+
|
|
156
|
+
```text
|
|
157
|
+
dist-lib/spark-fireworks.js
|
|
158
|
+
dist-lib/spark-fireworks.umd.cjs
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
MIT License. See [LICENSE](LICENSE).
|
package/advanced-guide.html
CHANGED
package/api-download.html
CHANGED
package/demo.html
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
<div class="top-bar">
|
|
24
24
|
<div class="action-group" aria-label="预设与配置">
|
|
25
25
|
<a class="toolbar-link" href="/">首页</a>
|
|
26
|
+
<a class="toolbar-link" href="https://gitee.com/march7th-online/firework-yoimiya" target="_blank" rel="noreferrer">开源地址</a>
|
|
26
27
|
<select id="presetSelect" aria-label="选择预设"></select>
|
|
27
28
|
<button id="resetConfigButton" type="button">初始化设置</button>
|
|
28
29
|
<button id="savePresetButton" type="button">保存</button>
|
package/guide.html
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
<a href="/guide.html">使用指导</a>
|
|
26
26
|
<a href="/advanced-guide.html">高级指导</a>
|
|
27
27
|
<a href="/api-download.html">API 下载</a>
|
|
28
|
+
<a href="https://gitee.com/march7th-online/firework-yoimiya" target="_blank" rel="noreferrer">开源地址</a>
|
|
28
29
|
</div>
|
|
29
30
|
</nav>
|
|
30
31
|
|
|
@@ -43,6 +44,17 @@
|
|
|
43
44
|
</ol>
|
|
44
45
|
</section>
|
|
45
46
|
|
|
47
|
+
<section class="doc-section">
|
|
48
|
+
<h2>npm 包地址</h2>
|
|
49
|
+
<p>
|
|
50
|
+
SparkFireworks 已发布到 npm:
|
|
51
|
+
<a href="https://www.npmjs.com/package/@mar7th/firework" target="_blank" rel="noreferrer">https://www.npmjs.com/package/@mar7th/firework</a>
|
|
52
|
+
</p>
|
|
53
|
+
<pre><code>npm install @mar7th/firework</code></pre>
|
|
54
|
+
<p>源码仓库:<a href="https://gitee.com/march7th-online/firework-yoimiya" target="_blank" rel="noreferrer">Gitee 开源地址</a></p>
|
|
55
|
+
<p class="note">如果只想通过 CDN 直接引入,请查看 <a href="/api-download.html">API 下载</a> 页面中的 unpkg 和 jsDelivr 示例。</p>
|
|
56
|
+
</section>
|
|
57
|
+
|
|
46
58
|
<section class="doc-section">
|
|
47
59
|
<h2>顶部工具栏</h2>
|
|
48
60
|
<ul>
|
package/index.html
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mar7th/firework",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist-lib/spark-fireworks.umd.cjs",
|
|
6
6
|
"module": "./dist-lib/spark-fireworks.js",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"docs",
|
|
19
19
|
"examples",
|
|
20
20
|
"*.html",
|
|
21
|
+
"README.md",
|
|
21
22
|
"favicon.jpg",
|
|
22
23
|
"vite.config.js",
|
|
23
24
|
"vite.lib.config.js"
|