xiaodao-painter 0.1.6 → 0.1.8
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# xiaodao-painter
|
|
2
2
|
|
|
3
|
-
A self-contained, embeddable SVG whiteboard component for Vue 3. Built with TypeScript
|
|
3
|
+
A self-contained, embeddable SVG whiteboard component for Vue 3. Built with TypeScript and Vite. Zero extra dependencies beyond Vue 3.
|
|
4
4
|
|
|
5
5
|
Supports drawing tools, selection, resize, pan/zoom, undo/redo, clipboard, layer ordering, color palettes, i18n, and light/dark themes — all with two-way data binding via `v-model`.
|
|
6
6
|
|
|
@@ -37,20 +37,7 @@ yarn add xiaodao-painter
|
|
|
37
37
|
|
|
38
38
|
## Usage
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
```ts
|
|
43
|
-
// main.ts
|
|
44
|
-
import { createApp } from 'vue'
|
|
45
|
-
import { createPinia } from 'pinia'
|
|
46
|
-
import App from './App.vue'
|
|
47
|
-
|
|
48
|
-
const app = createApp(App)
|
|
49
|
-
app.use(createPinia())
|
|
50
|
-
app.mount('#app')
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
Then import and use the `Painter` component:
|
|
40
|
+
Just import and use the `Painter` component. No additional plugins or global setup required — only Vue 3 is needed:
|
|
54
41
|
|
|
55
42
|
```vue
|
|
56
43
|
<script setup lang="ts">
|
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
import type { Stroke } from '../types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
declare function setPan(x: number, y: number): void;
|
|
3
|
+
declare function setCanvasSize(w: number, h: number): void;
|
|
4
|
+
declare function zoomAt(screenX: number, screenY: number, factor: number): void;
|
|
5
|
+
declare function continuousZoomAt(screenX: number, screenY: number, newZoom: number): void;
|
|
6
|
+
declare function getZoomPercent(): number;
|
|
7
|
+
declare function setStrokeWidth(w: number): void;
|
|
8
|
+
declare function setCanvasBackgroundColor(color: string): void;
|
|
9
|
+
declare function toggleColorPalette(): void;
|
|
10
|
+
declare function hideColorPalette(): void;
|
|
11
|
+
declare function isSelected(id: string): boolean;
|
|
12
|
+
declare function selectStroke(id: string | null): void;
|
|
13
|
+
declare function selectStrokes(ids: string[]): void;
|
|
14
|
+
declare function clearSelection(): void;
|
|
15
|
+
declare function addStroke(stroke: Stroke): void;
|
|
16
|
+
declare function updateStroke(id: string, changes: Partial<Stroke>): void;
|
|
17
|
+
declare function deleteSelectedStrokes(): void;
|
|
18
|
+
declare function cutSelectedStrokes(): void;
|
|
19
|
+
declare function copySelectedStrokes(): void;
|
|
20
|
+
declare function pasteStrokes(): void;
|
|
21
|
+
declare function pushUndo(): void;
|
|
22
|
+
declare function undo(): void;
|
|
23
|
+
declare function redo(): void;
|
|
24
|
+
declare function moveSelectedUp(): void;
|
|
25
|
+
declare function moveSelectedDown(): void;
|
|
26
|
+
declare function syncFromParent(data: Stroke[]): void;
|
|
27
|
+
declare function getStrokeDisplayBounds(stroke: Stroke): {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
};
|
|
33
|
+
declare function setColorSlot(slot: 'foreground' | 'background' | 'textColor'): void;
|
|
34
|
+
declare function setColor(color: string): void;
|
|
35
|
+
declare function buildStroke(type: Stroke['type'], x: number, y: number, width: number, height: number, points: Stroke['points']): Stroke;
|
|
36
|
+
declare function reset(): void;
|
|
37
|
+
declare const state: {
|
|
38
|
+
strokes: {
|
|
4
39
|
id: string;
|
|
5
40
|
type: import("../types").ToolType;
|
|
6
41
|
x: number;
|
|
@@ -19,7 +54,10 @@ export declare const useCanvasStore: import("pinia").SetupStoreDefinition<"canva
|
|
|
19
54
|
textAlign?: "left" | "center" | "right" | undefined;
|
|
20
55
|
textColor?: string | undefined;
|
|
21
56
|
textAutoWidth?: boolean | undefined;
|
|
22
|
-
}[]
|
|
57
|
+
}[];
|
|
58
|
+
selectedStrokeIds: Set<string> & Omit<Set<string>, keyof Set<any>>;
|
|
59
|
+
selectedStrokeId: string | null;
|
|
60
|
+
selectedStroke: {
|
|
23
61
|
id: string;
|
|
24
62
|
type: import("../types").ToolType;
|
|
25
63
|
x: number;
|
|
@@ -38,10 +76,8 @@ export declare const useCanvasStore: import("pinia").SetupStoreDefinition<"canva
|
|
|
38
76
|
textAlign?: "left" | "center" | "right" | undefined;
|
|
39
77
|
textColor?: string | undefined;
|
|
40
78
|
textAutoWidth?: boolean | undefined;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
selectedStrokeId: import("vue").ComputedRef<string | null>;
|
|
44
|
-
selectedStroke: import("vue").ComputedRef<{
|
|
79
|
+
} | null;
|
|
80
|
+
selectedStrokes: {
|
|
45
81
|
id: string;
|
|
46
82
|
type: import("../types").ToolType;
|
|
47
83
|
x: number;
|
|
@@ -60,121 +96,40 @@ export declare const useCanvasStore: import("pinia").SetupStoreDefinition<"canva
|
|
|
60
96
|
textAlign?: "left" | "center" | "right" | undefined;
|
|
61
97
|
textColor?: string | undefined;
|
|
62
98
|
textAutoWidth?: boolean | undefined;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
y: number;
|
|
74
|
-
}[];
|
|
75
|
-
strokeColor: string;
|
|
76
|
-
fillColor: string;
|
|
77
|
-
strokeWidth: number;
|
|
78
|
-
text?: string | undefined;
|
|
79
|
-
fontSize?: number | undefined;
|
|
80
|
-
textAlign?: "left" | "center" | "right" | undefined;
|
|
81
|
-
textColor?: string | undefined;
|
|
82
|
-
textAutoWidth?: boolean | undefined;
|
|
83
|
-
}[]>;
|
|
84
|
-
selectedStrokeColor: import("vue").ComputedRef<string | null>;
|
|
85
|
-
selectedFillColor: import("vue").ComputedRef<string | null>;
|
|
86
|
-
selectedTextColor: import("vue").ComputedRef<string | null>;
|
|
87
|
-
foregroundColor: import("vue").Ref<string, string>;
|
|
88
|
-
backgroundColor: import("vue").Ref<string, string>;
|
|
89
|
-
activeColorSlot: import("vue").Ref<"background" | "textColor" | "foreground", "background" | "textColor" | "foreground">;
|
|
90
|
-
showColorPalette: import("vue").Ref<boolean, boolean>;
|
|
91
|
-
isSelecting: import("vue").Ref<boolean, boolean>;
|
|
92
|
-
selectionBox: import("vue").Ref<{
|
|
93
|
-
x: number;
|
|
94
|
-
y: number;
|
|
95
|
-
width: number;
|
|
96
|
-
height: number;
|
|
97
|
-
} | null, {
|
|
98
|
-
x: number;
|
|
99
|
-
y: number;
|
|
100
|
-
width: number;
|
|
101
|
-
height: number;
|
|
102
|
-
} | {
|
|
103
|
-
x: number;
|
|
104
|
-
y: number;
|
|
105
|
-
width: number;
|
|
106
|
-
height: number;
|
|
107
|
-
} | null>;
|
|
108
|
-
toggleColorPalette: () => void;
|
|
109
|
-
hideColorPalette: () => void;
|
|
110
|
-
addStroke: (stroke: Stroke) => void;
|
|
111
|
-
updateStroke: (id: string, changes: Partial<Stroke>) => void;
|
|
112
|
-
selectStroke: (id: string | null) => void;
|
|
113
|
-
selectStrokes: (ids: string[]) => void;
|
|
114
|
-
clearSelection: () => void;
|
|
115
|
-
isSelected: (id: string) => boolean;
|
|
116
|
-
deleteSelectedStrokes: () => void;
|
|
117
|
-
setColorSlot: (slot: "foreground" | "background" | "textColor") => void;
|
|
118
|
-
setColor: (color: string) => void;
|
|
119
|
-
buildStroke: (type: Stroke["type"], x: number, y: number, width: number, height: number, points: Stroke["points"]) => Stroke;
|
|
120
|
-
strokeWidth: import("vue").Ref<number, number>;
|
|
121
|
-
setStrokeWidth: (w: number) => void;
|
|
122
|
-
canvasBackgroundColor: import("vue").Ref<string, string>;
|
|
123
|
-
setCanvasBackgroundColor: (color: string) => void;
|
|
124
|
-
canUndo: import("vue").ComputedRef<boolean>;
|
|
125
|
-
canRedo: import("vue").ComputedRef<boolean>;
|
|
126
|
-
undoStack: import("vue").Ref<{
|
|
127
|
-
id: string;
|
|
128
|
-
type: import("../types").ToolType;
|
|
129
|
-
x: number;
|
|
130
|
-
y: number;
|
|
131
|
-
width: number;
|
|
132
|
-
height: number;
|
|
133
|
-
points: {
|
|
134
|
-
x: number;
|
|
135
|
-
y: number;
|
|
136
|
-
}[];
|
|
137
|
-
strokeColor: string;
|
|
138
|
-
fillColor: string;
|
|
139
|
-
strokeWidth: number;
|
|
140
|
-
text?: string | undefined;
|
|
141
|
-
fontSize?: number | undefined;
|
|
142
|
-
textAlign?: "left" | "center" | "right" | undefined;
|
|
143
|
-
textColor?: string | undefined;
|
|
144
|
-
textAutoWidth?: boolean | undefined;
|
|
145
|
-
}[][], Stroke[][] | {
|
|
146
|
-
id: string;
|
|
147
|
-
type: import("../types").ToolType;
|
|
148
|
-
x: number;
|
|
149
|
-
y: number;
|
|
150
|
-
width: number;
|
|
151
|
-
height: number;
|
|
152
|
-
points: {
|
|
153
|
-
x: number;
|
|
154
|
-
y: number;
|
|
155
|
-
}[];
|
|
156
|
-
strokeColor: string;
|
|
157
|
-
fillColor: string;
|
|
158
|
-
strokeWidth: number;
|
|
159
|
-
text?: string | undefined;
|
|
160
|
-
fontSize?: number | undefined;
|
|
161
|
-
textAlign?: "left" | "center" | "right" | undefined;
|
|
162
|
-
textColor?: string | undefined;
|
|
163
|
-
textAutoWidth?: boolean | undefined;
|
|
164
|
-
}[][]>;
|
|
165
|
-
pushUndo: () => void;
|
|
166
|
-
undo: () => void;
|
|
167
|
-
redo: () => void;
|
|
168
|
-
moveSelectedUp: () => void;
|
|
169
|
-
moveSelectedDown: () => void;
|
|
170
|
-
syncFromParent: (data: Stroke[]) => void;
|
|
171
|
-
getStrokeDisplayBounds: (stroke: Stroke) => {
|
|
99
|
+
}[];
|
|
100
|
+
selectedStrokeColor: string | null;
|
|
101
|
+
selectedFillColor: string | null;
|
|
102
|
+
selectedTextColor: string | null;
|
|
103
|
+
foregroundColor: string;
|
|
104
|
+
backgroundColor: string;
|
|
105
|
+
activeColorSlot: "background" | "textColor" | "foreground";
|
|
106
|
+
showColorPalette: boolean;
|
|
107
|
+
isSelecting: boolean;
|
|
108
|
+
selectionBox: {
|
|
172
109
|
x: number;
|
|
173
110
|
y: number;
|
|
174
111
|
width: number;
|
|
175
112
|
height: number;
|
|
176
|
-
};
|
|
177
|
-
|
|
113
|
+
} | null;
|
|
114
|
+
toggleColorPalette: typeof toggleColorPalette;
|
|
115
|
+
hideColorPalette: typeof hideColorPalette;
|
|
116
|
+
addStroke: typeof addStroke;
|
|
117
|
+
updateStroke: typeof updateStroke;
|
|
118
|
+
selectStroke: typeof selectStroke;
|
|
119
|
+
selectStrokes: typeof selectStrokes;
|
|
120
|
+
clearSelection: typeof clearSelection;
|
|
121
|
+
isSelected: typeof isSelected;
|
|
122
|
+
deleteSelectedStrokes: typeof deleteSelectedStrokes;
|
|
123
|
+
setColorSlot: typeof setColorSlot;
|
|
124
|
+
setColor: typeof setColor;
|
|
125
|
+
buildStroke: typeof buildStroke;
|
|
126
|
+
strokeWidth: number;
|
|
127
|
+
setStrokeWidth: typeof setStrokeWidth;
|
|
128
|
+
canvasBackgroundColor: string;
|
|
129
|
+
setCanvasBackgroundColor: typeof setCanvasBackgroundColor;
|
|
130
|
+
canUndo: boolean;
|
|
131
|
+
canRedo: boolean;
|
|
132
|
+
undoStack: {
|
|
178
133
|
id: string;
|
|
179
134
|
type: import("../types").ToolType;
|
|
180
135
|
x: number;
|
|
@@ -193,7 +148,15 @@ export declare const useCanvasStore: import("pinia").SetupStoreDefinition<"canva
|
|
|
193
148
|
textAlign?: "left" | "center" | "right" | undefined;
|
|
194
149
|
textColor?: string | undefined;
|
|
195
150
|
textAutoWidth?: boolean | undefined;
|
|
196
|
-
}[]
|
|
151
|
+
}[][];
|
|
152
|
+
pushUndo: typeof pushUndo;
|
|
153
|
+
undo: typeof undo;
|
|
154
|
+
redo: typeof redo;
|
|
155
|
+
moveSelectedUp: typeof moveSelectedUp;
|
|
156
|
+
moveSelectedDown: typeof moveSelectedDown;
|
|
157
|
+
syncFromParent: typeof syncFromParent;
|
|
158
|
+
getStrokeDisplayBounds: typeof getStrokeDisplayBounds;
|
|
159
|
+
clipboard: {
|
|
197
160
|
id: string;
|
|
198
161
|
type: import("../types").ToolType;
|
|
199
162
|
x: number;
|
|
@@ -212,27 +175,30 @@ export declare const useCanvasStore: import("pinia").SetupStoreDefinition<"canva
|
|
|
212
175
|
textAlign?: "left" | "center" | "right" | undefined;
|
|
213
176
|
textColor?: string | undefined;
|
|
214
177
|
textAutoWidth?: boolean | undefined;
|
|
215
|
-
}[]
|
|
216
|
-
cutSelectedStrokes:
|
|
217
|
-
copySelectedStrokes:
|
|
218
|
-
pasteStrokes:
|
|
219
|
-
canvasWidth:
|
|
220
|
-
canvasHeight:
|
|
221
|
-
panX:
|
|
222
|
-
panY:
|
|
223
|
-
zoomLevel:
|
|
224
|
-
showZoomIndicator:
|
|
225
|
-
viewBox:
|
|
226
|
-
canvasTransform:
|
|
227
|
-
setPan:
|
|
228
|
-
setCanvasSize:
|
|
229
|
-
zoomAt:
|
|
230
|
-
continuousZoomAt:
|
|
231
|
-
getZoomPercent:
|
|
232
|
-
dataVersion:
|
|
233
|
-
theme:
|
|
234
|
-
textColor:
|
|
235
|
-
editingTextId:
|
|
236
|
-
hoveredTextId:
|
|
237
|
-
reset:
|
|
238
|
-
}
|
|
178
|
+
}[];
|
|
179
|
+
cutSelectedStrokes: typeof cutSelectedStrokes;
|
|
180
|
+
copySelectedStrokes: typeof copySelectedStrokes;
|
|
181
|
+
pasteStrokes: typeof pasteStrokes;
|
|
182
|
+
canvasWidth: number;
|
|
183
|
+
canvasHeight: number;
|
|
184
|
+
panX: number;
|
|
185
|
+
panY: number;
|
|
186
|
+
zoomLevel: number;
|
|
187
|
+
showZoomIndicator: boolean;
|
|
188
|
+
viewBox: string;
|
|
189
|
+
canvasTransform: string;
|
|
190
|
+
setPan: typeof setPan;
|
|
191
|
+
setCanvasSize: typeof setCanvasSize;
|
|
192
|
+
zoomAt: typeof zoomAt;
|
|
193
|
+
continuousZoomAt: typeof continuousZoomAt;
|
|
194
|
+
getZoomPercent: typeof getZoomPercent;
|
|
195
|
+
dataVersion: number;
|
|
196
|
+
theme: "dark" | "light";
|
|
197
|
+
textColor: string;
|
|
198
|
+
editingTextId: string | null;
|
|
199
|
+
hoveredTextId: string | null;
|
|
200
|
+
reset: typeof reset;
|
|
201
|
+
};
|
|
202
|
+
export type CanvasStore = typeof state;
|
|
203
|
+
export declare function useCanvasStore(): CanvasStore;
|
|
204
|
+
export {};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { ToolType } from '../types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
declare function setTool(tool: ToolType): void;
|
|
3
|
+
declare function reset(): void;
|
|
4
|
+
declare const state: {
|
|
5
|
+
activeTool: ToolType;
|
|
6
|
+
setTool: typeof setTool;
|
|
7
|
+
reset: typeof reset;
|
|
8
|
+
};
|
|
9
|
+
export type ToolsStore = typeof state;
|
|
10
|
+
export declare function useToolsStore(): ToolsStore;
|
|
11
|
+
export {};
|