@motionscript/math 0.1.1-alpha.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -2
  3. package/dist/annotate/curly-brace.d.ts +3 -3
  4. package/dist/annotate/emphasis-mark.d.ts +3 -3
  5. package/dist/browser/chunks/chunk-347RSDIW.js +2 -0
  6. package/dist/browser/chunks/chunk-347RSDIW.js.map +7 -0
  7. package/dist/browser/index.js +1 -1
  8. package/dist/browser/index.js.map +4 -4
  9. package/dist/browser/kit.js +1 -1
  10. package/dist/browser/manifest.json +1 -1
  11. package/dist/engine.d.ts +1 -1
  12. package/dist/engine.js +1 -1
  13. package/dist/engine.js.map +1 -1
  14. package/dist/index.d.ts +28 -28
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +29 -28
  17. package/dist/index.js.map +1 -1
  18. package/dist/marks/curve-area.d.ts +3 -3
  19. package/dist/marks/drop-lines.d.ts +3 -3
  20. package/dist/marks/riemann-sum.d.ts +3 -3
  21. package/dist/marks/tangent-line.d.ts +3 -3
  22. package/dist/marks/vector-arrow.d.ts +3 -3
  23. package/dist/plots/function-plot.d.ts +4 -4
  24. package/dist/plots/points-plot.d.ts +3 -3
  25. package/dist/plots/stream-lines.d.ts +6 -6
  26. package/dist/plots/traced-path.d.ts +6 -6
  27. package/dist/plots/vector-field.d.ts +6 -6
  28. package/dist/systems/number-line.d.ts +3 -3
  29. package/dist/systems/number-plane.d.ts +6 -6
  30. package/dist/tex/matrix.d.ts +3 -3
  31. package/dist/tex/node.d.ts +3 -3
  32. package/dist/three/curve-plot3d.d.ts +3 -3
  33. package/dist/three/surface-plot3d.d.ts +8 -8
  34. package/dist/unstable.d.ts +29 -0
  35. package/dist/unstable.d.ts.map +1 -0
  36. package/dist/unstable.js +31 -0
  37. package/dist/unstable.js.map +1 -0
  38. package/package.json +6 -6
  39. package/registry.json +1 -1
  40. package/src/engine.ts +1 -1
  41. package/src/index.ts +29 -28
  42. package/src/unstable.ts +30 -0
  43. package/dist/browser/chunks/chunk-FZ2YBTPL.js +0 -2
  44. package/dist/browser/chunks/chunk-FZ2YBTPL.js.map +0 -7
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/kit/coords.ts", "../../../src/kit/furniture.ts", "../../../src/kit/expression.ts", "../../../src/kit/equation.ts", "../../../src/kit/source.ts", "../../../src/kit/curve.ts", "../../../src/kit/graph.ts", "../../../src/kit/geometry.ts", "../../../src/kit/mark.ts", "../../../src/kit/place.ts", "../../../src/kit/system.ts", "../../../src/kit/ticks.ts", "../../../src/systems/number-line.ts", "../../../src/systems/axes2d.ts", "../../../src/kit/field.ts", "../../../src/systems/number-plane.ts", "../../../src/systems/polar-plane.ts", "../../../src/kit/contour.ts", "../../../src/kit/sampler.ts", "../../../src/plots/function-plot.ts", "../../../src/plots/points-plot.ts", "../../../src/kit/scale.ts", "../../../src/kit/field-mark.ts", "../../../src/plots/vector-field.ts", "../../../src/plots/stream-lines.ts", "../../../src/plots/traced-path.ts", "../../../src/marks/plot-point.ts", "../../../src/marks/vector-arrow.ts", "../../../src/marks/curve-area.ts", "../../../src/marks/riemann-sum.ts", "../../../src/marks/tangent-line.ts", "../../../src/marks/drop-lines.ts", "../../../src/kit/follow.ts", "../../../src/kit/brace.ts", "../../../src/annotate/curly-brace.ts", "../../../src/annotate/angle-mark.ts", "../../../src/annotate/emphasis-mark.ts", "../../../src/three/label3d.ts", "../../../src/three/space.ts", "../../../src/three/axes3d.ts", "../../../src/kit/equation3d.ts", "../../../src/three/entries.ts", "../../../src/three/surface-plot3d.ts", "../../../src/three/curve-plot3d.ts", "../../../src/three/plot-point3d.ts", "../../../src/three/vector-arrow3d.ts", "../../../src/structures/graph-layout.ts", "../../../src/structures/network-graph.ts", "../../../src/structures/sample-space.ts"],
4
+ "sourcesContent": ["import { lerpNumber, type Extents, type Vector2 } from \"@motionscript/sdk\";\n\n/** A closed span of graph values, low to high. */\nexport type Interval = readonly [number, number];\n\nexport type AxisScaling = \"linear\" | \"log\";\n\n/**\n * How a coordinate system's graph values land on its pixels. Pixels are y-up\n * from the centre of the system's own box, which is the frame a `Graphics2D` op\n * is written in.\n */\nexport interface CoordinateMap {\n /** Graph to pixels. Writes into `out` when given, so a sampler allocates nothing. */\n toPoint(x: number, y: number, out?: Vector2): Vector2;\n toCoords(x: number, y: number, out?: Vector2): Vector2;\n /** The plot area. */\n readonly area: Extents;\n readonly xRange: Interval;\n readonly yRange: Interval;\n /** Equal for two maps that place every point alike: what a geometry cache keys on. */\n readonly revision: string;\n /** Set where a straight run of graph values is not a straight run of pixels, so a line through the map is sampled. */\n readonly curved?: boolean;\n /** Set where what is ruled over the ranges can leave the plot area, so the system keeps it in. */\n readonly spills?: boolean;\n}\n\n/** One axis: a graph value to a pixel and back. */\nexport interface AxisScale {\n to(value: number): number;\n from(pixel: number): number;\n}\n\n/** `range`, made usable: finite, ordered, non-empty, and positive on a log axis. */\nexport function resolveInterval(range: Interval | undefined, scaling: AxisScaling = \"linear\"): Interval {\n let [min, max] = range ?? [0, 1];\n if (!Number.isFinite(min) || !Number.isFinite(max)) [min, max] = [0, 1];\n if (min > max) [min, max] = [max, min];\n if (scaling === \"log\") {\n if (!(max > 0)) max = 10;\n if (!(min > 0)) min = max / 1000;\n }\n return max > min ? [min, max] : [min, min + 1];\n}\n\n/** `range` spread over the pixels from `lo` to `hi`. */\nexport function axisScale(range: Interval, lo: number, hi: number, scaling: AxisScaling = \"linear\"): AxisScale {\n const [min, max] = range;\n if (scaling === \"log\") {\n const from = Math.log10(min);\n const k = (hi - lo) / (Math.log10(max) - from);\n return { to: (v) => lo + (Math.log10(v) - from) * k, from: (p) => 10 ** (from + (p - lo) / k) };\n }\n const k = (hi - lo) / (max - min);\n return { to: (v) => lo + (v - min) * k, from: (p) => min + (p - lo) / k };\n}\n\nexport interface CartesianOptions {\n xRange: Interval;\n yRange: Interval;\n area: Extents;\n xScaling?: AxisScaling;\n yScaling?: AxisScaling;\n}\n\n/** Two independent axes at right angles: what a number line, axes and a number plane share. */\nexport function cartesianMap({ xRange, yRange, area, xScaling = \"linear\", yScaling = \"linear\" }: CartesianOptions): CoordinateMap {\n const x = axisScale(xRange, area.minX, area.maxX, xScaling);\n const y = axisScale(yRange, area.minY, area.maxY, yScaling);\n return {\n toPoint: (gx, gy, out = { x: 0, y: 0 }) => {\n out.x = x.to(gx);\n out.y = y.to(gy);\n return out;\n },\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\n out.x = x.from(px);\n out.y = y.from(py);\n return out;\n },\n area,\n xRange,\n yRange,\n revision: [xRange, yRange, area.minX, area.minY, area.maxX, area.maxY, xScaling, yScaling].join(\"|\"),\n };\n}\n\nconst UNBOUNDED: Extents = { minX: -Infinity, minY: -Infinity, maxX: Infinity, maxY: Infinity };\n\n/** One graph unit is one pixel: what a mark outside any system is drawn through. */\nexport const PIXEL_MAP: CoordinateMap = {\n toPoint: (x, y, out = { x: 0, y: 0 }) => {\n out.x = x;\n out.y = y;\n return out;\n },\n toCoords: (x, y, out = { x: 0, y: 0 }) => {\n out.x = x;\n out.y = y;\n return out;\n },\n area: UNBOUNDED,\n xRange: [-Infinity, Infinity],\n yRange: [-Infinity, Infinity],\n revision: \"pixels\",\n};\n\n/** A 2 × 2 matrix, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\nexport type Matrix2 = readonly [number, number, number, number];\n\nexport const IDENTITY_MATRIX: Matrix2 = [1, 0, 0, 1];\n\n/** A matrix from its rows, or flat; anything else is the identity. */\nexport function readMatrix(value: unknown, previous: Matrix2 = IDENTITY_MATRIX): Matrix2 {\n const flat = Array.isArray(value) ? value.flat() : [];\n if (flat.length !== 4 || flat.some((entry) => typeof entry !== \"number\" || !Number.isFinite(entry))) return previous;\n return [flat[0], flat[1], flat[2], flat[3]];\n}\n\nexport function lerpMatrix(from: Matrix2, to: Matrix2, t: number): Matrix2 {\n return [0, 1, 2, 3].map((i) => lerpNumber(from[i], to[i], t)) as unknown as Matrix2;\n}\n\nexport function isIdentityMatrix([a, b, c, d]: Matrix2): boolean {\n return a === 1 && b === 0 && c === 0 && d === 1;\n}\n\n/**\n * How far a transformed plane reaches, in half-widths of its own ranges about\n * their middle. Finite on purpose: a plane squeezed towards a line shows the\n * pre-image of its box growing as 1/det, and ruling all of it packs the box\n * with lines, a solid wash just before the plane goes flat.\n */\nconst REACH = 4;\n\nfunction reach([min, max]: Interval): Interval {\n const middle = (min + max) / 2;\n const half = ((max - min) / 2) * REACH;\n return [middle - half, middle + half];\n}\n\n/**\n * `base` with every graph point sent through `matrix` first: a plane sheared,\n * turned or squeezed about its origin. Its ranges are what the plot area then\n * shows, up to {@link REACH}, so a grid ruled over them fills the box under a\n * turn, a shear or a fourfold shrink, and folds into a band as it goes flat.\n */\nexport function transformedMap(base: CoordinateMap, matrix: Matrix2): CoordinateMap {\n const [a, b, c, d] = matrix;\n const det = a * d - b * c;\n // A plane squeezed onto a line has no way back: a point is read as the untransformed plane has it.\n const flat = Math.abs(det) < 1e-9;\n const back = (u: number, v: number, out: Vector2): Vector2 => {\n if (flat) {\n out.x = u;\n out.y = v;\n } else {\n out.x = (d * u - b * v) / det;\n out.y = (a * v - c * u) / det;\n }\n return out;\n };\n const xReach = reach(base.xRange);\n const yReach = reach(base.yRange);\n let xRange = xReach;\n let yRange = yReach;\n if (!flat) {\n const corner: Vector2 = { x: 0, y: 0 };\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const u of base.xRange) {\n for (const v of base.yRange) {\n back(u, v, corner);\n minX = Math.min(minX, corner.x);\n maxX = Math.max(maxX, corner.x);\n minY = Math.min(minY, corner.y);\n maxY = Math.max(maxY, corner.y);\n }\n }\n xRange = [Math.max(minX, xReach[0]), Math.min(maxX, xReach[1])];\n yRange = [Math.max(minY, yReach[0]), Math.min(maxY, yReach[1])];\n }\n return {\n toPoint: (x, y, out = { x: 0, y: 0 }) => base.toPoint(a * x + b * y, c * x + d * y, out),\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\n base.toCoords(px, py, out);\n return back(out.x, out.y, out);\n },\n area: base.area,\n xRange,\n yRange,\n revision: `${base.revision}|m${matrix.join(\",\")}`,\n spills: true,\n };\n}\n\n/** Where a warp sends a graph point, written into `out`; `false` where it has no value. */\nexport type Warp = (x: number, y: number, out: Vector2) => boolean;\n\n/**\n * `base` with every graph point sent to where `warp` sends it: a plane bent by\n * a function of its own points. `key` names the warp for the revision, since a\n * function has no text of its own.\n */\nexport function warpedMap(base: CoordinateMap, warp: Warp, key: string): CoordinateMap {\n const bend = (x: number, y: number, out: Vector2): Vector2 => {\n // A point the warp has no value at stays where it is, so a pole does not tear the grid.\n if (!warp(x, y, out)) {\n out.x = x;\n out.y = y;\n }\n return out;\n };\n const at: Vector2 = { x: 0, y: 0 };\n const dx: Vector2 = { x: 0, y: 0 };\n const dy: Vector2 = { x: 0, y: 0 };\n const H = 1e-4;\n return {\n toPoint: (x, y, out = { x: 0, y: 0 }) => {\n bend(x, y, out);\n return base.toPoint(out.x, out.y, out);\n },\n // No closed form: a few Newton steps from where the unbent plane has the point.\n toCoords: (px, py, out = { x: 0, y: 0 }) => {\n const target = base.toCoords(px, py);\n let gx = target.x;\n let gy = target.y;\n for (let i = 0; i < 8; i++) {\n bend(gx, gy, at);\n const ex = at.x - target.x;\n const ey = at.y - target.y;\n if (Math.abs(ex) + Math.abs(ey) < 1e-9) break;\n bend(gx + H, gy, dx);\n bend(gx, gy + H, dy);\n const j00 = (dx.x - at.x) / H;\n const j10 = (dx.y - at.y) / H;\n const j01 = (dy.x - at.x) / H;\n const j11 = (dy.y - at.y) / H;\n const det = j00 * j11 - j01 * j10;\n if (!(Math.abs(det) > 1e-12)) break;\n gx -= (j11 * ex - j01 * ey) / det;\n gy -= (j00 * ey - j10 * ex) / det;\n }\n out.x = Number.isFinite(gx) ? gx : target.x;\n out.y = Number.isFinite(gy) ? gy : target.y;\n return out;\n },\n area: base.area,\n // A bent plane pulls its edges in somewhere: it is ruled a little past them so the box stays full.\n xRange: widened(base.xRange),\n yRange: widened(base.yRange),\n revision: `${base.revision}|w${key}`,\n curved: true,\n spills: true,\n };\n}\n\n/** How much further than its range, as a share of it, a warped plane is ruled each way. */\nconst WARP_MARGIN = 0.3;\n\nfunction widened([min, max]: Interval): Interval {\n const margin = (max - min) * WARP_MARGIN;\n return Number.isFinite(margin) ? [min - margin, max + margin] : [min, max];\n}\n\n/** How many pieces a line through a curved map is drawn in. */\nconst CURVED_STEPS = 48;\n\n/** The pixel points that draw the straight run of graph values from one point to another. */\nexport function lineThrough(map: CoordinateMap, x0: number, y0: number, x1: number, y1: number): Vector2[] {\n if (!map.curved) return [map.toPoint(x0, y0), map.toPoint(x1, y1)];\n const run: Vector2[] = [];\n for (let i = 0; i <= CURVED_STEPS; i++) {\n const t = i / CURVED_STEPS;\n run.push(map.toPoint(x0 + (x1 - x0) * t, y0 + (y1 - y0) * t));\n }\n return run;\n}\n", "import { Fills, Graphics2D, lerpNumber, toPathString, Types, type AssetScope, type Color, type Loader, type StrokeResolved, type Vector2 } from \"@motionscript/sdk\";\nimport { buildLatexPath, LatexNotLoaded, loadMathJax, MATHJAX_LOADER } from \"../tex/geometry\";\nimport type { Interval } from \"./coords\";\n\n/** What a system draws its axes and numbers in, and a plot its curve, until told otherwise. */\nexport const AXIS_COLOR = \"#9ca3af\";\nexport const PLOT_COLOR = \"#58a6ff\";\n\n/** A stroke without end markers: an axis wears a tip, its ticks do not. */\nexport function withoutTips(stroke: StrokeResolved[]): StrokeResolved[] {\n return stroke.map((layer) => ({ ...layer, startCap: undefined, endCap: undefined }));\n}\n\nexport interface LabelStyle {\n fontSize: number;\n fontFamily: string;\n color: Color;\n}\n\nexport interface Label {\n text: string;\n /** Where the label's box is anchored, in pixels. */\n at: Vector2;\n align: \"left\" | \"center\" | \"right\";\n}\n\n/** How wide a label's box is, in ems: room for a long number, so alignment is by the box's edge. */\nconst LABEL_BOX_EM = 8;\n\n/** A label written between dollar signs is a formula: `$\\\\frac{\\\\pi}{2}$`. */\nconst FORMULA = /^\\$([\\s\\S]+)\\$$/;\n\n/** Ask the host for MathJax when any of `texts` is a formula, so it is there before the node is laid out. */\nexport function declareFormulas(assets: AssetScope, texts: readonly string[]): void {\n if (texts.some((text) => FORMULA.test(text.trim()))) assets.loader(MATHJAX_LOADER, loadMathJax, { gate: \"layout\" });\n}\n\n/** {@link declareFormulas}, for a component's `load`. */\nexport function loadFormulas(loader: Loader, texts: readonly string[]): void {\n if (texts.some((text) => FORMULA.test(text.trim()))) loader.task(MATHJAX_LOADER, loadMathJax, { before: \"layout\" });\n}\n\n/** What draws `labels`: text in the scene's face, and a typeset formula for each one written as such. */\nexport function drawLabels(labels: readonly Label[], style: LabelStyle): Graphics2D[] {\n const out: Graphics2D[] = [];\n const fill = Fills.color(style.color);\n const text = new Graphics2D();\n const width = style.fontSize * LABEL_BOX_EM;\n let written = false;\n for (const label of labels) {\n const formula = FORMULA.exec(label.text.trim());\n const glyphs = formula ? typeset(formula[1], label, style.fontSize) : null;\n if (glyphs) {\n for (const glyph of glyphs) out.push(glyph.fill(fill));\n continue;\n }\n const { at, align } = label;\n written = true;\n text.text({\n text: label.text,\n fontSize: style.fontSize,\n // An empty family is left out, so the label takes the scene's own face.\n ...(style.fontFamily === \"\" ? {} : { fontFamily: style.fontFamily }),\n wrap: false,\n width,\n textAlign: align,\n x: align === \"center\" ? at.x : align === \"right\" ? at.x - width / 2 : at.x + width / 2,\n y: at.y,\n });\n }\n if (written) out.push(text.fill(fill));\n return out;\n}\n\n// A formula's glyphs with its box anchored at the label's point; `null` for one that will not typeset, which is then\n// drawn as written, and nothing at all while MathJax is still on its way: its source is not a stand-in for it.\nfunction typeset(source: string, { at, align }: Label, fontSize: number): Graphics2D[] | null {\n let formula: ReturnType<typeof buildLatexPath>;\n try {\n formula = buildLatexPath(source, fontSize);\n } catch (error) {\n return error instanceof LatexNotLoaded ? [] : null;\n }\n const [minX, minY, maxX, maxY] = formula.bounds;\n const dx = at.x + (align === \"left\" ? formula.width / 2 : align === \"right\" ? -formula.width / 2 : 0);\n // Glyph paths are y-down; the frame whose centre lands on the node's is shifted the other way.\n const frame: [number, number, number, number] = [minX - dx, minY + at.y, maxX - dx, maxY + at.y];\n return formula.tokens.map((token) => new Graphics2D().path({ data: toPathString(token.path), centerBounds: frame }));\n}\n\n/** Whether a mark `u` of the way along an axis is inside the part of it drawn so far. */\nexport function drawn(u: number, start: number, end: number): boolean {\n return u >= start - 1e-9 && u <= end + 1e-9;\n}\n\n/** How far along `range` a value is, 0 to 1, by pixel distance. */\nexport function along(at: Vector2, from: Vector2, to: Vector2): number {\n const dx = to.x - from.x;\n const dy = to.y - from.y;\n const length = dx * dx + dy * dy;\n return length === 0 ? 0 : ((at.x - from.x) * dx + (at.y - from.y) * dy) / length;\n}\n\nexport function lerpInterval(from: Interval, to: Interval, t: number): Interval {\n return [lerpNumber(from[0], to[0], t), lerpNumber(from[1], to[1], t)];\n}\n\n/** An entry holding a `[min, max]` range, read forgivingly and lerped end by end. */\nexport function intervalEntry(initial: Interval) {\n return Types.custom<Interval>(initial, { resolve: readInterval, lerp: lerpInterval });\n}\n\nexport function readInterval(value: Interval | undefined, previous?: Interval): Interval {\n const [min, max] = Array.isArray(value) ? value : (previous ?? [0, 1]);\n return [Number(min), Number(max)];\n}\n", "import { expressionOps } from \"@motionscript/sdk\";\nimport type { ExpressionDialect, ExpressionNode } from \"@motionscript/sdk\";\nimport { createBoundedCache, remember } from \"./cache\";\n\n/** Named values an expression reads at call time, beside its two variables. */\nexport type ExpressionScope = Readonly<Record<string, number>>;\n\n/**\n * A compiled expression. The two variables are fixed slots because this is the\n * hot path of every sampled curve; a one-variable expression never reads `b`.\n */\nexport type CompiledExpression = (a: number, b: number, scope?: ExpressionScope) => number;\n\nconst UNARY: Record<string, (v: number) => number> = {\n sin: Math.sin, cos: Math.cos, tan: Math.tan,\n asin: Math.asin, acos: Math.acos, atan: Math.atan,\n sinh: Math.sinh, cosh: Math.cosh, tanh: Math.tanh,\n sqrt: Math.sqrt, cbrt: Math.cbrt, abs: Math.abs, exp: Math.exp,\n log: Math.log, ln: Math.log, log2: Math.log2, log10: Math.log10,\n floor: Math.floor, ceil: Math.ceil, round: Math.round, sign: Math.sign, trunc: Math.trunc,\n};\n\nconst NARY: Record<string, { fn: (...args: number[]) => number; arity: [number, number] }> = {\n atan2: { fn: Math.atan2, arity: [2, 2] },\n pow: { fn: Math.pow, arity: [2, 2] },\n mod: { fn: (a, b) => a % b, arity: [2, 2] },\n hypot: { fn: Math.hypot, arity: [1, Infinity] },\n min: { fn: Math.min, arity: [1, Infinity] },\n max: { fn: Math.max, arity: [1, Infinity] },\n};\n\nconst CONSTANTS: Record<string, number> = {\n pi: Math.PI, PI: Math.PI, e: Math.E, E: Math.E, tau: Math.PI * 2, phi: (1 + Math.sqrt(5)) / 2,\n};\n\n/**\n * The language a plot's equation is written in: the engine's expression grammar\n * under a dialect of its own (trig in radians, bare identifiers, logs and\n * hyperbolics). Never `new Function`: an equation is stored text.\n */\nexport const MATH_DIALECT: ExpressionDialect = {\n functions: {\n ...Object.fromEntries(Object.keys(UNARY).map((name) => [name, { arity: [1, 1] as [number, number] }])),\n ...Object.fromEntries(Object.entries(NARY).map(([name, { arity }]) => [name, { arity }])),\n },\n constants: CONSTANTS,\n refs: \"bare\",\n unknownName: (name) => `Unknown name '${name}'`,\n};\n\n/** What an expression may name, for a host's \"what can I write here\" help. */\nexport interface ExpressionVocabulary {\n variables: readonly string[];\n functions: readonly string[];\n constants: readonly string[];\n}\n\nexport function expressionVocabulary(variables: readonly string[]): ExpressionVocabulary {\n return {\n variables,\n functions: [...Object.keys(UNARY), ...Object.keys(NARY)].sort(),\n constants: Object.keys(CONSTANTS).filter((name) => name === name.toLowerCase()),\n };\n}\n\n/**\n * Compile `source` over up to two `variables`, in slot order, and any `params`\n * it may read from the scope. Throws on a syntax error or an unknown name.\n */\nexport function compileExpression(\n source: string,\n variables: readonly string[],\n params: readonly string[] = [],\n): CompiledExpression {\n // The parser folds a constant before it yields a reference, so a name that is both stops being the variable.\n for (const name of [...variables, ...params]) {\n if (Object.hasOwn(CONSTANTS, name)) throw new Error(`'${name}' is a constant, so it cannot be a variable`);\n }\n return emit(expressionOps.parse(source, MATH_DIALECT).root, variables, params);\n}\n\nfunction emit(node: ExpressionNode, variables: readonly string[], params: readonly string[]): CompiledExpression {\n switch (node.kind) {\n case \"const\": {\n const { value } = node;\n return () => value;\n }\n case \"ref\": {\n const { name } = node;\n const slot = variables.indexOf(name);\n if (slot === 0) return (a) => a;\n if (slot === 1) return (_a, b) => b;\n if (params.includes(name)) return (_a, _b, scope) => scope?.[name] ?? NaN;\n throw new Error(MATH_DIALECT.unknownName(name));\n }\n case \"unary\": {\n const operand = emit(node.operand, variables, params);\n return (a, b, s) => -operand(a, b, s);\n }\n case \"binary\": {\n const l = emit(node.left, variables, params);\n const r = emit(node.right, variables, params);\n switch (node.op) {\n case \"+\": return (a, b, s) => l(a, b, s) + r(a, b, s);\n case \"-\": return (a, b, s) => l(a, b, s) - r(a, b, s);\n case \"*\": return (a, b, s) => l(a, b, s) * r(a, b, s);\n case \"/\": return (a, b, s) => l(a, b, s) / r(a, b, s);\n case \"%\": return (a, b, s) => l(a, b, s) % r(a, b, s);\n case \"^\": return (a, b, s) => Math.pow(l(a, b, s), r(a, b, s));\n }\n break;\n }\n case \"call\": {\n const args = node.args.map((arg) => emit(arg, variables, params));\n const unary = UNARY[node.name];\n if (unary) {\n const [x] = args;\n return (a, b, s) => unary(x(a, b, s));\n }\n const { fn } = NARY[node.name];\n // The common arity, so the hot path allocates no array per sample.\n if (args.length === 2) {\n const [x, y] = args;\n return (a, b, s) => fn(x(a, b, s), y(a, b, s));\n }\n return (a, b, s) => fn(...args.map((arg) => arg(a, b, s)));\n }\n }\n throw new Error(\"Unsupported expression\");\n}\n\nconst compiled = createBoundedCache<CompiledExpression | Error>(256);\n\n/**\n * {@link compileExpression}, memoised: equal source under equal names is the\n * identical closure, so \"did this expression change\" is an `===`, and a failure\n * is remembered rather than re-parsed every frame.\n */\nexport function compileExpressionCached(\n source: string,\n variables: readonly string[],\n params: readonly string[] = [],\n): CompiledExpression | Error {\n return remember(compiled, `${variables.join(\",\")}|${params.join(\",\")}|${source}`, () => compileExpression(source, variables, params));\n}\n\n/** A compiler that throws a failure instead of returning it, for a reader running inside `memoParse`. */\nexport function compilerFor(params: readonly string[]) {\n return (text: string, variables: readonly string[]): CompiledExpression => {\n const result = compileExpressionCached(text.trim(), variables, params);\n if (result instanceof Error) throw result;\n return result;\n };\n}\n", "import { expressionOps, type ExpressionNode } from \"@motionscript/sdk\";\nimport { createBoundedCache, memoParse } from \"./cache\";\nimport { compilerFor, MATH_DIALECT, type CompiledExpression } from \"./expression\";\n\n/**\n * A plotted equation, read the way it is written rather than by a `kind` prop:\n * `sin(x)` or `y = sin(x)` is a function of `x`, `x = y^2` of `y`,\n * `r = 1 + cos(theta)` polar, `(cos(t), sin(t))` parametric, and\n * `x^2 + y^2 = 4` implicit.\n */\nexport type Equation =\n | { kind: \"function\"; of: \"x\" | \"y\"; f: CompiledExpression }\n | { kind: \"polar\"; f: CompiledExpression }\n | { kind: \"parametric\"; x: CompiledExpression; y: CompiledExpression }\n | { kind: \"implicit\"; f: CompiledExpression };\n\n/** The free variable each kind is sampled over, for a host's help. */\nexport const EQUATION_VARIABLES = {\n function: [\"x\"],\n polar: [\"theta\"],\n parametric: [\"t\"],\n implicit: [\"x\", \"y\"],\n} as const satisfies Record<Equation[\"kind\"], readonly string[]>;\n\n/** `source` as an {@link Equation}, or the reason it is not one. */\nexport const parseEquation = memoParse<Equation>(256, read);\n\n/** Why `source` will not plot, or `null`. Empty text is no error, and neither is an unknown name: that is a named value ({@link equationParams}). */\nexport function equationError(source: string): string | null {\n if (source.trim() === \"\") return null;\n const equation = parseEquation(source, equationParams(source));\n return equation instanceof Error ? equation.message : null;\n}\n\n/** A name that is always a variable of some kind of equation, so never a named value. */\nconst VARIABLE_NAMES: ReadonlySet<string> = new Set([\"r\", ...Object.values(EQUATION_VARIABLES).flat()]);\n\nconst named = createBoundedCache<readonly string[]>(256);\n\n/** Every name `source` reads, in the order first named, variables included; empty for text that does not parse. */\nexport function equationNames(source: string): readonly string[] {\n const hit = named.get(source);\n if (hit !== undefined) return hit;\n const names = new Set<string>();\n const text = source.trim();\n try {\n for (const part of splitTuple(text) ?? splitTopLevel(text, \"=\")) {\n collectNames(expressionOps.parse(part.trim(), MATH_DIALECT).root, names);\n }\n } catch {\n names.clear();\n }\n const result = [...names];\n named.set(source, result);\n return result;\n}\n\n/** The named values `source` reads: every name that is not a variable, function or constant. */\nexport function equationParams(source: string): readonly string[] {\n return equationNames(source).filter((name) => !VARIABLE_NAMES.has(name));\n}\n\nfunction collectNames(node: ExpressionNode, into: Set<string>): void {\n switch (node.kind) {\n case \"ref\":\n into.add(node.name);\n return;\n case \"unary\":\n collectNames(node.operand, into);\n return;\n case \"binary\":\n collectNames(node.left, into);\n collectNames(node.right, into);\n return;\n case \"call\":\n for (const arg of node.args) collectNames(arg, into);\n return;\n default:\n }\n}\n\nfunction read(source: string, params: readonly string[]): Equation {\n const compile = compilerFor(params);\n\n const pair = splitTuple(source);\n if (pair?.length === 2) return { kind: \"parametric\", x: compile(pair[0], [\"t\"]), y: compile(pair[1], [\"t\"]) };\n\n const sides = splitTopLevel(source, \"=\");\n if (sides.length > 2) throw new Error(\"An equation has one '='\");\n if (sides.length === 1) return { kind: \"function\", of: \"x\", f: compile(source, [\"x\"]) };\n\n const [left, right] = sides;\n const subject = left.trim();\n const implicit = (): Equation => {\n const l = compile(left, [\"x\", \"y\"]);\n const r = compile(right, [\"x\", \"y\"]);\n return { kind: \"implicit\", f: (x, y, scope) => l(x, y, scope) - r(x, y, scope) };\n };\n if (subject === \"r\") return { kind: \"polar\", f: compile(right, [\"theta\"]) };\n if (subject === \"y\" || subject === \"x\") {\n const of = subject === \"y\" ? \"x\" : \"y\";\n // `y = x + y` names its own subject on the right, so it is not a function of one variable.\n try {\n return { kind: \"function\", of, f: compile(right, [of]) };\n } catch (error) {\n try {\n return implicit();\n } catch {\n throw error;\n }\n }\n }\n return implicit();\n}\n\n/** `(a, b, …)` as its parts, or `null` when `source` is not one parenthesised list of two or more. */\nexport function splitTuple(source: string): string[] | null {\n if (!source.startsWith(\"(\") || !source.endsWith(\")\")) return null;\n let depth = 0;\n for (let i = 0; i < source.length - 1; i++) {\n if (source[i] === \"(\") depth++;\n else if (source[i] === \")\" && --depth === 0) return null;\n }\n const parts = splitTopLevel(source.slice(1, -1), \",\");\n return parts.length >= 2 ? parts : null;\n}\n\nexport function splitTopLevel(source: string, separator: string): string[] {\n const parts: string[] = [];\n let depth = 0;\n let from = 0;\n for (let i = 0; i < source.length; i++) {\n const c = source[i];\n if (c === \"(\") depth++;\n else if (c === \")\") depth--;\n else if (c === separator && depth === 0) {\n parts.push(source.slice(from, i));\n from = i + 1;\n }\n }\n parts.push(source.slice(from));\n return parts;\n}\n", "import type { Interval } from \"./coords\";\nimport type { ExpressionScope } from \"./expression\";\n\n/** What a plot's equation, domain and named values are held as, and how each tweens: shared by every plot, 2D and 3D. */\n\n/** An equation on its way to another: both are drawn, `t` of the way across. */\nexport interface PlotSource {\n source: string;\n blend?: { from: string; t: number };\n}\n\nexport function readSource(value: string | PlotSource | undefined): PlotSource {\n if (typeof value === \"string\") return { source: value };\n return value ?? { source: \"\" };\n}\n\n// Mid-tween the prop holds both equations, so a seek restores the blend with it.\nexport function lerpSource(from: PlotSource, to: PlotSource, t: number): PlotSource {\n if (t <= 0 || from.source === to.source) return t <= 0 ? from : to;\n return t >= 1 ? to : { source: to.source, blend: { from: from.source, t } };\n}\n\nexport function lerpDomain(from: Interval | null, to: Interval | null, t: number): Interval | null {\n if (!from || !to) return t < 1 ? from : to;\n return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];\n}\n\n/** What a named value is until it is given one. */\nexport const UNSET_PARAM = 1;\n\nexport function lerpParams(from: ExpressionScope, to: ExpressionScope, t: number): ExpressionScope {\n const out: Record<string, number> = { ...from };\n for (const [name, value] of Object.entries(to)) {\n const start = from[name] ?? UNSET_PARAM;\n out[name] = start + (value - start) * t;\n }\n return out;\n}\n\n/** `params` with every name of `names` given a value, so one nobody has set yet still draws. */\nexport function scopeFor(names: readonly string[], params: ExpressionScope): ExpressionScope {\n let filled: Record<string, number> | null = null;\n for (const name of names) {\n if (typeof params[name] !== \"number\") (filled ??= { ...params })[name] = UNSET_PARAM;\n }\n return filled ?? params;\n}\n\n/** A string as a number that changes when it does: what a geometry's `revision` wants. */\nexport function revisionOf(key: string): number {\n let hash = 0x811c9dc5;\n for (let i = 0; i < key.length; i++) {\n hash ^= key.charCodeAt(i);\n hash = Math.imul(hash, 0x01000193);\n }\n return hash >>> 0;\n}\n", "import type { NodeView } from \"@motionscript/sdk\";\nimport { equationParams, parseEquation } from \"./equation\";\nimport type { ExpressionScope } from \"./expression\";\nimport { scopeFor, type PlotSource } from \"./source\";\n\n/** A curve as a mark reads it. Data rather than a class, so a copied plot is ridden like the kit's own. */\nexport interface CurveValues {\n readonly expression: PlotSource;\n readonly params: ExpressionScope;\n readonly x: number;\n readonly y: number;\n /** The plane the plot was laid out on; `null` outside any system. */\n readonly graph?: object | null;\n}\n\n/** The node types a point, a tangent or an area can ride: they have a height at each `x`. */\nexport const CURVE_KEYS: readonly string[] = [\"functionPlot\", \"tracedPath\"];\n\n/**\n * The curve's height at graph `x`, or `NaN` where it has none or is not a\n * function of `x`. What a point, a tangent or an area riding a plot reads.\n */\nexport function curveValue(curve: CurveValues, x: number): number {\n const { source, blend } = curve.expression;\n const shift = curve.graph ? curve : NO_SHIFT;\n const value = heightOf(source, curve.params, x - shift.x) + shift.y;\n if (!blend) return value;\n const from = heightOf(blend.from, curve.params, x - shift.x) + shift.y;\n return from + (value - from) * blend.t;\n}\n\n/** Whether `view` is a node a mark can ride. */\nexport function isCurve(view: unknown): view is NodeView & { readonly state: CurveValues } {\n return typeof view === \"object\" && view !== null && CURVE_KEYS.includes((view as { key?: string }).key ?? \"\");\n}\n\nconst NO_SHIFT = { x: 0, y: 0 };\n\nfunction heightOf(source: string, params: ExpressionScope, x: number): number {\n const equation = parseEquation(source, equationParams(source));\n if (equation instanceof Error || equation.kind !== \"function\" || equation.of !== \"x\") return NaN;\n return equation.f(x, 0, scopeFor(equationParams(source), params));\n}\n", "import {\n createContext,\n Types,\n type ChildView,\n type EntryOptions,\n type NodeView,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Context as _Context,\n} from \"@motionscript/sdk\";\nimport { PIXEL_MAP, type CoordinateMap } from \"./coords\";\nimport { CURVE_KEYS, isCurve, type CurveValues } from \"./curve\";\n\n/**\n * What a coordinate system hands the plots and marks inside it: the map it was\n * last laid out on, the curves it holds by id, and, under a plot, that plot.\n * Inherited once, so it is a live object the system's layout keeps current.\n */\nexport interface GraphPlane {\n readonly map: CoordinateMap;\n readonly curves: ReadonlyMap<string, CurveValues>;\n /** The curve a mark rides when it names none: the plot it sits in. */\n readonly enclosing: CurveValues | null;\n}\n\n/** The plane of the nearest coordinate system: what a plot is laid out on. */\nexport const SYSTEM = createContext<GraphPlane | null>(null, \"mathSystem\");\n/** The plane under a plot: the system's, riding that plot. */\nexport const PLOT = createContext<GraphPlane | null>(null, \"mathPlot\");\n\ntype Inherited = { readonly private: true };\n\n/** A plot's plane: the system it sits in, `null` outside one. */\nexport const SYSTEM_ENTRY = Types.custom<GraphPlane | null, GraphPlane | null, Inherited>(null, {\n private: true,\n inherit: (use) => use(SYSTEM),\n});\n\n/** A mark's plane: the plot or the system that lays it out, `null` outside both. */\nexport const PLANE_ENTRY = Types.custom<GraphPlane | null, GraphPlane | null, Inherited>(null, {\n private: true,\n inherit: (use) => use(PLOT) ?? use(SYSTEM),\n});\n\n/** A reference to the plot a mark reads, by id: a host offers the plots. */\nexport const PLOT_REF = Types.custom<string, NodeView | null, EntryOptions & { readonly nodeTypes: readonly string[] }>(\"\", { kind: \"nodeRef\", nodeTypes: [\"functionPlot\"], animatable: false });\n\nconst NO_CURVES: ReadonlyMap<string, CurveValues> = new Map();\n\nclass SystemPlane implements GraphPlane {\n map: CoordinateMap = PIXEL_MAP;\n curves: ReadonlyMap<string, CurveValues> = NO_CURVES;\n readonly enclosing = null;\n}\n\nclass PlotPlane implements GraphPlane {\n constructor(readonly parent: GraphPlane | null, readonly enclosing: CurveValues) { }\n\n get map(): CoordinateMap {\n return this.parent?.map ?? PIXEL_MAP;\n }\n\n get curves(): ReadonlyMap<string, CurveValues> {\n return this.parent?.curves ?? NO_CURVES;\n }\n}\n\nconst systems = new WeakMap<object, SystemPlane>();\nconst plots = new WeakMap<object, PlotPlane>();\n\n/** The plane a system provides, one per system: its `layout` writes the map and the curves into it. */\nexport function systemPlane(state: object): SystemPlane {\n let plane = systems.get(state);\n if (!plane) systems.set(state, (plane = new SystemPlane()));\n return plane;\n}\n\n/** Lay `plane` out on `map`, holding the curves among `children`. */\nexport function settle(plane: SystemPlane, map: CoordinateMap, children: readonly ChildView[]): void {\n plane.map = map;\n const curves = new Map<string, CurveValues>();\n collectCurves(children, curves);\n plane.curves = curves;\n}\n\n/** The plane a plot provides the marks inside it, one per plot and system. */\nexport function plotPlane(plot: CurveValues, parent: GraphPlane | null): GraphPlane {\n let plane = plots.get(plot);\n if (!plane || plane.parent !== parent) plots.set(plot, (plane = new PlotPlane(parent, plot)));\n return plane;\n}\n\n/**\n * The curve a mark reads: the one `on` names in its system, or, naming none or\n * one the system does not hold, the plot it sits in. `on` as the mark's own\n * fields read a reference (a view) or its holder's layout does (an id). Outside\n * any system a named curve is read wherever it is.\n */\nexport function curveFor(plane: GraphPlane | null, on: unknown, enclosing = true): CurveValues | null {\n if (!plane) return isCurve(on) ? on.state : null;\n const id = refId(on);\n return (id === \"\" ? undefined : plane.curves.get(id)) ?? (enclosing ? plane.enclosing : null);\n}\n\n/** The id a reference holds, read as an id or as a view of the node. */\nexport function refId(on: unknown): string {\n if (typeof on === \"string\") return on;\n if (typeof on === \"object\" && on !== null && typeof (on as { id?: unknown }).id === \"string\") return (on as { id: string }).id;\n return \"\";\n}\n\nfunction collectCurves(children: readonly ChildView[], into: Map<string, CurveValues>): void {\n for (const child of children) {\n if (child.id !== \"\" && CURVE_KEYS.includes(child.key)) into.set(child.id, child.state as unknown as CurveValues);\n collectCurves(child.children, into);\n }\n}\n", "import type { Extents, PathCommand, Vector2 } from \"@motionscript/sdk\";\n\n/**\n * Runs of pixel points as path commands. Commands are y-up like every other\n * `Graphics2D` op (only an SVG `d` string is y-down), so nothing is flipped here.\n */\nexport function runsToPath(runs: readonly (readonly Vector2[])[], closed = false): PathCommand[] {\n const out: PathCommand[] = [];\n for (const run of runs) {\n if (run.length < 2) continue;\n out.push({ type: \"M\", x: run[0].x, y: run[0].y });\n for (let i = 1; i < run.length; i++) out.push({ type: \"L\", x: run[i].x, y: run[i].y });\n if (closed) out.push({ type: \"Z\" });\n }\n return out;\n}\n\nexport function boundsOfRuns(runs: readonly (readonly Vector2[])[]): Extents | null {\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const run of runs) {\n if (run.length < 2) continue;\n for (const p of run) {\n if (p.x < minX) minX = p.x;\n if (p.x > maxX) maxX = p.x;\n if (p.y < minY) minY = p.y;\n if (p.y > maxY) maxY = p.y;\n }\n }\n return minX <= maxX ? { minX, minY, maxX, maxY } : null;\n}\n\n/** `area` grown by `margin` on every side. */\nexport function inflate(area: Extents, margin: number): Extents {\n return { minX: area.minX - margin, minY: area.minY - margin, maxX: area.maxX + margin, maxY: area.maxY + margin };\n}\n\nexport function radians(degrees: number): number {\n return (degrees * Math.PI) / 180;\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return value < min ? min : value > max ? max : value;\n}\n\n/** `data` without the arguments a command was not given, which arrive as `undefined` and are not destinations. */\nexport function stated<T extends object>(data: T | undefined): Partial<T> {\n const out: Partial<T> = {};\n if (!data) return out;\n for (const key of Object.keys(data) as (keyof T)[]) {\n if (data[key] !== undefined) out[key] = data[key];\n }\n return out;\n}\n", "import {\n Graphics2D,\n type ChildView,\n type Extents,\n type Fill,\n type RenderContext,\n type Shadow,\n type Size2D,\n type Stroke,\n type StrokeResolved,\n type Vector2,\n} from \"@motionscript/sdk\";\nimport { painted } from \"./component\";\nimport { PIXEL_MAP, type CoordinateMap } from \"./coords\";\nimport { boundsOfRuns, runsToPath } from \"./geometry\";\nimport type { GraphPlane } from \"./graph\";\n\n/**\n * What a mark is traced through: the map, its own `x`/`y` as a shift, and the\n * plane it reads curves from. A mark is a shape whose box is the tight box of its\n * ink; outside a system a graph unit is a pixel and `x`/`y` the usual offset.\n */\nexport interface MarkReading {\n readonly map: CoordinateMap;\n /** Zero outside a system, where `x`/`y` are pixels. */\n readonly shift: Vector2;\n readonly plane: GraphPlane | null;\n}\n\n/** The runs a mark draws, in pixels, y-up from the system's centre. */\nexport type Tracer<V> = (state: V, read: MarkReading) => Vector2[][];\n\n/** What every mark's state reads: its place, and the plane it is laid out on. */\nexport interface MarkState {\n readonly x: number;\n readonly y: number;\n readonly graph: GraphPlane | null;\n}\n\nconst NO_SHIFT: Vector2 = { x: 0, y: 0 };\n\nconst tracers: { readonly is: (child: ChildView) => boolean; readonly trace: Tracer<never> }[] = [];\n\n/** `component`, declared a mark: a holder lays it out on the ink `trace` draws. Hand back the component. */\nexport function traced<C extends { is(child: ChildView): boolean }>(component: C, trace: Tracer<never>): C {\n tracers.push({ is: (child) => component.is(child), trace });\n return component;\n}\n\n/** The runs `child` draws on `plane`, or `undefined` for a child that is no mark. */\nexport function markRuns(child: ChildView, map: CoordinateMap, plane: GraphPlane): Vector2[][] | undefined {\n const mark = tracers.find((entry) => entry.is(child));\n if (!mark) return undefined;\n const state = child.state as unknown as MarkState;\n return (mark.trace as Tracer<MarkState>)(state, { map, shift: { x: state.x, y: state.y }, plane });\n}\n\n/** How a mark's own fields read it: through its plane's map when one lays it out, through pixels when none does. */\nexport function reading(state: MarkState): MarkReading {\n const plane = state.graph;\n return plane ? { map: plane.map, shift: { x: state.x, y: state.y }, plane } : { map: PIXEL_MAP, shift: NO_SHIFT, plane: null };\n}\n\n/** The size of a mark's ink: its box when a node other than a system lays it out. */\nexport function inkSize(runs: readonly (readonly Vector2[])[]): Size2D {\n const ink = boundsOfRuns(runs);\n return ink ? { width: ink.maxX - ink.minX, height: ink.maxY - ink.minY } : { width: 0, height: 0 };\n}\n\n/** The centre of `runs`' ink in the map's pixels: where a mark's children are placed from. */\nexport function inkCentre(runs: readonly (readonly Vector2[])[]): Vector2 {\n const ink = boundsOfRuns(runs);\n return ink ? { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2 } : NO_SHIFT;\n}\n\n/** A graph point in a mark's own frame, where a handle on it sits. */\nexport function ownPoint(read: MarkReading, runs: readonly (readonly Vector2[])[], point: Vector2): Vector2 {\n const at = read.map.toPoint(point.x + read.shift.x, point.y + read.shift.y);\n const centre = inkCentre(runs);\n return { x: at.x - centre.x, y: at.y - centre.y };\n}\n\n/** The graph point at `at` in a mark's own frame: {@link ownPoint} undone. */\nexport function graphPoint(read: MarkReading, runs: readonly (readonly Vector2[])[], at: Vector2): Vector2 {\n const centre = inkCentre(runs);\n const point = read.map.toCoords(at.x + centre.x, at.y + centre.y);\n return { x: point.x - read.shift.x, y: point.y - read.shift.y };\n}\n\n/** What a mark paints with. */\nexport interface MarkPaint {\n readonly fill?: Fill;\n readonly stroke?: Stroke;\n readonly shadow: Shadow;\n readonly start?: number;\n readonly end?: number;\n}\n\nexport interface MarkOptions {\n /** Whether each run is closed into an outline. */\n readonly closed?: boolean;\n /** Whether the fill is painted: a mark whose ink has no inside yet (an open line) says no. */\n readonly fills?: boolean;\n /** The stroke along the ink, when it is not the plain one. */\n readonly ink?: (ctx: RenderContext, ink: Extents) => void;\n}\n\nconst NONE: never[] = [];\n\n/** One mark's outline, the same commands for each paint. */\nexport function markShape(runs: readonly (readonly Vector2[])[], s: MarkPaint, closed = false): (() => Graphics2D) | null {\n const ink = boundsOfRuns(runs);\n const data = runsToPath(runs, closed);\n if (!ink || data.length === 0) return null;\n const centerBounds: [number, number, number, number] = [ink.minX, ink.minY, ink.maxX, ink.maxY];\n return () => new Graphics2D().path({ data, centerBounds, start: s.start ?? 0, end: s.end ?? 1 });\n}\n\n/**\n * A mark's paint: the fill under the stroke along its ink, both before its\n * children, so a point or a tangent riding a plot sits on the curve.\n */\nexport function drawMark(ctx: RenderContext, s: MarkPaint, runs: readonly (readonly Vector2[])[], options: MarkOptions = {}): void {\n const shape = markShape(runs, s, options.closed);\n const fill = s.fill ?? NONE;\n painted(ctx, () => {\n if (shape && options.fills !== false) ctx.draw(shape().shadow(s.shadow).fill(fill));\n const ink = options.ink ? boundsOfRuns(runs) : null;\n if (ink && options.ink) options.ink(ctx, ink);\n else if (shape) strokeShape(ctx, shape, s);\n });\n}\n\n/** The stroke along a shape, casting the shadow when nothing fills it. */\nexport function strokeShape(ctx: RenderContext, shape: () => Graphics2D, s: MarkPaint): void {\n const stroke = (s.stroke ?? NONE) as StrokeResolved[];\n if (stroke.length === 0) return;\n ctx.draw(castsShadow(s) ? shape().shadow(s.shadow).stroke(stroke) : shape().stroke(stroke));\n}\n\n/** A shadow is cast by the stroke when nothing visible fills the shape. */\nexport function castsShadow(s: MarkPaint): boolean {\n if ((s.shadow as unknown[]).length === 0) return false;\n return !((s.fill ?? NONE) as { opacity?: number }[]).some((layer) => (layer.opacity ?? 1) > 0);\n}\n", "import type { ChildPlane, ChildView, Placement2D, Size2D, Vector2 } from \"@motionscript/sdk\";\nimport type { CoordinateMap } from \"./coords\";\nimport { boundsOfRuns } from \"./geometry\";\nimport type { GraphPlane } from \"./graph\";\nimport { markRuns } from \"./mark\";\n\n/** Where a child that sits somewhere other than its own `x`/`y` is (a point riding a curve), given its own `x`/`y`. */\nexport type Anchor = (x: number, y: number) => Vector2;\n\nconst anchors: { readonly is: (child: ChildView) => boolean; readonly anchor: (state: never, plane: GraphPlane) => Anchor | null }[] = [];\n\n/** `component`, declared to sit at `anchor` of its own `x`/`y` on a graph. Hand back the component. */\nexport function anchored<C extends { is(child: ChildView): boolean }>(component: C, anchor: (state: never, plane: GraphPlane) => Anchor | null): C {\n anchors.push({ is: (child) => component.is(child), anchor });\n return component;\n}\n\n/**\n * Lay `children` out on `map` for a system or a plot: a mark goes on its ink,\n * anything else keeps its size and reads `x`/`y` as graph coordinates.\n * `origin` is the holder's centre in the map's pixels (y-up).\n */\nexport function placeOnMap(children: readonly ChildView[], map: CoordinateMap, origin: Vector2, room: Size2D, plane: GraphPlane): Placement2D[] {\n return children.map((child) => {\n const runs = markRuns(child, map, plane);\n if (runs) {\n const ink = boundsOfRuns(runs);\n const cx = ink ? (ink.minX + ink.maxX) / 2 : origin.x;\n const cy = ink ? (ink.minY + ink.maxY) / 2 : origin.y;\n return {\n x: cx - origin.x,\n y: cy - origin.y,\n width: ink ? ink.maxX - ink.minX : 0,\n height: ink ? ink.maxY - ink.minY : 0,\n plane: markPlane(map, cx, cy),\n };\n }\n const size = child.measure({ width: room.width, height: room.height });\n const entry = anchors.find((a) => a.is(child));\n const anchor = entry ? (entry.anchor as (state: unknown, plane: GraphPlane) => Anchor | null)(child.state, plane) : null;\n // Its box is centred on the map's own centre, so its offset from there is its point.\n return { x: -origin.x, y: -origin.y, width: size.width, height: size.height, plane: pointPlane(map, anchor) };\n });\n}\n\n/** The plane of a child that is not there yet, under a holder centred on `origin`: where a host would drop one. */\nexport function openPlane(map: CoordinateMap, origin: Vector2): ChildPlane {\n return {\n toOffset: (x, y) => {\n const at = map.toPoint(x, y);\n return { x: at.x - origin.x, y: at.y - origin.y };\n },\n toCoords: (x, y) => map.toCoords(x + origin.x, y + origin.y),\n };\n}\n\nfunction pointPlane(map: CoordinateMap, anchor: Anchor | null): ChildPlane {\n const point: Vector2 = { x: 0, y: 0 };\n return {\n toOffset: (x, y) => {\n const at = anchor?.(x, y);\n return at ? map.toPoint(at.x, at.y, point) : map.toPoint(x, y, point);\n },\n toCoords: (x, y) => map.toCoords(x, y),\n };\n}\n\n// A mark reads its own `x`/`y` as it draws, so its holder adds nothing; a drag still answers in graph units.\nfunction markPlane(map: CoordinateMap, cx: number, cy: number): ChildPlane {\n const none: Vector2 = { x: 0, y: 0 };\n return {\n toOffset: () => none,\n toCoords: (x, y) => map.toCoords(cx + x, cy + y),\n };\n}\n", "import {\n Graphics2D,\n insetsOps,\n Paint,\n provides,\n type ChildPlane,\n type ChildView,\n type Extents,\n type InsetsResolved,\n type Placement2D,\n type Provided,\n type RenderContext,\n type Shadow,\n type Fill,\n type Size2D,\n type Vector2,\n} from \"@motionscript/sdk\";\nimport type { CoordinateMap } from \"./coords\";\nimport { settle, SYSTEM, systemPlane } from \"./graph\";\nimport { openPlane, placeOnMap } from \"./place\";\n\n// A child's `x`/`y` are in the system's units and it keeps its own size; a mark is drawn through the map and laid out on its ink.\n// The `stroke` is the axis line (`endCap` is its tip), the `fill` the backdrop. Ticks, grid and labels are drawing ops, never\n// child nodes: they would share their indices with a document's children.\nconst CENTRE: Vector2 = { x: 0, y: 0 };\n\nexport interface SystemState {\n readonly padding: InsetsResolved;\n readonly fill: Fill;\n readonly shadow: Shadow;\n readonly clip: boolean;\n}\n\n/** How a system's graph values land on its plot area. */\nexport type MapFor<S> = (area: Extents, state: S) => CoordinateMap;\n\n/** The plot area: the box less its padding, y-up from the box's centre. */\nexport function plotArea(size: Size2D, padding: InsetsResolved): Extents {\n const inner = insetsOps.insetBounds(size.width, size.height, padding);\n return {\n minX: inner.x - inner.width / 2,\n maxX: inner.x + inner.width / 2,\n minY: -inner.y - inner.height / 2,\n maxY: -inner.y + inner.height / 2,\n };\n}\n\n/** A system's map at a laid-out `size`. */\nexport function systemMap<S extends SystemState>(size: Size2D, state: S, mapFor: MapFor<S>): CoordinateMap {\n return mapFor(plotArea(size, state.padding), state);\n}\n\n/** A system is the size it is given: its children are placed in it, not measured into it. */\nexport function systemSize(state: SystemState): Size2D {\n const { left, right, top, bottom } = state.padding;\n return { width: left + right, height: top + bottom };\n}\n\n/** What a system hands its subtree: its plane, which its layout keeps current. */\nexport function systemProvides(state: object): readonly Provided[] {\n return [provides(SYSTEM, systemPlane(state))];\n}\n\n/** Lay a system's children out on its map. */\nexport function systemLayout<S extends SystemState>(size: Size2D, state: S, children: readonly ChildView[], mapFor: MapFor<S>): Placement2D[] {\n const map = systemMap(size, state, mapFor);\n const plane = systemPlane(state);\n settle(plane, map, children);\n const inner = insetsOps.insetBounds(size.width, size.height, state.padding);\n return placeOnMap(children, map, CENTRE, inner, plane);\n}\n\n/** Where a child dropped on a system would sit. */\nexport function systemOpenPlane<S extends SystemState>(size: Size2D, state: S, mapFor: MapFor<S>): ChildPlane {\n return openPlane(systemMap(size, state, mapFor), CENTRE);\n}\n\n/**\n * A system's paint: the backdrop, then the furniture under its children, kept\n * in the plot area where the map spills from it, then the children, confined\n * to the plot area when `clip` is set. The stroke is the axis line, drawn with\n * the furniture: painted after the children it would land over them.\n */\nexport function drawSystem(ctx: RenderContext, state: SystemState, map: CoordinateMap, furniture: (map: CoordinateMap) => Graphics2D[]): void {\n const { width, height } = ctx.size;\n const { minX, minY, maxX, maxY } = map.area;\n const area = new Graphics2D().rect({ x: (minX + maxX) / 2, y: (minY + maxY) / 2, width: maxX - minX, height: maxY - minY });\n ctx.inFront(() => {\n ctx.draw(new Graphics2D().rect({ x: 0, y: 0, width, height }).shadow(state.shadow).fill(state.fill));\n const parts = furniture(map);\n if (map.spills) ctx.clip(area, () => ctx.draw(parts));\n else ctx.draw(parts);\n });\n // No shape of its own to paint here; the plot area is what clips the children and what picking tests.\n Paint.draw(ctx, state as unknown as Paint.PaintState, null, { clipShape: area });\n}\n", "import { niceStep } from \"@motionscript/sdk/component\";\nimport type { AxisScaling, Interval } from \"./coords\";\n\n/** Where an axis is marked, and the spacing its labels are rounded to. */\nexport interface Ticks {\n values: number[];\n step: number;\n}\n\n/** Past this an axis is not marked at all, rather than drawn as a solid bar of ticks. */\nconst MAX_TICKS = 200;\n\n/** How far apart, in pixels, marks sit when the axis picks its own step. */\nconst AUTO_SPACING = 64;\n\n/**\n * The marks along `range`, drawn over `length` pixels. A `step` of zero lets the\n * axis choose a tidy one (1, 2 or 5 times a power of ten) for its size; a log\n * axis is marked at the powers of ten whatever the step.\n */\nexport function ticksFor(range: Interval, step: number, length: number, scaling: AxisScaling = \"linear\"): Ticks {\n const [min, max] = range;\n if (scaling === \"log\") return decades(min, max);\n const span = max - min;\n if (!(span > 0)) return { values: [], step: 1 };\n const chosen = step > 0 ? step : niceStep((AUTO_SPACING / Math.max(1, length)) * span);\n return { values: multiplesWithin(min, max, chosen), step: chosen };\n}\n\nfunction decades(min: number, max: number): Ticks {\n const values: number[] = [];\n for (let k = Math.ceil(Math.log10(min) - 1e-9); k <= Math.floor(Math.log10(max) + 1e-9) && values.length < MAX_TICKS; k++) {\n values.push(10 ** k);\n }\n return { values, step: 0 };\n}\n\nfunction multiplesWithin(min: number, max: number, step: number): number[] {\n const first = Math.ceil(min / step - 1e-9);\n const last = Math.floor(max / step + 1e-9);\n const count = last - first + 1;\n if (!Number.isFinite(count) || count <= 0 || count > MAX_TICKS) return [];\n const out = new Array<number>(count);\n // Multiplied rather than accumulated, so the tenth tick of 0.1 is 1 and not 0.9999999999999999.\n for (let i = 0; i < count; i++) out[i] = (first + i) * step;\n return out;\n}\n\nfunction decadeOf(value: number): number {\n return Math.floor(Math.log10(value) + 1e-12);\n}\n\n/**\n * `value` as a tick label, with as many decimals as `step` needs and no more:\n * 0.30000000000000004 on a 0.1 ladder is `0.3`. A `step` of zero (a log axis)\n * prints the value as it is.\n */\nexport function formatTick(value: number, step: number): string {\n if (value === 0) return \"0\";\n if (!Number.isFinite(value)) return \"\";\n if (!(step > 0)) {\n const decade = decadeOf(Math.abs(value));\n return decade >= 6 || decade <= -5 ? trimExponent(value.toExponential(0)) : String(Number(value.toPrecision(12)));\n }\n const decade = decadeOf(Math.abs(value));\n const digits = Math.max(1, decade - decadeOf(step) + 1);\n if ((decade >= 6 || decade <= -5) && digits <= 6) return trimExponent(value.toExponential(digits - 1));\n const decimals = decimalsOf(step);\n const text = value.toFixed(decimals);\n return decimals > 0 ? text.replace(/\\.?0+$/, \"\") : text;\n}\n\n/** The decimal places it takes to write `step` out: 1 for 0.5, 2 for 0.25. */\nfunction decimalsOf(step: number): number {\n for (let d = 0; d < 12; d++) {\n const scaled = step * 10 ** d;\n if (Math.abs(scaled - Math.round(scaled)) < 1e-9 * Math.max(1, scaled)) return d;\n }\n return 12;\n}\n\nfunction trimExponent(text: string): string {\n const [mantissa, exponent] = text.split(\"e\");\n return `${mantissa.replace(/\\.?0+$/, \"\")}e${Number(exponent)}`;\n}\n", "import {\n component2d,\n Graphics2D,\n Types,\n type Extents,\n type NodeOf,\n type Color as _Color,\n type NormalizedColor,\n type StrokeResolved,\n type Values,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n} from \"@motionscript/sdk\";\nimport { listed, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { cartesianMap, resolveInterval, type CoordinateMap } from \"../kit/coords\";\nimport { along, AXIS_COLOR, drawLabels, drawn, intervalEntry, withoutTips, type Label } from \"../kit/furniture\";\nimport { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\nimport { formatTick, ticksFor } from \"../kit/ticks\";\n\nconst state = {\n ...PAINT,\n range: intervalEntry([-5, 5]),\n /** The spacing of the ticks; zero picks a tidy one for the line's length. */\n step: Types.number(0, { min: 0 }),\n scaling: listed([\"linear\", \"log\"], \"linear\", { animatable: false }),\n ticks: Types.boolean(true, { animatable: false }),\n tickSize: Types.number(12, { min: 0, unit: \"px\" }),\n /** Values whose ticks are drawn twice as long. */\n longTicks: Types.custom<number[]>([], { animatable: false }),\n labels: Types.boolean(true, { animatable: false }),\n labelExclude: Types.custom<number[]>([], { animatable: false }),\n labelSide: listed([\"below\", \"above\"], \"below\", { animatable: false }),\n labelSize: Types.number(18, { min: 1, unit: \"px\" }),\n labelColor: Types.color(AXIS_COLOR),\n fontFamily: Types.text(\"\", { animatable: false }),\n};\n\ntype LineValues = Values<typeof state>;\n\n/**\n * One axis with ticks and numbers. A child's `x` is a value on the line and its\n * `y` is pixels above it, so a dot or a label sits on a number.\n */\nexport const NumberLine = component2d({\n key: \"numberLine\",\n state,\n defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\" } },\n load: (loader, s) => {\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\n },\n commands: {\n ...PAINT_COMMANDS,\n /** Animate the span of values the line shows: a pan when both ends move alike, a zoom when they do not. */\n rangeTo: { args: [\"range\"] },\n },\n provide: (s) => systemProvides(s),\n measure: (_measurer, s) => systemSize(s),\n layout: (box, s, children) => systemLayout(box, s, children, lineMap),\n plane: (box, s) => systemOpenPlane(box, s, lineMap),\n render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, lineMap), (map) => lineFurniture(map, s)),\n});\n\nexport type NumberLine = NodeOf<typeof NumberLine>;\n\nfunction lineMap(area: Extents, s: LineValues): CoordinateMap {\n return cartesianMap({\n xRange: resolveInterval(s.range, s.scaling),\n yRange: [area.minY, area.maxY],\n area,\n xScaling: s.scaling,\n });\n}\n\nfunction lineFurniture(map: CoordinateMap, s: LineValues): Graphics2D[] {\n const stroke = s.stroke as StrokeResolved[];\n const { start, end } = s;\n const [min, max] = map.xRange;\n const from = map.toPoint(min, 0);\n const to = map.toPoint(max, 0);\n const parts: Graphics2D[] = [];\n if (stroke.length > 0) parts.push(new Graphics2D().line({ points: [from, to], radius: 0, start, end }).stroke(stroke));\n\n const marks = ticksFor(map.xRange, s.step, to.x - from.x, s.scaling);\n const sign = s.labelSide === \"below\" ? -1 : 1;\n const tickMarks = new Graphics2D();\n const labels: Label[] = [];\n let ticked = false;\n for (const value of marks.values) {\n const at: Vector2 = map.toPoint(value, 0);\n if (!drawn(along(at, from, to), start, end)) continue;\n const half = s.longTicks.includes(value) ? s.tickSize : s.tickSize / 2;\n if (s.ticks && half > 0) {\n tickMarks.line({ points: [{ x: at.x, y: at.y - half }, { x: at.x, y: at.y + half }], radius: 0 });\n ticked = true;\n }\n if (s.labels && !s.labelExclude.includes(value)) {\n labels.push({\n text: formatTick(value, marks.step),\n at: { x: at.x, y: at.y + sign * (s.tickSize / 2 + s.labelSize * 0.9) },\n align: \"center\",\n });\n }\n }\n if (ticked && stroke.length > 0) parts.push(tickMarks.stroke(withoutTips(stroke)));\n parts.push(...drawLabels(labels, { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));\n return parts;\n}\n", "import {\n component2d,\n Graphics2D,\n Types,\n type Color,\n type Extents,\n type InsetsResolved,\n type Loader,\n type NodeOf,\n type NormalizedColor,\n type PaintProps,\n type StrokeResolved,\n type Values,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n} from \"@motionscript/sdk\";\nimport { listed, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { cartesianMap, lineThrough, resolveInterval, type AxisScaling, type CoordinateMap, type Interval } from \"../kit/coords\";\nimport { clamp } from \"../kit/geometry\";\nimport { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\nimport { formatTick, ticksFor, type Ticks } from \"../kit/ticks\";\nimport { along, AXIS_COLOR, drawLabels, drawn, loadFormulas, intervalEntry, type Label, withoutTips } from \"../kit/furniture\";\n\nexport interface Axes2dProps extends PaintProps {\n xRange?: Interval;\n yRange?: Interval;\n xStep?: number;\n yStep?: number;\n xScaling?: AxisScaling;\n yScaling?: AxisScaling;\n squareUnits?: boolean;\n ticks?: boolean;\n tickSize?: number;\n labels?: boolean;\n labelSize?: number;\n labelColor?: Color;\n fontFamily?: string;\n xLabel?: string;\n yLabel?: string;\n}\n\n/** One axis, as its furniture is drawn: its line's ends and what is marked along it. */\nexport interface AxisLayout {\n from: Vector2;\n to: Vector2;\n /** The pixel points that draw its line: its two ends, or more where the system's map bends it. */\n line: Vector2[];\n marks: Ticks;\n /** The value on this axis the other one crosses at, which is left unmarked. */\n crossing: number;\n /** A mark's pixel point. */\n at(value: number): Vector2;\n}\n\n/** An x and a y axis's entries: what a number plane is built on too. */\nexport const AXES = {\n ...PAINT,\n xRange: intervalEntry([-5, 5]),\n yRange: intervalEntry([-3, 3]),\n /** The spacing of each axis's ticks; zero picks a tidy one for the axis's length. */\n xStep: Types.number(0, { min: 0 }),\n yStep: Types.number(0, { min: 0 }),\n xScaling: listed([\"linear\", \"log\"], \"linear\", { animatable: false }),\n yScaling: listed([\"linear\", \"log\"], \"linear\", { animatable: false }),\n /** Give a y unit the length of an x unit: `yRange` keeps its centre and takes the span that fits. */\n squareUnits: Types.boolean(false, { animatable: false }),\n ticks: Types.boolean(true, { animatable: false }),\n tickSize: Types.number(10, { min: 0, unit: \"px\" }),\n labels: Types.boolean(true, { animatable: false }),\n labelSize: Types.number(18, { min: 1, unit: \"px\" }),\n labelColor: Types.color(AXIS_COLOR),\n fontFamily: Types.text(\"\", { animatable: false }),\n /** A title at the positive end of each axis. */\n xLabel: Types.text(\"\", { animatable: false }),\n yLabel: Types.text(\"\", { animatable: false }),\n};\n\n/** The axes' own commands, beside a shape's paints. */\nexport const AXES_COMMANDS = {\n ...PAINT_COMMANDS,\n /** Animate the window of values the axes show: a pan when a range's ends move alike, a zoom when they do not. */\n rangeTo: { args: [\"xRange\", \"yRange\"] as const },\n};\n\nexport type AxesValues = Values<typeof AXES> & { readonly padding: InsetsResolved; readonly clip: boolean };\n\n/** What axes declare before they are laid out: their face, and MathJax for a title written as a formula. */\nexport function loadAxes(loader: Loader, s: AxesValues): void {\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\n loadFormulas(loader, [s.xLabel, s.yLabel]);\n}\n\n/** How the axes' values land on a plot area. */\nexport function axesMap(area: Extents, s: AxesValues): CoordinateMap {\n const xRange = resolveInterval(s.xRange, s.xScaling);\n let yRange = resolveInterval(s.yRange, s.yScaling);\n const width = area.maxX - area.minX;\n if (s.squareUnits && s.xScaling === \"linear\" && s.yScaling === \"linear\" && width > 0) {\n const span = ((xRange[1] - xRange[0]) * (area.maxY - area.minY)) / width;\n const centre = (yRange[0] + yRange[1]) / 2;\n if (span > 0) yRange = [centre - span / 2, centre + span / 2];\n }\n return cartesianMap({ xRange, yRange, area, xScaling: s.xScaling, yScaling: s.yScaling });\n}\n\n/** The two axes as laid out on `map`: where each runs, what it marks, and where the other crosses it. */\nexport function axesOf(map: CoordinateMap, s: AxesValues): [AxisLayout, AxisLayout] {\n const [xMin, xMax] = map.xRange;\n const [yMin, yMax] = map.yRange;\n // An axis sits on the other's zero, or on its near edge when zero is out of range or it is logarithmic.\n const crossX = s.xScaling === \"log\" ? xMin : clamp(0, xMin, xMax);\n const crossY = s.yScaling === \"log\" ? yMin : clamp(0, yMin, yMax);\n const xFrom = map.toPoint(xMin, crossY);\n const xTo = map.toPoint(xMax, crossY);\n const yFrom = map.toPoint(crossX, yMin);\n const yTo = map.toPoint(crossX, yMax);\n return [\n {\n from: xFrom,\n to: xTo,\n line: lineThrough(map, xMin, crossY, xMax, crossY),\n marks: ticksFor(map.xRange, s.xStep, Math.hypot(xTo.x - xFrom.x, xTo.y - xFrom.y), s.xScaling),\n crossing: crossX,\n at: (value) => map.toPoint(value, crossY),\n },\n {\n from: yFrom,\n to: yTo,\n line: lineThrough(map, crossX, yMin, crossX, yMax),\n marks: ticksFor(map.yRange, s.yStep, Math.hypot(yTo.x - yFrom.x, yTo.y - yFrom.y), s.yScaling),\n crossing: crossY,\n at: (value) => map.toPoint(crossX, value),\n },\n ];\n}\n\n/** What the axes draw of themselves on `map`, over what `backdrop` draws behind them (a number plane's grid). */\nexport function axesFurniture(\n map: CoordinateMap,\n s: AxesValues,\n backdrop: (x: AxisLayout, y: AxisLayout) => Graphics2D[] = () => [],\n): Graphics2D[] {\n const stroke = s.stroke as StrokeResolved[];\n const { start, end } = s;\n const [x, y] = axesOf(map, s);\n const parts: Graphics2D[] = [...backdrop(x, y)];\n if (stroke.length === 0 && !s.labels) return parts;\n\n if (stroke.length > 0) {\n parts.push(\n new Graphics2D()\n .line({ points: x.line, radius: 0, start, end })\n .line({ points: y.line, radius: 0, start, end })\n .stroke(stroke),\n );\n }\n\n const half = s.tickSize / 2;\n const gap = half + s.labelSize * 0.35;\n const tickMarks = new Graphics2D();\n const labels: Label[] = [];\n let ticked = false;\n const mark = (axis: AxisLayout, horizontal: boolean): void => {\n for (const value of axis.marks.values) {\n if (Math.abs(value - axis.crossing) < 1e-9 * Math.max(1, Math.abs(value))) continue;\n const at = axis.at(value);\n if (!drawn(along(at, axis.from, axis.to), start, end)) continue;\n if (s.ticks && half > 0) {\n tickMarks.line({\n points: horizontal\n ? [{ x: at.x, y: at.y - half }, { x: at.x, y: at.y + half }]\n : [{ x: at.x - half, y: at.y }, { x: at.x + half, y: at.y }],\n radius: 0,\n });\n ticked = true;\n }\n if (!s.labels) continue;\n labels.push(\n horizontal\n ? { text: formatTick(value, axis.marks.step), at: { x: at.x, y: at.y - gap - s.labelSize / 2 }, align: \"center\" }\n : { text: formatTick(value, axis.marks.step), at: { x: at.x - gap, y: at.y }, align: \"right\" },\n );\n }\n };\n mark(x, true);\n mark(y, false);\n if (ticked && stroke.length > 0) parts.push(tickMarks.stroke(withoutTips(stroke)));\n\n if (s.xLabel !== \"\" && end >= 1) {\n labels.push({ text: s.xLabel, at: { x: x.to.x, y: x.to.y + gap + s.labelSize / 2 }, align: \"right\" });\n }\n if (s.yLabel !== \"\" && end >= 1) {\n labels.push({ text: s.yLabel, at: { x: y.to.x + gap, y: y.to.y - s.labelSize / 2 }, align: \"left\" });\n }\n parts.push(...drawLabels(labels, { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));\n return parts;\n}\n\n/**\n * An x and a y axis, crossing at the origin while it is in range and at the\n * nearest edge otherwise. Children sit in its graph coordinates.\n */\nexport const Axes2d = component2d({\n key: \"axes2d\",\n state: AXES,\n defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\", endCap: \"triangle\", capScale: 5 } },\n load: (loader, s) => loadAxes(loader, s),\n commands: AXES_COMMANDS,\n provide: (s) => systemProvides(s),\n measure: (_measurer, s) => systemSize(s),\n layout: (box, s, children) => systemLayout(box, s, children, axesMap),\n plane: (box, s) => systemOpenPlane(box, s, axesMap),\n render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, axesMap), (map) => axesFurniture(map, s)),\n});\n\nexport type Axes2d = NodeOf<typeof Axes2d>;\n", "import { memoParse } from \"./cache\";\nimport { equationNames, splitTuple } from \"./equation\";\nimport { compilerFor, type CompiledExpression } from \"./expression\";\n\n/** A vector at every point of the plane, two parts in `x` and `y`: `(-y, x)`. A warp is written the same way. */\nexport interface FieldEquation {\n x: CompiledExpression;\n y: CompiledExpression;\n}\n\nexport const FIELD_VARIABLES = [\"x\", \"y\"] as const;\n\nconst NAMES: ReadonlySet<string> = new Set(FIELD_VARIABLES);\n\n/** The named values a field's equation reads: every name that is not `x` or `y`. */\nexport function fieldParams(source: string): readonly string[] {\n return equationNames(source).filter((name) => !NAMES.has(name));\n}\n\n/** `source` as a field, or the reason it is not one. */\nexport const parseField = memoParse<FieldEquation>(128, (text, params) => {\n const parts = splitTuple(text);\n if (parts?.length !== 2) throw new Error(\"A field has two parts: (x, y)\");\n const compile = compilerFor(params);\n const [x, y] = parts.map((part) => compile(part, FIELD_VARIABLES));\n return { x, y };\n});\n\n/** Why `source` is not a field, or `null`; empty text is not an error. */\nexport function fieldError(source: string): string | null {\n if (source.trim() === \"\") return null;\n const field = parseField(source, fieldParams(source));\n return field instanceof Error ? field.message : null;\n}\n", "import {\n component2d,\n Graphics2D,\n Types,\n type Extents,\n type NodeOf,\n type Stroke as _Stroke,\n\n type StrokeResolved,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Color as _Color,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type NormalizedColor as _NormalizedColor,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n} from \"@motionscript/sdk\";\nimport {\n isIdentityMatrix,\n lerpMatrix,\n lineThrough,\n readMatrix,\n transformedMap,\n warpedMap,\n type CoordinateMap,\n type Matrix2,\n type Warp,\n} from \"../kit/coords\";\nimport { fieldParams, parseField } from \"../kit/field\";\nimport { AXIS_COLOR } from \"../kit/furniture\";\nimport { lerpSource, readSource, type PlotSource } from \"../kit/source\";\nimport { drawSystem, plotArea, systemLayout, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\nimport { AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes, type AxesValues, type AxisLayout } from \"./axes2d\";\n\nconst state = {\n ...AXES,\n grid: Types.boolean(true, { animatable: false }),\n /** The line at every tick. */\n gridStroke: Types.stroke({ weight: 1.5, fill: \"#3b4658\", align: \"center\" }),\n /** The lines between ticks. */\n minorStroke: Types.stroke({ weight: 1, fill: \"#232b38\", align: \"center\" }),\n /** How many parts the space between two ticks is cut into; one draws no line between them. */\n minorDivisions: Types.number(2, { min: 1, max: 10, step: 1 }),\n /** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\n matrix: Types.custom<Matrix2 | readonly (readonly number[])[], Matrix2>([1, 0, 0, 1], { resolve: readMatrix, lerp: lerpMatrix }),\n /**\n * Where each point of the plane is sent, two parts in x and y:\n * `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.\n */\n warp: Types.custom<string | PlotSource, PlotSource>(\"\", { resolve: readSource, lerp: lerpSource, kind: \"fieldEquation\" }),\n /** Leave the plane as it was, faintly, behind one that has been transformed or warped. */\n ghost: Types.boolean(true, { animatable: false }),\n};\n\ntype PlaneValues = AxesValues & {\n readonly grid: boolean;\n readonly gridStroke: StrokeResolved[];\n readonly minorStroke: StrokeResolved[];\n readonly minorDivisions: number;\n readonly matrix: Matrix2;\n readonly warp: PlotSource;\n readonly ghost: boolean;\n};\n\n/** Axes over a full grid with square units: the plane vectors and transformations are drawn on. `matrix` and `warp` move the grid, the axes and everything on the plane. */\nexport const NumberPlane = component2d({\n key: \"numberPlane\",\n state,\n defaults: {\n squareUnits: true,\n stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\" },\n // A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.\n clip: (s) => spills(s),\n },\n load: (loader, s) => loadAxes(loader, s),\n commands: {\n ...AXES_COMMANDS,\n /** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */\n transformTo: { args: [\"matrix\"] },\n /** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */\n warpTo: { args: [\"warp\"] },\n },\n provide: (s) => systemProvides(s),\n measure: (_measurer, s) => systemSize(s),\n layout: (box, s, children) => systemLayout(box, s, children, planeMap),\n plane: (box, s) => systemOpenPlane(box, s, planeMap),\n render: (ctx, s) => {\n const { flat, map } = planeMaps(plotArea(ctx.size, s.padding), s);\n drawSystem(ctx, s, map, (on) => axesFurniture(on, s, (x, y) => grid(s, flat, on, x, y)));\n },\n});\n\nexport type NumberPlane = NodeOf<typeof NumberPlane>;\n\n/** The plane's map on a plot area: the flat one, sent through its matrix and its warp. */\nexport function planeMap(area: Extents, s: PlaneValues): CoordinateMap {\n return planeMaps(area, s).map;\n}\n\n/** The flat plane on a plot area, and the plane as its matrix and its warp have it. */\nfunction planeMaps(area: Extents, s: PlaneValues): { flat: CoordinateMap; map: CoordinateMap } {\n const flat = axesMap(area, s);\n const map = isIdentityMatrix(s.matrix) ? flat : transformedMap(flat, s.matrix);\n const { source, blend } = s.warp;\n const to = warpOf(source);\n if (!blend) return { flat, map: to ? warpedMap(map, to, source) : map };\n // Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.\n const from = warpOf(blend.from);\n if (!from && !to) return { flat, map };\n const start = { x: 0, y: 0 };\n return {\n flat,\n map: warpedMap(\n map,\n (x, y, out) => {\n if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out)) return false;\n out.x = start.x + (out.x - start.x) * blend.t;\n out.y = start.y + (out.y - start.y) * blend.t;\n return true;\n },\n `${blend.from}>${source}@${blend.t}`,\n ),\n };\n}\n\n/** Whether the plane reaches past its box: it is transformed or warped. */\nfunction spills(s: PlaneValues): boolean {\n if (!isIdentityMatrix(s.matrix)) return true;\n const { source, blend } = s.warp;\n return warpOf(source) !== null || (blend !== undefined && warpOf(blend.from) !== null);\n}\n\n/** The grid behind the axes, with the flat plane faintly behind a transformed one. */\nfunction grid(s: PlaneValues, flat: CoordinateMap, map: CoordinateMap, x: AxisLayout, y: AxisLayout): Graphics2D[] {\n if (!s.grid) return [];\n const parts: Graphics2D[] = [];\n if (s.ghost && flat.revision !== map.revision) {\n const [gx, gy] = axesOf(flat, s);\n parts.push(...ruled(s, flat, gx, gy, true));\n }\n parts.push(...ruled(s, map, x, y, false));\n return parts;\n}\n\n/** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */\nfunction ruled(s: PlaneValues, map: CoordinateMap, x: AxisLayout, y: AxisLayout, ghost: boolean): Graphics2D[] {\n const { start, end } = s;\n const [xMin, xMax] = map.xRange;\n const [yMin, yMax] = map.yRange;\n const lines = (values: readonly number[], vertical: boolean): Graphics2D => {\n const g = new Graphics2D();\n for (const value of values) {\n g.line({\n points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),\n radius: 0,\n start,\n end,\n });\n }\n return g;\n };\n const parts: Graphics2D[] = [];\n const minor = s.minorStroke;\n if (ghost) {\n if (minor.length === 0) return parts;\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(minor));\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(minor));\n return parts;\n }\n const divisions = Math.round(s.minorDivisions);\n if (minor.length > 0 && divisions > 1) {\n const between = (axis: AxisLayout, [min, max]: readonly [number, number]): number[] => {\n const { step, values } = axis.marks;\n if (!(step > 0) || values.length === 0) return [];\n const out: number[] = [];\n for (let base = values[0] - step; base < max; base += step) {\n for (let i = 1; i < divisions; i++) {\n const value = base + (step * i) / divisions;\n if (value > min && value < max) out.push(value);\n }\n }\n return out;\n };\n const xs = between(x, map.xRange);\n const ys = between(y, map.yRange);\n if (xs.length > 0) parts.push(lines(xs, true).stroke(minor));\n if (ys.length > 0) parts.push(lines(ys, false).stroke(minor));\n }\n const major = s.gridStroke;\n if (major.length > 0) {\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(major));\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(major));\n }\n return parts;\n}\n\nconst STAY: Warp = (x, y, out) => {\n out.x = x;\n out.y = y;\n return true;\n};\n\n/** `source` as a warp, or `null` for text that is empty or not a field: the plane is then left as it is. */\nfunction warpOf(source: string): Warp | null {\n const field = source.trim() === \"\" ? null : parseField(source, fieldParams(source));\n if (!field || field instanceof Error) return null;\n const { x, y } = field;\n return (gx, gy, out) => {\n const wx = x(gx, gy);\n const wy = y(gx, gy);\n out.x = wx;\n out.y = wy;\n return Number.isFinite(wx) && Number.isFinite(wy);\n };\n}\n", "import {\n component2d,\n Graphics2D,\n Types,\n type Extents,\n type NodeOf,\n type Color as _Color,\n\n type NormalizedColor,\n type Stroke as _Stroke,\n\n type StrokeResolved,\n type Values,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n} from \"@motionscript/sdk\";\nimport { listed, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { cartesianMap, type CoordinateMap } from \"../kit/coords\";\nimport { AXIS_COLOR, drawLabels, type Label } from \"../kit/furniture\";\nimport { radians } from \"../kit/geometry\";\nimport { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\nimport { formatTick, ticksFor } from \"../kit/ticks\";\n\n/** How much room, in label sizes, the angles written round the outer ring take from the plane. */\nconst LABEL_ROOM = 2.2;\n\nconst state = {\n ...PAINT,\n /** The radius of the outermost ring, in graph units. */\n radius: Types.number(4, { min: 0.0001, step: 0.5 }),\n /** The spacing of the rings; zero picks a tidy one for the plane's size. */\n ringStep: Types.number(0, { min: 0 }),\n /** How many spokes divide the turn; zero draws none. */\n spokes: Types.number(12, { min: 0, max: 72, step: 1, animatable: false }),\n angleUnit: listed([\"degrees\", \"radians\"], \"degrees\", { animatable: false }),\n /** The inner rings and the spokes. */\n gridStroke: Types.stroke({ weight: 1.25, fill: \"#3b4658\", align: \"center\" }),\n /** A number at each ring, and an angle at each spoke. */\n labels: Types.boolean(true, { animatable: false }),\n labelSize: Types.number(16, { min: 1, unit: \"px\" }),\n labelColor: Types.color(AXIS_COLOR),\n fontFamily: Types.text(\"\", { animatable: false }),\n};\n\ntype PolarValues = Values<typeof state>;\n\n/** Rings and spokes about an origin: the plane a polar curve is read on. Children sit in its graph coordinates, as on axes. */\nexport const PolarPlane = component2d({\n key: \"polarPlane\",\n state,\n /** The outer ring and the two lines through the origin. */\n defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\" } },\n load: (loader, s) => {\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\n },\n commands: {\n ...PAINT_COMMANDS,\n /** Animate how far out the plane reaches: a zoom about its origin. */\n rangeTo: { args: [\"radius\"] },\n },\n provide: (s) => systemProvides(s),\n measure: (_measurer, s) => systemSize(s),\n layout: (box, s, children) => systemLayout(box, s, children, polarMap),\n plane: (box, s) => systemOpenPlane(box, s, polarMap),\n render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, polarMap), (map) => polarFurniture(map, s)),\n});\n\nexport type PolarPlane = NodeOf<typeof PolarPlane>;\n\nfunction polarMap(area: Extents, s: PolarValues): CoordinateMap {\n const width = area.maxX - area.minX;\n const height = area.maxY - area.minY;\n // The outer ring fits the shorter side, less the room its angles are written in; units are square.\n const reach = Math.max(1, Math.min(width, height) / 2 - (s.labels ? s.labelSize * LABEL_ROOM : 0));\n const unit = reach / Math.max(s.radius, 1e-9);\n return cartesianMap({\n xRange: [-width / 2 / unit, width / 2 / unit],\n yRange: [-height / 2 / unit, height / 2 / unit],\n area,\n });\n}\n\nfunction polarFurniture(map: CoordinateMap, s: PolarValues): Graphics2D[] {\n const stroke = s.stroke as StrokeResolved[];\n const grid = s.gridStroke as StrokeResolved[];\n const { start, end, radius } = s;\n const centre = map.toPoint(0, 0);\n const reach = map.toPoint(radius, 0).x - centre.x;\n if (!(reach > 0)) return [];\n const at = (r: number, degrees: number) => {\n const angle = radians(degrees);\n return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));\n };\n const ring = (g: Graphics2D, r: number): Graphics2D => {\n const size = (map.toPoint(r, 0).x - centre.x) * 2;\n return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });\n };\n\n const parts: Graphics2D[] = [];\n const marks = ticksFor([0, radius], s.ringStep, reach);\n const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));\n const count = Math.round(s.spokes);\n const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);\n\n if (grid.length > 0) {\n const inner = new Graphics2D();\n for (const r of rings) ring(inner, r);\n // The four along the axes are drawn with them.\n for (const degrees of turns) {\n if (degrees % 90 !== 0) inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });\n }\n if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0)) parts.push(inner.stroke(grid));\n }\n if (stroke.length > 0) {\n parts.push(\n ring(new Graphics2D(), radius)\n .line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })\n .line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })\n .stroke(stroke),\n );\n }\n if (!s.labels) return parts;\n\n const size = s.labelSize;\n const labels: Label[] = [];\n for (const r of [...rings, radius]) {\n const p = map.toPoint(r, 0);\n labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: \"right\" });\n }\n for (const degrees of turns) {\n const p = at(radius, degrees);\n const cos = Math.cos(radians(degrees));\n const sin = Math.sin(radians(degrees));\n labels.push({\n text: s.angleUnit === \"degrees\" ? `${formatTick(degrees, 1)}°` : radiansLabel(degrees),\n at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },\n align: cos > 0.3 ? \"left\" : cos < -0.3 ? \"right\" : \"center\",\n });\n }\n parts.push(...drawLabels(labels, { fontSize: size, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));\n return parts;\n}\n\n/** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */\nfunction radiansLabel(degrees: number): string {\n if (degrees === 0) return \"0\";\n let numerator = Math.round(degrees);\n let denominator = 180;\n for (let a = numerator, b = denominator; ; [a, b] = [b, a % b]) {\n if (b === 0) {\n numerator /= a;\n denominator /= a;\n break;\n }\n }\n const top = numerator === 1 ? \"π\" : `${numerator}π`;\n return denominator === 1 ? top : `${top}/${denominator}`;\n}\n", "import type { Vector2 } from \"@motionscript/sdk\";\n\n/**\n * The lines along which a function of two variables is zero, over a box of\n * graph values: marching squares, its crossings placed by linear interpolation\n * and joined end to end into runs. Points are graph coordinates.\n */\nexport function traceContour(\n f: (x: number, y: number) => number,\n [x0, x1]: readonly [number, number],\n [y0, y1]: readonly [number, number],\n columns: number,\n rows: number,\n): Vector2[][] {\n if (!(x1 > x0) || !(y1 > y0) || columns < 1 || rows < 1) return [];\n const dx = (x1 - x0) / columns;\n const dy = (y1 - y0) / rows;\n const stride = columns + 1;\n const values = new Float64Array(stride * (rows + 1));\n for (let j = 0; j <= rows; j++) {\n for (let i = 0; i <= columns; i++) values[j * stride + i] = f(x0 + i * dx, y0 + j * dy);\n }\n\n // A crossing lives on a grid edge, which is its name: two cells sharing the edge share the point.\n const points = new Map<number, Vector2>();\n const edgeCount = stride * (rows + 1);\n const crossing = (i: number, j: number, vertical: boolean): number | null => {\n const a = values[j * stride + i];\n const b = vertical ? values[(j + 1) * stride + i] : values[j * stride + i + 1];\n if (!Number.isFinite(a) || !Number.isFinite(b) || a < 0 === b < 0) return null;\n const key = (vertical ? edgeCount : 0) + j * stride + i;\n if (!points.has(key)) {\n const t = a / (a - b);\n points.set(key, vertical ? { x: x0 + i * dx, y: y0 + (j + t) * dy } : { x: x0 + (i + t) * dx, y: y0 + j * dy });\n }\n return key;\n };\n\n const next = new Map<number, number[]>();\n const join = (a: number | null, b: number | null): void => {\n if (a === null || b === null) return;\n (next.get(a) ?? next.set(a, []).get(a)!).push(b);\n (next.get(b) ?? next.set(b, []).get(b)!).push(a);\n };\n for (let j = 0; j < rows; j++) {\n for (let i = 0; i < columns; i++) {\n const bottom = crossing(i, j, false);\n const top = crossing(i, j + 1, false);\n const left = crossing(i, j, true);\n const right = crossing(i + 1, j, true);\n const found = [bottom, right, top, left].filter((edge) => edge !== null);\n if (found.length === 2) join(found[0], found[1]);\n else if (found.length === 4) {\n // A saddle: the centre's sign says which pairs of edges the curve joins.\n const centre = f(x0 + (i + 0.5) * dx, y0 + (j + 0.5) * dy);\n const corner = values[j * stride + i];\n if (centre < 0 === corner < 0) {\n join(bottom, right);\n join(top, left);\n } else {\n join(bottom, left);\n join(top, right);\n }\n }\n }\n }\n\n const runs: Vector2[][] = [];\n const used = new Set<number>();\n const walk = (from: number): Vector2[] => {\n const run: Vector2[] = [points.get(from)!];\n used.add(from);\n let at = from;\n for (;;) {\n const onward = (next.get(at) ?? []).find((key) => !used.has(key));\n if (onward === undefined) break;\n used.add(onward);\n run.push(points.get(onward)!);\n at = onward;\n }\n return run;\n };\n // Open runs first, from their ends, so each is one run and not two halves.\n for (const [key, links] of next) {\n if (links.length === 1 && !used.has(key)) runs.push(walk(key));\n }\n for (const key of next.keys()) {\n if (used.has(key)) continue;\n const run = walk(key);\n run.push(run[0]);\n runs.push(run);\n }\n return runs.filter((run) => run.length > 1);\n}\n", "import type { Extents, Vector2 } from \"@motionscript/sdk\";\n\n/** A curve's parameter to its pixel, written into `out`. `false` where the curve is undefined. */\nexport type CurveProjection = (t: number, out: Vector2) => boolean;\n\nexport interface SampleOptions {\n /** The equal steps the parameter range starts as, before any is split. */\n seeds?: number;\n /** A parameter step that is not split again, however bent. */\n minStep?: number;\n}\n\n/** Path coordinates are 32-bit floats in the renderer; past this a clamped point still clips to the same edge. */\nconst COORD_LIMIT = 16_000;\n/** How far, in pixels, the drawn chord may stray from the curve. */\nconst TOLERANCE_PX = 0.25;\n/** A turn, in radians, a chord is allowed to hide: what keeps a symmetric bump from reading as flat. */\nconst ANGLE_TOLERANCE = 0.05;\nconst MAX_DEPTH = 12;\nconst MAX_EVALUATIONS = 40_000;\nconst MAX_POINTS = 24_000;\n/** Bisections spent finding where a domain ends. */\nconst BOUNDARY_STEPS = 60;\nconst DEFAULT_SEEDS = 256;\n\ninterface Sample {\n t: number;\n px: number;\n py: number;\n /** The pixel before clamping: what tells an asymptote from a steep line. */\n rx: number;\n ry: number;\n ok: boolean;\n}\n\n// Midpoints are pooled: a refine is a depth-first walk, so a slot is free again\n// as soon as the seed interval it was taken for is done.\nconst arena: Sample[] = [];\nlet arenaMark = 0;\n\nfunction takeSample(): Sample {\n let slot = arena[arenaMark];\n if (slot === undefined) {\n slot = blank();\n arena.push(slot);\n }\n arenaMark++;\n return slot;\n}\n\nfunction blank(): Sample {\n return { t: 0, px: 0, py: 0, rx: 0, ry: 0, ok: false };\n}\n\nconst scratch: Vector2 = { x: 0, y: 0 };\n\n/** The runs of points that draw `project` over `[t0, t1]`, clipped to `clip`. */\nexport function sampleCurve(\n project: CurveProjection,\n t0: number,\n t1: number,\n clip: Extents,\n { seeds = DEFAULT_SEEDS, minStep = 0 }: SampleOptions = {},\n): Vector2[][] {\n if (!(t1 > t0) || !Number.isFinite(t0) || !Number.isFinite(t1)) return [];\n const pen = new CurvePen(clip);\n let spent = 0;\n\n const write = (slot: Sample, t: number): Sample => {\n const defined = project(t, scratch);\n spent++;\n const ok = defined && Number.isFinite(scratch.x) && Number.isFinite(scratch.y);\n slot.t = t;\n slot.rx = ok ? scratch.x : 0;\n slot.ry = ok ? scratch.y : 0;\n slot.px = clampCoord(slot.rx);\n slot.py = clampCoord(slot.ry);\n slot.ok = ok;\n return slot;\n };\n const at = (t: number): Sample => write(takeSample(), t);\n\n // The last defined point before `to`, which is not: where `sqrt(x)` meets its axis.\n const edgeOf = (from: Sample, to: Sample): Sample => {\n let inside = from;\n let outsideT = to.t;\n for (let i = 0; i < BOUNDARY_STEPS; i++) {\n if (spent >= MAX_EVALUATIONS || offFrame(inside, clip)) break;\n const midT = (inside.t + outsideT) / 2;\n if (midT === inside.t || midT === outsideT) break;\n const mid = at(midT);\n if (!mid.ok) {\n outsideT = midT;\n continue;\n }\n const settled = Math.abs(mid.px - inside.px) < TOLERANCE_PX && Math.abs(mid.py - inside.py) < TOLERANCE_PX;\n inside = mid;\n if (settled) break;\n }\n return inside;\n };\n\n const emit = (a: Sample, m: Sample | null, b: Sample, floored: boolean): void => {\n if (a.ok && b.ok) {\n if (floored && diverges(a, m, b, clip)) pen.break();\n else pen.draw(a, b);\n return;\n }\n if (a.ok) {\n const edge = edgeOf(a, b);\n if (edge.t !== a.t) pen.draw(a, edge);\n pen.break();\n return;\n }\n pen.break();\n if (b.ok) {\n const edge = edgeOf(b, a);\n if (edge.t !== b.t) pen.draw(edge, b);\n else pen.start(b);\n }\n };\n\n const refine = (a: Sample, b: Sample, depth: number): void => {\n if (spent >= MAX_EVALUATIONS || pen.points >= MAX_POINTS) {\n emit(a, null, b, false);\n return;\n }\n const m = at((a.t + b.t) / 2);\n const floored = depth >= MAX_DEPTH || b.t - a.t <= minStep;\n if (floored || flat(a, m, b)) {\n emit(a, m, b, floored);\n return;\n }\n refine(a, m, depth + 1);\n refine(m, b, depth + 1);\n };\n\n const count = Math.max(1, Math.round(seeds));\n const step = (t1 - t0) / count;\n const ends: [Sample, Sample] = [blank(), blank()];\n let previous = write(ends[0], t0);\n for (let i = 1; i <= count; i++) {\n const next = write(ends[i & 1], i === count ? t1 : t0 + i * step);\n arenaMark = 0;\n refine(previous, next, 0);\n previous = next;\n }\n arenaMark = 0;\n return pen.finish();\n}\n\nfunction flat(a: Sample, m: Sample, b: Sample): boolean {\n if (a.ok !== m.ok || m.ok !== b.ok) return false;\n if (!a.ok) return true;\n const dx = b.px - a.px;\n const dy = b.py - a.py;\n const length = Math.hypot(dx, dy) || 1;\n if (Math.abs((m.px - a.px) * dy - (m.py - a.py) * dx) / length > TOLERANCE_PX) return false;\n let turn = Math.abs(Math.atan2(m.py - a.py, m.px - a.px) - Math.atan2(b.py - m.py, b.px - m.px));\n if (turn > Math.PI) turn = 2 * Math.PI - turn;\n return turn < ANGLE_TOLERANCE;\n}\n\n// Two neighbours on opposite sides of the frame, with nothing between them that\n// is between them: an asymptote, not a steep line.\nfunction diverges(a: Sample, m: Sample | null, b: Sample, clip: Extents): boolean {\n const straddles =\n (a.py > clip.maxY && b.py < clip.minY) || (a.py < clip.minY && b.py > clip.maxY) ||\n (a.px > clip.maxX && b.px < clip.minX) || (a.px < clip.minX && b.px > clip.maxX);\n if (!straddles || m === null) return false;\n if (!m.ok) return true;\n return (\n m.ry < Math.min(a.ry, b.ry) || m.ry > Math.max(a.ry, b.ry) ||\n m.rx < Math.min(a.rx, b.rx) || m.rx > Math.max(a.rx, b.rx)\n );\n}\n\nfunction offFrame(sample: Sample, clip: Extents): boolean {\n return sample.py > clip.maxY || sample.py < clip.minY || sample.px > clip.maxX || sample.px < clip.minX;\n}\n\nfunction clampCoord(value: number): number {\n if (value > COORD_LIMIT) return COORD_LIMIT;\n if (value < -COORD_LIMIT) return -COORD_LIMIT;\n return value;\n}\n\nclass CurvePen {\n points = 0;\n private readonly runs: Vector2[][] = [];\n private open: Vector2[] = [];\n private cursor: Vector2 | null = null;\n\n constructor(private readonly clip: Extents) {}\n\n draw(a: Sample, b: Sample): void {\n const segment = clipSegment(a.px, a.py, b.px, b.py, this.clip);\n if (!segment) {\n this.break();\n return;\n }\n const [start, end] = segment;\n if (this.cursor && samePoint(this.cursor, start)) {\n this.push(end);\n } else {\n this.break();\n this.push(start);\n this.push(end);\n }\n this.cursor = end;\n }\n\n start(b: Sample): void {\n this.break();\n if (!inside(b.px, b.py, this.clip)) return;\n this.cursor = { x: b.px, y: b.py };\n this.push(this.cursor);\n }\n\n break(): void {\n if (this.open.length >= 2) this.runs.push(this.open);\n this.open = [];\n this.cursor = null;\n }\n\n finish(): Vector2[][] {\n this.break();\n return this.runs;\n }\n\n private push(point: Vector2): void {\n this.open.push(point);\n this.points++;\n }\n}\n\nfunction samePoint(a: Vector2, b: Vector2): boolean {\n return Math.abs(a.x - b.x) < 0.1 && Math.abs(a.y - b.y) < 0.1;\n}\n\nfunction inside(x: number, y: number, clip: Extents): boolean {\n return x >= clip.minX && x <= clip.maxX && y >= clip.minY && y <= clip.maxY;\n}\n\n// Liang–Barsky: the part of a segment inside the clip, or null when none is.\nfunction clipSegment(ax: number, ay: number, bx: number, by: number, clip: Extents): [Vector2, Vector2] | null {\n const dx = bx - ax;\n const dy = by - ay;\n let t0 = 0;\n let t1 = 1;\n const edges: [number, number][] = [\n [-dx, ax - clip.minX],\n [dx, clip.maxX - ax],\n [-dy, ay - clip.minY],\n [dy, clip.maxY - ay],\n ];\n for (const [p, q] of edges) {\n if (p === 0) {\n if (q < 0) return null;\n continue;\n }\n const r = q / p;\n if (p < 0) {\n if (r > t1) return null;\n if (r > t0) t0 = r;\n } else {\n if (r < t0) return null;\n if (r < t1) t1 = r;\n }\n }\n return [\n { x: ax + t0 * dx, y: ay + t0 * dy },\n { x: ax + t1 * dx, y: ay + t1 * dy },\n ];\n}\n", "import {\n component2d,\n provides,\n Types,\n type EntryOptions,\n type NodeOf,\n type PaintProps,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { createBoundedCache } from \"../kit/cache\";\nimport { omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { traceContour } from \"../kit/contour\";\nimport type { CoordinateMap, Interval } from \"../kit/coords\";\nimport { equationParams, parseEquation, type Equation } from \"../kit/equation\";\nimport type { ExpressionScope } from \"../kit/expression\";\nimport { PLOT_COLOR } from \"../kit/furniture\";\nimport { PLOT, plotPlane, SYSTEM, SYSTEM_ENTRY } from \"../kit/graph\";\nimport { drawMark, inkCentre, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\nimport { openPlane, placeOnMap } from \"../kit/place\";\nimport { sampleCurve, type CurveProjection } from \"../kit/sampler\";\nimport { lerpDomain, lerpParams, lerpSource, readSource, scopeFor, type PlotSource } from \"../kit/source\";\n\nexport interface FunctionPlotProps extends PaintProps {\n expression?: string | PlotSource;\n domain?: Interval | null;\n params?: ExpressionScope;\n}\n\nconst TAU = Math.PI * 2;\n\n/** A plot's entries: what a traced path is built on too. It is only a line, so it has no fill. */\nexport const PLOT_STATE = {\n ...omit(PAINT, \"fill\"),\n expression: Types.custom<string | PlotSource, PlotSource>(\"\", { resolve: readSource, lerp: lerpSource, kind: \"equation\" }),\n /**\n * The span of the free variable that is drawn. Left out, a function runs the\n * width of its system, a polar curve one turn and a parametric one from 0 to 1.\n */\n domain: Types.custom<Interval | null, Interval | null, EntryOptions & { readonly defaultMin: number; readonly defaultMax: number }>(null, { lerp: lerpDomain, kind: \"range\", defaultMin: -5, defaultMax: 5 }),\n /**\n * The equation's named values: any name in it that is not a variable, a\n * function or a constant. One left unset is 1, and a formula can bind each\n * to a variable.\n */\n params: Types.custom<ExpressionScope>({}, { lerp: lerpParams }),\n graph: SYSTEM_ENTRY,\n};\n\n/** A plot's own commands, beside a line's paints. */\nexport const PLOT_COMMANDS = {\n ...omit(PAINT_COMMANDS, \"fillTo\"),\n /** Change the equation, the curve bending from the one into the other. */\n morphTo: { args: [\"expression\"] as const },\n /** Animate the equation's named values. */\n paramsTo: { args: [\"params\"] as const },\n /** Animate the span that is drawn. */\n domainTo: { args: [\"domain\"] as const },\n};\n\nexport const PLOT_STROKE = { weight: 3, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" } as const;\n\nexport interface PlotValues {\n readonly expression: PlotSource;\n readonly params: ExpressionScope;\n}\n\n/** The curve of an equation, drawn in the system it is a child of; a mark put inside it reads it. */\nexport const FunctionPlot = traced(component2d({\n key: \"functionPlot\",\n state: PLOT_STATE,\n defaults: { stroke: PLOT_STROKE, width: \"hug\", height: \"hug\" },\n commands: PLOT_COMMANDS,\n // The marks inside it ride it, on its system's map.\n provide: (s, inherited) => [provides(PLOT, plotPlane(s, inherited(SYSTEM)))],\n measure: (_measurer, s) => inkSize(tracePlot(s, reading(s), s.domain)),\n layout: (box, s, children) => {\n const read = reading(s);\n return placeOnMap(children, read.map, inkCentre(tracePlot(s, read, s.domain)), box, plotPlane(s, s.graph));\n },\n plane: (_box, s) => {\n const read = reading(s);\n return openPlane(read.map, inkCentre(tracePlot(s, read, s.domain)));\n },\n render: (ctx, s) => drawMark(ctx, s, tracePlot(s, reading(s), s.domain)),\n}), (s: PlotValues & { readonly domain: Interval | null }, read: MarkReading) => tracePlot(s, read, s.domain));\n\nexport type FunctionPlot = NodeOf<typeof FunctionPlot>;\n\nconst traces = createBoundedCache<Vector2[][]>(256);\n\n/** The runs a plot of `s` draws through `read`, over `span` of its free variable (all of it for `null`). */\nexport function tracePlot(s: PlotValues, read: MarkReading, span: Interval | null): Vector2[][] {\n const { map, shift } = read;\n const { area } = map;\n if (!Number.isFinite(area.maxX - area.minX)) return [];\n const { source, blend } = s.expression;\n const key = [source, blend?.from, blend?.t, map.revision, span, JSON.stringify(s.params), shift.x, shift.y].join(\"|\");\n const known = traces.get(key);\n if (known) return known;\n\n let runs: Vector2[][];\n // A curve with no parameter to walk cannot bend into another: it changes over half way.\n const shown = blend && blend.t < 0.5 ? blend.from : source;\n if (equationOf(source)?.kind === \"implicit\" || (blend && equationOf(blend.from)?.kind === \"implicit\")) {\n runs = contour(shown, s.params, map, shift);\n } else {\n let curve = projectionOf(source, s.params, span, map, shift);\n if (curve && blend) {\n const from = projectionOf(blend.from, s.params, span, map, shift);\n if (from) curve = between(from, curve, blend.t);\n }\n const width = area.maxX - area.minX;\n runs = curve\n ? sampleCurve(curve, 0, 1, area, { seeds: Math.min(512, Math.max(64, Math.round(width / 8))), minStep: 0.5 / Math.max(1, width) })\n : [];\n }\n traces.set(key, runs);\n return runs;\n}\n\nfunction equationOf(source: string): Equation | null {\n const equation = parseEquation(source, equationParams(source));\n return equation instanceof Error ? null : equation;\n}\n\n/** Where an implicit `source` holds, over what the system shows, as pixel runs. */\nfunction contour(source: string, params: ExpressionScope, map: CoordinateMap, shift: Vector2): Vector2[][] {\n const equation = equationOf(source);\n if (equation?.kind !== \"implicit\") return [];\n const scope = scopeFor(equationParams(source), params);\n const { area } = map;\n const cells = (pixels: number) => Math.min(CONTOUR_MAX, Math.max(8, Math.round(pixels / CONTOUR_CELL)));\n const { f } = equation;\n const runs = traceContour(\n (x, y) => f(x - shift.x, y - shift.y, scope),\n map.xRange,\n map.yRange,\n cells(area.maxX - area.minX),\n cells(area.maxY - area.minY),\n );\n return runs.map((run) => run.map((point) => map.toPoint(point.x, point.y)));\n}\n\n/** `source` as a pixel curve over a parameter running 0 to 1. */\nfunction projectionOf(source: string, params: ExpressionScope, domain: Interval | null, map: CoordinateMap, shift: Vector2): CurveProjection | null {\n const equation = equationOf(source);\n if (!equation || equation.kind === \"implicit\") return null;\n const scope = scopeFor(equationParams(source), params);\n switch (equation.kind) {\n case \"function\": {\n const horizontal = equation.of === \"x\";\n const [lo, hi] = horizontal ? map.xRange : map.yRange;\n const offset = horizontal ? shift.x : shift.y;\n // Only what the system shows is sampled, however wide the domain.\n const a = Math.max(lo - offset, domain?.[0] ?? -Infinity);\n const b = Math.min(hi - offset, domain?.[1] ?? Infinity);\n if (!(b > a)) return null;\n const { f } = equation;\n return (u, out) => {\n const v = a + (b - a) * u;\n const w = f(v, 0, scope);\n if (!Number.isFinite(w)) return false;\n if (horizontal) map.toPoint(v + shift.x, w + shift.y, out);\n else map.toPoint(w + shift.x, v + shift.y, out);\n return true;\n };\n }\n case \"polar\": {\n const [a, b] = domain ?? [0, TAU];\n const { f } = equation;\n return (u, out) => {\n const theta = a + (b - a) * u;\n const r = f(theta, 0, scope);\n if (!Number.isFinite(r)) return false;\n map.toPoint(r * Math.cos(theta) + shift.x, r * Math.sin(theta) + shift.y, out);\n return true;\n };\n }\n case \"parametric\": {\n const [a, b] = domain ?? [0, 1];\n const { x, y } = equation;\n return (u, out) => {\n const t = a + (b - a) * u;\n const gx = x(t, 0, scope);\n const gy = y(t, 0, scope);\n if (!Number.isFinite(gx) || !Number.isFinite(gy)) return false;\n map.toPoint(gx + shift.x, gy + shift.y, out);\n return true;\n };\n }\n }\n}\n\n// Roughly one cell of the contour's grid to this many pixels, each way.\nconst CONTOUR_CELL = 5;\nconst CONTOUR_MAX = 220;\n\n// Two curves blended point for point along their parameters, in pixels, so any\n// kind bends into any other.\nfunction between(from: CurveProjection, to: CurveProjection, t: number): CurveProjection {\n const a: Vector2 = { x: 0, y: 0 };\n return (u, out) => {\n if (!from(u, a) || !to(u, out)) return false;\n out.x = a.x + (out.x - a.x) * t;\n out.y = a.y + (out.y - a.y) * t;\n return true;\n };\n}\n", "import {\n component2d,\n Types,\n type NodeOf,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { PLOT_COLOR } from \"../kit/furniture\";\nimport { PLANE_ENTRY } from \"../kit/graph\";\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\n// A shorter list is padded with its own last point, so a line grows new points out of its end.\nfunction lerpPoints(from: Vector2[], to: Vector2[], t: number): Vector2[] {\n const count = Math.max(from.length, to.length);\n if (from.length === 0 || to.length === 0) return t < 1 ? from : to;\n const out = new Array<Vector2>(count);\n for (let i = 0; i < count; i++) {\n const a = from[Math.min(i, from.length - 1)];\n const b = to[Math.min(i, to.length - 1)];\n out[i] = { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };\n }\n return out;\n}\n\n/** Points on the curve between each pair of a smooth line's points. */\nconst SMOOTH_STEPS = 16;\n\nconst state = {\n ...PAINT,\n points: Types.custom<Vector2[]>([], { lerp: lerpPoints }),\n /** Join the last point to the first. */\n closed: Types.boolean(false, { animatable: false }),\n /** Curve through the points instead of turning a corner at each. */\n smooth: Types.boolean(false, { animatable: false }),\n graph: PLANE_ENTRY,\n};\n\ninterface PointsValues {\n readonly points: Vector2[];\n readonly closed: boolean;\n readonly smooth: boolean;\n}\n\n/** A line through listed graph points: data, or a shape drawn in graph coordinates when closed, which is when it is filled. */\nexport const PointsPlot = traced(component2d({\n key: \"pointsPlot\",\n state,\n defaults: { stroke: { weight: 3, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\n commands: {\n ...PAINT_COMMANDS,\n /** Move the points to new places; extra ones grow from the line's end. */\n pointsTo: { args: [\"points\"] },\n },\n measure: (_measurer, s) => inkSize(tracePoints(s, reading(s))),\n // An open line has no inside, so its fill waits until it is closed.\n render: (ctx, s) => drawMark(ctx, s, tracePoints(s, reading(s)), { closed: s.closed, fills: s.closed }),\n}), tracePoints);\n\nexport type PointsPlot = NodeOf<typeof PointsPlot>;\n\nfunction tracePoints(s: PointsValues, { map, shift }: MarkReading): Vector2[][] {\n const pixels = s.points.map((p) => map.toPoint(p.x + shift.x, p.y + shift.y));\n if (pixels.length < 2) return [];\n return [s.smooth && pixels.length > 2 ? spline(pixels, s.closed) : pixels];\n}\n\n// Catmull–Rom, so the curve passes through every point it was given.\nfunction spline(points: readonly Vector2[], closed: boolean): Vector2[] {\n const n = points.length;\n const at = (i: number): Vector2 => (closed ? points[((i % n) + n) % n] : points[Math.max(0, Math.min(n - 1, i))]);\n const out: Vector2[] = [];\n const spans = closed ? n : n - 1;\n for (let i = 0; i < spans; i++) {\n const p0 = at(i - 1), p1 = at(i), p2 = at(i + 1), p3 = at(i + 2);\n for (let s = 0; s < SMOOTH_STEPS; s++) {\n const t = s / SMOOTH_STEPS;\n const t2 = t * t;\n const t3 = t2 * t;\n out.push({\n x: 0.5 * (2 * p1.x + (p2.x - p0.x) * t + (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 + (3 * p1.x - p0.x - 3 * p2.x + p3.x) * t3),\n y: 0.5 * (2 * p1.y + (p2.y - p0.y) * t + (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 + (3 * p1.y - p0.y - 3 * p2.y + p3.y) * t3),\n });\n }\n }\n if (!closed) out.push(points[n - 1]);\n return out;\n}\n", "import { colorOps, fillOps, type Color, type Fill, type FillResolved, type NormalizedColor } from \"@motionscript/sdk\";\nimport { clamp } from \"./geometry\";\n\n/** A run of colours a value is read off, lowest first: a surface's height, a field's strength. */\n\nexport function readScale(value: readonly Color[] | undefined): NormalizedColor[] {\n return (value ?? []).map((color) => colorOps.resolve(color));\n}\n\nexport function lerpScale(from: NormalizedColor[], to: NormalizedColor[], t: number): NormalizedColor[] {\n if (from.length !== to.length) return t < 1 ? from : to;\n return to.map((color, index) => colorOps.lerp(from[index], color, t));\n}\n\n/** The colour `share` of the way along `scale`, 0 to 1. */\nexport function colorAt(scale: readonly NormalizedColor[], share: number): NormalizedColor {\n if (scale.length === 1) return scale[0];\n const at = clamp(share, 0, 1) * (scale.length - 1);\n const index = Math.min(scale.length - 2, Math.floor(at));\n return colorOps.lerp(scale[index], scale[index + 1], at - index);\n}\n\n/** A run of paints a value is read off, lowest first: a field's strength. Every entry is kept as written. */\nexport function readFillScale(value: readonly Fill[] | undefined): FillResolved[][] {\n return (Array.isArray(value) ? value : []).map((fill) => fillOps.resolve(fill ?? []));\n}\n\nexport function lerpFillScale(from: FillResolved[][], to: FillResolved[][], t: number): FillResolved[][] {\n if (from.length !== to.length) return t < 1 ? from : to;\n return to.map((fill, index) => fillOps.lerp(from[index], fill, t));\n}\n\n/** The paint `share` of the way along `scale`, 0 to 1. */\nexport function fillAt(scale: readonly FillResolved[][], share: number): FillResolved[] {\n if (scale.length === 1) return scale[0];\n const at = clamp(share, 0, 1) * (scale.length - 1);\n const index = Math.min(scale.length - 2, Math.floor(at));\n return fillOps.lerp(scale[index], scale[index + 1], at - index);\n}\n", "import {\n Graphics2D,\n Types,\n type Fill,\n type FillResolved,\n type PaintProps,\n type RenderContext,\n type StrokeResolved,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n} from \"@motionscript/sdk\";\nimport { createBoundedCache } from \"./cache\";\nimport { omit, PAINT, PAINT_COMMANDS } from \"./component\";\nimport type { CoordinateMap } from \"./coords\";\nimport type { ExpressionScope } from \"./expression\";\nimport { fieldParams, parseField } from \"./field\";\nimport { runsToPath } from \"./geometry\";\nimport { PLANE_ENTRY } from \"./graph\";\nimport { drawMark, type MarkPaint, type MarkReading } from \"./mark\";\nimport { fillAt, lerpFillScale, readFillScale } from \"./scale\";\nimport { lerpParams, lerpSource, readSource, scopeFor, type PlotSource } from \"./source\";\n\n// Without strength fills a field mark is one path in the stroke's paint; with them it is sorted by strength into a few shades.\n\nexport interface FieldProps extends PaintProps {\n expression?: string | PlotSource;\n params?: ExpressionScope;\n strengthFills?: Fill[];\n maxMagnitude?: number;\n}\n\n/** A field's vector at a graph point, written into `out`; `false` where it has none. */\nexport type FieldSampler = (x: number, y: number, out: Vector2) => boolean;\n\n/** One thing a field draws, and how strong the field is there: what it is coloured by. */\nexport interface FieldStroke {\n runs: Vector2[][];\n magnitude: number;\n}\n\n/** How many shades the strength fills are drawn in: each is one path. */\nconst SHADES = 12;\n\n/** A field mark's entries. It is only strokes, revealed its own way: it has no fill and trims no outline. */\nexport const FIELD_STATE = {\n ...omit(PAINT, \"fill\", \"start\", \"end\"),\n expression: Types.custom<string | PlotSource, PlotSource>(\"\", { resolve: readSource, lerp: lerpSource, kind: \"fieldEquation\" }),\n /** The equation's named values: any name in it that is not `x`, `y`, a function or a constant. */\n params: Types.custom<ExpressionScope>({}, { lerp: lerpParams }),\n /** Paints by the field's strength, weakest first. Empty draws everything in the stroke's own paint. */\n strengthFills: Types.custom<Fill[], FillResolved[][]>([], { resolve: readFillScale, lerp: lerpFillScale, kind: \"vector\" }),\n /** The strength the last paint stands for; zero takes the strongest the field is where it is drawn. */\n maxMagnitude: Types.number(0, { min: 0, step: 0.1 }),\n graph: PLANE_ENTRY,\n};\n\nexport const FIELD_COMMANDS = {\n ...omit(PAINT_COMMANDS, \"fillTo\", \"progressTo\", \"flash\"),\n /** Change the field, each vector turning from the one into the other. */\n morphTo: { args: [\"expression\"] as const },\n /** Animate the equation's named values. */\n paramsTo: { args: [\"params\"] as const },\n};\n\nexport interface FieldValues {\n readonly expression: PlotSource;\n readonly params: ExpressionScope;\n}\n\n/** What one kind of field mark draws of `field` through `map`, and the entries of its own that change it. */\nexport interface FieldDrawing<S> {\n strokes(s: S, map: CoordinateMap, field: FieldSampler): FieldStroke[];\n /** The entries of its own that change what `strokes` returns, as a key. */\n own(s: S): string;\n}\n\ninterface Traced {\n readonly drawn: FieldStroke[];\n readonly runs: Vector2[][];\n}\n\nconst traces = createBoundedCache<Traced>(64);\nconst EMPTY: Traced = { drawn: [], runs: [] };\n\n/** What a field mark of `kind` draws through `read`: each stroke with its strength, and all their runs. */\nexport function traceField<S extends FieldValues>(kind: string, drawing: FieldDrawing<S>, s: S, { map, shift }: MarkReading): Traced {\n const { area } = map;\n if (!Number.isFinite(area.maxX - area.minX)) return EMPTY;\n const { source, blend } = s.expression;\n const key = [kind, source, blend?.from, blend?.t, map.revision, JSON.stringify(s.params), shift.x, shift.y, drawing.own(s)].join(\"|\");\n const known = traces.get(key);\n if (known) return known;\n const field = sampler(s, shift);\n const drawn = field ? drawing.strokes(s, map, field) : [];\n const traced = { drawn, runs: drawn.flatMap((stroke) => stroke.runs) };\n traces.set(key, traced);\n return traced;\n}\n\n/** A field mark's paint: one stroke, or a shade per strength when it has strength fills. */\nexport function drawField(\n ctx: RenderContext,\n s: MarkPaint & { readonly strengthFills: FillResolved[][]; readonly maxMagnitude: number },\n { drawn, runs }: Traced,\n): void {\n const scale = s.strengthFills;\n const stroke = s.stroke as StrokeResolved[];\n const shaded = scale.length > 0 && stroke.length > 0;\n drawMark(ctx, s, runs, {\n ink: shaded\n ? (ctx, ink) => {\n const top = s.maxMagnitude > 0 ? s.maxMagnitude : drawn.reduce((most, d) => Math.max(most, d.magnitude), 0);\n const shades: Vector2[][][] = Array.from({ length: SHADES }, () => []);\n for (const d of drawn) {\n const share = top > 0 ? Math.min(1, d.magnitude / top) : 0;\n shades[Math.min(SHADES - 1, Math.floor(share * SHADES))].push(...d.runs);\n }\n shades.forEach((shade, index) => {\n if (shade.length === 0) return;\n const fill = fillAt(scale, (index + 0.5) / SHADES);\n ctx.draw(\n new Graphics2D()\n .path({ data: runsToPath(shade), centerBounds: [ink.minX, ink.minY, ink.maxX, ink.maxY], start: s.start ?? 0, end: s.end ?? 1 })\n .shadow(s.shadow)\n .stroke(stroke.map((layer) => ({ ...layer, fill }))),\n );\n });\n }\n : undefined,\n });\n}\n\n/** The field at a graph point, measured from the mark's own shift, mid-morph a blend of two. */\nfunction sampler(s: FieldValues, shift: Vector2): FieldSampler | null {\n const { source, blend } = s.expression;\n const to = fieldOf(source, s.params, shift);\n if (!to || !blend) return to;\n const from = fieldOf(blend.from, s.params, shift);\n if (!from) return to;\n const start: Vector2 = { x: 0, y: 0 };\n return (x, y, out) => {\n if (!from(x, y, start) || !to(x, y, out)) return false;\n out.x = start.x + (out.x - start.x) * blend.t;\n out.y = start.y + (out.y - start.y) * blend.t;\n return true;\n };\n}\n\nfunction fieldOf(source: string, params: ExpressionScope, shift: Vector2): FieldSampler | null {\n const names = fieldParams(source);\n const field = parseField(source, names);\n if (field instanceof Error) return null;\n const scope = scopeFor(names, params);\n const { x, y } = field;\n return (gx, gy, out) => {\n const vx = x(gx - shift.x, gy - shift.y, scope);\n const vy = y(gx - shift.x, gy - shift.y, scope);\n out.x = vx;\n out.y = vy;\n return Number.isFinite(vx) && Number.isFinite(vy);\n };\n}\n", "import {\n component2d,\n Types,\n type NodeOf,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport type { CoordinateMap } from \"../kit/coords\";\nimport { drawField, FIELD_COMMANDS, FIELD_STATE, traceField, type FieldDrawing, type FieldValues, type FieldSampler, type FieldStroke } from \"../kit/field-mark\";\nimport { PLOT_COLOR } from \"../kit/furniture\";\nimport { radians } from \"../kit/geometry\";\nimport { inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\n/** Past this many arrows the spacing is widened, so a field over a huge range is still a field and not a wash. */\nconst MAX_ARROWS = 2400;\n/** An arrow's head, as a share of its length and in pixels at most, and the half-angle it opens to. */\nconst HEAD_SHARE = 0.38;\nconst HEAD_MAX = 11;\nconst HEAD_ANGLE = radians(26);\n\nconst state = {\n ...FIELD_STATE,\n /** How far apart the arrows stand, in graph units. */\n spacing: Types.number(1, { min: 0.01, step: 0.1 }),\n /** How long an arrow is drawn for a vector of length one, in graph units. */\n arrowScale: Types.number(0.4, { min: 0, step: 0.05 }),\n};\n\ninterface ArrowsValues extends FieldValues {\n readonly spacing: number;\n readonly arrowScale: number;\n}\n\nconst ARROWS: FieldDrawing<ArrowsValues> = {\n own: (s) => `${s.spacing}|${s.arrowScale}`,\n strokes: (s, map, field) => arrows(s, map, field),\n};\n\nconst traceArrows = (s: ArrowsValues, read: MarkReading) => traceField(\"vectorField\", ARROWS, s, read);\n\n/** A grid of arrows showing a vector field, `(-y, x)`: each is centred on its point and as long as the field is strong there, up to the spacing. */\nexport const VectorField = traced(component2d({\n key: \"vectorField\",\n state,\n defaults: { stroke: { weight: 2.5, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\n commands: FIELD_COMMANDS,\n measure: (_measurer, s) => inkSize(traceArrows(s, reading(s)).runs),\n render: (ctx, s) => drawField(ctx, s, traceArrows(s, reading(s))),\n}), (s: ArrowsValues, read: MarkReading) => traceArrows(s, read).runs);\n\nexport type VectorField = NodeOf<typeof VectorField>;\n\nfunction arrows(s: ArrowsValues, map: CoordinateMap, field: FieldSampler): FieldStroke[] {\n const [x0, x1] = map.xRange;\n const [y0, y1] = map.yRange;\n let spacing = Math.max(s.spacing, 1e-6);\n const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);\n while (count() > MAX_ARROWS) spacing *= 2;\n\n const drawn: FieldStroke[] = [];\n const v: Vector2 = { x: 0, y: 0 };\n const longest = spacing * 0.9;\n for (let i = Math.ceil(x0 / spacing - 1e-9); i * spacing <= x1 + 1e-9; i++) {\n for (let j = Math.ceil(y0 / spacing - 1e-9); j * spacing <= y1 + 1e-9; j++) {\n const gx = i * spacing;\n const gy = j * spacing;\n if (!field(gx, gy, v)) continue;\n const magnitude = Math.hypot(v.x, v.y);\n const length = Math.min(magnitude * s.arrowScale, longest);\n if (!(length > 0)) continue;\n const hx = ((v.x / magnitude) * length) / 2;\n const hy = ((v.y / magnitude) * length) / 2;\n const tail = map.toPoint(gx - hx, gy - hy);\n const head = map.toPoint(gx + hx, gy + hy);\n drawn.push({ runs: arrow(tail, head), magnitude });\n }\n }\n return drawn;\n}\n\n/** A shaft and the two barbs of its head, in pixels. */\nfunction arrow(tail: Vector2, head: Vector2): Vector2[][] {\n const dx = head.x - tail.x;\n const dy = head.y - tail.y;\n const length = Math.hypot(dx, dy);\n if (!(length > 0)) return [];\n const barb = Math.min(length * HEAD_SHARE, HEAD_MAX);\n const back = Math.atan2(dy, dx) + Math.PI;\n const at = (angle: number): Vector2 => ({ x: head.x + Math.cos(angle) * barb, y: head.y + Math.sin(angle) * barb });\n return [[tail, head], [at(back - HEAD_ANGLE), head, at(back + HEAD_ANGLE)]];\n}\n", "import {\n component2d,\n Types,\n type NodeOf,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport type { CoordinateMap } from \"../kit/coords\";\nimport { drawField, FIELD_COMMANDS, FIELD_STATE, traceField, type FieldDrawing, type FieldSampler, type FieldStroke, type FieldValues } from \"../kit/field-mark\";\nimport { PLOT_COLOR } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\nconst MAX_LINES = 1600;\n/** Steps a line takes across one spacing: what keeps a tight swirl round. */\nconst STEPS_PER_SPACING = 8;\nconst MAX_STEPS = 600;\n\nconst state = {\n ...FIELD_STATE,\n /** How far apart the lines start, in graph units. */\n spacing: Types.number(1, { min: 0.01, step: 0.1 }),\n /** How far each line runs from where it starts, in graph units along itself. */\n length: Types.number(3, { min: 0, step: 0.1 }),\n /** The share of each line that is shown at once; one shows all of it. */\n window: Types.number(1, { min: 0.01, max: 1, step: 0.01 }),\n /** Where along its line each shown stretch is: one turn of it runs every line from end to end. */\n phase: Types.number(0, { step: 0.01 }),\n};\n\ninterface LinesValues extends FieldValues {\n readonly spacing: number;\n readonly length: number;\n readonly window: number;\n readonly phase: number;\n}\n\nconst LINES: FieldDrawing<LinesValues> = {\n own: (s) => `${s.spacing}|${s.length}|${s.window}|${s.phase}`,\n strokes: (s, map, field) => lines(s, map, field),\n};\n\nconst traceLines = (s: LinesValues, read: MarkReading) => traceField(\"streamLines\", LINES, s, read);\n\n/**\n * The lines a vector field carries a point along, one from each point of a\n * grid: `(-y, x)` draws circles. With a `window` below one, each line shows\n * only a stretch of itself, and `flowTo` sends those stretches along.\n */\nexport const StreamLines = traced(component2d({\n key: \"streamLines\",\n state,\n defaults: { stroke: { weight: 2, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\n commands: {\n ...FIELD_COMMANDS,\n /** Send the shown stretches along their lines: a whole number runs each line that many times over. */\n flowTo: { args: [\"phase\"] },\n },\n measure: (_measurer, s) => inkSize(traceLines(s, reading(s)).runs),\n render: (ctx, s) => drawField(ctx, s, traceLines(s, reading(s))),\n}), (s: LinesValues, read: MarkReading) => traceLines(s, read).runs);\n\nexport type StreamLines = NodeOf<typeof StreamLines>;\n\nfunction lines(s: LinesValues, map: CoordinateMap, field: FieldSampler): FieldStroke[] {\n const [x0, x1] = map.xRange;\n const [y0, y1] = map.yRange;\n let spacing = Math.max(s.spacing, 1e-6);\n const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);\n while (count() > MAX_LINES) spacing *= 2;\n const step = spacing / STEPS_PER_SPACING;\n const steps = Math.min(MAX_STEPS, Math.round(s.length / step));\n if (steps < 1) return [];\n // A line is followed a little past what is shown, so it leaves the box rather than stopping at its edge.\n const inside = (x: number, y: number) => x >= x0 - spacing && x <= x1 + spacing && y >= y0 - spacing && y <= y1 + spacing;\n const window = clamp(s.window, 0, 1);\n\n const drawn: FieldStroke[] = [];\n let index = 0;\n for (let i = Math.ceil(x0 / spacing - 1e-9); i * spacing <= x1 + 1e-9; i++) {\n for (let j = Math.ceil(y0 / spacing - 1e-9); j * spacing <= y1 + 1e-9; j++) {\n const line = follow(field, i * spacing, j * spacing, step, steps, inside);\n index++;\n if (line.points.length < 2) continue;\n const shown = window >= 1 ? line.points : stretch(line.points, window, s.phase + stagger(index));\n if (shown.length < 2) continue;\n drawn.push({ runs: [shown.map((p) => map.toPoint(p.x, p.y))], magnitude: line.magnitude });\n }\n }\n return drawn;\n}\n\n/** The graph points a field carries a point through from `(x, y)`, at an even pace, and how strong it was on the way. */\nfunction follow(\n field: FieldSampler,\n x: number,\n y: number,\n step: number,\n steps: number,\n inside: (x: number, y: number) => boolean,\n): { points: Vector2[]; magnitude: number } {\n const points: Vector2[] = [{ x, y }];\n const v: Vector2 = { x: 0, y: 0 };\n let strength = 0;\n let read = 0;\n // The field's direction at a point, as a unit step; `false` where it has none or is at rest.\n const heading = (px: number, py: number, out: Vector2): boolean => {\n if (!field(px, py, v)) return false;\n const magnitude = Math.hypot(v.x, v.y);\n if (!(magnitude > 1e-9)) return false;\n out.x = v.x / magnitude;\n out.y = v.y / magnitude;\n strength += magnitude;\n read++;\n return true;\n };\n const a: Vector2 = { x: 0, y: 0 };\n const b: Vector2 = { x: 0, y: 0 };\n for (let i = 0; i < steps; i++) {\n // Midpoint rule: the direction half a step on is the one the whole step takes.\n if (!heading(x, y, a) || !heading(x + (a.x * step) / 2, y + (a.y * step) / 2, b)) break;\n x += b.x * step;\n y += b.y * step;\n if (!inside(x, y)) break;\n points.push({ x, y });\n }\n return { points, magnitude: read > 0 ? strength / read : 0 };\n}\n\n/** The part of `points` a window `share` long shows at `phase`: it enters at one end and leaves by the other. */\nfunction stretch(points: Vector2[], share: number, phase: number): Vector2[] {\n const turn = phase - Math.floor(phase);\n const end = turn * (1 + share);\n const from = Math.max(0, end - share);\n const to = Math.min(1, end);\n if (!(to > from)) return [];\n const last = points.length - 1;\n return points.slice(Math.floor(from * last), Math.ceil(to * last) + 1);\n}\n\n/** A share of a turn that differs from line to line and never from frame to frame, so the stretches do not march in step. */\nfunction stagger(index: number): number {\n const mixed = Math.sin(index * 12.9898) * 43758.5453;\n return mixed - Math.floor(mixed);\n}\n", "import {\n component2d,\n Types,\n type NodeOf,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { omit } from \"../kit/component\";\nimport type { Interval } from \"../kit/coords\";\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\nimport { PLOT_COMMANDS, PLOT_STATE, PLOT_STROKE, tracePlot, type PlotValues } from \"./function-plot\";\n\nconst state = {\n // It reveals itself by its value, so it trims no outline of its own.\n ...omit(PLOT_STATE, \"start\", \"end\"),\n /** The value the trail starts at. */\n from: Types.number(0, { step: 0.1 }),\n /** The value the point is at now: where the trail ends. */\n value: Types.number(0, { step: 0.1 }),\n /** How much of the trail is kept, in the value's own units; zero keeps all of it. */\n tail: Types.number(0, { min: 0, step: 0.1 }),\n};\n\ninterface TrailValues extends PlotValues {\n readonly from: number;\n readonly value: number;\n readonly tail: number;\n}\n\n/** The trail a point leaves as a value changes: the curve of its equation from where the value began to where it is. */\nexport const TracedPath = traced(component2d({\n key: \"tracedPath\",\n state,\n defaults: { stroke: PLOT_STROKE, width: \"hug\", height: \"hug\" },\n commands: {\n ...omit(PLOT_COMMANDS, \"progressTo\", \"flash\"),\n /** Carry the point on to another value, the trail following it. */\n traceTo: { args: [\"value\"] },\n },\n measure: (_measurer, s) => inkSize(traceTrail(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceTrail(s, reading(s))),\n}), traceTrail);\n\nexport type TracedPath = NodeOf<typeof TracedPath>;\n\nfunction traceTrail(s: TrailValues, read: MarkReading) {\n return tracePlot(s, read, span(s));\n}\n\n/** The span of the free variable the trail covers: from where the value began, or its tail, to where it is. */\nfunction span({ from, value, tail }: TrailValues): Interval {\n const kept = tail > 0 ? Math.min(Math.abs(value - from), tail) : Math.abs(value - from);\n return value >= from ? [value - kept, value] : [value, value + kept];\n}\n", "import {\n component2d,\n Graphics2D,\n Types,\n type NodeOf,\n type Color as _Color,\n\n type NormalizedColor,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { listed, omit, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\nimport { curveValue } from \"../kit/curve\";\nimport { drawLabels, loadFormulas, type Label } from \"../kit/furniture\";\nimport { curveFor, PLANE_ENTRY, PLOT_REF, type GraphPlane } from \"../kit/graph\";\nimport { strokeShape } from \"../kit/mark\";\nimport { anchored } from \"../kit/place\";\n\nconst state = {\n // A dot has no outline worth trimming.\n ...omit(PAINT, \"start\", \"end\"),\n /** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */\n on: PLOT_REF,\n radius: Types.number(7, { min: 0, unit: \"px\" }),\n label: Types.text(\"\", { animatable: false }),\n labelSide: listed([\"above\", \"below\", \"left\", \"right\"], \"above\", { animatable: false }),\n labelSize: Types.number(18, { min: 1, unit: \"px\" }),\n labelColor: Types.color(\"#e5e7eb\"),\n fontFamily: Types.text(\"\", { animatable: false }),\n graph: PLANE_ENTRY,\n /** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */\n value: Types.number(0, { private: true }),\n};\n\n/**\n * A dot at graph coordinates, with an optional label. Named a plot in `on`, it\n * rides that curve: its `x` is where along it, and its height is the curve's.\n */\nexport const PlotPoint = anchored(component2d({\n key: \"plotPoint\",\n state,\n defaults: { fill: \"#e5e7eb\", width: \"hug\", height: \"hug\", value: (s) => heightOf(s.graph, s.on, s.x, s.y) },\n load: (loader, s) => {\n if (s.label !== \"\" && s.fontFamily !== \"\") loader.font(s.fontFamily);\n loadFormulas(loader, [s.label]);\n },\n commands: omit(PAINT_COMMANDS, \"progressTo\", \"flash\"),\n measure: (_measurer, s) => ({ width: s.radius * 2, height: s.radius * 2 }),\n render: (ctx, s) => {\n const size = s.radius * 2;\n const shape = size > 0 ? () => new Graphics2D().ellipse({ x: 0, y: 0, width: size, height: size }) : null;\n painted(\n ctx,\n () => {\n if (shape) ctx.draw(shape().shadow(s.shadow).fill(s.fill));\n if (s.label === \"\") return;\n const gap = s.radius + s.labelSize * 0.45;\n const side = s.labelSide;\n const horizontal = side === \"left\" || side === \"right\";\n const label: Label = {\n text: s.label,\n align: side === \"left\" ? \"right\" : side === \"right\" ? \"left\" : \"center\",\n at: {\n x: horizontal ? (side === \"left\" ? -1 : 1) * gap : 0,\n y: horizontal ? 0 : (side === \"below\" ? -1 : 1) * (gap + s.labelSize / 2),\n },\n };\n ctx.draw(drawLabels([label], { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));\n },\n () => {\n if (shape) strokeShape(ctx, shape, s);\n },\n );\n },\n}), (s: { readonly on: unknown }, plane) => (x, y) => ({ x, y: heightOf(plane, s.on, x, y) }));\n\nexport type PlotPoint = NodeOf<typeof PlotPoint>;\n\n/** The height a point at `x`/`y` sits at: the curve's, when it rides one that has a value there. */\nfunction heightOf(plane: GraphPlane | null, on: unknown, x: number, y: number): number {\n const curve = curveFor(plane, on);\n const height = curve ? curveValue(curve, x) : NaN;\n // Off the end of its curve a point stays where its own `y` puts it rather than vanishing.\n return Number.isFinite(height) ? height : y;\n}\n", "import {\n component2d,\n Types,\n type NodeOf,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { radians } from \"../kit/geometry\";\nimport { PLANE_ENTRY } from \"../kit/graph\";\nimport { drawMark, graphPoint, inkSize, ownPoint, reading, traced, type MarkReading, type MarkState } from \"../kit/mark\";\n\n/** Degrees of arc per drawn segment of a bent arrow. */\nconst BEND_STEP = 4;\n\nconst state = {\n ...omit(PAINT, \"fill\"),\n tail: Types.vector2(),\n head: Types.vector2({ x: 1, y: 1 }),\n /** The arc the arrow sweeps, in degrees: zero is straight, positive bows to its left. */\n bend: Types.number(0, { min: -180, max: 180, unit: \"°\" }),\n graph: PLANE_ENTRY,\n};\n\ninterface ArrowValues {\n readonly tail: Vector2;\n readonly head: Vector2;\n readonly bend: number;\n}\n\n/** A handle on one end of the arrow: where the end is in its own frame, and the graph point a drop there gives. */\nconst end = (which: \"tail\" | \"head\") => ({\n at: (s: ArrowValues & MarkState) => {\n const read = reading(s);\n return ownPoint(read, traceArrow(s, read), s[which]);\n },\n value: (at: Vector2, s: ArrowValues & MarkState) => {\n const read = reading(s);\n return graphPoint(read, traceArrow(s, read), at);\n },\n});\n\n/** An arrow from `tail` to `head`, two graph points; its arrowhead is the stroke's `endCap`. (Not `from`/`to`: every node has a `to`.) */\nexport const VectorArrow = traced(component2d({\n key: \"vectorArrow\",\n state,\n defaults: { stroke: { weight: 4, fill: \"#e5e7eb\", align: \"center\", endCap: \"triangle\" }, width: \"hug\", height: \"hug\" },\n commands: {\n ...omit(PAINT_COMMANDS, \"fillTo\"),\n /** Move either end, in graph coordinates. */\n endpointsTo: { args: [\"tail\", \"head\"] },\n },\n handles: { tail: end(\"tail\"), head: end(\"head\") },\n measure: (_measurer, s) => inkSize(traceArrow(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceArrow(s, reading(s))),\n}), traceArrow);\n\nexport type VectorArrow = NodeOf<typeof VectorArrow>;\n\nfunction traceArrow(s: ArrowValues, { map, shift }: MarkReading): Vector2[][] {\n const a = map.toPoint(s.tail.x + shift.x, s.tail.y + shift.y);\n const b = map.toPoint(s.head.x + shift.x, s.head.y + shift.y);\n const sweep = radians(s.bend);\n const chord = Math.hypot(b.x - a.x, b.y - a.y);\n if (Math.abs(sweep) < 1e-3 || chord === 0) return [[a, b]];\n\n // The circle through both ends that subtends `sweep` at its centre.\n const radius = chord / (2 * Math.sin(Math.abs(sweep) / 2));\n const side = Math.sign(sweep);\n const reach = radius * Math.cos(sweep / 2);\n // The centre sits to the arrow's right for a positive sweep, so the arc bows to its left.\n const cx = (a.x + b.x) / 2 + (side * (b.y - a.y) * reach) / chord;\n const cy = (a.y + b.y) / 2 - (side * (b.x - a.x) * reach) / chord;\n const from = Math.atan2(a.y - cy, a.x - cx);\n const steps = Math.max(8, Math.ceil(Math.abs(s.bend) / BEND_STEP));\n const run: Vector2[] = [];\n for (let i = 0; i <= steps; i++) {\n const angle = from - (sweep * i) / steps;\n run.push({ x: cx + radius * Math.cos(angle), y: cy + radius * Math.sin(angle) });\n }\n return [run];\n}\n", "import {\n component2d,\n type NodeOf,\n type NodeView,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n} from \"@motionscript/sdk\";\nimport { omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport type { Interval } from \"../kit/coords\";\nimport { curveValue } from \"../kit/curve\";\nimport { intervalEntry, PLOT_COLOR } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\nconst state = {\n // An area is only its fill, and has no outline to trim.\n ...omit(PAINT, \"stroke\", \"start\", \"end\"),\n /** The plot that bounds the area, by id. */\n on: PLOT_REF,\n /** A second plot to fill down to, in place of the x axis. */\n under: PLOT_REF,\n domain: intervalEntry([0, 1]),\n graph: PLANE_ENTRY,\n};\n\ninterface AreaValues {\n readonly on: NodeView | null;\n readonly under: NodeView | null;\n readonly domain: Interval;\n}\n\n/** The region between a plot and the x axis, or between two plots, over a span of x. It sits beside the plots it reads, since it may read two. */\nexport const CurveArea = traced(component2d({\n key: \"curveArea\",\n state,\n defaults: { fill: { type: \"solid\", color: PLOT_COLOR, opacity: 0.35 }, width: \"hug\", height: \"hug\" },\n commands: {\n ...omit(PAINT_COMMANDS, \"strokeTo\", \"progressTo\", \"flash\"),\n /** Animate the span of x that is filled: sweep an area open, or slide it along. */\n domainTo: { args: [\"domain\"] },\n },\n measure: (_measurer, s) => inkSize(traceArea(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceArea(s, reading(s)), { closed: true }),\n}), traceArea);\n\nexport type CurveArea = NodeOf<typeof CurveArea>;\n\nfunction traceArea(s: AreaValues, { map, plane }: MarkReading): Vector2[][] {\n const top = curveFor(plane, s.on);\n if (!top) return [];\n const floor = curveFor(plane, s.under, false);\n const [yMin, yMax] = map.yRange;\n const a = Math.max(s.domain[0], map.xRange[0]);\n const b = Math.min(s.domain[1], map.xRange[1]);\n if (!(b > a)) return [];\n\n const width = Math.abs(map.toPoint(b, 0).x - map.toPoint(a, 0).x);\n const steps = Math.max(8, Math.min(600, Math.round(width / 2)));\n // Held inside the system's range, and at the axis where a curve has no value.\n const height = (value: number) => (Number.isFinite(value) ? clamp(value, yMin, yMax) : clamp(0, yMin, yMax));\n const upper: Vector2[] = [];\n const lower: Vector2[] = [];\n for (let i = 0; i <= steps; i++) {\n const x = a + ((b - a) * i) / steps;\n upper.push(map.toPoint(x, height(curveValue(top, x))));\n lower.push(map.toPoint(x, height(floor ? curveValue(floor, x) : 0)));\n }\n return [[...upper, ...lower.reverse()]];\n}\n", "import {\n component2d,\n Types,\n type NodeOf,\n type NodeView,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { listed, omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport type { Interval } from \"../kit/coords\";\nimport { curveValue } from \"../kit/curve\";\nimport { intervalEntry, PLOT_COLOR } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\nexport type RiemannSample = \"left\" | \"right\" | \"center\";\n\n/** More rectangles than this is a filled area with extra steps. */\nconst MAX_RECTANGLES = 2000;\n\nconst state = {\n // Its rectangles are revealed by `dx`, not by trimming their outlines.\n ...omit(PAINT, \"start\", \"end\"),\n on: PLOT_REF,\n domain: intervalEntry([0, 1]),\n /** Each rectangle's width, in graph units. */\n dx: Types.number(0.25, { min: 0.001 }),\n /** Where in its width a rectangle reads the curve's height. */\n sample: listed([\"left\", \"right\", \"center\"], \"left\", { animatable: false }),\n graph: PLANE_ENTRY,\n};\n\ninterface SumValues {\n readonly on: NodeView | null;\n readonly domain: Interval;\n readonly dx: number;\n readonly sample: RiemannSample;\n}\n\n/** Rectangles under a plot, each `dx` wide and as tall as the curve where it is sampled. */\nexport const RiemannSum = traced(component2d({\n key: \"riemannSum\",\n state,\n defaults: {\n fill: { type: \"solid\", color: PLOT_COLOR, opacity: 0.35 },\n stroke: { weight: 1.5, fill: PLOT_COLOR, align: \"center\", join: \"round\" },\n width: \"hug\",\n height: \"hug\",\n },\n commands: {\n ...omit(PAINT_COMMANDS, \"progressTo\", \"flash\"),\n /** Animate the rectangles' width: narrower is the sum closing in on the area. */\n refineTo: { args: [\"dx\"] },\n /** Animate the span of x the rectangles cover. */\n domainTo: { args: [\"domain\"] },\n },\n measure: (_measurer, s) => inkSize(traceSum(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceSum(s, reading(s)), { closed: true }),\n}), traceSum);\n\nexport type RiemannSum = NodeOf<typeof RiemannSum>;\n\nfunction traceSum(s: SumValues, { map, plane }: MarkReading): Vector2[][] {\n const plot = curveFor(plane, s.on);\n const [a, b] = s.domain;\n const dx = s.dx;\n if (!plot || !(b > a) || !(dx > 0)) return [];\n const [yMin, yMax] = map.yRange;\n const base = clamp(0, yMin, yMax);\n const at = s.sample === \"left\" ? 0 : s.sample === \"right\" ? 1 : 0.5;\n const count = Math.min(MAX_RECTANGLES, Math.ceil((b - a) / dx - 1e-9));\n const runs: Vector2[][] = [];\n for (let i = 0; i < count; i++) {\n const left = a + i * dx;\n const right = Math.min(b, left + dx);\n const value = curveValue(plot, left + (right - left) * at);\n if (!Number.isFinite(value)) continue;\n const height = clamp(value, yMin, yMax);\n runs.push([map.toPoint(left, base), map.toPoint(left, height), map.toPoint(right, height), map.toPoint(right, base)]);\n }\n return runs;\n}\n", "import {\n component2d,\n Types,\n type NodeOf,\n type NodeView,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { curveValue, type CurveValues } from \"../kit/curve\";\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\n/** The step a slope is measured over, as a share of the system's width. */\nconst SLOPE_STEP = 1e-4;\n\nconst state = {\n ...omit(PAINT, \"fill\"),\n on: PLOT_REF,\n length: Types.number(260, { min: 0, unit: \"px\" }),\n /** The second point's distance along x; zero is the tangent itself. */\n dx: Types.number(0, { min: 0 }),\n legs: Types.boolean(false, { animatable: false }),\n graph: PLANE_ENTRY,\n /** The slope drawn, in graph units: the curve's at `x`, or the secant's when there is a `dx`. A formula reads it back as `[key.slope]`. */\n slope: Types.number(NaN, { private: true }),\n};\n\ninterface TangentValues {\n readonly x: number;\n readonly on: NodeView | null;\n readonly length: number;\n readonly dx: number;\n readonly legs: boolean;\n}\n\n/** The tangent to a plot at this node's `x`, a fixed length on screen; with a `dx`, the secant through `x` and `x + dx`. */\nexport const TangentLine = traced(component2d({\n key: \"tangentLine\",\n state,\n defaults: {\n stroke: { weight: 3, fill: \"#f59e0b\", align: \"center\", cap: \"round\", join: \"round\" },\n width: \"hug\",\n height: \"hug\",\n slope: (s) => {\n const plot = curveFor(s.graph, s.on);\n return plot ? tangentSlope(plot, s.x, s.dx) : NaN;\n },\n },\n commands: omit(PAINT_COMMANDS, \"fillTo\"),\n measure: (_measurer, s) => inkSize(traceTangent(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceTangent(s, reading(s))),\n}), traceTangent);\n\nexport type TangentLine = NodeOf<typeof TangentLine>;\n\n/** The slope a tangent at `x` draws on `curve`, in graph units: the curve's at `x`, or the secant's to `x + dx`. */\nexport function tangentSlope(curve: CurveValues, x: number, dx = 0): number {\n if (dx > 0) return (curveValue(curve, x + dx) - curveValue(curve, x)) / dx;\n const h = 1e-6 * Math.max(1, Math.abs(x));\n return (curveValue(curve, x + h) - curveValue(curve, x - h)) / (2 * h);\n}\n\nfunction traceTangent(s: TangentValues, { map, plane }: MarkReading): Vector2[][] {\n const plot = curveFor(plane, s.on);\n if (!plot) return [];\n const x = s.x;\n const y = curveValue(plot, x);\n if (!Number.isFinite(y)) return [];\n const half = s.length / 2;\n\n if (s.dx > 0) {\n const y2 = curveValue(plot, x + s.dx);\n if (!Number.isFinite(y2)) return [];\n const a = map.toPoint(x, y);\n const b = map.toPoint(x + s.dx, y2);\n const span = Math.hypot(b.x - a.x, b.y - a.y);\n if (span === 0) return [];\n const reach = Math.max(half, span / 2 + 16);\n const ux = (b.x - a.x) / span;\n const uy = (b.y - a.y) / span;\n const mx = (a.x + b.x) / 2;\n const my = (a.y + b.y) / 2;\n const secant = [{ x: mx - ux * reach, y: my - uy * reach }, { x: mx + ux * reach, y: my + uy * reach }];\n return s.legs ? [secant, [a, map.toPoint(x + s.dx, y), b]] : [secant];\n }\n\n const [xMin, xMax] = map.xRange;\n const h = Number.isFinite(xMax - xMin) ? (xMax - xMin) * SLOPE_STEP : 1e-4;\n const before = curveValue(plot, x - h);\n const after = curveValue(plot, x + h);\n if (!Number.isFinite(before) || !Number.isFinite(after)) return [];\n const p = map.toPoint(x, y);\n const a = map.toPoint(x - h, before);\n const b = map.toPoint(x + h, after);\n const span = Math.hypot(b.x - a.x, b.y - a.y);\n if (span === 0) return [];\n const ux = (b.x - a.x) / span;\n const uy = (b.y - a.y) / span;\n return [[{ x: p.x - ux * half, y: p.y - uy * half }, { x: p.x + ux * half, y: p.y + uy * half }]];\n}\n", "import {\n component2d,\n type NodeOf,\n type NodeView,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { listed, omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { curveValue } from \"../kit/curve\";\nimport { AXIS_COLOR } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\nexport type DropAxis = \"x\" | \"y\" | \"both\";\n\nconst state = {\n ...omit(PAINT, \"fill\"),\n /** A plot to take the point's height from, by id. */\n on: PLOT_REF,\n /** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */\n axis: listed([\"x\", \"y\", \"both\"], \"both\", { animatable: false }),\n graph: PLANE_ENTRY,\n};\n\ninterface DropValues {\n readonly x: number;\n readonly y: number;\n readonly on: NodeView | null;\n readonly axis: DropAxis;\n}\n\n/**\n * Guide lines from a graph point to the axes, reading its coordinates off them.\n * The point is this node's `x`/`y`, or the point of a plot above its `x`.\n */\nexport const DropLines = traced(component2d({\n key: \"dropLines\",\n state,\n defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\", dash: [8, 6] }, width: \"hug\", height: \"hug\" },\n commands: omit(PAINT_COMMANDS, \"fillTo\"),\n measure: (_measurer, s) => inkSize(traceDrops(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceDrops(s, reading(s))),\n}), traceDrops);\n\nexport type DropLines = NodeOf<typeof DropLines>;\n\nfunction traceDrops(s: DropValues, { map, plane }: MarkReading): Vector2[][] {\n const x = s.x;\n const plot = curveFor(plane, s.on);\n const y = plot ? curveValue(plot, x) : s.y;\n if (!Number.isFinite(y)) return [];\n const at = map.toPoint(x, y);\n const runs: Vector2[][] = [];\n // Each line starts on its axis, so drawing it on grows it towards the point.\n if (s.axis !== \"y\") runs.push([map.toPoint(x, clamp(0, map.yRange[0], map.yRange[1])), at]);\n if (s.axis !== \"x\") runs.push([map.toPoint(clamp(0, map.xRange[0], map.xRange[1]), y), at]);\n return runs;\n}\n", "import {\n commandsFor,\n pathOps,\n Types,\n type BoxBounds,\n type NodeView,\n type PaintProps,\n type PathCommand,\n type RenderContext,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { omit, PAINT, PAINT_COMMANDS } from \"./component\";\nimport { LatexMatrix } from \"../tex/matrix\";\nimport { Latex } from \"../tex/node\";\nimport { isFormula, latexPartBounds } from \"../tex/typeset\";\nimport { radians } from \"./geometry\";\nimport { refId } from \"./graph\";\n\n/** A node with parts that can be pointed at by name: a formula's terms. */\nexport interface Parted {\n /** The box of `part`, y-up from the node's centre, or `null` when it has no such part. */\n partBounds(part: string, occurrence?: number): BoxBounds | null;\n}\n\nfunction isParted(node: object): boolean {\n return typeof (node as Partial<Parted>).partBounds === \"function\" || isFormula(node);\n}\n\n/** The box of `part` in `node`: its own `partBounds` answer, or a formula component's by its source. */\nfunction partBoundsOf(node: object, part: string, occurrence: number): BoxBounds | null {\n if (typeof (node as Partial<Parted>).partBounds === \"function\") return (node as Parted).partBounds(part, occurrence);\n return latexPartBounds(node, part, occurrence) ?? null;\n}\n\n/** What a mark is drawn on: a node by id, and one part of it where it has parts. */\nexport interface Target {\n on: string;\n part?: string;\n occurrence?: number;\n}\n\n/** A target on its way to another: `t` of the way from `from`, or from the mark's resting target. */\nexport interface Retarget extends Target {\n from?: Target | null;\n t: number;\n}\n\nexport interface FollowProps extends PaintProps {\n on?: string;\n part?: string;\n occurrence?: number;\n retarget?: Retarget | null;\n}\n\n/** A target's four corners in its mark's own frame, y-up: top left, top right, bottom right, bottom left. */\nexport type Quad = [Vector2, Vector2, Vector2, Vector2];\n\nconst restOf = ({ on, part, occurrence }: Target): Target => ({ on, part, occurrence });\n\nfunction lerpRetarget(from: Retarget | null, to: Retarget | null, t: number): Retarget | null {\n if (t <= 0 || !to) return t < 1 ? from : to;\n return { ...restOf(to), from: from ? restOf(from) : null, t };\n}\n\nconst REF = Types.custom<string, NodeView | null>(\"\", { kind: \"nodeRef\", animatable: false });\nconst HELD_REF = Types.custom<string, NodeView | null, { readonly private: true }>(\"\", { kind: \"nodeRef\", private: true });\n\n/**\n * A mark drawn on another node or one part of a formula (a brace, a box, an\n * underline). It has no size and takes no place in a layout; its selection box is its ink.\n */\nexport const FOLLOW_STATE = {\n // It is only an outline.\n ...omit(PAINT, \"fill\"),\n /** The node this mark is drawn on, by id. Left empty, it is the formula the mark sits inside. */\n on: REF,\n /** One part of that node, by its source, where it has parts: `x^2` of a formula. */\n part: Types.text(\"\", { animatable: false }),\n /** Which of the places the part is written, counted from 1. */\n occurrence: Types.number(1, { min: 1, step: 1, animatable: false }),\n /** Where a `retargetTo` has taken the mark, and how far along it is. Not an author's to state. */\n retarget: Types.custom<Retarget | null>(null, { lerp: lerpRetarget }),\n /** The nodes the retarget names, there and where it set out from, read as nodes. */\n retargetOn: HELD_REF,\n retargetFrom: HELD_REF,\n};\n\nexport const FOLLOW_COMMANDS = {\n ...omit(PAINT_COMMANDS, \"fillTo\"),\n ...commandsFor(FOLLOW_STATE, {\n /** Move the mark onto another node, or another part. */\n retargetTo: {\n // No defaults for the node and the part: one left out keeps the mark's own.\n args: {\n on: Types.custom<string | undefined>(undefined, { kind: \"nodeRef\" }),\n part: Types.custom<string | undefined>(undefined, { kind: \"text\" }),\n occurrence: Types.number(1, { min: 1, step: 1 }),\n },\n run: (timeline, s) => {\n const next = timeline.args;\n const held = s.retarget ?? restingOf(s);\n const to: Retarget = {\n on: next.on ?? held.on,\n part: next.part ?? (next.on ? \"\" : held.part),\n occurrence: next.occurrence ?? 1,\n t: 1,\n };\n const from = s.retarget;\n return timeline.animate((t) => {\n const retarget = lerpRetarget(from, to, t);\n return { retarget, retargetOn: retarget?.on ?? \"\", retargetFrom: retarget?.from?.on ?? \"\" };\n });\n },\n },\n }),\n};\n\nexport interface FollowValues {\n readonly on: NodeView | null;\n readonly part: string;\n readonly occurrence: number;\n readonly retarget: Retarget | null;\n readonly retargetOn: NodeView | null;\n readonly retargetFrom: NodeView | null;\n}\n\nfunction restingOf(s: FollowValues): Target {\n return { on: refId(s.on), part: s.part, occurrence: s.occurrence };\n}\n\nconst containers = new WeakMap<object, NodeView | null>();\n\n/** The formula a follow mark sits in, as its render last found it: its bounds and handles read it where there is no context to ask. */\nexport function container(ctx: RenderContext | null, s: object): NodeView | null {\n if (!ctx) return containers.get(s) ?? null;\n const found = ctx.ancestor(Latex) ?? ctx.ancestor(LatexMatrix);\n const parted = found && isParted(found.state) ? found : null;\n containers.set(s, parted);\n return parted;\n}\n\n/** The node the mark rests on: the one `on` names, or the formula it sits in. */\nexport function resting(s: FollowValues, parted: NodeView | null): NodeView | null {\n return s.on ?? parted;\n}\n\n/** The target's corners now: its resting one, or part-way to where a `retargetTo` is taking it. */\nexport function followedQuad(s: FollowValues, parted: NodeView | null): Quad | null {\n const state = s.retarget;\n const rest = (): Quad | null => quadOf(resting(s, parted), s);\n if (!state) return rest();\n const to = quadOf(state.on === \"\" ? parted : s.retargetOn, state);\n const from = state.from ? quadOf(state.from.on === \"\" ? parted : s.retargetFrom, state.from) : rest();\n if (!from || !to || state.t >= 1) return to ?? from;\n return lerpQuad(from, to, state.t);\n}\n\n/** Where `target` is, as the mark sees it; `null` when it names no node or part. */\nfunction quadOf(node: NodeView | null, target: Omit<Target, \"on\">): Quad | null {\n if (!node) return null;\n const box: BoxBounds | null =\n target.part && isParted(node.state)\n ? partBoundsOf(node.state, target.part, target.occurrence || 1)\n : { x: 0, y: 0, width: node.size.width, height: node.size.height };\n if (!box) return null;\n const frame = node.frame;\n const turn = radians(frame.rotation);\n const cos = Math.cos(turn);\n const sin = Math.sin(turn);\n // The engine's turn is clockwise, in a y-up frame.\n const place = (x: number, y: number): Vector2 => ({\n x: frame.x + (cos * x + sin * y) * frame.scale,\n y: frame.y + (-sin * x + cos * y) * frame.scale,\n });\n const w = box.width / 2;\n const h = box.height / 2;\n return [place(box.x - w, box.y + h), place(box.x + w, box.y + h), place(box.x + w, box.y - h), place(box.x - w, box.y - h)];\n}\n\nfunction lerpQuad(a: Quad, b: Quad, t: number): Quad {\n return a.map((from, i) => ({ x: from.x + (b[i].x - from.x) * t, y: from.y + (b[i].y - from.y) * t })) as Quad;\n}\n\n/** The box of an outline, as a follow mark's bounds: it has no size of its own, so its ink is what is selected. */\nexport function outlineBounds(outline: readonly PathCommand[]): BoxBounds {\n const ink = pathOps.bounds(outline as PathCommand[]);\n if (!ink) return { x: 0, y: 0, width: 0, height: 0 };\n return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };\n}\n\n/** Every drawn point's centre frame: the mark's own centre, so its outline is where it says. */\nexport const OWN_FRAME: [number, number, number, number] = [-1, -1, 1, 1];\n\nexport const add = (a: Vector2, b: Vector2, k = 1): Vector2 => ({ x: a.x + b.x * k, y: a.y + b.y * k });\nexport const between = (a: Vector2, b: Vector2, t = 0.5): Vector2 => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });\n\n/** The unit vector from `a` to `b`, and its length; a zero one points right. */\nexport function heading(a: Vector2, b: Vector2): { unit: Vector2; length: number } {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const length = Math.hypot(dx, dy);\n return { unit: length === 0 ? { x: 1, y: 0 } : { x: dx / length, y: dy / length }, length };\n}\n\n/** A quad grown by `by` pixels on every side, along its own edges. */\nexport function grown(quad: Quad, by: number): Quad {\n const [tl, tr, br, bl] = quad;\n const across = heading(tl, tr).unit;\n const up = heading(bl, tl).unit;\n return [\n add(add(tl, across, -by), up, by),\n add(add(tr, across, by), up, by),\n add(add(br, across, by), up, -by),\n add(add(bl, across, -by), up, -by),\n ];\n}\n", "import type { PathCommand, Vector2 } from \"@motionscript/sdk\";\nimport { add, between, heading } from \"./follow\";\n\n/** How far a quarter circle's control points sit along its tangents, as a share of its radius. */\nconst QUARTER = 0.5523;\n\n/**\n * A curly brace from `from` to `to`, bulging toward `out` (a unit vector) and\n * `reach` deep at its tip: what a brace node draws, and a sample space beside\n * its parts. Path commands, y-up.\n */\nexport function braceOutline(from: Vector2, to: Vector2, out: Vector2, reach: number): PathCommand[] {\n const { unit, length } = heading(from, to);\n if (length === 0) return [];\n const r = Math.min(reach / 2, length / 4);\n const mid = between(from, to);\n const lift = (p: Vector2, k: number) => add(p, out, k * r);\n const along = (p: Vector2, k: number) => add(p, unit, k * r);\n const h = QUARTER;\n const curve = (c1: Vector2, c2: Vector2, end: Vector2): PathCommand => ({\n type: \"C\", x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: end.x, y: end.y,\n });\n const a = lift(along(from, 1), 1);\n const b = lift(along(mid, -1), 1);\n const tip = lift(mid, 2);\n const c = lift(along(mid, 1), 1);\n const d = lift(along(to, -1), 1);\n return [\n { type: \"M\", x: from.x, y: from.y },\n curve(lift(from, h), lift(along(from, 1 - h), 1), a),\n { type: \"L\", x: b.x, y: b.y },\n curve(lift(along(mid, -1 + h), 1), lift(mid, 2 - h), tip),\n curve(lift(mid, 2 - h), lift(along(mid, 1 - h), 1), c),\n { type: \"L\", x: d.x, y: d.y },\n curve(lift(along(to, -1 + h), 1), lift(to, h), to),\n ];\n}\n", "import {\n component2d,\n Graphics2D,\n Types,\n type NodeOf,\n type NodeView,\n type Color as _Color,\n type NormalizedColor,\n type PathCommand,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { braceOutline } from \"../kit/brace\";\nimport { listed, painted } from \"../kit/component\";\nimport {\n add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, heading, outlineBounds, OWN_FRAME, resting,\n type FollowValues, type Quad,\n} from \"../kit/follow\";\nimport { drawLabels, loadFormulas } from \"../kit/furniture\";\nimport { strokeShape } from \"../kit/mark\";\n\nexport type BraceSide = \"below\" | \"above\" | \"left\" | \"right\";\n\n/** The edge of a target a brace runs along, as two corner indexes of its quad, read with the brace's bulge to the left. */\nconst EDGE: Record<BraceSide, [number, number]> = {\n below: [2, 3],\n above: [0, 1],\n left: [3, 0],\n right: [1, 2],\n};\n\nconst state = {\n ...FOLLOW_STATE,\n side: listed([\"below\", \"above\", \"left\", \"right\"], \"below\", { animatable: false }),\n /** The two ends of a brace that follows nothing, from the brace's own position. It bulges to the left of tail to head. */\n tail: Types.vector2({ x: -80, y: 0 }),\n head: Types.vector2({ x: 80, y: 0 }),\n /** The room between the target and the brace. (`gap` is a layout's.) */\n clearance: Types.number(8, { min: 0, unit: \"px\" }),\n /** How far the brace reaches from its ends to its tip. (`depth` is a node's place in 3D.) */\n reach: Types.number(18, { min: 2, unit: \"px\" }),\n label: Types.text(\"\", { animatable: false }),\n labelSize: Types.number(28, { min: 1, unit: \"px\" }),\n labelColor: Types.color(\"#e5e7eb\"),\n fontFamily: Types.text(\"\", { animatable: false }),\n};\n\ninterface BraceValues extends FollowValues {\n readonly side: BraceSide;\n readonly tail: Vector2;\n readonly head: Vector2;\n readonly clearance: number;\n readonly reach: number;\n}\n\n/** Whether the brace follows nothing, and so spans its own two points. */\nfunction spans(s: BraceValues, parted: NodeView | null): boolean {\n return !s.retarget && resting(s, parted) === null;\n}\n\n/** No target: the span itself, as an edge with nothing above it. */\nfunction quadOf(s: BraceValues, parted: NodeView | null): Quad | null {\n return spans(s, parted) ? [s.head, s.tail, s.tail, s.head] : followedQuad(s, parted);\n}\n\n/** The edge the brace runs along, pushed out by the gap, and the way it bulges. */\nfunction edgeOf(s: BraceValues, parted: NodeView | null, quad: Quad): { from: Vector2; to: Vector2; out: Vector2 } {\n const [i, j] = spans(s, parted) ? [1, 0] : EDGE[s.side];\n const { unit } = heading(quad[i], quad[j]);\n // Left of the edge's own direction, in a y-up frame.\n const out = { x: -unit.y, y: unit.x };\n return { from: add(quad[i], out, s.clearance), to: add(quad[j], out, s.clearance), out };\n}\n\nfunction outline(s: BraceValues, parted: NodeView | null): PathCommand[] {\n const quad = quadOf(s, parted);\n if (!quad) return [];\n const { from, to, out } = edgeOf(s, parted, quad);\n return braceOutline(from, to, out, s.reach);\n}\n\n/** One of the two ends to drag, while the brace spans them. */\nconst end = (which: \"tail\" | \"head\") => ({\n at: (s: BraceValues) => (spans(s, container(null, s)) ? s[which] : null),\n value: (at: Vector2) => ({ x: at.x, y: at.y }),\n});\n\n/**\n * A curly brace along one side of a node or of a part of a formula, or between\n * two points when it names neither, with an optional label at its tip. A label\n * written between dollar signs is typeset.\n */\nexport const CurlyBrace = component2d({\n key: \"curlyBrace\",\n state,\n defaults: { stroke: { weight: 3, fill: \"#e5e7eb\", align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\n load: (loader, s) => {\n if (s.label !== \"\" && s.fontFamily !== \"\") loader.font(s.fontFamily);\n loadFormulas(loader, [s.label]);\n },\n commands: FOLLOW_COMMANDS,\n handles: { tail: end(\"tail\"), head: end(\"head\") },\n measure: () => ({ width: 0, height: 0 }),\n bounds: (_size, s) => outlineBounds(outline(s, container(null, s))),\n render: (ctx, s) => {\n const parted = container(ctx, s);\n const data = outline(s, parted);\n const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;\n painted(\n ctx,\n () => {\n if (shape) ctx.draw(shape().shadow(s.shadow).fill([]));\n if (s.label === \"\") return;\n const quad = quadOf(s, parted);\n if (!quad) return;\n const { from, to, out } = edgeOf(s, parted, quad);\n const reach = Math.min(s.reach, heading(from, to).length / 2) + s.labelSize * 0.75;\n const at = add(between(from, to), out, reach);\n const align = out.x > 0.5 ? \"left\" : out.x < -0.5 ? \"right\" : \"center\";\n const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor };\n ctx.draw(drawLabels([{ text: s.label, at, align }], style));\n },\n () => {\n if (shape) strokeShape(ctx, shape, s);\n },\n );\n },\n});\n\nexport type CurlyBrace = NodeOf<typeof CurlyBrace>;\n", "import {\n component2d,\n Graphics2D,\n Types,\n type NodeOf,\n type Color as _Color,\n\n type NormalizedColor,\n type PathCommand,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { listed, omit, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\nimport { outlineBounds, OWN_FRAME } from \"../kit/follow\";\nimport { drawLabels, loadFormulas } from \"../kit/furniture\";\nimport { radians } from \"../kit/geometry\";\nimport { strokeShape } from \"../kit/mark\";\n\n/** Degrees of arc per drawn segment. */\nconst ARC_STEP = 4;\n/** How close to a right angle `auto` draws the square. */\nconst RIGHT_SLOP = 0.5;\n\nconst point = (radius: number, degrees: number) => {\n const turn = radians(degrees);\n return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };\n};\n\nconst state = {\n // It is only an outline.\n ...omit(PAINT, \"fill\"),\n fromAngle: Types.number(0, { unit: \"°\" }),\n toAngle: Types.number(60, { unit: \"°\" }),\n radius: Types.number(48, { min: 0, unit: \"px\" }),\n /** `auto` draws the square where the angle is a right one. */\n corner: listed([\"auto\", \"arc\", \"square\"], \"auto\", { animatable: false }),\n /** Text, a formula between dollar signs, or `°` for the angle's own size. */\n label: Types.text(\"\", { animatable: false }),\n labelSize: Types.number(24, { min: 1, unit: \"px\" }),\n labelColor: Types.color(\"#e5e7eb\"),\n fontFamily: Types.text(\"\", { animatable: false }),\n /** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */\n value: Types.number(0, { private: true }),\n};\n\ninterface AngleValues {\n readonly fromAngle: number;\n readonly toAngle: number;\n readonly radius: number;\n readonly corner: \"arc\" | \"square\" | \"auto\";\n}\n\n/**\n * The mark of an angle at the node's own position: an arc from one direction\n * to another, or the small square of a right angle, with an optional label.\n * Directions are degrees counter-clockwise from the right, so binding one to a\n * variable opens and closes the angle. A label of `°` shows the angle's size.\n */\nexport const AngleMark = component2d({\n key: \"angleMark\",\n state,\n defaults: { stroke: { weight: 3, fill: \"#e5e7eb\", align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\", value: (s) => angleOf(s) },\n load: (loader, s) => {\n if (s.label !== \"\" && s.fontFamily !== \"\") loader.font(s.fontFamily);\n loadFormulas(loader, [s.label]);\n },\n commands: {\n ...omit(PAINT_COMMANDS, \"fillTo\"),\n /** Grow or shrink the mark. */\n radiusTo: { args: [\"radius\"] },\n },\n measure: () => ({ width: 0, height: 0 }),\n bounds: (_size, s) => outlineBounds(outline(s)),\n render: (ctx, s) => {\n const data = outline(s);\n const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;\n painted(\n ctx,\n () => {\n if (shape) ctx.draw(shape().shadow(s.shadow).fill([]));\n if (s.label === \"\" || s.radius <= 0) return;\n const text = s.label === \"°\" ? `${Math.round(Math.abs(s.value) * 10) / 10}°` : s.label;\n const at = point(s.radius + s.labelSize * 0.9, (s.fromAngle + s.toAngle) / 2);\n const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor };\n ctx.draw(drawLabels([{ text, at, align: \"center\" }], style));\n },\n () => {\n if (shape) strokeShape(ctx, shape, s);\n },\n );\n },\n});\n\nexport type AngleMark = NodeOf<typeof AngleMark>;\n\n/** The angle a mark marks, in degrees: positive counter-clockwise. */\nexport function angleOf(s: Pick<AngleValues, \"fromAngle\" | \"toAngle\">): number {\n return s.toAngle - s.fromAngle;\n}\n\nfunction outline({ fromAngle, toAngle, radius, corner }: AngleValues): PathCommand[] {\n const sweep = toAngle - fromAngle;\n if (radius <= 0 || sweep === 0) return [];\n const square = corner === \"square\" || (corner === \"auto\" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);\n if (square) {\n const side = radius * 0.6;\n const a = point(side, fromAngle);\n const b = point(side, toAngle);\n return [\n { type: \"M\", x: a.x, y: a.y },\n { type: \"L\", x: a.x + b.x, y: a.y + b.y },\n { type: \"L\", x: b.x, y: b.y },\n ];\n }\n const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));\n const out: PathCommand[] = [];\n for (let i = 0; i <= steps; i++) {\n const p = point(radius, fromAngle + (sweep * i) / steps);\n out.push({ type: i === 0 ? \"M\" : \"L\", x: p.x, y: p.y });\n }\n return out;\n}\n", "import {\n component2d,\n Graphics2D,\n Types,\n type NodeOf,\n type NodeView,\n type PathCommand,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { listed, painted } from \"../kit/component\";\nimport {\n add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, grown, heading, outlineBounds, OWN_FRAME, type FollowValues, type Quad,\n} from \"../kit/follow\";\nimport { strokeShape } from \"../kit/mark\";\n\nexport type EmphasisShape = \"box\" | \"circle\" | \"underline\" | \"cross\";\n\n/** How far a cubic's handle reaches to draw a quarter of an ellipse. */\nconst QUARTER = 0.5523;\n\nconst line = (a: Vector2, b: Vector2): PathCommand[] => [\n { type: \"M\", x: a.x, y: a.y },\n { type: \"L\", x: b.x, y: b.y },\n];\n\nconst SHAPES: Record<EmphasisShape, (quad: Quad, gap: number) => PathCommand[]> = {\n box: (quad, gap) => {\n const [tl, tr, br, bl] = grown(quad, gap);\n return [{ type: \"M\", x: tl.x, y: tl.y }, ...[tr, br, bl].map((p): PathCommand => ({ type: \"L\", x: p.x, y: p.y })), { type: \"Z\" }];\n },\n // The ellipse through the grown box's corners.\n circle: (quad, gap) => {\n const [tl, tr, br, bl] = grown(quad, gap);\n const centre = between(tl, br);\n const across = { x: ((tr.x - tl.x) / 2) * Math.SQRT2, y: ((tr.y - tl.y) / 2) * Math.SQRT2 };\n const up = { x: ((tl.x - bl.x) / 2) * Math.SQRT2, y: ((tl.y - bl.y) / 2) * Math.SQRT2 };\n const at = (a: number, u: number) => add(add(centre, across, a), up, u);\n const arc = (c1: Vector2, c2: Vector2, end: Vector2): PathCommand => ({\n type: \"C\", x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: end.x, y: end.y,\n });\n const k = QUARTER;\n const start = at(0, 1);\n return [\n { type: \"M\", x: start.x, y: start.y },\n arc(at(k, 1), at(1, k), at(1, 0)),\n arc(at(1, -k), at(k, -1), at(0, -1)),\n arc(at(-k, -1), at(-1, -k), at(-1, 0)),\n arc(at(-1, k), at(-k, 1), start),\n { type: \"Z\" },\n ];\n },\n underline: (quad, gap) => {\n const [, , br, bl] = quad;\n const down = heading(quad[0], bl).unit;\n return line(add(bl, down, gap), add(br, down, gap));\n },\n cross: (quad, gap) => {\n const [tl, tr, br, bl] = grown(quad, gap);\n return [...line(tl, br), ...line(bl, tr)];\n },\n};\n\nconst state = {\n ...FOLLOW_STATE,\n shape: listed([\"box\", \"circle\", \"underline\", \"cross\"], \"box\", { animatable: false }),\n /** The room between the target and the mark. (`gap` is a layout's.) */\n clearance: Types.number(10, { unit: \"px\" }),\n};\n\ninterface EmphasisValues extends FollowValues {\n readonly shape: EmphasisShape;\n readonly clearance: number;\n}\n\nfunction outline(s: EmphasisValues, parted: NodeView | null): PathCommand[] {\n const quad = followedQuad(s, parted);\n return quad ? SHAPES[s.shape](quad, s.clearance) : [];\n}\n\n/**\n * A box, a circle, an underline or a cross drawn on a node, or on one part of\n * a formula. `progressTo` draws it on, and `retargetTo` slides it to another.\n */\nexport const EmphasisMark = component2d({\n key: \"emphasisMark\",\n state,\n defaults: { stroke: { weight: 3, fill: \"#facc15\", align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\n commands: FOLLOW_COMMANDS,\n measure: () => ({ width: 0, height: 0 }),\n bounds: (_size, s) => outlineBounds(outline(s, container(null, s))),\n render: (ctx, s) => {\n const data = outline(s, container(ctx, s));\n const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;\n painted(\n ctx,\n () => {\n if (shape) ctx.draw(shape().shadow(s.shadow).fill([]));\n },\n () => {\n if (shape) strokeShape(ctx, shape, s);\n },\n );\n },\n});\n\nexport type EmphasisMark = NodeOf<typeof EmphasisMark>;\n", "import { Fills, Graphics2D, Mat, Tex, type Color, type Graphics3D, type SurfaceTexture3D, type Vector3 } from \"@motionscript/sdk\";\nimport { createBoundedCache } from \"../kit/cache\";\n\n/** Text in a 3D graph: a camera-facing card, so a number reads square-on from wherever the scene is seen. */\n\nexport interface LabelStyle3D {\n /** The height of the text's em, in scene units. */\n size: number;\n color: Color;\n fontFamily: string;\n}\n\n/** The em the text is rasterized at, in buffer pixels, and the card's height around it. */\nconst EM = 64;\nconst CARD_HEIGHT = 96;\n\n// A texture's identity is its source object, so one text in one style is one source for as long as it is asked for.\nconst cards = createBoundedCache<{ texture: SurfaceTexture3D; width: number }>(256);\n\nfunction card(text: string, style: LabelStyle3D): { texture: SurfaceTexture3D; width: number } {\n const key = `${style.fontFamily}|${JSON.stringify(style.color)}|${text}`;\n const hit = cards.get(key);\n if (hit) return hit;\n const width = Math.min(1024, Math.max(128, Math.ceil((text.length * EM * 0.62 + EM) / 32) * 32));\n const source = new Graphics2D()\n .text({\n text,\n fontSize: EM,\n ...(style.fontFamily === \"\" ? {} : { fontFamily: style.fontFamily }),\n wrap: false,\n width,\n textAlign: \"center\",\n })\n .fill(Fills.color(style.color));\n // Its pixels never change, so the renderer rasterizes it once rather than every frame.\n const texture: SurfaceTexture3D = { ...Tex.surface(source, { width, height: CARD_HEIGHT }), static: true, identity: `label3d:${key}` };\n const made = { texture, width };\n cards.set(key, made);\n return made;\n}\n\n/** Draw `text` centred on `at`, a local point. */\nexport function drawLabel3D(g3: Graphics3D, text: string, at: Vector3, style: LabelStyle3D): void {\n if (text === \"\" || !(style.size > 0)) return;\n const { texture, width } = card(text, style);\n const height = (style.size * CARD_HEIGHT) / EM;\n g3.sprite({\n material: Mat.sprite({ map: texture, transparent: true, depthWrite: false }),\n position: at,\n scale: [(height * width) / CARD_HEIGHT, height, 1],\n });\n}\n", "import {\n createContext,\n Types,\n type ChildSpace3D,\n type Type,\n type Vector3,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Context as _Context,\n} from \"@motionscript/sdk\";\nimport type { Interval } from \"../kit/coords\";\n\n/**\n * A 3D graph's coordinates, as its axes' local space sees them. A graph is\n * right-handed with z up, and the scene has y up, so graph x, y and z run along\n * the scene's z, x and y: looked at head-on, y is to the right and z is up.\n */\nexport interface GraphSpace extends ChildSpace3D {\n readonly xRange: Interval;\n readonly yRange: Interval;\n readonly zRange: Interval;\n /** Changes exactly when the mapping does: what a mark's geometry is cached under. */\n readonly revision: string;\n /** A graph step as a local one: what a mark's own geometry is drawn in. */\n offset(x: number, y: number, z: number): Vector3;\n}\n\n/** The space of a box `lengths` on a side, in scene units, showing the three ranges, centred on its node. */\nexport function graphSpace(xRange: Interval, yRange: Interval, zRange: Interval, lengths: Vector3): GraphSpace {\n const ux = unit(xRange, lengths.x);\n const uy = unit(yRange, lengths.y);\n const uz = unit(zRange, lengths.z);\n const cx = (xRange[0] + xRange[1]) / 2;\n const cy = (yRange[0] + yRange[1]) / 2;\n const cz = (zRange[0] + zRange[1]) / 2;\n return {\n xRange,\n yRange,\n zRange,\n revision: [xRange, yRange, zRange, lengths.x, lengths.y, lengths.z].join(\"|\"),\n toLocal: (x, y, z) => ({ x: (y - cy) * uy, y: (z - cz) * uz, z: (x - cx) * ux }),\n offset: (x, y, z) => ({ x: y * uy, y: z * uz, z: x * ux }),\n };\n}\n\nfunction unit([min, max]: Interval, length: number): number {\n const span = max - min;\n return span > 0 ? length / span : 0;\n}\n\n/** A 3D graph, as the marks inside it see it: its coordinates as they stand now. */\nexport interface Graph3D {\n space(): GraphSpace;\n}\n\n/** The graph a mark is inside: `axes3d` provides itself to everything in it. */\nexport const GRAPH_3D = createContext<Graph3D | null>(null, \"math:graph3d\");\n\n/** The entry a mark reads its graph through, set from the nearest `axes3d` above it; `null` outside one. */\nexport function graphEntry(): Type<Graph3D | null, Graph3D | null, true> {\n return Types.custom<Graph3D | null, Graph3D | null, { readonly private: true }>(null, {\n private: true,\n inherit: (use) => use(GRAPH_3D),\n });\n}\n\n/** The graph space a mark with a {@link graphEntry} is drawn in, or `null` outside a graph. */\nexport function graphOf(mark: { readonly graph: Graph3D | null }): GraphSpace | null {\n return mark.graph?.space() ?? null;\n}\n\n/** A unit quaternion turning the scene's +y, the way a cylinder or a cone points, onto `direction`. */\nexport function aim(direction: Vector3): { x: number; y: number; z: number; w: number } {\n const length = Math.hypot(direction.x, direction.y, direction.z);\n if (!(length > 0)) return { x: 0, y: 0, z: 0, w: 1 };\n const dx = direction.x / length;\n const dy = direction.y / length;\n const dz = direction.z / length;\n // Straight down is the one turn with no single axis: any in the ground plane will do.\n if (dy < -1 + 1e-9) return { x: 1, y: 0, z: 0, w: 0 };\n const w = 1 + dy;\n const norm = Math.hypot(dz, dx, w);\n return { x: dz / norm, y: 0, z: -dx / norm, w: w / norm };\n}\n", "import {\n component2d,\n Flow,\n Geo,\n Graphics3D,\n Mat,\n Paint,\n provides,\n Shapes,\n Types,\n View3D,\n type NodeOf,\n type Scene3D,\n type Transform3D,\n type Values,\n type Vector3,\n type Vector3Input,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type CornerRadiusResolved as _CornerRadiusResolved,\n type CornerStyleResolved as _CornerStyleResolved,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Color as _Color,\n\n type NormalizedColor as _NormalizedColor,\n type PostEffect3D as _PostEffect3D,\n type RectCornerRadius as _RectCornerRadius,\n type RectCornerStyle as _RectCornerStyle,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Shadows3D as _Shadows3D,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n type ToneMapping3D as _ToneMapping3D,\n type Vector2 as _Vector2,\n} from \"@motionscript/sdk\";\nimport type { Interval } from \"../kit/coords\";\nimport { AXIS_COLOR, intervalEntry } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { formatTick, ticksFor } from \"../kit/ticks\";\nimport { drawLabel3D, type LabelStyle3D } from \"./label3d\";\nimport { GRAPH_3D, graphSpace, type Graph3D, type GraphSpace } from \"./space\";\n\n/** How many pixels of a 2D axis one scene unit counts as, when an axis picks its own tick spacing. */\nconst UNIT_AS_PIXELS = 64;\n\ntype AxisName = \"x\" | \"y\" | \"z\";\n\n/** The turn that lays a shape built along the scene's +y along each graph axis. */\nconst ALONG: Record<AxisName, Vector3Input> = { x: [90, 0, 0], y: [0, 0, -90], z: [0, 0, 0] };\n\n/** The graph axis each axis's tick marks lie along. */\nconst TICK_ALONG: Record<AxisName, AxisName> = { x: \"y\", y: \"x\", z: \"y\" };\n\n/** The axes' own entries, beside a 3D canvas's. */\nconst own = {\n xRange: intervalEntry([-3, 3]),\n yRange: intervalEntry([-3, 3]),\n zRange: intervalEntry([-2, 2]),\n /** How long each axis is drawn, in scene units. */\n xLength: Types.number(6, { min: 0.01, step: 0.1 }),\n yLength: Types.number(6, { min: 0.01, step: 0.1 }),\n zLength: Types.number(4, { min: 0.01, step: 0.1 }),\n /** The spacing of each axis's ticks; zero picks a tidy one for the axis's length. */\n xStep: Types.number(0, { min: 0 }),\n yStep: Types.number(0, { min: 0 }),\n zStep: Types.number(0, { min: 0 }),\n color: Types.color(AXIS_COLOR),\n /** The radius of an axis line, in scene units. */\n thickness: Types.number(0.02, { min: 0, step: 0.005 }),\n tips: Types.boolean(true, { animatable: false }),\n ticks: Types.boolean(true, { animatable: false }),\n tickSize: Types.number(0.16, { min: 0, step: 0.01 }),\n /** Lines across the plane the x and y axes lie in, at each of their ticks. */\n grid: Types.boolean(false, { animatable: false }),\n /** (`gridColor` is the viewport's own reference grid.) */\n gridLineColor: Types.color(\"#374151\"),\n /** A number at each tick. */\n labels: Types.boolean(false, { animatable: false }),\n /** The height of a label's text, in scene units. */\n labelSize: Types.number(0.26, { min: 0.01, step: 0.01 }),\n labelColor: Types.color(AXIS_COLOR),\n fontFamily: Types.text(\"\", { animatable: false }),\n /** A title at the positive end of each axis. */\n xLabel: Types.text(\"x\", { animatable: false }),\n yLabel: Types.text(\"y\", { animatable: false }),\n zLabel: Types.text(\"z\", { animatable: false }),\n};\n\ntype AxesValues = Values<typeof own>;\n\n/** A 3D graph: three axes through a box of graph coordinates, z up, seen through its own camera. Its 3D children sit in graph coordinates. */\nexport const Axes3d = component2d({\n key: \"axes3d\",\n state: { ...Paint.state, ...Flow.state, ...Shapes.corners, ...View3D.state, ...own },\n defaults: { width: \"fill\", height: \"fill\" },\n commands: {\n ...Paint.commands,\n ...View3D.commands,\n /** Animate the window of values the axes show; everything drawn in them follows. */\n rangeTo: { args: [\"xRange\", \"yRange\", \"zRange\"] },\n },\n allowedChildren: [\"2d\", \"3d\"],\n load: (loader, s) => {\n View3D.load(loader, furnish(s));\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\n },\n provide: (s) => [provides(GRAPH_3D, graphOfAxes(s))],\n space: (s) => axesSpace(s),\n measure: (measurer, s, children) => Flow.measure(measurer, s, children, Paint.inset(s)),\n layout: (box, s, children) => Flow.layout(box, s, children, Paint.inset(s)),\n render: (ctx, s) => View3D.draw(ctx, s, furnish(s)),\n});\n\nexport type Axes3d = NodeOf<typeof Axes3d>;\n\n/** The axes' own drawing, added to the scene: what `render` draws and `load` declares. */\nfunction furnish(s: AxesValues): (scene: Scene3D) => void {\n return (scene) => scene.draw(furniture(s));\n}\n\n/** The last space worked out for each axes, kept while its ranges and lengths are unchanged. */\nconst spaces = new WeakMap<object, { readonly key: string; readonly space: GraphSpace }>();\n\n/** The coordinates of a 3D graph: what its children's `x`, `y` and `z` are in. */\nfunction axesSpace(s: AxesValues): GraphSpace {\n const { xRange, yRange, zRange, xLength, yLength, zLength } = s;\n const key = [xRange, yRange, zRange, xLength, yLength, zLength].join(\"|\");\n let kept = spaces.get(s);\n if (kept?.key !== key) spaces.set(s, (kept = { key, space: graphSpace(xRange, yRange, zRange, { x: xLength, y: yLength, z: zLength }) }));\n return kept.space;\n}\n\n// One per axes, so the context its subtree holds is the same from frame to frame.\nconst graphs = new WeakMap<object, Graph3D>();\n\nfunction graphOfAxes(s: AxesValues): Graph3D {\n let graph = graphs.get(s);\n if (!graph) graphs.set(s, (graph = { space: () => axesSpace(s) }));\n return graph;\n}\n\n/** The axes, their ticks, numbers and titles, and the grid, in the scene's units. */\nfunction furniture(s: AxesValues): Graphics3D {\n const space = axesSpace(s);\n const g3 = new Graphics3D();\n const ranges: Record<AxisName, Interval> = { x: space.xRange, y: space.yRange, z: space.zRange };\n const lengths: Record<AxisName, number> = { x: s.xLength, y: s.yLength, z: s.zLength };\n const steps: Record<AxisName, number> = { x: s.xStep, y: s.yStep, z: s.zStep };\n const titles: Record<AxisName, string> = { x: s.xLabel, y: s.yLabel, z: s.zLabel };\n // Where each axis is crossed by the other two: their zero, or the nearest end of a range without one.\n const cross: Record<AxisName, number> = {\n x: clamp(0, ranges.x[0], ranges.x[1]),\n y: clamp(0, ranges.y[0], ranges.y[1]),\n z: clamp(0, ranges.z[0], ranges.z[1]),\n };\n const at = (axis: AxisName, value: number, shift: Partial<Record<AxisName, number>> = {}): Vector3 => {\n const point = { ...cross, [axis]: value };\n const local = space.toLocal(point.x, point.y, point.z);\n const moved = space.offset(0, 0, 0);\n for (const key of [\"x\", \"y\", \"z\"] as const) {\n const by = shift[key];\n if (by === undefined) continue;\n // A shift is in scene units, along the graph axis it names.\n if (key === \"x\") moved.z += by;\n else if (key === \"y\") moved.x += by;\n else moved.y += by;\n }\n return { x: local.x + moved.x, y: local.y + moved.y, z: local.z + moved.z };\n };\n\n const { thickness, tickSize } = s;\n const paint = Mat.basic({ color: s.color });\n const style: LabelStyle3D = { size: s.labelSize, color: s.labelColor, fontFamily: s.fontFamily };\n const tipLength = s.tips ? thickness * 9 : 0;\n const marks: Transform3D[] = [];\n const plane: Vector3[] = [];\n\n for (const axis of [\"x\", \"y\", \"z\"] as const) {\n const [min, max] = ranges[axis];\n const length = lengths[axis];\n if (!(max > min) || !(length > 0)) continue;\n\n if (thickness > 0) {\n const from = at(axis, min);\n const to = at(axis, max);\n g3.mesh(Geo.cylinder({ radius: thickness, height: length, segments: [12, 1] }), paint, {\n position: { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2, z: (from.z + to.z) / 2 },\n rotation: ALONG[axis],\n });\n if (s.tips) {\n g3.mesh(Geo.cone({ radius: thickness * 3.2, height: tipLength, segments: [16, 1] }), paint, {\n position: at(axis, max, { [axis]: tipLength / 2 }),\n rotation: ALONG[axis],\n });\n }\n }\n\n const ticks = ticksFor(ranges[axis], steps[axis], length * UNIT_AS_PIXELS);\n const side = TICK_ALONG[axis];\n for (const value of ticks.values) {\n // The crossing is marked by the other axes, and the far end by the tip.\n if (Math.abs(value - cross[axis]) < 1e-9 || (s.tips && Math.abs(value - max) < 1e-9)) continue;\n if (s.ticks && tickSize > 0) marks.push({ position: at(axis, value), rotation: ALONG[side] });\n if (s.labels) {\n drawLabel3D(g3, formatTick(value, ticks.step), at(axis, value, { [side]: -(tickSize / 2 + style.size * 0.8) }), style);\n }\n }\n drawLabel3D(g3, titles[axis], at(axis, max, { [axis]: tipLength + style.size * 0.9 }), style);\n\n if (s.grid && axis !== \"z\") {\n const other = axis === \"x\" ? \"y\" : \"x\";\n for (const value of ticks.values) {\n const a = { x: 0, y: 0, z: cross.z, [axis]: value, [other]: ranges[other][0] };\n const b = { ...a, [other]: ranges[other][1] };\n plane.push(space.toLocal(a.x, a.y, a.z), space.toLocal(b.x, b.y, b.z));\n }\n }\n }\n\n if (marks.length > 0) {\n g3.instances(Geo.cylinder({ radius: Math.max(thickness * 0.7, 0.008), height: tickSize, segments: [8, 1] }), paint, marks);\n }\n if (plane.length > 0) g3.line({ points: plane, segments: true, stroke: { fill: s.gridLineColor } });\n return g3;\n}\n", "import { memoParse } from \"./cache\";\nimport { equationError, equationNames, equationParams, EQUATION_VARIABLES, splitTopLevel, splitTuple } from \"./equation\";\nimport { compilerFor, type CompiledExpression } from \"./expression\";\nimport { fieldError, fieldParams, FIELD_VARIABLES } from \"./field\";\n\n/**\n * A surface's equation, read the way it is written:\n *\n * | Written as | Is |\n * |---|---|\n * | `sin(x) * cos(y)`, `z = x^2 - y^2` | a height over `x` and `y` |\n * | `(cos(u) sin(v), sin(u) sin(v), cos(v))` | parametric, in `u` and `v` |\n */\nexport type SurfaceEquation =\n | { kind: \"height\"; f: CompiledExpression }\n | { kind: \"parametric\"; x: CompiledExpression; y: CompiledExpression; z: CompiledExpression };\n\n/** A curve through space, three parts in `t`: `(cos(t), sin(t), t / 4)`. */\nexport interface SpaceCurveEquation {\n x: CompiledExpression;\n y: CompiledExpression;\n z: CompiledExpression;\n}\n\n/** What each 3D form is written over, for a host's help text. */\nexport const EQUATION_VARIABLES_3D = {\n height: [\"x\", \"y\"],\n surface: [\"u\", \"v\"],\n spaceCurve: [\"t\"],\n} as const;\n\nconst SURFACE_NAMES: ReadonlySet<string> = new Set([\"x\", \"y\", \"z\", \"u\", \"v\"]);\nconst SPACE_CURVE_NAMES: ReadonlySet<string> = new Set([\"t\"]);\n\n/** The named values a surface's equation reads: every name that is not one of its variables. */\nexport function surfaceParams(source: string): readonly string[] {\n return equationNames(source).filter((name) => !SURFACE_NAMES.has(name));\n}\n\n/** The named values a space curve's equation reads. */\nexport function spaceCurveParams(source: string): readonly string[] {\n return equationNames(source).filter((name) => !SPACE_CURVE_NAMES.has(name));\n}\n\n/** `source` as a surface, or the reason it is not one. */\nexport const parseSurface = memoParse<SurfaceEquation>(128, (text, params) => {\n const compile = compilerFor(params);\n const parts = splitTuple(text);\n if (parts) {\n if (parts.length !== 3) throw new Error(\"A parametric surface has three parts: (x, y, z)\");\n const [x, y, z] = parts.map((part) => compile(part, EQUATION_VARIABLES_3D.surface));\n return { kind: \"parametric\", x, y, z };\n }\n const sides = splitTopLevel(text, \"=\");\n if (sides.length > 2) throw new Error(\"An equation has one '='\");\n if (sides.length === 2 && sides[0].trim() !== \"z\") throw new Error(\"A surface is written z = …, or as three parts (x, y, z)\");\n return { kind: \"height\", f: compile(sides[sides.length - 1], EQUATION_VARIABLES_3D.height) };\n});\n\n/** `source` as a space curve, or the reason it is not one. */\nexport const parseSpaceCurve = memoParse<SpaceCurveEquation>(128, (text, params) => {\n const compile = compilerFor(params);\n const parts = splitTuple(text);\n if (parts?.length !== 3) throw new Error(\"A space curve has three parts: (x, y, z)\");\n const [x, y, z] = parts.map((part) => compile(part, EQUATION_VARIABLES_3D.spaceCurve));\n return { x, y, z };\n});\n\n/** Why `source` will not draw as a surface, or `null`; empty text is not an error. */\nexport function surfaceError(source: string): string | null {\n if (source.trim() === \"\") return null;\n const equation = parseSurface(source, surfaceParams(source));\n return equation instanceof Error ? equation.message : null;\n}\n\n/** Why `source` will not draw as a space curve, or `null`. */\nexport function spaceCurveError(source: string): string | null {\n if (source.trim() === \"\") return null;\n const equation = parseSpaceCurve(source, spaceCurveParams(source));\n return equation instanceof Error ? equation.message : null;\n}\n\n/** How a host checks an equation as it is typed, and finds its named values, by the `kind` its property declares. */\nexport interface EquationLanguage {\n error(source: string): string | null;\n params(source: string): readonly string[];\n variables: readonly string[];\n}\n\nexport const EQUATION_KINDS: Readonly<\n Record<\"equation\" | \"surfaceEquation\" | \"spaceCurveEquation\" | \"fieldEquation\", EquationLanguage>\n> = {\n equation: { error: equationError, params: equationParams, variables: [...new Set(Object.values(EQUATION_VARIABLES).flat())] },\n surfaceEquation: {\n error: surfaceError,\n params: surfaceParams,\n variables: [...EQUATION_VARIABLES_3D.height, ...EQUATION_VARIABLES_3D.surface],\n },\n spaceCurveEquation: { error: spaceCurveError, params: spaceCurveParams, variables: EQUATION_VARIABLES_3D.spaceCurve },\n fieldEquation: { error: fieldError, params: fieldParams, variables: FIELD_VARIABLES },\n};\n", "import {\n Material,\n Types,\n type EntryOptions,\n type Geometry3D,\n type Type,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Blend3D as _Blend3D,\n type Color as _Color,\n type Faces3D as _Faces3D,\n type Fill3D as _Fill3D,\n type Material3D as _Material3D,\n type NormalizedColor as _NormalizedColor,\n type Shading3D as _Shading3D,\n type Texture3D as _Texture3D,\n} from \"@motionscript/sdk\";\nimport type { Interval } from \"../kit/coords\";\nimport { lerpDomain } from \"../kit/source\";\n\ntype MeshState = { readonly geometry: Type<Geometry3D | undefined> } & typeof Material.state;\n// Restated key by key, so a mark spreading these names each entry's type through the sdk: spread\n// as inferred, a mark's declaration copied `emission`'s colour types from core's own.\ntype Restated<T> = { [K in Extract<keyof T, string>]: T[K] };\n\n/**\n * A mesh's entries, as a 3D mark draws with them: its surface, and the\n * `geometry` a mesh takes, which a mark builds itself and never reads.\n */\nexport const meshEntries: Restated<MeshState> = {\n geometry: Types.custom<Geometry3D | undefined>(undefined),\n ...Material.state,\n};\n\ninterface RangeHints extends EntryOptions {\n readonly defaultMin: number;\n readonly defaultMax: number;\n}\n\n/** A span of a variable, unset until given: what a host offers as a range from `defaultMin` to `defaultMax`. */\nexport function domainEntry(defaultMin: number, defaultMax: number): Type<Interval | null> {\n return Types.custom<Interval | null, Interval | null, RangeHints>(null, { lerp: lerpDomain, kind: \"range\", defaultMin, defaultMax });\n}\n", "import {\n colorOps,\n component3d,\n Geo,\n Graphics3D,\n Mat,\n Material,\n Types,\n type ChildSpace3D,\n type Color,\n type Geometry3D,\n type Material3D,\n type NodeOf,\n type NormalizedColor,\n type Values,\n type Vector3,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Blend3D as _Blend3D,\n type Color as _Color,\n type Faces3D as _Faces3D,\n type Fill3D as _Fill3D,\n type Node3D as _Node3D,\n type Node3DProps as _Node3DProps,\n type NormalizedColor as _NormalizedColor,\n type Shading3D as _Shading3D,\n type Texture3D as _Texture3D,\n} from \"@motionscript/sdk\";\nimport { parseSurface, surfaceParams, type SurfaceEquation } from \"../kit/equation3d\";\nimport type { ExpressionScope } from \"../kit/expression\";\nimport { PLOT_COLOR } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { colorAt, lerpScale, readScale } from \"../kit/scale\";\nimport { lerpParams, lerpSource, readSource, revisionOf, scopeFor, type PlotSource } from \"../kit/source\";\nimport { domainEntry, meshEntries } from \"./entries\";\nimport { graphEntry, graphOf, type GraphSpace } from \"./space\";\n\n/** A graph point for grid coordinate `(u, v)`, both 0 to 1, written into `out`. */\ntype SurfaceSampler = (u: number, v: number, out: Vector3) => void;\n\nconst state = {\n ...meshEntries,\n expression: Types.custom<string | PlotSource, PlotSource>(\"\", {\n resolve: readSource,\n lerp: lerpSource,\n kind: \"surfaceEquation\",\n }),\n /**\n * The span of each variable that is drawn: x and y for a height, which run\n * the width of the axes when left out, u and v for a parametric surface,\n * which run from 0 to 1.\n */\n uDomain: domainEntry(-3, 3),\n vDomain: domainEntry(-3, 3),\n /** The equation's named values: any name in it that is not a variable, a function or a constant. */\n params: Types.custom<ExpressionScope>({}, { lerp: lerpParams }),\n /** How finely the surface is sampled, each way. */\n segments: Types.number(48, { min: 2, max: 256, step: 1, animatable: false }),\n /** Colours by height, lowest first, over the axes' z range. Empty paints the surface in its fill. */\n colorScale: Types.custom<Color[], NormalizedColor[]>([], { resolve: readScale, lerp: lerpScale, kind: \"vector\" }),\n /** How many lines are drawn across the surface each way; zero leaves it bare. */\n meshLines: Types.number(12, { min: 0, max: 64, step: 1, animatable: false }),\n meshColor: Types.custom<Color, Color>(\"#0b1220\", { kind: \"color\" }),\n /** The opacity of the surface's shadow, laid flat on the floor of the axes and coloured by height; zero draws none. */\n floorShadow: Types.number(0, { min: 0, max: 1, step: 0.01 }),\n graph: graphEntry(),\n};\n\nexport type SurfaceValues = Values<typeof state> & { readonly x: number; readonly y: number; readonly z: number };\n\n/**\n * A surface in a 3D graph: a height over x and y (`sin(x) * cos(y)`), or three\n * parts in u and v. A point put inside it rides it.\n */\nexport const SurfacePlot3d = component3d({\n key: \"surfacePlot3d\",\n state,\n defaults: { fill: PLOT_COLOR },\n commands: {\n /** Change the equation, the surface bending from the one into the other. */\n morphTo: { args: [\"expression\"] },\n /** Animate the equation's named values. */\n paramsTo: { args: [\"params\"] },\n /** Animate the spans that are drawn. */\n domainTo: { args: [\"uDomain\", \"vDomain\"] },\n },\n space: (s) => surfaceSpace(s),\n render: (ctx, s) => ctx.draw(ctx.declaring ? declaredSurface(s) : drawSurface(s)),\n});\n\nexport type SurfacePlot3d = NodeOf<typeof SurfacePlot3d>;\n\n/**\n * The surface's height above its own origin at graph `(x, y)`, or `NaN`\n * where it has none or is not a height. What a point riding it reads.\n */\nexport function surfaceValueAt(surface: Pick<SurfaceValues, \"expression\" | \"params\">, x: number, y: number): number {\n const { source, blend } = surface.expression;\n const value = heightOf(surface, source, x, y);\n if (!blend) return value;\n const from = heightOf(surface, blend.from, x, y);\n return from + (value - from) * blend.t;\n}\n\n/** A point inside a surface stands on it: its `x` and `y` say where, and its height is the surface's. */\nfunction surfaceSpace(s: SurfaceValues): ChildSpace3D | null {\n const space = graphOf(s);\n if (!space) return null;\n return {\n toLocal: (x, y, z) => {\n const height = surfaceValueAt(s, x, y);\n return space.offset(x, y, Number.isFinite(height) ? height : z);\n },\n };\n}\n\n/** Its paint on a stand-in: only a material loads, and reading no equation keeps a morph from re-declaring. */\nfunction declaredSurface(s: SurfaceValues): Graphics3D {\n const paint = Material.shorthand(s);\n return new Graphics3D().plane(s.colorScale.length > 0 ? { ...paint, fill: \"white\" } : paint);\n}\n\nfunction drawSurface(s: SurfaceValues): Graphics3D {\n const g3 = new Graphics3D();\n const space = graphOf(s);\n const lines = space ? meshLines(s, space) : [];\n const scaled = s.colorScale.length > 0;\n // A surface is seen from both sides; a vertex colour multiplies the fill, so a scale is shown on white.\n const surface = { ...s, faces: s.faces ?? \"both\", ...(scaled ? { vertexColors: true, fill: \"white\" } : {}) };\n for (const op of Material.mesh(surface, space ? surfaceGeometry(s, space) : undefined).ops()) {\n if (op.kind !== \"mesh\") continue;\n g3.mesh(op.geometry, mapMaterials(op.material, (material) => ({\n ...material,\n // Pushed back a hair so the lines drawn on it are not fought for, and blended rather than a hole when faded.\n ...(lines.length > 0 ? { polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 } : {}),\n ...((s.opacity ?? 1) < 1 ? { depthWrite: false } : {}),\n } as Material3D)), op.transform);\n }\n if (lines.length > 0) {\n const color = colorOps.resolve(s.meshColor);\n g3.line({ points: lines, segments: true, stroke: { fill: color }, opacity: color[3] * (s.opacity ?? 1) });\n }\n const shadow = space && s.floorShadow > 0 ? floorShadow(s, space) : undefined;\n if (shadow) {\n g3.mesh(shadow, Mat.basic({\n color: scaled ? \"white\" : PLOT_COLOR,\n vertexColors: scaled,\n opacity: s.floorShadow * (s.opacity ?? 1),\n transparent: true,\n // Translucent and under everything: writing depth would hide the floor's grid lines behind it.\n depthWrite: false,\n faces: \"both\",\n }));\n }\n return g3;\n}\n\nfunction surfaceGeometry(s: SurfaceValues, space: GraphSpace): Geometry3D | undefined {\n const sample = sampler(s, space);\n if (!sample) return undefined;\n const scale = s.colorScale;\n const point: Vector3 = { x: 0, y: 0, z: 0 };\n const low = space.offset(0, 0, space.zRange[0] - s.z).y;\n const high = space.offset(0, 0, space.zRange[1] - s.z).y;\n return Geo.parametric({\n segments: Math.max(2, Math.round(s.segments)),\n vertex: (u, v) => {\n sample(u, v, point);\n return space.offset(point.x, point.y, point.z);\n },\n ...(scale.length > 0\n ? { color: (_u, _v, position) => colorAt(scale, high > low ? (position.y - low) / (high - low) : 0) }\n : {}),\n computeNormals: true,\n revision: revisionOf(`${keyOf(s, space)}|${JSON.stringify(scale)}`),\n });\n}\n\nfunction heightOf(surface: Pick<SurfaceValues, \"params\">, source: string, x: number, y: number): number {\n const equation = equationOf(source);\n if (equation?.kind !== \"height\") return NaN;\n return equation.f(x, y, scopeFor(surfaceParams(source), surface.params));\n}\n\nfunction keyOf(s: SurfaceValues, space: GraphSpace): string {\n const { source, blend } = s.expression;\n return [source, blend?.from, blend?.t, space.revision, s.uDomain, s.vDomain, JSON.stringify(s.params), s.x, s.y, s.z].join(\"|\");\n}\n\nfunction sampler(s: SurfaceValues, space: GraphSpace): SurfaceSampler | null {\n const { source, blend } = s.expression;\n const to = surfaceOf(s, source, space);\n if (!to || !blend) return to;\n const from = surfaceOf(s, blend.from, space);\n if (!from) return to;\n const start: Vector3 = { x: 0, y: 0, z: 0 };\n return (u, v, out) => {\n from(u, v, start);\n to(u, v, out);\n out.x = start.x + (out.x - start.x) * blend.t;\n out.y = start.y + (out.y - start.y) * blend.t;\n out.z = start.z + (out.z - start.z) * blend.t;\n };\n}\n\n/** `source` as graph points, measured from the surface's own position. */\nfunction surfaceOf(s: SurfaceValues, source: string, space: GraphSpace): SurfaceSampler | null {\n const equation = equationOf(source);\n if (!equation) return null;\n const params = scopeFor(surfaceParams(source), s.params);\n if (equation.kind === \"parametric\") {\n const [u0, u1] = s.uDomain ?? [0, 1];\n const [v0, v1] = s.vDomain ?? [0, 1];\n const { x, y, z } = equation;\n return (u, v, out) => {\n const a = u0 + (u1 - u0) * u;\n const b = v0 + (v1 - v0) * v;\n out.x = finite(x(a, b, params));\n out.y = finite(y(a, b, params));\n out.z = finite(z(a, b, params));\n };\n }\n const [x0, x1] = s.uDomain ?? [space.xRange[0] - s.x, space.xRange[1] - s.x];\n const [y0, y1] = s.vDomain ?? [space.yRange[0] - s.y, space.yRange[1] - s.y];\n // Held inside the axes: a pole would otherwise stretch one triangle across the scene.\n const low = space.zRange[0] - s.z;\n const high = space.zRange[1] - s.z;\n const { f } = equation;\n return (u, v, out) => {\n out.x = x0 + (x1 - x0) * u;\n out.y = y0 + (y1 - y0) * v;\n out.z = clamp(finite(f(out.x, out.y, params)), low, high);\n };\n}\n\nfunction floorShadow(s: SurfaceValues, space: GraphSpace): Geometry3D | undefined {\n const sample = sampler(s, space);\n if (!sample) return undefined;\n const scale = s.colorScale;\n const [low, high] = space.zRange;\n const floor = low - s.z;\n const point: Vector3 = { x: 0, y: 0, z: 0 };\n return Geo.parametric({\n segments: Math.max(2, Math.round(s.segments)),\n vertex: (u, v) => {\n sample(u, v, point);\n return space.offset(point.x, point.y, floor);\n },\n ...(scale.length > 0\n ? {\n color: (u: number, v: number) => {\n sample(u, v, point);\n return colorAt(scale, high > low ? (point.z + s.z - low) / (high - low) : 0);\n },\n }\n : {}),\n revision: revisionOf(`${keyOf(s, space)}|${JSON.stringify(scale)}|floor`),\n });\n}\n\n/** The last lines drawn for each surface, kept while what they are drawn from is unchanged. */\nconst linesDrawn = new WeakMap<object, { readonly key: string; readonly lines: Vector3[] }>();\n\nfunction meshLines(s: SurfaceValues, space: GraphSpace): Vector3[] {\n const count = Math.round(s.meshLines);\n const sample = count > 0 ? sampler(s, space) : null;\n if (!sample) return [];\n const steps = Math.max(2, Math.round(s.segments));\n const key = `${keyOf(s, space)}|${count}|${steps}`;\n const kept = linesDrawn.get(s);\n if (kept?.key === key) return kept.lines;\n const lines: Vector3[] = [];\n const point: Vector3 = { x: 0, y: 0, z: 0 };\n const at = (u: number, v: number): Vector3 => {\n sample(u, v, point);\n return space.offset(point.x, point.y, point.z);\n };\n for (let i = 0; i <= count; i++) {\n const fixed = i / count;\n for (let j = 0; j < steps; j++) {\n lines.push(at(fixed, j / steps), at(fixed, (j + 1) / steps));\n lines.push(at(j / steps, fixed), at((j + 1) / steps, fixed));\n }\n }\n linesDrawn.set(s, { key, lines });\n return lines;\n}\n\nfunction equationOf(source: string): SurfaceEquation | null {\n const equation = parseSurface(source, surfaceParams(source));\n return equation instanceof Error ? null : equation;\n}\n\n// A hole in the data is drawn flat rather than as a hole in the mesh.\nfunction finite(value: number): number {\n return Number.isFinite(value) ? value : 0;\n}\n\nfunction mapMaterials(\n material: Material3D | readonly Material3D[],\n change: (material: Material3D) => Material3D,\n): Material3D | readonly Material3D[] {\n return Array.isArray(material) ? (material as readonly Material3D[]).map(change) : change(material as Material3D);\n}\n", "import {\n component3d,\n Geo,\n Graphics3D,\n Material,\n Types,\n type Geometry3D,\n type NodeOf,\n type Values,\n type Vector3,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Blend3D as _Blend3D,\n type Color as _Color,\n type Faces3D as _Faces3D,\n type Fill3D as _Fill3D,\n type Material3D as _Material3D,\n type Node3D as _Node3D,\n type Node3DProps as _Node3DProps,\n type NormalizedColor as _NormalizedColor,\n type Shading3D as _Shading3D,\n type Texture3D as _Texture3D,\n} from \"@motionscript/sdk\";\nimport { parseSpaceCurve, spaceCurveParams, type SpaceCurveEquation } from \"../kit/equation3d\";\nimport type { ExpressionScope } from \"../kit/expression\";\nimport { PLOT_COLOR } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { lerpParams, lerpSource, readSource, scopeFor, type PlotSource } from \"../kit/source\";\nimport { domainEntry, meshEntries } from \"./entries\";\nimport { graphEntry, graphOf, type GraphSpace } from \"./space\";\n\nconst state = {\n ...meshEntries,\n expression: Types.custom<string | PlotSource, PlotSource>(\"\", {\n resolve: readSource,\n lerp: lerpSource,\n kind: \"spaceCurveEquation\",\n }),\n /** The span of `t` that is drawn; 0 to 1 when left out. */\n domain: domainEntry(0, 1),\n params: Types.custom<ExpressionScope>({}, { lerp: lerpParams }),\n /** How many points the curve is drawn through. */\n samples: Types.number(160, { min: 2, max: 2000, step: 1, animatable: false }),\n /** The radius of the line, in scene units. */\n thickness: Types.number(0.04, { min: 0.001, step: 0.005 }),\n /** The part of the curve that is drawn, as shares of its length in `t`. */\n start: Types.number(0, { min: 0, max: 1, step: 0.01 }),\n end: Types.number(1, { min: 0, max: 1, step: 0.01 }),\n graph: graphEntry(),\n};\n\ntype CurveValues = Values<typeof state>;\n\n/** A curve through a 3D graph, three parts in `t`: `(cos(t), sin(t), t / 4)`. */\nexport const CurvePlot3d = component3d({\n key: \"curvePlot3d\",\n state,\n defaults: { fill: PLOT_COLOR },\n commands: {\n /** Change the equation, the curve bending from the one into the other. */\n morphTo: { args: [\"expression\"] },\n /** Animate the equation's named values. */\n paramsTo: { args: [\"params\"] },\n /** Animate the span of `t` that is drawn. */\n domainTo: { args: [\"domain\"] },\n /** Draw the curve on, or wipe it off: animates `start` and `end`. */\n progressTo: { args: [\"start\", \"end\"] },\n },\n // Declaring, its paint on a stand-in: only a material loads, and the curve's points are not sampled.\n render: (ctx, s) => ctx.draw(ctx.declaring ? new Graphics3D().plane(Material.shorthand(s)) : Material.mesh(s, curveGeometry(s))),\n});\n\nexport type CurvePlot3d = NodeOf<typeof CurvePlot3d>;\n\nfunction curveGeometry(s: CurveValues): Geometry3D | undefined {\n const space = graphOf(s);\n if (!space) return undefined;\n const points = pointsOf(s, space);\n if (points.length < 2) return undefined;\n return Geo.tube({ points, radius: s.thickness, segments: [points.length - 1, 8] });\n}\n\n/** The last run drawn for each curve, kept while what it is drawn from is unchanged. */\nconst runs = new WeakMap<object, { readonly key: string; readonly run: Vector3[] }>();\n\nfunction pointsOf(s: CurveValues, space: GraphSpace): Vector3[] {\n const { source, blend } = s.expression;\n const start = clamp(s.start, 0, 1);\n const end = clamp(s.end, 0, 1);\n const samples = Math.max(2, Math.round(s.samples));\n const key = [source, blend?.from, blend?.t, space.revision, s.domain, JSON.stringify(s.params), start, end, samples].join(\"|\");\n const kept = runs.get(s);\n if (kept?.key === key) return kept.run;\n const run: Vector3[] = [];\n runs.set(s, { key, run });\n const to = curveOf(s, source);\n if (!to || !(end > start)) return run;\n const from = blend ? curveOf(s, blend.from) : null;\n const steps = Math.max(1, Math.round(samples * (end - start)));\n const a: Vector3 = { x: 0, y: 0, z: 0 };\n const b: Vector3 = { x: 0, y: 0, z: 0 };\n for (let i = 0; i <= steps; i++) {\n const u = start + ((end - start) * i) / steps;\n if (!to(u, b)) continue;\n if (from && blend) {\n if (!from(u, a)) continue;\n b.x = a.x + (b.x - a.x) * blend.t;\n b.y = a.y + (b.y - a.y) * blend.t;\n b.z = a.z + (b.z - a.z) * blend.t;\n }\n run.push(space.offset(b.x, b.y, b.z));\n }\n return run;\n}\n\n/** `source` as a graph point for a share `u` of its span, or `false` where it has none. */\nfunction curveOf(s: CurveValues, source: string): ((u: number, out: Vector3) => boolean) | null {\n const equation = equationOf(source);\n if (!equation) return null;\n const params = scopeFor(spaceCurveParams(source), s.params);\n const [t0, t1] = s.domain ?? [0, 1];\n const { x, y, z } = equation;\n return (u, out) => {\n const t = t0 + (t1 - t0) * u;\n out.x = x(t, 0, params);\n out.y = y(t, 0, params);\n out.z = z(t, 0, params);\n return Number.isFinite(out.x) && Number.isFinite(out.y) && Number.isFinite(out.z);\n };\n}\n\nfunction equationOf(source: string): SpaceCurveEquation | null {\n const equation = parseSpaceCurve(source, spaceCurveParams(source));\n return equation instanceof Error ? null : equation;\n}\n", "import {\n component3d,\n Geo,\n Material,\n Types,\n type NodeOf,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Blend3D as _Blend3D,\n type Color as _Color,\n type Faces3D as _Faces3D,\n type Fill3D as _Fill3D,\n type Geometry3D as _Geometry3D,\n type Material3D as _Material3D,\n type Node3D as _Node3D,\n type Node3DProps as _Node3DProps,\n type NormalizedColor as _NormalizedColor,\n type Shading3D as _Shading3D,\n type Texture3D as _Texture3D,\n} from \"@motionscript/sdk\";\nimport { meshEntries } from \"./entries\";\nimport { drawLabel3D } from \"./label3d\";\n\n/**\n * A dot at graph coordinates in a 3D graph, with an optional label. Put inside\n * a surface it rides it: its `x` and `y` say where, and its height is the surface's.\n */\nexport const PlotPoint3d = component3d({\n key: \"plotPoint3d\",\n state: {\n ...meshEntries,\n /** In scene units, so a point is the same size whatever the axes show. */\n radius: Types.number(0.1, { min: 0, step: 0.01 }),\n label: Types.text(\"\", { animatable: false }),\n /** The height of the label's text, in scene units. */\n labelSize: Types.number(0.26, { min: 0.01, step: 0.01 }),\n labelColor: Types.color(\"#e5e7eb\"),\n fontFamily: Types.text(\"\", { animatable: false }),\n },\n load: (loader, s) => {\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\n },\n render: (ctx, s) => {\n const g3 = Material.mesh(s, s.radius > 0 ? Geo.sphere({ radius: s.radius, segments: [24, 16] }) : undefined);\n drawLabel3D(g3, s.label, { x: 0, y: s.radius + s.labelSize * 0.85, z: 0 }, {\n size: s.labelSize,\n color: s.labelColor,\n fontFamily: s.fontFamily,\n });\n ctx.draw(g3);\n },\n});\n\nexport type PlotPoint3d = NodeOf<typeof PlotPoint3d>;\n", "import {\n component3d,\n Graphics3D,\n lerpVector3,\n Material,\n resolveVector3,\n Types,\n type NodeOf,\n type Values,\n type Vector3,\n type Vector3Input,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Blend3D as _Blend3D,\n type Color as _Color,\n type Faces3D as _Faces3D,\n type Fill3D as _Fill3D,\n type Geometry3D as _Geometry3D,\n type Material3D as _Material3D,\n type Node3D as _Node3D,\n type Node3DProps as _Node3DProps,\n type NormalizedColor as _NormalizedColor,\n type Shading3D as _Shading3D,\n type Texture3D as _Texture3D,\n} from \"@motionscript/sdk\";\nimport { meshEntries } from \"./entries\";\nimport { aim, graphEntry, graphOf } from \"./space\";\n\nfunction point(initial: Vector3) {\n return Types.custom<Vector3Input, Vector3>(initial, { resolve: resolveVector3, lerp: lerpVector3, kind: \"vector3\" });\n}\n\nconst state = {\n ...meshEntries,\n tail: point({ x: 0, y: 0, z: 0 }),\n head: point({ x: 1, y: 1, z: 1 }),\n /** The radius of the shaft, in scene units; the tip is sized from it. */\n thickness: Types.number(0.035, { min: 0.001, step: 0.005 }),\n tip: Types.boolean(true, { animatable: false }),\n graph: graphEntry(),\n};\n\n/** An arrow between two points of a 3D graph: a vector from the origin by default. */\nexport const VectorArrow3d = component3d({\n key: \"vectorArrow3d\",\n state,\n commands: {\n /** Animate either end, or both. */\n endpointsTo: { args: [\"tail\", \"head\"] },\n },\n render: (ctx, s) => ctx.draw(drawArrow(s)),\n});\n\nexport type VectorArrow3d = NodeOf<typeof VectorArrow3d>;\n\nfunction drawArrow(s: Values<typeof state>): Graphics3D {\n const g3 = new Graphics3D();\n const space = graphOf(s);\n const { tail, head, thickness } = s;\n // Outside a graph an arrow is drawn in the scene's own units.\n const from = space ? space.offset(tail.x, tail.y, tail.z) : tail;\n const to = space ? space.offset(head.x, head.y, head.z) : head;\n const along: Vector3 = { x: to.x - from.x, y: to.y - from.y, z: to.z - from.z };\n const length = Math.hypot(along.x, along.y, along.z);\n if (!(length > 0)) return g3;\n\n const paint = Material.shorthand(s);\n const quaternion = aim(along);\n const tipLength = s.tip ? Math.min(thickness * 8, length) : 0;\n const shaft = length - tipLength;\n const at = (distance: number): Vector3 => ({\n x: from.x + (along.x * distance) / length,\n y: from.y + (along.y * distance) / length,\n z: from.z + (along.z * distance) / length,\n });\n if (shaft > 0) g3.cylinder({ ...paint, radius: thickness, height: shaft, segments: [12, 1], position: at(shaft / 2), quaternion });\n if (tipLength > 0) {\n g3.cone({ ...paint, radius: thickness * 2.8, height: tipLength, segments: [20, 1], position: at(shaft + tipLength / 2), quaternion });\n }\n return g3;\n}\n", "import type { Vector2 } from \"@motionscript/sdk\";\n\n/** Where a graph's vertices are placed, inside a square from -1 to 1 each way, y up. */\n\nexport type GraphLayout = \"circular\" | \"spring\" | \"tree\" | \"grid\";\n\nexport const GRAPH_LAYOUTS: readonly GraphLayout[] = [\"circular\", \"spring\", \"tree\", \"grid\"];\n\nexport interface GraphEdge {\n from: string;\n to: string;\n}\n\n/** Each vertex's place under `layout`, by name. */\nexport function layOut(layout: GraphLayout, vertices: readonly string[], edges: readonly GraphEdge[], root: string): Map<string, Vector2> {\n const n = vertices.length;\n if (n === 0) return new Map();\n if (n === 1) return new Map([[vertices[0], { x: 0, y: 0 }]]);\n switch (layout) {\n case \"grid\":\n return grid(vertices);\n case \"tree\":\n return fill(tree(vertices, edges, root));\n case \"spring\":\n return fill(spring(vertices, edges));\n default:\n return circular(vertices);\n }\n}\n\nfunction circular(vertices: readonly string[]): Map<string, Vector2> {\n const n = vertices.length;\n // The first at the top, the rest clockwise, as a clock is read.\n return new Map(vertices.map((name, i) => {\n const angle = Math.PI / 2 - (2 * Math.PI * i) / n;\n return [name, { x: Math.cos(angle), y: Math.sin(angle) }];\n }));\n}\n\nfunction grid(vertices: readonly string[]): Map<string, Vector2> {\n const columns = Math.ceil(Math.sqrt(vertices.length));\n const rows = Math.ceil(vertices.length / columns);\n const at = (i: number, count: number) => (count === 1 ? 0 : -1 + (2 * i) / (count - 1));\n return new Map(vertices.map((name, i) => [name, { x: at(i % columns, columns), y: -at(Math.floor(i / columns), rows) }]));\n}\n\nfunction neighbours(vertices: readonly string[], edges: readonly GraphEdge[]): Map<string, string[]> {\n const near = new Map(vertices.map((name) => [name, [] as string[]]));\n for (const { from, to } of edges) {\n if (from === to || !near.has(from) || !near.has(to)) continue;\n near.get(from)!.push(to);\n near.get(to)!.push(from);\n }\n return near;\n}\n\n/** Levels down from `root`, and across by the leaves under each, every component its own tree beside the last. */\nfunction tree(vertices: readonly string[], edges: readonly GraphEdge[], root: string): Map<string, Vector2> {\n const near = neighbours(vertices, edges);\n const placed = new Map<string, Vector2>();\n let column = 0;\n const visit = (name: string, depth: number, seen: Set<string>): number => {\n seen.add(name);\n const children = near.get(name)!.filter((next) => !seen.has(next));\n for (const child of children) seen.add(child);\n if (children.length === 0) {\n placed.set(name, { x: column++, y: -depth });\n return placed.get(name)!.x;\n }\n const xs = children.map((child) => visit(child, depth + 1, seen));\n const x = (xs[0] + xs[xs.length - 1]) / 2;\n placed.set(name, { x, y: -depth });\n return x;\n };\n const seen = new Set<string>();\n const first = near.has(root) ? root : vertices[0];\n for (const start of [first, ...vertices]) if (!seen.has(start)) visit(start, 0, seen);\n return placed;\n}\n\n/** Edges pull and every pair pushes, from the circle, for a fixed number of cooling steps: the same answer every time. */\nfunction spring(vertices: readonly string[], edges: readonly GraphEdge[]): Map<string, Vector2> {\n const n = vertices.length;\n const index = new Map(vertices.map((name, i) => [name, i]));\n const start = circular(vertices);\n const x = vertices.map((name) => start.get(name)!.x);\n const y = vertices.map((name) => start.get(name)!.y);\n const links = edges.flatMap(({ from, to }) => {\n const a = index.get(from);\n const b = index.get(to);\n return a === undefined || b === undefined || a === b ? [] : [[a, b] as const];\n });\n const k = Math.sqrt(4 / n);\n const steps = 160;\n for (let step = 0; step < steps; step++) {\n const dx = new Float64Array(n);\n const dy = new Float64Array(n);\n for (let i = 0; i < n; i++) {\n for (let j = i + 1; j < n; j++) {\n let ex = x[i] - x[j];\n let ey = y[i] - y[j];\n let d = Math.hypot(ex, ey);\n // Two on one spot are parted along a fixed, if arbitrary, line.\n if (d < 1e-6) [ex, ey, d] = [1e-3 * (i - j), 1e-3, 1e-3];\n const push = (k * k) / d;\n dx[i] += (ex / d) * push;\n dy[i] += (ey / d) * push;\n dx[j] -= (ex / d) * push;\n dy[j] -= (ey / d) * push;\n }\n }\n for (const [a, b] of links) {\n const ex = x[a] - x[b];\n const ey = y[a] - y[b];\n const d = Math.max(Math.hypot(ex, ey), 1e-6);\n const pull = (d * d) / k;\n dx[a] -= (ex / d) * pull;\n dy[a] -= (ey / d) * pull;\n dx[b] += (ex / d) * pull;\n dy[b] += (ey / d) * pull;\n }\n const limit = 0.12 * (1 - step / steps);\n for (let i = 0; i < n; i++) {\n const d = Math.hypot(dx[i], dy[i]);\n if (d > 0) {\n x[i] += (dx[i] / d) * Math.min(d, limit);\n y[i] += (dy[i] / d) * Math.min(d, limit);\n }\n }\n }\n return new Map(vertices.map((name, i) => [name, { x: x[i], y: y[i] }]));\n}\n\n/** `placed` stretched to reach -1 and 1 on each axis it spreads along, and centred on the one it does not. */\nfunction fill(placed: Map<string, Vector2>): Map<string, Vector2> {\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const p of placed.values()) {\n minX = Math.min(minX, p.x);\n maxX = Math.max(maxX, p.x);\n minY = Math.min(minY, p.y);\n maxY = Math.max(maxY, p.y);\n }\n const scale = (v: number, lo: number, hi: number) => (hi - lo < 1e-9 ? 0 : -1 + (2 * (v - lo)) / (hi - lo));\n return new Map([...placed].map(([name, p]) => [name, { x: scale(p.x, minX, maxX), y: scale(p.y, minY, maxY) }]));\n}\n", "import {\n component2d,\n Graphics2D,\n Types,\n type Fill,\n type FillResolved,\n type NodeOf,\n type Color as _Color,\n\n type NormalizedColor,\n type RenderContext,\n type ShadowResolved,\n type Size2D,\n type Stroke as _Stroke,\n\n type StrokeResolved,\n type Values,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n} from \"@motionscript/sdk\";\nimport { createBoundedCache } from \"../kit/cache\";\nimport { listed, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\nimport { drawLabels, loadFormulas, type Label } from \"../kit/furniture\";\nimport { lerpPartFills, partPaint, readPartFills, withPartFill, type PartFill, type PartFillResolved } from \"../kit/part-fills\";\nimport { GRAPH_LAYOUTS, layOut, type GraphEdge, type GraphLayout } from \"./graph-layout\";\n\n/** A vertex placed by hand, in the graph's box from -1 to 1 each way, y up. */\nexport interface GraphPosition {\n vertex: string;\n x: number;\n y: number;\n}\n\n// Every list keeps each entry as it was written, a blank or a repeat included, so\n// an editor showing the list shows the row it just added. What is drawn skips\n// what is not complete yet (`names`, `links`).\n\nfunction readVertices(value: readonly unknown[] | undefined): string[] {\n return (Array.isArray(value) ? value : []).map((name) => String(name ?? \"\"));\n}\n\n// An edge reads from `{ from, to }` or a pair, so a list written by hand is as good as one from a table.\nfunction readEdges(value: readonly unknown[] | undefined): GraphEdge[] {\n return (Array.isArray(value) ? value : []).map((edge) => {\n const [from, to] = Array.isArray(edge) ? edge : [(edge as GraphEdge)?.from, (edge as GraphEdge)?.to];\n return { from: String(from ?? \"\"), to: String(to ?? \"\") };\n });\n}\n\nfunction readPositions(value: readonly GraphPosition[] | undefined): GraphPosition[] {\n const at = (n: unknown) => (typeof n === \"number\" && Number.isFinite(n) ? n : 0);\n return (Array.isArray(value) ? value : []).map((entry) => ({ vertex: String(entry?.vertex ?? \"\"), x: at(entry?.x), y: at(entry?.y) }));\n}\n\n/** How far a directed edge and the one back between the same two vertices bow apart, as a share of their length. */\nconst BOW = 0.12;\n\nconst NUL = String.fromCharCode(0);\n\nconst state = {\n ...PAINT,\n vertices: Types.custom<string[]>([], { resolve: readVertices, animatable: false, kind: \"vector\" }),\n edges: Types.custom<GraphEdge[]>([], { resolve: readEdges, animatable: false, kind: \"vector\" }),\n /** Draw each edge as an arrow from its `from` to its `to`. */\n directed: Types.boolean(false, { animatable: false }),\n arrangement: listed(GRAPH_LAYOUTS, \"circular\", { animatable: false }),\n /** The vertex a tree hangs from; left empty, the first. */\n root: Types.text(\"\", { animatable: false }),\n /** Vertices placed by hand, whatever the layout says, in the box from -1 to 1 each way. */\n positions: Types.custom<GraphPosition[]>([], { resolve: readPositions, animatable: false, kind: \"vector\" }),\n vertexRadius: Types.number(18, { min: 0, unit: \"px\" }),\n vertexStroke: Types.stroke([]),\n labels: Types.boolean(true, { animatable: false }),\n labelSize: Types.number(18, { min: 1, unit: \"px\" }),\n labelColor: Types.color(\"#111827\"),\n fontFamily: Types.text(\"\", { animatable: false }),\n /** Paints for a vertex by its name, or an edge written `a-b`, over the graph's own. */\n partFills: Types.custom<PartFill[], PartFillResolved[]>([], { resolve: readPartFills, lerp: lerpPartFills, kind: \"vector\" }),\n /** The arrangement an `arrangeTo` is leaving, and how far it is towards the new one. */\n layoutFrom: Types.text(\"\", { private: true }),\n layoutMix: Types.number(1, { private: true }),\n};\n\nexport type GraphValues = Values<typeof state>;\n\n/**\n * Vertices and the edges between them, arranged by a rule (circle, springs, tree,\n * grid). Its `fill` is the vertices and its `stroke` the edges. (`layout` is every node's own box.)\n */\nexport const NetworkGraph = component2d({\n key: \"networkGraph\",\n state,\n defaults: {\n fill: \"#e5e7eb\",\n stroke: { weight: 3, fill: \"#9ca3af\", align: \"center\", cap: \"round\" },\n },\n load: (loader, s) => {\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\n if (s.labels) loadFormulas(loader, names(s));\n },\n commands: {\n ...PAINT_COMMANDS,\n /** Move every vertex to where another arrangement places it. */\n arrangeTo: {\n // No default: one left out keeps the arrangement the graph has.\n args: { arrangement: listed(GRAPH_LAYOUTS, undefined) },\n run: (timeline, s) => {\n const from = s.arrangement;\n const to = timeline.args.arrangement ?? from;\n return timeline.animate((t) => ({ arrangement: to, layoutFrom: from, layoutMix: t }));\n },\n },\n /** Paint one part of the graph: a vertex by its name, or an edge written `a-b`. */\n partFillTo: {\n args: { part: Types.text(\"\"), fill: Types.custom<Fill>(\"#facc15\", { kind: \"fills\" }) },\n run: (timeline, s) => {\n const { part, fill } = timeline.args;\n if (!part || fill == null) return timeline.tween({});\n return timeline.tween({ partFills: withPartFill(s.partFills, { part, fill }) });\n },\n },\n },\n render: (ctx, s) => painted(ctx, () => drawGraph(ctx, s)),\n});\n\nexport type NetworkGraph = NodeOf<typeof NetworkGraph>;\n\n/** Where each vertex is drawn in a graph of `size`, in pixels from its centre, y up. */\nexport function vertexPoints(graph: GraphValues, size: Size2D): Map<string, Vector2> {\n const room = graph.vertexRadius + Math.max(2, graph.labelSize * 0.2);\n const halfX = Math.max(0, size.width / 2 - room);\n const halfY = Math.max(0, size.height / 2 - room);\n const to = placed(graph, graph.arrangement);\n const from = graph.layoutMix < 1 && graph.layoutFrom !== \"\" ? placed(graph, graph.layoutFrom as GraphLayout) : null;\n const t = graph.layoutMix;\n const out = new Map<string, Vector2>();\n for (const [name, p] of to) {\n const q = from?.get(name) ?? p;\n out.set(name, { x: (q.x + (p.x - q.x) * t) * halfX, y: (q.y + (p.y - q.y) * t) * halfY });\n }\n return out;\n}\n\nfunction drawGraph(ctx: RenderContext, graph: GraphValues): void {\n const points = vertexPoints(graph, ctx.size);\n if (points.size === 0) return;\n const parts = new Map((graph.partFills as PartFillResolved[]).map((entry) => [entry.part, entry]));\n drawEdges(ctx, graph, points, parts);\n drawVertices(ctx, graph, points, parts);\n}\n\n// Two layouts are held at once while one becomes the other, and a scene may hold several graphs.\nconst layouts = createBoundedCache<Map<string, Vector2>>(32);\n\n/** Each vertex's place under `layout`, from -1 to 1, a hand-placed one where it is. */\nfunction placed(graph: GraphValues, layout: GraphLayout): Map<string, Vector2> {\n const vertices = names(graph);\n const edges = links(graph);\n const key = [layout, graph.root, vertices.join(NUL), JSON.stringify(edges), JSON.stringify(graph.positions)].join(\"|\");\n let at = layouts.get(key);\n if (!at) {\n at = layOut(layout, vertices, edges, graph.root.trim());\n for (const { vertex, x, y } of graph.positions) {\n const name = vertex.trim();\n if (at.has(name)) at.set(name, { x, y });\n }\n layouts.set(key, at);\n }\n return at;\n}\n\nfunction drawEdges(ctx: RenderContext, graph: GraphValues, points: Map<string, Vector2>, parts: Map<string, PartFillResolved>): void {\n const stroke = graph.stroke as StrokeResolved[];\n if (stroke.length === 0) return;\n const r = graph.vertexRadius;\n const all = links(graph);\n const pairs = new Set(all.map(({ from, to }) => `${from}${NUL}${to}`));\n const plain = new Graphics2D();\n let drawnPlain = false;\n for (const { from, to } of all) {\n const a = points.get(from);\n const b = points.get(to);\n if (!a || !b) continue;\n const run = from === to ? loop(a, r) : edge(a, b, r, graph.directed && pairs.has(`${to}${NUL}${from}`) ? BOW : 0);\n if (run.length < 2) continue;\n const paint = parts.get(`${from}-${to}`) ?? (graph.directed ? undefined : parts.get(`${to}-${from}`));\n const own = graph.directed || paint !== undefined;\n const g = own ? new Graphics2D() : plain;\n g.line({ points: run, radius: 0, start: graph.start, end: graph.end });\n if (!own) {\n drawnPlain = true;\n continue;\n }\n let layers = stroke;\n if (paint) layers = layers.map((layer) => ({ ...layer, fill: partPaint(layer.fill, paint) }));\n if (graph.directed && from !== to) layers = layers.map((layer) => ({ ...layer, endCap: layer.endCap ?? \"triangle\" }));\n ctx.draw(g.stroke(layers));\n }\n if (drawnPlain) ctx.draw(plain.stroke(stroke));\n}\n\nfunction drawVertices(ctx: RenderContext, graph: GraphValues, points: Map<string, Vector2>, parts: Map<string, PartFillResolved>): void {\n const r = graph.vertexRadius;\n const fill = graph.fill as FillResolved[];\n const outline = graph.vertexStroke as StrokeResolved[];\n const labels: Label[] = [];\n for (const [name, p] of points) {\n if (r > 0) {\n const paint = partPaint(fill, parts.get(name));\n const disc = new Graphics2D().ellipse({ x: p.x, y: p.y, width: r * 2, height: r * 2 });\n ctx.draw(disc.shadow(graph.shadow as ShadowResolved[]).fill(paint));\n if (outline.length > 0) ctx.draw(new Graphics2D().ellipse({ x: p.x, y: p.y, width: r * 2, height: r * 2 }).stroke(outline));\n }\n if (graph.labels) labels.push({ text: name, at: { x: p.x, y: p.y }, align: \"center\" });\n }\n for (const part of drawLabels(labels, { fontSize: graph.labelSize, fontFamily: graph.fontFamily, color: graph.labelColor as NormalizedColor })) {\n ctx.draw(part);\n }\n}\n\n/** The vertices drawn: each name once, trimmed, the blank ones left out. */\nfunction names(graph: Pick<GraphValues, \"vertices\">): string[] {\n return [...new Set(graph.vertices.map((name) => name.trim()).filter((name) => name !== \"\"))];\n}\n\n/** The edges drawn: both ends named. */\nfunction links(graph: Pick<GraphValues, \"edges\">): GraphEdge[] {\n return graph.edges.flatMap(({ from, to }) => {\n const a = from.trim();\n const b = to.trim();\n return a === \"\" || b === \"\" ? [] : [{ from: a, to: b }];\n });\n}\n\n/** An edge from one vertex's rim to the other's, straight or bowed to its left. */\nfunction edge(a: Vector2, b: Vector2, r: number, bow: number): Vector2[] {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const length = Math.hypot(dx, dy);\n if (!(length > 2 * r)) return [];\n if (bow === 0) {\n const ux = dx / length;\n const uy = dy / length;\n return [{ x: a.x + ux * r, y: a.y + uy * r }, { x: b.x - ux * r, y: b.y - uy * r }];\n }\n const mid = { x: (a.x + b.x) / 2 - (dy / length) * bow * length, y: (a.y + b.y) / 2 + (dx / length) * bow * length };\n const run: Vector2[] = [];\n for (let i = 0; i <= 16; i++) {\n const t = i / 16;\n const u = 1 - t;\n run.push({ x: u * u * a.x + 2 * u * t * mid.x + t * t * b.x, y: u * u * a.y + 2 * u * t * mid.y + t * t * b.y });\n }\n // Trimmed back to the rims along the curve.\n const outside = (p: Vector2, c: Vector2) => Math.hypot(p.x - c.x, p.y - c.y) >= r;\n return run.filter((p) => outside(p, a) && outside(p, b));\n}\n\n/** An edge from a vertex to itself: a small loop above it. */\nfunction loop(c: Vector2, r: number): Vector2[] {\n const run: Vector2[] = [];\n const radius = Math.max(r * 0.8, 6);\n const cy = c.y + r + radius * 0.6;\n for (let i = 0; i <= 24; i++) {\n const angle = -Math.PI / 2 + (2 * Math.PI * i) / 24;\n const p = { x: c.x + Math.cos(angle) * radius, y: cy + Math.sin(angle) * radius };\n if (Math.hypot(p.x - c.x, p.y - c.y) >= r) run.push(p);\n }\n return run;\n}\n", "import {\n component2d,\n fillOps,\n Graphics2D,\n Types,\n type Fill,\n type FillResolved,\n type NodeOf,\n type Color as _Color,\n\n type NormalizedColor,\n type RenderContext,\n type ShadowResolved,\n type Size2D,\n type StrokeResolved,\n type Values,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type Stroke as _Stroke,\n} from \"@motionscript/sdk\";\nimport { braceOutline } from \"../kit/brace\";\nimport { omit, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\nimport { drawLabels, loadFormulas, type Label } from \"../kit/furniture\";\nimport { lerpFillScale, readFillScale } from \"../kit/scale\";\nimport { formatTick } from \"../kit/ticks\";\n\n/** The parts' paints until told otherwise, a column each, round again past the last. */\nconst PALETTE = [\"#58a6ff\", \"#f59e0b\", \"#4ade80\", \"#f472b6\", \"#a78bfa\", \"#2dd4bf\"];\n\n/** How strongly the lower part of a split column shows its paint. */\nconst LOWER = 0.45;\n\nfunction readShares(value: readonly number[] | undefined): number[] {\n return (Array.isArray(value) ? value : []).map((share) => (Number.isFinite(share) && share > 0 ? share : 0));\n}\n\n// Shares tween one by one; a different count has nothing to pair with, and changes at the end.\nfunction lerpShares(from: number[], to: number[], t: number): number[] {\n if (from.length !== to.length) return t < 1 ? from : to;\n return to.map((share, i) => from[i] + (share - from[i]) * t);\n}\n\nconst state = {\n // Its parts are painted from `columnFills`, and it trims no outline of its own.\n ...omit(PAINT, \"fill\", \"start\", \"end\"),\n /** How the whole is shared across, left to right; any numbers, read as shares of their sum. */\n columnShares: Types.custom<number[]>([1], { resolve: readShares, lerp: lerpShares, kind: \"vector\" }),\n /** Each column's upper share, 0 to 1; a column without one is not cut across. */\n rowShares: Types.custom<number[]>([], { resolve: readShares, lerp: lerpShares, kind: \"vector\" }),\n /** Each column's paint, left to right, round again past the last; its lower part shows it fainter. */\n columnFills: Types.custom<Fill[], FillResolved[][]>([], { resolve: readFillScale, lerp: lerpFillScale, kind: \"vector\" }),\n columnLabels: Types.custom<string[]>([], { animatable: false, kind: \"vector\" }),\n /** The upper part's name and the lower's, written on the left. */\n rowLabels: Types.custom<string[]>([], { animatable: false, kind: \"vector\" }),\n /** Write each part's probability in it. */\n values: Types.boolean(false, { animatable: false }),\n labelSize: Types.number(20, { min: 1, unit: \"px\" }),\n labelColor: Types.color(\"#e5e7eb\"),\n fontFamily: Types.text(\"\", { animatable: false }),\n};\n\nexport type SampleSpaceValues = Values<typeof state>;\n\n/** One part of a sample space: its box in pixels from the node's centre, y up, and its probability. */\nexport interface SamplePart {\n x: number;\n y: number;\n width: number;\n height: number;\n probability: number;\n column: number;\n upper: boolean;\n}\n\n/**\n * A probability's whole as a box cut into columns by `columnShares`, each cut\n * again by its `rowShares` entry (P(B | A) above, the rest below): each part's\n * area is its probability.\n */\nexport const SampleSpace = component2d({\n key: \"sampleSpace\",\n state,\n defaults: { stroke: { weight: 2, fill: \"#0b0d12\", align: \"center\" } },\n load: (loader, s) => {\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\n loadFormulas(loader, [...s.columnLabels, ...s.rowLabels]);\n },\n commands: {\n ...omit(PAINT_COMMANDS, \"fillTo\", \"progressTo\", \"flash\"),\n /** Move the cuts: the columns' shares, each column's upper share, or both. */\n divideTo: { args: [\"columnShares\", \"rowShares\"] },\n },\n render: (ctx, s) => painted(ctx, () => drawSpace(ctx, s)),\n});\n\nexport type SampleSpace = NodeOf<typeof SampleSpace>;\n\n/** Each part of a sample space of `size`: columns left to right, upper part first. */\nexport function sampleParts(space: SampleSpaceValues, size: Size2D): SamplePart[] {\n const box = boxOf(space, size);\n const shares = space.columnShares;\n const total = shares.reduce((sum, share) => sum + share, 0);\n if (!(total > 0) || box.width <= 0 || box.height <= 0) return [];\n const out: SamplePart[] = [];\n let left = box.x - box.width / 2;\n shares.forEach((share, column) => {\n const width = (box.width * share) / total;\n const p = share / total;\n const cut = space.rowShares[column];\n const top = box.y + box.height / 2;\n if (cut === undefined) {\n out.push({ x: left + width / 2, y: box.y, width, height: box.height, probability: p, column, upper: true });\n } else {\n const upper = Math.min(1, Math.max(0, cut));\n const h = box.height * upper;\n out.push({ x: left + width / 2, y: top - h / 2, width, height: h, probability: p * upper, column, upper: true });\n out.push({ x: left + width / 2, y: top - h - (box.height - h) / 2, width, height: box.height - h, probability: p * (1 - upper), column, upper: false });\n }\n left += width;\n });\n return out;\n}\n\nfunction drawSpace(ctx: RenderContext, space: SampleSpaceValues): void {\n const parts = sampleParts(space, ctx.size);\n if (parts.length === 0) return;\n const fills = space.columnFills;\n const stroke = space.stroke as StrokeResolved[];\n const labels: Label[] = [];\n for (const part of parts) {\n if (!(part.width > 0) || !(part.height > 0)) continue;\n const base = fills.length > 0 ? fills[part.column % fills.length] : fillOps.resolve(PALETTE[part.column % PALETTE.length]);\n const paint = part.upper ? base : base.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * LOWER }));\n const g = new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height });\n ctx.draw(g.shadow(space.shadow as ShadowResolved[]).fill(paint));\n if (stroke.length > 0) ctx.draw(new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height }).stroke(stroke));\n if (space.values && part.height > space.labelSize && part.width > space.labelSize) {\n labels.push({ text: formatTick(Math.round(part.probability * 1000) / 1000, 0.001), at: { x: part.x, y: part.y }, align: \"center\" });\n }\n }\n labels.push(...braces(ctx, space, parts));\n const style = { fontSize: space.labelSize, fontFamily: space.fontFamily, color: space.labelColor as NormalizedColor };\n for (const part of drawLabels(labels, style)) ctx.draw(part);\n}\n\n/** Room for the braces and their names, below and on the left, taken from the box. */\nfunction boxOf(space: SampleSpaceValues, size: Size2D): { x: number; y: number; width: number; height: number } {\n const { width, height } = size;\n const room = space.labelSize * 2.6;\n const below = space.columnLabels.some((label) => label !== \"\") ? room : 0;\n const left = space.rowLabels.some((label) => label !== \"\") ? room * 1.6 : 0;\n return { x: left / 2, y: below / 2, width: Math.max(0, width - left), height: Math.max(0, height - below) };\n}\n\n/** Braces under each column and beside the first column's parts, and the labels that name them. */\nfunction braces(ctx: RenderContext, space: SampleSpaceValues, parts: readonly SamplePart[]): Label[] {\n const box = boxOf(space, ctx.size);\n const reach = space.labelSize * 0.8;\n const gap = 6;\n const runs = new Graphics2D();\n const labels: Label[] = [];\n let drawn = false;\n const brace = (from: Vector2, to: Vector2, out: Vector2, text: string, align: Label[\"align\"]) => {\n if (text === \"\") return;\n // A frame centred on the node's own centre, so the path is drawn where it is and not moved onto it.\n runs.path({ data: braceOutline(from, to, out, reach), centerBounds: [-1, -1, 1, 1] });\n drawn = true;\n const mid = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 };\n const far = reach + space.labelSize * 0.75;\n labels.push({ text, at: { x: mid.x + out.x * far, y: mid.y + out.y * far }, align });\n };\n const bottom = box.y - box.height / 2 - gap;\n for (const part of parts) {\n if (!part.upper && space.rowShares[part.column] !== undefined) continue;\n const text = space.columnLabels[part.column] ?? \"\";\n // Left to right along the bottom, so the bulge, to the edge's right, points down.\n brace({ x: part.x + part.width / 2, y: bottom }, { x: part.x - part.width / 2, y: bottom }, { x: 0, y: -1 }, text, \"center\");\n }\n const first = parts.filter((part) => part.column === 0);\n const left = box.x - box.width / 2 - gap;\n if (space.rowShares[0] !== undefined) {\n first.forEach((part) => {\n const text = space.rowLabels[part.upper ? 0 : 1] ?? \"\";\n brace({ x: left, y: part.y - part.height / 2 }, { x: left, y: part.y + part.height / 2 }, { x: -1, y: 0 }, text, \"right\");\n });\n }\n if (drawn) {\n const fill = fillOps.resolve({ type: \"solid\", color: space.labelColor as NormalizedColor });\n ctx.draw(runs.stroke({ weight: 2, fill, align: \"center\", cap: \"round\", join: \"round\" }));\n }\n return labels;\n}\n"],
5
+ "mappings": "2LAAA,OAAS,cAAAA,OAA8C,oBAmCjD,SAAUC,GAAgBC,EAA6BC,EAAuB,SAAQ,CACxF,GAAI,CAACC,EAAKC,CAAG,EAAIH,GAAS,CAAC,EAAG,CAAC,EAC/B,OAAI,CAAC,OAAO,SAASE,CAAG,GAAK,CAAC,OAAO,SAASC,CAAG,KAAG,CAACD,EAAKC,CAAG,EAAI,CAAC,EAAG,CAAC,GAClED,EAAMC,IAAK,CAACD,EAAKC,CAAG,EAAI,CAACA,EAAKD,CAAG,GACjCD,IAAY,QACNE,EAAM,IAAIA,EAAM,IAChBD,EAAM,IAAIA,EAAMC,EAAM,MAEzBA,EAAMD,EAAM,CAACA,EAAKC,CAAG,EAAI,CAACD,EAAKA,EAAM,CAAC,CACjD,CAGM,SAAUE,GAAUJ,EAAiBK,EAAYC,EAAYL,EAAuB,SAAQ,CAC9F,GAAM,CAACC,EAAKC,CAAG,EAAIH,EACnB,GAAIC,IAAY,MAAO,CACnB,IAAMM,EAAO,KAAK,MAAML,CAAG,EACrBM,GAAKF,EAAKD,IAAO,KAAK,MAAMF,CAAG,EAAII,GACzC,MAAO,CAAE,GAAKE,GAAMJ,GAAM,KAAK,MAAMI,CAAC,EAAIF,GAAQC,EAAG,KAAOE,GAAM,KAAOH,GAAQG,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,OAAQI,GAASA,EAAK,SAAW,CAAC,EAChDX,EAAON,EAAI,EAAIA,EAAI,MAAQ,EAAIiC,EAOrC,GANInC,EAAM,UAAU,CAAC,IAAM,QACvB6C,EAAM,QAAS1B,GAAQ,CACnB,IAAMoB,EAAOvC,EAAM,UAAUmB,EAAK,MAAQ,EAAI,CAAC,GAAK,GACpDmB,EAAM,CAAE,EAAG9B,EAAM,EAAGW,EAAK,EAAIA,EAAK,OAAS,CAAC,EAAI,CAAE,EAAGX,EAAM,EAAGW,EAAK,EAAIA,EAAK,OAAS,CAAC,EAAI,CAAE,EAAG,GAAI,EAAG,CAAC,EAAIoB,EAAM,OAAO,CAC5H,CAAC,EAEDF,EAAO,CACP,IAAMS,EAAOzB,GAAQ,QAAQ,CAAE,KAAM,QAAS,MAAOrB,EAAM,UAA6B,CAAE,EAC1FJ,EAAI,KAAKwC,EAAK,OAAO,CAAE,OAAQ,EAAG,KAAAU,EAAM,MAAO,SAAU,IAAK,QAAS,KAAM,OAAO,CAAE,CAAC,CAC3F,CACA,OAAO5B,CACX",
6
+ "names": ["lerpNumber", "resolveInterval", "range", "scaling", "min", "max", "axisScale", "lo", "hi", "from", "k", "v", "p", "cartesianMap", "xRange", "yRange", "area", "xScaling", "yScaling", "x", "y", "gx", "gy", "out", "px", "py", "UNBOUNDED", "PIXEL_MAP", "IDENTITY_MATRIX", "readMatrix", "value", "previous", "flat", "entry", "lerpMatrix", "to", "t", "i", "isIdentityMatrix", "a", "b", "c", "d", "REACH", "reach", "middle", "half", "transformedMap", "base", "matrix", "det", "back", "u", "xReach", "yReach", "corner", "minX", "minY", "maxX", "maxY", "warpedMap", "warp", "key", "bend", "at", "dx", "dy", "H", "target", "ex", "ey", "j00", "j10", "j01", "j11", "widened", "WARP_MARGIN", "margin", "CURVED_STEPS", "lineThrough", "map", "x0", "y0", "x1", "y1", "run", "Fills", "Graphics2D", "lerpNumber", "toPathString", "Types", "AXIS_COLOR", "PLOT_COLOR", "withoutTips", "stroke", "layer", "LABEL_BOX_EM", "FORMULA", "declareFormulas", "assets", "texts", "text", "MATHJAX_LOADER", "loadMathJax", "loadFormulas", "loader", "drawLabels", "labels", "style", "out", "fill", "Fills", "Graphics2D", "width", "written", "label", "formula", "glyphs", "typeset", "glyph", "at", "align", "source", "fontSize", "buildLatexPath", "error", "LatexNotLoaded", "minX", "minY", "maxX", "maxY", "dx", "frame", "token", "toPathString", "drawn", "u", "start", "end", "along", "from", "to", "dy", "length", "lerpInterval", "t", "lerpNumber", "intervalEntry", "initial", "Types", "readInterval", "value", "previous", "min", "max", "expressionOps", "UNARY", "NARY", "a", "b", "CONSTANTS", "MATH_DIALECT", "name", "arity", "expressionVocabulary", "variables", "compileExpression", "source", "params", "emit", "expressionOps", "node", "value", "slot", "_a", "_b", "scope", "operand", "s", "l", "args", "arg", "unary", "x", "fn", "y", "compiled", "createBoundedCache", "compileExpressionCached", "remember", "compilerFor", "text", "result", "expressionOps", "EQUATION_VARIABLES", "parseEquation", "memoParse", "read", "equationError", "source", "equation", "equationParams", "VARIABLE_NAMES", "named", "createBoundedCache", "equationNames", "hit", "names", "text", "part", "splitTuple", "splitTopLevel", "collectNames", "expressionOps", "MATH_DIALECT", "result", "name", "node", "into", "arg", "params", "compile", "compilerFor", "pair", "sides", "left", "right", "subject", "implicit", "l", "r", "x", "y", "scope", "of", "error", "depth", "i", "parts", "separator", "from", "c", "readSource", "value", "lerpSource", "from", "to", "t", "lerpDomain", "UNSET_PARAM", "lerpParams", "out", "name", "start", "scopeFor", "names", "params", "filled", "revisionOf", "key", "hash", "i", "CURVE_KEYS", "curveValue", "curve", "x", "source", "blend", "shift", "NO_SHIFT", "value", "heightOf", "from", "isCurve", "view", "params", "equation", "parseEquation", "equationParams", "scopeFor", "createContext", "Types", "SYSTEM", "createContext", "PLOT", "SYSTEM_ENTRY", "Types", "use", "PLANE_ENTRY", "PLOT_REF", "NO_CURVES", "SystemPlane", "PIXEL_MAP", "PlotPlane", "parent", "enclosing", "systems", "plots", "systemPlane", "state", "plane", "settle", "map", "children", "curves", "collectCurves", "plotPlane", "plot", "curveFor", "on", "isCurve", "id", "refId", "into", "child", "CURVE_KEYS", "runsToPath", "runs", "closed", "out", "run", "i", "boundsOfRuns", "minX", "minY", "maxX", "maxY", "p", "inflate", "area", "margin", "radians", "degrees", "clamp", "value", "min", "max", "stated", "data", "key", "Graphics2D", "NO_SHIFT", "tracers", "traced", "component", "trace", "child", "markRuns", "map", "plane", "mark", "entry", "state", "reading", "PIXEL_MAP", "inkSize", "runs", "ink", "boundsOfRuns", "inkCentre", "ownPoint", "read", "point", "at", "centre", "graphPoint", "NONE", "markShape", "s", "closed", "data", "runsToPath", "centerBounds", "Graphics2D", "drawMark", "ctx", "options", "shape", "fill", "painted", "strokeShape", "stroke", "castsShadow", "layer", "anchors", "anchored", "component", "anchor", "child", "placeOnMap", "children", "map", "origin", "room", "plane", "runs", "markRuns", "ink", "boundsOfRuns", "cx", "cy", "markPlane", "size", "entry", "a", "pointPlane", "openPlane", "x", "y", "at", "point", "none", "Graphics2D", "insetsOps", "Paint", "provides", "CENTRE", "plotArea", "size", "padding", "inner", "insetsOps", "systemMap", "state", "mapFor", "systemSize", "left", "right", "top", "bottom", "systemProvides", "provides", "SYSTEM", "systemPlane", "systemLayout", "children", "map", "plane", "settle", "placeOnMap", "systemOpenPlane", "openPlane", "drawSystem", "ctx", "furniture", "width", "height", "minX", "minY", "maxX", "maxY", "area", "Graphics2D", "parts", "Paint", "niceStep", "MAX_TICKS", "AUTO_SPACING", "ticksFor", "range", "step", "length", "scaling", "min", "max", "decades", "span", "chosen", "multiplesWithin", "values", "k", "first", "count", "out", "i", "decadeOf", "value", "formatTick", "decade", "trimExponent", "digits", "decimals", "decimalsOf", "text", "d", "scaled", "mantissa", "exponent", "component2d", "Graphics2D", "Types", "state", "PAINT", "intervalEntry", "Types", "listed", "AXIS_COLOR", "NumberLine", "component2d", "loader", "s", "PAINT_COMMANDS", "systemProvides", "_measurer", "systemSize", "box", "children", "systemLayout", "lineMap", "systemOpenPlane", "ctx", "drawSystem", "systemMap", "map", "lineFurniture", "area", "cartesianMap", "resolveInterval", "stroke", "start", "end", "min", "max", "from", "to", "parts", "Graphics2D", "marks", "ticksFor", "sign", "tickMarks", "labels", "ticked", "value", "at", "drawn", "along", "half", "formatTick", "withoutTips", "drawLabels", "component2d", "Graphics2D", "Types", "AXES", "PAINT", "intervalEntry", "Types", "listed", "AXIS_COLOR", "AXES_COMMANDS", "PAINT_COMMANDS", "loadAxes", "loader", "s", "loadFormulas", "axesMap", "area", "xRange", "resolveInterval", "yRange", "width", "span", "centre", "cartesianMap", "axesOf", "map", "xMin", "xMax", "yMin", "yMax", "crossX", "clamp", "crossY", "xFrom", "xTo", "yFrom", "yTo", "lineThrough", "ticksFor", "value", "axesFurniture", "backdrop", "stroke", "start", "end", "x", "y", "parts", "Graphics2D", "half", "gap", "tickMarks", "labels", "ticked", "mark", "axis", "horizontal", "at", "drawn", "along", "formatTick", "withoutTips", "drawLabels", "Axes2d", "component2d", "systemProvides", "_measurer", "systemSize", "box", "children", "systemLayout", "systemOpenPlane", "ctx", "drawSystem", "systemMap", "FIELD_VARIABLES", "NAMES", "fieldParams", "source", "equationNames", "name", "parseField", "memoParse", "text", "params", "parts", "splitTuple", "compile", "compilerFor", "x", "y", "part", "fieldError", "field", "component2d", "Graphics2D", "Types", "state", "AXES", "Types", "readMatrix", "lerpMatrix", "readSource", "lerpSource", "NumberPlane", "component2d", "AXIS_COLOR", "s", "spills", "loader", "loadAxes", "AXES_COMMANDS", "systemProvides", "_measurer", "systemSize", "box", "children", "systemLayout", "planeMap", "systemOpenPlane", "ctx", "flat", "map", "planeMaps", "plotArea", "drawSystem", "on", "axesFurniture", "x", "y", "grid", "area", "axesMap", "isIdentityMatrix", "transformedMap", "source", "blend", "to", "warpOf", "warpedMap", "from", "start", "out", "STAY", "parts", "gx", "gy", "axesOf", "ruled", "ghost", "end", "xMin", "xMax", "yMin", "yMax", "lines", "values", "vertical", "g", "Graphics2D", "value", "lineThrough", "minor", "divisions", "between", "axis", "min", "max", "step", "base", "i", "xs", "ys", "major", "field", "parseField", "fieldParams", "wx", "wy", "component2d", "Graphics2D", "Types", "LABEL_ROOM", "state", "PAINT", "Types", "listed", "AXIS_COLOR", "PolarPlane", "component2d", "loader", "s", "PAINT_COMMANDS", "systemProvides", "_measurer", "systemSize", "box", "children", "systemLayout", "polarMap", "systemOpenPlane", "ctx", "drawSystem", "systemMap", "map", "polarFurniture", "area", "width", "height", "unit", "cartesianMap", "stroke", "grid", "start", "end", "radius", "centre", "reach", "at", "r", "degrees", "angle", "radians", "ring", "g", "size", "parts", "marks", "ticksFor", "rings", "count", "turns", "_", "i", "inner", "Graphics2D", "labels", "p", "formatTick", "cos", "sin", "radiansLabel", "drawLabels", "numerator", "denominator", "a", "b", "top", "traceContour", "f", "x0", "x1", "y0", "y1", "columns", "rows", "dx", "dy", "stride", "values", "j", "i", "points", "edgeCount", "crossing", "vertical", "a", "b", "key", "t", "next", "join", "bottom", "top", "left", "right", "found", "edge", "centre", "corner", "runs", "used", "walk", "from", "run", "at", "onward", "links", "arena", "arenaMark", "takeSample", "slot", "blank", "scratch", "sampleCurve", "project", "t0", "t1", "clip", "seeds", "minStep", "pen", "CurvePen", "spent", "write", "t", "defined", "ok", "clampCoord", "at", "edgeOf", "from", "to", "inside", "outsideT", "i", "offFrame", "midT", "mid", "settled", "emit", "a", "m", "b", "floored", "diverges", "edge", "refine", "depth", "flat", "count", "step", "ends", "previous", "next", "dx", "dy", "length", "turn", "sample", "value", "segment", "clipSegment", "start", "end", "samePoint", "point", "x", "y", "ax", "ay", "bx", "by", "edges", "p", "q", "r", "component2d", "provides", "Types", "TAU", "PLOT_STATE", "omit", "PAINT", "Types", "readSource", "lerpSource", "lerpDomain", "lerpParams", "SYSTEM_ENTRY", "PLOT_COMMANDS", "PAINT_COMMANDS", "PLOT_STROKE", "PLOT_COLOR", "FunctionPlot", "traced", "component2d", "s", "inherited", "provides", "PLOT", "plotPlane", "SYSTEM", "_measurer", "inkSize", "tracePlot", "reading", "box", "children", "read", "placeOnMap", "inkCentre", "_box", "openPlane", "ctx", "drawMark", "traces", "createBoundedCache", "span", "map", "shift", "area", "source", "blend", "key", "known", "runs", "shown", "equationOf", "contour", "curve", "projectionOf", "from", "between", "width", "sampleCurve", "equation", "parseEquation", "equationParams", "params", "scope", "scopeFor", "cells", "pixels", "CONTOUR_MAX", "CONTOUR_CELL", "f", "traceContour", "x", "y", "run", "point", "domain", "horizontal", "lo", "hi", "offset", "a", "b", "u", "out", "v", "w", "theta", "r", "t", "gx", "gy", "to", "component2d", "Types", "lerpPoints", "from", "to", "t", "count", "out", "b", "SMOOTH_STEPS", "state", "PAINT", "Types", "PLANE_ENTRY", "PointsPlot", "traced", "component2d", "PLOT_COLOR", "PAINT_COMMANDS", "_measurer", "s", "inkSize", "tracePoints", "reading", "ctx", "drawMark", "map", "shift", "pixels", "p", "spline", "points", "closed", "n", "at", "i", "spans", "p0", "p1", "p2", "p3", "t2", "t3", "colorOps", "fillOps", "readScale", "value", "color", "colorOps", "lerpScale", "from", "to", "t", "index", "colorAt", "scale", "share", "at", "clamp", "readFillScale", "fill", "fillOps", "lerpFillScale", "fillAt", "Graphics2D", "Types", "SHADES", "FIELD_STATE", "omit", "PAINT", "Types", "readSource", "lerpSource", "lerpParams", "readFillScale", "lerpFillScale", "PLANE_ENTRY", "FIELD_COMMANDS", "PAINT_COMMANDS", "traces", "createBoundedCache", "EMPTY", "traceField", "kind", "drawing", "s", "map", "shift", "area", "source", "blend", "key", "known", "field", "sampler", "drawn", "traced", "stroke", "drawField", "ctx", "runs", "scale", "shaded", "drawMark", "ink", "top", "most", "d", "shades", "share", "shade", "index", "fill", "fillAt", "Graphics2D", "runsToPath", "layer", "to", "fieldOf", "from", "start", "x", "y", "out", "params", "names", "fieldParams", "parseField", "scope", "scopeFor", "gx", "gy", "vx", "vy", "component2d", "Types", "MAX_ARROWS", "HEAD_SHARE", "HEAD_MAX", "HEAD_ANGLE", "radians", "state", "FIELD_STATE", "Types", "ARROWS", "s", "map", "field", "arrows", "traceArrows", "read", "traceField", "VectorField", "traced", "component2d", "PLOT_COLOR", "FIELD_COMMANDS", "_measurer", "inkSize", "reading", "ctx", "drawField", "x0", "x1", "y0", "y1", "spacing", "count", "drawn", "v", "longest", "i", "j", "gx", "gy", "magnitude", "length", "hx", "hy", "tail", "head", "arrow", "dx", "dy", "barb", "back", "at", "angle", "component2d", "Types", "MAX_LINES", "STEPS_PER_SPACING", "MAX_STEPS", "state", "FIELD_STATE", "Types", "LINES", "s", "map", "field", "lines", "traceLines", "read", "traceField", "StreamLines", "traced", "component2d", "PLOT_COLOR", "FIELD_COMMANDS", "_measurer", "inkSize", "reading", "ctx", "drawField", "x0", "x1", "y0", "y1", "spacing", "count", "step", "steps", "inside", "y", "window", "clamp", "drawn", "index", "i", "j", "line", "follow", "shown", "stretch", "stagger", "p", "x", "points", "v", "strength", "heading", "px", "py", "out", "magnitude", "a", "b", "share", "phase", "end", "from", "to", "last", "mixed", "component2d", "Types", "state", "omit", "PLOT_STATE", "Types", "TracedPath", "traced", "component2d", "PLOT_STROKE", "PLOT_COMMANDS", "_measurer", "s", "inkSize", "traceTrail", "reading", "ctx", "drawMark", "read", "tracePlot", "span", "from", "value", "tail", "kept", "component2d", "Graphics2D", "Types", "state", "omit", "PAINT", "PLOT_REF", "Types", "listed", "PLANE_ENTRY", "PlotPoint", "anchored", "component2d", "s", "heightOf", "loader", "loadFormulas", "PAINT_COMMANDS", "_measurer", "ctx", "size", "shape", "Graphics2D", "painted", "gap", "side", "horizontal", "label", "drawLabels", "strokeShape", "plane", "x", "y", "on", "curve", "curveFor", "height", "curveValue", "component2d", "Types", "BEND_STEP", "state", "omit", "PAINT", "Types", "PLANE_ENTRY", "end", "which", "s", "read", "reading", "ownPoint", "traceArrow", "at", "graphPoint", "VectorArrow", "traced", "component2d", "PAINT_COMMANDS", "_measurer", "inkSize", "ctx", "drawMark", "map", "shift", "a", "b", "sweep", "radians", "chord", "radius", "side", "reach", "cx", "cy", "from", "steps", "run", "i", "angle", "component2d", "state", "omit", "PAINT", "PLOT_REF", "intervalEntry", "PLANE_ENTRY", "CurveArea", "traced", "component2d", "PLOT_COLOR", "PAINT_COMMANDS", "_measurer", "s", "inkSize", "traceArea", "reading", "ctx", "drawMark", "map", "plane", "top", "curveFor", "floor", "yMin", "yMax", "a", "b", "width", "steps", "height", "value", "clamp", "upper", "lower", "i", "curveValue", "component2d", "Types", "MAX_RECTANGLES", "state", "omit", "PAINT", "PLOT_REF", "intervalEntry", "Types", "listed", "PLANE_ENTRY", "RiemannSum", "traced", "component2d", "PLOT_COLOR", "PAINT_COMMANDS", "_measurer", "s", "inkSize", "traceSum", "reading", "ctx", "drawMark", "map", "plane", "plot", "curveFor", "a", "b", "dx", "yMin", "yMax", "base", "clamp", "at", "count", "runs", "i", "left", "right", "value", "curveValue", "height", "component2d", "Types", "SLOPE_STEP", "state", "omit", "PAINT", "PLOT_REF", "Types", "PLANE_ENTRY", "TangentLine", "traced", "component2d", "s", "plot", "curveFor", "tangentSlope", "PAINT_COMMANDS", "_measurer", "inkSize", "traceTangent", "reading", "ctx", "drawMark", "curve", "x", "dx", "curveValue", "h", "map", "plane", "y", "half", "y2", "a", "b", "span", "reach", "ux", "uy", "mx", "my", "secant", "xMin", "xMax", "before", "after", "p", "component2d", "state", "omit", "PAINT", "PLOT_REF", "listed", "PLANE_ENTRY", "DropLines", "traced", "component2d", "AXIS_COLOR", "PAINT_COMMANDS", "_measurer", "s", "inkSize", "traceDrops", "reading", "ctx", "drawMark", "map", "plane", "x", "plot", "curveFor", "y", "curveValue", "at", "runs", "clamp", "commandsFor", "pathOps", "Types", "isParted", "node", "isFormula", "partBoundsOf", "part", "occurrence", "latexPartBounds", "restOf", "on", "lerpRetarget", "from", "to", "t", "REF", "Types", "HELD_REF", "FOLLOW_STATE", "omit", "PAINT", "FOLLOW_COMMANDS", "PAINT_COMMANDS", "commandsFor", "timeline", "s", "next", "held", "restingOf", "retarget", "refId", "containers", "container", "ctx", "found", "Latex", "LatexMatrix", "parted", "resting", "followedQuad", "state", "rest", "quadOf", "lerpQuad", "target", "box", "frame", "turn", "radians", "cos", "sin", "place", "x", "y", "w", "h", "a", "b", "i", "outlineBounds", "outline", "ink", "pathOps", "OWN_FRAME", "add", "k", "between", "heading", "dx", "dy", "length", "grown", "quad", "by", "tl", "tr", "br", "bl", "across", "up", "QUARTER", "braceOutline", "from", "to", "out", "reach", "unit", "length", "heading", "r", "mid", "between", "lift", "p", "k", "add", "along", "h", "curve", "c1", "c2", "end", "a", "b", "tip", "c", "d", "component2d", "Graphics2D", "Types", "EDGE", "state", "FOLLOW_STATE", "listed", "Types", "spans", "s", "parted", "resting", "quadOf", "followedQuad", "edgeOf", "quad", "i", "j", "unit", "heading", "out", "add", "outline", "from", "to", "braceOutline", "end", "which", "container", "at", "CurlyBrace", "component2d", "loader", "loadFormulas", "FOLLOW_COMMANDS", "_size", "outlineBounds", "ctx", "data", "shape", "Graphics2D", "OWN_FRAME", "painted", "reach", "between", "align", "style", "drawLabels", "strokeShape", "component2d", "Graphics2D", "Types", "ARC_STEP", "RIGHT_SLOP", "point", "radius", "degrees", "turn", "radians", "state", "omit", "PAINT", "Types", "listed", "AngleMark", "component2d", "s", "angleOf", "loader", "loadFormulas", "PAINT_COMMANDS", "_size", "outlineBounds", "outline", "ctx", "data", "shape", "Graphics2D", "OWN_FRAME", "painted", "text", "at", "style", "drawLabels", "strokeShape", "fromAngle", "toAngle", "corner", "sweep", "side", "a", "b", "steps", "out", "i", "p", "component2d", "Graphics2D", "Types", "QUARTER", "line", "a", "b", "SHAPES", "quad", "gap", "tl", "tr", "br", "bl", "grown", "p", "centre", "between", "across", "up", "at", "u", "add", "arc", "c1", "c2", "end", "k", "start", "down", "heading", "state", "FOLLOW_STATE", "listed", "Types", "outline", "s", "parted", "followedQuad", "EmphasisMark", "component2d", "FOLLOW_COMMANDS", "_size", "outlineBounds", "container", "ctx", "data", "shape", "Graphics2D", "OWN_FRAME", "painted", "strokeShape", "Fills", "Graphics2D", "Mat", "Tex", "EM", "CARD_HEIGHT", "cards", "createBoundedCache", "card", "text", "style", "key", "hit", "width", "source", "Graphics2D", "Fills", "made", "Tex", "drawLabel3D", "g3", "at", "texture", "height", "Mat", "createContext", "Types", "graphSpace", "xRange", "yRange", "zRange", "lengths", "ux", "unit", "uy", "uz", "cx", "cy", "cz", "x", "y", "z", "min", "max", "length", "span", "GRAPH_3D", "graphEntry", "use", "graphOf", "mark", "aim", "direction", "dx", "dy", "dz", "w", "norm", "component2d", "Flow", "Geo", "Graphics3D", "Mat", "Paint", "provides", "Shapes", "Types", "View3D", "UNIT_AS_PIXELS", "ALONG", "TICK_ALONG", "own", "intervalEntry", "Types", "AXIS_COLOR", "Axes3d", "component2d", "Paint", "Flow", "Shapes", "View3D", "loader", "s", "furnish", "provides", "GRAPH_3D", "graphOfAxes", "axesSpace", "measurer", "children", "box", "ctx", "scene", "furniture", "spaces", "xRange", "yRange", "zRange", "xLength", "yLength", "zLength", "key", "kept", "graphSpace", "graphs", "graph", "space", "g3", "Graphics3D", "ranges", "lengths", "steps", "titles", "cross", "clamp", "at", "axis", "value", "shift", "point", "local", "moved", "by", "thickness", "tickSize", "paint", "Mat", "style", "tipLength", "marks", "plane", "min", "max", "length", "from", "to", "Geo", "ticks", "ticksFor", "side", "drawLabel3D", "formatTick", "other", "a", "b", "EQUATION_VARIABLES_3D", "SURFACE_NAMES", "SPACE_CURVE_NAMES", "surfaceParams", "source", "equationNames", "name", "spaceCurveParams", "parseSurface", "memoParse", "text", "params", "compile", "compilerFor", "parts", "splitTuple", "x", "y", "z", "part", "sides", "splitTopLevel", "parseSpaceCurve", "surfaceError", "equation", "spaceCurveError", "EQUATION_KINDS", "equationError", "equationParams", "EQUATION_VARIABLES", "fieldError", "fieldParams", "FIELD_VARIABLES", "Material", "Types", "meshEntries", "Types", "Material", "domainEntry", "defaultMin", "defaultMax", "lerpDomain", "colorOps", "component3d", "Geo", "Graphics3D", "Mat", "Material", "Types", "state", "meshEntries", "Types", "readSource", "lerpSource", "domainEntry", "lerpParams", "readScale", "lerpScale", "graphEntry", "SurfacePlot3d", "component3d", "PLOT_COLOR", "s", "surfaceSpace", "ctx", "declaredSurface", "drawSurface", "surfaceValueAt", "surface", "x", "y", "source", "blend", "value", "heightOf", "from", "space", "graphOf", "z", "height", "paint", "Material", "Graphics3D", "g3", "lines", "meshLines", "scaled", "op", "surfaceGeometry", "mapMaterials", "material", "color", "colorOps", "shadow", "floorShadow", "Mat", "sample", "sampler", "scale", "point", "low", "high", "Geo", "u", "v", "_u", "_v", "position", "colorAt", "revisionOf", "keyOf", "equation", "equationOf", "scopeFor", "surfaceParams", "to", "surfaceOf", "start", "out", "params", "u0", "u1", "v0", "v1", "a", "b", "finite", "x0", "x1", "y0", "y1", "clamp", "floor", "linesDrawn", "count", "steps", "key", "kept", "at", "i", "fixed", "j", "parseSurface", "change", "component3d", "Geo", "Graphics3D", "Material", "Types", "state", "meshEntries", "Types", "readSource", "lerpSource", "domainEntry", "lerpParams", "graphEntry", "CurvePlot3d", "component3d", "PLOT_COLOR", "ctx", "s", "Graphics3D", "Material", "curveGeometry", "space", "graphOf", "points", "pointsOf", "Geo", "runs", "source", "blend", "start", "clamp", "end", "samples", "key", "kept", "run", "to", "curveOf", "from", "steps", "a", "b", "i", "u", "equation", "equationOf", "params", "scopeFor", "spaceCurveParams", "t0", "t1", "x", "y", "z", "out", "t", "parseSpaceCurve", "component3d", "Geo", "Material", "Types", "PlotPoint3d", "component3d", "meshEntries", "Types", "loader", "s", "ctx", "g3", "Material", "Geo", "drawLabel3D", "component3d", "Graphics3D", "lerpVector3", "Material", "resolveVector3", "Types", "point", "initial", "Types", "resolveVector3", "lerpVector3", "state", "meshEntries", "graphEntry", "VectorArrow3d", "component3d", "ctx", "s", "drawArrow", "g3", "Graphics3D", "space", "graphOf", "tail", "head", "thickness", "from", "to", "along", "length", "paint", "Material", "quaternion", "aim", "tipLength", "shaft", "at", "distance", "GRAPH_LAYOUTS", "layOut", "layout", "vertices", "edges", "root", "n", "grid", "fill", "tree", "spring", "circular", "name", "i", "angle", "columns", "rows", "at", "count", "neighbours", "near", "from", "to", "placed", "column", "visit", "depth", "seen", "children", "next", "child", "xs", "x", "first", "start", "index", "y", "links", "a", "b", "k", "steps", "step", "dx", "dy", "j", "ex", "ey", "d", "push", "pull", "limit", "minX", "minY", "maxX", "maxY", "p", "scale", "v", "lo", "hi", "component2d", "Graphics2D", "Types", "readVertices", "value", "name", "readEdges", "edge", "from", "to", "readPositions", "at", "n", "entry", "BOW", "NUL", "state", "PAINT", "Types", "listed", "GRAPH_LAYOUTS", "readPartFills", "lerpPartFills", "NetworkGraph", "component2d", "loader", "s", "loadFormulas", "names", "PAINT_COMMANDS", "timeline", "t", "part", "fill", "withPartFill", "ctx", "painted", "drawGraph", "vertexPoints", "graph", "size", "room", "halfX", "halfY", "placed", "out", "p", "q", "points", "parts", "drawEdges", "drawVertices", "layouts", "createBoundedCache", "layout", "vertices", "edges", "links", "key", "layOut", "vertex", "x", "y", "stroke", "r", "all", "pairs", "plain", "Graphics2D", "drawnPlain", "a", "b", "run", "loop", "paint", "own", "layers", "layer", "partPaint", "outline", "labels", "disc", "drawLabels", "bow", "dx", "dy", "length", "ux", "uy", "mid", "i", "u", "outside", "c", "radius", "cy", "angle", "component2d", "fillOps", "Graphics2D", "Types", "PALETTE", "LOWER", "readShares", "value", "share", "lerpShares", "from", "to", "t", "i", "state", "omit", "PAINT", "Types", "readFillScale", "lerpFillScale", "SampleSpace", "component2d", "loader", "s", "loadFormulas", "PAINT_COMMANDS", "ctx", "painted", "drawSpace", "sampleParts", "space", "size", "box", "boxOf", "shares", "total", "sum", "out", "left", "column", "width", "p", "cut", "top", "upper", "parts", "fills", "stroke", "labels", "part", "base", "fillOps", "paint", "layer", "g", "Graphics2D", "formatTick", "braces", "style", "drawLabels", "height", "room", "below", "label", "reach", "gap", "runs", "drawn", "brace", "text", "align", "braceOutline", "mid", "far", "bottom", "first", "fill"]
7
+ }