@aprovan/patchwork 0.1.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.
Files changed (225) hide show
  1. package/.eslintrc.json +22 -0
  2. package/.github/workflows/publish.yml +41 -0
  3. package/.prettierignore +17 -0
  4. package/LICENSE +373 -0
  5. package/README.md +15 -0
  6. package/apps/chat/.utcp_config.json +14 -0
  7. package/apps/chat/.working/widgets/27060b91-a2a5-4272-b243-6eb904bd4070/main.tsx +107 -0
  8. package/apps/chat/index.html +17 -0
  9. package/apps/chat/node_modules/.bin/autoprefixer +17 -0
  10. package/apps/chat/node_modules/.bin/browserslist +17 -0
  11. package/apps/chat/node_modules/.bin/conc +17 -0
  12. package/apps/chat/node_modules/.bin/concurrently +17 -0
  13. package/apps/chat/node_modules/.bin/copilot-proxy +17 -0
  14. package/apps/chat/node_modules/.bin/jiti +17 -0
  15. package/apps/chat/node_modules/.bin/tailwind +17 -0
  16. package/apps/chat/node_modules/.bin/tailwindcss +17 -0
  17. package/apps/chat/node_modules/.bin/tsc +17 -0
  18. package/apps/chat/node_modules/.bin/tsserver +17 -0
  19. package/apps/chat/node_modules/.bin/tsx +17 -0
  20. package/apps/chat/node_modules/.bin/vite +17 -0
  21. package/apps/chat/package.json +55 -0
  22. package/apps/chat/postcss.config.js +6 -0
  23. package/apps/chat/src/App.tsx +7 -0
  24. package/apps/chat/src/components/ui/avatar.tsx +48 -0
  25. package/apps/chat/src/components/ui/badge.tsx +36 -0
  26. package/apps/chat/src/components/ui/button.tsx +56 -0
  27. package/apps/chat/src/components/ui/card.tsx +86 -0
  28. package/apps/chat/src/components/ui/collapsible.tsx +9 -0
  29. package/apps/chat/src/components/ui/dialog.tsx +60 -0
  30. package/apps/chat/src/components/ui/input.tsx +25 -0
  31. package/apps/chat/src/components/ui/scroll-area.tsx +46 -0
  32. package/apps/chat/src/index.css +190 -0
  33. package/apps/chat/src/lib/utils.ts +6 -0
  34. package/apps/chat/src/main.tsx +10 -0
  35. package/apps/chat/src/pages/ChatPage.tsx +460 -0
  36. package/apps/chat/tailwind.config.js +71 -0
  37. package/apps/chat/tsconfig.json +25 -0
  38. package/apps/chat/vite.config.ts +26 -0
  39. package/package.json +35 -0
  40. package/packages/bobbin/node_modules/.bin/esbuild +14 -0
  41. package/packages/bobbin/node_modules/.bin/jiti +17 -0
  42. package/packages/bobbin/node_modules/.bin/tsc +17 -0
  43. package/packages/bobbin/node_modules/.bin/tsserver +17 -0
  44. package/packages/bobbin/node_modules/.bin/tsup +17 -0
  45. package/packages/bobbin/node_modules/.bin/tsup-node +17 -0
  46. package/packages/bobbin/node_modules/.bin/tsx +17 -0
  47. package/packages/bobbin/package.json +30 -0
  48. package/packages/bobbin/src/Bobbin.tsx +89 -0
  49. package/packages/bobbin/src/components/EditPanel/EditPanel.tsx +376 -0
  50. package/packages/bobbin/src/components/EditPanel/controls/ColorPicker.tsx +138 -0
  51. package/packages/bobbin/src/components/EditPanel/controls/QuickSelectDropdown.tsx +142 -0
  52. package/packages/bobbin/src/components/EditPanel/controls/SliderInput.tsx +94 -0
  53. package/packages/bobbin/src/components/EditPanel/controls/SpacingControl.tsx +285 -0
  54. package/packages/bobbin/src/components/EditPanel/controls/ToggleGroup.tsx +37 -0
  55. package/packages/bobbin/src/components/EditPanel/controls/TokenDropdown.tsx +33 -0
  56. package/packages/bobbin/src/components/EditPanel/sections/AnnotationSection.tsx +136 -0
  57. package/packages/bobbin/src/components/EditPanel/sections/BackgroundSection.tsx +79 -0
  58. package/packages/bobbin/src/components/EditPanel/sections/EffectsSection.tsx +85 -0
  59. package/packages/bobbin/src/components/EditPanel/sections/LayoutSection.tsx +224 -0
  60. package/packages/bobbin/src/components/EditPanel/sections/SectionWrapper.tsx +57 -0
  61. package/packages/bobbin/src/components/EditPanel/sections/SizeSection.tsx +166 -0
  62. package/packages/bobbin/src/components/EditPanel/sections/SpacingSection.tsx +69 -0
  63. package/packages/bobbin/src/components/EditPanel/sections/TypographySection.tsx +148 -0
  64. package/packages/bobbin/src/components/Inspector/Inspector.tsx +221 -0
  65. package/packages/bobbin/src/components/Overlay/ControlHandles.tsx +572 -0
  66. package/packages/bobbin/src/components/Overlay/MarginPaddingOverlay.tsx +229 -0
  67. package/packages/bobbin/src/components/Overlay/SelectionOverlay.tsx +73 -0
  68. package/packages/bobbin/src/components/Pill/Pill.tsx +155 -0
  69. package/packages/bobbin/src/components/ThemeToggle/ThemeToggle.tsx +72 -0
  70. package/packages/bobbin/src/core/changeSerializer.ts +139 -0
  71. package/packages/bobbin/src/core/useBobbin.ts +399 -0
  72. package/packages/bobbin/src/core/useChangeTracker.ts +186 -0
  73. package/packages/bobbin/src/core/useClipboard.ts +21 -0
  74. package/packages/bobbin/src/core/useElementSelection.ts +146 -0
  75. package/packages/bobbin/src/index.ts +46 -0
  76. package/packages/bobbin/src/tokens/borders.ts +19 -0
  77. package/packages/bobbin/src/tokens/colors.ts +150 -0
  78. package/packages/bobbin/src/tokens/index.ts +37 -0
  79. package/packages/bobbin/src/tokens/shadows.ts +10 -0
  80. package/packages/bobbin/src/tokens/spacing.ts +37 -0
  81. package/packages/bobbin/src/tokens/typography.ts +51 -0
  82. package/packages/bobbin/src/types.ts +157 -0
  83. package/packages/bobbin/src/utils/animation.ts +40 -0
  84. package/packages/bobbin/src/utils/dom.ts +36 -0
  85. package/packages/bobbin/src/utils/selectors.ts +76 -0
  86. package/packages/bobbin/tsconfig.json +10 -0
  87. package/packages/bobbin/tsup.config.ts +10 -0
  88. package/packages/compiler/node_modules/.bin/esbuild +17 -0
  89. package/packages/compiler/node_modules/.bin/jiti +17 -0
  90. package/packages/compiler/node_modules/.bin/tsc +17 -0
  91. package/packages/compiler/node_modules/.bin/tsserver +17 -0
  92. package/packages/compiler/node_modules/.bin/tsup +17 -0
  93. package/packages/compiler/node_modules/.bin/tsup-node +17 -0
  94. package/packages/compiler/node_modules/.bin/tsx +17 -0
  95. package/packages/compiler/package.json +38 -0
  96. package/packages/compiler/src/compiler.ts +258 -0
  97. package/packages/compiler/src/images/index.ts +13 -0
  98. package/packages/compiler/src/images/loader.ts +234 -0
  99. package/packages/compiler/src/images/registry.ts +112 -0
  100. package/packages/compiler/src/index.ts +141 -0
  101. package/packages/compiler/src/mount/bridge.ts +399 -0
  102. package/packages/compiler/src/mount/embedded.ts +306 -0
  103. package/packages/compiler/src/mount/iframe.ts +433 -0
  104. package/packages/compiler/src/mount/index.ts +18 -0
  105. package/packages/compiler/src/schemas.ts +169 -0
  106. package/packages/compiler/src/transforms/cdn.ts +411 -0
  107. package/packages/compiler/src/transforms/index.ts +4 -0
  108. package/packages/compiler/src/transforms/vfs.ts +138 -0
  109. package/packages/compiler/src/types.ts +233 -0
  110. package/packages/compiler/src/vfs/backends/indexeddb.ts +66 -0
  111. package/packages/compiler/src/vfs/backends/local-fs.ts +41 -0
  112. package/packages/compiler/src/vfs/backends/s3.ts +60 -0
  113. package/packages/compiler/src/vfs/index.ts +11 -0
  114. package/packages/compiler/src/vfs/project.ts +56 -0
  115. package/packages/compiler/src/vfs/store.ts +53 -0
  116. package/packages/compiler/src/vfs/types.ts +20 -0
  117. package/packages/compiler/tsconfig.json +8 -0
  118. package/packages/compiler/tsup.config.ts +14 -0
  119. package/packages/editor/node_modules/.bin/jiti +17 -0
  120. package/packages/editor/node_modules/.bin/tsc +17 -0
  121. package/packages/editor/node_modules/.bin/tsserver +17 -0
  122. package/packages/editor/node_modules/.bin/tsup +17 -0
  123. package/packages/editor/node_modules/.bin/tsup-node +17 -0
  124. package/packages/editor/node_modules/.bin/tsx +17 -0
  125. package/packages/editor/package.json +45 -0
  126. package/packages/editor/src/components/CodeBlockExtension.tsx +190 -0
  127. package/packages/editor/src/components/CodePreview.tsx +344 -0
  128. package/packages/editor/src/components/MarkdownEditor.tsx +270 -0
  129. package/packages/editor/src/components/ServicesInspector.tsx +118 -0
  130. package/packages/editor/src/components/edit/EditHistory.tsx +89 -0
  131. package/packages/editor/src/components/edit/EditModal.tsx +236 -0
  132. package/packages/editor/src/components/edit/FileTree.tsx +144 -0
  133. package/packages/editor/src/components/edit/api.ts +100 -0
  134. package/packages/editor/src/components/edit/index.ts +6 -0
  135. package/packages/editor/src/components/edit/types.ts +53 -0
  136. package/packages/editor/src/components/edit/useEditSession.ts +164 -0
  137. package/packages/editor/src/components/index.ts +5 -0
  138. package/packages/editor/src/index.ts +72 -0
  139. package/packages/editor/src/lib/code-extractor.ts +210 -0
  140. package/packages/editor/src/lib/diff.ts +308 -0
  141. package/packages/editor/src/lib/index.ts +4 -0
  142. package/packages/editor/src/lib/utils.ts +6 -0
  143. package/packages/editor/src/lib/vfs.ts +106 -0
  144. package/packages/editor/tsconfig.json +10 -0
  145. package/packages/editor/tsup.config.ts +10 -0
  146. package/packages/images/ink/node_modules/.bin/jiti +17 -0
  147. package/packages/images/ink/node_modules/.bin/tsc +17 -0
  148. package/packages/images/ink/node_modules/.bin/tsserver +17 -0
  149. package/packages/images/ink/node_modules/.bin/tsup +17 -0
  150. package/packages/images/ink/node_modules/.bin/tsup-node +17 -0
  151. package/packages/images/ink/node_modules/.bin/tsx +17 -0
  152. package/packages/images/ink/package.json +53 -0
  153. package/packages/images/ink/src/index.ts +48 -0
  154. package/packages/images/ink/src/runner.ts +331 -0
  155. package/packages/images/ink/src/setup.ts +123 -0
  156. package/packages/images/ink/tsconfig.json +10 -0
  157. package/packages/images/ink/tsup.config.ts +11 -0
  158. package/packages/images/shadcn/node_modules/.bin/jiti +17 -0
  159. package/packages/images/shadcn/node_modules/.bin/tsc +17 -0
  160. package/packages/images/shadcn/node_modules/.bin/tsserver +17 -0
  161. package/packages/images/shadcn/node_modules/.bin/tsup +17 -0
  162. package/packages/images/shadcn/node_modules/.bin/tsup-node +17 -0
  163. package/packages/images/shadcn/node_modules/.bin/tsx +17 -0
  164. package/packages/images/shadcn/package.json +82 -0
  165. package/packages/images/shadcn/src/html.ts +341 -0
  166. package/packages/images/shadcn/src/index.ts +37 -0
  167. package/packages/images/shadcn/src/setup.ts +287 -0
  168. package/packages/images/shadcn/tsconfig.json +9 -0
  169. package/packages/images/shadcn/tsup.config.ts +13 -0
  170. package/packages/images/vanilla/node_modules/.bin/jiti +17 -0
  171. package/packages/images/vanilla/node_modules/.bin/tsc +17 -0
  172. package/packages/images/vanilla/node_modules/.bin/tsserver +17 -0
  173. package/packages/images/vanilla/node_modules/.bin/tsup +17 -0
  174. package/packages/images/vanilla/node_modules/.bin/tsup-node +17 -0
  175. package/packages/images/vanilla/node_modules/.bin/tsx +17 -0
  176. package/packages/images/vanilla/package.json +35 -0
  177. package/packages/images/vanilla/src/index.ts +7 -0
  178. package/packages/images/vanilla/src/setup.ts +6 -0
  179. package/packages/images/vanilla/tsconfig.json +9 -0
  180. package/packages/images/vanilla/tsup.config.ts +10 -0
  181. package/packages/patchwork/node_modules/.bin/jiti +17 -0
  182. package/packages/patchwork/node_modules/.bin/tsc +17 -0
  183. package/packages/patchwork/node_modules/.bin/tsserver +17 -0
  184. package/packages/patchwork/node_modules/.bin/tsup +17 -0
  185. package/packages/patchwork/node_modules/.bin/tsup-node +17 -0
  186. package/packages/patchwork/node_modules/.bin/tsx +17 -0
  187. package/packages/patchwork/package.json +27 -0
  188. package/packages/patchwork/src/index.ts +15 -0
  189. package/packages/patchwork/src/services/index.ts +11 -0
  190. package/packages/patchwork/src/services/proxy.ts +213 -0
  191. package/packages/patchwork/src/services/types.ts +28 -0
  192. package/packages/patchwork/src/types.ts +116 -0
  193. package/packages/patchwork/tsconfig.json +8 -0
  194. package/packages/patchwork/tsup.config.ts +14 -0
  195. package/packages/stitchery/node_modules/.bin/jiti +17 -0
  196. package/packages/stitchery/node_modules/.bin/tsc +17 -0
  197. package/packages/stitchery/node_modules/.bin/tsserver +17 -0
  198. package/packages/stitchery/node_modules/.bin/tsup +17 -0
  199. package/packages/stitchery/node_modules/.bin/tsup-node +17 -0
  200. package/packages/stitchery/node_modules/.bin/tsx +17 -0
  201. package/packages/stitchery/package.json +40 -0
  202. package/packages/stitchery/src/cli.ts +116 -0
  203. package/packages/stitchery/src/index.ts +16 -0
  204. package/packages/stitchery/src/prompts.ts +326 -0
  205. package/packages/stitchery/src/server/index.ts +365 -0
  206. package/packages/stitchery/src/server/local-packages.ts +91 -0
  207. package/packages/stitchery/src/server/routes.ts +122 -0
  208. package/packages/stitchery/src/server/services.ts +382 -0
  209. package/packages/stitchery/src/server/vfs-routes.ts +142 -0
  210. package/packages/stitchery/src/types.ts +59 -0
  211. package/packages/stitchery/tsconfig.json +13 -0
  212. package/packages/stitchery/tsup.config.ts +15 -0
  213. package/packages/utcp/node_modules/.bin/jiti +17 -0
  214. package/packages/utcp/node_modules/.bin/tsc +17 -0
  215. package/packages/utcp/node_modules/.bin/tsserver +17 -0
  216. package/packages/utcp/node_modules/.bin/tsup +17 -0
  217. package/packages/utcp/node_modules/.bin/tsup-node +17 -0
  218. package/packages/utcp/node_modules/.bin/tsx +17 -0
  219. package/packages/utcp/package.json +38 -0
  220. package/packages/utcp/src/index.ts +153 -0
  221. package/packages/utcp/tsconfig.json +8 -0
  222. package/packages/utcp/tsup.config.ts +12 -0
  223. package/pnpm-workspace.yaml +3 -0
  224. package/tsconfig.json +18 -0
  225. package/turbo.json +23 -0
@@ -0,0 +1,94 @@
1
+ import { useState, useCallback } from 'react';
2
+
3
+ interface SliderInputProps {
4
+ value: number;
5
+ min?: number;
6
+ max?: number;
7
+ step?: number;
8
+ unit?: string;
9
+ onChange: (value: number) => void;
10
+ label?: string;
11
+ }
12
+
13
+ export function SliderInput({
14
+ value,
15
+ min = 0,
16
+ max = 100,
17
+ step = 1,
18
+ unit = 'px',
19
+ onChange,
20
+ label,
21
+ }: SliderInputProps) {
22
+ const [isDragging, setIsDragging] = useState(false);
23
+ const [localValue, setLocalValue] = useState(value);
24
+
25
+ const handleMouseDown = useCallback((e: React.MouseEvent) => {
26
+ e.preventDefault();
27
+ setIsDragging(true);
28
+ const startX = e.clientX;
29
+ const startValue = localValue;
30
+
31
+ const handleMouseMove = (e: MouseEvent) => {
32
+ const delta = e.clientX - startX;
33
+ const sensitivity = e.shiftKey ? 0.1 : 1; // Shift for fine control
34
+ const newValue = Math.min(max, Math.max(min, startValue + delta * sensitivity));
35
+ const steppedValue = Math.round(newValue / step) * step;
36
+ setLocalValue(steppedValue);
37
+ onChange(steppedValue);
38
+ };
39
+
40
+ const handleMouseUp = () => {
41
+ setIsDragging(false);
42
+ document.removeEventListener('mousemove', handleMouseMove);
43
+ document.removeEventListener('mouseup', handleMouseUp);
44
+ };
45
+
46
+ document.addEventListener('mousemove', handleMouseMove);
47
+ document.addEventListener('mouseup', handleMouseUp);
48
+ }, [localValue, min, max, step, onChange]);
49
+
50
+ const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
51
+ const newValue = parseFloat(e.target.value) || 0;
52
+ setLocalValue(newValue);
53
+ onChange(newValue);
54
+ };
55
+
56
+ return (
57
+ <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
58
+ {label && (
59
+ <span style={{ fontSize: '10px', color: '#71717a', width: '18px' }}>{label}</span>
60
+ )}
61
+ <div
62
+ style={{
63
+ flex: 1,
64
+ display: 'flex',
65
+ alignItems: 'center',
66
+ backgroundColor: '#ffffff',
67
+ border: '1px solid #e4e4e7',
68
+ borderRadius: '4px',
69
+ padding: '3px 6px',
70
+ cursor: 'ew-resize',
71
+ }}
72
+ onMouseDown={handleMouseDown}
73
+ >
74
+ <input
75
+ type="number"
76
+ value={localValue}
77
+ onChange={handleInputChange}
78
+ style={{
79
+ width: '100%',
80
+ backgroundColor: 'transparent',
81
+ border: 'none',
82
+ color: '#18181b',
83
+ fontSize: '11px',
84
+ fontFamily: 'ui-monospace, monospace',
85
+ outline: 'none',
86
+ cursor: isDragging ? 'ew-resize' : 'text',
87
+ }}
88
+ onClick={(e) => e.stopPropagation()}
89
+ />
90
+ <span style={{ fontSize: '10px', color: '#a1a1aa', marginLeft: '4px' }}>{unit}</span>
91
+ </div>
92
+ </div>
93
+ );
94
+ }
@@ -0,0 +1,285 @@
1
+ import { useState, useCallback, useRef, useEffect } from 'react';
2
+
3
+ type Side = 'top' | 'right' | 'bottom' | 'left';
4
+
5
+ interface SpacingControlProps {
6
+ values: { top: string; right: string; bottom: string; left: string };
7
+ onChange: (side: Side, value: string) => void;
8
+ label: string;
9
+ hasChanges?: { top?: boolean; right?: boolean; bottom?: boolean; left?: boolean };
10
+ }
11
+
12
+ // Chain link icon (for linked sides)
13
+ const ChainIcon = ({ linked }: { linked: boolean }) => (
14
+ <svg
15
+ width="12"
16
+ height="12"
17
+ viewBox="0 0 24 24"
18
+ fill="none"
19
+ stroke="currentColor"
20
+ strokeWidth="2"
21
+ strokeLinecap="round"
22
+ strokeLinejoin="round"
23
+ style={{ opacity: linked ? 1 : 0.4 }}
24
+ >
25
+ {linked ? (
26
+ // Linked chain
27
+ <>
28
+ <path d="M9 17H7A5 5 0 0 1 7 7h2" />
29
+ <path d="M15 7h2a5 5 0 1 1 0 10h-2" />
30
+ <line x1="8" y1="12" x2="16" y2="12" />
31
+ </>
32
+ ) : (
33
+ // Broken chain
34
+ <>
35
+ <path d="M9 17H7A5 5 0 0 1 7 7h2" />
36
+ <path d="M15 7h2a5 5 0 1 1 0 10h-2" />
37
+ <line x1="8" y1="12" x2="10" y2="12" />
38
+ <line x1="14" y1="12" x2="16" y2="12" />
39
+ </>
40
+ )}
41
+ </svg>
42
+ );
43
+
44
+ // Check if a CSS value is valid
45
+ function isValidCSSValue(value: string): boolean {
46
+ if (!value || value.trim() === '') return true; // Empty is valid (will revert to default)
47
+
48
+ // Common valid patterns
49
+ const validPatterns = [
50
+ /^-?\d+(\.\d+)?(px|em|rem|%|vh|vw|pt|cm|mm|in|pc)?$/i,
51
+ /^auto$/i,
52
+ /^inherit$/i,
53
+ /^initial$/i,
54
+ /^unset$/i,
55
+ /^0$/,
56
+ ];
57
+
58
+ return validPatterns.some(pattern => pattern.test(value.trim()));
59
+ }
60
+
61
+ export function SpacingControl({ values, onChange, label, hasChanges = {} }: SpacingControlProps) {
62
+ const [editingSide, setEditingSide] = useState<Side | null>(null);
63
+ const [editValue, setEditValue] = useState('');
64
+ const [linkVertical, setLinkVertical] = useState(false);
65
+ const [linkHorizontal, setLinkHorizontal] = useState(false);
66
+ const [highlightLinked, setHighlightLinked] = useState<'vertical' | 'horizontal' | null>(null);
67
+ const inputRef = useRef<HTMLInputElement>(null);
68
+
69
+ // Focus input when editing starts
70
+ useEffect(() => {
71
+ if (editingSide && inputRef.current) {
72
+ inputRef.current.focus();
73
+ inputRef.current.select();
74
+ }
75
+ }, [editingSide]);
76
+
77
+ const handleChange = useCallback((side: Side, value: string) => {
78
+ onChange(side, value);
79
+
80
+ // Apply linked changes
81
+ if (linkVertical && (side === 'top' || side === 'bottom')) {
82
+ onChange(side === 'top' ? 'bottom' : 'top', value);
83
+ }
84
+ if (linkHorizontal && (side === 'left' || side === 'right')) {
85
+ onChange(side === 'left' ? 'right' : 'left', value);
86
+ }
87
+ }, [onChange, linkVertical, linkHorizontal]);
88
+
89
+ const handleBoxClick = (side: Side, e: React.MouseEvent) => {
90
+ e.stopPropagation();
91
+ setEditingSide(side);
92
+ setEditValue(values[side]);
93
+
94
+ // Highlight linked sides
95
+ if (linkVertical && (side === 'top' || side === 'bottom')) {
96
+ setHighlightLinked('vertical');
97
+ } else if (linkHorizontal && (side === 'left' || side === 'right')) {
98
+ setHighlightLinked('horizontal');
99
+ }
100
+ };
101
+
102
+ const handleInputChange = (value: string) => {
103
+ setEditValue(value);
104
+ // Apply changes even if temporarily invalid (user is typing)
105
+ if (editingSide) {
106
+ handleChange(editingSide, value);
107
+ }
108
+ };
109
+
110
+ const handleInputBlur = () => {
111
+ setEditingSide(null);
112
+ setHighlightLinked(null);
113
+ };
114
+
115
+ const handleKeyDown = (e: React.KeyboardEvent) => {
116
+ if (e.key === 'Enter' || e.key === 'Escape') {
117
+ setEditingSide(null);
118
+ setHighlightLinked(null);
119
+ }
120
+ };
121
+
122
+ const formatValue = (value: string) => {
123
+ // Extract just the numeric value for compact display
124
+ const match = value.match(/^([\d.]+)/);
125
+ return match ? match[1] : value || '0';
126
+ };
127
+
128
+ const isLinkedHighlighted = (side: Side): boolean => {
129
+ if (!highlightLinked) return false;
130
+ if (highlightLinked === 'vertical' && (side === 'top' || side === 'bottom')) return true;
131
+ if (highlightLinked === 'horizontal' && (side === 'left' || side === 'right')) return true;
132
+ return false;
133
+ };
134
+
135
+ const getBoxStyle = (side: Side): React.CSSProperties => {
136
+ const isEditing = editingSide === side;
137
+ const isLinked = isLinkedHighlighted(side);
138
+ const isValid = isEditing ? isValidCSSValue(editValue) : true;
139
+ const hasChange = hasChanges[side];
140
+
141
+ return {
142
+ padding: isEditing ? '0' : '2px 4px',
143
+ borderRadius: '3px',
144
+ border: `1px solid ${
145
+ !isValid ? '#ef4444' :
146
+ hasChange ? '#3b82f6' :
147
+ isLinked ? '#8b5cf6' :
148
+ isEditing ? '#18181b' :
149
+ '#e4e4e7'
150
+ }`,
151
+ backgroundColor:
152
+ !isValid ? '#fef2f2' :
153
+ hasChange ? '#eff6ff' :
154
+ isLinked ? '#f5f3ff' :
155
+ '#ffffff',
156
+ color: '#18181b',
157
+ fontSize: '9px',
158
+ textAlign: 'center',
159
+ cursor: 'text',
160
+ minWidth: '28px',
161
+ transition: 'all 0.1s ease',
162
+ outline: 'none',
163
+ };
164
+ };
165
+
166
+ const linkButtonStyle = (active: boolean): React.CSSProperties => ({
167
+ padding: '2px 4px',
168
+ borderRadius: '3px',
169
+ border: `1px solid ${active ? '#8b5cf6' : '#e4e4e7'}`,
170
+ backgroundColor: active ? '#f5f3ff' : '#ffffff',
171
+ color: active ? '#8b5cf6' : '#71717a',
172
+ cursor: 'pointer',
173
+ display: 'flex',
174
+ alignItems: 'center',
175
+ justifyContent: 'center',
176
+ transition: 'all 0.1s ease',
177
+ });
178
+
179
+ const renderValueBox = (side: Side, position: React.CSSProperties) => {
180
+ const isEditing = editingSide === side;
181
+
182
+ return (
183
+ <div style={{ position: 'absolute', ...position }}>
184
+ {isEditing ? (
185
+ <input
186
+ ref={inputRef}
187
+ type="text"
188
+ value={editValue}
189
+ onChange={(e) => handleInputChange(e.target.value)}
190
+ onBlur={handleInputBlur}
191
+ onKeyDown={handleKeyDown}
192
+ style={{
193
+ ...getBoxStyle(side),
194
+ width: '36px',
195
+ fontFamily: 'inherit',
196
+ }}
197
+ />
198
+ ) : (
199
+ <div
200
+ onClick={(e) => handleBoxClick(side, e)}
201
+ style={getBoxStyle(side)}
202
+ title={`${side}: ${values[side]}`}
203
+ >
204
+ {formatValue(values[side])}
205
+ </div>
206
+ )}
207
+ </div>
208
+ );
209
+ };
210
+
211
+ return (
212
+ <div>
213
+ <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: '6px' }}>
214
+ <label style={{ fontSize: '10px', color: '#71717a' }}>
215
+ {label}
216
+ </label>
217
+ <div style={{ display: 'flex', gap: '2px' }}>
218
+ <button
219
+ style={linkButtonStyle(linkVertical)}
220
+ onClick={() => setLinkVertical(!linkVertical)}
221
+ title={linkVertical ? 'Unlink top/bottom' : 'Link top/bottom'}
222
+ >
223
+ <span style={{ transform: 'rotate(90deg)', display: 'flex' }}>
224
+ <ChainIcon linked={linkVertical} />
225
+ </span>
226
+ </button>
227
+ <button
228
+ style={linkButtonStyle(linkHorizontal)}
229
+ onClick={() => setLinkHorizontal(!linkHorizontal)}
230
+ title={linkHorizontal ? 'Unlink left/right' : 'Link left/right'}
231
+ >
232
+ <ChainIcon linked={linkHorizontal} />
233
+ </button>
234
+ </div>
235
+ </div>
236
+
237
+ {/* Visual spacing box with outline square in center */}
238
+ <div
239
+ style={{
240
+ position: 'relative',
241
+ width: '100px',
242
+ height: '40px',
243
+ margin: '0 auto',
244
+ }}
245
+ >
246
+ {/* Outline square connecting all sides */}
247
+ <svg
248
+ style={{
249
+ position: 'absolute',
250
+ top: 0,
251
+ left: 0,
252
+ width: '100%',
253
+ height: '100%',
254
+ pointerEvents: 'none',
255
+ }}
256
+ viewBox="0 0 100 70"
257
+ >
258
+ {/* Outer rectangle outline */}
259
+ <rect
260
+ x="10"
261
+ y="10"
262
+ width="80"
263
+ height="50"
264
+ fill="none"
265
+ stroke="lightgray"
266
+ strokeWidth="1"
267
+ strokeDasharray="3,2"
268
+ rx="2"
269
+ />
270
+ {/* Lines connecting to value boxes */}
271
+ <line x1="50" y1="10" x2="50" y2="2" stroke="lightgray" strokeWidth="1" />
272
+ <line x1="50" y1="60" x2="50" y2="68" stroke="lightgray" strokeWidth="1" />
273
+ <line x1="10" y1="35" x2="2" y2="35" stroke="lightgray" strokeWidth="1" />
274
+ <line x1="90" y1="35" x2="98" y2="35" stroke="lightgray" strokeWidth="1" />
275
+ </svg>
276
+
277
+ {/* Value boxes at each side */}
278
+ {renderValueBox('top', { top: '-8px', left: '50%', transform: 'translateX(-50%)' })}
279
+ {renderValueBox('bottom', { bottom: '-8px', left: '50%', transform: 'translateX(-50%)' })}
280
+ {renderValueBox('left', { left: '-12px', top: '50%', transform: 'translateY(-50%)' })}
281
+ {renderValueBox('right', { right: '-12px', top: '50%', transform: 'translateY(-50%)' })}
282
+ </div>
283
+ </div>
284
+ );
285
+ }
@@ -0,0 +1,37 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ interface ToggleGroupProps {
4
+ value: string;
5
+ options: Array<{ value: string; label: ReactNode }>;
6
+ onChange: (value: string) => void;
7
+ }
8
+
9
+ export function ToggleGroup({ value, options, onChange }: ToggleGroupProps) {
10
+ return (
11
+ <div style={{ display: 'flex', gap: '2px' }}>
12
+ {options.map(option => (
13
+ <button
14
+ key={option.value}
15
+ onClick={() => onChange(option.value)}
16
+ style={{
17
+ flex: 1,
18
+ padding: '4px 6px',
19
+ borderRadius: '4px',
20
+ border: '1px solid #e4e4e7',
21
+ backgroundColor: value === option.value ? '#18181b' : '#ffffff',
22
+ color: value === option.value ? '#fafafa' : '#71717a',
23
+ cursor: 'pointer',
24
+ fontSize: '10px',
25
+ fontWeight: 500,
26
+ transition: 'all 0.1s ease',
27
+ display: 'flex',
28
+ alignItems: 'center',
29
+ justifyContent: 'center',
30
+ }}
31
+ >
32
+ {option.label}
33
+ </button>
34
+ ))}
35
+ </div>
36
+ );
37
+ }
@@ -0,0 +1,33 @@
1
+ interface TokenDropdownProps {
2
+ value: string;
3
+ tokens: Record<string, string>;
4
+ onChange: (value: string) => void;
5
+ placeholder?: string;
6
+ }
7
+
8
+ export function TokenDropdown({ value, tokens, onChange, placeholder = 'Select...' }: TokenDropdownProps) {
9
+ return (
10
+ <select
11
+ value={value}
12
+ onChange={(e) => onChange(e.target.value)}
13
+ style={{
14
+ width: '100%',
15
+ padding: '4px 8px',
16
+ borderRadius: '4px',
17
+ border: '1px solid #e4e4e7',
18
+ backgroundColor: '#ffffff',
19
+ color: '#18181b',
20
+ fontSize: '11px',
21
+ cursor: 'pointer',
22
+ outline: 'none',
23
+ }}
24
+ >
25
+ <option value="">{placeholder}</option>
26
+ {Object.entries(tokens).map(([key, tokenValue]) => (
27
+ <option key={key} value={tokenValue}>
28
+ {key}: {tokenValue}
29
+ </option>
30
+ ))}
31
+ </select>
32
+ );
33
+ }
@@ -0,0 +1,136 @@
1
+ import { useState, useEffect, useRef, useCallback } from 'react';
2
+ import { SectionWrapper } from './SectionWrapper';
3
+
4
+ interface AnnotationSectionProps {
5
+ expanded: boolean;
6
+ onToggle: () => void;
7
+ onAnnotate: (content: string) => void;
8
+ existingAnnotation?: string;
9
+ hasChanges?: boolean;
10
+ }
11
+
12
+ export function AnnotationSection({
13
+ expanded,
14
+ onToggle,
15
+ onAnnotate,
16
+ existingAnnotation = '',
17
+ hasChanges = false,
18
+ }: AnnotationSectionProps) {
19
+ const [note, setNote] = useState(existingAnnotation);
20
+ const [isSaved, setIsSaved] = useState(!!existingAnnotation);
21
+ const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
22
+ const textareaRef = useRef<HTMLTextAreaElement>(null);
23
+
24
+ // Initialize with existing annotation
25
+ useEffect(() => {
26
+ setNote(existingAnnotation);
27
+ setIsSaved(!!existingAnnotation);
28
+ }, [existingAnnotation]);
29
+
30
+ // Auto-save with debounce
31
+ const handleChange = useCallback((value: string) => {
32
+ setNote(value);
33
+ setIsSaved(false);
34
+
35
+ // Clear previous timeout
36
+ if (debounceRef.current) {
37
+ clearTimeout(debounceRef.current);
38
+ }
39
+
40
+ // Auto-save after 500ms of no typing
41
+ if (value.trim()) {
42
+ debounceRef.current = setTimeout(() => {
43
+ onAnnotate(value.trim());
44
+ setIsSaved(true);
45
+ }, 500);
46
+ }
47
+ }, [onAnnotate]);
48
+
49
+ // Cleanup timeout on unmount
50
+ useEffect(() => {
51
+ return () => {
52
+ if (debounceRef.current) {
53
+ clearTimeout(debounceRef.current);
54
+ }
55
+ };
56
+ }, []);
57
+
58
+ // Save immediately on blur if there's unsaved content
59
+ const handleBlur = () => {
60
+ if (debounceRef.current) {
61
+ clearTimeout(debounceRef.current);
62
+ }
63
+ if (note.trim() && !isSaved) {
64
+ onAnnotate(note.trim());
65
+ setIsSaved(true);
66
+ }
67
+ };
68
+
69
+ const showActiveState = !!(note.trim() && isSaved);
70
+
71
+ return (
72
+ <SectionWrapper
73
+ title="Annotation"
74
+ expanded={expanded}
75
+ onToggle={onToggle}
76
+ hasChanges={hasChanges || showActiveState}
77
+ >
78
+ <div
79
+ style={{
80
+ position: 'relative',
81
+ borderRadius: '4px',
82
+ border: `1px solid ${showActiveState ? '#3b82f6' : '#e4e4e7'}`,
83
+ backgroundColor: showActiveState ? '#eff6ff' : '#ffffff',
84
+ transition: 'all 0.15s ease',
85
+ }}
86
+ >
87
+ <textarea
88
+ ref={textareaRef}
89
+ value={note}
90
+ onChange={(e) => handleChange(e.target.value)}
91
+ onBlur={handleBlur}
92
+ placeholder="Add a note about this element..."
93
+ style={{
94
+ width: '100%',
95
+ minHeight: '60px',
96
+ padding: '8px',
97
+ borderRadius: '4px',
98
+ border: 'none',
99
+ backgroundColor: 'transparent',
100
+ color: '#18181b',
101
+ fontSize: '11px',
102
+ resize: 'vertical',
103
+ fontFamily: 'system-ui, -apple-system, sans-serif',
104
+ outline: 'none',
105
+ }}
106
+ />
107
+ {/* Save indicator */}
108
+ {note.trim() && (
109
+ <div
110
+ style={{
111
+ position: 'absolute',
112
+ bottom: '4px',
113
+ right: '4px',
114
+ fontSize: '9px',
115
+ color: isSaved ? '#3b82f6' : '#a1a1aa',
116
+ display: 'flex',
117
+ alignItems: 'center',
118
+ gap: '2px',
119
+ }}
120
+ >
121
+ {isSaved ? (
122
+ <>
123
+ <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
124
+ <polyline points="20 6 9 17 4 12" />
125
+ </svg>
126
+ Saved
127
+ </>
128
+ ) : (
129
+ 'Saving...'
130
+ )}
131
+ </div>
132
+ )}
133
+ </div>
134
+ </SectionWrapper>
135
+ );
136
+ }
@@ -0,0 +1,79 @@
1
+ import type { DesignTokens } from '../../../types';
2
+ import { SectionWrapper } from './SectionWrapper';
3
+ import { ColorPicker } from '../controls/ColorPicker';
4
+ import { TokenDropdown } from '../controls/TokenDropdown';
5
+
6
+ interface BackgroundSectionProps {
7
+ expanded: boolean;
8
+ onToggle: () => void;
9
+ computedStyle: CSSStyleDeclaration;
10
+ onApplyStyle: (property: string, value: string) => void;
11
+ tokens: DesignTokens;
12
+ hasChanges?: boolean;
13
+ }
14
+
15
+ export function BackgroundSection({
16
+ expanded,
17
+ onToggle,
18
+ computedStyle,
19
+ onApplyStyle,
20
+ tokens,
21
+ hasChanges = false,
22
+ }: BackgroundSectionProps) {
23
+ const backgroundColor = computedStyle.backgroundColor;
24
+ const borderColor = computedStyle.borderColor;
25
+ const borderWidth = computedStyle.borderWidth;
26
+ const borderRadius = computedStyle.borderRadius;
27
+
28
+ return (
29
+ <SectionWrapper title="Background & Border" expanded={expanded} onToggle={onToggle} hasChanges={hasChanges}>
30
+ {/* Background Color */}
31
+ <div style={{ marginBottom: '12px' }}>
32
+ <label style={{ fontSize: '10px', color: '#71717a', marginBottom: '4px', display: 'block' }}>
33
+ Background
34
+ </label>
35
+ <ColorPicker
36
+ value={backgroundColor}
37
+ colors={tokens.colors}
38
+ onChange={(value) => onApplyStyle('background-color', value)}
39
+ />
40
+ </div>
41
+
42
+ {/* Border Color */}
43
+ <div style={{ marginBottom: '12px' }}>
44
+ <label style={{ fontSize: '10px', color: '#71717a', marginBottom: '4px', display: 'block' }}>
45
+ Border Color
46
+ </label>
47
+ <ColorPicker
48
+ value={borderColor}
49
+ colors={tokens.colors}
50
+ onChange={(value) => onApplyStyle('border-color', value)}
51
+ />
52
+ </div>
53
+
54
+ {/* Border Width */}
55
+ <div style={{ marginBottom: '12px' }}>
56
+ <label style={{ fontSize: '10px', color: '#71717a', marginBottom: '4px', display: 'block' }}>
57
+ Border Width
58
+ </label>
59
+ <TokenDropdown
60
+ value={borderWidth}
61
+ tokens={tokens.borderWidth}
62
+ onChange={(value) => onApplyStyle('border-width', value)}
63
+ />
64
+ </div>
65
+
66
+ {/* Border Radius */}
67
+ <div>
68
+ <label style={{ fontSize: '10px', color: '#71717a', marginBottom: '4px', display: 'block' }}>
69
+ Border Radius
70
+ </label>
71
+ <TokenDropdown
72
+ value={borderRadius}
73
+ tokens={tokens.borderRadius}
74
+ onChange={(value) => onApplyStyle('border-radius', value)}
75
+ />
76
+ </div>
77
+ </SectionWrapper>
78
+ );
79
+ }