@lace-cloud/proto 0.16.1 → 0.16.2

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
@@ -40,7 +40,8 @@ __export(index_exports, {
40
40
  parseModuleKey: () => parseModuleKey,
41
41
  projectCanvasView: () => projectCanvasView,
42
42
  resolveScopePath: () => resolveScopePath,
43
- resolveScopePositions: () => resolveScopePositions
43
+ resolveScopePositions: () => resolveScopePositions,
44
+ resolveScopePositionsByDepth: () => resolveScopePositionsByDepth
44
45
  });
45
46
  module.exports = __toCommonJS(index_exports);
46
47
 
@@ -3823,7 +3824,7 @@ function overlapsAny(candidate, occupied) {
3823
3824
  (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
3824
3825
  );
3825
3826
  }
3826
- function resolveScopePositions(ids, arrangementNodes) {
3827
+ function partitionStored(ids, arrangementNodes) {
3827
3828
  const positions = /* @__PURE__ */ new Map();
3828
3829
  const occupied = [];
3829
3830
  const unresolved = [];
@@ -3836,6 +3837,10 @@ function resolveScopePositions(ids, arrangementNodes) {
3836
3837
  unresolved.push(id);
3837
3838
  }
3838
3839
  }
3840
+ return { positions, occupied, unresolved };
3841
+ }
3842
+ function resolveScopePositions(ids, arrangementNodes) {
3843
+ const { positions, occupied, unresolved } = partitionStored(ids, arrangementNodes);
3839
3844
  let slot = 0;
3840
3845
  for (const id of unresolved) {
3841
3846
  let candidate = gridPosition(slot, ids.length);
@@ -3849,6 +3854,82 @@ function resolveScopePositions(ids, arrangementNodes) {
3849
3854
  }
3850
3855
  return positions;
3851
3856
  }
3857
+ function resolveScopePositionsByDepth(ids, arrangementNodes, edges) {
3858
+ const { positions, occupied, unresolved } = partitionStored(ids, arrangementNodes);
3859
+ const columns = columnByDepth(ids, edges);
3860
+ const predecessors = /* @__PURE__ */ new Map();
3861
+ for (const edge of edges) {
3862
+ if (edge.source_instance === edge.target_instance) continue;
3863
+ predecessors.set(edge.target_instance, [
3864
+ ...predecessors.get(edge.target_instance) ?? [],
3865
+ edge.source_instance
3866
+ ]);
3867
+ }
3868
+ const rows = /* @__PURE__ */ new Map();
3869
+ const order = [...ids].sort((a, b) => (columns.get(a) ?? 0) - (columns.get(b) ?? 0));
3870
+ const seeded = /* @__PURE__ */ new Map();
3871
+ for (const id of order) {
3872
+ const column = columns.get(id) ?? 0;
3873
+ const stored = arrangementNodes?.[id];
3874
+ if (stored) {
3875
+ rows.set(id, stored.y);
3876
+ continue;
3877
+ }
3878
+ const seq = seeded.get(column) ?? 0;
3879
+ seeded.set(column, seq + 1);
3880
+ rows.set(id, seq * SPACING_Y);
3881
+ }
3882
+ for (const id of order) {
3883
+ if (arrangementNodes?.[id]) continue;
3884
+ const feeders = (predecessors.get(id) ?? []).filter((f) => rows.has(f));
3885
+ if (feeders.length === 0) continue;
3886
+ rows.set(id, feeders.reduce((sum, f) => sum + (rows.get(f) ?? 0), 0) / feeders.length);
3887
+ }
3888
+ const byColumn = /* @__PURE__ */ new Map();
3889
+ for (const id of ids) {
3890
+ const column = columns.get(id) ?? 0;
3891
+ byColumn.set(column, [...byColumn.get(column) ?? [], id]);
3892
+ }
3893
+ for (const [, members] of byColumn) {
3894
+ const movable = members.filter((id) => !arrangementNodes?.[id]);
3895
+ if (movable.length < 2) continue;
3896
+ const sorted = [...movable].sort((a, b) => (rows.get(a) ?? 0) - (rows.get(b) ?? 0));
3897
+ const centre = sorted.reduce((sum, id) => sum + (rows.get(id) ?? 0), 0) / sorted.length;
3898
+ const first = centre - (sorted.length - 1) * SPACING_Y / 2;
3899
+ for (const [i, id] of sorted.entries()) {
3900
+ rows.set(id, first + i * SPACING_Y);
3901
+ }
3902
+ }
3903
+ for (const id of unresolved) {
3904
+ const column = columns.get(id) ?? 0;
3905
+ let candidate = { x: column * SPACING_X, y: rows.get(id) ?? 0 };
3906
+ while (overlapsAny(candidate, occupied)) {
3907
+ candidate = { x: candidate.x, y: candidate.y + SPACING_Y };
3908
+ }
3909
+ positions.set(id, candidate);
3910
+ occupied.push(candidate);
3911
+ }
3912
+ return positions;
3913
+ }
3914
+ function columnByDepth(ids, edges) {
3915
+ const present = new Set(ids);
3916
+ const real = edges.filter(
3917
+ (e) => e.source_instance !== e.target_instance && present.has(e.source_instance) && present.has(e.target_instance)
3918
+ );
3919
+ const depth = new Map(ids.map((id) => [id, 0]));
3920
+ for (let round = 0; round < ids.length; round += 1) {
3921
+ let moved = false;
3922
+ for (const e of real) {
3923
+ const want = (depth.get(e.source_instance) ?? 0) + 1;
3924
+ if (want > (depth.get(e.target_instance) ?? 0)) {
3925
+ depth.set(e.target_instance, want);
3926
+ moved = true;
3927
+ }
3928
+ }
3929
+ if (!moved) break;
3930
+ }
3931
+ return depth;
3932
+ }
3852
3933
 
3853
3934
  // src/projection/derive-edges.ts
3854
3935
  var moduleDepPattern = /\bmodule\.([A-Za-z_][A-Za-z0-9_-]*)(?:\[\s*(?:\*|[0-9]+|"[^"]*")\s*\])?\.([A-Za-z_][A-Za-z0-9_-]*)/g;
@@ -4009,7 +4090,7 @@ function projectScope(bundle, mod, path, arrangement, errorsByInstance) {
4009
4090
  const groups = [];
4010
4091
  const classified = uses.map((use) => ({ use, group: isGroupUse(bundle, use) }));
4011
4092
  const nodeUseIds = classified.filter((c) => !c.group).map((c) => c.use.id);
4012
- const positions = resolveScopePositions(nodeUseIds, scopeArrangement?.nodes);
4093
+ const positions = resolveScopePositionsByDepth(nodeUseIds, scopeArrangement?.nodes, derived);
4013
4094
  for (const { use, group } of classified) {
4014
4095
  const fullId = joinPath(path, use.id);
4015
4096
  if (group) {
@@ -4022,7 +4103,7 @@ function projectScope(bundle, mod, path, arrangement, errorsByInstance) {
4022
4103
  bundle,
4023
4104
  use,
4024
4105
  fullId,
4025
- // Every non-group use is in nodeUseIds, so resolveScopePositions
4106
+ // Every non-group use is in nodeUseIds, so resolveScopePositionsByDepth
4026
4107
  // always has an entry for it — a fallback here would only mask a
4027
4108
  // classification bug, not handle a real gap.
4028
4109
  positions.get(use.id),
@@ -7293,6 +7374,7 @@ var SettingsConfigProto = SettingsConfig;
7293
7374
  parseModuleKey,
7294
7375
  projectCanvasView,
7295
7376
  resolveScopePath,
7296
- resolveScopePositions
7377
+ resolveScopePositions,
7378
+ resolveScopePositionsByDepth
7297
7379
  });
7298
7380
  //# sourceMappingURL=index.cjs.map