@aprovan/bobbin 0.1.0-dev.6bd527d

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.
Files changed (45) hide show
  1. package/.turbo/turbo-build.log +16 -0
  2. package/LICENSE +373 -0
  3. package/dist/index.d.ts +402 -0
  4. package/dist/index.js +3704 -0
  5. package/package.json +30 -0
  6. package/src/Bobbin.tsx +89 -0
  7. package/src/components/EditPanel/EditPanel.tsx +376 -0
  8. package/src/components/EditPanel/controls/ColorPicker.tsx +138 -0
  9. package/src/components/EditPanel/controls/QuickSelectDropdown.tsx +142 -0
  10. package/src/components/EditPanel/controls/SliderInput.tsx +94 -0
  11. package/src/components/EditPanel/controls/SpacingControl.tsx +285 -0
  12. package/src/components/EditPanel/controls/ToggleGroup.tsx +37 -0
  13. package/src/components/EditPanel/controls/TokenDropdown.tsx +33 -0
  14. package/src/components/EditPanel/sections/AnnotationSection.tsx +136 -0
  15. package/src/components/EditPanel/sections/BackgroundSection.tsx +79 -0
  16. package/src/components/EditPanel/sections/EffectsSection.tsx +85 -0
  17. package/src/components/EditPanel/sections/LayoutSection.tsx +224 -0
  18. package/src/components/EditPanel/sections/SectionWrapper.tsx +57 -0
  19. package/src/components/EditPanel/sections/SizeSection.tsx +166 -0
  20. package/src/components/EditPanel/sections/SpacingSection.tsx +69 -0
  21. package/src/components/EditPanel/sections/TypographySection.tsx +148 -0
  22. package/src/components/Inspector/Inspector.tsx +221 -0
  23. package/src/components/Overlay/ControlHandles.tsx +572 -0
  24. package/src/components/Overlay/MarginPaddingOverlay.tsx +229 -0
  25. package/src/components/Overlay/SelectionOverlay.tsx +73 -0
  26. package/src/components/Pill/Pill.tsx +155 -0
  27. package/src/components/ThemeToggle/ThemeToggle.tsx +72 -0
  28. package/src/core/changeSerializer.ts +139 -0
  29. package/src/core/useBobbin.ts +399 -0
  30. package/src/core/useChangeTracker.ts +186 -0
  31. package/src/core/useClipboard.ts +21 -0
  32. package/src/core/useElementSelection.ts +146 -0
  33. package/src/index.ts +46 -0
  34. package/src/tokens/borders.ts +19 -0
  35. package/src/tokens/colors.ts +150 -0
  36. package/src/tokens/index.ts +37 -0
  37. package/src/tokens/shadows.ts +10 -0
  38. package/src/tokens/spacing.ts +37 -0
  39. package/src/tokens/typography.ts +51 -0
  40. package/src/types.ts +157 -0
  41. package/src/utils/animation.ts +40 -0
  42. package/src/utils/dom.ts +36 -0
  43. package/src/utils/selectors.ts +76 -0
  44. package/tsconfig.json +10 -0
  45. package/tsup.config.ts +10 -0
@@ -0,0 +1,402 @@
1
+ import * as react from 'react';
2
+
3
+ interface SelectedElement {
4
+ element: HTMLElement;
5
+ rect: DOMRect;
6
+ path: string;
7
+ xpath: string;
8
+ tagName: string;
9
+ id?: string;
10
+ classList: string[];
11
+ }
12
+ type ChangeType = 'style' | 'text' | 'delete' | 'move' | 'duplicate' | 'insert' | 'attribute';
13
+ interface Change {
14
+ id: string;
15
+ type: ChangeType;
16
+ timestamp: number;
17
+ target: {
18
+ path: string;
19
+ xpath: string;
20
+ tagName: string;
21
+ };
22
+ before: unknown;
23
+ after: unknown;
24
+ metadata?: Record<string, unknown>;
25
+ }
26
+ interface StyleChange extends Change {
27
+ type: 'style';
28
+ before: {
29
+ property: string;
30
+ value: string;
31
+ };
32
+ after: {
33
+ property: string;
34
+ value: string;
35
+ };
36
+ }
37
+ interface TextChange extends Change {
38
+ type: 'text';
39
+ before: string;
40
+ after: string;
41
+ }
42
+ interface MoveChange extends Change {
43
+ type: 'move';
44
+ before: {
45
+ parent: string;
46
+ index: number;
47
+ };
48
+ after: {
49
+ parent: string;
50
+ index: number;
51
+ };
52
+ }
53
+ interface Annotation {
54
+ id: string;
55
+ elementPath: string;
56
+ elementXpath: string;
57
+ content: string;
58
+ createdAt: number;
59
+ }
60
+ interface DesignTokens {
61
+ colors: Record<string, Record<string, string>>;
62
+ spacing: Record<string, string>;
63
+ fontSize: Record<string, string>;
64
+ fontWeight: Record<string, string>;
65
+ fontFamily: Record<string, string>;
66
+ borderRadius: Record<string, string>;
67
+ borderWidth: Record<string, string>;
68
+ boxShadow: Record<string, string>;
69
+ lineHeight: Record<string, string>;
70
+ letterSpacing: Record<string, string>;
71
+ }
72
+ interface BobbinState {
73
+ isActive: boolean;
74
+ isPillExpanded: boolean;
75
+ hoveredElement: SelectedElement | null;
76
+ selectedElement: SelectedElement | null;
77
+ changes: Change[];
78
+ annotations: Annotation[];
79
+ clipboard: SelectedElement | null;
80
+ showMarginPadding: boolean;
81
+ activePanel: 'style' | 'inspector' | null;
82
+ theme: 'light' | 'dark' | 'system';
83
+ }
84
+ interface BobbinActions {
85
+ activate: () => void;
86
+ deactivate: () => void;
87
+ selectElement: (el: HTMLElement | null) => void;
88
+ clearSelection: () => void;
89
+ applyStyle: (property: string, value: string) => void;
90
+ deleteElement: () => void;
91
+ moveElement: (targetParent: HTMLElement, index: number) => void;
92
+ duplicateElement: () => void;
93
+ insertElement: (direction: 'before' | 'after' | 'child', content?: string) => void;
94
+ copyElement: () => void;
95
+ pasteElement: (direction: 'before' | 'after' | 'child') => void;
96
+ annotate: (content: string) => void;
97
+ toggleMarginPadding: () => void;
98
+ toggleTheme: () => void;
99
+ undo: () => void;
100
+ exportChanges: () => string;
101
+ getChanges: () => Change[];
102
+ resetChanges: () => void;
103
+ }
104
+ interface BobbinChangeset {
105
+ version: '1.0';
106
+ timestamp: string;
107
+ changeCount: number;
108
+ changes: Array<{
109
+ type: ChangeType;
110
+ target: string;
111
+ xpath: string;
112
+ property?: string;
113
+ before?: string;
114
+ after?: string;
115
+ note?: string;
116
+ }>;
117
+ annotations: Array<{
118
+ type: 'annotation';
119
+ target: string;
120
+ xpath: string;
121
+ note: string;
122
+ }>;
123
+ }
124
+ interface BobbinProps {
125
+ /** Custom design tokens to merge with defaults */
126
+ tokens?: Partial<DesignTokens>;
127
+ /** Container to scope element selection (default: document.body) */
128
+ container?: HTMLElement | null;
129
+ /** Container for pill positioning (if different from container) */
130
+ pillContainer?: HTMLElement | null;
131
+ /** Initial active state */
132
+ defaultActive?: boolean;
133
+ /** Callback when changes occur */
134
+ onChanges?: (changes: Change[]) => void;
135
+ /** Callback when selection changes */
136
+ onSelect?: (element: SelectedElement | null) => void;
137
+ /** Custom pill position offset from bottom-right of container */
138
+ position?: {
139
+ bottom: number;
140
+ right: number;
141
+ };
142
+ /** Z-index for overlay elements */
143
+ zIndex?: number;
144
+ /** Elements to exclude from selection (CSS selectors) */
145
+ exclude?: string[];
146
+ }
147
+
148
+ interface BobbinComponentProps extends BobbinProps {
149
+ /** Show inspector panel */
150
+ showInspector?: boolean;
151
+ }
152
+ declare function Bobbin(props: BobbinComponentProps): react.ReactPortal;
153
+
154
+ declare function useBobbin(props?: BobbinProps): {
155
+ tokens: DesignTokens;
156
+ setActivePanel: react.Dispatch<react.SetStateAction<"style" | "inspector" | null>>;
157
+ setIsPillExpanded: react.Dispatch<react.SetStateAction<boolean>>;
158
+ activate: () => void;
159
+ deactivate: () => void;
160
+ selectElement: (el: HTMLElement | null) => void;
161
+ clearSelection: () => void;
162
+ applyStyle: (property: string, value: string) => void;
163
+ deleteElement: () => void;
164
+ moveElement: (targetParent: HTMLElement, index: number) => void;
165
+ duplicateElement: () => void;
166
+ insertElement: (direction: "before" | "after" | "child", content?: string) => void;
167
+ copyElement: () => void;
168
+ pasteElement: (direction: "before" | "after" | "child") => void;
169
+ annotate: (content: string) => void;
170
+ toggleMarginPadding: () => void;
171
+ toggleTheme: () => void;
172
+ undo: () => void;
173
+ exportChanges: () => string;
174
+ getChanges: () => Change[];
175
+ resetChanges: () => void;
176
+ isActive: boolean;
177
+ isPillExpanded: boolean;
178
+ hoveredElement: SelectedElement | null;
179
+ selectedElement: SelectedElement | null;
180
+ changes: Change[];
181
+ annotations: Annotation[];
182
+ clipboard: SelectedElement | null;
183
+ showMarginPadding: boolean;
184
+ activePanel: "style" | "inspector" | null;
185
+ theme: "light" | "dark" | "system";
186
+ };
187
+
188
+ interface UseElementSelectionOptions {
189
+ container?: HTMLElement | null;
190
+ exclude?: string[];
191
+ enabled?: boolean;
192
+ }
193
+ declare function useElementSelection(options: UseElementSelectionOptions): {
194
+ hoveredElement: SelectedElement | null;
195
+ selectedElement: SelectedElement | null;
196
+ selectElement: (el: HTMLElement | null) => void;
197
+ clearSelection: () => void;
198
+ lastRect: DOMRect | null;
199
+ };
200
+
201
+ declare function useChangeTracker(): {
202
+ changes: Change[];
203
+ deduplicatedChanges: Change[];
204
+ changeCount: number;
205
+ recordStyleChange: (path: string, xpath: string, tagName: string, property: string, value: string, originalValue: string) => StyleChange;
206
+ recordTextChange: (path: string, xpath: string, tagName: string, originalText: string, newText: string) => TextChange;
207
+ recordMoveChange: (path: string, xpath: string, tagName: string, fromParent: string, fromIndex: number, toParent: string, toIndex: number) => MoveChange;
208
+ recordChange: (type: ChangeType, path: string, xpath: string, tagName: string, before: unknown, after: unknown, metadata?: Record<string, unknown>) => Change;
209
+ undo: () => Change | null | undefined;
210
+ clearChanges: () => void;
211
+ getChanges: () => Change[];
212
+ originalStates: Map<string, Map<string, string>>;
213
+ };
214
+
215
+ declare function useClipboard(): {
216
+ copied: SelectedElement | null;
217
+ copy: (element: SelectedElement) => void;
218
+ clear: () => void;
219
+ hasCopied: boolean;
220
+ };
221
+
222
+ declare function serializeChangesToYAML(changes: Change[], annotations?: Annotation[]): string;
223
+ declare function parseYAMLChangeset(yaml: string): BobbinChangeset;
224
+
225
+ declare function generateId(): string;
226
+ declare function getElementPath(el: HTMLElement): string;
227
+ declare function getElementXPath(el: HTMLElement): string;
228
+
229
+ declare const colors: {
230
+ slate: {
231
+ 50: string;
232
+ 100: string;
233
+ 200: string;
234
+ 300: string;
235
+ 400: string;
236
+ 500: string;
237
+ 600: string;
238
+ 700: string;
239
+ 800: string;
240
+ 900: string;
241
+ 950: string;
242
+ };
243
+ gray: {
244
+ 50: string;
245
+ 100: string;
246
+ 200: string;
247
+ 300: string;
248
+ 400: string;
249
+ 500: string;
250
+ 600: string;
251
+ 700: string;
252
+ 800: string;
253
+ 900: string;
254
+ 950: string;
255
+ };
256
+ zinc: {
257
+ 50: string;
258
+ 100: string;
259
+ 200: string;
260
+ 300: string;
261
+ 400: string;
262
+ 500: string;
263
+ 600: string;
264
+ 700: string;
265
+ 800: string;
266
+ 900: string;
267
+ 950: string;
268
+ };
269
+ red: {
270
+ 50: string;
271
+ 100: string;
272
+ 200: string;
273
+ 300: string;
274
+ 400: string;
275
+ 500: string;
276
+ 600: string;
277
+ 700: string;
278
+ 800: string;
279
+ 900: string;
280
+ 950: string;
281
+ };
282
+ orange: {
283
+ 50: string;
284
+ 100: string;
285
+ 200: string;
286
+ 300: string;
287
+ 400: string;
288
+ 500: string;
289
+ 600: string;
290
+ 700: string;
291
+ 800: string;
292
+ 900: string;
293
+ 950: string;
294
+ };
295
+ yellow: {
296
+ 50: string;
297
+ 100: string;
298
+ 200: string;
299
+ 300: string;
300
+ 400: string;
301
+ 500: string;
302
+ 600: string;
303
+ 700: string;
304
+ 800: string;
305
+ 900: string;
306
+ 950: string;
307
+ };
308
+ green: {
309
+ 50: string;
310
+ 100: string;
311
+ 200: string;
312
+ 300: string;
313
+ 400: string;
314
+ 500: string;
315
+ 600: string;
316
+ 700: string;
317
+ 800: string;
318
+ 900: string;
319
+ 950: string;
320
+ };
321
+ blue: {
322
+ 50: string;
323
+ 100: string;
324
+ 200: string;
325
+ 300: string;
326
+ 400: string;
327
+ 500: string;
328
+ 600: string;
329
+ 700: string;
330
+ 800: string;
331
+ 900: string;
332
+ 950: string;
333
+ };
334
+ indigo: {
335
+ 50: string;
336
+ 100: string;
337
+ 200: string;
338
+ 300: string;
339
+ 400: string;
340
+ 500: string;
341
+ 600: string;
342
+ 700: string;
343
+ 800: string;
344
+ 900: string;
345
+ 950: string;
346
+ };
347
+ purple: {
348
+ 50: string;
349
+ 100: string;
350
+ 200: string;
351
+ 300: string;
352
+ 400: string;
353
+ 500: string;
354
+ 600: string;
355
+ 700: string;
356
+ 800: string;
357
+ 900: string;
358
+ 950: string;
359
+ };
360
+ pink: {
361
+ 50: string;
362
+ 100: string;
363
+ 200: string;
364
+ 300: string;
365
+ 400: string;
366
+ 500: string;
367
+ 600: string;
368
+ 700: string;
369
+ 800: string;
370
+ 900: string;
371
+ 950: string;
372
+ };
373
+ white: {
374
+ DEFAULT: string;
375
+ };
376
+ black: {
377
+ DEFAULT: string;
378
+ };
379
+ transparent: {
380
+ DEFAULT: string;
381
+ };
382
+ current: {
383
+ DEFAULT: string;
384
+ };
385
+ };
386
+
387
+ declare const spacing: Record<string, string>;
388
+
389
+ declare const fontSize: Record<string, string>;
390
+ declare const fontWeight: Record<string, string>;
391
+ declare const fontFamily: Record<string, string>;
392
+ declare const lineHeight: Record<string, string>;
393
+ declare const letterSpacing: Record<string, string>;
394
+
395
+ declare const borderRadius: Record<string, string>;
396
+ declare const borderWidth: Record<string, string>;
397
+
398
+ declare const boxShadow: Record<string, string>;
399
+
400
+ declare const defaultTokens: DesignTokens;
401
+
402
+ export { type Annotation, Bobbin, type BobbinActions, type BobbinChangeset, type BobbinComponentProps, type BobbinProps, type BobbinState, type Change, type ChangeType, type DesignTokens, type MoveChange, type SelectedElement, type StyleChange, type TextChange, borderRadius, borderWidth, boxShadow, colors, defaultTokens, fontFamily, fontSize, fontWeight, generateId, getElementPath, getElementXPath, letterSpacing, lineHeight, parseYAMLChangeset, serializeChangesToYAML, spacing, useBobbin, useChangeTracker, useClipboard, useElementSelection };