@conscience-technology/ovenn 0.6.7 → 0.7.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/assets/components/AIMessage/AIMessage.module.css +2 -1
- 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 +9 -3
- package/assets/components/AttachmentThumb/AttachmentThumb.module.css +4 -0
- 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 +1 -0
- 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/ChatInput/ChatInput.module.css +5 -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 +7 -3
- package/assets/components/ColorArea/ColorArea.module.css +3 -0
- package/assets/components/ColorField/ColorField.module.css +6 -0
- package/assets/components/ColorField/ColorField.tsx +3 -1
- 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 +1 -1
- package/assets/components/Combobox/Combobox.tsx +1 -1
- package/assets/components/CommandPalette/CommandPalette.module.css +18 -23
- 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 +7 -1
- package/assets/components/DataTable/DataTable.module.css +2 -0
- package/assets/components/DatePicker/DatePicker.module.css +36 -3
- package/assets/components/DatePicker/DatePicker.tsx +11 -1
- package/assets/components/DatePicker/TimeSelector.tsx +1 -1
- package/assets/components/Disclosure/Disclosure.module.css +1 -0
- package/assets/components/Drawer/Drawer.module.css +11 -4
- package/assets/components/Drawer/Drawer.tsx +5 -1
- package/assets/components/DropdownMenu/DropdownMenu.tsx +5 -0
- 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 +2 -0
- 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 +434 -0
- package/assets/components/Icon/MissingIcon.tsx +25 -0
- package/assets/components/Icon/SolarFamilyIcon.tsx +439 -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 +30 -12
- package/assets/components/Input/Input.tsx +1 -1
- 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 +36 -0
- 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 +8 -8
- package/assets/components/ProgressBar/ProgressBar.tsx +0 -5
- 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 +78 -3
- package/assets/components/RadioCard/RadioCard.tsx +34 -12
- 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.tsx +7 -4
- 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 +22 -7
- package/assets/components/Tabs/Tabs.tsx +2 -1
- 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 +7 -0
- package/assets/components/ThemeController.tsx +30 -3
- package/assets/components/TimePicker/TimePicker.module.css +1 -0
- package/assets/components/TimePicker/TimePicker.tsx +37 -16
- 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 +2 -0
- 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 +17 -8
- package/assets/components/TopLoader/TopLoader.module.css +1 -0
- package/assets/components/TreeNav/TreeNav.module.css +1 -0
- package/assets/components/_color.ts +2 -2
- package/assets/components/_data.ts +33 -32
- package/assets/components/_utils.css +5 -0
- package/assets/components/axisOptions.ts +2 -0
- package/assets/components/component-registry.json +151 -2
- package/assets/components/index.ts +16 -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 +225 -71
- package/assets/components/useChartEntrance.ts +119 -0
- package/assets/prompts/ASSEMBLY.md +9 -7
- package/assets/prompts/CATALOG.md +18 -4
- package/assets/prompts/FEEDBACK_PROCESS.md +19 -0
- package/assets/prompts/PRINCIPLES.md +14 -0
- package/assets/prompts/WORKFLOW_DESIGN.md +46 -70
- package/assets/prompts/axes/font.md +6 -1
- package/assets/prompts/axes/icon.md +6 -4
- package/assets/prompts/axes/material.md +40 -0
- package/assets/prompts/axes/palette.md +2 -1
- package/assets/prompts/axes/shape.md +8 -0
- package/assets/prompts/components/attachment-item.md +2 -1
- package/assets/prompts/components/badge.md +32 -97
- package/assets/prompts/components/breadcrumb.md +1 -0
- package/assets/prompts/components/calendar.md +151 -0
- package/assets/prompts/components/canvas-edge.md +67 -0
- package/assets/prompts/components/canvas-node.md +25 -8
- package/assets/prompts/components/canvas.md +82 -0
- package/assets/prompts/components/card.md +10 -10
- 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/checkbox-card.md +26 -45
- package/assets/prompts/components/checkbox.md +23 -0
- package/assets/prompts/components/chip.md +6 -6
- package/assets/prompts/components/code-block.md +1 -0
- package/assets/prompts/components/color-picker.md +173 -0
- package/assets/prompts/components/color-slider.md +7 -7
- package/assets/prompts/components/command-palette.md +7 -6
- package/assets/prompts/components/comment.md +72 -0
- package/assets/prompts/components/context-menu.md +6 -3
- package/assets/prompts/components/data-table.md +9 -0
- package/assets/prompts/components/date-picker.md +10 -0
- package/assets/prompts/components/drawer.md +10 -0
- package/assets/prompts/components/dropdown-menu.md +3 -1
- package/assets/prompts/components/event-chip.md +60 -18
- package/assets/prompts/components/event-list-item.md +14 -10
- package/assets/prompts/components/file-upload.md +1 -1
- package/assets/prompts/components/gallery-item.md +5 -4
- package/assets/prompts/components/icon.md +30 -8
- package/assets/prompts/components/kanban.md +1 -1
- package/assets/prompts/components/list-item.md +11 -2
- package/assets/prompts/components/menu-item.md +8 -3
- package/assets/prompts/components/message-actions.md +9 -0
- package/assets/prompts/components/metric-card.md +57 -109
- package/assets/prompts/components/mini-calendar.md +72 -0
- package/assets/prompts/components/modal.md +1 -0
- package/assets/prompts/components/onboarding.md +11 -7
- package/assets/prompts/components/page-header.md +11 -2
- package/assets/prompts/components/progress-bar.md +12 -2
- package/assets/prompts/components/radio-card.md +33 -117
- package/assets/prompts/components/segmented-chart.md +19 -5
- package/assets/prompts/components/select.md +1 -0
- package/assets/prompts/components/sidebar.md +12 -3
- package/assets/prompts/components/skeleton.md +44 -0
- package/assets/prompts/components/stepper.md +15 -1
- package/assets/prompts/components/switch.md +15 -10
- package/assets/prompts/components/tab-strip.md +1 -0
- package/assets/prompts/components/table-cell.md +6 -4
- package/assets/prompts/components/table-row.md +12 -3
- package/assets/prompts/components/table-toolbar.md +9 -0
- package/assets/prompts/components/tabs.md +4 -2
- package/assets/prompts/components/tag.md +54 -0
- package/assets/prompts/components/time-picker.md +1 -0
- package/assets/prompts/components/timeline-view.md +129 -0
- package/assets/prompts/components/toast.md +1 -1
- package/assets/prompts/components/toolbar.md +17 -4
- package/assets/prompts/components/tooltip.md +21 -3
- package/assets/prompts/components/top-loader.md +1 -1
- package/assets/prompts/components/topbar.md +9 -0
- package/assets/prompts/components/tree-nav.md +1 -1
- package/assets/prompts/templates/ains.md +2 -1
- package/assets/prompts/templates/aurora.md +5 -4
- package/assets/prompts/templates/glass-button.md +6 -5
- package/assets/prompts/templates/minimal.md +8 -6
- package/assets/prompts/templates/workspace.md +3 -3
- package/assets/prompts/tokens/color.md +4 -2
- package/assets/prompts/tokens/material.md +51 -0
- package/assets/prompts/tokens/radius.md +12 -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/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 +1163 -0
- package/assets/prompts/use-cases/feedback-progress-bar.md +427 -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 +1200 -0
- package/assets/public/ovenn-wordmark.svg +19 -0
- package/package.json +6 -2
- package/src/commands/info.js +1 -1
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
export type CanvasEdgeSide = "left" | "right" | "top" | "bottom";
|
|
2
|
+
export type CanvasEdgeVariant = "curve" | "orthogonal";
|
|
3
|
+
export type CanvasEdgePoint = { x: number; y: number };
|
|
4
|
+
export type CanvasEdgeObstacle = CanvasEdgePoint & { width: number; height: number };
|
|
5
|
+
export type CanvasEdgeEndpoint = CanvasEdgePoint & { side: CanvasEdgeSide; bounds?: CanvasEdgeObstacle };
|
|
6
|
+
export interface CanvasEdgePathOptions {
|
|
7
|
+
source: CanvasEdgeEndpoint;
|
|
8
|
+
target: CanvasEdgeEndpoint;
|
|
9
|
+
variant?: CanvasEdgeVariant;
|
|
10
|
+
/** Outward clearance in canvas coordinates; clamped to 1–160. */
|
|
11
|
+
offset?: number;
|
|
12
|
+
/** Cubic handle strength, clamped to 0.05–1. */
|
|
13
|
+
curvature?: number;
|
|
14
|
+
/** Small corner rounding for orthogonal paths, clamped to 0–48. */
|
|
15
|
+
cornerRadius?: number;
|
|
16
|
+
/** Other node bounds in the same coordinate system; orthogonal only. */
|
|
17
|
+
obstacles?: readonly CanvasEdgeObstacle[];
|
|
18
|
+
/** Clearance from node bounds in world coordinates. */
|
|
19
|
+
obstaclePadding?: number;
|
|
20
|
+
/** Previous generated orthogonal path, used as a soft stability preference. */
|
|
21
|
+
previousPath?: string;
|
|
22
|
+
}
|
|
23
|
+
export const MAX_CANVAS_EDGE_CORNER_RADIUS = 48;
|
|
24
|
+
const EPS = 1e-6;
|
|
25
|
+
const normals: Record<CanvasEdgeSide, CanvasEdgePoint> = {
|
|
26
|
+
right: { x: 1, y: 0 }, bottom: { x: 0, y: 1 }, left: { x: -1, y: 0 }, top: { x: 0, y: -1 },
|
|
27
|
+
};
|
|
28
|
+
const directions: Record<CanvasEdgeSide, number> = { right: 0, bottom: 1, left: 2, top: 3 };
|
|
29
|
+
const number = (value: number) => Number(value.toFixed(6));
|
|
30
|
+
const xy = (point: CanvasEdgePoint) => `${number(point.x)} ${number(point.y)}`;
|
|
31
|
+
const equal = (a: CanvasEdgePoint, b: CanvasEdgePoint) => Math.abs(a.x - b.x) < EPS && Math.abs(a.y - b.y) < EPS;
|
|
32
|
+
const move = (point: CanvasEdgePoint, normal: CanvasEdgePoint, distance: number): CanvasEdgePoint => ({ x: point.x + normal.x * distance, y: point.y + normal.y * distance });
|
|
33
|
+
const finite = (value: number | undefined, fallback: number, min: number, max: number) =>
|
|
34
|
+
typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : fallback;
|
|
35
|
+
|
|
36
|
+
function curve(source: CanvasEdgeEndpoint, target: CanvasEdgeEndpoint, offset: number, curvature: number): string {
|
|
37
|
+
const sn = normals[source.side], tn = normals[target.side];
|
|
38
|
+
const dx = target.x - source.x, dy = target.y - source.y;
|
|
39
|
+
const distance = Math.hypot(dx, dy);
|
|
40
|
+
const minimum = Math.min(offset, distance / 2);
|
|
41
|
+
const c1 = move(source, sn, Math.max(minimum, Math.abs(sn.x ? dx : dy) * curvature));
|
|
42
|
+
const c2 = move(target, tn, Math.max(minimum, Math.abs(tn.x ? dx : dy) * curvature));
|
|
43
|
+
const horizontal = sn.x !== 0 && tn.x !== 0;
|
|
44
|
+
const vertical = sn.y !== 0 && tn.y !== 0;
|
|
45
|
+
const facing = horizontal ? sn.x === -tn.x && dx * sn.x > 0 : vertical && sn.y === -tn.y && dy * sn.y > 0;
|
|
46
|
+
const perpendicularGap = horizontal ? Math.abs(dy) : Math.abs(dx);
|
|
47
|
+
if ((horizontal || vertical) && !facing && perpendicularGap < offset * 2) {
|
|
48
|
+
const clearance = Math.max(offset * 2, distance * 0.25);
|
|
49
|
+
const middle = horizontal
|
|
50
|
+
? { x: (source.x + target.x) / 2, y: Math.min(source.y, target.y) - clearance }
|
|
51
|
+
: { x: Math.max(source.x, target.x) + clearance, y: (source.y + target.y) / 2 };
|
|
52
|
+
const tangent = horizontal ? { x: Math.sign(dx) || 1, y: 0 } : { x: 0, y: Math.sign(dy) || 1 };
|
|
53
|
+
const middleHandle = Math.max(offset, distance * 0.2);
|
|
54
|
+
return `M ${xy(source)} C ${xy(c1)} ${xy(move(middle, tangent, -middleHandle))} ${xy(middle)} C ${xy(move(middle, tangent, middleHandle))} ${xy(c2)} ${xy(target)}`;
|
|
55
|
+
}
|
|
56
|
+
return `M ${xy(source)} C ${xy(c1)} ${xy(c2)} ${xy(target)}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function simplify(points: CanvasEdgePoint[]): CanvasEdgePoint[] {
|
|
60
|
+
const result: CanvasEdgePoint[] = [];
|
|
61
|
+
for (const point of points) {
|
|
62
|
+
if (result.length && equal(result[result.length - 1], point)) continue;
|
|
63
|
+
while (result.length > 1) {
|
|
64
|
+
const a = result[result.length - 2], b = result[result.length - 1];
|
|
65
|
+
const collinear = Math.abs((b.x - a.x) * (point.y - b.y) - (b.y - a.y) * (point.x - b.x)) < EPS;
|
|
66
|
+
const sameDirection = (b.x - a.x) * (point.x - b.x) + (b.y - a.y) * (point.y - b.y) >= 0;
|
|
67
|
+
if (!collinear || !sameDirection) break;
|
|
68
|
+
result.pop();
|
|
69
|
+
}
|
|
70
|
+
result.push(point);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Manhattan visibility grid with directional port exits and rectangular obstacles. */
|
|
76
|
+
function orthogonal(source: CanvasEdgeEndpoint, target: CanvasEdgeEndpoint, offset: number,
|
|
77
|
+
obstacles: readonly CanvasEdgeObstacle[] = [], padding = 0, previousPath = "", stemScale = 1): CanvasEdgePoint[] {
|
|
78
|
+
const sn = normals[source.side], tn = normals[target.side];
|
|
79
|
+
const distance = Math.hypot(target.x - source.x, target.y - source.y);
|
|
80
|
+
let clearance = Math.min(offset, distance / 2);
|
|
81
|
+
if (sn.x === -tn.x && sn.y === -tn.y) {
|
|
82
|
+
const forwardGap = (target.x - source.x) * sn.x + (target.y - source.y) * sn.y;
|
|
83
|
+
if (forwardGap > 0) clearance = Math.min(clearance, forwardGap / 2);
|
|
84
|
+
}
|
|
85
|
+
const validBounds = (r: CanvasEdgeObstacle | undefined): r is CanvasEdgeObstacle => !!r &&
|
|
86
|
+
[r.x, r.y, r.width, r.height, r.x + r.width, r.y + r.height].every(Number.isFinite) && r.width > 0 && r.height > 0;
|
|
87
|
+
const inflate = (r: CanvasEdgeObstacle) => ({ x: r.x - padding, y: r.y - padding, width: r.width + 2 * padding, height: r.height + 2 * padding });
|
|
88
|
+
const otherBounds = obstacles.filter(validBounds).map(inflate);
|
|
89
|
+
const sourceBounds = validBounds(source.bounds) ? inflate(source.bounds) : undefined;
|
|
90
|
+
const targetBounds = validBounds(target.bounds) ? inflate(target.bounds) : undefined;
|
|
91
|
+
const bounds = [...otherBounds, ...(sourceBounds ? [sourceBounds] : []), ...(targetBounds ? [targetBounds] : [])];
|
|
92
|
+
const inside = (p: CanvasEdgePoint, r: CanvasEdgeObstacle) => p.x > r.x + EPS && p.x < r.x + r.width - EPS && p.y > r.y + EPS && p.y < r.y + r.height - EPS;
|
|
93
|
+
const blocked = (a: CanvasEdgePoint, b: CanvasEdgePoint, rectangles = bounds) => rectangles.some(r => {
|
|
94
|
+
if (Math.abs(a.y - b.y) < EPS) return a.y > r.y + EPS && a.y < r.y + r.height - EPS && Math.max(a.x, b.x) > r.x + EPS && Math.min(a.x, b.x) < r.x + r.width - EPS;
|
|
95
|
+
return a.x > r.x + EPS && a.x < r.x + r.width - EPS && Math.max(a.y, b.y) > r.y + EPS && Math.min(a.y, b.y) < r.y + r.height - EPS;
|
|
96
|
+
});
|
|
97
|
+
const exit = (p: CanvasEdgeEndpoint, normal: CanvasEdgePoint, r: CanvasEdgeObstacle | undefined) => {
|
|
98
|
+
if (!r) return move(p, normal, Math.max(EPS * 2, clearance * stemScale));
|
|
99
|
+
const extent = normal.x > 0 ? r.x + r.width - p.x : normal.x < 0 ? p.x - r.x : normal.y > 0 ? r.y + r.height - p.y : p.y - r.y;
|
|
100
|
+
return move(p, normal, Math.max(EPS * 2, extent, clearance * stemScale));
|
|
101
|
+
};
|
|
102
|
+
const start = exit(source, sn, sourceBounds), end = exit(target, tn, targetBounds);
|
|
103
|
+
// Only each port's own body may be crossed by its escape segment.
|
|
104
|
+
if (blocked(source, start, [...otherBounds, ...(targetBounds ? [targetBounds] : [])]) ||
|
|
105
|
+
blocked(target, end, [...otherBounds, ...(sourceBounds ? [sourceBounds] : [])])) return [];
|
|
106
|
+
if (bounds.some(r => inside(start, r) || inside(end, r))) return [];
|
|
107
|
+
if (equal(start, end)) return simplify([source, start, target]);
|
|
108
|
+
const mx = (start.x + end.x) / 2, my = (start.y + end.y) / 2;
|
|
109
|
+
const unique = (values: number[]) => [...new Set(values)].sort((a, b) => a - b);
|
|
110
|
+
const baseX = [...bounds.flatMap(r => [r.x, r.x + r.width]), source.x, target.x, start.x, end.x, mx,
|
|
111
|
+
Math.min(source.x, target.x, start.x, end.x) - offset, Math.max(source.x, target.x, start.x, end.x) + offset];
|
|
112
|
+
const baseY = [...bounds.flatMap(r => [r.y, r.y + r.height]), source.y, target.y, start.y, end.y, my,
|
|
113
|
+
Math.min(source.y, target.y, start.y, end.y) - offset, Math.max(source.y, target.y, start.y, end.y) + offset];
|
|
114
|
+
// Rendered paths are rounded to six decimals; measured positions can drift by
|
|
115
|
+
// a few thousandths after zoom. Do not turn that noise into tiny new elbows.
|
|
116
|
+
const snapHistory = (value: number, coordinates: number[]) => coordinates.find(at => Math.abs(at - value) < .001) ?? value;
|
|
117
|
+
const previous = previousPath ? simplify(routeCorners(previousPath).map(p => ({ x: snapHistory(p.x, baseX), y: snapHistory(p.y, baseY) }))) : [];
|
|
118
|
+
const xs = unique([...baseX, ...previous.map(p => p.x)]);
|
|
119
|
+
const ys = unique([...baseY, ...previous.map(p => p.y)]);
|
|
120
|
+
const width = xs.length;
|
|
121
|
+
const at = (x: number, y: number) => y * width + x;
|
|
122
|
+
const point = (index: number): CanvasEdgePoint => ({ x: xs[index % width], y: ys[Math.floor(index / width)] });
|
|
123
|
+
const startIndex = at(xs.indexOf(start.x), ys.indexOf(start.y));
|
|
124
|
+
const endIndex = at(xs.indexOf(end.x), ys.indexOf(end.y));
|
|
125
|
+
const startKey = startIndex * 4 + directions[source.side];
|
|
126
|
+
type State = { key: number; cost: number };
|
|
127
|
+
const queue: State[] = [{ key: startKey, cost: 0 }];
|
|
128
|
+
const less = (a: State, b: State) => a.cost < b.cost || (a.cost === b.cost && a.key < b.key);
|
|
129
|
+
const push = (state: State) => {
|
|
130
|
+
queue.push(state);
|
|
131
|
+
for (let i = queue.length - 1; i > 0;) {
|
|
132
|
+
const p = (i - 1) >> 1;
|
|
133
|
+
if (!less(queue[i], queue[p])) break;
|
|
134
|
+
[queue[i], queue[p]] = [queue[p], queue[i]]; i = p;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const pop = () => {
|
|
138
|
+
const first = queue[0], last = queue.pop()!;
|
|
139
|
+
if (queue.length) {
|
|
140
|
+
queue[0] = last;
|
|
141
|
+
for (let i = 0;;) {
|
|
142
|
+
let next = i; const l = i * 2 + 1, r = l + 1;
|
|
143
|
+
if (l < queue.length && less(queue[l], queue[next])) next = l;
|
|
144
|
+
if (r < queue.length && less(queue[r], queue[next])) next = r;
|
|
145
|
+
if (next === i) break;
|
|
146
|
+
[queue[i], queue[next]] = [queue[next], queue[i]]; i = next;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return first;
|
|
150
|
+
};
|
|
151
|
+
const onPrevious = (a: CanvasEdgePoint, b: CanvasEdgePoint) => previous.some((p, i) => {
|
|
152
|
+
if (!i) return false;
|
|
153
|
+
const q = previous[i - 1];
|
|
154
|
+
return Math.abs(a.y - b.y) < EPS ? Math.abs(p.y - q.y) < EPS && Math.abs(a.y - p.y) < EPS && Math.min(a.x, b.x) >= Math.min(p.x, q.x) - EPS && Math.max(a.x, b.x) <= Math.max(p.x, q.x) + EPS :
|
|
155
|
+
Math.abs(p.x - q.x) < EPS && Math.abs(a.x - p.x) < EPS && Math.min(a.y, b.y) >= Math.min(p.y, q.y) - EPS && Math.max(a.y, b.y) <= Math.max(p.y, q.y) + EPS;
|
|
156
|
+
});
|
|
157
|
+
const costs = new Map<number, number>([[startKey, 0]]);
|
|
158
|
+
const parents = new Map<number, number>();
|
|
159
|
+
const visited = new Set<number>();
|
|
160
|
+
let bestKey: number | undefined, bestCost = Infinity;
|
|
161
|
+
const turnCost = (p: CanvasEdgePoint) => offset + (Math.abs(p.x - mx) + Math.abs(p.y - my)) * 0.001;
|
|
162
|
+
while (queue.length) {
|
|
163
|
+
const state = pop()!;
|
|
164
|
+
if (visited.has(state.key)) continue;
|
|
165
|
+
if (state.cost > bestCost) break;
|
|
166
|
+
visited.add(state.key);
|
|
167
|
+
const index = Math.floor(state.key / 4), incoming = state.key % 4, current = point(index);
|
|
168
|
+
if (index === endIndex) {
|
|
169
|
+
const finalDirection = (directions[target.side] + 2) % 4;
|
|
170
|
+
if (incoming !== (finalDirection + 2) % 4) {
|
|
171
|
+
const total = state.cost + (incoming === finalDirection ? 0 : turnCost(current));
|
|
172
|
+
if (total < bestCost) { bestCost = total; bestKey = state.key; }
|
|
173
|
+
}
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const x = index % width, y = Math.floor(index / width);
|
|
177
|
+
const neighbors = [[x + 1, y], [x, y + 1], [x - 1, y], [x, y - 1]];
|
|
178
|
+
neighbors.forEach(([nx, ny], direction) => {
|
|
179
|
+
if (nx < 0 || nx >= xs.length || ny < 0 || ny >= ys.length || direction === (incoming + 2) % 4) return;
|
|
180
|
+
const nextIndex = at(nx, ny), next = point(nextIndex);
|
|
181
|
+
if ((equal(next, source) || equal(next, target)) && nextIndex !== endIndex) return;
|
|
182
|
+
if (blocked(current, next)) return;
|
|
183
|
+
const key = nextIndex * 4 + direction;
|
|
184
|
+
const length = Math.abs(next.x - current.x) + Math.abs(next.y - current.y);
|
|
185
|
+
const cost = state.cost + length * (onPrevious(current, next) ? .8 : 1) + (direction === incoming ? 0 : turnCost(current));
|
|
186
|
+
if (cost + EPS < (costs.get(key) ?? Infinity)) { costs.set(key, cost); parents.set(key, state.key); push({ key, cost }); }
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (bestKey === undefined) return [];
|
|
190
|
+
const middle: CanvasEdgePoint[] = [];
|
|
191
|
+
for (let key: number | undefined = bestKey; key !== undefined; key = parents.get(key)) middle.push(point(Math.floor(key / 4)));
|
|
192
|
+
return simplify([source, ...middle.reverse(), target]);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Sample only generated M/L/C paths to reject compact cubic loops. */
|
|
196
|
+
function sample(d: string): CanvasEdgePoint[] {
|
|
197
|
+
const points: CanvasEdgePoint[] = [];
|
|
198
|
+
let current: CanvasEdgePoint = { x: 0, y: 0 };
|
|
199
|
+
for (const match of d.matchAll(/([MLC])([^MLC]*)/g)) {
|
|
200
|
+
const n = (match[2].match(/-?\d+(?:\.\d+)?(?:e[+-]?\d+)?/gi) ?? []).map(Number);
|
|
201
|
+
if (match[1] !== "C") { current = { x: n[0], y: n[1] }; points.push(current); continue; }
|
|
202
|
+
const start = current;
|
|
203
|
+
for (let step = 1; step <= 32; step++) {
|
|
204
|
+
const t = step / 32, u = 1 - t;
|
|
205
|
+
points.push({ x: u ** 3 * start.x + 3 * u * u * t * n[0] + 3 * u * t * t * n[2] + t ** 3 * n[4],
|
|
206
|
+
y: u ** 3 * start.y + 3 * u * u * t * n[1] + 3 * u * t * t * n[3] + t ** 3 * n[5] });
|
|
207
|
+
}
|
|
208
|
+
current = { x: n[4], y: n[5] };
|
|
209
|
+
}
|
|
210
|
+
return points.filter((point, index) => !index || !equal(point, points[index - 1]));
|
|
211
|
+
}
|
|
212
|
+
function selfIntersects(d: string): boolean {
|
|
213
|
+
const points = sample(d);
|
|
214
|
+
const cross = (a: CanvasEdgePoint, b: CanvasEdgePoint, c: CanvasEdgePoint) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
|
215
|
+
const between = (a: CanvasEdgePoint, b: CanvasEdgePoint, c: CanvasEdgePoint) => c.x >= Math.min(a.x, b.x) - EPS && c.x <= Math.max(a.x, b.x) + EPS && c.y >= Math.min(a.y, b.y) - EPS && c.y <= Math.max(a.y, b.y) + EPS;
|
|
216
|
+
for (let i = 1; i < points.length; i++) for (let j = i + 2; j < points.length; j++) {
|
|
217
|
+
const a = points[i - 1], b = points[i], c = points[j - 1], e = points[j];
|
|
218
|
+
const abC = cross(a, b, c), abE = cross(a, b, e), ceA = cross(c, e, a), ceB = cross(c, e, b);
|
|
219
|
+
if (((abC > 0 && abE < 0) || (abC < 0 && abE > 0)) && ((ceA > 0 && ceB < 0) || (ceA < 0 && ceB > 0))) return true;
|
|
220
|
+
if ((Math.abs(abC) < EPS && between(a, b, c)) || (Math.abs(abE) < EPS && between(a, b, e)) ||
|
|
221
|
+
(Math.abs(ceA) < EPS && between(c, e, a)) || (Math.abs(ceB) < EPS && between(c, e, b))) return true;
|
|
222
|
+
}
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
/** Conservative Bezier/rectangle test. A cubic stays inside its control hull. */
|
|
226
|
+
function cornerHits(points: CanvasEdgePoint[], bounds: CanvasEdgeObstacle, depth = 0): boolean {
|
|
227
|
+
const xs = points.map(p => p.x), ys = points.map(p => p.y);
|
|
228
|
+
if (Math.max(...xs) <= bounds.x + EPS || Math.min(...xs) >= bounds.x + bounds.width - EPS ||
|
|
229
|
+
Math.max(...ys) <= bounds.y + EPS || Math.min(...ys) >= bounds.y + bounds.height - EPS) return false;
|
|
230
|
+
if (depth >= 18) return true;
|
|
231
|
+
const mid = (a: CanvasEdgePoint, b: CanvasEdgePoint) => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 });
|
|
232
|
+
const a = mid(points[0], points[1]), b = mid(points[1], points[2]), c = mid(points[2], points[3]);
|
|
233
|
+
const d = mid(a, b), e = mid(b, c), f = mid(d, e);
|
|
234
|
+
return cornerHits([points[0], a, d, f], bounds, depth + 1) || cornerHits([f, e, c, points[3]], bounds, depth + 1);
|
|
235
|
+
}
|
|
236
|
+
function rounded(points: CanvasEdgePoint[], radius: number, obstacles: readonly CanvasEdgeObstacle[] = []): string {
|
|
237
|
+
if (!points.length) return "";
|
|
238
|
+
let d = `M ${xy(points[0])}`;
|
|
239
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
240
|
+
const a = points[i - 1], b = points[i], c = points[i + 1];
|
|
241
|
+
const before = Math.hypot(b.x - a.x, b.y - a.y), after = Math.hypot(c.x - b.x, c.y - b.y);
|
|
242
|
+
let r = Math.min(radius, before / 2, after / 2);
|
|
243
|
+
const incoming = { x: (b.x - a.x) / before, y: (b.y - a.y) / before };
|
|
244
|
+
const outgoing = { x: (c.x - b.x) / after, y: (c.y - b.y) / after };
|
|
245
|
+
const controls = (size: number) => {
|
|
246
|
+
const start = move(b, incoming, -size), end = move(b, outgoing, size), k = size * 0.5522847498;
|
|
247
|
+
return [start, move(start, incoming, k), move(end, outgoing, -k), end];
|
|
248
|
+
};
|
|
249
|
+
let curve = controls(r);
|
|
250
|
+
// Shrink only the obstructed elbow; other bends keep the requested radius.
|
|
251
|
+
while (r > 0 && obstacles.some(bounds => cornerHits(curve, bounds))) {
|
|
252
|
+
r = r < .25 ? 0 : r / 2;
|
|
253
|
+
curve = controls(r);
|
|
254
|
+
}
|
|
255
|
+
if (!r) { d += ` L ${xy(b)}`; continue; }
|
|
256
|
+
d += ` L ${xy(curve[0])} C ${xy(curve[1])} ${xy(curve[2])} ${xy(curve[3])}`;
|
|
257
|
+
}
|
|
258
|
+
return d + ` L ${xy(points[points.length - 1])}`;
|
|
259
|
+
}
|
|
260
|
+
const polyline = (points: CanvasEdgePoint[]) => points.map((p, i) => `${i ? "L" : "M"} ${xy(p)}`).join(" ");
|
|
261
|
+
|
|
262
|
+
/** Path order is always source → target, including reversed and vertical layouts. */
|
|
263
|
+
export function getCanvasEdgePath({ source, target, variant = "curve", offset, curvature, cornerRadius, obstacles = [], obstaclePadding, previousPath }: CanvasEdgePathOptions): string {
|
|
264
|
+
if (!source || !target || !Object.hasOwn(normals, source.side) || !Object.hasOwn(normals, target.side)) return "";
|
|
265
|
+
if (![source.x, source.y, target.x, target.y].every(Number.isFinite)) return "";
|
|
266
|
+
const distance = Math.hypot(target.x - source.x, target.y - source.y);
|
|
267
|
+
if (!Number.isFinite(distance) || distance < EPS) return "";
|
|
268
|
+
const gap = finite(offset, 24, 1, 160), bend = finite(curvature, 0.45, 0.05, 1);
|
|
269
|
+
if (variant === "orthogonal") {
|
|
270
|
+
// Route hysteresis follows a translated pair instead of pinning its elbows
|
|
271
|
+
// to their old world positions. Obstacles are still checked below.
|
|
272
|
+
if (previousPath) {
|
|
273
|
+
const history = routeCorners(previousPath);
|
|
274
|
+
if (history.length > 1) {
|
|
275
|
+
const first = history[0], last = history[history.length - 1];
|
|
276
|
+
const dx = source.x - first.x, dy = source.y - first.y;
|
|
277
|
+
const next = history[1], before = history[history.length - 2];
|
|
278
|
+
const sourceNormal = normals[source.side], targetNormal = normals[target.side];
|
|
279
|
+
const sameDirections = (next.x - first.x) * sourceNormal.x + (next.y - first.y) * sourceNormal.y > 0
|
|
280
|
+
&& (before.x - last.x) * targetNormal.x + (before.y - last.y) * targetNormal.y > 0;
|
|
281
|
+
if (sameDirections && Math.abs(target.x - last.x - dx) < EPS && Math.abs(target.y - last.y - dy) < EPS) {
|
|
282
|
+
previousPath = polyline(history.map(point => ({ x: point.x + dx, y: point.y + dy })));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const radius = finite(cornerRadius, 6, 0, MAX_CANVAS_EDGE_CORNER_RADIUS);
|
|
287
|
+
// Keep routing stable when radius changes. Each elbow is collision-checked
|
|
288
|
+
// separately, rather than inflating every body by the full requested radius.
|
|
289
|
+
const routingRadius = Math.min(radius, 6);
|
|
290
|
+
const padding = finite(obstaclePadding, 12, 0, 80) + routingRadius;
|
|
291
|
+
const collisionBounds = [...obstacles, source.bounds, target.bounds].filter((r): r is CanvasEdgeObstacle => !!r &&
|
|
292
|
+
[r.x, r.y, r.width, r.height].every(Number.isFinite) && r.width > 0 && r.height > 0);
|
|
293
|
+
const routeLength = (points: CanvasEdgePoint[]) => points.slice(1).reduce((sum, point, i) => sum + Math.abs(point.x - points[i].x) + Math.abs(point.y - points[i].y), 0);
|
|
294
|
+
const direct = Math.abs(target.x - source.x) + Math.abs(target.y - source.y);
|
|
295
|
+
let best: CanvasEdgePoint[] = [], bestLength = Infinity;
|
|
296
|
+
for (const margin of [...new Set([padding, Math.min(padding, routingRadius + 2)])]) {
|
|
297
|
+
const points = orthogonal(source, target, gap, obstacles, margin, previousPath);
|
|
298
|
+
if (!points.length) continue;
|
|
299
|
+
const length = routeLength(points);
|
|
300
|
+
if (length < bestLength) { best = points; bestLength = length; }
|
|
301
|
+
// Prefer generous clearance, except when inflated bodies force a large detour.
|
|
302
|
+
if (length <= direct * 1.6 + gap * 2) break;
|
|
303
|
+
}
|
|
304
|
+
if (best.length) return radius > 0 ? rounded(best, radius, collisionBounds) : polyline(best);
|
|
305
|
+
// Relax only when full port stems cannot fit. Keep rounding on every
|
|
306
|
+
// unobstructed bend instead of turning the entire fallback into a polyline.
|
|
307
|
+
for (const stemScale of [1, .5, .25, 0]) {
|
|
308
|
+
const points = orthogonal(source, target, gap, obstacles, 2, previousPath, stemScale);
|
|
309
|
+
if (points.length) return radius > 0 ? rounded(points, radius, collisionBounds) : polyline(points);
|
|
310
|
+
}
|
|
311
|
+
return "";
|
|
312
|
+
}
|
|
313
|
+
const candidate = curve(source, target, gap, bend);
|
|
314
|
+
if (!selfIntersects(candidate)) return candidate;
|
|
315
|
+
const points = orthogonal(source, target, gap);
|
|
316
|
+
for (const factor of [2, 1, 0.5, 0.25]) {
|
|
317
|
+
const smooth = rounded(points, gap * factor);
|
|
318
|
+
if (!selfIntersects(smooth)) return smooth;
|
|
319
|
+
}
|
|
320
|
+
return polyline(points);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Recover the Manhattan corners of our own M/L/C output for route hysteresis. */
|
|
324
|
+
function routeCorners(path: string): CanvasEdgePoint[] {
|
|
325
|
+
const points: CanvasEdgePoint[] = [];
|
|
326
|
+
for (const match of path.matchAll(/([MLC])([^MLC]*)/g)) {
|
|
327
|
+
const n = (match[2].match(/-?\d+(?:\.\d+)?(?:e[+-]?\d+)?/gi) ?? []).map(Number);
|
|
328
|
+
if (!n.every(Number.isFinite)) return [];
|
|
329
|
+
if (match[1] === "C" && points.length) {
|
|
330
|
+
const start = points[points.length - 1];
|
|
331
|
+
const horizontal = Math.abs(n[0] - start.x) > EPS;
|
|
332
|
+
points.push({ x: horizontal ? n[4] : start.x, y: horizontal ? start.y : n[5] });
|
|
333
|
+
points.push({ x: n[4], y: n[5] });
|
|
334
|
+
} else if (n.length >= 2) points.push({ x: n[0], y: n[1] });
|
|
335
|
+
}
|
|
336
|
+
return simplify(points);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** Trim only the final straight segment; visible/arrow/hit routes share all bends. */
|
|
340
|
+
export function trimCanvasEdgePath(path: string, clearance: number): string {
|
|
341
|
+
const commands = [...path.matchAll(/([MLC])([^MLC]*)/g)];
|
|
342
|
+
if (commands.length < 2 || commands[commands.length - 1][1] !== "L") return path;
|
|
343
|
+
const coordinates = (text: string) => (text.match(/-?\d+(?:\.\d+)?(?:e[+-]?\d+)?/gi) ?? []).map(Number);
|
|
344
|
+
const last = commands[commands.length - 1], end = coordinates(last[2]);
|
|
345
|
+
const before = coordinates(commands[commands.length - 2][2]).slice(-2);
|
|
346
|
+
const length = Math.hypot(end[0] - before[0], end[1] - before[1]);
|
|
347
|
+
if (length < EPS) return path;
|
|
348
|
+
const trim = Math.min(clearance, length / 2);
|
|
349
|
+
return path.slice(0, last.index) + `L ${xy({ x: end[0] + (before[0] - end[0]) * trim / length, y: end[1] + (before[1] - end[1]) * trim / length })}`;
|
|
350
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CanvasEdge } from "./CanvasEdge";
|
|
2
|
+
export type { CanvasEdgeProps, CanvasEdgeLineStyle, CanvasEdgeStatus } from "./CanvasEdge";
|
|
3
|
+
export { getCanvasEdgePath } from "./geometry";
|
|
4
|
+
export type { CanvasEdgeObstacle, CanvasEdgeSide, CanvasEdgePoint, CanvasEdgeEndpoint, CanvasEdgeVariant, CanvasEdgePathOptions } from "./geometry";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type ActivationEvent = {
|
|
2
|
+
defaultPrevented: boolean;
|
|
3
|
+
stopPropagation(): void;
|
|
4
|
+
preventDefault(): void;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/** Cancelling edge selection must not turn the same gesture into a canvas-background action. */
|
|
8
|
+
export function activateCanvasEdge<E extends ActivationEvent>(event: E, select: () => void, before?: (event: E) => void, keyboard = false): void {
|
|
9
|
+
event.stopPropagation();
|
|
10
|
+
before?.(event);
|
|
11
|
+
if (event.defaultPrevented) return;
|
|
12
|
+
if (keyboard) event.preventDefault();
|
|
13
|
+
select();
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[data-slot="canvas-edge"] {
|
|
2
|
+
--edge-color: color-mix(in oklab, var(--border-strong) 95%, var(--fg) 5%);
|
|
3
|
+
--edge-hover-color: var(--fg-muted);
|
|
4
|
+
--edge-selected-color: var(--fg);
|
|
5
|
+
--edge-width: 1.5px;
|
|
6
|
+
--edge-arrow-width: 1.5px;
|
|
7
|
+
--edge-hit-width: 16px;
|
|
8
|
+
--edge-disabled-opacity: 0.4;
|
|
9
|
+
--edge-preview-opacity: 0.65;
|
|
10
|
+
--edge-track-opacity: 1;
|
|
11
|
+
--edge-running-track-opacity: 0.24;
|
|
12
|
+
--edge-running-selected-opacity: 0.5;
|
|
13
|
+
--edge-success-color: var(--success);
|
|
14
|
+
--edge-error-color: var(--destructive);
|
|
15
|
+
--edge-dash: none;
|
|
16
|
+
--edge-dashed-pattern: 6 6;
|
|
17
|
+
--edge-preview-pattern: 4 5;
|
|
18
|
+
--edge-flow-span: 80px;
|
|
19
|
+
--edge-flow-fade-fraction: 0.8;
|
|
20
|
+
--edge-flow-fade-step: calc(var(--edge-flow-span) * var(--edge-flow-fade-fraction) / 47);
|
|
21
|
+
--edge-flow-layer-opacity: 0.07;
|
|
22
|
+
--edge-flow-repeat: 400px;
|
|
23
|
+
--edge-flow-end: -100px;
|
|
24
|
+
--edge-flow-duration: calc(1500ms * var(--motion-scale));
|
|
25
|
+
--edge-flow-easing: cubic-bezier(0.65, 0, 0.25, 1);
|
|
26
|
+
--edge-mask-color: var(--fixed-white);
|
|
27
|
+
--edge-mask-padding: 2px;
|
|
28
|
+
--edge-transition-duration: calc(140ms * var(--motion-scale));
|
|
29
|
+
}
|