@vanduo-oss/vd3-cbun 1.0.0 → 1.2.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.
@@ -0,0 +1,249 @@
1
+ // Type definitions for the framework-agnostic draw tool core.
2
+ // Hand-written to mirror the runtime in ./core.js + ./shapes.js. Self-contained
3
+ // (the shipped .d.ts trio is index/core/vue — no shapes.d.ts), so every draw
4
+ // type and constant is declared here.
5
+
6
+ export type DrawTool =
7
+ 'select' | 'hand' | 'draw' | 'eraser' | 'rectangle' | 'ellipse' | 'line' | 'text' | 'sticky';
8
+
9
+ export type DrawShapeType = 'rectangle' | 'ellipse' | 'line' | 'freehand' | 'text' | 'sticky';
10
+
11
+ export type BrushName = 'pen' | 'pencil' | 'marker' | 'highlighter' | 'calligraphy';
12
+
13
+ export interface BrushPreset {
14
+ size: number;
15
+ thinning: number;
16
+ smoothing: number;
17
+ streamline: number;
18
+ taperStart: number;
19
+ taperEnd: number;
20
+ opacity: number;
21
+ blend: string;
22
+ nibAngle?: number;
23
+ }
24
+
25
+ export interface DrawViewport {
26
+ x: number;
27
+ y: number;
28
+ scale: number;
29
+ }
30
+
31
+ /** A world-space point `[x, y]` with an optional third `pressure` (0–1) slot. */
32
+ export type DrawPoint = [number, number] | [number, number, number];
33
+
34
+ /**
35
+ * A shape in the document. Box shapes (rectangle/ellipse/text/sticky) use
36
+ * x/y/w/h; line/freehand use `points`. `color` is the stroke color for shapes /
37
+ * lines and the fill color for freehand brush strokes.
38
+ */
39
+ export interface DrawShape {
40
+ id: string;
41
+ type: DrawShapeType;
42
+ x?: number;
43
+ y?: number;
44
+ w?: number;
45
+ h?: number;
46
+ rotation?: number;
47
+ points?: DrawPoint[];
48
+ /** freehand: the brush preset. */
49
+ brush?: BrushName;
50
+ /** stroke color (shapes/line) or fill color (freehand). */
51
+ color?: string;
52
+ fill?: string;
53
+ /** freehand brush size. */
54
+ size?: number;
55
+ /** shapes/line stroke width. */
56
+ strokeWidth?: number;
57
+ opacity?: number;
58
+ text?: string;
59
+ arrowStart?: boolean;
60
+ arrowEnd?: boolean;
61
+ groupId?: string;
62
+ }
63
+
64
+ export interface DrawDocument {
65
+ version: string;
66
+ viewport: DrawViewport;
67
+ shapes: DrawShape[];
68
+ }
69
+
70
+ export interface DrawBounds {
71
+ x: number;
72
+ y: number;
73
+ w: number;
74
+ h: number;
75
+ }
76
+
77
+ export interface DrawChangeEvent {
78
+ reason: string;
79
+ document: DrawDocument;
80
+ shape?: DrawShape;
81
+ shapeId?: string;
82
+ shapeIds?: string[];
83
+ groupId?: string;
84
+ }
85
+
86
+ export interface DrawSelectEvent {
87
+ ids: string[];
88
+ shapes: DrawShape[];
89
+ }
90
+
91
+ export interface DrawViewportEvent {
92
+ reason: string;
93
+ viewport: DrawViewport;
94
+ document: DrawDocument;
95
+ }
96
+
97
+ export interface DrawHistoryEvent {
98
+ reason: string;
99
+ canUndo: boolean;
100
+ canRedo: boolean;
101
+ }
102
+
103
+ export interface DrawEventMap {
104
+ change: DrawChangeEvent;
105
+ select: DrawSelectEvent;
106
+ viewport: DrawViewportEvent;
107
+ history: DrawHistoryEvent;
108
+ ready: VdDraw;
109
+ }
110
+
111
+ export interface VdDrawOptions {
112
+ element?: Element | string;
113
+ /** Alias for `element`. */
114
+ target?: Element | string;
115
+ data?: Partial<DrawDocument> | string;
116
+ readonly?: boolean;
117
+ tool?: DrawTool;
118
+ gridSize?: number;
119
+ /** Show the background grid (default true). */
120
+ showGrid?: boolean;
121
+ /** Snap to nearby edges/centres while moving/resizing (default true). */
122
+ snap?: boolean;
123
+ /** Fit to content once the canvas reports a measurable size. */
124
+ autoFit?: boolean;
125
+ /** Enable built-in undo/redo (default true). */
126
+ history?: boolean;
127
+ /** Maximum retained history entries (default 100). */
128
+ historyLimit?: number;
129
+ /** Initial current-style color / opacity / brush size / brush preset. */
130
+ color?: string;
131
+ opacity?: number;
132
+ brushSize?: number;
133
+ brush?: BrushName;
134
+ }
135
+
136
+ export interface StylePatch {
137
+ color?: string;
138
+ fill?: string;
139
+ strokeWidth?: number;
140
+ opacity?: number;
141
+ size?: number;
142
+ brush?: BrushName;
143
+ }
144
+
145
+ export class VdDraw {
146
+ constructor(options?: VdDrawOptions);
147
+
148
+ readonly element: Element;
149
+ readonly readonly: boolean;
150
+ gridSize: number;
151
+ tool: DrawTool;
152
+ snap: boolean;
153
+ showGrid: boolean;
154
+ destroyed: boolean;
155
+ /** The current drawing style new marks adopt. */
156
+ style: { color: string; opacity: number; size: number; brush: BrushName };
157
+
158
+ // Events
159
+ on<K extends keyof DrawEventMap>(event: K, callback: (payload: DrawEventMap[K]) => void): this;
160
+ off<K extends keyof DrawEventMap>(event: K, callback: (payload: DrawEventMap[K]) => void): this;
161
+
162
+ // Tool + current style
163
+ setTool(tool: DrawTool): this;
164
+ setColor(color: string): this;
165
+ setOpacity(opacity: number): this;
166
+ setBrushSize(size: number): this;
167
+ setBrush(brush: BrushName): this;
168
+
169
+ // Grid
170
+ setGridSize(size: number): this;
171
+ setGridVisible(visible: boolean): this;
172
+ toggleGrid(): this;
173
+
174
+ // Shapes
175
+ getShape(id: string): DrawShape | null;
176
+ addShape(partial?: Partial<DrawShape>): DrawShape;
177
+ updateShape(
178
+ id: string,
179
+ patch?: Partial<DrawShape>,
180
+ options?: { reason?: string },
181
+ ): DrawShape | null;
182
+ removeShape(id: string): boolean;
183
+
184
+ // Selection
185
+ getSelectedShapes(): DrawShape[];
186
+ select(ids: string | string[] | null, options?: { additive?: boolean }): this;
187
+ selectAll(): this;
188
+ deselect(): this;
189
+ selectInBounds(box: DrawBounds, options?: { additive?: boolean }): this;
190
+
191
+ // Manipulation
192
+ nudge(dx: number, dy: number): this;
193
+ setSelectionBounds(target: DrawBounds): this;
194
+ deleteSelection(): boolean;
195
+ setStyle(patch: StylePatch): this;
196
+
197
+ // Z-order
198
+ bringForward(): this;
199
+ sendBackward(): this;
200
+ bringToFront(): this;
201
+ sendToBack(): this;
202
+
203
+ // Grouping
204
+ group(): this;
205
+ ungroup(): this;
206
+
207
+ // Clipboard
208
+ copy(): this;
209
+ cut(): this;
210
+ paste(options?: { offset?: number }): this;
211
+ duplicate(): this;
212
+
213
+ // Export
214
+ toSVG(): string;
215
+ toPNG(options?: { scale?: number }): Promise<string>;
216
+
217
+ // Viewport
218
+ setViewport(patch: Partial<DrawViewport>): this;
219
+ scaleAround(factor: number, localX: number, localY: number): this;
220
+ zoomIn(): this;
221
+ zoomOut(): this;
222
+ resetView(): this;
223
+ fitView(): this;
224
+
225
+ // History
226
+ undo(): this;
227
+ redo(): this;
228
+ canUndo(): boolean;
229
+ canRedo(): boolean;
230
+ clearHistory(): this;
231
+
232
+ // Document
233
+ clear(): this;
234
+ load(data: Partial<DrawDocument> | string): this;
235
+ toJSON(): DrawDocument;
236
+
237
+ // Text editing
238
+ startTextEdit(id: string): boolean;
239
+ stopTextEdit(options?: { commit?: boolean }): void;
240
+
241
+ // Rendering + lifecycle
242
+ render(flags?: { scene?: boolean; overlay?: boolean }): void;
243
+ destroy(): void;
244
+ }
245
+
246
+ export const VD_DRAW_VERSION: string;
247
+ export const DRAW_TOOLS: readonly DrawTool[];
248
+ export const DRAW_SHAPE_TYPES: readonly DrawShapeType[];
249
+ export const BRUSH_PRESETS: Readonly<Record<BrushName, BrushPreset>>;