@bendyline/squisq-editor-react 1.5.3 → 1.6.1
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 +57 -10
- package/dist/index.d.ts +1114 -52
- package/dist/index.js +18446 -8050
- package/dist/index.js.map +1 -1
- package/dist/styles/fa-brands-400-AHOAZHCU.woff2 +0 -0
- package/dist/styles/fa-regular-400-VRZYIBIZ.woff2 +0 -0
- package/dist/styles/fa-solid-900-MDEYK55F.woff2 +0 -0
- package/dist/styles/fa-v4compatibility-ETEVP6IB.woff2 +0 -0
- package/dist/styles/index.css +13867 -0
- package/package.json +15 -7
- package/src/BlockCardView.tsx +121 -0
- package/src/BlockPreviewPanel.tsx +69 -0
- package/src/BlockPropertiesPopover.tsx +191 -0
- package/src/EditorContext.tsx +165 -16
- package/src/EditorShell.tsx +265 -144
- package/src/FolderView.tsx +131 -0
- package/src/Icon.tsx +26 -0
- package/src/ImageEditor.tsx +69 -22
- package/src/OutlinePanel.tsx +64 -7
- package/src/PlainHtmlPreview.tsx +30 -3
- package/src/PreviewControls.tsx +491 -122
- package/src/PreviewPanel.tsx +15 -9
- package/src/RawEditor.tsx +179 -17
- package/src/RecorderEntry.tsx +9 -16
- package/src/TemplateAnnotation.ts +44 -0
- package/src/TemplatePicker.tsx +329 -54
- package/src/ThemeCustomizerPanel.tsx +30 -336
- package/src/ThemePicker.tsx +112 -3
- package/src/TimelineBlockPreview.tsx +37 -0
- package/src/TimelineTrack.tsx +671 -0
- package/src/Toolbar.tsx +544 -180
- package/src/Tooltip.tsx +22 -4
- package/src/TransitionPicker.tsx +351 -0
- package/src/VersionHistoryPanel.tsx +4 -16
- package/src/ViewMenuPanel.tsx +17 -14
- package/src/WysiwygEditor.tsx +161 -65
- package/src/__tests__/blockProperties.test.ts +92 -0
- package/src/__tests__/blockRange.test.ts +105 -0
- package/src/__tests__/buildPreviewDocTransition.test.ts +73 -0
- package/src/__tests__/codeContextSectionView.test.tsx +95 -0
- package/src/__tests__/codeContextZoneManager.test.ts +127 -0
- package/src/__tests__/createShapeLayer.test.ts +46 -0
- package/src/__tests__/diffContextSections.test.ts +39 -0
- package/src/__tests__/drawingShapeRoundTrip.test.ts +49 -0
- package/src/__tests__/editorShellCodeContext.test.tsx +86 -0
- package/src/__tests__/editorShellProps.test.tsx +96 -0
- package/src/__tests__/embeddedMedia.test.ts +48 -0
- package/src/__tests__/headingTransition.test.ts +138 -0
- package/src/__tests__/layoutChildRoundTrip.test.ts +71 -0
- package/src/__tests__/plainHtmlPreview.test.tsx +10 -8
- package/src/__tests__/previewControls.test.tsx +70 -0
- package/src/__tests__/recorderMediaInsert.test.ts +86 -0
- package/src/__tests__/templateAnnotationRoundTrip.test.ts +18 -0
- package/src/__tests__/templatePickerMetadata.test.ts +32 -0
- package/src/__tests__/timelineSource.test.ts +134 -0
- package/src/__tests__/tiptapBridge.test.ts +92 -0
- package/src/__tests__/tiptapBridgeConformance.test.ts +47 -0
- package/src/__tests__/tooltip.test.tsx +72 -0
- package/src/__tests__/transitionCatalog.test.ts +64 -0
- package/src/__tests__/useBlockNavigator.test.tsx +67 -0
- package/src/__tests__/useJsonEditorTokens.test.ts +59 -0
- package/src/__tests__/useMediaRecorder.test.ts +41 -0
- package/src/__tests__/useTimelineClock.test.ts +21 -0
- package/src/blockProperties.ts +88 -0
- package/src/blockRange.ts +132 -0
- package/src/buildPreviewDoc.ts +98 -9
- package/src/codeContext/CodeContextSectionView.tsx +124 -0
- package/src/codeContext/CodeContextZoneManager.ts +149 -0
- package/src/codeContext/CodeContextZones.tsx +121 -0
- package/src/codeContext/diffContextSections.ts +38 -0
- package/src/codeContext/types.ts +75 -0
- package/src/customTemplates/AddBin.tsx +126 -0
- package/src/customTemplates/CustomLayoutManager.tsx +233 -0
- package/src/customTemplates/CustomTemplateContext.tsx +182 -0
- package/src/customTemplates/LayerToolbar.tsx +580 -0
- package/src/customTemplates/ShapeGlyph.tsx +47 -0
- package/src/customTemplates/TemplateDesigner.tsx +430 -0
- package/src/customTemplates/__tests__/library.test.ts +88 -0
- package/src/customTemplates/__tests__/normalizePositions.test.ts +109 -0
- package/src/customTemplates/__tests__/shapeDefs.test.ts +49 -0
- package/src/customTemplates/__tests__/useMemoryLayerAdapter.test.ts +95 -0
- package/src/customTemplates/designer.css +673 -0
- package/src/customTemplates/index.ts +31 -0
- package/src/customTemplates/library.ts +97 -0
- package/src/customTemplates/normalizePositions.ts +75 -0
- package/src/customTemplates/shapeDefs.ts +131 -0
- package/src/customTemplates/thumbnail.tsx +63 -0
- package/src/customTemplates/tokenDefs.ts +60 -0
- package/src/customTemplates/useDocCustomTemplates.ts +52 -0
- package/src/customTemplates/useMemoryLayerAdapter.ts +123 -0
- package/src/customThemes/CustomThemeContext.tsx +179 -0
- package/src/customThemes/CustomThemeDialog.tsx +286 -0
- package/src/customThemes/__tests__/CustomThemeContext.test.tsx +64 -0
- package/src/customThemes/__tests__/CustomThemeDialog.test.tsx +47 -0
- package/src/customThemes/__tests__/customThemeLibrary.test.ts +51 -0
- package/src/customThemes/customThemeLibrary.ts +97 -0
- package/src/customThemes/index.ts +31 -0
- package/src/customThemes/themeControls.tsx +229 -0
- package/src/customThemes/themeDraft.ts +272 -0
- package/src/customThemes/useDocCustomThemes.ts +49 -0
- package/src/diagram/DiagramCanvas.tsx +240 -0
- package/src/diagram/DiagramExtension.ts +209 -0
- package/src/diagram/DiagramMaximizedOverlay.tsx +46 -0
- package/src/diagram/DiagramWidget.tsx +270 -0
- package/src/diagram/diagramCommands.ts +604 -0
- package/src/diagram/diagramConstants.ts +17 -0
- package/src/diagram/useDiagramData.ts +126 -0
- package/src/embeddedMedia.ts +78 -0
- package/src/frontmatter.ts +29 -0
- package/src/headingTransition.ts +231 -0
- package/src/imageEditor/CanvasSurface.tsx +383 -88
- package/src/imageEditor/PropertiesPanel.tsx +47 -1
- package/src/imageEditor/Toolbar.tsx +229 -16
- package/src/imageEditor/createShapeLayer.ts +280 -0
- package/src/imageEditor/icons.tsx +34 -114
- package/src/imageEditor/image-editor.css +54 -5
- package/src/imageEditor/state.ts +23 -3
- package/src/index.ts +109 -1
- package/src/jsonEditor/useJsonEditorTokens.ts +13 -43
- package/src/recorder/RecorderModal.tsx +120 -53
- package/src/recorder/RecorderPanel.tsx +2 -26
- package/src/recorder/hooks/useMediaRecorder.ts +17 -11
- package/src/recorder/insertMediaBlock.ts +30 -0
- package/src/resolveBlockVisual.ts +33 -0
- package/src/scene/Scene.tsx +540 -0
- package/src/scene/SceneBlockExtension.ts +198 -0
- package/src/scene/SceneBlockToolbar.tsx +201 -0
- package/src/scene/SceneBlockWidget.tsx +434 -0
- package/src/scene/ScenePropsBar.tsx +85 -0
- package/src/scene/SceneSelection.tsx +107 -0
- package/src/scene/SceneViewport.tsx +102 -0
- package/src/scene/ShapePalette.tsx +181 -0
- package/src/scene/__tests__/DiagramAdapter.test.ts +56 -0
- package/src/scene/__tests__/bezierEdit.test.ts +85 -0
- package/src/scene/__tests__/blockLayers.test.ts +57 -0
- package/src/scene/__tests__/shapeLayers.test.ts +106 -0
- package/src/scene/__tests__/useSceneHitTest.test.ts +90 -0
- package/src/scene/__tests__/useScenePanZoom.test.ts +103 -0
- package/src/scene/adapters/DiagramAdapter.ts +168 -0
- package/src/scene/adapters/DrawingAdapter.ts +415 -0
- package/src/scene/adapters/LayoutAdapter.ts +310 -0
- package/src/scene/adapters/blockLayers.ts +159 -0
- package/src/scene/commands/SceneCommand.ts +70 -0
- package/src/scene/commands/drawingCommands.ts +318 -0
- package/src/scene/commands/layoutCommands.ts +301 -0
- package/src/scene/hooks/useSceneHitTest.ts +105 -0
- package/src/scene/hooks/useScenePanZoom.ts +147 -0
- package/src/scene/hooks/useSceneSelection.ts +62 -0
- package/src/scene/index.ts +95 -0
- package/src/scene/layers/DiagramEdges.tsx +127 -0
- package/src/scene/layers/edgeGeometry.ts +77 -0
- package/src/scene/layers/nodeCard.tsx +145 -0
- package/src/scene/layers/renderLayer.tsx +70 -0
- package/src/scene/layers/shapeLayers.ts +201 -0
- package/src/scene/paths/bezierEdit.ts +208 -0
- package/src/scene/scene.css +649 -0
- package/src/scene/text/SceneTextOverlay.tsx +161 -0
- package/src/scene/text/sceneTextChannel.ts +40 -0
- package/src/scene/text/sceneTextConfig.ts +27 -0
- package/src/scene/text/sceneTiptap.ts +36 -0
- package/src/scene/text/useSceneTextEditing.ts +39 -0
- package/src/scene/tools/ConnectTool.ts +111 -0
- package/src/scene/tools/DrawingConnectTool.ts +161 -0
- package/src/scene/tools/PathTool.ts +158 -0
- package/src/scene/tools/PlaceTool.ts +47 -0
- package/src/scene/tools/SceneTool.ts +75 -0
- package/src/scene/tools/SelectTool.ts +284 -0
- package/src/scene/tools/ShapeTool.ts +144 -0
- package/src/scene/tools/TextTool.ts +72 -0
- package/src/scene/tools/TokenTool.ts +95 -0
- package/src/scene/tools/createDrawShapeTool.ts +82 -0
- package/src/styles/code-context.css +155 -0
- package/src/styles/diagram.css +183 -0
- package/src/styles/editor.css +1708 -150
- package/src/styles/folder-view.css +210 -0
- package/src/styles/image-edit-affordance.css +2 -2
- package/src/styles/index.css +5 -0
- package/src/timelineSource.ts +244 -0
- package/src/tiptapBridge.ts +115 -34
- package/src/tooltipPlacement.ts +13 -0
- package/src/transitionCatalog.ts +159 -0
- package/src/types/monaco-shims.d.ts +10 -0
- package/src/useBlockNavigator.ts +153 -0
- package/src/useMonacoLoader.ts +23 -1
- package/src/useTimelineClock.ts +76 -0
- package/src/utils/dropUtils.ts +1 -1
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LayerToolbar — contextual styling controls for the layer currently
|
|
3
|
+
* selected in the TemplateDesigner. Renders a compact toolbar whose
|
|
4
|
+
* controls depend on the layer type:
|
|
5
|
+
*
|
|
6
|
+
* - text → alignment, font size/weight/family, text color, plus a
|
|
7
|
+
* background fill (color · opacity · gradient) and border
|
|
8
|
+
* (color · thickness · style) — text is a rectangle too.
|
|
9
|
+
* - shape → shape kind, fill (color · opacity · gradient), and border
|
|
10
|
+
* (color · thickness · style).
|
|
11
|
+
* - image → object-fit.
|
|
12
|
+
*
|
|
13
|
+
* Fill and border editors are shared between text and shapes via
|
|
14
|
+
* {@link FillEditor} / {@link BorderEditor}, parameterized by the dotted
|
|
15
|
+
* attribute paths each layer type uses.
|
|
16
|
+
*
|
|
17
|
+
* Every control dispatches a single `setLayerAttr` via `onAttr(path,
|
|
18
|
+
* value)`, where `path` is a dotted path into the layer (e.g.
|
|
19
|
+
* `content.style.color`). The parent owns the command dispatch and the
|
|
20
|
+
* selected-layer lookup, so this component stays a pure view over the
|
|
21
|
+
* current layer.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import type { Layer, LinearGradient, BorderStyle } from '@bendyline/squisq/schemas';
|
|
25
|
+
import { AVAILABLE_FONT_STACKS } from '@bendyline/squisq/schemas';
|
|
26
|
+
import { Icon } from '../Icon';
|
|
27
|
+
|
|
28
|
+
interface LayerToolbarProps {
|
|
29
|
+
layer: Layer;
|
|
30
|
+
/** Set a single dotted attribute path on the selected layer. */
|
|
31
|
+
onAttr: (path: string, value: unknown) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function LayerToolbar({ layer, onAttr }: LayerToolbarProps) {
|
|
35
|
+
return (
|
|
36
|
+
<div className="squisq-layer-toolbar" role="toolbar" aria-label="Layer styling">
|
|
37
|
+
{layer.type === 'text' && <TextControls layer={layer} onAttr={onAttr} />}
|
|
38
|
+
{layer.type === 'shape' && <ShapeControls layer={layer} onAttr={onAttr} />}
|
|
39
|
+
{layer.type === 'path' && <PathControls layer={layer} onAttr={onAttr} />}
|
|
40
|
+
{layer.type === 'image' && <ImageControls layer={layer} onAttr={onAttr} />}
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ─── Text ───────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
const FONT_SIZES: Array<[string, number]> = [
|
|
48
|
+
['Small', 24],
|
|
49
|
+
['Medium', 40],
|
|
50
|
+
['Large', 72],
|
|
51
|
+
['Huge', 120],
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
function TextControls({
|
|
55
|
+
layer,
|
|
56
|
+
onAttr,
|
|
57
|
+
}: {
|
|
58
|
+
layer: Layer & { type: 'text' };
|
|
59
|
+
onAttr: LayerToolbarProps['onAttr'];
|
|
60
|
+
}) {
|
|
61
|
+
const style = layer.content.style;
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
<SegGroup
|
|
65
|
+
label="Horizontal align"
|
|
66
|
+
value={style.textAlign ?? 'left'}
|
|
67
|
+
onChange={(v) => onAttr('content.style.textAlign', v)}
|
|
68
|
+
options={[
|
|
69
|
+
{ value: 'left', icon: 'fa-solid fa-align-left', title: 'Align left' },
|
|
70
|
+
{ value: 'center', icon: 'fa-solid fa-align-center', title: 'Align center' },
|
|
71
|
+
{ value: 'right', icon: 'fa-solid fa-align-right', title: 'Align right' },
|
|
72
|
+
]}
|
|
73
|
+
/>
|
|
74
|
+
<SegGroup
|
|
75
|
+
label="Vertical align"
|
|
76
|
+
value={style.verticalAlign ?? 'top'}
|
|
77
|
+
onChange={(v) => onAttr('content.style.verticalAlign', v)}
|
|
78
|
+
options={[
|
|
79
|
+
{ value: 'top', icon: 'fa-solid fa-arrow-up', title: 'Align top' },
|
|
80
|
+
{ value: 'middle', icon: 'fa-solid fa-grip-lines', title: 'Align middle' },
|
|
81
|
+
{ value: 'bottom', icon: 'fa-solid fa-arrow-down', title: 'Align bottom' },
|
|
82
|
+
]}
|
|
83
|
+
/>
|
|
84
|
+
<Sep />
|
|
85
|
+
<select
|
|
86
|
+
className="squisq-layer-toolbar-select"
|
|
87
|
+
aria-label="Font size"
|
|
88
|
+
title="Font size"
|
|
89
|
+
value={nearestSize(style.fontSize)}
|
|
90
|
+
onChange={(e) => onAttr('content.style.fontSize', Number(e.target.value))}
|
|
91
|
+
>
|
|
92
|
+
{FONT_SIZES.map(([l, v]) => (
|
|
93
|
+
<option key={v} value={v}>
|
|
94
|
+
{l}
|
|
95
|
+
</option>
|
|
96
|
+
))}
|
|
97
|
+
</select>
|
|
98
|
+
<button
|
|
99
|
+
type="button"
|
|
100
|
+
className={`squisq-layer-toolbar-btn${
|
|
101
|
+
style.fontWeight === 'bold' ? ' squisq-layer-toolbar-btn--active' : ''
|
|
102
|
+
}`}
|
|
103
|
+
aria-label="Bold"
|
|
104
|
+
aria-pressed={style.fontWeight === 'bold'}
|
|
105
|
+
title="Bold"
|
|
106
|
+
onClick={() =>
|
|
107
|
+
onAttr('content.style.fontWeight', style.fontWeight === 'bold' ? 'normal' : 'bold')
|
|
108
|
+
}
|
|
109
|
+
>
|
|
110
|
+
<Icon icon="fa-solid fa-bold" />
|
|
111
|
+
</button>
|
|
112
|
+
<Sep />
|
|
113
|
+
<span className="squisq-layer-toolbar-label">
|
|
114
|
+
<Icon icon="fa-solid fa-font" />
|
|
115
|
+
</span>
|
|
116
|
+
<select
|
|
117
|
+
className="squisq-layer-toolbar-select squisq-layer-toolbar-select--font"
|
|
118
|
+
aria-label="Font"
|
|
119
|
+
title="Font"
|
|
120
|
+
value={style.fontFamily ?? ''}
|
|
121
|
+
onChange={(e) => onAttr('content.style.fontFamily', e.target.value || undefined)}
|
|
122
|
+
>
|
|
123
|
+
<option value="">Default</option>
|
|
124
|
+
{AVAILABLE_FONT_STACKS.map((s) => (
|
|
125
|
+
<option key={s.id} value={s.family}>
|
|
126
|
+
{s.label}
|
|
127
|
+
</option>
|
|
128
|
+
))}
|
|
129
|
+
</select>
|
|
130
|
+
<Color
|
|
131
|
+
label="Text color"
|
|
132
|
+
value={style.color}
|
|
133
|
+
onChange={(v) => onAttr('content.style.color', v)}
|
|
134
|
+
/>
|
|
135
|
+
<Sep />
|
|
136
|
+
<span className="squisq-layer-toolbar-label" title="Background fill">
|
|
137
|
+
<Icon icon="fa-solid fa-fill-drip" />
|
|
138
|
+
</span>
|
|
139
|
+
<FillEditor
|
|
140
|
+
label="Background"
|
|
141
|
+
color={style.background}
|
|
142
|
+
opacity={style.backgroundOpacity}
|
|
143
|
+
gradient={style.backgroundGradient}
|
|
144
|
+
defaultColor="#1f2937"
|
|
145
|
+
noFillValue={undefined}
|
|
146
|
+
colorPath="content.style.background"
|
|
147
|
+
opacityPath="content.style.backgroundOpacity"
|
|
148
|
+
gradientPath="content.style.backgroundGradient"
|
|
149
|
+
onAttr={onAttr}
|
|
150
|
+
/>
|
|
151
|
+
<Sep />
|
|
152
|
+
<span className="squisq-layer-toolbar-label" title="Border">
|
|
153
|
+
<Icon icon="fa-solid fa-border-top-left" />
|
|
154
|
+
</span>
|
|
155
|
+
<BorderEditor
|
|
156
|
+
color={style.borderColor}
|
|
157
|
+
width={style.borderWidth}
|
|
158
|
+
style={style.borderStyle}
|
|
159
|
+
defaultColor="#1e293b"
|
|
160
|
+
noBorderValue={undefined}
|
|
161
|
+
colorPath="content.style.borderColor"
|
|
162
|
+
widthPath="content.style.borderWidth"
|
|
163
|
+
stylePath="content.style.borderStyle"
|
|
164
|
+
onAttr={onAttr}
|
|
165
|
+
/>
|
|
166
|
+
</>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Snap an arbitrary font size to the nearest named preset for the select. */
|
|
171
|
+
function nearestSize(size: number): number {
|
|
172
|
+
let best = FONT_SIZES[0][1];
|
|
173
|
+
for (const [, v] of FONT_SIZES) {
|
|
174
|
+
if (Math.abs(v - size) < Math.abs(best - size)) best = v;
|
|
175
|
+
}
|
|
176
|
+
return best;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ─── Shape (native) + Path (computed shape) ─────────────────────
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Fill + border controls shared by native `ShapeLayer`s and computed
|
|
183
|
+
* `PathLayer` shapes — both keep fill/stroke under the same
|
|
184
|
+
* `content.*` paths, so the editor is identical.
|
|
185
|
+
*/
|
|
186
|
+
function FillBorderControls({
|
|
187
|
+
content,
|
|
188
|
+
onAttr,
|
|
189
|
+
}: {
|
|
190
|
+
content: {
|
|
191
|
+
fill?: string;
|
|
192
|
+
fillOpacity?: number;
|
|
193
|
+
gradient?: LinearGradient;
|
|
194
|
+
stroke?: string;
|
|
195
|
+
strokeWidth?: number;
|
|
196
|
+
borderStyle?: BorderStyle;
|
|
197
|
+
};
|
|
198
|
+
onAttr: LayerToolbarProps['onAttr'];
|
|
199
|
+
}) {
|
|
200
|
+
return (
|
|
201
|
+
<>
|
|
202
|
+
<span className="squisq-layer-toolbar-label" title="Fill">
|
|
203
|
+
<Icon icon="fa-solid fa-fill-drip" />
|
|
204
|
+
</span>
|
|
205
|
+
<FillEditor
|
|
206
|
+
label="Fill"
|
|
207
|
+
color={content.fill}
|
|
208
|
+
opacity={content.fillOpacity}
|
|
209
|
+
gradient={content.gradient}
|
|
210
|
+
defaultColor="#3b82f6"
|
|
211
|
+
noFillValue="none"
|
|
212
|
+
colorPath="content.fill"
|
|
213
|
+
opacityPath="content.fillOpacity"
|
|
214
|
+
gradientPath="content.gradient"
|
|
215
|
+
onAttr={onAttr}
|
|
216
|
+
/>
|
|
217
|
+
<Sep />
|
|
218
|
+
<span className="squisq-layer-toolbar-label" title="Border">
|
|
219
|
+
<Icon icon="fa-solid fa-border-top-left" />
|
|
220
|
+
</span>
|
|
221
|
+
<BorderEditor
|
|
222
|
+
color={content.stroke}
|
|
223
|
+
width={content.strokeWidth}
|
|
224
|
+
style={content.borderStyle}
|
|
225
|
+
defaultColor="#1e293b"
|
|
226
|
+
noBorderValue="none"
|
|
227
|
+
colorPath="content.stroke"
|
|
228
|
+
widthPath="content.strokeWidth"
|
|
229
|
+
stylePath="content.borderStyle"
|
|
230
|
+
onAttr={onAttr}
|
|
231
|
+
/>
|
|
232
|
+
</>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function ShapeControls({
|
|
237
|
+
layer,
|
|
238
|
+
onAttr,
|
|
239
|
+
}: {
|
|
240
|
+
layer: Layer & { type: 'shape' };
|
|
241
|
+
onAttr: LayerToolbarProps['onAttr'];
|
|
242
|
+
}) {
|
|
243
|
+
return (
|
|
244
|
+
<>
|
|
245
|
+
<select
|
|
246
|
+
className="squisq-layer-toolbar-select"
|
|
247
|
+
aria-label="Shape"
|
|
248
|
+
title="Shape"
|
|
249
|
+
value={layer.content.shape}
|
|
250
|
+
onChange={(e) => onAttr('content.shape', e.target.value)}
|
|
251
|
+
>
|
|
252
|
+
<option value="rect">Rectangle</option>
|
|
253
|
+
<option value="circle">Ellipse</option>
|
|
254
|
+
<option value="line">Line</option>
|
|
255
|
+
</select>
|
|
256
|
+
<Sep />
|
|
257
|
+
<FillBorderControls content={layer.content} onAttr={onAttr} />
|
|
258
|
+
</>
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function PathControls({
|
|
263
|
+
layer,
|
|
264
|
+
onAttr,
|
|
265
|
+
}: {
|
|
266
|
+
layer: Layer & { type: 'path' };
|
|
267
|
+
onAttr: LayerToolbarProps['onAttr'];
|
|
268
|
+
}) {
|
|
269
|
+
// Computed shapes (diamond, star, arrows…) carry the same fill/stroke
|
|
270
|
+
// fields as native shapes — no shape-kind select since the geometry is
|
|
271
|
+
// fixed by the placed shape.
|
|
272
|
+
return <FillBorderControls content={layer.content} onAttr={onAttr} />;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ─── Image ──────────────────────────────────────────────────────
|
|
276
|
+
|
|
277
|
+
function ImageControls({
|
|
278
|
+
layer,
|
|
279
|
+
onAttr,
|
|
280
|
+
}: {
|
|
281
|
+
layer: Layer & { type: 'image' };
|
|
282
|
+
onAttr: LayerToolbarProps['onAttr'];
|
|
283
|
+
}) {
|
|
284
|
+
return (
|
|
285
|
+
<select
|
|
286
|
+
className="squisq-layer-toolbar-select"
|
|
287
|
+
aria-label="Image fit"
|
|
288
|
+
title="How the image fills its box"
|
|
289
|
+
value={layer.content.fit ?? 'cover'}
|
|
290
|
+
onChange={(e) => onAttr('content.fit', e.target.value)}
|
|
291
|
+
>
|
|
292
|
+
<option value="cover">Fit: Cover</option>
|
|
293
|
+
<option value="contain">Fit: Contain</option>
|
|
294
|
+
<option value="fill">Fit: Stretch</option>
|
|
295
|
+
</select>
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ─── Shared controls ────────────────────────────────────────────
|
|
300
|
+
|
|
301
|
+
interface SegOption {
|
|
302
|
+
value: string;
|
|
303
|
+
icon: string;
|
|
304
|
+
title: string;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function SegGroup({
|
|
308
|
+
label,
|
|
309
|
+
value,
|
|
310
|
+
options,
|
|
311
|
+
onChange,
|
|
312
|
+
}: {
|
|
313
|
+
label: string;
|
|
314
|
+
value: string;
|
|
315
|
+
options: SegOption[];
|
|
316
|
+
onChange: (v: string) => void;
|
|
317
|
+
}) {
|
|
318
|
+
return (
|
|
319
|
+
<div className="squisq-layer-toolbar-seg" role="group" aria-label={label}>
|
|
320
|
+
{options.map((o) => (
|
|
321
|
+
<button
|
|
322
|
+
key={o.value}
|
|
323
|
+
type="button"
|
|
324
|
+
className={`squisq-layer-toolbar-btn${
|
|
325
|
+
value === o.value ? ' squisq-layer-toolbar-btn--active' : ''
|
|
326
|
+
}`}
|
|
327
|
+
aria-label={o.title}
|
|
328
|
+
aria-pressed={value === o.value}
|
|
329
|
+
title={o.title}
|
|
330
|
+
onClick={() => onChange(o.value)}
|
|
331
|
+
>
|
|
332
|
+
<Icon icon={o.icon} />
|
|
333
|
+
</button>
|
|
334
|
+
))}
|
|
335
|
+
</div>
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function Color({
|
|
340
|
+
label,
|
|
341
|
+
value,
|
|
342
|
+
onChange,
|
|
343
|
+
onClear,
|
|
344
|
+
clearLabel,
|
|
345
|
+
cleared,
|
|
346
|
+
}: {
|
|
347
|
+
label: string;
|
|
348
|
+
value: string;
|
|
349
|
+
onChange: (v: string) => void;
|
|
350
|
+
onClear?: () => void;
|
|
351
|
+
clearLabel?: string;
|
|
352
|
+
cleared?: boolean;
|
|
353
|
+
}) {
|
|
354
|
+
return (
|
|
355
|
+
<span className="squisq-layer-toolbar-color" title={label}>
|
|
356
|
+
<input
|
|
357
|
+
type="color"
|
|
358
|
+
aria-label={label}
|
|
359
|
+
value={normalizeColor(value)}
|
|
360
|
+
onChange={(e) => onChange(e.target.value)}
|
|
361
|
+
style={cleared ? { opacity: 0.4 } : undefined}
|
|
362
|
+
/>
|
|
363
|
+
{onClear && (
|
|
364
|
+
<button
|
|
365
|
+
type="button"
|
|
366
|
+
className={`squisq-layer-toolbar-btn${cleared ? ' squisq-layer-toolbar-btn--active' : ''}`}
|
|
367
|
+
aria-label={clearLabel ?? 'None'}
|
|
368
|
+
title={clearLabel ?? 'None'}
|
|
369
|
+
onClick={onClear}
|
|
370
|
+
>
|
|
371
|
+
<Icon icon="fa-solid fa-ban" />
|
|
372
|
+
</button>
|
|
373
|
+
)}
|
|
374
|
+
</span>
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ─── Fill editor (color · opacity · gradient) ───────────────────
|
|
379
|
+
|
|
380
|
+
const GRADIENT_DIRECTIONS: Array<[string, number, string]> = [
|
|
381
|
+
['↓', 0, 'Top to bottom'],
|
|
382
|
+
['→', 90, 'Left to right'],
|
|
383
|
+
['↘', 45, 'Diagonal ↘'],
|
|
384
|
+
['↙', 135, 'Diagonal ↙'],
|
|
385
|
+
];
|
|
386
|
+
|
|
387
|
+
function FillEditor({
|
|
388
|
+
label,
|
|
389
|
+
color,
|
|
390
|
+
opacity,
|
|
391
|
+
gradient,
|
|
392
|
+
defaultColor,
|
|
393
|
+
noFillValue,
|
|
394
|
+
colorPath,
|
|
395
|
+
opacityPath,
|
|
396
|
+
gradientPath,
|
|
397
|
+
onAttr,
|
|
398
|
+
}: {
|
|
399
|
+
label: string;
|
|
400
|
+
color: string | undefined;
|
|
401
|
+
opacity: number | undefined;
|
|
402
|
+
gradient: LinearGradient | undefined;
|
|
403
|
+
/** Solid swatch shown when no color is set yet. */
|
|
404
|
+
defaultColor: string;
|
|
405
|
+
/** Value written when the user clears the fill (`'none'` for shapes,
|
|
406
|
+
* `undefined` for text backgrounds). */
|
|
407
|
+
noFillValue: 'none' | undefined;
|
|
408
|
+
colorPath: string;
|
|
409
|
+
opacityPath: string;
|
|
410
|
+
gradientPath: string;
|
|
411
|
+
onAttr: LayerToolbarProps['onAttr'];
|
|
412
|
+
}) {
|
|
413
|
+
const isGradient = !!gradient;
|
|
414
|
+
const swatch = color && color !== 'none' ? color : defaultColor;
|
|
415
|
+
return (
|
|
416
|
+
<>
|
|
417
|
+
<select
|
|
418
|
+
className="squisq-layer-toolbar-select"
|
|
419
|
+
aria-label={`${label} style`}
|
|
420
|
+
title={`${label} style`}
|
|
421
|
+
value={isGradient ? 'gradient' : 'solid'}
|
|
422
|
+
onChange={(e) => {
|
|
423
|
+
if (e.target.value === 'gradient') {
|
|
424
|
+
onAttr(gradientPath, { from: swatch, to: '#ffffff', angle: 0 });
|
|
425
|
+
} else {
|
|
426
|
+
onAttr(gradientPath, undefined);
|
|
427
|
+
}
|
|
428
|
+
}}
|
|
429
|
+
>
|
|
430
|
+
<option value="solid">Solid</option>
|
|
431
|
+
<option value="gradient">Gradient</option>
|
|
432
|
+
</select>
|
|
433
|
+
{isGradient ? (
|
|
434
|
+
<>
|
|
435
|
+
<Color
|
|
436
|
+
label={`${label} start color`}
|
|
437
|
+
value={gradient!.from}
|
|
438
|
+
onChange={(v) => onAttr(gradientPath, { ...gradient, from: v })}
|
|
439
|
+
/>
|
|
440
|
+
<Color
|
|
441
|
+
label={`${label} end color`}
|
|
442
|
+
value={gradient!.to}
|
|
443
|
+
onChange={(v) => onAttr(gradientPath, { ...gradient, to: v })}
|
|
444
|
+
/>
|
|
445
|
+
<select
|
|
446
|
+
className="squisq-layer-toolbar-select"
|
|
447
|
+
aria-label={`${label} direction`}
|
|
448
|
+
title={`${label} direction`}
|
|
449
|
+
value={String(gradient!.angle ?? 0)}
|
|
450
|
+
onChange={(e) => onAttr(gradientPath, { ...gradient, angle: Number(e.target.value) })}
|
|
451
|
+
>
|
|
452
|
+
{GRADIENT_DIRECTIONS.map(([glyph, deg, title]) => (
|
|
453
|
+
<option key={deg} value={deg} title={title}>
|
|
454
|
+
{glyph}
|
|
455
|
+
</option>
|
|
456
|
+
))}
|
|
457
|
+
</select>
|
|
458
|
+
</>
|
|
459
|
+
) : (
|
|
460
|
+
<Color
|
|
461
|
+
label={`${label} color`}
|
|
462
|
+
value={swatch}
|
|
463
|
+
onChange={(v) => onAttr(colorPath, v)}
|
|
464
|
+
clearLabel="No fill"
|
|
465
|
+
onClear={() => onAttr(colorPath, noFillValue)}
|
|
466
|
+
cleared={!color || color === 'none'}
|
|
467
|
+
/>
|
|
468
|
+
)}
|
|
469
|
+
<Opacity
|
|
470
|
+
label={`${label} opacity`}
|
|
471
|
+
value={opacity}
|
|
472
|
+
onChange={(v) => onAttr(opacityPath, v)}
|
|
473
|
+
/>
|
|
474
|
+
</>
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// ─── Border editor (color · thickness · style) ──────────────────
|
|
479
|
+
|
|
480
|
+
function BorderEditor({
|
|
481
|
+
color,
|
|
482
|
+
width,
|
|
483
|
+
style,
|
|
484
|
+
defaultColor,
|
|
485
|
+
noBorderValue,
|
|
486
|
+
colorPath,
|
|
487
|
+
widthPath,
|
|
488
|
+
stylePath,
|
|
489
|
+
onAttr,
|
|
490
|
+
}: {
|
|
491
|
+
color: string | undefined;
|
|
492
|
+
width: number | undefined;
|
|
493
|
+
style: BorderStyle | undefined;
|
|
494
|
+
defaultColor: string;
|
|
495
|
+
noBorderValue: 'none' | undefined;
|
|
496
|
+
colorPath: string;
|
|
497
|
+
widthPath: string;
|
|
498
|
+
stylePath: string;
|
|
499
|
+
onAttr: LayerToolbarProps['onAttr'];
|
|
500
|
+
}) {
|
|
501
|
+
return (
|
|
502
|
+
<>
|
|
503
|
+
<Color
|
|
504
|
+
label="Border color"
|
|
505
|
+
value={color && color !== 'none' ? color : defaultColor}
|
|
506
|
+
onChange={(v) => onAttr(colorPath, v)}
|
|
507
|
+
clearLabel="No border"
|
|
508
|
+
onClear={() => onAttr(colorPath, noBorderValue)}
|
|
509
|
+
cleared={!color || color === 'none'}
|
|
510
|
+
/>
|
|
511
|
+
<input
|
|
512
|
+
type="number"
|
|
513
|
+
className="squisq-layer-toolbar-number"
|
|
514
|
+
aria-label="Border thickness"
|
|
515
|
+
title="Border thickness"
|
|
516
|
+
min={0}
|
|
517
|
+
max={80}
|
|
518
|
+
step={1}
|
|
519
|
+
value={width ?? 0}
|
|
520
|
+
onChange={(e) => onAttr(widthPath, Number(e.target.value))}
|
|
521
|
+
/>
|
|
522
|
+
<select
|
|
523
|
+
className="squisq-layer-toolbar-select"
|
|
524
|
+
aria-label="Border style"
|
|
525
|
+
title="Border style"
|
|
526
|
+
value={style ?? 'solid'}
|
|
527
|
+
onChange={(e) => onAttr(stylePath, e.target.value)}
|
|
528
|
+
>
|
|
529
|
+
<option value="solid">Solid</option>
|
|
530
|
+
<option value="dashed">Dashed</option>
|
|
531
|
+
<option value="dotted">Dotted</option>
|
|
532
|
+
</select>
|
|
533
|
+
</>
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function Opacity({
|
|
538
|
+
label,
|
|
539
|
+
value,
|
|
540
|
+
onChange,
|
|
541
|
+
}: {
|
|
542
|
+
label: string;
|
|
543
|
+
value: number | undefined;
|
|
544
|
+
onChange: (v: number) => void;
|
|
545
|
+
}) {
|
|
546
|
+
const pct = Math.round((value ?? 1) * 100);
|
|
547
|
+
return (
|
|
548
|
+
<label className="squisq-layer-toolbar-opacity" title={`${label} (${pct}%)`}>
|
|
549
|
+
<input
|
|
550
|
+
type="range"
|
|
551
|
+
aria-label={label}
|
|
552
|
+
min={0}
|
|
553
|
+
max={100}
|
|
554
|
+
step={5}
|
|
555
|
+
value={pct}
|
|
556
|
+
onChange={(e) => onChange(Number(e.target.value) / 100)}
|
|
557
|
+
/>
|
|
558
|
+
</label>
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function Sep() {
|
|
563
|
+
return <div className="squisq-layer-toolbar-sep" aria-hidden="true" />;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/** Coerce an arbitrary CSS color to a 6-digit hex the color input accepts. */
|
|
567
|
+
function normalizeColor(v: string): string {
|
|
568
|
+
if (/^#[0-9a-f]{6}$/i.test(v)) return v;
|
|
569
|
+
if (/^#[0-9a-f]{3}$/i.test(v)) {
|
|
570
|
+
return (
|
|
571
|
+
'#' +
|
|
572
|
+
v
|
|
573
|
+
.slice(1)
|
|
574
|
+
.split('')
|
|
575
|
+
.map((c) => c + c)
|
|
576
|
+
.join('')
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
return '#000000';
|
|
580
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShapeGlyph — a tiny SVG preview of a shape kind for the Add bin's
|
|
3
|
+
* shape buttons. Uses the same {@link shapePath} geometry the placed
|
|
4
|
+
* `PathLayer` will use, so the button icon matches what lands on the
|
|
5
|
+
* canvas. Native kinds (rect / circle / line) are drawn directly since
|
|
6
|
+
* `shapePath` returns null for them.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { shapePath } from '@bendyline/squisq/doc';
|
|
10
|
+
|
|
11
|
+
const W = 30;
|
|
12
|
+
const H = 24;
|
|
13
|
+
const PAD = 3;
|
|
14
|
+
|
|
15
|
+
interface ShapeGlyphProps {
|
|
16
|
+
kind: string;
|
|
17
|
+
rounded?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function ShapeGlyph({ kind, rounded }: ShapeGlyphProps) {
|
|
21
|
+
const x = PAD;
|
|
22
|
+
const y = PAD;
|
|
23
|
+
const w = W - PAD * 2;
|
|
24
|
+
const h = H - PAD * 2;
|
|
25
|
+
const common = {
|
|
26
|
+
fill: '#e2e8f0',
|
|
27
|
+
stroke: '#475569',
|
|
28
|
+
strokeWidth: 1.5,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
let body;
|
|
32
|
+
if (kind === 'rect') {
|
|
33
|
+
body = <rect x={x} y={y} width={w} height={h} rx={rounded ? 5 : 0} {...common} />;
|
|
34
|
+
} else if (kind === 'circle') {
|
|
35
|
+
body = <ellipse cx={W / 2} cy={H / 2} rx={w / 2} ry={h / 2} {...common} />;
|
|
36
|
+
} else if (kind === 'line') {
|
|
37
|
+
body = <line x1={x} y1={H - PAD} x2={W - PAD} y2={y} stroke="#475569" strokeWidth={2} />;
|
|
38
|
+
} else {
|
|
39
|
+
body = <path d={shapePath(kind, x, y, w, h) ?? ''} {...common} />;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<svg width={W} height={H} viewBox={`0 0 ${W} ${H}`} aria-hidden="true" focusable="false">
|
|
44
|
+
{body}
|
|
45
|
+
</svg>
|
|
46
|
+
);
|
|
47
|
+
}
|