@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.mjs CHANGED
@@ -29,7 +29,6 @@ function convertDiagnostic(d) {
29
29
  // src/engine-bridge.ts
30
30
  var ENGINE_METHODS = [
31
31
  "Initialize",
32
- "ReadCredential",
33
32
  "SessionOpen",
34
33
  "TestSessionOpen",
35
34
  "SessionSave",
@@ -41,10 +40,7 @@ var ENGINE_METHODS = [
41
40
  "CancelInvoke"
42
41
  ];
43
42
  var ENGINE_STREAM_METHODS = ["Subscribe", "Invoke"];
44
- var HOST_ONLY_METHODS = [
45
- "TestSessionOpen",
46
- "ReadCredential"
47
- ];
43
+ var HOST_ONLY_METHODS = ["TestSessionOpen"];
48
44
  var HOST_ONLY_METHOD_NAMES = HOST_ONLY_METHODS;
49
45
  var BRIDGE_METHODS = ENGINE_METHODS.filter(
50
46
  (m) => !HOST_ONLY_METHOD_NAMES.includes(m)
@@ -3820,6 +3816,101 @@ function nodeIdForDiagnostic(view, diagnostic) {
3820
3816
  return index.known.has(nodeId) ? nodeId : null;
3821
3817
  }
3822
3818
 
3819
+ // src/projection/geometry.ts
3820
+ var NODE_WIDTH = 200;
3821
+ var NODE_HEADER_HEIGHT = 28;
3822
+ var NODE_ROW_HEIGHT = 22;
3823
+ var GROUP_PADDING = { x: 40, top: 60, bottom: 20 };
3824
+ var GROUP_HEADER_HEIGHT = 32;
3825
+ var COLLAPSED_GROUP_WIDTH = 220;
3826
+ function visibleInputs(inputs) {
3827
+ return inputs.filter((pin) => pin.required || pin.wired);
3828
+ }
3829
+ function nodeRows(node) {
3830
+ const shown = visibleInputs(node.inputs);
3831
+ const folded = node.inputs.length > shown.length ? 1 : 0;
3832
+ return Math.max(shown.length + folded, node.outputs.length);
3833
+ }
3834
+ function nodeSize(node) {
3835
+ return { width: NODE_WIDTH, height: NODE_HEADER_HEIGHT + nodeRows(node) * NODE_ROW_HEIGHT };
3836
+ }
3837
+ function inputPinY(node, name) {
3838
+ const row = visibleInputs(node.inputs).findIndex((pin) => pin.name === name);
3839
+ return row < 0 ? NODE_HEADER_HEIGHT / 2 : NODE_HEADER_HEIGHT + (row + 0.5) * NODE_ROW_HEIGHT;
3840
+ }
3841
+ function extentOf(rects) {
3842
+ if (rects.length === 0) return { x: 0, y: 0, width: 0, height: 0 };
3843
+ const x = Math.min(...rects.map((r) => r.x));
3844
+ const y = Math.min(...rects.map((r) => r.y));
3845
+ return {
3846
+ x,
3847
+ y,
3848
+ width: Math.max(...rects.map((r) => r.x + r.width)) - x,
3849
+ height: Math.max(...rects.map((r) => r.y + r.height)) - y
3850
+ };
3851
+ }
3852
+ function groupBoxSize(content) {
3853
+ return {
3854
+ width: content.width + 2 * GROUP_PADDING.x,
3855
+ height: GROUP_PADDING.top + content.height + GROUP_PADDING.bottom
3856
+ };
3857
+ }
3858
+ function collapsedGroupSize(pins) {
3859
+ const rows = Math.max(pins.inputs?.length ?? 0, pins.outputs?.length ?? 0);
3860
+ return { width: COLLAPSED_GROUP_WIDTH, height: GROUP_HEADER_HEIGHT + rows * NODE_ROW_HEIGHT };
3861
+ }
3862
+ function groupPinY(row) {
3863
+ return GROUP_HEADER_HEIGHT + (row + 0.5) * NODE_ROW_HEIGHT;
3864
+ }
3865
+ function groupInputPinY(group, name) {
3866
+ const row = group.collapsed ? (group.inputs ?? []).findIndex((pin) => pin.name === name) : -1;
3867
+ return row < 0 ? GROUP_HEADER_HEIGHT / 2 : groupPinY(row);
3868
+ }
3869
+ function groupFootprint(group, box) {
3870
+ return group.collapsed ? collapsedGroupSize(group) : box;
3871
+ }
3872
+ function groupReach(pins, box) {
3873
+ const card = collapsedGroupSize(pins);
3874
+ return { width: Math.max(card.width, box.width), height: Math.max(card.height, box.height) };
3875
+ }
3876
+
3877
+ // src/projection/frames.ts
3878
+ var ZERO = { x: 0, y: 0 };
3879
+ function boxAt(origin, min = ZERO) {
3880
+ return { x: origin.x + min.x - GROUP_PADDING.x, y: origin.y + min.y - GROUP_PADDING.top };
3881
+ }
3882
+ function originAt(box, min = ZERO) {
3883
+ return { x: box.x - min.x + GROUP_PADDING.x, y: box.y - min.y + GROUP_PADDING.top };
3884
+ }
3885
+ function drawnAt(view, canvasPath) {
3886
+ return view.nodes.find((n) => n.id === canvasPath)?.position ?? view.groups.find((g) => g.id === canvasPath)?.position;
3887
+ }
3888
+ function drawnRect(view, canvasPath) {
3889
+ const node = view.nodes.find((n) => n.id === canvasPath);
3890
+ if (node) return { ...node.position, ...nodeSize(node) };
3891
+ const group = view.groups.find((g) => g.id === canvasPath);
3892
+ return group ? { ...group.position, ...groupFootprint(group, group.size) } : void 0;
3893
+ }
3894
+ function reachRect(view, canvasPath) {
3895
+ const group = view.groups.find((g) => g.id === canvasPath);
3896
+ if (!group) return drawnRect(view, canvasPath);
3897
+ return { ...group.position, ...groupReach(group, group.size) };
3898
+ }
3899
+ function frameOf(view, canvasPath) {
3900
+ const { parentPath } = splitPath(canvasPath);
3901
+ if (parentPath === "") return ZERO;
3902
+ return view.groups.find((g) => g.id === parentPath)?.origin ?? ZERO;
3903
+ }
3904
+ function localIn(view, canvasPath, drawn, frame = frameOf(view, canvasPath)) {
3905
+ const group = view.groups.find((g) => g.id === canvasPath);
3906
+ if (!group) return { x: drawn.x - frame.x, y: drawn.y - frame.y };
3907
+ const anchor = boxAt(group.origin);
3908
+ return {
3909
+ x: drawn.x - (group.position.x - anchor.x) - frame.x,
3910
+ y: drawn.y - (group.position.y - anchor.y) - frame.y
3911
+ };
3912
+ }
3913
+
3823
3914
  // src/projection/parse-module-key.ts
3824
3915
  function parseModuleKey(key) {
3825
3916
  const at = key.lastIndexOf("@");
@@ -3837,103 +3928,163 @@ function isGroupUse(bundle, use) {
3837
3928
  // src/projection/compute-layout.ts
3838
3929
  var SPACING_X = 260;
3839
3930
  var SPACING_Y = 180;
3840
- function gridPosition(index, n) {
3841
- const cols = Math.max(2, Math.ceil(Math.sqrt(n)));
3842
- const col = index % cols;
3843
- const row = Math.floor(index / cols);
3844
- return { x: col * SPACING_X, y: row * SPACING_Y };
3931
+ var GAP_X = 60;
3932
+ var GAP_Y = 40;
3933
+ var ORDINARY = { width: NODE_WIDTH, height: SPACING_Y - GAP_Y };
3934
+ function slotOf(size) {
3935
+ return {
3936
+ width: Math.max(SPACING_X, size.width + GAP_X),
3937
+ height: Math.max(SPACING_Y, size.height + GAP_Y)
3938
+ };
3939
+ }
3940
+ function overlaps(a, b) {
3941
+ 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;
3942
+ }
3943
+ function stepDown(at, size, taken) {
3944
+ let candidate = at;
3945
+ const blocking = () => taken.filter((r) => overlaps({ ...candidate, ...size }, r));
3946
+ for (let inWay = blocking(); inWay.length > 0; inWay = blocking()) {
3947
+ candidate = { x: candidate.x, y: Math.max(...inWay.map((r) => r.y + r.height)) };
3948
+ }
3949
+ return candidate;
3845
3950
  }
3846
- function overlapsAny(candidate, occupied) {
3847
- return occupied.some(
3848
- (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
3951
+ function keepOrder(a, b) {
3952
+ return a.y - b.y || a.x - b.x || a.declared - b.declared;
3953
+ }
3954
+ function freeSlot(extent, occupied) {
3955
+ return stepDown(
3956
+ { x: 0, y: 0 },
3957
+ slotOf(extent),
3958
+ occupied.map((r) => ({ x: r.x, y: r.y, ...slotOf(r) }))
3849
3959
  );
3850
3960
  }
3851
- function partitionStored(ids, arrangementNodes) {
3852
- const positions = /* @__PURE__ */ new Map();
3853
- const occupied = [];
3854
- const unresolved = [];
3961
+ function resolveScopePositionsByDepth(ids, arrangementNodes, edges) {
3962
+ const stored = /* @__PURE__ */ new Map();
3855
3963
  for (const id of ids) {
3856
- const stored = arrangementNodes?.[id];
3857
- if (stored) {
3858
- positions.set(id, stored);
3859
- occupied.push(stored);
3860
- } else {
3861
- unresolved.push(id);
3862
- }
3964
+ const at = arrangementNodes?.[id];
3965
+ if (at) stored.set(id, at);
3863
3966
  }
3864
- return { positions, occupied, unresolved };
3967
+ return layoutByDepth(
3968
+ ids.map((id) => ({ id, size: ORDINARY })),
3969
+ stored,
3970
+ edges
3971
+ );
3865
3972
  }
3866
- function resolveScopePositions(ids, arrangementNodes) {
3867
- const { positions, occupied, unresolved } = partitionStored(ids, arrangementNodes);
3868
- let slot = 0;
3869
- for (const id of unresolved) {
3870
- let candidate = gridPosition(slot, ids.length);
3871
- while (overlapsAny(candidate, occupied)) {
3872
- slot += 1;
3873
- candidate = gridPosition(slot, ids.length);
3874
- }
3875
- positions.set(id, candidate);
3876
- occupied.push(candidate);
3877
- slot += 1;
3973
+ function layoutByDepth(items, stored, edges) {
3974
+ const byId = new Map(items.map((item) => [item.id, item]));
3975
+ const ids = items.map((item) => item.id);
3976
+ const slots = new Map(items.map((item) => [item.id, slotOf(item.size)]));
3977
+ const slotOfId = (id) => slots.get(id) ?? slotOf(ORDINARY);
3978
+ const declared = new Map(ids.map((id, i) => [id, i]));
3979
+ const keyOf = (id, at) => ({ ...at, declared: declared.get(id) ?? 0 });
3980
+ const inOrder = [...stored].sort(([p, a], [q, b]) => keepOrder(keyOf(p, a), keyOf(q, b)));
3981
+ const kept = /* @__PURE__ */ new Map();
3982
+ const keptRects = [];
3983
+ const keptSlots = [];
3984
+ for (const [id, wanted] of inOrder) {
3985
+ const item = byId.get(id);
3986
+ if (!item) continue;
3987
+ const slot = slotOfId(id);
3988
+ const clear = !keptRects.some((r) => overlaps({ ...wanted, ...item.size }, r));
3989
+ const at = clear ? wanted : stepDown(wanted, slot, keptSlots);
3990
+ kept.set(id, at);
3991
+ keptRects.push({ ...at, ...item.size });
3992
+ keptSlots.push({ ...at, ...slot });
3878
3993
  }
3879
- return positions;
3880
- }
3881
- function resolveScopePositionsByDepth(ids, arrangementNodes, edges) {
3882
- const { positions, occupied, unresolved } = partitionStored(ids, arrangementNodes);
3883
3994
  const columns = columnByDepth(ids, edges);
3884
- const predecessors = /* @__PURE__ */ new Map();
3995
+ const columnX = /* @__PURE__ */ new Map();
3996
+ {
3997
+ const widths = /* @__PURE__ */ new Map();
3998
+ for (const id of ids) {
3999
+ const c = columns.get(id) ?? 0;
4000
+ widths.set(c, Math.max(widths.get(c) ?? SPACING_X, slotOfId(id).width));
4001
+ }
4002
+ const last = Math.max(0, ...widths.keys());
4003
+ let x = 0;
4004
+ for (let c = 0; c <= last; c += 1) {
4005
+ columnX.set(c, x);
4006
+ x += widths.get(c) ?? SPACING_X;
4007
+ }
4008
+ }
4009
+ const feeders = /* @__PURE__ */ new Map();
4010
+ const fed = /* @__PURE__ */ new Map();
3885
4011
  for (const edge of edges) {
3886
4012
  if (edge.source_instance === edge.target_instance) continue;
3887
- predecessors.set(edge.target_instance, [
3888
- ...predecessors.get(edge.target_instance) ?? [],
4013
+ if (!byId.has(edge.source_instance) || !byId.has(edge.target_instance)) continue;
4014
+ feeders.set(edge.target_instance, [
4015
+ ...feeders.get(edge.target_instance) ?? [],
3889
4016
  edge.source_instance
3890
4017
  ]);
3891
- }
3892
- const rows = /* @__PURE__ */ new Map();
3893
- const order = [...ids].sort((a, b) => (columns.get(a) ?? 0) - (columns.get(b) ?? 0));
3894
- const seeded = /* @__PURE__ */ new Map();
3895
- for (const id of order) {
3896
- const column = columns.get(id) ?? 0;
3897
- const stored = arrangementNodes?.[id];
3898
- if (stored) {
3899
- rows.set(id, stored.y);
3900
- continue;
3901
- }
3902
- const seq = seeded.get(column) ?? 0;
3903
- seeded.set(column, seq + 1);
3904
- rows.set(id, seq * SPACING_Y);
3905
- }
3906
- for (const id of order) {
3907
- if (arrangementNodes?.[id]) continue;
3908
- const feeders = (predecessors.get(id) ?? []).filter((f) => rows.has(f));
3909
- if (feeders.length === 0) continue;
3910
- rows.set(id, feeders.reduce((sum, f) => sum + (rows.get(f) ?? 0), 0) / feeders.length);
4018
+ fed.set(edge.source_instance, [...fed.get(edge.source_instance) ?? [], edge]);
3911
4019
  }
3912
4020
  const byColumn = /* @__PURE__ */ new Map();
3913
4021
  for (const id of ids) {
4022
+ if (kept.has(id)) continue;
3914
4023
  const column = columns.get(id) ?? 0;
3915
4024
  byColumn.set(column, [...byColumn.get(column) ?? [], id]);
3916
4025
  }
3917
- for (const [, members] of byColumn) {
3918
- const movable = members.filter((id) => !arrangementNodes?.[id]);
3919
- if (movable.length < 2) continue;
3920
- const sorted = [...movable].sort((a, b) => (rows.get(a) ?? 0) - (rows.get(b) ?? 0));
3921
- const centre = sorted.reduce((sum, id) => sum + (rows.get(id) ?? 0), 0) / sorted.length;
3922
- const first = centre - (sorted.length - 1) * SPACING_Y / 2;
3923
- for (const [i, id] of sorted.entries()) {
3924
- rows.set(id, first + i * SPACING_Y);
3925
- }
3926
- }
3927
- for (const id of unresolved) {
3928
- const column = columns.get(id) ?? 0;
3929
- let candidate = { x: column * SPACING_X, y: rows.get(id) ?? 0 };
3930
- while (overlapsAny(candidate, occupied)) {
3931
- candidate = { x: candidate.x, y: candidate.y + SPACING_Y };
4026
+ const heightOf = (id) => byId.get(id)?.size.height ?? 0;
4027
+ const mean = (values) => values.reduce((sum, v) => sum + v, 0) / values.length;
4028
+ const place = (unfedOrder2) => {
4029
+ const rank = new Map(unfedOrder2.map((id, i) => [id, i]));
4030
+ const positions = new Map(kept);
4031
+ const taken = [...keptSlots];
4032
+ for (const column of [...byColumn.keys()].sort((p, q) => p - q)) {
4033
+ const members = [...byColumn.get(column) ?? []].sort(
4034
+ (p, q) => (rank.get(p) ?? 0) - (rank.get(q) ?? 0)
4035
+ );
4036
+ const tops = /* @__PURE__ */ new Map();
4037
+ let stacked = 0;
4038
+ for (const id of members) {
4039
+ const from = (feeders.get(id) ?? []).flatMap((f) => {
4040
+ const at = positions.get(f);
4041
+ return at ? [at.y + heightOf(f) / 2] : [];
4042
+ });
4043
+ if (from.length > 0) {
4044
+ tops.set(id, mean(from) - heightOf(id) / 2);
4045
+ } else {
4046
+ tops.set(id, stacked);
4047
+ stacked += slotOfId(id).height;
4048
+ }
4049
+ }
4050
+ const sorted = [...members].sort((p, q) => (tops.get(p) ?? 0) - (tops.get(q) ?? 0));
4051
+ if (sorted.length > 1) {
4052
+ const offsets = [];
4053
+ let run = 0;
4054
+ for (const id of sorted) {
4055
+ offsets.push(run);
4056
+ run += slotOfId(id).height;
4057
+ }
4058
+ const first = mean(sorted.map((id) => tops.get(id) ?? 0)) - mean(offsets);
4059
+ for (const [i, id] of sorted.entries()) tops.set(id, first + offsets[i]);
4060
+ }
4061
+ const x = columnX.get(column) ?? 0;
4062
+ for (const id of sorted) {
4063
+ const slot = slotOfId(id);
4064
+ const at = stepDown({ x, y: tops.get(id) ?? 0 }, slot, taken);
4065
+ positions.set(id, at);
4066
+ taken.push({ ...at, ...slot });
4067
+ }
3932
4068
  }
3933
- positions.set(id, candidate);
3934
- occupied.push(candidate);
3935
- }
3936
- return positions;
4069
+ return positions;
4070
+ };
4071
+ const provisional = place(ids);
4072
+ const landing = (id) => {
4073
+ const out = fed.get(id) ?? [];
4074
+ const at = provisional.get(id);
4075
+ if (out.length === 0) return (at?.y ?? 0) + slotOfId(id).height / 2;
4076
+ const ys = out.map((edge) => {
4077
+ const target = byId.get(edge.target_instance);
4078
+ const top = provisional.get(edge.target_instance)?.y ?? 0;
4079
+ const pin = target?.pinY && edge.to_input !== void 0 ? target.pinY(edge.to_input) : 0;
4080
+ return top + pin;
4081
+ });
4082
+ return mean(ys);
4083
+ };
4084
+ const unfedOrder = [...ids].sort(
4085
+ (p, q) => landing(p) - landing(q) || (declared.get(p) ?? 0) - (declared.get(q) ?? 0)
4086
+ );
4087
+ return place(unfedOrder);
3937
4088
  }
3938
4089
  function columnByDepth(ids, edges) {
3939
4090
  const present = new Set(ids);
@@ -3960,39 +4111,40 @@ function projectGroup(use, target, fullId, parentArrangement) {
3960
4111
  const childIds = (target.modules ?? []).map((u) => joinPath(fullId, u.id));
3961
4112
  const parentGroup = parentArrangement?.groups?.[use.id];
3962
4113
  const collapsed = parentGroup ? parentGroup.collapsed : true;
3963
- const label = parentGroup?.label ? parentGroup.label : use.id;
3964
- const inputs = (target.interface?.inputs ?? []).map((in_) => ({
3965
- name: in_.name,
3966
- type: in_.type,
3967
- required: in_.required,
3968
- description: in_.description
3969
- }));
3970
- const outputs = (target.interface?.outputs ?? []).map((out) => ({
3971
- name: out.name,
3972
- type: out.type,
3973
- description: out.description,
3974
- sensitive: out.sensitive
3975
- }));
3976
4114
  return {
3977
4115
  id: fullId,
3978
- label,
4116
+ label: use.id,
3979
4117
  node_ids: childIds,
3980
4118
  collapsed,
3981
4119
  module_key: use.module,
3982
- inputs,
3983
- outputs
4120
+ ...groupPins(target)
4121
+ };
4122
+ }
4123
+ function groupPins(target) {
4124
+ return {
4125
+ inputs: (target.interface?.inputs ?? []).map((in_) => ({
4126
+ name: in_.name,
4127
+ type: in_.type,
4128
+ required: in_.required,
4129
+ description: in_.description
4130
+ })),
4131
+ outputs: (target.interface?.outputs ?? []).map((out) => ({
4132
+ name: out.name,
4133
+ type: out.type,
4134
+ description: out.description,
4135
+ sensitive: out.sensitive
4136
+ }))
3984
4137
  };
3985
4138
  }
3986
4139
 
3987
4140
  // src/projection/project-node.ts
3988
- function projectNode(bundle, use, fullId, position, wiredIn, wiredOut) {
4141
+ function projectNode(bundle, use, fullId, wiredIn, wiredOut) {
3989
4142
  const schema = resolveSchema(bundle, use, wiredOut);
3990
4143
  return {
3991
4144
  id: fullId,
3992
4145
  label: use.id,
3993
4146
  kind: "module",
3994
4147
  module_key: use.module,
3995
- position,
3996
4148
  inputs: schema.inputs.map((in_) => ({
3997
4149
  name: in_.name,
3998
4150
  type: in_.type,
@@ -4012,43 +4164,58 @@ function projectNode(bundle, use, fullId, position, wiredIn, wiredOut) {
4012
4164
  }
4013
4165
 
4014
4166
  // src/projection/project-scope.ts
4015
- function requirePosition(positions, id) {
4016
- const pos = positions.get(id);
4017
- if (!pos) throw new Error(`projectScope: no computed position for "${id}"`);
4018
- return pos;
4019
- }
4020
- function projectScope(bundle, mod, path, arrangement) {
4167
+ function projectScope(bundle, mod, use, path, arrangement, children) {
4021
4168
  const uses = mod.modules ?? [];
4022
4169
  const derived = deriveEdges(uses);
4023
4170
  const { inputs: wiredIn, outputs: wiredOut } = indexWires(derived);
4024
- const scopeKey = resolveScopePath(bundle, path);
4025
- const scopeArrangement = scopeKey ? arrangement?.[scopeKey] : void 0;
4026
- const nodes = [];
4171
+ const scopeArrangement = arrangement?.[use ? use.module : bundle.entry];
4172
+ const cards = [];
4027
4173
  const groups = [];
4028
- const classified = uses.map((use) => ({ use, group: isGroupUse(bundle, use) }));
4029
- const nodeUseIds = classified.filter((c) => !c.group).map((c) => c.use.id);
4030
- const positions = resolveScopePositionsByDepth(nodeUseIds, scopeArrangement?.nodes, derived);
4031
- for (const { use, group } of classified) {
4032
- const fullId = joinPath(path, use.id);
4033
- if (group) {
4034
- const target = bundle.modules[use.module];
4035
- groups.push(projectGroup(use, target, fullId, scopeArrangement));
4174
+ const items = [];
4175
+ const boxMin = /* @__PURE__ */ new Map();
4176
+ for (const child of uses) {
4177
+ const fullId = joinPath(path, child.id);
4178
+ if (isGroupUse(bundle, child)) {
4179
+ const group = projectGroup(child, bundle.modules[child.module], fullId, scopeArrangement);
4180
+ const content = children.get(fullId);
4181
+ if (!content) throw new Error(`projectScope: no layout for group "${fullId}"`);
4182
+ groups.push(group);
4183
+ boxMin.set(child.id, content.min);
4184
+ items.push({
4185
+ id: child.id,
4186
+ size: groupFootprint(group, content.box),
4187
+ pinY: (input) => groupInputPinY(group, input)
4188
+ });
4036
4189
  continue;
4037
4190
  }
4038
- nodes.push(
4039
- projectNode(
4040
- bundle,
4041
- use,
4042
- fullId,
4043
- // Every non-group use is in nodeUseIds, so resolveScopePositionsByDepth
4044
- // always has an entry for it — requirePosition turns that into a
4045
- // checked invariant instead of a silent gap a fallback would mask.
4046
- requirePosition(positions, use.id),
4047
- wiredIn.get(use.id) ?? /* @__PURE__ */ new Set(),
4048
- wiredOut.get(use.id) ?? /* @__PURE__ */ new Set()
4049
- )
4191
+ const node = projectNode(
4192
+ bundle,
4193
+ child,
4194
+ fullId,
4195
+ wiredIn.get(child.id) ?? /* @__PURE__ */ new Set(),
4196
+ wiredOut.get(child.id) ?? /* @__PURE__ */ new Set()
4050
4197
  );
4198
+ cards.push(node);
4199
+ items.push({ id: child.id, size: nodeSize(node), pinY: (input) => inputPinY(node, input) });
4200
+ }
4201
+ const stored = /* @__PURE__ */ new Map();
4202
+ for (const child of uses) {
4203
+ const at = scopeArrangement?.nodes?.[child.id];
4204
+ if (!at) continue;
4205
+ const min = boxMin.get(child.id);
4206
+ stored.set(child.id, min ? boxAt(originAt(at), min) : at);
4051
4207
  }
4208
+ const local = layoutByDepth(items, stored, derived);
4209
+ const placedAt = (useId) => {
4210
+ const at = local.get(useId);
4211
+ if (!at) throw new Error(`projectScope: no position for "${joinPath(path, useId)}"`);
4212
+ return at;
4213
+ };
4214
+ const nodes = cards.map((card) => ({ ...card, position: placedAt(splitPath(card.id).localId) }));
4215
+ const extent = extentOf([
4216
+ { x: 0, y: 0, width: 0, height: 0 },
4217
+ ...items.map((item) => ({ ...placedAt(item.id), ...item.size }))
4218
+ ]);
4052
4219
  const edges = derived.map((de) => {
4053
4220
  const sourceId = joinPath(path, de.source_instance);
4054
4221
  const targetId = joinPath(path, de.target_instance);
@@ -4060,7 +4227,14 @@ function projectScope(bundle, mod, path, arrangement) {
4060
4227
  target_input: de.to_input
4061
4228
  };
4062
4229
  });
4063
- return { nodes, edges, groups };
4230
+ return {
4231
+ nodes,
4232
+ groups,
4233
+ edges,
4234
+ local,
4235
+ min: { x: extent.x, y: extent.y },
4236
+ box: groupBoxSize(extent)
4237
+ };
4064
4238
  }
4065
4239
 
4066
4240
  // src/projection/walk-modules.ts
@@ -4085,15 +4259,36 @@ var EMPTY_BUNDLE = Bundle.fromPartial({
4085
4259
  modules: { "root@v1": { id: "root", version: "v1.0.0" } }
4086
4260
  });
4087
4261
  function projectCanvasView(bundle, arrangement, meta) {
4262
+ const scopes = [];
4263
+ walk(bundle, (mod, use, path) => {
4264
+ scopes.push({ mod, use, path });
4265
+ });
4266
+ const layouts = /* @__PURE__ */ new Map();
4267
+ for (const { mod, use, path } of [...scopes].reverse()) {
4268
+ layouts.set(path, projectScope(bundle, mod, use, path, arrangement, layouts));
4269
+ }
4088
4270
  const nodes = [];
4089
4271
  const edges = [];
4090
4272
  const groups = [];
4091
- walk(bundle, (mod, _use, path) => {
4092
- const scope = projectScope(bundle, mod, path, arrangement);
4093
- nodes.push(...scope.nodes);
4094
- edges.push(...scope.edges);
4095
- groups.push(...scope.groups);
4096
- });
4273
+ const origins = /* @__PURE__ */ new Map([["", { x: 0, y: 0 }]]);
4274
+ for (const { path } of scopes) {
4275
+ const layout = layouts.get(path);
4276
+ const origin = origins.get(path);
4277
+ if (!layout || !origin) continue;
4278
+ const at = (local) => ({ x: origin.x + local.x, y: origin.y + local.y });
4279
+ for (const node of layout.nodes) nodes.push({ ...node, position: at(node.position) });
4280
+ for (const group of layout.groups) {
4281
+ const content = layouts.get(group.id);
4282
+ const box = layout.local.get(splitPath(group.id).localId);
4283
+ if (!content || !box)
4284
+ throw new Error(`projectCanvasView: group "${group.id}" was not laid out`);
4285
+ const position = at(box);
4286
+ const membersAt = originAt(position, content.min);
4287
+ origins.set(group.id, membersAt);
4288
+ groups.push({ ...group, position, size: content.box, origin: membersAt });
4289
+ }
4290
+ edges.push(...layout.edges);
4291
+ }
4097
4292
  const moduleName = meta.moduleName ?? parseModuleKey(bundle.entry).id;
4098
4293
  return {
4099
4294
  module_name: moduleName,
@@ -4104,7 +4299,7 @@ function projectCanvasView(bundle, arrangement, meta) {
4104
4299
  unsaved: meta.unsaved,
4105
4300
  conflict: meta.conflict,
4106
4301
  ungenerated: meta.ungenerated ?? false,
4107
- // Every group is now a Use whose target has sub-Uses (CreateGroupAction
4302
+ // Every group is a Use whose target has sub-Uses (CreateGroupAction
4108
4303
  // mints a module); emission order already mirrors Use declaration order
4109
4304
  // via the walk, so no separate user-group sort is needed.
4110
4305
  groups
@@ -4909,7 +5104,7 @@ function isSet3(value) {
4909
5104
  var CanvasViewProto = CanvasView;
4910
5105
 
4911
5106
  // src/protocol-version.ts
4912
- var ENGINE_PROTOCOL_VERSION = String(3 /* PROTOCOL_VERSION_CURRENT */);
5107
+ var ENGINE_PROTOCOL_VERSION = String(4 /* PROTOCOL_VERSION_CURRENT */);
4913
5108
  var EngineProtocolMismatchError = class extends Error {
4914
5109
  constructor(engineVersion, engineProtocol, requiredProtocol) {
4915
5110
  super(
@@ -4936,6 +5131,7 @@ function checkEngineProtocol(engineVersion, engineProtocol) {
4936
5131
  export {
4937
5132
  BRIDGE_METHODS,
4938
5133
  Bundle,
5134
+ COLLAPSED_GROUP_WIDTH,
4939
5135
  CONNECT_CODE_NAMES,
4940
5136
  CanvasViewProto,
4941
5137
  EMPTY_BUNDLE,
@@ -4943,21 +5139,49 @@ export {
4943
5139
  ENGINE_PROTOCOL_VERSION,
4944
5140
  ENGINE_STREAM_METHODS,
4945
5141
  EngineProtocolMismatchError,
5142
+ GROUP_HEADER_HEIGHT,
5143
+ GROUP_PADDING,
4946
5144
  HOST_ONLY_METHODS,
5145
+ NODE_HEADER_HEIGHT,
5146
+ NODE_ROW_HEIGHT,
5147
+ NODE_WIDTH,
5148
+ boxAt,
4947
5149
  callText,
4948
5150
  checkEngineProtocol,
5151
+ collapsedGroupSize,
4949
5152
  convertDiagnostic,
4950
5153
  deriveNodeConfig,
4951
5154
  deriveSettingsConfig,
5155
+ drawnAt,
5156
+ drawnRect,
5157
+ extentOf,
5158
+ frameOf,
5159
+ freeSlot,
5160
+ groupBoxSize,
5161
+ groupFootprint,
5162
+ groupInputPinY,
5163
+ groupPinY,
5164
+ groupPins,
5165
+ groupReach,
5166
+ inputPinY,
4952
5167
  instanceAddress,
5168
+ joinPath,
5169
+ keepOrder,
5170
+ layoutByDepth,
5171
+ localIn,
4953
5172
  nodeIdForAddress,
4954
5173
  nodeIdForDiagnostic,
5174
+ nodeRows,
5175
+ nodeSize,
5176
+ originAt,
4955
5177
  parseModuleKey,
4956
5178
  projectCanvasView,
5179
+ reachRect,
4957
5180
  resolveInstance,
4958
5181
  resolveScopePath,
4959
- resolveScopePositions,
4960
5182
  resolveScopePositionsByDepth,
4961
- splitPath
5183
+ splitPath,
5184
+ stepDown,
5185
+ visibleInputs
4962
5186
  };
4963
5187
  //# sourceMappingURL=index.mjs.map