expressive-charts 0.1.0 → 0.3.0

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 (36) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +14 -13
  3. package/dist/{chunk-N5IF2RO2.js → chunk-7A7LXXT4.js} +6 -2
  4. package/dist/chunk-7A7LXXT4.js.map +1 -0
  5. package/dist/{chunk-ZIGBM4NY.js → chunk-CJUQHEX6.js} +92 -28
  6. package/dist/chunk-CJUQHEX6.js.map +1 -0
  7. package/dist/{chunk-CVXP2L2J.js → chunk-N2BLUETM.js} +17 -5
  8. package/dist/chunk-N2BLUETM.js.map +1 -0
  9. package/dist/{drawing-Du6DAgrW.d.cts → drawing-CdTgixMY.d.cts} +20 -2
  10. package/dist/{drawing-Du6DAgrW.d.ts → drawing-CdTgixMY.d.ts} +20 -2
  11. package/dist/{effect-dPmXiWlL.d.cts → effect-Bu3MHHeg.d.ts} +4 -2
  12. package/dist/{effect-OcyvtfZi.d.ts → effect-D4vmdYP4.d.cts} +4 -2
  13. package/dist/expressive-charts.css +11 -6
  14. package/dist/expressive-charts.css.d.cts +2 -0
  15. package/dist/expressive-charts.css.d.ts +2 -0
  16. package/dist/expressive-charts.global.js +29 -24
  17. package/dist/expressive-charts.global.js.map +1 -1
  18. package/dist/icons/sport.cjs +5 -1
  19. package/dist/icons/sport.cjs.map +1 -1
  20. package/dist/icons/sport.js +2 -2
  21. package/dist/index.cjs +1610 -669
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +143 -18
  24. package/dist/index.d.ts +143 -18
  25. package/dist/index.js +1448 -591
  26. package/dist/index.js.map +1 -1
  27. package/dist/testing.cjs +93 -42
  28. package/dist/testing.cjs.map +1 -1
  29. package/dist/testing.d.cts +2 -2
  30. package/dist/testing.d.ts +2 -2
  31. package/dist/testing.js +6 -8
  32. package/dist/testing.js.map +1 -1
  33. package/package.json +16 -4
  34. package/dist/chunk-CVXP2L2J.js.map +0 -1
  35. package/dist/chunk-N5IF2RO2.js.map +0 -1
  36. package/dist/chunk-ZIGBM4NY.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/report.ts","../src/core/clock.ts","../src/core/easing.ts","../src/core/motion.ts","../src/core/tween.ts","../src/core/animated.ts","../src/core/playback.ts","../src/core/registry.ts","../src/core/merge.ts","../src/core/runner.ts","../src/core/transition.ts"],"sourcesContent":["/**\n * Surface an error without interrupting the caller, so one failing frame\n * callback or listener can't stop the others. Uses the platform's\n * `reportError` (shows up as an uncaught error) where it exists.\n */\nexport function report(error: unknown): void {\n const platform = (globalThis as { reportError?: (error: unknown) => void }).reportError;\n if (typeof platform === \"function\") platform(error);\n else console.error(error);\n}\n","import { report } from \"./report\";\n\n/** Where frames come from. The default uses requestAnimationFrame, or a 16 ms timer outside the browser. */\nexport interface FrameSource {\n now(): number;\n /** Ask for one callback on the next frame. Returns a function that cancels it. */\n request(callback: (now: number) => void): () => void;\n}\n\nexport interface Clock {\n now(): number;\n /** Call `callback` on every frame until the returned function is called. */\n onFrame(callback: (now: number) => void): () => void;\n}\n\n/** A clock that only moves when told to. For tests. */\nexport interface ManualClock extends Clock {\n /** Move time forward by `ms` and run one frame at the new time. */\n advance(ms: number): void;\n /** True when nothing is waiting for a frame. */\n readonly idle: boolean;\n}\n\n/**\n * One shared frame loop. It requests a frame only while something is\n * subscribed, so an idle page costs nothing.\n */\nexport function createClock(source: FrameSource = browserFrames()): Clock {\n const callbacks = new Set<(now: number) => void>();\n let cancelFrame: (() => void) | undefined;\n\n const schedule = (): void => {\n if (!cancelFrame && callbacks.size > 0) cancelFrame = source.request(tick);\n };\n\n const tick = (now: number): void => {\n cancelFrame = undefined;\n // Copy so callbacks can subscribe or unsubscribe while we iterate.\n for (const callback of [...callbacks]) {\n if (!callbacks.has(callback)) continue;\n try {\n callback(now);\n } catch (error) {\n report(error);\n }\n }\n schedule();\n };\n\n return {\n now: () => source.now(),\n onFrame(callback) {\n // Wrap so the same function can be subscribed twice and unsubscribed independently.\n const entry = (now: number): void => callback(now);\n callbacks.add(entry);\n schedule();\n return () => {\n if (!callbacks.delete(entry)) return;\n if (callbacks.size === 0 && cancelFrame) {\n cancelFrame();\n cancelFrame = undefined;\n }\n };\n }\n };\n}\n\nexport function manualClock(start = 0): ManualClock {\n let time = start;\n let pending: ((now: number) => void) | undefined;\n\n const clock = createClock({\n now: () => time,\n request(callback) {\n pending = callback;\n return () => {\n if (pending === callback) pending = undefined;\n };\n }\n });\n\n return {\n now: clock.now,\n onFrame: clock.onFrame,\n get idle() {\n return pending === undefined;\n },\n advance(ms) {\n if (!(ms >= 0)) throw new RangeError(`manualClock.advance needs a non-negative number of ms, got ${ms}`);\n time += ms;\n const callback = pending;\n pending = undefined;\n callback?.(time);\n }\n };\n}\n\n// Looks up browser APIs when a frame is requested, never at import time, so Node can import the library.\nfunction browserFrames(): FrameSource {\n const now = (): number => (typeof performance !== \"undefined\" ? performance.now() : Date.now());\n return {\n now,\n request(callback) {\n if (typeof requestAnimationFrame === \"function\") {\n const id = requestAnimationFrame(callback);\n return () => cancelAnimationFrame(id);\n }\n const id = setTimeout(() => callback(now()), 16);\n return () => clearTimeout(id);\n }\n };\n}\n\n/** The page-wide clock every tween uses unless given another. */\nexport const defaultClock: Clock = /* @__PURE__ */ createClock();\n","/** Maps linear progress (0–1) to eased progress. Any function of this shape works. */\nexport type Easing = (t: number) => number;\n\n/** For playback, where speed should stay constant. */\nexport const linear: Easing = (t) => t;\n\n/** For data transitions: starts and ends gently. */\nexport const easeInOutCubic: Easing = (t) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2);\n\n/** For travel, and for animations retargeted mid-flight: starts at speed, settles gently. */\nexport const easeOutCubic: Easing = (t) => 1 - Math.pow(1 - t, 3);\n\n/**\n * The linear progress at which easeInOutCubic reaches s: its inverse. Internal. A run that starts part\n * way, from shapes already at s, takes the rest of a full run's time from here, as morph and a chart\n * switch do.\n */\nexport function unease(s: number): number {\n return s < 0.5 ? Math.cbrt(s / 4) : 1 - Math.cbrt(2 * (1 - s)) / 2;\n}\n","import { report } from \"./report\";\n\nexport type MotionMode = \"presentation\" | \"analysis\" | \"off\";\n\n/** What a duration is for. Each kind scales differently by mode. */\nexport type Timing = \"feedback\" | \"transition\" | \"effect\" | \"playback\" | \"stagger\";\n\n/** Base ms × factor, clamped to [min(base, min), max]. A floor never makes an animation longer than its base. */\nexport interface ScalingRule {\n readonly factor: number;\n readonly min?: number;\n readonly max?: number;\n}\n\ntype ScaledMode = Exclude<MotionMode, \"off\">;\n\nexport type ScalingTable = { readonly [M in ScaledMode]: { readonly [T in Timing]: ScalingRule } };\nexport type ScalingOverrides = { readonly [M in ScaledMode]?: { readonly [T in Timing]?: ScalingRule } };\n\n/** Starting values from the prototype; tuned in the demos. Off is always 0. */\nexport const defaultScaling: ScalingTable = {\n presentation: {\n feedback: { factor: 1 },\n transition: { factor: 1 },\n effect: { factor: 1 },\n playback: { factor: 1 },\n stagger: { factor: 1 }\n },\n analysis: {\n feedback: { factor: 1 },\n transition: { factor: 0.35, max: 200 },\n effect: { factor: 0.35, min: 140, max: 300 },\n playback: { factor: 0.3 },\n // Analysis has no staging, so marks don't wait for each other.\n stagger: { factor: 0 }\n }\n};\n\n/** What charts and effects need from the motion system. */\nexport interface MotionView {\n /** The effective mode, after the reduced-motion rule. */\n readonly mode: MotionMode;\n /** True only in presentation: split data changes into stages. */\n readonly staged: boolean;\n /** Scale a base duration (ms) for the current mode. 0 means \"jump to the end\". */\n duration(base: number, timing?: Timing): number;\n}\n\nexport interface Motion extends MotionView {\n /** The mode the page author asked for. */\n readonly requested: MotionMode;\n /** The mode the viewer picked in an on-page control, if any. */\n readonly viewerChoice: MotionMode | undefined;\n /** Live value of `prefers-reduced-motion: reduce`. */\n readonly prefersReduced: boolean;\n /** The author's default. Never overrides reduced motion. */\n setMode(mode: MotionMode): void;\n /** The viewer's explicit choice from an on-page control. Overrides reduced motion. */\n chooseMode(mode: MotionMode): void;\n /** Forget the viewer's choice and follow the author's mode and the device setting again. */\n clearChoice(): void;\n /** Called whenever the mode, the viewer's choice or the device setting changes. */\n subscribe(listener: () => void): () => void;\n}\n\n/** A live reduced-motion preference. */\nexport interface ReducedMotionSource {\n readonly matches: boolean;\n subscribe(listener: () => void): () => void;\n}\n\nexport interface MotionOptions {\n /** The author's mode. Default \"presentation\". */\n readonly mode?: MotionMode;\n readonly scaling?: ScalingOverrides;\n /** Default: the `prefers-reduced-motion` media query. */\n readonly reducedMotion?: ReducedMotionSource;\n}\n\nconst MODES: readonly MotionMode[] = [\"presentation\", \"analysis\", \"off\"];\n/** Every timing, for checking options. Internal: not exported from core's index. */\nexport const TIMINGS: readonly Timing[] = [\"feedback\", \"transition\", \"effect\", \"playback\", \"stagger\"];\n\nexport function createMotion(options: MotionOptions = {}): Motion {\n let requested = checkMode(options.mode ?? \"presentation\");\n let viewerChoice: MotionMode | undefined;\n const scaling = mergeScaling(options.scaling);\n const reduced = options.reducedMotion ?? mediaReducedMotion();\n const listeners = new Set<() => void>();\n let stopWatching: (() => void) | undefined;\n\n const effective = (): MotionMode => viewerChoice ?? (reduced.matches ? \"off\" : requested);\n\n const notify = (): void => {\n for (const listener of [...listeners]) {\n if (!listeners.has(listener)) continue;\n try {\n listener();\n } catch (error) {\n report(error);\n }\n }\n };\n\n return {\n get mode() {\n return effective();\n },\n get staged() {\n return effective() === \"presentation\";\n },\n get requested() {\n return requested;\n },\n get viewerChoice() {\n return viewerChoice;\n },\n get prefersReduced() {\n return reduced.matches;\n },\n duration(base, timing = \"transition\") {\n const mode = effective();\n return mode === \"off\" ? 0 : scaleDuration(base, scaling[mode][timing]);\n },\n setMode(mode) {\n checkMode(mode);\n if (mode === requested) return;\n requested = mode;\n notify();\n },\n chooseMode(mode) {\n checkMode(mode);\n if (mode === viewerChoice) return;\n viewerChoice = mode;\n notify();\n },\n clearChoice() {\n if (viewerChoice === undefined) return;\n viewerChoice = undefined;\n notify();\n },\n subscribe(listener) {\n const entry = (): void => listener();\n listeners.add(entry);\n // Only watch the media query while someone is listening.\n stopWatching ??= reduced.subscribe(notify);\n return () => {\n if (!listeners.delete(entry) || listeners.size > 0) return;\n stopWatching?.();\n stopWatching = undefined;\n };\n }\n };\n}\n\nexport function scaleDuration(base: number, rule: ScalingRule): number {\n if (!(base > 0)) return 0;\n const floor = Math.min(base, rule.min ?? 0);\n const ceiling = rule.max ?? Infinity;\n return Math.min(Math.max(base * rule.factor, floor), ceiling);\n}\n\n/** Reads `prefers-reduced-motion` lazily: nothing touches the DOM until `matches` is read or someone subscribes. */\nexport function mediaReducedMotion(query = \"(prefers-reduced-motion: reduce)\"): ReducedMotionSource {\n let list: MediaQueryList | null | undefined;\n const lookup = (): MediaQueryList | null => {\n if (list === undefined) {\n try {\n list = typeof matchMedia === \"function\" ? matchMedia(query) : null;\n } catch {\n list = null;\n }\n }\n return list;\n };\n\n return {\n get matches() {\n return lookup()?.matches ?? false;\n },\n subscribe(listener) {\n const media = lookup();\n if (!media) return () => {};\n const onChange = (): void => listener();\n if (typeof media.addEventListener === \"function\") {\n media.addEventListener(\"change\", onChange);\n return () => media.removeEventListener(\"change\", onChange);\n }\n // Safari before 14.\n media.addListener(onChange);\n return () => media.removeListener(onChange);\n }\n };\n}\n\nfunction checkMode(mode: MotionMode): MotionMode {\n if (!MODES.includes(mode)) {\n throw new TypeError(`Unknown motion mode \"${String(mode)}\". Use one of: ${MODES.join(\", \")}.`);\n }\n return mode;\n}\n\nfunction mergeScaling(overrides: ScalingOverrides = {}): ScalingTable {\n const merge = (mode: ScaledMode): Record<Timing, ScalingRule> => {\n const table: Record<Timing, ScalingRule> = { ...defaultScaling[mode] };\n for (const timing of TIMINGS) {\n const rule = overrides[mode]?.[timing];\n if (rule) table[timing] = rule;\n }\n return table;\n };\n return { presentation: merge(\"presentation\"), analysis: merge(\"analysis\") };\n}\n\n/** The page-wide motion every chart follows unless given its own. */\nexport const motion: Motion = /* @__PURE__ */ createMotion();\n","import { defaultClock, type Clock } from \"./clock\";\nimport { easeInOutCubic, type Easing } from \"./easing\";\nimport { motion, type MotionView, type Timing } from \"./motion\";\n\n/** The clock and motion settings an animation runs against. */\nexport interface MotionEnv {\n readonly clock: Clock;\n readonly motion: MotionView;\n}\n\nexport interface TweenOptions {\n /** Base duration in ms, scaled by the motion mode. */\n readonly duration: number;\n /** Default \"transition\". */\n readonly timing?: Timing;\n /** Default easeInOutCubic. */\n readonly ease?: Easing;\n /** Base delay in ms before progress starts, scaled like the duration. */\n readonly delay?: number;\n /** Called with eased progress: once with ease(0) at the start, then every frame, then with ease(1) at the end. */\n readonly update: (progress: number) => void;\n readonly signal?: AbortSignal;\n}\n\nexport type TweenResult = \"done\" | \"cancelled\";\n\nexport interface Tween {\n /** Resolves when the tween ends. Never rejects. */\n readonly finished: Promise<TweenResult>;\n readonly state: \"running\" | TweenResult;\n /** Stop where it is. */\n cancel(): void;\n /** Jump to the end now. */\n finish(): void;\n}\n\n/**\n * Animate progress from 0 to 1. If the motion mode scales the duration to 0,\n * `update(ease(1))` runs synchronously, before `tween` returns. If the mode\n * turns off while the tween runs, it jumps to the end on the next frame.\n */\nexport function tween(options: TweenOptions, env: Partial<MotionEnv> = {}): Tween {\n const clock = env.clock ?? defaultClock;\n const view = env.motion ?? motion;\n const timing = options.timing ?? \"transition\";\n const ease = options.ease ?? easeInOutCubic;\n const duration = view.duration(options.duration, timing);\n const delay = options.delay ? view.duration(options.delay, timing) : 0;\n const { update, signal } = options;\n const start = clock.now();\n\n let state: Tween[\"state\"] = \"running\";\n let unsubscribe: (() => void) | undefined;\n let resolve!: (result: TweenResult) => void;\n const finished = new Promise<TweenResult>((r) => {\n resolve = r;\n });\n\n const settle = (result: TweenResult): void => {\n state = result;\n unsubscribe?.();\n unsubscribe = undefined;\n signal?.removeEventListener(\"abort\", cancel);\n resolve(result);\n };\n\n function cancel(): void {\n if (state === \"running\") settle(\"cancelled\");\n }\n\n // True while the final update runs, so an update that calls finish() can't recurse.\n let finishing = false;\n\n function finish(): void {\n if (state !== \"running\" || finishing) return;\n finishing = true;\n step(1);\n // `update` may have cancelled the tween itself.\n if (state === \"running\") settle(\"done\");\n }\n\n // Runs `update` and cancels the tween if it throws: a broken callback is reported once instead of\n // every frame, and `finished` never says \"done\" when the last update failed.\n function step(progress: number): void {\n try {\n update(ease(progress));\n } catch (error) {\n cancel();\n throw error;\n }\n }\n\n const onFrame = (now: number): void => {\n // The effective mode can turn off mid-flight (the device switches to reduced motion, or the\n // viewer picks Off). Every animation then jumps to its end state.\n if (view.mode === \"off\") {\n finish();\n return;\n }\n const elapsed = now - start - delay;\n if (elapsed >= duration) finish();\n else if (elapsed > 0) step(elapsed / duration);\n };\n\n const handle: Tween = {\n finished,\n get state() {\n return state;\n },\n cancel,\n finish\n };\n\n if (signal?.aborted) {\n settle(\"cancelled\");\n return handle;\n }\n signal?.addEventListener(\"abort\", cancel, { once: true });\n\n if (duration <= 0 && delay <= 0) {\n finish();\n return handle;\n }\n step(0);\n if (state === \"running\") unsubscribe = clock.onFrame(onFrame);\n return handle;\n}\n","import type { Point } from \"./contracts/geometry\";\nimport { easeInOutCubic, easeOutCubic, type Easing } from \"./easing\";\nimport type { Timing } from \"./motion\";\nimport { tween, type MotionEnv, type Tween, type TweenResult } from \"./tween\";\n\n/** Builds a function that blends `from` into `to` as t goes from 0 to 1. */\nexport type Interpolator<T> = (from: T, to: T) => (t: number) => T;\n\n/** Exact at both ends, so a finished animation lands on its target. */\nexport const interpolateNumber: Interpolator<number> = (a, b) => (t) => a * (1 - t) + b * t;\n\nexport const interpolatePoint: Interpolator<Point> = (a, b) => (t) => ({\n x: a.x * (1 - t) + b.x * t,\n y: a.y * (1 - t) + b.y * t\n});\n\n/**\n * Blends every key. A key missing on one side counts as 0 there, so a series\n * that appears grows from 0, and one that disappears shrinks to 0 and is gone at t = 1.\n */\nexport function interpolateRecord<K extends string>(\n a: Readonly<Record<K, number>>,\n b: Readonly<Record<K, number>>\n): (t: number) => Record<K, number> {\n const keys = [...new Set([...Object.keys(a), ...Object.keys(b)])] as K[];\n return (t) => {\n if (t === 1) return { ...b };\n const out = {} as Record<K, number>;\n for (const key of keys) out[key] = (a[key] ?? 0) * (1 - t) + (b[key] ?? 0) * t;\n return out;\n };\n}\n\nexport interface AnimateOptions {\n /** Base duration in ms, scaled by the motion mode. */\n readonly duration: number;\n /** Default \"transition\". */\n readonly timing?: Timing;\n /** Default easeInOutCubic, or easeOutCubic when this interrupts a moving value and starts at once (no delay). */\n readonly ease?: Easing;\n readonly delay?: number;\n readonly signal?: AbortSignal;\n}\n\nexport interface AnimatedOptions<T> extends Partial<MotionEnv> {\n /** Called whenever the value changes, including every animation frame. */\n readonly onChange?: (value: T) => void;\n}\n\n/** A value that can be retargeted mid-flight. */\nexport interface Animated<T> {\n /** The current value, in between while animating. */\n readonly value: T;\n /** Where the value is heading (equal to `value` when at rest). */\n readonly target: T;\n readonly animating: boolean;\n /** Animate from the current value, cancelling any animation already running. */\n to(target: T, options: AnimateOptions): Promise<TweenResult>;\n /** Jump to a value, cancelling any running animation. */\n set(value: T): void;\n /** Stop where it is; the current value becomes the target. */\n stop(): void;\n}\n\nexport function animated<T>(initial: T, interpolate: Interpolator<T>, options: AnimatedOptions<T> = {}): Animated<T> {\n const { onChange, ...env } = options;\n let value = initial;\n let target = initial;\n let running: Tween | undefined;\n /** The running animation is past its delay: its value is on the move. */\n let moving = false;\n\n const assign = (next: T): void => {\n value = next;\n onChange?.(next);\n };\n\n const halt = (): void => {\n const current = running;\n running = undefined;\n moving = false;\n current?.cancel();\n };\n\n return {\n get value() {\n return value;\n },\n get target() {\n // Cancelled from outside (its signal aborted, or onChange threw): it's at rest where it stopped.\n return running?.state === \"cancelled\" ? value : target;\n },\n get animating() {\n return running?.state === \"running\";\n },\n to(next, animate) {\n // Restarting an ease-in-out from a moving value would stall; ease out instead. A value still\n // waiting out a delay isn't moving, and one told to wait first starts from rest anyway.\n const interrupted = running?.state === \"running\" && moving && !(animate.delay && animate.delay > 0);\n halt();\n target = next;\n const blend = interpolate(value, next);\n // The tween's first update is its start value; any later one means it's past its delay.\n let started = false;\n const current = tween(\n {\n duration: animate.duration,\n timing: animate.timing,\n ease: animate.ease ?? (interrupted ? easeOutCubic : easeInOutCubic),\n delay: animate.delay,\n signal: animate.signal,\n update: (progress) => {\n if (started) moving = true;\n started = true;\n assign(blend(progress));\n }\n },\n env\n );\n // Kept even if already settled, so `target` can tell an outside cancellation from a finish.\n running = current;\n return current.finished;\n },\n set(next) {\n halt();\n target = next;\n assign(next);\n },\n stop() {\n halt();\n target = value;\n }\n };\n}\n","// playback: a clock-driven controller for anything that plays through a range of values, such as a season\n// revealed week by week. It owns a position and moves it; the page draws each position in onFrame. It has\n// no DOM: playButton() (src/charts/controls) and the page's own scrubber drive it.\n\nimport { defaultClock } from \"./clock\";\nimport { easeInOutCubic, easeOutCubic, linear, type Easing } from \"./easing\";\nimport { motion as pageMotion, TIMINGS, type Timing } from \"./motion\";\nimport { report } from \"./report\";\nimport type { MotionEnv } from \"./tween\";\n\nexport interface PlaybackOptions extends Partial<MotionEnv> {\n /** Where a play starts again once it's at the end. */\n readonly from: number;\n /** Where a play ends. The playback starts here, at rest, as a chart shows all its data until something reveals less. */\n readonly to: number;\n /** Base ms for a play from `from` to `to`, scaled by `timing`. A play from part way takes its share, so the speed stays the same. */\n readonly duration: number;\n /** How a play moves. Default linear: constant speed. Seeks ease on their own. */\n readonly ease?: Easing;\n /** Default \"playback\": ×1 in Presentation, ×0.3 in Analysis, a jump in Off. */\n readonly timing?: Timing;\n /** Draws a position. Called whenever the position changes: every frame of a play or a seek, and every jump. */\n readonly onFrame: (position: number) => void;\n}\n\n/** What `subscribe` hears. Frames go to `onFrame` instead. */\nexport type PlaybackEvent = \"play\" | \"pause\" | \"end\" | \"seek\";\n\nexport interface SeekOptions {\n /** Default true: move over 350 ms base transition timing (at most 200 ms in Analysis, a jump in Off). false jumps. */\n readonly animate?: boolean;\n}\n\nexport interface Playback {\n /** Plays on from where it is to `to`, or from `from` when it's at the end. Does nothing while playing. */\n play(): void;\n /** Stops a play where it is. Does nothing unless it's playing, so a seek on its way still lands. */\n pause(): void;\n /** Pauses, and moves to `x`, clamped to the range. A seek while it's moving starts from where it is. */\n seek(x: number, options?: SeekOptions): void;\n /** Where it is now, in between while it moves. */\n readonly position: number;\n /** True from `play()` until a pause, a seek or the end. */\n readonly playing: boolean;\n /** Hears play, pause, the end and seeks, not every frame. Returns a function that stops listening. */\n subscribe(listener: (event: PlaybackEvent) => void): () => void;\n /** Pauses it, if it's playing, and stops it for good: later calls do nothing. */\n destroy(): void;\n}\n\n/** The lab's scrubber: a seek takes 350 ms base, with \"transition\" timing. */\nconst SEEK_MS = 350;\n\n/** A move under way: a play or a seek. `moved` once a frame has moved it, so a retarget eases out. */\ninterface Move {\n moved: boolean;\n readonly stop: () => void;\n}\n\n/**\n * A playback through `from`…`to`. `play()` moves the position at constant speed (with the default\n * `linear`), over `duration` scaled by the motion mode, and `onFrame` draws each position. With motion\n * off, a play jumps to the end, and motion turning off mid-play jumps there too, as tweens do. Nothing\n * plays by itself. Uses the page-wide motion and clock unless given its own.\n */\nexport function playback(options: PlaybackOptions): Playback {\n checkOptions(options);\n const { from, to, duration, onFrame } = options;\n const ease = options.ease ?? linear;\n const timing = options.timing ?? \"playback\";\n const clock = options.clock ?? defaultClock;\n const view = options.motion ?? pageMotion;\n const low = Math.min(from, to);\n const high = Math.max(from, to);\n\n let position = to;\n let playing = false;\n let destroyed = false;\n let move: Move | undefined;\n // Bumped by every play, pause, seek and destroy. Anything that calls out (to onFrame or a listener)\n // checks it afterwards, so it stops if that call started something else.\n let generation = 0;\n const listeners = new Set<(event: PlaybackEvent) => void>();\n\n const notify = (event: PlaybackEvent): void => {\n for (const listener of [...listeners]) {\n if (!listeners.has(listener)) continue;\n try {\n listener(event);\n } catch (error) {\n report(error);\n }\n }\n };\n\n /** Stops the move under way, where it is. True if it had moved. */\n const halt = (): boolean => {\n const current = move;\n move = undefined;\n current?.stop();\n return current?.moved ?? false;\n };\n\n /** Ends a play that didn't reach the end: halted by a pause, a seek, destroy(), or a failing onFrame or ease. */\n const stopPlaying = (): void => {\n if (!playing) return;\n playing = false;\n notify(\"pause\");\n };\n\n // When the page's onFrame or ease throws, everything stops where it is and the error goes on to the\n // caller (or to the clock, which reports it), so a broken callback is reported once rather than every frame.\n const fail = (error: unknown): never => {\n generation++;\n halt();\n stopPlaying();\n throw error;\n };\n\n /** Draws a new position. */\n const assign = (x: number): void => {\n if (x === position) return;\n position = x;\n try {\n onFrame(x);\n } catch (error) {\n fail(error);\n }\n };\n\n /** Moves to `target` over `ms`, eased, then calls `landed`. 0 ms jumps, before it returns. */\n const glide = (target: number, ms: number, curve: Easing, landed: () => void): void => {\n const mine = generation;\n if (!(ms > 0)) {\n assign(target);\n if (generation === mine) landed();\n return;\n }\n const origin = position;\n const start = clock.now();\n const current: Move = {\n moved: false,\n stop: clock.onFrame((now) => {\n // The effective mode can turn off mid-move (the device switches to reduced motion, or the\n // viewer picks Off). The move then jumps to its end, as tweens do.\n const t = view.mode === \"off\" ? 1 : (now - start) / ms;\n if (t < 1) {\n current.moved = true;\n let progress: number;\n try {\n progress = curve(t);\n } catch (error) {\n return fail(error);\n }\n assign(origin + (target - origin) * progress);\n return;\n }\n halt();\n assign(target);\n if (generation === mine) landed();\n })\n };\n move = current;\n };\n\n const landedAtEnd = (): void => {\n playing = false;\n notify(\"end\");\n };\n\n return {\n get position() {\n return position;\n },\n get playing() {\n return playing;\n },\n play() {\n if (destroyed || playing) return;\n const mine = ++generation;\n halt();\n playing = true;\n notify(\"play\");\n if (generation !== mine) return;\n // Scaled once for the whole range, then shared out, so a play from part way keeps the same speed.\n const whole = view.duration(duration, timing);\n // At the end, a play starts again from `from`. With motion off it just shows the end, which is already there.\n if (whole > 0 && position === to) {\n assign(from);\n if (generation !== mine) return;\n }\n glide(to, (whole * Math.abs(to - position)) / Math.abs(to - from), ease, landedAtEnd);\n },\n pause() {\n if (destroyed || !playing) return;\n generation++;\n halt();\n stopPlaying();\n },\n seek(x, seekOptions = {}) {\n checkSeek(x, seekOptions);\n if (destroyed) return;\n const mine = ++generation;\n const moving = halt();\n stopPlaying();\n if (generation !== mine) return;\n notify(\"seek\");\n if (generation !== mine) return;\n const ms = seekOptions.animate === false ? 0 : view.duration(SEEK_MS, \"transition\");\n // Retargeting a moving position eases out, so the motion doesn't stall; from rest it eases in and\n // out. The same rule as animated values.\n glide(Math.min(Math.max(x, low), high), ms, moving ? easeOutCubic : easeInOutCubic, () => {});\n },\n subscribe(listener) {\n if (typeof listener !== \"function\") throw new TypeError(`playback.subscribe needs a function, got ${typeof listener}.`);\n if (destroyed) return () => {};\n // Wrapped so the same function can be subscribed twice and unsubscribed independently.\n const entry = (event: PlaybackEvent): void => listener(event);\n listeners.add(entry);\n return () => {\n listeners.delete(entry);\n };\n },\n destroy() {\n if (destroyed) return;\n destroyed = true;\n generation++;\n halt();\n // Heard before the listeners go, so a play button still on the page goes back to Play.\n stopPlaying();\n listeners.clear();\n }\n };\n}\n\nfunction checkOptions(options: PlaybackOptions): void {\n if (typeof options !== \"object\" || options === null) {\n throw new TypeError(\"playback needs options: { from, to, duration, onFrame }.\");\n }\n const { from, to, duration, ease, timing, onFrame, clock, motion } = options;\n for (const [name, value] of [[\"from\", from], [\"to\", to]] as const) {\n if (!isFiniteNumber(value)) throw new RangeError(`playback: ${name} must be a finite number, got ${String(value)}.`);\n }\n if (from === to) throw new RangeError(`playback: from and to must differ, got ${from} for both.`);\n if (!isFiniteNumber(duration) || duration < 0) {\n throw new RangeError(`playback: duration must be a non-negative number of ms, got ${String(duration)}.`);\n }\n if (typeof onFrame !== \"function\") throw new TypeError(`playback: onFrame must be a function, got ${typeof onFrame}.`);\n if (ease !== undefined && typeof ease !== \"function\") throw new TypeError(`playback: ease must be a function, got ${typeof ease}.`);\n if (timing !== undefined && !TIMINGS.includes(timing)) {\n throw new RangeError(`playback: timing must be one of ${TIMINGS.join(\", \")}, got ${JSON.stringify(timing) ?? String(timing)}.`);\n }\n if (clock !== undefined && (typeof clock?.now !== \"function\" || typeof clock.onFrame !== \"function\")) {\n throw new TypeError(\"playback: clock must be a Clock, such as one from createClock() or manualClock().\");\n }\n if (motion !== undefined && typeof motion?.duration !== \"function\") {\n throw new TypeError(\"playback: motion must be a Motion, such as the page-wide `motion` or one from createMotion().\");\n }\n}\n\nfunction checkSeek(x: number, options: SeekOptions): void {\n if (!isFiniteNumber(x)) throw new RangeError(`playback.seek needs a finite number, got ${String(x)}.`);\n if (typeof options !== \"object\" || options === null) throw new TypeError(\"playback.seek's options must be an object, such as { animate: false }.\");\n if (options.animate !== undefined && typeof options.animate !== \"boolean\") {\n throw new TypeError(`playback.seek: animate must be true or false, got ${String(options.animate)}.`);\n }\n}\n\nfunction isFiniteNumber(value: unknown): value is number {\n return typeof value === \"number\" && Number.isFinite(value);\n}\n","// Named things charts look up: presets (name → effect factory) and icons. The composition root\n// (src/index.ts) owns the page-wide registries and hands them to charts, so a chart never knows\n// what a name means.\n\nimport type { AnyMarkEffect, MarkEffect } from \"./contracts/effect\";\nimport type { EffectSlot, EffectSlots } from \"./contracts/slots\";\nimport type { SlotEffects } from \"./runner\";\n\nexport interface Registry<T> {\n /** The entry registered under `name`, if any. A Registry<Icon> is an IconSource. */\n get(name: string): T | undefined;\n /** Like get(), but an unknown name throws a RangeError that lists what is registered. */\n resolve(name: string): T;\n /** A later registration under the same name replaces the earlier one. */\n register(name: string, value: T): void;\n /** Registered names, in the order they were first registered. */\n names(): string[];\n}\n\nexport interface RegistryOptions<T> {\n /** What the entries are, for error messages: \"preset\", \"icon\". */\n readonly kind: string;\n readonly entries?: Readonly<Record<string, T>>;\n /** Appended to the unknown-name error, for example how to register one. */\n readonly hint?: string;\n}\n\nexport function createRegistry<T>(options: RegistryOptions<T>): Registry<T> {\n const { kind, hint } = options;\n const entries = new Map<string, T>();\n\n const registry: Registry<T> = {\n get: (name) => entries.get(name),\n resolve(name) {\n const value = entries.get(name);\n if (value !== undefined) return value;\n const known = entries.size > 0 ? [...entries.keys()].join(\", \") : \"none\";\n throw new RangeError(`Unknown ${kind} \"${String(name)}\". Registered ${kind}s: ${known}.${hint ? ` ${hint}` : \"\"}`);\n },\n register(name, value) {\n if (typeof name !== \"string\" || name === \"\") throw new TypeError(`A ${kind} needs a non-empty string name, got ${JSON.stringify(name)}.`);\n if (value === undefined) throw new TypeError(`Registering ${kind} \"${name}\" needs a value.`);\n entries.set(name, value);\n },\n names: () => [...entries.keys()]\n };\n for (const [name, value] of Object.entries(options.entries ?? {})) registry.register(name, value);\n return registry;\n}\n\n/** Makes a fresh effect for a preset name. Presets work on any rows, so they return MarkEffect. */\nexport type PresetFactory = () => MarkEffect;\n\nexport const EFFECT_SLOTS: readonly EffectSlot[] = [\"hover\", \"enter\", \"update\", \"exit\", \"decorate\"];\n\n/**\n * Turns a chart's `on` option into the effects its runner plays: preset names go through `presets`,\n * effects pass through. Charts call it when they're created, so an unknown preset name, a slot that\n * doesn't exist or a transition effect in a mark slot throws there instead of drawing nothing.\n */\nexport function resolveEffects<D>(on: EffectSlots<D> | undefined, presets: Pick<Registry<PresetFactory>, \"resolve\">): SlotEffects<D> {\n const effects: { [S in EffectSlot]?: MarkEffect<D> } = {};\n for (const slot of Object.keys(on ?? {})) {\n if (!(EFFECT_SLOTS as readonly string[]).includes(slot)) {\n throw new TypeError(`on.${slot} isn't an effect slot. Use one of: ${EFFECT_SLOTS.join(\", \")}.`);\n }\n }\n for (const slot of EFFECT_SLOTS) {\n const option = on?.[slot];\n if (option === undefined) continue;\n if (typeof option === \"string\") {\n const effect: unknown = presets.resolve(option)();\n if (!isMarkEffect(effect)) throw new TypeError(`Preset \"${option}\" for on.${slot} didn't return a mark effect; it returned ${describeValue(effect)}.`);\n effects[slot] = effect;\n } else {\n if (!isMarkEffect(option)) throw new TypeError(`on.${slot} needs a mark effect (kind \"geometry\" or \"data\") or a preset name, got ${describeValue(option)}.`);\n effects[slot] = option;\n }\n }\n return effects;\n}\n\n/** True for a geometry or data effect with run, end and clear. Combinators check their parts with it too. */\nexport function isMarkEffect(value: unknown): value is AnyMarkEffect {\n if (typeof value !== \"object\" || value === null) return false;\n const effect = value as Partial<Record<\"kind\" | \"run\" | \"end\" | \"clear\", unknown>>;\n return (\n (effect.kind === \"geometry\" || effect.kind === \"data\") &&\n typeof effect.run === \"function\" &&\n typeof effect.end === \"function\" &&\n typeof effect.clear === \"function\"\n );\n}\n\n/** What a value that isn't a mark effect is, for error messages. */\nexport function describeValue(value: unknown): string {\n if (typeof value !== \"object\" || value === null) return value === null ? \"null\" : typeof value;\n const kind = (value as { kind?: unknown }).kind;\n if (kind === \"transition\") return \"a transition effect, which runs between two charts rather than on one mark\";\n if (kind === \"geometry\" || kind === \"data\") return `a ${kind} effect without run(), end() and clear()`;\n return kind === undefined ? \"an object with no kind\" : `an effect of kind ${JSON.stringify(kind)}`;\n}\n","/**\n * The merge behind `mark.set()` and the handles' `update()`: fields given replace the current ones,\n * and a field given as undefined is removed, so it goes back to its default.\n */\nexport function mergeFields<T extends object>(current: T, next: Partial<T> | undefined): T {\n const result: Record<string, unknown> = { ...(current as Record<string, unknown>) };\n for (const [field, value] of Object.entries(next ?? {})) {\n if (value === undefined) delete result[field];\n else result[field] = value;\n }\n return result as T;\n}\n","// The effect runner: connects a chart's mark events to its effects and owns every run's lifecycle,\n// so effects stay small and stateless. Each chart or adapter creates one. Internal: charts and\n// adapters use it; it isn't part of the public API. See docs/architecture.md#runner.\n\nimport { defaultClock, type Clock } from \"./clock\";\nimport type { MarkData } from \"./contracts/data\";\nimport type { Layer, MarkHandle, MarkStyle } from \"./contracts/drawing\";\nimport type { AnyMarkEffect, EffectContext, MarkEffect } from \"./contracts/effect\";\nimport type { MarkGeometry } from \"./contracts/geometry\";\nimport type { IconSource } from \"./contracts/icon\";\nimport type { EffectSlot } from \"./contracts/slots\";\nimport { mergeFields } from \"./merge\";\nimport { motion as pageMotion, type Motion, type MotionView } from \"./motion\";\nimport { report } from \"./report\";\nimport { tween } from \"./tween\";\n\ntype Batch = { readonly index: number; readonly count: number };\n\n// ── One run's context ────────────────────────────────────────────────────────\n\nexport interface RunScopeOptions {\n readonly clock: Clock;\n readonly motion: MotionView;\n readonly icons: IconSource;\n readonly layer: Layer & { clear(): void };\n readonly mark: MarkHandle;\n readonly batch: Batch;\n readonly previous?: MarkGeometry | undefined;\n}\n\n/** An EffectContext plus the controls the runner keeps for itself. testContext() is built on it too. */\nexport interface RunScope {\n readonly context: EffectContext;\n abort(): void;\n /** Calls the run's onChange listeners. */\n change(mark: MarkGeometry, data?: MarkData): void;\n /** The runner's cleanup after effect.clear(ctx): abort, empty the layer, reset the mark, drop onChange listeners. */\n clear(): void;\n}\n\nexport function runScope(options: RunScopeOptions): RunScope {\n const { clock, motion, layer, mark } = options;\n const controller = new AbortController();\n let listeners: ((mark: MarkGeometry, data?: MarkData) => void)[] = [];\n\n const context: EffectContext = {\n signal: controller.signal,\n motion,\n mark,\n layer,\n icons: options.icons,\n batch: options.batch,\n ...(options.previous ? { previous: options.previous } : {}),\n tween(tweenOptions) {\n const own = tweenOptions.signal;\n const running = tween({ ...tweenOptions, signal: own ?? controller.signal }, { clock, motion });\n // An effect's own signal doesn't stop the run's signal from cancelling it too.\n if (own && own !== controller.signal) {\n if (controller.signal.aborted) running.cancel();\n else controller.signal.addEventListener(\"abort\", () => running.cancel(), { once: true });\n }\n return running;\n },\n onChange(listener) {\n listeners.push(listener);\n }\n };\n\n return {\n context,\n abort() {\n controller.abort();\n },\n change(geometry, data) {\n for (const listener of [...listeners]) listener(geometry, data);\n },\n clear() {\n controller.abort();\n layer.clear();\n mark.reset();\n listeners = [];\n }\n };\n}\n\n// ── The runner ───────────────────────────────────────────────────────────────\n\n/** The effects a runner plays, at most one per slot, with preset names already resolved (resolveEffects). */\nexport type SlotEffects<D = unknown> = { readonly [S in EffectSlot]?: MarkEffect<D> };\n\n/** A mark as the runner sees it. Chart events (MarkEvent) fit as they are. */\nexport interface RunInput<D = unknown> {\n readonly mark: MarkGeometry;\n readonly data: MarkData<D>;\n}\n\nexport interface UpdateInput<D = unknown> extends RunInput<D> {\n /** The geometry before this update. Default: the last geometry the runner saw for the key. */\n readonly from?: MarkGeometry;\n}\n\n/** One run's overlay group. */\nexport interface SurfaceGroup extends Layer {\n /**\n * Removes everything drawn in the group. Called once, when the run is cleared; nothing is drawn in\n * the group after that, so it can remove itself. Handles from a cleared group must ignore calls.\n */\n clear(): void;\n}\n\n/** What the runner draws on: a chart's or adapter's renderer (SVG today) implements it. */\nexport interface RunnerSurface {\n /**\n * A new, empty overlay group for one run, above the marks, in chart coordinates. Asked for on the\n * run's first draw, which can come late (a decoration that draws on its first change). Stack groups\n * by `order`, the run's start order, lower below higher, not by when they were asked for.\n */\n group(key: string, slot: EffectSlot, order: number): SurfaceGroup;\n /** The mark's own style handle. The runner merges every live run's style into it. */\n mark(key: string): MarkHandle;\n}\n\nexport interface RunnerOptions<D = unknown> {\n readonly effects: SlotEffects<D>;\n readonly surface: RunnerSurface;\n /** Default: the page-wide motion. The runner subscribes, so turning motion off mid-run jumps to end states. */\n readonly motion?: MotionView & Pick<Motion, \"subscribe\">;\n /** Default: the page-wide clock. */\n readonly clock?: Clock;\n /** Default: no icons. */\n readonly icons?: IconSource;\n}\n\n/**\n * Charts call these as things happen; the runner starts, clears and replays runs. A run is one\n * effect playing on one mark for one slot. Every method takes marks by key, as given in their\n * geometry, and is a no-op after destroy().\n */\nexport interface Runner<D = unknown> {\n /** Marks appeared: starts `decorate` (it stays until the mark exits), then `enter`. */\n enter(marks: readonly RunInput<D>[]): void;\n /** Marks' values changed, when their transition starts: runs `update`, with the previous geometry and data. */\n update(marks: readonly UpdateInput<D>[]): void;\n /**\n * Marks are leaving: clears their other runs and runs `exit`. Resolves when every exit run has\n * finished, been cleared by a re-enter, or the runner is destroyed; then the chart removes them.\n */\n exit(marks: readonly RunInput<D>[]): Promise<void>;\n /** Pointer or focus arrived: runs `hover`. While a transition is in flight it waits until settle(). */\n hover(marks: readonly RunInput<D>[]): void;\n /** Pointer or focus left these marks (default: every hovered mark): clears their hover runs. */\n leave(keys?: readonly string[]): void;\n /** A mark's geometry (or data) changed on screen: every frame of a transition, a resize, a line reveal. */\n change(mark: MarkGeometry, data?: MarkData<D>): void;\n /** A data transition starts: clears hover runs, and holds new hovers until settle(). */\n interrupt(): void;\n /** The last transition settled: replays hover on the marks still hovered or focused. */\n settle(): void;\n /**\n * New effects, as a chart's update({ on }) gives them. A slot whose effect is the same object keeps\n * its runs. A changed slot's runs are cleared and the new effect starts where they were: `decorate`\n * on every mark in `marks`, and `hover` on the marks still hovered (from settle() while a transition\n * is in flight). `enter`, `update` and `exit` draw the new effect's end state on the marks whose runs\n * they replace, in their place, so nothing enters again, an update keeps showing what it explains,\n * and an exit still ends. A slot left empty clears its runs.\n *\n * `marks` are the marks staying through the chart's update, as they're heading, in visual order:\n * the marks entering start theirs with enter(). Their geometry and data start the new runs but\n * aren't taken as the marks' own, so an update() that follows still gets the values before it.\n */\n swap(effects: SlotEffects<D>, marks: readonly RunInput<D>[]): void;\n /** Clears every run and stops following the motion mode. */\n destroy(): void;\n}\n\ninterface Entry<D> {\n readonly key: string;\n /** The latest geometry and data seen for the key. */\n mark: MarkGeometry;\n data: MarkData<D>;\n readonly runs: Map<EffectSlot, Run<D>>;\n /** The merged style last written to the mark's handle. */\n applied: MarkStyle;\n handle: MarkHandle | undefined;\n /** Resolves the exit() promise while the mark is leaving. */\n exiting: (() => void) | undefined;\n}\n\ninterface Run<D> {\n readonly entry: Entry<D>;\n readonly slot: EffectSlot;\n /**\n * Start order: when two runs set the same style field the later one wins, and later runs' overlay\n * groups stack above. A run replaced by end() when the mode turns off keeps its order.\n */\n readonly order: number;\n readonly effect: AnyMarkEffect;\n readonly data: MarkData<D>;\n readonly batch: Batch;\n readonly previous: MarkGeometry | undefined;\n readonly scope: RunScope;\n /** This run's own style fields. */\n style: MarkStyle;\n /** \"ended\": run() resolved or end() drew; the run stays live (layer, style, onChange) until cleared. */\n state: \"running\" | \"ended\" | \"cleared\";\n /** Called once, when the run finishes or is cleared (exit() waits on it). */\n done: (() => void) | undefined;\n}\n\ninterface StartOptions {\n readonly previous?: MarkGeometry | undefined;\n readonly done?: (() => void) | undefined;\n /** Default: the next start order. */\n readonly order?: number | undefined;\n /** Draws the effect's end state, whatever the motion mode. */\n readonly end?: boolean;\n /** The geometry to start on. Default: the latest the runner saw for the key. */\n readonly mark?: MarkGeometry;\n}\n\nconst SLOTS: readonly EffectSlot[] = [\"decorate\", \"enter\", \"update\", \"exit\", \"hover\"];\n\nconst NO_ICONS: IconSource = { get: () => undefined };\n/** Handed out for draws after a run is cleared, so an effect that ignores its signal draws nothing. */\nconst INERT = { place() {}, update() {}, remove() {} };\n\nexport function createRunner<D = unknown>(options: RunnerOptions<D>): Runner<D> {\n const { surface } = options;\n let effects = options.effects;\n const motion = options.motion ?? pageMotion;\n const clock = options.clock ?? defaultClock;\n const icons = options.icons ?? NO_ICONS;\n const entries = new Map<string, Entry<D>>();\n /** Hovered or focused keys, in the order they arrived. */\n const hovered = new Set<string>();\n let transitioning = false;\n let destroyed = false;\n let order = 0;\n\n // The effective mode can turn off mid-run (the device asks for reduced motion, or the viewer picks\n // Off). Runs still going are replaced by end() on a fresh context, so they never finish half-drawn.\n const unsubscribe = motion.subscribe(() => {\n if (motion.mode === \"off\") endRunning();\n });\n\n function track(input: RunInput<D>): Entry<D> {\n const key = input.mark.key;\n const entry = entries.get(key);\n if (entry) {\n entry.mark = input.mark;\n entry.data = input.data;\n return entry;\n }\n const created: Entry<D> = { key, mark: input.mark, data: input.data, runs: new Map(), applied: {}, handle: undefined, exiting: undefined };\n entries.set(key, created);\n return created;\n }\n\n /** Starts `slot`'s effect on the entry, clearing the slot's current run first. */\n function start(entry: Entry<D>, slot: EffectSlot, data: MarkData<D>, batch: Batch, more: StartOptions = {}): void {\n const { previous, done } = more;\n const effect = effects[slot] as AnyMarkEffect | undefined;\n if (!effect) {\n done?.();\n return;\n }\n const current = entry.runs.get(slot);\n if (current) clearRun(current);\n\n const run: Run<D> = {\n entry,\n slot,\n order: more.order ?? ++order,\n effect,\n data,\n batch,\n previous,\n style: {},\n state: \"running\",\n done,\n scope: runScope({\n clock,\n motion,\n icons,\n batch,\n previous,\n layer: runLayer(entry.key, slot, () => run.order, () => run.state !== \"cleared\"),\n mark: runMark(() => run)\n })\n };\n entry.runs.set(slot, run);\n\n const mark = more.mark ?? entry.mark;\n const ctx = run.scope.context;\n try {\n if (more.end || motion.mode === \"off\") {\n if (effect.kind === \"data\") effect.end(mark, data, ctx);\n else effect.end(mark, ctx);\n finish(run);\n } else {\n const running = effect.kind === \"data\" ? effect.run(mark, data, ctx) : effect.run(mark, ctx);\n Promise.resolve(running).then(\n () => finish(run),\n (error: unknown) => fail(run, error)\n );\n }\n } catch (error) {\n fail(run, error);\n }\n }\n\n function finish(run: Run<D>): void {\n if (run.state !== \"running\") return;\n run.state = \"ended\";\n release(run);\n }\n\n function fail(run: Run<D>, error: unknown): void {\n const { signal } = run.scope.context;\n // A run that rejects because it was aborted isn't broken.\n if (signal.aborted && (error === signal.reason || (error as { name?: unknown } | null)?.name === \"AbortError\")) return;\n report(error);\n clearRun(run);\n }\n\n function release(run: Run<D>): void {\n const done = run.done;\n run.done = undefined;\n done?.();\n }\n\n /** Abort, effect.clear(ctx), then the runner's own cleanup: so it happens even if the effect forgets. */\n function clearRun(run: Run<D>): void {\n if (run.state === \"cleared\") return;\n run.state = \"cleared\";\n const { entry } = run;\n if (entry.runs.get(run.slot) === run) entry.runs.delete(run.slot);\n run.scope.abort();\n try {\n run.effect.clear(run.scope.context);\n } catch (error) {\n report(error);\n }\n run.scope.clear();\n release(run);\n }\n\n /** A run's overlay group, created on its first draw. Draws after the run is cleared do nothing. */\n function runLayer(key: string, slot: EffectSlot, order: () => number, live: () => boolean): Layer & { clear(): void } {\n let group: SurfaceGroup | undefined;\n const target = (): Layer | undefined => (live() ? (group ??= surface.group(key, slot, order())) : undefined);\n return {\n icon: (icon, iconOptions) => target()?.icon(icon, iconOptions) ?? INERT,\n path: (d, paint) => target()?.path(d, paint) ?? INERT,\n text: (content, style) => target()?.text(content, style) ?? INERT,\n clear() {\n const drawn = group;\n group = undefined;\n drawn?.clear();\n }\n };\n }\n\n /** A run's view of the mark's style: its own fields, merged with the other live runs' into the real handle. */\n function runMark(own: () => Run<D>): MarkHandle {\n return {\n set(style) {\n const run = own();\n if (run.state === \"cleared\") return;\n run.style = mergeFields(run.style, style);\n applyStyle(run.entry);\n },\n reset() {\n const run = own();\n if (Object.keys(run.style).length === 0) return;\n run.style = {};\n applyStyle(run.entry);\n }\n };\n }\n\n /** Writes what changed in the merged style of the entry's live runs (later runs win a field). */\n function applyStyle(entry: Entry<D>): void {\n const runs = [...entry.runs.values()].sort((a, b) => a.order - b.order);\n const next: Record<string, unknown> = Object.assign({}, ...runs.map((run) => run.style));\n const applied = entry.applied as Record<string, unknown>;\n entry.applied = next as MarkStyle;\n if (Object.keys(next).length === 0) {\n if (Object.keys(applied).length > 0) handle(entry).reset();\n return;\n }\n const changes: Record<string, unknown> = {};\n let changed = false;\n for (const field of new Set([...Object.keys(applied), ...Object.keys(next)])) {\n if (applied[field] === next[field]) continue;\n // A field no run sets any more is given as undefined, which resets it.\n changes[field] = next[field];\n changed = true;\n }\n if (changed) handle(entry).set(changes as MarkStyle);\n }\n\n function handle(entry: Entry<D>): MarkHandle {\n return (entry.handle ??= surface.mark(entry.key));\n }\n\n /** Clears every run on the entry and drops it; resolves its exit() promise if it was leaving. */\n function forget(entry: Entry<D>): void {\n if (entries.get(entry.key) === entry) entries.delete(entry.key);\n hovered.delete(entry.key);\n const exited = entry.exiting;\n entry.exiting = undefined;\n for (const run of [...entry.runs.values()]) clearRun(run);\n entry.handle = undefined;\n exited?.();\n }\n\n /** Stops a pending exit (a re-enter, or exit() again) without forgetting the mark. */\n function cancelExit(entry: Entry<D>): void {\n const exited = entry.exiting;\n if (!exited) return;\n entry.exiting = undefined;\n const run = entry.runs.get(\"exit\");\n if (run) clearRun(run);\n exited();\n }\n\n function endRunning(): void {\n for (const entry of [...entries.values()]) {\n for (const run of [...entry.runs.values()]) {\n if (run.state !== \"running\" || entry.runs.get(run.slot) !== run) continue;\n // The replacement takes the run's place: its order (style precedence and stacking) and the\n // exit() promise waiting on it.\n const done = run.done;\n run.done = undefined;\n start(entry, run.slot, latestData(entry, run), run.batch, { previous: run.previous, done, order: run.order });\n }\n }\n }\n\n /** Clears the slot's run on each entry, and returns each order, to start the slot's next run in its place. */\n function clearSlot(slot: EffectSlot): Map<Entry<D>, number> {\n const orders = new Map<Entry<D>, number>();\n for (const entry of [...entries.values()]) {\n const run = entry.runs.get(slot);\n if (!run) continue;\n orders.set(entry, run.order);\n clearRun(run);\n }\n return orders;\n }\n\n /** The entry's latest data, keeping the previous values the run was given. */\n function latestData(entry: Entry<D>, run: Run<D>): MarkData<D> {\n const previous = run.data.previous;\n return previous && !entry.data.previous ? withPrevious(entry.data, previous) : entry.data;\n }\n\n return {\n enter(marks) {\n if (destroyed) return;\n marks.forEach((input, index) => {\n const entry = track(input);\n cancelExit(entry);\n const batch = { index, count: marks.length };\n start(entry, \"decorate\", input.data, batch);\n start(entry, \"enter\", input.data, batch);\n });\n },\n\n update(marks) {\n if (destroyed) return;\n marks.forEach((input, index) => {\n const known = entries.get(input.mark.key);\n const previous = input.from ?? known?.mark;\n const data = known && !input.data.previous ? withPrevious(input.data, known.data) : input.data;\n start(track(input), \"update\", data, { index, count: marks.length }, { previous });\n });\n },\n\n exit(marks) {\n if (destroyed) return Promise.resolve();\n const exits = marks.map((input, index) => {\n const entry = track(input);\n cancelExit(entry);\n hovered.delete(entry.key);\n for (const run of [...entry.runs.values()]) clearRun(run);\n return new Promise<void>((resolve) => {\n entry.exiting = resolve;\n if (!effects.exit) {\n forget(entry);\n return;\n }\n start(entry, \"exit\", input.data, { index, count: marks.length }, {\n done: () => {\n if (entry.exiting && entries.get(entry.key) === entry) forget(entry);\n }\n });\n });\n });\n return Promise.all(exits).then(() => undefined);\n },\n\n hover(marks) {\n if (destroyed) return;\n marks.forEach((input, index) => {\n const entry = track(input);\n if (entry.exiting) return;\n hovered.add(entry.key);\n if (!transitioning) start(entry, \"hover\", input.data, { index, count: marks.length });\n });\n },\n\n leave(keys = [...hovered]) {\n for (const key of keys) {\n hovered.delete(key);\n const run = entries.get(key)?.runs.get(\"hover\");\n if (run) clearRun(run);\n }\n },\n\n change(mark, data) {\n const entry = entries.get(mark.key);\n if (!entry) return;\n entry.mark = mark;\n if (data) entry.data = data;\n for (const run of [...entry.runs.values()]) {\n if (run.state === \"cleared\") continue;\n try {\n // An update run keeps the previous values it was given, as when it's replaced by end().\n run.scope.change(mark, latestData(entry, run));\n } catch (error) {\n report(error);\n clearRun(run);\n }\n }\n },\n\n interrupt() {\n if (destroyed) return;\n transitioning = true;\n for (const entry of [...entries.values()]) {\n const run = entry.runs.get(\"hover\");\n if (run) clearRun(run);\n }\n },\n\n settle() {\n if (!transitioning) return;\n transitioning = false;\n const keys = [...hovered];\n keys.forEach((key, index) => {\n const entry = entries.get(key);\n if (entry) start(entry, \"hover\", entry.data, { index, count: keys.length });\n });\n },\n\n swap(next, marks) {\n if (destroyed) return;\n const changed = SLOTS.filter((slot) => next[slot] !== effects[slot]);\n effects = next;\n for (const slot of changed) {\n if (slot === \"decorate\") {\n const orders = clearSlot(slot);\n marks.forEach((input, index) => {\n const entry = entries.get(input.mark.key) ?? track(input);\n if (!entry.exiting) start(entry, slot, input.data, { index, count: marks.length }, { mark: input.mark, order: orders.get(entry) });\n });\n } else if (slot === \"hover\") {\n clearSlot(slot);\n // Mid-transition, settle() replays them with the new effect.\n if (transitioning) continue;\n const keys = [...hovered];\n keys.forEach((key, index) => {\n const entry = entries.get(key);\n if (entry) start(entry, slot, entry.data, { index, count: keys.length });\n });\n } else {\n for (const entry of [...entries.values()]) {\n const run = entry.runs.get(slot);\n if (!run) continue;\n // The new run takes the old one's place: its order, and the exit() promise waiting on it.\n const done = run.done;\n run.done = undefined;\n const data = latestData(entry, run);\n clearRun(run);\n start(entry, slot, data, run.batch, { previous: run.previous, done, order: run.order, end: true });\n }\n }\n }\n },\n\n destroy() {\n if (destroyed) return;\n destroyed = true;\n transitioning = false;\n unsubscribe();\n for (const entry of [...entries.values()]) forget(entry);\n hovered.clear();\n }\n };\n}\n\nfunction withPrevious<D>(data: MarkData<D>, previous: MarkData<D>): MarkData<D> {\n return { datum: data.datum, samples: data.samples, related: (series) => data.related(series), previous };\n}\n","// The transition player: plays a TransitionEffect on pairs of marks, one run per pair, with the\n// runner's rules, so transition effects stay small and stateless too. Internal: chartSwitch uses it;\n// it isn't part of the public API. Each pair's context is the runner's run scope plus `start`.\n\nimport { defaultClock, type Clock } from \"./clock\";\nimport type { Layer, MarkHandle } from \"./contracts/drawing\";\nimport type { TransitionContext, TransitionEffect } from \"./contracts/effect\";\nimport type { MarkGeometry } from \"./contracts/geometry\";\nimport type { IconSource } from \"./contracts/icon\";\nimport { motion as pageMotion, type Motion, type MotionView } from \"./motion\";\nimport { report } from \"./report\";\nimport { runScope, type RunScope, type SurfaceGroup } from \"./runner\";\n\n/** One mark in two views: where it is now and where it goes. Pairs are matched by key, so both have the same one. */\nexport interface TransitionPair {\n readonly from: MarkGeometry;\n readonly to: MarkGeometry;\n}\n\n/** What the player draws on: an overlay above both views. */\nexport interface TransitionSurface {\n /**\n * A new, empty group for one pair's run, in overlay coordinates. Asked for on the run's first draw,\n * for the pair's key (`to.key`), so \"mark\" is that key's colour. Stack groups by `order`, the pair's\n * place in the list, lower below higher.\n */\n group(key: string, order: number): SurfaceGroup;\n}\n\nexport interface TransitionOptions {\n readonly effect: TransitionEffect;\n readonly surface: TransitionSurface;\n /** Where every pair's run begins, from 0 to 1 (`TransitionContext.start`). Default 0. */\n readonly start?: number;\n /** Default: the page-wide motion. The player subscribes, so turning motion off mid-run jumps to end states. */\n readonly motion?: MotionView & Pick<Motion, \"subscribe\">;\n /** Default: the page-wide clock. */\n readonly clock?: Clock;\n /** Default: no icons. */\n readonly icons?: IconSource;\n}\n\n/** A transition playing on its pairs. */\nexport interface Transition {\n /**\n * Resolves once every pair's run has finished or been cleared. A finished run's end state stays\n * drawn until clear(). Never rejects.\n */\n readonly finished: Promise<void>;\n /** Aborts every run, calls the effect's clear() and empties each group. Later calls do nothing. */\n clear(): void;\n}\n\ninterface Run {\n readonly pair: TransitionPair;\n readonly index: number;\n readonly scope: RunScope;\n readonly context: TransitionContext;\n /** \"ended\": run() resolved or end() drew; the drawing stays until cleared. */\n state: \"running\" | \"ended\" | \"cleared\";\n /** Called once, when the run finishes or is cleared. A run replaced by end() hands it on. */\n done: (() => void) | undefined;\n}\n\nconst NO_ICONS: IconSource = { get: () => undefined };\n/** Both views' marks are hidden while a transition plays, so a run's mark handle does nothing. */\nconst NO_MARK: MarkHandle = { set() {}, reset() {} };\n/** Handed out for draws after a run is cleared, so an effect that ignores its signal draws nothing. */\nconst INERT = { place() {}, update() {}, remove() {} };\n\n/**\n * Plays `effect` from each pair's `from` to its `to`, every run on a context of its own: `signal`,\n * `motion`, `tween()`, a `layer` group, `icons`, `batch` (the pair's place among the pairs) and\n * `start`. Its `mark` does nothing and `onChange` never fires: a resize lands the transition instead.\n *\n * With motion off, `end()` draws on the context instead of `run()`, and motion turning off mid-run\n * replaces each run still going with `end()` on a fresh context. An effect that throws (or whose run\n * rejects) on one pair is reported and that pair is cleared; the others carry on.\n */\nexport function playTransition(pairs: readonly TransitionPair[], options: TransitionOptions): Transition {\n const { effect, surface } = options;\n if (!isTransitionEffect(effect)) throw new TypeError(`playTransition needs a transition effect (kind \"transition\" with run, end and clear), got ${describeEffect(effect)}.`);\n const start = options.start ?? 0;\n if (!(typeof start === \"number\" && start >= 0 && start <= 1)) throw new RangeError(`playTransition: start must be a number from 0 to 1, got ${String(start)}.`);\n const motion = options.motion ?? pageMotion;\n const clock = options.clock ?? defaultClock;\n const icons = options.icons ?? NO_ICONS;\n const count = pairs.length;\n const runs: Run[] = [];\n let cleared = false;\n let waiting = count;\n let resolve!: () => void;\n const finished = new Promise<void>((r) => {\n resolve = r;\n });\n\n // Runs still going when the effective mode turns off are replaced by end(), as the runner does.\n let unsubscribe: (() => void) | undefined = count > 0 ? motion.subscribe(() => {\n if (motion.mode === \"off\") endRunning();\n }) : undefined;\n\n const settled = (): void => {\n if (--waiting > 0) return;\n unsubscribe?.();\n unsubscribe = undefined;\n resolve();\n };\n\n function begin(pair: TransitionPair, index: number, done: (() => void) | undefined): void {\n const scope: RunScope = runScope({\n clock,\n motion,\n icons,\n batch: { index, count },\n layer: pairLayer(pair.to.key, index, () => run.state !== \"cleared\"),\n mark: NO_MARK\n });\n const run: Run = { pair, index, scope, context: { ...scope.context, start }, state: \"running\", done };\n runs[index] = run;\n\n const { from, to } = pair;\n try {\n if (motion.mode === \"off\") {\n effect.end(from, to, run.context);\n finish(run);\n } else {\n Promise.resolve(effect.run(from, to, run.context)).then(\n () => finish(run),\n (error: unknown) => fail(run, error)\n );\n }\n } catch (error) {\n fail(run, error);\n }\n }\n\n function finish(run: Run): void {\n if (run.state !== \"running\") return;\n run.state = \"ended\";\n release(run);\n }\n\n function fail(run: Run, error: unknown): void {\n const { signal } = run.context;\n // A run that rejects because it was aborted isn't broken.\n if (signal.aborted && (error === signal.reason || (error as { name?: unknown } | null)?.name === \"AbortError\")) return;\n report(error);\n clearRun(run);\n }\n\n function release(run: Run): void {\n const done = run.done;\n run.done = undefined;\n done?.();\n }\n\n /** Abort, effect.clear(ctx), then the player's own cleanup: so it happens even if the effect forgets. */\n function clearRun(run: Run): void {\n if (run.state === \"cleared\") return;\n run.state = \"cleared\";\n run.scope.abort();\n try {\n effect.clear(run.context);\n } catch (error) {\n report(error);\n }\n run.scope.clear();\n release(run);\n }\n\n function endRunning(): void {\n for (const run of [...runs]) {\n if (run.state !== \"running\") continue;\n // The replacement takes the run's place: its group's order and the wait on it.\n const done = run.done;\n run.done = undefined;\n clearRun(run);\n begin(run.pair, run.index, done);\n }\n }\n\n /** A run's overlay group, made on its first draw. Draws after the run is cleared do nothing. */\n function pairLayer(key: string, order: number, live: () => boolean): Layer & { clear(): void } {\n let group: SurfaceGroup | undefined;\n const target = (): Layer | undefined => (live() ? (group ??= surface.group(key, order)) : undefined);\n return {\n icon: (icon, iconOptions) => target()?.icon(icon, iconOptions) ?? INERT,\n path: (d, paint) => target()?.path(d, paint) ?? INERT,\n text: (content, style) => target()?.text(content, style) ?? INERT,\n clear() {\n const drawn = group;\n group = undefined;\n drawn?.clear();\n }\n };\n }\n\n pairs.forEach((pair, index) => begin(pair, index, settled));\n if (count === 0) resolve();\n\n return {\n finished,\n clear() {\n if (cleared) return;\n cleared = true;\n for (const run of [...runs]) clearRun(run);\n }\n };\n}\n\n/** True for a transition effect with run, end and clear. */\nexport function isTransitionEffect(value: unknown): value is TransitionEffect {\n if (typeof value !== \"object\" || value === null) return false;\n const effect = value as Partial<Record<\"kind\" | \"run\" | \"end\" | \"clear\", unknown>>;\n return effect.kind === \"transition\" && typeof effect.run === \"function\" && typeof effect.end === \"function\" && typeof effect.clear === \"function\";\n}\n\nfunction describeEffect(value: unknown): string {\n if (typeof value !== \"object\" || value === null) return value === null ? \"null\" : typeof value;\n const kind = (value as { kind?: unknown }).kind;\n if (kind === \"geometry\" || kind === \"data\") return `a ${kind} effect, which plays on one mark: put it in a chart's \\`on\\` option`;\n if (kind === \"transition\") return \"a transition effect without run(), end() and clear()\";\n return kind === undefined ? \"an object with no kind\" : `an effect of kind ${JSON.stringify(kind)}`;\n}\n"],"mappings":";AAKO,SAAS,OAAO,OAAsB;AAC3C,QAAM,WAAY,WAA0D;AAC5E,MAAI,OAAO,aAAa,WAAY,UAAS,KAAK;AAAA,MAC7C,SAAQ,MAAM,KAAK;AAC1B;;;ACkBO,SAAS,YAAY,SAAsB,cAAc,GAAU;AACxE,QAAM,YAAY,oBAAI,IAA2B;AACjD,MAAI;AAEJ,QAAM,WAAW,MAAY;AAC3B,QAAI,CAAC,eAAe,UAAU,O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AO,OAAO,UAAU;AACzI;AAEA,SAAS,eAAe,OAAwB;AAC9C,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO,UAAU,OAAO,SAAS,OAAO;AACzF,QAAM,OAAQ,MAA6B;AAC3C,MAAI,SAAS,cAAc,SAAS,OAAQ,QAAO,KAAK,IAAI;AAC5D,MAAI,SAAS,aAAc,QAAO;AAClC,SAAO,SAAS,SAAY,2BAA2B,qBAAqB,KAAK,UAAU,IAAI,CAAC;AAClG;","names":["id","motion","motion","order","NO_ICONS","INERT","motion"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/icons/define.ts"],"sourcesContent":["// defineIcon: fills an icon's defaults and checks every field, so effects can rely on all of them.\n\nimport type { Icon, IconShape, Point, Rect } from \"../core\";\n\n/** What defineIcon takes: an Icon whose pivot, footprint and size are optional. */\nexport type IconSpec = Omit<Icon, \"footprint\" | \"pivot\" | \"size\"> & Partial<Pick<Icon, \"footprint\" | \"pivot\" | \"size\">>;\n\nconst GAITS: readonly string[] = [\"roll\", \"step\", \"slide\"];\nconst LINECAPS: readonly string[] = [\"butt\", \"round\"];\nconst LINEJOINS: readonly string[] = [\"miter\", \"round\"];\n/** Path data: commands, numbers, separators. Anything else (markup, url(), quotes) is a mistake. */\nconst PATH_DATA = /^\\s*[Mm][MmLlHhVvCcSsQqTtAaZz0-9eE.,+\\-\\s]*$/;\n\n/**\n * Makes an icon from its parts. Shapes are drawn facing +x, up towards −y, in px at the icon's\n * natural size. Defaults: `pivot` is the anchor, `footprint` reaches from the anchor to the box's\n * edges, `size` is the box's width and `radius` half its height. Bad input throws a RangeError\n * naming the field. The icon and its parts are frozen, since one icon is shared by every run.\n */\nexport function defineIcon(spec: IconSpec): Icon {\n const name = spec?.name;\n if (typeof name !== \"string\" || name === \"\") throw new TypeError(`defineIcon needs a non-empty string name, got ${JSON.stringify(name)}.`);\n const fail = (field: string, problem: string): never => {\n throw new RangeError(`defineIcon: \"${name}\" ${field} ${problem}.`);\n };\n const finite = (field: string, value: unknown): number =>\n typeof value === \"number\" && Number.isFinite(value) ? value : fail(field, `must be a finite number, got ${String(value)}`);\n const positive = (field: string, value: unknown): number => (finite(field, value) > 0 ? (value as number) : fail(field, `must be more than 0, got ${String(value)}`));\n const point = (field: string, value: Point | undefined): Point =>\n value && typeof value === \"object\" ? freeze({ x: finite(`${field}.x`, value.x), y: finite(`${field}.y`, value.y) }) : fail(field, \"must be a point { x, y }\");\n\n if (!Array.isArray(spec.shapes) || spec.shapes.length === 0) fail(\"shapes\", \"must be a non-empty array\");\n const shapes = spec.shapes.map((shape, i) => checkShape(shape, `shapes[${i}]`, fail, finite));\n\n const b = spec.box;\n if (!b || typeof b !== \"object\") fail(\"box\", \"must be a rectangle { x, y, width, height }\");\n const box: Rect = freeze({ x: finite(\"box.x\", b.x), y: finite(\"box.y\", b.y), width: positive(\"box.width\", b.width), height: positive(\"box.height\", b.height) });\n\n const anchor = point(\"anchor\", spec.anchor);\n const pivot = spec.pivot === undefined ? anchor : point(\"pivot\", spec.pivot);\n const footprint = spec.footprint ?? [Math.max(0, anchor.x - box.x), Math.max(0, box.x + box.width - anchor.x)];\n if (!Array.isArray(footprint) || footprint.length !== 2) fail(\"footprint\", \"must be [behind, ahead]\");\n footprint.forEach((reach, i) => {\n if (finite(`footprint[${i}]`, reach) < 0) fail(`footprint[${i}]`, `can't be negative, got ${reach}`);\n });\n const size = spec.size === undefined ? box.width : positive(\"size\", spec.size);\n const radius = spec.radius === undefined ? box.height / 2 : positive(\"radius\", spec.radius);\n if (spec.gait !== undefined && !GAITS.includes(spec.gait)) fail(\"gait\", `must be roll, step or slide, got ${String(spec.gait)}`);\n if (spec.upright !== undefined && typeof spec.upright !== \"boolean\") fail(\"upright\", `must be true or false, got ${String(spec.upright)}`);\n\n return freeze({\n name,\n shapes: freeze(shapes),\n box,\n size,\n anchor,\n pivot,\n footprint: freeze([footprint[0], footprint[1]] as const),\n ...(spec.gait !== undefined ? { gait: spec.gait } : {}),\n radius,\n ...(spec.upright !== undefined ? { upright: spec.upright } : {})\n });\n}\n\nfunction checkShape(\n shape: IconShape,\n field: string,\n fail: (field: string, problem: string) => never,\n finite: (field: string, value: unknown) => number\n): IconShape {\n if (!shape || typeof shape !== \"object\") fail(field, \"must be a shape { d, fill?, stroke?, … }\");\n if (typeof shape.d !== \"string\" || !PATH_DATA.test(shape.d)) fail(`${field}.d`, \"must be path data starting with a move\");\n if (shape.clip !== undefined && (typeof shape.clip !== \"string\" || !PATH_DATA.test(shape.clip))) fail(`${field}.clip`, \"must be path data starting with a move\");\n for (const paint of [\"fill\", \"stroke\"] as const) {\n const value = shape[paint];\n if (value !== undefined && (typeof value !== \"string\" || value === \"\")) fail(`${field}.${paint}`, `must be a colour, got ${String(value)}`);\n }\n if (shape.width !== undefined && finite(`${field}.width`, shape.width) < 0) fail(`${field}.width`, `can't be negative, got ${shape.width}`);\n if (shape.linecap !== undefined && !LINECAPS.includes(shape.linecap)) fail(`${field}.linecap`, `must be butt or round, got ${String(shape.linecap)}`);\n if (shape.linejoin !== undefined && !LINEJOINS.includes(shape.linejoin)) fail(`${field}.linejoin`, `must be miter or round, got ${String(shape.linejoin)}`);\n const copy: { -readonly [K in keyof IconShape]: IconShape[K] } = { d: shape.d };\n for (const key of [\"fill\", \"stroke\", \"width\", \"linecap\", \"linejoin\", \"clip\"] as const) {\n if (shape[key] !== undefined) (copy as Record<string, unknown>)[key] = shape[key];\n }\n return freeze(copy);\n}\n\nconst freeze = <T>(value: T): T => Object.freeze(value);\n"],"mappings":";AAOA,IAAM,QAA2B,CAAC,QAAQ,QAAQ,OAAO;AACzD,IAAM,WAA8B,CAAC,QAAQ,OAAO;AACpD,IAAM,YAA+B,CAAC,SAAS,OAAO;AAEtD,IAAM,YAAY;AAQX,SAAS,WAAW,MAAsB;AAC/C,QAAM,OAAO,MAAM;AACnB,MAAI,OAAO,SAAS,YAAY,SAAS,GAAI,OAAM,IAAI,UAAU,iDAAiD,KAAK,UAAU,IAAI,CAAC,G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AAM,wCAAwC;AACxH,MAAI,MAAM,SAAS,WAAc,OAAO,MAAM,SAAS,YAAY,CAAC,UAAU,KAAK,MAAM,IAAI,GAAI,MAAK,GAAG,KAAK,SAAS,wCAAwC;AAC/J,aAAW,SAAS,CAAC,QAAQ,QAAQ,GAAY;AAC/C,UAAM,QAAQ,MAAM,KAAK;AACzB,QAAI,UAAU,WAAc,OAAO,UAAU,YAAY,UAAU,IAAK,MAAK,GAAG,KAAK,IAAI,KAAK,IAAI,yBAAyB,OAAO,KAAK,CAAC,EAAE;AAAA,EAC5I;AACA,MAAI,MAAM,UAAU,UAAa,OAAO,GAAG,KAAK,UAAU,MAAM,KAAK,IAAI,EAAG,MAAK,GAAG,KAAK,UAAU,0BAA0B,MAAM,KAAK,EAAE;AAC1I,MAAI,MAAM,YAAY,UAAa,CAAC,SAAS,SAAS,MAAM,OAAO,EAAG,MAAK,GAAG,KAAK,YAAY,8BAA8B,OAAO,MAAM,OAAO,CAAC,EAAE;AACpJ,MAAI,MAAM,aAAa,UAAa,CAAC,UAAU,SAAS,MAAM,QAAQ,EAAG,MAAK,GAAG,KAAK,aAAa,+BAA+B,OAAO,MAAM,QAAQ,CAAC,EAAE;AAC1J,QAAM,OAA2D,EAAE,GAAG,MAAM,EAAE;AAC9E,aAAW,OAAO,CAAC,QAAQ,UAAU,SAAS,WAAW,YAAY,MAAM,GAAY;AACrF,QAAI,MAAM,GAAG,MAAM,OAAW,CAAC,KAAiC,GAAG,IAAI,MAAM,GAAG;AAAA,EAClF;AACA,SAAO,OAAO,IAAI;AACpB;AAEA,IAAM,SAAS,CAAI,UAAgB,OAAO,OAAO,KAAK;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/geometry/segment.ts","../src/core/geometry/path-data.ts","../src/core/geometry/walk.ts","../src/core/geometry/outline.ts","../src/core/geometry/describe/mark.ts","../src/core/geometry/describe/arc.ts","../src/core/geometry/describe/bar.ts","../src/core/geometry/describe/line.ts","../src/core/geometry/describe/point.ts","../src/core/geometry/describe/index.ts","../src/core/geometry/matrix.ts","../src/core/geometry/samples.ts"],"sourcesContent":["// Path segments: straight lines and circular arcs, with exact lengths.\n//\n// Angles are screen angles: radians, 0 along +x, increasing clockwise on screen (y points down).\n// That is the convention of Math.atan2 in chart pixels, and of the walk's `angle(t)`.\n\nimport type { Point, Rect } from \"../contracts/geometry\";\n\nexport const TAU = 2 * Math.PI;\n\nexport interface LineSegment {\n readonly kind: \"line\";\n readonly from: Point;\n readonly to: Point;\n readonly length: number;\n /** Direction from `from` to `to`, or the fallback given to `line()` when they coincide. */\n readonly angle: number;\n}\n\nexport interface ArcSegment {\n readonly kind: \"arc\";\n readonly center: Point;\n readonly radius: number;\n /** Screen angle of the first point. */\n readonly start: number;\n /** Signed: positive is clockwise on screen. */\n readonly sweep: number;\n /** Exact: radius × |sweep|. */\n readonly length: number;\n}\n\nexport type PathSegment = LineSegment | ArcSegment;\n\n/** A straight segment. `fallbackAngle` is its direction if `from` and `to` coincide. */\nexport function line(from: Point, to: Point, fallbackAngle = 0): LineSegment {\n const dx = to.x - from.x;\n const dy = to.y - from.y;\n const length = Math.hypot(dx, dy);\n return { kind: \"line\", from, to, length, angle: length > 0 ? Math.atan2(dy, dx) : normalizeAngle(fallbackAngle) };\n}\n\n/** A circular arc from screen angle `start`, turning `sweep` radians (positive = clockwise on screen). */\nexport function arc(center: Point, radius: number, start: number, sweep: number): ArcSegment {\n return { kind: \"arc\", center, radius, start, sweep, length: radius * Math.abs(sweep) };\n}\n\n/** The point a fraction `u` (0–1) of the way along the segment, by distance. Exact at both ends of a line. */\nexport function pointOn(segment: PathSegment, u: number): Point {\n if (segment.kind === \"line\") {\n const { from, to } = segment;\n return { x: from.x * (1 - u) + to.x * u, y: from.y * (1 - u) + to.y * u };\n }\n return polar(segment.center, segment.radius, segment.start + segment.sweep * u);\n}\n\n/** Direction of travel at fraction `u`, in (-PI, PI]. */\nexport function angleOn(segment: PathSegment, u: number): number {\n if (segment.kind === \"line\") return segment.angle;\n const quarter = segment.sweep < 0 ? -Math.PI / 2 : Math.PI / 2;\n return normalizeAngle(segment.start + segment.sweep * u + quarter);\n}\n\nexport function polar(center: Point, radius: number, angle: number): Point {\n return { x: center.x + radius * Math.cos(angle), y: center.y + radius * Math.sin(angle) };\n}\n\n/** The same angle in (-PI, PI]. */\nexport function normalizeAngle(angle: number): number {\n return angle - TAU * Math.ceil((angle - Math.PI) / TAU);\n}\n\n/** The points that bound a segment: its ends, plus an arc's extremes in x and y. */\nexport function extremes(segment: PathSegment): Point[] {\n if (segment.kind === \"line\") return [segment.from, segment.to];\n const points = [pointOn(segment, 0), pointOn(segment, 1)];\n for (let k = 0; k < 4; k++) {\n const angle = (k * Math.PI) / 2;\n if (sweeps(segment, angle)) points.push(polar(segment.center, segment.radius, angle));\n }\n return points;\n}\n\nexport function boundsOf(points: readonly Point[]): Rect {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const { x, y } of points) {\n if (x < minX) minX = x;\n if (x > maxX) maxX = x;\n if (y < minY) minY = y;\n if (y > maxY) maxY = y;\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n\n/** True if the arc passes through screen angle `angle`. */\nfunction sweeps(segment: ArcSegment, angle: number): boolean {\n const extent = Math.abs(segment.sweep);\n if (extent >= TAU) return true;\n const turned = segment.sweep >= 0 ? angle - segment.start : segment.start - angle;\n return ((turned % TAU) + TAU) % TAU <= extent;\n}\n","// SVG path data for segments: M, L, A and Z only, with numbers rounded to 0.001 px.\n\nimport type { Point } from \"../contracts/geometry\";\nimport { pointOn, polar, type PathSegment } from \"./segment\";\n\n/** A coordinate for path data: rounded to 0.001, with no \"-0\". */\nexport function formatNumber(value: number): string {\n const rounded = Math.round(value * 1000) / 1000;\n return rounded === 0 ? \"0\" : String(rounded);\n}\n\nexport function moveTo(point: Point): string {\n return `M${formatNumber(point.x)},${formatNumber(point.y)}`;\n}\n\n/**\n * Commands that draw a segment from fraction `u0` to `u1` of its length, assuming the pen is already\n * at the `u0` point. Arcs are split into pieces of at most half a turn, so the large-arc flag is\n * always 0 and a full circle still draws.\n */\nexport function drawTo(segment: PathSegment, u0 = 0, u1 = 1): string {\n if (segment.kind === \"line\") {\n const p = u1 === 1 ? segment.to : pointOn(segment, u1);\n return `L${formatNumber(p.x)},${formatNumber(p.y)}`;\n }\n const from = segment.start + segment.sweep * u0;\n const turn = segment.sweep * (u1 - u0);\n const pieces = Math.max(1, Math.ceil(Math.abs(turn) / Math.PI - 1e-9));\n const r = formatNumber(segment.radius);\n const clockwise = turn >= 0 ? 1 : 0;\n let d = \"\";\n for (let i = 1; i <= pieces; i++) {\n const p = polar(segment.center, segment.radius, from + (turn * i) / pieces);\n d += `A${r},${r} 0 0 ${clockwise} ${formatNumber(p.x)},${formatNumber(p.y)}`;\n }\n return d;\n}\n\n/**\n * Path data for a run of connected segments. Zero-length segments draw nothing. A closed run ends\n * with Z, which also replaces a final straight segment back to the start.\n */\nexport function pathData(segments: readonly PathSegment[], closed = false): string {\n const first = segments[0];\n if (!first) return \"\";\n let count = segments.length;\n if (closed) {\n while (count > 0 && segments[count - 1]!.length <= 0) count--;\n if (count > 0 && segments[count - 1]!.kind === \"line\") count--;\n }\n let d = moveTo(pointOn(first, 0));\n for (let i = 0; i < count; i++) {\n const segment = segments[i]!;\n if (segment.length > 0) d += drawTo(segment);\n }\n return closed ? `${d}Z` : d;\n}\n","// A walk: connected segments parameterised by distance, so t = 0.5 is halfway along on screen.\n\nimport type { Point } from \"../contracts/geometry\";\nimport { drawTo, moveTo, pathData } from \"./path-data\";\nimport { angleOn, pointOn, type PathSegment } from \"./segment\";\n\nexport interface Walk {\n readonly segments: readonly PathSegment[];\n readonly length: number;\n readonly start: Point;\n readonly end: Point;\n /** t in [0, 1], proportional to distance. Values outside are clamped. */\n point(t: number): Point;\n /** Direction of travel in (-PI, PI]. At a joint, the segment ahead wins, except at t = 1. */\n angle(t: number): number;\n /** Path data from t0 to t1, in either order. Just a move when they're equal. */\n slice(t0: number, t1: number): string;\n /** Path data for the whole walk. */\n readonly d: string;\n}\n\nconst clamp01 = (t: number): number => (t > 0 ? (t < 1 ? t : 1) : 0);\n\n/** The segments must connect: each starts where the one before ends. */\nexport function createWalk(segments: readonly PathSegment[]): Walk {\n const first = segments[0];\n const last = segments[segments.length - 1];\n if (!first || !last) throw new RangeError(\"A walk needs at least one segment.\");\n\n // cumulative[i] is the distance to the start of segment i.\n const cumulative = [0];\n for (const segment of segments) cumulative.push(cumulative[cumulative.length - 1]! + segment.length);\n const length = cumulative[segments.length]!;\n const start = pointOn(first, 0);\n const end = pointOn(last, 1);\n\n // The segment at distance d, and the fraction along it. Zero-length segments are never picked\n // unless the whole walk has zero length.\n const locate = (d: number): { readonly index: number; readonly u: number } => {\n if (!(length > 0)) return { index: 0, u: 0 };\n if (d >= length) {\n let index = segments.length - 1;\n while (index > 0 && !(segments[index]!.length > 0)) index--;\n return { index, u: 1 };\n }\n // The first segment that ends beyond d.\n let lo = 0;\n let hi = segments.length - 1;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (cumulative[mid + 1]! > d) hi = mid;\n else lo = mid + 1;\n }\n return { index: lo, u: Math.min(1, (d - cumulative[lo]!) / segments[lo]!.length) };\n };\n\n const point = (t: number): Point => {\n const at = clamp01(t);\n if (at === 0) return start;\n if (at === 1) return end;\n const { index, u } = locate(at * length);\n return pointOn(segments[index]!, u);\n };\n\n return {\n segments,\n length,\n start,\n end,\n point,\n angle(t) {\n const { index, u } = locate(clamp01(t) * length);\n return angleOn(segments[index]!, u);\n },\n slice(t0, t1) {\n const from = clamp01(Math.min(t0, t1));\n const to = clamp01(Math.max(t0, t1));\n let d = moveTo(point(from));\n const a = from * length;\n const b = to * length;\n if (!(b > a)) return d;\n const first = locate(a);\n for (let i = first.index; i < segments.length && cumulative[i]! < b; i++) {\n const segment = segments[i]!;\n if (!(segment.length > 0)) continue;\n const u0 = i === first.index ? first.u : 0;\n const u1 = cumulative[i + 1]! > b ? Math.min(1, (b - cumulative[i]!) / segment.length) : 1;\n if (u1 > u0) d += drawTo(segment, u0, u1);\n }\n return d;\n },\n d: pathData(segments)\n };\n}\n","// Outlines with canonical sampling, so morph can match corners and winding between any two marks.\n\nimport type { Outline, Point } from \"../contracts/geometry\";\nimport { pathData } from \"./path-data\";\nimport type { PathSegment } from \"./segment\";\nimport { createWalk, type Walk } from \"./walk\";\n\n/** The four sides of a closed outline, in order. Each must start where the one before ends. */\nexport type Sides = readonly [\n left: readonly PathSegment[],\n end: readonly PathSegment[],\n right: readonly PathSegment[],\n start: readonly PathSegment[]\n];\n\n/**\n * A closed outline from its sides: left (the up side, walked in the direction of travel), end,\n * right (walked back) and start. That order runs clockwise on screen from the start-left corner.\n */\nexport function closedOutline(sides: Sides): Outline {\n const walks = sides.map(createWalk);\n return {\n d: pathData(sides.flat(), true),\n closed: true,\n sample(n) {\n checkCount(n, 4);\n const perSide = n / 4;\n const points: Point[] = [];\n for (const walk of walks) {\n for (let j = 0; j < perSide; j++) points.push(walk.point(j / perSide));\n }\n return points;\n }\n };\n}\n\n/** An open outline: the stroke along a walk. */\nexport function openOutline(walk: Walk): Outline {\n return {\n d: walk.d,\n closed: false,\n sample(n) {\n checkCount(n, 1);\n if (n === 1) return [walk.start];\n const points: Point[] = [];\n for (let j = 0; j < n; j++) points.push(walk.point(j / (n - 1)));\n return points;\n }\n };\n}\n\nfunction checkCount(n: number, multiple: number): void {\n if (!Number.isInteger(n) || n < 0 || n % multiple !== 0) {\n const what = multiple === 1 ? \"a whole number ≥ 0\" : `a whole multiple of ${multiple}`;\n throw new RangeError(`outline.sample(n): n must be ${what}, got ${n}.`);\n }\n}\n","// Shared by the builders: assembling a MarkGeometry from a walk and a body, and checking input.\n\nimport type { MarkGeometry, Outline, Point, Rect } from \"../../contracts/geometry\";\nimport type { Walk } from \"../walk\";\n\nexport interface MarkParts {\n readonly key: string;\n readonly series?: string | undefined;\n readonly walk: Walk;\n readonly thickness: number;\n readonly outline: Outline;\n readonly bounds: Rect;\n readonly center: Point;\n readonly pivot: Point;\n readonly segments?: readonly MarkGeometry[];\n}\n\nexport function assemble({ key, series, walk, thickness, outline, bounds, center, pivot, segments }: MarkParts): MarkGeometry {\n return {\n key,\n ...(series === undefined ? {} : { series }),\n start: walk.start,\n end: walk.end,\n length: walk.length,\n path: (t) => walk.point(t),\n angle: (t) => walk.angle(t),\n slice: (t0, t1) => walk.slice(t0, t1),\n thickness,\n outline,\n bounds,\n center,\n pivot,\n ...(segments === undefined ? {} : { segments })\n };\n}\n\n/** Throws a RangeError naming the builder and field unless `value` is a finite number. */\nexport function finite(builder: string, field: string, value: number): number {\n if (!Number.isFinite(value)) throw new RangeError(`describe.${builder}: ${field} must be a finite number, got ${value}.`);\n return value;\n}\n\n/** Throws a RangeError unless `value` is a finite number ≥ 0. */\nexport function size(builder: string, field: string, value: number): number {\n if (!(Number.isFinite(value) && value >= 0)) {\n throw new RangeError(`describe.${builder}: ${field} must be a finite number ≥ 0, got ${value}.`);\n }\n return value;\n}\n","// describe.arc: donut and pie slices, in d3.pie()'s angle convention.\n\nimport type { MarkGeometry } from \"../../contracts/geometry\";\nimport { closedOutline } from \"../outline\";\nimport { arc, boundsOf, extremes, line, polar, TAU } from \"../segment\";\nimport { createWalk } from \"../walk\";\nimport { assemble, finite, size } from \"./mark\";\n\nexport interface ArcSpec {\n readonly key: string;\n readonly series?: string;\n /** The donut's centre. */\n readonly cx: number;\n readonly cy: number;\n /** Radii in px; 0 inner makes a pie slice. They're swapped if inner > outer, as d3.arc() does. */\n readonly inner: number;\n readonly outer: number;\n /** Radians, 0 at 12 o'clock, clockwise: the d3.pie() convention. end < start walks anticlockwise. */\n readonly start: number;\n readonly end: number;\n}\n\n/**\n * The walk runs along the mid-radius arc from the start angle to the end angle, so for a slice\n * walked clockwise \"up\" is outward. The angle of travel equals the d3 angle (normalised).\n */\nexport function describeArc(spec: ArcSpec): MarkGeometry {\n const { key, series } = spec;\n const center = { x: finite(\"arc\", \"cx\", spec.cx), y: finite(\"arc\", \"cy\", spec.cy) };\n const r0 = Math.min(size(\"arc\", \"inner\", spec.inner), size(\"arc\", \"outer\", spec.outer));\n const r1 = Math.max(spec.inner, spec.outer);\n finite(\"arc\", \"start\", spec.start);\n finite(\"arc\", \"end\", spec.end);\n // More than a full turn draws the same ring, as with d3.arc().\n const sweep = Math.max(-TAU, Math.min(TAU, spec.end - spec.start));\n // d3 measures from 12 o'clock; screen angles from 3 o'clock.\n const from = spec.start - Math.PI / 2;\n const to = from + sweep;\n\n // The up side is outward when walking clockwise, inward when walking anticlockwise.\n const [left, right] = sweep >= 0 ? [r1, r0] : [r0, r1];\n const sides = [\n [arc(center, left, from, sweep)],\n [line(polar(center, left, to), polar(center, right, to), to + (left > right ? Math.PI : 0))],\n [arc(center, right, to, -sweep)],\n [line(polar(center, right, from), polar(center, left, from), from + (left > right ? 0 : Math.PI))]\n ] as const;\n\n const walk = createWalk([arc(center, (r0 + r1) / 2, from, sweep)]);\n return assemble({\n key,\n series,\n walk,\n thickness: r1 - r0,\n outline: closedOutline(sides),\n bounds: boundsOf(sides.flat().flatMap(extremes)),\n center: walk.point(0.5),\n pivot: center\n });\n}\n","// describe.bar: horizontal bars and vertical columns, plain or stacked, with an optional rounded tip.\n\nimport type { MarkGeometry, Point, Rect } from \"../../contracts/geometry\";\nimport { closedOutline } from \"../outline\";\nimport { arc, boundsOf, line } from \"../segment\";\nimport { createWalk } from \"../walk\";\nimport { assemble, finite, size } from \"./mark\";\n\n/** The edge a bar grows from. */\nexport type Baseline = \"left\" | \"right\" | \"top\" | \"bottom\";\n\nexport interface BarSegmentSpec {\n readonly series: string;\n /** Px along the walk, gap included. */\n readonly size: number;\n}\n\nexport interface BarSpec {\n readonly key: string;\n readonly series?: string;\n /** The whole bar's rectangle, in chart px. */\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n readonly baseline: Baseline;\n /** Corner radius at the tip. The baseline end stays square. Default 0. */\n readonly radius?: number;\n /**\n * Ordered parts, from the baseline. Default: one segment named after `series`, covering the bar.\n * Sizes normally add up to the bar's length; anything past the tip is cut off.\n */\n readonly segments?: readonly BarSegmentSpec[];\n /**\n * Px left empty between segments (the prototype uses 2). It comes out of the start of the later\n * segment, so every segment still ends at its value, and it shrinks to fit when what comes\n * before is shorter. Default 0.\n */\n readonly gap?: number;\n}\n\nconst ANGLE: Readonly<Record<Baseline, number>> = { left: 0, right: Math.PI, top: Math.PI / 2, bottom: -Math.PI / 2 };\n\n/**\n * The walk runs along the centre line from the middle of the baseline edge to the middle of the\n * tip. A plain bar has one segment, so `travel(…, { along: \"goals\" })` works stacked or not.\n */\nexport function describeBar(spec: BarSpec): MarkGeometry {\n const { key, series, baseline, x, y, width, height } = spec;\n if (!Object.prototype.hasOwnProperty.call(ANGLE, baseline)) {\n throw new RangeError(`describe.bar: baseline must be left, right, top or bottom, got ${String(baseline)}.`);\n }\n finite(\"bar\", \"x\", x);\n finite(\"bar\", \"y\", y);\n size(\"bar\", \"width\", width);\n size(\"bar\", \"height\", height);\n const radius = size(\"bar\", \"radius\", spec.radius ?? 0);\n const gap = size(\"bar\", \"gap\", spec.gap ?? 0);\n\n const horizontal = baseline === \"left\" || baseline === \"right\";\n const length = horizontal ? width : height;\n const thickness = horizontal ? height : width;\n const T = thickness;\n const angle = ANGLE[baseline];\n const at = frame(spec);\n\n // The bar or segment covering [p0, p1] along the walk. The tip is rounded by up to `tip` px.\n const part = (\n p0: number,\n p1: number,\n tip: number,\n rest: { key: string; series: string | undefined; bounds?: Rect; segments?: readonly MarkGeometry[] }\n ): MarkGeometry => {\n const rr = Math.max(0, Math.min(tip, p1 - p0, T / 2));\n const outline = closedOutline([\n [line(at(p0, 0), at(p1 - rr, 0), angle)],\n rr > 0\n ? [\n arc(at(p1 - rr, rr), rr, angle - Math.PI / 2, Math.PI / 2),\n line(at(p1, rr), at(p1, T - rr), angle + Math.PI / 2),\n arc(at(p1 - rr, T - rr), rr, angle, Math.PI / 2)\n ]\n : [line(at(p1, 0), at(p1, T), angle + Math.PI / 2)],\n [line(at(p1 - rr, T), at(p0, T), angle + Math.PI)],\n [line(at(p0, T), at(p0, 0), angle - Math.PI / 2)]\n ]);\n const walk = createWalk([line(at(p0, T / 2), at(p1, T / 2), angle)]);\n return assemble({\n ...rest,\n walk,\n thickness,\n outline,\n bounds: rest.bounds ?? boundsOf([at(p0, 0), at(p1, T)]),\n center: at((p0 + p1) / 2, T / 2),\n pivot: walk.start\n });\n };\n\n const specs: readonly { readonly series?: string | undefined; readonly size: number }[] = spec.segments ?? [{ series, size: length }];\n const seen = new Set<string>();\n let cursor = 0;\n const spans = specs.map((segment, index) => {\n size(\"bar\", `segments[${index}].size`, segment.size);\n if (segment.series !== undefined) {\n if (seen.has(segment.series)) throw new Error(`describe.bar: series \"${segment.series}\" appears twice in the segments of \"${key}\".`);\n seen.add(segment.series);\n }\n const from = Math.min(cursor, length);\n cursor += segment.size;\n const to = Math.min(cursor, length);\n return { segment, index, p0: Math.min(from + Math.min(gap, from), to), p1: to };\n });\n\n const segments = spans.map(({ segment, index, p0, p1 }) =>\n // The rounding fades in as a segment nears the tip, so a growing stack never pops.\n part(p0, p1, radius - (length - p1), {\n key: segment.series === undefined ? `${key}/${index}` : `${key}/${segment.series}`,\n series: segment.series\n })\n );\n // The whole bar keeps the exact rectangle it was given.\n return part(0, length, radius, { key, series, bounds: { x, y, width, height }, segments });\n}\n\n/** Chart px at distance p along the walk and s across it, measured from the left (up) edge. */\nfunction frame({ x, y, width: w, height: h, baseline }: BarSpec): (p: number, s: number) => Point {\n switch (baseline) {\n case \"left\":\n return (p, s) => ({ x: x + p, y: y + s });\n case \"right\":\n return (p, s) => ({ x: x + w - p, y: y + h - s });\n case \"top\":\n return (p, s) => ({ x: x + w - s, y: y + p });\n case \"bottom\":\n return (p, s) => ({ x: x + s, y: y + h - p });\n }\n}\n","// describe.line: a straight-segment polyline, as d3.line() draws with its default curve.\n\nimport type { MarkGeometry, Point } from \"../../contracts/geometry\";\nimport { openOutline } from \"../outline\";\nimport { boundsOf, line, type LineSegment } from \"../segment\";\nimport { createWalk } from \"../walk\";\nimport { assemble, finite, size } from \"./mark\";\n\nexport interface LineSpec {\n readonly key: string;\n readonly series?: string;\n /** At least one point, in chart px. */\n readonly points: readonly Point[];\n /** Stroke width in px. Default 1, SVG's default. */\n readonly width?: number;\n}\n\n/** The walk is the line itself, first point to last. Its outline is open: the stroke. */\nexport function describeLine(spec: LineSpec): MarkGeometry {\n const { key, series, points } = spec;\n const width = size(\"line\", \"width\", spec.width ?? 1);\n const first = points[0];\n if (!first) throw new RangeError(`describe.line: \"${key}\" needs at least one point.`);\n points.forEach((p, i) => {\n finite(\"line\", `points[${i}].x`, p.x);\n finite(\"line\", `points[${i}].y`, p.y);\n });\n\n const segments: LineSegment[] = [];\n for (let i = 1; i < points.length; i++) {\n // A repeated point keeps the direction so far.\n segments.push(line(points[i - 1]!, points[i]!, segments[segments.length - 1]?.angle ?? 0));\n }\n if (segments.length === 0) segments.push(line(first, first));\n\n const walk = createWalk(segments);\n const box = boundsOf(points);\n const pad = width / 2;\n return assemble({\n key,\n series,\n walk,\n thickness: width,\n outline: openOutline(walk),\n bounds: { x: box.x - pad, y: box.y - pad, width: box.width + width, height: box.height + width },\n center: walk.point(0.5),\n pivot: first\n });\n}\n","// describe.point: a dot with no direction (a scatter point or a marker).\n\nimport type { MarkGeometry } from \"../../contracts/geometry\";\nimport { closedOutline } from \"../outline\";\nimport { arc, line } from \"../segment\";\nimport { createWalk } from \"../walk\";\nimport { assemble, finite, size } from \"./mark\";\n\nexport interface PointSpec {\n readonly key: string;\n readonly series?: string;\n readonly x: number;\n readonly y: number;\n /** Radius in px. */\n readonly r: number;\n}\n\n/**\n * Length 0, with start = end = centre, so travel does nothing while wiggle, pulse and flash still\n * work. Faces +x: the outline's sides are the quarter circles top, right, bottom and left.\n */\nexport function describePoint(spec: PointSpec): MarkGeometry {\n const { key, series } = spec;\n const center = { x: finite(\"point\", \"x\", spec.x), y: finite(\"point\", \"y\", spec.y) };\n const r = size(\"point\", \"r\", spec.r);\n const quarter = Math.PI / 2;\n return assemble({\n key,\n series,\n walk: createWalk([line(center, center)]),\n thickness: 2 * r,\n outline: closedOutline([\n [arc(center, r, (-3 * quarter) / 2, quarter)],\n [arc(center, r, -quarter / 2, quarter)],\n [arc(center, r, quarter / 2, quarter)],\n [arc(center, r, (3 * quarter) / 2, quarter)]\n ]),\n bounds: { x: center.x - r, y: center.y - r, width: 2 * r, height: 2 * r },\n center,\n pivot: center\n });\n}\n","// The public geometry builders. Reference charts and adapters share these, so a bar is described\n// the same way whoever drew it.\n\nimport { describeArc } from \"./arc\";\nimport { describeBar } from \"./bar\";\nimport { describeLine } from \"./line\";\nimport { describePoint } from \"./point\";\n\nexport const describe = {\n bar: describeBar,\n arc: describeArc,\n line: describeLine,\n point: describePoint\n};\n\nexport type { ArcSpec } from \"./arc\";\nexport type { BarSegmentSpec, BarSpec, Baseline } from \"./bar\";\nexport type { LineSpec } from \"./line\";\nexport type { PointSpec } from \"./point\";\n","// Transform helpers for effect authors: matrix and offset are public (docs/effects-guide.md).\n\nimport type { Matrix } from \"../contracts/drawing\";\nimport type { Point } from \"../contracts/geometry\";\n\nfunction translate(x: number, y: number): Matrix {\n return [1, 0, 0, 1, x, y];\n}\n\n/** Positive radians turn clockwise on screen, like SVG's rotate(). */\nfunction rotate(radians: number, about?: Point): Matrix {\n const cos = Math.cos(radians);\n const sin = Math.sin(radians);\n return around([cos, sin, -sin, cos, 0, 0], about);\n}\n\nfunction scale(sx: number, sy: number = sx, about?: Point): Matrix {\n return around([sx, 0, 0, sy, 0, 0], about);\n}\n\n/** Composes like an SVG transform list: multiply(a, b) applies b first, then a. No arguments gives the identity. */\nfunction multiply(...matrices: Matrix[]): Matrix {\n let result: Matrix = [1, 0, 0, 1, 0, 0];\n for (const m of matrices) result = product(result, m);\n return result;\n}\n\n/** Where the transform takes a point. */\nfunction apply(m: Matrix, point: Point): Point {\n const [a, b, c, d, e, f] = m;\n return { x: a * point.x + c * point.y + e, y: b * point.x + d * point.y + f };\n}\n\nfunction product(l: Matrix, r: Matrix): Matrix {\n const [a1, b1, c1, d1, e1, f1] = l;\n const [a2, b2, c2, d2, e2, f2] = r;\n return [\n a1 * a2 + c1 * b2,\n b1 * a2 + d1 * b2,\n a1 * c2 + c1 * d2,\n b1 * c2 + d1 * d2,\n a1 * e2 + c1 * f2 + e1,\n b1 * e2 + d1 * f2 + f1\n ];\n}\n\n/** A linear transform (no translation) moved so it keeps `about` fixed. */\nfunction around(m: Matrix, about: Point | undefined): Matrix {\n if (!about) return m;\n const [a, b, c, d] = m;\n return [a, b, c, d, about.x - a * about.x - c * about.y, about.y - b * about.x - d * about.y];\n}\n\n/** Builds and applies 2D transforms in SVG order, for `mark.set({ transform })` and `IconHandle.place()`. */\nexport const matrix = { translate, rotate, scale, multiply, apply };\n\n// Internal: iconFromSvg and the adapter read SVG transforms with these.\n\n/** The inverse transform. A singular matrix (it squashes everything onto a line) throws a RangeError. */\nexport function invert(m: Matrix): Matrix {\n const [a, b, c, d, e, f] = m;\n const det = a * d - b * c;\n if (!Number.isFinite(det) || Math.abs(det) < 1e-12) throw new RangeError(\"This transform can't be inverted: it has no area.\");\n return [d / det, -b / det, -c / det, a / det, (c * f - d * e) / det, (b * e - a * f) / det];\n}\n\n/** An SVG transform list, as in the transform attribute. An unknown or malformed function is skipped. */\nexport function parseTransform(source: string): Matrix {\n const parts: Matrix[] = [];\n for (const [, name, rawArgs = \"\"] of source.matchAll(/(matrix|translate|scale|rotate|skewX|skewY)\\s*\\(([^)]*)\\)/g)) {\n const args = rawArgs.trim().split(/[\\s,]+/).filter(Boolean).map(Number);\n if (!args.every(Number.isFinite)) continue;\n const [a = 0, b, c, d = 0, e = 0, f = 0] = args;\n const radians = (degrees: number): number => (degrees * Math.PI) / 180;\n switch (name) {\n case \"matrix\":\n if (args.length === 6) parts.push([a, b!, c!, d, e, f]);\n break;\n case \"translate\":\n parts.push(translate(a, b ?? 0));\n break;\n case \"scale\":\n parts.push(scale(a, b ?? a));\n break;\n case \"rotate\":\n parts.push(rotate(radians(a), b !== undefined && c !== undefined ? { x: b, y: c } : undefined));\n break;\n case \"skewX\":\n parts.push([1, 0, Math.tan(radians(a)), 1, 0, 0]);\n break;\n case \"skewY\":\n parts.push([1, Math.tan(radians(a)), 0, 1, 0, 0]);\n break;\n }\n }\n return multiply(...parts);\n}\n\n/** A point `distance` px from `point` in direction `angle` (screen radians). */\nexport function offset(point: Point, angle: number, distance: number): Point {\n return { x: point.x + distance * Math.cos(angle), y: point.y + distance * Math.sin(angle) };\n}\n","// samplesAlong: data points placed on a mark's walk, as data effects' samples. A page gives a host's\n// line its values this way: the points that drew it, projected onto the walk that describes it.\n// It reads only the MarkGeometry contract (path and length), so it works on any mark.\n\nimport type { Sample } from \"../contracts/data\";\nimport type { MarkGeometry, Point } from \"../contracts/geometry\";\n\n/** A data point in the mark's coordinates, with its value and, optionally, the x value behind it. */\nexport interface SamplePoint {\n readonly x: number;\n readonly y: number;\n readonly value: number;\n readonly at?: string | number | Date;\n}\n\n/** The grid that finds each point's nearest stretch of the walk: a point every px, up to this many. */\nconst MAX_GRID = 4096;\n/**\n * Golden-section steps that narrow a stretch of 2 grid steps down: to about 1e-12 px for a point on\n * the walk, and to well under 1e-6 px for one off it, where the nearest point is a flat minimum.\n */\nconst REFINE = 48;\nconst GOLDEN = (Math.sqrt(5) - 1) / 2;\n\n/**\n * Projects each point onto the nearest point of the mark's walk and returns the samples in `t` order\n * (points at the same `t` keep their order). A point on the walk, such as a vertex of the polyline it\n * drew, lands exactly where it is. Throws a RangeError on a point whose x, y or value isn't finite.\n */\nexport function samplesAlong(mark: MarkGeometry, points: readonly SamplePoint[]): Sample[] {\n if (typeof mark !== \"object\" || mark === null || typeof mark.path !== \"function\" || !Number.isFinite(mark.length)) {\n throw new TypeError(\"samplesAlong needs a MarkGeometry, as describe builds it.\");\n }\n if (!Array.isArray(points)) throw new TypeError(\"samplesAlong needs an array of points { x, y, value, at? }.\");\n points.forEach((p, i) => {\n for (const field of [\"x\", \"y\", \"value\"] as const) {\n const value: unknown = (p as Partial<SamplePoint> | null)?.[field];\n if (typeof value !== \"number\" || !Number.isFinite(value)) throw new RangeError(`samplesAlong: points[${i}].${field} must be a finite number, got ${String(value)}.`);\n }\n });\n\n const n = mark.length > 0 ? Math.min(MAX_GRID, Math.ceil(mark.length) + 1) : 1;\n const grid = Array.from({ length: n }, (_, i): Point => mark.path(n === 1 ? 0 : i / (n - 1)));\n return points\n .map((p, index) => ({ index, sample: { t: nearest(mark, grid, p), value: p.value, ...(p.at === undefined ? {} : { at: p.at }) } }))\n .sort((a, b) => a.sample.t - b.sample.t || a.index - b.index)\n .map(({ sample }) => sample);\n}\n\n/** The t of the walk's nearest point to `p`: the nearest grid point, then a golden-section search on the stretch either side of it. */\nfunction nearest(mark: MarkGeometry, grid: readonly Point[], p: Point): number {\n const n = grid.length;\n if (n === 1) return 0;\n let best = 0;\n let bestDistance = Infinity;\n grid.forEach((q, i) => {\n const d = squared(q, p);\n if (d < bestDistance) {\n best = i;\n bestDistance = d;\n }\n });\n const f = (t: number): number => squared(mark.path(t), p);\n let lo = Math.max(0, best - 1) / (n - 1);\n let hi = Math.min(n - 1, best + 1) / (n - 1);\n let a = hi - GOLDEN * (hi - lo);\n let b = lo + GOLDEN * (hi - lo);\n let fa = f(a);\n let fb = f(b);\n for (let step = 0; step < REFINE; step++) {\n if (fa <= fb) {\n hi = b;\n b = a;\n fb = fa;\n a = hi - GOLDEN * (hi - lo);\n fa = f(a);\n } else {\n lo = a;\n a = b;\n fa = fb;\n b = lo + GOLDEN * (hi - lo);\n fb = f(b);\n }\n }\n const t = (lo + hi) / 2;\n // The grid point itself unless the search found somewhere nearer, so a point at either end lands\n // on exactly 0 or 1, and a stretch that isn't one dip can't make it worse.\n const found = f(t) < bestDistance ? t : best / (n - 1);\n return found > 0 ? (found < 1 ? found : 1) : 0;\n}\n\nfunction squared(a: Point,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