@visualli/core 0.2.9 → 0.2.10

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.d.cts CHANGED
@@ -182,6 +182,38 @@ declare function fitView(bounds: FrameBox, width: number, height: number): {
182
182
  y: number;
183
183
  };
184
184
  };
185
+ /** Insets: room the host's chrome takes at each edge of the map (a docked Vault, a top bar, the Composer). */
186
+ type FrameInsets = {
187
+ top?: number;
188
+ right?: number;
189
+ bottom?: number;
190
+ left?: number;
191
+ };
192
+ /** The smallest free area a map is ever fitted into, however much the insets take. */
193
+ declare const FIT_ROOM: {
194
+ readonly minWidth: 200;
195
+ readonly minHeight: 160;
196
+ };
197
+ /** Fit to view inside insets. The map's canvas fills its whole frame - so the canvas itself and its chromatic immersion
198
+ * run behind the host's chrome (a docked Vault floats over the tinted canvas) - while the layer is fitted into the
199
+ * free area (the frame less the insets, never below FIT_ROOM) and centred in it. `screen`: where on the canvas the
200
+ * world `center` goes (screen = world × scale + translation); `room`: the free area's size. With no insets this is
201
+ * fitView, centred on the canvas. */
202
+ declare function fitViewInset(bounds: FrameBox, width: number, height: number, insets?: FrameInsets): {
203
+ scale: number;
204
+ center: {
205
+ x: number;
206
+ y: number;
207
+ };
208
+ screen: {
209
+ x: number;
210
+ y: number;
211
+ };
212
+ room: {
213
+ width: number;
214
+ height: number;
215
+ };
216
+ };
185
217
  /** Where the peek card sits (pointer): beside the idea — right of it if it fits, else left — and level with it. */
186
218
  declare const PEEK_PLACEMENT: {
187
219
  /** Gap between the idea's outermost ring and the card. */ readonly gap: 16;
@@ -271,10 +303,15 @@ interface ContainerGroupInfo {
271
303
  * nested-data format `{data:{label,formation}}` and the flat format `{label}`.
272
304
  */
273
305
  declare function getContainersForLayer(doc: VisualliDocument, layerId: string): ContainerGroupInfo[];
274
- /** Fit to view: centre and zoom for a layer in one call (the design system's fitView). */
306
+ /**
307
+ * Fit to view: centre and zoom for a layer in one call (the design system's fitView). With `insets` (room the host's
308
+ * chrome takes at each edge - a docked panel, a top bar, a composer), the canvas still fills its whole frame but the
309
+ * layer fits the free area and sits centred in it (the design system's fitViewInset); the viewport centre returned is
310
+ * the world point at the middle of the canvas, as the viewport store keeps it.
311
+ */
275
312
  declare function calculateFitView(nodes: FlatNode[], canvasWidth: number, canvasHeight: number, containers?: ReadonlyArray<{
276
313
  nodeIds: string[];
277
- }>): FitResult;
314
+ }>, insets?: FrameInsets): FitResult;
278
315
 
279
316
  interface CullingOptions {
280
317
  nodes: FlatNode[];
@@ -476,4 +513,4 @@ declare function ideaDetail(screenWidth: number, emphasised?: boolean): IdeaDeta
476
513
  /** Whether idea shadows are drawn with this many ideas in view. */
477
514
  declare function shadowsShown(visibleIdeas: number): boolean;
478
515
 
479
- export { type Bezier, type BoundingBox, type ContainerGroupInfo, type CullingOptions, DETAIL, EASE, FEATURE_FLAGS, FRAME, type FitResult, FlatNode, type FrameBox, GESTURE, HULL, HULL_CLEAR, type Hull, type IRenderConfigStore, type ISelectionStore, type ISpatialIndex, type IdeaDetail, type Box as LabelBox, type LabelPlacement, type LabelSide, MOTION, MindMapConnection, NodeSelection, PEEK, PEEK_PLACEMENT, type Pt, RBushSpatialIndex, RenderConfig, SHEET, TERM, TRAIL, VIEW, ViewportState, VisualliDocument, VisualliLayer, bloomOffset, calculateFitCenter, calculateFitView, calculateFitZoom, connectorDelay, connectorSamples, containerHull, cssEase, ease as easeBezier, fitView, getChildLayerForNode, getConnectionsForLayer, getContainersForLayer, getLayerForNavigation, getViewportVisibleNodes, hoverOpensTerm, ideaDetail, intersectsViewport, labelCandidates, layerBlooms, layerBounds, layerFrame, layerReveal, motionVars, peekPosition, pinchZoom, placeContainerLabel, pointerModeFor, renderConfigStore, revealDelay, revealSlot, revealTotal, selectionStore, shadowsShown, swapDelay, zoomAround };
516
+ export { type Bezier, type BoundingBox, type ContainerGroupInfo, type CullingOptions, DETAIL, EASE, FEATURE_FLAGS, FIT_ROOM, FRAME, type FitResult, FlatNode, type FrameBox, type FrameInsets, GESTURE, HULL, HULL_CLEAR, type Hull, type IRenderConfigStore, type ISelectionStore, type ISpatialIndex, type IdeaDetail, type Box as LabelBox, type LabelPlacement, type LabelSide, MOTION, MindMapConnection, NodeSelection, PEEK, PEEK_PLACEMENT, type Pt, RBushSpatialIndex, RenderConfig, SHEET, TERM, TRAIL, VIEW, ViewportState, VisualliDocument, VisualliLayer, bloomOffset, calculateFitCenter, calculateFitView, calculateFitZoom, connectorDelay, connectorSamples, containerHull, cssEase, ease as easeBezier, fitView, fitViewInset, getChildLayerForNode, getConnectionsForLayer, getContainersForLayer, getLayerForNavigation, getViewportVisibleNodes, hoverOpensTerm, ideaDetail, intersectsViewport, labelCandidates, layerBlooms, layerBounds, layerFrame, layerReveal, motionVars, peekPosition, pinchZoom, placeContainerLabel, pointerModeFor, renderConfigStore, revealDelay, revealSlot, revealTotal, selectionStore, shadowsShown, swapDelay, zoomAround };
package/dist/index.d.ts CHANGED
@@ -182,6 +182,38 @@ declare function fitView(bounds: FrameBox, width: number, height: number): {
182
182
  y: number;
183
183
  };
184
184
  };
185
+ /** Insets: room the host's chrome takes at each edge of the map (a docked Vault, a top bar, the Composer). */
186
+ type FrameInsets = {
187
+ top?: number;
188
+ right?: number;
189
+ bottom?: number;
190
+ left?: number;
191
+ };
192
+ /** The smallest free area a map is ever fitted into, however much the insets take. */
193
+ declare const FIT_ROOM: {
194
+ readonly minWidth: 200;
195
+ readonly minHeight: 160;
196
+ };
197
+ /** Fit to view inside insets. The map's canvas fills its whole frame - so the canvas itself and its chromatic immersion
198
+ * run behind the host's chrome (a docked Vault floats over the tinted canvas) - while the layer is fitted into the
199
+ * free area (the frame less the insets, never below FIT_ROOM) and centred in it. `screen`: where on the canvas the
200
+ * world `center` goes (screen = world × scale + translation); `room`: the free area's size. With no insets this is
201
+ * fitView, centred on the canvas. */
202
+ declare function fitViewInset(bounds: FrameBox, width: number, height: number, insets?: FrameInsets): {
203
+ scale: number;
204
+ center: {
205
+ x: number;
206
+ y: number;
207
+ };
208
+ screen: {
209
+ x: number;
210
+ y: number;
211
+ };
212
+ room: {
213
+ width: number;
214
+ height: number;
215
+ };
216
+ };
185
217
  /** Where the peek card sits (pointer): beside the idea — right of it if it fits, else left — and level with it. */
186
218
  declare const PEEK_PLACEMENT: {
187
219
  /** Gap between the idea's outermost ring and the card. */ readonly gap: 16;
@@ -271,10 +303,15 @@ interface ContainerGroupInfo {
271
303
  * nested-data format `{data:{label,formation}}` and the flat format `{label}`.
272
304
  */
273
305
  declare function getContainersForLayer(doc: VisualliDocument, layerId: string): ContainerGroupInfo[];
274
- /** Fit to view: centre and zoom for a layer in one call (the design system's fitView). */
306
+ /**
307
+ * Fit to view: centre and zoom for a layer in one call (the design system's fitView). With `insets` (room the host's
308
+ * chrome takes at each edge - a docked panel, a top bar, a composer), the canvas still fills its whole frame but the
309
+ * layer fits the free area and sits centred in it (the design system's fitViewInset); the viewport centre returned is
310
+ * the world point at the middle of the canvas, as the viewport store keeps it.
311
+ */
275
312
  declare function calculateFitView(nodes: FlatNode[], canvasWidth: number, canvasHeight: number, containers?: ReadonlyArray<{
276
313
  nodeIds: string[];
277
- }>): FitResult;
314
+ }>, insets?: FrameInsets): FitResult;
278
315
 
279
316
  interface CullingOptions {
280
317
  nodes: FlatNode[];
@@ -476,4 +513,4 @@ declare function ideaDetail(screenWidth: number, emphasised?: boolean): IdeaDeta
476
513
  /** Whether idea shadows are drawn with this many ideas in view. */
477
514
  declare function shadowsShown(visibleIdeas: number): boolean;
478
515
 
479
- export { type Bezier, type BoundingBox, type ContainerGroupInfo, type CullingOptions, DETAIL, EASE, FEATURE_FLAGS, FRAME, type FitResult, FlatNode, type FrameBox, GESTURE, HULL, HULL_CLEAR, type Hull, type IRenderConfigStore, type ISelectionStore, type ISpatialIndex, type IdeaDetail, type Box as LabelBox, type LabelPlacement, type LabelSide, MOTION, MindMapConnection, NodeSelection, PEEK, PEEK_PLACEMENT, type Pt, RBushSpatialIndex, RenderConfig, SHEET, TERM, TRAIL, VIEW, ViewportState, VisualliDocument, VisualliLayer, bloomOffset, calculateFitCenter, calculateFitView, calculateFitZoom, connectorDelay, connectorSamples, containerHull, cssEase, ease as easeBezier, fitView, getChildLayerForNode, getConnectionsForLayer, getContainersForLayer, getLayerForNavigation, getViewportVisibleNodes, hoverOpensTerm, ideaDetail, intersectsViewport, labelCandidates, layerBlooms, layerBounds, layerFrame, layerReveal, motionVars, peekPosition, pinchZoom, placeContainerLabel, pointerModeFor, renderConfigStore, revealDelay, revealSlot, revealTotal, selectionStore, shadowsShown, swapDelay, zoomAround };
516
+ export { type Bezier, type BoundingBox, type ContainerGroupInfo, type CullingOptions, DETAIL, EASE, FEATURE_FLAGS, FIT_ROOM, FRAME, type FitResult, FlatNode, type FrameBox, type FrameInsets, GESTURE, HULL, HULL_CLEAR, type Hull, type IRenderConfigStore, type ISelectionStore, type ISpatialIndex, type IdeaDetail, type Box as LabelBox, type LabelPlacement, type LabelSide, MOTION, MindMapConnection, NodeSelection, PEEK, PEEK_PLACEMENT, type Pt, RBushSpatialIndex, RenderConfig, SHEET, TERM, TRAIL, VIEW, ViewportState, VisualliDocument, VisualliLayer, bloomOffset, calculateFitCenter, calculateFitView, calculateFitZoom, connectorDelay, connectorSamples, containerHull, cssEase, ease as easeBezier, fitView, fitViewInset, getChildLayerForNode, getConnectionsForLayer, getContainersForLayer, getLayerForNavigation, getViewportVisibleNodes, hoverOpensTerm, ideaDetail, intersectsViewport, labelCandidates, layerBlooms, layerBounds, layerFrame, layerReveal, motionVars, peekPosition, pinchZoom, placeContainerLabel, pointerModeFor, renderConfigStore, revealDelay, revealSlot, revealTotal, selectionStore, shadowsShown, swapDelay, zoomAround };
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  setViewportCenter,
10
10
  worldToScreen,
11
11
  zoomViewport
12
- } from "./chunk-HRRGKHUD.js";
12
+ } from "./chunk-FDG2FGYG.js";
13
13
  import "./chunk-LSPDGEVE.js";
14
14
  import {
15
15
  DEFAULT_RENDER_CONFIG,
@@ -22,7 +22,7 @@ import {
22
22
  getRecommendedRenderConfig,
23
23
  getRenderConfigForQuality,
24
24
  isFeatureEnabled
25
- } from "./chunk-WKZHCJAT.js";
25
+ } from "./chunk-IBCQFSQQ.js";
26
26
  import {
27
27
  checkCollision,
28
28
  getNodeBounds,
@@ -96,7 +96,7 @@ import {
96
96
  FPSMonitor,
97
97
  MemoryMonitor,
98
98
  PerformanceProfiler
99
- } from "./chunk-AQY3VHRM.js";
99
+ } from "./chunk-DYL3RO6W.js";
100
100
  import {
101
101
  CIRCULAR_REFERENCE_MAX_DEPTH,
102
102
  CLICK_THRESHOLD,
@@ -105,6 +105,7 @@ import {
105
105
  DEFAULT_CANVAS_WIDTH,
106
106
  DOUBLE_CLICK_DELAY,
107
107
  DRAG_START_DISTANCE,
108
+ FIT_ROOM,
108
109
  FPS_CRITICAL_THRESHOLD,
109
110
  FPS_DOWNGRADE_THRESHOLD,
110
111
  FPS_SAMPLE_WINDOW,
@@ -148,14 +149,14 @@ import {
148
149
  ZOOM_MAX,
149
150
  ZOOM_MIN,
150
151
  fitView,
152
+ fitViewInset,
151
153
  hoverOpensTerm,
152
154
  layerBounds,
153
155
  peekPosition,
154
156
  pinchZoom,
155
157
  pointerModeFor,
156
158
  zoomAround
157
- } from "./chunk-6US6V2BX.js";
158
- import "./chunk-VLGR5PZX.js";
159
+ } from "./chunk-EU2VXWFX.js";
159
160
  import {
160
161
  CUSTOM,
161
162
  IMMERSION,
@@ -187,6 +188,7 @@ import {
187
188
  TOPICS,
188
189
  TYPE_STYLES
189
190
  } from "./chunk-TJF6R4WH.js";
191
+ import "./chunk-VLGR5PZX.js";
190
192
 
191
193
  // src/spatial/spatialIndex.ts
192
194
  import RBush from "rbush";
@@ -406,10 +408,14 @@ function getContainersForLayer(doc, layerId) {
406
408
  return { id: c.id, label, nodeIds: c.nodes, level: layer.level };
407
409
  });
408
410
  }
409
- function calculateFitView(nodes, canvasWidth, canvasHeight, containers = []) {
411
+ function calculateFitView(nodes, canvasWidth, canvasHeight, containers = [], insets) {
410
412
  if (nodes.length === 0) return { centerX: 0, centerY: 0, zoomLevel: 1 };
411
- const { scale, center } = fitView(layerFrame(nodes, containers), canvasWidth, canvasHeight);
412
- return { centerX: center.x, centerY: center.y, zoomLevel: scale };
413
+ if (!insets) {
414
+ const { scale: scale2, center: center2 } = fitView(layerFrame(nodes, containers), canvasWidth, canvasHeight);
415
+ return { centerX: center2.x, centerY: center2.y, zoomLevel: scale2 };
416
+ }
417
+ const { scale, center, screen } = fitViewInset(layerFrame(nodes, containers), canvasWidth, canvasHeight, insets);
418
+ return { centerX: center.x - (screen.x - canvasWidth / 2) / scale, centerY: center.y - (screen.y - canvasHeight / 2) / scale, zoomLevel: scale };
413
419
  }
414
420
 
415
421
  // src/rendering/culling.ts
@@ -633,6 +639,7 @@ export {
633
639
  EASE,
634
640
  ELLIPSE,
635
641
  FEATURE_FLAGS,
642
+ FIT_ROOM,
636
643
  FPSMonitor,
637
644
  FPS_CRITICAL_THRESHOLD,
638
645
  FPS_DOWNGRADE_THRESHOLD,
@@ -734,6 +741,7 @@ export {
734
741
  edgePath,
735
742
  fetchAndParseVisualli,
736
743
  fitView,
744
+ fitViewInset,
737
745
  flattenNodes,
738
746
  focusOnNode,
739
747
  generateSampleConfig,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/spatial/spatialIndex.ts","../../../../../node_modules/zustand/esm/vanilla.mjs","../src/stores/index.ts","../src/generated/geometry/container.ts","../src/utils/navigation.ts","../src/rendering/culling.ts","../src/generated/geometry/motion.ts","../src/generated/geometry/detail.ts"],"sourcesContent":["// ─── Spatial Index ────────────────────────────────────────────────────────────\n//\n// RBush-backed R-tree for O(log n) viewport culling queries.\n// Wraps the `rbush` library with a typed, domain-specific interface.\n\nimport RBush from 'rbush';\n\nexport interface BoundingBox {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n}\n\ninterface SpatialItem extends BoundingBox {\n nodeId: string;\n}\n\nexport interface ISpatialIndex {\n insert(nodeId: string, bounds: BoundingBox): void;\n remove(nodeId: string, bounds: BoundingBox): void;\n update(nodeId: string, oldBounds: BoundingBox, newBounds: BoundingBox): void;\n query(bounds: BoundingBox): string[];\n clear(): void;\n size(): number;\n bulkLoad(items: Array<{ nodeId: string; bounds: BoundingBox }>): void;\n}\n\n/**\n * RBush-based spatial index for efficient viewport culling.\n *\n * - Insert / remove / update: O(log n)\n * - Query: O(log n + k) where k = result count\n * - Bulk load: O(n log n) — use instead of repeated inserts for initial load\n */\nexport class RBushSpatialIndex implements ISpatialIndex {\n private tree: RBush<SpatialItem>;\n private cache: Map<string, BoundingBox>;\n\n constructor() {\n this.tree = new RBush<SpatialItem>();\n this.cache = new Map();\n }\n\n insert(nodeId: string, bounds: BoundingBox): void {\n this.tree.insert({ ...bounds, nodeId });\n this.cache.set(nodeId, bounds);\n }\n\n remove(nodeId: string, bounds: BoundingBox): void {\n this.tree.remove({ ...bounds, nodeId }, (a, b) => a.nodeId === b.nodeId);\n this.cache.delete(nodeId);\n }\n\n update(nodeId: string, oldBounds: BoundingBox, newBounds: BoundingBox): void {\n this.remove(nodeId, oldBounds);\n this.insert(nodeId, newBounds);\n }\n\n query(bounds: BoundingBox): string[] {\n return this.tree.search(bounds).map(item => item.nodeId);\n }\n\n clear(): void {\n this.tree.clear();\n this.cache.clear();\n }\n\n size(): number {\n return this.cache.size;\n }\n\n bulkLoad(items: Array<{ nodeId: string; bounds: BoundingBox }>): void {\n const rbushItems = items.map(({ nodeId, bounds }) => ({ ...bounds, nodeId }));\n this.tree.load(rbushItems);\n for (const { nodeId, bounds } of items) this.cache.set(nodeId, bounds);\n }\n\n /** Return the cached bounding box for a node (undefined if not indexed). */\n getBounds(nodeId: string): BoundingBox | undefined {\n return this.cache.get(nodeId);\n }\n}\n","const createStoreImpl = (createState) => {\n let state;\n const listeners = /* @__PURE__ */ new Set();\n const setState = (partial, replace) => {\n const nextState = typeof partial === \"function\" ? partial(state) : partial;\n if (!Object.is(nextState, state)) {\n const previousState = state;\n state = (replace != null ? replace : typeof nextState !== \"object\" || nextState === null) ? nextState : Object.assign({}, state, nextState);\n listeners.forEach((listener) => listener(state, previousState));\n }\n };\n const getState = () => state;\n const getInitialState = () => initialState;\n const subscribe = (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n const destroy = () => {\n if ((import.meta.env ? import.meta.env.MODE : void 0) !== \"production\") {\n console.warn(\n \"[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected.\"\n );\n }\n listeners.clear();\n };\n const api = { setState, getState, getInitialState, subscribe, destroy };\n const initialState = state = createState(setState, getState, api);\n return api;\n};\nconst createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;\nvar vanilla = (createState) => {\n if ((import.meta.env ? import.meta.env.MODE : void 0) !== \"production\") {\n console.warn(\n \"[DEPRECATED] Default export is deprecated. Instead use import { createStore } from 'zustand/vanilla'.\"\n );\n }\n return createStore(createState);\n};\n\nexport { createStore, vanilla as default };\n","import { createStore } from 'zustand/vanilla';\nimport type { NodeSelection, RenderConfig } from '../types/index.js';\nimport {\n DEFAULT_RENDER_CONFIG,\n getOptimalQualityLevel,\n getRenderConfigForQuality,\n isFeatureEnabled,\n FEATURE_FLAGS,\n} from '../constants/renderConfig.js';\n\n// ─── Selection Store ──────────────────────────────────────────────────────────\n\nexport interface ISelectionStore extends NodeSelection {\n select: (nodeId: string) => void;\n clear: () => void;\n toggle: (nodeId: string) => void;\n isSelected: (nodeId: string) => boolean;\n}\n\nexport const selectionStore = createStore<ISelectionStore>((set, get) => ({\n selectedId: null,\n select: (nodeId) => set({ selectedId: nodeId }),\n clear: () => set({ selectedId: null }),\n toggle: (nodeId) => set((s) => ({ selectedId: s.selectedId === nodeId ? null : nodeId })),\n isSelected: (nodeId) => get().selectedId === nodeId,\n}));\n\n// ─── Render Config Store ──────────────────────────────────────────────────────\n\nexport interface IRenderConfigStore extends RenderConfig {\n setQualityLevel: (level: RenderConfig['qualityLevel']) => void;\n setRenderMode: (mode: RenderConfig['renderMode']) => void;\n setCullingEnabled: (enabled: boolean) => void;\n autoAdjustQuality: (currentFPS: number) => void;\n autoAdjustQualityByMemory: (memoryMB: number) => void;\n resetToDefaults: () => void;\n isFeatureEnabled: (feature: keyof typeof FEATURE_FLAGS) => boolean;\n}\n\nexport const renderConfigStore = createStore<IRenderConfigStore>((set, get) => ({\n ...DEFAULT_RENDER_CONFIG,\n\n setQualityLevel: (level) => set(getRenderConfigForQuality(level)),\n setRenderMode: (mode) => set({ renderMode: mode }),\n setCullingEnabled: (enabled) => set({ cullingEnabled: enabled }),\n\n autoAdjustQuality: (fps) =>\n set((s) => {\n const q = getOptimalQualityLevel(fps, s.qualityLevel);\n return q !== s.qualityLevel ? getRenderConfigForQuality(q) : s;\n }),\n\n autoAdjustQualityByMemory: (mb) =>\n set((s) => {\n const q = mb > 500 ? 'low' : mb > 400 && s.qualityLevel === 'high' ? 'medium' : s.qualityLevel;\n return q !== s.qualityLevel ? getRenderConfigForQuality(q as RenderConfig['qualityLevel']) : s;\n }),\n\n resetToDefaults: () => set({ ...DEFAULT_RENDER_CONFIG }),\n isFeatureEnabled: (feature) => isFeatureEnabled(feature, get()),\n}));\n","// Generated from visualli.ai design-system/components/src/container.ts — do not edit here.\n/* Containers: the dashed hull around a group of ideas, and where its name goes.\n The name is a pill straddling the hull's boundary. Which point of the boundary depends on what's inside and around\n the container: the spot is chosen by scoring candidates along all four edges against the ideas, the connectors and\n the names already placed — deterministic, so every renderer (VisualMap, the spec SDK on a canvas, PDF export) puts\n it in the same place for the same file. Pure functions, no dependencies. World units (the map's coordinates). */\n\nexport type Pt = { x: number; y: number };\nexport type Box = { x0: number; y0: number; x1: number; y1: number };\nexport type Hull = Box & { radius: number };\nexport type LabelSide = 'bottom' | 'top' | 'left' | 'right';\nexport type LabelPlacement = { x: number; y: number; side: LabelSide; score: number };\n\n/** The hull reaches this far beyond its ideas' centers, and rounds its corners this much. */\nexport const HULL = { padX: 150, padY: 125, radius: 48 };\n/** Penalties: an idea or another name under the pill is never fine; a connector through it is bad; order breaks ties. */\nconst WEIGHT = { idea: 1000, label: 1000, connector: 60, preference: 1 };\n\n/** Room kept between a member's outline and the hull, for ideas larger than the base size. */\nexport const HULL_CLEAR = { x: 50, y: 51 } as const;\n\n/** The hull around a group's ideas: `padX` / `padY` beyond their centres, or more for an idea that has grown to show\n * its label (`rx` / `ry`, its half size: then its outline plus HULL_CLEAR). */\nexport function containerHull(members: ReadonlyArray<Pt & { rx?: number; ry?: number }>): Hull | null {\n if (!members.length) return null;\n let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;\n for (const m of members) {\n const px = Math.max(HULL.padX, (m.rx ?? 0) + HULL_CLEAR.x), py = Math.max(HULL.padY, (m.ry ?? 0) + HULL_CLEAR.y);\n x0 = Math.min(x0, m.x - px); x1 = Math.max(x1, m.x + px); y0 = Math.min(y0, m.y - py); y1 = Math.max(y1, m.y + py);\n }\n return { x0, x1, y0, y1, radius: HULL.radius };\n}\n\n/** Candidate spots for a w × h pill, in preference order: bottom center (the default look), top center, the thirds of\n * bottom and top, then the sides. Spots keep the whole pill on the straight part of an edge, clear of the corners. */\nexport function labelCandidates(hull: Hull, w: number, h: number): { x: number; y: number; side: LabelSide }[] {\n const { x0, x1, y0, y1, radius } = hull;\n const cx = (x0 + x1) / 2, cy = (y0 + y1) / 2;\n const minX = x0 + radius + w / 2, maxX = x1 - radius - w / 2; // horizontal room on top / bottom\n const minY = y0 + radius + h / 2, maxY = y1 - radius - h / 2; // vertical room on the sides\n const along = (lo: number, hi: number, f: number) => (lo > hi ? (lo + hi) / 2 : lo + (hi - lo) * f);\n const out: { x: number; y: number; side: LabelSide }[] = [\n { x: cx, y: y1, side: 'bottom' }, { x: cx, y: y0, side: 'top' },\n { x: along(minX, maxX, 0.2), y: y1, side: 'bottom' }, { x: along(minX, maxX, 0.8), y: y1, side: 'bottom' },\n { x: along(minX, maxX, 0.2), y: y0, side: 'top' }, { x: along(minX, maxX, 0.8), y: y0, side: 'top' },\n { x: x1, y: cy, side: 'right' }, { x: x0, y: cy, side: 'left' },\n { x: x1, y: along(minY, maxY, 0.25), side: 'right' }, { x: x1, y: along(minY, maxY, 0.75), side: 'right' },\n { x: x0, y: along(minY, maxY, 0.25), side: 'left' }, { x: x0, y: along(minY, maxY, 0.75), side: 'left' },\n ];\n // The extremes of the top / bottom edges, for wide labels on narrow hulls.\n out.push({ x: along(minX, maxX, 0), y: y1, side: 'bottom' }, { x: along(minX, maxX, 1), y: y1, side: 'bottom' },\n { x: along(minX, maxX, 0), y: y0, side: 'top' }, { x: along(minX, maxX, 1), y: y0, side: 'top' });\n return out;\n}\n\nconst overlap = (a: Box, b: Box) => Math.max(0, Math.min(a.x1, b.x1) - Math.max(a.x0, b.x0)) * Math.max(0, Math.min(a.y1, b.y1) - Math.max(a.y0, b.y0));\n\n/** Where a container's name goes. `ideas`: the boxes of every idea on the layer (outermost ring included);\n * `connectors`: points sampled along every connector; `labels`: the pills already placed on this layer.\n * `gap` keeps a little air between the pill and what it avoids. */\nexport function placeContainerLabel(hull: Hull, size: { w: number; h: number }, obstacles: { ideas: Box[]; connectors?: Pt[][]; labels?: Box[] }, gap = 10): LabelPlacement {\n const { w, h } = size;\n let best: LabelPlacement | null = null;\n labelCandidates(hull, w, h).forEach((c, i) => {\n const box = { x0: c.x - w / 2 - gap, x1: c.x + w / 2 + gap, y0: c.y - h / 2 - gap, y1: c.y + h / 2 + gap };\n const area = w * h;\n let score = i * WEIGHT.preference;\n for (const b of obstacles.ideas) score += (overlap(box, b) / area) * WEIGHT.idea;\n for (const b of obstacles.labels || []) score += (overlap(box, b) / area) * WEIGHT.label;\n for (const line of obstacles.connectors || []) if (line.some((p) => p.x > box.x0 && p.x < box.x1 && p.y > box.y0 && p.y < box.y1)) score += WEIGHT.connector;\n if (!best || score < best.score) best = { x: c.x, y: c.y, side: c.side, score };\n });\n return best!;\n}\n\n/** Points along a connector, for `connectors`: the same cubic edgePath draws (control points two-thirds of the way\n * from each end to the bowed midpoint `mid`, which edgePath returns). */\nexport function connectorSamples(a: Pt, mid: Pt, b: Pt, n = 16): Pt[] {\n const c1 = { x: a.x + (mid.x - a.x) * 0.66, y: a.y + (mid.y - a.y) * 0.66 }, c2 = { x: b.x + (mid.x - b.x) * 0.66, y: b.y + (mid.y - b.y) * 0.66 };\n return Array.from({ length: n + 1 }, (_, k) => {\n const t = k / n, u = 1 - t;\n return { x: u * u * u * a.x + 3 * u * u * t * c1.x + 3 * u * t * t * c2.x + t * t * t * b.x, y: u * u * u * a.y + 3 * u * u * t * c1.y + 3 * u * t * t * c2.y + t * t * t * b.y };\n });\n}\n","import type { VisualliDocument, VisualliLayer, FlatNode, MindMapConnection } from '../types/index.js';\nimport { fitView, layerBounds, type FrameBox } from '../generated/geometry/interaction.js';\nimport { containerHull } from '../generated/geometry/container.js';\n\n// ── Connection helpers ────────────────────────────────────────────────────────\n\n/**\n * Returns all top-level connections that originate from the given layer.\n * A \"top-level connection\" links two nodes that both live in `layerId`.\n */\nexport function getConnectionsForLayer(\n doc: VisualliDocument,\n layerId: string,\n): MindMapConnection[] {\n const layer = doc.layers.get(layerId);\n if (!layer) return [];\n // Convert schema LayerConnection to simplified mindmap MindMapConnection\n return layer.connections.map(c => ({\n from: c.from,\n to: c.to,\n level: layer.level,\n label: c.data?.label,\n style: c.data?.style === 'dashed' ? 'dashed' : 'solid',\n } satisfies MindMapConnection));\n}\n\n/**\n * Given a node in the current layer, returns the child layer (if any) that the\n * node \"owns\" — i.e. the node is the entry-point into that child layer.\n */\nexport function getChildLayerForNode(\n doc: VisualliDocument,\n nodeId: string,\n currentLayerId: string,\n): VisualliLayer | null {\n // Walk all layers looking for one whose `parentNodeId` matches\n for (const [, layer] of doc.layers) {\n if (layer.parentLayerId === currentLayerId && layer.parentNodeId === nodeId) {\n return layer;\n }\n }\n return null;\n}\n\n/**\n * \n */\nexport function getLayerForNavigation(\n doc: VisualliDocument,\n nodeId: string,\n currentLayerId: string,\n): VisualliLayer | null {\n return getChildLayerForNode(doc, nodeId, currentLayerId);\n}\n\n// ── Fit to view ───────────────────────────────────────────────────────────────\n//\n// The design system's fit (geometry/interaction.ts → layerBounds / fitView): every\n// idea at its real size with room around it, and every container hull with room for\n// its name pill; never enlarging a layer beyond VIEW.fitMax.\n\nexport interface FitResult {\n centerX: number;\n centerY: number;\n zoomLevel: number;\n}\n\n/** The box a layer is framed by: its ideas (their real sizes) and the hulls of its `containers`. */\nexport function layerFrame(nodes: ReadonlyArray<FlatNode>, containers: ReadonlyArray<{ nodeIds: string[] }> = []): FrameBox {\n const byId = new Map(nodes.map((n) => [n.id, n]));\n const hulls: FrameBox[] = [];\n for (const c of containers) {\n const hull = containerHull(c.nodeIds.flatMap((id) => { const n = byId.get(id); return n ? [{ x: n.x, y: n.y, rx: n.width / 2, ry: n.height / 2 }] : []; }));\n if (hull) hulls.push(hull);\n }\n return layerBounds(nodes.map((n) => ({ x: n.x, y: n.y, rx: n.width / 2, ry: n.height / 2 })), hulls);\n}\n\n/** The zoom that fits a layer's ideas (and container hulls) into a canvas of `canvasWidth` × `canvasHeight`. */\nexport function calculateFitZoom(nodes: FlatNode[], canvasWidth: number, canvasHeight: number, containers: ReadonlyArray<{ nodeIds: string[] }> = []): number {\n if (nodes.length === 0) return 1;\n return fitView(layerFrame(nodes, containers), canvasWidth, canvasHeight).scale;\n}\n\n/** The world point a fitted layer is centred on: the middle of its frame. */\nexport function calculateFitCenter(nodes: FlatNode[], containers: ReadonlyArray<{ nodeIds: string[] }> = []): { x: number; y: number } {\n if (nodes.length === 0) return { x: 0, y: 0 };\n const f = layerFrame(nodes, containers);\n return { x: (f.x0 + f.x1) / 2, y: (f.y0 + f.y1) / 2 };\n}\n\n// ── Container helpers ────────────────────────────────────────────────────────\n\n// Inline the container shape here to avoid a circular import with KonvaContainerLayer.\nexport interface ContainerGroupInfo {\n id: string;\n label?: string;\n nodeIds: string[];\n level: number;\n}\n\n/**\n * Returns the container groups the given layer draws, normalising both the\n * nested-data format `{data:{label,formation}}` and the flat format `{label}`.\n */\nexport function getContainersForLayer(\n doc: VisualliDocument,\n layerId: string,\n): ContainerGroupInfo[] {\n const layer = doc.layers.get(layerId);\n if (!layer) return [];\n \n // Defensive: ensure containers is an array\n const containers = layer.containers ?? [];\n if (!Array.isArray(containers)) return [];\n \n // A container whose style is 'none' groups ideas without a hull or a name (the design system draws nothing for it).\n return containers.filter(c => c.data?.style !== 'none').map(c => {\n // Schema Container has nested data.label structure\n const label = c.data?.label ?? c.id;\n return { id: c.id, label, nodeIds: c.nodes, level: layer.level };\n });\n}\n\n/** Fit to view: centre and zoom for a layer in one call (the design system's fitView). */\nexport function calculateFitView(\n nodes: FlatNode[],\n canvasWidth: number,\n canvasHeight: number,\n containers: ReadonlyArray<{ nodeIds: string[] }> = [],\n): FitResult {\n if (nodes.length === 0) return { centerX: 0, centerY: 0, zoomLevel: 1 };\n const { scale, center } = fitView(layerFrame(nodes, containers), canvasWidth, canvasHeight);\n return { centerX: center.x, centerY: center.y, zoomLevel: scale };\n}\n","import type { FlatNode, ViewportState } from '../types/index.js';\nimport { RBushSpatialIndex } from '../spatial/spatialIndex.js';\nimport { calculateViewportBounds } from '../viewport/viewportUtils.js';\nimport { nodeBounds } from './nodeGeometry.js';\n\nexport interface CullingOptions {\n nodes: FlatNode[];\n viewport: ViewportState;\n canvasWidth: number;\n canvasHeight: number;\n levelFilter?: number;\n skipCulling?: boolean;\n isDragging?: boolean;\n spatialIndex?: RBushSpatialIndex | null;\n spatialIndexThreshold?: number;\n}\n\nconst DEFAULT_SPATIAL_INDEX_THRESHOLD = 200;\n\n/**\n * True when anything drawn for the node touches the viewport. Nodes are drawn\n * CENTRED on (x, y) with rings and stroke around them, so the test uses the\n * node's real visual bounds (not a top-left rectangle).\n */\nexport function intersectsViewport(\n n: FlatNode,\n bounds: { minX: number; minY: number; maxX: number; maxY: number },\n): boolean {\n const b = nodeBounds(n);\n return b.maxX >= bounds.minX && b.minX <= bounds.maxX && b.maxY >= bounds.minY && b.minY <= bounds.maxY;\n}\n\n/**\n * Returns the subset of nodes currently visible in the viewport.\n * Framework-agnostic logic for culling and spatial indexing.\n */\nexport function getViewportVisibleNodes(options: CullingOptions): FlatNode[] {\n const {\n nodes,\n viewport,\n canvasWidth,\n canvasHeight,\n levelFilter,\n skipCulling = false,\n isDragging = false,\n spatialIndex,\n spatialIndexThreshold = DEFAULT_SPATIAL_INDEX_THRESHOLD,\n } = options;\n\n const filtered = levelFilter !== undefined\n ? nodes.filter(n => n.level === levelFilter)\n : nodes;\n\n if (filtered.length === 0) return [];\n\n // During transitions or drags show all nodes to avoid partial layer appearance\n if (skipCulling || isDragging) return filtered;\n\n const bounds = calculateViewportBounds(viewport, canvasWidth, canvasHeight);\n\n if (filtered.length < spatialIndexThreshold) {\n return filtered.filter(n => intersectsViewport(n, bounds));\n }\n\n if (spatialIndex) {\n const nodeIds = spatialIndex.query({\n minX: bounds.minX, minY: bounds.minY, maxX: bounds.maxX, maxY: bounds.maxY,\n });\n const idSet = new Set(nodeIds);\n return filtered.filter(n => idSet.has(n.id));\n }\n\n // Fallback to simple filter if no index provided but threshold exceeded\n return filtered.filter(n => intersectsViewport(n, bounds));\n}\n","// Generated from visualli.ai design-system/components/src/motion.ts — do not edit here.\n/* The canvas choreography — how a layer arrives, how you step inside and back out, how an idea answers hover.\n One source for every renderer: VisualMap drives its CSS animations from these values (as CSS variables and\n animation delays), and a canvas renderer (e.g. the spec SDK on Konva) can run the same timeline from its own loop.\n Times in ms, scales as factors, easings as cubic-bezier control points. No dependencies, so it can travel alone.\n The durations and easings equal the motion tokens (duration-*, ease-*, stagger-reveal); the build checks that. */\n\nexport type Bezier = readonly [number, number, number, number];\n\nexport const EASE = {\n /** ease-standard — UI and connector drawing. */ standard: [0.4, 0, 0.2, 1] as Bezier,\n /** ease-zoom — diving into and out of layers. */ zoom: [0.2, 0.8, 0.2, 1] as Bezier,\n /** ease-bloom — ideas arriving, with a little overshoot. */ bloom: [0.34, 1.4, 0.64, 1] as Bezier,\n};\n\nexport const MOTION = {\n /** A layer arrives: ideas bloom one by one in sibling order, center first, then connectors draw. */\n reveal: {\n /** duration-reveal: each idea's bloom. */ duration: 420,\n /** stagger-reveal: delay between consecutive ideas. */ stagger: 70,\n /** An idea starts at this scale… */ fromScale: 0.55,\n /** …and this fraction of the way from its place toward the layer's center. */ fromCenter: 0.5,\n ease: EASE.bloom,\n /** Settle time after the last bloom before the map is idle (interactive again). */ tail: 200,\n },\n /** Connectors of an arriving layer: they start once the ideas are mostly in. */\n connector: {\n /** Lead time before the first connector, on top of the ideas' stagger. */ lead: 240,\n /** Delay between consecutive connectors. */ stagger: 60,\n /** A solid connector draws from source to target; a dashed one fades in instead. */ draw: 500,\n /** The connector group's fade (duration-base). */ fade: 240,\n ease: EASE.standard,\n },\n /** Step inside: the current layer zooms toward the idea and fades; the inner layer then arrives (reveal). */\n dive: {\n /** The old layer's zoom, toward the idea's position. */ scale: 3.2,\n /** duration-zoom. */ duration: 500,\n /** It fades out after this delay, over `fade`. */ fadeDelay: 150, fade: 160,\n /** The layers swap (and the reveal starts) this long after the dive starts. */ swapAfter: 320,\n ease: EASE.zoom,\n },\n /** Back out (depth trail): the current layer shrinks toward the center and fades; the outer layer arrives. */\n surface: {\n scale: 0.6, duration: 220, fade: 200,\n swapAfter: 220,\n ease: EASE.zoom,\n },\n /** The arriving layer as a whole settles from slightly small. */\n settle: { fromScale: 0.94, duration: 260, ease: EASE.standard },\n /** Hover (pointer) or select: the idea lifts; its rings turn and grow a touch — a nudge, not a wobble. */\n hover: {\n lift: 2, ringRotate: -2, ringScale: 1.015,\n /** duration-base, for both the lift (ease-bloom) and the rings (ease-standard). */ duration: 240,\n liftEase: EASE.bloom, ringEase: EASE.standard,\n },\n /** Reduced motion, or Gradual reveal off: everything appears together with a short fade; dives become cross-fades. */\n reduced: { fade: 120 },\n /** Large layers. The stagger is written for a dozen ideas; a layer of hundreds would take minutes to arrive and\n * every frame of a bloom repaints the whole layer. Above `staggerSlots` ideas (and connectors), they share that many\n * slots, so a layer never takes longer to arrive than `staggerSlots` ideas would. Above `bloomMax` ideas the layer\n * fades in together (the reduced fade) and hover lifts snap instead of easing. */\n largeLayer: { staggerSlots: 30, bloomMax: 150 },\n} as const;\n\nexport type Point = { x: number; y: number };\n\n/** Delay before idea `i` (sibling order) starts to bloom. */\nexport function revealDelay(i: number): number { return i * MOTION.reveal.stagger; }\n\n/** Delay before connector `i` starts, in a layer of `nodeCount` ideas. */\nexport function connectorDelay(i: number, nodeCount: number): number {\n return MOTION.connector.lead + nodeCount * MOTION.reveal.stagger + i * MOTION.connector.stagger;\n}\n\n/** How long a layer's arrival takes, until the map is idle again. 0 with reduced motion. */\nexport function revealTotal(nodeCount: number, reduced = false): number {\n return reduced ? 0 : MOTION.reveal.duration + nodeCount * MOTION.reveal.stagger + MOTION.reveal.tail;\n}\n\n/** Where an idea starts its bloom, as an offset from its final position: part of the way toward the layer's center. */\nexport function bloomOffset(node: Point, center: Point): Point {\n const k = MOTION.reveal.fromCenter;\n return { x: (center.x - node.x) * k, y: (center.y - node.y) * k };\n}\n\n/** When the layers swap after Step inside ('in') or Back out ('out'). 0 with reduced motion (a cross-fade). */\nexport function swapDelay(dir: 'in' | 'out', reduced = false): number {\n return reduced ? 0 : dir === 'in' ? MOTION.dive.swapAfter : MOTION.surface.swapAfter;\n}\n\n/** The stagger slot of item `i` of `count` (ideas or connectors): its own index up to `staggerSlots`, then shared. */\nexport function revealSlot(i: number, count: number): number {\n const slots = Math.min(count, MOTION.largeLayer.staggerSlots);\n return count > slots ? Math.floor((i * slots) / count) : i;\n}\n\n/** Whether a layer of `nodeCount` ideas blooms in one by one (else it fades in together and hover lifts snap). */\nexport function layerBlooms(nodeCount: number): boolean { return nodeCount <= MOTION.largeLayer.bloomMax; }\n\n/** A layer's whole arrival, large layers included: when idea `i` and connector `i` start, and when the layer is idle. */\nexport function layerReveal(nodeCount: number, connectorCount: number, reduced = false) {\n const instant = reduced || !layerBlooms(nodeCount);\n const slots = Math.min(nodeCount, MOTION.largeLayer.staggerSlots);\n const edgeSlots = Math.min(connectorCount, MOTION.largeLayer.staggerSlots);\n return {\n /** Fades in together (reduced motion, Gradual reveal off, or a layer past `bloomMax`). */ instant,\n ideaDelay: (i: number) => (instant ? 0 : revealDelay(revealSlot(i, nodeCount))),\n connectorDelay: (i: number) => (instant ? 0 : connectorDelay(revealSlot(i, connectorCount), slots)),\n /** Until the map is idle again. */\n total: instant ? (reduced ? 0 : MOTION.reduced.fade) : Math.max(revealTotal(slots), edgeSlots ? connectorDelay(edgeSlots - 1, slots) + MOTION.connector.draw : 0),\n };\n}\n\n/** CSS form of an easing. */\nexport function cssEase(e: Bezier): string { return `cubic-bezier(${e.join(', ')})`; }\n\n/** Evaluate an easing at progress t (0–1), for renderers that animate in their own loop. */\nexport function ease(e: Bezier, t: number): number {\n const [x1, y1, x2, y2] = e;\n if (t <= 0) return 0; if (t >= 1) return 1;\n const bx = (u: number) => 3 * x1 * u * (1 - u) ** 2 + 3 * x2 * u * u * (1 - u) + u ** 3;\n const by = (u: number) => 3 * y1 * u * (1 - u) ** 2 + 3 * y2 * u * u * (1 - u) + u ** 3;\n let lo = 0, hi = 1, u = t;\n for (let k = 0; k < 24; k++) { u = (lo + hi) / 2; if (bx(u) < t) lo = u; else hi = u; }\n return by(u);\n}\n\n/** The CSS variables VisualMap sets on its root, so its stylesheet animates with exactly these values. */\nexport function motionVars(): Record<string, string> {\n const m = MOTION;\n return {\n '--vi-bloom-from': String(m.reveal.fromScale),\n '--vi-line-draw': `${m.connector.draw}ms`,\n '--vi-dive-scale': String(m.dive.scale), '--vi-dive-fade': `${m.dive.fade}ms`, '--vi-dive-fade-delay': `${m.dive.fadeDelay}ms`,\n '--vi-surface-scale': String(m.surface.scale), '--vi-surface-dur': `${m.surface.duration}ms`, '--vi-surface-fade': `${m.surface.fade}ms`,\n '--vi-settle-from': String(m.settle.fromScale), '--vi-settle-dur': `${m.settle.duration}ms`,\n '--vi-reduced-fade': `${m.reduced.fade}ms`,\n '--vi-lift': `${m.hover.lift}px`, '--vi-ring-turn': `${m.hover.ringRotate}deg`, '--vi-ring-grow': String(m.hover.ringScale),\n };\n}\n","// Generated from visualli.ai design-system/components/src/detail.ts — do not edit here.\n/* Level of detail: what an idea draws at the size it's seen. Far-out views of large maps show ideas as specks; the\n rings, label and shadow of an idea a few pixels wide can't be seen, and drawing them makes large maps slow. Every\n renderer follows the same thresholds, so a map simplifies alike everywhere. Sizes are on-screen CSS pixels of the\n idea's width. No dependencies, so it can travel alone. */\n\nexport const DETAIL = {\n /** Below this on-screen width an idea draws only its body: no rings, label or shadow. */ bodyOnlyBelow: 24,\n /** Below this it may be drawn as a plain filled speck in its topic fill (no outline) — indistinguishable at this size. */ speckBelow: 12,\n /** Above this many ideas in view, idea shadows are skipped (the costliest effect to draw). */ shadowsMaxVisible: 150,\n} as const;\n\nexport type IdeaDetail = 'full' | 'body' | 'speck';\n\n/** What an idea of this on-screen width draws. A selected, focused or hovered idea always draws in full. */\nexport function ideaDetail(screenWidth: number, emphasised = false): IdeaDetail {\n if (emphasised || screenWidth >= DETAIL.bodyOnlyBelow) return 'full';\n return screenWidth < DETAIL.speckBelow ? 'speck' : 'body';\n}\n\n/** Whether idea shadows are drawn with this many ideas in view. */\nexport function shadowsShown(visibleIdeas: number): boolean { return visibleIdeas <= DETAIL.shadowsMaxVisible; }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,OAAO,WAAW;AA8BX,IAAM,oBAAN,MAAiD;AAA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C9D,SAAO,cAAc,OAAO,aAAa,UAAU;AACrD;AAGO,SAAS,aAAa,cAA+B;AAAE,SAAO,gBAAgB,OAAO;AAAmB;","names":["u"]}
1
+ {"version":3,"sources":["../src/spatial/spatialIndex.ts","../../../../../node_modules/zustand/esm/vanilla.mjs","../src/stores/index.ts","../src/generated/geometry/container.ts","../src/utils/navigation.ts","../src/rendering/culling.ts","../src/generated/geometry/motion.ts","../src/generated/geometry/detail.ts"],"sourcesContent":["// ─── Spatial Index ────────────────────────────────────────────────────────────\n//\n// RBush-backed R-tree for O(log n) viewport culling queries.\n// Wraps the `rbush` library with a typed, domain-specific interface.\n\nimport RBush from 'rbush';\n\nexport interface BoundingBox {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n}\n\ninterface SpatialItem extends BoundingBox {\n nodeId: string;\n}\n\nexport interface ISpatialIndex {\n insert(nodeId: string, bounds: BoundingBox): void;\n remove(nodeId: string, bounds: BoundingBox): void;\n update(nodeId: string, oldBounds: BoundingBox, newBounds: BoundingBox): void;\n query(bounds: BoundingBox): string[];\n clear(): void;\n size(): number;\n bulkLoad(items: Array<{ nodeId: string; bounds: BoundingBox }>): void;\n}\n\n/**\n * RBush-based spatial index for efficient viewport culling.\n *\n * - Insert / remove / update: O(log n)\n * - Query: O(log n + k) where k = result count\n * - Bulk load: O(n log n) — use instead of repeated inserts for initial load\n */\nexport class RBushSpatialIndex implements ISpatialIndex {\n private tree: RBush<SpatialItem>;\n private cache: Map<string, BoundingBox>;\n\n constructor() {\n this.tree = new RBush<SpatialItem>();\n this.cache = new Map();\n }\n\n insert(nodeId: string, bounds: BoundingBox): void {\n this.tree.insert({ ...bounds, nodeId });\n this.cache.set(nodeId, bounds);\n }\n\n remove(nodeId: string, bounds: BoundingBox): void {\n this.tree.remove({ ...bounds, nodeId }, (a, b) => a.nodeId === b.nodeId);\n this.cache.delete(nodeId);\n }\n\n update(nodeId: string, oldBounds: BoundingBox, newBounds: BoundingBox): void {\n this.remove(nodeId, oldBounds);\n this.insert(nodeId, newBounds);\n }\n\n query(bounds: BoundingBox): string[] {\n return this.tree.search(bounds).map(item => item.nodeId);\n }\n\n clear(): void {\n this.tree.clear();\n this.cache.clear();\n }\n\n size(): number {\n return this.cache.size;\n }\n\n bulkLoad(items: Array<{ nodeId: string; bounds: BoundingBox }>): void {\n const rbushItems = items.map(({ nodeId, bounds }) => ({ ...bounds, nodeId }));\n this.tree.load(rbushItems);\n for (const { nodeId, bounds } of items) this.cache.set(nodeId, bounds);\n }\n\n /** Return the cached bounding box for a node (undefined if not indexed). */\n getBounds(nodeId: string): BoundingBox | undefined {\n return this.cache.get(nodeId);\n }\n}\n","const createStoreImpl = (createState) => {\n let state;\n const listeners = /* @__PURE__ */ new Set();\n const setState = (partial, replace) => {\n const nextState = typeof partial === \"function\" ? partial(state) : partial;\n if (!Object.is(nextState, state)) {\n const previousState = state;\n state = (replace != null ? replace : typeof nextState !== \"object\" || nextState === null) ? nextState : Object.assign({}, state, nextState);\n listeners.forEach((listener) => listener(state, previousState));\n }\n };\n const getState = () => state;\n const getInitialState = () => initialState;\n const subscribe = (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n const destroy = () => {\n if ((import.meta.env ? import.meta.env.MODE : void 0) !== \"production\") {\n console.warn(\n \"[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected.\"\n );\n }\n listeners.clear();\n };\n const api = { setState, getState, getInitialState, subscribe, destroy };\n const initialState = state = createState(setState, getState, api);\n return api;\n};\nconst createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;\nvar vanilla = (createState) => {\n if ((import.meta.env ? import.meta.env.MODE : void 0) !== \"production\") {\n console.warn(\n \"[DEPRECATED] Default export is deprecated. Instead use import { createStore } from 'zustand/vanilla'.\"\n );\n }\n return createStore(createState);\n};\n\nexport { createStore, vanilla as default };\n","import { createStore } from 'zustand/vanilla';\nimport type { NodeSelection, RenderConfig } from '../types/index.js';\nimport {\n DEFAULT_RENDER_CONFIG,\n getOptimalQualityLevel,\n getRenderConfigForQuality,\n isFeatureEnabled,\n FEATURE_FLAGS,\n} from '../constants/renderConfig.js';\n\n// ─── Selection Store ──────────────────────────────────────────────────────────\n\nexport interface ISelectionStore extends NodeSelection {\n select: (nodeId: string) => void;\n clear: () => void;\n toggle: (nodeId: string) => void;\n isSelected: (nodeId: string) => boolean;\n}\n\nexport const selectionStore = createStore<ISelectionStore>((set, get) => ({\n selectedId: null,\n select: (nodeId) => set({ selectedId: nodeId }),\n clear: () => set({ selectedId: null }),\n toggle: (nodeId) => set((s) => ({ selectedId: s.selectedId === nodeId ? null : nodeId })),\n isSelected: (nodeId) => get().selectedId === nodeId,\n}));\n\n// ─── Render Config Store ──────────────────────────────────────────────────────\n\nexport interface IRenderConfigStore extends RenderConfig {\n setQualityLevel: (level: RenderConfig['qualityLevel']) => void;\n setRenderMode: (mode: RenderConfig['renderMode']) => void;\n setCullingEnabled: (enabled: boolean) => void;\n autoAdjustQuality: (currentFPS: number) => void;\n autoAdjustQualityByMemory: (memoryMB: number) => void;\n resetToDefaults: () => void;\n isFeatureEnabled: (feature: keyof typeof FEATURE_FLAGS) => boolean;\n}\n\nexport const renderConfigStore = createStore<IRenderConfigStore>((set, get) => ({\n ...DEFAULT_RENDER_CONFIG,\n\n setQualityLevel: (level) => set(getRenderConfigForQuality(level)),\n setRenderMode: (mode) => set({ renderMode: mode }),\n setCullingEnabled: (enabled) => set({ cullingEnabled: enabled }),\n\n autoAdjustQuality: (fps) =>\n set((s) => {\n const q = getOptimalQualityLevel(fps, s.qualityLevel);\n return q !== s.qualityLevel ? getRenderConfigForQuality(q) : s;\n }),\n\n autoAdjustQualityByMemory: (mb) =>\n set((s) => {\n const q = mb > 500 ? 'low' : mb > 400 && s.qualityLevel === 'high' ? 'medium' : s.qualityLevel;\n return q !== s.qualityLevel ? getRenderConfigForQuality(q as RenderConfig['qualityLevel']) : s;\n }),\n\n resetToDefaults: () => set({ ...DEFAULT_RENDER_CONFIG }),\n isFeatureEnabled: (feature) => isFeatureEnabled(feature, get()),\n}));\n","// Generated from visualli.ai design-system/components/src/container.ts — do not edit here.\n/* Containers: the dashed hull around a group of ideas, and where its name goes.\n The name is a pill straddling the hull's boundary. Which point of the boundary depends on what's inside and around\n the container: the spot is chosen by scoring candidates along all four edges against the ideas, the connectors and\n the names already placed — deterministic, so every renderer (VisualMap, the spec SDK on a canvas, PDF export) puts\n it in the same place for the same file. Pure functions, no dependencies. World units (the map's coordinates). */\n\nexport type Pt = { x: number; y: number };\nexport type Box = { x0: number; y0: number; x1: number; y1: number };\nexport type Hull = Box & { radius: number };\nexport type LabelSide = 'bottom' | 'top' | 'left' | 'right';\nexport type LabelPlacement = { x: number; y: number; side: LabelSide; score: number };\n\n/** The hull reaches this far beyond its ideas' centers, and rounds its corners this much. */\nexport const HULL = { padX: 150, padY: 125, radius: 48 };\n/** Penalties: an idea or another name under the pill is never fine; a connector through it is bad; order breaks ties. */\nconst WEIGHT = { idea: 1000, label: 1000, connector: 60, preference: 1 };\n\n/** Room kept between a member's outline and the hull, for ideas larger than the base size. */\nexport const HULL_CLEAR = { x: 50, y: 51 } as const;\n\n/** The hull around a group's ideas: `padX` / `padY` beyond their centres, or more for an idea that has grown to show\n * its label (`rx` / `ry`, its half size: then its outline plus HULL_CLEAR). */\nexport function containerHull(members: ReadonlyArray<Pt & { rx?: number; ry?: number }>): Hull | null {\n if (!members.length) return null;\n let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;\n for (const m of members) {\n const px = Math.max(HULL.padX, (m.rx ?? 0) + HULL_CLEAR.x), py = Math.max(HULL.padY, (m.ry ?? 0) + HULL_CLEAR.y);\n x0 = Math.min(x0, m.x - px); x1 = Math.max(x1, m.x + px); y0 = Math.min(y0, m.y - py); y1 = Math.max(y1, m.y + py);\n }\n return { x0, x1, y0, y1, radius: HULL.radius };\n}\n\n/** Candidate spots for a w × h pill, in preference order: bottom center (the default look), top center, the thirds of\n * bottom and top, then the sides. Spots keep the whole pill on the straight part of an edge, clear of the corners. */\nexport function labelCandidates(hull: Hull, w: number, h: number): { x: number; y: number; side: LabelSide }[] {\n const { x0, x1, y0, y1, radius } = hull;\n const cx = (x0 + x1) / 2, cy = (y0 + y1) / 2;\n const minX = x0 + radius + w / 2, maxX = x1 - radius - w / 2; // horizontal room on top / bottom\n const minY = y0 + radius + h / 2, maxY = y1 - radius - h / 2; // vertical room on the sides\n const along = (lo: number, hi: number, f: number) => (lo > hi ? (lo + hi) / 2 : lo + (hi - lo) * f);\n const out: { x: number; y: number; side: LabelSide }[] = [\n { x: cx, y: y1, side: 'bottom' }, { x: cx, y: y0, side: 'top' },\n { x: along(minX, maxX, 0.2), y: y1, side: 'bottom' }, { x: along(minX, maxX, 0.8), y: y1, side: 'bottom' },\n { x: along(minX, maxX, 0.2), y: y0, side: 'top' }, { x: along(minX, maxX, 0.8), y: y0, side: 'top' },\n { x: x1, y: cy, side: 'right' }, { x: x0, y: cy, side: 'left' },\n { x: x1, y: along(minY, maxY, 0.25), side: 'right' }, { x: x1, y: along(minY, maxY, 0.75), side: 'right' },\n { x: x0, y: along(minY, maxY, 0.25), side: 'left' }, { x: x0, y: along(minY, maxY, 0.75), side: 'left' },\n ];\n // The extremes of the top / bottom edges, for wide labels on narrow hulls.\n out.push({ x: along(minX, maxX, 0), y: y1, side: 'bottom' }, { x: along(minX, maxX, 1), y: y1, side: 'bottom' },\n { x: along(minX, maxX, 0), y: y0, side: 'top' }, { x: along(minX, maxX, 1), y: y0, side: 'top' });\n return out;\n}\n\nconst overlap = (a: Box, b: Box) => Math.max(0, Math.min(a.x1, b.x1) - Math.max(a.x0, b.x0)) * Math.max(0, Math.min(a.y1, b.y1) - Math.max(a.y0, b.y0));\n\n/** Where a container's name goes. `ideas`: the boxes of every idea on the layer (outermost ring included);\n * `connectors`: points sampled along every connector; `labels`: the pills already placed on this layer.\n * `gap` keeps a little air between the pill and what it avoids. */\nexport function placeContainerLabel(hull: Hull, size: { w: number; h: number }, obstacles: { ideas: Box[]; connectors?: Pt[][]; labels?: Box[] }, gap = 10): LabelPlacement {\n const { w, h } = size;\n let best: LabelPlacement | null = null;\n labelCandidates(hull, w, h).forEach((c, i) => {\n const box = { x0: c.x - w / 2 - gap, x1: c.x + w / 2 + gap, y0: c.y - h / 2 - gap, y1: c.y + h / 2 + gap };\n const area = w * h;\n let score = i * WEIGHT.preference;\n for (const b of obstacles.ideas) score += (overlap(box, b) / area) * WEIGHT.idea;\n for (const b of obstacles.labels || []) score += (overlap(box, b) / area) * WEIGHT.label;\n for (const line of obstacles.connectors || []) if (line.some((p) => p.x > box.x0 && p.x < box.x1 && p.y > box.y0 && p.y < box.y1)) score += WEIGHT.connector;\n if (!best || score < best.score) best = { x: c.x, y: c.y, side: c.side, score };\n });\n return best!;\n}\n\n/** Points along a connector, for `connectors`: the same cubic edgePath draws (control points two-thirds of the way\n * from each end to the bowed midpoint `mid`, which edgePath returns). */\nexport function connectorSamples(a: Pt, mid: Pt, b: Pt, n = 16): Pt[] {\n const c1 = { x: a.x + (mid.x - a.x) * 0.66, y: a.y + (mid.y - a.y) * 0.66 }, c2 = { x: b.x + (mid.x - b.x) * 0.66, y: b.y + (mid.y - b.y) * 0.66 };\n return Array.from({ length: n + 1 }, (_, k) => {\n const t = k / n, u = 1 - t;\n return { x: u * u * u * a.x + 3 * u * u * t * c1.x + 3 * u * t * t * c2.x + t * t * t * b.x, y: u * u * u * a.y + 3 * u * u * t * c1.y + 3 * u * t * t * c2.y + t * t * t * b.y };\n });\n}\n","import type { VisualliDocument, VisualliLayer, FlatNode, MindMapConnection } from '../types/index.js';\nimport { fitView, fitViewInset, layerBounds, type FrameBox, type FrameInsets } from '../generated/geometry/interaction.js';\nimport { containerHull } from '../generated/geometry/container.js';\n\n// ── Connection helpers ────────────────────────────────────────────────────────\n\n/**\n * Returns all top-level connections that originate from the given layer.\n * A \"top-level connection\" links two nodes that both live in `layerId`.\n */\nexport function getConnectionsForLayer(\n doc: VisualliDocument,\n layerId: string,\n): MindMapConnection[] {\n const layer = doc.layers.get(layerId);\n if (!layer) return [];\n // Convert schema LayerConnection to simplified mindmap MindMapConnection\n return layer.connections.map(c => ({\n from: c.from,\n to: c.to,\n level: layer.level,\n label: c.data?.label,\n style: c.data?.style === 'dashed' ? 'dashed' : 'solid',\n } satisfies MindMapConnection));\n}\n\n/**\n * Given a node in the current layer, returns the child layer (if any) that the\n * node \"owns\" — i.e. the node is the entry-point into that child layer.\n */\nexport function getChildLayerForNode(\n doc: VisualliDocument,\n nodeId: string,\n currentLayerId: string,\n): VisualliLayer | null {\n // Walk all layers looking for one whose `parentNodeId` matches\n for (const [, layer] of doc.layers) {\n if (layer.parentLayerId === currentLayerId && layer.parentNodeId === nodeId) {\n return layer;\n }\n }\n return null;\n}\n\n/**\n * \n */\nexport function getLayerForNavigation(\n doc: VisualliDocument,\n nodeId: string,\n currentLayerId: string,\n): VisualliLayer | null {\n return getChildLayerForNode(doc, nodeId, currentLayerId);\n}\n\n// ── Fit to view ───────────────────────────────────────────────────────────────\n//\n// The design system's fit (geometry/interaction.ts → layerBounds / fitView): every\n// idea at its real size with room around it, and every container hull with room for\n// its name pill; never enlarging a layer beyond VIEW.fitMax.\n\nexport interface FitResult {\n centerX: number;\n centerY: number;\n zoomLevel: number;\n}\n\n/** The box a layer is framed by: its ideas (their real sizes) and the hulls of its `containers`. */\nexport function layerFrame(nodes: ReadonlyArray<FlatNode>, containers: ReadonlyArray<{ nodeIds: string[] }> = []): FrameBox {\n const byId = new Map(nodes.map((n) => [n.id, n]));\n const hulls: FrameBox[] = [];\n for (const c of containers) {\n const hull = containerHull(c.nodeIds.flatMap((id) => { const n = byId.get(id); return n ? [{ x: n.x, y: n.y, rx: n.width / 2, ry: n.height / 2 }] : []; }));\n if (hull) hulls.push(hull);\n }\n return layerBounds(nodes.map((n) => ({ x: n.x, y: n.y, rx: n.width / 2, ry: n.height / 2 })), hulls);\n}\n\n/** The zoom that fits a layer's ideas (and container hulls) into a canvas of `canvasWidth` × `canvasHeight`. */\nexport function calculateFitZoom(nodes: FlatNode[], canvasWidth: number, canvasHeight: number, containers: ReadonlyArray<{ nodeIds: string[] }> = []): number {\n if (nodes.length === 0) return 1;\n return fitView(layerFrame(nodes, containers), canvasWidth, canvasHeight).scale;\n}\n\n/** The world point a fitted layer is centred on: the middle of its frame. */\nexport function calculateFitCenter(nodes: FlatNode[], containers: ReadonlyArray<{ nodeIds: string[] }> = []): { x: number; y: number } {\n if (nodes.length === 0) return { x: 0, y: 0 };\n const f = layerFrame(nodes, containers);\n return { x: (f.x0 + f.x1) / 2, y: (f.y0 + f.y1) / 2 };\n}\n\n// ── Container helpers ────────────────────────────────────────────────────────\n\n// Inline the container shape here to avoid a circular import with KonvaContainerLayer.\nexport interface ContainerGroupInfo {\n id: string;\n label?: string;\n nodeIds: string[];\n level: number;\n}\n\n/**\n * Returns the container groups the given layer draws, normalising both the\n * nested-data format `{data:{label,formation}}` and the flat format `{label}`.\n */\nexport function getContainersForLayer(\n doc: VisualliDocument,\n layerId: string,\n): ContainerGroupInfo[] {\n const layer = doc.layers.get(layerId);\n if (!layer) return [];\n \n // Defensive: ensure containers is an array\n const containers = layer.containers ?? [];\n if (!Array.isArray(containers)) return [];\n \n // A container whose style is 'none' groups ideas without a hull or a name (the design system draws nothing for it).\n return containers.filter(c => c.data?.style !== 'none').map(c => {\n // Schema Container has nested data.label structure\n const label = c.data?.label ?? c.id;\n return { id: c.id, label, nodeIds: c.nodes, level: layer.level };\n });\n}\n\n/**\n * Fit to view: centre and zoom for a layer in one call (the design system's fitView). With `insets` (room the host's\n * chrome takes at each edge - a docked panel, a top bar, a composer), the canvas still fills its whole frame but the\n * layer fits the free area and sits centred in it (the design system's fitViewInset); the viewport centre returned is\n * the world point at the middle of the canvas, as the viewport store keeps it.\n */\nexport function calculateFitView(\n nodes: FlatNode[],\n canvasWidth: number,\n canvasHeight: number,\n containers: ReadonlyArray<{ nodeIds: string[] }> = [],\n insets?: FrameInsets,\n): FitResult {\n if (nodes.length === 0) return { centerX: 0, centerY: 0, zoomLevel: 1 };\n if (!insets) {\n const { scale, center } = fitView(layerFrame(nodes, containers), canvasWidth, canvasHeight);\n return { centerX: center.x, centerY: center.y, zoomLevel: scale };\n }\n const { scale, center, screen } = fitViewInset(layerFrame(nodes, containers), canvasWidth, canvasHeight, insets);\n // screen = (world − centre) × scale + canvas / 2, so the frame's centre lands on `screen` (the free area's middle).\n return { centerX: center.x - (screen.x - canvasWidth / 2) / scale, centerY: center.y - (screen.y - canvasHeight / 2) / scale, zoomLevel: scale };\n}\n","import type { FlatNode, ViewportState } from '../types/index.js';\nimport { RBushSpatialIndex } from '../spatial/spatialIndex.js';\nimport { calculateViewportBounds } from '../viewport/viewportUtils.js';\nimport { nodeBounds } from './nodeGeometry.js';\n\nexport interface CullingOptions {\n nodes: FlatNode[];\n viewport: ViewportState;\n canvasWidth: number;\n canvasHeight: number;\n levelFilter?: number;\n skipCulling?: boolean;\n isDragging?: boolean;\n spatialIndex?: RBushSpatialIndex | null;\n spatialIndexThreshold?: number;\n}\n\nconst DEFAULT_SPATIAL_INDEX_THRESHOLD = 200;\n\n/**\n * True when anything drawn for the node touches the viewport. Nodes are drawn\n * CENTRED on (x, y) with rings and stroke around them, so the test uses the\n * node's real visual bounds (not a top-left rectangle).\n */\nexport function intersectsViewport(\n n: FlatNode,\n bounds: { minX: number; minY: number; maxX: number; maxY: number },\n): boolean {\n const b = nodeBounds(n);\n return b.maxX >= bounds.minX && b.minX <= bounds.maxX && b.maxY >= bounds.minY && b.minY <= bounds.maxY;\n}\n\n/**\n * Returns the subset of nodes currently visible in the viewport.\n * Framework-agnostic logic for culling and spatial indexing.\n */\nexport function getViewportVisibleNodes(options: CullingOptions): FlatNode[] {\n const {\n nodes,\n viewport,\n canvasWidth,\n canvasHeight,\n levelFilter,\n skipCulling = false,\n isDragging = false,\n spatialIndex,\n spatialIndexThreshold = DEFAULT_SPATIAL_INDEX_THRESHOLD,\n } = options;\n\n const filtered = levelFilter !== undefined\n ? nodes.filter(n => n.level === levelFilter)\n : nodes;\n\n if (filtered.length === 0) return [];\n\n // During transitions or drags show all nodes to avoid partial layer appearance\n if (skipCulling || isDragging) return filtered;\n\n const bounds = calculateViewportBounds(viewport, canvasWidth, canvasHeight);\n\n if (filtered.length < spatialIndexThreshold) {\n return filtered.filter(n => intersectsViewport(n, bounds));\n }\n\n if (spatialIndex) {\n const nodeIds = spatialIndex.query({\n minX: bounds.minX, minY: bounds.minY, maxX: bounds.maxX, maxY: bounds.maxY,\n });\n const idSet = new Set(nodeIds);\n return filtered.filter(n => idSet.has(n.id));\n }\n\n // Fallback to simple filter if no index provided but threshold exceeded\n return filtered.filter(n => intersectsViewport(n, bounds));\n}\n","// Generated from visualli.ai design-system/components/src/motion.ts — do not edit here.\n/* The canvas choreography — how a layer arrives, how you step inside and back out, how an idea answers hover.\n One source for every renderer: VisualMap drives its CSS animations from these values (as CSS variables and\n animation delays), and a canvas renderer (e.g. the spec SDK on Konva) can run the same timeline from its own loop.\n Times in ms, scales as factors, easings as cubic-bezier control points. No dependencies, so it can travel alone.\n The durations and easings equal the motion tokens (duration-*, ease-*, stagger-reveal); the build checks that. */\n\nexport type Bezier = readonly [number, number, number, number];\n\nexport const EASE = {\n /** ease-standard — UI and connector drawing. */ standard: [0.4, 0, 0.2, 1] as Bezier,\n /** ease-zoom — diving into and out of layers. */ zoom: [0.2, 0.8, 0.2, 1] as Bezier,\n /** ease-bloom — ideas arriving, with a little overshoot. */ bloom: [0.34, 1.4, 0.64, 1] as Bezier,\n};\n\nexport const MOTION = {\n /** A layer arrives: ideas bloom one by one in sibling order, center first, then connectors draw. */\n reveal: {\n /** duration-reveal: each idea's bloom. */ duration: 420,\n /** stagger-reveal: delay between consecutive ideas. */ stagger: 70,\n /** An idea starts at this scale… */ fromScale: 0.55,\n /** …and this fraction of the way from its place toward the layer's center. */ fromCenter: 0.5,\n ease: EASE.bloom,\n /** Settle time after the last bloom before the map is idle (interactive again). */ tail: 200,\n },\n /** Connectors of an arriving layer: they start once the ideas are mostly in. */\n connector: {\n /** Lead time before the first connector, on top of the ideas' stagger. */ lead: 240,\n /** Delay between consecutive connectors. */ stagger: 60,\n /** A solid connector draws from source to target; a dashed one fades in instead. */ draw: 500,\n /** The connector group's fade (duration-base). */ fade: 240,\n ease: EASE.standard,\n },\n /** Step inside: the current layer zooms toward the idea and fades; the inner layer then arrives (reveal). */\n dive: {\n /** The old layer's zoom, toward the idea's position. */ scale: 3.2,\n /** duration-zoom. */ duration: 500,\n /** It fades out after this delay, over `fade`. */ fadeDelay: 150, fade: 160,\n /** The layers swap (and the reveal starts) this long after the dive starts. */ swapAfter: 320,\n ease: EASE.zoom,\n },\n /** Back out (depth trail): the current layer shrinks toward the center and fades; the outer layer arrives. */\n surface: {\n scale: 0.6, duration: 220, fade: 200,\n swapAfter: 220,\n ease: EASE.zoom,\n },\n /** The arriving layer as a whole settles from slightly small. */\n settle: { fromScale: 0.94, duration: 260, ease: EASE.standard },\n /** Hover (pointer) or select: the idea lifts; its rings turn and grow a touch — a nudge, not a wobble. */\n hover: {\n lift: 2, ringRotate: -2, ringScale: 1.015,\n /** duration-base, for both the lift (ease-bloom) and the rings (ease-standard). */ duration: 240,\n liftEase: EASE.bloom, ringEase: EASE.standard,\n },\n /** Reduced motion, or Gradual reveal off: everything appears together with a short fade; dives become cross-fades. */\n reduced: { fade: 120 },\n /** Large layers. The stagger is written for a dozen ideas; a layer of hundreds would take minutes to arrive and\n * every frame of a bloom repaints the whole layer. Above `staggerSlots` ideas (and connectors), they share that many\n * slots, so a layer never takes longer to arrive than `staggerSlots` ideas would. Above `bloomMax` ideas the layer\n * fades in together (the reduced fade) and hover lifts snap instead of easing. */\n largeLayer: { staggerSlots: 30, bloomMax: 150 },\n} as const;\n\nexport type Point = { x: number; y: number };\n\n/** Delay before idea `i` (sibling order) starts to bloom. */\nexport function revealDelay(i: number): number { return i * MOTION.reveal.stagger; }\n\n/** Delay before connector `i` starts, in a layer of `nodeCount` ideas. */\nexport function connectorDelay(i: number, nodeCount: number): number {\n return MOTION.connector.lead + nodeCount * MOTION.reveal.stagger + i * MOTION.connector.stagger;\n}\n\n/** How long a layer's arrival takes, until the map is idle again. 0 with reduced motion. */\nexport function revealTotal(nodeCount: number, reduced = false): number {\n return reduced ? 0 : MOTION.reveal.duration + nodeCount * MOTION.reveal.stagger + MOTION.reveal.tail;\n}\n\n/** Where an idea starts its bloom, as an offset from its final position: part of the way toward the layer's center. */\nexport function bloomOffset(node: Point, center: Point): Point {\n const k = MOTION.reveal.fromCenter;\n return { x: (center.x - node.x) * k, y: (center.y - node.y) * k };\n}\n\n/** When the layers swap after Step inside ('in') or Back out ('out'). 0 with reduced motion (a cross-fade). */\nexport function swapDelay(dir: 'in' | 'out', reduced = false): number {\n return reduced ? 0 : dir === 'in' ? MOTION.dive.swapAfter : MOTION.surface.swapAfter;\n}\n\n/** The stagger slot of item `i` of `count` (ideas or connectors): its own index up to `staggerSlots`, then shared. */\nexport function revealSlot(i: number, count: number): number {\n const slots = Math.min(count, MOTION.largeLayer.staggerSlots);\n return count > slots ? Math.floor((i * slots) / count) : i;\n}\n\n/** Whether a layer of `nodeCount` ideas blooms in one by one (else it fades in together and hover lifts snap). */\nexport function layerBlooms(nodeCount: number): boolean { return nodeCount <= MOTION.largeLayer.bloomMax; }\n\n/** A layer's whole arrival, large layers included: when idea `i` and connector `i` start, and when the layer is idle. */\nexport function layerReveal(nodeCount: number, connectorCount: number, reduced = false) {\n const instant = reduced || !layerBlooms(nodeCount);\n const slots = Math.min(nodeCount, MOTION.largeLayer.staggerSlots);\n const edgeSlots = Math.min(connectorCount, MOTION.largeLayer.staggerSlots);\n return {\n /** Fades in together (reduced motion, Gradual reveal off, or a layer past `bloomMax`). */ instant,\n ideaDelay: (i: number) => (instant ? 0 : revealDelay(revealSlot(i, nodeCount))),\n connectorDelay: (i: number) => (instant ? 0 : connectorDelay(revealSlot(i, connectorCount), slots)),\n /** Until the map is idle again. */\n total: instant ? (reduced ? 0 : MOTION.reduced.fade) : Math.max(revealTotal(slots), edgeSlots ? connectorDelay(edgeSlots - 1, slots) + MOTION.connector.draw : 0),\n };\n}\n\n/** CSS form of an easing. */\nexport function cssEase(e: Bezier): string { return `cubic-bezier(${e.join(', ')})`; }\n\n/** Evaluate an easing at progress t (0–1), for renderers that animate in their own loop. */\nexport function ease(e: Bezier, t: number): number {\n const [x1, y1, x2, y2] = e;\n if (t <= 0) return 0; if (t >= 1) return 1;\n const bx = (u: number) => 3 * x1 * u * (1 - u) ** 2 + 3 * x2 * u * u * (1 - u) + u ** 3;\n const by = (u: number) => 3 * y1 * u * (1 - u) ** 2 + 3 * y2 * u * u * (1 - u) + u ** 3;\n let lo = 0, hi = 1, u = t;\n for (let k = 0; k < 24; k++) { u = (lo + hi) / 2; if (bx(u) < t) lo = u; else hi = u; }\n return by(u);\n}\n\n/** The CSS variables VisualMap sets on its root, so its stylesheet animates with exactly these values. */\nexport function motionVars(): Record<string, string> {\n const m = MOTION;\n return {\n '--vi-bloom-from': String(m.reveal.fromScale),\n '--vi-line-draw': `${m.connector.draw}ms`,\n '--vi-dive-scale': String(m.dive.scale), '--vi-dive-fade': `${m.dive.fade}ms`, '--vi-dive-fade-delay': `${m.dive.fadeDelay}ms`,\n '--vi-surface-scale': String(m.surface.scale), '--vi-surface-dur': `${m.surface.duration}ms`, '--vi-surface-fade': `${m.surface.fade}ms`,\n '--vi-settle-from': String(m.settle.fromScale), '--vi-settle-dur': `${m.settle.duration}ms`,\n '--vi-reduced-fade': `${m.reduced.fade}ms`,\n '--vi-lift': `${m.hover.lift}px`, '--vi-ring-turn': `${m.hover.ringRotate}deg`, '--vi-ring-grow': String(m.hover.ringScale),\n };\n}\n","// Generated from visualli.ai design-system/components/src/detail.ts — do not edit here.\n/* Level of detail: what an idea draws at the size it's seen. Far-out views of large maps show ideas as specks; the\n rings, label and shadow of an idea a few pixels wide can't be seen, and drawing them makes large maps slow. Every\n renderer follows the same thresholds, so a map simplifies alike everywhere. Sizes are on-screen CSS pixels of the\n idea's width. No dependencies, so it can travel alone. */\n\nexport const DETAIL = {\n /** Below this on-screen width an idea draws only its body: no rings, label or shadow. */ bodyOnlyBelow: 24,\n /** Below this it may be drawn as a plain filled speck in its topic fill (no outline) — indistinguishable at this size. */ speckBelow: 12,\n /** Above this many ideas in view, idea shadows are skipped (the costliest effect to draw). */ shadowsMaxVisible: 150,\n} as const;\n\nexport type IdeaDetail = 'full' | 'body' | 'speck';\n\n/** What an idea of this on-screen width draws. A selected, focused or hovered idea always draws in full. */\nexport function ideaDetail(screenWidth: number, emphasised = false): IdeaDetail {\n if (emphasised || screenWidth >= DETAIL.bodyOnlyBelow) return 'full';\n return screenWidth < DETAIL.speckBelow ? 'speck' : 'body';\n}\n\n/** Whether idea shadows are drawn with this many ideas in view. */\nexport function shadowsShown(visibleIdeas: number): boolean { return visibleIdeas <= DETAIL.shadowsMaxVisible; }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,OAAO,WAAW;AA8BX,IAAM,oBAAN,MAAiD;AAAA,EAItD,cAAc;AACZ,SAAK,OAAQ,IAAI,MAAmB;AACpC,SAAK,QAAQ,oBAAI,IAAI;AAAA,EACvB;AAAA,EAEA,OAAO,QAAgB,QAA2B;AAChD,SAAK,KAAK,OAAO,EAAE,GAAG,QAAQ,OAAO,CAAC;AACtC,SAAK,MAAM,IAAI,QAAQ,MAAM;AAAA,EAC/B;AAAA,EAEA,OAAO,QAAgB,QAA2B;AAChD,SAAK,KAAK,OAAO,EAAE,GAAG,QAAQ,OAAO,GAAG,CAAC,GAAG,MAAM,EAAE,WAAW,E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AO,gBAAgB,OAAO;AAAmB;","names":["scale","center","u"]}
@@ -2,8 +2,8 @@ import {
2
2
  FPSMonitor,
3
3
  MemoryMonitor,
4
4
  PerformanceProfiler
5
- } from "../chunk-AQY3VHRM.js";
6
- import "../chunk-6US6V2BX.js";
5
+ } from "../chunk-DYL3RO6W.js";
6
+ import "../chunk-EU2VXWFX.js";
7
7
  export {
8
8
  FPSMonitor,
9
9
  MemoryMonitor,
@@ -9,8 +9,8 @@ import {
9
9
  setViewportCenter,
10
10
  worldToScreen,
11
11
  zoomViewport
12
- } from "../chunk-HRRGKHUD.js";
13
- import "../chunk-6US6V2BX.js";
12
+ } from "../chunk-FDG2FGYG.js";
13
+ import "../chunk-EU2VXWFX.js";
14
14
  export {
15
15
  calculateViewportBounds,
16
16
  clampZoom,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visualli/core",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "Framework-agnostic core logic, types, and engines for Visualli",
5
5
  "repository": {
6
6
  "type": "git",
@@ -74,7 +74,7 @@
74
74
  "test": "vitest run"
75
75
  },
76
76
  "dependencies": {
77
- "@visualli/bindings": "0.2.9",
77
+ "@visualli/bindings": "0.2.10",
78
78
  "rbush": "^3.0.1"
79
79
  },
80
80
  "devDependencies": {
package/src/index.ts CHANGED
@@ -26,8 +26,8 @@ export type { Hull, Box as LabelBox, LabelPlacement, LabelSide, Pt } from './gen
26
26
  // How terms, the peek, the touch sheet, zoom, fit and the depth trail behave, and which colour an idea gets: the design
27
27
  // system's geometry/interaction.ts and geometry/color.ts, verbatim. (Idea size and label growth, geometry/idea.ts, come
28
28
  // through rendering/ideaSize.)
29
- export { TERM, PEEK, SHEET, VIEW, GESTURE, FRAME, PEEK_PLACEMENT, TRAIL, pointerModeFor, hoverOpensTerm, pinchZoom, zoomAround, layerBounds, fitView, peekPosition } from './generated/geometry/interaction.js';
30
- export type { FrameBox } from './generated/geometry/interaction.js';
29
+ export { TERM, PEEK, SHEET, VIEW, GESTURE, FRAME, PEEK_PLACEMENT, TRAIL, pointerModeFor, hoverOpensTerm, pinchZoom, zoomAround, layerBounds, fitView, fitViewInset, FIT_ROOM, peekPosition } from './generated/geometry/interaction.js';
30
+ export type { FrameBox, FrameInsets } from './generated/geometry/interaction.js';
31
31
  // Level of detail: what an idea draws at the size it's seen, and when shadows are skipped (geometry/detail.ts, verbatim).
32
32
  export { DETAIL, ideaDetail, shadowsShown } from './generated/geometry/detail.js';
33
33
  export type { IdeaDetail } from './generated/geometry/detail.js';
@@ -1,5 +1,5 @@
1
1
  import type { VisualliDocument, VisualliLayer, FlatNode, MindMapConnection } from '../types/index.js';
2
- import { fitView, layerBounds, type FrameBox } from '../generated/geometry/interaction.js';
2
+ import { fitView, fitViewInset, layerBounds, type FrameBox, type FrameInsets } from '../generated/geometry/interaction.js';
3
3
  import { containerHull } from '../generated/geometry/container.js';
4
4
 
5
5
  // ── Connection helpers ────────────────────────────────────────────────────────
@@ -122,14 +122,25 @@ export function getContainersForLayer(
122
122
  });
123
123
  }
124
124
 
125
- /** Fit to view: centre and zoom for a layer in one call (the design system's fitView). */
125
+ /**
126
+ * Fit to view: centre and zoom for a layer in one call (the design system's fitView). With `insets` (room the host's
127
+ * chrome takes at each edge - a docked panel, a top bar, a composer), the canvas still fills its whole frame but the
128
+ * layer fits the free area and sits centred in it (the design system's fitViewInset); the viewport centre returned is
129
+ * the world point at the middle of the canvas, as the viewport store keeps it.
130
+ */
126
131
  export function calculateFitView(
127
132
  nodes: FlatNode[],
128
133
  canvasWidth: number,
129
134
  canvasHeight: number,
130
135
  containers: ReadonlyArray<{ nodeIds: string[] }> = [],
136
+ insets?: FrameInsets,
131
137
  ): FitResult {
132
138
  if (nodes.length === 0) return { centerX: 0, centerY: 0, zoomLevel: 1 };
133
- const { scale, center } = fitView(layerFrame(nodes, containers), canvasWidth, canvasHeight);
134
- return { centerX: center.x, centerY: center.y, zoomLevel: scale };
139
+ if (!insets) {
140
+ const { scale, center } = fitView(layerFrame(nodes, containers), canvasWidth, canvasHeight);
141
+ return { centerX: center.x, centerY: center.y, zoomLevel: scale };
142
+ }
143
+ const { scale, center, screen } = fitViewInset(layerFrame(nodes, containers), canvasWidth, canvasHeight, insets);
144
+ // screen = (world − centre) × scale + canvas / 2, so the frame's centre lands on `screen` (the free area's middle).
145
+ return { centerX: center.x - (screen.x - canvasWidth / 2) / scale, centerY: center.y - (screen.y - canvasHeight / 2) / scale, zoomLevel: scale };
135
146
  }