@cycjimmy/canvas-snow 3.0.2 → 4.0.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 +69 -25
- package/dist/Snow.d.ts +15 -0
- package/dist/SnowList.d.ts +9 -0
- package/dist/canvas-snow.esm.js +234 -332
- package/dist/canvas-snow.umd.js +246 -348
- package/dist/canvas-snow.umd.min.js +2 -2
- package/dist/index.d.ts +45 -0
- package/dist/tools.d.ts +35 -0
- package/package.json +30 -14
- package/dist/canvas-snow.cjs +0 -342
package/README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
# Canvas Snow
|
|
2
2
|
|
|
3
|
-
![][workflows-badge-image]
|
|
4
|
-
[![libraries dependency status][libraries-status-image]][libraries-status-url]
|
|
5
|
-
[![libraries sourcerank][libraries-sourcerank-image]][libraries-sourcerank-url]
|
|
3
|
+
[![Test CI][workflows-badge-image]][workflows-url]
|
|
6
4
|
[![Coverage Status][coverage-image]][coverage-url]
|
|
7
5
|
[![Release date][release-date-image]][release-url]
|
|
8
|
-
[![
|
|
6
|
+
[![vite][vite-image]][vite-url]
|
|
7
|
+
[![vitest][vitest-image]][vitest-url]
|
|
9
8
|
[![semantic-release][semantic-image]][semantic-url]
|
|
10
|
-
[![jest][jest-image]][jest-url]
|
|
11
9
|
[![npm license][license-image]][download-url]
|
|
12
10
|
|
|
13
11
|
* Generates snow in canvas. ([Demo][github-pages-url])
|
|
@@ -25,14 +23,17 @@ $ npm install @cycjimmy/canvas-snow --save
|
|
|
25
23
|
$ yarn add @cycjimmy/canvas-snow
|
|
26
24
|
```
|
|
27
25
|
|
|
26
|
+
The package is ESM only and ships its own type declarations, so it works with a
|
|
27
|
+
bundler or a native `import` without any extra setup.
|
|
28
|
+
|
|
28
29
|
## Usage
|
|
29
30
|
```javascript
|
|
30
|
-
import CanvasSnow from '@cycjimmy/canvas-snow'
|
|
31
|
+
import CanvasSnow from '@cycjimmy/canvas-snow'
|
|
31
32
|
|
|
32
33
|
const canvasSnow = new CanvasSnow({
|
|
33
34
|
...options
|
|
34
|
-
}).init()
|
|
35
|
-
canvasSnow.start()
|
|
35
|
+
}).init()
|
|
36
|
+
canvasSnow.start()
|
|
36
37
|
```
|
|
37
38
|
|
|
38
39
|
* `options`
|
|
@@ -49,15 +50,15 @@ canvasSnow.start();
|
|
|
49
50
|
|
|
50
51
|
### Use in browser
|
|
51
52
|
```html
|
|
52
|
-
<div
|
|
53
|
+
<div class="snow-wrapper"></div>
|
|
53
54
|
<script src="canvas-snow.umd.min.js"></script>
|
|
54
55
|
<script>
|
|
55
|
-
const canvasSnow = new CanvasSnow(
|
|
56
|
-
context: '
|
|
57
|
-
|
|
58
|
-
}).init()
|
|
56
|
+
const canvasSnow = new CanvasSnow({
|
|
57
|
+
context: '.snow-wrapper',
|
|
58
|
+
cell: 30
|
|
59
|
+
}).init()
|
|
59
60
|
|
|
60
|
-
canvasSnow.start()
|
|
61
|
+
canvasSnow.start()
|
|
61
62
|
</script>
|
|
62
63
|
```
|
|
63
64
|
|
|
@@ -66,9 +67,56 @@ canvasSnow.start();
|
|
|
66
67
|
|
|
67
68
|
To use via a CDN include this in your HTML:
|
|
68
69
|
```text
|
|
69
|
-
<script src="https://cdn.jsdelivr.net/npm/@cycjimmy/canvas-snow@
|
|
70
|
+
<script src="https://cdn.jsdelivr.net/npm/@cycjimmy/canvas-snow@4/dist/canvas-snow.umd.min.js"></script>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Migration to v4
|
|
74
|
+
|
|
75
|
+
Version 4 replaces the whole build toolchain (rollup/babel/jest → vite/vitest/typescript)
|
|
76
|
+
and drops the CommonJS bundle. Consumers upgrading from v3 need to know about
|
|
77
|
+
the following changes.
|
|
78
|
+
|
|
79
|
+
### No CommonJS bundle
|
|
80
|
+
|
|
81
|
+
`dist/canvas-snow.cjs` is gone, and the `require` condition was removed from
|
|
82
|
+
`exports`. Use `import` from ESM code:
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
import CanvasSnow from '@cycjimmy/canvas-snow'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
A CommonJS file can still load the package through dynamic `import()`, which
|
|
89
|
+
resolves to the module namespace, so the constructor is on `.default`:
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
const { default: CanvasSnow } = await import('@cycjimmy/canvas-snow')
|
|
70
93
|
```
|
|
71
94
|
|
|
95
|
+
### Bundle and browser support
|
|
96
|
+
|
|
97
|
+
* `main`, `module` and the `default` export condition all point at
|
|
98
|
+
`dist/canvas-snow.esm.js`. The UMD builds (`canvas-snow.umd.js` and
|
|
99
|
+
`canvas-snow.umd.min.js`) are unchanged for `<script>` tags and CDNs.
|
|
100
|
+
* Every output targets ES2015, which drops the IE support the old babel build
|
|
101
|
+
still provided.
|
|
102
|
+
* Type declarations are published for the first time (`dist/index.d.ts`).
|
|
103
|
+
* The runtime dependency `@cycjimmy/awesome-js-funcs` moved to v5 and is bundled
|
|
104
|
+
into the output, so nothing extra is installed.
|
|
105
|
+
|
|
106
|
+
### Unchanged behaviour
|
|
107
|
+
|
|
108
|
+
The public API, the UMD global name (`CanvasSnow`), the three bundle file names
|
|
109
|
+
and the animation itself (13ms frame interval, sizing rules, drawing) are
|
|
110
|
+
identical to v3.
|
|
111
|
+
|
|
112
|
+
The only visible surface reduction is that `_initCanvas`, `_newSnow` and
|
|
113
|
+
`_getRandom` became private implementation details; they were never documented
|
|
114
|
+
and should not be called from the outside.
|
|
115
|
+
|
|
116
|
+
### Requirements
|
|
117
|
+
|
|
118
|
+
Node.js `^22.18.0 || >=24.11.0` for development and for the release tooling.
|
|
119
|
+
|
|
72
120
|
<!-- Links: -->
|
|
73
121
|
[npm-image]: https://img.shields.io/npm/v/@cycjimmy/canvas-snow
|
|
74
122
|
[npm-url]: https://npmjs.org/package/@cycjimmy/canvas-snow
|
|
@@ -81,11 +129,7 @@ To use via a CDN include this in your HTML:
|
|
|
81
129
|
[jsdelivr-url]: https://www.jsdelivr.com/package/npm/@cycjimmy/canvas-snow
|
|
82
130
|
|
|
83
131
|
[workflows-badge-image]: https://github.com/cycjimmy/canvas-snow/workflows/Test%20CI/badge.svg
|
|
84
|
-
|
|
85
|
-
[libraries-status-image]: https://img.shields.io/librariesio/release/npm/@cycjimmy/canvas-snow
|
|
86
|
-
[libraries-sourcerank-image]: https://img.shields.io/librariesio/sourcerank/npm/@cycjimmy/canvas-snow
|
|
87
|
-
[libraries-status-url]: https://libraries.io/github/cycjimmy/canvas-snow
|
|
88
|
-
[libraries-sourcerank-url]: https://libraries.io/npm/@cycjimmy%2Fcanvas-snow
|
|
132
|
+
[workflows-url]: https://github.com/cycjimmy/canvas-snow/actions/workflows/nodeTestCI.yml
|
|
89
133
|
|
|
90
134
|
[coverage-image]: https://img.shields.io/coveralls/github/cycjimmy/canvas-snow
|
|
91
135
|
[coverage-url]: https://coveralls.io/github/cycjimmy/canvas-snow
|
|
@@ -93,15 +137,15 @@ To use via a CDN include this in your HTML:
|
|
|
93
137
|
[release-date-image]: https://img.shields.io/github/release-date/cycjimmy/canvas-snow
|
|
94
138
|
[release-url]: https://github.com/cycjimmy/canvas-snow/releases
|
|
95
139
|
|
|
96
|
-
[
|
|
97
|
-
[
|
|
140
|
+
[vite-image]: https://img.shields.io/badge/bundled_with-vite-646cff
|
|
141
|
+
[vite-url]: https://vite.dev
|
|
142
|
+
|
|
143
|
+
[vitest-image]: https://img.shields.io/badge/tested_with-vitest-6e9f18
|
|
144
|
+
[vitest-url]: https://vitest.dev
|
|
98
145
|
|
|
99
146
|
[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
|
100
147
|
[semantic-url]: https://github.com/semantic-release/semantic-release
|
|
101
148
|
|
|
102
|
-
[jest-image]: https://img.shields.io/badge/tested_with-jest-99424f.svg
|
|
103
|
-
[jest-url]: https://github.com/facebook/jest
|
|
104
|
-
|
|
105
149
|
[license-image]: https://img.shields.io/npm/l/@cycjimmy/canvas-snow
|
|
106
150
|
|
|
107
151
|
[github-pages-url]: https://cycjimmy.github.io/canvas-snow/
|
package/dist/Snow.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface SnowMotion {
|
|
2
|
+
x: (x: number, y: number) => number;
|
|
3
|
+
y: (x: number, y: number) => number;
|
|
4
|
+
}
|
|
5
|
+
export default class Snow {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
r: number;
|
|
9
|
+
fn: SnowMotion;
|
|
10
|
+
canvasW: number;
|
|
11
|
+
canvasH: number;
|
|
12
|
+
constructor(x: number, y: number, radius: number, fn: SnowMotion, canvasW: number, canvasH: number);
|
|
13
|
+
update(): void;
|
|
14
|
+
draw(cxt: CanvasRenderingContext2D): void;
|
|
15
|
+
}
|