@conscience-technology/ovenn 0.6.7 → 0.7.2
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/assets/components/AIMessage/AIMessage.module.css +23 -1
- package/assets/components/AIMessage/AIMessage.tsx +27 -7
- package/assets/components/Accordion/Accordion.module.css +3 -0
- package/assets/components/AppFrame/AppFrame.module.css +2 -0
- package/assets/components/AttachmentItem/AttachmentItem.module.css +50 -13
- package/assets/components/AttachmentItem/AttachmentItem.tsx +25 -8
- package/assets/components/AttachmentThumb/AttachmentThumb.module.css +12 -9
- package/assets/components/Avatar/Avatar.module.css +26 -11
- package/assets/components/Avatar/Avatar.tsx +1 -1
- package/assets/components/AvatarUpload/AvatarUpload.module.css +4 -3
- package/assets/components/Badge/Badge.module.css +96 -70
- package/assets/components/Badge/Badge.tsx +33 -25
- package/assets/components/Breadcrumb/Breadcrumb.module.css +8 -4
- package/assets/components/Breadcrumb/Breadcrumb.tsx +1 -1
- package/assets/components/Bubble/Bubble.module.css +6 -0
- package/assets/components/Button/Button.module.css +6 -0
- package/assets/components/Calendar/Calendar.module.css +244 -0
- package/assets/components/Calendar/Calendar.tsx +419 -0
- package/assets/components/Calendar/index.ts +2 -0
- package/assets/components/Callout/Callout.module.css +54 -7
- package/assets/components/Callout/Callout.tsx +26 -2
- package/assets/components/Callout/index.ts +1 -1
- package/assets/components/Canvas/Canvas.module.css +75 -0
- package/assets/components/Canvas/Canvas.tsx +699 -0
- package/assets/components/Canvas/alignment.ts +34 -0
- package/assets/components/Canvas/clipboard.ts +30 -0
- package/assets/components/Canvas/collision.ts +67 -0
- package/assets/components/Canvas/edgeOptions.ts +11 -0
- package/assets/components/Canvas/graph.ts +11 -0
- package/assets/components/Canvas/history.ts +41 -0
- package/assets/components/Canvas/index.ts +4 -0
- package/assets/components/Canvas/selection.ts +56 -0
- package/assets/components/Canvas/tokens.css +61 -0
- package/assets/components/Canvas/types.ts +27 -0
- package/assets/components/Canvas/useCanvasSettlement.ts +79 -0
- package/assets/components/CanvasEdge/CanvasEdge.module.css +62 -0
- package/assets/components/CanvasEdge/CanvasEdge.tsx +121 -0
- package/assets/components/CanvasEdge/geometry.ts +350 -0
- package/assets/components/CanvasEdge/index.ts +4 -0
- package/assets/components/CanvasEdge/interactions.ts +14 -0
- package/assets/components/CanvasEdge/tokens.css +29 -0
- package/assets/components/CanvasNode/CanvasNode.module.css +234 -30
- package/assets/components/CanvasNode/CanvasNode.tsx +95 -28
- package/assets/components/CanvasNode/index.ts +1 -1
- package/assets/components/CanvasNode/runningOutline.ts +59 -0
- package/assets/components/CanvasNode/tokens.css +76 -13
- package/assets/components/Card/Card.module.css +5 -0
- package/assets/components/Chart/Chart.module.css +278 -0
- package/assets/components/Chart/Chart.tsx +385 -0
- package/assets/components/Chart/entrance.tsx +57 -0
- package/assets/components/Chart/index.ts +14 -0
- package/assets/components/ChatComposer/ChatComposer.module.css +17 -0
- package/assets/components/ChatComposer/ChatComposer.tsx +131 -0
- package/assets/components/ChatComposer/index.ts +2 -0
- package/assets/components/ChatInput/ChatInput.module.css +197 -30
- package/assets/components/ChatInput/ChatInput.tsx +137 -45
- package/assets/components/ChatInput/SendButton.tsx +4 -1
- package/assets/components/ChatInput/index.ts +5 -0
- package/assets/components/ChatMessage/ChatMessage.module.css +19 -0
- package/assets/components/ChatMessage/ChatMessage.tsx +63 -0
- package/assets/components/ChatMessage/index.ts +2 -0
- package/assets/components/ChatReactions/ChatReactions.module.css +15 -0
- package/assets/components/ChatReactions/ChatReactions.tsx +58 -0
- package/assets/components/ChatReactions/index.ts +2 -0
- package/assets/components/Checkbox/Checkbox.module.css +39 -0
- package/assets/components/Checkbox/Checkbox.tsx +99 -14
- package/assets/components/Checkbox/index.ts +1 -1
- package/assets/components/CheckboxCard/CheckboxCard.module.css +1 -177
- package/assets/components/CheckboxCard/CheckboxCard.tsx +6 -72
- package/assets/components/Chip/Chip.module.css +20 -30
- package/assets/components/Code/Code.module.css +1 -0
- package/assets/components/CodeBlock/CodeBlock.module.css +113 -13
- package/assets/components/CodeBlock/CodeBlock.tsx +114 -29
- package/assets/components/CodeBlock/SyntaxHighlight.tsx +20 -0
- package/assets/components/CodeBlock/diff-lines.ts +21 -0
- package/assets/components/CodeBlock/index.ts +2 -1
- package/assets/components/CodeBlock/line-preview.ts +7 -0
- package/assets/components/CodeBlock/syntax-highlighter.ts +96 -0
- package/assets/components/CodeBlock/use-syntax-tokens.ts +17 -0
- package/assets/components/ColorArea/ColorArea.module.css +3 -0
- package/assets/components/ColorField/ColorField.module.css +19 -190
- package/assets/components/ColorField/ColorField.tsx +116 -107
- package/assets/components/ColorPicker/ColorPicker.module.css +310 -0
- package/assets/components/ColorPicker/ColorPicker.tsx +387 -0
- package/assets/components/ColorPicker/index.ts +16 -0
- package/assets/components/ColorSlider/ColorSlider.module.css +15 -12
- package/assets/components/ColorSlider/ColorSlider.tsx +3 -3
- package/assets/components/ColorSwatch/ColorSwatch.module.css +2 -2
- package/assets/components/ColorSwatchPicker/ColorSwatchPicker.module.css +4 -3
- package/assets/components/Combobox/Combobox.module.css +21 -4
- package/assets/components/Combobox/Combobox.tsx +38 -22
- package/assets/components/CommandPalette/CommandPalette.module.css +19 -24
- package/assets/components/CommandPalette/CommandPalette.tsx +7 -5
- package/assets/components/Comment/Comment.module.css +25 -0
- package/assets/components/Comment/Comment.tsx +44 -0
- package/assets/components/Comment/CommentComposer.module.css +26 -0
- package/assets/components/Comment/CommentComposer.tsx +56 -0
- package/assets/components/Comment/CommentEditor.module.css +8 -0
- package/assets/components/Comment/CommentEditor.tsx +43 -0
- package/assets/components/Comment/CommentMentionInput.module.css +9 -0
- package/assets/components/Comment/CommentMentionInput.tsx +150 -0
- package/assets/components/Comment/index.ts +9 -0
- package/assets/components/Comment/types.ts +1 -0
- package/assets/components/ContextMenu/ContextMenu.module.css +5 -2
- package/assets/components/ContextMenu/ContextMenu.tsx +5 -0
- package/assets/components/ControlGroup/ControlGroup.module.css +20 -7
- package/assets/components/DataTable/DataTable.module.css +2 -0
- package/assets/components/DatePicker/DateField.tsx +72 -25
- package/assets/components/DatePicker/DatePicker.module.css +56 -54
- package/assets/components/DatePicker/DatePicker.tsx +86 -40
- package/assets/components/DatePicker/TimeSelector.tsx +1 -1
- package/assets/components/Disclosure/Disclosure.module.css +1 -0
- package/assets/components/Drawer/Drawer.module.css +23 -19
- package/assets/components/Drawer/Drawer.tsx +20 -24
- package/assets/components/DropdownMenu/DropdownMenu.tsx +5 -0
- package/assets/components/EmojiPicker/EmojiGlyph.module.css +2 -0
- package/assets/components/EmojiPicker/EmojiGlyph.tsx +12 -0
- package/assets/components/EmojiPicker/EmojiPicker.module.css +43 -0
- package/assets/components/EmojiPicker/EmojiPicker.tsx +143 -0
- package/assets/components/EmojiPicker/UNICODE-LICENSE.txt +39 -0
- package/assets/components/EmojiPicker/data.ts +41 -0
- package/assets/components/EmojiPicker/emojiData-0.json +1 -0
- package/assets/components/EmojiPicker/emojiData-1.json +1 -0
- package/assets/components/EmojiPicker/emojiData-2.json +1 -0
- package/assets/components/EmojiPicker/emojiData-3.json +1 -0
- package/assets/components/EmojiPicker/emojiData.sources.json +35 -0
- package/assets/components/EmojiPicker/emojiData.ts +8 -0
- package/assets/components/EmojiPicker/emojiFallbacks.json +1 -0
- package/assets/components/EmojiPicker/index.ts +4 -0
- package/assets/components/EmptyState/EmptyState.module.css +2 -2
- package/assets/components/EventChip/EventChip.module.css +120 -53
- package/assets/components/EventChip/EventChip.tsx +54 -6
- package/assets/components/EventChip/index.ts +1 -1
- package/assets/components/EventListItem/EventListItem.module.css +3 -0
- package/assets/components/EventListItem/EventListItem.tsx +15 -8
- package/assets/components/FileIcon/FileIcon.module.css +6 -6
- package/assets/components/FileUpload/FileUpload.module.css +10 -3
- package/assets/components/FileUpload/FileUpload.tsx +5 -9
- package/assets/components/FileUpload/FileUploadItem.tsx +34 -0
- package/assets/components/GalleryItem/GalleryItem.module.css +16 -19
- package/assets/components/GeneratedImage/GeneratedImage.module.css +2 -0
- package/assets/components/Icon/Icon.tsx +264 -1088
- package/assets/components/Icon/LucideFamilyIcon.tsx +436 -0
- package/assets/components/Icon/MissingIcon.tsx +25 -0
- package/assets/components/Icon/SolarFamilyIcon.tsx +443 -0
- package/assets/components/Icon/catalogNames.ts +8 -0
- package/assets/components/Icon/context.tsx +1 -1
- package/assets/components/Icon/index.ts +2 -0
- package/assets/components/Icon/lucideCatalog.ts +11358 -0
- package/assets/components/Icon/phosphorCatalog.ts +3052 -0
- package/assets/components/Icon/solarCatalog.ts +16064 -0
- package/assets/components/IconButton/IconButton.module.css +3 -2
- package/assets/components/Input/Input.module.css +63 -22
- package/assets/components/Input/Input.tsx +21 -10
- package/assets/components/Kanban/Kanban.module.css +6 -0
- package/assets/components/ListItem/ListItem.module.css +9 -6
- package/assets/components/MenuItem/MenuItem.module.css +24 -22
- package/assets/components/MenuItem/MenuItem.tsx +12 -12
- package/assets/components/MessageActions/MessageActions.module.css +38 -2
- package/assets/components/MessageActions/MessageActions.tsx +53 -28
- package/assets/components/MessageQuote/MessageQuote.module.css +1 -0
- package/assets/components/MessageSources/MessageSources.module.css +2 -0
- package/assets/components/MessageState/MessageState.module.css +1 -1
- package/assets/components/MetricCard/MetricCard.module.css +96 -108
- package/assets/components/MetricCard/MetricCard.tsx +45 -23
- package/assets/components/MetricCard/tokens.css +10 -0
- package/assets/components/MiniCalendar/MiniCalendar.module.css +130 -0
- package/assets/components/MiniCalendar/MiniCalendar.tsx +161 -0
- package/assets/components/MiniCalendar/index.ts +2 -0
- package/assets/components/Modal/Modal.module.css +13 -4
- package/assets/components/Modal/Modal.tsx +4 -0
- package/assets/components/Onboarding/LayoutBuilder.tsx +12 -50
- package/assets/components/Onboarding/Onboarding.module.css +211 -278
- package/assets/components/Onboarding/OnboardingAxisPanel.tsx +81 -125
- package/assets/components/Onboarding/OnboardingPage.tsx +244 -467
- package/assets/components/Onboarding/actions.ts +5 -0
- package/assets/components/Onboarding/palette.css +8 -0
- package/assets/components/Onboarding/wizardData.ts +8 -8
- package/assets/components/ProgressBar/ProgressBar.module.css +42 -8
- package/assets/components/ProgressBar/ProgressBar.tsx +5 -6
- package/assets/components/ProgressBar/index.ts +0 -1
- package/assets/components/QuotationBar/QuotationBar.module.css +2 -0
- package/assets/components/Radio/Radio.module.css +2 -0
- package/assets/components/RadioCard/RadioCard.module.css +96 -3
- package/assets/components/RadioCard/RadioCard.tsx +76 -13
- package/assets/components/RadioCard/index.ts +1 -1
- package/assets/components/SegmentedChart/SegmentedChart.module.css +16 -0
- package/assets/components/SegmentedChart/SegmentedChart.tsx +25 -8
- package/assets/components/Select/Select.module.css +9 -7
- package/assets/components/Select/Select.tsx +22 -6
- package/assets/components/Shortcut/Shortcut.module.css +2 -0
- package/assets/components/Sidebar/Sidebar.module.css +1 -0
- package/assets/components/Sidebar/Sidebar.tsx +2 -2
- package/assets/components/Skeleton/Skeleton.module.css +33 -0
- package/assets/components/Skeleton/Skeleton.tsx +20 -0
- package/assets/components/Skeleton/index.ts +2 -0
- package/assets/components/Skeleton/tokens.css +11 -0
- package/assets/components/Slider/Slider.module.css +3 -0
- package/assets/components/Slider/Slider.tsx +7 -2
- package/assets/components/Spinner/LottiePlayer.tsx +4 -4
- package/assets/components/Spinner/Spinner.module.css +3 -0
- package/assets/components/Spinner/lottieManifest.ts +3 -0
- package/assets/components/Stepper/Stepper.module.css +56 -8
- package/assets/components/Stepper/Stepper.tsx +13 -4
- package/assets/components/Switch/Switch.module.css +55 -42
- package/assets/components/Switch/Switch.tsx +6 -2
- package/assets/components/Switch/index.ts +1 -1
- package/assets/components/TabStrip/TabStrip.module.css +5 -1
- package/assets/components/TableCell/TableCell.module.css +8 -1
- package/assets/components/TableCell/TableCellBadge.tsx +7 -3
- package/assets/components/TableCell/TableCellImage.tsx +1 -1
- package/assets/components/TableCell/TableCellTag.tsx +23 -0
- package/assets/components/TableCell/index.ts +3 -0
- package/assets/components/TableHeader/TableHeader.module.css +4 -0
- package/assets/components/TableRow/TableRow.module.css +3 -0
- package/assets/components/TableRowEdit/TableRowEdit.module.css +2 -0
- package/assets/components/TableToolbar/TableToolbar.module.css +1 -0
- package/assets/components/Tabs/Tabs.module.css +23 -8
- package/assets/components/Tabs/Tabs.tsx +4 -3
- package/assets/components/Tag/Tag.module.css +101 -0
- package/assets/components/Tag/Tag.tsx +55 -0
- package/assets/components/Tag/index.ts +2 -0
- package/assets/components/TemplateBoundary/TemplateBoundary.tsx +22 -18
- package/assets/components/TemplateBoundary/types.ts +2 -0
- package/assets/components/Textarea/Textarea.module.css +30 -226
- package/assets/components/Textarea/Textarea.tsx +2 -2
- package/assets/components/ThemeController.tsx +30 -3
- package/assets/components/TimePicker/TimePicker.module.css +17 -4
- package/assets/components/TimePicker/TimePicker.tsx +102 -23
- package/assets/components/TimelineView/TimelineEventBar.tsx +109 -0
- package/assets/components/TimelineView/TimelineView.module.css +203 -0
- package/assets/components/TimelineView/TimelineView.tsx +137 -0
- package/assets/components/TimelineView/axis.ts +62 -0
- package/assets/components/TimelineView/index.ts +3 -0
- package/assets/components/TimelineView/layout.ts +56 -0
- package/assets/components/TimelineView/move.ts +51 -0
- package/assets/components/TimelineView/useTimelineDrag.ts +215 -0
- package/assets/components/TimelineView/useTimelineZoom.ts +92 -0
- package/assets/components/Toast/Toast.module.css +20 -0
- package/assets/components/Toast/Toast.tsx +1 -1
- package/assets/components/Toolbar/Toolbar.module.css +31 -24
- package/assets/components/Toolbar/Toolbar.tsx +4 -3
- package/assets/components/Tooltip/Tooltip.module.css +10 -0
- package/assets/components/Tooltip/Tooltip.tsx +50 -15
- package/assets/components/TopLoader/TopLoader.module.css +1 -0
- package/assets/components/TreeNav/TreeNav.module.css +1 -0
- package/assets/components/UserMessage/UserMessage.module.css +110 -1
- package/assets/components/UserMessage/UserMessage.tsx +138 -16
- package/assets/components/UserMessage/index.ts +4 -0
- package/assets/components/_color.ts +2 -2
- package/assets/components/_data.ts +37 -31
- package/assets/components/_utils.css +36 -5
- package/assets/components/axisOptions.ts +2 -0
- package/assets/components/component-registry.json +1731 -94
- package/assets/components/index.ts +23 -0
- package/assets/components/materialScope.tsx +11 -0
- package/assets/components/reset.css +1 -0
- package/assets/components/themeBootScript.ts +3 -2
- package/assets/components/tokens.css +308 -71
- package/assets/components/useChartEntrance.ts +119 -0
- package/assets/prompts/ASSEMBLY.md +20 -7
- package/assets/prompts/CATALOG.md +110 -92
- package/assets/prompts/FEEDBACK_PROCESS.md +19 -0
- package/assets/prompts/PRINCIPLES.md +25 -1
- package/assets/prompts/TEMPLATE_PREVIEWS.md +21 -0
- package/assets/prompts/WORKFLOW_DESIGN.md +48 -70
- package/assets/prompts/axes/font.md +12 -1
- package/assets/prompts/axes/icon.md +6 -4
- package/assets/prompts/axes/material.md +40 -0
- package/assets/prompts/axes/motion.md +2 -0
- package/assets/prompts/axes/palette.md +10 -2
- package/assets/prompts/axes/shape.md +8 -0
- package/assets/prompts/axes/voice.md +4 -0
- package/assets/prompts/components/README.md +3 -3
- package/assets/prompts/components/_variants.md +35 -35
- package/assets/prompts/components/accordion.md +15 -15
- package/assets/prompts/components/ai-message.md +14 -12
- package/assets/prompts/components/app-frame.md +16 -16
- package/assets/prompts/components/attachment-item.md +38 -31
- package/assets/prompts/components/attachment-thumb.md +14 -12
- package/assets/prompts/components/avatar-upload.md +10 -10
- package/assets/prompts/components/avatar.md +16 -16
- package/assets/prompts/components/badge.md +32 -97
- package/assets/prompts/components/breadcrumb.md +25 -24
- package/assets/prompts/components/bubble.md +13 -13
- package/assets/prompts/components/button-group.md +1 -1
- package/assets/prompts/components/button.md +36 -36
- package/assets/prompts/components/calendar.md +151 -0
- package/assets/prompts/components/callout.md +39 -23
- package/assets/prompts/components/canvas-edge.md +70 -0
- package/assets/prompts/components/canvas-node.md +27 -10
- package/assets/prompts/components/canvas.md +85 -0
- package/assets/prompts/components/card.md +31 -31
- package/assets/prompts/components/chart-bar.md +77 -0
- package/assets/prompts/components/chart-pie.md +63 -0
- package/assets/prompts/components/chart-radar.md +56 -0
- package/assets/prompts/components/chart-radial.md +56 -0
- package/assets/prompts/components/chart.md +129 -0
- package/assets/prompts/components/chat-composer.md +71 -0
- package/assets/prompts/components/chat-input.md +82 -27
- package/assets/prompts/components/chat-message.md +48 -0
- package/assets/prompts/components/chat-reactions.md +38 -0
- package/assets/prompts/components/checkbox-card.md +26 -45
- package/assets/prompts/components/checkbox.md +40 -17
- package/assets/prompts/components/chip.md +34 -34
- package/assets/prompts/components/code-block.md +109 -65
- package/assets/prompts/components/code.md +4 -4
- package/assets/prompts/components/color-area.md +9 -9
- package/assets/prompts/components/color-field.md +17 -13
- package/assets/prompts/components/color-picker.md +173 -0
- package/assets/prompts/components/color-slider.md +14 -14
- package/assets/prompts/components/color-swatch-picker.md +8 -8
- package/assets/prompts/components/color-swatch.md +9 -9
- package/assets/prompts/components/combobox.md +5 -2
- package/assets/prompts/components/command-palette.md +31 -30
- package/assets/prompts/components/comment.md +75 -0
- package/assets/prompts/components/context-menu.md +28 -25
- package/assets/prompts/components/control-group.md +4 -4
- package/assets/prompts/components/data-table.md +9 -0
- package/assets/prompts/components/date-picker.md +41 -23
- package/assets/prompts/components/disclosure.md +10 -10
- package/assets/prompts/components/drawer.md +29 -18
- package/assets/prompts/components/dropdown-menu.md +23 -21
- package/assets/prompts/components/emoji-picker.md +45 -0
- package/assets/prompts/components/empty-state.md +20 -18
- package/assets/prompts/components/event-chip.md +70 -28
- package/assets/prompts/components/event-list-item.md +32 -28
- package/assets/prompts/components/file-icon.md +18 -19
- package/assets/prompts/components/file-upload.md +1 -1
- package/assets/prompts/components/gallery-item.md +24 -23
- package/assets/prompts/components/generated-image.md +10 -10
- package/assets/prompts/components/hint.md +19 -19
- package/assets/prompts/components/icon-button.md +16 -16
- package/assets/prompts/components/icon.md +42 -17
- package/assets/prompts/components/input.md +49 -46
- package/assets/prompts/components/kanban.md +35 -35
- package/assets/prompts/components/list-item.md +50 -41
- package/assets/prompts/components/menu-item.md +49 -44
- package/assets/prompts/components/message-actions.md +15 -6
- package/assets/prompts/components/message-quote.md +7 -7
- package/assets/prompts/components/message-sources.md +10 -10
- package/assets/prompts/components/message-state.md +17 -17
- package/assets/prompts/components/message-table.md +5 -5
- package/assets/prompts/components/metric-card.md +57 -109
- package/assets/prompts/components/mini-calendar.md +77 -0
- package/assets/prompts/components/modal.md +40 -39
- package/assets/prompts/components/multi-select.md +4 -1
- package/assets/prompts/components/onboarding.md +23 -19
- package/assets/prompts/components/page-header.md +42 -33
- package/assets/prompts/components/pagination.md +17 -17
- package/assets/prompts/components/progress-bar.md +26 -13
- package/assets/prompts/components/quotation-bar.md +10 -10
- package/assets/prompts/components/radio-card.md +34 -117
- package/assets/prompts/components/radio.md +9 -9
- package/assets/prompts/components/segmented-chart.md +19 -5
- package/assets/prompts/components/select.md +29 -25
- package/assets/prompts/components/shortcut.md +11 -11
- package/assets/prompts/components/sidebar.md +67 -58
- package/assets/prompts/components/skeleton.md +47 -0
- package/assets/prompts/components/slider.md +18 -18
- package/assets/prompts/components/spinner.md +16 -16
- package/assets/prompts/components/stepper.md +29 -15
- package/assets/prompts/components/switch.md +30 -26
- package/assets/prompts/components/tab-strip.md +32 -31
- package/assets/prompts/components/table-cell.md +9 -7
- package/assets/prompts/components/table-header.md +16 -16
- package/assets/prompts/components/table-row-edit.md +19 -19
- package/assets/prompts/components/table-row-select.md +9 -9
- package/assets/prompts/components/table-row.md +29 -20
- package/assets/prompts/components/table-toolbar.md +9 -0
- package/assets/prompts/components/tabs.md +30 -27
- package/assets/prompts/components/tag.md +54 -0
- package/assets/prompts/components/textarea.md +16 -15
- package/assets/prompts/components/time-picker.md +22 -14
- package/assets/prompts/components/timeline-view.md +129 -0
- package/assets/prompts/components/toast.md +43 -42
- package/assets/prompts/components/toolbar.md +36 -23
- package/assets/prompts/components/tooltip.md +36 -17
- package/assets/prompts/components/top-loader.md +12 -12
- package/assets/prompts/components/topbar.md +43 -34
- package/assets/prompts/components/tree-nav.md +10 -10
- package/assets/prompts/components/user-message.md +23 -12
- package/assets/prompts/design-examples/README.md +1 -1
- package/assets/prompts/design-examples/ai-chat-full-page.png +0 -0
- package/assets/prompts/design-examples/catalog.json +124 -1
- package/assets/prompts/design-examples/sources/ai-chat-full-page/ChatExperience.module.css +346 -0
- package/assets/prompts/design-examples/sources/ai-chat-full-page/ChatExperience.tsx +375 -0
- package/assets/prompts/design-examples/sources/ai-chat-full-page/FullPageChat.tsx +8 -0
- package/assets/prompts/design-examples/sources/ai-chat-full-page/REFERENCE.md +19 -0
- package/assets/prompts/design-examples/sources/ai-chat-full-page/useChatDemo.ts +139 -0
- package/assets/prompts/design-examples/sources/ai-chat-full-page/useDemoTextStream.ts +30 -0
- package/assets/prompts/primitives/emerge.md +2 -0
- package/assets/prompts/templates/README.md +1 -1
- package/assets/prompts/templates/ains.md +9 -1
- package/assets/prompts/templates/aurora.md +5 -4
- package/assets/prompts/templates/minimal.md +14 -6
- package/assets/prompts/templates/onboarding.md +156 -0
- package/assets/prompts/templates/workspace.md +16 -11
- package/assets/prompts/tokens/color.md +11 -4
- package/assets/prompts/tokens/material.md +51 -0
- package/assets/prompts/tokens/radius.md +34 -0
- package/assets/prompts/tokens/typography.md +24 -2
- package/assets/prompts/use-cases/chart-chart-area.md +1334 -0
- package/assets/prompts/use-cases/chart-chart-bar.md +1886 -0
- package/assets/prompts/use-cases/chart-chart-pie.md +1031 -0
- package/assets/prompts/use-cases/chart-chart-radar.md +785 -0
- package/assets/prompts/use-cases/chart-chart-radial.md +988 -0
- package/assets/prompts/use-cases/chart-segmented-chart.md +262 -0
- package/assets/prompts/use-cases/chat-chat-composer.md +529 -0
- package/assets/prompts/use-cases/chat-chat-input.md +1766 -0
- package/assets/prompts/use-cases/data-comment.md +360 -0
- package/assets/prompts/use-cases/data-data-table.md +249 -0
- package/assets/prompts/use-cases/data-list-item.md +1056 -0
- package/assets/prompts/use-cases/data-metric-card.md +673 -0
- package/assets/prompts/use-cases/data-table-row.md +966 -0
- package/assets/prompts/use-cases/data-table-toolbar.md +481 -0
- package/assets/prompts/use-cases/feedback-drawer.md +1168 -0
- package/assets/prompts/use-cases/feedback-progress-bar.md +432 -0
- package/assets/prompts/use-cases/general-toolbar.md +854 -0
- package/assets/prompts/use-cases/general-tooltip.md +652 -0
- package/assets/prompts/use-cases/input-checkbox.md +443 -0
- package/assets/prompts/use-cases/structure-card.md +603 -0
- package/assets/prompts/use-cases/structure-page-header.md +755 -0
- package/assets/prompts/use-cases/structure-sidebar.md +1132 -0
- package/assets/prompts/use-cases/structure-topbar.md +1196 -0
- package/assets/public/ovenn-wordmark.svg +19 -0
- package/assets/skills/ovenn-wireframe/SKILL.md +17 -4
- package/package.json +10 -2
- package/src/commands/info.js +1 -1
- package/src/utils/design-examples.js +3 -4
- package/assets/prompts/templates/glass-button.md +0 -336
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CanvasCollisionRect, CanvasMovement } from "./collision";
|
|
2
|
+
export interface CanvasAlignmentBody extends CanvasCollisionRect { id: string }
|
|
3
|
+
type Anchor = "center" | "start" | "end";
|
|
4
|
+
export interface CanvasAlignmentGuide {
|
|
5
|
+
axis: "x" | "y"; at: number; from: number; to: number;
|
|
6
|
+
movingId: string; fixedId: string; anchor: Anchor;
|
|
7
|
+
}
|
|
8
|
+
export interface CanvasAlignmentConfig { threshold: number; release: number; extension: number }
|
|
9
|
+
const anchors: Anchor[] = ["center", "start", "end"];
|
|
10
|
+
const coordinate = (body: CanvasAlignmentBody, axis: "x" | "y", anchor: Anchor) => body[axis] + (anchor === "start" ? 0 : body[axis === "x" ? "width" : "height"] * (anchor === "center" ? .5 : 1));
|
|
11
|
+
/** Thresholds are screen pixels; all geometry and the returned rigid delta are world coordinates. */
|
|
12
|
+
export function alignCanvasNodes(moving: readonly CanvasAlignmentBody[], fixed: readonly CanvasAlignmentBody[], desired: CanvasMovement,
|
|
13
|
+
zoom: number, config: CanvasAlignmentConfig, previous: readonly CanvasAlignmentGuide[] = []): { delta: CanvasMovement; guides: CanvasAlignmentGuide[] } {
|
|
14
|
+
const scale = Number.isFinite(zoom) && zoom > 0 ? zoom : 1, delta = { ...desired };
|
|
15
|
+
const movingIds = new Set(moving.map(body => body.id)), stationary = fixed.filter(body => !movingIds.has(body.id));
|
|
16
|
+
const matches: { axis: "x" | "y"; moving: CanvasAlignmentBody; fixed: CanvasAlignmentBody; anchor: Anchor; offset: number }[] = [];
|
|
17
|
+
for (const axis of ["x", "y"] as const) {
|
|
18
|
+
const latch = previous.find(guide => guide.axis === axis);
|
|
19
|
+
const candidates = moving.flatMap(body => stationary.flatMap(other => anchors.map(anchor => ({ axis, moving: body, fixed: other, anchor,
|
|
20
|
+
offset: coordinate(other, axis, anchor) - coordinate(body, axis, anchor) - desired[axis] }))));
|
|
21
|
+
const locked = latch && candidates.find(candidate => candidate.moving.id === latch.movingId && candidate.fixed.id === latch.fixedId && candidate.anchor === latch.anchor
|
|
22
|
+
&& Math.abs(candidate.offset) <= config.release / scale);
|
|
23
|
+
const closest = locked || candidates.filter(candidate => Math.abs(candidate.offset) <= config.threshold / scale).sort((a, b) => Math.abs(a.offset) - Math.abs(b.offset)
|
|
24
|
+
|| anchors.indexOf(a.anchor) - anchors.indexOf(b.anchor) || a.fixed.id.localeCompare(b.fixed.id) || a.moving.id.localeCompare(b.moving.id))[0];
|
|
25
|
+
if (closest) { delta[axis] += closest.offset; matches.push(closest); }
|
|
26
|
+
}
|
|
27
|
+
return { delta, guides: matches.map(match => {
|
|
28
|
+
const perpendicular = match.axis === "x" ? "y" : "x", size = perpendicular === "x" ? "width" : "height";
|
|
29
|
+
return { axis: match.axis, at: coordinate(match.fixed, match.axis, match.anchor),
|
|
30
|
+
from: Math.min(match.moving[perpendicular] + delta[perpendicular], match.fixed[perpendicular]) - config.extension / scale,
|
|
31
|
+
to: Math.max(match.moving[perpendicular] + delta[perpendicular] + match.moving[size], match.fixed[perpendicular] + match.fixed[size]) + config.extension / scale,
|
|
32
|
+
movingId: match.moving.id, fixedId: match.fixed.id, anchor: match.anchor };
|
|
33
|
+
}) };
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CanvasCollisionRect } from "./collision";
|
|
2
|
+
import type { CanvasItem, CanvasLink } from "./types";
|
|
3
|
+
|
|
4
|
+
export interface CanvasClipboardSnapshot { nodes: CanvasItem[]; edges: CanvasLink[]; footprints?: Record<string, CanvasCollisionRect[]> }
|
|
5
|
+
const cloneNode = (node: CanvasItem): CanvasItem => ({ ...node, position: { ...node.position }, ...(node.ports && { ports: [...node.ports] }) });
|
|
6
|
+
const cloneEdge = (edge: CanvasLink): CanvasLink => ({ ...edge, source: { ...edge.source }, target: { ...edge.target } });
|
|
7
|
+
export function snapshotCanvasSelection(nodes: readonly CanvasItem[], edges: readonly CanvasLink[], ids: readonly string[], footprints?: ReadonlyMap<string, readonly CanvasCollisionRect[]>): CanvasClipboardSnapshot {
|
|
8
|
+
const copiedNodes = nodes.filter(node => ids.includes(node.id) && !node.disabled).map(cloneNode);
|
|
9
|
+
const included = new Set(copiedNodes.map(node => node.id));
|
|
10
|
+
return { ...(footprints && { footprints: Object.fromEntries(copiedNodes.map(node => [node.id, (footprints.get(node.id) ?? []).map(rect => ({ ...rect }))])) }), nodes: copiedNodes, edges: edges.filter(edge => included.has(edge.source.nodeId) && included.has(edge.target.nodeId)).map(cloneEdge) };
|
|
11
|
+
}
|
|
12
|
+
export function instantiateCanvasClipboard(snapshot: CanvasClipboardSnapshot, offset: number, createId: () => string): CanvasClipboardSnapshot {
|
|
13
|
+
const ids = new Map(snapshot.nodes.map(node => [node.id, createId()]));
|
|
14
|
+
return {
|
|
15
|
+
...(snapshot.footprints && { footprints: Object.fromEntries(snapshot.nodes.map(node => [ids.get(node.id)!, (snapshot.footprints?.[node.id] ?? []).map(rect => ({ ...rect, x: rect.x + offset, y: rect.y + offset }))])) }),
|
|
16
|
+
nodes: snapshot.nodes.map(node => ({ ...cloneNode(node), id: ids.get(node.id)!, position: { x: node.position.x + offset, y: node.position.y + offset } })),
|
|
17
|
+
edges: snapshot.edges.map(edge => ({ ...cloneEdge(edge), id: createId(), source: { ...edge.source, nodeId: ids.get(edge.source.nodeId)! }, target: { ...edge.target, nodeId: ids.get(edge.target.nodeId)! } })),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
// React media must remain in memory; only the matching session token enters the OS clipboard.
|
|
21
|
+
let clipboard: { token: string; snapshot: CanvasClipboardSnapshot; pastes: number } | null = null;
|
|
22
|
+
export function storeCanvasClipboard(snapshot: CanvasClipboardSnapshot): string {
|
|
23
|
+
const token = `ovenn:canvas:${crypto.randomUUID()}`;
|
|
24
|
+
clipboard = { token, snapshot, pastes: 0 };
|
|
25
|
+
return token;
|
|
26
|
+
}
|
|
27
|
+
export function readCanvasClipboard(token: string): CanvasClipboardSnapshot | null {
|
|
28
|
+
if (!clipboard || clipboard.token !== token) return null;
|
|
29
|
+
return instantiateCanvasClipboard(clipboard.snapshot, ++clipboard.pastes * 24, () => `canvas-${crypto.randomUUID()}`);
|
|
30
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface CanvasCollisionRect { x: number; y: number; width: number; height: number }
|
|
2
|
+
export interface CanvasMovement { x: number; y: number }
|
|
3
|
+
const EPS = 1e-7;
|
|
4
|
+
const shifted = (rect: CanvasCollisionRect, delta: CanvasMovement): CanvasCollisionRect => ({ ...rect, x: rect.x + delta.x, y: rect.y + delta.y });
|
|
5
|
+
const overlap = (a: CanvasCollisionRect, b: CanvasCollisionRect, gap: number): number =>
|
|
6
|
+
Math.max(0, Math.min(a.x + a.width, b.x + b.width + gap) - Math.max(a.x, b.x - gap))
|
|
7
|
+
* Math.max(0, Math.min(a.y + a.height, b.y + b.height + gap) - Math.max(a.y, b.y - gap));
|
|
8
|
+
const clear = (moving: readonly CanvasCollisionRect[], fixed: readonly CanvasCollisionRect[], delta: CanvasMovement, gap: number) =>
|
|
9
|
+
moving.every(rect => fixed.every(other => overlap(shifted(rect, delta), other, gap) <= EPS));
|
|
10
|
+
|
|
11
|
+
/** Resolve a rigid group against individual fixed rectangles, with sliding along contact. */
|
|
12
|
+
export function constrainCanvasMovement(moving: readonly CanvasCollisionRect[], fixed: readonly CanvasCollisionRect[], desired: CanvasMovement, gap: number): CanvasMovement {
|
|
13
|
+
const result = { x: 0, y: 0 }, remaining = { ...desired };
|
|
14
|
+
for (let pass = 0; pass < 3; pass++) {
|
|
15
|
+
let time = 1, axis: "x" | "y" | null = null;
|
|
16
|
+
for (const original of moving) for (const other of fixed) {
|
|
17
|
+
const rect = shifted(original, result);
|
|
18
|
+
const near = { x: other.x - gap - rect.width, y: other.y - gap - rect.height };
|
|
19
|
+
const far = { x: other.x + other.width + gap, y: other.y + other.height + gap };
|
|
20
|
+
if (overlap(rect, other, gap) > EPS) {
|
|
21
|
+
// Older/imported overlaps may escape toward a nearest boundary on either
|
|
22
|
+
// axis, but cannot tunnel deeper through an obstacle (area can saturate).
|
|
23
|
+
const blocked = (["x", "y"] as const).find(key => {
|
|
24
|
+
const lower = rect[key] - near[key], upper = far[key] - rect[key];
|
|
25
|
+
return remaining[key] > EPS && lower < upper - EPS || remaining[key] < -EPS && upper < lower - EPS;
|
|
26
|
+
});
|
|
27
|
+
if (blocked) { time = 0; axis = blocked; }
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const entries = { x: -Infinity, y: -Infinity }, exits = { x: Infinity, y: Infinity };
|
|
31
|
+
let miss = false;
|
|
32
|
+
for (const key of ["x", "y"] as const) {
|
|
33
|
+
if (Math.abs(remaining[key]) < EPS) { if (rect[key] <= near[key] + EPS || rect[key] >= far[key] - EPS) miss = true; }
|
|
34
|
+
else {
|
|
35
|
+
const a = (near[key] - rect[key]) / remaining[key], b = (far[key] - rect[key]) / remaining[key];
|
|
36
|
+
entries[key] = Math.min(a, b); exits[key] = Math.max(a, b);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const enter = Math.max(entries.x, entries.y), exit = Math.min(exits.x, exits.y);
|
|
40
|
+
if (!miss && enter >= -EPS && enter <= exit && exit > EPS && enter <= time) {
|
|
41
|
+
time = Math.max(0, enter); axis = entries.x >= entries.y ? "x" : "y";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
result.x += remaining.x * time; result.y += remaining.y * time;
|
|
45
|
+
if (!axis) break;
|
|
46
|
+
remaining.x *= 1 - time; remaining.y *= 1 - time; remaining[axis] = 0;
|
|
47
|
+
if (Math.abs(remaining.x) + Math.abs(remaining.y) < EPS) break;
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Find nearby empty space; cardinal boundary candidates guarantee an exterior escape. */
|
|
53
|
+
export function findCanvasPlacement(moving: readonly CanvasCollisionRect[], fixed: readonly CanvasCollisionRect[], gap: number): CanvasMovement {
|
|
54
|
+
const zero = { x: 0, y: 0 };
|
|
55
|
+
if (!moving.length || clear(moving, fixed, zero, gap)) return zero;
|
|
56
|
+
const xs = new Set([0]), ys = new Set([0]);
|
|
57
|
+
for (const rect of moving) for (const other of fixed) {
|
|
58
|
+
xs.add(other.x - gap - rect.x - rect.width); xs.add(other.x + other.width + gap - rect.x);
|
|
59
|
+
ys.add(other.y - gap - rect.y - rect.height); ys.add(other.y + other.height + gap - rect.y);
|
|
60
|
+
}
|
|
61
|
+
const sort = (values: Set<number>) => [...values].sort((a, b) => Math.abs(a) - Math.abs(b) || a - b);
|
|
62
|
+
const horizontal = sort(xs), vertical = sort(ys);
|
|
63
|
+
const candidates = [...horizontal.map(x => ({ x, y: 0 })), ...vertical.map(y => ({ x: 0, y }))];
|
|
64
|
+
for (const x of horizontal.slice(0, 32)) for (const y of vertical.slice(0, 32)) candidates.push({ x, y });
|
|
65
|
+
candidates.sort((a, b) => Math.hypot(a.x, a.y) - Math.hypot(b.x, b.y) || a.y - b.y || a.x - b.x);
|
|
66
|
+
return candidates.find(delta => clear(moving, fixed, delta, gap))!;
|
|
67
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MAX_CANVAS_EDGE_CORNER_RADIUS } from "../CanvasEdge/geometry";
|
|
2
|
+
import type { CanvasEdgeCornerRadius } from "./types";
|
|
3
|
+
|
|
4
|
+
export type CanvasCornerRadii = Record<CanvasEdgeCornerRadius, number> & { default: number };
|
|
5
|
+
|
|
6
|
+
/** SVG uses numbers internally; consumers choose one of three Shape-aware types. */
|
|
7
|
+
export function resolveCanvasCornerRadius(value: CanvasEdgeCornerRadius | undefined, radii: CanvasCornerRadii, fallback = radii.default): number {
|
|
8
|
+
const radius = value === "sm" || value === "md" || value === "lg" ? radii[value] : fallback;
|
|
9
|
+
const safe = Number.isFinite(radius) ? radius : Number.isFinite(fallback) ? fallback : 6;
|
|
10
|
+
return Math.min(MAX_CANVAS_EDGE_CORNER_RADIUS, Math.max(6, safe));
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CanvasConnection, CanvasItem, CanvasLink, CanvasPort } from "./types";
|
|
2
|
+
|
|
3
|
+
export const samePort = (a: CanvasPort, b: CanvasPort) => a.nodeId === b.nodeId && a.side === b.side;
|
|
4
|
+
export function canConnectCanvas(nodes: readonly CanvasItem[], edges: readonly CanvasLink[], connection: CanvasConnection): boolean {
|
|
5
|
+
if (connection.source.nodeId === connection.target.nodeId) return false;
|
|
6
|
+
for (const port of [connection.source, connection.target]) {
|
|
7
|
+
const node = nodes.find(node => node.id === port.nodeId);
|
|
8
|
+
if (!node || node.disabled || !(node.ports ?? ["left", "right"]).includes(port.side)) return false;
|
|
9
|
+
}
|
|
10
|
+
return !edges.some(edge => samePort(edge.source, connection.source) && samePort(edge.target, connection.target));
|
|
11
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CanvasItem, CanvasLink, CanvasSelection } from "./types";
|
|
2
|
+
export interface CanvasGraph { nodes: readonly CanvasItem[]; edges: readonly CanvasLink[] }
|
|
3
|
+
export interface CanvasSnapshot extends CanvasGraph { selection: CanvasSelection }
|
|
4
|
+
export function canvasGraphSignature({ nodes, edges }: CanvasGraph): string {
|
|
5
|
+
return JSON.stringify([nodes.map(node => [node.id, node.position.x, node.position.y, node.shape ?? "card", node.ports ?? ["left", "right"], !!node.disabled]),
|
|
6
|
+
edges.map(edge => [edge.id, edge.source.nodeId, edge.source.side, edge.target.nodeId, edge.target.side, !!edge.disabled])]);
|
|
7
|
+
}
|
|
8
|
+
export function snapshotCanvasGraph(graph: CanvasGraph, selection: CanvasSelection): CanvasSnapshot {
|
|
9
|
+
return {
|
|
10
|
+
nodes: graph.nodes.map(node => ({ ...node, position: { ...node.position }, ...(node.ports && { ports: [...node.ports] }) })),
|
|
11
|
+
edges: graph.edges.map(edge => ({ ...edge, source: { ...edge.source }, target: { ...edge.target } })),
|
|
12
|
+
selection: selection?.type === "group" ? { ...selection, nodeIds: [...selection.nodeIds], edgeIds: [...selection.edgeIds] }
|
|
13
|
+
: selection?.type === "nodes" ? { ...selection, ids: [...selection.ids] } : selection ? { ...selection } : null,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Preserve fresh runtime presentation for surviving IDs; history owns graph edits. */
|
|
17
|
+
export function restoreCanvasGraph(snapshot: CanvasSnapshot, current: CanvasGraph): CanvasSnapshot {
|
|
18
|
+
const nodes = new Map(current.nodes.map(node => [node.id, node])), edges = new Map(current.edges.map(edge => [edge.id, edge]));
|
|
19
|
+
return snapshotCanvasGraph({
|
|
20
|
+
nodes: snapshot.nodes.map(node => ({ ...(nodes.get(node.id) ?? node), position: { ...node.position } })),
|
|
21
|
+
edges: snapshot.edges.map(edge => ({ ...(edges.get(edge.id) ?? edge), source: { ...edge.source }, target: { ...edge.target } })),
|
|
22
|
+
}, snapshot.selection);
|
|
23
|
+
}
|
|
24
|
+
export class CanvasHistory {
|
|
25
|
+
private past: { before: CanvasSnapshot; after: CanvasSnapshot }[] = [];
|
|
26
|
+
private future: { before: CanvasSnapshot; after: CanvasSnapshot }[] = [];
|
|
27
|
+
record(before: CanvasSnapshot, after: CanvasSnapshot): void {
|
|
28
|
+
if (canvasGraphSignature(before) === canvasGraphSignature(after)) return;
|
|
29
|
+
this.past.push({ before: snapshotCanvasGraph(before, before.selection), after: snapshotCanvasGraph(after, after.selection) });
|
|
30
|
+
if (this.past.length > 100) this.past.shift();
|
|
31
|
+
this.future = [];
|
|
32
|
+
}
|
|
33
|
+
peek(redo: boolean): CanvasSnapshot | null { const entry = redo ? this.future.at(-1) : this.past.at(-1); return entry ? redo ? entry.after : entry.before : null; }
|
|
34
|
+
take(redo: boolean): CanvasSnapshot | null {
|
|
35
|
+
const entry = (redo ? this.future : this.past).pop();
|
|
36
|
+
if (!entry) return null;
|
|
37
|
+
(redo ? this.past : this.future).push(entry);
|
|
38
|
+
return redo ? entry.after : entry.before;
|
|
39
|
+
}
|
|
40
|
+
clear(): void { this.past = []; this.future = []; }
|
|
41
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Canvas } from "./Canvas";
|
|
2
|
+
export type { CanvasProps } from "./Canvas";
|
|
3
|
+
export type { CanvasEdgeCornerRadius, CanvasBackground, CanvasItem, CanvasLink, CanvasPort, CanvasConnection, CanvasSelection, CanvasLabels } from "./types";
|
|
4
|
+
export { canConnectCanvas } from "./graph";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { CanvasItem, CanvasSelection } from "./types";
|
|
2
|
+
|
|
3
|
+
export interface CanvasSelectionRect { x: number; y: number; width: number; height: number }
|
|
4
|
+
export const canvasNodeSelectionIds = (selection: CanvasSelection): readonly string[] => selection?.type === "group" ? selection.nodeIds : selection?.type === "nodes" ? selection.ids : selection?.type === "node" ? [selection.id] : [];
|
|
5
|
+
export function makeCanvasNodeSelection(ids: readonly string[]): CanvasSelection {
|
|
6
|
+
const unique = [...new Set(ids)];
|
|
7
|
+
return unique.length === 0 ? null : unique.length === 1 ? { type: "node", id: unique[0] } : { type: "nodes", ids: unique };
|
|
8
|
+
}
|
|
9
|
+
export function canvasSelectionRect(a: { x: number; y: number }, b: { x: number; y: number }): CanvasSelectionRect {
|
|
10
|
+
return { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y), width: Math.abs(b.x - a.x), height: Math.abs(b.y - a.y) };
|
|
11
|
+
}
|
|
12
|
+
export function canvasNodesInRect(nodes: readonly CanvasItem[], bodies: ReadonlyMap<string, CanvasSelectionRect>, rect: CanvasSelectionRect): string[] {
|
|
13
|
+
if (rect.width <= 0 || rect.height <= 0) return [];
|
|
14
|
+
return nodes.filter(node => {
|
|
15
|
+
const body = bodies.get(node.id);
|
|
16
|
+
return !node.disabled && body && rect.x < body.x + body.width && rect.x + rect.width > body.x && rect.y < body.y + body.height && rect.y + rect.height > body.y;
|
|
17
|
+
}).map(node => node.id);
|
|
18
|
+
}
|
|
19
|
+
export const canvasEdgeSelectionIds = (selection: CanvasSelection): readonly string[] => selection?.type === "group" ? selection.edgeIds : selection?.type === "edge" ? [selection.id] : [];
|
|
20
|
+
export function makeCanvasSelection(nodeIds: readonly string[], edgeIds: readonly string[]): CanvasSelection {
|
|
21
|
+
const nodes = [...new Set(nodeIds)], edges = [...new Set(edgeIds)];
|
|
22
|
+
if (!edges.length) return makeCanvasNodeSelection(nodes);
|
|
23
|
+
if (!nodes.length && edges.length === 1) return { type: "edge", id: edges[0] };
|
|
24
|
+
return { type: "group", nodeIds: nodes, edgeIds: edges };
|
|
25
|
+
}
|
|
26
|
+
export function sameCanvasSelection(a: CanvasSelection, b: CanvasSelection): boolean {
|
|
27
|
+
const same = (left: readonly string[], right: readonly string[]) => left.length === right.length && left.every(id => right.includes(id));
|
|
28
|
+
return same(canvasNodeSelectionIds(a), canvasNodeSelectionIds(b)) && same(canvasEdgeSelectionIds(a), canvasEdgeSelectionIds(b));
|
|
29
|
+
}
|
|
30
|
+
/** Liang–Barsky clipping also detects a crossing when neither endpoint lies inside. */
|
|
31
|
+
export function canvasSegmentIntersectsRect(a: { x: number; y: number }, b: { x: number; y: number }, rect: CanvasSelectionRect): boolean {
|
|
32
|
+
if (rect.width <= 0 || rect.height <= 0) return false;
|
|
33
|
+
const dx = b.x - a.x, dy = b.y - a.y;
|
|
34
|
+
let enter = 0, exit = 1;
|
|
35
|
+
for (const [p, q] of [[-dx, a.x - rect.x], [dx, rect.x + rect.width - a.x], [-dy, a.y - rect.y], [dy, rect.y + rect.height - a.y]]) {
|
|
36
|
+
if (p === 0) { if (q < 0) return false; continue; }
|
|
37
|
+
const t = q / p;
|
|
38
|
+
if (p < 0) enter = Math.max(enter, t); else exit = Math.min(exit, t);
|
|
39
|
+
if (enter > exit) return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
export function canvasPathIntersectsRect(path: SVGPathElement, rect: CanvasSelectionRect): boolean {
|
|
44
|
+
const bounds = path.getBBox();
|
|
45
|
+
if (bounds.x > rect.x + rect.width || bounds.x + bounds.width < rect.x || bounds.y > rect.y + rect.height || bounds.y + bounds.height < rect.y) return false;
|
|
46
|
+
const length = path.getTotalLength();
|
|
47
|
+
if (!Number.isFinite(length) || length <= 0) return false;
|
|
48
|
+
const steps = Math.max(1, Math.min(4096, Math.ceil(length / 4)));
|
|
49
|
+
let previous = path.getPointAtLength(0);
|
|
50
|
+
for (let i = 1; i <= steps; i++) {
|
|
51
|
+
const point = path.getPointAtLength(length * i / steps);
|
|
52
|
+
if (canvasSegmentIntersectsRect(previous, point, rect)) return true;
|
|
53
|
+
previous = point;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[data-slot="canvas"] {
|
|
2
|
+
--canvas-height: 460px;
|
|
3
|
+
--canvas-node-gap: 24px;
|
|
4
|
+
--canvas-settle-duration: var(--duration-slow);
|
|
5
|
+
--canvas-settle-easing: var(--ease-out);
|
|
6
|
+
--canvas-min-height: 320px;
|
|
7
|
+
--canvas-background: var(--bg);
|
|
8
|
+
--canvas-grid-color: color-mix(in oklab, var(--fg) 12%, transparent);
|
|
9
|
+
--canvas-grid-spacing: 24px;
|
|
10
|
+
--canvas-grid-dot: 1.5px;
|
|
11
|
+
--canvas-grid-dot-min: 0.75px;
|
|
12
|
+
--canvas-grid-line: 1px;
|
|
13
|
+
--canvas-grid-line-color: color-mix(in oklab, var(--fg) 6%, transparent);
|
|
14
|
+
--canvas-zoom-value-width: 48px;
|
|
15
|
+
--canvas-port-hit: 28px;
|
|
16
|
+
--canvas-port-hit-size: min(var(--canvas-port-hit), calc(var(--canvas-port-hit) / var(--canvas-zoom)));
|
|
17
|
+
--canvas-caption-clearance: 3px;
|
|
18
|
+
--canvas-port-feedback: color-mix(in oklab, var(--fg) 10%, transparent);
|
|
19
|
+
--canvas-controls-offset: 16px;
|
|
20
|
+
--canvas-world-layer: 0;
|
|
21
|
+
--canvas-node-layer: 1;
|
|
22
|
+
--canvas-drag-layer: 2;
|
|
23
|
+
--canvas-controls-layer: 3;
|
|
24
|
+
--canvas-marquee-layer: 2;
|
|
25
|
+
--canvas-guide-layer: 2;
|
|
26
|
+
--canvas-guide-threshold: 6px;
|
|
27
|
+
--canvas-guide-release: 10px;
|
|
28
|
+
--canvas-guide-extension: 12px;
|
|
29
|
+
--canvas-guide-color: color-mix(in oklab, var(--primary) 75%, transparent);
|
|
30
|
+
--canvas-guide-width: 1px;
|
|
31
|
+
--canvas-guide-dash: 4 3;
|
|
32
|
+
--canvas-marquee-border: var(--fg-subtle);
|
|
33
|
+
--canvas-marquee-fill: color-mix(in oklab, var(--fg) 4%, transparent);
|
|
34
|
+
--canvas-marquee-radius: 2px;
|
|
35
|
+
--canvas-port-feedback-radius: 50%;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
:root, [data-shape="standard"] {
|
|
39
|
+
--canvas-edge-radius-sm: 6px;
|
|
40
|
+
--canvas-edge-radius-md: 12px;
|
|
41
|
+
--canvas-edge-radius-lg: 24px;
|
|
42
|
+
--canvas-edge-radius-default: var(--canvas-edge-radius-md);
|
|
43
|
+
}
|
|
44
|
+
[data-shape="crisp"] {
|
|
45
|
+
--canvas-edge-radius-sm: 6px;
|
|
46
|
+
--canvas-edge-radius-md: 10px;
|
|
47
|
+
--canvas-edge-radius-lg: 16px;
|
|
48
|
+
--canvas-edge-radius-default: var(--canvas-edge-radius-sm);
|
|
49
|
+
}
|
|
50
|
+
[data-shape="soft"] {
|
|
51
|
+
--canvas-edge-radius-sm: 8px;
|
|
52
|
+
--canvas-edge-radius-md: 18px;
|
|
53
|
+
--canvas-edge-radius-lg: 32px;
|
|
54
|
+
--canvas-edge-radius-default: var(--canvas-edge-radius-lg);
|
|
55
|
+
}
|
|
56
|
+
[data-shape="pill"] {
|
|
57
|
+
--canvas-edge-radius-sm: 10px;
|
|
58
|
+
--canvas-edge-radius-md: 20px;
|
|
59
|
+
--canvas-edge-radius-lg: 40px;
|
|
60
|
+
--canvas-edge-radius-default: var(--canvas-edge-radius-lg);
|
|
61
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CanvasNodeProps, CanvasNodePortSide } from "../CanvasNode";
|
|
2
|
+
import type { CanvasEdgeLineStyle, CanvasEdgeStatus } from "../CanvasEdge";
|
|
3
|
+
|
|
4
|
+
export interface CanvasItem extends Pick<CanvasNodeProps, "title" | "description" | "media" | "icon" | "shape" | "variant" | "status" | "statusLabel" | "disabled" | "ports"> {
|
|
5
|
+
id: string;
|
|
6
|
+
position: { x: number; y: number };
|
|
7
|
+
}
|
|
8
|
+
export interface CanvasPort { nodeId: string; side: CanvasNodePortSide }
|
|
9
|
+
export interface CanvasConnection { source: CanvasPort; target: CanvasPort }
|
|
10
|
+
export interface CanvasLink extends CanvasConnection {
|
|
11
|
+
id: string;
|
|
12
|
+
lineStyle?: CanvasEdgeLineStyle;
|
|
13
|
+
/** Per-link Shape-aware orthogonal corner preset. */
|
|
14
|
+
cornerRadius?: CanvasEdgeCornerRadius;
|
|
15
|
+
status?: CanvasEdgeStatus;
|
|
16
|
+
statusLabel?: string;
|
|
17
|
+
arrow?: boolean;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type CanvasEdgeCornerRadius = "sm" | "md" | "lg";
|
|
21
|
+
export type CanvasBackground = "dots" | "grid" | "none";
|
|
22
|
+
export type CanvasSelection = { type: "node" | "edge"; id: string } | { type: "nodes"; ids: readonly string[] } | { type: "group"; nodeIds: readonly string[]; edgeIds: readonly string[] } | null;
|
|
23
|
+
export interface CanvasLabels {
|
|
24
|
+
canvas: string; controls: string; zoomIn: string; zoomOut: string; fit: string; zoom: string;
|
|
25
|
+
instructions: string; connecting: string; connected: string; cancelled: string;
|
|
26
|
+
port: (title: string, side: CanvasNodePortSide) => string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState, type RefObject } from "react";
|
|
2
|
+
import type { CanvasItem } from "./types";
|
|
3
|
+
type Point = { x: number; y: number };
|
|
4
|
+
type Positions = Record<string, Point>;
|
|
5
|
+
const EMPTY: Positions = {};
|
|
6
|
+
function easing(value: string): (progress: number) => number {
|
|
7
|
+
if (value === "linear") return progress => progress;
|
|
8
|
+
const values = value.match(/^cubic-bezier\(([^)]+)\)$/)?.[1].split(",").map(Number);
|
|
9
|
+
if (!values || values.length !== 4 || !values.every(Number.isFinite)) return progress => progress;
|
|
10
|
+
const [x1, y1, x2, y2] = values;
|
|
11
|
+
const curve = (t: number, a: number, b: number) => 3 * (1 - t) ** 2 * t * a + 3 * (1 - t) * t ** 2 * b + t ** 3;
|
|
12
|
+
return progress => {
|
|
13
|
+
let low = 0, high = 1;
|
|
14
|
+
for (let i = 0; i < 18; i++) { const t = (low + high) / 2; if (curve(t, x1, x2) < progress) low = t; else high = t; }
|
|
15
|
+
return curve((low + high) / 2, y1, y2);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function timing(element: HTMLElement) {
|
|
19
|
+
// Resolve CSS calc()/axis tokens through computed CSS, rather than parsing token expressions.
|
|
20
|
+
const probe = document.createElement("span"); probe.hidden = true;
|
|
21
|
+
probe.style.transitionDuration = "var(--canvas-settle-duration)";
|
|
22
|
+
probe.style.transitionTimingFunction = "var(--canvas-settle-easing)";
|
|
23
|
+
element.appendChild(probe); const style = getComputedStyle(probe);
|
|
24
|
+
const time = style.transitionDuration, ease = easing(style.transitionTimingFunction); probe.remove();
|
|
25
|
+
return { duration: parseFloat(time) * (time.endsWith("ms") ? 1 : 1000), ease };
|
|
26
|
+
}
|
|
27
|
+
export function useCanvasSettlement(root: RefObject<HTMLDivElement | null>, nodes: readonly CanvasItem[]) {
|
|
28
|
+
const [positions, setPositions] = useState<Positions>(EMPTY);
|
|
29
|
+
const committed = useRef<Positions>(EMPTY);
|
|
30
|
+
useLayoutEffect(() => { committed.current = positions; }, [positions]);
|
|
31
|
+
const active = useRef<{ current: Positions; targets: Positions; frame: number } | null>(null);
|
|
32
|
+
const stop = (ids?: readonly string[]) => {
|
|
33
|
+
const previous = active.current;
|
|
34
|
+
if (previous && ids) {
|
|
35
|
+
const interrupted = ids.filter(id => previous.targets[id] && committed.current[id]);
|
|
36
|
+
if (!interrupted.length) return null;
|
|
37
|
+
const current = Object.fromEntries(interrupted.map(id => [id, committed.current[id]]));
|
|
38
|
+
const targets = Object.fromEntries(interrupted.map(id => [id, previous.targets[id]]));
|
|
39
|
+
const remaining = Object.fromEntries(Object.entries(committed.current).filter(([id]) => !interrupted.includes(id)));
|
|
40
|
+
interrupted.forEach(id => { delete previous.targets[id]; });
|
|
41
|
+
previous.current = remaining;
|
|
42
|
+
if (!Object.keys(previous.targets).length) { cancelAnimationFrame(previous.frame); active.current = null; }
|
|
43
|
+
setPositions(remaining);
|
|
44
|
+
return { current, targets, frame: 0 };
|
|
45
|
+
}
|
|
46
|
+
if (previous) cancelAnimationFrame(previous.frame);
|
|
47
|
+
active.current = null; setPositions(EMPTY);
|
|
48
|
+
return previous ? { ...previous, current: committed.current } : null;
|
|
49
|
+
};
|
|
50
|
+
const start = (from: Positions, targets: Positions) => {
|
|
51
|
+
const previous = stop(), element = root.current;
|
|
52
|
+
if (!element || window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
|
|
53
|
+
const { duration, ease } = timing(element);
|
|
54
|
+
if (!Number.isFinite(duration) || duration <= 1) return;
|
|
55
|
+
from = { ...previous?.current, ...from }; targets = { ...previous?.targets, ...targets };
|
|
56
|
+
const run = { current: from, targets, frame: 0 }, started = performance.now();
|
|
57
|
+
active.current = run; setPositions(from);
|
|
58
|
+
const frame = (now: number) => {
|
|
59
|
+
if (active.current !== run) return;
|
|
60
|
+
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches || parseFloat(getComputedStyle(element).getPropertyValue("--motion-scale")) === 0) { stop(); return; }
|
|
61
|
+
const progress = Math.min(1, (now - started) / duration), amount = ease(progress);
|
|
62
|
+
if (progress >= 1) { stop(); return; }
|
|
63
|
+
run.current = Object.fromEntries(Object.entries(targets).map(([id, target]) => [id, {
|
|
64
|
+
x: from[id].x + (target.x - from[id].x) * amount, y: from[id].y + (target.y - from[id].y) * amount,
|
|
65
|
+
}]));
|
|
66
|
+
setPositions(run.current); run.frame = requestAnimationFrame(frame);
|
|
67
|
+
};
|
|
68
|
+
run.frame = requestAnimationFrame(frame);
|
|
69
|
+
};
|
|
70
|
+
useLayoutEffect(() => {
|
|
71
|
+
const run = active.current;
|
|
72
|
+
if (run && Object.entries(run.targets).some(([id, target]) => {
|
|
73
|
+
const node = nodes.find(node => node.id === id);
|
|
74
|
+
return !node || node.disabled || node.position.x !== target.x || node.position.y !== target.y;
|
|
75
|
+
})) { cancelAnimationFrame(run.frame); active.current = null; setPositions(EMPTY); }
|
|
76
|
+
}, [nodes]);
|
|
77
|
+
useLayoutEffect(() => () => { if (active.current) cancelAnimationFrame(active.current.frame); active.current = null; }, []);
|
|
78
|
+
return { positions, start, stop };
|
|
79
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
.root { color: var(--edge-color); outline: none; }
|
|
2
|
+
.root[data-line-style="dashed"] {
|
|
3
|
+
--edge-dash: var(--edge-dashed-pattern);
|
|
4
|
+
}
|
|
5
|
+
.root[data-interactive]:not([data-disabled]):where(:not([data-selected], :focus-visible)):hover { --edge-color: var(--edge-hover-color); }
|
|
6
|
+
.root[data-selected],
|
|
7
|
+
.root[data-interactive]:focus-visible {
|
|
8
|
+
--edge-color: var(--edge-selected-color);
|
|
9
|
+
}
|
|
10
|
+
.root[data-status="running"] { color: var(--primary); --edge-track-opacity: var(--edge-running-track-opacity); }
|
|
11
|
+
.root[data-status="running"]:where(:not([data-disabled], [data-preview]))[data-selected],
|
|
12
|
+
.root[data-status="running"]:where(:not([data-disabled], [data-preview])):focus-visible { --edge-track-opacity: var(--edge-running-selected-opacity); }
|
|
13
|
+
.root[data-status="success"] { color: var(--edge-success-color); }
|
|
14
|
+
.root[data-status="error"] { color: var(--edge-error-color); }
|
|
15
|
+
.root[data-preview] { color: var(--primary); opacity: var(--edge-preview-opacity); pointer-events: none; --edge-track-opacity: 1; }
|
|
16
|
+
.root[data-preview][data-line-style="solid"] { --edge-dash: var(--edge-preview-pattern); }
|
|
17
|
+
.root[data-disabled] { opacity: var(--edge-disabled-opacity); pointer-events: none; --edge-track-opacity: 1; }
|
|
18
|
+
.track,
|
|
19
|
+
.flow {
|
|
20
|
+
fill: none;
|
|
21
|
+
stroke: currentColor;
|
|
22
|
+
stroke-width: var(--edge-width);
|
|
23
|
+
stroke-linecap: round;
|
|
24
|
+
stroke-linejoin: round;
|
|
25
|
+
vector-effect: non-scaling-stroke;
|
|
26
|
+
pointer-events: none;
|
|
27
|
+
transition: stroke var(--edge-transition-duration) var(--ease-out), opacity var(--edge-transition-duration) var(--ease-out);
|
|
28
|
+
}
|
|
29
|
+
.root[data-variant="orthogonal"] :is(.track, .flow) { stroke-linejoin: miter; }
|
|
30
|
+
.track { stroke-dasharray: var(--edge-dash); opacity: var(--edge-track-opacity); }
|
|
31
|
+
.flow { stroke-dasharray: var(--edge-dash); }
|
|
32
|
+
.flowMask { mask-type: alpha; }
|
|
33
|
+
.maskStroke {
|
|
34
|
+
--edge-flow-offset: calc(var(--edge-flow-index) * var(--edge-flow-fade-step) / -2);
|
|
35
|
+
--edge-flow-segment: calc(var(--edge-flow-span) - var(--edge-flow-index) * var(--edge-flow-fade-step));
|
|
36
|
+
|
|
37
|
+
fill: none;
|
|
38
|
+
stroke: var(--edge-mask-color);
|
|
39
|
+
stroke-width: calc(var(--edge-width) + var(--edge-mask-padding));
|
|
40
|
+
stroke-linecap: round;
|
|
41
|
+
stroke-dasharray: var(--edge-flow-segment) calc(var(--edge-flow-repeat) - var(--edge-flow-segment));
|
|
42
|
+
stroke-dashoffset: var(--edge-flow-offset);
|
|
43
|
+
vector-effect: non-scaling-stroke;
|
|
44
|
+
opacity: var(--edge-flow-layer-opacity);
|
|
45
|
+
animation: travel var(--edge-flow-duration) var(--edge-flow-easing) infinite;
|
|
46
|
+
}
|
|
47
|
+
.marker > path { fill: none; stroke: currentColor; stroke-width: var(--edge-arrow-width); stroke-linecap: round; stroke-linejoin: round; }
|
|
48
|
+
.hit { fill: none; stroke: transparent; stroke-width: var(--edge-hit-width); stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: stroke; cursor: pointer; }
|
|
49
|
+
@keyframes travel {
|
|
50
|
+
0%, 8% { stroke-dashoffset: calc(var(--edge-flow-offset) + var(--edge-flow-span)); }
|
|
51
|
+
92%, 100% { stroke-dashoffset: calc(var(--edge-flow-offset) + var(--edge-flow-end)); }
|
|
52
|
+
}
|
|
53
|
+
:global([data-motion="none"]) .root[data-status] :is(.track, .maskStroke) { animation: none; transition: none; }
|
|
54
|
+
:global([data-motion="none"]) .root[data-status="running"] { --edge-track-opacity: 1; }
|
|
55
|
+
:global([data-motion="none"]) .root .flow { display: none; }
|
|
56
|
+
@media (prefers-reduced-motion: reduce) {
|
|
57
|
+
.root[data-status] :is(.track, .maskStroke) { animation: none; transition: none; }
|
|
58
|
+
.root[data-status="running"],
|
|
59
|
+
.root[data-status="running"][data-selected],
|
|
60
|
+
.root[data-status="running"]:focus-visible { --edge-track-opacity: 1; }
|
|
61
|
+
.root .flow { display: none; }
|
|
62
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useId, useMemo, useRef, useLayoutEffect, type CSSProperties, type KeyboardEvent, type MouseEvent, type SVGProps } from "react";
|
|
4
|
+
import { getCanvasEdgePath, trimCanvasEdgePath, type CanvasEdgeObstacle, type CanvasEdgeEndpoint, type CanvasEdgeVariant } from "./geometry";
|
|
5
|
+
import { activateCanvasEdge } from "./interactions";
|
|
6
|
+
import "./tokens.css";
|
|
7
|
+
import styles from "./CanvasEdge.module.css";
|
|
8
|
+
|
|
9
|
+
export type CanvasEdgeLineStyle = "solid" | "dashed";
|
|
10
|
+
export type CanvasEdgeStatus = "idle" | "running" | "success" | "error";
|
|
11
|
+
export interface CanvasEdgeProps extends Omit<SVGProps<SVGGElement>, "children" | "onSelect" | "role" | "tabIndex" | "source" | "target"> {
|
|
12
|
+
source: CanvasEdgeEndpoint;
|
|
13
|
+
target: CanvasEdgeEndpoint;
|
|
14
|
+
variant?: CanvasEdgeVariant;
|
|
15
|
+
lineStyle?: CanvasEdgeLineStyle;
|
|
16
|
+
status?: CanvasEdgeStatus;
|
|
17
|
+
selected?: boolean;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** A non-interactive connection-in-progress. */
|
|
20
|
+
preview?: boolean;
|
|
21
|
+
arrow?: boolean;
|
|
22
|
+
/** Accessible name of the connection. */
|
|
23
|
+
label?: string;
|
|
24
|
+
statusLabel?: string;
|
|
25
|
+
offset?: number;
|
|
26
|
+
curvature?: number;
|
|
27
|
+
cornerRadius?: number;
|
|
28
|
+
onSelect?: () => void;
|
|
29
|
+
/** Bounds to route around. Canvas passes other node bodies and masks external captions. Endpoint bodies belong on source/target.bounds. */
|
|
30
|
+
obstacles?: readonly CanvasEdgeObstacle[];
|
|
31
|
+
obstaclePadding?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Render inside an SVG, below the nodes. Coordinates belong to the host canvas. */
|
|
35
|
+
export const CanvasEdge = forwardRef<SVGGElement, CanvasEdgeProps>(function CanvasEdge(
|
|
36
|
+
{ source, target, variant = "curve", lineStyle = "solid", status = "idle", selected = false,
|
|
37
|
+
disabled = false, preview = false, arrow = false, label = "Connection", statusLabel, offset, curvature, cornerRadius,
|
|
38
|
+
onSelect, onClick, onKeyDown, className, obstacles, obstaclePadding, "aria-label": ariaLabel, "aria-describedby": describedBy, ...rest }, ref,
|
|
39
|
+
) {
|
|
40
|
+
const id = useId();
|
|
41
|
+
const { x: sourceX, y: sourceY, side: sourceSide } = source;
|
|
42
|
+
const { x: targetX, y: targetY, side: targetSide } = target;
|
|
43
|
+
const signature = JSON.stringify([variant, sourceSide, targetSide, arrow]);
|
|
44
|
+
const finite = [sourceX, sourceY, targetX, targetY].every(Number.isFinite)
|
|
45
|
+
&& [sourceSide, targetSide].every(side => ["left", "right", "top", "bottom"].includes(side));
|
|
46
|
+
// A detour belongs to the obstacle layout that required it. Keeping its
|
|
47
|
+
// preference after a block moves away pins elbows to obsolete coordinates.
|
|
48
|
+
// Source-relative bounds keep a rigid translation of the whole scene stable.
|
|
49
|
+
const relative = (value: number) => Number(value.toFixed(6));
|
|
50
|
+
const obstacleSignature = JSON.stringify([obstaclePadding, (obstacles ?? []).map(({ x, y, width, height }) =>
|
|
51
|
+
[relative(x - sourceX), relative(y - sourceY), relative(width), relative(height)]).sort()]);
|
|
52
|
+
const previousRoute = useRef<{ signature: string; obstacleSignature: string; path: string } | null>(null);
|
|
53
|
+
const lastVisible = useRef<{ signature: string; route: string; visible: string } | null>(null);
|
|
54
|
+
const route = useMemo(() => getCanvasEdgePath({ source: { x: sourceX, y: sourceY, side: sourceSide, bounds: source.bounds },
|
|
55
|
+
target: { x: targetX, y: targetY, side: targetSide, bounds: target.bounds }, variant, offset, curvature, cornerRadius,
|
|
56
|
+
obstacles, obstaclePadding, previousPath: previousRoute.current?.signature === signature && previousRoute.current.obstacleSignature === obstacleSignature ? previousRoute.current.path : "" }),
|
|
57
|
+
[sourceX, sourceY, sourceSide, source.bounds, targetX, targetY, targetSide, target.bounds, variant, offset, curvature, cornerRadius, obstacles, obstaclePadding, signature, obstacleSignature]);
|
|
58
|
+
const calculatedD = useMemo(() => {
|
|
59
|
+
if (!arrow || !route) return route;
|
|
60
|
+
const clearance = Math.min(9, Math.hypot(targetX - sourceX, targetY - sourceY) / 4);
|
|
61
|
+
if (variant === "orthogonal") return trimCanvasEdgePath(route, clearance);
|
|
62
|
+
const direction = { left: [-1, 0], right: [1, 0], top: [0, -1], bottom: [0, 1] }[targetSide];
|
|
63
|
+
return getCanvasEdgePath({ source: { x: sourceX, y: sourceY, side: sourceSide },
|
|
64
|
+
target: { x: targetX + direction[0] * clearance, y: targetY + direction[1] * clearance, side: targetSide },
|
|
65
|
+
variant, offset, curvature, cornerRadius });
|
|
66
|
+
}, [arrow, route, sourceX, sourceY, sourceSide, targetX, targetY, targetSide, variant, offset, curvature, cornerRadius]);
|
|
67
|
+
const retained = !preview && finite && !calculatedD && lastVisible.current?.signature === signature ? lastVisible.current : null;
|
|
68
|
+
const hitD = retained?.route ?? route;
|
|
69
|
+
const d = retained?.visible ?? calculatedD;
|
|
70
|
+
useLayoutEffect(() => {
|
|
71
|
+
if (!finite || previousRoute.current?.signature !== signature) previousRoute.current = null;
|
|
72
|
+
if (!finite || preview || lastVisible.current?.signature !== signature) lastVisible.current = null;
|
|
73
|
+
if (!finite) return;
|
|
74
|
+
if (variant === "orthogonal" && route && calculatedD) previousRoute.current = { signature, obstacleSignature, path: route };
|
|
75
|
+
if (!preview && route && calculatedD) lastVisible.current = { signature, route, visible: calculatedD };
|
|
76
|
+
}, [finite, signature, obstacleSignature, variant, preview, route, calculatedD]);
|
|
77
|
+
const bounds = useMemo(() => {
|
|
78
|
+
const values = (d.match(/-?\d+(?:\.\d+)?(?:e[+-]?\d+)?/gi) ?? []).map(Number);
|
|
79
|
+
const xs = values.filter((_, index) => index % 2 === 0), ys = values.filter((_, index) => index % 2 === 1);
|
|
80
|
+
return xs.length ? { x: Math.min(...xs) - 32, y: Math.min(...ys) - 32, width: Math.max(...xs) - Math.min(...xs) + 64, height: Math.max(...ys) - Math.min(...ys) + 64 } : { x: 0, y: 0, width: 1, height: 1 };
|
|
81
|
+
}, [d]);
|
|
82
|
+
const interactive = !!onSelect && !preview;
|
|
83
|
+
const stateLabel = statusLabel ?? (preview ? "Connecting" : status === "running" ? "Running" : status === "success" ? "Complete" : status === "error" ? "Error" : undefined);
|
|
84
|
+
const canSelect = interactive && !disabled;
|
|
85
|
+
const hasFlow = status === "running" && !preview && !disabled;
|
|
86
|
+
const click = (event: MouseEvent<SVGGElement>) => {
|
|
87
|
+
if (!canSelect) return;
|
|
88
|
+
activateCanvasEdge(event, () => onSelect?.(), onClick);
|
|
89
|
+
};
|
|
90
|
+
const keyDown = (event: KeyboardEvent<SVGGElement>) => {
|
|
91
|
+
if (!canSelect) return;
|
|
92
|
+
if (event.key === "Enter" || event.key === " ") activateCanvasEdge(event, () => onSelect?.(), onKeyDown, true);
|
|
93
|
+
else onKeyDown?.(event);
|
|
94
|
+
};
|
|
95
|
+
if (!d) return null;
|
|
96
|
+
return <g {...rest} ref={ref} data-slot="canvas-edge" data-variant={variant} data-line-style={lineStyle}
|
|
97
|
+
data-status={status} data-selected={selected || undefined} data-disabled={disabled || undefined}
|
|
98
|
+
data-preview={preview || undefined} data-path-retained={!!retained || undefined} data-interactive={interactive || undefined}
|
|
99
|
+
role={interactive ? "button" : "img"} tabIndex={canSelect ? 0 : undefined}
|
|
100
|
+
aria-label={ariaLabel ?? label} aria-describedby={[describedBy, stateLabel ? `${id}-status` : undefined].filter(Boolean).join(" ") || undefined}
|
|
101
|
+
aria-busy={status === "running" && !preview || undefined}
|
|
102
|
+
aria-pressed={interactive ? selected : undefined} aria-disabled={interactive && disabled || undefined}
|
|
103
|
+
onClick={canSelect ? click : undefined} onKeyDown={canSelect ? keyDown : undefined}
|
|
104
|
+
className={[styles.root, className].filter(Boolean).join(" ")}>
|
|
105
|
+
{stateLabel && <desc id={`${id}-status`}>{stateLabel}</desc>}
|
|
106
|
+
{arrow && <defs><marker id={`${id}-arrow`} className={styles.marker} viewBox="0 0 8 8"
|
|
107
|
+
refX="5" refY="4" markerWidth="8" markerHeight="8" markerUnits="userSpaceOnUse" orient="auto">
|
|
108
|
+
<path d="M 1 1 L 5 4 L 1 7" />
|
|
109
|
+
</marker></defs>}
|
|
110
|
+
{hasFlow && <defs>
|
|
111
|
+
<path id={`${id}-flow-path`} d={d} pathLength="100" />
|
|
112
|
+
<mask id={`${id}-flow-mask`} maskUnits="userSpaceOnUse" {...bounds} className={styles.flowMask}>
|
|
113
|
+
{Array.from({ length: 48 }, (_, index) => <use key={index} href={`#${id}-flow-path`} data-edge-part="fade"
|
|
114
|
+
className={styles.maskStroke} style={{ "--edge-flow-index": index } as CSSProperties} />)}
|
|
115
|
+
</mask>
|
|
116
|
+
</defs>}
|
|
117
|
+
<path data-edge-part="track" className={styles.track} d={d} markerEnd={arrow ? `url(#${id}-arrow)` : undefined} aria-hidden="true" />
|
|
118
|
+
{hasFlow && <path data-edge-part="flow" className={styles.flow} d={d} mask={`url(#${id}-flow-mask)`} aria-hidden="true" />}
|
|
119
|
+
{interactive && !disabled && <path className={styles.hit} d={hitD} aria-hidden="true" />}
|
|
120
|
+
</g>;
|
|
121
|
+
});
|