@cratis/components 0.1.15 → 0.1.16

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.
Files changed (46) hide show
  1. package/dist/cjs/PivotViewer/PivotViewer.css +16 -3
  2. package/dist/cjs/PivotViewer/PivotViewer.js +34 -5
  3. package/dist/cjs/PivotViewer/PivotViewer.js.map +1 -1
  4. package/dist/cjs/PivotViewer/components/PivotCanvas.js +0 -2
  5. package/dist/cjs/PivotViewer/components/PivotCanvas.js.map +1 -1
  6. package/dist/cjs/PivotViewer/components/PivotViewerMain.js +4 -2
  7. package/dist/cjs/PivotViewer/components/PivotViewerMain.js.map +1 -1
  8. package/dist/cjs/PivotViewer/components/pivot/visibility.js +0 -20
  9. package/dist/cjs/PivotViewer/components/pivot/visibility.js.map +1 -1
  10. package/dist/cjs/PivotViewer/hooks/usePivotEngine.js +1 -31
  11. package/dist/cjs/PivotViewer/hooks/usePivotEngine.js.map +1 -1
  12. package/dist/cjs/PivotViewer/types.js.map +1 -1
  13. package/dist/cjs/PivotViewer/utils/animations.js +0 -16
  14. package/dist/cjs/PivotViewer/utils/animations.js.map +1 -1
  15. package/dist/esm/PivotViewer/PivotViewer.css +16 -3
  16. package/dist/esm/PivotViewer/PivotViewer.d.ts +1 -1
  17. package/dist/esm/PivotViewer/PivotViewer.d.ts.map +1 -1
  18. package/dist/esm/PivotViewer/PivotViewer.js +34 -5
  19. package/dist/esm/PivotViewer/PivotViewer.js.map +1 -1
  20. package/dist/esm/PivotViewer/PivotViewer.stories.d.ts.map +1 -1
  21. package/dist/esm/PivotViewer/PivotViewer.stories.js +5 -2
  22. package/dist/esm/PivotViewer/PivotViewer.stories.js.map +1 -1
  23. package/dist/esm/PivotViewer/components/PivotCanvas.d.ts.map +1 -1
  24. package/dist/esm/PivotViewer/components/PivotCanvas.js +0 -2
  25. package/dist/esm/PivotViewer/components/PivotCanvas.js.map +1 -1
  26. package/dist/esm/PivotViewer/components/PivotViewerMain.d.ts +2 -1
  27. package/dist/esm/PivotViewer/components/PivotViewerMain.d.ts.map +1 -1
  28. package/dist/esm/PivotViewer/components/PivotViewerMain.js +4 -2
  29. package/dist/esm/PivotViewer/components/PivotViewerMain.js.map +1 -1
  30. package/dist/esm/PivotViewer/components/pivot/visibility.d.ts.map +1 -1
  31. package/dist/esm/PivotViewer/components/pivot/visibility.js +0 -20
  32. package/dist/esm/PivotViewer/components/pivot/visibility.js.map +1 -1
  33. package/dist/esm/PivotViewer/engine/pivot.worker.d.ts.map +1 -1
  34. package/dist/esm/PivotViewer/engine/pivot.worker.js +0 -8
  35. package/dist/esm/PivotViewer/engine/pivot.worker.js.map +1 -1
  36. package/dist/esm/PivotViewer/hooks/usePivotEngine.d.ts.map +1 -1
  37. package/dist/esm/PivotViewer/hooks/usePivotEngine.js +1 -31
  38. package/dist/esm/PivotViewer/hooks/usePivotEngine.js.map +1 -1
  39. package/dist/esm/PivotViewer/types.d.ts +16 -0
  40. package/dist/esm/PivotViewer/types.d.ts.map +1 -1
  41. package/dist/esm/PivotViewer/types.js.map +1 -1
  42. package/dist/esm/PivotViewer/utils/animations.d.ts.map +1 -1
  43. package/dist/esm/PivotViewer/utils/animations.js +0 -16
  44. package/dist/esm/PivotViewer/utils/animations.js.map +1 -1
  45. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +1 -1
@@ -7,14 +7,6 @@ function syncSpritesToViewport(params) {
7
7
  const { root, container, sprites: sprites$1, layout, visibleIds, items, cardWidth, cardHeight, panX, panY, panDeltaX, panDeltaY, viewportWidth, viewportHeight, createCardSprite, updateCardContent, zoomLevel, isViewTransition, prevLayout } = params;
8
8
  if (!root || !container)
9
9
  return;
10
- console.log('[syncSpritesToViewport] Called with', {
11
- layoutPositionsSize: layout.positions.size,
12
- visibleIdsSize: visibleIds.length,
13
- spritesSize: sprites$1.size,
14
- itemsLength: items.length,
15
- isViewTransition,
16
- zoomLevel
17
- });
18
10
  if (isViewTransition && (panDeltaX || panDeltaY)) {
19
11
  const dx = (panDeltaX || 0) / (zoomLevel || 1);
20
12
  const dy = (panDeltaY || 0) / (zoomLevel || 1);
@@ -165,22 +157,17 @@ function syncSpritesToViewport(params) {
165
157
  }
166
158
  const MAX_SPRITES_PER_FRAME = 50;
167
159
  let createdCount = 0;
168
- console.log('[syncSpritesToViewport] About to create sprites for inViewportIds:', inViewportIds.length);
169
- console.log('[syncSpritesToViewport] layout.positions IDs:', Array.from(layout.positions.keys()));
170
160
  for (const id of inViewportIds) {
171
161
  const position = layout.positions.get(id);
172
162
  if (!position) {
173
- console.log('[syncSpritesToViewport] No position for id:', id, 'in layout.positions');
174
163
  continue;
175
164
  }
176
165
  let sprite = sprites$1.get(id);
177
166
  if (!sprite) {
178
167
  if (createdCount >= MAX_SPRITES_PER_FRAME) {
179
- console.log('[syncSpritesToViewport] Max sprites per frame reached');
180
168
  continue;
181
169
  }
182
170
  createdCount++;
183
- console.log('[syncSpritesToViewport] Creating sprite for id:', id, 'at position:', position);
184
171
  let startX = position.x;
185
172
  let startY = position.y;
186
173
  let shouldAnimate = false;
@@ -216,10 +203,6 @@ function syncSpritesToViewport(params) {
216
203
  }
217
204
  }
218
205
  if (sprite.targetX !== position.x || sprite.targetY !== position.y) {
219
- console.log('[syncSpritesToViewport] Updating sprite target position for id:', id, 'from', {
220
- oldX: sprite.targetX,
221
- oldY: sprite.targetY
222
- }, 'to', position);
223
206
  if (isViewTransition) {
224
207
  sprite.startX = sprite.currentX;
225
208
  sprite.startY = sprite.currentY;
@@ -235,9 +218,6 @@ function syncSpritesToViewport(params) {
235
218
  delete sprite.animationDelay;
236
219
  }
237
220
  }
238
- else {
239
- console.log('[syncSpritesToViewport] Sprite position unchanged for id:', id, 'at', position);
240
- }
241
221
  const item = items[Number(id)];
242
222
  if (item) {
243
223
  updateCardContent(sprite, item);
@@ -1 +1 @@
1
- {"version":3,"file":"visibility.js","sources":["../../../../../PivotViewer/components/pivot/visibility.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport * as PIXI from 'pixi.js';\nimport type { CardSprite } from './constants';\nimport { CARD_GAP } from './constants';\nimport type { LayoutResult } from '../../engine/types';\nimport { destroySprite } from './sprites';\n\nexport interface SyncParams<TItem> {\n root: PIXI.Container | null;\n container: HTMLDivElement | null;\n sprites: Map<string | number, CardSprite>;\n layout: LayoutResult;\n visibleIds: Uint32Array;\n items: TItem[];\n cardWidth: number;\n cardHeight: number;\n panX: number;\n panY: number;\n panDeltaX?: number;\n panDeltaY?: number;\n viewportWidth: number;\n viewportHeight: number;\n zoomLevel: number;\n createCardSprite: (id: string | number, x: number, y: number) => CardSprite;\n updateCardContent: (sprite: CardSprite, item: TItem) => void;\n isViewTransition?: boolean;\n prevLayout?: LayoutResult | null;\n}\n\nexport function syncSpritesToViewport<TItem>(params: SyncParams<TItem>) {\n const { root, container, sprites, layout, visibleIds, items, cardWidth, cardHeight, panX, panY, panDeltaX, panDeltaY, viewportWidth, viewportHeight, createCardSprite, updateCardContent, zoomLevel, isViewTransition, prevLayout } = params;\n if (!root || !container) return;\n\n console.log('[syncSpritesToViewport] Called with', {\n layoutPositionsSize: layout.positions.size,\n visibleIdsSize: visibleIds.length,\n spritesSize: sprites.size,\n itemsLength: items.length,\n isViewTransition,\n zoomLevel\n });\n\n // `visibleIds` comes from callers but this module iterates `layout.positions`.\n // Keep a reference to avoid unused variable lint errors when callers include it.\n void visibleIds;\n\n // Apply pan delta to animating sprites to keep them visually stable during camera jumps\n if (isViewTransition && (panDeltaX || panDeltaY)) {\n const dx = (panDeltaX || 0) / (zoomLevel || 1);\n const dy = (panDeltaY || 0) / (zoomLevel || 1);\n\n for (const sprite of sprites.values()) {\n if (sprite.animationStartTime !== undefined) {\n if (sprite.startX !== undefined) sprite.startX += dx;\n if (sprite.startY !== undefined) sprite.startY += dy;\n sprite.currentX += dx;\n sprite.currentY += dy;\n sprite.container?.position?.set(sprite.currentX, sprite.currentY);\n }\n }\n }\n\n const visibleSet = new Set<string | number>();\n\n // Increase buffer (in world units) to reduce edge cases where rapid\n // scrolling skips sprite creation. Keep buffer in world units and convert\n // DOM pixel measurements into world coordinates below to avoid mixing\n // coordinate spaces which can cause precision drift at browser zooms.\n const baseBufferWorld = Math.max(cardWidth, cardHeight) * 4;\n // Ensure buffer scales with viewport size (in world units) so that when\n // zoomed out we still pre-create enough sprites ahead of the viewport.\n const invScale = zoomLevel && zoomLevel !== 0 ? 1 / zoomLevel : 1;\n // The layout positions are in world units; when the root container is scaled\n // (zoomed) the rendered pixel position = position * zoomLevel. The DOM\n // scroll positions (`container.scrollLeft/Top`) are the authoritative pixel\n // camera offsets; prefer them over the passed `panX/panY` to avoid stale\n // values or race conditions between React state and direct DOM updates.\n const effectivePanX = typeof container.scrollLeft === 'number' ? container.scrollLeft : (panX || 0);\n const effectivePanY = typeof container.scrollTop === 'number' ? container.scrollTop : (panY || 0);\n\n // Convert pixel-based DOM measurements into world units so we compare like\n // with like. root.position is set using -pixels, so the mapping\n // from DOM scroll (pixels) to world units is: world = pixels / zoomLevel.\n const panWorldX = effectivePanX * invScale;\n const panWorldY = effectivePanY * invScale;\n\n // Use the container's measured client size for the viewport dimensions\n // (in pixels). The passed `viewportWidth`/`viewportHeight` can be stale\n // when the browser/device zoom changes; `clientWidth/clientHeight` are\n // authoritative for the actual visible pixel area.\n const viewportPxWidth = container.clientWidth || viewportWidth;\n const viewportPxHeight = container.clientHeight || viewportHeight;\n\n const viewportWorldWidth = viewportPxWidth * invScale;\n const viewportWorldHeight = viewportPxHeight * invScale;\n\n // Ensure bufferWorld is calculated from the actual measured viewport\n // in world units (after converting client pixel dims using invScale).\n // Make buffer adaptive to zoom: when zoomed out (invScale > 1) a small\n // pixel scroll maps to a larger world delta, so increase the buffer.\n // Use the larger of width/height to ensure we buffer enough in both directions.\n const bufferWorld = Math.max(baseBufferWorld * invScale, Math.max(viewportWorldWidth, viewportWorldHeight) * 2.0, baseBufferWorld);\n\n // Do not clamp viewport edges to 0 — allow negative top/left values so the\n // visible window correctly follows the scroll even when the buffer is\n // larger than the current scroll offset.\n const viewportLeftWorld = panWorldX - bufferWorld;\n const viewportRightWorld = panWorldX + viewportWorldWidth + bufferWorld;\n const viewportTopWorld = panWorldY - bufferWorld;\n const viewportBottomWorld = panWorldY + viewportWorldHeight + bufferWorld;\n\n const inViewportIds: (string | number)[] = [];\n // Small tolerance in world units to avoid floating-point edge cases when\n // browser/device zoom or high scroll values produce tiny rounding errors.\n // Scale epsilon with invScale so tolerance grows when zoomed out.\n const worldEpsilon = Math.max(0.5, 0.5 * invScale);\n\n // Iterate layout positions directly to avoid depending on `visibleIds`\n // which may be calculated in a different coordinate space or with\n // different assumptions about zoom. Looping the positions map is\n // deterministic and uses world coordinates directly.\n for (const [id, position] of layout.positions) {\n if (!position) continue;\n const worldX = position.x;\n const worldY = position.y;\n const worldCardW = cardWidth;\n const worldCardH = cardHeight;\n\n if (\n worldX + worldCardW >= viewportLeftWorld - worldEpsilon &&\n worldX <= viewportRightWorld + worldEpsilon &&\n worldY + worldCardH >= viewportTopWorld - worldEpsilon &&\n worldY <= viewportBottomWorld + worldEpsilon\n ) {\n inViewportIds.push(id);\n visibleSet.add(id);\n }\n }\n\n // Ensure last rows are present when the user scrolls near the bottom.\n // Compute slot/row information and force-insert IDs from the last few\n // rows to avoid missing tiles due to rounding/precision at zoom levels.\n try {\n const slotHeight = cardHeight + (CARD_GAP || 8);\n const totalRows = Math.ceil((layout.totalHeight || 0) / slotHeight) || 0;\n // Determine how many rows are visible in the viewport (world units),\n // then prefetch a fraction of that adjusted by zoom (invScale).\n const rowsVisible = Math.max(1, Math.ceil(viewportWorldHeight / slotHeight));\n const prefetchMultiplier = 0.75; // fraction of viewport to prefetch\n const prefetchRows = Math.max(2, Math.ceil(rowsVisible * prefetchMultiplier * Math.max(1, invScale)));\n const lastRowThresholdY = Math.max(0, (totalRows - prefetchRows) * slotHeight);\n for (const [id, position] of layout.positions) {\n if (position.y >= lastRowThresholdY) {\n if (!visibleSet.has(id)) {\n inViewportIds.push(id);\n visibleSet.add(id);\n }\n }\n }\n } catch (e) {\n void e;\n }\n\n // If we detect a very large discrepancy between created sprites and the\n // computed in-viewport count, that's a signal our culling math may be\n // unstable (especially at non-100% zoom). In that case, skip hiding this\n // frame as a conservative safeguard to avoid mass disappearing tiles.\n // However, disable this safeguard during view transitions to ensure old sprites are cleaned up.\n // EXCEPT: During view transitions, if scroll position hasn't stabilized yet (e.g., switching to grouped\n // mode triggers a scroll-to-bottom), keep all sprites visible to prevent flickering\n const scrollStabilized = Math.abs(panWorldY - (container.scrollTop * invScale)) < 10;\n const aggressiveCull = (!isViewTransition && sprites.size > Math.max(120, Math.ceil(inViewportIds.length * 1.5))) || \n (isViewTransition && !scrollStabilized);\n\n for (const [id, sprite] of sprites) {\n if (!visibleSet.has(id)) {\n // If view transition is active, check if this sprite has a valid target in the new layout\n // If so, keep it visible and animate it to the new position (even if off-screen)\n if (isViewTransition && layout.positions.has(id)) {\n const newPos = layout.positions.get(id);\n if (newPos) {\n sprite.targetX = newPos.x;\n sprite.targetY = newPos.y;\n\n // Trigger animation if not already animating\n if (sprite.animationStartTime === undefined) {\n sprite.startX = sprite.currentX;\n sprite.startY = sprite.currentY;\n sprite.animationStartTime = Date.now();\n sprite.animationDelay = Math.random() * 300;\n }\n\n try { if (sprite.container) sprite.container.visible = true; } catch (e) { void e; }\n // Don't mark as hidden, so it won't be swept\n if ((sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt) delete (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n continue;\n }\n }\n\n if (aggressiveCull) {\n // Keep sprite visible this frame to avoid visual holes\n try { if (sprite.container) sprite.container.visible = true; } catch (e) { void e; }\n continue;\n }\n\n try {\n if (sprite.container) {\n sprite.container.visible = false;\n }\n (sprite as unknown as { __lastHiddenAt: number }).__lastHiddenAt = Date.now();\n } catch (e) {\n void e;\n }\n } else {\n try {\n if (sprite.container) {\n sprite.container.visible = true;\n }\n if ((sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt) delete (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n } catch (e) { void e; }\n }\n }\n\n // Sweep: actually destroy sprites that have been hidden longer than threshold\n try {\n const SWEEP_MS = 100; // keep hidden sprites for 100ms before destruction (reduced from 500ms for faster mode transitions)\n const now = Date.now();\n for (const [id, sprite] of sprites) {\n const lastHidden = (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n if (lastHidden && now - lastHidden > SWEEP_MS) {\n try {\n // remove from parent if present\n if (sprite.container && sprite.container.parent) sprite.container.parent.removeChild(sprite.container);\n } catch (e) {\n void e;\n }\n try {\n destroySprite(sprite);\n } catch (e) {\n void e;\n }\n sprites.delete(id);\n }\n }\n } catch (e) {\n void e;\n }\n\n // Limit the number of sprites created per frame to avoid choking the GPU/CPU\n // when scrolling rapidly or zooming out significantly.\n const MAX_SPRITES_PER_FRAME = 50;\n let createdCount = 0;\n\n console.log('[syncSpritesToViewport] About to create sprites for inViewportIds:', inViewportIds.length);\n console.log('[syncSpritesToViewport] layout.positions IDs:', Array.from(layout.positions.keys()));\n\n for (const id of inViewportIds) {\n const position = layout.positions.get(id);\n if (!position) {\n console.log('[syncSpritesToViewport] No position for id:', id, 'in layout.positions');\n continue;\n }\n\n let sprite = sprites.get(id);\n if (!sprite) {\n if (createdCount >= MAX_SPRITES_PER_FRAME) {\n console.log('[syncSpritesToViewport] Max sprites per frame reached');\n continue;\n }\n createdCount++;\n\n console.log('[syncSpritesToViewport] Creating sprite for id:', id, 'at position:', position);\n\n let startX = position.x;\n let startY = position.y;\n let shouldAnimate = false;\n\n // If view transition, try to find old position to fly in from\n if (isViewTransition && prevLayout && prevLayout.positions.has(id)) {\n const oldPos = prevLayout.positions.get(id);\n if (oldPos) {\n startX = oldPos.x;\n startY = oldPos.y;\n\n // If we have a pan delta (camera jump), we need to adjust the start position\n // so that the sprite appears at the same visual location relative to the NEW camera.\n // StartWorld = OldWorld + PanDelta\n if (panDeltaX || panDeltaY) {\n const dx = (panDeltaX || 0) / (zoomLevel || 1);\n const dy = (panDeltaY || 0) / (zoomLevel || 1);\n startX += dx;\n startY += dy;\n }\n\n shouldAnimate = true;\n }\n }\n\n sprite = createCardSprite(id, startX, startY);\n sprites.set(id, sprite);\n if (sprite.container) {\n root.addChild(sprite.container);\n sprite.currentX = startX;\n sprite.currentY = startY;\n // Keep sprite.container positioned in world units; animation/update\n // loop will apply root.scale/position to convert to pixels.\n sprite.container.position.set(startX, startY);\n }\n\n if (shouldAnimate) {\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n sprite.startX = startX;\n sprite.startY = startY;\n sprite.animationStartTime = Date.now();\n sprite.animationDelay = Math.random() * 300;\n }\n }\n\n // Check if target changed to trigger animation\n if (sprite.targetX !== position.x || sprite.targetY !== position.y) {\n console.log('[syncSpritesToViewport] Updating sprite target position for id:', id, 'from', {\n oldX: sprite.targetX,\n oldY: sprite.targetY\n }, 'to', position);\n if (isViewTransition) {\n sprite.startX = sprite.currentX;\n sprite.startY = sprite.currentY;\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n sprite.animationStartTime = Date.now();\n // Add random delay for \"organic\" fly effect\n sprite.animationDelay = Math.random() * 300;\n } else {\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n delete sprite.animationStartTime;\n delete sprite.animationDelay;\n }\n } else {\n console.log('[syncSpritesToViewport] Sprite position unchanged for id:', id, 'at', position);\n }\n\n const item = items[Number(id)];\n if (item) {\n updateCardContent(sprite, item);\n }\n }\n}\n"],"names":["sprites","CARD_GAP","destroySprite"],"mappings":";;;;;AA+BM,SAAU,qBAAqB,CAAQ,MAAyB,EAAA;AAClE,IAAA,MAAM,EAAE,IAAI,EAAE,SAAS,WAAEA,SAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,aA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AAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;gBAC3B,OAAO,MAAM,CAAC,kBAAkB;gBAChC,OAAO,MAAM,CAAC,cAAc;YAChC;QACJ;aAAO;YACH,OAAO,CAAC,GAAG,CAAC,2DAA2D,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC;QAChG;QAEA,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,IAAI,EAAE;AACN,YAAA,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC;QACnC;IACJ;AACJ;;;;"}
1
+ {"version":3,"file":"visibility.js","sources":["../../../../../PivotViewer/components/pivot/visibility.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport * as PIXI from 'pixi.js';\nimport type { CardSprite } from './constants';\nimport { CARD_GAP } from './constants';\nimport type { LayoutResult } from '../../engine/types';\nimport { destroySprite } from './sprites';\n\nexport interface SyncParams<TItem> {\n root: PIXI.Container | null;\n container: HTMLDivElement | null;\n sprites: Map<string | number, CardSprite>;\n layout: LayoutResult;\n visibleIds: Uint32Array;\n items: TItem[];\n cardWidth: number;\n cardHeight: number;\n panX: number;\n panY: number;\n panDeltaX?: number;\n panDeltaY?: number;\n viewportWidth: number;\n viewportHeight: number;\n zoomLevel: number;\n createCardSprite: (id: string | number, x: number, y: number) => CardSprite;\n updateCardContent: (sprite: CardSprite, item: TItem) => void;\n isViewTransition?: boolean;\n prevLayout?: LayoutResult | null;\n}\n\nexport function syncSpritesToViewport<TItem>(params: SyncParams<TItem>) {\n const { root, container, sprites, layout, visibleIds, items, cardWidth, cardHeight, panX, panY, panDeltaX, panDeltaY, viewportWidth, viewportHeight, createCardSprite, updateCardContent, zoomLevel, isViewTransition, prevLayout } = params;\n if (!root || !container) return;\n\n // `visibleIds` comes from callers but this module iterates `layout.positions`.\n // Keep a reference to avoid unused variable lint errors when callers include it.\n void visibleIds;\n\n // Apply pan delta to animating sprites to keep them visually stable during camera jumps\n if (isViewTransition && (panDeltaX || panDeltaY)) {\n const dx = (panDeltaX || 0) / (zoomLevel || 1);\n const dy = (panDeltaY || 0) / (zoomLevel || 1);\n\n for (const sprite of sprites.values()) {\n if (sprite.animationStartTime !== undefined) {\n if (sprite.startX !== undefined) sprite.startX += dx;\n if (sprite.startY !== undefined) sprite.startY += dy;\n sprite.currentX += dx;\n sprite.currentY += dy;\n sprite.container?.position?.set(sprite.currentX, sprite.currentY);\n }\n }\n }\n\n const visibleSet = new Set<string | number>();\n\n // Increase buffer (in world units) to reduce edge cases where rapid\n // scrolling skips sprite creation. Keep buffer in world units and convert\n // DOM pixel measurements into world coordinates below to avoid mixing\n // coordinate spaces which can cause precision drift at browser zooms.\n const baseBufferWorld = Math.max(cardWidth, cardHeight) * 4;\n // Ensure buffer scales with viewport size (in world units) so that when\n // zoomed out we still pre-create enough sprites ahead of the viewport.\n const invScale = zoomLevel && zoomLevel !== 0 ? 1 / zoomLevel : 1;\n // The layout positions are in world units; when the root container is scaled\n // (zoomed) the rendered pixel position = position * zoomLevel. The DOM\n // scroll positions (`container.scrollLeft/Top`) are the authoritative pixel\n // camera offsets; prefer them over the passed `panX/panY` to avoid stale\n // values or race conditions between React state and direct DOM updates.\n const effectivePanX = typeof container.scrollLeft === 'number' ? container.scrollLeft : (panX || 0);\n const effectivePanY = typeof container.scrollTop === 'number' ? container.scrollTop : (panY || 0);\n\n // Convert pixel-based DOM measurements into world units so we compare like\n // with like. root.position is set using -pixels, so the mapping\n // from DOM scroll (pixels) to world units is: world = pixels / zoomLevel.\n const panWorldX = effectivePanX * invScale;\n const panWorldY = effectivePanY * invScale;\n\n // Use the container's measured client size for the viewport dimensions\n // (in pixels). The passed `viewportWidth`/`viewportHeight` can be stale\n // when the browser/device zoom changes; `clientWidth/clientHeight` are\n // authoritative for the actual visible pixel area.\n const viewportPxWidth = container.clientWidth || viewportWidth;\n const viewportPxHeight = container.clientHeight || viewportHeight;\n\n const viewportWorldWidth = viewportPxWidth * invScale;\n const viewportWorldHeight = viewportPxHeight * invScale;\n\n // Ensure bufferWorld is calculated from the actual measured viewport\n // in world units (after converting client pixel dims using invScale).\n // Make buffer adaptive to zoom: when zoomed out (invScale > 1) a small\n // pixel scroll maps to a larger world delta, so increase the buffer.\n // Use the larger of width/height to ensure we buffer enough in both directions.\n const bufferWorld = Math.max(baseBufferWorld * invScale, Math.max(viewportWorldWidth, viewportWorldHeight) * 2.0, baseBufferWorld);\n\n // Do not clamp viewport edges to 0 — allow negative top/left values so the\n // visible window correctly follows the scroll even when the buffer is\n // larger than the current scroll offset.\n const viewportLeftWorld = panWorldX - bufferWorld;\n const viewportRightWorld = panWorldX + viewportWorldWidth + bufferWorld;\n const viewportTopWorld = panWorldY - bufferWorld;\n const viewportBottomWorld = panWorldY + viewportWorldHeight + bufferWorld;\n\n const inViewportIds: (string | number)[] = [];\n // Small tolerance in world units to avoid floating-point edge cases when\n // browser/device zoom or high scroll values produce tiny rounding errors.\n // Scale epsilon with invScale so tolerance grows when zoomed out.\n const worldEpsilon = Math.max(0.5, 0.5 * invScale);\n\n // Iterate layout positions directly to avoid depending on `visibleIds`\n // which may be calculated in a different coordinate space or with\n // different assumptions about zoom. Looping the positions map is\n // deterministic and uses world coordinates directly.\n for (const [id, position] of layout.positions) {\n if (!position) continue;\n const worldX = position.x;\n const worldY = position.y;\n const worldCardW = cardWidth;\n const worldCardH = cardHeight;\n\n if (\n worldX + worldCardW >= viewportLeftWorld - worldEpsilon &&\n worldX <= viewportRightWorld + worldEpsilon &&\n worldY + worldCardH >= viewportTopWorld - worldEpsilon &&\n worldY <= viewportBottomWorld + worldEpsilon\n ) {\n inViewportIds.push(id);\n visibleSet.add(id);\n }\n }\n\n // Ensure last rows are present when the user scrolls near the bottom.\n // Compute slot/row information and force-insert IDs from the last few\n // rows to avoid missing tiles due to rounding/precision at zoom levels.\n try {\n const slotHeight = cardHeight + (CARD_GAP || 8);\n const totalRows = Math.ceil((layout.totalHeight || 0) / slotHeight) || 0;\n // Determine how many rows are visible in the viewport (world units),\n // then prefetch a fraction of that adjusted by zoom (invScale).\n const rowsVisible = Math.max(1, Math.ceil(viewportWorldHeight / slotHeight));\n const prefetchMultiplier = 0.75; // fraction of viewport to prefetch\n const prefetchRows = Math.max(2, Math.ceil(rowsVisible * prefetchMultiplier * Math.max(1, invScale)));\n const lastRowThresholdY = Math.max(0, (totalRows - prefetchRows) * slotHeight);\n for (const [id, position] of layout.positions) {\n if (position.y >= lastRowThresholdY) {\n if (!visibleSet.has(id)) {\n inViewportIds.push(id);\n visibleSet.add(id);\n }\n }\n }\n } catch (e) {\n void e;\n }\n\n // If we detect a very large discrepancy between created sprites and the\n // computed in-viewport count, that's a signal our culling math may be\n // unstable (especially at non-100% zoom). In that case, skip hiding this\n // frame as a conservative safeguard to avoid mass disappearing tiles.\n // However, disable this safeguard during view transitions to ensure old sprites are cleaned up.\n // EXCEPT: During view transitions, if scroll position hasn't stabilized yet (e.g., switching to grouped\n // mode triggers a scroll-to-bottom), keep all sprites visible to prevent flickering\n const scrollStabilized = Math.abs(panWorldY - (container.scrollTop * invScale)) < 10;\n const aggressiveCull = (!isViewTransition && sprites.size > Math.max(120, Math.ceil(inViewportIds.length * 1.5))) || \n (isViewTransition && !scrollStabilized);\n\n for (const [id, sprite] of sprites) {\n if (!visibleSet.has(id)) {\n // If view transition is active, check if this sprite has a valid target in the new layout\n // If so, keep it visible and animate it to the new position (even if off-screen)\n if (isViewTransition && layout.positions.has(id)) {\n const newPos = layout.positions.get(id);\n if (newPos) {\n sprite.targetX = newPos.x;\n sprite.targetY = newPos.y;\n\n // Trigger animation if not already animating\n if (sprite.animationStartTime === undefined) {\n sprite.startX = sprite.currentX;\n sprite.startY = sprite.currentY;\n sprite.animationStartTime = Date.now();\n sprite.animationDelay = Math.random() * 300;\n }\n\n try { if (sprite.container) sprite.container.visible = true; } catch (e) { void e; }\n // Don't mark as hidden, so it won't be swept\n if ((sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt) delete (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n continue;\n }\n }\n\n if (aggressiveCull) {\n // Keep sprite visible this frame to avoid visual holes\n try { if (sprite.container) sprite.container.visible = true; } catch (e) { void e; }\n continue;\n }\n\n try {\n if (sprite.container) {\n sprite.container.visible = false;\n }\n (sprite as unknown as { __lastHiddenAt: number }).__lastHiddenAt = Date.now();\n } catch (e) {\n void e;\n }\n } else {\n try {\n if (sprite.container) {\n sprite.container.visible = true;\n }\n if ((sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt) delete (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n } catch (e) { void e; }\n }\n }\n\n // Sweep: actually destroy sprites that have been hidden longer than threshold\n try {\n const SWEEP_MS = 100; // keep hidden sprites for 100ms before destruction (reduced from 500ms for faster mode transitions)\n const now = Date.now();\n for (const [id, sprite] of sprites) {\n const lastHidden = (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n if (lastHidden && now - lastHidden > SWEEP_MS) {\n try {\n // remove from parent if present\n if (sprite.container && sprite.container.parent) sprite.container.parent.removeChild(sprite.container);\n } catch (e) {\n void e;\n }\n try {\n destroySprite(sprite);\n } catch (e) {\n void e;\n }\n sprites.delete(id);\n }\n }\n } catch (e) {\n void e;\n }\n\n // Limit the number of sprites created per frame to avoid choking the GPU/CPU\n // when scrolling rapidly or zooming out significantly.\n const MAX_SPRITES_PER_FRAME = 50;\n let createdCount = 0;\n\n\n for (const id of inViewportIds) {\n const position = layout.positions.get(id);\n if (!position) {\n continue;\n }\n\n let sprite = sprites.get(id);\n if (!sprite) {\n if (createdCount >= MAX_SPRITES_PER_FRAME) {\n continue;\n }\n createdCount++;\n\n let startX = position.x;\n let startY = position.y;\n let shouldAnimate = false;\n\n // If view transition, try to find old position to fly in from\n if (isViewTransition && prevLayout && prevLayout.positions.has(id)) {\n const oldPos = prevLayout.positions.get(id);\n if (oldPos) {\n startX = oldPos.x;\n startY = oldPos.y;\n\n // If we have a pan delta (camera jump), we need to adjust the start position\n // so that the sprite appears at the same visual location relative to the NEW camera.\n // StartWorld = OldWorld + PanDelta\n if (panDeltaX || panDeltaY) {\n const dx = (panDeltaX || 0) / (zoomLevel || 1);\n const dy = (panDeltaY || 0) / (zoomLevel || 1);\n startX += dx;\n startY += dy;\n }\n\n shouldAnimate = true;\n }\n }\n\n sprite = createCardSprite(id, startX, startY);\n sprites.set(id, sprite);\n if (sprite.container) {\n root.addChild(sprite.container);\n sprite.currentX = startX;\n sprite.currentY = startY;\n // Keep sprite.container positioned in world units; animation/update\n // loop will apply root.scale/position to convert to pixels.\n sprite.container.position.set(startX, startY);\n }\n\n if (shouldAnimate) {\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n sprite.startX = startX;\n sprite.startY = startY;\n sprite.animationStartTime = Date.now();\n sprite.animationDelay = Math.random() * 300;\n }\n }\n\n // Check if target changed to trigger animation\n if (sprite.targetX !== position.x || sprite.targetY !== position.y) {\n if (isViewTransition) {\n sprite.startX = sprite.currentX;\n sprite.startY = sprite.currentY;\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n sprite.animationStartTime = Date.now();\n // Add random delay for \"organic\" fly effect\n sprite.animationDelay = Math.random() * 300;\n } else {\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n delete sprite.animationStartTime;\n delete sprite.animationDelay;\n }\n }\n\n const item = items[Number(id)];\n if (item) {\n updateCardContent(sprite, item);\n }\n }\n}\n"],"names":["sprites","CARD_GAP","destroySprite"],"mappings":";;;;;AA+BM,SAAU,qBAAqB,CAAQ,MAAyB,EAAA;AAClE,IAAA,MAAM,EAAE,IAAI,EAAE,SAAS,WAAEA,SAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,i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GAAG,MAAM,CAAC,QAAQ;AAC/B,gBAAA,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;AAC3B,gBAAA,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;AAC3B,gBAAA,MAAM,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,EAAE;gBAEtC,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG;YAC/C;iBAAO;AACH,gBAAA,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;AAC3B,gBAAA,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;gBAC3B,OAAO,MAAM,CAAC,kBAAkB;gBAChC,OAAO,MAAM,CAAC,cAAc;YAChC;QACJ;QAEA,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,IAAI,EAAE;AACN,YAAA,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC;QACnC;IACJ;AACJ;;;;"}
@@ -14,7 +14,6 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
14
14
  const pendingCallbacksRef = React.useRef(new Map());
15
15
  React.useEffect(() => {
16
16
  if (typeof window === 'undefined' || typeof Worker === 'undefined') {
17
- console.warn('[PivotEngine] Worker not supported in this environment, using main thread');
18
17
  fallbackRef.current = true;
19
18
  setWorkerAvailable(false);
20
19
  return;
@@ -32,68 +31,49 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
32
31
  const response = await fetch(workerUrl, { method: 'HEAD' });
33
32
  const contentType = response.headers.get('content-type') ?? '';
34
33
  if (!response.ok || !contentType.includes('javascript')) {
35
- console.warn('[PivotEngine] Worker asset not reachable, using main thread');
36
34
  enableFallback();
37
35
  return;
38
36
  }
39
37
  }
40
38
  }
41
- catch (error) {
42
- console.warn('[PivotEngine] Worker preflight failed, using main thread', error);
39
+ catch {
43
40
  enableFallback();
44
41
  return;
45
42
  }
46
43
  if (disposed) {
47
44
  return;
48
45
  }
49
- console.log('[PivotEngine] Creating worker');
50
46
  const worker = new Worker(workerUrl, { type: 'module' });
51
47
  workerRef.current = worker;
52
48
  setWorkerAvailable(true);
53
- console.log('[PivotEngine] Worker created, setting up message handlers');
54
49
  worker.onmessage = (e) => {
55
50
  const message = e.data;
56
- console.log('[PivotEngine] Received message from worker:', message.type);
57
51
  switch (message.type) {
58
52
  case 'indexesReady':
59
- console.log('[PivotEngine] Indexes ready');
60
53
  setReady(true);
61
54
  break;
62
55
  case 'filterResult': {
63
56
  const callback = pendingCallbacksRef.current.get('filter');
64
57
  if (callback) {
65
- console.log('[PivotEngine] Calling filter callback and deleting');
66
58
  callback(message.result);
67
59
  pendingCallbacksRef.current.delete('filter');
68
60
  }
69
- else {
70
- console.warn('[PivotEngine] No callback registered for filter result - ignoring duplicate message');
71
- }
72
61
  break;
73
62
  }
74
63
  case 'groupingResult': {
75
- console.log('[PivotEngine] Received groupingResult:', message.result);
76
64
  const callback = pendingCallbacksRef.current.get('grouping');
77
65
  if (callback) {
78
- console.log('[PivotEngine] Calling grouping callback and deleting');
79
66
  callback(message.result);
80
67
  pendingCallbacksRef.current.delete('grouping');
81
68
  }
82
- else {
83
- console.warn('[PivotEngine] No callback registered for grouping result - ignoring duplicate message');
84
- }
85
69
  break;
86
70
  }
87
71
  case 'sortResult': {
88
72
  const callback = pendingCallbacksRef.current.get('sort');
89
73
  if (callback) {
90
- console.log('[PivotEngine] Calling sort callback and deleting');
91
74
  callback(message.result);
92
75
  pendingCallbacksRef.current.delete('sort');
93
76
  }
94
- else {
95
- console.warn('[PivotEngine] No callback registered for sort result - ignoring duplicate message');
96
- }
97
77
  break;
98
78
  }
99
79
  }
@@ -121,11 +101,9 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
121
101
  };
122
102
  }, [indexFields]);
123
103
  React.useEffect(() => {
124
- console.log('[PivotEngine] Building indexes for', data.length, 'items');
125
104
  setReady(false);
126
105
  const store$1 = store.buildStore(data, fieldExtractors);
127
106
  storeRef.current = store$1;
128
- console.log('[PivotEngine] Store built with', store$1.items.length, 'items and', store$1.fields.size, 'fields');
129
107
  try {
130
108
  indexesRef.current = store.buildIndexes(store$1, indexFields);
131
109
  }
@@ -144,7 +122,6 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
144
122
  store: serializableStore,
145
123
  fields: indexFields,
146
124
  };
147
- console.log('[PivotEngine] Posting buildIndexes with', fieldsArray.length, 'fields');
148
125
  workerRef.current.postMessage(message);
149
126
  }
150
127
  else {
@@ -178,20 +155,16 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
178
155
  });
179
156
  }, [ready]);
180
157
  const computeGroupingCallback = React.useCallback((visibleIds, groupBy) => {
181
- console.log('[PivotEngine] computeGroupingCallback called with', visibleIds.length, 'visibleIds');
182
158
  if (pendingCallbacksRef.current.has('grouping')) {
183
- console.warn('[PivotEngine] Grouping already in progress, ignoring duplicate request');
184
159
  return Promise.resolve({ groups: [] });
185
160
  }
186
161
  return new Promise((resolve) => {
187
162
  if (!workerRef.current || fallbackRef.current) {
188
- console.log('[PivotEngine] Using synchronous fallback for grouping');
189
163
  try {
190
164
  const store$1 = storeRef.current;
191
165
  const indexes = indexesRef.current;
192
166
  if (store$1 && indexes) {
193
167
  const result = store.computeGrouping(store$1, indexes, visibleIds, groupBy);
194
- console.log('[PivotEngine] Fallback grouping result:', result);
195
168
  resolve(result);
196
169
  return;
197
170
  }
@@ -199,11 +172,9 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
199
172
  catch (e) {
200
173
  console.error('[PivotEngine] fallback computeGrouping error:', e);
201
174
  }
202
- console.warn('[PivotEngine] No store/indexes for fallback, returning empty');
203
175
  resolve({ groups: [] });
204
176
  return;
205
177
  }
206
- console.log('[PivotEngine] Setting grouping callback and posting to worker');
207
178
  pendingCallbacksRef.current.set('grouping', resolve);
208
179
  const message = {
209
180
  type: 'computeGrouping',
@@ -211,7 +182,6 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
211
182
  groupBy,
212
183
  };
213
184
  workerRef.current.postMessage(message);
214
- console.log('[PivotEngine] Message posted to worker');
215
185
  });
216
186
  }, [ready]);
217
187
  const sortIdsCallback = React.useCallback((visibleIds, sortBy) => {
@@ -1 +1 @@
1
- {"version":3,"file":"usePivotEngine.js","sources":["../../../../PivotViewer/hooks/usePivotEngine.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useEffect, useRef, useState, useCallback } from 'react';\nimport type {\n PivotStore,\n PivotIndexes,\n FilterSpec,\n FilterResult,\n GroupSpec,\n GroupingResult,\n WorkerInMessage,\n WorkerOutMessage,\n FieldValue,\n} from '../engine/types';\nimport { buildStore, buildIndexes, applyFilters, computeGrouping, sortIds } from '../engine/store';\n\nexport interface UsePivotEngineOptions<TItem extends object> {\n data: TItem[];\n fieldExtractors: Map<string, (item: TItem) => FieldValue>;\n indexFields: string[];\n}\n\nexport interface UsePivotEngineResult {\n ready: boolean;\n applyFilters: (filters: FilterSpec[]) => Promise<FilterResult>;\n computeGrouping: (visibleIds: Uint32Array, groupBy: GroupSpec) => Promise<GroupingResult>;\n sortIds: (visibleIds: Uint32Array, sortBy: string) => Promise<Uint32Array>;\n}\n\nexport function usePivotEngine<TItem extends object>({\n data,\n fieldExtractors,\n indexFields,\n}: UsePivotEngineOptions<TItem>): UsePivotEngineResult {\n const [ready, setReady] = useState(false);\n const [workerAvailable, setWorkerAvailable] = useState(false);\n const workerRef = useRef<Worker | null>(null);\n const indexesRef = useRef<PivotIndexes | null>(null);\n const fallbackRef = useRef(false);\n const storeRef = useRef<PivotStore | null>(null);\n const pendingCallbacksRef = useRef<Map<string, (result: unknown) => void>>(new Map());\n\n useEffect(() => {\n if (typeof window === 'undefined' || typeof Worker === 'undefined') {\n console.warn('[PivotEngine] Worker not supported in this environment, using main thread');\n fallbackRef.current = true;\n setWorkerAvailable(false);\n return;\n }\n\n const workerUrl = new URL('../engine/pivot.worker.js', import.meta.url);\n let disposed = false;\n\n const enableFallback = () => {\n fallbackRef.current = true;\n workerRef.current = null;\n setWorkerAvailable(false);\n };\n\n const setupWorker = async () => {\n try {\n if (typeof fetch === 'function') {\n const response = await fetch(workerUrl, { method: 'HEAD' });\n const contentType = response.headers.get('content-type') ?? '';\n\n if (!response.ok || !contentType.includes('javascript')) {\n console.warn('[PivotEngine] Worker asset not reachable, using main thread');\n enableFallback();\n return;\n }\n }\n } catch (error) {\n console.warn('[PivotEngine] Worker preflight failed, using main thread', error);\n enableFallback();\n return;\n }\n\n if (disposed) {\n return;\n }\n\n console.log('[PivotEngine] Creating worker');\n const worker = new Worker(workerUrl, { type: 'module' });\n\n workerRef.current = worker;\n setWorkerAvailable(true);\n console.log('[PivotEngine] Worker created, setting up message handlers');\n\n worker.onmessage = (e: MessageEvent<WorkerOutMessage>) => {\n const message = e.data;\n console.log('[PivotEngine] Received message from worker:', message.type);\n\n switch (message.type) {\n case 'indexesReady':\n console.log('[PivotEngine] Indexes ready');\n setReady(true);\n break;\n\n case 'filterResult': {\n const callback = pendingCallbacksRef.current.get('filter');\n if (callback) {\n console.log('[PivotEngine] Calling filter callback and deleting');\n callback(message.result);\n pendingCallbacksRef.current.delete('filter');\n } else {\n console.warn('[PivotEngine] No callback registered for filter result - ignoring duplicate message');\n }\n break;\n }\n\n case 'groupingResult': {\n console.log('[PivotEngine] Received groupingResult:', message.result);\n const callback = pendingCallbacksRef.current.get('grouping');\n if (callback) {\n console.log('[PivotEngine] Calling grouping callback and deleting');\n callback(message.result);\n pendingCallbacksRef.current.delete('grouping');\n } else {\n console.warn('[PivotEngine] No callback registered for grouping result - ignoring duplicate message');\n }\n break;\n }\n\n case 'sortResult': {\n const callback = pendingCallbacksRef.current.get('sort');\n if (callback) {\n console.log('[PivotEngine] Calling sort callback and deleting');\n callback(message.result);\n pendingCallbacksRef.current.delete('sort');\n } else {\n console.warn('[PivotEngine] No callback registered for sort result - ignoring duplicate message');\n }\n break;\n }\n }\n };\n\n worker.onerror = (error) => {\n console.error('[PivotEngine] Worker error:', error);\n enableFallback();\n if (storeRef.current) {\n try {\n indexesRef.current = buildIndexes(storeRef.current, indexFields);\n } catch (e) {\n console.error('[PivotEngine] Failed to build indexes in fallback:', e);\n indexesRef.current = null;\n }\n setReady(true);\n }\n };\n };\n\n void setupWorker();\n\n return () => {\n disposed = true;\n workerRef.current?.terminate();\n workerRef.current = null;\n };\n }, [indexFields]);\n\n useEffect(() => {\n console.log('[PivotEngine] Building indexes for', data.length, 'items');\n setReady(false);\n\n const store = buildStore(data, fieldExtractors);\n storeRef.current = store;\n console.log('[PivotEngine] Store built with', store.items.length, 'items and', store.fields.size, 'fields');\n\n try {\n indexesRef.current = buildIndexes(store, indexFields);\n } catch (e) {\n console.error('[PivotEngine] buildIndexes failed:', e);\n indexesRef.current = null;\n }\n\n if (workerRef.current && !fallbackRef.current) {\n const fieldsArray = Array.from(store.fields.entries());\n const serializableStore = {\n ...store,\n fields: fieldsArray,\n };\n\n const message: WorkerInMessage = {\n type: 'buildIndexes',\n store: serializableStore as unknown as PivotStore,\n fields: indexFields,\n };\n\n console.log('[PivotEngine] Posting buildIndexes with', fieldsArray.length, 'fields');\n workerRef.current.postMessage(message);\n } else {\n setReady(true);\n }\n }, [data, fieldExtractors, indexFields, workerAvailable]);\n\n const applyFiltersCallback = useCallback(\n (filters: FilterSpec[]): Promise<FilterResult> => {\n return new Promise((resolve) => {\n // If worker is not available, use synchronous fallback using local indexes\n if (!workerRef.current || fallbackRef.current) {\n try {\n const store = storeRef.current;\n const indexes = indexesRef.current;\n if (store && indexes) {\n const result = applyFilters(store, indexes, filters);\n resolve(result);\n return;\n }\n } catch (e) {\n console.error('[PivotEngine] fallback applyFilters error:', e);\n }\n\n // if fallback not possible, return empty result\n resolve({ visibleIds: new Uint32Array(0), count: 0 });\n return;\n }\n\n pendingCallbacksRef.current.set('filter', resolve as (result: unknown) => void);\n\n const message: WorkerInMessage = {\n type: 'applyFilters',\n filters,\n };\n\n workerRef.current.postMessage(message);\n });\n },\n [ready]\n );\n\n const computeGroupingCallback = useCallback(\n (visibleIds: Uint32Array, groupBy: GroupSpec): Promise<GroupingResult> => {\n console.log('[PivotEngine] computeGroupingCallback called with', visibleIds.length, 'visibleIds');\n \n // Check if there's already a pending grouping request\n if (pendingCallbacksRef.current.has('grouping')) {\n console.warn('[PivotEngine] Grouping already in progress, ignoring duplicate request');\n return Promise.resolve({ groups: [] });\n }\n \n return new Promise((resolve) => {\n // synchronous fallback if worker unavailable\n if (!workerRef.current || fallbackRef.current) {\n console.log('[PivotEngine] Using synchronous fallback for grouping');\n try {\n const store = storeRef.current;\n const indexes = indexesRef.current;\n if (store && indexes) {\n const result = computeGrouping(store, indexes, visibleIds, groupBy);\n console.log('[PivotEngine] Fallback grouping result:', result);\n resolve(result);\n return;\n }\n } catch (e) {\n console.error('[PivotEngine] fallback computeGrouping error:', e);\n }\n\n console.warn('[PivotEngine] No store/indexes for fallback, returning empty');\n resolve({ groups: [] });\n return;\n }\n\n console.log('[PivotEngine] Setting grouping callback and posting to worker');\n pendingCallbacksRef.current.set('grouping', resolve as (result: unknown) => void);\n\n const message: WorkerInMessage = {\n type: 'computeGrouping',\n visibleIds,\n groupBy,\n };\n\n workerRef.current.postMessage(message);\n console.log('[PivotEngine] Message posted to worker');\n });\n },\n [ready]\n );\n\n const sortIdsCallback = useCallback(\n (visibleIds: Uint32Array, sortBy: string): Promise<Uint32Array> => {\n return new Promise((resolve) => {\n // synchronous fallback if worker unavailable\n if (!workerRef.current || fallbackRef.current) {\n try {\n const store = storeRef.current;\n if (store) {\n const result = sortIds(store, visibleIds, sortBy);\n resolve(result);\n return;\n }\n } catch (e) {\n console.error('[PivotEngine] fallback sortIds error:', e);\n }\n\n resolve(visibleIds);\n return;\n }\n\n pendingCallbacksRef.current.set('sort', resolve as (result: unknown) => void);\n\n const message: WorkerInMessage = {\n type: 'sort',\n ids: visibleIds,\n sortBy,\n };\n\n workerRef.current.postMessage(message);\n });\n },\n [ready]\n );\n\n return {\n ready,\n applyFilters: applyFiltersCallback,\n computeGrouping: computeGroupingCallback,\n sortIds: sortIdsCallback,\n };\n}\n"],"names":["useState","useRef","useEffect","buildIndexes","store","buildStore","useCallback","applyFilters","computeGrouping","sortIds"],"mappings":";;;;;;AA8BM,SAAU,cAAc,CAAuB,EACnD,IAAI,EACJ,eAAe,EACf,WAAW,GACkB,EAAA;IAC7B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;IACzC,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;AAC7D,IAAA,MAAM,SAAS,GAAGC,YAAM,CAAgB,IAAI,CAAC;AAC7C,IAAA,MAAM,UAAU,GAAGA,YAAM,CAAsB,IAAI,CAAC;AACpD,IAAA,MAAM,WAAW,GAAGA,YAAM,CAAC,KAAK,CAAC;AACjC,IAAA,MAAM,QAAQ,GAAGA,YAAM,CAAoB,IAAI,CAAC;IAChD,MAAM,mBAAmB,GAAGA,YAAM,CAAyC,IAAI,GAAG,EAAE,CAAC;IAErFC,eAAS,CAAC,MAAK;QACb,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AAClE,YAAA,OAAO,CAAC,IAAI,CAAC,2EAA2E,CAAC;AACzF,YAAA,WAAW,CAAC,OAAO,GAAG,IAAI;YAC1B,kBAAkB,CAAC,KAAK,CAAC;YACzB;QACF;AAEA,QAAA,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,2BAA2B,EAAE,qRAAe,CAAC;QACvE,IAAI,QAAQ,GAAG,KAAK;QAEpB,MAAM,cAAc,GAAG,MAAK;AAC1B,YAAA,WAAW,CAAC,OAAO,GAAG,IAAI;AAC1B,YAAA,SAAS,CAAC,OAAO,GAAG,IAAI;YACxB,kBAAkB,CAAC,KAAK,CAAC;AAC3B,QAAA,C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,OAAO,CAAC,MAAM,CAAC;wBACf;oBACF;gBACF;gBAAE,OAAO,CAAC,EAAE;AACV,oBAAA,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,CAAC,CAAC;gBAC3D;gBAEA,OAAO,CAAC,UAAU,CAAC;gBACnB;YACF;YAEA,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAoC,CAAC;AAE7E,YAAA,MAAM,OAAO,GAAoB;AAC/B,gBAAA,IAAI,EAAE,MAAM;AACZ,gBAAA,GAAG,EAAE,UAAU;gBACf,MAAM;aACP;AAED,YAAA,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC;AACxC,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC,EACD,CAAC,KAAK,CAAC,CACR;IAED,OAAO;QACL,KAAK;AACL,QAAA,YAAY,EAAE,oBAAoB;AAClC,QAAA,eAAe,EAAE,uBAAuB;AACxC,QAAA,OAAO,EAAE,eAAe;KACzB;AACH;;;;"}
1
+ {"version":3,"file":"usePivotEngine.js","sources":["../../../../PivotViewer/hooks/usePivotEngine.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useEffect, useRef, useState, useCallback } from 'react';\nimport type {\n PivotStore,\n PivotIndexes,\n FilterSpec,\n FilterResult,\n GroupSpec,\n GroupingResult,\n WorkerInMessage,\n WorkerOutMessage,\n FieldValue,\n} from '../engine/types';\nimport { buildStore, buildIndexes, applyFilters, computeGrouping, sortIds } from '../engine/store';\n\nexport interface UsePivotEngineOptions<TItem extends object> {\n data: TItem[];\n fieldExtractors: Map<string, (item: TItem) => FieldValue>;\n indexFields: string[];\n}\n\nexport interface UsePivotEngineResult {\n ready: boolean;\n applyFilters: (filters: FilterSpec[]) => Promise<FilterResult>;\n computeGrouping: (visibleIds: Uint32Array, groupBy: GroupSpec) => Promise<GroupingResult>;\n sortIds: (visibleIds: Uint32Array, sortBy: string) => Promise<Uint32Array>;\n}\n\nexport function usePivotEngine<TItem extends object>({\n data,\n fieldExtractors,\n indexFields,\n}: UsePivotEngineOptions<TItem>): UsePivotEngineResult {\n const [ready, setReady] = useState(false);\n const [workerAvailable, setWorkerAvailable] = useState(false);\n const workerRef = useRef<Worker | null>(null);\n const indexesRef = useRef<PivotIndexes | null>(null);\n const fallbackRef = useRef(false);\n const storeRef = useRef<PivotStore | null>(null);\n const pendingCallbacksRef = useRef<Map<string, (result: unknown) => void>>(new Map());\n\n useEffect(() => {\n if (typeof window === 'undefined' || typeof Worker === 'undefined') {\n fallbackRef.current = true;\n setWorkerAvailable(false);\n return;\n }\n\n const workerUrl = new URL('../engine/pivot.worker.js', import.meta.url);\n let disposed = false;\n\n const enableFallback = () => {\n fallbackRef.current = true;\n workerRef.current = null;\n setWorkerAvailable(false);\n };\n\n const setupWorker = async () => {\n try {\n if (typeof fetch === 'function') {\n const response = await fetch(workerUrl, { method: 'HEAD' });\n const contentType = response.headers.get('content-type') ?? '';\n\n if (!response.ok || !contentType.includes('javascript')) {\n enableFallback();\n return;\n }\n }\n } catch {\n enableFallback();\n return;\n }\n\n if (disposed) {\n return;\n }\n\n const worker = new Worker(workerUrl, { type: 'module' });\n\n workerRef.current = worker;\n setWorkerAvailable(true);\n\n worker.onmessage = (e: MessageEvent<WorkerOutMessage>) => {\n const message = e.data;\n\n switch (message.type) {\n case 'indexesReady':\n setReady(true);\n break;\n\n case 'filterResult': {\n const callback = pendingCallbacksRef.current.get('filter');\n if (callback) {\n callback(message.result);\n pendingCallbacksRef.current.delete('filter');\n }\n break;\n }\n\n case 'groupingResult': {\n const callback = pendingCallbacksRef.current.get('grouping');\n if (callback) {\n callback(message.result);\n pendingCallbacksRef.current.delete('grouping');\n }\n break;\n }\n\n case 'sortResult': {\n const callback = pendingCallbacksRef.current.get('sort');\n if (callback) {\n callback(message.result);\n pendingCallbacksRef.current.delete('sort');\n }\n break;\n }\n }\n };\n\n worker.onerror = (error) => {\n console.error('[PivotEngine] Worker error:', error);\n enableFallback();\n if (storeRef.current) {\n try {\n indexesRef.current = buildIndexes(storeRef.current, indexFields);\n } catch (e) {\n console.error('[PivotEngine] Failed to build indexes in fallback:', e);\n indexesRef.current = null;\n }\n setReady(true);\n }\n };\n };\n\n void setupWorker();\n\n return () => {\n disposed = true;\n workerRef.current?.terminate();\n workerRef.current = null;\n };\n }, [indexFields]);\n\n useEffect(() => {\n setReady(false);\n\n const store = buildStore(data, fieldExtractors);\n storeRef.current = store;\n\n try {\n indexesRef.current = buildIndexes(store, indexFields);\n } catch (e) {\n console.error('[PivotEngine] buildIndexes failed:', e);\n indexesRef.current = null;\n }\n\n if (workerRef.current && !fallbackRef.current) {\n const fieldsArray = Array.from(store.fields.entries());\n const serializableStore = {\n ...store,\n fields: fieldsArray,\n };\n\n const message: WorkerInMessage = {\n type: 'buildIndexes',\n store: serializableStore as unknown as PivotStore,\n fields: indexFields,\n };\n workerRef.current.postMessage(message);\n } else {\n setReady(true);\n }\n }, [data, fieldExtractors, indexFields, workerAvailable]);\n\n const applyFiltersCallback = useCallback(\n (filters: FilterSpec[]): Promise<FilterResult> => {\n return new Promise((resolve) => {\n // If worker is not available, use synchronous fallback using local indexes\n if (!workerRef.current || fallbackRef.current) {\n try {\n const store = storeRef.current;\n const indexes = indexesRef.current;\n if (store && indexes) {\n const result = applyFilters(store, indexes, filters);\n resolve(result);\n return;\n }\n } catch (e) {\n console.error('[PivotEngine] fallback applyFilters error:', e);\n }\n\n // if fallback not possible, return empty result\n resolve({ visibleIds: new Uint32Array(0), count: 0 });\n return;\n }\n\n pendingCallbacksRef.current.set('filter', resolve as (result: unknown) => void);\n\n const message: WorkerInMessage = {\n type: 'applyFilters',\n filters,\n };\n\n workerRef.current.postMessage(message);\n });\n },\n [ready]\n );\n\n const computeGroupingCallback = useCallback(\n (visibleIds: Uint32Array, groupBy: GroupSpec): Promise<GroupingResult> => {\n // Check if there's already a pending grouping request\n if (pendingCallbacksRef.current.has('grouping')) {\n return Promise.resolve({ groups: [] });\n }\n\n return new Promise((resolve) => {\n // synchronous fallback if worker unavailable\n if (!workerRef.current || fallbackRef.current) {\n try {\n const store = storeRef.current;\n const indexes = indexesRef.current;\n if (store && indexes) {\n const result = computeGrouping(store, indexes, visibleIds, groupBy);\n resolve(result);\n return;\n }\n } catch (e) {\n console.error('[PivotEngine] fallback computeGrouping error:', e);\n }\n\n resolve({ groups: [] });\n return;\n }\n\n pendingCallbacksRef.current.set('grouping', resolve as (result: unknown) => void);\n\n const message: WorkerInMessage = {\n type: 'computeGrouping',\n visibleIds,\n groupBy,\n };\n\n workerRef.current.postMessage(message);\n });\n },\n [ready]\n );\n\n const sortIdsCallback = useCallback(\n (visibleIds: Uint32Array, sortBy: string): Promise<Uint32Array> => {\n return new Promise((resolve) => {\n // synchronous fallback if worker unavailable\n if (!workerRef.current || fallbackRef.current) {\n try {\n const store = storeRef.current;\n if (store) {\n const result = sortIds(store, visibleIds, sortBy);\n resolve(result);\n return;\n }\n } catch (e) {\n console.error('[PivotEngine] fallback sortIds error:', e);\n }\n\n resolve(visibleIds);\n return;\n }\n\n pendingCallbacksRef.current.set('sort', resolve as (result: unknown) => void);\n\n const message: WorkerInMessage = {\n type: 'sort',\n ids: visibleIds,\n sortBy,\n };\n\n workerRef.current.postMessage(message);\n });\n },\n [ready]\n );\n\n return {\n ready,\n applyFilters: applyFiltersCallback,\n computeGrouping: computeGroupingCallback,\n sortIds: sortIdsCallback,\n };\n}\n"],"names":["useState","useRef","useEffect","buildIndexes","store","buildStore","useCallback","applyFilters","computeGrouping","sortIds"],"mappings":";;;;;;AA8BM,SAAU,cAAc,CAAuB,EACnD,IAAI,EACJ,eAAe,EACf,WAAW,GACkB,EAAA;IAC7B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;IACzC,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;AAC7D,IAA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A,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC;AACxC,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC,EACD,CAAC,KAAK,CAAC,CACR;IAED,MAAM,eAAe,GAAGE,iBAAW,CACjC,CAAC,UAAuB,EAAE,MAAc,KAA0B;AAChE,QAAA,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAI;YAE7B,IAAI,CAAC,SAAS,CAAC,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE;AAC7C,gBAAA,IAAI;AACF,oBAAA,MAAMF,OAAK,GAAG,QAAQ,CAAC,OAAO;oBAC9B,IAAIA,OAAK,EAAE;wBACT,MAAM,MAAM,GAAGK,aAAO,CAACL,OAAK,EAAE,UAAU,EAAE,MAAM,CAAC;wBACjD,OAAO,CAAC,MAAM,CAAC;wBACf;oBACF;gBACF;gBAAE,OAAO,CAAC,EAAE;AACV,oBAAA,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,CAAC,CAAC;gBAC3D;gBAEA,OAAO,CAAC,UAAU,CAAC;gBACnB;YACF;YAEA,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAoC,CAAC;AAE7E,YAAA,MAAM,OAAO,GAAoB;AAC/B,gBAAA,IAAI,EAAE,MAAM;AACZ,gBAAA,GAAG,EAAE,UAAU;gBACf,MAAM;aACP;AAED,YAAA,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC;AACxC,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC,EACD,CAAC,KAAK,CAAC,CACR;IAED,OAAO;QACL,KAAK;AACL,QAAA,YAAY,EAAE,oBAAoB;AAClC,QAAA,eAAe,EAAE,uBAAuB;AACxC,QAAA,OAAO,EAAE,eAAe;KACzB;AACH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../PivotViewer/types.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { ReactNode } from 'react';\n\nexport type PivotPrimitive = string | number | boolean | Date | null | undefined;\n\n/**\n * Type-safe property accessor for accessing properties, including nested ones\n */\nexport type PropertyAccessor<TItem> = (item: TItem) => unknown;\n\n/**\n * Extract property path from a property accessor function\n * Supports nested properties like item => item.address.city\n */\nexport function getPropertyPath<TItem>(accessor: PropertyAccessor<TItem>): string {\n const fnStr = accessor.toString();\n // Match patterns like: item => item.prop or item => item.prop.nested or (item) => item.prop\n const match = fnStr.match(/(?:=>|return)\\s*[a-zA-Z_$][a-zA-Z0-9_$]*\\.([a-zA-Z_$][a-zA-Z0-9_$.]*)/);\n return match ? match[1] : '';\n}\n\n/**\n * Get the value from an item using a property path string\n * Supports nested properties like \"address.city\"\n */\nexport function getValueByPath<TItem>(item: TItem, path: string): unknown {\n const parts = path.split('.');\n let value: unknown = item;\n for (const part of parts) {\n if (value === null || value === undefined) {\n return undefined;\n }\n value = value[part];\n }\n return value;\n}\n\nexport interface PivotGroup<TItem extends object> {\n key: string;\n label: string;\n value: PivotPrimitive;\n items: TItem[];\n count?: number;\n}\n\nexport interface PivotDimension<TItem extends object> {\n key: string;\n label: string;\n getValue: (item: TItem) => PivotPrimitive;\n formatValue?: (value: PivotPrimitive) => string;\n sort?: (a: PivotGroup<TItem>, b: PivotGroup<TItem>) => number;\n}\n\nexport interface PivotFilterOption {\n key: string;\n label: string;\n value: PivotPrimitive;\n count: number;\n}\n\nexport interface PivotFilter<TItem extends object> {\n key: string;\n label: string;\n getValue: (item: TItem) => PivotPrimitive;\n multi?: boolean;\n options?: PivotFilterOption[];\n sort?: (a: PivotFilterOption, b: PivotFilterOption) => number;\n /** For numeric filters, enables range picker with histogram */\n type?: 'string' | 'number' | 'date';\n /** Number of buckets for the histogram in range filters */\n buckets?: number;\n}\n\nexport interface PivotViewerProps<TItem extends object> {\n data: TItem[];\n dimensions: PivotDimension<TItem>[];\n filters?: PivotFilter<TItem>[];\n defaultDimensionKey?: string;\n cardRenderer?: (item: TItem) => ReactNode;\n getItemId?: (item: TItem, index: number) => string | number;\n searchFields?: PropertyAccessor<TItem>[];\n className?: string;\n emptyContent?: ReactNode;\n isLoading?: boolean;\n}\n\nexport type FilterState = Record<string, Set<string>>;\n\nexport type RangeFilterState = Record<string, [number, number] | null>;\n"],"names":[],"mappings":";;AAgBM,SAAU,eAAe,CAAQ,QAAiC,EAAA;AACpE,IAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE;IAEjC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,uEAAuE,CAAC;AAClG,IAAA,OAAO,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE;AAChC;AAMM,SAAU,cAAc,CAAQ,IAAW,EAAE,IAAY,EAAA;IAC3D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAC7B,IAAI,KAAK,GAAY,IAAI;AACzB,IAAA,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE;AACvC,YAAA,OAAO,SAAS;QACpB;AACA,QAAA,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC;IACvB;AACA,IAAA,OAAO,KAAK;AAChB;;;;;"}
1
+ {"version":3,"file":"types.js","sources":["../../../PivotViewer/types.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { ReactNode } from 'react';\n\nexport type PivotPrimitive = string | number | boolean | Date | null | undefined;\n\n/**\n * Type-safe property accessor for accessing properties, including nested ones\n */\nexport type PropertyAccessor<TItem> = (item: TItem) => unknown;\n\n/**\n * Extract property path from a property accessor function\n * Supports nested properties like item => item.address.city\n */\nexport function getPropertyPath<TItem>(accessor: PropertyAccessor<TItem>): string {\n const fnStr = accessor.toString();\n // Match patterns like: item => item.prop or item => item.prop.nested or (item) => item.prop\n const match = fnStr.match(/(?:=>|return)\\s*[a-zA-Z_$][a-zA-Z0-9_$]*\\.([a-zA-Z_$][a-zA-Z0-9_$.]*)/);\n return match ? match[1] : '';\n}\n\n/**\n * Get the value from an item using a property path string\n * Supports nested properties like \"address.city\"\n */\nexport function getValueByPath<TItem>(item: TItem, path: string): unknown {\n const parts = path.split('.');\n let value: unknown = item;\n for (const part of parts) {\n if (value === null || value === undefined) {\n return undefined;\n }\n value = value[part];\n }\n return value;\n}\n\nexport interface PivotGroup<TItem extends object> {\n key: string;\n label: string;\n value: PivotPrimitive;\n items: TItem[];\n count?: number;\n}\n\nexport interface PivotDimension<TItem extends object> {\n key: string;\n label: string;\n getValue: (item: TItem) => PivotPrimitive;\n formatValue?: (value: PivotPrimitive) => string;\n sort?: (a: PivotGroup<TItem>, b: PivotGroup<TItem>) => number;\n}\n\nexport interface PivotFilterOption {\n key: string;\n label: string;\n value: PivotPrimitive;\n count: number;\n}\n\nexport interface PivotFilter<TItem extends object> {\n key: string;\n label: string;\n getValue: (item: TItem) => PivotPrimitive;\n multi?: boolean;\n options?: PivotFilterOption[];\n sort?: (a: PivotFilterOption, b: PivotFilterOption) => number;\n /** For numeric filters, enables range picker with histogram */\n type?: 'string' | 'number' | 'date';\n /** Number of buckets for the histogram in range filters */\n buckets?: number;\n}\n\nexport interface PivotViewerProps<TItem extends object> {\n data: TItem[];\n dimensions: PivotDimension<TItem>[];\n filters?: PivotFilter<TItem>[];\n defaultDimensionKey?: string;\n cardRenderer?: (item: TItem) => ReactNode;\n /** Optional renderer for the slide-in detail panel when a card is selected */\n detailRenderer?: (item: TItem, onClose: () => void) => ReactNode;\n getItemId?: (item: TItem, index: number) => string | number;\n searchFields?: PropertyAccessor<TItem>[];\n className?: string;\n emptyContent?: ReactNode;\n isLoading?: boolean;\n /**\n * Optional color overrides mapped to PrimeReact-like CSS variables.\n * If omitted, values are taken from the global theme (PrimeReact defaults).\n */\n colors?: Partial<{\n primaryColor: string;\n primaryColorText: string;\n primary500: string;\n surfaceGround: string;\n surfaceCard: string;\n surfaceSection: string;\n surfaceOverlay: string;\n surfaceBorder: string;\n textColor: string;\n textColorSecondary: string;\n highlightBg: string;\n maskbg: string;\n focusRing: string;\n }>;\n}\n\nexport type FilterState = Record<string, Set<string>>;\n\nexport type RangeFilterState = Record<string, [number, number] | null>;\n"],"names":[],"mappings":";;AAgBM,SAAU,eAAe,CAAQ,QAAiC,EAAA;AACpE,IAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE;IAEjC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,uEAAuE,CAAC;AAClG,IAAA,OAAO,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE;AAChC;AAMM,SAAU,cAAc,CAAQ,IAAW,EAAE,IAAY,EAAA;IAC3D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAC7B,IAAI,KAAK,GAAY,IAAI;AACzB,IAAA,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE;AACvC,YAAA,OAAO,SAAS;QACpB;AACA,QAAA,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC;IACvB;AACA,IAAA,OAAO,KAAK;AAChB;;;;;"}
@@ -105,26 +105,10 @@ function calculateCenterScrollPosition(container, cardPosition, zoomLevel, detai
105
105
  const targetY = container.clientHeight / 2;
106
106
  const scrollLeft = Math.max(0, cardCenterX - targetX);
107
107
  let scrollTop = Math.max(0, cardCenterY - targetY);
108
- console.log('[Animation] calculateCenterScrollPosition', {
109
- cardY: cardPosition.y,
110
- zoomLevel,
111
- cardCenterY,
112
- targetY,
113
- initialScrollTop: scrollTop,
114
- totalHeight,
115
- containerHeight: container.clientHeight
116
- });
117
108
  if (totalHeight) {
118
109
  const contentHeight = totalHeight * zoomLevel;
119
110
  const viewportHeight = container.clientHeight;
120
111
  const maxScrollTop = Math.max(0, contentHeight - viewportHeight);
121
- console.log('[Animation] Clamping', {
122
- contentHeight,
123
- viewportHeight,
124
- maxScrollTop,
125
- currentScrollTop: scrollTop,
126
- clamped: Math.min(scrollTop, maxScrollTop)
127
- });
128
112
  scrollTop = Math.min(scrollTop, maxScrollTop);
129
113
  }
130
114
  return { scrollLeft, scrollTop };
@@ -1 +1 @@
1
- {"version":3,"file":"animations.js","sources":["../../../../PivotViewer/utils/animations.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nexport type EasingFunction = (t: number) => number;\n\nexport const easeOutCubic: EasingFunction = (t: number) => 1 - Math.pow(1 - t, 3);\n\nexport interface ZoomAnimationParams {\n startZoom: number;\n targetZoom: number;\n duration?: number;\n easing?: EasingFunction;\n}\n\nexport interface ScrollAnimationParams {\n targetScrollLeft: number;\n targetScrollTop: number;\n}\n\nexport interface ZoomScrollAnimationParams extends ZoomAnimationParams, ScrollAnimationParams {\n container: HTMLElement;\n cardPosition?: { x: number; y: number; width: number; height: number } | null;\n targetCardPosition?: { x: number; y: number; width: number; height: number } | null;\n getCardPositionAtZoom?: (zoom: number) => { x: number; y: number; width: number; height: number } | null;\n getLayoutSizeAtZoom?: (zoom: number) => { width: number; height: number };\n spacer?: HTMLElement | null;\n onUpdate: (zoom: number) => void;\n onComplete?: () => void;\n startScrollLeft?: number; // Optional explicit start scroll\n startScrollTop?: number; // Optional explicit start scroll\n}\n\n/**\n * Animate zoom and scroll together, keeping a specific element centered\n */\nexport function animateZoomAndScroll({\n container,\n cardPosition,\n targetCardPosition,\n getCardPositionAtZoom,\n getLayoutSizeAtZoom,\n spacer,\n startZoom,\n targetZoom,\n targetScrollLeft,\n targetScrollTop,\n duration = 300,\n easing = easeOutCubic,\n onUpdate,\n onComplete,\n startScrollLeft,\n startScrollTop,\n}: ZoomScrollAnimationParams): () => void {\n container.style.scrollBehavior = 'auto';\n\n let startTime: number | null = null;\n let rafId: number | null = null;\n\n // Capture start scroll if not provided\n const initialScrollLeft = startScrollLeft ?? container.scrollLeft;\n const initialScrollTop = startScrollTop ?? container.scrollTop;\n\n // Calculate initial center point relative to viewport\n const startCardCenterX = cardPosition ? (cardPosition.x * startZoom + (cardPosition.width * startZoom) / 2) : 0;\n const startCardCenterY = cardPosition ? (cardPosition.y * startZoom + (cardPosition.height * startZoom) / 2) : 0;\n\n const startCardScreenX = startCardCenterX - initialScrollLeft;\n const startCardScreenY = startCardCenterY - initialScrollTop;\n\n const animate = (timestamp: number) => {\n if (startTime === null) {\n startTime = timestamp;\n }\n\n const elapsed = timestamp - startTime;\n const progress = Math.min(1, elapsed / duration);\n const easedProgress = easing(progress);\n\n const currentZoom = startZoom + (targetZoom - startZoom) * easedProgress;\n\n // Update spacer size synchronously if possible\n if (spacer && getLayoutSizeAtZoom) {\n const size = getLayoutSizeAtZoom(currentZoom);\n if (size) {\n spacer.style.width = `${size.width * currentZoom}px`;\n spacer.style.height = `${size.height * currentZoom}px`;\n }\n }\n\n onUpdate(currentZoom);\n\n if (cardPosition) {\n let currentCardX: number;\n let currentCardY: number;\n\n if (getCardPositionAtZoom) {\n const pos = getCardPositionAtZoom(currentZoom);\n if (pos) {\n currentCardX = pos.x;\n currentCardY = pos.y;\n } else {\n currentCardX = cardPosition.x;\n currentCardY = cardPosition.y;\n }\n } else {\n // Interpolate card position if target is provided (for layouts that change with zoom)\n currentCardX = targetCardPosition\n ? cardPosition.x + (targetCardPosition.x - cardPosition.x) * easedProgress\n : cardPosition.x;\n currentCardY = targetCardPosition\n ? cardPosition.y + (targetCardPosition.y - cardPosition.y) * easedProgress\n : cardPosition.y;\n }\n\n // Calculate where the card center is at current zoom\n const currentCardCenterX = currentCardX * currentZoom + (cardPosition.width * currentZoom) / 2;\n const currentCardCenterY = currentCardY * currentZoom + (cardPosition.height * currentZoom) / 2;\n\n // Calculate where the card center will be at the end of animation (relative to viewport)\n // Target scroll position is where we want to end up\n const endCardX = targetCardPosition ? targetCardPosition.x : cardPosition.x;\n const endCardY = targetCardPosition ? targetCardPosition.y : cardPosition.y;\n\n const endCardCenterX = endCardX * targetZoom + (cardPosition.width * targetZoom) / 2;\n const endCardCenterY = endCardY * targetZoom + (cardPosition.height * targetZoom) / 2;\n\n const endCardScreenX = endCardCenterX - targetScrollLeft;\n const endCardScreenY = endCardCenterY - targetScrollTop;\n\n // Interpolate the desired screen position\n const desiredScreenX = startCardScreenX + (endCardScreenX - startCardScreenX) * easedProgress;\n const desiredScreenY = startCardScreenY + (endCardScreenY - startCardScreenY) * easedProgress;\n\n // Calculate needed scroll position to put card at desired screen position\n const neededScrollLeft = currentCardCenterX - desiredScreenX;\n const neededScrollTop = currentCardCenterY - desiredScreenY;\n\n let maxScrollLeft = container.scrollWidth - container.clientWidth;\n let maxScrollTop = container.scrollHeight - container.clientHeight;\n\n // If we have explicit layout size, use it for clamping to avoid DOM sync issues\n if (getLayoutSizeAtZoom) {\n const size = getLayoutSizeAtZoom(currentZoom);\n if (size) {\n maxScrollLeft = Math.max(0, size.width * currentZoom - container.clientWidth);\n maxScrollTop = Math.max(0, size.height * currentZoom - container.clientHeight);\n }\n }\n\n // We can't clamp strictly during animation because the scrollWidth/Height might not have updated yet\n // if the spacer hasn't resized. But usually spacer resizes immediately on zoom update.\n // For safety, we just set it.\n container.scrollLeft = Math.min(Math.max(0, neededScrollLeft), maxScrollLeft);\n container.scrollTop = Math.min(Math.max(0, neededScrollTop), maxScrollTop);\n } else {\n // If no card position, just interpolate scroll position\n // Use captured initial scroll positions for linear interpolation\n const currentScrollLeft = initialScrollLeft + (targetScrollLeft - initialScrollLeft) * easedProgress;\n const currentScrollTop = initialScrollTop + (targetScrollTop - initialScrollTop) * easedProgress;\n\n container.scrollLeft = currentScrollLeft;\n container.scrollTop = currentScrollTop;\n }\n\n if (progress < 1) {\n rafId = requestAnimationFrame(animate);\n } else {\n container.style.scrollBehavior = '';\n container.scrollLeft = targetScrollLeft;\n container.scrollTop = targetScrollTop;\n onComplete?.();\n }\n };\n\n rafId = requestAnimationFrame(animate);\n\n return () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n container.style.scrollBehavior = '';\n }\n };\n}\n\n/**\n * Calculate scroll position to center a card in viewport, accounting for detail panel\n */\nexport function calculateCenterScrollPosition(\n container: HTMLElement,\n cardPosition: { x: number; y: number; width: number; height: number },\n zoomLevel: number,\n detailPanelWidth: number = 0,\n totalHeight?: number\n): { scrollLeft: number; scrollTop: number } {\n const cardCenterX = cardPosition.x * zoomLevel + (cardPosition.width * zoomLevel) / 2;\n const cardCenterY = cardPosition.y * zoomLevel + (cardPosition.height * zoomLevel) / 2;\n\n const availableWidth = container.clientWidth - detailPanelWidth;\n const targetX = availableWidth / 2;\n const targetY = container.clientHeight / 2;\n\n const scrollLeft = Math.max(0, cardCenterX - targetX);\n let scrollTop = Math.max(0, cardCenterY - targetY);\n\n console.log('[Animation] calculateCenterScrollPosition', {\n cardY: cardPosition.y,\n zoomLevel,\n cardCenterY,\n targetY,\n initialScrollTop: scrollTop,\n totalHeight,\n containerHeight: container.clientHeight\n });\n\n // If totalHeight is provided, clamp to valid scroll range\n if (totalHeight) {\n const contentHeight = totalHeight * zoomLevel;\n const viewportHeight = container.clientHeight;\n const maxScrollTop = Math.max(0, contentHeight - viewportHeight);\n\n console.log('[Animation] Clamping', {\n contentHeight,\n viewportHeight,\n maxScrollTop,\n currentScrollTop: scrollTop,\n clamped: Math.min(scrollTop, maxScrollTop)\n });\n\n scrollTop = Math.min(scrollTop, maxScrollTop);\n }\n\n return { scrollLeft, scrollTop };\n}\n\n/**\n * Smooth scroll to position\n */\nexport function smoothScrollTo(\n container: HTMLElement,\n scrollLeft: number,\n scrollTop: number,\n smooth: boolean = true\n): void {\n container.scrollTo({\n left: scrollLeft,\n top: scrollTop,\n behavior: smooth ? 'smooth' : 'auto',\n });\n}\n"],"names":[],"mappings":";;MAKa,YAAY,GAAmB,CAAC,CAAS,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CA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IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY;AAC1C,SAAA,CAAC;QAEF,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC;IAC/C;AAEA,IAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE;AAClC;AAKM,SAAU,cAAc,CAC5B,SAAsB,EACtB,UAAkB,EAClB,SAAiB,EACjB,MAAA,GAAkB,IAAI,EAAA;IAEtB,SAAS,CAAC,QAAQ,CAAC;AACjB,QAAA,IAAI,EAAE,UAAU;AAChB,QAAA,GAAG,EAAE,SAAS;QACd,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM;AACrC,KAAA,CAAC;AACJ;;;;;;;"}
1
+ {"version":3,"file":"animations.js","sources":["../../../../PivotViewer/utils/animations.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nexport type EasingFunction = (t: number) => number;\n\nexport const easeOutCubic: EasingFunction = (t: number) => 1 - Math.pow(1 - t, 3);\n\nexport interface ZoomAnimationParams {\n startZoom: number;\n targetZoom: number;\n duration?: number;\n easing?: EasingFunction;\n}\n\nexport interface ScrollAnimationParams {\n targetScrollLeft: number;\n targetScrollTop: number;\n}\n\nexport interface ZoomScrollAnimationParams extends ZoomAnimationParams, ScrollAnimationParams {\n container: HTMLElement;\n cardPosition?: { x: number; y: number; width: number; height: number } | null;\n targetCardPosition?: { x: number; y: number; width: number; height: number } | null;\n getCardPositionAtZoom?: (zoom: number) => { x: number; y: number; width: number; height: number } | null;\n getLayoutSizeAtZoom?: (zoom: number) => { width: number; height: number };\n spacer?: HTMLElement | null;\n onUpdate: (zoom: number) => void;\n onComplete?: () => void;\n startScrollLeft?: number; // Optional explicit start scroll\n startScrollTop?: number; // Optional explicit start scroll\n}\n\n/**\n * Animate zoom and scroll together, keeping a specific element centered\n */\nexport function animateZoomAndScroll({\n container,\n cardPosition,\n targetCardPosition,\n getCardPositionAtZoom,\n getLayoutSizeAtZoom,\n spacer,\n startZoom,\n targetZoom,\n targetScrollLeft,\n targetScrollTop,\n duration = 300,\n easing = easeOutCubic,\n onUpdate,\n onComplete,\n startScrollLeft,\n startScrollTop,\n}: ZoomScrollAnimationParams): () => void {\n container.style.scrollBehavior = 'auto';\n\n let startTime: number | null = null;\n let rafId: number | null = null;\n\n // Capture start scroll if not provided\n const initialScrollLeft = startScrollLeft ?? container.scrollLeft;\n const initialScrollTop = startScrollTop ?? container.scrollTop;\n\n // Calculate initial center point relative to viewport\n const startCardCenterX = cardPosition ? (cardPosition.x * startZoom + (cardPosition.width * startZoom) / 2) : 0;\n const startCardCenterY = cardPosition ? (cardPosition.y * startZoom + (cardPosition.height * startZoom) / 2) : 0;\n\n const startCardScreenX = startCardCenterX - initialScrollLeft;\n const startCardScreenY = startCardCenterY - initialScrollTop;\n\n const animate = (timestamp: number) => {\n if (startTime === null) {\n startTime = timestamp;\n }\n\n const elapsed = timestamp - startTime;\n const progress = Math.min(1, elapsed / duration);\n const easedProgress = easing(progress);\n\n const currentZoom = startZoom + (targetZoom - startZoom) * easedProgress;\n\n // Update spacer size synchronously if possible\n if (spacer && getLayoutSizeAtZoom) {\n const size = getLayoutSizeAtZoom(currentZoom);\n if (size) {\n spacer.style.width = `${size.width * currentZoom}px`;\n spacer.style.height = `${size.height * currentZoom}px`;\n }\n }\n\n onUpdate(currentZoom);\n\n if (cardPosition) {\n let currentCardX: number;\n let currentCardY: number;\n\n if (getCardPositionAtZoom) {\n const pos = getCardPositionAtZoom(currentZoom);\n if (pos) {\n currentCardX = pos.x;\n currentCardY = pos.y;\n } else {\n currentCardX = cardPosition.x;\n currentCardY = cardPosition.y;\n }\n } else {\n // Interpolate card position if target is provided (for layouts that change with zoom)\n currentCardX = targetCardPosition\n ? cardPosition.x + (targetCardPosition.x - cardPosition.x) * easedProgress\n : cardPosition.x;\n currentCardY = targetCardPosition\n ? cardPosition.y + (targetCardPosition.y - cardPosition.y) * easedProgress\n : cardPosition.y;\n }\n\n // Calculate where the card center is at current zoom\n const currentCardCenterX = currentCardX * currentZoom + (cardPosition.width * currentZoom) / 2;\n const currentCardCenterY = currentCardY * currentZoom + (cardPosition.height * currentZoom) / 2;\n\n // Calculate where the card center will be at the end of animation (relative to viewport)\n // Target scroll position is where we want to end up\n const endCardX = targetCardPosition ? targetCardPosition.x : cardPosition.x;\n const endCardY = targetCardPosition ? targetCardPosition.y : cardPosition.y;\n\n const endCardCenterX = endCardX * targetZoom + (cardPosition.width * targetZoom) / 2;\n const endCardCenterY = endCardY * targetZoom + (cardPosition.height * targetZoom) / 2;\n\n const endCardScreenX = endCardCenterX - targetScrollLeft;\n const endCardScreenY = endCardCenterY - targetScrollTop;\n\n // Interpolate the desired screen position\n const desiredScreenX = startCardScreenX + (endCardScreenX - startCardScreenX) * easedProgress;\n const desiredScreenY = startCardScreenY + (endCardScreenY - startCardScreenY) * easedProgress;\n\n // Calculate needed scroll position to put card at desired screen position\n const neededScrollLeft = currentCardCenterX - desiredScreenX;\n const neededScrollTop = currentCardCenterY - desiredScreenY;\n\n let maxScrollLeft = container.scrollWidth - container.clientWidth;\n let maxScrollTop = container.scrollHeight - container.clientHeight;\n\n // If we have explicit layout size, use it for clamping to avoid DOM sync issues\n if (getLayoutSizeAtZoom) {\n const size = getLayoutSizeAtZoom(currentZoom);\n if (size) {\n maxScrollLeft = Math.max(0, size.width * currentZoom - container.clientWidth);\n maxScrollTop = Math.max(0, size.height * currentZoom - container.clientHeight);\n }\n }\n\n // We can't clamp strictly during animation because the scrollWidth/Height might not have updated yet\n // if the spacer hasn't resized. But usually spacer resizes immediately on zoom update.\n // For safety, we just set it.\n container.scrollLeft = Math.min(Math.max(0, neededScrollLeft), maxScrollLeft);\n container.scrollTop = Math.min(Math.max(0, neededScrollTop), maxScrollTop);\n } else {\n // If no card position, just interpolate scroll position\n // Use captured initial scroll positions for linear interpolation\n const currentScrollLeft = initialScrollLeft + (targetScrollLeft - initialScrollLeft) * easedProgress;\n const currentScrollTop = initialScrollTop + (targetScrollTop - initialScrollTop) * easedProgress;\n\n container.scrollLeft = currentScrollLeft;\n container.scrollTop = currentScrollTop;\n }\n\n if (progress < 1) {\n rafId = requestAnimationFrame(animate);\n } else {\n container.style.scrollBehavior = '';\n container.scrollLeft = targetScrollLeft;\n container.scrollTop = targetScrollTop;\n onComplete?.();\n }\n };\n\n rafId = requestAnimationFrame(animate);\n\n return () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n container.style.scrollBehavior = '';\n }\n };\n}\n\n/**\n * Calculate scroll position to center a card in viewport, accounting for detail panel\n */\nexport function calculateCenterScrollPosition(\n container: HTMLElement,\n cardPosition: { x: number; y: number; width: number; height: number },\n zoomLevel: number,\n detailPanelWidth: number = 0,\n totalHeight?: number\n): { scrollLeft: number; scrollTop: number } {\n const cardCenterX = cardPosition.x * zoomLevel + (cardPosition.width * zoomLevel) / 2;\n const cardCenterY = cardPosition.y * zoomLevel + (cardPosition.height * zoomLevel) / 2;\n\n const availableWidth = container.clientWidth - detailPanelWidth;\n const targetX = availableWidth / 2;\n const targetY = container.clientHeight / 2;\n\n const scrollLeft = Math.max(0, cardCenterX - targetX);\n let scrollTop = Math.max(0, cardCenterY - targetY);\n\n // If totalHeight is provided, clamp to valid scroll range\n if (totalHeight) {\n const contentHeight = totalHeight * zoomLevel;\n const viewportHeight = container.clientHeight;\n const maxScrollTop = Math.max(0, contentHeight - viewportHeight);\n\n scrollTop = Math.min(scrollTop, maxScrollTop);\n }\n\n return { scrollLeft, scrollTop };\n}\n\n/**\n * Smooth scroll to position\n */\nexport function smoothScrollTo(\n container: HTMLElement,\n scrollLeft: number,\n scrollTop: number,\n smooth: boolean = true\n): void {\n container.scrollTo({\n left: scrollLeft,\n top: scrollTop,\n behavior: smooth ? 'smooth' : 'auto',\n });\n}\n"],"names":[],"mappings":";;MAKa,YAAY,GAAmB,CAAC,CAAS,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC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AM;AACrC,KAAA,CAAC;AACJ;;;;;;;"}
@@ -4,12 +4,19 @@
4
4
 
5
5
  .pivot-viewer {
6
6
  position: relative;
7
- height: 100vh;
7
+ /* CRITICAL: Don't set explicit height - let parent control it via container constraints */
8
+ display: flex;
9
+ flex-direction: column;
10
+ min-height: 0; /* allow children to size without forcing overflow */
11
+ max-height: 100%; /* respect parent height if set */
8
12
  width: 100%;
9
- background: radial-gradient(circle at 25% 20%, var(--primary-500), var(--surface-ground));
13
+ /* Keep root neutral; move visual background to the viewport so it never exceeds the container */
14
+ background: var(--surface-ground);
10
15
  color: var(--text-color);
11
16
  overflow: hidden;
12
17
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
18
+ /* Ensure we shrink within flex parent */
19
+ flex: 1 1 0%;
13
20
  }
14
21
 
15
22
  .pv-filter-panel {
@@ -276,7 +283,8 @@
276
283
  display: flex;
277
284
  flex-direction: column;
278
285
  min-height: 0;
279
- height: 100%;
286
+ flex: 1 1 auto; /* grow within pivot-viewer */
287
+ height: auto;
280
288
  padding-left: 0;
281
289
  overflow: hidden;
282
290
  }
@@ -581,6 +589,11 @@
581
589
  background: transparent;
582
590
  }
583
591
 
592
+ /* Visual background belongs to the scrollable viewport area so it respects container bounds */
593
+ .pv-viewport {
594
+ background: radial-gradient(circle at 25% 20%, var(--primary-500), var(--surface-ground));
595
+ }
596
+
584
597
  .pv-groups-buckets {
585
598
  flex: 1;
586
599
  padding-bottom: 0;
@@ -1,4 +1,4 @@
1
1
  import type { PivotViewerProps } from './types';
2
2
  import './PivotViewer.css';
3
- export declare function PivotViewer<TItem extends object>({ data, dimensions, filters, defaultDimensionKey, cardRenderer, getItemId, searchFields, className, emptyContent, isLoading, }: PivotViewerProps<TItem>): import("react/jsx-runtime").JSX.Element;
3
+ export declare function PivotViewer<TItem extends object>({ data, dimensions, filters, defaultDimensionKey, cardRenderer, detailRenderer, getItemId, searchFields, className, emptyContent, isLoading, colors, }: PivotViewerProps<TItem>): import("react/jsx-runtime").JSX.Element;
4
4
  //# sourceMappingURL=PivotViewer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PivotViewer.d.ts","sourceRoot":"","sources":["../../../PivotViewer/PivotViewer.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAQhD,OAAO,mBAAmB,CAAC;AAe3B,wBAAgB,WAAW,CAAC,KAAK,SAAS,MAAM,EAAE,EAC9C,IAAI,EACJ,UAAU,EACV,OAAO,EACP,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,SAAiB,GACpB,EAAE,gBAAgB,CAAC,KAAK,CAAC,2CA6VzB"}
1
+ {"version":3,"file":"PivotViewer.d.ts","sourceRoot":"","sources":["../../../PivotViewer/PivotViewer.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAQhD,OAAO,mBAAmB,CAAC;AAe3B,wBAAgB,WAAW,CAAC,KAAK,SAAS,MAAM,EAAE,EAC9C,IAAI,EACJ,UAAU,EACV,OAAO,EACP,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,SAAS,EACT,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,SAAiB,EACjB,MAAM,GACT,EAAE,gBAAgB,CAAC,KAAK,CAAC,2CA+WzB"}