@opendata-ai/openchart-vanilla 8.9.1 → 9.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/{chunk-REH5UQCL.js → chunk-46E3QB6O.js} +6 -20
- package/dist/chunk-46E3QB6O.js.map +1 -0
- package/dist/{chunk-APMUBW72.js → chunk-5OQZRGUL.js} +1565 -294
- package/dist/chunk-5OQZRGUL.js.map +1 -0
- package/dist/{chunk-GX6BWMJD.js → chunk-5ZLSMZRM.js} +466 -330
- package/dist/chunk-5ZLSMZRM.js.map +1 -0
- package/dist/{chunk-SDJHUELU.js → chunk-A5C4VCUO.js} +26 -45
- package/dist/chunk-A5C4VCUO.js.map +1 -0
- package/dist/{chunk-MGFXAROR.js → chunk-CMIJA63X.js} +5 -3
- package/dist/chunk-CMIJA63X.js.map +1 -0
- package/dist/chunk-FFP5GXIP.js +45 -0
- package/dist/chunk-FFP5GXIP.js.map +1 -0
- package/dist/{chunk-Q7YEEF2X.js → chunk-LDSPJFOU.js} +16 -50
- package/dist/chunk-LDSPJFOU.js.map +1 -0
- package/dist/chunk-NLKQ5AOA.js +448 -0
- package/dist/chunk-NLKQ5AOA.js.map +1 -0
- package/dist/{chunk-R5TZHNTG.js → chunk-RBXIZJPE.js} +17 -5
- package/dist/chunk-RBXIZJPE.js.map +1 -0
- package/dist/{chunk-CCRFYGHU.js → chunk-RY5JEGFM.js} +2368 -2339
- package/dist/chunk-RY5JEGFM.js.map +1 -0
- package/dist/export-gif.d.ts +2 -2
- package/dist/export-gif.js +4 -3
- package/dist/graph-3d/index.d.ts +28 -1
- package/dist/graph-3d/index.js +26 -12
- package/dist/graph-3d/index.js.map +1 -1
- package/dist/index.d.ts +155 -29
- package/dist/index.js +1774 -186
- package/dist/index.js.map +1 -1
- package/dist/{mount-TEjIdF0m.d.ts → mount-types-DeUCa2hy.d.ts} +34 -21
- package/dist/{renderer-registry-Cng76n8F.d.ts → renderer-registry-Bu22Roek.d.ts} +5 -22
- package/dist/simulation-worker.js +27 -26
- package/dist/static.d.ts +4 -2
- package/dist/static.js +34 -10
- package/dist/static.js.map +1 -1
- package/dist/story/index.d.ts +8 -6
- package/dist/story/index.js +15 -12
- package/dist/story/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-APMUBW72.js.map +0 -1
- package/dist/chunk-CCRFYGHU.js.map +0 -1
- package/dist/chunk-GX6BWMJD.js.map +0 -1
- package/dist/chunk-MGFXAROR.js.map +0 -1
- package/dist/chunk-Q7YEEF2X.js.map +0 -1
- package/dist/chunk-R5TZHNTG.js.map +0 -1
- package/dist/chunk-REH5UQCL.js.map +0 -1
- package/dist/chunk-SDJHUELU.js.map +0 -1
- package/dist/chunk-UC4IHEUO.js +0 -73
- package/dist/chunk-UC4IHEUO.js.map +0 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ import { createChart } from '@opendata-ai/openchart-vanilla';
|
|
|
17
17
|
|
|
18
18
|
const chart = createChart(container, spec, {
|
|
19
19
|
darkMode: 'auto',
|
|
20
|
-
|
|
20
|
+
autoResize: true,
|
|
21
21
|
onMarkClick: (event) => console.log(event.datum),
|
|
22
22
|
onMarkHover: (event) => showTooltip(event),
|
|
23
23
|
onMarkLeave: () => hideTooltip(),
|
|
@@ -33,7 +33,7 @@ chart.export('csv'); // Export data as CSV
|
|
|
33
33
|
chart.destroy(); // Clean up DOM and observers
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
Auto-resize (`autoResize`, on by default) uses a `ResizeObserver` on the container. Charts recompile at new dimensions automatically.
|
|
37
37
|
|
|
38
38
|
## Tables
|
|
39
39
|
|
|
@@ -41,7 +41,7 @@ Responsive mode (default) uses a `ResizeObserver` on the container. Charts recom
|
|
|
41
41
|
import { createTable } from '@opendata-ai/openchart-vanilla';
|
|
42
42
|
|
|
43
43
|
const table = createTable(container, tableSpec, {
|
|
44
|
-
|
|
44
|
+
autoResize: true,
|
|
45
45
|
onRowClick: (row) => console.log(row),
|
|
46
46
|
onStateChange: (state) => console.log(state.sort, state.search, state.page),
|
|
47
47
|
});
|
|
@@ -60,7 +60,7 @@ import { createGraph } from '@opendata-ai/openchart-vanilla';
|
|
|
60
60
|
|
|
61
61
|
const graph = createGraph(container, graphSpec, {
|
|
62
62
|
darkMode: 'auto',
|
|
63
|
-
|
|
63
|
+
autoResize: true,
|
|
64
64
|
onNodeClick: (node) => console.log(node),
|
|
65
65
|
onNodeDoubleClick: (node) => console.log(node),
|
|
66
66
|
onSelectionChange: (nodeIds) => console.log(nodeIds),
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cubicInOut,
|
|
3
|
+
cubicOut
|
|
4
|
+
} from "./chunk-NLKQ5AOA.js";
|
|
5
|
+
|
|
1
6
|
// src/resize-observer.ts
|
|
2
7
|
var DEBOUNCE_MS = 16;
|
|
3
8
|
function observeResize(container, callback) {
|
|
@@ -150,20 +155,6 @@ function esc(str) {
|
|
|
150
155
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
151
156
|
}
|
|
152
157
|
|
|
153
|
-
// src/motion/easing.ts
|
|
154
|
-
function linear(t) {
|
|
155
|
-
return t;
|
|
156
|
-
}
|
|
157
|
-
function cubicOut(t) {
|
|
158
|
-
const f = 1 - t;
|
|
159
|
-
return 1 - f * f * f;
|
|
160
|
-
}
|
|
161
|
-
function cubicInOut(t) {
|
|
162
|
-
return t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
|
|
163
|
-
}
|
|
164
|
-
var clamp01 = (t) => Math.min(1, Math.max(0, t));
|
|
165
|
-
var lerp = (a, b, t) => a + (b - a) * t;
|
|
166
|
-
|
|
167
158
|
// src/resolve-dark-mode.ts
|
|
168
159
|
function resolveDarkMode(mode) {
|
|
169
160
|
if (mode === "force") return true;
|
|
@@ -365,13 +356,8 @@ export {
|
|
|
365
356
|
createTooltipManager,
|
|
366
357
|
AnimationScheduler,
|
|
367
358
|
SpatialIndex,
|
|
368
|
-
linear,
|
|
369
|
-
cubicOut,
|
|
370
|
-
cubicInOut,
|
|
371
|
-
clamp01,
|
|
372
|
-
lerp,
|
|
373
359
|
resolveEase,
|
|
374
360
|
prefersReducedMotion,
|
|
375
361
|
createTween
|
|
376
362
|
};
|
|
377
|
-
//# sourceMappingURL=chunk-
|
|
363
|
+
//# sourceMappingURL=chunk-46E3QB6O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/resize-observer.ts","../src/tooltip.ts","../src/resolve-dark-mode.ts","../src/motion/scheduler.ts","../src/spatial-index.ts","../src/motion/tween.ts"],"sourcesContent":["/**\n * Resize observer: thin wrapper around ResizeObserver with debounce.\n *\n * Watches a container element for size changes and calls back with\n * the new width and height. Debounced at ~60fps (16ms) to avoid\n * excessive re-renders during drag resizes.\n */\n\nconst DEBOUNCE_MS = 16;\n\n/**\n * Observe a container element for size changes.\n *\n * @param container - The element to watch.\n * @param callback - Called with (width, height) when size changes.\n * @returns A cleanup function that disconnects the observer.\n */\nexport function observeResize(\n container: HTMLElement,\n callback: (width: number, height: number) => void,\n): () => void {\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n let lastDelivered: { width: number; height: number } | null = null;\n\n const observer = new ResizeObserver((entries) => {\n // Debounce to ~60fps\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n timeoutId = setTimeout(() => {\n for (const entry of entries) {\n const { width, height } = entry.contentRect;\n // Always deliver the first callback (the initial fire on insertion is\n // load-bearing, see .claude/rules/svg-animation.md). Only dedupe\n // subsequent deliveries whose size didn't actually change.\n if (lastDelivered && lastDelivered.width === width && lastDelivered.height === height) {\n continue;\n }\n lastDelivered = { width, height };\n callback(width, height);\n }\n timeoutId = null;\n }, DEBOUNCE_MS);\n });\n\n observer.observe(container);\n\n return () => {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n observer.disconnect();\n };\n}\n","/**\n * Tooltip manager: creates and positions a floating tooltip element.\n *\n * Shows tooltip content near the mouse/touch position with viewport\n * edge avoidance via @floating-ui/dom. Touch support via tap-to-show,\n * tap-outside-to-hide.\n */\n\nimport type { Placement } from '@floating-ui/dom';\nimport { computePosition, flip, offset, shift } from '@floating-ui/dom';\nimport type { TooltipContent } from '@opendata-ai/openchart-core';\n\nexport interface TooltipShowOptions {\n /**\n * Floating-ui placement. Defaults to 'bottom-start' for mark hover\n * (the legacy behavior). Line/area snap-tooltips pass 'right-start'\n * so the card sits beside the snapped point and flips to 'left-start'\n * via the flip middleware when crowding the right edge.\n */\n placement?: Placement;\n}\n\n/**\n * Content accepted by {@link TooltipManager.show}. A structured\n * {@link TooltipContent} is rendered by the manager; `{ text }` is inserted as\n * plain text (escaped via textContent); `{ element }` is a caller-owned node\n * trusted verbatim (the host owns sanitization).\n */\nexport type TooltipInput = TooltipContent | { text: string } | { element: HTMLElement };\n\nexport interface TooltipManager {\n /** Show the tooltip with content at a given position. */\n show(content: TooltipInput, x: number, y: number, opts?: TooltipShowOptions): void;\n /**\n * Re-anchor the open tooltip without re-rendering its content.\n *\n * The 3D graph re-anchors on every engine tick and every camera change, and\n * `show()` would re-run the host formatter and rewrite the DOM at frame rate\n * for content that has not changed.\n */\n move(x: number, y: number, opts?: TooltipShowOptions): void;\n /** Hide the tooltip. */\n hide(): void;\n /** Remove the tooltip element and clean up event listeners. */\n destroy(): void;\n}\n\nconst TOOLTIP_OFFSET = 12;\n\n/**\n * Create a tooltip manager attached to a container element.\n *\n * The manager creates a floating div positioned relative to the container.\n * Content is rendered as a title line with optional color indicator,\n * followed by a compact list of field-value pairs.\n *\n * @param container - The parent element for the tooltip.\n * @returns TooltipManager with show/hide/destroy methods.\n */\nexport function createTooltipManager(container: HTMLElement): TooltipManager {\n const tooltip = document.createElement('div');\n tooltip.className = 'oc-tooltip';\n tooltip.setAttribute('role', 'tooltip');\n\n container.style.position = container.style.position || 'relative';\n container.appendChild(tooltip);\n\n // Track last content to skip innerHTML when only position changes\n let lastContentKey = '';\n // Generation counter to discard stale async position callbacks\n let currentPositionId = 0;\n\n // Hide on tap-outside for touch devices\n const handleDocumentTouch = (e: Event): void => {\n if (!container.contains(e.target as Node)) {\n hide();\n }\n };\n document.addEventListener('touchstart', handleDocumentTouch);\n\n // WCAG 1.4.13: hover-triggered content must be dismissible without moving\n // the pointer. Document-level so it works while hovering, when the chart\n // container does not have keyboard focus.\n const handleDocumentKeydown = (e: KeyboardEvent): void => {\n if (e.key === 'Escape' && tooltip.style.display === 'block') {\n hide();\n }\n };\n document.addEventListener('keydown', handleDocumentKeydown);\n\n function show(input: TooltipInput, x: number, y: number, opts?: TooltipShowOptions): void {\n // Custom-element form: trusted verbatim (host owns sanitization).\n if ('element' in input) {\n lastContentKey = '';\n tooltip.replaceChildren(input.element);\n position(x, y, opts);\n return;\n }\n // Plain-text form: escaped via textContent, never innerHTML.\n if ('text' in input) {\n lastContentKey = '';\n tooltip.textContent = input.text;\n position(x, y, opts);\n return;\n }\n\n const content = input;\n // Fast content identity check: title + field count + first/last field values\n // Includes the emphasized row: moving the pointer between series at the\n // same x changes only which row is bold, and the fast path would skip it.\n const emphasisIndex = content.fields.findIndex((f) => f.emphasis);\n const contentKey = `${content.title}|${content.fields.length}|${content.fields[0]?.value}|${content.fields[content.fields.length - 1]?.value}|${emphasisIndex}`;\n\n if (contentKey !== lastContentKey) {\n lastContentKey = contentKey;\n\n let html = '';\n\n // Multi-series tooltips put a swatch on each row instead of in the\n // header, so detect that case once.\n const colorRowCount = content.fields.filter((f) => f.color && f.role !== 'total').length;\n const perRowSwatches = colorRowCount > 1;\n\n // Title row: header dot only when there's a single color (single-series)\n if (content.title) {\n const titleColor = perRowSwatches ? undefined : content.fields.find((f) => f.color)?.color;\n html += '<div class=\"oc-tooltip-header\">';\n if (titleColor) {\n html += `<span class=\"oc-tooltip-dot\" style=\"background:${esc(titleColor)}\"></span>`;\n }\n html += `<span class=\"oc-tooltip-title\">${esc(content.title)}</span>`;\n html += '</div>';\n }\n\n // Field rows\n if (content.fields.length > 0) {\n html += '<div class=\"oc-tooltip-body\">';\n for (const field of content.fields) {\n let rowClass = 'oc-tooltip-row';\n if (field.emphasis) rowClass += ' oc-tooltip-row--emphasis';\n if (field.role === 'total') rowClass += ' oc-tooltip-row--total';\n html += `<div class=\"${rowClass}\">`;\n html += '<span class=\"oc-tooltip-label\">';\n if (perRowSwatches && field.color) {\n html += `<span class=\"oc-tooltip-row-swatch\" style=\"background:${esc(field.color)}\"></span>`;\n }\n html += `${esc(field.label)}</span>`;\n html += `<span class=\"oc-tooltip-value\">${esc(field.value)}</span>`;\n html += '</div>';\n }\n html += '</div>';\n }\n\n tooltip.innerHTML = html;\n }\n\n position(x, y, opts);\n }\n\n /** Show and position the tooltip at a container-relative coordinate. */\n function position(x: number, y: number, opts?: TooltipShowOptions): void {\n tooltip.style.display = 'block';\n\n // Position with viewport-aware edge avoidance via @floating-ui/dom.\n // Uses a virtual element since the reference point is a coordinate,\n // not a DOM element.\n const positionId = ++currentPositionId;\n const virtualRef = {\n getBoundingClientRect() {\n const rect = container.getBoundingClientRect();\n return {\n x: rect.left + x,\n y: rect.top + y,\n width: 0,\n height: 0,\n top: rect.top + y,\n left: rect.left + x,\n right: rect.left + x,\n bottom: rect.top + y,\n };\n },\n };\n\n computePosition(virtualRef, tooltip, {\n placement: opts?.placement ?? 'bottom-start',\n middleware: [offset(TOOLTIP_OFFSET), flip(), shift({ padding: 8 })],\n }).then(({ x: fx, y: fy }) => {\n // Discard stale callbacks from earlier show() calls\n if (positionId !== currentPositionId) return;\n // computePosition returns coordinates relative to the tooltip's offset\n // parent (the container with position: relative), so apply directly.\n tooltip.style.left = `${fx}px`;\n tooltip.style.top = `${fy}px`;\n });\n }\n\n /** Re-anchor the tooltip at a new coordinate, leaving its content alone. */\n function move(x: number, y: number, opts?: TooltipShowOptions): void {\n // `position()` unhides the element, so moving a hidden tooltip would put\n // whatever content was last rendered back on screen. A move only ever\n // re-anchors something already visible.\n if (tooltip.style.display !== 'block') return;\n position(x, y, opts);\n }\n\n function hide(): void {\n tooltip.style.display = 'none';\n lastContentKey = '';\n }\n\n function destroy(): void {\n document.removeEventListener('touchstart', handleDocumentTouch);\n document.removeEventListener('keydown', handleDocumentKeydown);\n if (tooltip.parentNode) {\n tooltip.parentNode.removeChild(tooltip);\n }\n }\n\n return { show, move, hide, destroy };\n}\n\nfunction esc(str: string): string {\n return str\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n","import type { DarkMode } from '@opendata-ai/openchart-core';\n\n/**\n * Resolve a DarkMode option to a boolean. 'auto' consults the OS preference\n * via matchMedia; environments without matchMedia (SSR, happy-dom) resolve\n * to light.\n */\nexport function resolveDarkMode(mode?: DarkMode): boolean {\n if (mode === 'force') return true;\n if (mode === 'off' || mode === undefined) return false;\n if (typeof window !== 'undefined' && window.matchMedia) {\n return window.matchMedia('(prefers-color-scheme: dark)').matches;\n }\n return false;\n}\n","/**\n * Canvas animation scheduler.\n *\n * Owns the set of running rAF-driven animations and the first-frame arming.\n * The mount's render loop ticks the scheduler once per frame and re-arms rAF\n * only while animations are active — a continuous loop that costs nothing when\n * idle (the base render loop stays strictly dirty-flag).\n *\n * Shared by the graph canvas and the scatter canvas mark layer.\n *\n * Two hazards this design guards against:\n *\n * 1. **First-frame arming is the scheduler's job, not the call site's.** `add()`\n * invokes the injected `requestFrame` on the idle→active transition, so no\n * call site can forget to arm the first frame.\n *\n * 2. **Reentrancy.** A tween's `onDone` may call `update()` / `destroy()`, which\n * trigger `finishAll` / `cancelAll` mid-tick. `tick()` iterates a SNAPSHOT of\n * the animation list; `remove` / `cancelAll` are safe to call mid-tick.\n */\n\n/** A single rAF-driven animation. */\nexport interface Animation {\n /** Advance to `now` (ms). Returns true while running, false when complete. */\n tick(now: number): boolean;\n /** Jump to the final state and fire completion callbacks. */\n finish(): void;\n /** Stop immediately without applying the final state or firing completion. */\n cancel(): void;\n}\n\n/** Manages a set of active animations and drives frame arming. */\nexport class AnimationScheduler {\n private animations = new Set<Animation>();\n private readonly requestFrame: () => void;\n\n /**\n * @param requestFrame Called on the idle→active transition to arm the first\n * frame (typically the mount's `scheduleRender`).\n */\n constructor(requestFrame: () => void) {\n this.requestFrame = requestFrame;\n }\n\n /** Add an animation. Arms the first frame if the scheduler was idle. */\n add(a: Animation): void {\n const wasIdle = this.animations.size === 0;\n this.animations.add(a);\n if (wasIdle) this.requestFrame();\n }\n\n /** Remove an animation without finishing or cancelling it. Safe mid-tick. */\n remove(a: Animation): void {\n this.animations.delete(a);\n }\n\n /**\n * Advance all animations to `now`. Completed animations are removed. Returns\n * true if any animation ran this frame (so the caller marks the frame dirty).\n *\n * Iterates a snapshot so an `onDone` that mutates the set (via update/destroy)\n * can't corrupt the loop.\n */\n tick(now: number): boolean {\n if (this.animations.size === 0) return false;\n const snapshot = [...this.animations];\n let ran = false;\n for (const a of snapshot) {\n // An earlier animation's onDone may have removed this one mid-loop.\n if (!this.animations.has(a)) continue;\n ran = true;\n const running = a.tick(now);\n if (!running) this.animations.delete(a);\n }\n return ran;\n }\n\n /** True while any animation is active (drives rAF re-arming). */\n get active(): boolean {\n return this.animations.size > 0;\n }\n\n /** Cancel every animation (no final state, no onDone). Used on teardown. */\n cancelAll(): void {\n const snapshot = [...this.animations];\n this.animations.clear();\n for (const a of snapshot) a.cancel();\n }\n\n /** Finish every animation (snap to final, fire onDone). Used before update(). */\n finishAll(): void {\n const snapshot = [...this.animations];\n this.animations.clear();\n for (const a of snapshot) a.finish();\n }\n}\n","/**\n * Spatial index for fast node hit-testing.\n *\n * Wraps d3-quadtree to provide findNearest (accounts for node radius)\n * and findInRect queries. Tracks a generation counter to avoid unnecessary\n * rebuilds when positions haven't changed.\n */\n\nimport { type Quadtree, quadtree } from 'd3-quadtree';\n\n/** Minimum shape a spatial-index entry must have. */\nexport interface SpatialEntry {\n x: number;\n y: number;\n radius: number;\n}\n\nexport class SpatialIndex<T extends SpatialEntry = SpatialEntry> {\n private tree: Quadtree<T> | null = null;\n private nodes: T[] = [];\n private maxRadius = 0;\n private generation = 0;\n\n /** Rebuild the quadtree from the current set of positioned nodes. */\n rebuild(nodes: T[]): void {\n this.nodes = nodes;\n this.maxRadius = 0;\n for (const n of nodes) {\n if (n.radius > this.maxRadius) this.maxRadius = n.radius;\n }\n\n this.tree = quadtree<T>()\n .x((d) => d.x)\n .y((d) => d.y)\n .addAll(nodes);\n this.generation++;\n }\n\n /** Current generation counter. Increments on each rebuild. */\n getGeneration(): number {\n return this.generation;\n }\n\n /**\n * Find the nearest node to (x, y) within maxDistance.\n * Accounts for node radius: a hit occurs if the point is inside\n * the node circle (distance to center < node.radius), or if the\n * edge-to-edge distance is within maxDistance.\n */\n findNearest(x: number, y: number, maxDistance: number = Infinity): T | null {\n if (!this.tree || this.nodes.length === 0) return null;\n\n // The effective search radius for the quadtree needs to include\n // the largest node radius, because we might be \"inside\" a large node\n // whose center is far from our search point.\n const searchRadius = maxDistance + this.maxRadius;\n\n let best: T | null = null;\n let bestEffectiveDist = maxDistance + this.maxRadius + 1;\n\n this.tree.visit((node, x0, y0, x1, y1) => {\n // Closest point in this quad to our target\n const closestX = Math.max(x0, Math.min(x, x1));\n const closestY = Math.max(y0, Math.min(y, y1));\n const quadDist = Math.hypot(closestX - x, closestY - y);\n\n // Prune: if the closest edge of this quad is beyond searchRadius, skip\n if (quadDist > searchRadius) return true;\n\n // Check leaf data\n if (!node.length) {\n let current = node;\n do {\n const d = current.data;\n if (d) {\n const dist = Math.hypot(d.x - x, d.y - y);\n // Effective distance: subtract the node's radius.\n // If we're inside the circle, effective distance is 0.\n const effectiveDist = Math.max(0, dist - d.radius);\n if (effectiveDist <= maxDistance && effectiveDist < bestEffectiveDist) {\n bestEffectiveDist = effectiveDist;\n best = d;\n }\n }\n } while ((current = current.next!));\n }\n\n return false;\n });\n\n return best;\n }\n\n /** Find all nodes whose centers fall within the given rectangle. */\n findInRect(x1: number, y1: number, x2: number, y2: number): T[] {\n if (!this.tree) return [];\n\n const minX = Math.min(x1, x2);\n const minY = Math.min(y1, y2);\n const maxX = Math.max(x1, x2);\n const maxY = Math.max(y1, y2);\n\n const results: T[] = [];\n\n this.tree.visit((node, qx0, qy0, qx1, qy1) => {\n // If quad doesn't overlap the search rect, skip\n if (qx0 > maxX || qx1 < minX || qy0 > maxY || qy1 < minY) {\n return true;\n }\n\n // Check leaf nodes\n if (!node.length) {\n let current = node;\n do {\n const d = current.data;\n if (d && d.x >= minX && d.x <= maxX && d.y >= minY && d.y <= maxY) {\n results.push(d);\n }\n } while ((current = current.next!));\n }\n\n return false;\n });\n\n return results;\n }\n}\n","/**\n * Canvas motion primitives: easings, reduced-motion detection, and a generic\n * time-based tween.\n *\n * Canvas marks animate via a rAF scheduler (see scheduler.ts), NOT via CSS\n * keyframes like SVG charts. Only the easing vocabulary is shared with charts\n * (`'smooth'` / `'snappy'`). No `d3-ease` dependency — easings are hand-rolled,\n * matching `transition.ts`'s `cubicOut`.\n */\n\nimport type { AnimationEase } from '@opendata-ai/openchart-core';\nimport { cubicInOut, cubicOut } from './easing';\nimport type { Animation } from './scheduler';\n\n// ---------------------------------------------------------------------------\n// Easings (shared definitions live in easing.ts; re-exported for callers)\n// ---------------------------------------------------------------------------\n\nexport { cubicInOut, cubicOut, linear } from './easing';\n\n/** Resolve a named ease preset to an easing function. */\nexport function resolveEase(ease: AnimationEase): (t: number) => number {\n return ease === 'snappy' ? cubicOut : cubicInOut;\n}\n\n// ---------------------------------------------------------------------------\n// Reduced motion\n// ---------------------------------------------------------------------------\n\n/**\n * Whether the user prefers reduced motion. Mirrors `transition.ts`: guards\n * SSR/happy-dom where matchMedia may be missing or throw.\n */\nexport function prefersReducedMotion(): boolean {\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return false;\n try {\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n } catch {\n return false;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Tween\n// ---------------------------------------------------------------------------\n\n/** Options for {@link createTween}. */\nexport interface TweenOptions {\n /** Duration in ms. A duration <= 0 completes on the first tick. */\n duration: number;\n /** Easing function applied to the normalized 0..1 progress. */\n ease: (t: number) => number;\n /** Called each tick with the eased progress. */\n apply: (t: number) => void;\n /** Called once when the tween completes (not on cancel). */\n onDone?: () => void;\n}\n\n/**\n * Create a time-based tween as an {@link Animation}.\n *\n * The start time locks on the FIRST `tick(now)` call (not at construction), so\n * a tween added while the scheduler is idle starts cleanly on the next frame\n * and tests get deterministic progress from a controllable clock.\n */\nexport function createTween(opts: TweenOptions): Animation {\n const { duration, ease, apply, onDone } = opts;\n let startTime: number | null = null;\n let finished = false;\n\n function settleAt(t: number): void {\n apply(ease(t));\n }\n\n return {\n tick(now: number): boolean {\n if (finished) return false;\n if (startTime === null) startTime = now;\n const elapsed = now - startTime;\n const raw = duration <= 0 ? 1 : Math.min(1, elapsed / duration);\n settleAt(raw);\n if (raw >= 1) {\n finished = true;\n onDone?.();\n return false;\n }\n return true;\n },\n finish(): void {\n if (finished) return;\n finished = true;\n settleAt(1);\n onDone?.();\n },\n cancel(): void {\n finished = true;\n },\n };\n}\n"],"mappings":";;;;;;AAQA,IAAM,cAAc;AASb,SAAS,cACd,WACA,UACY;AACZ,MAAI,YAAkD;AACtD,MAAI,gBAA0D;AAE9D,QAAM,WAAW,IAAI,eAAe,CAAC,YAAY;AAE/C,QAAI,cAAc,MAAM;AACtB,mBAAa,SAAS;AAAA,IACxB;AACA,gBAAY,WAAW,MAAM;AAC3B,iBAAW,SAAS,SAAS;AAC3B,cAAM,EAAE,OAAO,OAAO,IAAI,MAAM;AAIhC,YAAI,iBAAiB,cAAc,UAAU,SAAS,cAAc,WAAW,QAAQ;AACrF;AAAA,QACF;AACA,wBAAgB,EAAE,OAAO,OAAO;AAChC,iBAAS,OAAO,MAAM;AAAA,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