@zukhruf/diagram 0.3.32 → 0.3.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -52
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/compiler/diagram-compile.d.ts +3 -4
- package/dist/lib/compiler/diagram-compile.d.ts.map +1 -1
- package/dist/lib/compiler/diagram-compile.js +85 -370
- package/dist/lib/compiler/diagram-compile.js.map +1 -1
- package/dist/lib/layouts/graph/attach.d.ts +25 -0
- package/dist/lib/layouts/graph/attach.d.ts.map +1 -0
- package/dist/lib/layouts/graph/attach.js +272 -0
- package/dist/lib/layouts/graph/attach.js.map +1 -0
- package/dist/lib/layouts/graph/connections.d.ts +45 -0
- package/dist/lib/layouts/graph/connections.d.ts.map +1 -0
- package/dist/lib/layouts/graph/connections.js +138 -0
- package/dist/lib/layouts/graph/connections.js.map +1 -0
- package/dist/lib/layouts/graph/graph-layout-result.d.ts +5 -3
- package/dist/lib/layouts/graph/graph-layout-result.d.ts.map +1 -1
- package/dist/lib/layouts/graph/graph-layout-result.js.map +1 -1
- package/dist/lib/layouts/graph/gutters.js +41 -22
- package/dist/lib/layouts/graph/gutters.js.map +1 -1
- package/dist/lib/layouts/graph/labels.d.ts +23 -0
- package/dist/lib/layouts/graph/labels.d.ts.map +1 -0
- package/dist/lib/layouts/graph/labels.js +120 -0
- package/dist/lib/layouts/graph/labels.js.map +1 -0
- package/dist/lib/layouts/graph/layout.d.ts +1 -1
- package/dist/lib/layouts/graph/layout.d.ts.map +1 -1
- package/dist/lib/layouts/graph/layout.js +37 -12
- package/dist/lib/layouts/graph/layout.js.map +1 -1
- package/dist/lib/layouts/graph/measure.d.ts +15 -11
- package/dist/lib/layouts/graph/measure.d.ts.map +1 -1
- package/dist/lib/layouts/graph/measure.js +82 -38
- package/dist/lib/layouts/graph/measure.js.map +1 -1
- package/dist/lib/layouts/graph/min-heap.d.ts +8 -0
- package/dist/lib/layouts/graph/min-heap.d.ts.map +1 -0
- package/dist/lib/layouts/graph/min-heap.js +56 -0
- package/dist/lib/layouts/graph/min-heap.js.map +1 -0
- package/dist/lib/layouts/graph/node-content.d.ts +2 -3
- package/dist/lib/layouts/graph/node-content.d.ts.map +1 -1
- package/dist/lib/layouts/graph/node-content.js +67 -47
- package/dist/lib/layouts/graph/node-content.js.map +1 -1
- package/dist/lib/layouts/graph/path.d.ts +6 -0
- package/dist/lib/layouts/graph/path.d.ts.map +1 -0
- package/dist/lib/layouts/graph/path.js +53 -0
- package/dist/lib/layouts/graph/path.js.map +1 -0
- package/dist/lib/layouts/graph/round.d.ts +11 -0
- package/dist/lib/layouts/graph/round.d.ts.map +1 -0
- package/dist/lib/layouts/graph/round.js +181 -0
- package/dist/lib/layouts/graph/round.js.map +1 -0
- package/dist/lib/layouts/graph/route-search.d.ts +34 -0
- package/dist/lib/layouts/graph/route-search.d.ts.map +1 -0
- package/dist/lib/layouts/graph/route-search.js +208 -0
- package/dist/lib/layouts/graph/route-search.js.map +1 -0
- package/dist/lib/layouts/graph/route.d.ts +20 -0
- package/dist/lib/layouts/graph/route.d.ts.map +1 -0
- package/dist/lib/layouts/graph/route.js +276 -0
- package/dist/lib/layouts/graph/route.js.map +1 -0
- package/dist/lib/layouts/graph/sides.d.ts +28 -0
- package/dist/lib/layouts/graph/sides.d.ts.map +1 -0
- package/dist/lib/layouts/graph/sides.js +98 -0
- package/dist/lib/layouts/graph/sides.js.map +1 -0
- package/dist/lib/layouts/timeline/timeline-layout.d.ts +2 -1
- package/dist/lib/layouts/timeline/timeline-layout.d.ts.map +1 -1
- package/dist/lib/layouts/timeline/timeline-layout.js +9 -4
- package/dist/lib/layouts/timeline/timeline-layout.js.map +1 -1
- package/dist/lib/model/diagram-ir.d.ts +19 -156
- package/dist/lib/model/diagram-ir.d.ts.map +1 -1
- package/dist/lib/model/diagram-ir.js.map +1 -1
- package/dist/lib/model/validate-graph.d.ts +7 -0
- package/dist/lib/model/validate-graph.d.ts.map +1 -0
- package/dist/lib/model/validate-graph.js +54 -0
- package/dist/lib/model/validate-graph.js.map +1 -0
- package/dist/lib/react/Diagram.d.ts +3 -9
- package/dist/lib/react/Diagram.d.ts.map +1 -1
- package/dist/lib/react/Diagram.js +1 -13
- package/dist/lib/react/Diagram.js.map +1 -1
- package/dist/lib/react/diagram-types.d.ts +17 -46
- package/dist/lib/react/diagram-types.d.ts.map +1 -1
- package/dist/lib/react/diagram-types.js.map +1 -1
- package/dist/lib/renderers/canvas/graph-canvas.d.ts +2 -5
- package/dist/lib/renderers/canvas/graph-canvas.d.ts.map +1 -1
- package/dist/lib/renderers/canvas/graph-canvas.js +68 -43
- package/dist/lib/renderers/canvas/graph-canvas.js.map +1 -1
- package/dist/lib/renderers/html/graph-html.d.ts +2 -3
- package/dist/lib/renderers/html/graph-html.d.ts.map +1 -1
- package/dist/lib/renderers/html/graph-html.js +298 -289
- package/dist/lib/renderers/html/graph-html.js.map +1 -1
- package/dist/lib/renderers/shared/graph-parts.d.ts +3 -1
- package/dist/lib/renderers/shared/graph-parts.d.ts.map +1 -1
- package/dist/lib/renderers/shared/graph-parts.js +350 -418
- package/dist/lib/renderers/shared/graph-parts.js.map +1 -1
- package/dist/lib/renderers/shared/node-parts.d.ts +5 -6
- package/dist/lib/renderers/shared/node-parts.d.ts.map +1 -1
- package/dist/lib/renderers/shared/node-parts.js +112 -190
- package/dist/lib/renderers/shared/node-parts.js.map +1 -1
- package/dist/lib/renderers/shared/run-spans.js +2 -2
- package/dist/lib/renderers/shared/run-spans.js.map +1 -1
- package/dist/lib/renderers/shared/text-runs.d.ts +0 -6
- package/dist/lib/renderers/shared/text-runs.d.ts.map +1 -1
- package/dist/lib/renderers/shared/text-runs.js +0 -12
- package/dist/lib/renderers/shared/text-runs.js.map +1 -1
- package/dist/lib/renderers/svg/graph-svg.d.ts +1 -3
- package/dist/lib/renderers/svg/graph-svg.d.ts.map +1 -1
- package/dist/lib/renderers/svg/graph-svg.js +66 -80
- package/dist/lib/renderers/svg/graph-svg.js.map +1 -1
- package/dist/lib/renderers/svg/timeline-svg.d.ts.map +1 -1
- package/dist/lib/renderers/svg/timeline-svg.js +7 -5
- package/dist/lib/renderers/svg/timeline-svg.js.map +1 -1
- package/package.json +1 -1
- package/dist/lib/layouts/graph/graph-layout.d.ts +0 -154
- package/dist/lib/layouts/graph/graph-layout.d.ts.map +0 -1
- package/dist/lib/layouts/graph/graph-layout.js +0 -2340
- package/dist/lib/layouts/graph/graph-layout.js.map +0 -1
- package/dist/lib/layouts/graph/legacy-graph-layout.d.ts +0 -6
- package/dist/lib/layouts/graph/legacy-graph-layout.d.ts.map +0 -1
- package/dist/lib/layouts/graph/legacy-graph-layout.js +0 -542
- package/dist/lib/layouts/graph/legacy-graph-layout.js.map +0 -1
- package/dist/lib/layouts/text-metrics.d.ts +0 -7
- package/dist/lib/layouts/text-metrics.d.ts.map +0 -1
- package/dist/lib/layouts/text-metrics.js +0 -40
- package/dist/lib/layouts/text-metrics.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagram-compile.js","names":["Children","Fragment","isValidElement","parseEndpointRef","DIAGRAM_PRIMITIVE","Symbol","for","PRIMITIVE_KINDS","primitive","kind","Object","assign","primitiveKind","node","type","isPrimitiveKind","value","some","emptyCompileResult","nodes","edges","groups","annotations","lanes","signals","frames","guides","mergeCompileResults","target","source","push","compileGraph","children","layout","result","compileChildren","length","Error","compileTimeline","frame","context","forEach","child","undefined","isTextNode","String","trim","name","isNodeKind","compileNode","isEdgeKind","compileEdge","group","compileGroup","compileText","compileLane","compileSignal","compileFrame","requirePrimitiveProps","props","label","compileLabelChildren","hasLabel","id","row","col","width","height","groupId","hidden","fontSize","fontWeight","textColor","accent","textAlign","connectable","tone","caption","captionSide","captionOffset","captionColor","captionFontSize","captionFontWeight","colSpan","rx","texture","icon","iconSize","ports","appliancePorts","antenna","slant","_children","nodeProps","labelChildren","content","splitNodeContent","nodeFrame","CONTENT_HOSTS","Set","has","explicit","badgeLabel","edgeProps","lines","waypoints","entrySide","exitSide","entryGap","edgeChild","text","edgeChildKind","lineText","entry","side","gap","normalizeStringLines","headless","Array","isArray","map","line","filter","Boolean","bounds","rowStart","rowEnd","colStart","colEnd","inferGroupBounds","normalizeGroupLabel","labelAlign","labelSide","fill","parent","tight","tightX","tightY","titleBand","titleGap","padding","dividers","grouped","childGroups","emptyGroupBounds","includeGroupBounds","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","Math","min","max","textProps","compileStringLines","normalizeBoxed","boxed","signalProps","normalizedBoxed","frameChild","owner","toArray","part","join","validateGraph","ir","nodeIds","add","groupIds","guideIds","guide","nodesById","Map","groupsById","bodyFontSize","isFinite","bodyLineGap","edge","route","labelLineGap","exitOffset","entryOffset","stubDistance","nodeId","sourceNodeId","portId","sourcePortId","from","targetNodeId","targetPortId","to","get","port","annotation","lineGap","validateTimeline","laneIds","lane","signal"],"sources":["../../../src/lib/compiler/diagram-compile.ts"],"sourcesContent":["import {\n Children,\n Fragment,\n type ReactElement,\n type ReactNode,\n isValidElement,\n} from 'react';\n\nimport type {\n DiagramAnnotation,\n DiagramEdge,\n DiagramFrameElement,\n DiagramGraphIR,\n DiagramGraphLayout,\n DiagramGuide,\n DiagramLabelLine,\n DiagramLane,\n DiagramNode,\n DiagramSignal,\n DiagramSignalBox,\n DiagramTimelineSpec,\n DiagramWaypoint,\n} from '../model/diagram-ir.ts';\nimport { parseEndpointRef } from '../model/endpoint-ref.ts';\nimport type {\n DiagramApplianceProps,\n DiagramConnectorProps,\n DiagramContentProps,\n DiagramEdgeProps,\n DiagramEntryProps,\n DiagramExitProps,\n DiagramFrameProps,\n DiagramGroupProps,\n DiagramGuideProps,\n DiagramJunctionProps,\n DiagramLaneProps,\n DiagramLineProps,\n DiagramMarkerProps,\n DiagramNodeProps,\n DiagramPhantomProps,\n DiagramSignalProps,\n DiagramTextProps,\n DiagramWaypointProps,\n} from '../react/diagram-types.ts';\n\nexport const DIAGRAM_PRIMITIVE = Symbol.for('@zukhruf/diagram/primitive');\n\nconst PRIMITIVE_KINDS = [\n 'node',\n 'box',\n 'card',\n 'port',\n 'label',\n 'float',\n 'phantom',\n 'appliance',\n 'connector',\n 'junction',\n 'edge',\n 'arrow',\n 'wire',\n 'group',\n 'text',\n 'line',\n 'lane',\n 'signal',\n 'frame',\n 'marker',\n 'guide',\n 'waypoint',\n 'entry',\n 'exit',\n 'content',\n] as const;\n\nexport type PrimitiveKind = (typeof PRIMITIVE_KINDS)[number];\n\nexport type PrimitiveComponent<P> = ((props: P) => null) & {\n [DIAGRAM_PRIMITIVE]: PrimitiveKind;\n};\n\nexport function primitive<P>(kind: PrimitiveKind): PrimitiveComponent<P> {\n return Object.assign(() => null, { [DIAGRAM_PRIMITIVE]: kind });\n}\n\nexport function primitiveKind(node: ReactNode): PrimitiveKind | null {\n if (!isValidElement(node)) return null;\n const { type } = node;\n if (typeof type !== 'function' || !(DIAGRAM_PRIMITIVE in type)) return null;\n const kind = type[DIAGRAM_PRIMITIVE];\n return isPrimitiveKind(kind) ? kind : null;\n}\n\nfunction isPrimitiveKind(value: unknown): value is PrimitiveKind {\n return PRIMITIVE_KINDS.some((kind) => kind === value);\n}\n\ntype CompileContext = {\n groupId?: string;\n};\n\ntype CompileResult = {\n nodes: DiagramNode[];\n edges: DiagramEdge[];\n groups: DiagramGraphIR['groups'];\n annotations: DiagramAnnotation[];\n lanes: DiagramLane[];\n signals: DiagramSignal[];\n frames: DiagramFrameElement[];\n guides: DiagramGuide[];\n};\n\nfunction emptyCompileResult(): CompileResult {\n return {\n nodes: [],\n edges: [],\n groups: [],\n annotations: [],\n lanes: [],\n signals: [],\n frames: [],\n guides: [],\n };\n}\n\nfunction mergeCompileResults(target: CompileResult, source: CompileResult) {\n target.nodes.push(...source.nodes);\n target.edges.push(...source.edges);\n target.groups.push(...source.groups);\n target.annotations.push(...source.annotations);\n target.lanes.push(...source.lanes);\n target.signals.push(...source.signals);\n target.frames.push(...source.frames);\n target.guides.push(...source.guides);\n}\n\nexport function compileGraph(\n children: ReactNode,\n layout: DiagramGraphLayout | undefined,\n): DiagramGraphIR {\n const result = compileChildren(children, {});\n if (\n result.lanes.length > 0 ||\n result.signals.length > 0 ||\n result.frames.length > 0\n ) {\n throw new Error(\n 'A graph diagram cannot contain Diagram.Lane, Diagram.Signal or Diagram.Frame; draw those with SvgTimelineDiagram.',\n );\n }\n return {\n nodes: result.nodes,\n edges: result.edges,\n groups: result.groups,\n annotations: result.annotations,\n guides: result.guides,\n layout,\n };\n}\n\nexport function compileTimeline(children: ReactNode): DiagramTimelineSpec {\n const result = compileChildren(children, {});\n if (\n result.nodes.length > 0 ||\n result.edges.length > 0 ||\n result.groups.length > 0 ||\n result.annotations.length > 0 ||\n result.guides.length > 0\n ) {\n throw new Error(\n 'A timeline diagram only accepts Diagram.Lane, Diagram.Signal and Diagram.Frame; draw other primitives with SvgGraphDiagram or CanvasGraphDiagram.',\n );\n }\n return {\n lanes: result.lanes,\n signals: result.signals,\n frame: result.frames[0],\n };\n}\n\nfunction compileChildren(\n children: ReactNode,\n context: CompileContext,\n): CompileResult {\n const result = emptyCompileResult();\n Children.forEach(children, (child) => {\n if (child === null || child === undefined || typeof child === 'boolean')\n return;\n if (isTextNode(child)) {\n if (String(child).trim().length === 0) return;\n throw new Error(\n `Unexpected text \"${String(child).trim()}\" directly inside Diagram.`,\n );\n }\n if (!isValidElement(child)) {\n throw new Error('Diagram only accepts Diagram primitives as children.');\n }\n if (child.type === Fragment) {\n throw new Error(\n 'Diagram does not accept React fragments. Place Diagram primitives directly or return an array of primitives.',\n );\n }\n\n const kind = primitiveKind(child);\n if (!kind) {\n const name =\n typeof child.type === 'function' ? child.type.name : String(child.type);\n throw new Error(\n `Diagram cannot compile <${name || 'Component'} />. Use direct Diagram primitives as children.`,\n );\n }\n\n if (isNodeKind(kind)) {\n result.nodes.push(compileNode(kind, child, context));\n return;\n }\n if (isEdgeKind(kind)) {\n result.edges.push(compileEdge(kind, child));\n return;\n }\n if (kind === 'group') {\n const group = compileGroup(child, context);\n result.groups.push(group.group);\n mergeCompileResults(result, group.children);\n return;\n }\n if (kind === 'text') {\n result.annotations.push(compileText(child));\n return;\n }\n if (kind === 'lane') {\n result.lanes.push(compileLane(child));\n return;\n }\n if (kind === 'signal') {\n result.signals.push(compileSignal(child));\n return;\n }\n if (kind === 'frame') {\n if (result.frames.length > 0) {\n throw new Error(\n 'Diagram supports one Frame in lane/signal layout for now.',\n );\n }\n result.frames.push(compileFrame(child));\n return;\n }\n if (kind === 'guide') {\n result.guides.push(requirePrimitiveProps<DiagramGuideProps>(child));\n return;\n }\n\n throw new Error(`<Diagram.${kind}> cannot be a direct child of Diagram.`);\n });\n return result;\n}\n\nfunction isTextNode(child: ReactNode): child is string | number {\n return typeof child === 'string' || typeof child === 'number';\n}\n\nfunction isNodeKind(kind: PrimitiveKind): boolean {\n return (\n kind === 'node' ||\n kind === 'box' ||\n kind === 'card' ||\n kind === 'port' ||\n kind === 'label' ||\n kind === 'float' ||\n kind === 'phantom' ||\n kind === 'appliance' ||\n kind === 'connector' ||\n kind === 'junction' ||\n kind === 'marker'\n );\n}\n\nfunction isEdgeKind(kind: PrimitiveKind): boolean {\n return kind === 'edge' || kind === 'arrow' || kind === 'wire';\n}\n\nfunction requirePrimitiveProps<P>(child: ReactElement): P {\n // React's own guard types the element's props; only the calling primitive\n // knows their shape P.\n if (!isValidElement<P>(child)) {\n throw new Error('Diagram only accepts Diagram primitives as children.');\n }\n return child.props;\n}\n\nfunction compileNode(\n kind: PrimitiveKind,\n child: ReactElement,\n context: CompileContext,\n): DiagramNode {\n if (kind === 'phantom') {\n const props = requirePrimitiveProps<DiagramPhantomProps>(child);\n const label = compileLabelChildren(props.children, 'Diagram.Phantom');\n const hasLabel = label.length > 0;\n return {\n id: props.id,\n label: hasLabel ? label : '',\n row: props.row,\n col: props.col,\n width: props.width ?? 1,\n height: props.height ?? 1,\n ...((props.group ?? context.groupId)\n ? { group: props.group ?? context.groupId }\n : {}),\n frame: 'none',\n hidden: props.hidden ?? !hasLabel,\n ...(props.fontSize ? { fontSize: props.fontSize } : {}),\n ...(props.fontWeight ? { fontWeight: props.fontWeight } : {}),\n ...(props.textColor ? { textColor: props.textColor } : {}),\n ...(props.accent !== undefined ? { accent: props.accent } : {}),\n ...(props.textAlign ? { textAlign: props.textAlign } : {}),\n ...(props.connectable !== undefined\n ? { connectable: props.connectable }\n : {}),\n };\n }\n\n if (kind === 'junction') {\n const props = requirePrimitiveProps<DiagramJunctionProps>(child);\n const label = compileLabelChildren(props.children, 'Diagram.Junction');\n const group = props.group ?? context.groupId;\n return {\n id: props.id,\n kind: 'junction',\n label: label.length > 0 ? label : '',\n row: props.row,\n col: props.col,\n width: props.width ?? 16,\n height: props.height ?? 16,\n ...(group ? { group } : {}),\n frame: 'none',\n connectable: true,\n hidden: props.hidden,\n accent: props.accent,\n tone: props.tone,\n fontSize: props.fontSize,\n fontWeight: props.fontWeight,\n textColor: props.textColor,\n caption: props.caption,\n captionSide: props.captionSide,\n captionOffset: props.captionOffset,\n captionColor: props.captionColor,\n captionFontSize: props.captionFontSize,\n captionFontWeight: props.captionFontWeight,\n };\n }\n\n if (kind === 'connector') {\n const props = requirePrimitiveProps<DiagramConnectorProps>(child);\n const label = compileLabelChildren(props.children, 'Diagram.Connector');\n const group = props.group ?? context.groupId;\n return {\n id: props.id,\n kind: 'connector',\n label: label.length > 0 ? label : '',\n row: props.row,\n col: props.col,\n colSpan: props.colSpan,\n width: props.width ?? 148,\n height: props.height ?? 40,\n ...(group ? { group } : {}),\n frame: 'solid',\n connectable: true,\n rx: props.rx ?? 10,\n accent: props.accent,\n tone: props.tone,\n texture: props.texture,\n icon: props.icon,\n iconSize: props.iconSize,\n ports: props.ports,\n fontSize: props.fontSize,\n fontWeight: props.fontWeight,\n textColor: props.textColor,\n caption: props.caption,\n captionSide: props.captionSide,\n captionOffset: props.captionOffset,\n captionColor: props.captionColor,\n captionFontSize: props.captionFontSize,\n captionFontWeight: props.captionFontWeight,\n };\n }\n\n if (kind === 'appliance') {\n const props = requirePrimitiveProps<DiagramApplianceProps>(child);\n const label = compileLabelChildren(props.children, 'Diagram.Appliance');\n const group = props.group ?? context.groupId;\n return {\n id: props.id,\n kind: 'appliance',\n label: label.length > 0 ? label : '',\n row: props.row,\n col: props.col,\n width: props.width ?? 112,\n height: props.height ?? 72,\n ...(group ? { group } : {}),\n frame: 'none',\n connectable: true,\n accent: props.accent,\n tone: props.tone,\n texture: props.texture,\n ports: props.ports,\n fontSize: props.fontSize,\n fontWeight: props.fontWeight,\n textColor: props.textColor,\n caption: props.caption,\n captionSide: props.captionSide,\n captionOffset: props.captionOffset,\n captionColor: props.captionColor,\n captionFontSize: props.captionFontSize,\n captionFontWeight: props.captionFontWeight,\n appliancePorts: props.appliancePorts,\n antenna: props.antenna,\n slant: props.slant,\n };\n }\n\n const props = requirePrimitiveProps<DiagramNodeProps | DiagramMarkerProps>(\n child,\n );\n const { children: _children, ...nodeProps } = props;\n const { labelChildren, content } = splitNodeContent(props.children, kind);\n const label = compileLabelChildren(labelChildren, `Diagram.${kind}`);\n const group = nodeProps.group ?? context.groupId;\n return {\n ...nodeProps,\n label: label.length > 0 ? label : '',\n ...(content.length > 0 ? { content: content[0] } : {}),\n ...(kind === 'marker'\n ? {\n kind: 'marker' as const,\n width: nodeProps.width ?? 72,\n height: nodeProps.height ?? 76,\n }\n : {}),\n ...(group ? { group } : {}),\n frame: nodeFrame(kind, nodeProps.frame),\n textAlign:\n kind === 'card' ? (nodeProps.textAlign ?? 'start') : nodeProps.textAlign,\n hidden: kind === 'marker' ? false : nodeProps.hidden,\n connectable: kind === 'float' ? false : nodeProps.connectable,\n ...(kind === 'marker' ? { frame: nodeProps.frame ?? 'none' } : {}),\n };\n}\n\nconst CONTENT_HOSTS = new Set<PrimitiveKind>(['node', 'box', 'card']);\n\nfunction splitNodeContent(children: ReactNode, kind: PrimitiveKind) {\n const labelChildren: ReactNode[] = [];\n const content: ReactNode[] = [];\n Children.forEach(children, (child) => {\n if (!isValidElement(child) || primitiveKind(child) !== 'content') {\n labelChildren.push(child);\n return;\n }\n if (!CONTENT_HOSTS.has(kind)) {\n throw new Error(\n `Diagram.Content goes inside Diagram.Box, Diagram.Card or Diagram.Node, not Diagram.${kind}.`,\n );\n }\n if (content.length > 0) {\n throw new Error(`Diagram.${kind} accepts one Diagram.Content.`);\n }\n content.push(requirePrimitiveProps<DiagramContentProps>(child).children);\n });\n return { labelChildren, content };\n}\n\nfunction nodeFrame(kind: PrimitiveKind, explicit: DiagramNode['frame']) {\n if (explicit) return explicit;\n if (kind === 'port') return 'transparent';\n if (kind === 'label') return 'none';\n if (kind === 'float') return 'flat';\n if (kind === 'appliance') return 'none';\n if (kind === 'marker') return 'none';\n return 'solid';\n}\n\nfunction compileEdge(kind: PrimitiveKind, child: ReactElement): DiagramEdge {\n const props = requirePrimitiveProps<DiagramEdgeProps>(child);\n const { children: _children, badgeLabel, ...edgeProps } = props;\n const lines: string[] = [];\n const waypoints: DiagramWaypoint[] = [...(props.waypoints ?? [])];\n let entrySide = props.entrySide;\n let exitSide = props.exitSide;\n let entryGap = props.entryGap;\n\n Children.forEach(props.children, (edgeChild) => {\n if (\n edgeChild === null ||\n edgeChild === undefined ||\n typeof edgeChild === 'boolean'\n )\n return;\n if (isTextNode(edgeChild)) {\n const text = String(edgeChild).trim();\n if (text.length > 0) lines.push(text);\n return;\n }\n if (!isValidElement(edgeChild)) {\n throw new Error(\n 'Diagram edges only accept text, Line, Entry, Exit, and Waypoint children.',\n );\n }\n if (edgeChild.type === Fragment) {\n throw new Error(\n 'Diagram edges do not accept fragments. Use direct Line/Entry/Exit/Waypoint children.',\n );\n }\n const edgeChildKind = primitiveKind(edgeChild);\n if (edgeChildKind === 'line') {\n lines.push(lineText(edgeChild));\n return;\n }\n if (edgeChildKind === 'entry') {\n const entry = requirePrimitiveProps<DiagramEntryProps>(edgeChild);\n entrySide = entry.side;\n entryGap = entry.gap ?? entryGap;\n return;\n }\n if (edgeChildKind === 'exit') {\n exitSide = requirePrimitiveProps<DiagramExitProps>(edgeChild).side;\n return;\n }\n if (edgeChildKind === 'waypoint') {\n waypoints.push(requirePrimitiveProps<DiagramWaypointProps>(edgeChild));\n return;\n }\n throw new Error(\n `Diagram edge cannot contain <Diagram.${edgeChildKind ?? 'Unknown'}>.`,\n );\n });\n\n return {\n ...edgeProps,\n ...(lines.length > 0 ? { label: lines } : {}),\n ...(badgeLabel !== undefined\n ? { badgeLabel: normalizeStringLines(badgeLabel) }\n : {}),\n ...(waypoints.length > 0 ? { waypoints } : {}),\n ...(entrySide ? { entrySide } : {}),\n ...(exitSide ? { exitSide } : {}),\n ...(entryGap !== undefined ? { entryGap } : {}),\n headless: kind === 'wire' ? true : edgeProps.headless,\n };\n}\n\nfunction normalizeStringLines(value: string | string[]) {\n return (Array.isArray(value) ? value : [value])\n .map((line) => line.trim())\n .filter(Boolean);\n}\n\nfunction compileGroup(\n child: ReactElement,\n context: CompileContext,\n): { group: DiagramGraphIR['groups'][number]; children: CompileResult } {\n const props = requirePrimitiveProps<DiagramGroupProps>(child);\n const children = compileChildren(props.children, {\n ...context,\n groupId: props.id,\n });\n const bounds =\n props.rowStart !== undefined &&\n props.rowEnd !== undefined &&\n props.colStart !== undefined &&\n props.colEnd !== undefined\n ? {\n rowStart: props.rowStart,\n rowEnd: props.rowEnd,\n colStart: props.colStart,\n colEnd: props.colEnd,\n }\n : inferGroupBounds(props.id, children.nodes, children.groups);\n\n return {\n group: {\n id: props.id,\n label: normalizeGroupLabel(props.label),\n labelAlign: props.labelAlign,\n labelSide: props.labelSide,\n accent: props.accent,\n tone: props.tone,\n texture: props.texture,\n rx: props.rx,\n frame: props.frame,\n fill: props.fill,\n ports: props.ports,\n parent: context.groupId,\n tight: props.tight,\n tightX: props.tightX,\n tightY: props.tightY,\n titleBand: props.titleBand,\n titleGap: props.titleGap,\n padding: props.padding,\n dividers: props.dividers,\n bounds,\n },\n children,\n };\n}\n\nfunction normalizeGroupLabel(label: string | string[] | undefined) {\n if (Array.isArray(label)) {\n return label.map((line) => line.trim()).filter(Boolean);\n }\n return label?.trim() ?? '';\n}\n\nfunction inferGroupBounds(\n groupId: string,\n nodes: DiagramNode[],\n groups: DiagramGraphIR['groups'] = [],\n) {\n const grouped = nodes.filter((node) => node.group === groupId);\n const childGroups = groups.filter((group) => group.parent === groupId);\n if (grouped.length === 0 && childGroups.length === 0) {\n throw new Error(\n `Diagram.Group \"${groupId}\" needs bounds or direct node/group children so bounds can be inferred.`,\n );\n }\n const bounds = emptyGroupBounds();\n for (const node of grouped) {\n if (node.row === undefined || node.col === undefined) return undefined;\n includeGroupBounds(bounds, {\n rowStart: node.row,\n rowEnd: node.row,\n colStart: node.col,\n colEnd: node.col + (node.colSpan ?? 1) - 1,\n });\n }\n for (const group of childGroups) {\n if (!group.bounds) return undefined;\n includeGroupBounds(bounds, group.bounds);\n }\n return bounds;\n}\n\nfunction emptyGroupBounds(): NonNullable<\n DiagramGraphIR['groups'][number]['bounds']\n> {\n return {\n rowStart: Number.POSITIVE_INFINITY,\n rowEnd: Number.NEGATIVE_INFINITY,\n colStart: Number.POSITIVE_INFINITY,\n colEnd: Number.NEGATIVE_INFINITY,\n };\n}\n\nfunction includeGroupBounds(\n target: NonNullable<DiagramGraphIR['groups'][number]['bounds']>,\n source: NonNullable<DiagramGraphIR['groups'][number]['bounds']>,\n) {\n target.rowStart = Math.min(target.rowStart, source.rowStart);\n target.rowEnd = Math.max(target.rowEnd, source.rowEnd);\n target.colStart = Math.min(target.colStart, source.colStart);\n target.colEnd = Math.max(target.colEnd, source.colEnd);\n}\n\nfunction compileText(child: ReactElement): DiagramAnnotation {\n const props = requirePrimitiveProps<DiagramTextProps>(child);\n const { children: _children, ...textProps } = props;\n const lines = compileStringLines(props.children, 'Diagram.Text');\n return {\n ...textProps,\n text: lines.length > 0 ? lines : [''],\n };\n}\n\nfunction compileLane(child: ReactElement): DiagramLane {\n const props = requirePrimitiveProps<DiagramLaneProps>(child);\n return {\n id: props.id,\n label: compileStringLines(props.children, 'Diagram.Lane'),\n accent: props.accent,\n };\n}\n\nfunction normalizeBoxed(\n boxed: boolean | DiagramSignalBox | undefined,\n): DiagramSignalBox | undefined {\n if (boxed === true) return 'source';\n if (!boxed) return undefined;\n return boxed;\n}\n\nfunction compileSignal(child: ReactElement): DiagramSignal {\n const props = requirePrimitiveProps<DiagramSignalProps>(child);\n const { children: _children, boxed, ...signalProps } = props;\n const normalizedBoxed = normalizeBoxed(boxed);\n return {\n ...signalProps,\n label: compileStringLines(props.children, 'Diagram.Signal'),\n ...(normalizedBoxed ? { boxed: normalizedBoxed } : {}),\n };\n}\n\nfunction compileFrame(child: ReactElement): DiagramFrameElement {\n const props = requirePrimitiveProps<DiagramFrameProps>(child);\n const signals: DiagramSignal[] = [];\n Children.forEach(props.children, (frameChild) => {\n if (\n frameChild === null ||\n frameChild === undefined ||\n typeof frameChild === 'boolean'\n )\n return;\n if (!isValidElement(frameChild) || primitiveKind(frameChild) !== 'signal') {\n throw new Error(\n 'Diagram.Frame only accepts direct Diagram.Signal children.',\n );\n }\n signals.push(compileSignal(frameChild));\n });\n return { label: props.label, signals };\n}\n\nfunction compileStringLines(children: ReactNode, owner: string): string[] {\n const lines: string[] = [];\n Children.forEach(children, (child) => {\n if (child === null || child === undefined || typeof child === 'boolean')\n return;\n if (isTextNode(child)) {\n const text = String(child).trim();\n if (text.length > 0) lines.push(text);\n return;\n }\n if (!isValidElement(child)) {\n throw new Error(`${owner} only accepts text or Diagram.Line children.`);\n }\n if (child.type === Fragment) {\n throw new Error(\n `${owner} does not accept React fragments. Use direct text or Diagram.Line children.`,\n );\n }\n if (primitiveKind(child) === 'line') {\n lines.push(lineText(child));\n return;\n }\n throw new Error(`${owner} only accepts text or Diagram.Line children.`);\n });\n return lines;\n}\n\nfunction compileLabelChildren(\n children: ReactNode,\n owner: string,\n): DiagramLabelLine[] {\n const lines: DiagramLabelLine[] = [];\n Children.forEach(children, (child) => {\n if (child === null || child === undefined || typeof child === 'boolean')\n return;\n if (isTextNode(child)) {\n const text = String(child).trim();\n if (text.length > 0) lines.push(text);\n return;\n }\n if (!isValidElement(child)) {\n throw new Error(`${owner} only accepts text or Diagram.Line children.`);\n }\n if (child.type === Fragment) {\n throw new Error(\n `${owner} does not accept React fragments. Use direct text or Diagram.Line children.`,\n );\n }\n if (primitiveKind(child) === 'line') {\n const props = requirePrimitiveProps<DiagramLineProps>(child);\n lines.push({\n text: lineText(child),\n ...(props.textColor ? { textColor: props.textColor } : {}),\n ...(props.fontWeight ? { fontWeight: props.fontWeight } : {}),\n });\n return;\n }\n throw new Error(`${owner} only accepts text or Diagram.Line children.`);\n });\n return lines;\n}\n\nfunction lineText(child: ReactElement): string {\n const props = requirePrimitiveProps<DiagramLineProps>(child);\n return Children.toArray(props.children)\n .map((part) => {\n if (!isTextNode(part)) {\n throw new Error('Diagram.Line only accepts text children.');\n }\n return String(part).trim();\n })\n .filter(Boolean)\n .join('');\n}\n\nexport function validateGraph(ir: DiagramGraphIR) {\n const nodeIds = new Set<string>();\n for (const node of ir.nodes) {\n if (nodeIds.has(node.id))\n throw new Error(`Duplicate Diagram node id \"${node.id}\".`);\n nodeIds.add(node.id);\n }\n const groupIds = new Set<string>();\n for (const group of ir.groups) {\n if (groupIds.has(group.id))\n throw new Error(`Duplicate Diagram group id \"${group.id}\".`);\n groupIds.add(group.id);\n }\n const guideIds = new Set<string>();\n for (const guide of ir.guides) {\n if (!guide.id) continue;\n if (guideIds.has(guide.id))\n throw new Error(`Duplicate Diagram guide id \"${guide.id}\".`);\n guideIds.add(guide.id);\n }\n const nodesById = new Map(ir.nodes.map((node) => [node.id, node]));\n const groupsById = new Map(ir.groups.map((group) => [group.id, group]));\n for (const node of ir.nodes) {\n if (groupsById.has(node.id)) {\n throw new Error(\n `Diagram node id \"${node.id}\" conflicts with a Diagram group id. Node and group endpoint ids must be unique.`,\n );\n }\n if (\n node.bodyFontSize !== undefined &&\n (!Number.isFinite(node.bodyFontSize) || node.bodyFontSize <= 0)\n ) {\n throw new Error(\n `Diagram node \"${node.id}\" bodyFontSize must be a positive finite number, got ${node.bodyFontSize}.`,\n );\n }\n if (\n node.bodyLineGap !== undefined &&\n (!Number.isFinite(node.bodyLineGap) || node.bodyLineGap < 0)\n ) {\n throw new Error(\n `Diagram node \"${node.id}\" bodyLineGap must be a non-negative finite number, got ${node.bodyLineGap}.`,\n );\n }\n }\n for (const edge of ir.edges) {\n if (\n edge.route !== undefined &&\n edge.route !== 'orthogonal' &&\n edge.route !== 'straight'\n ) {\n throw new Error(\n `Diagram edge route must be \"orthogonal\" or \"straight\", got \"${edge.route}\".`,\n );\n }\n if (\n edge.labelLineGap !== undefined &&\n (!Number.isFinite(edge.labelLineGap) || edge.labelLineGap < 0)\n ) {\n throw new Error(\n `Diagram edge labelLineGap must be a non-negative finite number, got ${edge.labelLineGap}.`,\n );\n }\n if (edge.exitOffset !== undefined && !Number.isFinite(edge.exitOffset)) {\n throw new Error(\n `Diagram edge exitOffset must be a finite number, got ${edge.exitOffset}.`,\n );\n }\n if (edge.entryOffset !== undefined && !Number.isFinite(edge.entryOffset)) {\n throw new Error(\n `Diagram edge entryOffset must be a finite number, got ${edge.entryOffset}.`,\n );\n }\n if (\n edge.stubDistance !== undefined &&\n (!Number.isFinite(edge.stubDistance) || edge.stubDistance < 0)\n ) {\n throw new Error(\n `Diagram edge stubDistance must be a non-negative finite number, got ${edge.stubDistance}.`,\n );\n }\n const { nodeId: sourceNodeId, portId: sourcePortId } = parseEndpointRef(\n edge.from,\n );\n const { nodeId: targetNodeId, portId: targetPortId } = parseEndpointRef(\n edge.to,\n );\n if (!nodeIds.has(sourceNodeId) && !groupsById.has(sourceNodeId)) {\n throw new Error(\n `Diagram edge ${edge.from}->${edge.to} references missing source \"${sourceNodeId}\".`,\n );\n }\n if (!nodeIds.has(targetNodeId) && !groupsById.has(targetNodeId)) {\n throw new Error(\n `Diagram edge ${edge.from}->${edge.to} references missing target \"${targetNodeId}\".`,\n );\n }\n if (\n sourcePortId &&\n !(\n nodesById\n .get(sourceNodeId)\n ?.ports?.some((port) => port.id === sourcePortId) ||\n groupsById\n .get(sourceNodeId)\n ?.ports?.some((port) => port.id === sourcePortId)\n )\n ) {\n throw new Error(\n `Diagram edge ${edge.from}->${edge.to} references missing source port \"${sourcePortId}\" on \"${sourceNodeId}\".`,\n );\n }\n if (\n targetPortId &&\n !(\n nodesById\n .get(targetNodeId)\n ?.ports?.some((port) => port.id === targetPortId) ||\n groupsById\n .get(targetNodeId)\n ?.ports?.some((port) => port.id === targetPortId)\n )\n ) {\n throw new Error(\n `Diagram edge ${edge.from}->${edge.to} references missing target port \"${targetPortId}\" on \"${targetNodeId}\".`,\n );\n }\n }\n for (const annotation of ir.annotations) {\n if (\n annotation.lineGap !== undefined &&\n (!Number.isFinite(annotation.lineGap) || annotation.lineGap < 0)\n ) {\n throw new Error(\n `Diagram.Text lineGap must be a non-negative finite number, got ${annotation.lineGap}.`,\n );\n }\n }\n}\n\nexport function validateTimeline(ir: DiagramTimelineSpec) {\n const laneIds = new Set<string>();\n for (const lane of ir.lanes) {\n if (laneIds.has(lane.id))\n throw new Error(`Duplicate Diagram lane id \"${lane.id}\".`);\n laneIds.add(lane.id);\n }\n const signals = [...ir.signals, ...(ir.frame?.signals ?? [])];\n for (const signal of signals) {\n if (!laneIds.has(signal.from)) {\n throw new Error(\n `Diagram signal ${signal.from}->${signal.to} references missing lane \"${signal.from}\".`,\n );\n }\n if (!laneIds.has(signal.to)) {\n throw new Error(\n `Diagram signal ${signal.from}->${signal.to} references missing lane \"${signal.to}\".`,\n );\n }\n }\n}\n"],"mappings":"AAAA,SACEA,QAAQ,EACRC,QAAQ,EAGRC,cAAc,QACT,OAAO;AAiBd,SAASC,gBAAgB,QAAQ,0BAA0B;AAsB3D,OAAO,MAAMC,iBAAiB,GAAGC,MAAM,CAACC,GAAG,CAAC,4BAA4B,CAAC;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AAG,CAACgG,IAAI,CAACrI,EAAE,CAAC,EACtB,MAAM,IAAI1B,KAAK,CAAC,8BAA8B+J,IAAI,CAACrI,EAAE,IAAI,CAAC;IAC5DoI,OAAO,CAAC7B,GAAG,CAAC8B,IAAI,CAACrI,EAAE,CAAC;EACtB;EACA,MAAMvC,OAAO,GAAG,CAAC,GAAG4I,EAAE,CAAC5I,OAAO,EAAE,IAAI4I,EAAE,CAAC7H,KAAK,EAAEf,OAAO,IAAI,EAAE,CAAC,CAAC;EAC7D,KAAK,MAAM6K,MAAM,IAAI7K,OAAO,EAAE;IAC5B,IAAI,CAAC2K,OAAO,CAAC/F,GAAG,CAACiG,MAAM,CAACX,IAAI,CAAC,EAAE;MAC7B,MAAM,IAAIrJ,KAAK,CACb,kBAAkBgK,MAAM,CAACX,IAAI,KAAKW,MAAM,CAACR,EAAE,6BAA6BQ,MAAM,CAACX,IAAI,IACrF,CAAC;IACH;IACA,IAAI,CAACS,OAAO,CAAC/F,GAAG,CAACiG,MAAM,CAACR,EAAE,CAAC,EAAE;MAC3B,MAAM,IAAIxJ,KAAK,CACb,kBAAkBgK,MAAM,CAACX,IAAI,KAAKW,MAAM,CAACR,EAAE,6BAA6BQ,MAAM,CAACR,EAAE,IACnF,CAAC;IACH;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"diagram-compile.js","names":["Children","Fragment","isValidElement","DIAGRAM_PRIMITIVE","Symbol","for","PRIMITIVE_KINDS","primitive","kind","Object","assign","primitiveKind","node","type","isPrimitiveKind","value","some","emptyCompileResult","nodes","edges","groups","lanes","signals","frames","mergeCompileResults","target","source","push","compileGraph","children","result","compileChildren","length","Error","compileTimeline","frame","context","forEach","child","undefined","isTextNode","String","trim","name","isNodeKind","compileNode","isEdgeKind","compileEdge","group","compileGroup","compileLane","compileSignal","compileFrame","requirePrimitiveProps","props","groupId","label","nodeLabel","labelChildren","content","splitNodeContent","nodeFrame","textAlign","hidden","connectable","owner","compileLabelChildren","CONTENT_HOSTS","Set","has","element","size","explicit","badgeLabel","edgeProps","lines","compileStringLines","normalizeStringLines","headless","Array","isArray","map","line","filter","Boolean","groupChildren","id","normalizeGroupLabel","parent","accent","normalizeBoxed","boxed","_children","signalProps","normalizedBoxed","frameChild","text","lineText","textColor","fontWeight","toArray","part","join","validateTimeline","ir","laneIds","lane","add","signal","from","to"],"sources":["../../../src/lib/compiler/diagram-compile.ts"],"sourcesContent":["import {\n Children,\n Fragment,\n type ReactElement,\n type ReactNode,\n isValidElement,\n} from 'react';\n\nimport type {\n DiagramEdge,\n DiagramFrameElement,\n DiagramGraphIR,\n DiagramLabelLine,\n DiagramLane,\n DiagramNode,\n DiagramNodeContent,\n DiagramSignal,\n DiagramSignalBox,\n DiagramTimelineSpec,\n} from '../model/diagram-ir.ts';\nimport type {\n DiagramApplianceProps,\n DiagramConnectorProps,\n DiagramContentProps,\n DiagramEdgeProps,\n DiagramFrameProps,\n DiagramGroupProps,\n DiagramJunctionProps,\n DiagramLaneProps,\n DiagramLineProps,\n DiagramMarkerProps,\n DiagramNodeProps,\n DiagramNoteProps,\n DiagramSignalProps,\n} from '../react/diagram-types.ts';\n\nexport const DIAGRAM_PRIMITIVE = Symbol.for('@zukhruf/diagram/primitive');\n\nconst PRIMITIVE_KINDS = [\n 'node',\n 'box',\n 'card',\n 'port',\n 'label',\n 'float',\n 'appliance',\n 'connector',\n 'junction',\n 'edge',\n 'arrow',\n 'wire',\n 'group',\n 'note',\n 'line',\n 'lane',\n 'signal',\n 'frame',\n 'marker',\n 'content',\n] as const;\n\nexport type PrimitiveKind = (typeof PRIMITIVE_KINDS)[number];\n\nexport type PrimitiveComponent<P> = ((props: P) => null) & {\n [DIAGRAM_PRIMITIVE]: PrimitiveKind;\n};\n\nexport function primitive<P>(kind: PrimitiveKind): PrimitiveComponent<P> {\n return Object.assign(() => null, { [DIAGRAM_PRIMITIVE]: kind });\n}\n\nexport function primitiveKind(node: ReactNode): PrimitiveKind | null {\n if (!isValidElement(node)) return null;\n const { type } = node;\n if (typeof type !== 'function' || !(DIAGRAM_PRIMITIVE in type)) return null;\n const kind = type[DIAGRAM_PRIMITIVE];\n return isPrimitiveKind(kind) ? kind : null;\n}\n\nfunction isPrimitiveKind(value: unknown): value is PrimitiveKind {\n return PRIMITIVE_KINDS.some((kind) => kind === value);\n}\n\ntype CompileContext = {\n groupId?: string;\n};\n\ntype CompileResult = {\n nodes: DiagramNode[];\n edges: DiagramEdge[];\n groups: DiagramGraphIR['groups'];\n lanes: DiagramLane[];\n signals: DiagramSignal[];\n frames: DiagramFrameElement[];\n};\n\nfunction emptyCompileResult(): CompileResult {\n return {\n nodes: [],\n edges: [],\n groups: [],\n lanes: [],\n signals: [],\n frames: [],\n };\n}\n\nfunction mergeCompileResults(target: CompileResult, source: CompileResult) {\n target.nodes.push(...source.nodes);\n target.edges.push(...source.edges);\n target.groups.push(...source.groups);\n target.lanes.push(...source.lanes);\n target.signals.push(...source.signals);\n target.frames.push(...source.frames);\n}\n\nexport function compileGraph(children: ReactNode): DiagramGraphIR {\n const result = compileChildren(children, {});\n if (\n result.lanes.length > 0 ||\n result.signals.length > 0 ||\n result.frames.length > 0\n ) {\n throw new Error(\n 'A graph diagram cannot contain Diagram.Lane, Diagram.Signal or Diagram.Frame; draw those with SvgTimelineDiagram.',\n );\n }\n return {\n nodes: result.nodes,\n edges: result.edges,\n groups: result.groups,\n };\n}\n\nexport function compileTimeline(children: ReactNode): DiagramTimelineSpec {\n const result = compileChildren(children, {});\n if (\n result.nodes.length > 0 ||\n result.edges.length > 0 ||\n result.groups.length > 0\n ) {\n throw new Error(\n 'A timeline diagram only accepts Diagram.Lane, Diagram.Signal and Diagram.Frame; draw other primitives with SvgGraphDiagram or CanvasGraphDiagram.',\n );\n }\n return {\n lanes: result.lanes,\n signals: result.signals,\n frame: result.frames[0],\n };\n}\n\nfunction compileChildren(\n children: ReactNode,\n context: CompileContext,\n): CompileResult {\n const result = emptyCompileResult();\n Children.forEach(children, (child) => {\n if (child === null || child === undefined || typeof child === 'boolean')\n return;\n if (isTextNode(child)) {\n if (String(child).trim().length === 0) return;\n throw new Error(\n `Unexpected text \"${String(child).trim()}\" directly inside Diagram.`,\n );\n }\n if (!isValidElement(child)) {\n throw new Error('Diagram only accepts Diagram primitives as children.');\n }\n if (child.type === Fragment) {\n throw new Error(\n 'Diagram does not accept React fragments. Place Diagram primitives directly or return an array of primitives.',\n );\n }\n\n const kind = primitiveKind(child);\n if (!kind) {\n const name =\n typeof child.type === 'function' ? child.type.name : String(child.type);\n throw new Error(\n `Diagram cannot compile <${name || 'Component'} />. Use direct Diagram primitives as children.`,\n );\n }\n\n if (isNodeKind(kind)) {\n result.nodes.push(compileNode(kind, child, context));\n return;\n }\n if (isEdgeKind(kind)) {\n result.edges.push(compileEdge(kind, child));\n return;\n }\n if (kind === 'group') {\n const group = compileGroup(child, context);\n result.groups.push(group.group);\n mergeCompileResults(result, group.children);\n return;\n }\n if (kind === 'lane') {\n result.lanes.push(compileLane(child));\n return;\n }\n if (kind === 'signal') {\n result.signals.push(compileSignal(child));\n return;\n }\n if (kind === 'frame') {\n if (result.frames.length > 0) {\n throw new Error(\n 'Diagram supports one Frame in lane/signal layout for now.',\n );\n }\n result.frames.push(compileFrame(child));\n return;\n }\n\n throw new Error(`<Diagram.${kind}> cannot be a direct child of Diagram.`);\n });\n return result;\n}\n\nfunction isTextNode(child: ReactNode): child is string | number {\n return typeof child === 'string' || typeof child === 'number';\n}\n\nfunction isNodeKind(kind: PrimitiveKind): boolean {\n return (\n kind === 'node' ||\n kind === 'box' ||\n kind === 'card' ||\n kind === 'port' ||\n kind === 'label' ||\n kind === 'float' ||\n kind === 'note' ||\n kind === 'appliance' ||\n kind === 'connector' ||\n kind === 'junction' ||\n kind === 'marker'\n );\n}\n\nfunction isEdgeKind(kind: PrimitiveKind): boolean {\n return kind === 'edge' || kind === 'arrow' || kind === 'wire';\n}\n\nfunction requirePrimitiveProps<P>(child: ReactElement): P {\n // React's own guard types the element's props; only the calling primitive\n // knows their shape P.\n if (!isValidElement<P>(child)) {\n throw new Error('Diagram only accepts Diagram primitives as children.');\n }\n return child.props;\n}\n\nfunction compileNode(\n kind: PrimitiveKind,\n child: ReactElement,\n context: CompileContext,\n): DiagramNode {\n const group = context.groupId === undefined ? {} : { group: context.groupId };\n\n if (kind === 'note') {\n const { children, ...props } =\n requirePrimitiveProps<DiagramNoteProps>(child);\n return {\n ...props,\n kind: 'note',\n label: nodeLabel(children, 'Diagram.Note'),\n ...group,\n frame: 'none',\n };\n }\n\n if (kind === 'junction') {\n const { children, ...props } =\n requirePrimitiveProps<DiagramJunctionProps>(child);\n return {\n ...props,\n kind: 'junction',\n label: nodeLabel(children, 'Diagram.Junction'),\n ...group,\n frame: 'none',\n };\n }\n\n if (kind === 'connector') {\n const { children, ...props } =\n requirePrimitiveProps<DiagramConnectorProps>(child);\n return {\n ...props,\n kind: 'connector',\n label: nodeLabel(children, 'Diagram.Connector'),\n ...group,\n frame: 'solid',\n };\n }\n\n if (kind === 'appliance') {\n const { children, ...props } =\n requirePrimitiveProps<DiagramApplianceProps>(child);\n return {\n ...props,\n kind: 'appliance',\n label: nodeLabel(children, 'Diagram.Appliance'),\n ...group,\n frame: 'none',\n };\n }\n\n const { children, ...props } = requirePrimitiveProps<\n DiagramNodeProps | DiagramMarkerProps\n >(child);\n const { labelChildren, content } = splitNodeContent(children, kind);\n return {\n ...props,\n label: nodeLabel(labelChildren, `Diagram.${kind}`),\n ...(content ? { content } : {}),\n ...(kind === 'marker' ? { kind: 'marker' as const } : {}),\n ...group,\n frame: nodeFrame(kind, props.frame),\n ...(kind === 'card' ? { textAlign: 'start' as const } : {}),\n hidden: kind === 'marker' ? false : props.hidden,\n ...(kind === 'float' ? { connectable: false } : {}),\n };\n}\n\nfunction nodeLabel(children: ReactNode, owner: string): DiagramNode['label'] {\n const label = compileLabelChildren(children, owner);\n return label.length > 0 ? label : '';\n}\n\nconst CONTENT_HOSTS = new Set<PrimitiveKind>(['node', 'box', 'card']);\n\nfunction splitNodeContent(children: ReactNode, kind: PrimitiveKind) {\n const labelChildren: ReactNode[] = [];\n let content: DiagramNodeContent | undefined;\n Children.forEach(children, (child) => {\n if (!isValidElement(child) || primitiveKind(child) !== 'content') {\n labelChildren.push(child);\n return;\n }\n if (!CONTENT_HOSTS.has(kind)) {\n throw new Error(\n `Diagram.Content goes inside Diagram.Box, Diagram.Card or Diagram.Node, not Diagram.${kind}.`,\n );\n }\n if (content) {\n throw new Error(`Diagram.${kind} accepts one Diagram.Content.`);\n }\n const { children: element, size } =\n requirePrimitiveProps<DiagramContentProps>(child);\n content = { element, size };\n });\n return { labelChildren, content };\n}\n\nfunction nodeFrame(kind: PrimitiveKind, explicit: DiagramNode['frame']) {\n if (explicit) return explicit;\n if (kind === 'port') return 'transparent';\n if (kind === 'label') return 'none';\n if (kind === 'float') return 'flat';\n if (kind === 'appliance') return 'none';\n if (kind === 'marker') return 'none';\n return 'solid';\n}\n\nfunction compileEdge(kind: PrimitiveKind, child: ReactElement): DiagramEdge {\n const { children, badgeLabel, ...edgeProps } =\n requirePrimitiveProps<DiagramEdgeProps>(child);\n const lines = compileStringLines(children, `Diagram.${kind}`);\n return {\n ...edgeProps,\n ...(lines.length > 0 ? { label: lines } : {}),\n ...(badgeLabel !== undefined\n ? { badgeLabel: normalizeStringLines(badgeLabel) }\n : {}),\n headless: kind === 'wire' ? true : edgeProps.headless,\n };\n}\n\nfunction normalizeStringLines(value: string | string[]) {\n return (Array.isArray(value) ? value : [value])\n .map((line) => line.trim())\n .filter(Boolean);\n}\n\nfunction compileGroup(\n child: ReactElement,\n context: CompileContext,\n): { group: DiagramGraphIR['groups'][number]; children: CompileResult } {\n const {\n children: groupChildren,\n label,\n ...props\n } = requirePrimitiveProps<DiagramGroupProps>(child);\n const children = compileChildren(groupChildren, {\n ...context,\n groupId: props.id,\n });\n return {\n group: {\n ...props,\n label: normalizeGroupLabel(label),\n parent: context.groupId,\n },\n children,\n };\n}\n\nfunction normalizeGroupLabel(label: string | string[] | undefined) {\n if (Array.isArray(label)) {\n return label.map((line) => line.trim()).filter(Boolean);\n }\n return label?.trim() ?? '';\n}\n\nfunction compileLane(child: ReactElement): DiagramLane {\n const props = requirePrimitiveProps<DiagramLaneProps>(child);\n return {\n id: props.id,\n label: compileStringLines(props.children, 'Diagram.Lane'),\n accent: props.accent,\n };\n}\n\nfunction normalizeBoxed(\n boxed: boolean | DiagramSignalBox | undefined,\n): DiagramSignalBox | undefined {\n if (boxed === true) return 'source';\n if (!boxed) return undefined;\n return boxed;\n}\n\nfunction compileSignal(child: ReactElement): DiagramSignal {\n const props = requirePrimitiveProps<DiagramSignalProps>(child);\n const { children: _children, boxed, ...signalProps } = props;\n const normalizedBoxed = normalizeBoxed(boxed);\n return {\n ...signalProps,\n label: compileStringLines(props.children, 'Diagram.Signal'),\n ...(normalizedBoxed ? { boxed: normalizedBoxed } : {}),\n };\n}\n\nfunction compileFrame(child: ReactElement): DiagramFrameElement {\n const props = requirePrimitiveProps<DiagramFrameProps>(child);\n const signals: DiagramSignal[] = [];\n Children.forEach(props.children, (frameChild) => {\n if (\n frameChild === null ||\n frameChild === undefined ||\n typeof frameChild === 'boolean'\n )\n return;\n if (!isValidElement(frameChild) || primitiveKind(frameChild) !== 'signal') {\n throw new Error(\n 'Diagram.Frame only accepts direct Diagram.Signal children.',\n );\n }\n signals.push(compileSignal(frameChild));\n });\n return { label: props.label, signals };\n}\n\nfunction compileStringLines(children: ReactNode, owner: string): string[] {\n const lines: string[] = [];\n Children.forEach(children, (child) => {\n if (child === null || child === undefined || typeof child === 'boolean')\n return;\n if (isTextNode(child)) {\n const text = String(child).trim();\n if (text.length > 0) lines.push(text);\n return;\n }\n if (!isValidElement(child)) {\n throw new Error(`${owner} only accepts text or Diagram.Line children.`);\n }\n if (child.type === Fragment) {\n throw new Error(\n `${owner} does not accept React fragments. Use direct text or Diagram.Line children.`,\n );\n }\n if (primitiveKind(child) === 'line') {\n lines.push(lineText(child));\n return;\n }\n throw new Error(`${owner} only accepts text or Diagram.Line children.`);\n });\n return lines;\n}\n\nfunction compileLabelChildren(\n children: ReactNode,\n owner: string,\n): DiagramLabelLine[] {\n const lines: DiagramLabelLine[] = [];\n Children.forEach(children, (child) => {\n if (child === null || child === undefined || typeof child === 'boolean')\n return;\n if (isTextNode(child)) {\n const text = String(child).trim();\n if (text.length > 0) lines.push(text);\n return;\n }\n if (!isValidElement(child)) {\n throw new Error(`${owner} only accepts text or Diagram.Line children.`);\n }\n if (child.type === Fragment) {\n throw new Error(\n `${owner} does not accept React fragments. Use direct text or Diagram.Line children.`,\n );\n }\n if (primitiveKind(child) === 'line') {\n const props = requirePrimitiveProps<DiagramLineProps>(child);\n lines.push({\n text: lineText(child),\n ...(props.textColor ? { textColor: props.textColor } : {}),\n ...(props.fontWeight ? { fontWeight: props.fontWeight } : {}),\n });\n return;\n }\n throw new Error(`${owner} only accepts text or Diagram.Line children.`);\n });\n return lines;\n}\n\nfunction lineText(child: ReactElement): string {\n const props = requirePrimitiveProps<DiagramLineProps>(child);\n return Children.toArray(props.children)\n .map((part) => {\n if (!isTextNode(part)) {\n throw new Error('Diagram.Line only accepts text children.');\n }\n return String(part).trim();\n })\n .filter(Boolean)\n .join('');\n}\n\nexport function validateTimeline(ir: DiagramTimelineSpec) {\n const laneIds = new Set<string>();\n for (const lane of ir.lanes) {\n if (laneIds.has(lane.id))\n throw new Error(`Duplicate Diagram lane id \"${lane.id}\".`);\n laneIds.add(lane.id);\n }\n const signals = [...ir.signals, ...(ir.frame?.signals ?? [])];\n for (const signal of signals) {\n if (!laneIds.has(signal.from)) {\n throw new Error(\n `Diagram signal ${signal.from}->${signal.to} references missing lane \"${signal.from}\".`,\n );\n }\n if (!laneIds.has(signal.to)) {\n throw new Error(\n `Diagram signal ${signal.from}->${signal.to} references missing lane \"${signal.to}\".`,\n );\n }\n }\n}\n"],"mappings":"AAAA,SACEA,QAAQ,EACRC,QAAQ,EAGRC,cAAc,QACT,OAAO;AA8Bd,OAAO,MAAMC,i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'../../model/diagram-ir.ts';
|
|
2
|
+
import type { Connection } from './connections.ts';
|
|
3
|
+
/** Where a connection touches its two shapes, and where its stubs leave them. */
|
|
4
|
+
export type Attachment = {
|
|
5
|
+
start: Point;
|
|
6
|
+
startStub: Point;
|
|
7
|
+
end: Point;
|
|
8
|
+
endStub: Point;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Picks where every connection touches its shapes. A junction end is its
|
|
12
|
+
* centre and a port end is its port. The other ends that share a side of a
|
|
13
|
+
* shape split the free part of it, clear of the corners and of a caption on
|
|
14
|
+
* that side, into even slots, ordered by where their other ends lie, so they
|
|
15
|
+
* do not cross. A connection alone on two facing sides that overlap runs
|
|
16
|
+
* straight across the middle of the widest part of the overlap that no
|
|
17
|
+
* group label text lies on.
|
|
18
|
+
*/
|
|
19
|
+
export declare function attachConnections(connections: Connection[],
|
|
20
|
+
/** Group label text, by group id: a straight line between two facing sides passes beside it. */
|
|
21
|
+
groupLabels: {
|
|
22
|
+
group: string;
|
|
23
|
+
box: Box;
|
|
24
|
+
}[]): Attachment[];
|
|
25
|
+
//# sourceMappingURL=attach.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attach.d.ts","sourceRoot":"","sources":["../../../../src/lib/layouts/graph/attach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,kBAAkB,CAAC;AAalE,iFAAiF;AACjF,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,KAAK,CAAC;IACjB,GAAG,EAAE,KAAK,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;AAQF;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,UAAU,EAAE;AACzB,gGAAgG;AAChG,WAAW,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,EAAE,GACzC,UAAU,EAAE,CAkHd"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { round } from "./round.js";
|
|
2
|
+
import { GRID } from "./route-search.js";
|
|
3
|
+
import { OPPOSITE, beyond, isVertical, pointOnSide, sideLine, sideSpan } from "./sides.js";
|
|
4
|
+
import { LAYOUT_TOKENS } from "./tokens.js";
|
|
5
|
+
|
|
6
|
+
/** Where a connection touches its two shapes, and where its stubs leave them. */
|
|
7
|
+
|
|
8
|
+
/** The closest two slots on one side may lie: two grid lines, so their routes keep a line between them. */
|
|
9
|
+
const SLOT_PITCH = 2 * GRID;
|
|
10
|
+
/**
|
|
11
|
+
* Picks where every connection touches its shapes. A junction end is its
|
|
12
|
+
* centre and a port end is its port. The other ends that share a side of a
|
|
13
|
+
* shape split the free part of it, clear of the corners and of a caption on
|
|
14
|
+
* that side, into even slots, ordered by where their other ends lie, so they
|
|
15
|
+
* do not cross. A connection alone on two facing sides that overlap runs
|
|
16
|
+
* straight across the middle of the widest part of the overlap that no
|
|
17
|
+
* group label text lies on.
|
|
18
|
+
*/
|
|
19
|
+
export function attachConnections(connections, /** Group label text, by group id: a straight line between two facing sides passes beside it. */
|
|
20
|
+
groupLabels) {
|
|
21
|
+
const fixed = end => {
|
|
22
|
+
if (end.port) return end.port.point;
|
|
23
|
+
if (end.shape.kind === 'junction') return centre(end.shape.box);
|
|
24
|
+
return undefined;
|
|
25
|
+
};
|
|
26
|
+
const bySide = new Map();
|
|
27
|
+
for (const [index, connection] of connections.entries()) {
|
|
28
|
+
for (const role of ['from', 'to']) {
|
|
29
|
+
const end = connection[role];
|
|
30
|
+
if (fixed(end)) continue;
|
|
31
|
+
const key = sideKey(end);
|
|
32
|
+
bySide.set(key, [...(bySide.get(key) ?? []), {
|
|
33
|
+
connection: index,
|
|
34
|
+
role,
|
|
35
|
+
end
|
|
36
|
+
}]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const crowd = end => bySide.get(sideKey(end)).length;
|
|
40
|
+
|
|
41
|
+
/** Where each slot end touches its side, by `${connection}:${role}`. */
|
|
42
|
+
const touches = new Map();
|
|
43
|
+
const touchKey = (connection, role) => `${connection}:${role}`;
|
|
44
|
+
for (const [index, {
|
|
45
|
+
from,
|
|
46
|
+
to
|
|
47
|
+
}] of connections.entries()) {
|
|
48
|
+
const between = groupLabels.flatMap(({
|
|
49
|
+
group,
|
|
50
|
+
box
|
|
51
|
+
}) => group === from.shape.id || group === to.shape.id ? [] : [box]);
|
|
52
|
+
const aligned = facingAlignment(from, to, fixed(from), fixed(to), crowd, between);
|
|
53
|
+
if (aligned) {
|
|
54
|
+
touches.set(touchKey(index, 'from'), aligned.from);
|
|
55
|
+
touches.set(touchKey(index, 'to'), aligned.to);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const slots of bySide.values()) {
|
|
59
|
+
const open = slots.filter(({
|
|
60
|
+
connection,
|
|
61
|
+
role
|
|
62
|
+
}) => !touches.has(touchKey(connection, role)));
|
|
63
|
+
if (open.length === 0) continue;
|
|
64
|
+
const {
|
|
65
|
+
end
|
|
66
|
+
} = slots[0];
|
|
67
|
+
const vertical = isVertical(end.side);
|
|
68
|
+
const otherAt = ({
|
|
69
|
+
connection,
|
|
70
|
+
role
|
|
71
|
+
}) => {
|
|
72
|
+
const other = connections[connection][role === 'from' ? 'to' : 'from'];
|
|
73
|
+
const at = fixed(other) ?? centre(other.shape.box);
|
|
74
|
+
return vertical ? at.x : at.y;
|
|
75
|
+
};
|
|
76
|
+
const ordered = open.map((slot, order) => ({
|
|
77
|
+
slot,
|
|
78
|
+
order,
|
|
79
|
+
at: otherAt(slot)
|
|
80
|
+
})).sort((a, b) => a.at - b.at || a.order - b.order);
|
|
81
|
+
const alongs = spread(end, ordered.length);
|
|
82
|
+
const free = freeIntervals(end, ordered.length);
|
|
83
|
+
for (const [index, {
|
|
84
|
+
slot,
|
|
85
|
+
at
|
|
86
|
+
}] of ordered.entries()) {
|
|
87
|
+
// A slot whose other end is a fixed point on the facing side moves in line with it, when it stays in order and SLOT_PITCH clear.
|
|
88
|
+
const {
|
|
89
|
+
from,
|
|
90
|
+
to
|
|
91
|
+
} = connections[slot.connection];
|
|
92
|
+
const other = slot.role === 'from' ? to : from;
|
|
93
|
+
if (to.side !== OPPOSITE[from.side] || !fixed(other)) continue;
|
|
94
|
+
const before = alongs[index - 1] ?? -Infinity;
|
|
95
|
+
const after = alongs[index + 1] ?? Infinity;
|
|
96
|
+
const fits = at - before >= SLOT_PITCH && after - at >= SLOT_PITCH && free.some(([low, high]) => at >= low && at <= high);
|
|
97
|
+
if (fits) alongs[index] = at;
|
|
98
|
+
}
|
|
99
|
+
for (const [index, {
|
|
100
|
+
slot
|
|
101
|
+
}] of ordered.entries()) {
|
|
102
|
+
touches.set(touchKey(slot.connection, slot.role), pointOnSide(end.face, end.side, alongs[index]));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// An end alone on a side that faces a shared side lines up with its slot there, so the connection runs straight.
|
|
107
|
+
for (const [index, {
|
|
108
|
+
from,
|
|
109
|
+
to
|
|
110
|
+
}] of connections.entries()) {
|
|
111
|
+
if (fixed(from) || fixed(to)) continue;
|
|
112
|
+
const ends = [{
|
|
113
|
+
lone: from,
|
|
114
|
+
loneRole: 'from',
|
|
115
|
+
shared: to,
|
|
116
|
+
sharedRole: 'to'
|
|
117
|
+
}, {
|
|
118
|
+
lone: to,
|
|
119
|
+
loneRole: 'to',
|
|
120
|
+
shared: from,
|
|
121
|
+
sharedRole: 'from'
|
|
122
|
+
}];
|
|
123
|
+
for (const {
|
|
124
|
+
lone,
|
|
125
|
+
loneRole,
|
|
126
|
+
shared,
|
|
127
|
+
sharedRole
|
|
128
|
+
} of ends) {
|
|
129
|
+
if (crowd(lone) !== 1 || crowd(shared) === 1) continue;
|
|
130
|
+
const slot = touches.get(touchKey(index, sharedRole));
|
|
131
|
+
const between = groupLabels.flatMap(({
|
|
132
|
+
group,
|
|
133
|
+
box
|
|
134
|
+
}) => group === from.shape.id || group === to.shape.id ? [] : [box]);
|
|
135
|
+
const aligned = loneRole === 'from' ? facingAlignment(lone, shared, undefined, slot, crowd, between)?.from : facingAlignment(shared, lone, slot, undefined, crowd, between)?.to;
|
|
136
|
+
if (aligned) touches.set(touchKey(index, loneRole), aligned);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return connections.map((connection, index) => {
|
|
140
|
+
const start = fixed(connection.from) ?? touches.get(touchKey(index, 'from'));
|
|
141
|
+
const end = fixed(connection.to) ?? touches.get(touchKey(index, 'to'));
|
|
142
|
+
const stub = stubLength(connection, start, end);
|
|
143
|
+
return {
|
|
144
|
+
start,
|
|
145
|
+
startStub: beyond(start, connection.from.side, stub),
|
|
146
|
+
end,
|
|
147
|
+
endStub: beyond(end, connection.to.side, stub)
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The parts of a side a connection may touch: the side less its corner
|
|
154
|
+
* inset, less what lies behind a caption on that side. A short side gives up
|
|
155
|
+
* its corner inset before its slots come closer than SLOT_PITCH.
|
|
156
|
+
*/
|
|
157
|
+
function freeIntervals(end, count) {
|
|
158
|
+
const {
|
|
159
|
+
shape,
|
|
160
|
+
side,
|
|
161
|
+
face
|
|
162
|
+
} = end;
|
|
163
|
+
const [from, to] = sideSpan(face, side);
|
|
164
|
+
const inset = Math.max(0, Math.min(shape.radius, (to - from - (count + 1) * SLOT_PITCH) / 2));
|
|
165
|
+
const vertical = isVertical(side);
|
|
166
|
+
const line = sideLine(face, side);
|
|
167
|
+
const outward = side === 'bottom' || side === 'right';
|
|
168
|
+
const behind = shape.clear.flatMap(box => {
|
|
169
|
+
const [near, far] = vertical ? [box.y, box.y + box.h] : [box.x, box.x + box.w];
|
|
170
|
+
if (outward ? near < line : far > line) return [];
|
|
171
|
+
return vertical ? [[box.x - SLOT_PITCH, box.x + box.w + SLOT_PITCH]] : [[box.y - SLOT_PITCH, box.y + box.h + SLOT_PITCH]];
|
|
172
|
+
});
|
|
173
|
+
return cut([[from + inset, to - inset]], behind);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** The parts of `intervals` outside every one of `cuts`. */
|
|
177
|
+
function cut(intervals, cuts) {
|
|
178
|
+
let free = intervals;
|
|
179
|
+
for (const [cutStart, cutEnd] of cuts) {
|
|
180
|
+
free = free.flatMap(([a, b]) => [[a, Math.min(b, cutStart)], [Math.max(a, cutEnd), b]]).filter(([low, high]) => high > low);
|
|
181
|
+
}
|
|
182
|
+
return free;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Positions for `count` slots on the free parts of a side, in order along
|
|
187
|
+
* it: each next slot goes to the part where slots would lie farthest apart,
|
|
188
|
+
* and each part spaces its slots evenly.
|
|
189
|
+
*/
|
|
190
|
+
function spread(end, count) {
|
|
191
|
+
const intervals = freeIntervals(end, count);
|
|
192
|
+
const counts = intervals.map(() => 0);
|
|
193
|
+
const pitchWithOneMore = index => (intervals[index][1] - intervals[index][0]) / (counts[index] + 2);
|
|
194
|
+
for (let placed = 0; placed < count && intervals.length > 0; placed++) {
|
|
195
|
+
const roomiest = counts.reduce((best, _, index) => pitchWithOneMore(index) > pitchWithOneMore(best) ? index : best, 0);
|
|
196
|
+
counts[roomiest] = counts[roomiest] + 1;
|
|
197
|
+
}
|
|
198
|
+
const alongs = intervals.flatMap(([a, b], index) => Array.from({
|
|
199
|
+
length: counts[index]
|
|
200
|
+
}, (_, slot) => a + (slot + 1) / (counts[index] + 1) * (b - a)));
|
|
201
|
+
// Rounded to the layout's output precision: when freeIntervals shrinks a
|
|
202
|
+
// side to fit its slots exactly SLOT_PITCH apart, float drift lands just
|
|
203
|
+
// under SLOT_PITCH.
|
|
204
|
+
const closest = round(Math.min(...intervals.flatMap(([a, b], index) => counts[index] > 1 ? [(b - a) / (counts[index] + 1)] : [])));
|
|
205
|
+
if (alongs.length < count || closest < SLOT_PITCH) {
|
|
206
|
+
const {
|
|
207
|
+
shape,
|
|
208
|
+
side
|
|
209
|
+
} = end;
|
|
210
|
+
throw new Error(`Diagram ${shape.kind === 'group' ? 'group' : 'node'} "${shape.id}" side ${side} has no room for ${count} connections ${SLOT_PITCH}px apart beside its corners and caption.`);
|
|
211
|
+
}
|
|
212
|
+
return alongs;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Both ends on the middle of the widest part of the overlap of two facing
|
|
217
|
+
* sides that no label in `labels` between the sides lies on, when the
|
|
218
|
+
* connection is alone on each.
|
|
219
|
+
*/
|
|
220
|
+
function facingAlignment(from, to, fromFixed, toFixed, crowd, labels) {
|
|
221
|
+
if (to.side !== OPPOSITE[from.side] || fromFixed && toFixed) return;
|
|
222
|
+
if (!fromFixed && crowd(from) !== 1) return;
|
|
223
|
+
if (!toFixed && crowd(to) !== 1) return;
|
|
224
|
+
const vertical = isVertical(from.side);
|
|
225
|
+
const free = (end, at) => {
|
|
226
|
+
if (!at) return freeIntervals(end, 1);
|
|
227
|
+
const along = vertical ? at.x : at.y;
|
|
228
|
+
return [[along, along]];
|
|
229
|
+
};
|
|
230
|
+
const lines = [sideLine(from.face, from.side), sideLine(to.face, to.side)];
|
|
231
|
+
const [gapStart, gapEnd] = [Math.min(...lines), Math.max(...lines)];
|
|
232
|
+
const inGap = labels.flatMap(({
|
|
233
|
+
x,
|
|
234
|
+
y,
|
|
235
|
+
w,
|
|
236
|
+
h
|
|
237
|
+
}) => {
|
|
238
|
+
const [across, acrossEnd, along, alongEnd] = vertical ? [y, y + h, x, x + w] : [x, x + w, y, y + h];
|
|
239
|
+
return across < gapEnd && acrossEnd > gapStart ? [[along, alongEnd]] : [];
|
|
240
|
+
});
|
|
241
|
+
const widest = free(from, fromFixed).flatMap(([a0, a1]) => free(to, toFixed).flatMap(([b0, b1]) => cut([[Math.max(a0, b0), Math.min(a1, b1)]], inGap))).filter(([low, high]) => low <= high).sort((a, b) => b[1] - b[0] - (a[1] - a[0]))[0];
|
|
242
|
+
if (!widest) return;
|
|
243
|
+
const along = (widest[0] + widest[1]) / 2;
|
|
244
|
+
return {
|
|
245
|
+
from: fromFixed ?? pointOnSide(from.face, from.side, along),
|
|
246
|
+
to: toFixed ?? pointOnSide(to.face, to.side, along)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* A stub is STUB long, except between two ends that face each other closer
|
|
252
|
+
* than two stubs: then each stub reaches half way, so they meet in the gap.
|
|
253
|
+
*/
|
|
254
|
+
function stubLength(connection, start, end) {
|
|
255
|
+
const {
|
|
256
|
+
from,
|
|
257
|
+
to
|
|
258
|
+
} = connection;
|
|
259
|
+
if (to.side !== OPPOSITE[from.side]) return LAYOUT_TOKENS.STUB;
|
|
260
|
+
const gap = (isVertical(from.side) ? end.y - start.y : end.x - start.x) * (from.side === 'bottom' || from.side === 'right' ? 1 : -1);
|
|
261
|
+
return gap > 0 && gap < 2 * LAYOUT_TOKENS.STUB ? gap / 2 : LAYOUT_TOKENS.STUB;
|
|
262
|
+
}
|
|
263
|
+
function sideKey(end) {
|
|
264
|
+
return `${end.shape.id}\u0000${end.side}`;
|
|
265
|
+
}
|
|
266
|
+
function centre(box) {
|
|
267
|
+
return {
|
|
268
|
+
x: box.x + box.w / 2,
|
|
269
|
+
y: box.y + box.h / 2
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=attach.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attach.js","names":["round","GRID","OPPOSITE","beyond","isVertical","pointOnSide","sideLine","sideSpan","LAYOUT_TOKENS","SLOT_PITCH","attachConnections","connections","groupLabels","fixed","end","port","point","shape","kind","centre","box","undefined","bySide","Map","index","connection","entries","role","key","sideKey","set","get","crowd","length","touches","touchKey","from","to","between","flatMap","group","id","aligned","facingAlignment","slots","values","open","filter","has","vertical","side","otherAt","other","at","x","y","ordered","map","slot","order","sort","a","b","alongs","spread","free","freeIntervals","before","Infinity","after","fits","some","low","high","face","ends","lone","loneRole","shared","sharedRole","start","stub","stubLength","startStub","endStub","count","inset","Math","max","min","radius","line","outward","behind","clear","near","far","h","w","cut","intervals","cuts","cutStart","cutEnd","counts","pitchWithOneMore","placed","roomiest","reduce","best","_","Array","closest","Error","fromFixed","toFixed","labels","along","lines","gapStart","gapEnd","inGap","across","acrossEnd","alongEnd","widest","a0","a1","b0","b1","STUB","gap"],"sources":["../../../../src/lib/layouts/graph/attach.ts"],"sourcesContent":["import type { Box, Point } from '../../model/diagram-ir.ts';\nimport type { Connection, ConnectionEnd } from './connections.ts';\nimport { round } from './round.ts';\nimport { GRID } from './route-search.ts';\nimport {\n OPPOSITE,\n beyond,\n isVertical,\n pointOnSide,\n sideLine,\n sideSpan,\n} from './sides.ts';\nimport { LAYOUT_TOKENS } from './tokens.ts';\n\n/** Where a connection touches its two shapes, and where its stubs leave them. */\nexport type Attachment = {\n start: Point;\n startStub: Point;\n end: Point;\n endStub: Point;\n};\n\n/** The closest two slots on one side may lie: two grid lines, so their routes keep a line between them. */\nconst SLOT_PITCH = 2 * GRID;\n\ntype Slot = { connection: number; role: 'from' | 'to'; end: ConnectionEnd };\ntype Interval = [number, number];\n\n/**\n * Picks where every connection touches its shapes. A junction end is its\n * centre and a port end is its port. The other ends that share a side of a\n * shape split the free part of it, clear of the corners and of a caption on\n * that side, into even slots, ordered by where their other ends lie, so they\n * do not cross. A connection alone on two facing sides that overlap runs\n * straight across the middle of the widest part of the overlap that no\n * group label text lies on.\n */\nexport function attachConnections(\n connections: Connection[],\n /** Group label text, by group id: a straight line between two facing sides passes beside it. */\n groupLabels: { group: string; box: Box }[],\n): Attachment[] {\n const fixed = (end: ConnectionEnd): Point | undefined => {\n if (end.port) return end.port.point;\n if (end.shape.kind === 'junction') return centre(end.shape.box);\n return undefined;\n };\n\n const bySide = new Map<string, Slot[]>();\n for (const [index, connection] of connections.entries()) {\n for (const role of ['from', 'to'] as const) {\n const end = connection[role];\n if (fixed(end)) continue;\n const key = sideKey(end);\n bySide.set(key, [\n ...(bySide.get(key) ?? []),\n { connection: index, role, end },\n ]);\n }\n }\n const crowd = (end: ConnectionEnd) => bySide.get(sideKey(end))!.length;\n\n /** Where each slot end touches its side, by `${connection}:${role}`. */\n const touches = new Map<string, Point>();\n const touchKey = (connection: number, role: 'from' | 'to') =>\n `${connection}:${role}`;\n for (const [index, { from, to }] of connections.entries()) {\n const between = groupLabels.flatMap(({ group, box }) =>\n group === from.shape.id || group === to.shape.id ? [] : [box],\n );\n const aligned = facingAlignment(\n from,\n to,\n fixed(from),\n fixed(to),\n crowd,\n between,\n );\n if (aligned) {\n touches.set(touchKey(index, 'from'), aligned.from);\n touches.set(touchKey(index, 'to'), aligned.to);\n }\n }\n\n for (const slots of bySide.values()) {\n const open = slots.filter(\n ({ connection, role }) => !touches.has(touchKey(connection, role)),\n );\n if (open.length === 0) continue;\n const { end } = slots[0]!;\n const vertical = isVertical(end.side);\n const otherAt = ({ connection, role }: Slot) => {\n const other = connections[connection]![role === 'from' ? 'to' : 'from'];\n const at = fixed(other) ?? centre(other.shape.box);\n return vertical ? at.x : at.y;\n };\n const ordered = open\n .map((slot, order) => ({ slot, order, at: otherAt(slot) }))\n .sort((a, b) => a.at - b.at || a.order - b.order);\n const alongs = spread(end, ordered.length);\n const free = freeIntervals(end, ordered.length);\n for (const [index, { slot, at }] of ordered.entries()) {\n // A slot whose other end is a fixed point on the facing side moves in line with it, when it stays in order and SLOT_PITCH clear.\n const { from, to } = connections[slot.connection]!;\n const other = slot.role === 'from' ? to : from;\n if (to.side !== OPPOSITE[from.side] || !fixed(other)) continue;\n const before = alongs[index - 1] ?? -Infinity;\n const after = alongs[index + 1] ?? Infinity;\n const fits =\n at - before >= SLOT_PITCH &&\n after - at >= SLOT_PITCH &&\n free.some(([low, high]) => at >= low && at <= high);\n if (fits) alongs[index] = at;\n }\n for (const [index, { slot }] of ordered.entries()) {\n touches.set(\n touchKey(slot.connection, slot.role),\n pointOnSide(end.face, end.side, alongs[index]!),\n );\n }\n }\n\n // An end alone on a side that faces a shared side lines up with its slot there, so the connection runs straight.\n for (const [index, { from, to }] of connections.entries()) {\n if (fixed(from) || fixed(to)) continue;\n const ends = [\n { lone: from, loneRole: 'from', shared: to, sharedRole: 'to' },\n { lone: to, loneRole: 'to', shared: from, sharedRole: 'from' },\n ] as const;\n for (const { lone, loneRole, shared, sharedRole } of ends) {\n if (crowd(lone) !== 1 || crowd(shared) === 1) continue;\n const slot = touches.get(touchKey(index, sharedRole))!;\n const between = groupLabels.flatMap(({ group, box }) =>\n group === from.shape.id || group === to.shape.id ? [] : [box],\n );\n const aligned =\n loneRole === 'from'\n ? facingAlignment(lone, shared, undefined, slot, crowd, between)?.from\n : facingAlignment(shared, lone, slot, undefined, crowd, between)?.to;\n if (aligned) touches.set(touchKey(index, loneRole), aligned);\n }\n }\n\n return connections.map((connection, index) => {\n const start =\n fixed(connection.from) ?? touches.get(touchKey(index, 'from'))!;\n const end = fixed(connection.to) ?? touches.get(touchKey(index, 'to'))!;\n const stub = stubLength(connection, start, end);\n return {\n start,\n startStub: beyond(start, connection.from.side, stub),\n end,\n endStub: beyond(end, connection.to.side, stub),\n };\n });\n}\n\n/**\n * The parts of a side a connection may touch: the side less its corner\n * inset, less what lies behind a caption on that side. A short side gives up\n * its corner inset before its slots come closer than SLOT_PITCH.\n */\nfunction freeIntervals(end: ConnectionEnd, count: number): Interval[] {\n const { shape, side, face } = end;\n const [from, to] = sideSpan(face, side);\n const inset = Math.max(\n 0,\n Math.min(shape.radius, (to - from - (count + 1) * SLOT_PITCH) / 2),\n );\n const vertical = isVertical(side);\n const line = sideLine(face, side);\n const outward = side === 'bottom' || side === 'right';\n const behind = shape.clear.flatMap((box): Interval[] => {\n const [near, far] = vertical\n ? [box.y, box.y + box.h]\n : [box.x, box.x + box.w];\n if (outward ? near < line : far > line) return [];\n return vertical\n ? [[box.x - SLOT_PITCH, box.x + box.w + SLOT_PITCH]]\n : [[box.y - SLOT_PITCH, box.y + box.h + SLOT_PITCH]];\n });\n return cut([[from + inset, to - inset]], behind);\n}\n\n/** The parts of `intervals` outside every one of `cuts`. */\nfunction cut(intervals: Interval[], cuts: Interval[]): Interval[] {\n let free = intervals;\n for (const [cutStart, cutEnd] of cuts) {\n free = free\n .flatMap(([a, b]): Interval[] => [\n [a, Math.min(b, cutStart)],\n [Math.max(a, cutEnd), b],\n ])\n .filter(([low, high]) => high > low);\n }\n return free;\n}\n\n/**\n * Positions for `count` slots on the free parts of a side, in order along\n * it: each next slot goes to the part where slots would lie farthest apart,\n * and each part spaces its slots evenly.\n */\nfunction spread(end: ConnectionEnd, count: number): number[] {\n const intervals = freeIntervals(end, count);\n const counts = intervals.map(() => 0);\n const pitchWithOneMore = (index: number) =>\n (intervals[index]![1] - intervals[index]![0]) / (counts[index]! + 2);\n for (let placed = 0; placed < count && intervals.length > 0; placed++) {\n const roomiest = counts.reduce(\n (best, _, index) =>\n pitchWithOneMore(index) > pitchWithOneMore(best) ? index : best,\n 0,\n );\n counts[roomiest] = counts[roomiest]! + 1;\n }\n const alongs = intervals.flatMap(([a, b], index) =>\n Array.from(\n { length: counts[index]! },\n (_, slot) => a + ((slot + 1) / (counts[index]! + 1)) * (b - a),\n ),\n );\n // Rounded to the layout's output precision: when freeIntervals shrinks a\n // side to fit its slots exactly SLOT_PITCH apart, float drift lands just\n // under SLOT_PITCH.\n const closest = round(\n Math.min(\n ...intervals.flatMap(([a, b], index) =>\n counts[index]! > 1 ? [(b - a) / (counts[index]! + 1)] : [],\n ),\n ),\n );\n if (alongs.length < count || closest < SLOT_PITCH) {\n const { shape, side } = end;\n throw new Error(\n `Diagram ${shape.kind === 'group' ? 'group' : 'node'} \"${shape.id}\" side ${side} has no room for ${count} connections ${SLOT_PITCH}px apart beside its corners and caption.`,\n );\n }\n return alongs;\n}\n\n/**\n * Both ends on the middle of the widest part of the overlap of two facing\n * sides that no label in `labels` between the sides lies on, when the\n * connection is alone on each.\n */\nfunction facingAlignment(\n from: ConnectionEnd,\n to: ConnectionEnd,\n fromFixed: Point | undefined,\n toFixed: Point | undefined,\n crowd: (end: ConnectionEnd) => number,\n labels: Box[],\n): { from: Point; to: Point } | undefined {\n if (to.side !== OPPOSITE[from.side] || (fromFixed && toFixed)) return;\n if (!fromFixed && crowd(from) !== 1) return;\n if (!toFixed && crowd(to) !== 1) return;\n const vertical = isVertical(from.side);\n const free = (end: ConnectionEnd, at: Point | undefined): Interval[] => {\n if (!at) return freeIntervals(end, 1);\n const along = vertical ? at.x : at.y;\n return [[along, along]];\n };\n const lines = [sideLine(from.face, from.side), sideLine(to.face, to.side)];\n const [gapStart, gapEnd] = [Math.min(...lines), Math.max(...lines)];\n const inGap = labels.flatMap(({ x, y, w, h }): Interval[] => {\n const [across, acrossEnd, along, alongEnd] = vertical\n ? [y, y + h, x, x + w]\n : [x, x + w, y, y + h];\n return across < gapEnd && acrossEnd > gapStart ? [[along, alongEnd]] : [];\n });\n const widest = free(from, fromFixed)\n .flatMap(([a0, a1]) =>\n free(to, toFixed).flatMap(([b0, b1]) =>\n cut([[Math.max(a0, b0), Math.min(a1, b1)]], inGap),\n ),\n )\n .filter(([low, high]) => low <= high)\n .sort((a, b) => b[1] - b[0] - (a[1] - a[0]))[0];\n if (!widest) return;\n const along = (widest[0] + widest[1]) / 2;\n return {\n from: fromFixed ?? pointOnSide(from.face, from.side, along),\n to: toFixed ?? pointOnSide(to.face, to.side, along),\n };\n}\n\n/**\n * A stub is STUB long, except between two ends that face each other closer\n * than two stubs: then each stub reaches half way, so they meet in the gap.\n */\nfunction stubLength(connection: Connection, start: Point, end: Point): number {\n const { from, to } = connection;\n if (to.side !== OPPOSITE[from.side]) return LAYOUT_TOKENS.STUB;\n const gap =\n (isVertical(from.side) ? end.y - start.y : end.x - start.x) *\n (from.side === 'bottom' || from.side === 'right' ? 1 : -1);\n return gap > 0 && gap < 2 * LAYOUT_TOKENS.STUB ? gap / 2 : LAYOUT_TOKENS.STUB;\n}\n\nfunction sideKey(end: ConnectionEnd): string {\n return `${end.shape.id}\\u0000${end.side}`;\n}\n\nfunction centre(box: Box): Point {\n return { x: box.x + box.w / 2, y: box.y + box.h / 2 };\n}\n"],"mappings":"AAEA,SAASA,KAAK,QAAQ,YAAY;AAClC,SAASC,IAAI,QAAQ,mBAAmB;AACxC,SACEC,QAAQ,EACRC,MAAM,EACNC,UAAU,EACVC,WAAW,EACXC,QAAQ,EACRC,QAAQ,QACH,YAAY;AACnB,SAASC,aAAa,QAAQ,aAAa;;AAE3C;;AAQA;AACA,MAAMC,UAAU,GAAG,CAAC,GAAGR,IAAI;AAK3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASS,iBAAiBA,CAC/BC,WAAyB,EACzB;AACAC,WAA0C,EAC5B;EACd,MAAMC,KAAK,GAAIC,GAAkB,IAAwB;IACvD,IAAIA,GAAG,CAACC,IAAI,EAAE,OAAOD,GAAG,CAACC,IAAI,CAACC,KAAK;IACnC,IAAIF,GAAG,CAACG,KAAK,CAACC,IAAI,KAAK,UAAU,EAAE,OAAOC,MAAM,CAACL,GAAG,CAACG,KAAK,CAACG,GAAG,CAAC;IAC/D,OAAOC,SAAS;EAClB,CAAC;EAED,MAAMC,MAAM,GAAG,IAAIC,GAAG,CAAiB,CAAC;EACxC,KAAK,MAAM,CAACC,KAAK,EAAEC,UAAU,CAAC,IAAId,WAAW,CAACe,OAAO,CAAC,CAAC,EAAE;IACvD,KAAK,MAAMC,IAAI,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAW;MAC1C,MAAMb,GAAG,GAAGW,UAAU,CAACE,IAAI,CAAC;MAC5B,IAAId,KAAK,CAACC,GAAG,CAAC,EAAE;MAChB,MAAMc,GAAG,GAAGC,OAAO,CAACf,GAAG,CAAC;MACxBQ,MAAM,CAACQ,GAAG,CAACF,GAAG,EAAE,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C,CAAC,EAAEnC,GAAG,CAACmC,CAAC,GAAGnC,GAAG,CAAC6E,CAAC,GAAG;EAAE,CAAC;AACvD","ignoreList":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Box, DiagramGraphIR, DiagramSide } from '../../model/diagram-ir.ts';
|
|
2
|
+
import type { CellArea, GridAreas } from './areas.ts';
|
|
3
|
+
import type { GroupLayout, NodeLayout, PortLayout } from './graph-layout-result.ts';
|
|
4
|
+
/** A node or group that a connection starts or ends at. */
|
|
5
|
+
export type Shape = {
|
|
6
|
+
id: string;
|
|
7
|
+
kind: 'node' | 'junction' | 'group';
|
|
8
|
+
box: Box;
|
|
9
|
+
/** The corner radius, which slots keep clear of. */
|
|
10
|
+
radius: number;
|
|
11
|
+
/** A stack's back frames, which draw as one unit with `box`. */
|
|
12
|
+
frames: Box[];
|
|
13
|
+
ports: PortLayout[];
|
|
14
|
+
/** What a connection may not touch the shape through: its caption. */
|
|
15
|
+
clear: Box[];
|
|
16
|
+
area: CellArea;
|
|
17
|
+
};
|
|
18
|
+
export type ConnectionEnd = {
|
|
19
|
+
shape: Shape;
|
|
20
|
+
side: DiagramSide;
|
|
21
|
+
port: PortLayout | undefined;
|
|
22
|
+
/** The box whose `side` the end touches: of a stack, the frame that reaches farthest out on that side. */
|
|
23
|
+
face: Box;
|
|
24
|
+
};
|
|
25
|
+
/** An edge, or the leader from a note to its target: anything the router draws between two shapes. */
|
|
26
|
+
export type Connection = {
|
|
27
|
+
/** How errors name it: `edge a→b`, or `note leader "n"→"t"`. */
|
|
28
|
+
name: string;
|
|
29
|
+
/** The index of the edge in the graph, or undefined for a leader. */
|
|
30
|
+
edge: number | undefined;
|
|
31
|
+
from: ConnectionEnd;
|
|
32
|
+
to: ConnectionEnd;
|
|
33
|
+
/** The Manhattan distance between the two cell areas' centres. */
|
|
34
|
+
cellDistance: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Resolves every edge and every note leader to the shapes and sides it may
|
|
38
|
+
* join, in order of preference. A side hint wins over the cells; a port
|
|
39
|
+
* fixes the side; a side that declares ports takes no edge without one. A
|
|
40
|
+
* connection between two shapes with no hint and no port on either end may
|
|
41
|
+
* also take the other side pairs the cells allow, whose sides declare no
|
|
42
|
+
* ports; any other connection has one choice.
|
|
43
|
+
*/
|
|
44
|
+
export declare function graphConnections(ir: DiagramGraphIR, nodes: NodeLayout[], groups: GroupLayout[], areas: GridAreas): Connection[][];
|
|
45
|
+
//# sourceMappingURL=connections.d.ts.map
|