@motionscript/math 0.1.0-alpha.8 → 0.1.0-alpha.9

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 (157) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +49 -49
  4. package/README.md +390 -391
  5. package/dist/annotate/angle-mark.js.map +1 -1
  6. package/dist/annotate/curly-brace.js.map +1 -1
  7. package/dist/annotate/emphasis-mark.js.map +1 -1
  8. package/dist/browser/chunks/{chunk-FETQZEN2.js → chunk-IRZCG6PM.js} +2 -2
  9. package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
  10. package/dist/browser/chunks/{chunk-K77KLQX4.js → chunk-WMVW6ZIV.js} +2 -2
  11. package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
  12. package/dist/browser/chunks/{mathjax-DNP3YRES.js → mathjax-WV55AC2P.js} +1 -1
  13. package/dist/browser/chunks/{mathjax-DNP3YRES.js.map → mathjax-WV55AC2P.js.map} +1 -1
  14. package/dist/browser/index.js +1 -1
  15. package/dist/browser/index.js.map +1 -1
  16. package/dist/browser/kit.js +1 -1
  17. package/dist/browser/tex.js +1 -1
  18. package/dist/browser/tex.js.map +1 -1
  19. package/dist/engine.d.ts +1 -1
  20. package/dist/engine.js +1 -1
  21. package/dist/engine.js.map +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/kit/brace.js.map +1 -1
  24. package/dist/kit/cache.js.map +1 -1
  25. package/dist/kit/component.d.ts.map +1 -1
  26. package/dist/kit/component.js.map +1 -1
  27. package/dist/kit/contour.js.map +1 -1
  28. package/dist/kit/coords.js.map +1 -1
  29. package/dist/kit/curve.js.map +1 -1
  30. package/dist/kit/equation.js.map +1 -1
  31. package/dist/kit/equation3d.js.map +1 -1
  32. package/dist/kit/expression.js.map +1 -1
  33. package/dist/kit/field-mark.d.ts.map +1 -1
  34. package/dist/kit/field-mark.js.map +1 -1
  35. package/dist/kit/field.js.map +1 -1
  36. package/dist/kit/follow.d.ts.map +1 -1
  37. package/dist/kit/follow.js.map +1 -1
  38. package/dist/kit/furniture.js.map +1 -1
  39. package/dist/kit/geometry.js.map +1 -1
  40. package/dist/kit/graph.js.map +1 -1
  41. package/dist/kit/mark.js.map +1 -1
  42. package/dist/kit/part-fills.js.map +1 -1
  43. package/dist/kit/place.js.map +1 -1
  44. package/dist/kit/sampler.js.map +1 -1
  45. package/dist/kit/scale.js.map +1 -1
  46. package/dist/kit/source.js.map +1 -1
  47. package/dist/kit/system.js.map +1 -1
  48. package/dist/kit/ticks.js.map +1 -1
  49. package/dist/kit/withdrawn.js.map +1 -1
  50. package/dist/marks/curve-area.js.map +1 -1
  51. package/dist/marks/drop-lines.js.map +1 -1
  52. package/dist/marks/plot-point.js.map +1 -1
  53. package/dist/marks/riemann-sum.js.map +1 -1
  54. package/dist/marks/tangent-line.js.map +1 -1
  55. package/dist/marks/vector-arrow.js.map +1 -1
  56. package/dist/nodes.js.map +1 -1
  57. package/dist/plots/function-plot.d.ts.map +1 -1
  58. package/dist/plots/function-plot.js.map +1 -1
  59. package/dist/plots/points-plot.js.map +1 -1
  60. package/dist/plots/stream-lines.js.map +1 -1
  61. package/dist/plots/traced-path.js.map +1 -1
  62. package/dist/plots/vector-field.js.map +1 -1
  63. package/dist/structures/graph-layout.js.map +1 -1
  64. package/dist/structures/network-graph.js.map +1 -1
  65. package/dist/structures/sample-space.js.map +1 -1
  66. package/dist/systems/axes2d.d.ts.map +1 -1
  67. package/dist/systems/axes2d.js.map +1 -1
  68. package/dist/systems/number-line.js.map +1 -1
  69. package/dist/systems/number-plane.js.map +1 -1
  70. package/dist/systems/polar-plane.js.map +1 -1
  71. package/dist/tex/geometry.js.map +1 -1
  72. package/dist/tex/index.js.map +1 -1
  73. package/dist/tex/mathjax.js.map +1 -1
  74. package/dist/tex/matrix.js.map +1 -1
  75. package/dist/tex/node.js.map +1 -1
  76. package/dist/tex/tween.js.map +1 -1
  77. package/dist/tex/typeset.d.ts.map +1 -1
  78. package/dist/tex/typeset.js.map +1 -1
  79. package/dist/three/axes3d.js.map +1 -1
  80. package/dist/three/curve-plot3d.js.map +1 -1
  81. package/dist/three/entries.js.map +1 -1
  82. package/dist/three/label3d.js.map +1 -1
  83. package/dist/three/plot-point3d.js.map +1 -1
  84. package/dist/three/space.js.map +1 -1
  85. package/dist/three/surface-plot3d.js.map +1 -1
  86. package/dist/three/vector-arrow3d.js.map +1 -1
  87. package/package.json +4 -4
  88. package/registry.json +251 -251
  89. package/src/annotate/angle-mark.ts +137 -137
  90. package/src/annotate/curly-brace.ts +148 -148
  91. package/src/annotate/emphasis-mark.ts +118 -118
  92. package/src/engine.ts +86 -86
  93. package/src/index.ts +29 -29
  94. package/src/kit/brace.ts +37 -37
  95. package/src/kit/cache.ts +61 -61
  96. package/src/kit/component.ts +57 -57
  97. package/src/kit/contour.ts +94 -94
  98. package/src/kit/coords.ts +278 -278
  99. package/src/kit/curve.ts +47 -47
  100. package/src/kit/equation.ts +181 -181
  101. package/src/kit/equation3d.ts +137 -137
  102. package/src/kit/expression.ts +159 -159
  103. package/src/kit/field-mark.ts +171 -171
  104. package/src/kit/field.ts +50 -50
  105. package/src/kit/follow.ts +229 -229
  106. package/src/kit/furniture.ts +113 -113
  107. package/src/kit/geometry.ts +49 -49
  108. package/src/kit/graph.ts +116 -116
  109. package/src/kit/mark.ts +152 -152
  110. package/src/kit/part-fills.ts +61 -61
  111. package/src/kit/place.ts +77 -77
  112. package/src/kit/sampler.ts +281 -281
  113. package/src/kit/scale.ts +39 -39
  114. package/src/kit/source.ts +57 -57
  115. package/src/kit/system.ts +105 -105
  116. package/src/kit/ticks.ts +85 -85
  117. package/src/kit/withdrawn.ts +8 -8
  118. package/src/marks/curve-area.ts +89 -89
  119. package/src/marks/drop-lines.ts +71 -71
  120. package/src/marks/plot-point.ts +102 -102
  121. package/src/marks/riemann-sum.ts +99 -99
  122. package/src/marks/tangent-line.ts +119 -119
  123. package/src/marks/vector-arrow.ts +98 -98
  124. package/src/nodes.ts +99 -99
  125. package/src/plots/function-plot.ts +220 -220
  126. package/src/plots/points-plot.ts +103 -103
  127. package/src/plots/stream-lines.ts +160 -160
  128. package/src/plots/traced-path.ts +70 -70
  129. package/src/plots/vector-field.ts +107 -107
  130. package/src/structures/graph-layout.ts +145 -145
  131. package/src/structures/network-graph.ts +291 -291
  132. package/src/structures/sample-space.ts +210 -210
  133. package/src/systems/axes2d.ts +226 -226
  134. package/src/systems/number-line.ts +130 -130
  135. package/src/systems/number-plane.ts +232 -232
  136. package/src/systems/polar-plane.ts +177 -177
  137. package/src/tex/geometry.ts +703 -703
  138. package/src/tex/index.ts +15 -15
  139. package/src/tex/mathjax.ts +82 -82
  140. package/src/tex/matrix.ts +97 -97
  141. package/src/tex/node.ts +74 -74
  142. package/src/tex/tween.ts +308 -308
  143. package/src/tex/typeset.ts +461 -461
  144. package/src/three/axes3d.ts +267 -267
  145. package/src/three/curve-plot3d.ts +146 -146
  146. package/src/three/entries.ts +42 -42
  147. package/src/three/label3d.ts +52 -52
  148. package/src/three/plot-point3d.ts +63 -63
  149. package/src/three/space.ts +92 -92
  150. package/src/three/surface-plot3d.ts +318 -318
  151. package/src/three/vector-arrow3d.ts +88 -88
  152. package/dist/browser/chunks/chunk-FETQZEN2.js.map +0 -7
  153. package/dist/browser/chunks/chunk-K77KLQX4.js.map +0 -7
  154. package/dist/kit/placement.d.ts +0 -8
  155. package/dist/kit/placement.d.ts.map +0 -1
  156. package/dist/kit/placement.js +0 -8
  157. package/dist/kit/placement.js.map +0 -1
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/kit/withdrawn.ts", "../../../src/kit/system.ts", "../../../src/kit/graph.ts", "../../../src/kit/coords.ts", "../../../src/kit/equation.ts", "../../../src/kit/expression.ts", "../../../src/kit/source.ts", "../../../src/kit/curve.ts", "../../../src/kit/geometry.ts", "../../../src/kit/mark.ts", "../../../src/kit/place.ts", "../../../src/systems/axes2d.ts", "../../../src/kit/ticks.ts", "../../../src/kit/furniture.ts", "../../../src/kit/sampler.ts", "../../../src/kit/follow.ts", "../../../src/kit/field.ts", "../../../src/kit/equation3d.ts", "../../../src/three/space.ts", "../../../src/three/entries.ts", "../../../src/three/label3d.ts", "../../../src/plots/function-plot.ts", "../../../src/kit/contour.ts", "../../../src/kit/field-mark.ts", "../../../src/kit/scale.ts", "../../../src/kit/brace.ts", "../../../src/structures/graph-layout.ts"],
4
+ "sourcesContent": ["/**\n * The paint entries and commands a math node may have no use for: a node that\n * is only a line has no fill, an area no outline, and one that reveals itself\n * in its own way no outline trim.\n */\nexport const FILL_PAINT = [\"fill\", \"fillTo\"] as const;\nexport const STROKE_PAINT = [\"stroke\", \"strokeTo\"] as const;\nexport const OUTLINE_TRIM = [\"start\", \"end\", \"progressTo\", \"flash\"] as const;\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/**\n * What a coordinate system shares: a node whose children sit in its graph\n * coordinates. A child's `x`/`y` are in the system's units and the child keeps\n * its own size, so anything can be put on a graph: a dot, a label, an image. A\n * mark is drawn through the system's map instead and laid out on its ink.\n *\n * The system's `stroke` is its axis line (so `endCap` is the tip) and its `fill`\n * the backdrop. Ticks, grid and labels are drawing ops, never child nodes: a\n * document's children would otherwise share their indices with them.\n */\n\nconst CENTRE: Vector2 = { x: 0, y: 0 };\n\n/** What a system's helpers read of its state. */\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 {\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, 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) => from[i] + (to[i] - from[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 { expressionOps, type ExpressionNode } from \"@motionscript/sdk\";\nimport { createBoundedCache } from \"./cache\";\nimport { compileExpressionCached, 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 *\n * | Written as | Is |\n * |---|---|\n * | `sin(x)`, `y = sin(x)` | a function of `x` |\n * | `x = y^2` | a function of `y` |\n * | `r = 1 + cos(theta)` | polar, in `theta` |\n * | `(cos(t), sin(t))` | parametric, in `t` |\n * | `x^2 + y^2 = 4` | implicit, in `x` and `y` |\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 /** Drawn where `f(x, y)` is zero. */\n | { kind: \"implicit\"; f: CompiledExpression };\n\n/** The free variable each kind is sampled over, for a host's help text. */\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\nconst parsed = createBoundedCache<Equation | Error>(256);\n\n/**\n * `source` as an {@link Equation}, or the reason it is not one. Memoised, so an\n * unchanged equation is the identical object and a geometry cache can key on it.\n */\nexport function parseEquation(source: string, params: readonly string[] = []): Equation | Error {\n const key = `${params.join(\",\")}|${source}`;\n const hit = parsed.get(key);\n if (hit !== undefined) return hit;\n let result: Equation | Error;\n try {\n result = read(source.trim(), params);\n } catch (error) {\n result = error instanceof Error ? error : new Error(String(error));\n }\n parsed.set(key, result);\n return result;\n}\n\n/**\n * Why `source` will not plot, or `null` when it will. An empty one is not an\n * error (nobody has written it yet), and neither is a name it does not know:\n * that is a named value, see {@link equationParams}.\n */\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/**\n * Every name `source` reads, in the order it first names them, variables\n * included. Empty for text that does not parse.\n */\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/**\n * The named values `source` reads: every name that is not a variable, a\n * function or a constant.\n */\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 if (source === \"\") throw new Error(\"Empty equation\");\n const compile = (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 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 { expressionOps } from \"@motionscript/sdk\";\nimport type { ExpressionDialect, ExpressionNode } from \"@motionscript/sdk\";\nimport { createBoundedCache } from \"./cache\";\n\n/**\n * The language a plot's equation is written in: the engine's own expression\n * grammar (`expressionOps.parse`) under a dialect of its own, where trig is in\n * radians, names are bare identifiers, and the logs and hyperbolics a plot\n * wants are present. Never `new Function`: an equation is text stored in a\n * document, and the shared parser can only produce arithmetic.\n */\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\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: [\"pi\", \"e\", \"tau\", \"phi\"],\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\n // is both would silently stop being the variable it was passed as.\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 const key = `${variables.join(\",\")}|${params.join(\",\")}|${source}`;\n const hit = compiled.get(key);\n if (hit !== undefined) return hit;\n let result: CompiledExpression | Error;\n try {\n result = compileExpression(source, variables, params);\n } catch (error) {\n result = error instanceof Error ? error : new Error(String(error));\n }\n compiled.set(key, result);\n return result;\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/**\n * A curve as a mark reads it: what a plot is drawn from, its own `x`/`y`, and\n * whether a system laid it out, which is when those are a shift in graph units.\n * Data rather than a class, so a copied plot is ridden like the kit's own.\n */\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 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 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 * A mark is a node drawn in graph coordinates: a plot, an area, an arrow\n * between two graph points. It answers with runs of pixel points and is\n * otherwise a shape, so its box is the tight box of its ink.\n *\n * Inside a coordinate system (or a plot) the holder lays it out on that ink,\n * calling the mark's own trace with its map, and the mark's `x`/`y` are a shift\n * in graph units. Outside one a graph unit is a pixel and `x`/`y` are the usual\n * offset.\n */\n\n/** What a mark is traced through: the map, its own `x`/`y` as a shift, and the plane it reads curves from. */\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: a shape's paints, any it withdrew left out. */\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 whichever node holds them: a coordinate\n * system, or a plot holding the marks that read it. A mark goes on its ink;\n * anything else keeps its own size and has its `x`/`y` read as graph\n * coordinates. `origin` is the holder's own centre in the map's pixels (y-up),\n * since a child's box is placed from there.\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 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, type Label, lerpInterval, readInterval, 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\nconst interval = (initial: Interval) => Types.custom<Interval>(initial, { resolve: readInterval, lerp: lerpInterval });\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: interval([-5, 5]),\n yRange: interval([-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\n/** What axes are drawn from: their own entries, as a number plane's helpers read them too. */\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 { 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 { Fills, Graphics2D, toPathString, 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/** Shared drawing for the systems' own furniture: axis lines, tick marks and their numbers. */\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 [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];\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 type { Extents, Vector2 } from \"@motionscript/sdk\";\n\n/**\n * Turns a curve into the polylines that draw it: adaptively, so a straight\n * stretch costs two points and a tight bend as many as it needs, and broken\n * wherever the curve is, at an asymptote or the edge of its domain.\n */\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 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 { 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 on one part of a formula: a brace, a box,\n * an underline. It has no size of its own and takes no place in a layout; it\n * is drawn where its target is, wherever the two are in the tree, and its\n * selection box is its ink. Its entries, and what it draws on.\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\n/** What a follow mark reads of its state. */\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/**\n * The formula a follow mark sits in, as its render last found it: what a mark\n * naming no node is drawn on. Its bounds and handles read it from there, where\n * there is no context to ask.\n */\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 = (frame.rotation * Math.PI) / 180;\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\n// --- Geometry the marks share ---\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 { createBoundedCache } from \"./cache\";\nimport { equationNames, splitTuple } from \"./equation\";\nimport { compileExpressionCached, 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);\nconst fields = createBoundedCache<FieldEquation | Error>(128);\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. Memoised, so an unchanged equation is the identical object. */\nexport function parseField(source: string, params: readonly string[] = []): FieldEquation | Error {\n const key = `${params.join(\",\")}|${source}`;\n const hit = fields.get(key);\n if (hit !== undefined) return hit;\n let result: FieldEquation | Error;\n try {\n const text = source.trim();\n if (text === \"\") throw new Error(\"Empty equation\");\n const parts = splitTuple(text);\n if (parts?.length !== 2) throw new Error(\"A field has two parts: (x, y)\");\n const [x, y] = parts.map((part) => {\n const compiled = compileExpressionCached(part.trim(), FIELD_VARIABLES, params);\n if (compiled instanceof Error) throw compiled;\n return compiled;\n });\n result = { x, y };\n } catch (error) {\n result = error instanceof Error ? error : new Error(String(error));\n }\n fields.set(key, result);\n return result;\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 { createBoundedCache } from \"./cache\";\nimport { equationError, equationNames, equationParams, EQUATION_VARIABLES, splitTopLevel, splitTuple } from \"./equation\";\nimport { compileExpressionCached, 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\nconst surfaces = createBoundedCache<SurfaceEquation | Error>(128);\nconst curves = createBoundedCache<SpaceCurveEquation | Error>(128);\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. Memoised, so an unchanged equation is the identical object. */\nexport function parseSurface(source: string, params: readonly string[] = []): SurfaceEquation | Error {\n return memo(surfaces, source, params, (text) => {\n const compile = compiler(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\n/** `source` as a space curve, or the reason it is not one. */\nexport function parseSpaceCurve(source: string, params: readonly string[] = []): SpaceCurveEquation | Error {\n return memo(curves, source, params, (text) => {\n const compile = compiler(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\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\nfunction compiler(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\nfunction memo<T extends object>(\n cache: ReturnType<typeof createBoundedCache<T | Error>>,\n source: string,\n params: readonly string[],\n read: (text: string) => T,\n): T | Error {\n const key = `${params.join(\",\")}|${source}`;\n const hit = cache.get(key);\n if (hit !== undefined) return hit;\n let result: T | Error;\n try {\n const text = source.trim();\n if (text === \"\") throw new Error(\"Empty equation\");\n result = read(text);\n } catch (error) {\n result = error instanceof Error ? error : new Error(String(error));\n }\n cache.set(key, result);\n return result;\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 createContext,\n Types,\n type ChildSpace3D,\n type Node3D,\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 step from one graph point to another, as the 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/**\n * The entry a mark reads the graph it is drawn in through, set from the nearest\n * `axes3d` above it, through any 3D node between; `null` outside one.\n */\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/** The graph a 3D node is drawn in: what the nearest `axes3d` above it provides, once it is in the tree. */\nexport function spaceOf(mark: Node3D): GraphSpace | null {\n return mark.useContext(GRAPH_3D)?.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 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 { 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 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\n/** What a plot's curve is drawn from. */\nexport interface PlotValues {\n readonly expression: PlotSource;\n readonly params: ExpressionScope;\n}\n\n/**\n * The curve of an equation, drawn in the coordinate system it is a child of.\n * How the equation is written says what it is: see `Equation`. A mark put\n * inside it reads it: the area under it, a tangent, a point that rides it.\n */\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 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 {\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/**\n * What a mark drawn from a vector field, `(P(x, y), Q(x, y))`, shares: arrows,\n * or the lines that follow it, all in one stroke. Without strength fills it is\n * one path in the stroke's paint; with them, what it draws is sorted by the\n * field's strength into a few shades.\n */\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\n/** What a field mark is drawn from. */\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 { 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 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 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"],
5
+ "mappings": "6IAKO,IAAMA,GAAa,CAAC,OAAQ,QAAQ,EAC9BC,GAAe,CAAC,SAAU,UAAU,EACpCC,GAAe,CAAC,QAAS,MAAO,aAAc,OAAO,ECPlE,OACI,cAAAC,GACA,aAAAC,GACA,SAAAC,GACA,YAAAC,OAYG,oBChBP,OACI,iBAAAC,GACA,SAAAC,OAMG,oBC2BD,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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,EAAE,EAAGJ,EAAME,CAAI,EAAG,EAAGG,EAAMD,EAAE,EAAGH,EAAME,CAAI,CAAC,CAAE,CAAC,CAAC,CACnH",
6
+ "names": ["FILL_PAINT", "STROKE_PAINT", "OUTLINE_TRIM", "Graphics2D", "insetsOps", "Paint", "provides", "createContext", "Types", "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", "expressionOps", "expressionOps", "UNARY", "NARY", "a", "b", "CONSTANTS", "MATH_DIALECT", "name", "arity", "expressionVocabulary", "variables", "compileExpression", "source", "params", "emit", "expressionOps", "node", "value", "slot", "_a", "_b", "scope", "operand", "l", "r", "s", "args", "arg", "unary", "x", "fn", "y", "compiled", "createBoundedCache", "compileExpressionCached", "key", "hit", "result", "error", "EQUATION_VARIABLES", "parsed", "createBoundedCache", "parseEquation", "source", "params", "key", "hit", "result", "read", "error", "equationError", "equation", "equationParams", "VARIABLE_NAMES", "named", "equationNames", "names", "text", "part", "splitTuple", "splitTopLevel", "collectNames", "expressionOps", "MATH_DIALECT", "name", "node", "into", "arg", "compile", "variables", "compileExpressionCached", "pair", "sides", "left", "right", "subject", "implicit", "l", "r", "x", "y", "scope", "of", "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", "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", "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", "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", "component2d", "Graphics2D", "Types", "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", "Fills", "Graphics2D", "toPathString", "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", "readInterval", "value", "previous", "min", "max", "interval", "initial", "Types", "readInterval", "lerpInterval", "AXES", "PAINT", "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", "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", "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", "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", "FIELD_VARIABLES", "NAMES", "fields", "createBoundedCache", "fieldParams", "source", "equationNames", "name", "parseField", "params", "key", "hit", "result", "text", "parts", "splitTuple", "x", "y", "part", "compiled", "compileExpressionCached", "error", "fieldError", "field", "EQUATION_VARIABLES_3D", "SURFACE_NAMES", "SPACE_CURVE_NAMES", "surfaces", "createBoundedCache", "curves", "surfaceParams", "source", "equationNames", "name", "spaceCurveParams", "parseSurface", "params", "memo", "text", "compile", "compiler", "parts", "splitTuple", "x", "y", "z", "part", "sides", "splitTopLevel", "parseSpaceCurve", "surfaceError", "equation", "spaceCurveError", "variables", "result", "compileExpressionCached", "cache", "read", "key", "hit", "error", "EQUATION_KINDS", "equationError", "equationParams", "EQUATION_VARIABLES", "fieldError", "fieldParams", "FIELD_VARIABLES", "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", "spaceOf", "aim", "direction", "dx", "dy", "dz", "w", "norm", "Material", "Types", "meshEntries", "Types", "Material", "domainEntry", "defaultMin", "defaultMax", "lerpDomain", "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", "component2d", "provides", "Types", "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", "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", "traceContour", "x", "y", "run", "point", "domain", "horizontal", "lo", "hi", "offset", "a", "b", "f", "u", "out", "v", "w", "theta", "r", "t", "gx", "gy", "to", "Graphics2D", "Types", "colorOps", "fillOps", "readScale", "value", "color", "colorOps", "lerpScale", "from", "to", "t", "index", "colorAt", "scale", "share", "at", "clamp", "readFillScale", "fill", "fillOps", "lerpFillScale", "fillAt", "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", "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", "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"]
7
+ }