@ankhorage/zora 21.0.12 → 21.0.13

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
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 21.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - 4504e86: Retry GraphView's pending initial fit when the container first becomes usable after a zero-size layout mount.
8
+
3
9
  ## 21.0.12
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # @ankhorage/zora
5
5
 
6
- ![license: MIT](././paradox/badges/license.svg) ![npm: v21.0.12](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![docs: paradox](././paradox/badges/docs.svg)
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v21.0.13](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![docs: paradox](././paradox/badges/docs.svg)
7
7
 
8
8
  Opinionated React Native and React Native Web UI kit built on @ankhorage/surface.
9
9
 
@@ -6,10 +6,13 @@ interface CreateGraphResizeObserverInput {
6
6
  readonly layoutRunningRef: {
7
7
  current: boolean;
8
8
  };
9
+ readonly pendingInitialFitRef: {
10
+ current: boolean;
11
+ };
9
12
  readonly readyRef: {
10
13
  current: boolean;
11
14
  };
12
- readonly onViewportSettled: () => void;
15
+ readonly onViewportSettled: (completedPendingInitialFit: boolean) => void;
13
16
  }
14
17
  export interface GraphResizeObserver {
15
18
  disconnect(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"createGraphResizeObserver.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphResizeObserver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAItC,UAAU,8BAA8B;IACtC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,cAAc,EAAE,MAAM,IAAI,CAAC;IACpC,QAAQ,CAAC,gBAAgB,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAChD,QAAQ,CAAC,QAAQ,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IACxC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,IAAI,CAAC;CACxC;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,IAAI,IAAI,CAAC;CACpB;AAED,sFAAsF;AACtF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,8BAA8B,GACpC,mBAAmB,GAAG,IAAI,CAe5B"}
1
+ {"version":3,"file":"createGraphResizeObserver.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphResizeObserver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAItC,UAAU,8BAA8B;IACtC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,cAAc,EAAE,MAAM,IAAI,CAAC;IACpC,QAAQ,CAAC,gBAAgB,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAChD,QAAQ,CAAC,oBAAoB,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IACxC,QAAQ,CAAC,iBAAiB,EAAE,CAAC,0BAA0B,EAAE,OAAO,KAAK,IAAI,CAAC;CAC3E;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,IAAI,IAAI,CAAC;CACpB;AAED,sFAAsF;AACtF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,8BAA8B,GACpC,mBAAmB,GAAG,IAAI,CAgB5B"}
@@ -11,7 +11,9 @@ export function createGraphResizeObserver(input) {
11
11
  return;
12
12
  sizeRef.height = entry.contentRect.height;
13
13
  sizeRef.width = entry.contentRect.width;
14
- if (!input.readyRef.current || input.layoutRunningRef.current)
14
+ if (input.layoutRunningRef.current)
15
+ return;
16
+ if (!input.readyRef.current && !input.pendingInitialFitRef.current)
15
17
  return;
16
18
  scheduleResizeFit(input);
17
19
  });
@@ -24,8 +26,12 @@ function scheduleResizeFit(input) {
24
26
  if (input.cy.destroyed() || input.layoutRunningRef.current)
25
27
  return;
26
28
  input.cy.resize();
29
+ if (input.cy.width() <= 0 || input.cy.height() <= 0)
30
+ return;
31
+ const completedPendingInitialFit = input.pendingInitialFitRef.current;
32
+ input.pendingInitialFitRef.current = false;
27
33
  input.settleViewport();
28
- input.onViewportSettled();
34
+ input.onViewportSettled(completedPendingInitialFit);
29
35
  });
30
36
  }
31
37
  /*** Return whether ResizeObserver reported a genuinely different container size. */
@@ -1 +1 @@
1
- {"version":3,"file":"createGraphResizeObserver.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphResizeObserver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAe1D,sFAAsF;AACtF,MAAM,UAAU,yBAAyB,CACvC,KAAqC;IAErC,MAAM,QAAQ,GAAG,6BAA6B,EAAE,CAAC;IACjD,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACnC,MAAM,OAAO,GAAG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AED,qFAAqF;AACrF,SAAS,6BAA6B;IACpC,MAAM,KAAK,GACT,UAGD,CAAC,cAAc,CAAC;IACjB,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import type { Core } from 'cytoscape';\n\nimport { scheduleGraphFrame } from './scheduleGraphFrame';\n\ninterface CreateGraphResizeObserverInput {\n readonly container: unknown;\n readonly cy: Core;\n readonly settleViewport: () => void;\n readonly layoutRunningRef: { current: boolean };\n readonly readyRef: { current: boolean };\n readonly onViewportSettled: () => void;\n}\n\nexport interface GraphResizeObserver {\n disconnect(): void;\n}\n\n/*** Observe settled container resizing without racing an active layout generation. */\nexport function createGraphResizeObserver(\n input: CreateGraphResizeObserverInput,\n): GraphResizeObserver | null {\n const Observer = readResizeObserverConstructor();\n if (Observer === null) return null;\n const sizeRef = { height: -1, width: -1 };\n\n const observer = new Observer((entries) => {\n const entry = entries.at(0);\n if (entry === undefined || !hasSizeChanged(sizeRef, entry.contentRect)) return;\n sizeRef.height = entry.contentRect.height;\n sizeRef.width = entry.contentRect.width;\n if (!input.readyRef.current || input.layoutRunningRef.current) return;\n scheduleResizeFit(input);\n });\n observer.observe(input.container);\n return observer;\n}\n\n/*** Fit one genuine resize only after the active layout has settled. */\nfunction scheduleResizeFit(input: CreateGraphResizeObserverInput) {\n scheduleGraphFrame(() => {\n if (input.cy.destroyed() || input.layoutRunningRef.current) return;\n input.cy.resize();\n input.settleViewport();\n input.onViewportSettled();\n });\n}\n\n/*** Return whether ResizeObserver reported a genuinely different container size. */\nfunction hasSizeChanged(\n previous: { readonly height: number; readonly width: number },\n next: { readonly height: number; readonly width: number },\n): boolean {\n return previous.height !== next.height || previous.width !== next.width;\n}\n\n/*** Read ResizeObserver without imposing DOM library types on the package target. */\nfunction readResizeObserverConstructor(): ResizeObserverConstructorLike | null {\n const value = (\n globalThis as unknown as {\n ResizeObserver?: ResizeObserverConstructorLike;\n }\n ).ResizeObserver;\n return value ?? null;\n}\n\ninterface ResizeObserverEntryLike {\n readonly contentRect: {\n readonly height: number;\n readonly width: number;\n };\n}\n\ninterface ResizeObserverLike extends GraphResizeObserver {\n observe(target: unknown): void;\n}\n\ntype ResizeObserverConstructorLike = new (\n callback: (entries: readonly ResizeObserverEntryLike[]) => void,\n) => ResizeObserverLike;\n"]}
1
+ {"version":3,"file":"createGraphResizeObserver.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphResizeObserver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAgB1D,sFAAsF;AACtF,MAAM,UAAU,yBAAyB,CACvC,KAAqC;IAErC,MAAM,QAAQ,GAAG,6BAA6B,EAAE,CAAC;IACjD,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACnC,MAAM,OAAO,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;IAE1C,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,CAAC,OAAO,EAAE,EAAE;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC;YAAE,OAAO;QAC/E,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC;QAC1C,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC;QACxC,IAAI,KAAK,CAAC,gBAAgB,CAAC,OAAO;YAAE,OAAO;QAC3C,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,OAAO;YAAE,OAAO;QAC3E,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,wEAAwE;AACxE,SAAS,iBAAiB,CAAC,KAAqC;IAC9D,kBAAkB,CAAC,GAAG,EAAE;QACtB,IAAI,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,KAAK,CAAC,gBAAgB,CAAC,OAAO;YAAE,OAAO;QACnE,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC;QAClB,IAAI,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC;YAAE,OAAO;QAC5D,MAAM,0BAA0B,GAAG,KAAK,CAAC,oBAAoB,CAAC,OAAO,CAAC;QACtE,KAAK,CAAC,oBAAoB,CAAC,OAAO,GAAG,KAAK,CAAC;QAC3C,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,KAAK,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,oFAAoF;AACpF,SAAS,cAAc,CACrB,QAA6D,EAC7D,IAAyD;IAEzD,OAAO,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,IAAI,QAAQ,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC;AAC1E,CAAC;AAED,qFAAqF;AACrF,SAAS,6BAA6B;IACpC,MAAM,KAAK,GACT,UAGD,CAAC,cAAc,CAAC;IACjB,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import type { Core } from 'cytoscape';\n\nimport { scheduleGraphFrame } from './scheduleGraphFrame';\n\ninterface CreateGraphResizeObserverInput {\n readonly container: unknown;\n readonly cy: Core;\n readonly settleViewport: () => void;\n readonly layoutRunningRef: { current: boolean };\n readonly pendingInitialFitRef: { current: boolean };\n readonly readyRef: { current: boolean };\n readonly onViewportSettled: (completedPendingInitialFit: boolean) => void;\n}\n\nexport interface GraphResizeObserver {\n disconnect(): void;\n}\n\n/*** Observe settled container resizing without racing an active layout generation. */\nexport function createGraphResizeObserver(\n input: CreateGraphResizeObserverInput,\n): GraphResizeObserver | null {\n const Observer = readResizeObserverConstructor();\n if (Observer === null) return null;\n const sizeRef = { height: -1, width: -1 };\n\n const observer = new Observer((entries) => {\n const entry = entries.at(0);\n if (entry === undefined || !hasSizeChanged(sizeRef, entry.contentRect)) return;\n sizeRef.height = entry.contentRect.height;\n sizeRef.width = entry.contentRect.width;\n if (input.layoutRunningRef.current) return;\n if (!input.readyRef.current && !input.pendingInitialFitRef.current) return;\n scheduleResizeFit(input);\n });\n observer.observe(input.container);\n return observer;\n}\n\n/*** Fit one genuine resize only after the active layout has settled. */\nfunction scheduleResizeFit(input: CreateGraphResizeObserverInput) {\n scheduleGraphFrame(() => {\n if (input.cy.destroyed() || input.layoutRunningRef.current) return;\n input.cy.resize();\n if (input.cy.width() <= 0 || input.cy.height() <= 0) return;\n const completedPendingInitialFit = input.pendingInitialFitRef.current;\n input.pendingInitialFitRef.current = false;\n input.settleViewport();\n input.onViewportSettled(completedPendingInitialFit);\n });\n}\n\n/*** Return whether ResizeObserver reported a genuinely different container size. */\nfunction hasSizeChanged(\n previous: { readonly height: number; readonly width: number },\n next: { readonly height: number; readonly width: number },\n): boolean {\n return previous.height !== next.height || previous.width !== next.width;\n}\n\n/*** Read ResizeObserver without imposing DOM library types on the package target. */\nfunction readResizeObserverConstructor(): ResizeObserverConstructorLike | null {\n const value = (\n globalThis as unknown as {\n ResizeObserver?: ResizeObserverConstructorLike;\n }\n ).ResizeObserver;\n return value ?? null;\n}\n\ninterface ResizeObserverEntryLike {\n readonly contentRect: {\n readonly height: number;\n readonly width: number;\n };\n}\n\ninterface ResizeObserverLike extends GraphResizeObserver {\n observe(target: unknown): void;\n}\n\ntype ResizeObserverConstructorLike = new (\n callback: (entries: readonly ResizeObserverEntryLike[]) => void,\n) => ResizeObserverLike;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"createGraphRuntime.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAkB,EAAa,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAExE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAQhF,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EAEzB,qBAAqB,EACrB,aAAa,EAEd,MAAM,aAAa,CAAC;AAUrB,KAAK,cAAc,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACpD,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,SAAS,qBAAqB,EAAE,KAAK,IAAI,CAAC;AAE9E,MAAM,WAAW,YAAY;IAC3B,OAAO,IAAI,IAAI,CAAC;IAChB,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAC1E,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;IACnD,kBAAkB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC;IACjE,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,IAAI,CAAC;IACnE,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC;AA2BD,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,cAAc,EACzB,YAAY,EAAE;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,GAC5C,YAAY,CAmBd"}
1
+ {"version":3,"file":"createGraphRuntime.d.ts","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAkB,EAAa,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAExE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAQhF,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EAEzB,qBAAqB,EACrB,aAAa,EAEd,MAAM,aAAa,CAAC;AAUrB,KAAK,cAAc,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACpD,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,SAAS,qBAAqB,EAAE,KAAK,IAAI,CAAC;AAE9E,MAAM,WAAW,YAAY;IAC3B,OAAO,IAAI,IAAI,CAAC;IAChB,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAC1E,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;IACnD,kBAAkB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC;IACjE,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,IAAI,CAAC;IACnE,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC;AA4BD,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,cAAc,EACzB,YAAY,EAAE;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,GAC5C,YAAY,CAmBd"}
@@ -59,6 +59,7 @@ function createRuntimeState(cy, container, callbacksRef) {
59
59
  nodeSizes: new Map(),
60
60
  labelSizedNodeIds: new Set(),
61
61
  loopSizer: createGraphLoopSizer(cy),
62
+ pendingInitialFitRef: { current: false },
62
63
  readyRef,
63
64
  settledTopologyRef: { current: null },
64
65
  relayoutScheduledRef: { current: false },
@@ -70,7 +71,15 @@ function createRuntimeState(cy, container, callbacksRef) {
70
71
  cy,
71
72
  settleViewport: () => viewport.settle(true),
72
73
  layoutRunningRef,
73
- onViewportSettled: () => emitRenderedNodes(stateBase),
74
+ pendingInitialFitRef: stateBase.pendingInitialFitRef,
75
+ onViewportSettled: (completedPendingInitialFit) => {
76
+ emitRenderedNodes(stateBase);
77
+ if (!completedPendingInitialFit || readyRef.current)
78
+ return;
79
+ readyRef.current = true;
80
+ callbacksRef.current.onReady?.(controller);
81
+ callbacksRef.current.onLayoutComplete?.(controller);
82
+ },
74
83
  readyRef,
75
84
  });
76
85
  const state = { ...stateBase, resizeObserver, unbindEvents };
@@ -118,7 +127,7 @@ function updateRuntime(state, input) {
118
127
  state.viewport.settle(previous?.zoomMode !== input.zoomMode);
119
128
  }
120
129
  emitRenderedNodes(state);
121
- if (!state.layoutRunningRef.current)
130
+ if (!state.layoutRunningRef.current && !state.pendingInitialFitRef.current)
122
131
  state.callbacksRef.current.onLayoutComplete?.(state.controller);
123
132
  return;
124
133
  }
@@ -129,6 +138,7 @@ function updateRuntime(state, input) {
129
138
  }
130
139
  /*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */
131
140
  function startCurrentLayout(state, input) {
141
+ state.pendingInitialFitRef.current = false;
132
142
  const generation = state.generationRef.current + 1;
133
143
  state.generationRef.current = generation;
134
144
  state.layoutRunningRef.current = true;
@@ -151,8 +161,12 @@ function completeCurrentLayout(state, generation) {
151
161
  state.layoutRef.current = null;
152
162
  state.cy.resize();
153
163
  state.layoutRunningRef.current = false;
154
- if (!hasUsableViewport(state.cy))
164
+ if (!hasUsableViewport(state.cy)) {
165
+ if (!state.readyRef.current)
166
+ state.pendingInitialFitRef.current = true;
155
167
  return;
168
+ }
169
+ state.pendingInitialFitRef.current = false;
156
170
  const input = state.latestUpdateRef.current;
157
171
  if (input === null)
158
172
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"createGraphRuntime.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAoC,MAAM,WAAW,CAAC;AAGxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CA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AAqB,CAAC,KAAK,EAAE,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE;QAAE,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;AAChD,CAAC;AAED,oBAAoB,EAAE,CAAC","sourcesContent":["import cytoscape, { type Core, type CytoscapeOptions } from 'cytoscape';\n\nimport type { GraphRuntimeUpdate } from '../../../../../types/graphViewRuntime';\nimport { bindGraphEvents } from './bindGraphEvents';\nimport { compactGraphSpacing } from './compactGraphSpacing';\nimport { createGraphController } from './createGraphController';\nimport { createGraphLoopSizer } from './createGraphLoopSizer';\nimport { createGraphResizeObserver, type GraphResizeObserver } from './createGraphResizeObserver';\nimport { getGraphGeometryKey } from './getGraphGeometryKey';\nimport { getGraphTopologyKey } from './getGraphTopologyKey';\nimport type {\n GraphViewCallbacks,\n GraphViewElementEventType,\n GraphViewFitOptions,\n GraphViewRenderedNode,\n GraphViewSize,\n GraphViewStyleRule,\n} from './GraphView';\nimport { hasGraphLayoutChanged } from './hasGraphLayoutChanged';\nimport { readGraphRenderedNodes } from './readGraphRenderedNodes';\nimport { registerGraphLayouts } from './registerGraphLayouts';\nimport { runGraphLayout } from './runGraphLayout';\nimport { scheduleGraphFrame } from './scheduleGraphFrame';\nimport { shouldFitGraphAfterLayout } from './shouldFitGraphAfterLayout';\nimport { sizeGraphNodesToLabels } from './sizeGraphNodesToLabels';\nimport { syncGraphElements } from './syncGraphElements';\n\ntype GraphContainer = CytoscapeOptions['container'];\ntype RenderedNodeListener = (nodes: readonly GraphViewRenderedNode[]) => void;\n\nexport interface GraphRuntime {\n destroy(): void;\n handleOverlayNodeEvent(id: string, type: GraphViewElementEventType): void;\n setNodeSize(id: string, size: GraphViewSize): void;\n setSelectedNodeIds(nodeIds: readonly string[] | undefined): void;\n subscribeRenderedNodes(listener: RenderedNodeListener): () => void;\n update(input: GraphRuntimeUpdate): void;\n}\n\ninterface GraphRuntimeState {\n readonly fitRequestRef: { current: GraphViewFitOptions | null };\n readonly optimizedSpacingRef: { current: number | null };\n readonly callbacksRef: { current: GraphViewCallbacks };\n readonly controller: ReturnType<typeof createGraphController>['controller'];\n readonly viewport: ReturnType<typeof createGraphController>;\n readonly cy: Core;\n readonly fitPaddingRef: { current: number };\n readonly generationRef: { current: number };\n readonly geometryRef: { current: string | null };\n readonly hoveredNodeIds: Set<string>;\n readonly latestUpdateRef: { current: GraphRuntimeUpdate | null };\n readonly layoutRef: { current: ReturnType<typeof runGraphLayout> | null };\n readonly layoutRunningRef: { current: boolean };\n readonly nodeSizes: Map<string, GraphViewSize>;\n readonly labelSizedNodeIds: Set<string>;\n readonly loopSizer: ReturnType<typeof createGraphLoopSizer>;\n readonly readyRef: { current: boolean };\n readonly settledTopologyRef: { current: string | null };\n readonly relayoutScheduledRef: { current: boolean };\n readonly renderedNodeListeners: Set<RenderedNodeListener>;\n readonly resizeObserver: GraphResizeObserver | null;\n readonly unbindEvents: () => void;\n}\n\n/*** Create one Cytoscape runtime that exclusively owns layout, fit, resize, and disposal. */\nexport function createGraphRuntime(\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n): GraphRuntime {\n const cy = cytoscape({\n container,\n elements: [],\n minZoom: 0.05,\n maxZoom: 2,\n selectionType: 'additive',\n userPanningEnabled: true,\n });\n const state = createRuntimeState(cy, container, callbacksRef);\n\n return {\n destroy: () => destroyRuntime(state),\n handleOverlayNodeEvent: (id, type) => handleOverlayNodeEvent(state, id, type),\n setNodeSize: (id, size) => setNodeSize(state, id, size),\n setSelectedNodeIds: (nodeIds) => setSelectedNodeIds(state, nodeIds),\n subscribeRenderedNodes: (listener) => subscribeRenderedNodes(state, listener),\n update: (input) => updateRuntime(state, input),\n };\n}\n\n/*** Build the mutable state shared by the single graph-runtime owner. */\nfunction createRuntimeState(\n cy: Core,\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n): GraphRuntimeState {\n const fitPaddingRef = { current: 50 };\n const viewport = createGraphController(cy, fitPaddingRef, (options) =>\n requestOptimizedFit(state, options),\n );\n const { controller } = viewport;\n const layoutRunningRef = { current: false };\n const readyRef = { current: false };\n const renderedNodeListeners = new Set<RenderedNodeListener>();\n const stateBase = {\n fitRequestRef: { current: null as GraphViewFitOptions | null },\n optimizedSpacingRef: { current: null as number | null },\n callbacksRef,\n controller,\n viewport,\n cy,\n fitPaddingRef,\n generationRef: { current: 0 },\n geometryRef: { current: null as string | null },\n hoveredNodeIds: new Set<string>(),\n latestUpdateRef: { current: null as GraphRuntimeUpdate | null },\n layoutRef: { current: null as ReturnType<typeof runGraphLayout> | null },\n layoutRunningRef,\n nodeSizes: new Map<string, GraphViewSize>(),\n labelSizedNodeIds: new Set<string>(),\n loopSizer: createGraphLoopSizer(cy),\n readyRef,\n settledTopologyRef: { current: null as string | null },\n relayoutScheduledRef: { current: false },\n renderedNodeListeners,\n };\n const unbindEvents = bindGraphEvents(cy, callbacksRef, controller, () =>\n emitRenderedNodes(stateBase),\n );\n const resizeObserver = createGraphResizeObserver({\n container,\n cy,\n settleViewport: () => viewport.settle(true),\n layoutRunningRef,\n onViewportSettled: () => emitRenderedNodes(stateBase),\n readyRef,\n });\n\n const state = { ...stateBase, resizeObserver, unbindEvents };\n return state;\n}\n\n/***\n * Reconcile presentation in place and relayout only when graph geometry or layout policy changes.\n * @performance Batch reconciliation and skip layout for presentation-only updates.\n */\nfunction updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n if (state.cy.destroyed()) return;\n const last = state.latestUpdateRef.current;\n const acceptsSpacing =\n state.optimizedSpacingRef.current !== null &&\n state.optimizedSpacingRef.current === input.spacingFactor;\n const previous = acceptsSpacing && last ? { ...last, spacingFactor: input.spacingFactor } : last;\n if (acceptsSpacing) state.optimizedSpacingRef.current = null;\n state.latestUpdateRef.current = input;\n state.fitPaddingRef.current = input.fitPadding ?? 50;\n state.viewport.configure(input);\n state.cy.batch(() => {\n if (previous?.nodes !== input.nodes || previous.edges !== input.edges) {\n syncGraphElements(state.cy, input.nodes, input.edges);\n }\n if (\n previous?.styleRules !== input.styleRules ||\n previous?.richNodeRendering !== input.richNodeRendering\n ) {\n state.loopSizer.reset();\n applyGraphStyles(state.cy, input.styleRules, input.richNodeRendering);\n }\n });\n sizeGraphNodesToLabels(\n state.cy,\n state.labelSizedNodeIds,\n input.sizeNodesToLabels === true && !input.richNodeRendering,\n );\n applyKnownNodeSizes(state);\n state.loopSizer.update();\n const geometry = getGraphGeometryKey(state.cy);\n const relayout = geometry !== state.geometryRef.current || hasGraphLayoutChanged(previous, input);\n state.geometryRef.current = geometry;\n if (!relayout) {\n if (\n previous?.zoomMode !== input.zoomMode ||\n previous?.fitPadding !== input.fitPadding ||\n previous?.minZoom !== input.minZoom ||\n previous?.maxZoom !== input.maxZoom ||\n previous?.minReadableLabelSize !== input.minReadableLabelSize ||\n previous?.maxFitLabelSize !== input.maxFitLabelSize\n ) {\n state.viewport.settle(previous?.zoomMode !== input.zoomMode);\n }\n emitRenderedNodes(state);\n if (!state.layoutRunningRef.current)\n state.callbacksRef.current.onLayoutComplete?.(state.controller);\n return;\n }\n stopCurrentLayout(state);\n state.fitRequestRef.current = null;\n state.optimizedSpacingRef.current = null;\n startCurrentLayout(state, input);\n}\n\n/*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */\nfunction startCurrentLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n const generation = state.generationRef.current + 1;\n state.generationRef.current = generation;\n state.layoutRunningRef.current = true;\n state.cy.resize();\n state.layoutRef.current = runGraphLayout(\n state.cy,\n {\n layout: input.layout ?? 'concentric',\n layoutOptions: input.layoutOptions,\n spacingFactor: input.spacingFactor ?? 1,\n },\n () => completeCurrentLayout(state, generation),\n );\n}\n\n/***\n * Settle only the latest layout generation and fit once from node bounds.\n * @performance Discard stale completions and avoid repeated automatic fits.\n */\nfunction completeCurrentLayout(state: GraphRuntimeState, generation: number) {\n scheduleGraphFrame(() => {\n if (state.cy.destroyed() || generation !== state.generationRef.current) return;\n state.loopSizer.update();\n state.layoutRef.current = null;\n state.cy.resize();\n state.layoutRunningRef.current = false;\n if (!hasUsableViewport(state.cy)) return;\n const input = state.latestUpdateRef.current;\n if (input === null) return;\n const topology = getGraphTopologyKey(input.nodes, input.edges);\n const shouldFit = shouldFitGraphAfterLayout(\n state.readyRef.current,\n topology !== state.settledTopologyRef.current,\n );\n state.viewport.settle(shouldFit);\n state.settledTopologyRef.current = topology;\n const fitRequest = state.fitRequestRef.current;\n state.fitRequestRef.current = null;\n if (fitRequest) requestOptimizedFit(state, fitRequest);\n emitRenderedNodes(state);\n\n if (!state.readyRef.current) {\n state.readyRef.current = true;\n state.callbacksRef.current.onReady?.(state.controller);\n }\n state.callbacksRef.current.onLayoutComplete?.(state.controller);\n });\n}\n\n/***\n * Handle explicit readable-fit intent in the runtime owner, never from zoom or React effects.\n * @performance Bounded spacing optimization preserves the settled algorithm instead of repeatedly running it.\n */\nfunction requestOptimizedFit(state: GraphRuntimeState, options: GraphViewFitOptions) {\n if (state.cy.destroyed()) return;\n if (state.layoutRunningRef.current) {\n state.fitRequestRef.current = options;\n return;\n }\n const input = state.latestUpdateRef.current;\n if (!input) return;\n const previous = state.optimizedSpacingRef.current ?? input.spacingFactor ?? 1;\n const spacing = compactGraphSpacing(state.cy, previous);\n state.geometryRef.current = getGraphGeometryKey(state.cy);\n state.loopSizer.update();\n state.viewport.settle(false);\n state.controller.fit({ ...options, optimizeSpacing: false });\n if (spacing !== previous) {\n state.optimizedSpacingRef.current = spacing;\n state.callbacksRef.current.onSpacingFactorChange?.(spacing);\n }\n emitRenderedNodes(state);\n}\n\n/*** Stop the current layout and invalidate every stale completion callback. */\nfunction stopCurrentLayout(state: GraphRuntimeState) {\n state.generationRef.current += 1;\n state.layoutRunningRef.current = false;\n state.layoutRef.current?.stop();\n state.layoutRef.current = null;\n}\n\n/*** Apply consumer styles and hide native node paint only when React rich nodes are active. */\nfunction applyGraphStyles(\n cy: Core,\n rules: readonly GraphViewStyleRule[] | undefined,\n richNodeRendering: boolean,\n) {\n const styles = [...(rules ?? [])];\n if (richNodeRendering) {\n styles.push({\n selector: 'node',\n style: {\n 'background-opacity': 0,\n 'border-width': 0,\n label: '',\n 'overlay-opacity': 0,\n },\n });\n }\n if (styles.length > 0) cy.style(styles).update();\n}\n\n/***\n * Synchronize controlled selection without rerunning layout.\n * @performance Selection updates must not trigger graph reconstruction or layout.\n */\nfunction setSelectedNodeIds(state: GraphRuntimeState, nodeIds: readonly string[] | undefined) {\n if (state.cy.destroyed() || nodeIds === undefined) return;\n const selectedIds = new Set(nodeIds);\n state.cy.nodes().forEach((node) => {\n if (selectedIds.has(node.id())) node.select();\n else node.unselect();\n });\n emitRenderedNodes(state);\n}\n\n/***\n * Persist one rich-node size and schedule at most one relayout for changed geometry.\n * @performance Ignore unchanged measurements before scheduling layout work.\n */\nfunction setNodeSize(state: GraphRuntimeState, id: string, size: GraphViewSize) {\n const previous = state.nodeSizes.get(id);\n if (previous?.width === size.width && previous.height === size.height) return;\n state.nodeSizes.set(id, size);\n applyNodeSize(state.cy, id, size);\n scheduleMeasuredNodeRelayout(state);\n}\n\n/*** Apply every known rich-node size after Cytoscape elements are replaced. */\nfunction applyKnownNodeSizes(state: GraphRuntimeState) {\n for (const [id, size] of state.nodeSizes) applyNodeSize(state.cy, id, size);\n}\n\n/*** Apply one measured model-space size as a Cytoscape per-node style bypass. */\nfunction applyNodeSize(cy: Core, id: string, size: GraphViewSize) {\n const node = cy.getElementById(id);\n if (node.empty()) return;\n node.style({ height: size.height, width: size.width });\n}\n\n/***\n * Coalesce DOM measurements into one follow-up layout generation.\n * @performance Keep one scheduled layout per frame instead of one per measured node.\n */\nfunction scheduleMeasuredNodeRelayout(state: GraphRuntimeState) {\n if (state.relayoutScheduledRef.current) return;\n state.relayoutScheduledRef.current = true;\n scheduleGraphFrame(() => {\n state.relayoutScheduledRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null || state.cy.destroyed()) return;\n stopCurrentLayout(state);\n startCurrentLayout(state, input);\n });\n}\n\n/*** Subscribe one React overlay to rendered node state without exposing the Cytoscape core. */\nfunction subscribeRenderedNodes(state: GraphRuntimeState, listener: RenderedNodeListener) {\n state.renderedNodeListeners.add(listener);\n listener(readGraphRenderedNodes(state.cy, state.hoveredNodeIds));\n return () => {\n state.renderedNodeListeners.delete(listener);\n };\n}\n\n/***\n * Publish current rendered node positions only to active rich-node subscribers.\n * @performance Skip snapshot preparation when no overlay is subscribed.\n */\nfunction emitRenderedNodes(\n state: Pick<GraphRuntimeState, 'cy' | 'hoveredNodeIds' | 'renderedNodeListeners'>,\n) {\n if (state.renderedNodeListeners.size === 0) return;\n const nodes = readGraphRenderedNodes(state.cy, state.hoveredNodeIds);\n for (const listener of state.renderedNodeListeners) listener(nodes);\n}\n\n/*** Translate one rich-overlay event back into normal graph selection and callbacks. */\nfunction handleOverlayNodeEvent(\n state: GraphRuntimeState,\n id: string,\n type: GraphViewElementEventType,\n) {\n if (type === 'pointer-enter') state.hoveredNodeIds.add(id);\n if (type === 'pointer-leave') state.hoveredNodeIds.delete(id);\n if (type === 'press') state.cy.getElementById(id).select();\n state.callbacksRef.current.onNodeEvent?.({ id, type });\n emitRenderedNodes(state);\n}\n\n/*** Return whether Cytoscape currently has dimensions suitable for fitting. */\nfunction hasUsableViewport(cy: Core): boolean {\n return cy.width() > 0 && cy.height() > 0;\n}\n\n/*** Dispose all runtime resources in the reverse order they were acquired. */\nfunction destroyRuntime(state: GraphRuntimeState) {\n state.resizeObserver?.disconnect();\n stopCurrentLayout(state);\n state.unbindEvents();\n state.renderedNodeListeners.clear();\n if (!state.cy.destroyed()) state.cy.destroy();\n}\n\nregisterGraphLayouts();\n"]}
1
+ {"version":3,"file":"createGraphRuntime.js","sourceRoot":"","sources":["../../../../../../src/features/graph-view/adapters/inbound/web-artifact/createGraphRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAoC,MAAM,WAAW,CAAC;AAGxE,OAAO,EAAE,eAAe,EAAE,M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;QAAE,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC9D,IAAI,IAAI,KAAK,OAAO;QAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;IAC3D,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,+EAA+E;AAC/E,SAAS,iBAAiB,CAAC,EAAQ;IACjC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED,8EAA8E;AAC9E,SAAS,cAAc,CAAC,KAAwB;IAC9C,KAAK,CAAC,cAAc,EAAE,UAAU,EAAE,CAAC;IACnC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACzB,KAAK,CAAC,YAAY,EAAE,CAAC;IACrB,KAAK,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE;QAAE,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;AAChD,CAAC;AAED,oBAAoB,EAAE,CAAC","sourcesContent":["import cytoscape, { type Core, type CytoscapeOptions } from 'cytoscape';\n\nimport type { GraphRuntimeUpdate } from '../../../../../types/graphViewRuntime';\nimport { bindGraphEvents } from './bindGraphEvents';\nimport { compactGraphSpacing } from './compactGraphSpacing';\nimport { createGraphController } from './createGraphController';\nimport { createGraphLoopSizer } from './createGraphLoopSizer';\nimport { createGraphResizeObserver, type GraphResizeObserver } from './createGraphResizeObserver';\nimport { getGraphGeometryKey } from './getGraphGeometryKey';\nimport { getGraphTopologyKey } from './getGraphTopologyKey';\nimport type {\n GraphViewCallbacks,\n GraphViewElementEventType,\n GraphViewFitOptions,\n GraphViewRenderedNode,\n GraphViewSize,\n GraphViewStyleRule,\n} from './GraphView';\nimport { hasGraphLayoutChanged } from './hasGraphLayoutChanged';\nimport { readGraphRenderedNodes } from './readGraphRenderedNodes';\nimport { registerGraphLayouts } from './registerGraphLayouts';\nimport { runGraphLayout } from './runGraphLayout';\nimport { scheduleGraphFrame } from './scheduleGraphFrame';\nimport { shouldFitGraphAfterLayout } from './shouldFitGraphAfterLayout';\nimport { sizeGraphNodesToLabels } from './sizeGraphNodesToLabels';\nimport { syncGraphElements } from './syncGraphElements';\n\ntype GraphContainer = CytoscapeOptions['container'];\ntype RenderedNodeListener = (nodes: readonly GraphViewRenderedNode[]) => void;\n\nexport interface GraphRuntime {\n destroy(): void;\n handleOverlayNodeEvent(id: string, type: GraphViewElementEventType): void;\n setNodeSize(id: string, size: GraphViewSize): void;\n setSelectedNodeIds(nodeIds: readonly string[] | undefined): void;\n subscribeRenderedNodes(listener: RenderedNodeListener): () => void;\n update(input: GraphRuntimeUpdate): void;\n}\n\ninterface GraphRuntimeState {\n readonly fitRequestRef: { current: GraphViewFitOptions | null };\n readonly optimizedSpacingRef: { current: number | null };\n readonly callbacksRef: { current: GraphViewCallbacks };\n readonly controller: ReturnType<typeof createGraphController>['controller'];\n readonly viewport: ReturnType<typeof createGraphController>;\n readonly cy: Core;\n readonly fitPaddingRef: { current: number };\n readonly generationRef: { current: number };\n readonly geometryRef: { current: string | null };\n readonly hoveredNodeIds: Set<string>;\n readonly latestUpdateRef: { current: GraphRuntimeUpdate | null };\n readonly layoutRef: { current: ReturnType<typeof runGraphLayout> | null };\n readonly layoutRunningRef: { current: boolean };\n readonly nodeSizes: Map<string, GraphViewSize>;\n readonly labelSizedNodeIds: Set<string>;\n readonly loopSizer: ReturnType<typeof createGraphLoopSizer>;\n readonly pendingInitialFitRef: { current: boolean };\n readonly readyRef: { current: boolean };\n readonly settledTopologyRef: { current: string | null };\n readonly relayoutScheduledRef: { current: boolean };\n readonly renderedNodeListeners: Set<RenderedNodeListener>;\n readonly resizeObserver: GraphResizeObserver | null;\n readonly unbindEvents: () => void;\n}\n\n/*** Create one Cytoscape runtime that exclusively owns layout, fit, resize, and disposal. */\nexport function createGraphRuntime(\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n): GraphRuntime {\n const cy = cytoscape({\n container,\n elements: [],\n minZoom: 0.05,\n maxZoom: 2,\n selectionType: 'additive',\n userPanningEnabled: true,\n });\n const state = createRuntimeState(cy, container, callbacksRef);\n\n return {\n destroy: () => destroyRuntime(state),\n handleOverlayNodeEvent: (id, type) => handleOverlayNodeEvent(state, id, type),\n setNodeSize: (id, size) => setNodeSize(state, id, size),\n setSelectedNodeIds: (nodeIds) => setSelectedNodeIds(state, nodeIds),\n subscribeRenderedNodes: (listener) => subscribeRenderedNodes(state, listener),\n update: (input) => updateRuntime(state, input),\n };\n}\n\n/*** Build the mutable state shared by the single graph-runtime owner. */\nfunction createRuntimeState(\n cy: Core,\n container: GraphContainer,\n callbacksRef: { current: GraphViewCallbacks },\n): GraphRuntimeState {\n const fitPaddingRef = { current: 50 };\n const viewport = createGraphController(cy, fitPaddingRef, (options) =>\n requestOptimizedFit(state, options),\n );\n const { controller } = viewport;\n const layoutRunningRef = { current: false };\n const readyRef = { current: false };\n const renderedNodeListeners = new Set<RenderedNodeListener>();\n const stateBase = {\n fitRequestRef: { current: null as GraphViewFitOptions | null },\n optimizedSpacingRef: { current: null as number | null },\n callbacksRef,\n controller,\n viewport,\n cy,\n fitPaddingRef,\n generationRef: { current: 0 },\n geometryRef: { current: null as string | null },\n hoveredNodeIds: new Set<string>(),\n latestUpdateRef: { current: null as GraphRuntimeUpdate | null },\n layoutRef: { current: null as ReturnType<typeof runGraphLayout> | null },\n layoutRunningRef,\n nodeSizes: new Map<string, GraphViewSize>(),\n labelSizedNodeIds: new Set<string>(),\n loopSizer: createGraphLoopSizer(cy),\n pendingInitialFitRef: { current: false },\n readyRef,\n settledTopologyRef: { current: null as string | null },\n relayoutScheduledRef: { current: false },\n renderedNodeListeners,\n };\n const unbindEvents = bindGraphEvents(cy, callbacksRef, controller, () =>\n emitRenderedNodes(stateBase),\n );\n const resizeObserver = createGraphResizeObserver({\n container,\n cy,\n settleViewport: () => viewport.settle(true),\n layoutRunningRef,\n pendingInitialFitRef: stateBase.pendingInitialFitRef,\n onViewportSettled: (completedPendingInitialFit) => {\n emitRenderedNodes(stateBase);\n if (!completedPendingInitialFit || readyRef.current) return;\n readyRef.current = true;\n callbacksRef.current.onReady?.(controller);\n callbacksRef.current.onLayoutComplete?.(controller);\n },\n readyRef,\n });\n\n const state = { ...stateBase, resizeObserver, unbindEvents };\n return state;\n}\n\n/***\n * Reconcile presentation in place and relayout only when graph geometry or layout policy changes.\n * @performance Batch reconciliation and skip layout for presentation-only updates.\n */\nfunction updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n if (state.cy.destroyed()) return;\n const last = state.latestUpdateRef.current;\n const acceptsSpacing =\n state.optimizedSpacingRef.current !== null &&\n state.optimizedSpacingRef.current === input.spacingFactor;\n const previous = acceptsSpacing && last ? { ...last, spacingFactor: input.spacingFactor } : last;\n if (acceptsSpacing) state.optimizedSpacingRef.current = null;\n state.latestUpdateRef.current = input;\n state.fitPaddingRef.current = input.fitPadding ?? 50;\n state.viewport.configure(input);\n state.cy.batch(() => {\n if (previous?.nodes !== input.nodes || previous.edges !== input.edges) {\n syncGraphElements(state.cy, input.nodes, input.edges);\n }\n if (\n previous?.styleRules !== input.styleRules ||\n previous?.richNodeRendering !== input.richNodeRendering\n ) {\n state.loopSizer.reset();\n applyGraphStyles(state.cy, input.styleRules, input.richNodeRendering);\n }\n });\n sizeGraphNodesToLabels(\n state.cy,\n state.labelSizedNodeIds,\n input.sizeNodesToLabels === true && !input.richNodeRendering,\n );\n applyKnownNodeSizes(state);\n state.loopSizer.update();\n const geometry = getGraphGeometryKey(state.cy);\n const relayout = geometry !== state.geometryRef.current || hasGraphLayoutChanged(previous, input);\n state.geometryRef.current = geometry;\n if (!relayout) {\n if (\n previous?.zoomMode !== input.zoomMode ||\n previous?.fitPadding !== input.fitPadding ||\n previous?.minZoom !== input.minZoom ||\n previous?.maxZoom !== input.maxZoom ||\n previous?.minReadableLabelSize !== input.minReadableLabelSize ||\n previous?.maxFitLabelSize !== input.maxFitLabelSize\n ) {\n state.viewport.settle(previous?.zoomMode !== input.zoomMode);\n }\n emitRenderedNodes(state);\n if (!state.layoutRunningRef.current && !state.pendingInitialFitRef.current)\n state.callbacksRef.current.onLayoutComplete?.(state.controller);\n return;\n }\n stopCurrentLayout(state);\n state.fitRequestRef.current = null;\n state.optimizedSpacingRef.current = null;\n startCurrentLayout(state, input);\n}\n\n/*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */\nfunction startCurrentLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {\n state.pendingInitialFitRef.current = false;\n const generation = state.generationRef.current + 1;\n state.generationRef.current = generation;\n state.layoutRunningRef.current = true;\n state.cy.resize();\n state.layoutRef.current = runGraphLayout(\n state.cy,\n {\n layout: input.layout ?? 'concentric',\n layoutOptions: input.layoutOptions,\n spacingFactor: input.spacingFactor ?? 1,\n },\n () => completeCurrentLayout(state, generation),\n );\n}\n\n/***\n * Settle only the latest layout generation and fit once from node bounds.\n * @performance Discard stale completions and avoid repeated automatic fits.\n */\nfunction completeCurrentLayout(state: GraphRuntimeState, generation: number) {\n scheduleGraphFrame(() => {\n if (state.cy.destroyed() || generation !== state.generationRef.current) return;\n state.loopSizer.update();\n state.layoutRef.current = null;\n state.cy.resize();\n state.layoutRunningRef.current = false;\n if (!hasUsableViewport(state.cy)) {\n if (!state.readyRef.current) state.pendingInitialFitRef.current = true;\n return;\n }\n state.pendingInitialFitRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null) return;\n const topology = getGraphTopologyKey(input.nodes, input.edges);\n const shouldFit = shouldFitGraphAfterLayout(\n state.readyRef.current,\n topology !== state.settledTopologyRef.current,\n );\n state.viewport.settle(shouldFit);\n state.settledTopologyRef.current = topology;\n const fitRequest = state.fitRequestRef.current;\n state.fitRequestRef.current = null;\n if (fitRequest) requestOptimizedFit(state, fitRequest);\n emitRenderedNodes(state);\n\n if (!state.readyRef.current) {\n state.readyRef.current = true;\n state.callbacksRef.current.onReady?.(state.controller);\n }\n state.callbacksRef.current.onLayoutComplete?.(state.controller);\n });\n}\n\n/***\n * Handle explicit readable-fit intent in the runtime owner, never from zoom or React effects.\n * @performance Bounded spacing optimization preserves the settled algorithm instead of repeatedly running it.\n */\nfunction requestOptimizedFit(state: GraphRuntimeState, options: GraphViewFitOptions) {\n if (state.cy.destroyed()) return;\n if (state.layoutRunningRef.current) {\n state.fitRequestRef.current = options;\n return;\n }\n const input = state.latestUpdateRef.current;\n if (!input) return;\n const previous = state.optimizedSpacingRef.current ?? input.spacingFactor ?? 1;\n const spacing = compactGraphSpacing(state.cy, previous);\n state.geometryRef.current = getGraphGeometryKey(state.cy);\n state.loopSizer.update();\n state.viewport.settle(false);\n state.controller.fit({ ...options, optimizeSpacing: false });\n if (spacing !== previous) {\n state.optimizedSpacingRef.current = spacing;\n state.callbacksRef.current.onSpacingFactorChange?.(spacing);\n }\n emitRenderedNodes(state);\n}\n\n/*** Stop the current layout and invalidate every stale completion callback. */\nfunction stopCurrentLayout(state: GraphRuntimeState) {\n state.generationRef.current += 1;\n state.layoutRunningRef.current = false;\n state.layoutRef.current?.stop();\n state.layoutRef.current = null;\n}\n\n/*** Apply consumer styles and hide native node paint only when React rich nodes are active. */\nfunction applyGraphStyles(\n cy: Core,\n rules: readonly GraphViewStyleRule[] | undefined,\n richNodeRendering: boolean,\n) {\n const styles = [...(rules ?? [])];\n if (richNodeRendering) {\n styles.push({\n selector: 'node',\n style: {\n 'background-opacity': 0,\n 'border-width': 0,\n label: '',\n 'overlay-opacity': 0,\n },\n });\n }\n if (styles.length > 0) cy.style(styles).update();\n}\n\n/***\n * Synchronize controlled selection without rerunning layout.\n * @performance Selection updates must not trigger graph reconstruction or layout.\n */\nfunction setSelectedNodeIds(state: GraphRuntimeState, nodeIds: readonly string[] | undefined) {\n if (state.cy.destroyed() || nodeIds === undefined) return;\n const selectedIds = new Set(nodeIds);\n state.cy.nodes().forEach((node) => {\n if (selectedIds.has(node.id())) node.select();\n else node.unselect();\n });\n emitRenderedNodes(state);\n}\n\n/***\n * Persist one rich-node size and schedule at most one relayout for changed geometry.\n * @performance Ignore unchanged measurements before scheduling layout work.\n */\nfunction setNodeSize(state: GraphRuntimeState, id: string, size: GraphViewSize) {\n const previous = state.nodeSizes.get(id);\n if (previous?.width === size.width && previous.height === size.height) return;\n state.nodeSizes.set(id, size);\n applyNodeSize(state.cy, id, size);\n scheduleMeasuredNodeRelayout(state);\n}\n\n/*** Apply every known rich-node size after Cytoscape elements are replaced. */\nfunction applyKnownNodeSizes(state: GraphRuntimeState) {\n for (const [id, size] of state.nodeSizes) applyNodeSize(state.cy, id, size);\n}\n\n/*** Apply one measured model-space size as a Cytoscape per-node style bypass. */\nfunction applyNodeSize(cy: Core, id: string, size: GraphViewSize) {\n const node = cy.getElementById(id);\n if (node.empty()) return;\n node.style({ height: size.height, width: size.width });\n}\n\n/***\n * Coalesce DOM measurements into one follow-up layout generation.\n * @performance Keep one scheduled layout per frame instead of one per measured node.\n */\nfunction scheduleMeasuredNodeRelayout(state: GraphRuntimeState) {\n if (state.relayoutScheduledRef.current) return;\n state.relayoutScheduledRef.current = true;\n scheduleGraphFrame(() => {\n state.relayoutScheduledRef.current = false;\n const input = state.latestUpdateRef.current;\n if (input === null || state.cy.destroyed()) return;\n stopCurrentLayout(state);\n startCurrentLayout(state, input);\n });\n}\n\n/*** Subscribe one React overlay to rendered node state without exposing the Cytoscape core. */\nfunction subscribeRenderedNodes(state: GraphRuntimeState, listener: RenderedNodeListener) {\n state.renderedNodeListeners.add(listener);\n listener(readGraphRenderedNodes(state.cy, state.hoveredNodeIds));\n return () => {\n state.renderedNodeListeners.delete(listener);\n };\n}\n\n/***\n * Publish current rendered node positions only to active rich-node subscribers.\n * @performance Skip snapshot preparation when no overlay is subscribed.\n */\nfunction emitRenderedNodes(\n state: Pick<GraphRuntimeState, 'cy' | 'hoveredNodeIds' | 'renderedNodeListeners'>,\n) {\n if (state.renderedNodeListeners.size === 0) return;\n const nodes = readGraphRenderedNodes(state.cy, state.hoveredNodeIds);\n for (const listener of state.renderedNodeListeners) listener(nodes);\n}\n\n/*** Translate one rich-overlay event back into normal graph selection and callbacks. */\nfunction handleOverlayNodeEvent(\n state: GraphRuntimeState,\n id: string,\n type: GraphViewElementEventType,\n) {\n if (type === 'pointer-enter') state.hoveredNodeIds.add(id);\n if (type === 'pointer-leave') state.hoveredNodeIds.delete(id);\n if (type === 'press') state.cy.getElementById(id).select();\n state.callbacksRef.current.onNodeEvent?.({ id, type });\n emitRenderedNodes(state);\n}\n\n/*** Return whether Cytoscape currently has dimensions suitable for fitting. */\nfunction hasUsableViewport(cy: Core): boolean {\n return cy.width() > 0 && cy.height() > 0;\n}\n\n/*** Dispose all runtime resources in the reverse order they were acquired. */\nfunction destroyRuntime(state: GraphRuntimeState) {\n state.resizeObserver?.disconnect();\n stopCurrentLayout(state);\n state.unbindEvents();\n state.renderedNodeListeners.clear();\n if (!state.cy.destroyed()) state.cy.destroy();\n}\n\nregisterGraphLayouts();\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ankhorage/zora",
3
3
  "type": "module",
4
- "version": "21.0.12",
4
+ "version": "21.0.13",
5
5
  "description": "Opinionated React Native and React Native Web UI kit built on @ankhorage/surface.",
6
6
  "homepage": "https://github.com/ankhorage/zora#readme",
7
7
  "bugs": {
@@ -0,0 +1,99 @@
1
+ import { expect, test } from 'bun:test';
2
+ import type { Core } from 'cytoscape';
3
+
4
+ import { createGraphResizeObserver } from './createGraphResizeObserver';
5
+
6
+ test('settles a pending initial fit only after the viewport becomes usable', () => {
7
+ interface ResizeEntry {
8
+ readonly contentRect: { readonly height: number; readonly width: number };
9
+ }
10
+ type ResizeCallback = (entries: readonly ResizeEntry[]) => void;
11
+
12
+ const globals = globalThis as unknown as {
13
+ ResizeObserver?: unknown;
14
+ requestAnimationFrame?: (callback: () => void) => number;
15
+ };
16
+ const previousObserver = globals.ResizeObserver;
17
+ const previousFrame = globals.requestAnimationFrame;
18
+ let callback: ResizeCallback | null = null;
19
+ let width = 0;
20
+ let height = 0;
21
+ const calls = { resize: 0, settle: 0, completedPending: [] as boolean[] };
22
+ const observerCalls = { disconnect: 0, observe: 0 };
23
+
24
+ class FakeResizeObserver {
25
+ constructor(next: ResizeCallback) {
26
+ callback = next;
27
+ }
28
+
29
+ observe() {
30
+ observerCalls.observe += 1;
31
+ }
32
+
33
+ disconnect() {
34
+ observerCalls.disconnect += 1;
35
+ }
36
+ }
37
+
38
+ globals.ResizeObserver = FakeResizeObserver;
39
+ globals.requestAnimationFrame = (scheduled) => {
40
+ scheduled();
41
+ return 1;
42
+ };
43
+
44
+ const cy = {
45
+ destroyed: () => false,
46
+ height: () => height,
47
+ resize: () => {
48
+ calls.resize += 1;
49
+ },
50
+ width: () => width,
51
+ } as unknown as Core;
52
+ const pendingInitialFitRef = { current: false };
53
+ const readyRef = { current: false };
54
+ const layoutRunningRef = { current: false };
55
+
56
+ try {
57
+ const observer = createGraphResizeObserver({
58
+ container: {},
59
+ cy,
60
+ settleViewport: () => {
61
+ calls.settle += 1;
62
+ },
63
+ layoutRunningRef,
64
+ pendingInitialFitRef,
65
+ readyRef,
66
+ onViewportSettled: (completedPendingInitialFit) => {
67
+ calls.completedPending.push(completedPendingInitialFit);
68
+ },
69
+ });
70
+ expect(observer).not.toBeNull();
71
+ expect(observerCalls.observe).toBe(1);
72
+
73
+ callback?.([{ contentRect: { height: 0, width: 0 } }]);
74
+ expect(calls).toEqual({ resize: 0, settle: 0, completedPending: [] });
75
+
76
+ pendingInitialFitRef.current = true;
77
+ callback?.([{ contentRect: { height: 1, width: 1 } }]);
78
+ expect(calls.resize).toBe(1);
79
+ expect(calls.settle).toBe(0);
80
+ expect(pendingInitialFitRef.current).toBe(true);
81
+
82
+ width = 640;
83
+ height = 480;
84
+ callback?.([{ contentRect: { height, width } }]);
85
+
86
+ expect(calls.resize).toBe(2);
87
+ expect(calls.settle).toBe(1);
88
+ expect(calls.completedPending).toEqual([true]);
89
+ expect(pendingInitialFitRef.current).toBe(false);
90
+
91
+ observer?.disconnect();
92
+ expect(observerCalls.disconnect).toBe(1);
93
+ } finally {
94
+ if (previousObserver === undefined) delete globals.ResizeObserver;
95
+ else globals.ResizeObserver = previousObserver;
96
+ if (previousFrame === undefined) delete globals.requestAnimationFrame;
97
+ else globals.requestAnimationFrame = previousFrame;
98
+ }
99
+ });
@@ -7,8 +7,9 @@ interface CreateGraphResizeObserverInput {
7
7
  readonly cy: Core;
8
8
  readonly settleViewport: () => void;
9
9
  readonly layoutRunningRef: { current: boolean };
10
+ readonly pendingInitialFitRef: { current: boolean };
10
11
  readonly readyRef: { current: boolean };
11
- readonly onViewportSettled: () => void;
12
+ readonly onViewportSettled: (completedPendingInitialFit: boolean) => void;
12
13
  }
13
14
 
14
15
  export interface GraphResizeObserver {
@@ -28,7 +29,8 @@ export function createGraphResizeObserver(
28
29
  if (entry === undefined || !hasSizeChanged(sizeRef, entry.contentRect)) return;
29
30
  sizeRef.height = entry.contentRect.height;
30
31
  sizeRef.width = entry.contentRect.width;
31
- if (!input.readyRef.current || input.layoutRunningRef.current) return;
32
+ if (input.layoutRunningRef.current) return;
33
+ if (!input.readyRef.current && !input.pendingInitialFitRef.current) return;
32
34
  scheduleResizeFit(input);
33
35
  });
34
36
  observer.observe(input.container);
@@ -40,8 +42,11 @@ function scheduleResizeFit(input: CreateGraphResizeObserverInput) {
40
42
  scheduleGraphFrame(() => {
41
43
  if (input.cy.destroyed() || input.layoutRunningRef.current) return;
42
44
  input.cy.resize();
45
+ if (input.cy.width() <= 0 || input.cy.height() <= 0) return;
46
+ const completedPendingInitialFit = input.pendingInitialFitRef.current;
47
+ input.pendingInitialFitRef.current = false;
43
48
  input.settleViewport();
44
- input.onViewportSettled();
49
+ input.onViewportSettled(completedPendingInitialFit);
45
50
  });
46
51
  }
47
52
 
@@ -54,6 +54,7 @@ interface GraphRuntimeState {
54
54
  readonly nodeSizes: Map<string, GraphViewSize>;
55
55
  readonly labelSizedNodeIds: Set<string>;
56
56
  readonly loopSizer: ReturnType<typeof createGraphLoopSizer>;
57
+ readonly pendingInitialFitRef: { current: boolean };
57
58
  readonly readyRef: { current: boolean };
58
59
  readonly settledTopologyRef: { current: string | null };
59
60
  readonly relayoutScheduledRef: { current: boolean };
@@ -118,6 +119,7 @@ function createRuntimeState(
118
119
  nodeSizes: new Map<string, GraphViewSize>(),
119
120
  labelSizedNodeIds: new Set<string>(),
120
121
  loopSizer: createGraphLoopSizer(cy),
122
+ pendingInitialFitRef: { current: false },
121
123
  readyRef,
122
124
  settledTopologyRef: { current: null as string | null },
123
125
  relayoutScheduledRef: { current: false },
@@ -131,7 +133,14 @@ function createRuntimeState(
131
133
  cy,
132
134
  settleViewport: () => viewport.settle(true),
133
135
  layoutRunningRef,
134
- onViewportSettled: () => emitRenderedNodes(stateBase),
136
+ pendingInitialFitRef: stateBase.pendingInitialFitRef,
137
+ onViewportSettled: (completedPendingInitialFit) => {
138
+ emitRenderedNodes(stateBase);
139
+ if (!completedPendingInitialFit || readyRef.current) return;
140
+ readyRef.current = true;
141
+ callbacksRef.current.onReady?.(controller);
142
+ callbacksRef.current.onLayoutComplete?.(controller);
143
+ },
135
144
  readyRef,
136
145
  });
137
146
 
@@ -188,7 +197,7 @@ function updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {
188
197
  state.viewport.settle(previous?.zoomMode !== input.zoomMode);
189
198
  }
190
199
  emitRenderedNodes(state);
191
- if (!state.layoutRunningRef.current)
200
+ if (!state.layoutRunningRef.current && !state.pendingInitialFitRef.current)
192
201
  state.callbacksRef.current.onLayoutComplete?.(state.controller);
193
202
  return;
194
203
  }
@@ -200,6 +209,7 @@ function updateRuntime(state: GraphRuntimeState, input: GraphRuntimeUpdate) {
200
209
 
201
210
  /*** Start a generation-safe layout whose completion is the only normal automatic fit trigger. */
202
211
  function startCurrentLayout(state: GraphRuntimeState, input: GraphRuntimeUpdate) {
212
+ state.pendingInitialFitRef.current = false;
203
213
  const generation = state.generationRef.current + 1;
204
214
  state.generationRef.current = generation;
205
215
  state.layoutRunningRef.current = true;
@@ -226,7 +236,11 @@ function completeCurrentLayout(state: GraphRuntimeState, generation: number) {
226
236
  state.layoutRef.current = null;
227
237
  state.cy.resize();
228
238
  state.layoutRunningRef.current = false;
229
- if (!hasUsableViewport(state.cy)) return;
239
+ if (!hasUsableViewport(state.cy)) {
240
+ if (!state.readyRef.current) state.pendingInitialFitRef.current = true;
241
+ return;
242
+ }
243
+ state.pendingInitialFitRef.current = false;
230
244
  const input = state.latestUpdateRef.current;
231
245
  if (input === null) return;
232
246
  const topology = getGraphTopologyKey(input.nodes, input.edges);
@@ -122759,7 +122759,9 @@ function createGraphResizeObserver(input) {
122759
122759
  return;
122760
122760
  sizeRef.height = entry.contentRect.height;
122761
122761
  sizeRef.width = entry.contentRect.width;
122762
- if (!input.readyRef.current || input.layoutRunningRef.current)
122762
+ if (input.layoutRunningRef.current)
122763
+ return;
122764
+ if (!input.readyRef.current && !input.pendingInitialFitRef.current)
122763
122765
  return;
122764
122766
  scheduleResizeFit(input);
122765
122767
  });
@@ -122771,8 +122773,12 @@ function scheduleResizeFit(input) {
122771
122773
  if (input.cy.destroyed() || input.layoutRunningRef.current)
122772
122774
  return;
122773
122775
  input.cy.resize();
122776
+ if (input.cy.width() <= 0 || input.cy.height() <= 0)
122777
+ return;
122778
+ const completedPendingInitialFit = input.pendingInitialFitRef.current;
122779
+ input.pendingInitialFitRef.current = false;
122774
122780
  input.settleViewport();
122775
- input.onViewportSettled();
122781
+ input.onViewportSettled(completedPendingInitialFit);
122776
122782
  });
122777
122783
  }
122778
122784
  function hasSizeChanged(previous, next) {
@@ -123229,6 +123235,7 @@ function createRuntimeState(cy, container, callbacksRef) {
123229
123235
  nodeSizes: new Map,
123230
123236
  labelSizedNodeIds: new Set,
123231
123237
  loopSizer: createGraphLoopSizer(cy),
123238
+ pendingInitialFitRef: { current: false },
123232
123239
  readyRef,
123233
123240
  settledTopologyRef: { current: null },
123234
123241
  relayoutScheduledRef: { current: false },
@@ -123240,7 +123247,15 @@ function createRuntimeState(cy, container, callbacksRef) {
123240
123247
  cy,
123241
123248
  settleViewport: () => viewport.settle(true),
123242
123249
  layoutRunningRef,
123243
- onViewportSettled: () => emitRenderedNodes(stateBase),
123250
+ pendingInitialFitRef: stateBase.pendingInitialFitRef,
123251
+ onViewportSettled: (completedPendingInitialFit) => {
123252
+ emitRenderedNodes(stateBase);
123253
+ if (!completedPendingInitialFit || readyRef.current)
123254
+ return;
123255
+ readyRef.current = true;
123256
+ callbacksRef.current.onReady?.(controller);
123257
+ callbacksRef.current.onLayoutComplete?.(controller);
123258
+ },
123244
123259
  readyRef
123245
123260
  });
123246
123261
  const state = { ...stateBase, resizeObserver, unbindEvents };
@@ -123277,7 +123292,7 @@ function updateRuntime(state, input) {
123277
123292
  state.viewport.settle(previous?.zoomMode !== input.zoomMode);
123278
123293
  }
123279
123294
  emitRenderedNodes(state);
123280
- if (!state.layoutRunningRef.current)
123295
+ if (!state.layoutRunningRef.current && !state.pendingInitialFitRef.current)
123281
123296
  state.callbacksRef.current.onLayoutComplete?.(state.controller);
123282
123297
  return;
123283
123298
  }
@@ -123287,6 +123302,7 @@ function updateRuntime(state, input) {
123287
123302
  startCurrentLayout(state, input);
123288
123303
  }
123289
123304
  function startCurrentLayout(state, input) {
123305
+ state.pendingInitialFitRef.current = false;
123290
123306
  const generation = state.generationRef.current + 1;
123291
123307
  state.generationRef.current = generation;
123292
123308
  state.layoutRunningRef.current = true;
@@ -123305,8 +123321,12 @@ function completeCurrentLayout(state, generation) {
123305
123321
  state.layoutRef.current = null;
123306
123322
  state.cy.resize();
123307
123323
  state.layoutRunningRef.current = false;
123308
- if (!hasUsableViewport(state.cy))
123324
+ if (!hasUsableViewport(state.cy)) {
123325
+ if (!state.readyRef.current)
123326
+ state.pendingInitialFitRef.current = true;
123309
123327
  return;
123328
+ }
123329
+ state.pendingInitialFitRef.current = false;
123310
123330
  const input = state.latestUpdateRef.current;
123311
123331
  if (input === null)
123312
123332
  return;