canvas2d-wrapper 1.9.1 → 1.11.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/LICENSE +21 -21
- package/canvas2d-wrapper.d.ts +78 -44
- package/dist/index.js +245 -75
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +245 -76
- package/dist/index.modern.js.map +1 -1
- package/package.json +12 -12
package/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2021-
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021-2025 Dysnomia
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/canvas2d-wrapper.d.ts
CHANGED
@@ -1,30 +1,53 @@
|
|
1
1
|
declare module "canvas2d-wrapper" {
|
2
|
+
export type Position2D = {
|
3
|
+
x: number,
|
4
|
+
y: number
|
5
|
+
};
|
6
|
+
|
7
|
+
export type Surface2D = {
|
8
|
+
x: number,
|
9
|
+
y: number,
|
10
|
+
width: number,
|
11
|
+
height: number
|
12
|
+
};
|
13
|
+
|
14
|
+
export type Canvas2DEventCallbackParams = {
|
15
|
+
id: string | null,
|
16
|
+
element: CanvasObject | null,
|
17
|
+
originalEvent: Event,
|
18
|
+
posOnMap: Position2D
|
19
|
+
};
|
20
|
+
|
2
21
|
// React component
|
3
22
|
export type Canvas2DProps = {
|
4
|
-
width
|
5
|
-
height
|
6
|
-
trackMouseMove
|
7
|
-
minZoom
|
8
|
-
maxZoom
|
9
|
-
tileSize
|
10
|
-
onClick
|
11
|
-
onRightClick
|
12
|
-
onHover
|
13
|
-
onElementMoved
|
14
|
-
onWheel
|
15
|
-
onFrame
|
16
|
-
lockXAxis
|
17
|
-
lockYAxis
|
18
|
-
smoothingQuality
|
19
|
-
dragObjects
|
20
|
-
deltaLeft
|
21
|
-
deltaTop
|
23
|
+
width: number,
|
24
|
+
height: number,
|
25
|
+
trackMouseMove?: boolean,
|
26
|
+
minZoom?: number,
|
27
|
+
maxZoom?: number,
|
28
|
+
tileSize?: number,
|
29
|
+
onClick: ({ id, element, originalEvent }: Canvas2DEventCallbackParams) => void,
|
30
|
+
onRightClick?: ({ id, element, originalEvent }: Canvas2DEventCallbackParams) => void,
|
31
|
+
onHover?: ({ id, element, originalEvent }?: Canvas2DEventCallbackParams | null, position: Position2D | undefined) => void,
|
32
|
+
onElementMoved?: (element: CanvasObject, x: number, y: number) => void,
|
33
|
+
onWheel?: (e: Event) => void,
|
34
|
+
onFrame: () => CanvasObject[],
|
35
|
+
lockXAxis?: boolean,
|
36
|
+
lockYAxis?: boolean,
|
37
|
+
smoothingQuality?: string,
|
38
|
+
dragObjects?: boolean,
|
39
|
+
deltaLeft?: number,
|
40
|
+
deltaTop?: number,
|
22
41
|
// Additional props
|
23
42
|
id: string,
|
24
43
|
className?: string,
|
44
|
+
showMinimap?: boolean,
|
45
|
+
minimapWidth?: number,
|
46
|
+
minimapHeight?: number,
|
47
|
+
minimapFilter?: (e: CanvasObject) => boolean,
|
25
48
|
};
|
26
49
|
|
27
|
-
export function Canvas2D(props
|
50
|
+
export function Canvas2D(props: Canvas2DProps);
|
28
51
|
|
29
52
|
// Shapes
|
30
53
|
export class CanvasObject {
|
@@ -36,11 +59,11 @@ declare module "canvas2d-wrapper" {
|
|
36
59
|
draggable?: boolean
|
37
60
|
);
|
38
61
|
|
39
|
-
get constructorName()
|
62
|
+
get constructorName(): string;
|
40
63
|
|
41
|
-
get zIndex()
|
64
|
+
get zIndex(): number;
|
42
65
|
|
43
|
-
set zIndex(zIndex
|
66
|
+
set zIndex(zIndex: number);
|
44
67
|
|
45
68
|
id: string;
|
46
69
|
x: number;
|
@@ -66,7 +89,7 @@ declare module "canvas2d-wrapper" {
|
|
66
89
|
}
|
67
90
|
|
68
91
|
export class CanvasImage extends ColoredCanvasObject {
|
69
|
-
constructor({ id, x, y, width, height, src, zIndex, draggable }
|
92
|
+
constructor({ id, x, y, width, height, src, zIndex, draggable }: {
|
70
93
|
id: string,
|
71
94
|
x: number,
|
72
95
|
y: number,
|
@@ -77,7 +100,7 @@ declare module "canvas2d-wrapper" {
|
|
77
100
|
draggable?: boolean,
|
78
101
|
});
|
79
102
|
|
80
|
-
crop(sx
|
103
|
+
crop(sx: number, swidth: number, sheight: number);
|
81
104
|
|
82
105
|
src: string;
|
83
106
|
width: number;
|
@@ -85,7 +108,7 @@ declare module "canvas2d-wrapper" {
|
|
85
108
|
}
|
86
109
|
|
87
110
|
export class Circle extends ColoredCanvasObject {
|
88
|
-
constructor({ id, x, y, radius, fill, stroke, zIndex, draggable }
|
111
|
+
constructor({ id, x, y, radius, fill, stroke, zIndex, draggable }: {
|
89
112
|
id: string,
|
90
113
|
x: number,
|
91
114
|
y: number,
|
@@ -99,27 +122,38 @@ declare module "canvas2d-wrapper" {
|
|
99
122
|
radius: number;
|
100
123
|
}
|
101
124
|
|
125
|
+
export class LinePath extends ColoredCanvasObject {
|
126
|
+
constructor({ id, points, stroke, zIndex }: {
|
127
|
+
id: string,
|
128
|
+
lineWidth: number,
|
129
|
+
points: Position2D[],
|
130
|
+
stroke: string,
|
131
|
+
zIndex?: number,
|
132
|
+
smoothCorners?: boolean,
|
133
|
+
smoothCornersRadius?: number,
|
134
|
+
});
|
135
|
+
|
136
|
+
points: Position2D[];
|
137
|
+
lineWidth: number;
|
138
|
+
smoothCorners?: boolean;
|
139
|
+
smoothCornersRadius?: number;
|
140
|
+
}
|
141
|
+
|
102
142
|
export class Polygon extends ColoredCanvasObject {
|
103
|
-
constructor({ id,
|
143
|
+
constructor({ id, points, width, height, src, zIndex, draggable }: {
|
104
144
|
id: string,
|
105
|
-
points:
|
106
|
-
x: number,
|
107
|
-
y: number,
|
108
|
-
}[],
|
145
|
+
points: Position2D[],
|
109
146
|
fill?: string,
|
110
147
|
stroke?: string,
|
111
148
|
zIndex?: number,
|
112
149
|
draggable?: boolean,
|
113
150
|
});
|
114
151
|
|
115
|
-
points:
|
116
|
-
x: number,
|
117
|
-
y: number,
|
118
|
-
}[];
|
152
|
+
points: Position2D[];
|
119
153
|
}
|
120
154
|
|
121
155
|
export class Rect extends ColoredCanvasObject {
|
122
|
-
constructor({ id, x, y, width, height, src, zIndex, draggable }
|
156
|
+
constructor({ id, x, y, width, height, src, zIndex, draggable }: {
|
123
157
|
id: string,
|
124
158
|
x: number,
|
125
159
|
y: number,
|
@@ -136,17 +170,17 @@ declare module "canvas2d-wrapper" {
|
|
136
170
|
}
|
137
171
|
|
138
172
|
// Functions
|
139
|
-
export function preloadImages(images
|
173
|
+
export function preloadImages(images: string[]): void;
|
140
174
|
|
141
175
|
// Hooks
|
142
|
-
export function useGamepad()
|
143
|
-
export function useKeyboard()
|
144
|
-
export function useMousePosition()
|
145
|
-
x
|
146
|
-
y
|
176
|
+
export function useGamepad(): { [id: string]: string };
|
177
|
+
export function useKeyboard(): { [id: string]: string };
|
178
|
+
export function useMousePosition(): {
|
179
|
+
x: number | null,
|
180
|
+
y: number | null,
|
147
181
|
};
|
148
|
-
export function useWindowDimensions()
|
149
|
-
width
|
150
|
-
height
|
182
|
+
export function useWindowDimensions(): {
|
183
|
+
width: number,
|
184
|
+
height: number,
|
151
185
|
};
|
152
186
|
}
|