canvas2d-wrapper 1.4.0 → 1.5.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 +101 -98
- package/dist/index.js +209 -191
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +207 -193
- package/dist/index.modern.js.map +1 -1
- package/package.json +54 -53
package/README.md
CHANGED
@@ -1,98 +1,101 @@
|
|
1
|
-
# canvas2d-wrapper
|
2
|
-
|
3
|
-
> A React Wrapper to use HTML5 canvas with mouse move and zoom abilities.
|
4
|
-
|
5
|
-
[](https://www.npmjs.com/package/canvas2d-wrapper)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
import '
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
}
|
89
|
-
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
1
|
+
# canvas2d-wrapper
|
2
|
+
|
3
|
+
> A React Wrapper to use HTML5 canvas with mouse move and zoom abilities.
|
4
|
+
|
5
|
+
[](https://www.npmjs.com/package/canvas2d-wrapper)
|
6
|
+
[](https://sonar.dysnomia.studio/dashboard?id=canvas2d-wrapper) [](https://sonar.dysnomia.studio/dashboard?id=canvas2d-wrapper) [](https://sonar.dysnomia.studio/dashboard?id=canvas2d-wrapper)
|
7
|
+
[](https://sonar.dysnomia.studio/dashboard?id=canvas2d-wrapper) [](https://sonar.dysnomia.studio/dashboard?id=canvas2d-wrapper)
|
8
|
+
|
9
|
+
|
10
|
+
Do you want an example app made with this library ? Check out my game Alchemistry on [Steam](https://store.steampowered.com/app/1730540/Alchemistry/) or on [itch.io](https://elanis.itch.io/alchemistry).
|
11
|
+
|
12
|
+
## Install
|
13
|
+
|
14
|
+
```bash
|
15
|
+
npm install --save canvas2d-wrapper
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
```jsx
|
21
|
+
import React from 'react'
|
22
|
+
|
23
|
+
import { Canvas2D, CanvasImage, Circle, Polygon, Rect } from 'canvas2d-wrapper'
|
24
|
+
import 'canvas2d-wrapper/dist/index.css'
|
25
|
+
|
26
|
+
const App = () => {
|
27
|
+
const elements = [];
|
28
|
+
for(let i = 0; i < 998; i++) {
|
29
|
+
let object = null;
|
30
|
+
if(Math.random() > 0.5) {
|
31
|
+
object = new Rect({
|
32
|
+
id: i,
|
33
|
+
x: 50 - Math.round(Math.random() * 100),
|
34
|
+
y: 50 - Math.round(Math.random() * 100),
|
35
|
+
width: 1,
|
36
|
+
height: 1,
|
37
|
+
fill: (Math.random() > 0.5) ? 'black' : undefined,
|
38
|
+
stroke: (Math.random() > 0.5) ? 'black' : undefined
|
39
|
+
});
|
40
|
+
} else {
|
41
|
+
object = new Circle({
|
42
|
+
id: i,
|
43
|
+
x: 50 - Math.round(Math.random() * 100),
|
44
|
+
y: 50 - Math.round(Math.random() * 100),
|
45
|
+
radius: 0.5,
|
46
|
+
fill: (Math.random() > 0.5) ? 'black' : undefined,
|
47
|
+
stroke: (Math.random() > 0.5) ? 'black' : undefined
|
48
|
+
});
|
49
|
+
}
|
50
|
+
|
51
|
+
if(!object.fill && !object.stroke) {
|
52
|
+
object.fill = 'green';
|
53
|
+
}
|
54
|
+
|
55
|
+
elements.push(object);
|
56
|
+
}
|
57
|
+
|
58
|
+
const points = [];
|
59
|
+
for(let i = 0; i < 5; i++) {
|
60
|
+
points.push({
|
61
|
+
x: 50 - Math.round(Math.random() * 100),
|
62
|
+
y: 50 - Math.round(Math.random() * 100),
|
63
|
+
});
|
64
|
+
}
|
65
|
+
|
66
|
+
const polygon = new Polygon({
|
67
|
+
id: 'poly',
|
68
|
+
points,
|
69
|
+
stroke: 'red',
|
70
|
+
});
|
71
|
+
elements.push(polygon);
|
72
|
+
|
73
|
+
const polygon2 = new Polygon({
|
74
|
+
id: 'poly',
|
75
|
+
points,
|
76
|
+
fill: 'orange',
|
77
|
+
zIndex: -1,
|
78
|
+
});
|
79
|
+
elements.push(polygon2);
|
80
|
+
|
81
|
+
return (
|
82
|
+
<Canvas2D
|
83
|
+
elements={elements}
|
84
|
+
width={1200}
|
85
|
+
height={700}
|
86
|
+
minZoom={0.25}
|
87
|
+
maxZoom={4}
|
88
|
+
tileSize={32}
|
89
|
+
onClick={(e) => {
|
90
|
+
console.log('Click event:', e);
|
91
|
+
}}
|
92
|
+
/>
|
93
|
+
);
|
94
|
+
}
|
95
|
+
|
96
|
+
export default App;
|
97
|
+
```
|
98
|
+
|
99
|
+
## License
|
100
|
+
|
101
|
+
MIT © [Elanis](https://github.com/Elanis)
|