@lace-cloud/proto 0.20.0 → 0.21.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/dist/index.cjs CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  BRIDGE_METHODS: () => BRIDGE_METHODS,
24
24
  Bundle: () => Bundle,
25
+ COLLAPSED_GROUP_WIDTH: () => COLLAPSED_GROUP_WIDTH,
25
26
  CONNECT_CODE_NAMES: () => CONNECT_CODE_NAMES,
26
27
  CanvasViewProto: () => CanvasViewProto,
27
28
  EMPTY_BUNDLE: () => EMPTY_BUNDLE,
@@ -29,22 +30,50 @@ __export(index_exports, {
29
30
  ENGINE_PROTOCOL_VERSION: () => ENGINE_PROTOCOL_VERSION,
30
31
  ENGINE_STREAM_METHODS: () => ENGINE_STREAM_METHODS,
31
32
  EngineProtocolMismatchError: () => EngineProtocolMismatchError,
33
+ GROUP_HEADER_HEIGHT: () => GROUP_HEADER_HEIGHT,
34
+ GROUP_PADDING: () => GROUP_PADDING,
32
35
  HOST_ONLY_METHODS: () => HOST_ONLY_METHODS,
36
+ NODE_HEADER_HEIGHT: () => NODE_HEADER_HEIGHT,
37
+ NODE_ROW_HEIGHT: () => NODE_ROW_HEIGHT,
38
+ NODE_WIDTH: () => NODE_WIDTH,
39
+ boxAt: () => boxAt,
33
40
  callText: () => callText,
34
41
  checkEngineProtocol: () => checkEngineProtocol,
42
+ collapsedGroupSize: () => collapsedGroupSize,
35
43
  convertDiagnostic: () => convertDiagnostic,
36
44
  deriveNodeConfig: () => deriveNodeConfig,
37
45
  deriveSettingsConfig: () => deriveSettingsConfig,
46
+ drawnAt: () => drawnAt,
47
+ drawnRect: () => drawnRect,
48
+ extentOf: () => extentOf,
49
+ frameOf: () => frameOf,
50
+ freeSlot: () => freeSlot,
51
+ groupBoxSize: () => groupBoxSize,
52
+ groupFootprint: () => groupFootprint,
53
+ groupInputPinY: () => groupInputPinY,
54
+ groupPinY: () => groupPinY,
55
+ groupPins: () => groupPins,
56
+ groupReach: () => groupReach,
57
+ inputPinY: () => inputPinY,
38
58
  instanceAddress: () => instanceAddress,
59
+ joinPath: () => joinPath,
60
+ keepOrder: () => keepOrder,
61
+ layoutByDepth: () => layoutByDepth,
62
+ localIn: () => localIn,
39
63
  nodeIdForAddress: () => nodeIdForAddress,
40
64
  nodeIdForDiagnostic: () => nodeIdForDiagnostic,
65
+ nodeRows: () => nodeRows,
66
+ nodeSize: () => nodeSize,
67
+ originAt: () => originAt,
41
68
  parseModuleKey: () => parseModuleKey,
42
69
  projectCanvasView: () => projectCanvasView,
70
+ reachRect: () => reachRect,
43
71
  resolveInstance: () => resolveInstance,
44
72
  resolveScopePath: () => resolveScopePath,
45
- resolveScopePositions: () => resolveScopePositions,
46
73
  resolveScopePositionsByDepth: () => resolveScopePositionsByDepth,
47
- splitPath: () => splitPath
74
+ splitPath: () => splitPath,
75
+ stepDown: () => stepDown,
76
+ visibleInputs: () => visibleInputs
48
77
  });
49
78
  module.exports = __toCommonJS(index_exports);
50
79
 
@@ -79,7 +108,6 @@ function convertDiagnostic(d) {
79
108
  // src/engine-bridge.ts
80
109
  var ENGINE_METHODS = [
81
110
  "Initialize",
82
- "ReadCredential",
83
111
  "SessionOpen",
84
112
  "TestSessionOpen",
85
113
  "SessionSave",
@@ -91,10 +119,7 @@ var ENGINE_METHODS = [
91
119
  "CancelInvoke"
92
120
  ];
93
121
  var ENGINE_STREAM_METHODS = ["Subscribe", "Invoke"];
94
- var HOST_ONLY_METHODS = [
95
- "TestSessionOpen",
96
- "ReadCredential"
97
- ];
122
+ var HOST_ONLY_METHODS = ["TestSessionOpen"];
98
123
  var HOST_ONLY_METHOD_NAMES = HOST_ONLY_METHODS;
99
124
  var BRIDGE_METHODS = ENGINE_METHODS.filter(
100
125
  (m) => !HOST_ONLY_METHOD_NAMES.includes(m)
@@ -3870,6 +3895,101 @@ function nodeIdForDiagnostic(view, diagnostic) {
3870
3895
  return index.known.has(nodeId) ? nodeId : null;
3871
3896
  }
3872
3897
 
3898
+ // src/projection/geometry.ts
3899
+ var NODE_WIDTH = 200;
3900
+ var NODE_HEADER_HEIGHT = 28;
3901
+ var NODE_ROW_HEIGHT = 22;
3902
+ var GROUP_PADDING = { x: 40, top: 60, bottom: 20 };
3903
+ var GROUP_HEADER_HEIGHT = 32;
3904
+ var COLLAPSED_GROUP_WIDTH = 220;
3905
+ function visibleInputs(inputs) {
3906
+ return inputs.filter((pin) => pin.required || pin.wired);
3907
+ }
3908
+ function nodeRows(node) {
3909
+ const shown = visibleInputs(node.inputs);
3910
+ const folded = node.inputs.length > shown.length ? 1 : 0;
3911
+ return Math.max(shown.length + folded, node.outputs.length);
3912
+ }
3913
+ function nodeSize(node) {
3914
+ return { width: NODE_WIDTH, height: NODE_HEADER_HEIGHT + nodeRows(node) * NODE_ROW_HEIGHT };
3915
+ }
3916
+ function inputPinY(node, name) {
3917
+ const row = visibleInputs(node.inputs).findIndex((pin) => pin.name === name);
3918
+ return row < 0 ? NODE_HEADER_HEIGHT / 2 : NODE_HEADER_HEIGHT + (row + 0.5) * NODE_ROW_HEIGHT;
3919
+ }
3920
+ function extentOf(rects) {
3921
+ if (rects.length === 0) return { x: 0, y: 0, width: 0, height: 0 };
3922
+ const x = Math.min(...rects.map((r) => r.x));
3923
+ const y = Math.min(...rects.map((r) => r.y));
3924
+ return {
3925
+ x,
3926
+ y,
3927
+ width: Math.max(...rects.map((r) => r.x + r.width)) - x,
3928
+ height: Math.max(...rects.map((r) => r.y + r.height)) - y
3929
+ };
3930
+ }
3931
+ function groupBoxSize(content) {
3932
+ return {
3933
+ width: content.width + 2 * GROUP_PADDING.x,
3934
+ height: GROUP_PADDING.top + content.height + GROUP_PADDING.bottom
3935
+ };
3936
+ }
3937
+ function collapsedGroupSize(pins) {
3938
+ const rows = Math.max(pins.inputs?.length ?? 0, pins.outputs?.length ?? 0);
3939
+ return { width: COLLAPSED_GROUP_WIDTH, height: GROUP_HEADER_HEIGHT + rows * NODE_ROW_HEIGHT };
3940
+ }
3941
+ function groupPinY(row) {
3942
+ return GROUP_HEADER_HEIGHT + (row + 0.5) * NODE_ROW_HEIGHT;
3943
+ }
3944
+ function groupInputPinY(group, name) {
3945
+ const row = group.collapsed ? (group.inputs ?? []).findIndex((pin) => pin.name === name) : -1;
3946
+ return row < 0 ? GROUP_HEADER_HEIGHT / 2 : groupPinY(row);
3947
+ }
3948
+ function groupFootprint(group, box) {
3949
+ return group.collapsed ? collapsedGroupSize(group) : box;
3950
+ }
3951
+ function groupReach(pins, box) {
3952
+ const card = collapsedGroupSize(pins);
3953
+ return { width: Math.max(card.width, box.width), height: Math.max(card.height, box.height) };
3954
+ }
3955
+
3956
+ // src/projection/frames.ts
3957
+ var ZERO = { x: 0, y: 0 };
3958
+ function boxAt(origin, min = ZERO) {
3959
+ return { x: origin.x + min.x - GROUP_PADDING.x, y: origin.y + min.y - GROUP_PADDING.top };
3960
+ }
3961
+ function originAt(box, min = ZERO) {
3962
+ return { x: box.x - min.x + GROUP_PADDING.x, y: box.y - min.y + GROUP_PADDING.top };
3963
+ }
3964
+ function drawnAt(view, canvasPath) {
3965
+ return view.nodes.find((n) => n.id === canvasPath)?.position ?? view.groups.find((g) => g.id === canvasPath)?.position;
3966
+ }
3967
+ function drawnRect(view, canvasPath) {
3968
+ const node = view.nodes.find((n) => n.id === canvasPath);
3969
+ if (node) return { ...node.position, ...nodeSize(node) };
3970
+ const group = view.groups.find((g) => g.id === canvasPath);
3971
+ return group ? { ...group.position, ...groupFootprint(group, group.size) } : void 0;
3972
+ }
3973
+ function reachRect(view, canvasPath) {
3974
+ const group = view.groups.find((g) => g.id === canvasPath);
3975
+ if (!group) return drawnRect(view, canvasPath);
3976
+ return { ...group.position, ...groupReach(group, group.size) };
3977
+ }
3978
+ function frameOf(view, canvasPath) {
3979
+ const { parentPath } = splitPath(canvasPath);
3980
+ if (parentPath === "") return ZERO;
3981
+ return view.groups.find((g) => g.id === parentPath)?.origin ?? ZERO;
3982
+ }
3983
+ function localIn(view, canvasPath, drawn, frame = frameOf(view, canvasPath)) {
3984
+ const group = view.groups.find((g) => g.id === canvasPath);
3985
+ if (!group) return { x: drawn.x - frame.x, y: drawn.y - frame.y };
3986
+ const anchor = boxAt(group.origin);
3987
+ return {
3988
+ x: drawn.x - (group.position.x - anchor.x) - frame.x,
3989
+ y: drawn.y - (group.position.y - anchor.y) - frame.y
3990
+ };
3991
+ }
3992
+
3873
3993
  // src/projection/parse-module-key.ts
3874
3994
  function parseModuleKey(key) {
3875
3995
  const at = key.lastIndexOf("@");
@@ -3887,103 +4007,163 @@ function isGroupUse(bundle, use) {
3887
4007
  // src/projection/compute-layout.ts
3888
4008
  var SPACING_X = 260;
3889
4009
  var SPACING_Y = 180;
3890
- function gridPosition(index, n) {
3891
- const cols = Math.max(2, Math.ceil(Math.sqrt(n)));
3892
- const col = index % cols;
3893
- const row = Math.floor(index / cols);
3894
- return { x: col * SPACING_X, y: row * SPACING_Y };
4010
+ var GAP_X = 60;
4011
+ var GAP_Y = 40;
4012
+ var ORDINARY = { width: NODE_WIDTH, height: SPACING_Y - GAP_Y };
4013
+ function slotOf(size) {
4014
+ return {
4015
+ width: Math.max(SPACING_X, size.width + GAP_X),
4016
+ height: Math.max(SPACING_Y, size.height + GAP_Y)
4017
+ };
4018
+ }
4019
+ function overlaps(a, b) {
4020
+ return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
4021
+ }
4022
+ function stepDown(at, size, taken) {
4023
+ let candidate = at;
4024
+ const blocking = () => taken.filter((r) => overlaps({ ...candidate, ...size }, r));
4025
+ for (let inWay = blocking(); inWay.length > 0; inWay = blocking()) {
4026
+ candidate = { x: candidate.x, y: Math.max(...inWay.map((r) => r.y + r.height)) };
4027
+ }
4028
+ return candidate;
3895
4029
  }
3896
- function overlapsAny(candidate, occupied) {
3897
- return occupied.some(
3898
- (o) => candidate.x < o.x + SPACING_X && candidate.x + SPACING_X > o.x && candidate.y < o.y + SPACING_Y && candidate.y + SPACING_Y > o.y
4030
+ function keepOrder(a, b) {
4031
+ return a.y - b.y || a.x - b.x || a.declared - b.declared;
4032
+ }
4033
+ function freeSlot(extent, occupied) {
4034
+ return stepDown(
4035
+ { x: 0, y: 0 },
4036
+ slotOf(extent),
4037
+ occupied.map((r) => ({ x: r.x, y: r.y, ...slotOf(r) }))
3899
4038
  );
3900
4039
  }
3901
- function partitionStored(ids, arrangementNodes) {
3902
- const positions = /* @__PURE__ */ new Map();
3903
- const occupied = [];
3904
- const unresolved = [];
4040
+ function resolveScopePositionsByDepth(ids, arrangementNodes, edges) {
4041
+ const stored = /* @__PURE__ */ new Map();
3905
4042
  for (const id of ids) {
3906
- const stored = arrangementNodes?.[id];
3907
- if (stored) {
3908
- positions.set(id, stored);
3909
- occupied.push(stored);
3910
- } else {
3911
- unresolved.push(id);
3912
- }
4043
+ const at = arrangementNodes?.[id];
4044
+ if (at) stored.set(id, at);
3913
4045
  }
3914
- return { positions, occupied, unresolved };
4046
+ return layoutByDepth(
4047
+ ids.map((id) => ({ id, size: ORDINARY })),
4048
+ stored,
4049
+ edges
4050
+ );
3915
4051
  }
3916
- function resolveScopePositions(ids, arrangementNodes) {
3917
- const { positions, occupied, unresolved } = partitionStored(ids, arrangementNodes);
3918
- let slot = 0;
3919
- for (const id of unresolved) {
3920
- let candidate = gridPosition(slot, ids.length);
3921
- while (overlapsAny(candidate, occupied)) {
3922
- slot += 1;
3923
- candidate = gridPosition(slot, ids.length);
3924
- }
3925
- positions.set(id, candidate);
3926
- occupied.push(candidate);
3927
- slot += 1;
4052
+ function layoutByDepth(items, stored, edges) {
4053
+ const byId = new Map(items.map((item) => [item.id, item]));
4054
+ const ids = items.map((item) => item.id);
4055
+ const slots = new Map(items.map((item) => [item.id, slotOf(item.size)]));
4056
+ const slotOfId = (id) => slots.get(id) ?? slotOf(ORDINARY);
4057
+ const declared = new Map(ids.map((id, i) => [id, i]));
4058
+ const keyOf = (id, at) => ({ ...at, declared: declared.get(id) ?? 0 });
4059
+ const inOrder = [...stored].sort(([p, a], [q, b]) => keepOrder(keyOf(p, a), keyOf(q, b)));
4060
+ const kept = /* @__PURE__ */ new Map();
4061
+ const keptRects = [];
4062
+ const keptSlots = [];
4063
+ for (const [id, wanted] of inOrder) {
4064
+ const item = byId.get(id);
4065
+ if (!item) continue;
4066
+ const slot = slotOfId(id);
4067
+ const clear = !keptRects.some((r) => overlaps({ ...wanted, ...item.size }, r));
4068
+ const at = clear ? wanted : stepDown(wanted, slot, keptSlots);
4069
+ kept.set(id, at);
4070
+ keptRects.push({ ...at, ...item.size });
4071
+ keptSlots.push({ ...at, ...slot });
3928
4072
  }
3929
- return positions;
3930
- }
3931
- function resolveScopePositionsByDepth(ids, arrangementNodes, edges) {
3932
- const { positions, occupied, unresolved } = partitionStored(ids, arrangementNodes);
3933
4073
  const columns = columnByDepth(ids, edges);
3934
- const predecessors = /* @__PURE__ */ new Map();
4074
+ const columnX = /* @__PURE__ */ new Map();
4075
+ {
4076
+ const widths = /* @__PURE__ */ new Map();
4077
+ for (const id of ids) {
4078
+ const c = columns.get(id) ?? 0;
4079
+ widths.set(c, Math.max(widths.get(c) ?? SPACING_X, slotOfId(id).width));
4080
+ }
4081
+ const last = Math.max(0, ...widths.keys());
4082
+ let x = 0;
4083
+ for (let c = 0; c <= last; c += 1) {
4084
+ columnX.set(c, x);
4085
+ x += widths.get(c) ?? SPACING_X;
4086
+ }
4087
+ }
4088
+ const feeders = /* @__PURE__ */ new Map();
4089
+ const fed = /* @__PURE__ */ new Map();
3935
4090
  for (const edge of edges) {
3936
4091
  if (edge.source_instance === edge.target_instance) continue;
3937
- predecessors.set(edge.target_instance, [
3938
- ...predecessors.get(edge.target_instance) ?? [],
4092
+ if (!byId.has(edge.source_instance) || !byId.has(edge.target_instance)) continue;
4093
+ feeders.set(edge.target_instance, [
4094
+ ...feeders.get(edge.target_instance) ?? [],
3939
4095
  edge.source_instance
3940
4096
  ]);
3941
- }
3942
- const rows = /* @__PURE__ */ new Map();
3943
- const order = [...ids].sort((a, b) => (columns.get(a) ?? 0) - (columns.get(b) ?? 0));
3944
- const seeded = /* @__PURE__ */ new Map();
3945
- for (const id of order) {
3946
- const column = columns.get(id) ?? 0;
3947
- const stored = arrangementNodes?.[id];
3948
- if (stored) {
3949
- rows.set(id, stored.y);
3950
- continue;
3951
- }
3952
- const seq = seeded.get(column) ?? 0;
3953
- seeded.set(column, seq + 1);
3954
- rows.set(id, seq * SPACING_Y);
3955
- }
3956
- for (const id of order) {
3957
- if (arrangementNodes?.[id]) continue;
3958
- const feeders = (predecessors.get(id) ?? []).filter((f) => rows.has(f));
3959
- if (feeders.length === 0) continue;
3960
- rows.set(id, feeders.reduce((sum, f) => sum + (rows.get(f) ?? 0), 0) / feeders.length);
4097
+ fed.set(edge.source_instance, [...fed.get(edge.source_instance) ?? [], edge]);
3961
4098
  }
3962
4099
  const byColumn = /* @__PURE__ */ new Map();
3963
4100
  for (const id of ids) {
4101
+ if (kept.has(id)) continue;
3964
4102
  const column = columns.get(id) ?? 0;
3965
4103
  byColumn.set(column, [...byColumn.get(column) ?? [], id]);
3966
4104
  }
3967
- for (const [, members] of byColumn) {
3968
- const movable = members.filter((id) => !arrangementNodes?.[id]);
3969
- if (movable.length < 2) continue;
3970
- const sorted = [...movable].sort((a, b) => (rows.get(a) ?? 0) - (rows.get(b) ?? 0));
3971
- const centre = sorted.reduce((sum, id) => sum + (rows.get(id) ?? 0), 0) / sorted.length;
3972
- const first = centre - (sorted.length - 1) * SPACING_Y / 2;
3973
- for (const [i, id] of sorted.entries()) {
3974
- rows.set(id, first + i * SPACING_Y);
3975
- }
3976
- }
3977
- for (const id of unresolved) {
3978
- const column = columns.get(id) ?? 0;
3979
- let candidate = { x: column * SPACING_X, y: rows.get(id) ?? 0 };
3980
- while (overlapsAny(candidate, occupied)) {
3981
- candidate = { x: candidate.x, y: candidate.y + SPACING_Y };
4105
+ const heightOf = (id) => byId.get(id)?.size.height ?? 0;
4106
+ const mean = (values) => values.reduce((sum, v) => sum + v, 0) / values.length;
4107
+ const place = (unfedOrder2) => {
4108
+ const rank = new Map(unfedOrder2.map((id, i) => [id, i]));
4109
+ const positions = new Map(kept);
4110
+ const taken = [...keptSlots];
4111
+ for (const column of [...byColumn.keys()].sort((p, q) => p - q)) {
4112
+ const members = [...byColumn.get(column) ?? []].sort(
4113
+ (p, q) => (rank.get(p) ?? 0) - (rank.get(q) ?? 0)
4114
+ );
4115
+ const tops = /* @__PURE__ */ new Map();
4116
+ let stacked = 0;
4117
+ for (const id of members) {
4118
+ const from = (feeders.get(id) ?? []).flatMap((f) => {
4119
+ const at = positions.get(f);
4120
+ return at ? [at.y + heightOf(f) / 2] : [];
4121
+ });
4122
+ if (from.length > 0) {
4123
+ tops.set(id, mean(from) - heightOf(id) / 2);
4124
+ } else {
4125
+ tops.set(id, stacked);
4126
+ stacked += slotOfId(id).height;
4127
+ }
4128
+ }
4129
+ const sorted = [...members].sort((p, q) => (tops.get(p) ?? 0) - (tops.get(q) ?? 0));
4130
+ if (sorted.length > 1) {
4131
+ const offsets = [];
4132
+ let run = 0;
4133
+ for (const id of sorted) {
4134
+ offsets.push(run);
4135
+ run += slotOfId(id).height;
4136
+ }
4137
+ const first = mean(sorted.map((id) => tops.get(id) ?? 0)) - mean(offsets);
4138
+ for (const [i, id] of sorted.entries()) tops.set(id, first + offsets[i]);
4139
+ }
4140
+ const x = columnX.get(column) ?? 0;
4141
+ for (const id of sorted) {
4142
+ const slot = slotOfId(id);
4143
+ const at = stepDown({ x, y: tops.get(id) ?? 0 }, slot, taken);
4144
+ positions.set(id, at);
4145
+ taken.push({ ...at, ...slot });
4146
+ }
3982
4147
  }
3983
- positions.set(id, candidate);
3984
- occupied.push(candidate);
3985
- }
3986
- return positions;
4148
+ return positions;
4149
+ };
4150
+ const provisional = place(ids);
4151
+ const landing = (id) => {
4152
+ const out = fed.get(id) ?? [];
4153
+ const at = provisional.get(id);
4154
+ if (out.length === 0) return (at?.y ?? 0) + slotOfId(id).height / 2;
4155
+ const ys = out.map((edge) => {
4156
+ const target = byId.get(edge.target_instance);
4157
+ const top = provisional.get(edge.target_instance)?.y ?? 0;
4158
+ const pin = target?.pinY && edge.to_input !== void 0 ? target.pinY(edge.to_input) : 0;
4159
+ return top + pin;
4160
+ });
4161
+ return mean(ys);
4162
+ };
4163
+ const unfedOrder = [...ids].sort(
4164
+ (p, q) => landing(p) - landing(q) || (declared.get(p) ?? 0) - (declared.get(q) ?? 0)
4165
+ );
4166
+ return place(unfedOrder);
3987
4167
  }
3988
4168
  function columnByDepth(ids, edges) {
3989
4169
  const present = new Set(ids);
@@ -4010,39 +4190,40 @@ function projectGroup(use, target, fullId, parentArrangement) {
4010
4190
  const childIds = (target.modules ?? []).map((u) => joinPath(fullId, u.id));
4011
4191
  const parentGroup = parentArrangement?.groups?.[use.id];
4012
4192
  const collapsed = parentGroup ? parentGroup.collapsed : true;
4013
- const label = parentGroup?.label ? parentGroup.label : use.id;
4014
- const inputs = (target.interface?.inputs ?? []).map((in_) => ({
4015
- name: in_.name,
4016
- type: in_.type,
4017
- required: in_.required,
4018
- description: in_.description
4019
- }));
4020
- const outputs = (target.interface?.outputs ?? []).map((out) => ({
4021
- name: out.name,
4022
- type: out.type,
4023
- description: out.description,
4024
- sensitive: out.sensitive
4025
- }));
4026
4193
  return {
4027
4194
  id: fullId,
4028
- label,
4195
+ label: use.id,
4029
4196
  node_ids: childIds,
4030
4197
  collapsed,
4031
4198
  module_key: use.module,
4032
- inputs,
4033
- outputs
4199
+ ...groupPins(target)
4200
+ };
4201
+ }
4202
+ function groupPins(target) {
4203
+ return {
4204
+ inputs: (target.interface?.inputs ?? []).map((in_) => ({
4205
+ name: in_.name,
4206
+ type: in_.type,
4207
+ required: in_.required,
4208
+ description: in_.description
4209
+ })),
4210
+ outputs: (target.interface?.outputs ?? []).map((out) => ({
4211
+ name: out.name,
4212
+ type: out.type,
4213
+ description: out.description,
4214
+ sensitive: out.sensitive
4215
+ }))
4034
4216
  };
4035
4217
  }
4036
4218
 
4037
4219
  // src/projection/project-node.ts
4038
- function projectNode(bundle, use, fullId, position, wiredIn, wiredOut) {
4220
+ function projectNode(bundle, use, fullId, wiredIn, wiredOut) {
4039
4221
  const schema = resolveSchema(bundle, use, wiredOut);
4040
4222
  return {
4041
4223
  id: fullId,
4042
4224
  label: use.id,
4043
4225
  kind: "module",
4044
4226
  module_key: use.module,
4045
- position,
4046
4227
  inputs: schema.inputs.map((in_) => ({
4047
4228
  name: in_.name,
4048
4229
  type: in_.type,
@@ -4062,43 +4243,58 @@ function projectNode(bundle, use, fullId, position, wiredIn, wiredOut) {
4062
4243
  }
4063
4244
 
4064
4245
  // src/projection/project-scope.ts
4065
- function requirePosition(positions, id) {
4066
- const pos = positions.get(id);
4067
- if (!pos) throw new Error(`projectScope: no computed position for "${id}"`);
4068
- return pos;
4069
- }
4070
- function projectScope(bundle, mod, path, arrangement) {
4246
+ function projectScope(bundle, mod, use, path, arrangement, children) {
4071
4247
  const uses = mod.modules ?? [];
4072
4248
  const derived = deriveEdges(uses);
4073
4249
  const { inputs: wiredIn, outputs: wiredOut } = indexWires(derived);
4074
- const scopeKey = resolveScopePath(bundle, path);
4075
- const scopeArrangement = scopeKey ? arrangement?.[scopeKey] : void 0;
4076
- const nodes = [];
4250
+ const scopeArrangement = arrangement?.[use ? use.module : bundle.entry];
4251
+ const cards = [];
4077
4252
  const groups = [];
4078
- const classified = uses.map((use) => ({ use, group: isGroupUse(bundle, use) }));
4079
- const nodeUseIds = classified.filter((c) => !c.group).map((c) => c.use.id);
4080
- const positions = resolveScopePositionsByDepth(nodeUseIds, scopeArrangement?.nodes, derived);
4081
- for (const { use, group } of classified) {
4082
- const fullId = joinPath(path, use.id);
4083
- if (group) {
4084
- const target = bundle.modules[use.module];
4085
- groups.push(projectGroup(use, target, fullId, scopeArrangement));
4253
+ const items = [];
4254
+ const boxMin = /* @__PURE__ */ new Map();
4255
+ for (const child of uses) {
4256
+ const fullId = joinPath(path, child.id);
4257
+ if (isGroupUse(bundle, child)) {
4258
+ const group = projectGroup(child, bundle.modules[child.module], fullId, scopeArrangement);
4259
+ const content = children.get(fullId);
4260
+ if (!content) throw new Error(`projectScope: no layout for group "${fullId}"`);
4261
+ groups.push(group);
4262
+ boxMin.set(child.id, content.min);
4263
+ items.push({
4264
+ id: child.id,
4265
+ size: groupFootprint(group, content.box),
4266
+ pinY: (input) => groupInputPinY(group, input)
4267
+ });
4086
4268
  continue;
4087
4269
  }
4088
- nodes.push(
4089
- projectNode(
4090
- bundle,
4091
- use,
4092
- fullId,
4093
- // Every non-group use is in nodeUseIds, so resolveScopePositionsByDepth
4094
- // always has an entry for it — requirePosition turns that into a
4095
- // checked invariant instead of a silent gap a fallback would mask.
4096
- requirePosition(positions, use.id),
4097
- wiredIn.get(use.id) ?? /* @__PURE__ */ new Set(),
4098
- wiredOut.get(use.id) ?? /* @__PURE__ */ new Set()
4099
- )
4270
+ const node = projectNode(
4271
+ bundle,
4272
+ child,
4273
+ fullId,
4274
+ wiredIn.get(child.id) ?? /* @__PURE__ */ new Set(),
4275
+ wiredOut.get(child.id) ?? /* @__PURE__ */ new Set()
4100
4276
  );
4277
+ cards.push(node);
4278
+ items.push({ id: child.id, size: nodeSize(node), pinY: (input) => inputPinY(node, input) });
4279
+ }
4280
+ const stored = /* @__PURE__ */ new Map();
4281
+ for (const child of uses) {
4282
+ const at = scopeArrangement?.nodes?.[child.id];
4283
+ if (!at) continue;
4284
+ const min = boxMin.get(child.id);
4285
+ stored.set(child.id, min ? boxAt(originAt(at), min) : at);
4101
4286
  }
4287
+ const local = layoutByDepth(items, stored, derived);
4288
+ const placedAt = (useId) => {
4289
+ const at = local.get(useId);
4290
+ if (!at) throw new Error(`projectScope: no position for "${joinPath(path, useId)}"`);
4291
+ return at;
4292
+ };
4293
+ const nodes = cards.map((card) => ({ ...card, position: placedAt(splitPath(card.id).localId) }));
4294
+ const extent = extentOf([
4295
+ { x: 0, y: 0, width: 0, height: 0 },
4296
+ ...items.map((item) => ({ ...placedAt(item.id), ...item.size }))
4297
+ ]);
4102
4298
  const edges = derived.map((de) => {
4103
4299
  const sourceId = joinPath(path, de.source_instance);
4104
4300
  const targetId = joinPath(path, de.target_instance);
@@ -4110,7 +4306,14 @@ function projectScope(bundle, mod, path, arrangement) {
4110
4306
  target_input: de.to_input
4111
4307
  };
4112
4308
  });
4113
- return { nodes, edges, groups };
4309
+ return {
4310
+ nodes,
4311
+ groups,
4312
+ edges,
4313
+ local,
4314
+ min: { x: extent.x, y: extent.y },
4315
+ box: groupBoxSize(extent)
4316
+ };
4114
4317
  }
4115
4318
 
4116
4319
  // src/projection/walk-modules.ts
@@ -4135,15 +4338,36 @@ var EMPTY_BUNDLE = Bundle.fromPartial({
4135
4338
  modules: { "root@v1": { id: "root", version: "v1.0.0" } }
4136
4339
  });
4137
4340
  function projectCanvasView(bundle, arrangement, meta) {
4341
+ const scopes = [];
4342
+ walk(bundle, (mod, use, path) => {
4343
+ scopes.push({ mod, use, path });
4344
+ });
4345
+ const layouts = /* @__PURE__ */ new Map();
4346
+ for (const { mod, use, path } of [...scopes].reverse()) {
4347
+ layouts.set(path, projectScope(bundle, mod, use, path, arrangement, layouts));
4348
+ }
4138
4349
  const nodes = [];
4139
4350
  const edges = [];
4140
4351
  const groups = [];
4141
- walk(bundle, (mod, _use, path) => {
4142
- const scope = projectScope(bundle, mod, path, arrangement);
4143
- nodes.push(...scope.nodes);
4144
- edges.push(...scope.edges);
4145
- groups.push(...scope.groups);
4146
- });
4352
+ const origins = /* @__PURE__ */ new Map([["", { x: 0, y: 0 }]]);
4353
+ for (const { path } of scopes) {
4354
+ const layout = layouts.get(path);
4355
+ const origin = origins.get(path);
4356
+ if (!layout || !origin) continue;
4357
+ const at = (local) => ({ x: origin.x + local.x, y: origin.y + local.y });
4358
+ for (const node of layout.nodes) nodes.push({ ...node, position: at(node.position) });
4359
+ for (const group of layout.groups) {
4360
+ const content = layouts.get(group.id);
4361
+ const box = layout.local.get(splitPath(group.id).localId);
4362
+ if (!content || !box)
4363
+ throw new Error(`projectCanvasView: group "${group.id}" was not laid out`);
4364
+ const position = at(box);
4365
+ const membersAt = originAt(position, content.min);
4366
+ origins.set(group.id, membersAt);
4367
+ groups.push({ ...group, position, size: content.box, origin: membersAt });
4368
+ }
4369
+ edges.push(...layout.edges);
4370
+ }
4147
4371
  const moduleName = meta.moduleName ?? parseModuleKey(bundle.entry).id;
4148
4372
  return {
4149
4373
  module_name: moduleName,
@@ -4154,7 +4378,7 @@ function projectCanvasView(bundle, arrangement, meta) {
4154
4378
  unsaved: meta.unsaved,
4155
4379
  conflict: meta.conflict,
4156
4380
  ungenerated: meta.ungenerated ?? false,
4157
- // Every group is now a Use whose target has sub-Uses (CreateGroupAction
4381
+ // Every group is a Use whose target has sub-Uses (CreateGroupAction
4158
4382
  // mints a module); emission order already mirrors Use declaration order
4159
4383
  // via the walk, so no separate user-group sort is needed.
4160
4384
  groups
@@ -4959,7 +5183,7 @@ function isSet3(value) {
4959
5183
  var CanvasViewProto = CanvasView;
4960
5184
 
4961
5185
  // src/protocol-version.ts
4962
- var ENGINE_PROTOCOL_VERSION = String(3 /* PROTOCOL_VERSION_CURRENT */);
5186
+ var ENGINE_PROTOCOL_VERSION = String(4 /* PROTOCOL_VERSION_CURRENT */);
4963
5187
  var EngineProtocolMismatchError = class extends Error {
4964
5188
  constructor(engineVersion, engineProtocol, requiredProtocol) {
4965
5189
  super(
@@ -4987,6 +5211,7 @@ function checkEngineProtocol(engineVersion, engineProtocol) {
4987
5211
  0 && (module.exports = {
4988
5212
  BRIDGE_METHODS,
4989
5213
  Bundle,
5214
+ COLLAPSED_GROUP_WIDTH,
4990
5215
  CONNECT_CODE_NAMES,
4991
5216
  CanvasViewProto,
4992
5217
  EMPTY_BUNDLE,
@@ -4994,21 +5219,49 @@ function checkEngineProtocol(engineVersion, engineProtocol) {
4994
5219
  ENGINE_PROTOCOL_VERSION,
4995
5220
  ENGINE_STREAM_METHODS,
4996
5221
  EngineProtocolMismatchError,
5222
+ GROUP_HEADER_HEIGHT,
5223
+ GROUP_PADDING,
4997
5224
  HOST_ONLY_METHODS,
5225
+ NODE_HEADER_HEIGHT,
5226
+ NODE_ROW_HEIGHT,
5227
+ NODE_WIDTH,
5228
+ boxAt,
4998
5229
  callText,
4999
5230
  checkEngineProtocol,
5231
+ collapsedGroupSize,
5000
5232
  convertDiagnostic,
5001
5233
  deriveNodeConfig,
5002
5234
  deriveSettingsConfig,
5235
+ drawnAt,
5236
+ drawnRect,
5237
+ extentOf,
5238
+ frameOf,
5239
+ freeSlot,
5240
+ groupBoxSize,
5241
+ groupFootprint,
5242
+ groupInputPinY,
5243
+ groupPinY,
5244
+ groupPins,
5245
+ groupReach,
5246
+ inputPinY,
5003
5247
  instanceAddress,
5248
+ joinPath,
5249
+ keepOrder,
5250
+ layoutByDepth,
5251
+ localIn,
5004
5252
  nodeIdForAddress,
5005
5253
  nodeIdForDiagnostic,
5254
+ nodeRows,
5255
+ nodeSize,
5256
+ originAt,
5006
5257
  parseModuleKey,
5007
5258
  projectCanvasView,
5259
+ reachRect,
5008
5260
  resolveInstance,
5009
5261
  resolveScopePath,
5010
- resolveScopePositions,
5011
5262
  resolveScopePositionsByDepth,
5012
- splitPath
5263
+ splitPath,
5264
+ stepDown,
5265
+ visibleInputs
5013
5266
  });
5014
5267
  //# sourceMappingURL=index.cjs.map