expressive-charts 0.2.0 → 0.4.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 (46) hide show
  1. package/CHANGELOG.md +69 -1
  2. package/README.md +10 -10
  3. package/dist/define-DeZLs1h7.js +95 -0
  4. package/dist/define-DeZLs1h7.js.map +1 -0
  5. package/dist/drawing-Dz_IvJPB.d.cts +208 -0
  6. package/dist/drawing-Dz_IvJPB.d.ts +208 -0
  7. package/dist/effect-CdH5449m.d.ts +232 -0
  8. package/dist/effect-uYC8Vs6_.d.cts +232 -0
  9. package/dist/expressive-charts.css +8 -1
  10. package/dist/expressive-charts.css.d.cts +1 -0
  11. package/dist/expressive-charts.css.d.ts +1 -0
  12. package/dist/expressive-charts.global.js +50 -47
  13. package/dist/expressive-charts.global.js.map +1 -1
  14. package/dist/icons/sport.cjs +211 -152
  15. package/dist/icons/sport.cjs.map +1 -1
  16. package/dist/icons/sport.d.cts +5 -7
  17. package/dist/icons/sport.d.ts +5 -7
  18. package/dist/icons/sport.js +122 -71
  19. package/dist/icons/sport.js.map +1 -1
  20. package/dist/index.cjs +12647 -9513
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +929 -859
  23. package/dist/index.d.ts +929 -859
  24. package/dist/index.js +10452 -7822
  25. package/dist/index.js.map +1 -1
  26. package/dist/path-data-DnEckjY8.js +123 -0
  27. package/dist/path-data-DnEckjY8.js.map +1 -0
  28. package/dist/testing.cjs +2034 -1222
  29. package/dist/testing.cjs.map +1 -1
  30. package/dist/testing.d.cts +137 -141
  31. package/dist/testing.d.ts +137 -141
  32. package/dist/testing.js +696 -501
  33. package/dist/testing.js.map +1 -1
  34. package/dist/transition-DSRt2DH3.js +2053 -0
  35. package/dist/transition-DSRt2DH3.js.map +1 -0
  36. package/package.json +18 -6
  37. package/dist/chunk-CVXP2L2J.js +0 -1182
  38. package/dist/chunk-CVXP2L2J.js.map +0 -1
  39. package/dist/chunk-N5IF2RO2.js +0 -66
  40. package/dist/chunk-N5IF2RO2.js.map +0 -1
  41. package/dist/chunk-V5IUTXRW.js +0 -571
  42. package/dist/chunk-V5IUTXRW.js.map +0 -1
  43. package/dist/drawing-DWZIXIeR.d.cts +0 -194
  44. package/dist/drawing-DWZIXIeR.d.ts +0 -194
  45. package/dist/effect-CZUckY0l.d.ts +0 -245
  46. package/dist/effect-CcGdU41j.d.cts +0 -245
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/testing/index.ts","../src/core/registry.ts","../src/core/report.ts","../src/core/clock.ts","../src/core/motion.ts","../src/core/merge.ts","../src/core/easing.ts","../src/core/tween.ts","../src/core/runner.ts","../src/core/testing/recording.ts","../src/core/testing/context.ts","../src/core/testing/play.ts","../src/core/transition.ts","../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/testing/fixtures.ts","../src/testing/check.ts"],"sourcesContent":["// expressive-charts/testing: the conformance suite for effects, with the helpers it's built on, for\n// effects written inside the library or outside it. It imports no test runner, and it's a separate\n// entry, so nothing here reaches the main bundle or the script-tag build.\n\nexport { checkEffect, checkTransition, type CheckEffectOptions, type CheckTransitionOptions } from \"./check\";\nexport { fixturePairs, fixtures, type FixtureName, type FixturePairName } from \"./fixtures\";\nexport { play, testContext, type PlayOptions, type TestContext, type TestContextOptions } from \"../core/testing\";\nexport type { Drawn, DrawnIcon, DrawnPath, DrawnText, LayerCall, MarkCall, Picture, RecordingLayer, RecordingMark } from \"../core/testing\";\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 * 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","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","/**\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","/** 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 { 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","// 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","// In-memory versions of the drawing API, so effects can be tested with no DOM at all.\n\nimport type { IconHandle, Layer, MarkHandle, MarkStyle, Matrix, Paint, PathHandle, TextHandle, TextStyle } from \"../contracts/drawing\";\nimport type { Icon } from \"../contracts/icon\";\nimport type { EffectSlot } from \"../contracts/slots\";\nimport { mergeFields as merge } from \"../merge\";\nimport type { RunnerSurface, SurfaceGroup } from \"../runner\";\n\nexport interface DrawnIcon {\n readonly kind: \"icon\";\n readonly id: number;\n readonly icon: Icon;\n readonly size: number | undefined;\n /** Undefined until first placed, while the icon is hidden. */\n readonly transform: Matrix | undefined;\n}\n\nexport interface DrawnPath {\n readonly kind: \"path\";\n readonly id: number;\n readonly d: string;\n readonly paint: Paint;\n}\n\nexport interface DrawnText {\n readonly kind: \"text\";\n readonly id: number;\n readonly content: string;\n readonly style: TextStyle;\n}\n\nexport type Drawn = DrawnIcon | DrawnPath | DrawnText;\n\n/** Every call made on a layer or its handles, in order. Calls on removed handles are logged and ignored. */\nexport type LayerCall =\n | { readonly op: \"icon\"; readonly id: number; readonly icon: string; readonly size: number | undefined }\n | { readonly op: \"place\"; readonly id: number; readonly transform: Matrix }\n | { readonly op: \"path\"; readonly id: number; readonly d: string; readonly paint: Paint }\n | { readonly op: \"update-path\"; readonly id: number; readonly d: string; readonly paint: Partial<Paint> | undefined }\n | { readonly op: \"text\"; readonly id: number; readonly content: string; readonly style: TextStyle }\n | { readonly op: \"update-text\"; readonly id: number; readonly style: Partial<TextStyle>; readonly content: string | undefined }\n | { readonly op: \"remove\"; readonly id: number }\n | { readonly op: \"clear\" };\n\n/** What's on screen, without ids and with numbers rounded, so a full run can be compared with end(). */\nexport type Picture =\n | { readonly kind: \"icon\"; readonly icon: string; readonly size: number | undefined; readonly transform: readonly number[] | undefined }\n | { readonly kind: \"path\"; readonly d: string; readonly paint: Paint }\n | { readonly kind: \"text\"; readonly content: string; readonly style: TextStyle };\n\nexport interface RecordingLayer extends Layer {\n /** What's drawn now, in creation order (which is also stacking order). */\n readonly drawn: readonly Drawn[];\n readonly calls: readonly LayerCall[];\n /** `drawn` as plain data, numbers rounded to `decimals` (default 3). */\n picture(decimals?: number): Picture[];\n /** Remove everything, as the runner does when a run is cleared. */\n clear(): void;\n}\n\nexport function recordingLayer(): RecordingLayer {\n const drawn = new Map<number, Drawn>();\n const calls: LayerCall[] = [];\n let nextId = 1;\n\n // Replaces a live item; calls on removed handles change nothing.\n const replace = (id: number, next: (current: Drawn) => Drawn): void => {\n const current = drawn.get(id);\n if (current) drawn.set(id, next(current));\n };\n const remove = (id: number): void => {\n calls.push({ op: \"remove\", id });\n drawn.delete(id);\n };\n\n return {\n get drawn() {\n return [...drawn.values()];\n },\n get calls() {\n return calls;\n },\n icon(icon, options) {\n const id = nextId++;\n const size = options?.size;\n calls.push({ op: \"icon\", id, icon: icon.name, size });\n drawn.set(id, { kind: \"icon\", id, icon, size, transform: undefined });\n const handle: IconHandle = {\n place(transform) {\n calls.push({ op: \"place\", id, transform });\n replace(id, (current) => ({ ...current, transform }) as DrawnIcon);\n },\n remove: () => remove(id)\n };\n return handle;\n },\n path(d, paint) {\n const id = nextId++;\n calls.push({ op: \"path\", id, d, paint });\n drawn.set(id, { kind: \"path\", id, d, paint: { ...paint } });\n const handle: PathHandle = {\n update(nextD, nextPaint) {\n calls.push({ op: \"update-path\", id, d: nextD, paint: nextPaint });\n replace(id, (current) => {\n const path = current as DrawnPath;\n return { ...path, d: nextD, paint: merge(path.paint, nextPaint) };\n });\n },\n remove: () => remove(id)\n };\n return handle;\n },\n text(content, style) {\n const id = nextId++;\n calls.push({ op: \"text\", id, content, style });\n drawn.set(id, { kind: \"text\", id, content, style: { ...style } });\n const handle: TextHandle = {\n update(nextStyle, nextContent) {\n calls.push({ op: \"update-text\", id, style: nextStyle, content: nextContent });\n replace(id, (current) => {\n const text = current as DrawnText;\n return { ...text, style: merge(text.style, nextStyle), content: nextContent ?? text.content };\n });\n },\n remove: () => remove(id)\n };\n return handle;\n },\n picture(decimals = 3) {\n const round = rounder(decimals);\n return [...drawn.values()].map((item): Picture => {\n switch (item.kind) {\n case \"icon\":\n return { kind: \"icon\", icon: item.icon.name, size: item.size, transform: item.transform?.map(round) };\n case \"path\":\n return { kind: \"path\", d: item.d, paint: roundFields(item.paint, round) };\n case \"text\":\n return { kind: \"text\", content: item.content, style: { ...roundFields(item.style, round), at: { x: round(item.style.at.x), y: round(item.style.at.y) } } };\n }\n });\n },\n clear() {\n calls.push({ op: \"clear\" });\n drawn.clear();\n }\n };\n}\n\nexport type MarkCall = { readonly op: \"set\"; readonly style: MarkStyle } | { readonly op: \"reset\" };\n\nexport interface RecordingMark extends MarkHandle {\n /** The style now, after every set() and reset(). Empty means the mark's own style. */\n readonly style: MarkStyle;\n readonly calls: readonly MarkCall[];\n}\n\nexport function recordingMark(): RecordingMark {\n let style: MarkStyle = {};\n const calls: MarkCall[] = [];\n return {\n get style() {\n return style;\n },\n get calls() {\n return calls;\n },\n set(next) {\n calls.push({ op: \"set\", style: next });\n style = merge(style, next);\n },\n reset() {\n calls.push({ op: \"reset\" });\n style = {};\n }\n };\n}\n\n/** One overlay group a runner asked for. */\nexport interface RecordedGroup {\n readonly key: string;\n readonly slot: EffectSlot;\n /** The run's start order, which stacks groups. */\n readonly order: number;\n readonly layer: RecordingLayer;\n /** True once the runner cleared it. */\n readonly cleared: boolean;\n}\n\n/** A RunnerSurface in memory: every run's group is a recording layer, every mark a recording mark. */\nexport interface RecordingSurface extends RunnerSurface {\n /** Every group asked for, in order, cleared ones included. */\n readonly groups: readonly RecordedGroup[];\n /** The mark's handle, made on first use. */\n mark(key: string): RecordingMark;\n /** What's drawn now in the groups not yet cleared, optionally for one key, bottom to top (by order), as RecordingLayer.picture() gives it. */\n picture(key?: string): Picture[];\n}\n\nexport function recordingSurface(): RecordingSurface {\n const groups: { key: string; slot: EffectSlot; order: number; layer: RecordingLayer; cleared: boolean }[] = [];\n const marks = new Map<string, RecordingMark>();\n return {\n groups,\n group(key, slot, order) {\n const record = { key, slot, order, layer: recordingLayer(), cleared: false };\n groups.push(record);\n const group: SurfaceGroup = {\n icon: (icon, options) => record.layer.icon(icon, options),\n path: (d, paint) => record.layer.path(d, paint),\n text: (content, style) => record.layer.text(content, style),\n clear() {\n record.cleared = true;\n record.layer.clear();\n }\n };\n return group;\n },\n mark(key) {\n let mark = marks.get(key);\n if (!mark) marks.set(key, (mark = recordingMark()));\n return mark;\n },\n picture(key) {\n return groups\n .filter((group) => !group.cleared && (key === undefined || group.key === key))\n .sort((a, b) => a.order - b.order)\n .flatMap((group) => group.layer.picture());\n }\n };\n}\n\nfunction rounder(decimals: number): (value: number) => number {\n const factor = 10 ** decimals;\n return (value) => {\n const rounded = Math.round(value * factor) / factor;\n return rounded === 0 ? 0 : rounded;\n };\n}\n\nfunction roundFields<T extends object>(fields: T, round: (value: number) => number): T {\n const result: Record<string, unknown> = {};\n for (const [field, value] of Object.entries(fields)) result[field] = typeof value === \"number\" ? round(value) : value;\n return result as T;\n}\n","// An EffectContext for effect tests: a manual clock, its own motion, and recording drawing handles.\n\nimport { manualClock, type ManualClock } from \"../clock\";\nimport type { MarkData } from \"../contracts/data\";\nimport type { EffectContext } from \"../contracts/effect\";\nimport type { MarkGeometry } from \"../contracts/geometry\";\nimport type { Icon } from \"../contracts/icon\";\nimport { createMotion, type Motion, type MotionMode, type ScalingOverrides } from \"../motion\";\nimport { runScope } from \"../runner\";\nimport { recordingLayer, recordingMark, type RecordingLayer, type RecordingMark } from \"./recording\";\n\nexport interface TestContextOptions {\n /** The author's mode. Default \"presentation\". The device never asks for reduced motion here. */\n readonly mode?: MotionMode;\n /** Overrides for the duration scaling, as a page's createMotion({ scaling }) gives. */\n readonly scaling?: ScalingOverrides;\n readonly icons?: readonly Icon[];\n readonly batch?: { readonly index: number; readonly count: number };\n readonly previous?: MarkGeometry;\n}\n\nexport interface TestContext extends EffectContext {\n readonly motion: Motion;\n readonly clock: ManualClock;\n readonly layer: RecordingLayer;\n readonly mark: RecordingMark;\n /** Abort the run, as the runner does on leave or re-trigger. */\n abort(): void;\n /** The runner's cleanup after effect.clear(ctx): abort, empty the layer, reset the mark, drop onChange listeners. */\n clear(): void;\n /** Tell onChange listeners the geometry moved, as the runner does on every frame of a transition. */\n change(mark: MarkGeometry, data?: MarkData): void;\n}\n\nexport function testContext(options: TestContextOptions = {}): TestContext {\n const clock = manualClock();\n const motion = createMotion({\n mode: options.mode ?? \"presentation\",\n ...(options.scaling ? { scaling: options.scaling } : {}),\n reducedMotion: { matches: false, subscribe: () => () => {} }\n });\n const layer = recordingLayer();\n const mark = recordingMark();\n const icons = new Map((options.icons ?? []).map((icon) => [icon.name, icon]));\n // The same run scope the runner gives every run, so clear() here is the runner's cleanup.\n const scope = runScope({\n clock,\n motion,\n layer,\n mark,\n icons: { get: (name) => icons.get(name) },\n batch: options.batch ?? { index: 0, count: 1 },\n previous: options.previous\n });\n\n return {\n ...scope.context,\n motion,\n clock,\n layer,\n mark,\n abort: scope.abort,\n clear: scope.clear,\n change: scope.change\n };\n}\n","// Plays a run to its end on a manual clock, for effect tests.\n\nimport type { ManualClock } from \"../clock\";\n\nexport interface PlayOptions {\n /** Ms per frame. Default 16. */\n readonly frame?: number;\n /** Gives up after this many ms. Default 10 000. */\n readonly limit?: number;\n}\n\n/**\n * Advances the clock a frame at a time until `running` settles, letting promise callbacks run\n * between frames (so a sequence's next part starts on time). Resolves with the ms it advanced; throws\n * if `running` hasn't settled within the limit.\n */\nexport async function play(clock: ManualClock, running: Promise<unknown>, options: PlayOptions = {}): Promise<number> {\n const frame = options.frame ?? 16;\n const limit = options.limit ?? 10_000;\n let settled = false;\n running.then(\n () => (settled = true),\n () => (settled = true)\n );\n let elapsed = 0;\n await flush();\n while (!settled) {\n if (elapsed >= limit) throw new Error(`play: still running after ${limit} ms.`);\n clock.advance(frame);\n elapsed += frame;\n await flush();\n }\n return elapsed;\n}\n\n/** Lets pending promise callbacks run. */\nexport async function flush(): Promise<void> {\n for (let i = 0; i < 20; i++) await Promise.resolve();\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","// 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 labelBounds?: readonly Rect[] | undefined;\n readonly segments?: readonly MarkGeometry[];\n}\n\nexport function assemble({ key, series, walk, thickness, outline, bounds, center, pivot, labelBounds, 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 ...(labelBounds === undefined ? {} : { labelBounds }),\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/** A spec's `labelBounds`, checked: each box's numbers finite, its sizes ≥ 0. Charts give them every frame, so a good box costs four comparisons. */\nexport function labelBoxes(builder: string, boxes: readonly Rect[] | undefined): readonly Rect[] | undefined {\n if (!boxes) return boxes;\n for (let i = 0; i < boxes.length; i++) {\n const { x, y, width, height } = boxes[i]!;\n if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && width >= 0 && Number.isFinite(height) && height >= 0) continue;\n finite(builder, `labelBounds[${i}].x`, x);\n finite(builder, `labelBounds[${i}].y`, y);\n size(builder, `labelBounds[${i}].width`, width);\n size(builder, `labelBounds[${i}].height`, height);\n }\n return boxes;\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, Rect } from \"../../contracts/geometry\";\nimport { closedOutline } from \"../outline\";\nimport { arc, boundsOf, extremes, line, polar, TAU } from \"../segment\";\nimport { createWalk } from \"../walk\";\nimport { assemble, finite, labelBoxes, 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 /** The boxes of the text drawn for the mark, in the same px: passed through as `labelBounds`. */\n readonly labelBounds?: readonly Rect[];\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 labelBounds: labelBoxes(\"arc\", spec.labelBounds)\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, labelBoxes, 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 /** The boxes of the text drawn for the bar, its segments having none, in the same px: passed through as `labelBounds`. */\n readonly labelBounds?: readonly Rect[];\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 const labelBounds = labelBoxes(\"bar\", spec.labelBounds);\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; labelBounds?: readonly Rect[] | undefined; 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 }, labelBounds, 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, Rect } from \"../../contracts/geometry\";\nimport { openOutline } from \"../outline\";\nimport { boundsOf, line, type LineSegment } from \"../segment\";\nimport { createWalk } from \"../walk\";\nimport { assemble, finite, labelBoxes, 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 /** The boxes of the text drawn for the mark, in the same px: passed through as `labelBounds`. */\n readonly labelBounds?: readonly Rect[];\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 labelBounds: labelBoxes(\"line\", spec.labelBounds)\n });\n}\n","// describe.point: a dot with no direction (a scatter point or a marker).\n\nimport type { MarkGeometry, Rect } from \"../../contracts/geometry\";\nimport { closedOutline } from \"../outline\";\nimport { arc, line } from \"../segment\";\nimport { createWalk } from \"../walk\";\nimport { assemble, finite, labelBoxes, 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 /** The boxes of the text drawn for the mark, in the same px: passed through as `labelBounds`. */\n readonly labelBounds?: readonly Rect[];\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 labelBounds: labelBoxes(\"point\", spec.labelBounds)\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","// The marks checkEffect runs an effect on by default: one of each kind the geometry builders\n// describe, plus the awkward cases (a bar growing the other way, a stack with a gap, a bar shorter\n// than most icons, a point whose walk has no length). Each has a moved twin: the same mark somewhere\n// else, as a resize or a transition's next frame leaves it, for the check that effects follow onChange.\n// checkTransition's pairs are made of the same marks.\n\nimport { describe as build, type MarkGeometry } from \"../core\";\n\nexport type FixtureName = \"bar\" | \"negative bar\" | \"column\" | \"stacked\" | \"short bar\" | \"slice\" | \"line\" | \"point\";\n\n/** Every kind of mark an effect meets: bars (plain, negative, a column, stacked, too short), a donut slice, a line and a point. */\nexport const fixtures: Readonly<Record<FixtureName, MarkGeometry>> = /* @__PURE__ */ makeFixtures(false);\n\n/**\n * Each fixture moved: the same key and series, somewhere else and another size. The bars are a row\n * lower and shorter (the stack's segments in another ratio), the slice turned and the ring smaller,\n * the line further revealed and rescaled, and the point moved.\n */\nexport const movedFixtures: Readonly<Record<FixtureName, MarkGeometry>> = /* @__PURE__ */ makeFixtures(true);\n\nexport type FixturePairName = \"slice and column\" | \"bar and column\" | \"two slices\" | \"two lines\" | \"two points\";\n\n/**\n * The pairs checkTransition runs a transition effect between by default, each both ways: a slice and\n * a column (a mark that goes round its pivot and one that doesn't), a bar and a column, two slices,\n * two lines and two points. The second of two alike is the first's moved twin.\n */\nexport const fixturePairs: Readonly<Record<FixturePairName, readonly [MarkGeometry, MarkGeometry]>> = /* @__PURE__ */ Object.freeze({\n \"slice and column\": [fixtures.slice, fixtures.column],\n \"bar and column\": [fixtures.bar, fixtures.column],\n \"two slices\": [fixtures.slice, movedFixtures.slice],\n \"two lines\": [fixtures.line, movedFixtures.line],\n \"two points\": [fixtures.point, movedFixtures.point]\n} as const);\n\nfunction makeFixtures(moved: boolean): Readonly<Record<FixtureName, MarkGeometry>> {\n const y = moved ? 30 : 0;\n const bar = (width: number, more: Partial<Parameters<typeof build.bar>[0]> = {}): MarkGeometry =>\n build.bar({ key: \"Okafor\", series: \"goals\", x: 0, y, width, height: 20, baseline: \"left\", ...more });\n const [goals, assists] = moved ? [120, 82] : [160, 62];\n return Object.freeze({\n bar: bar(moved ? 160 : 200, { radius: 4 }),\n \"negative bar\": build.bar({ key: \"n\", series: \"goals\", x: moved ? 30 : 0, y, width: moved ? 90 : 120, height: 20, baseline: \"right\" }),\n column: build.bar({ key: \"c\", series: \"goals\", x: moved ? 30 : 0, y: moved ? 40 : 0, width: 20, height: moved ? 110 : 150, baseline: \"bottom\" }),\n stacked: bar(goals + assists, { series: undefined, gap: 2, segments: [{ series: \"goals\", size: goals }, { series: \"assists\", size: assists }] }),\n \"short bar\": bar(moved ? 4 : 6),\n slice: moved\n ? build.arc({ key: \"Saved\", cx: 140, cy: 130, inner: 60, outer: 100, start: 0.5, end: 2 })\n : build.arc({ key: \"Saved\", cx: 150, cy: 150, inner: 70, outer: 116, start: 0.3, end: 2.4 }),\n line: build.line({\n key: \"goals\",\n series: \"goals\",\n points: moved\n ? [{ x: 0, y: 90 }, { x: 64, y: 58 }, { x: 128, y: 82 }, { x: 192, y: 26 }, { x: 256, y: 40 }]\n : [{ x: 0, y: 100 }, { x: 80, y: 60 }, { x: 160, y: 90 }, { x: 240, y: 20 }],\n width: 2\n }),\n point: build.point({ key: \"p\", x: moved ? 40 : 10, y: moved ? 25 : 10, r: 3 })\n });\n}\n","// checkEffect and checkTransition: the conformance checks from plan §8 for one effect, on many marks\n// or pairs of marks. They import no test runner: each runs every check on every mark, then throws one\n// Error that lists each failure, so `await checkEffect(effect)` works in Vitest, Jest, node:test or Mocha.\n\nimport type { AnyMarkEffect, DataEffect, GeometryEffect, Icon, MarkData, MarkGeometry, TransitionContext, TransitionEffect } from \"../core\";\nimport { describeValue, isMarkEffect } from \"../core/registry\";\nimport { flush, play, testContext, type Picture, type TestContext, type TestContextOptions } from \"../core/testing\";\nimport { isTransitionEffect } from \"../core/transition\";\nimport { fixturePairs, fixtures, movedFixtures, type FixtureName } from \"./fixtures\";\n\nexport interface CheckEffectOptions<D = unknown> {\n /**\n * The marks to check on: named, or a list such as a chart's `marks()` (each named by its key in the\n * report). Default: `fixtures`, every kind of mark.\n */\n readonly marks?: Readonly<Record<string, MarkGeometry>> | readonly MarkGeometry[];\n /** The icons the effect looks up by name, through `ctx.icons`. Default: none. */\n readonly icons?: readonly Icon[];\n /**\n * For a data effect, each mark's data. Default: no datum, values from 0 to 1 along the walk, and no\n * related series, so an effect that reads its rows or `needs` related series has to pass this.\n */\n readonly data?: (mark: MarkGeometry) => MarkData<D>;\n /**\n * The same mark moved (a resize, a transition's next frame): another geometry with the same key, for\n * the check that the effect follows `onChange`. Undefined skips that check on the mark. Default:\n * each fixture's moved twin, and nothing for other marks, so a page's own marks pass this or skip it.\n */\n readonly moved?: (mark: MarkGeometry) => MarkGeometry | undefined;\n /** The mark's place among the marks of its event, for effects that read `ctx.batch` (stagger). Default: the only one. */\n readonly batch?: { readonly index: number; readonly count: number };\n /** What the report calls the effect. Default: \"the effect\". */\n readonly name?: string;\n}\n\n/** A data effect typed for its own rows: data(mark) has to give them. */\ntype WithData<D> = CheckEffectOptions<D> & { readonly data: (mark: MarkGeometry) => MarkData<D> };\n\n/**\n * Runs the conformance checks on every mark (`options.marks`, or the fixtures):\n * 1. a full run ends with the same picture and mark style as `end()`;\n * 2. clearing leaves nothing drawn, the mark's own style, and no frames running;\n * 3. an abort mid-run settles the run (it resolves, without more frames) and clears to nothing;\n * 4. with motion off, no frames run and the run draws what `end()` draws;\n * 5. after a full run, and after `end()`, a `change()` to the moved mark (`options.moved`) leaves the\n * picture and mark style `end()` draws on it, so an effect that should stay attached follows `onChange`.\n *\n * Resolves when every check passes. Otherwise it rejects with one Error that lists every failure:\n * the mark, the check and what differed. A data effect typed for its own rows needs `data`, and so\n * does one that `needs` related series.\n */\nexport function checkEffect(effect: GeometryEffect | DataEffect<unknown>, options?: CheckEffectOptions<unknown>): Promise<void>;\nexport function checkEffect<D>(effect: GeometryEffect | DataEffect<D>, options: WithData<D>): Promise<void>;\nexport async function checkEffect(effect: AnyMarkEffect, options: CheckEffectOptions<any> = {}): Promise<void> {\n if (!isMarkEffect(effect)) {\n const hint = isTransitionEffect(effect) ? \"; check it with checkTransition\" : \"\";\n throw new TypeError(`checkEffect needs a mark effect (kind \"geometry\" or \"data\"), got ${describeValue(effect)}${hint}.`);\n }\n const name = options.name ?? \"the effect\";\n const related = effect.kind === \"data\" ? (effect.needs?.related ?? []) : [];\n if (related.length > 0 && !options.data) {\n throw new TypeError(\n `checkEffect: ${name} needs the related series ${related.map((s) => `\"${s}\"`).join(\", \")}, so pass data(mark) with them: the default data has no related series.`\n );\n }\n const marks = named(options.marks ?? fixtures);\n if (marks.length === 0) throw new TypeError(\"checkEffect: there are no marks to check on.\");\n\n const dataOf = (mark: MarkGeometry): MarkData<unknown> | undefined => (effect.kind === \"data\" ? (options.data ?? defaultData)(mark) : undefined);\n const failures: string[] = [];\n for (const [markName, mark] of marks) {\n let data: MarkData<unknown> | undefined;\n try {\n data = dataOf(mark);\n } catch (error) {\n failures.push(`on ${markName}: data(mark) threw ${describeError(error)}`);\n continue;\n }\n let moved: Moved | undefined;\n try {\n moved = movedSubject(effect, (options.moved ?? movedFixture)(mark), dataOf);\n } catch (error) {\n failures.push(`on ${markName}: the moved mark, or its data, threw ${describeError(error)}`);\n }\n const subject: Subject = {\n context: (more = {}) => testContext({ icons: options.icons, batch: options.batch, ...more }),\n run: (ctx) => promised(effect.kind === \"data\" ? effect.run(mark, data!, ctx) : effect.run(mark, ctx)),\n end: (ctx) => (effect.kind === \"data\" ? effect.end(mark, data!, ctx) : effect.end(mark, ctx)),\n clear: (ctx) => effect.clear(ctx),\n moved\n };\n for (const check of CHECKS) {\n const problem = await attempt(check, subject);\n if (problem) failures.push(`on ${markName}, ${check.title}: ${problem}`);\n }\n }\n\n if (failures.length > 0) throw new Error(`checkEffect found ${problems(failures)} with ${name}:\\n${list(failures)}`);\n}\n\nexport interface CheckTransitionOptions {\n /**\n * The pairs to check on, each as [a, b] and run both ways: named, or a list (each named by its\n * marks' keys in the report). Default: `fixturePairs`, a slice and a column, a bar and a column,\n * two slices, two lines and two points.\n */\n readonly pairs?: Readonly<Record<string, readonly [MarkGeometry, MarkGeometry]>> | readonly (readonly [MarkGeometry, MarkGeometry])[];\n /** The icons the effect looks up by name, through `ctx.icons`. Default: none. */\n readonly icons?: readonly Icon[];\n /** What the report calls the effect. Default: \"the effect\". */\n readonly name?: string;\n}\n\n/** Where the retrace check compares a run forward with a run back. */\nconst RETRACE_AT: readonly number[] = [0.25, 0.5, 0.75];\n\n/**\n * Runs the conformance checks for a transition effect on every pair (`options.pairs`, or the fixture\n * pairs), from a to b and from b to a:\n * 1. a full run ends with the same picture as `end()`;\n * 2. clearing leaves nothing drawn and no frames running;\n * 3. an abort mid-run settles the run (it resolves, without more frames) and clears to nothing;\n * 4. with motion off, no frames run and the run draws what `end()` draws;\n * 5. a run from `start: 0.5` ends with the same picture as `end()`;\n * 6. it retraces: at p = 0.25, 0.5 and 0.75, a run from b to a from `start: 1 - p` begins with the\n * picture a run from a to b begins with from `start: p`, the picture a full run draws at p. So a\n * switch back mid-way doesn't jump, and a pairing that depends on which mark is `from` fails.\n *\n * Resolves when every check passes. Otherwise it rejects with one Error that lists every failure:\n * the pair, which way, the check and what differed.\n */\nexport async function checkTransition(effect: TransitionEffect, options: CheckTransitionOptions = {}): Promise<void> {\n if (!isTransitionEffect(effect)) {\n const hint = isMarkEffect(effect) ? \"; check it with checkEffect\" : \"\";\n throw new TypeError(`checkTransition needs a transition effect (kind \"transition\" with run, end and clear), got ${describeTransition(effect)}${hint}.`);\n }\n const name = options.name ?? \"the effect\";\n const pairs = namedPairs(options.pairs ?? fixturePairs);\n if (pairs.length === 0) throw new TypeError(\"checkTransition: there are no pairs to check on.\");\n\n const failures: string[] = [];\n for (const [pairName, [a, b]] of pairs) {\n for (const [way, from, to] of [[\"a to b\", a, b], [\"b to a\", b, a]] as const) {\n for (const check of COMMON) {\n const problem = await attempt(check, transitionSubject(effect, from, to, 0, options.icons));\n if (problem) failures.push(`on ${pairName}, ${way}, ${check.title}: ${problem}`);\n }\n const problem = await attempt(FULL_RUN, transitionSubject(effect, from, to, 0.5, options.icons));\n if (problem) failures.push(`on ${pairName}, ${way}, a run from start: 0.5 should end with the same picture as end(): ${problem}`);\n }\n let problem: string | undefined;\n try {\n problem = await retraces(effect, a, b, options.icons);\n } catch (error) {\n problem = `it threw ${describeError(error)}`;\n }\n if (problem) failures.push(`on ${pairName}, a run back should retrace the run forward: ${problem}`);\n }\n\n if (failures.length > 0) throw new Error(`checkTransition found ${problems(failures)} with ${name}:\\n${list(failures)}`);\n}\n\n/** A test context that is also a transition's, starting at `start`. */\ntype TransitionTestContext = TestContext & TransitionContext;\n\nfunction transitionContext(start: number, options: TestContextOptions): TransitionTestContext {\n return { ...testContext(options), start };\n}\n\n/** One transition effect on one pair, one way, from `start`, as a Subject. Its contexts carry `start`. */\nfunction transitionSubject(effect: TransitionEffect, from: MarkGeometry, to: MarkGeometry, start: number, icons: readonly Icon[] | undefined): Subject {\n return {\n context: (more = {}) => transitionContext(start, { icons, ...more }),\n run: (ctx) => promised(effect.run(from, to, ctx as TransitionTestContext)),\n end: (ctx) => effect.end(from, to, ctx as TransitionTestContext),\n clear: (ctx) => effect.clear(ctx as TransitionTestContext),\n moved: undefined\n };\n}\n\n/** What a run from `start` draws before its first frame, after which it's aborted and cleared. */\nasync function opening(effect: TransitionEffect, from: MarkGeometry, to: MarkGeometry, start: number, icons: readonly Icon[] | undefined): Promise<Picture[]> {\n const ctx = transitionContext(start, { icons });\n const run = track(promised(effect.run(from, to, ctx)));\n await flush();\n const picture = ctx.layer.picture();\n ctx.abort();\n await settle(run);\n effect.clear(ctx);\n ctx.clear();\n if (run.failed) throw run.error;\n return picture;\n}\n\n/** The retrace check (6): what differs between a run back from 1 - p and a run forward from p, or undefined. */\nasync function retraces(effect: TransitionEffect, a: MarkGeometry, b: MarkGeometry, icons: readonly Icon[] | undefined): Promise<string | undefined> {\n for (const p of RETRACE_AT) {\n const forward = await opening(effect, a, b, p, icons);\n const back = await opening(effect, b, a, 1 - p, icons);\n if (same(back, forward)) continue;\n const index = back.findIndex((item, i) => !same(item, forward[i]));\n const what =\n back.length !== forward.length\n ? `${back.length} ${back.length === 1 ? \"item\" : \"items\"} (${show(back)}) where the run from a to b from start: ${p} begins with ${forward.length} (${show(forward)})`\n : `item ${index + 1} unlike the run from a to b from start: ${p}: ${difference(back[index], forward[index])}`;\n return `the run from b to a from start: ${1 - p} begins with ${what}`;\n }\n return undefined;\n}\n\n/** How a drawn item differs from another: its first differing field, and for long text the part where they part. */\nfunction difference(actual: unknown, expected: unknown): string {\n if (typeof actual !== \"object\" || typeof expected !== \"object\" || actual === null || expected === null) return `${show(actual)}, not ${show(expected)}`;\n const a = actual as Record<string, unknown>;\n const b = expected as Record<string, unknown>;\n for (const field of new Set([...Object.keys(a), ...Object.keys(b)])) {\n const x = a[field];\n const y = b[field];\n if (same(x, y)) continue;\n if (typeof x !== \"string\" || typeof y !== \"string\") return `its ${field} is ${show(x)}, not ${show(y)}`;\n let at = 0;\n while (at < x.length && x[at] === y[at]) at++;\n const from = Math.max(0, at - 24);\n const part = (text: string): string => `${from > 0 ? \"…\" : \"\"}${text.slice(from, at + 24)}${at + 24 < text.length ? \"…\" : \"\"}`;\n return `its ${field} parts at character ${at + 1}: ${JSON.stringify(part(x))}, not ${JSON.stringify(part(y))}`;\n }\n return `${show(actual)}, not ${show(expected)}`;\n}\n\nfunction namedPairs(\n pairs: Readonly<Record<string, readonly [MarkGeometry, MarkGeometry]>> | readonly (readonly [MarkGeometry, MarkGeometry])[]\n): [string, readonly [MarkGeometry, MarkGeometry]][] {\n if (!Array.isArray(pairs)) return Object.entries(pairs as Readonly<Record<string, readonly [MarkGeometry, MarkGeometry]>>).map(([name, pair]) => [`the ${name}`, pair]);\n return (pairs as readonly (readonly [MarkGeometry, MarkGeometry])[]).map((pair, i) => {\n const [a, b] = pair;\n const keys = a?.key === b?.key ? `\"${String(a?.key)}\"` : `\"${String(a?.key)}\" and \"${String(b?.key)}\"`;\n return [`pair ${i + 1} (${keys})`, pair];\n });\n}\n\nfunction describeTransition(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`;\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\n/** One effect on one mark (or one pair), ready to run on fresh contexts. */\ninterface Subject {\n context(options?: TestContextOptions): TestContext;\n /** Starts a run; throws if run() doesn't return a promise. */\n run(ctx: TestContext): Promise<void>;\n end(ctx: TestContext): void;\n /** The effect's own clear(). */\n clear(ctx: TestContext): void;\n /** The mark moved, for the onChange check; undefined skips it. */\n readonly moved: Moved | undefined;\n}\n\n/** A check's problem on the subject, or undefined; throwing counts as one. */\nasync function attempt(check: Check, subject: Subject): Promise<string | undefined> {\n try {\n return await check.test(subject);\n } catch (error) {\n return `it threw ${describeError(error)}`;\n }\n}\n\n/** run()'s result, which must be a promise. */\nfunction promised(running: unknown): Promise<void> {\n if (typeof (running as Promise<void> | undefined)?.then !== \"function\") throw new TypeError(`run() must return a promise, got ${describeValue(running)}.`);\n return running as Promise<void>;\n}\n\nconst problems = (failures: readonly string[]): string => (failures.length === 1 ? \"1 problem\" : `${failures.length} problems`);\nconst list = (failures: readonly string[]): string => failures.map((failure) => `- ${failure}`).join(\"\\n\");\n\n/** The moved mark, with its data. */\ninterface Moved {\n /** Tells the run's onChange listeners the mark moved, with its data there, as the runner does. */\n change(ctx: TestContext): void;\n /** end() on the moved mark. */\n end(ctx: TestContext): void;\n}\n\n/** The moved twin of a fixture (the same object, whatever it is named); nothing for other marks. */\nfunction movedFixture(mark: MarkGeometry): MarkGeometry | undefined {\n const name = (Object.keys(fixtures) as FixtureName[]).find((fixture) => fixtures[fixture] === mark);\n return name === undefined ? undefined : movedFixtures[name];\n}\n\nfunction movedSubject(effect: AnyMarkEffect, mark: MarkGeometry | undefined, dataOf: (mark: MarkGeometry) => MarkData<unknown> | undefined): Moved | undefined {\n if (mark === undefined) return undefined;\n const data = dataOf(mark);\n return {\n change: (ctx) => ctx.change(mark, data),\n end: (ctx) => (effect.kind === \"data\" ? effect.end(mark, data!, ctx) : effect.end(mark, ctx))\n };\n}\n\ninterface Check {\n readonly title: string;\n /** What went wrong, or undefined. Throwing counts as a failure too. */\n test(subject: Subject): Promise<string | undefined>;\n}\n\nconst FULL_RUN: Check = {\n title: \"a full run should end with the same picture and mark style as end()\",\n async test(subject) {\n const ran = subject.context();\n const run = track(subject.run(ran));\n await play(ran.clock, run.done);\n if (run.failed) return `run() rejected with ${describeError(run.error)}`;\n const ended = subject.context();\n subject.end(ended);\n return compare(ran, ended, \"after the run\");\n }\n};\n\n/** The checks for every kind of effect: checkEffect's first four, which checkTransition runs too. */\nconst COMMON: readonly Check[] = [\n FULL_RUN,\n {\n title: \"clearing should leave nothing behind\",\n async test(subject) {\n const ctx = subject.context();\n const run = track(subject.run(ctx));\n await play(ctx.clock, run.done);\n subject.clear(ctx);\n ctx.clear();\n // Nothing may come back afterwards, from a listener or a tween that outlived the run.\n ctx.clock.advance(48);\n await flush();\n return leftovers(ctx);\n }\n },\n {\n title: \"an abort mid-run should settle the run and clear to nothing\",\n async test(subject) {\n const ctx = subject.context();\n const run = track(subject.run(ctx));\n ctx.clock.advance(16);\n ctx.clock.advance(16);\n ctx.abort();\n await settle(run);\n if (!run.settled) return \"run() was still running after the abort; it should resolve once ctx.signal aborts, without more frames\";\n if (run.failed) return `run() rejected with ${describeError(run.error)} (it should resolve, aborted or not)`;\n subject.clear(ctx);\n ctx.clear();\n return leftovers(ctx);\n }\n },\n {\n title: \"with motion off, no frames should run and the end state should be drawn\",\n async test(subject) {\n const ctx = subject.context({ mode: \"off\" });\n const run = track(subject.run(ctx));\n const framesAtStart = !ctx.clock.idle;\n await settle(run);\n if (!run.settled) return \"run() didn't finish; with motion off ctx.tween() ends at once, so wait only through it, never on a timer\";\n if (run.failed) return `run() rejected with ${describeError(run.error)}`;\n if (framesAtStart || !ctx.clock.idle) return \"it asked for animation frames\";\n const ended = subject.context({ mode: \"off\" });\n subject.end(ended);\n return compare(ctx, ended, \"after the run with motion off\");\n }\n }\n];\n\nconst CHECKS: readonly Check[] = [\n ...COMMON,\n {\n title: \"a change() to the moved mark should leave what end() draws on it\",\n async test(subject) {\n const { moved } = subject;\n if (!moved) return undefined;\n const problems: string[] = [];\n\n const ran = subject.context();\n const run = track(subject.run(ran));\n await play(ran.clock, run.done);\n if (run.failed) return `run() rejected with ${describeError(run.error)}`;\n moved.change(ran);\n if (!(await finish(ran))) return \"it was still animating 10 s after the change()\";\n const ended = subject.context();\n moved.end(ended);\n const afterRun = compare(ran, ended, \"after a full run and a change()\");\n if (afterRun) problems.push(afterRun);\n\n // With motion off the runner draws end() instead of running, and changes still come.\n const still = subject.context({ mode: \"off\" });\n subject.end(still);\n moved.change(still);\n await flush();\n const endedOff = subject.context({ mode: \"off\" });\n moved.end(endedOff);\n const afterEnd = compare(still, endedOff, \"after end() and a change()\");\n if (afterEnd) problems.push(afterEnd);\n return problems.length > 0 ? problems.join(\"; \") : undefined;\n }\n }\n];\n\n/** Runs frames until nothing animates (an effect may ease to the new geometry); false if it's still going after 10 s. */\nasync function finish(ctx: TestContext): Promise<boolean> {\n await flush();\n for (let elapsed = 0; !ctx.clock.idle; elapsed += 16) {\n if (elapsed >= 10_000) return false;\n ctx.clock.advance(16);\n await flush();\n }\n return true;\n}\n\n/** No datum, values 0 to 1 along the walk, no related series. */\nconst defaultData = (): MarkData<unknown> => ({\n datum: undefined,\n samples: [\n { t: 0, value: 0 },\n { t: 1, value: 1 }\n ],\n related: () => undefined\n});\n\nfunction named(marks: Readonly<Record<string, MarkGeometry>> | readonly MarkGeometry[]): [string, MarkGeometry][] {\n if (!Array.isArray(marks)) return Object.entries(marks as Readonly<Record<string, MarkGeometry>>).map(([name, mark]) => [`the ${name}`, mark]);\n const seen = new Map<string, number>();\n return (marks as readonly MarkGeometry[]).map((mark) => {\n const count = (seen.get(mark.key) ?? 0) + 1;\n seen.set(mark.key, count);\n return [`mark \"${mark.key}\"${count > 1 ? ` (${count})` : \"\"}`, mark];\n });\n}\n\ninterface Tracked {\n /** Resolves when the run settles, either way. */\n readonly done: Promise<void>;\n readonly settled: boolean;\n readonly failed: boolean;\n readonly error: unknown;\n}\n\nfunction track(running: Promise<void>): Tracked {\n const state = { settled: false, failed: false, error: undefined as unknown };\n const done = running.then(\n () => {\n state.settled = true;\n },\n (error: unknown) => {\n Object.assign(state, { settled: true, failed: true, error });\n }\n );\n return Object.assign(state, { done });\n}\n\n/** Lets promise callbacks run, with no frames, until the run settles or plainly won't. */\nasync function settle(run: Tracked): Promise<void> {\n for (let i = 0; i < 10 && !run.settled; i++) await flush();\n}\n\n/** What differs between two contexts' pictures and mark styles, or undefined. */\nfunction compare(actual: TestContext, expected: TestContext, when: string): string | undefined {\n const problems: string[] = [];\n const drawn = actual.layer.picture();\n const wanted = expected.layer.picture();\n if (!same(drawn, wanted)) {\n const index = drawn.findIndex((item, i) => !same(item, wanted[i]));\n problems.push(\n drawn.length !== wanted.length\n ? `${drawn.length} ${drawn.length === 1 ? \"item is\" : \"items are\"} drawn ${when} but end() draws ${wanted.length} (${show(drawn)} vs ${show(wanted)})`\n : `item ${index + 1} drawn ${when} is ${show(drawn[index])} but end() draws ${show(wanted[index])}`\n );\n }\n const style = rounded(actual.mark.style);\n const wantedStyle = rounded(expected.mark.style);\n if (!same(style, wantedStyle)) problems.push(`the mark's style ${when} is ${show(style)} but end() leaves ${show(wantedStyle)}`);\n return problems.length > 0 ? problems.join(\"; \") : undefined;\n}\n\n/** What a cleared context still has: drawings, a mark style, running frames. */\nfunction leftovers(ctx: TestContext): string | undefined {\n const problems: string[] = [];\n if (ctx.layer.drawn.length > 0) problems.push(`${show(ctx.layer.picture())} is still drawn`);\n if (Object.keys(ctx.mark.style).length > 0) problems.push(`the mark's style is still ${show(ctx.mark.style)}`);\n if (!ctx.clock.idle) problems.push(\"animation frames are still running\");\n return problems.length > 0 ? problems.join(\"; \") : undefined;\n}\n\n/** Deep equality for plain data, ignoring key order. */\nfunction same(a: unknown, b: unknown): boolean {\n if (a === b || (Number.isNaN(a) && Number.isNaN(b))) return true;\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n const keysA = Object.keys(a).filter((key) => (a as Record<string, unknown>)[key] !== undefined);\n const keysB = Object.keys(b).filter((key) => (b as Record<string, unknown>)[key] !== undefined);\n return keysA.length === keysB.length && keysA.every((key) => same((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key]));\n}\n\n/** Numbers rounded to 0.001, as pictures are, so float noise in a style isn't a difference. */\nfunction rounded(value: unknown): unknown {\n if (typeof value === \"number\") {\n const round = Math.round(value * 1000) / 1000;\n return round === 0 ? 0 : round;\n }\n if (Array.isArray(value)) return value.map(rounded);\n if (typeof value === \"object\" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, field]) => [key, rounded(field)]));\n return value;\n}\n\nconst LONGEST = 240;\n\nfunction show(value: unknown): string {\n const text = JSON.stringify(value) ?? String(value);\n return text.length > LONGEST ? `${text.slice(0, LONGEST - 1)}…` : text;\n}\n\nfunction describeError(error: unknown): string {\n return error instanceof Error ? `${error.name}: ${error.message}` : show(error);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmFO,SAAS,aAAa,OAAwC;AACnE,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,QAAM,SAAS;AACf,UACG,OAAO,SAAS,cAAc,OAAO,SAAS,WAC/C,OAAO,OAAO,QAAQ,cACtB,OAAO,OAAO,QAAQ,cACtB,OAAO,OAAO,UAAU;AAE5B;AAGO,SAAS,cAAc,OAAwB;AACpD,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO,UAAU,OAAO,SAAS,OAAO;AACzF,QAAM,OAAQ,MAA6B;AAC3C,MAAI,SAAS,aAAc,QAAO;AAClC,MAAI,SAAS,cAAc,SAAS,OAAQ,QAAO,KAAK,IAAI;AAC5D,SAAO,SAAS,SAAY,2BAA2B,qBAAqB,KAAK,UAAU,IAAI,CAAC;AAClG;;;AChG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8B,GAAG,GAAI,EAA8B,GAAG,CAAC,CAAC;AAC7I;AAGA,SAAS,QAAQ,OAAyB;AACxC,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,QAAQ,KAAK,MAAM,QAAQ,GAAI,IAAI;AACzC,WAAO,UAAU,IAAI,IAAI;AAAA,EAC3B;AACA,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,IAAI,OAAO;AAClD,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO,OAAO,YAAY,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,QAAQ,KAAK,CAAC,CAAC,CAAC;AAC7I,SAAO;AACT;AAEA,IAAM,UAAU;AAEhB,SAAS,KAAK,OAAwB;AACpC,QAAM,OAAO,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;AAClD,SAAO,KAAK,SAAS,UAAU,GAAG,KAAK,MAAM,GAAG,UAAU,CAAC,CAAC,WAAM;AACpE;AAEA,SAAS,cAAc,OAAwB;AAC7C,SAAO,iBAAiB,QAAQ,GAAG,MAAM,IAAI,KAAK,MAAM,OAAO,KAAK,KAAK,KAAK;AAChF;","names":["id","list","settle","finish","motion","size","rounded","motion","frame","rounded","first","problem","problems"]}
1
+ {"version":3,"file":"testing.cjs","names":["merge","show","show","build"],"sources":["../src/core/registry.ts","../src/core/report.ts","../src/core/clock.ts","../src/core/motion.ts","../src/core/merge.ts","../src/core/easing.ts","../src/core/tween.ts","../src/core/runner.ts","../src/core/testing/recording.ts","../src/core/testing/context.ts","../src/core/testing/play.ts","../src/core/transition.ts","../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/flatten.ts","../src/core/geometry/path.ts","../src/core/geometry/describe/shape.ts","../src/core/geometry/describe/index.ts","../src/testing/fixtures.ts","../src/testing/check.ts"],"sourcesContent":["// 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 * 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","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","/**\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","/** 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 { 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","// 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 /**\n * An update started, as its transition starts (docs/architecture.md#events-and-effect-slots says\n * what counts as one). First it ends the `update` runs of the marks not in `marks`, as a re-trigger\n * would, so what the last update explained goes with it. Then it runs `update` on `marks`, the marks\n * whose values changed, with the geometry on screen and the values before: the data each key last\n * rested at, not values part way through a change.\n */\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 /**\n * The data the key last rested at: its last enter() or update() (where it was heading), a change()\n * outside a transition (a resize, a line's reveal), or settle(). An update run's `previous` values,\n * so an update that replaces one still moving counts from the values the last one gave.\n */\n resting: 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, resting: 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 entry.resting = input.data;\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 // What the last update explained goes with it, on the marks this one leaves alone: a flash\n // still playing stops, and a delta that stayed is cleared, as a re-trigger clears them.\n const changing = new Set(marks.map((input) => input.mark.key));\n for (const entry of [...entries.values()]) {\n const run = entry.runs.get(\"update\");\n if (run && !changing.has(entry.key)) clearRun(run);\n }\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.resting) : input.data;\n const entry = track(input);\n entry.resting = input.data;\n start(entry, \"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) {\n entry.data = data;\n // Outside a transition the values aren't on their way anywhere: a resize, a line's reveal.\n if (!transitioning) entry.resting = data;\n }\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 // Landed: each mark rests at the data its last frame gave.\n for (const entry of entries.values()) if (!entry.exiting) entry.resting = entry.data;\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","// In-memory versions of the drawing API, so effects can be tested with no DOM at all.\n\nimport type { IconHandle, Layer, MarkHandle, MarkStyle, Matrix, Paint, PathHandle, TextHandle, TextStyle } from \"../contracts/drawing\";\nimport type { Icon } from \"../contracts/icon\";\nimport type { EffectSlot } from \"../contracts/slots\";\nimport { mergeFields as merge } from \"../merge\";\nimport type { RunnerSurface, SurfaceGroup } from \"../runner\";\n\nexport interface DrawnIcon {\n readonly kind: \"icon\";\n readonly id: number;\n readonly icon: Icon;\n readonly size: number | undefined;\n /** Undefined until first placed, while the icon is hidden. */\n readonly transform: Matrix | undefined;\n}\n\nexport interface DrawnPath {\n readonly kind: \"path\";\n readonly id: number;\n readonly d: string;\n readonly paint: Paint;\n}\n\nexport interface DrawnText {\n readonly kind: \"text\";\n readonly id: number;\n readonly content: string;\n readonly style: TextStyle;\n}\n\nexport type Drawn = DrawnIcon | DrawnPath | DrawnText;\n\n/** Every call made on a layer or its handles, in order. Calls on removed handles are logged and ignored. */\nexport type LayerCall =\n | { readonly op: \"icon\"; readonly id: number; readonly icon: string; readonly size: number | undefined }\n | { readonly op: \"place\"; readonly id: number; readonly transform: Matrix }\n | { readonly op: \"path\"; readonly id: number; readonly d: string; readonly paint: Paint }\n | { readonly op: \"update-path\"; readonly id: number; readonly d: string; readonly paint: Partial<Paint> | undefined }\n | { readonly op: \"text\"; readonly id: number; readonly content: string; readonly style: TextStyle }\n | { readonly op: \"update-text\"; readonly id: number; readonly style: Partial<TextStyle>; readonly content: string | undefined }\n | { readonly op: \"remove\"; readonly id: number }\n | { readonly op: \"clear\" };\n\n/** What's on screen, without ids and with numbers rounded, so a full run can be compared with end(). */\nexport type Picture =\n | { readonly kind: \"icon\"; readonly icon: string; readonly size: number | undefined; readonly transform: readonly number[] | undefined }\n | { readonly kind: \"path\"; readonly d: string; readonly paint: Paint }\n | { readonly kind: \"text\"; readonly content: string; readonly style: TextStyle };\n\nexport interface RecordingLayer extends Layer {\n /** What's drawn now, in creation order (which is also stacking order). */\n readonly drawn: readonly Drawn[];\n readonly calls: readonly LayerCall[];\n /** `drawn` as plain data, numbers rounded to `decimals` (default 3). */\n picture(decimals?: number): Picture[];\n /** Remove everything, as the runner does when a run is cleared. */\n clear(): void;\n}\n\nexport function recordingLayer(): RecordingLayer {\n const drawn = new Map<number, Drawn>();\n const calls: LayerCall[] = [];\n let nextId = 1;\n\n // Replaces a live item; calls on removed handles change nothing.\n const replace = (id: number, next: (current: Drawn) => Drawn): void => {\n const current = drawn.get(id);\n if (current) drawn.set(id, next(current));\n };\n const remove = (id: number): void => {\n calls.push({ op: \"remove\", id });\n drawn.delete(id);\n };\n\n return {\n get drawn() {\n return [...drawn.values()];\n },\n get calls() {\n return calls;\n },\n icon(icon, options) {\n const id = nextId++;\n const size = options?.size;\n calls.push({ op: \"icon\", id, icon: icon.name, size });\n drawn.set(id, { kind: \"icon\", id, icon, size, transform: undefined });\n const handle: IconHandle = {\n place(transform) {\n calls.push({ op: \"place\", id, transform });\n replace(id, (current) => ({ ...current, transform }) as DrawnIcon);\n },\n remove: () => remove(id)\n };\n return handle;\n },\n path(d, paint) {\n const id = nextId++;\n calls.push({ op: \"path\", id, d, paint });\n drawn.set(id, { kind: \"path\", id, d, paint: { ...paint } });\n const handle: PathHandle = {\n update(nextD, nextPaint) {\n calls.push({ op: \"update-path\", id, d: nextD, paint: nextPaint });\n replace(id, (current) => {\n const path = current as DrawnPath;\n return { ...path, d: nextD, paint: merge(path.paint, nextPaint) };\n });\n },\n remove: () => remove(id)\n };\n return handle;\n },\n text(content, style) {\n const id = nextId++;\n calls.push({ op: \"text\", id, content, style });\n drawn.set(id, { kind: \"text\", id, content, style: { ...style } });\n const handle: TextHandle = {\n update(nextStyle, nextContent) {\n calls.push({ op: \"update-text\", id, style: nextStyle, content: nextContent });\n replace(id, (current) => {\n const text = current as DrawnText;\n return { ...text, style: merge(text.style, nextStyle), content: nextContent ?? text.content };\n });\n },\n remove: () => remove(id)\n };\n return handle;\n },\n picture(decimals = 3) {\n const round = rounder(decimals);\n return [...drawn.values()].map((item): Picture => {\n switch (item.kind) {\n case \"icon\":\n return { kind: \"icon\", icon: item.icon.name, size: item.size, transform: item.transform?.map(round) };\n case \"path\":\n return { kind: \"path\", d: item.d, paint: roundFields(item.paint, round) };\n case \"text\":\n return { kind: \"text\", content: item.content, style: { ...roundFields(item.style, round), at: { x: round(item.style.at.x), y: round(item.style.at.y) } } };\n }\n });\n },\n clear() {\n calls.push({ op: \"clear\" });\n drawn.clear();\n }\n };\n}\n\nexport type MarkCall = { readonly op: \"set\"; readonly style: MarkStyle } | { readonly op: \"reset\" };\n\nexport interface RecordingMark extends MarkHandle {\n /** The style now, after every set() and reset(). Empty means the mark's own style. */\n readonly style: MarkStyle;\n readonly calls: readonly MarkCall[];\n}\n\nexport function recordingMark(): RecordingMark {\n let style: MarkStyle = {};\n const calls: MarkCall[] = [];\n return {\n get style() {\n return style;\n },\n get calls() {\n return calls;\n },\n set(next) {\n calls.push({ op: \"set\", style: next });\n style = merge(style, next);\n },\n reset() {\n calls.push({ op: \"reset\" });\n style = {};\n }\n };\n}\n\n/** One overlay group a runner asked for. */\nexport interface RecordedGroup {\n readonly key: string;\n readonly slot: EffectSlot;\n /** The run's start order, which stacks groups. */\n readonly order: number;\n readonly layer: RecordingLayer;\n /** True once the runner cleared it. */\n readonly cleared: boolean;\n}\n\n/** A RunnerSurface in memory: every run's group is a recording layer, every mark a recording mark. */\nexport interface RecordingSurface extends RunnerSurface {\n /** Every group asked for, in order, cleared ones included. */\n readonly groups: readonly RecordedGroup[];\n /** The mark's handle, made on first use. */\n mark(key: string): RecordingMark;\n /** What's drawn now in the groups not yet cleared, optionally for one key, bottom to top (by order), as RecordingLayer.picture() gives it. */\n picture(key?: string): Picture[];\n}\n\nexport function recordingSurface(): RecordingSurface {\n const groups: { key: string; slot: EffectSlot; order: number; layer: RecordingLayer; cleared: boolean }[] = [];\n const marks = new Map<string, RecordingMark>();\n return {\n groups,\n group(key, slot, order) {\n const record = { key, slot, order, layer: recordingLayer(), cleared: false };\n groups.push(record);\n const group: SurfaceGroup = {\n icon: (icon, options) => record.layer.icon(icon, options),\n path: (d, paint) => record.layer.path(d, paint),\n text: (content, style) => record.layer.text(content, style),\n clear() {\n record.cleared = true;\n record.layer.clear();\n }\n };\n return group;\n },\n mark(key) {\n let mark = marks.get(key);\n if (!mark) marks.set(key, (mark = recordingMark()));\n return mark;\n },\n picture(key) {\n return groups\n .filter((group) => !group.cleared && (key === undefined || group.key === key))\n .sort((a, b) => a.order - b.order)\n .flatMap((group) => group.layer.picture());\n }\n };\n}\n\nfunction rounder(decimals: number): (value: number) => number {\n const factor = 10 ** decimals;\n return (value) => {\n const rounded = Math.round(value * factor) / factor;\n return rounded === 0 ? 0 : rounded;\n };\n}\n\nfunction roundFields<T extends object>(fields: T, round: (value: number) => number): T {\n const result: Record<string, unknown> = {};\n for (const [field, value] of Object.entries(fields)) result[field] = typeof value === \"number\" ? round(value) : value;\n return result as T;\n}\n","// An EffectContext for effect tests: a manual clock, its own motion, and recording drawing handles.\n\nimport { manualClock, type ManualClock } from \"../clock\";\nimport type { MarkData } from \"../contracts/data\";\nimport type { EffectContext } from \"../contracts/effect\";\nimport type { MarkGeometry } from \"../contracts/geometry\";\nimport type { Icon } from \"../contracts/icon\";\nimport { createMotion, type Motion, type MotionMode, type ScalingOverrides } from \"../motion\";\nimport { runScope } from \"../runner\";\nimport { recordingLayer, recordingMark, type RecordingLayer, type RecordingMark } from \"./recording\";\n\nexport interface TestContextOptions {\n /** The author's mode. Default \"presentation\". The device never asks for reduced motion here. */\n readonly mode?: MotionMode;\n /** Overrides for the duration scaling, as a page's createMotion({ scaling }) gives. */\n readonly scaling?: ScalingOverrides;\n readonly icons?: readonly Icon[];\n readonly batch?: { readonly index: number; readonly count: number };\n readonly previous?: MarkGeometry;\n}\n\nexport interface TestContext extends EffectContext {\n readonly motion: Motion;\n readonly clock: ManualClock;\n readonly layer: RecordingLayer;\n readonly mark: RecordingMark;\n /** Abort the run, as the runner does on leave or re-trigger. */\n abort(): void;\n /** The runner's cleanup after effect.clear(ctx): abort, empty the layer, reset the mark, drop onChange listeners. */\n clear(): void;\n /** Tell onChange listeners the geometry moved, as the runner does on every frame of a transition. */\n change(mark: MarkGeometry, data?: MarkData): void;\n}\n\nexport function testContext(options: TestContextOptions = {}): TestContext {\n const clock = manualClock();\n const motion = createMotion({\n mode: options.mode ?? \"presentation\",\n ...(options.scaling ? { scaling: options.scaling } : {}),\n reducedMotion: { matches: false, subscribe: () => () => {} }\n });\n const layer = recordingLayer();\n const mark = recordingMark();\n const icons = new Map((options.icons ?? []).map((icon) => [icon.name, icon]));\n // The same run scope the runner gives every run, so clear() here is the runner's cleanup.\n const scope = runScope({\n clock,\n motion,\n layer,\n mark,\n icons: { get: (name) => icons.get(name) },\n batch: options.batch ?? { index: 0, count: 1 },\n previous: options.previous\n });\n\n return {\n ...scope.context,\n motion,\n clock,\n layer,\n mark,\n abort: scope.abort,\n clear: scope.clear,\n change: scope.change\n };\n}\n","// Plays a run to its end on a manual clock, for effect tests.\n\nimport type { ManualClock } from \"../clock\";\n\nexport interface PlayOptions {\n /** Ms per frame. Default 16. */\n readonly frame?: number;\n /** Gives up after this many ms. Default 10 000. */\n readonly limit?: number;\n}\n\n/**\n * Advances the clock a frame at a time until `running` settles, letting promise callbacks run\n * between frames (so a sequence's next part starts on time). Resolves with the ms it advanced; throws\n * if `running` hasn't settled within the limit.\n */\nexport async function play(clock: ManualClock, running: Promise<unknown>, options: PlayOptions = {}): Promise<number> {\n const frame = options.frame ?? 16;\n const limit = options.limit ?? 10_000;\n let settled = false;\n running.then(\n () => (settled = true),\n () => (settled = true)\n );\n let elapsed = 0;\n await flush();\n while (!settled) {\n if (elapsed >= limit) throw new Error(`play: still running after ${limit} ms.`);\n clock.advance(frame);\n elapsed += frame;\n await flush();\n }\n return elapsed;\n}\n\n/** Lets pending promise callbacks run. */\nexport async function flush(): Promise<void> {\n for (let i = 0; i < 20; i++) await Promise.resolve();\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","// 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: number = 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. It can\n// have gaps, stretches with no data that its path data leaves out.\n\nimport type { Point } from \"../contracts/geometry\";\nimport { drawTo, moveTo, pathData } from \"./path-data\";\nimport { angleOn, pointOn, type PathSegment } from \"./segment\";\n\n/** Stretches of a walk with no data, as [from, to] values of t: in order, apart, each with 0 ≤ from < to ≤ 1. */\nexport type Gaps = readonly (readonly [from: number, to: number])[];\n\nexport interface Walk {\n readonly segments: readonly PathSegment[];\n readonly length: number;\n readonly start: Point;\n readonly end: Point;\n /** The stretches slice() and d leave out; empty when there are none. */\n readonly gaps: Gaps;\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 /**\n * Path data from t0 to t1, in either order. Just a move when they're equal. It leaves out the gaps:\n * each part between them starts with its own move, and a part with no length isn't written.\n */\n slice(t0: number, t1: number): string;\n /** Path data for the whole walk, less its gaps. */\n readonly d: string;\n}\n\nconst clamp01 = (t: number): number => (t > 0 ? (t < 1 ? t : 1) : 0);\nconst NONE: Gaps = Object.freeze([]);\n\n/** The segments must connect: each starts where the one before ends. The gaps are taken as given. */\nexport function createWalk(segments: readonly PathSegment[], gaps: Gaps = NONE): 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 /** Path data from t `from` to `to` (from ≤ to, both in [0, 1]), gaps and all. */\n const draw = (from: number, to: number): string => {\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\n const slice = (t0: number, t1: number): string => {\n const from = clamp01(Math.min(t0, t1));\n const to = clamp01(Math.max(t0, t1));\n if (gaps.length === 0) return draw(from, to);\n // The parts between the gaps, each drawn from its own move. All in a gap: a move where it starts.\n let d = \"\";\n let at = from;\n for (const [a, b] of gaps) {\n if (a >= to) break;\n if (a > at) d += draw(at, a);\n if (b > at) at = b;\n }\n if (to > at) d += draw(at, to);\n return d === \"\" ? moveTo(point(from)) : d;\n };\n\n return {\n segments,\n length,\n start,\n end,\n gaps,\n point,\n angle(t) {\n const { index, u } = locate(clamp01(t) * length);\n return angleOn(segments[index]!, u);\n },\n slice,\n d: gaps.length === 0 ? pathData(segments) : slice(0, 1)\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 { arc, line, pointOn, TAU, 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((side) => createWalk(side));\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/**\n * A closed outline round loops of connected segments, each a subpath, holes too. It's sampled round\n * the longest loop, clockwise on screen from its upper left (the point with the least x + y, the\n * higher of two), in four quarters of equal length, so a circle samples as a point's outline does.\n * Its path data starts there too: the longest loop first, from that point. If the longest runs\n * anticlockwise, every loop is written the other way round, which fills the same.\n */\nexport function loopOutline(loops: readonly (readonly PathSegment[])[]): Outline {\n const lengths = loops.map((loop) => loop.reduce((sum, segment) => sum + segment.length, 0));\n let longest = 0;\n lengths.forEach((length, i) => {\n if (length > lengths[longest]!) longest = i;\n });\n const turn = area(loops[longest]!) < 0;\n const clockwise = loops.map((loop) => (turn ? reversed(loop) : loop));\n const ring = fromUpperLeft(clockwise[longest]!);\n const walk = createWalk(ring);\n return {\n d: [ring, ...clockwise.filter((_, i) => i !== longest)].map((loop) => pathData(loop, true)).join(\"\"),\n closed: true,\n sample(n) {\n checkCount(n, 4);\n const perSide = n / 4;\n const points: Point[] = [];\n // Each quarter from its own corner, so the corners are the same points whatever n is.\n for (let side = 0; side < 4; side++) {\n for (let j = 0; j < perSide; j++) points.push(walk.point(side / 4 + j / perSide / 4));\n }\n return points;\n }\n };\n}\n\n/** The loop's signed area: more than 0 when it runs clockwise on screen. */\nfunction area(loop: readonly PathSegment[]): number {\n let sum = 0;\n for (const segment of loop) {\n if (segment.kind === \"line\") {\n sum += segment.from.x * segment.to.y - segment.to.x * segment.from.y;\n continue;\n }\n const { center, radius, start, sweep } = segment;\n const end = start + sweep;\n sum += radius * (center.x * (Math.sin(end) - Math.sin(start)) - center.y * (Math.cos(end) - Math.cos(start))) + radius * radius * sweep;\n }\n return sum / 2;\n}\n\n/** The loop walked the other way. */\nfunction reversed(loop: readonly PathSegment[]): PathSegment[] {\n return loop.map((segment) => (segment.kind === \"line\" ? line(segment.to, segment.from) : arc(segment.center, segment.radius, segment.start + segment.sweep, -segment.sweep))).reverse();\n}\n\n/** The loop from its upper left: the least x + y, at a segment's start or inside an arc, and of two, the higher. */\nfunction fromUpperLeft(loop: readonly PathSegment[]): PathSegment[] {\n let index = 0;\n let u = 0;\n let key = Infinity;\n let top = Infinity;\n const consider = (point: Point, i: number, at: number): void => {\n const k = point.x + point.y;\n if (k < key - 1e-9 || (k <= key + 1e-9 && point.y < top)) [index, u, key, top] = [i, at, k, point.y];\n };\n loop.forEach((segment, i) => {\n consider(pointOn(segment, 0), i, 0);\n if (segment.kind === \"arc\") {\n // On a circle, x + y is least at the upper left, 3π/4 anticlockwise from +x.\n const turned = segment.sweep >= 0 ? UPPER_LEFT - segment.start : segment.start - UPPER_LEFT;\n const at = (((turned % TAU) + TAU) % TAU) / Math.abs(segment.sweep);\n if (at < 1) consider(pointOn(segment, at), i, at);\n }\n });\n const [before, after] = split(loop[index]!, u);\n return [after, ...loop.slice(index + 1), ...loop.slice(0, index), before].filter((segment) => segment.length > 0);\n}\n\n/** A segment in two, at fraction u of its length. */\nfunction split(segment: PathSegment, u: number): [PathSegment, PathSegment] {\n if (segment.kind === \"line\") {\n const at = pointOn(segment, u);\n return [line(segment.from, at), line(at, segment.to)];\n }\n const { center, radius, start, sweep } = segment;\n return [arc(center, radius, start, sweep * u), arc(center, radius, start + sweep * u, sweep * (1 - u))];\n}\n\nconst UPPER_LEFT = (-3 * Math.PI) / 4;\n\n/** An open outline: the stroke along a walk, less its gaps. Its samples run along the whole walk, gaps and all. */\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 labelBounds?: readonly Rect[] | undefined;\n readonly segments?: readonly MarkGeometry[];\n}\n\nexport function assemble({ key, series, walk, thickness, outline, bounds, center, pivot, labelBounds, 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 ...(walk.gaps.length === 0 ? {} : { gaps: walk.gaps }),\n thickness,\n outline,\n bounds,\n center,\n pivot,\n ...(labelBounds === undefined ? {} : { labelBounds }),\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/** A spec's `labelBounds`, checked: each box's numbers finite, its sizes ≥ 0. Charts give them every frame, so a good box costs four comparisons. */\nexport function labelBoxes(builder: string, boxes: readonly Rect[] | undefined): readonly Rect[] | undefined {\n if (!boxes) return boxes;\n for (let i = 0; i < boxes.length; i++) {\n const { x, y, width, height } = boxes[i]!;\n if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && width >= 0 && Number.isFinite(height) && height >= 0) continue;\n finite(builder, `labelBounds[${i}].x`, x);\n finite(builder, `labelBounds[${i}].y`, y);\n size(builder, `labelBounds[${i}].width`, width);\n size(builder, `labelBounds[${i}].height`, height);\n }\n return boxes;\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, Rect } from \"../../contracts/geometry\";\nimport { closedOutline } from \"../outline\";\nimport { arc, boundsOf, extremes, line, polar, TAU } from \"../segment\";\nimport { createWalk } from \"../walk\";\nimport { assemble, finite, labelBoxes, 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 /** The boxes of the text drawn for the mark, in the same px: passed through as `labelBounds`. */\n readonly labelBounds?: readonly Rect[];\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 labelBounds: labelBoxes(\"arc\", spec.labelBounds)\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, labelBoxes, 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 /** The boxes of the text drawn for the bar, its segments having none, in the same px: passed through as `labelBounds`. */\n readonly labelBounds?: readonly Rect[];\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 const labelBounds = labelBoxes(\"bar\", spec.labelBounds);\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; labelBounds?: readonly Rect[] | undefined; 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 }, labelBounds, 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, with gaps\n// where a run of points ends and the next begins.\n\nimport type { MarkGeometry, Point, Rect } from \"../../contracts/geometry\";\nimport { openOutline } from \"../outline\";\nimport { boundsOf, line, type LineSegment } from \"../segment\";\nimport { createWalk, type Gaps } from \"../walk\";\nimport { assemble, finite, labelBoxes, 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 /**\n * The indices of the points that start a new run, so there's a gap from `points[i - 1]` to\n * `points[i]`: each a whole number from 1 to the last index, in order, with no repeats. A line\n * drawn with d3's `.defined()` is described by its defined points and where they break. Default none.\n */\n readonly breaks?: readonly number[];\n /** Stroke width in px. Default 1, SVG's default. */\n readonly width?: number;\n /** The boxes of the text drawn for the mark, in the same px: passed through as `labelBounds`. */\n readonly labelBounds?: readonly Rect[];\n}\n\n/**\n * The walk is the line itself, first point to last, running straight across each break. Its outline\n * is open: the stroke, with the breaks left out. A break between two points in the same place leaves\n * no gap, since there's nothing between them to leave out.\n */\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 const breaks = checkBreaks(spec.breaks, points.length);\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, gapsAt(breaks, 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 labelBounds: labelBoxes(\"line\", spec.labelBounds)\n });\n}\n\n/** The walk's gaps, in t: from the point before each break to the point at it, where they're apart. */\nfunction gapsAt(breaks: readonly number[], segments: readonly LineSegment[]): Gaps {\n // The distance to each point, summed as createWalk sums it, so the last point is at t = 1 exactly.\n const along = [0];\n for (const segment of segments) along.push(along[along.length - 1]! + segment.length);\n const length = along[along.length - 1]!;\n return breaks.filter((i) => along[i]! > along[i - 1]!).map((i) => [along[i - 1]! / length, along[i]! / length]);\n}\n\n/** `breaks`, checked: whole numbers from 1 to the last index, in order, with no repeats. */\nfunction checkBreaks(breaks: readonly number[] | undefined, count: number): readonly number[] {\n if (breaks === undefined) return [];\n if (!Array.isArray(breaks)) throw new RangeError(`describe.line: breaks must be an array of point indices, got ${show(breaks)}.`);\n let after = 0;\n breaks.forEach((index: unknown, i) => {\n if (!(Number.isInteger(index) && (index as number) > after && (index as number) < count)) {\n throw new RangeError(`describe.line: breaks[${i}] must be a whole number more than ${after} and less than ${count}, the number of points, got ${show(index)}.`);\n }\n after = index as number;\n });\n return breaks;\n}\n\nconst show = (value: unknown): string => (typeof value === \"string\" ? JSON.stringify(value) : String(value));\n","// describe.point: a dot with no direction (a scatter point or a marker).\n\nimport type { MarkGeometry, Rect } from \"../../contracts/geometry\";\nimport { closedOutline } from \"../outline\";\nimport { arc, line } from \"../segment\";\nimport { createWalk } from \"../walk\";\nimport { assemble, finite, labelBoxes, 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 /** The boxes of the text drawn for the mark, in the same px: passed through as `labelBounds`. */\n readonly labelBounds?: readonly Rect[];\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 labelBounds: labelBoxes(\"point\", spec.labelBounds)\n });\n}\n","// Path commands as walk segments: straight pieces and circular arcs. Béziers and arcs that aren't\n// circular become straight pieces within 0.1 px of the curve, so any path data can be walked.\n\nimport type { Point } from \"../contracts/geometry\";\nimport type { PathCommand } from \"./path\";\nimport { arc, line, TAU, type PathSegment } from \"./segment\";\n\n/** px: the most a straight piece strays from the curve it stands for. */\nexport const FLAT = 0.1;\n/** Pieces one curve can become, so a curve millions of px across can't make millions of them. */\nconst MAX_PIECES = 10_000;\n\n/**\n * One subpath: where it starts and ends, as written, its segments in order (none with no length),\n * and whether it ends with Z, which ends it where it started.\n */\nexport interface Subpath {\n readonly start: Point;\n readonly end: Point;\n readonly segments: readonly PathSegment[];\n readonly closed: boolean;\n}\n\n/**\n * The subpaths of absolute path commands, as `parsePath` gives them. A new subpath starts at each\n * move, and at a command after a Z, from where the Z closed. A move with nothing after it before the\n * next move, or the end, draws nothing and is left out.\n */\nexport function flattenPath(commands: readonly PathCommand[]): Subpath[] {\n const subpaths: Subpath[] = [];\n let start: Point | undefined;\n let pen: Point = { x: 0, y: 0 };\n let segments: PathSegment[] = [];\n let open = false;\n const finish = (closed: boolean): void => {\n if (open) subpaths.push({ start: start!, end: pen, segments, closed });\n segments = [];\n open = false;\n };\n const to = (point: Point): void => {\n if (!open) {\n start = pen;\n open = true;\n }\n pen = point;\n };\n // A piece with no length draws nothing. One that isn't finite is kept, for describe.shape to find.\n const push = (segment: PathSegment): void => {\n if (segment.length !== 0) segments.push(segment);\n };\n const straight = (a: Point, b: Point): void => push(line(a, b));\n const through = (points: readonly Point[]): void => {\n for (let k = 1; k < points.length; k++) straight(points[k - 1]!, points[k]!);\n };\n\n for (let i = 0; i < commands.length; i++) {\n const command = commands[i]!;\n const from = pen;\n switch (command.op) {\n case \"M\":\n finish(false);\n pen = command.to;\n // A move followed by a drawing command starts a subpath there.\n if (commands[i + 1] && commands[i + 1]!.op !== \"M\") {\n start = pen;\n open = true;\n }\n break;\n case \"Z\":\n to(start ?? pen);\n straight(from, pen);\n finish(true);\n break;\n case \"L\":\n to(command.to);\n straight(from, pen);\n break;\n case \"C\":\n to(command.to);\n through(bezier(from, command.c1, command.c2, command.to));\n break;\n case \"Q\":\n to(command.to);\n through(bezier(from, command.c, command.to));\n break;\n case \"A\":\n to(command.to);\n for (const segment of arcSegments(from, command)) push(segment);\n break;\n }\n }\n finish(false);\n return subpaths;\n}\n\n/**\n * The points of a quadratic or cubic Bézier at equal steps of its parameter, ends included, enough\n * that the straight pieces between them stay within FLAT of it. Between steps h apart, a piece strays\n * at most h²/8 times the curve's largest second derivative, which is 2|P0 − 2P1 + P2| for a quadratic\n * and 6 times the larger of |P0 − 2P1 + P2| and |P1 − 2P2 + P3| for a cubic.\n */\nfunction bezier(...p: Point[]): Point[] {\n const bend = (a: Point, b: Point, c: Point): number => Math.hypot(a.x - 2 * b.x + c.x, a.y - 2 * b.y + c.y);\n const cubic = p.length === 4;\n const second = cubic ? 6 * Math.max(bend(p[0]!, p[1]!, p[2]!), bend(p[1]!, p[2]!, p[3]!)) : 2 * bend(p[0]!, p[1]!, p[2]!);\n const n = pieces(1, second);\n const points = [p[0]!];\n for (let k = 1; k < n; k++) {\n const t = k / n;\n const s = 1 - t;\n const [a, b, c, d] = cubic ? [s * s * s, 3 * s * s * t, 3 * s * t * t, t * t * t] : [s * s, 2 * s * t, t * t, 0];\n points.push({\n x: a * p[0]!.x + b * p[1]!.x + c * p[2]!.x + (cubic ? d * p[3]!.x : 0),\n y: a * p[0]!.y + b * p[1]!.y + c * p[2]!.y + (cubic ? d * p[3]!.y : 0)\n });\n }\n points.push(p[p.length - 1]!);\n return points;\n}\n\n/** Pieces for a parameter that runs `span`, with the curve's second derivative at most `second`: see bezier(). */\nfunction pieces(span: number, second: number): number {\n const n = Math.ceil(span * Math.sqrt(second / (8 * FLAT)));\n return Number.isFinite(n) ? Math.min(MAX_PIECES, Math.max(1, n)) : MAX_PIECES;\n}\n\n/** Radii this close, relative to the larger, are equal: a circle moved through a matrix comes out so. */\nconst ROUND = 1e-9;\n\n/**\n * An SVG arc from `from` (SVG 1.1, F.6.5 and F.6.6): no segment when its ends are the same point, a\n * straight piece when a radius is 0, one circular arc when its radii are equal, and otherwise\n * straight pieces within FLAT of the ellipse.\n */\nfunction arcSegments(from: Point, command: Extract<PathCommand, { op: \"A\" }>): PathSegment[] {\n const { to, large, sweep } = command;\n if (from.x === to.x && from.y === to.y) return [];\n let { rx, ry } = command;\n if (!(rx > 0 && ry > 0)) return [line(from, to)];\n const circle = Math.abs(rx - ry) <= ROUND * Math.max(rx, ry);\n const phi = circle ? 0 : (command.rotation * Math.PI) / 180;\n const cos = Math.cos(phi);\n const sin = Math.sin(phi);\n // The start, relative to the chord's middle, in the ellipse's own axes.\n const hx = (from.x - to.x) / 2;\n const hy = (from.y - to.y) / 2;\n const x1 = cos * hx + sin * hy;\n const y1 = -sin * hx + cos * hy;\n // Radii too small to reach are scaled up until they just do.\n const reach = (x1 * x1) / (rx * rx) + (y1 * y1) / (ry * ry);\n if (reach > 1) {\n rx *= Math.sqrt(reach);\n ry *= Math.sqrt(reach);\n }\n const rx2 = rx * rx;\n const ry2 = ry * ry;\n const spread = rx2 * y1 * y1 + ry2 * x1 * x1;\n const k = (large !== sweep ? 1 : -1) * Math.sqrt(Math.max(0, (rx2 * ry2 - spread) / spread));\n const cx1 = (k * rx * y1) / ry;\n const cy1 = (-k * ry * x1) / rx;\n const center = { x: cos * cx1 - sin * cy1 + (from.x + to.x) / 2, y: sin * cx1 + cos * cy1 + (from.y + to.y) / 2 };\n const theta = Math.atan2((y1 - cy1) / ry, (x1 - cx1) / rx);\n let turn = Math.atan2((-y1 - cy1) / ry, (-x1 - cx1) / rx) - theta;\n // Positive turns clockwise on screen, as SVG's sweep flag 1 does with y down.\n if (sweep && turn < 0) turn += TAU;\n else if (!sweep && turn > 0) turn -= TAU;\n\n if (circle) return [arc(center, rx, theta, turn)];\n const n = pieces(Math.abs(turn), Math.max(rx, ry));\n const at = (angle: number): Point => {\n const ex = rx * Math.cos(angle);\n const ey = ry * Math.sin(angle);\n return { x: center.x + cos * ex - sin * ey, y: center.y + sin * ex + cos * ey };\n };\n const segments: PathSegment[] = [];\n let previous = from;\n for (let j = 1; j <= n; j++) {\n const next = j === n ? to : at(theta + (turn * j) / n);\n segments.push(line(previous, next));\n previous = next;\n }\n return segments;\n}\n","// Any SVG path data: read it, move it through a transform, and write it back out, and the outline of\n// any shape element as path commands. iconFromSvg reads icons' markup with it, expressive() reads the\n// circles and shapes other libraries draw, and a chart switch moves marks' outlines between\n// coordinate spaces. What's written is built from numbers only, so nothing from the input passes through.\n\nimport type { Matrix } from \"../contracts/drawing\";\nimport type { Point } from \"../contracts/geometry\";\nimport { formatNumber } from \"./path-data\";\n\n/** Absolute commands only: H and V become L, S becomes C, T becomes Q. */\nexport type PathCommand =\n | { readonly op: \"M\" | \"L\" | \"Z\"; readonly to: Point }\n | { readonly op: \"C\"; readonly c1: Point; readonly c2: Point; readonly to: Point }\n | { readonly op: \"Q\"; readonly c: Point; readonly to: Point }\n | {\n readonly op: \"A\";\n readonly rx: number;\n readonly ry: number;\n /** Degrees, as in path data. */\n readonly rotation: number;\n readonly large: boolean;\n readonly sweep: boolean;\n readonly to: Point;\n };\n\nconst ARITY: Readonly<Record<string, number>> = { M: 2, L: 2, H: 1, V: 1, C: 6, S: 4, Q: 4, T: 2, A: 7 };\n/** Separators, then a command letter or a number. Reading stops at anything else. */\nconst TOKEN = /[\\s,]*([A-Za-z]|[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][+-]?\\d+)?)/y;\nconst LETTER = /^[A-Za-z]$/;\n\n/** Reads path data as SVG does: up to the first error, which ends the path. */\nexport function parsePath(d: string): PathCommand[] {\n const tokens: string[] = [];\n TOKEN.lastIndex = 0;\n for (let match = TOKEN.exec(d); match; match = TOKEN.exec(d)) tokens.push(match[1]!);\n const out: PathCommand[] = [];\n let pen: Point = { x: 0, y: 0 };\n let start = pen;\n /** The last command's second control point, which S and T reflect. */\n let control: Point | undefined;\n let command = \"\";\n let i = 0;\n\n while (i < tokens.length) {\n if (LETTER.test(tokens[i]!)) command = tokens[i++]!;\n else if (command === \"\" || command === \"Z\" || command === \"z\") break; // numbers with no command\n const upper = command.toUpperCase();\n if (upper === \"Z\") {\n out.push({ op: \"Z\", to: start });\n pen = start;\n control = undefined;\n continue;\n }\n const arity = ARITY[upper];\n if (arity === undefined) break;\n const args: number[] = [];\n let flagError = false;\n while (args.length < arity && i < tokens.length && !LETTER.test(tokens[i]!)) {\n const token = tokens[i]!;\n // An arc's flags are one character each, and can run into each other and into the next\n // number: \"a1 1 0 0110 10\", \"A5 5 0 01.5 .5\". Anything but 0 or 1 there is an error.\n if (upper === \"A\" && (args.length === 3 || args.length === 4)) {\n const flag = token[0];\n if (flag !== \"0\" && flag !== \"1\") {\n flagError = true;\n break;\n }\n args.push(Number(flag));\n if (token.length > 1) tokens[i] = token.slice(1);\n else i++;\n continue;\n }\n args.push(Number(token));\n i++;\n }\n if (flagError || args.length < arity || !args.every(Number.isFinite)) break;\n\n const relative = command !== upper;\n const at = (x: number, y: number): Point => (relative ? { x: pen.x + x, y: pen.y + y } : { x, y });\n const [a = 0, b = 0, c = 0, e = 0, f = 0, g = 0, h = 0] = args;\n let next: Point | undefined;\n switch (upper) {\n case \"M\":\n pen = start = at(a, b);\n out.push({ op: \"M\", to: pen });\n // Further pairs after a move are lines.\n command = relative ? \"l\" : \"L\";\n break;\n case \"L\":\n out.push({ op: \"L\", to: (pen = at(a, b)) });\n break;\n case \"H\":\n out.push({ op: \"L\", to: (pen = { x: relative ? pen.x + a : a, y: pen.y }) });\n break;\n case \"V\":\n out.push({ op: \"L\", to: (pen = { x: pen.x, y: relative ? pen.y + a : a }) });\n break;\n case \"C\":\n case \"S\": {\n const smooth = upper === \"S\";\n const c1 = smooth ? (control && lastIs(out, \"C\") ? reflect(control, pen) : pen) : at(a, b);\n next = smooth ? at(a, b) : at(c, e);\n out.push({ op: \"C\", c1, c2: next, to: (pen = smooth ? at(c, e) : at(f, g)) });\n break;\n }\n case \"Q\":\n case \"T\": {\n const smooth = upper === \"T\";\n next = smooth ? (control && lastIs(out, \"Q\") ? reflect(control, pen) : pen) : at(a, b);\n out.push({ op: \"Q\", c: next, to: (pen = smooth ? at(a, b) : at(c, e)) });\n break;\n }\n case \"A\":\n out.push({ op: \"A\", rx: Math.abs(a), ry: Math.abs(b), rotation: c, large: e !== 0, sweep: f !== 0, to: (pen = at(g, h)) });\n break;\n }\n control = next;\n }\n return out;\n}\n\nconst lastIs = (commands: readonly PathCommand[], op: PathCommand[\"op\"]): boolean => commands[commands.length - 1]?.op === op;\nconst reflect = (control: Point, about: Point): Point => ({ x: 2 * about.x - control.x, y: 2 * about.y - control.y });\n\n/** A shape element's attribute by name, as written: an element's getAttribute, or a map's get. */\nexport type ShapeAttribute = (name: string) => string | null | undefined;\n\n/**\n * A shape element's outline as path commands, in its own coordinates: `<path>`, `<circle>`,\n * `<ellipse>`, `<line>`, `<polyline>`, `<polygon>` or `<rect>`, from its attributes. A shape SVG\n * wouldn't draw (a radius of 0, a polyline of one point) has none, and so does any other tag.\n */\nexport function shapeOutline(tag: string, attribute: ShapeAttribute): PathCommand[] {\n const num = (name: string): number => {\n const value = Number.parseFloat(attribute(name) ?? \"\");\n return Number.isFinite(value) ? value : 0;\n };\n switch (tag) {\n case \"path\":\n return parsePath(attribute(\"d\") ?? \"\");\n case \"circle\":\n return ellipse(num(\"cx\"), num(\"cy\"), num(\"r\"), num(\"r\"));\n case \"ellipse\":\n return ellipse(num(\"cx\"), num(\"cy\"), num(\"rx\"), num(\"ry\"));\n case \"line\":\n return [\n { op: \"M\", to: { x: num(\"x1\"), y: num(\"y1\") } },\n { op: \"L\", to: { x: num(\"x2\"), y: num(\"y2\") } }\n ];\n case \"polyline\":\n case \"polygon\": {\n const values = (attribute(\"points\") ?? \"\").trim().split(/[\\s,]+/).filter(Boolean).map(Number);\n const points: Point[] = [];\n for (let i = 0; i + 1 < values.length && Number.isFinite(values[i]) && Number.isFinite(values[i + 1]); i += 2) {\n points.push({ x: values[i]!, y: values[i + 1]! });\n }\n if (points.length < 2) return [];\n const lines = points.map((to, i): PathCommand => ({ op: i === 0 ? \"M\" : \"L\", to }));\n // A polyline is a polygon left open: no closing segment, and filled as any open path is.\n return tag === \"polygon\" ? [...lines, { op: \"Z\", to: points[0]! }] : lines;\n }\n case \"rect\":\n return rect(num(\"x\"), num(\"y\"), num(\"width\"), num(\"height\"), attribute);\n default:\n return [];\n }\n}\n\nfunction ellipse(cx: number, cy: number, rx: number, ry: number): PathCommand[] {\n if (!(rx > 0 && ry > 0)) return [];\n const arc = (x: number): PathCommand => ({ op: \"A\", rx, ry, rotation: 0, large: false, sweep: true, to: { x, y: cy } });\n return [{ op: \"M\", to: { x: cx + rx, y: cy } }, arc(cx - rx), arc(cx + rx), { op: \"Z\", to: { x: cx + rx, y: cy } }];\n}\n\nfunction rect(x: number, y: number, w: number, h: number, attribute: ShapeAttribute): PathCommand[] {\n if (!(w > 0 && h > 0)) return [];\n const corner = (name: string): number | undefined => {\n const value = Number.parseFloat(attribute(name) ?? \"\");\n return value >= 0 ? value : undefined;\n };\n // A missing rx or ry takes the other's value, and both are capped at half the side.\n const rx = Math.min(corner(\"rx\") ?? corner(\"ry\") ?? 0, w / 2);\n const ry = Math.min(corner(\"ry\") ?? corner(\"rx\") ?? 0, h / 2);\n const line = (px: number, py: number): PathCommand => ({ op: \"L\", to: { x: px, y: py } });\n if (!(rx > 0 && ry > 0)) return [{ op: \"M\", to: { x, y } }, line(x + w, y), line(x + w, y + h), line(x, y + h), { op: \"Z\", to: { x, y } }];\n const arc = (px: number, py: number): PathCommand => ({ op: \"A\", rx, ry, rotation: 0, large: false, sweep: true, to: { x: px, y: py } });\n return [\n { op: \"M\", to: { x: x + rx, y } },\n line(x + w - rx, y),\n arc(x + w, y + ry),\n line(x + w, y + h - ry),\n arc(x + w - rx, y + h),\n line(x + rx, y + h),\n arc(x, y + h - ry),\n line(x, y + ry),\n arc(x + rx, y),\n { op: \"Z\", to: { x: x + rx, y } }\n ];\n}\n\n/** Moves path commands through an affine transform. Arcs stay arcs: their ellipse is transformed too. */\nexport function transformPath(commands: readonly PathCommand[], m: Matrix): PathCommand[] {\n const p = (point: Point): Point => ({ x: m[0] * point.x + m[2] * point.y + m[4], y: m[1] * point.x + m[3] * point.y + m[5] });\n const mirrored = m[0] * m[3] - m[1] * m[2] < 0;\n return commands.map((command): PathCommand => {\n switch (command.op) {\n case \"M\":\n case \"L\":\n case \"Z\":\n return { op: command.op, to: p(command.to) };\n case \"C\":\n return { op: \"C\", c1: p(command.c1), c2: p(command.c2), to: p(command.to) };\n case \"Q\":\n return { op: \"Q\", c: p(command.c), to: p(command.to) };\n case \"A\":\n return { ...command, ...transformEllipse(command, m), sweep: mirrored !== command.sweep, to: p(command.to) };\n }\n });\n}\n\n/**\n * The arc's ellipse after the linear part of `m`. With E = M · R(rotation) · diag(rx, ry), the new\n * radii are E's singular values (the square roots of the eigenvalues of E·Eᵀ) and the new rotation\n * is the direction of the larger one's eigenvector.\n */\nfunction transformEllipse({ rx, ry, rotation }: { rx: number; ry: number; rotation: number }, m: Matrix): { rx: number; ry: number; rotation: number } {\n const r = (rotation * Math.PI) / 180;\n const cos = Math.cos(r);\n const sin = Math.sin(r);\n const e11 = (m[0] * cos + m[2] * sin) * rx;\n const e12 = (m[2] * cos - m[0] * sin) * ry;\n const e21 = (m[1] * cos + m[3] * sin) * rx;\n const e22 = (m[3] * cos - m[1] * sin) * ry;\n // E·Eᵀ = [[a, b], [b, c]].\n const a = e11 * e11 + e12 * e12;\n const b = e11 * e21 + e12 * e22;\n const c = e21 * e21 + e22 * e22;\n const mean = (a + c) / 2;\n const spread = Math.hypot((a - c) / 2, b);\n const major = mean + spread;\n const angle = Math.abs(b) < 1e-12 ? (a >= c ? 0 : Math.PI / 2) : Math.atan2(major - a, b);\n return { rx: Math.sqrt(major), ry: Math.sqrt(Math.max(0, mean - spread)), rotation: (angle * 180) / Math.PI };\n}\n\n/** Absolute path data with numbers rounded to 0.001 px. */\nexport function formatPath(commands: readonly PathCommand[]): string {\n const n = formatNumber;\n const pt = (point: Point): string => `${n(point.x)},${n(point.y)}`;\n return commands\n .map((command) => {\n switch (command.op) {\n case \"M\":\n case \"L\":\n return `${command.op}${pt(command.to)}`;\n case \"C\":\n return `C${pt(command.c1)} ${pt(command.c2)} ${pt(command.to)}`;\n case \"Q\":\n return `Q${pt(command.c)} ${pt(command.to)}`;\n case \"A\":\n return `A${n(command.rx)},${n(command.ry)} ${n(command.rotation)} ${command.large ? 1 : 0} ${command.sweep ? 1 : 0} ${pt(command.to)}`;\n case \"Z\":\n return \"Z\";\n }\n })\n .join(\"\");\n}\n","// describe.shape: any SVG path data, as an element with that `d` draws it. An open shape is a line,\n// with a gap at each later move; a closed one is an area with no direction, like a point.\n\nimport type { Matrix } from \"../../contracts/drawing\";\nimport type { MarkGeometry, Point, Rect } from \"../../contracts/geometry\";\nimport { flattenPath, type Subpath } from \"../flatten\";\nimport { loopOutline, openOutline } from \"../outline\";\nimport { parsePath, transformPath } from \"../path\";\nimport { boundsOf, extremes, line, type PathSegment } from \"../segment\";\nimport { createWalk, type Gaps } from \"../walk\";\nimport { assemble, labelBoxes } from \"./mark\";\n\nexport interface ShapeSpec {\n readonly key: string;\n readonly series?: string;\n /**\n * SVG path data in the shape's own px, read as SVG reads it, up to its first error. A shape is\n * closed when every subpath ends with Z, or where it started, and otherwise open, a line.\n */\n readonly d: string;\n /** Moves the shape into the marks' px, as an element's transform does, arcs too. Default none. */\n readonly matrix?: Matrix;\n /** An open shape's stroke width in px, more than 0. Default 1, SVG's default. */\n readonly width?: number;\n /** The boxes of the text drawn for the mark, in the marks' px: passed through as `labelBounds`. */\n readonly labelBounds?: readonly Rect[];\n}\n\n/**\n * Path data, flattened: straight pieces and circular arcs stay as they are, and Béziers and other\n * arcs become straight pieces within 0.1 px of the curve.\n * - An open shape is a line. Its walk runs along the path from its first point, and each later move\n * starts a new run after a gap. Its outline is the stroke, less the gaps, and its thickness,\n * bounds, centre and pivot are as `describe.line`'s.\n * - A closed shape has no direction: its walk is its bounds' centre, with length 0. Its outline's\n * `d` is the whole path, holes too, and `sample(n)` goes round its longest subpath, clockwise in\n * four quarters of equal length from its upper left. Its thickness is the smaller of its width and\n * height.\n * A subpath that ends where it started is closed too, as d3.arc() draws a full ring's outer edge.\n * A path whose subpaths are all closed but have no length, as d3 draws a value alone, is open: a line\n * with nothing to stroke.\n */\nexport function describeShape(spec: ShapeSpec): MarkGeometry {\n const { key, series, d } = spec;\n const width = spec.width ?? 1;\n if (!(Number.isFinite(width) && width > 0)) throw new RangeError(`describe.shape: width must be a finite number more than 0, got ${width}.`);\n const m = checkMatrix(spec.matrix);\n if (typeof d !== \"string\") throw new RangeError(`describe.shape: d must be path data, a string, got ${show(d)}.`);\n const commands = parsePath(d);\n const subpaths = commands[0]?.op === \"M\" ? flattenPath(m ? transformPath(commands, m) : commands) : [];\n if (subpaths.length === 0) throw new RangeError(`describe.shape: d must start with a move and draw something after it, got ${show(d)}.`);\n\n const points: Point[] = [];\n let length = 0;\n for (const subpath of subpaths) {\n points.push(subpath.start);\n for (const segment of subpath.segments) {\n for (const point of extremes(segment)) points.push(point);\n length += segment.length;\n }\n }\n const box = boundsOf(points);\n if (![box.x, box.y, box.width, box.height, length].every(Number.isFinite)) {\n throw new RangeError(`describe.shape: d must stay finite${m ? \" once moved by matrix\" : \"\"}, got ${show(d)}.`);\n }\n const labelBounds = labelBoxes(\"shape\", spec.labelBounds);\n\n if (subpaths.every(closes) && length > 0) {\n const center = { x: box.x + box.width / 2, y: box.y + box.height / 2 };\n return assemble({\n key,\n series,\n walk: createWalk([line(center, center)]),\n thickness: Math.min(box.width, box.height),\n // A subpath with no length encloses nothing.\n outline: loopOutline(subpaths.map((subpath) => subpath.segments).filter((segments) => segments.length > 0)),\n bounds: box,\n center,\n pivot: center,\n labelBounds\n });\n }\n\n const { segments, gaps } = joined(subpaths);\n const walk = createWalk(segments, gaps);\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: walk.start,\n labelBounds\n });\n}\n\n/** Whether a subpath ends with Z, or back where it started. */\nconst closes = ({ closed, start, end }: Subpath): boolean => closed || (start.x === end.x && start.y === end.y);\n\n/** The subpaths as one walk: a straight piece across from each to the next, which is a gap where they're apart. */\nfunction joined(subpaths: readonly Subpath[]): { segments: PathSegment[]; gaps: Gaps } {\n const segments: PathSegment[] = [];\n const across: number[] = [];\n let pen: Point | undefined;\n for (const subpath of subpaths) {\n if (pen && (pen.x !== subpath.start.x || pen.y !== subpath.start.y)) {\n across.push(segments.length);\n segments.push(line(pen, subpath.start));\n }\n for (const segment of subpath.segments) segments.push(segment);\n pen = subpath.end;\n }\n if (segments.length === 0) segments.push(line(subpaths[0]!.start, subpaths[0]!.start));\n // The distance to each segment, summed as createWalk sums it, so the walk's end is at t = 1 exactly.\n const along = [0];\n for (const segment of segments) along.push(along[along.length - 1]! + segment.length);\n const length = along[along.length - 1]!;\n return { segments, gaps: across.map((i) => [along[i]! / length, along[i + 1]! / length]) };\n}\n\n/** `matrix`, checked: six finite numbers. */\nfunction checkMatrix(m: Matrix | undefined): Matrix | undefined {\n if (m === undefined) return m;\n if (!(Array.isArray(m) && m.length === 6 && m.every(Number.isFinite))) {\n throw new RangeError(`describe.shape: matrix must be six finite numbers [a, b, c, d, e, f], got ${show(m)}.`);\n }\n return m;\n}\n\n/** A value for a message: strings quoted, and cut short past 40 characters. */\nfunction show(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(show).join(\", \")}]`;\n if (typeof value !== \"string\") return String(value);\n return JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value);\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\";\nimport { describeShape } from \"./shape\";\n\nexport const describe: {\n bar: typeof describeBar;\n arc: typeof describeArc;\n line: typeof describeLine;\n point: typeof describePoint;\n shape: typeof describeShape;\n} = {\n bar: describeBar,\n arc: describeArc,\n line: describeLine,\n point: describePoint,\n shape: describeShape\n};\n\nexport type { ArcSpec } from \"./arc\";\nexport type { BarSegmentSpec, BarSpec, Baseline } from \"./bar\";\nexport type { LineSpec } from \"./line\";\nexport type { PointSpec } from \"./point\";\nexport type { ShapeSpec } from \"./shape\";\n","// The marks checkEffect runs an effect on by default: one of each kind the geometry builders\n// describe, plus the awkward cases (a bar growing the other way, a stack with a gap, a bar shorter\n// than most icons, a line that skips a value, a point whose walk has no length). Each has a moved\n// twin: the same mark somewhere else, as a resize or a transition's next frame leaves it, for the\n// check that effects follow onChange. checkTransition's pairs are made of the same marks.\n\nimport { describe as build, type MarkGeometry } from \"../core\";\n\nexport type FixtureName = \"bar\" | \"negative bar\" | \"column\" | \"stacked\" | \"short bar\" | \"slice\" | \"line\" | \"gapped line\" | \"point\";\n\n/** Every kind of mark an effect meets: bars (plain, negative, a column, stacked, too short), a donut slice, a line, a line with a gap, and a point. */\nexport const fixtures: Readonly<Record<FixtureName, MarkGeometry>> = /* @__PURE__ */ makeFixtures(false);\n\n/**\n * Each fixture moved: the same key and series, somewhere else and another size. The bars are a row\n * lower and shorter (the stack's segments in another ratio), the slice turned and the ring smaller,\n * the lines further revealed and rescaled, and the point moved.\n */\nexport const movedFixtures: Readonly<Record<FixtureName, MarkGeometry>> = /* @__PURE__ */ makeFixtures(true);\n\nexport type FixturePairName = \"slice and column\" | \"bar and column\" | \"two slices\" | \"two lines\" | \"two points\";\n\n/**\n * The pairs checkTransition runs a transition effect between by default, each both ways: a slice and\n * a column (a mark that goes round its pivot and one that doesn't), a bar and a column, two slices,\n * two lines and two points. The second of two alike is the first's moved twin.\n */\nexport const fixturePairs: Readonly<Record<FixturePairName, readonly [MarkGeometry, MarkGeometry]>> = /* @__PURE__ */ Object.freeze({\n \"slice and column\": [fixtures.slice, fixtures.column],\n \"bar and column\": [fixtures.bar, fixtures.column],\n \"two slices\": [fixtures.slice, movedFixtures.slice],\n \"two lines\": [fixtures.line, movedFixtures.line],\n \"two points\": [fixtures.point, movedFixtures.point]\n} as const);\n\nfunction makeFixtures(moved: boolean): Readonly<Record<FixtureName, MarkGeometry>> {\n const y = moved ? 30 : 0;\n const bar = (width: number, more: Partial<Parameters<typeof build.bar>[0]> = {}): MarkGeometry =>\n build.bar({ key: \"Okafor\", series: \"goals\", x: 0, y, width, height: 20, baseline: \"left\", ...more });\n const [goals, assists] = moved ? [120, 82] : [160, 62];\n const points = moved\n ? [{ x: 0, y: 90 }, { x: 64, y: 58 }, { x: 128, y: 82 }, { x: 192, y: 26 }, { x: 256, y: 40 }]\n : [{ x: 0, y: 100 }, { x: 80, y: 60 }, { x: 160, y: 90 }, { x: 240, y: 20 }];\n return Object.freeze({\n bar: bar(moved ? 160 : 200, { radius: 4 }),\n \"negative bar\": build.bar({ key: \"n\", series: \"goals\", x: moved ? 30 : 0, y, width: moved ? 90 : 120, height: 20, baseline: \"right\" }),\n column: build.bar({ key: \"c\", series: \"goals\", x: moved ? 30 : 0, y: moved ? 40 : 0, width: 20, height: moved ? 110 : 150, baseline: \"bottom\" }),\n stacked: bar(goals + assists, { series: undefined, gap: 2, segments: [{ series: \"goals\", size: goals }, { series: \"assists\", size: assists }] }),\n \"short bar\": bar(moved ? 4 : 6),\n slice: moved\n ? build.arc({ key: \"Saved\", cx: 140, cy: 130, inner: 60, outer: 100, start: 0.5, end: 2 })\n : build.arc({ key: \"Saved\", cx: 150, cy: 150, inner: 70, outer: 116, start: 0.3, end: 2.4 }),\n line: build.line({ key: \"goals\", series: \"goals\", points, width: 2 }),\n // The line broken after its second point: a run, a gap, and a run.\n \"gapped line\": build.line({ key: \"goals\", series: \"goals\", points, breaks: [2], width: 2 }),\n point: build.point({ key: \"p\", x: moved ? 40 : 10, y: moved ? 25 : 10, r: 3 })\n });\n}\n","// checkEffect and checkTransition: the conformance checks from plan §8 for one effect, on many marks\n// or pairs of marks. They import no test runner: each runs every check on every mark, then throws one\n// Error that lists each failure, so `await checkEffect(effect)` works in Vitest, Jest, node:test or Mocha.\n\nimport type { AnyMarkEffect, DataEffect, GeometryEffect, Icon, MarkData, MarkGeometry, Sample, TransitionContext, TransitionEffect } from \"../core\";\nimport { describeValue, isMarkEffect } from \"../core/registry\";\nimport { flush, play, testContext, type Picture, type TestContext, type TestContextOptions } from \"../core/testing\";\nimport { isTransitionEffect } from \"../core/transition\";\nimport { fixturePairs, fixtures, movedFixtures, type FixtureName } from \"./fixtures\";\n\nexport interface CheckEffectOptions<D = unknown> {\n /**\n * The marks to check on: named, or a list such as a chart's `marks()` (each named by its key in the\n * report). Default: `fixtures`, every kind of mark.\n */\n readonly marks?: Readonly<Record<string, MarkGeometry>> | readonly MarkGeometry[];\n /** The icons the effect looks up by name, through `ctx.icons`. Default: none. */\n readonly icons?: readonly Icon[];\n /**\n * For a data effect, each mark's data. Default: no datum, values from 0 to 1 along the walk (each\n * sample's value is its `t`), and no related series, so an effect that reads its rows or `needs`\n * related series has to pass this. On a mark with gaps, there's a sample at each end of each gap,\n * with `gapBefore` on the one after, as on a line chart's line with a missing value.\n */\n readonly data?: (mark: MarkGeometry) => MarkData<D>;\n /**\n * The same mark moved (a resize, a transition's next frame): another geometry with the same key, for\n * the check that the effect follows `onChange`. Undefined skips that check on the mark. Default:\n * each fixture's moved twin, and nothing for other marks, so a page's own marks pass this or skip it.\n */\n readonly moved?: (mark: MarkGeometry) => MarkGeometry | undefined;\n /** The mark's place among the marks of its event, for effects that read `ctx.batch` (stagger). Default: the only one. */\n readonly batch?: { readonly index: number; readonly count: number };\n /** What the report calls the effect. Default: \"the effect\". */\n readonly name?: string;\n}\n\n/** A data effect typed for its own rows: data(mark) has to give them. */\ntype WithData<D> = CheckEffectOptions<D> & { readonly data: (mark: MarkGeometry) => MarkData<D> };\n\n/**\n * Runs the conformance checks on every mark (`options.marks`, or the fixtures):\n * 1. a full run ends with the same picture and mark style as `end()`;\n * 2. clearing leaves nothing drawn, the mark's own style, and no frames running;\n * 3. an abort mid-run settles the run (it resolves, without more frames) and clears to nothing;\n * 4. with motion off, no frames run and the run draws what `end()` draws;\n * 5. after a full run, and after `end()`, a `change()` to the moved mark (`options.moved`) leaves the\n * picture and mark style `end()` draws on it, so an effect that should stay attached follows `onChange`.\n *\n * Resolves when every check passes. Otherwise it rejects with one Error that lists every failure:\n * the mark, the check and what differed. A data effect typed for its own rows needs `data`, and so\n * does one that `needs` related series.\n */\nexport function checkEffect(effect: GeometryEffect | DataEffect<unknown>, options?: CheckEffectOptions<unknown>): Promise<void>;\nexport function checkEffect<D>(effect: GeometryEffect | DataEffect<D>, options: WithData<D>): Promise<void>;\nexport async function checkEffect(effect: AnyMarkEffect, options: CheckEffectOptions<any> = {}): Promise<void> {\n if (!isMarkEffect(effect)) {\n const hint = isTransitionEffect(effect) ? \"; check it with checkTransition\" : \"\";\n throw new TypeError(`checkEffect needs a mark effect (kind \"geometry\" or \"data\"), got ${describeValue(effect)}${hint}.`);\n }\n const name = options.name ?? \"the effect\";\n const related = effect.kind === \"data\" ? (effect.needs?.related ?? []) : [];\n if (related.length > 0 && !options.data) {\n throw new TypeError(\n `checkEffect: ${name} needs the related series ${related.map((s) => `\"${s}\"`).join(\", \")}, so pass data(mark) with them: the default data has no related series.`\n );\n }\n const marks = named(options.marks ?? fixtures);\n if (marks.length === 0) throw new TypeError(\"checkEffect: there are no marks to check on.\");\n\n const dataOf = (mark: MarkGeometry): MarkData<unknown> | undefined => (effect.kind === \"data\" ? (options.data ?? defaultData)(mark) : undefined);\n const failures: string[] = [];\n for (const [markName, mark] of marks) {\n let data: MarkData<unknown> | undefined;\n try {\n data = dataOf(mark);\n } catch (error) {\n failures.push(`on ${markName}: data(mark) threw ${describeError(error)}`);\n continue;\n }\n let moved: Moved | undefined;\n try {\n moved = movedSubject(effect, (options.moved ?? movedFixture)(mark), dataOf);\n } catch (error) {\n failures.push(`on ${markName}: the moved mark, or its data, threw ${describeError(error)}`);\n }\n const subject: Subject = {\n context: (more = {}) => testContext({ icons: options.icons, batch: options.batch, ...more }),\n run: (ctx) => promised(effect.kind === \"data\" ? effect.run(mark, data!, ctx) : effect.run(mark, ctx)),\n end: (ctx) => (effect.kind === \"data\" ? effect.end(mark, data!, ctx) : effect.end(mark, ctx)),\n clear: (ctx) => effect.clear(ctx),\n moved\n };\n for (const check of CHECKS) {\n const problem = await attempt(check, subject);\n if (problem) failures.push(`on ${markName}, ${check.title}: ${problem}`);\n }\n }\n\n if (failures.length > 0) throw new Error(`checkEffect found ${problems(failures)} with ${name}:\\n${list(failures)}`);\n}\n\nexport interface CheckTransitionOptions {\n /**\n * The pairs to check on, each as [a, b] and run both ways: named, or a list (each named by its\n * marks' keys in the report). Default: `fixturePairs`, a slice and a column, a bar and a column,\n * two slices, two lines and two points.\n */\n readonly pairs?: Readonly<Record<string, readonly [MarkGeometry, MarkGeometry]>> | readonly (readonly [MarkGeometry, MarkGeometry])[];\n /** The icons the effect looks up by name, through `ctx.icons`. Default: none. */\n readonly icons?: readonly Icon[];\n /** What the report calls the effect. Default: \"the effect\". */\n readonly name?: string;\n}\n\n/** Where the retrace check compares a run forward with a run back. */\nconst RETRACE_AT: readonly number[] = [0.25, 0.5, 0.75];\n\n/**\n * Runs the conformance checks for a transition effect on every pair (`options.pairs`, or the fixture\n * pairs), from a to b and from b to a:\n * 1. a full run ends with the same picture as `end()`;\n * 2. clearing leaves nothing drawn and no frames running;\n * 3. an abort mid-run settles the run (it resolves, without more frames) and clears to nothing;\n * 4. with motion off, no frames run and the run draws what `end()` draws;\n * 5. a run from `start: 0.5` ends with the same picture as `end()`;\n * 6. it retraces: at p = 0.25, 0.5 and 0.75, a run from b to a from `start: 1 - p` begins with the\n * picture a run from a to b begins with from `start: p`, the picture a full run draws at p. So a\n * switch back mid-way doesn't jump, and a pairing that depends on which mark is `from` fails.\n *\n * Resolves when every check passes. Otherwise it rejects with one Error that lists every failure:\n * the pair, which way, the check and what differed.\n */\nexport async function checkTransition(effect: TransitionEffect, options: CheckTransitionOptions = {}): Promise<void> {\n if (!isTransitionEffect(effect)) {\n const hint = isMarkEffect(effect) ? \"; check it with checkEffect\" : \"\";\n throw new TypeError(`checkTransition needs a transition effect (kind \"transition\" with run, end and clear), got ${describeTransition(effect)}${hint}.`);\n }\n const name = options.name ?? \"the effect\";\n const pairs = namedPairs(options.pairs ?? fixturePairs);\n if (pairs.length === 0) throw new TypeError(\"checkTransition: there are no pairs to check on.\");\n\n const failures: string[] = [];\n for (const [pairName, [a, b]] of pairs) {\n for (const [way, from, to] of [[\"a to b\", a, b], [\"b to a\", b, a]] as const) {\n for (const check of COMMON) {\n const problem = await attempt(check, transitionSubject(effect, from, to, 0, options.icons));\n if (problem) failures.push(`on ${pairName}, ${way}, ${check.title}: ${problem}`);\n }\n const problem = await attempt(FULL_RUN, transitionSubject(effect, from, to, 0.5, options.icons));\n if (problem) failures.push(`on ${pairName}, ${way}, a run from start: 0.5 should end with the same picture as end(): ${problem}`);\n }\n let problem: string | undefined;\n try {\n problem = await retraces(effect, a, b, options.icons);\n } catch (error) {\n problem = `it threw ${describeError(error)}`;\n }\n if (problem) failures.push(`on ${pairName}, a run back should retrace the run forward: ${problem}`);\n }\n\n if (failures.length > 0) throw new Error(`checkTransition found ${problems(failures)} with ${name}:\\n${list(failures)}`);\n}\n\n/** A test context that is also a transition's, starting at `start`. */\ntype TransitionTestContext = TestContext & TransitionContext;\n\nfunction transitionContext(start: number, options: TestContextOptions): TransitionTestContext {\n return { ...testContext(options), start };\n}\n\n/** One transition effect on one pair, one way, from `start`, as a Subject. Its contexts carry `start`. */\nfunction transitionSubject(effect: TransitionEffect, from: MarkGeometry, to: MarkGeometry, start: number, icons: readonly Icon[] | undefined): Subject {\n return {\n context: (more = {}) => transitionContext(start, { icons, ...more }),\n run: (ctx) => promised(effect.run(from, to, ctx as TransitionTestContext)),\n end: (ctx) => effect.end(from, to, ctx as TransitionTestContext),\n clear: (ctx) => effect.clear(ctx as TransitionTestContext),\n moved: undefined\n };\n}\n\n/** What a run from `start` draws before its first frame, after which it's aborted and cleared. */\nasync function opening(effect: TransitionEffect, from: MarkGeometry, to: MarkGeometry, start: number, icons: readonly Icon[] | undefined): Promise<Picture[]> {\n const ctx = transitionContext(start, { icons });\n const run = track(promised(effect.run(from, to, ctx)));\n await flush();\n const picture = ctx.layer.picture();\n ctx.abort();\n await settle(run);\n effect.clear(ctx);\n ctx.clear();\n if (run.failed) throw run.error;\n return picture;\n}\n\n/** The retrace check (6): what differs between a run back from 1 - p and a run forward from p, or undefined. */\nasync function retraces(effect: TransitionEffect, a: MarkGeometry, b: MarkGeometry, icons: readonly Icon[] | undefined): Promise<string | undefined> {\n for (const p of RETRACE_AT) {\n const forward = await opening(effect, a, b, p, icons);\n const back = await opening(effect, b, a, 1 - p, icons);\n if (same(back, forward)) continue;\n const index = back.findIndex((item, i) => !same(item, forward[i]));\n const what =\n back.length !== forward.length\n ? `${back.length} ${back.length === 1 ? \"item\" : \"items\"} (${show(back)}) where the run from a to b from start: ${p} begins with ${forward.length} (${show(forward)})`\n : `item ${index + 1} unlike the run from a to b from start: ${p}: ${difference(back[index], forward[index])}`;\n return `the run from b to a from start: ${1 - p} begins with ${what}`;\n }\n return undefined;\n}\n\n/** How a drawn item differs from another: its first differing field, and for long text the part where they part. */\nfunction difference(actual: unknown, expected: unknown): string {\n if (typeof actual !== \"object\" || typeof expected !== \"object\" || actual === null || expected === null) return `${show(actual)}, not ${show(expected)}`;\n const a = actual as Record<string, unknown>;\n const b = expected as Record<string, unknown>;\n for (const field of new Set([...Object.keys(a), ...Object.keys(b)])) {\n const x = a[field];\n const y = b[field];\n if (same(x, y)) continue;\n if (typeof x !== \"string\" || typeof y !== \"string\") return `its ${field} is ${show(x)}, not ${show(y)}`;\n let at = 0;\n while (at < x.length && x[at] === y[at]) at++;\n const from = Math.max(0, at - 24);\n const part = (text: string): string => `${from > 0 ? \"…\" : \"\"}${text.slice(from, at + 24)}${at + 24 < text.length ? \"…\" : \"\"}`;\n return `its ${field} parts at character ${at + 1}: ${JSON.stringify(part(x))}, not ${JSON.stringify(part(y))}`;\n }\n return `${show(actual)}, not ${show(expected)}`;\n}\n\nfunction namedPairs(\n pairs: Readonly<Record<string, readonly [MarkGeometry, MarkGeometry]>> | readonly (readonly [MarkGeometry, MarkGeometry])[]\n): [string, readonly [MarkGeometry, MarkGeometry]][] {\n if (!Array.isArray(pairs)) return Object.entries(pairs as Readonly<Record<string, readonly [MarkGeometry, MarkGeometry]>>).map(([name, pair]) => [`the ${name}`, pair]);\n return (pairs as readonly (readonly [MarkGeometry, MarkGeometry])[]).map((pair, i) => {\n const [a, b] = pair;\n const keys = a?.key === b?.key ? `\"${String(a?.key)}\"` : `\"${String(a?.key)}\" and \"${String(b?.key)}\"`;\n return [`pair ${i + 1} (${keys})`, pair];\n });\n}\n\nfunction describeTransition(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`;\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\n/** One effect on one mark (or one pair), ready to run on fresh contexts. */\ninterface Subject {\n context(options?: TestContextOptions): TestContext;\n /** Starts a run; throws if run() doesn't return a promise. */\n run(ctx: TestContext): Promise<void>;\n end(ctx: TestContext): void;\n /** The effect's own clear(). */\n clear(ctx: TestContext): void;\n /** The mark moved, for the onChange check; undefined skips it. */\n readonly moved: Moved | undefined;\n}\n\n/** A check's problem on the subject, or undefined; throwing counts as one. */\nasync function attempt(check: Check, subject: Subject): Promise<string | undefined> {\n try {\n return await check.test(subject);\n } catch (error) {\n return `it threw ${describeError(error)}`;\n }\n}\n\n/** run()'s result, which must be a promise. */\nfunction promised(running: unknown): Promise<void> {\n if (typeof (running as Promise<void> | undefined)?.then !== \"function\") throw new TypeError(`run() must return a promise, got ${describeValue(running)}.`);\n return running as Promise<void>;\n}\n\nconst problems = (failures: readonly string[]): string => (failures.length === 1 ? \"1 problem\" : `${failures.length} problems`);\nconst list = (failures: readonly string[]): string => failures.map((failure) => `- ${failure}`).join(\"\\n\");\n\n/** The moved mark, with its data. */\ninterface Moved {\n /** Tells the run's onChange listeners the mark moved, with its data there, as the runner does. */\n change(ctx: TestContext): void;\n /** end() on the moved mark. */\n end(ctx: TestContext): void;\n}\n\n/** The moved twin of a fixture (the same object, whatever it is named); nothing for other marks. */\nfunction movedFixture(mark: MarkGeometry): MarkGeometry | undefined {\n const name = (Object.keys(fixtures) as FixtureName[]).find((fixture) => fixtures[fixture] === mark);\n return name === undefined ? undefined : movedFixtures[name];\n}\n\nfunction movedSubject(effect: AnyMarkEffect, mark: MarkGeometry | undefined, dataOf: (mark: MarkGeometry) => MarkData<unknown> | undefined): Moved | undefined {\n if (mark === undefined) return undefined;\n const data = dataOf(mark);\n return {\n change: (ctx) => ctx.change(mark, data),\n end: (ctx) => (effect.kind === \"data\" ? effect.end(mark, data!, ctx) : effect.end(mark, ctx))\n };\n}\n\ninterface Check {\n readonly title: string;\n /** What went wrong, or undefined. Throwing counts as a failure too. */\n test(subject: Subject): Promise<string | undefined>;\n}\n\nconst FULL_RUN: Check = {\n title: \"a full run should end with the same picture and mark style as end()\",\n async test(subject) {\n const ran = subject.context();\n const run = track(subject.run(ran));\n await play(ran.clock, run.done);\n if (run.failed) return `run() rejected with ${describeError(run.error)}`;\n const ended = subject.context();\n subject.end(ended);\n return compare(ran, ended, \"after the run\");\n }\n};\n\n/** The checks for every kind of effect: checkEffect's first four, which checkTransition runs too. */\nconst COMMON: readonly Check[] = [\n FULL_RUN,\n {\n title: \"clearing should leave nothing behind\",\n async test(subject) {\n const ctx = subject.context();\n const run = track(subject.run(ctx));\n await play(ctx.clock, run.done);\n subject.clear(ctx);\n ctx.clear();\n // Nothing may come back afterwards, from a listener or a tween that outlived the run.\n ctx.clock.advance(48);\n await flush();\n return leftovers(ctx);\n }\n },\n {\n title: \"an abort mid-run should settle the run and clear to nothing\",\n async test(subject) {\n const ctx = subject.context();\n const run = track(subject.run(ctx));\n ctx.clock.advance(16);\n ctx.clock.advance(16);\n ctx.abort();\n await settle(run);\n if (!run.settled) return \"run() was still running after the abort; it should resolve once ctx.signal aborts, without more frames\";\n if (run.failed) return `run() rejected with ${describeError(run.error)} (it should resolve, aborted or not)`;\n subject.clear(ctx);\n ctx.clear();\n return leftovers(ctx);\n }\n },\n {\n title: \"with motion off, no frames should run and the end state should be drawn\",\n async test(subject) {\n const ctx = subject.context({ mode: \"off\" });\n const run = track(subject.run(ctx));\n const framesAtStart = !ctx.clock.idle;\n await settle(run);\n if (!run.settled) return \"run() didn't finish; with motion off ctx.tween() ends at once, so wait only through it, never on a timer\";\n if (run.failed) return `run() rejected with ${describeError(run.error)}`;\n if (framesAtStart || !ctx.clock.idle) return \"it asked for animation frames\";\n const ended = subject.context({ mode: \"off\" });\n subject.end(ended);\n return compare(ctx, ended, \"after the run with motion off\");\n }\n }\n];\n\nconst CHECKS: readonly Check[] = [\n ...COMMON,\n {\n title: \"a change() to the moved mark should leave what end() draws on it\",\n async test(subject) {\n const { moved } = subject;\n if (!moved) return undefined;\n const problems: string[] = [];\n\n const ran = subject.context();\n const run = track(subject.run(ran));\n await play(ran.clock, run.done);\n if (run.failed) return `run() rejected with ${describeError(run.error)}`;\n moved.change(ran);\n if (!(await finish(ran))) return \"it was still animating 10 s after the change()\";\n const ended = subject.context();\n moved.end(ended);\n const afterRun = compare(ran, ended, \"after a full run and a change()\");\n if (afterRun) problems.push(afterRun);\n\n // With motion off the runner draws end() instead of running, and changes still come.\n const still = subject.context({ mode: \"off\" });\n subject.end(still);\n moved.change(still);\n await flush();\n const endedOff = subject.context({ mode: \"off\" });\n moved.end(endedOff);\n const afterEnd = compare(still, endedOff, \"after end() and a change()\");\n if (afterEnd) problems.push(afterEnd);\n return problems.length > 0 ? problems.join(\"; \") : undefined;\n }\n }\n];\n\n/** Runs frames until nothing animates (an effect may ease to the new geometry); false if it's still going after 10 s. */\nasync function finish(ctx: TestContext): Promise<boolean> {\n await flush();\n for (let elapsed = 0; !ctx.clock.idle; elapsed += 16) {\n if (elapsed >= 10_000) return false;\n ctx.clock.advance(16);\n await flush();\n }\n return true;\n}\n\n/**\n * No datum, values 0 to 1 along the walk, no related series. On a mark with gaps, a sample at each\n * end of each gap too, with `gapBefore` on the one after, as a line chart gives a line with a missing\n * value; samples at one `t` (a gap from 0, or gaps either side of a value alone) are one.\n */\nconst defaultData = (mark: MarkGeometry): MarkData<unknown> => {\n const samples: Sample[] = [{ t: 0, value: 0 }];\n const add = (t: number, gapBefore: boolean): void => {\n const last = samples[samples.length - 1]!;\n if (t === last.t) samples[samples.length - 1] = gapBefore ? { ...last, gapBefore } : last;\n else samples.push(gapBefore ? { t, value: t, gapBefore } : { t, value: t });\n };\n for (const [from, to] of mark.gaps ?? []) {\n add(from, false);\n add(to, true);\n }\n add(1, false);\n return { datum: undefined, samples, related: () => undefined };\n};\n\nfunction named(marks: Readonly<Record<string, MarkGeometry>> | readonly MarkGeometry[]): [string, MarkGeometry][] {\n if (!Array.isArray(marks)) return Object.entries(marks as Readonly<Record<string, MarkGeometry>>).map(([name, mark]) => [`the ${name}`, mark]);\n const seen = new Map<string, number>();\n return (marks as readonly MarkGeometry[]).map((mark) => {\n const count = (seen.get(mark.key) ?? 0) + 1;\n seen.set(mark.key, count);\n return [`mark \"${mark.key}\"${count > 1 ? ` (${count})` : \"\"}`, mark];\n });\n}\n\ninterface Tracked {\n /** Resolves when the run settles, either way. */\n readonly done: Promise<void>;\n readonly settled: boolean;\n readonly failed: boolean;\n readonly error: unknown;\n}\n\nfunction track(running: Promise<void>): Tracked {\n const state = { settled: false, failed: false, error: undefined as unknown };\n const done = running.then(\n () => {\n state.settled = true;\n },\n (error: unknown) => {\n Object.assign(state, { settled: true, failed: true, error });\n }\n );\n return Object.assign(state, { done });\n}\n\n/** Lets promise callbacks run, with no frames, until the run settles or plainly won't. */\nasync function settle(run: Tracked): Promise<void> {\n for (let i = 0; i < 10 && !run.settled; i++) await flush();\n}\n\n/** What differs between two contexts' pictures and mark styles, or undefined. */\nfunction compare(actual: TestContext, expected: TestContext, when: string): string | undefined {\n const problems: string[] = [];\n const drawn = actual.layer.picture();\n const wanted = expected.layer.picture();\n if (!same(drawn, wanted)) {\n const index = drawn.findIndex((item, i) => !same(item, wanted[i]));\n problems.push(\n drawn.length !== wanted.length\n ? `${drawn.length} ${drawn.length === 1 ? \"item is\" : \"items are\"} drawn ${when} but end() draws ${wanted.length} (${show(drawn)} vs ${show(wanted)})`\n : `item ${index + 1} drawn ${when} is ${show(drawn[index])} but end() draws ${show(wanted[index])}`\n );\n }\n const style = rounded(actual.mark.style);\n const wantedStyle = rounded(expected.mark.style);\n if (!same(style, wantedStyle)) problems.push(`the mark's style ${when} is ${show(style)} but end() leaves ${show(wantedStyle)}`);\n return problems.length > 0 ? problems.join(\"; \") : undefined;\n}\n\n/** What a cleared context still has: drawings, a mark style, running frames. */\nfunction leftovers(ctx: TestContext): string | undefined {\n const problems: string[] = [];\n if (ctx.layer.drawn.length > 0) problems.push(`${show(ctx.layer.picture())} is still drawn`);\n if (Object.keys(ctx.mark.style).length > 0) problems.push(`the mark's style is still ${show(ctx.mark.style)}`);\n if (!ctx.clock.idle) problems.push(\"animation frames are still running\");\n return problems.length > 0 ? problems.join(\"; \") : undefined;\n}\n\n/** Deep equality for plain data, ignoring key order. */\nfunction same(a: unknown, b: unknown): boolean {\n if (a === b || (Number.isNaN(a) && Number.isNaN(b))) return true;\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n const keysA = Object.keys(a).filter((key) => (a as Record<string, unknown>)[key] !== undefined);\n const keysB = Object.keys(b).filter((key) => (b as Record<string, unknown>)[key] !== undefined);\n return keysA.length === keysB.length && keysA.every((key) => same((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key]));\n}\n\n/** Numbers rounded to 0.001, as pictures are, so float noise in a style isn't a difference. */\nfunction rounded(value: unknown): unknown {\n if (typeof value === \"number\") {\n const round = Math.round(value * 1000) / 1000;\n return round === 0 ? 0 : round;\n }\n if (Array.isArray(value)) return value.map(rounded);\n if (typeof value === \"object\" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, field]) => [key, rounded(field)]));\n return value;\n}\n\nconst LONGEST = 240;\n\nfunction show(value: unknown): string {\n const text = JSON.stringify(value) ?? String(value);\n return text.length > LONGEST ? `${text.slice(0, LONGEST - 1)}…` : text;\n}\n\nfunction describeError(error: unknown): string {\n return error instanceof Error ? `${error.name}: ${error.message}` : show(error);\n}\n"],"mappings":";;;AAmFA,SAAgB,aAAa,OAAwC;CACnE,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,MAAM,SAAS;CACf,QACG,OAAO,SAAS,cAAc,OAAO,SAAS,WAC/C,OAAO,OAAO,QAAQ,cACtB,OAAO,OAAO,QAAQ,cACtB,OAAO,OAAO,UAAU;AAE5B;AAGA,SAAgB,cAAc,OAAwB;CACpD,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,UAAU,OAAO,SAAS,OAAO;CACzF,MAAM,OAAQ,MAA6B;CAC3C,IAAI,SAAS,cAAc,OAAO;CAClC,IAAI,SAAS,cAAc,SAAS,QAAQ,OAAO,KAA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