@opsydyn/foldkit-zloz-elk 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,18 @@
8
8
 
9
9
  - Reserve caller-declared composite edge-label bounds in compound layouts and return validated world-coordinate boxes, including custom badges on unlabeled edges.
10
10
 
11
+ ## [0.6.1](https://github.com/opsydyn/fold-kit-experiments/compare/foldkit-zloz-elk-v0.6.0...foldkit-zloz-elk-v0.6.1) (2026-11-16)
12
+
13
+ ### Bug Fixes
14
+
15
+ - **zloz:** ship documentation through a verified family release train ([#156](https://github.com/opsydyn/fold-kit-experiments/issues/156)) ([51977d2](https://github.com/opsydyn/fold-kit-experiments/commit/51977d2c2c517c83c537454389c7f24689e229e7))
16
+
17
+ ## [0.6.0](https://github.com/opsydyn/fold-kit-experiments/compare/foldkit-zloz-elk-v0.5.0...foldkit-zloz-elk-v0.6.0) (2026-11-16)
18
+
19
+ ### Features
20
+
21
+ - **zloz:** complete native v3 workflows and release qualification ([#151](https://github.com/opsydyn/fold-kit-experiments/issues/151)) ([629f7a3](https://github.com/opsydyn/fold-kit-experiments/commit/629f7a3824fe0751ca6ea816880ede1f5b4bb2ee))
22
+
11
23
  ## [0.5.0](https://github.com/opsydyn/fold-kit-experiments/compare/foldkit-zloz-elk-v0.4.0...foldkit-zloz-elk-v0.5.0) (2026-11-15)
12
24
 
13
25
  ### Miscellaneous Chores
package/README.md CHANGED
@@ -3,11 +3,13 @@
3
3
  Optional automatic layout for `@opsydyn/foldkit-zloz`. The adapter maps flat and nested graphs with fixed ports to ELK Layered. It returns node
4
4
  positions, fitted group bounds, and orthogonal edge routes. It owns no UI, persistence, graph state or workflow execution.
5
5
 
6
- Version 0.1.0 is a local release candidate; npm publication has not been performed.
6
+ The public package family is released together. Native v3 group-port layout is included in 0.6.0.
7
7
 
8
- ## Install and use
8
+ The four public Zloz packages release together, with adapters pinned to the exact
9
+ core version. The [release train](https://github.com/opsydyn/fold-kit-experiments/blob/main/docs/releases/foldkit-zloz.md#release-action)
10
+ verifies registry archives and provenance before advancing to the next package.
9
11
 
10
- After publication:
12
+ ## Install and use
11
13
 
12
14
  ```sh
13
15
  npm install @opsydyn/foldkit-zloz @opsydyn/foldkit-zloz-elk
@@ -46,14 +48,16 @@ does not cancel ELK computation; request/revision checks prevent late publicatio
46
48
  See [ELK's worker documentation](https://github.com/kieler/elkjs#web-worker).
47
49
 
48
50
  ELK is an external dependency, not bundled into this package. The core package
49
- installs and works without it. Node 22+, ESM only. Initial compatibility is Zloz
50
- 0.1.0 and the pinned elkjs 0.12.1. Both Zloz packages release at the same version.
51
+ installs and works without it. Node 22+, ESM only. Compatibility uses the matching Zloz version and the pinned elkjs 0.12.1. Both Zloz packages release at the same version.
51
52
  The adapter has no FoldKit or Effect peer.
52
53
 
53
- The default adapter is qualified in Node and Chromium. Bun can compute layouts,
54
- but elkjs 0.12.1's bundled fallback installs a global `self.onmessage` handler in
55
- Bun 1.4.4, keeping a standalone process alive after completion. Use Node for CLI
56
- layout jobs. The dependency-free core is separately tested in both Node and Bun.
54
+ The server baseline is **Node 22+**; the default adapter is qualified in Node and
55
+ Chromium. In the observed Bun 1.4.4 / macOS 26.6.2 arm64 consumer, layout completes
56
+ but the standalone process stays alive. A minimal `elkjs@0.12.1` program reproduces
57
+ this without Zloz. Bun process-exit behavior for ELK is outside this release's
58
+ qualification; use Node for CLI layout jobs. Other Bun versions/platforms are
59
+ unqualified for this lifecycle behavior. Core, Force and Mermaid separately pass
60
+ standalone Node and Bun consumers.
57
61
 
58
62
  ## Scope and verification
59
63
 
@@ -68,7 +72,9 @@ real layout plus the optional FoldKit renderer.
68
72
  See [publication standards](https://github.com/opsydyn/fold-kit-experiments/blob/main/docs/releases/foldkit-zloz.md) and
69
73
  [dependency notices](THIRD-PARTY-NOTICES.md).
70
74
 
71
- ### Compound preview layouts (unreleased)
75
+ <a id="compound-preview-layouts-unreleased"></a>
76
+
77
+ ### Compound preview layouts
72
78
 
73
79
  Configured `direction` and `spacing` now apply to root **and group parent**
74
80
  containers. A real-engine regression retains at least the requested inter-layer
@@ -82,7 +88,9 @@ cancellation, geometry-only restoration and preserved source/findings. See
82
88
  [qualification](../../apps/zloz-demo/evidence/alchemy-layout.md). Label dimensions
83
89
  are not yet supplied to ELK, so this is not a universal label-collision guarantee.
84
90
 
85
- ### Custom label envelopes (unreleased)
91
+ <a id="custom-label-envelopes-unreleased"></a>
92
+
93
+ ### Custom label envelopes
86
94
 
87
95
  Pass `layoutRequest(editor, id, { edgeLabels: [{ id: edgeId, size: { width: 176,
88
96
  height: 36 } }] })` to reserve space for a composite label, including badges.
@@ -102,7 +110,9 @@ request. Recheck freshness before both starting ELK and applying its result; ELK
102
110
  does not load fonts, inspect DOM or start measurement itself. See the
103
111
  [core measured-label guide](../foldkit-zloz/README.md#opt-in-measured-label-bounds-unreleased).
104
112
 
105
- ### Group heading envelopes (unreleased)
113
+ <a id="group-heading-envelopes-unreleased"></a>
114
+
115
+ ### Group heading envelopes
106
116
 
107
117
  Core requests may declare `groupHeaders` with an existing group ID, header `size`,
108
118
  `padding: { top, right, bottom, left }` and a `gap` before children. ELK maps these
@@ -117,3 +127,43 @@ regressions qualify both directions. Requalify the correction when upgrading ELK
117
127
  or supplying a worker from another version. No post-layout stretching is used.
118
128
  These hints reserve child-node space; they do not guarantee arbitrary route or
119
129
  custom-artwork collision avoidance.
130
+
131
+ <a id="native-v3-group-port-layout-unreleased"></a>
132
+
133
+ ## Native v3 group-port layout
134
+
135
+ Use the distinct full-document entry for authored group ports:
136
+
137
+ ```ts
138
+ import { groupLayoutRequestV3, applyGroupLayoutV3 } from '@opsydyn/foldkit-zloz';
139
+ import { createElkGroupLayoutV3 } from '@opsydyn/foldkit-zloz-elk';
140
+
141
+ const active = groupLayoutRequestV3(editorV3, 'arrange-v3-1');
142
+ // Store active in Model before executing this Promise in a Command.
143
+ const result = await createElkGroupLayoutV3({ direction: 'RIGHT' })(active);
144
+ // At completion, read the current editor, active request and live policy from Model.
145
+ const decision = applyGroupLayoutV3(currentEditor, currentActive, result, livePolicy);
146
+ ```
147
+
148
+ Both RIGHT and DOWN support nested rectangular groups, unused/authored group
149
+ ports, ancestor-to-descendant edges and crossing boundaries. Group port definitions,
150
+ custom anchors, identities, membership, metadata, modes, capabilities and camera
151
+ remain authored data. ELK changes world positions and group bounds; core validates
152
+ all nodes/routes, declared header/label envelopes and resize/extent constraints.
153
+ A stale source, lifecycle veto or protected move/resize blocks the entire result.
154
+ A changed layout appends one Undo frame; identical geometry appends none.
155
+
156
+ `applyGroupWorkbenchLayoutV3` integrates accepted routes into the native controller.
157
+ Its optional Foldkit view renders them only while the complete document matches,
158
+ no move/connection gesture is active and no collapsed projection is present.
159
+ Undo/editing invalidates routes; camera/selection do not author layout geometry.
160
+ Routes are transient, not serialized into authored edges. Authored waypoints keep
161
+ precedence. Engine interiors are orthogonal; connector leads join ELK's fixed
162
+ boundary points to the exact final authored anchors after group resizing, and
163
+ may be oblique. This is not an obstacle/collision guarantee for arbitrary custom
164
+ content. Fixed-position compound ports are qualified with elkjs 0.12.1; its
165
+ FIXED_RATIO path failed on the nested regression and is not used.
166
+
167
+ Logical cancellation and supersession ignore late results; they do not terminate
168
+ ELK computation. Worker ownership and the Node/Bun qualification limits above
169
+ also apply to the native entry. V1/v2 `createElkLayout` still rejects group ports.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { LayoutEngine } from "@opsydyn/foldkit-zloz";
1
+ import { LayoutEngine, ZlozGroupLayoutEngineV3 } from "@opsydyn/foldkit-zloz";
2
2
  import { ELK } from "elkjs/lib/elk-api.js";
3
3
 
4
4
  //#region src/index.d.ts
@@ -7,8 +7,10 @@ type ElkLayoutOptions = Readonly<{
7
7
  spacing?: number; /** Supply a worker-backed instance when needed; the caller owns its lifetime. */
8
8
  elk?: Pick<ELK, 'layout'>;
9
9
  }>;
10
- /** Default invocations use in-process ELK. Caller-supplied worker instances remain caller-owned. */
10
+ /** Legacy graph layout. Group ports require the distinct native v3 entry. */
11
11
  declare function createElkLayout(options?: ElkLayoutOptions): LayoutEngine;
12
+ /** Native v3 compound layout; preserves authored group ports and their endpoint identities. */
13
+ declare function createElkGroupLayoutV3(options?: ElkLayoutOptions): ZlozGroupLayoutEngineV3;
12
14
  //#endregion
13
- export { ElkLayoutOptions, createElkLayout };
15
+ export { ElkLayoutOptions, createElkGroupLayoutV3, createElkLayout };
14
16
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ZlozError, portBoundaryPosition, portPosition, resolveLayoutGroupHeader, validateLayoutRequest } from "@opsydyn/foldkit-zloz";
1
+ import { ZlozError, portBoundaryPosition, portPosition, resolveLayoutGroupHeader, validateGroupLayoutRequestV3, validateLayoutRequest } from "@opsydyn/foldkit-zloz";
2
2
  import ELK from "elkjs/lib/elk.bundled.js";
3
3
  //#region src/index.ts
4
4
  /**
@@ -29,11 +29,11 @@ function routePoints(sections, edgeId) {
29
29
  throw new ZlozError("invalid-layout", `ELK omitted a continuous route for ${edgeId}`);
30
30
  }
31
31
  /** Default invocations use in-process ELK. Caller-supplied worker instances remain caller-owned. */
32
- function createElkLayout(options = {}) {
32
+ function elkLayout(options, nativeV3) {
33
33
  const spacing = options.spacing ?? 64;
34
34
  if (!Number.isFinite(spacing) || spacing <= 0) throw new ZlozError("invalid-layout", "Layout spacing must be positive and finite");
35
35
  return async (request) => {
36
- validateLayoutRequest(request);
36
+ if (!nativeV3) validateLayoutRequest(request);
37
37
  const labelHints = new Map((request.edgeLabels ?? []).map((label) => [label.id, label]));
38
38
  const groupHeaders = new Map((request.groupHeaders ?? []).map((header) => [header.id, header]));
39
39
  const nodeIds = new Map(request.graph.nodes.map((node, index) => [node.id, `n:${index}`]));
@@ -48,6 +48,24 @@ function createElkLayout(options = {}) {
48
48
  };
49
49
  const children = [];
50
50
  const elkNodes = new Map(request.graph.nodes.map((node, index) => {
51
+ const ports = new Map(node.ports.map((port, at) => [port.id, `p:${index}:${at}`]));
52
+ portIds.set(node.id, ports);
53
+ const elkPorts = node.ports.map((port) => {
54
+ const point = portBoundaryPosition(node, port.id);
55
+ return {
56
+ id: ports.get(port.id) ?? "",
57
+ width: 0,
58
+ height: 0,
59
+ x: point.x - node.position.x,
60
+ y: point.y - node.position.y,
61
+ layoutOptions: { "elk.port.side": {
62
+ left: "WEST",
63
+ right: "EAST",
64
+ top: "NORTH",
65
+ bottom: "SOUTH"
66
+ }[port.side] }
67
+ };
68
+ });
51
69
  if (node.kind === "group") {
52
70
  const hint = groupHeaders.get(node.id);
53
71
  const header = hint ? resolveLayoutGroupHeader(node, hint) : void 0;
@@ -55,6 +73,7 @@ function createElkLayout(options = {}) {
55
73
  ...layoutOptions,
56
74
  "elk.padding": "[top=52,left=24,bottom=24,right=24]"
57
75
  };
76
+ if (nativeV3) groupOptions["elk.portConstraints"] = "FIXED_POS";
58
77
  if (header) {
59
78
  const p = header.contentPadding;
60
79
  groupOptions["elk.padding"] = `[top=${p.top},left=${p.left},bottom=${p.bottom},right=${p.right}]`;
@@ -63,38 +82,22 @@ function createElkLayout(options = {}) {
63
82
  const minimum = header.minimumSize;
64
83
  groupOptions["elk.nodeSize.minimum"] = transposed ? `(${minimum.height},${minimum.width})` : `(${minimum.width},${minimum.height})`;
65
84
  }
66
- return [node.id, {
85
+ const group = {
67
86
  id: `n:${index}`,
68
87
  width: node.size.width,
69
88
  height: node.size.height,
70
89
  children: [],
71
90
  layoutOptions: groupOptions
72
- }];
91
+ };
92
+ if (nativeV3) group.ports = elkPorts;
93
+ return [node.id, group];
73
94
  }
74
- const ports = new Map(node.ports.map((port, at) => [port.id, `p:${index}:${at}`]));
75
- portIds.set(node.id, ports);
76
95
  return [node.id, {
77
96
  id: `n:${index}`,
78
97
  width: node.size.width,
79
98
  height: node.size.height,
80
99
  layoutOptions: { "elk.portConstraints": "FIXED_POS" },
81
- ports: node.ports.map((port) => {
82
- const point = portBoundaryPosition(node, port.id);
83
- const side = {
84
- left: "WEST",
85
- right: "EAST",
86
- top: "NORTH",
87
- bottom: "SOUTH"
88
- }[port.side];
89
- return {
90
- id: ports.get(port.id) ?? "",
91
- width: 0,
92
- height: 0,
93
- x: point.x - node.position.x,
94
- y: point.y - node.position.y,
95
- layoutOptions: { "elk.port.side": side }
96
- };
97
- })
100
+ ports: elkPorts
98
101
  }];
99
102
  }));
100
103
  for (const node of request.graph.nodes) {
@@ -177,12 +180,14 @@ function createElkLayout(options = {}) {
177
180
  const anchored = [
178
181
  portPosition({
179
182
  ...sourceNode,
180
- position: sourcePosition
183
+ position: sourcePosition,
184
+ size: sourcePosition.size ?? sourceNode.size
181
185
  }, edge.source.port),
182
186
  ...points,
183
187
  portPosition({
184
188
  ...targetNode,
185
- position: targetPosition
189
+ position: targetPosition,
190
+ size: targetPosition.size ?? targetNode.size
186
191
  }, edge.target.port)
187
192
  ];
188
193
  const route = {
@@ -215,7 +220,29 @@ function createElkLayout(options = {}) {
215
220
  };
216
221
  };
217
222
  }
223
+ /** Legacy graph layout. Group ports require the distinct native v3 entry. */
224
+ function createElkLayout(options = {}) {
225
+ return elkLayout(options, false);
226
+ }
227
+ /** Native v3 compound layout; preserves authored group ports and their endpoint identities. */
228
+ function createElkGroupLayoutV3(options = {}) {
229
+ const engine = elkLayout(options, true);
230
+ return async (request) => {
231
+ validateGroupLayoutRequestV3(request);
232
+ const document = request.source.document;
233
+ return {
234
+ ...await engine({
235
+ ...request.options,
236
+ requestId: request.requestId,
237
+ revision: request.source.revision,
238
+ graph: document.graph,
239
+ connectionMode: document.connectionMode
240
+ }),
241
+ version: 3
242
+ };
243
+ };
244
+ }
218
245
  //#endregion
219
- export { createElkLayout };
246
+ export { createElkGroupLayoutV3, createElkLayout };
220
247
 
221
248
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Optional ELK layout adapter; the host owns request publication and worker lifetime.\n * @module ELK\n */\nimport {\n ZlozError,\n portPosition,\n portBoundaryPosition,\n validateLayoutRequest,\n resolveLayoutGroupHeader,\n type EdgeRoute,\n type LayoutEngine,\n} from '@opsydyn/foldkit-zloz';\nimport type {\n ELK as ElkInstance,\n ElkNode,\n ElkEdgeSection,\n ElkLabel,\n LayoutOptions as ElkLayoutProperties,\n} from 'elkjs/lib/elk-api';\nimport ELK from 'elkjs/lib/elk.bundled.js';\n\nexport type ElkLayoutOptions = Readonly<{\n direction?: 'RIGHT' | 'DOWN';\n spacing?: number;\n /** Supply a worker-backed instance when needed; the caller owns its lifetime. */\n elk?: Pick<ElkInstance, 'layout'>;\n}>;\n\nfunction routePoints(sections: readonly ElkEdgeSection[], edgeId: string): EdgeRoute['points'] {\n const byId = new Map(sections.map((section) => [section.id, section]));\n const visited = new Set<string>();\n const points: Array<{ x: number; y: number }> = [];\n let current = sections.find((section) => !section.incomingSections?.length);\n while (current && !visited.has(current.id)) {\n visited.add(current.id);\n const previous = points.at(-1);\n if (\n previous &&\n (Math.abs(previous.x - current.startPoint.x) > 1e-6 ||\n Math.abs(previous.y - current.startPoint.y) > 1e-6)\n )\n break;\n if (!previous) points.push(current.startPoint);\n for (const bend of current.bendPoints ?? []) points.push(bend);\n points.push(current.endPoint);\n const outgoing = current.outgoingSections ?? [];\n if (outgoing.length === 0 && visited.size === sections.length)\n return points.map(({ x, y }) => ({ x, y }));\n const next = outgoing[0];\n if (outgoing.length !== 1 || next === undefined) break;\n current = byId.get(next);\n }\n throw new ZlozError('invalid-layout', `ELK omitted a continuous route for ${edgeId}`);\n}\n\n/** Default invocations use in-process ELK. Caller-supplied worker instances remain caller-owned. */\nexport function createElkLayout(options: ElkLayoutOptions = {}): LayoutEngine {\n const spacing = options.spacing ?? 64;\n if (!Number.isFinite(spacing) || spacing <= 0)\n throw new ZlozError('invalid-layout', 'Layout spacing must be positive and finite');\n return async (request) => {\n validateLayoutRequest(request);\n const labelHints = new Map((request.edgeLabels ?? []).map((label) => [label.id, label]));\n const groupHeaders = new Map((request.groupHeaders ?? []).map((header) => [header.id, header]));\n const nodeIds = new Map(request.graph.nodes.map((node, index) => [node.id, `n:${index}`]));\n const portIds = new Map<string, Map<string, string>>();\n const hasGroups = request.graph.nodes.some((node) => node.kind === 'group');\n const layoutOptions = {\n 'elk.algorithm': 'layered',\n 'elk.direction': options.direction ?? 'RIGHT',\n 'elk.edgeRouting': 'ORTHOGONAL',\n 'elk.spacing.nodeNode': String(spacing),\n 'elk.layered.spacing.nodeNodeBetweenLayers': String(spacing),\n } as const;\n const children: ElkNode[] = [];\n const elkNodes = new Map(\n request.graph.nodes.map((node, index): [string, ElkNode] => {\n if (node.kind === 'group') {\n const hint = groupHeaders.get(node.id);\n const header = hint ? resolveLayoutGroupHeader(node, hint) : undefined;\n const groupOptions: ElkLayoutProperties = {\n ...layoutOptions,\n 'elk.padding': '[top=52,left=24,bottom=24,right=24]',\n };\n if (header) {\n const p = header.contentPadding;\n groupOptions['elk.padding'] =\n `[top=${p.top},left=${p.left},bottom=${p.bottom},right=${p.right}]`;\n groupOptions['elk.nodeSize.constraints'] = 'MINIMUM_SIZE';\n // ELK 0.12.1 transposes compound graph minima in DOWN, but leaf/empty group minima remain physical.\n // Keep this correction behind the adapter; nested/empty, wide/tall real-engine regressions qualify upgrades.\n const transposed =\n options.direction === 'DOWN' &&\n request.graph.nodes.some((child) => child.parentId === node.id);\n const minimum = header.minimumSize;\n groupOptions['elk.nodeSize.minimum'] = transposed\n ? `(${minimum.height},${minimum.width})`\n : `(${minimum.width},${minimum.height})`;\n }\n return [\n node.id,\n {\n id: `n:${index}`,\n width: node.size.width,\n height: node.size.height,\n children: [],\n layoutOptions: groupOptions,\n },\n ];\n }\n const ports = new Map(node.ports.map((port, at) => [port.id, `p:${index}:${at}`]));\n portIds.set(node.id, ports);\n return [\n node.id,\n {\n id: `n:${index}`,\n width: node.size.width,\n height: node.size.height,\n layoutOptions: { 'elk.portConstraints': 'FIXED_POS' },\n ports: node.ports.map((port) => {\n const point = portBoundaryPosition(node, port.id);\n const side = { left: 'WEST', right: 'EAST', top: 'NORTH', bottom: 'SOUTH' }[\n port.side\n ];\n return {\n id: ports.get(port.id) ?? '',\n width: 0,\n height: 0,\n x: point.x - node.position.x,\n y: point.y - node.position.y,\n layoutOptions: { 'elk.port.side': side },\n };\n }),\n },\n ];\n }),\n );\n for (const node of request.graph.nodes) {\n const elkNode = elkNodes.get(node.id);\n if (!elkNode) throw new ZlozError('invalid-layout', `Missing input elkNode for ${node.id}`);\n const siblings =\n node.parentId === undefined ? children : elkNodes.get(node.parentId)?.children;\n if (!siblings) throw new ZlozError('invalid-layout', `Missing parent elkNode for ${node.id}`);\n siblings.push(elkNode);\n }\n const graph: ElkNode = {\n id: 'graph',\n layoutOptions: {\n ...layoutOptions,\n 'elk.hierarchyHandling': hasGroups ? 'INCLUDE_CHILDREN' : 'SEPARATE_CHILDREN',\n 'elk.json.shapeCoords': 'ROOT',\n 'elk.json.edgeCoords': 'ROOT',\n },\n children,\n edges: request.graph.edges.map((edge, index) => {\n const base = {\n id: `e:${index}`,\n sources: [portIds.get(edge.source.node)?.get(edge.source.port) ?? ''],\n targets: [portIds.get(edge.target.node)?.get(edge.target.port) ?? ''],\n };\n const hint = labelHints.get(edge.id);\n return hint\n ? {\n ...base,\n labels: [\n {\n id: `l:${index}`,\n text: edge.label?.trim() || 'label',\n width: hint.size.width,\n height: hint.size.height,\n layoutOptions: { 'elk.edgeLabels.placement': 'CENTER' },\n },\n ],\n }\n : base;\n }),\n };\n const elk = options.elk ?? new ELK();\n const result = await elk.layout(graph);\n const laidOutNodes = new Map<string, ElkNode>();\n const laidOutEdges = new Map<string, ElkEdgeSection[]>();\n const laidOutLabels = new Map<string, readonly ElkLabel[]>();\n const pending = [result];\n while (pending.length > 0) {\n const node = pending.pop();\n if (!node) break;\n laidOutNodes.set(node.id, node);\n for (const edge of node.edges ?? []) {\n laidOutEdges.set(edge.id, edge.sections ?? []);\n laidOutLabels.set(edge.id, edge.labels ?? []);\n }\n for (const child of node.children ?? []) pending.push(child);\n }\n const positions = request.graph.nodes.map((node) => {\n const laidOut = laidOutNodes.get(nodeIds.get(node.id) ?? '');\n if (\n !laidOut ||\n !Number.isFinite(laidOut.x) ||\n !Number.isFinite(laidOut.y) ||\n laidOut.x === undefined ||\n laidOut.y === undefined\n )\n throw new ZlozError('invalid-layout', `ELK omitted position for ${node.id}`);\n const position = { id: node.id, x: laidOut.x, y: laidOut.y };\n if (node.kind !== 'group') return position;\n const { width, height } = laidOut;\n if (\n width === undefined ||\n height === undefined ||\n !Number.isFinite(width) ||\n !Number.isFinite(height) ||\n width <= 0 ||\n height <= 0\n )\n throw new ZlozError('invalid-layout', `ELK returned invalid bounds for ${node.id}`);\n return { ...position, size: { width, height } };\n });\n const routes: EdgeRoute[] = request.graph.edges.map((edge, index) => {\n const sections = laidOutEdges.get(`e:${index}`) ?? [];\n const points = routePoints(sections, edge.id);\n if (!points.every((point) => Number.isFinite(point.x) && Number.isFinite(point.y)))\n throw new ZlozError('invalid-layout', `ELK returned an invalid route for ${edge.id}`);\n const sourceNode = request.graph.nodes.find((node) => node.id === edge.source.node);\n const targetNode = request.graph.nodes.find((node) => node.id === edge.target.node);\n const sourcePosition = positions.find((position) => position.id === edge.source.node);\n const targetPosition = positions.find((position) => position.id === edge.target.node);\n if (!sourceNode || !targetNode || !sourcePosition || !targetPosition)\n throw new ZlozError('invalid-layout', 'Missing routed endpoint');\n const anchored = [\n portPosition({ ...sourceNode, position: sourcePosition }, edge.source.port),\n ...points,\n portPosition({ ...targetNode, position: targetPosition }, edge.target.port),\n ];\n const route = {\n id: edge.id,\n points: anchored.filter((point, index) => {\n const previous = anchored[index - 1];\n return !previous || previous.x !== point.x || previous.y !== point.y;\n }),\n };\n const hint = labelHints.get(edge.id);\n if (!hint) return route;\n const labels = laidOutLabels.get(`e:${index}`) ?? [],\n label = labels[0];\n if (\n labels.length !== 1 ||\n !label ||\n label.id !== `l:${index}` ||\n label.x === undefined ||\n label.y === undefined ||\n !Number.isFinite(label.x) ||\n !Number.isFinite(label.y) ||\n label.width !== hint.size.width ||\n label.height !== hint.size.height\n )\n throw new ZlozError('invalid-layout', `ELK omitted a valid label box for ${edge.id}`);\n return {\n ...route,\n label: {\n position: { x: label.x + hint.size.width / 2, y: label.y + hint.size.height / 2 },\n size: { ...hint.size },\n },\n };\n });\n return { requestId: request.requestId, revision: request.revision, positions, routes };\n };\n}\n"],"mappings":";;;;;;;AA6BA,SAAS,YAAY,UAAqC,QAAqC;CAC7F,MAAM,OAAO,IAAI,IAAI,SAAS,KAAK,YAAY,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC;CACtE,MAAM,0BAAU,IAAI,KAAa;CACjC,MAAM,SAA0C,EAAE;CAClD,IAAI,UAAU,SAAS,MAAM,YAAY,CAAC,QAAQ,kBAAkB,OAAO;AAC3E,QAAO,WAAW,CAAC,QAAQ,IAAI,QAAQ,GAAG,EAAE;AAC1C,UAAQ,IAAI,QAAQ,GAAG;EACvB,MAAM,WAAW,OAAO,GAAG,GAAG;AAC9B,MACE,aACC,KAAK,IAAI,SAAS,IAAI,QAAQ,WAAW,EAAE,GAAG,QAC7C,KAAK,IAAI,SAAS,IAAI,QAAQ,WAAW,EAAE,GAAG,MAEhD;AACF,MAAI,CAAC,SAAU,QAAO,KAAK,QAAQ,WAAW;AAC9C,OAAK,MAAM,QAAQ,QAAQ,cAAc,EAAE,CAAE,QAAO,KAAK,KAAK;AAC9D,SAAO,KAAK,QAAQ,SAAS;EAC7B,MAAM,WAAW,QAAQ,oBAAoB,EAAE;AAC/C,MAAI,SAAS,WAAW,KAAK,QAAQ,SAAS,SAAS,OACrD,QAAO,OAAO,KAAK,EAAE,GAAG,SAAS;GAAE;GAAG;GAAG,EAAE;EAC7C,MAAM,OAAO,SAAS;AACtB,MAAI,SAAS,WAAW,KAAK,SAAS,KAAA,EAAW;AACjD,YAAU,KAAK,IAAI,KAAK;;AAE1B,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AM;KACvB;IACF;IACD;AACF,SAAO;GAAE,WAAW,QAAQ;GAAW,UAAU,QAAQ;GAAU;GAAW;GAAQ"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Optional ELK layout adapter; the host owns request publication and worker lifetime.\n * @module ELK\n */\nimport {\n ZlozError,\n portPosition,\n portBoundaryPosition,\n validateLayoutRequest,\n resolveLayoutGroupHeader,\n type EdgeRoute,\n type LayoutEngine,\n validateGroupLayoutRequestV3,\n type ZlozGroupLayoutEngineV3,\n type LayoutRequest,\n type LayoutResult,\n} from '@opsydyn/foldkit-zloz';\nimport type {\n ELK as ElkInstance,\n ElkNode,\n ElkEdgeSection,\n ElkLabel,\n LayoutOptions as ElkLayoutProperties,\n} from 'elkjs/lib/elk-api';\nimport ELK from 'elkjs/lib/elk.bundled.js';\n\nexport type ElkLayoutOptions = Readonly<{\n direction?: 'RIGHT' | 'DOWN';\n spacing?: number;\n /** Supply a worker-backed instance when needed; the caller owns its lifetime. */\n elk?: Pick<ElkInstance, 'layout'>;\n}>;\n\nfunction routePoints(sections: readonly ElkEdgeSection[], edgeId: string): EdgeRoute['points'] {\n const byId = new Map(sections.map((section) => [section.id, section]));\n const visited = new Set<string>();\n const points: Array<{ x: number; y: number }> = [];\n let current = sections.find((section) => !section.incomingSections?.length);\n while (current && !visited.has(current.id)) {\n visited.add(current.id);\n const previous = points.at(-1);\n if (\n previous &&\n (Math.abs(previous.x - current.startPoint.x) > 1e-6 ||\n Math.abs(previous.y - current.startPoint.y) > 1e-6)\n )\n break;\n if (!previous) points.push(current.startPoint);\n for (const bend of current.bendPoints ?? []) points.push(bend);\n points.push(current.endPoint);\n const outgoing = current.outgoingSections ?? [];\n if (outgoing.length === 0 && visited.size === sections.length)\n return points.map(({ x, y }) => ({ x, y }));\n const next = outgoing[0];\n if (outgoing.length !== 1 || next === undefined) break;\n current = byId.get(next);\n }\n throw new ZlozError('invalid-layout', `ELK omitted a continuous route for ${edgeId}`);\n}\n\n/** Default invocations use in-process ELK. Caller-supplied worker instances remain caller-owned. */\nfunction elkLayout(options: ElkLayoutOptions, nativeV3: boolean): LayoutEngine {\n const spacing = options.spacing ?? 64;\n if (!Number.isFinite(spacing) || spacing <= 0)\n throw new ZlozError('invalid-layout', 'Layout spacing must be positive and finite');\n return async (request) => {\n if (!nativeV3) validateLayoutRequest(request);\n const labelHints = new Map((request.edgeLabels ?? []).map((label) => [label.id, label]));\n const groupHeaders = new Map((request.groupHeaders ?? []).map((header) => [header.id, header]));\n const nodeIds = new Map(request.graph.nodes.map((node, index) => [node.id, `n:${index}`]));\n const portIds = new Map<string, Map<string, string>>();\n const hasGroups = request.graph.nodes.some((node) => node.kind === 'group');\n const layoutOptions = {\n 'elk.algorithm': 'layered',\n 'elk.direction': options.direction ?? 'RIGHT',\n 'elk.edgeRouting': 'ORTHOGONAL',\n 'elk.spacing.nodeNode': String(spacing),\n 'elk.layered.spacing.nodeNodeBetweenLayers': String(spacing),\n } as const;\n const children: ElkNode[] = [];\n const elkNodes = new Map(\n request.graph.nodes.map((node, index): [string, ElkNode] => {\n const ports = new Map(node.ports.map((port, at) => [port.id, `p:${index}:${at}`]));\n portIds.set(node.id, ports);\n const elkPorts = node.ports.map((port) => {\n const point = portBoundaryPosition(node, port.id);\n return {\n id: ports.get(port.id) ?? '',\n width: 0,\n height: 0,\n x: point.x - node.position.x,\n y: point.y - node.position.y,\n layoutOptions: {\n 'elk.port.side': { left: 'WEST', right: 'EAST', top: 'NORTH', bottom: 'SOUTH' }[\n port.side\n ],\n },\n };\n });\n if (node.kind === 'group') {\n const hint = groupHeaders.get(node.id);\n const header = hint ? resolveLayoutGroupHeader(node, hint) : undefined;\n const groupOptions: ElkLayoutProperties = {\n ...layoutOptions,\n 'elk.padding': '[top=52,left=24,bottom=24,right=24]',\n };\n if (nativeV3) groupOptions['elk.portConstraints'] = 'FIXED_POS';\n if (header) {\n const p = header.contentPadding;\n groupOptions['elk.padding'] =\n `[top=${p.top},left=${p.left},bottom=${p.bottom},right=${p.right}]`;\n groupOptions['elk.nodeSize.constraints'] = 'MINIMUM_SIZE';\n // ELK 0.12.1 transposes compound graph minima in DOWN, but leaf/empty group minima remain physical.\n // Keep this correction behind the adapter; nested/empty, wide/tall real-engine regressions qualify upgrades.\n const transposed =\n options.direction === 'DOWN' &&\n request.graph.nodes.some((child) => child.parentId === node.id);\n const minimum = header.minimumSize;\n groupOptions['elk.nodeSize.minimum'] = transposed\n ? `(${minimum.height},${minimum.width})`\n : `(${minimum.width},${minimum.height})`;\n }\n const group: ElkNode = {\n id: `n:${index}`,\n width: node.size.width,\n height: node.size.height,\n children: [],\n layoutOptions: groupOptions,\n };\n if (nativeV3) group.ports = elkPorts;\n return [node.id, group];\n }\n return [\n node.id,\n {\n id: `n:${index}`,\n width: node.size.width,\n height: node.size.height,\n layoutOptions: { 'elk.portConstraints': 'FIXED_POS' },\n ports: elkPorts,\n },\n ];\n }),\n );\n for (const node of request.graph.nodes) {\n const elkNode = elkNodes.get(node.id);\n if (!elkNode) throw new ZlozError('invalid-layout', `Missing input elkNode for ${node.id}`);\n const siblings =\n node.parentId === undefined ? children : elkNodes.get(node.parentId)?.children;\n if (!siblings) throw new ZlozError('invalid-layout', `Missing parent elkNode for ${node.id}`);\n siblings.push(elkNode);\n }\n const graph: ElkNode = {\n id: 'graph',\n layoutOptions: {\n ...layoutOptions,\n 'elk.hierarchyHandling': hasGroups ? 'INCLUDE_CHILDREN' : 'SEPARATE_CHILDREN',\n 'elk.json.shapeCoords': 'ROOT',\n 'elk.json.edgeCoords': 'ROOT',\n },\n children,\n edges: request.graph.edges.map((edge, index) => {\n const base = {\n id: `e:${index}`,\n sources: [portIds.get(edge.source.node)?.get(edge.source.port) ?? ''],\n targets: [portIds.get(edge.target.node)?.get(edge.target.port) ?? ''],\n };\n const hint = labelHints.get(edge.id);\n return hint\n ? {\n ...base,\n labels: [\n {\n id: `l:${index}`,\n text: edge.label?.trim() || 'label',\n width: hint.size.width,\n height: hint.size.height,\n layoutOptions: { 'elk.edgeLabels.placement': 'CENTER' },\n },\n ],\n }\n : base;\n }),\n };\n const elk = options.elk ?? new ELK();\n const result = await elk.layout(graph);\n const laidOutNodes = new Map<string, ElkNode>();\n const laidOutEdges = new Map<string, ElkEdgeSection[]>();\n const laidOutLabels = new Map<string, readonly ElkLabel[]>();\n const pending = [result];\n while (pending.length > 0) {\n const node = pending.pop();\n if (!node) break;\n laidOutNodes.set(node.id, node);\n for (const edge of node.edges ?? []) {\n laidOutEdges.set(edge.id, edge.sections ?? []);\n laidOutLabels.set(edge.id, edge.labels ?? []);\n }\n for (const child of node.children ?? []) pending.push(child);\n }\n const positions: LayoutResult['positions'] = request.graph.nodes.map((node) => {\n const laidOut = laidOutNodes.get(nodeIds.get(node.id) ?? '');\n if (\n !laidOut ||\n !Number.isFinite(laidOut.x) ||\n !Number.isFinite(laidOut.y) ||\n laidOut.x === undefined ||\n laidOut.y === undefined\n )\n throw new ZlozError('invalid-layout', `ELK omitted position for ${node.id}`);\n const position = { id: node.id, x: laidOut.x, y: laidOut.y };\n if (node.kind !== 'group') return position;\n const { width, height } = laidOut;\n if (\n width === undefined ||\n height === undefined ||\n !Number.isFinite(width) ||\n !Number.isFinite(height) ||\n width <= 0 ||\n height <= 0\n )\n throw new ZlozError('invalid-layout', `ELK returned invalid bounds for ${node.id}`);\n return { ...position, size: { width, height } };\n });\n const routes: EdgeRoute[] = request.graph.edges.map((edge, index) => {\n const sections = laidOutEdges.get(`e:${index}`) ?? [];\n const points = routePoints(sections, edge.id);\n if (!points.every((point) => Number.isFinite(point.x) && Number.isFinite(point.y)))\n throw new ZlozError('invalid-layout', `ELK returned an invalid route for ${edge.id}`);\n const sourceNode = request.graph.nodes.find((node) => node.id === edge.source.node);\n const targetNode = request.graph.nodes.find((node) => node.id === edge.target.node);\n const sourcePosition = positions.find((position) => position.id === edge.source.node);\n const targetPosition = positions.find((position) => position.id === edge.target.node);\n if (!sourceNode || !targetNode || !sourcePosition || !targetPosition)\n throw new ZlozError('invalid-layout', 'Missing routed endpoint');\n const anchored = [\n portPosition(\n { ...sourceNode, position: sourcePosition, size: sourcePosition.size ?? sourceNode.size },\n edge.source.port,\n ),\n ...points,\n portPosition(\n { ...targetNode, position: targetPosition, size: targetPosition.size ?? targetNode.size },\n edge.target.port,\n ),\n ];\n const route = {\n id: edge.id,\n points: anchored.filter((point, index) => {\n const previous = anchored[index - 1];\n return !previous || previous.x !== point.x || previous.y !== point.y;\n }),\n };\n const hint = labelHints.get(edge.id);\n if (!hint) return route;\n const labels = laidOutLabels.get(`e:${index}`) ?? [],\n label = labels[0];\n if (\n labels.length !== 1 ||\n !label ||\n label.id !== `l:${index}` ||\n label.x === undefined ||\n label.y === undefined ||\n !Number.isFinite(label.x) ||\n !Number.isFinite(label.y) ||\n label.width !== hint.size.width ||\n label.height !== hint.size.height\n )\n throw new ZlozError('invalid-layout', `ELK omitted a valid label box for ${edge.id}`);\n return {\n ...route,\n label: {\n position: { x: label.x + hint.size.width / 2, y: label.y + hint.size.height / 2 },\n size: { ...hint.size },\n },\n };\n });\n return { requestId: request.requestId, revision: request.revision, positions, routes };\n };\n}\n\n/** Legacy graph layout. Group ports require the distinct native v3 entry. */\nexport function createElkLayout(options: ElkLayoutOptions = {}): LayoutEngine {\n return elkLayout(options, false);\n}\n/** Native v3 compound layout; preserves authored group ports and their endpoint identities. */\nexport function createElkGroupLayoutV3(options: ElkLayoutOptions = {}): ZlozGroupLayoutEngineV3 {\n const engine = elkLayout(options, true);\n return async (request) => {\n validateGroupLayoutRequestV3(request);\n const document = request.source.document;\n // This internal geometry input never crosses a legacy validation/publication boundary.\n const geometry: LayoutRequest = {\n ...request.options,\n requestId: request.requestId,\n revision: request.source.revision,\n graph: document.graph,\n connectionMode: document.connectionMode,\n };\n return { ...(await engine(geometry)), version: 3 };\n };\n}\n"],"mappings":";;;;;;;AAiCA,SAAS,YAAY,UAAqC,QAAqC;CAC7F,MAAM,OAAO,IAAI,IAAI,SAAS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U,SAAS,KAAK;AACvC,QAAO,OAAO,YAAY;AACxB,+BAA6B,QAAQ;EACrC,MAAM,WAAW,QAAQ,OAAO;AAShC,SAAO;GAAE,GAAI,MAAM,OAAO;IANxB,GAAG,QAAQ;IACX,WAAW,QAAQ;IACnB,UAAU,QAAQ,OAAO;IACzB,OAAO,SAAS;IAChB,gBAAgB,SAAS;IAEO,CAAC;GAAG,SAAS;GAAG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opsydyn/foldkit-zloz-elk",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Optional ELK layout adapter for Foldkit Zloz.",
5
5
  "keywords": [
6
6
  "diagram",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@arethetypeswrong/cli": "0.18.5",
56
- "@opsydyn/foldkit-zloz": "0.5.0",
56
+ "@opsydyn/foldkit-zloz": "0.6.1",
57
57
  "@types/node": "^22.0.0",
58
58
  "bun-types": "^1.3.14",
59
59
  "publint": "0.3.25",
@@ -61,7 +61,7 @@
61
61
  "typescript": "^6.0.3"
62
62
  },
63
63
  "peerDependencies": {
64
- "@opsydyn/foldkit-zloz": "0.5.0"
64
+ "@opsydyn/foldkit-zloz": "0.6.1"
65
65
  },
66
66
  "engines": {
67
67
  "node": ">=22.0.0"