@bendyline/squisq-editor-react 2.0.1 → 2.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.
- package/LICENSE +21 -0
- package/NOTICE.md +40 -0
- package/README.md +10 -2
- package/dist/index.d.ts +683 -60
- package/dist/index.js +9648 -3750
- package/dist/monaco.js +0 -1
- package/dist/styles/index.css +1160 -241
- package/package.json +10 -6
- package/dist/index.js.map +0 -1
- package/dist/monaco.js.map +0 -1
- package/src/BlockCardView.tsx +0 -121
- package/src/BlockPreviewPanel.tsx +0 -69
- package/src/BlockPropertiesPopover.tsx +0 -222
- package/src/DocumentSettingsDialog.tsx +0 -272
- package/src/DropZoneOverlay.tsx +0 -137
- package/src/EditorContext.tsx +0 -1247
- package/src/EditorShell.tsx +0 -1334
- package/src/EmojiPicker.tsx +0 -332
- package/src/FolderView.tsx +0 -131
- package/src/Icon.tsx +0 -26
- package/src/ImageEditor.tsx +0 -395
- package/src/ImageNodeView.tsx +0 -284
- package/src/ImageViewer.tsx +0 -221
- package/src/InlineIcon.ts +0 -84
- package/src/InlinePreviewGutter.tsx +0 -590
- package/src/LinkDialog.tsx +0 -276
- package/src/MediaBin.tsx +0 -500
- package/src/MentionExtension.tsx +0 -261
- package/src/OutlinePanel.tsx +0 -547
- package/src/PlainHtmlPreview.tsx +0 -277
- package/src/PreviewControls.tsx +0 -1250
- package/src/PreviewPanel.tsx +0 -422
- package/src/RawEditor.tsx +0 -731
- package/src/RecorderEntry.tsx +0 -159
- package/src/StatusBar.tsx +0 -51
- package/src/TemplateAnnotation.ts +0 -167
- package/src/TemplateContentPreview.tsx +0 -56
- package/src/TemplatePicker.tsx +0 -1314
- package/src/ThemeCustomizerPanel.tsx +0 -304
- package/src/ThemePicker.tsx +0 -433
- package/src/TimelineBlockPreview.tsx +0 -37
- package/src/TimelineTrack.tsx +0 -671
- package/src/Toolbar.tsx +0 -2587
- package/src/Tooltip.tsx +0 -142
- package/src/TransitionPicker.tsx +0 -390
- package/src/VersionHistoryPanel.tsx +0 -359
- package/src/ViewMenuPanel.tsx +0 -189
- package/src/ViewSwitcher.tsx +0 -56
- package/src/WysiwygEditor.tsx +0 -792
- package/src/__tests__/blockProperties.test.ts +0 -92
- package/src/__tests__/blockPropertiesPopoverTheme.test.tsx +0 -33
- package/src/__tests__/blockRange.test.ts +0 -105
- package/src/__tests__/blockTagActivity.test.ts +0 -183
- package/src/__tests__/buildDocumentPreviewMarkdown.test.ts +0 -75
- package/src/__tests__/buildPreviewDocContent.test.ts +0 -48
- package/src/__tests__/buildPreviewDocTransition.test.ts +0 -92
- package/src/__tests__/canvasSurfaceTextEditing.test.tsx +0 -60
- package/src/__tests__/codeContextSectionView.test.tsx +0 -97
- package/src/__tests__/codeContextZoneManager.test.ts +0 -127
- package/src/__tests__/createShapeLayer.test.ts +0 -46
- package/src/__tests__/customLayoutManagerTheme.test.tsx +0 -34
- package/src/__tests__/detectMarkdown.test.ts +0 -73
- package/src/__tests__/diffContextSections.test.ts +0 -39
- package/src/__tests__/documentSettingsDialog.test.tsx +0 -197
- package/src/__tests__/drawingShapeRoundTrip.test.ts +0 -49
- package/src/__tests__/editorScrollHandoff.test.tsx +0 -102
- package/src/__tests__/editorScrollSync.test.ts +0 -65
- package/src/__tests__/editorShellCodeContext.test.tsx +0 -86
- package/src/__tests__/editorShellProps.test.tsx +0 -485
- package/src/__tests__/embeddedMedia.test.ts +0 -48
- package/src/__tests__/emojiPicker.test.tsx +0 -93
- package/src/__tests__/fileKind.test.ts +0 -112
- package/src/__tests__/headingTransition.test.ts +0 -176
- package/src/__tests__/imageEditAffordance.test.tsx +0 -272
- package/src/__tests__/imageEditModalContract.test.tsx +0 -119
- package/src/__tests__/imageEditorShell.test.tsx +0 -94
- package/src/__tests__/imageEditorState.test.ts +0 -171
- package/src/__tests__/inlinePreviewGutter.test.tsx +0 -62
- package/src/__tests__/inlinePreviewGutterAllBlocks.test.tsx +0 -103
- package/src/__tests__/jsonEditor.test.tsx +0 -223
- package/src/__tests__/layersPanel.test.tsx +0 -167
- package/src/__tests__/layoutChildRoundTrip.test.ts +0 -71
- package/src/__tests__/linkDialogDocPicker.test.tsx +0 -137
- package/src/__tests__/majorApiTypes.test.ts +0 -26
- package/src/__tests__/mediaAttachmentFlow.test.ts +0 -110
- package/src/__tests__/mediaBinDrop.test.tsx +0 -90
- package/src/__tests__/mediaReferences.test.ts +0 -82
- package/src/__tests__/narrationSave.test.ts +0 -148
- package/src/__tests__/outlinePanel.test.tsx +0 -169
- package/src/__tests__/outlineSource.test.ts +0 -217
- package/src/__tests__/plainHtmlPreview.test.tsx +0 -125
- package/src/__tests__/presentationMode.test.tsx +0 -290
- package/src/__tests__/previewControls.test.tsx +0 -540
- package/src/__tests__/previewPanelAudioFailure.test.tsx +0 -46
- package/src/__tests__/previewPanelPresentation.test.tsx +0 -126
- package/src/__tests__/previewPanelTransforms.test.tsx +0 -117
- package/src/__tests__/propertiesPanel.test.tsx +0 -69
- package/src/__tests__/rawEditorModelIsolation.test.ts +0 -19
- package/src/__tests__/recorderFormats.test.ts +0 -146
- package/src/__tests__/recorderMediaInsert.test.ts +0 -86
- package/src/__tests__/recorderTheme.test.tsx +0 -42
- package/src/__tests__/recorderTimingJson.test.ts +0 -41
- package/src/__tests__/resolveBlockVisual.test.ts +0 -43
- package/src/__tests__/selectionConversions.test.ts +0 -80
- package/src/__tests__/statusBar.test.tsx +0 -27
- package/src/__tests__/teleprompter.test.tsx +0 -190
- package/src/__tests__/templateAnnotationRoundTrip.test.ts +0 -99
- package/src/__tests__/templateContentPreview.test.ts +0 -101
- package/src/__tests__/templatePickerMetadata.test.ts +0 -32
- package/src/__tests__/templatePickerPortal.test.tsx +0 -62
- package/src/__tests__/timelineSource.test.ts +0 -134
- package/src/__tests__/tiptapBridge.test.ts +0 -566
- package/src/__tests__/tiptapBridgeConformance.test.ts +0 -47
- package/src/__tests__/tiptapCodeBlockRoundTrip.test.ts +0 -109
- package/src/__tests__/tiptapImageRoundTrip.test.ts +0 -73
- package/src/__tests__/toolbarSelectionConversion.test.tsx +0 -164
- package/src/__tests__/tooltip.test.tsx +0 -72
- package/src/__tests__/transformStyleId.test.ts +0 -13
- package/src/__tests__/transitionCatalog.test.ts +0 -64
- package/src/__tests__/useBlockNavigator.test.tsx +0 -67
- package/src/__tests__/useImageEditor.test.tsx +0 -226
- package/src/__tests__/useJsonEditorTokens.test.ts +0 -59
- package/src/__tests__/useMediaRecorder.test.ts +0 -302
- package/src/__tests__/useTimelineClock.test.ts +0 -21
- package/src/__tests__/versionHistory.test.tsx +0 -197
- package/src/__tests__/viewMenuPanel.test.tsx +0 -130
- package/src/__tests__/wysiwygImageUpload.test.ts +0 -69
- package/src/__tests__/wysiwygTemplateBadgeFocus.test.tsx +0 -56
- package/src/asciiDiagram/AsciiDiagramExtension.ts +0 -343
- package/src/asciiDiagram/AsciiDiagramWidget.tsx +0 -254
- package/src/asciiDiagram/RepairableDiagramExtension.ts +0 -200
- package/src/asciiDiagram/__tests__/AsciiDiagramExtension.test.ts +0 -145
- package/src/asciiDiagram/__tests__/RepairableDiagramExtension.test.ts +0 -159
- package/src/asciiDiagram/__tests__/asciiDiagramCommands.test.ts +0 -284
- package/src/asciiDiagram/__tests__/asciiDiagramOps.test.ts +0 -114
- package/src/asciiDiagram/__tests__/asciiPaste.test.ts +0 -43
- package/src/asciiDiagram/asciiDiagramCommands.ts +0 -174
- package/src/asciiDiagram/asciiDiagramData.ts +0 -149
- package/src/asciiDiagram/asciiDiagramOps.ts +0 -238
- package/src/asciiDiagram/asciiPaste.ts +0 -19
- package/src/blockProperties.ts +0 -88
- package/src/blockRange.ts +0 -132
- package/src/blockSlice.ts +0 -75
- package/src/blockTagActivity.ts +0 -233
- package/src/buildDocumentPreviewMarkdown.ts +0 -168
- package/src/buildPreviewDoc.ts +0 -405
- package/src/codeContext/CodeContextSectionView.tsx +0 -124
- package/src/codeContext/CodeContextZoneManager.ts +0 -149
- package/src/codeContext/CodeContextZones.tsx +0 -121
- package/src/codeContext/diffContextSections.ts +0 -38
- package/src/codeContext/types.ts +0 -75
- package/src/customTemplates/AddBin.tsx +0 -126
- package/src/customTemplates/CustomLayoutManager.tsx +0 -234
- package/src/customTemplates/CustomTemplateContext.tsx +0 -188
- package/src/customTemplates/LayerToolbar.tsx +0 -580
- package/src/customTemplates/ShapeGlyph.tsx +0 -47
- package/src/customTemplates/TemplateDesigner.tsx +0 -433
- package/src/customTemplates/__tests__/library.test.ts +0 -96
- package/src/customTemplates/__tests__/normalizePositions.test.ts +0 -109
- package/src/customTemplates/__tests__/shapeDefs.test.ts +0 -49
- package/src/customTemplates/__tests__/useMemoryLayerAdapter.test.ts +0 -108
- package/src/customTemplates/designer.css +0 -732
- package/src/customTemplates/index.ts +0 -31
- package/src/customTemplates/library.ts +0 -110
- package/src/customTemplates/normalizePositions.ts +0 -75
- package/src/customTemplates/shapeDefs.ts +0 -131
- package/src/customTemplates/thumbnail.tsx +0 -63
- package/src/customTemplates/tokenDefs.ts +0 -60
- package/src/customTemplates/useDocCustomTemplates.ts +0 -52
- package/src/customTemplates/useMemoryLayerAdapter.ts +0 -129
- package/src/customThemes/CustomThemeContext.tsx +0 -185
- package/src/customThemes/CustomThemeDialog.tsx +0 -316
- package/src/customThemes/ImportThemeSection.tsx +0 -178
- package/src/customThemes/__tests__/CustomThemeContext.test.tsx +0 -64
- package/src/customThemes/__tests__/CustomThemeDialog.test.tsx +0 -47
- package/src/customThemes/__tests__/customThemeLibrary.test.ts +0 -60
- package/src/customThemes/__tests__/importThemeSection.test.tsx +0 -192
- package/src/customThemes/customThemeLibrary.ts +0 -100
- package/src/customThemes/index.ts +0 -37
- package/src/customThemes/themeControls.tsx +0 -229
- package/src/customThemes/themeDraft.ts +0 -288
- package/src/customThemes/useDocCustomThemes.ts +0 -49
- package/src/detectMarkdown.ts +0 -62
- package/src/diagram/DiagramCanvas.tsx +0 -259
- package/src/diagram/DiagramMaximizedOverlay.tsx +0 -46
- package/src/diagram/diagramCommands.ts +0 -604
- package/src/diagram/diagramConstants.ts +0 -17
- package/src/diagram/types.ts +0 -35
- package/src/editorScrollSync.ts +0 -73
- package/src/embeddedMedia.ts +0 -78
- package/src/emojiData.ts +0 -1317
- package/src/fileKind.ts +0 -158
- package/src/frontmatter.ts +0 -29
- package/src/frontmatterSettings.ts +0 -23
- package/src/headingTransition.ts +0 -291
- package/src/hooks/useFileDrop.ts +0 -266
- package/src/imageEditor/CanvasSurface.tsx +0 -703
- package/src/imageEditor/ImageVersionHistoryDropdown.tsx +0 -396
- package/src/imageEditor/LayersPanel.tsx +0 -218
- package/src/imageEditor/PropertiesPanel.tsx +0 -474
- package/src/imageEditor/Toolbar.tsx +0 -459
- package/src/imageEditor/createShapeLayer.ts +0 -280
- package/src/imageEditor/icons.tsx +0 -68
- package/src/imageEditor/image-editor.css +0 -574
- package/src/imageEditor/layers/EditorImageLayer.tsx +0 -45
- package/src/imageEditor/layers/EditorShapeLayer.tsx +0 -62
- package/src/imageEditor/layers/EditorTextLayer.tsx +0 -45
- package/src/imageEditor/layers/SelectionHandles.tsx +0 -86
- package/src/imageEditor/state.ts +0 -173
- package/src/imageEditor/useImageEditor.ts +0 -385
- package/src/imageEditor/useImageEditorTokens.ts +0 -70
- package/src/index.ts +0 -470
- package/src/jsonEditor/EmbeddedRichTextField.tsx +0 -81
- package/src/jsonEditor/JsonEditor.tsx +0 -81
- package/src/jsonEditor/JsonEditorContext.tsx +0 -81
- package/src/jsonEditor/RenderNode.tsx +0 -87
- package/src/jsonEditor/editors.tsx +0 -745
- package/src/jsonEditor/index.ts +0 -2
- package/src/jsonEditor/json-editor.css +0 -463
- package/src/jsonEditor/useJsonEditorTokens.ts +0 -33
- package/src/mediaDragMime.ts +0 -32
- package/src/mediaEntries.ts +0 -12
- package/src/mediaReferences.ts +0 -299
- package/src/monaco.ts +0 -35
- package/src/monacoWorkers.ts +0 -89
- package/src/outlineSource.ts +0 -171
- package/src/presentation/PresentationMode.tsx +0 -596
- package/src/rawEditorIsolation.ts +0 -18
- package/src/recorder/RecorderButton.tsx +0 -80
- package/src/recorder/RecorderModal.tsx +0 -706
- package/src/recorder/RecorderPanel.tsx +0 -77
- package/src/recorder/formats.ts +0 -159
- package/src/recorder/hooks/useMediaRecorder.ts +0 -436
- package/src/recorder/hooks/useStreamPreview.ts +0 -47
- package/src/recorder/insertMediaBlock.ts +0 -30
- package/src/recorder/sources/cameraStream.ts +0 -32
- package/src/recorder/sources/micStream.ts +0 -25
- package/src/recorder/sources/screenStream.ts +0 -162
- package/src/recorder/timingJson.ts +0 -66
- package/src/resolveBlockVisual.ts +0 -39
- package/src/scene/Scene.tsx +0 -616
- package/src/scene/SceneBlockExtension.ts +0 -205
- package/src/scene/SceneBlockToolbar.tsx +0 -201
- package/src/scene/SceneBlockWidget.tsx +0 -441
- package/src/scene/ScenePropsBar.tsx +0 -85
- package/src/scene/SceneSelection.tsx +0 -111
- package/src/scene/SceneSideToolbar.tsx +0 -89
- package/src/scene/SceneViewport.tsx +0 -106
- package/src/scene/ShapePalette.tsx +0 -196
- package/src/scene/__tests__/DiagramAdapter.test.ts +0 -142
- package/src/scene/__tests__/SceneBlockExtension.test.ts +0 -33
- package/src/scene/__tests__/bezierEdit.test.ts +0 -85
- package/src/scene/__tests__/blockLayers.test.ts +0 -57
- package/src/scene/__tests__/sceneIsolation.test.tsx +0 -119
- package/src/scene/__tests__/shapeLayers.test.ts +0 -106
- package/src/scene/__tests__/useSceneHitTest.test.ts +0 -90
- package/src/scene/__tests__/useScenePanZoom.test.ts +0 -103
- package/src/scene/adapters/DiagramAdapter.ts +0 -79
- package/src/scene/adapters/DrawingAdapter.ts +0 -420
- package/src/scene/adapters/LayoutAdapter.ts +0 -313
- package/src/scene/adapters/blockLayers.ts +0 -159
- package/src/scene/commands/SceneCommand.ts +0 -84
- package/src/scene/commands/drawingCommands.ts +0 -318
- package/src/scene/commands/layoutCommands.ts +0 -301
- package/src/scene/hooks/useSceneHitTest.ts +0 -105
- package/src/scene/hooks/useScenePanZoom.ts +0 -147
- package/src/scene/hooks/useSceneSelection.ts +0 -62
- package/src/scene/index.ts +0 -90
- package/src/scene/layers/DiagramEdges.tsx +0 -142
- package/src/scene/layers/edgeGeometry.ts +0 -104
- package/src/scene/layers/nodeCard.tsx +0 -164
- package/src/scene/layers/renderLayer.tsx +0 -70
- package/src/scene/layers/shapeLayers.ts +0 -201
- package/src/scene/paths/bezierEdit.ts +0 -208
- package/src/scene/scene.css +0 -792
- package/src/scene/text/SceneTextOverlay.tsx +0 -161
- package/src/scene/text/sceneTextChannel.ts +0 -46
- package/src/scene/text/sceneTextConfig.ts +0 -31
- package/src/scene/text/sceneTiptap.ts +0 -36
- package/src/scene/text/useSceneTextEditing.ts +0 -39
- package/src/scene/tools/ConnectTool.ts +0 -209
- package/src/scene/tools/DrawingConnectTool.ts +0 -231
- package/src/scene/tools/PathTool.ts +0 -158
- package/src/scene/tools/PlaceTool.ts +0 -47
- package/src/scene/tools/SceneTool.ts +0 -85
- package/src/scene/tools/SelectTool.ts +0 -300
- package/src/scene/tools/ShapeTool.ts +0 -143
- package/src/scene/tools/TextTool.ts +0 -72
- package/src/scene/tools/TokenTool.ts +0 -95
- package/src/scene/tools/createDrawShapeTool.ts +0 -82
- package/src/selectionConversions.ts +0 -155
- package/src/styles/ascii-diagram.css +0 -79
- package/src/styles/ascii-timeline.css +0 -596
- package/src/styles/code-context.css +0 -155
- package/src/styles/diagram.css +0 -183
- package/src/styles/editor.css +0 -6811
- package/src/styles/folder-view.css +0 -210
- package/src/styles/image-edit-affordance.css +0 -201
- package/src/styles/index.css +0 -18
- package/src/styles/tree-view.css +0 -189
- package/src/teleprompter/TeleprompterControls.tsx +0 -218
- package/src/teleprompter/TeleprompterSelfView.tsx +0 -22
- package/src/teleprompter/TeleprompterSurface.tsx +0 -267
- package/src/teleprompter/TeleprompterView.tsx +0 -338
- package/src/teleprompter/canvasRenderer.ts +0 -161
- package/src/teleprompter/floatingWindow.ts +0 -352
- package/src/teleprompter/index.ts +0 -61
- package/src/teleprompter/pcmWorklet.ts +0 -62
- package/src/teleprompter/recording/insertPreamble.ts +0 -80
- package/src/teleprompter/recording/narrationSave.ts +0 -134
- package/src/teleprompter/recording/useNarrationRecorder.ts +0 -367
- package/src/teleprompter/scrollModel.ts +0 -85
- package/src/teleprompter/teleprompterTheme.ts +0 -303
- package/src/teleprompter/types.ts +0 -38
- package/src/teleprompter/useFloatingWindow.ts +0 -74
- package/src/teleprompter/useMicAnalysis.ts +0 -211
- package/src/teleprompter/useTeleprompter.ts +0 -421
- package/src/templateContentPreviewResolver.ts +0 -360
- package/src/timeline/TimelineEditorWidget.tsx +0 -861
- package/src/timeline/TimelineViewExtension.ts +0 -252
- package/src/timeline/__tests__/TimelineEditorWidget.test.tsx +0 -414
- package/src/timeline/__tests__/TimelineViewExtension.test.ts +0 -163
- package/src/timeline/__tests__/timelineCommands.test.ts +0 -359
- package/src/timeline/__tests__/timelineOps.test.ts +0 -277
- package/src/timeline/__tests__/timelinePaste.test.ts +0 -34
- package/src/timeline/timelineCommands.ts +0 -421
- package/src/timeline/timelineData.ts +0 -54
- package/src/timeline/timelineOps.ts +0 -381
- package/src/timeline/timelinePaste.ts +0 -8
- package/src/timelineSource.ts +0 -244
- package/src/tiptap/TiptapAudio.tsx +0 -86
- package/src/tiptap/TiptapVideo.tsx +0 -119
- package/src/tiptap/useResolvedMediaSrc.ts +0 -47
- package/src/tiptapBridge.ts +0 -986
- package/src/tooltipPlacement.ts +0 -13
- package/src/transformStyleId.ts +0 -17
- package/src/transitionCatalog.ts +0 -159
- package/src/treeview/TreeOutlineWidget.tsx +0 -390
- package/src/treeview/TreeViewExtension.ts +0 -250
- package/src/treeview/__tests__/TreeOutlineWidget.test.tsx +0 -156
- package/src/treeview/__tests__/TreeViewExtension.test.ts +0 -122
- package/src/treeview/__tests__/treeOps.test.ts +0 -177
- package/src/treeview/__tests__/treePaste.test.ts +0 -40
- package/src/treeview/__tests__/treeViewCommands.test.ts +0 -179
- package/src/treeview/treeOps.ts +0 -231
- package/src/treeview/treePaste.ts +0 -13
- package/src/treeview/treeViewCommands.ts +0 -99
- package/src/treeview/treeViewData.ts +0 -41
- package/src/types/monaco-shims.d.ts +0 -10
- package/src/useBlockNavigator.ts +0 -153
- package/src/useHeadingLayout.ts +0 -294
- package/src/useMonacoLoader.ts +0 -82
- package/src/useTimelineClock.ts +0 -76
- package/src/utils/collectInlineFontAwesomeCss.ts +0 -69
- package/src/utils/dropUtils.ts +0 -136
- package/src/utils/normalizeMalformedAssetUrl.ts +0 -22
- package/src/wysiwygImageUpload.ts +0 -113
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useSceneHitTest — point→layer lookup.
|
|
3
|
-
*
|
|
4
|
-
* Each layer's bounding rectangle is derived from its `position` field;
|
|
5
|
-
* the topmost layer (last in the array) under the point wins. Path
|
|
6
|
-
* layers also get a thicker stroke-aware hit area so users can grab a
|
|
7
|
-
* 2-pixel edge without pixel-perfect aim.
|
|
8
|
-
*
|
|
9
|
-
* Pure function for now (no state) — wrapped in a hook so consumers can
|
|
10
|
-
* cache the lookup table later without changing the call site.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { useCallback } from 'react';
|
|
14
|
-
import type { Layer } from '@bendyline/squisq/schemas';
|
|
15
|
-
|
|
16
|
-
export interface HitTestable {
|
|
17
|
-
id: string;
|
|
18
|
-
layer: Layer;
|
|
19
|
-
/** Bounding rect in viewport units. */
|
|
20
|
-
bounds: { x: number; y: number; width: number; height: number };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface UseSceneHitTestResult {
|
|
24
|
-
/** Topmost layer id at the given viewport-unit point, or null. */
|
|
25
|
-
hit: (point: { x: number; y: number }, items: HitTestable[]) => string | null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function useSceneHitTest(): UseSceneHitTestResult {
|
|
29
|
-
const hit = useCallback(
|
|
30
|
-
(point: { x: number; y: number }, items: HitTestable[]): string | null => {
|
|
31
|
-
// Walk from last (topmost) to first so the visually-on-top layer wins.
|
|
32
|
-
for (let i = items.length - 1; i >= 0; i--) {
|
|
33
|
-
const it = items[i];
|
|
34
|
-
if (pointInRect(point, it.bounds)) return it.id;
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
},
|
|
38
|
-
[],
|
|
39
|
-
);
|
|
40
|
-
return { hit };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Compute a layer's bounding rect in viewport units. Resolves `%` strings
|
|
45
|
-
* against the supplied viewport size and handles the `anchor` field on
|
|
46
|
-
* the layer's position. Returns null when the layer's geometry can't be
|
|
47
|
-
* resolved (e.g. a TextLayer with no explicit width — for those callers
|
|
48
|
-
* should measure DOM and fall back to a click-tolerance box).
|
|
49
|
-
*/
|
|
50
|
-
export function layerBounds(
|
|
51
|
-
layer: Layer,
|
|
52
|
-
viewport: { width: number; height: number },
|
|
53
|
-
defaults: { width?: number; height?: number } = {},
|
|
54
|
-
): { x: number; y: number; width: number; height: number } | null {
|
|
55
|
-
const pos = layer.position;
|
|
56
|
-
if (!pos) return null;
|
|
57
|
-
const w = resolveLen(pos.width, viewport.width, defaults.width);
|
|
58
|
-
const h = resolveLen(pos.height, viewport.height, defaults.height);
|
|
59
|
-
if (w == null || h == null) return null;
|
|
60
|
-
const cx = resolveLen(pos.x, viewport.width, 0) ?? 0;
|
|
61
|
-
const cy = resolveLen(pos.y, viewport.height, 0) ?? 0;
|
|
62
|
-
const anchor = pos.anchor ?? 'top-left';
|
|
63
|
-
const { ax, ay } = anchorOffsets(anchor, w, h);
|
|
64
|
-
return { x: cx - ax, y: cy - ay, width: w, height: h };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function pointInRect(
|
|
68
|
-
p: { x: number; y: number },
|
|
69
|
-
r: { x: number; y: number; width: number; height: number },
|
|
70
|
-
): boolean {
|
|
71
|
-
return p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function resolveLen(
|
|
75
|
-
v: number | string | undefined,
|
|
76
|
-
base: number,
|
|
77
|
-
fallback?: number,
|
|
78
|
-
): number | undefined {
|
|
79
|
-
if (typeof v === 'number') return v;
|
|
80
|
-
if (typeof v === 'string') {
|
|
81
|
-
if (v.endsWith('%')) {
|
|
82
|
-
const pct = parseFloat(v);
|
|
83
|
-
if (Number.isFinite(pct)) return (pct / 100) * base;
|
|
84
|
-
}
|
|
85
|
-
const n = parseFloat(v);
|
|
86
|
-
if (Number.isFinite(n)) return n;
|
|
87
|
-
}
|
|
88
|
-
return fallback;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function anchorOffsets(anchor: string, w: number, h: number): { ax: number; ay: number } {
|
|
92
|
-
switch (anchor) {
|
|
93
|
-
case 'center':
|
|
94
|
-
return { ax: w / 2, ay: h / 2 };
|
|
95
|
-
case 'top-right':
|
|
96
|
-
return { ax: w, ay: 0 };
|
|
97
|
-
case 'bottom-left':
|
|
98
|
-
return { ax: 0, ay: h };
|
|
99
|
-
case 'bottom-right':
|
|
100
|
-
return { ax: w, ay: h };
|
|
101
|
-
case 'top-left':
|
|
102
|
-
default:
|
|
103
|
-
return { ax: 0, ay: 0 };
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useScenePanZoom — transient viewport pan/zoom state for the Scene.
|
|
3
|
-
*
|
|
4
|
-
* State is a simple affine transform `{ tx, ty, scale }` that maps
|
|
5
|
-
* viewport units → screen pixels. The Scene's root `<svg>` applies the
|
|
6
|
-
* transform via a single `<g transform="translate(tx ty) scale(scale)">`
|
|
7
|
-
* so every layer renders at its natural viewport coordinates and the
|
|
8
|
-
* group transform handles all pan/zoom.
|
|
9
|
-
*
|
|
10
|
-
* The hook only owns state and a small command surface — DOM event
|
|
11
|
-
* binding is done by the Scene component so tests can drive the hook
|
|
12
|
-
* with synthetic transforms without a DOM.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { useCallback, useRef, useState } from 'react';
|
|
16
|
-
|
|
17
|
-
export interface SceneTransform {
|
|
18
|
-
/** Translation in screen pixels. */
|
|
19
|
-
tx: number;
|
|
20
|
-
ty: number;
|
|
21
|
-
/** Uniform scale factor. 1 = viewport units render 1:1 with screen pixels. */
|
|
22
|
-
scale: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const IDENTITY_TRANSFORM: SceneTransform = Object.freeze({ tx: 0, ty: 0, scale: 1 });
|
|
26
|
-
|
|
27
|
-
/** Clamp scale to a sensible range so a single accidental wheel doesn't escape. */
|
|
28
|
-
const MIN_SCALE = 0.1;
|
|
29
|
-
const MAX_SCALE = 8;
|
|
30
|
-
|
|
31
|
-
export interface UseScenePanZoomResult {
|
|
32
|
-
transform: SceneTransform;
|
|
33
|
-
/** Replace the transform wholesale. */
|
|
34
|
-
setTransform: (t: SceneTransform) => void;
|
|
35
|
-
/** Pan by a screen-pixel delta. */
|
|
36
|
-
panBy: (dx: number, dy: number) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Zoom toward a point in screen-pixel coordinates (relative to the
|
|
39
|
-
* scene's container origin). Scale multiplies by `factor`; positive
|
|
40
|
-
* factor > 1 zooms in, < 1 zooms out. The viewport point under
|
|
41
|
-
* `(focusX, focusY)` stays put after the zoom.
|
|
42
|
-
*/
|
|
43
|
-
zoomAt: (factor: number, focusX: number, focusY: number) => void;
|
|
44
|
-
/** Reset to identity. */
|
|
45
|
-
reset: () => void;
|
|
46
|
-
/**
|
|
47
|
-
* Fit a viewport-unit bounding box into a container of `containerSize`
|
|
48
|
-
* screen pixels, with optional padding (also in screen pixels). When
|
|
49
|
-
* the box is empty, no-ops.
|
|
50
|
-
*/
|
|
51
|
-
fitBox: (
|
|
52
|
-
box: { x: number; y: number; width: number; height: number },
|
|
53
|
-
containerSize: { width: number; height: number },
|
|
54
|
-
padding?: number,
|
|
55
|
-
) => void;
|
|
56
|
-
/** Convert a screen-pixel point (container-relative) → viewport units. */
|
|
57
|
-
screenToViewport: (sx: number, sy: number) => { x: number; y: number };
|
|
58
|
-
/** Convert a viewport-unit point → screen pixels (container-relative). */
|
|
59
|
-
viewportToScreen: (vx: number, vy: number) => { x: number; y: number };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function useScenePanZoom(
|
|
63
|
-
initial: SceneTransform = IDENTITY_TRANSFORM,
|
|
64
|
-
): UseScenePanZoomResult {
|
|
65
|
-
const [transform, setTransformState] = useState<SceneTransform>(initial);
|
|
66
|
-
// Keep a ref so commands batching multiple updates in the same tick see
|
|
67
|
-
// the latest state without waiting for a render cycle.
|
|
68
|
-
const ref = useRef(transform);
|
|
69
|
-
ref.current = transform;
|
|
70
|
-
|
|
71
|
-
const setTransform = useCallback((t: SceneTransform) => {
|
|
72
|
-
ref.current = t;
|
|
73
|
-
setTransformState(t);
|
|
74
|
-
}, []);
|
|
75
|
-
|
|
76
|
-
const panBy = useCallback(
|
|
77
|
-
(dx: number, dy: number) => {
|
|
78
|
-
const t = ref.current;
|
|
79
|
-
setTransform({ tx: t.tx + dx, ty: t.ty + dy, scale: t.scale });
|
|
80
|
-
},
|
|
81
|
-
[setTransform],
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
const zoomAt = useCallback(
|
|
85
|
-
(factor: number, focusX: number, focusY: number) => {
|
|
86
|
-
const t = ref.current;
|
|
87
|
-
const nextScale = clamp(t.scale * factor, MIN_SCALE, MAX_SCALE);
|
|
88
|
-
const effectiveFactor = nextScale / t.scale;
|
|
89
|
-
// Keep the viewport point under (focusX, focusY) stationary:
|
|
90
|
-
// focus_v = (focus_s - tx) / scale
|
|
91
|
-
// tx' = focus_s - focus_v * scale'
|
|
92
|
-
// = focus_s - (focus_s - tx) * (scale' / scale)
|
|
93
|
-
const tx = focusX - (focusX - t.tx) * effectiveFactor;
|
|
94
|
-
const ty = focusY - (focusY - t.ty) * effectiveFactor;
|
|
95
|
-
setTransform({ tx, ty, scale: nextScale });
|
|
96
|
-
},
|
|
97
|
-
[setTransform],
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const reset = useCallback(() => setTransform(IDENTITY_TRANSFORM), [setTransform]);
|
|
101
|
-
|
|
102
|
-
const fitBox = useCallback(
|
|
103
|
-
(
|
|
104
|
-
box: { x: number; y: number; width: number; height: number },
|
|
105
|
-
containerSize: { width: number; height: number },
|
|
106
|
-
padding = 24,
|
|
107
|
-
) => {
|
|
108
|
-
if (box.width <= 0 || box.height <= 0) return;
|
|
109
|
-
if (containerSize.width <= 0 || containerSize.height <= 0) return;
|
|
110
|
-
const availW = Math.max(1, containerSize.width - padding * 2);
|
|
111
|
-
const availH = Math.max(1, containerSize.height - padding * 2);
|
|
112
|
-
const scale = clamp(Math.min(availW / box.width, availH / box.height), MIN_SCALE, MAX_SCALE);
|
|
113
|
-
// Center the box in the container.
|
|
114
|
-
const scaledW = box.width * scale;
|
|
115
|
-
const scaledH = box.height * scale;
|
|
116
|
-
const tx = (containerSize.width - scaledW) / 2 - box.x * scale;
|
|
117
|
-
const ty = (containerSize.height - scaledH) / 2 - box.y * scale;
|
|
118
|
-
setTransform({ tx, ty, scale });
|
|
119
|
-
},
|
|
120
|
-
[setTransform],
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
const screenToViewport = useCallback((sx: number, sy: number) => {
|
|
124
|
-
const t = ref.current;
|
|
125
|
-
return { x: (sx - t.tx) / t.scale, y: (sy - t.ty) / t.scale };
|
|
126
|
-
}, []);
|
|
127
|
-
|
|
128
|
-
const viewportToScreen = useCallback((vx: number, vy: number) => {
|
|
129
|
-
const t = ref.current;
|
|
130
|
-
return { x: vx * t.scale + t.tx, y: vy * t.scale + t.ty };
|
|
131
|
-
}, []);
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
transform,
|
|
135
|
-
setTransform,
|
|
136
|
-
panBy,
|
|
137
|
-
zoomAt,
|
|
138
|
-
reset,
|
|
139
|
-
fitBox,
|
|
140
|
-
screenToViewport,
|
|
141
|
-
viewportToScreen,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function clamp(n: number, lo: number, hi: number): number {
|
|
146
|
-
return Math.min(hi, Math.max(lo, n));
|
|
147
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useSceneSelection — selected layer ids + selection-modification API.
|
|
3
|
-
*
|
|
4
|
-
* v1 supports single and shift-additive selection. Marquee/box selection
|
|
5
|
-
* is driven by SelectTool — it calls `setSelection` with the ids that
|
|
6
|
-
* intersect the marquee rect.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { useCallback, useState } from 'react';
|
|
10
|
-
|
|
11
|
-
export interface UseSceneSelectionResult {
|
|
12
|
-
/** Stable set of selected ids — referentially stable between renders unless changed. */
|
|
13
|
-
selection: ReadonlySet<string>;
|
|
14
|
-
/** Replace the selection. */
|
|
15
|
-
setSelection: (ids: Iterable<string>) => void;
|
|
16
|
-
/** Add `id` to the selection (or replace it when `additive=false`). */
|
|
17
|
-
select: (id: string, additive?: boolean) => void;
|
|
18
|
-
/** Toggle `id` in/out of the selection. */
|
|
19
|
-
toggle: (id: string) => void;
|
|
20
|
-
/** Clear all selection. */
|
|
21
|
-
clear: () => void;
|
|
22
|
-
/** Convenience: is this id currently selected? */
|
|
23
|
-
isSelected: (id: string) => boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function useSceneSelection(initial: Iterable<string> = []): UseSceneSelectionResult {
|
|
27
|
-
const [selection, setSelectionState] = useState<ReadonlySet<string>>(() => new Set(initial));
|
|
28
|
-
|
|
29
|
-
const setSelection = useCallback((ids: Iterable<string>) => {
|
|
30
|
-
setSelectionState(new Set(ids));
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
const select = useCallback((id: string, additive = false) => {
|
|
34
|
-
setSelectionState((prev) => {
|
|
35
|
-
if (additive) {
|
|
36
|
-
if (prev.has(id)) return prev;
|
|
37
|
-
const next = new Set(prev);
|
|
38
|
-
next.add(id);
|
|
39
|
-
return next;
|
|
40
|
-
}
|
|
41
|
-
if (prev.size === 1 && prev.has(id)) return prev;
|
|
42
|
-
return new Set([id]);
|
|
43
|
-
});
|
|
44
|
-
}, []);
|
|
45
|
-
|
|
46
|
-
const toggle = useCallback((id: string) => {
|
|
47
|
-
setSelectionState((prev) => {
|
|
48
|
-
const next = new Set(prev);
|
|
49
|
-
if (next.has(id)) next.delete(id);
|
|
50
|
-
else next.add(id);
|
|
51
|
-
return next;
|
|
52
|
-
});
|
|
53
|
-
}, []);
|
|
54
|
-
|
|
55
|
-
const clear = useCallback(() => {
|
|
56
|
-
setSelectionState((prev) => (prev.size === 0 ? prev : new Set()));
|
|
57
|
-
}, []);
|
|
58
|
-
|
|
59
|
-
const isSelected = useCallback((id: string) => selection.has(id), [selection]);
|
|
60
|
-
|
|
61
|
-
return { selection, setSelection, select, toggle, clear, isSelected };
|
|
62
|
-
}
|
package/src/scene/index.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Squisq Scene — public exports for the 2D editing engine.
|
|
3
|
-
*
|
|
4
|
-
* The Scene is a small, owned SVG-based framework for viewing and
|
|
5
|
-
* editing the same `Layer` schema Squisq already renders. Three
|
|
6
|
-
* consumers exist today:
|
|
7
|
-
*
|
|
8
|
-
* - DiagramAdapter (node + edge editing on top of markdown headings)
|
|
9
|
-
* - LayoutAdapter (positioning a block's layers)
|
|
10
|
-
* - DrawingAdapter (free-form shapes, paths, text)
|
|
11
|
-
*
|
|
12
|
-
* Most callers only need `<Scene>` plus the tool(s) and adapter for
|
|
13
|
-
* their use case. The hooks and selection components are exported for
|
|
14
|
-
* advanced consumers that want to build their own surface.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export { Scene } from './Scene';
|
|
18
|
-
export type { SceneProps } from './Scene';
|
|
19
|
-
export { SceneViewport } from './SceneViewport';
|
|
20
|
-
export { SceneSelection } from './SceneSelection';
|
|
21
|
-
export { SceneBlockExtension, type SceneBlockExtensionOptions } from './SceneBlockExtension';
|
|
22
|
-
export { SceneBlockWidget, type SceneBlockMode } from './SceneBlockWidget';
|
|
23
|
-
|
|
24
|
-
export type { SceneCommand, SceneEdge } from './commands/SceneCommand';
|
|
25
|
-
export type { SceneTool, SceneToolContext } from './tools/SceneTool';
|
|
26
|
-
|
|
27
|
-
export { SelectTool, getActiveMoveOffset } from './tools/SelectTool';
|
|
28
|
-
export { ConnectTool } from './tools/ConnectTool';
|
|
29
|
-
export { createShapeTool } from './tools/ShapeTool';
|
|
30
|
-
export { createPlaceTool, type PlaceToolOptions } from './tools/PlaceTool';
|
|
31
|
-
export { createPathTool } from './tools/PathTool';
|
|
32
|
-
export { createTextTool } from './tools/TextTool';
|
|
33
|
-
export {
|
|
34
|
-
createTokenTool,
|
|
35
|
-
buildTokenLayer,
|
|
36
|
-
type TokenKind,
|
|
37
|
-
type TokenToolOptions,
|
|
38
|
-
} from './tools/TokenTool';
|
|
39
|
-
export {
|
|
40
|
-
parsePath,
|
|
41
|
-
serializePath,
|
|
42
|
-
moveAnchor,
|
|
43
|
-
moveHandle,
|
|
44
|
-
type ParsedPath,
|
|
45
|
-
type PathPoint,
|
|
46
|
-
} from './paths/bezierEdit';
|
|
47
|
-
|
|
48
|
-
export { RenderLayer } from './layers/renderLayer';
|
|
49
|
-
export {
|
|
50
|
-
nodesToCardLayers,
|
|
51
|
-
nodeCardLayers,
|
|
52
|
-
nodeIdFromCardLayerId,
|
|
53
|
-
cardLayerIdForLabel,
|
|
54
|
-
labelLayerIdForCard,
|
|
55
|
-
diagramLayerFollows,
|
|
56
|
-
NODE_WIDTH,
|
|
57
|
-
NODE_HEIGHT,
|
|
58
|
-
type DiagramNodeDescriptor,
|
|
59
|
-
} from './layers/nodeCard';
|
|
60
|
-
export { DiagramEdges } from './layers/DiagramEdges';
|
|
61
|
-
|
|
62
|
-
export { buildDiagramScene, nodeCenter, type DiagramSceneData } from './adapters/DiagramAdapter';
|
|
63
|
-
|
|
64
|
-
export {
|
|
65
|
-
useLayoutAdapter,
|
|
66
|
-
type LayoutAdapterResult,
|
|
67
|
-
type LayoutAdapterOptions,
|
|
68
|
-
} from './adapters/LayoutAdapter';
|
|
69
|
-
export { useDrawingAdapter, type DrawingAdapterOptions } from './adapters/DrawingAdapter';
|
|
70
|
-
export {
|
|
71
|
-
encodeLayers,
|
|
72
|
-
decodeLayers,
|
|
73
|
-
updateLayer,
|
|
74
|
-
readLayersFromHeading,
|
|
75
|
-
writeLayersToHeading,
|
|
76
|
-
} from './adapters/blockLayers';
|
|
77
|
-
|
|
78
|
-
export {
|
|
79
|
-
useScenePanZoom,
|
|
80
|
-
IDENTITY_TRANSFORM,
|
|
81
|
-
type SceneTransform,
|
|
82
|
-
type UseScenePanZoomResult,
|
|
83
|
-
} from './hooks/useScenePanZoom';
|
|
84
|
-
export { useSceneSelection, type UseSceneSelectionResult } from './hooks/useSceneSelection';
|
|
85
|
-
export {
|
|
86
|
-
useSceneHitTest,
|
|
87
|
-
layerBounds,
|
|
88
|
-
type HitTestable,
|
|
89
|
-
type UseSceneHitTestResult,
|
|
90
|
-
} from './hooks/useSceneHitTest';
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DiagramEdges — render the edge layer for a diagram or drawing scene.
|
|
3
|
-
*
|
|
4
|
-
* Edges are derived from `connectsTo` / `from`–`to` attributes and are not
|
|
5
|
-
* stored as Layer objects (the SSR templates synthesize them at render time
|
|
6
|
-
* too). Drawn behind the shape cards so the cards clip the edge endpoints.
|
|
7
|
-
*
|
|
8
|
-
* Routing (`variant` default, per-edge `routing` override), end markers
|
|
9
|
-
* (`startMarker`/`endMarker`), and dash come from the shared core geometry
|
|
10
|
-
* (`connectorPath` / `markerPath`) so the editor and the SSR `PathLayer`
|
|
11
|
-
* renderer draw identical connectors. When `selectedId` is set, that edge is
|
|
12
|
-
* highlighted and given endpoint-handle markers (the active tool drives the
|
|
13
|
-
* drag).
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { useId } from 'react';
|
|
17
|
-
import type { MarkerStyle } from '@bendyline/squisq/schemas';
|
|
18
|
-
import { connectorPath, markerPath } from '@bendyline/squisq/doc';
|
|
19
|
-
import type { SceneEdge } from '../commands/SceneCommand';
|
|
20
|
-
import { boxesOf, edgeEndpoints } from './edgeGeometry';
|
|
21
|
-
import type { EdgeNodeBox } from './edgeGeometry';
|
|
22
|
-
|
|
23
|
-
interface DiagramEdgesProps {
|
|
24
|
-
nodes: readonly EdgeNodeBox[];
|
|
25
|
-
edges: readonly SceneEdge[];
|
|
26
|
-
/** Default routing when an edge sets none. Default 'curved' (diagrams). */
|
|
27
|
-
variant?: 'curved' | 'straight';
|
|
28
|
-
/** Id of the currently-selected edge (drawn highlighted, with handles). */
|
|
29
|
-
selectedId?: string | null;
|
|
30
|
-
/** Click handler for select-to-edit / delete on an edge. */
|
|
31
|
-
onEdgeClick?: (edge: SceneEdge) => void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Marker styles that carry a glyph (everything except 'none'). */
|
|
35
|
-
const MARKER_STYLES: MarkerStyle[] = ['arrow', 'open', 'diamond', 'circle', 'square'];
|
|
36
|
-
|
|
37
|
-
function markerId(prefix: string, style: MarkerStyle, dir: 'start' | 'end'): string {
|
|
38
|
-
return `${prefix}-squisq-edge-${style}-${dir}`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function DiagramEdges({
|
|
42
|
-
nodes,
|
|
43
|
-
edges,
|
|
44
|
-
variant = 'curved',
|
|
45
|
-
selectedId,
|
|
46
|
-
onEdgeClick,
|
|
47
|
-
}: DiagramEdgesProps) {
|
|
48
|
-
const boxById = boxesOf(nodes);
|
|
49
|
-
const markerPrefix = useId().replace(/:/g, '');
|
|
50
|
-
const defaultRouting = variant === 'straight' ? 'straight' : 'curved';
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<g className="squisq-scene-edges">
|
|
54
|
-
<defs>
|
|
55
|
-
{(['start', 'end'] as const).flatMap((dir) =>
|
|
56
|
-
MARKER_STYLES.map((style) => {
|
|
57
|
-
const mp = markerPath(style, dir);
|
|
58
|
-
if (!mp) return null;
|
|
59
|
-
return (
|
|
60
|
-
<marker
|
|
61
|
-
key={markerId(markerPrefix, style, dir)}
|
|
62
|
-
id={markerId(markerPrefix, style, dir)}
|
|
63
|
-
viewBox="0 0 10 10"
|
|
64
|
-
refX={dir === 'end' ? 9 : 1}
|
|
65
|
-
refY={5}
|
|
66
|
-
markerWidth={8}
|
|
67
|
-
markerHeight={8}
|
|
68
|
-
orient="auto-start-reverse"
|
|
69
|
-
markerUnits="userSpaceOnUse"
|
|
70
|
-
>
|
|
71
|
-
<path
|
|
72
|
-
d={mp.d}
|
|
73
|
-
className={
|
|
74
|
-
mp.filled ? 'squisq-scene-edge-arrow' : 'squisq-scene-edge-marker-open'
|
|
75
|
-
}
|
|
76
|
-
/>
|
|
77
|
-
</marker>
|
|
78
|
-
);
|
|
79
|
-
}),
|
|
80
|
-
)}
|
|
81
|
-
</defs>
|
|
82
|
-
{edges.map((edge) => {
|
|
83
|
-
const a = boxById.get(edge.source);
|
|
84
|
-
const b = boxById.get(edge.target);
|
|
85
|
-
if (!a || !b) return null;
|
|
86
|
-
const snapped = edgeEndpoints(
|
|
87
|
-
nodes,
|
|
88
|
-
edge.source,
|
|
89
|
-
edge.target,
|
|
90
|
-
edge.sourceAnchor,
|
|
91
|
-
edge.targetAnchor,
|
|
92
|
-
);
|
|
93
|
-
if (!snapped) return null;
|
|
94
|
-
const { start, end } = snapped;
|
|
95
|
-
const d = connectorPath(edge.routing ?? defaultRouting, start, end);
|
|
96
|
-
const startMarker = edge.startMarker ?? 'none';
|
|
97
|
-
const endMarker = edge.endMarker ?? 'arrow';
|
|
98
|
-
const selected = selectedId === edge.id;
|
|
99
|
-
return (
|
|
100
|
-
<g
|
|
101
|
-
key={edge.id}
|
|
102
|
-
className={selected ? 'squisq-scene-edge selected' : 'squisq-scene-edge'}
|
|
103
|
-
onClick={onEdgeClick ? () => onEdgeClick(edge) : undefined}
|
|
104
|
-
>
|
|
105
|
-
<path
|
|
106
|
-
d={d}
|
|
107
|
-
className="squisq-scene-edge-path"
|
|
108
|
-
strokeDasharray={edge.dasharray}
|
|
109
|
-
markerStart={
|
|
110
|
-
startMarker !== 'none'
|
|
111
|
-
? `url(#${markerId(markerPrefix, startMarker, 'start')})`
|
|
112
|
-
: undefined
|
|
113
|
-
}
|
|
114
|
-
markerEnd={
|
|
115
|
-
endMarker !== 'none'
|
|
116
|
-
? `url(#${markerId(markerPrefix, endMarker, 'end')})`
|
|
117
|
-
: undefined
|
|
118
|
-
}
|
|
119
|
-
/>
|
|
120
|
-
{edge.label ? (
|
|
121
|
-
<text
|
|
122
|
-
x={(a.cx + b.cx) / 2}
|
|
123
|
-
y={(a.cy + b.cy) / 2}
|
|
124
|
-
className="squisq-scene-edge-label"
|
|
125
|
-
textAnchor="middle"
|
|
126
|
-
dominantBaseline="middle"
|
|
127
|
-
>
|
|
128
|
-
{edge.label}
|
|
129
|
-
</text>
|
|
130
|
-
) : null}
|
|
131
|
-
{selected ? (
|
|
132
|
-
<>
|
|
133
|
-
<circle cx={start.x} cy={start.y} r={6} className="squisq-scene-edge-handle" />
|
|
134
|
-
<circle cx={end.x} cy={end.y} r={6} className="squisq-scene-edge-handle" />
|
|
135
|
-
</>
|
|
136
|
-
) : null}
|
|
137
|
-
</g>
|
|
138
|
-
);
|
|
139
|
-
})}
|
|
140
|
-
</g>
|
|
141
|
-
);
|
|
142
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* edgeGeometry — pure geometry for scene connector edges (shared by the
|
|
3
|
-
* `DiagramEdges` renderer and the drawing adapter's endpoint hit-testing).
|
|
4
|
-
*
|
|
5
|
-
* Endpoints are clipped to the source/target bounding boxes so an arrowhead
|
|
6
|
-
* sits on a card's edge rather than inside it — matching `diagramBlock.ts` /
|
|
7
|
-
* `drawingBlock.ts` so the editor and the SSR preview agree.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { NODE_WIDTH, NODE_HEIGHT } from './nodeCard';
|
|
11
|
-
import {
|
|
12
|
-
anchorPoint,
|
|
13
|
-
nearestSnapPoint as nearestCoreSnapPoint,
|
|
14
|
-
snapEndpoints as coreSnapEndpoints,
|
|
15
|
-
type ConnectorAnchor,
|
|
16
|
-
type ConnectorSnapPoint,
|
|
17
|
-
} from '@bendyline/squisq/doc';
|
|
18
|
-
|
|
19
|
-
/** Minimal box an edge needs from a node/shape (id + bounds). */
|
|
20
|
-
export interface EdgeNodeBox {
|
|
21
|
-
id: string;
|
|
22
|
-
x: number;
|
|
23
|
-
y: number;
|
|
24
|
-
width?: number;
|
|
25
|
-
height?: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Center + half-extents of a node/shape box. */
|
|
29
|
-
export interface NodeBox {
|
|
30
|
-
cx: number;
|
|
31
|
-
cy: number;
|
|
32
|
-
rx: number;
|
|
33
|
-
ry: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function boxesOf(nodes: readonly EdgeNodeBox[]): Map<string, NodeBox> {
|
|
37
|
-
const map = new Map<string, NodeBox>();
|
|
38
|
-
for (const n of nodes) {
|
|
39
|
-
const w = n.width ?? NODE_WIDTH;
|
|
40
|
-
const h = n.height ?? NODE_HEIGHT;
|
|
41
|
-
map.set(n.id, { cx: n.x + w / 2, cy: n.y + h / 2, rx: w / 2, ry: h / 2 });
|
|
42
|
-
}
|
|
43
|
-
return map;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Intersection of the center-to-center line with `from`'s bounding box. */
|
|
47
|
-
export function edgePoint(from: NodeBox, to: NodeBox): { x: number; y: number } {
|
|
48
|
-
const dx = to.cx - from.cx;
|
|
49
|
-
const dy = to.cy - from.cy;
|
|
50
|
-
if (dx === 0 && dy === 0) return { x: from.cx, y: from.cy };
|
|
51
|
-
const adx = Math.abs(dx);
|
|
52
|
-
const ady = Math.abs(dy);
|
|
53
|
-
const sx = adx > 0 ? from.rx / adx : Infinity;
|
|
54
|
-
const sy = ady > 0 ? from.ry / ady : Infinity;
|
|
55
|
-
const s = Math.min(sx, sy);
|
|
56
|
-
return { x: from.cx + dx * s, y: from.cy + dy * s };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function boxFor(nodes: readonly EdgeNodeBox[], id: string): NodeBox | null {
|
|
60
|
-
return boxesOf(nodes).get(id) ?? null;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Nearest stable connector port on the named node/shape to `point`. */
|
|
64
|
-
export function snapPointToward(
|
|
65
|
-
nodes: readonly EdgeNodeBox[],
|
|
66
|
-
id: string,
|
|
67
|
-
point: { x: number; y: number },
|
|
68
|
-
): ConnectorSnapPoint | null {
|
|
69
|
-
const box = boxFor(nodes, id);
|
|
70
|
-
return box ? nearestCoreSnapPoint(box, point) : null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Snapped start/end points of the edge `source`→`target`, or null when an
|
|
75
|
-
* endpoint shape is missing. Used by the renderer and by tool hit-testing
|
|
76
|
-
* endpoint handles against the same geometry the renderer draws.
|
|
77
|
-
*/
|
|
78
|
-
export function edgeEndpoints(
|
|
79
|
-
nodes: readonly EdgeNodeBox[],
|
|
80
|
-
source: string,
|
|
81
|
-
target: string,
|
|
82
|
-
sourceAnchor?: ConnectorAnchor,
|
|
83
|
-
targetAnchor?: ConnectorAnchor,
|
|
84
|
-
): { start: ConnectorSnapPoint; end: ConnectorSnapPoint } | null {
|
|
85
|
-
const boxes = boxesOf(nodes);
|
|
86
|
-
const a = boxes.get(source);
|
|
87
|
-
const b = boxes.get(target);
|
|
88
|
-
if (!a || !b) return null;
|
|
89
|
-
const snapped = coreSnapEndpoints(a, b);
|
|
90
|
-
return {
|
|
91
|
-
start: sourceAnchor ? anchorPoint(a, sourceAnchor) : snapped.start,
|
|
92
|
-
end: targetAnchor ? anchorPoint(b, targetAnchor) : snapped.end,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function straightPath(a: { x: number; y: number }, b: { x: number; y: number }): string {
|
|
97
|
-
return `M ${a.x} ${a.y} L ${b.x} ${b.y}`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function curvedPath(start: { x: number; y: number }, end: { x: number; y: number }): string {
|
|
101
|
-
const dx = Math.abs(end.x - start.x);
|
|
102
|
-
const cp = Math.max(40, dx / 2);
|
|
103
|
-
return `M ${start.x} ${start.y} C ${start.x + cp} ${start.y}, ${end.x - cp} ${end.y}, ${end.x} ${end.y}`;
|
|
104
|
-
}
|