@motionscript/math 0.0.0-stage → 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +144 -0
- package/LICENSE +201 -0
- package/NOTICE +49 -0
- package/README.md +389 -2
- package/dist/annotate/angle-mark.d.ts +96 -0
- package/dist/annotate/angle-mark.d.ts.map +1 -0
- package/dist/annotate/angle-mark.js +97 -0
- package/dist/annotate/angle-mark.js.map +1 -0
- package/dist/annotate/curly-brace.d.ts +115 -0
- package/dist/annotate/curly-brace.d.ts.map +1 -0
- package/dist/annotate/curly-brace.js +99 -0
- package/dist/annotate/curly-brace.js.map +1 -0
- package/dist/annotate/emphasis-mark.d.ts +80 -0
- package/dist/annotate/emphasis-mark.d.ts.map +1 -0
- package/dist/annotate/emphasis-mark.js +80 -0
- package/dist/annotate/emphasis-mark.js.map +1 -0
- package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
- package/dist/browser/chunks/chunk-IRZCG6PM.js +2 -0
- package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
- package/dist/browser/chunks/chunk-WMVW6ZIV.js +2 -0
- package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
- package/dist/browser/chunks/mathjax-WV55AC2P.js +61 -0
- package/dist/browser/chunks/mathjax-WV55AC2P.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +30 -0
- package/dist/browser/tex.js +2 -0
- package/dist/browser/tex.js.map +7 -0
- package/dist/engine.d.ts +71 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +45 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/brace.d.ts +8 -0
- package/dist/kit/brace.d.ts.map +1 -0
- package/dist/kit/brace.js +36 -0
- package/dist/kit/brace.js.map +1 -0
- package/dist/kit/cache.d.ts +30 -0
- package/dist/kit/cache.d.ts.map +1 -0
- package/dist/kit/cache.js +53 -0
- package/dist/kit/cache.js.map +1 -0
- package/dist/kit/component.d.ts +51 -0
- package/dist/kit/component.d.ts.map +1 -0
- package/dist/kit/component.js +30 -0
- package/dist/kit/component.js.map +1 -0
- package/dist/kit/contour.d.ts +8 -0
- package/dist/kit/contour.d.ts.map +1 -0
- package/dist/kit/contour.js +93 -0
- package/dist/kit/contour.js.map +1 -0
- package/dist/kit/coords.d.ts +69 -0
- package/dist/kit/coords.d.ts.map +1 -0
- package/dist/kit/coords.js +224 -0
- package/dist/kit/coords.js.map +1 -0
- package/dist/kit/curve.d.ts +28 -0
- package/dist/kit/curve.d.ts.map +1 -0
- package/dist/kit/curve.js +29 -0
- package/dist/kit/curve.js.map +1 -0
- package/dist/kit/equation.d.ts +61 -0
- package/dist/kit/equation.d.ts.map +1 -0
- package/dist/kit/equation.js +168 -0
- package/dist/kit/equation.js.map +1 -0
- package/dist/kit/equation3d.d.ts +50 -0
- package/dist/kit/equation3d.d.ts.map +1 -0
- package/dist/kit/equation3d.js +103 -0
- package/dist/kit/equation3d.js.map +1 -0
- package/dist/kit/expression.d.ts +35 -0
- package/dist/kit/expression.d.ts.map +1 -0
- package/dist/kit/expression.js +124 -0
- package/dist/kit/expression.js.map +1 -0
- package/dist/kit/field-mark.d.ts +79 -0
- package/dist/kit/field-mark.d.ts.map +1 -0
- package/dist/kit/field-mark.js +109 -0
- package/dist/kit/field-mark.js.map +1 -0
- package/dist/kit/field.d.ts +14 -0
- package/dist/kit/field.d.ts.map +1 -0
- package/dist/kit/field.js +46 -0
- package/dist/kit/field.js.map +1 -0
- package/dist/kit/follow.d.ts +109 -0
- package/dist/kit/follow.d.ts.map +1 -0
- package/dist/kit/follow.js +163 -0
- package/dist/kit/follow.js.map +1 -0
- package/dist/kit/furniture.d.ts +32 -0
- package/dist/kit/furniture.d.ts.map +1 -0
- package/dist/kit/furniture.js +92 -0
- package/dist/kit/furniture.js.map +1 -0
- package/dist/kit/geometry.d.ts +13 -0
- package/dist/kit/geometry.d.ts.map +1 -0
- package/dist/kit/geometry.js +54 -0
- package/dist/kit/geometry.js.map +1 -0
- package/dist/kit/graph.d.ts +46 -0
- package/dist/kit/graph.d.ts.map +1 -0
- package/dist/kit/graph.js +90 -0
- package/dist/kit/graph.js.map +1 -0
- package/dist/kit/mark.d.ts +72 -0
- package/dist/kit/mark.d.ts.map +1 -0
- package/dist/kit/mark.js +87 -0
- package/dist/kit/mark.js.map +1 -0
- package/dist/kit/part-fills.d.ts +23 -0
- package/dist/kit/part-fills.d.ts.map +1 -0
- package/dist/kit/part-fills.js +46 -0
- package/dist/kit/part-fills.js.map +1 -0
- package/dist/kit/place.d.ts +20 -0
- package/dist/kit/place.d.ts.map +1 -0
- package/dist/kit/place.js +66 -0
- package/dist/kit/place.js.map +1 -0
- package/dist/kit/sampler.d.ts +17 -0
- package/dist/kit/sampler.d.ts.map +1 -0
- package/dist/kit/sampler.js +250 -0
- package/dist/kit/sampler.js.map +1 -0
- package/dist/kit/scale.d.ts +12 -0
- package/dist/kit/scale.d.ts.map +1 -0
- package/dist/kit/scale.js +37 -0
- package/dist/kit/scale.js.map +1 -0
- package/dist/kit/source.d.ts +22 -0
- package/dist/kit/source.d.ts.map +1 -0
- package/dist/kit/source.js +45 -0
- package/dist/kit/source.js.map +1 -0
- package/dist/kit/system.d.ts +31 -0
- package/dist/kit/system.d.ts.map +1 -0
- package/dist/kit/system.js +71 -0
- package/dist/kit/system.js.map +1 -0
- package/dist/kit/ticks.d.ts +19 -0
- package/dist/kit/ticks.d.ts.map +1 -0
- package/dist/kit/ticks.js +78 -0
- package/dist/kit/ticks.js.map +1 -0
- package/dist/kit/withdrawn.d.ts +9 -0
- package/dist/kit/withdrawn.d.ts.map +1 -0
- package/dist/kit/withdrawn.js +9 -0
- package/dist/kit/withdrawn.js.map +1 -0
- package/dist/marks/curve-area.d.ts +51 -0
- package/dist/marks/curve-area.d.ts.map +1 -0
- package/dist/marks/curve-area.js +59 -0
- package/dist/marks/curve-area.js.map +1 -0
- package/dist/marks/drop-lines.d.ts +57 -0
- package/dist/marks/drop-lines.d.ts.map +1 -0
- package/dist/marks/drop-lines.js +43 -0
- package/dist/marks/drop-lines.js.map +1 -0
- package/dist/marks/plot-point.d.ts +71 -0
- package/dist/marks/plot-point.d.ts.map +1 -0
- package/dist/marks/plot-point.js +71 -0
- package/dist/marks/plot-point.js.map +1 -0
- package/dist/marks/riemann-sum.d.ts +58 -0
- package/dist/marks/riemann-sum.d.ts.map +1 -0
- package/dist/marks/riemann-sum.js +63 -0
- package/dist/marks/riemann-sum.js.map +1 -0
- package/dist/marks/tangent-line.d.ts +71 -0
- package/dist/marks/tangent-line.d.ts.map +1 -0
- package/dist/marks/tangent-line.js +89 -0
- package/dist/marks/tangent-line.js.map +1 -0
- package/dist/marks/vector-arrow.d.ts +60 -0
- package/dist/marks/vector-arrow.d.ts.map +1 -0
- package/dist/marks/vector-arrow.js +67 -0
- package/dist/marks/vector-arrow.js.map +1 -0
- package/dist/nodes.d.ts +43 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +57 -0
- package/dist/nodes.js.map +1 -0
- package/dist/plots/function-plot.d.ts +159 -0
- package/dist/plots/function-plot.d.ts.map +1 -0
- package/dist/plots/function-plot.js +184 -0
- package/dist/plots/function-plot.js.map +1 -0
- package/dist/plots/points-plot.d.ts +64 -0
- package/dist/plots/points-plot.d.ts.map +1 -0
- package/dist/plots/points-plot.js +72 -0
- package/dist/plots/points-plot.js.map +1 -0
- package/dist/plots/stream-lines.d.ts +76 -0
- package/dist/plots/stream-lines.d.ts.map +1 -0
- package/dist/plots/stream-lines.js +122 -0
- package/dist/plots/stream-lines.js.map +1 -0
- package/dist/plots/traced-path.d.ts +70 -0
- package/dist/plots/traced-path.d.ts.map +1 -0
- package/dist/plots/traced-path.js +41 -0
- package/dist/plots/traced-path.js.map +1 -0
- package/dist/plots/vector-field.d.ts +60 -0
- package/dist/plots/vector-field.d.ts.map +1 -0
- package/dist/plots/vector-field.js +77 -0
- package/dist/plots/vector-field.js.map +1 -0
- package/dist/structures/graph-layout.d.ts +11 -0
- package/dist/structures/graph-layout.d.ts.map +1 -0
- package/dist/structures/graph-layout.js +135 -0
- package/dist/structures/graph-layout.js.map +1 -0
- package/dist/structures/network-graph.d.ts +174 -0
- package/dist/structures/network-graph.d.ts.map +1 -0
- package/dist/structures/network-graph.js +240 -0
- package/dist/structures/network-graph.js.map +1 -0
- package/dist/structures/sample-space.d.ts +114 -0
- package/dist/structures/sample-space.d.ts.map +1 -0
- package/dist/structures/sample-space.js +161 -0
- package/dist/structures/sample-space.js.map +1 -0
- package/dist/systems/axes2d.d.ts +197 -0
- package/dist/systems/axes2d.d.ts.map +1 -0
- package/dist/systems/axes2d.js +157 -0
- package/dist/systems/axes2d.js.map +1 -0
- package/dist/systems/number-line.d.ts +101 -0
- package/dist/systems/number-line.d.ts.map +1 -0
- package/dist/systems/number-line.js +91 -0
- package/dist/systems/number-line.js.map +1 -0
- package/dist/systems/number-plane.d.ts +168 -0
- package/dist/systems/number-plane.d.ts.map +1 -0
- package/dist/systems/number-plane.js +186 -0
- package/dist/systems/number-plane.js.map +1 -0
- package/dist/systems/polar-plane.d.ts +98 -0
- package/dist/systems/polar-plane.d.ts.map +1 -0
- package/dist/systems/polar-plane.js +139 -0
- package/dist/systems/polar-plane.js.map +1 -0
- package/dist/tex/geometry.d.ts +85 -0
- package/dist/tex/geometry.d.ts.map +1 -0
- package/dist/tex/geometry.js +632 -0
- package/dist/tex/geometry.js.map +1 -0
- package/dist/tex/index.d.ts +11 -0
- package/dist/tex/index.d.ts.map +1 -0
- package/dist/tex/index.js +10 -0
- package/dist/tex/index.js.map +1 -0
- package/dist/tex/mathjax.d.ts +33 -0
- package/dist/tex/mathjax.d.ts.map +1 -0
- package/dist/tex/mathjax.js +74 -0
- package/dist/tex/mathjax.js.map +1 -0
- package/dist/tex/matrix.d.ts +101 -0
- package/dist/tex/matrix.d.ts.map +1 -0
- package/dist/tex/matrix.js +56 -0
- package/dist/tex/matrix.js.map +1 -0
- package/dist/tex/node.d.ts +98 -0
- package/dist/tex/node.d.ts.map +1 -0
- package/dist/tex/node.js +25 -0
- package/dist/tex/node.js.map +1 -0
- package/dist/tex/tween.d.ts +50 -0
- package/dist/tex/tween.d.ts.map +1 -0
- package/dist/tex/tween.js +253 -0
- package/dist/tex/tween.js.map +1 -0
- package/dist/tex/typeset.d.ts +133 -0
- package/dist/tex/typeset.d.ts.map +1 -0
- package/dist/tex/typeset.js +403 -0
- package/dist/tex/typeset.js.map +1 -0
- package/dist/three/axes3d.d.ts +247 -0
- package/dist/three/axes3d.d.ts.map +1 -0
- package/dist/three/axes3d.js +187 -0
- package/dist/three/axes3d.js.map +1 -0
- package/dist/three/curve-plot3d.d.ts +126 -0
- package/dist/three/curve-plot3d.d.ts.map +1 -0
- package/dist/three/curve-plot3d.js +109 -0
- package/dist/three/curve-plot3d.js.map +1 -0
- package/dist/three/entries.d.ts +17 -0
- package/dist/three/entries.d.ts.map +1 -0
- package/dist/three/entries.js +15 -0
- package/dist/three/entries.js.map +1 -0
- package/dist/three/label3d.d.ts +11 -0
- package/dist/three/label3d.d.ts.map +1 -0
- package/dist/three/label3d.js +42 -0
- package/dist/three/label3d.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +99 -0
- package/dist/three/plot-point3d.d.ts.map +1 -0
- package/dist/three/plot-point3d.js +34 -0
- package/dist/three/plot-point3d.js.map +1 -0
- package/dist/three/space.d.ts +43 -0
- package/dist/three/space.d.ts.map +1 -0
- package/dist/three/space.js +58 -0
- package/dist/three/space.js.map +1 -0
- package/dist/three/surface-plot3d.d.ts +207 -0
- package/dist/three/surface-plot3d.d.ts.map +1 -0
- package/dist/three/surface-plot3d.js +261 -0
- package/dist/three/surface-plot3d.js.map +1 -0
- package/dist/three/vector-arrow3d.d.ts +96 -0
- package/dist/three/vector-arrow3d.d.ts.map +1 -0
- package/dist/three/vector-arrow3d.js +53 -0
- package/dist/three/vector-arrow3d.js.map +1 -0
- package/package.json +80 -3
- package/registry.json +251 -0
- package/src/annotate/angle-mark.ts +137 -0
- package/src/annotate/curly-brace.ts +148 -0
- package/src/annotate/emphasis-mark.ts +118 -0
- package/src/engine.ts +86 -0
- package/src/index.ts +29 -0
- package/src/kit/brace.ts +37 -0
- package/src/kit/cache.ts +61 -0
- package/src/kit/component.ts +57 -0
- package/src/kit/contour.ts +94 -0
- package/src/kit/coords.ts +278 -0
- package/src/kit/curve.ts +47 -0
- package/src/kit/equation.ts +181 -0
- package/src/kit/equation3d.ts +137 -0
- package/src/kit/expression.ts +159 -0
- package/src/kit/field-mark.ts +171 -0
- package/src/kit/field.ts +50 -0
- package/src/kit/follow.ts +229 -0
- package/src/kit/furniture.ts +113 -0
- package/src/kit/geometry.ts +49 -0
- package/src/kit/graph.ts +116 -0
- package/src/kit/mark.ts +152 -0
- package/src/kit/part-fills.ts +61 -0
- package/src/kit/place.ts +77 -0
- package/src/kit/sampler.ts +281 -0
- package/src/kit/scale.ts +39 -0
- package/src/kit/source.ts +57 -0
- package/src/kit/system.ts +105 -0
- package/src/kit/ticks.ts +85 -0
- package/src/kit/withdrawn.ts +8 -0
- package/src/marks/curve-area.ts +89 -0
- package/src/marks/drop-lines.ts +71 -0
- package/src/marks/plot-point.ts +102 -0
- package/src/marks/riemann-sum.ts +99 -0
- package/src/marks/tangent-line.ts +119 -0
- package/src/marks/vector-arrow.ts +98 -0
- package/src/nodes.ts +99 -0
- package/src/plots/function-plot.ts +220 -0
- package/src/plots/points-plot.ts +103 -0
- package/src/plots/stream-lines.ts +160 -0
- package/src/plots/traced-path.ts +70 -0
- package/src/plots/vector-field.ts +107 -0
- package/src/structures/graph-layout.ts +145 -0
- package/src/structures/network-graph.ts +291 -0
- package/src/structures/sample-space.ts +210 -0
- package/src/systems/axes2d.ts +226 -0
- package/src/systems/number-line.ts +130 -0
- package/src/systems/number-plane.ts +232 -0
- package/src/systems/polar-plane.ts +177 -0
- package/src/tex/geometry.ts +703 -0
- package/src/tex/index.ts +15 -0
- package/src/tex/mathjax.ts +82 -0
- package/src/tex/matrix.ts +97 -0
- package/src/tex/node.ts +74 -0
- package/src/tex/tween.ts +308 -0
- package/src/tex/typeset.ts +461 -0
- package/src/three/axes3d.ts +267 -0
- package/src/three/curve-plot3d.ts +146 -0
- package/src/three/entries.ts +42 -0
- package/src/three/label3d.ts +52 -0
- package/src/three/plot-point3d.ts +63 -0
- package/src/three/space.ts +92 -0
- package/src/three/surface-plot3d.ts +318 -0
- package/src/three/vector-arrow3d.ts +88 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/tex/node.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GAmBR,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EACH,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,gBAAgB,GAEvH,MAAM,WAAW,CAAC;AAoBnB,MAAM,KAAK,GAAG;IACV,GAAG,OAAO;IACV,mGAAmG;IACnG,KAAK,EAAE,KAAK,CAAC,MAAM,CAA+F,EAAE,EAAE;QAClH,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS;KACjD,CAAC;CACL,CAAC;AAEF,sFAAsF;AACtF,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC;IACrC,GAAG,EAAE,OAAO;IACZ,KAAK;IACL,QAAQ,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;IACzC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC;IACrC,QAAQ,EAAE;QACN,GAAG,gBAAgB;QACnB,oFAAoF;QACpF,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE;KAC/B;IACD,OAAO,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAC5F,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,EAAE,QAAQ,CAAC;IAC7D,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;CAC1F,CAAC,EAAE,CAAC,CAAuC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC","sourcesContent":["import {\n component2d,\n Types,\n type EntryOptions,\n type InsetsProps,\n type NodeOf,\n type ShapeProps,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Alignment as _Alignment,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n type Vector2 as _Vector2,\n} from \"@motionscript/sdk\";\n// From each module, never the `../engine` barrel: it re-exports this file, so a\n// load that enters through the barrel would build this component before the\n// modules it spreads exist.\nimport type { PartFill } from \"../kit/part-fills\";\nimport {\n drawFormula, formula, formulaFrame, layoutFormula, lerpMorph, loadFormula, measureFormula, TYPESET, TYPESET_COMMANDS,\n type Morphing,\n} from \"./typeset\";\nimport type { LatexMorphStrategy } from \"./tween\";\n\nexport interface LatexProps extends ShapeProps {\n latex: string;\n fontSize: number;\n padding: InsetsProps;\n partFills: PartFill[];\n written: number;\n}\n\n/**\n * How a formula morphs, for a node built on the `Typeset` helpers: they take it\n * as an argument (`formulaFrame(source, fontSize, partFills, morph)`).\n */\nexport interface LatexStrategies {\n /** How the node morphs between two formulas. Defaults to `defaultLatexMorph`. */\n morph?: LatexMorphStrategy;\n}\n\nconst state = {\n ...TYPESET,\n /** The formula. Mid-tween it holds both ends, and the glyphs morph from the one into the other. */\n latex: Types.custom<string, Morphing<string>, EntryOptions & { readonly kind: \"text\"; readonly multiline: true }>(\"\", {\n kind: \"text\", multiline: true, lerp: lerpMorph,\n }),\n};\n\n/** A LaTeX formula drawn as glyph paths, morphing token by token between formulas. */\nexport const Latex = formula(component2d({\n key: \"latex\",\n state,\n defaults: { width: \"hug\", height: \"hug\" },\n load: (loader) => loadFormula(loader),\n commands: {\n ...TYPESET_COMMANDS,\n /** Morph this formula into another, its glyphs travelling to their places in it. */\n morphTo: { args: [\"latex\"] },\n },\n measure: (_measurer, s) => measureFormula(formulaFrame(s.latex, s.fontSize, s.partFills), s),\n layout: (box, s, children) => layoutFormula(box, s, children),\n render: (ctx, s) => drawFormula(ctx, s, formulaFrame(s.latex, s.fontSize, s.partFills)),\n}), (s: { readonly latex: Morphing<string> }) => s.latex);\n\nexport type Latex = NodeOf<typeof Latex>;\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { LatexToken } from "./geometry.js";
|
|
2
|
+
export interface AnimatedToken {
|
|
3
|
+
token: string;
|
|
4
|
+
path: LatexToken["path"];
|
|
5
|
+
/** The top-level term it belongs to at rest; a morph matches on it. */
|
|
6
|
+
term?: string;
|
|
7
|
+
/** 0 = invisible, 1 = fully visible */
|
|
8
|
+
opacity: number;
|
|
9
|
+
/** Interpolated position offset applied during morph (x, y in formula space). */
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
/** Mid-morph: the index of the token it was in the formula left, and of the one it becomes. */
|
|
13
|
+
from?: number;
|
|
14
|
+
to?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* How a `Latex` node interpolates between two formulas: given the tokens it
|
|
18
|
+
* currently holds and the tokens the target formula resolves to, return a
|
|
19
|
+
* pure `t → AnimatedToken[]` frame function. `prepareLatexTween` below is the
|
|
20
|
+
* default implementation (exported as `defaultLatexMorph`) — pass a `morph`
|
|
21
|
+
* of this shape to `<Latex>` to replace it with your own.
|
|
22
|
+
*/
|
|
23
|
+
export type LatexMorphStrategy = (from: LatexToken[], to: LatexToken[]) => (t: number) => AnimatedToken[];
|
|
24
|
+
/**
|
|
25
|
+
* Precompute a formula-change morph and return a pure `t → AnimatedToken[]`
|
|
26
|
+
* frame function:
|
|
27
|
+
* - Deleted tokens fade out over the first half of `t`.
|
|
28
|
+
* - Matched tokens are interpolated — place *and* size — across the full range
|
|
29
|
+
* of `t`.
|
|
30
|
+
* - Added tokens fade in over the second half of `t`.
|
|
31
|
+
*
|
|
32
|
+
* A matched glyph is rarely the same size at both ends: the `2` of `b^2` is set
|
|
33
|
+
* at script size and the `2` of `2a` at full size, and a `\frac`'s arguments
|
|
34
|
+
* come back a step smaller than the same symbols on a baseline. So the
|
|
35
|
+
* interpolation has to carry the glyph's *geometry*, not just where it sits.
|
|
36
|
+
* Sliding the target outline from one centroid to the other — which is all this
|
|
37
|
+
* used to do — put the whole size change between the last static frame and the
|
|
38
|
+
* morph's first one: a snap to the new size, then a smooth glide to the new
|
|
39
|
+
* place. Point-by-point lerping (see {@link lerpPath}) is that same
|
|
40
|
+
* interpolation generalised from a glyph's average point to all of them, and it
|
|
41
|
+
* costs nothing extra — the path was already being rebuilt every frame to apply
|
|
42
|
+
* the slide.
|
|
43
|
+
*
|
|
44
|
+
* `t` is normalized `[0, 1]` and already eased — the caller (a `Command`'s
|
|
45
|
+
* `at`) applies easing once, up front, the same eased value driving every
|
|
46
|
+
* concurrent aspect of the morph (props, intrinsic size, tokens) in lockstep.
|
|
47
|
+
*/
|
|
48
|
+
export declare function prepareLatexTween(from: LatexToken[], to: LatexToken[]): (t: number) => AnimatedToken[];
|
|
49
|
+
export { prepareLatexTween as defaultLatexMorph };
|
|
50
|
+
//# sourceMappingURL=tween.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tween.d.ts","sourceRoot":"","sources":["../../src/tex/tween.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACzB,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,+FAA+F;IAC/F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC,EAAE,MAAM,KAAK,aAAa,EAAE,CAAC;AAgK1G;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAC7B,IAAI,EAAE,UAAU,EAAE,EAClB,EAAE,EAAE,UAAU,EAAE,GACjB,CAAC,CAAC,EAAE,MAAM,KAAK,aAAa,EAAE,CA6FhC;AAED,OAAO,EAAE,iBAAiB,IAAI,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { lerpNumber } from "@motionscript/sdk";
|
|
2
|
+
/** The coordinate pairs a `PathCommand` can carry, as (x, y) field names. */
|
|
3
|
+
const POINT_FIELDS = [["x", "y"], ["x1", "y1"], ["x2", "y2"]];
|
|
4
|
+
/**
|
|
5
|
+
* Compute the centroid of a token's path for position-based interpolation.
|
|
6
|
+
*/
|
|
7
|
+
function centroid(path) {
|
|
8
|
+
let sx = 0, sy = 0, n = 0;
|
|
9
|
+
for (const cmd of path) {
|
|
10
|
+
if ("x" in cmd && "y" in cmd) {
|
|
11
|
+
sx += cmd.x;
|
|
12
|
+
sy += cmd.y;
|
|
13
|
+
n++;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return n > 0 ? { x: sx / n, y: sy / n } : { x: 0, y: 0 };
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A glyph's on-screen extent, as the diagonal of its control-point bbox.
|
|
20
|
+
*
|
|
21
|
+
* Only ever used as a *ratio* between the two ends of a match, so the fact that
|
|
22
|
+
* control points overshoot the true outline doesn't matter: both ends overshoot
|
|
23
|
+
* by the same proportion, because they are the same outline.
|
|
24
|
+
*/
|
|
25
|
+
function extent(path) {
|
|
26
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
27
|
+
for (const cmd of path) {
|
|
28
|
+
const c = cmd;
|
|
29
|
+
for (const [kx, ky] of POINT_FIELDS) {
|
|
30
|
+
if (kx in c) {
|
|
31
|
+
if (c[kx] < minX)
|
|
32
|
+
minX = c[kx];
|
|
33
|
+
if (c[kx] > maxX)
|
|
34
|
+
maxX = c[kx];
|
|
35
|
+
if (c[ky] < minY)
|
|
36
|
+
minY = c[ky];
|
|
37
|
+
if (c[ky] > maxY)
|
|
38
|
+
maxY = c[ky];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (minX > maxX)
|
|
43
|
+
return 0;
|
|
44
|
+
return Math.hypot(maxX - minX, maxY - minY);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Whether two paths can be interpolated point by point: same command count,
|
|
48
|
+
* same command types in the same order.
|
|
49
|
+
*
|
|
50
|
+
* For a matched pair this is the overwhelmingly common case, and not by luck.
|
|
51
|
+
* Tokens are matched on the character their MathJax glyph id decodes to, and
|
|
52
|
+
* that id *is* the key into the `<defs>` dictionary — so the same character in
|
|
53
|
+
* two formulas is the same outline, emitted twice under two different
|
|
54
|
+
* transforms. Same commands, different numbers.
|
|
55
|
+
*/
|
|
56
|
+
function isPointwiseCompatible(from, to) {
|
|
57
|
+
if (from.length !== to.length)
|
|
58
|
+
return false;
|
|
59
|
+
for (let i = 0; i < from.length; i++) {
|
|
60
|
+
if (from[i].type !== to[i].type)
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Lerp two structurally identical paths point by point.
|
|
67
|
+
*
|
|
68
|
+
* When the two ends are the same outline under two affine transforms — which is
|
|
69
|
+
* what a matched glyph is — this is exact at both ends *and* correct in
|
|
70
|
+
* between: `(1-t)·A·q + t·B·q = ((1-t)A + tB)·q`, and a blend of two
|
|
71
|
+
* uniform-scale-plus-translate transforms is another one. The intermediate is a
|
|
72
|
+
* properly formed glyph at an intermediate size, not a smeared one.
|
|
73
|
+
*/
|
|
74
|
+
function lerpPath(from, to, t) {
|
|
75
|
+
const out = new Array(from.length);
|
|
76
|
+
for (let i = 0; i < from.length; i++) {
|
|
77
|
+
const f = from[i];
|
|
78
|
+
const g = to[i];
|
|
79
|
+
const c = { ...g };
|
|
80
|
+
for (const [kx, ky] of POINT_FIELDS) {
|
|
81
|
+
if (kx in g && kx in f) {
|
|
82
|
+
c[kx] = lerpNumber(f[kx], g[kx], t);
|
|
83
|
+
c[ky] = lerpNumber(f[ky], g[ky], t);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
out[i] = c;
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Scale a path uniformly about (cx, cy), then translate by (dx, dy).
|
|
92
|
+
*
|
|
93
|
+
* The fallback for a matched pair whose paths *aren't* structurally identical —
|
|
94
|
+
* a stretchy delimiter assembled from a different number of pieces at the two
|
|
95
|
+
* sizes, say. Point-by-point lerping is impossible there, so the target outline
|
|
96
|
+
* is shrunk to the source's size instead and grown back over the morph: the
|
|
97
|
+
* size still changes continuously, which is the whole point, at the cost of
|
|
98
|
+
* showing the target's shape from the start.
|
|
99
|
+
*/
|
|
100
|
+
function scaleAbout(path, cx, cy, s, dx, dy) {
|
|
101
|
+
return path.map(cmd => {
|
|
102
|
+
const c = { ...cmd };
|
|
103
|
+
for (const [kx, ky] of POINT_FIELDS) {
|
|
104
|
+
if (kx in c) {
|
|
105
|
+
c[kx] = cx + (c[kx] - cx) * s + dx;
|
|
106
|
+
c[ky] = cy + (c[ky] - cy) * s + dy;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return c;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Match tokens from `from` to `to` by character key, a term that both formulas
|
|
114
|
+
* write first: the `x^2` of `x^2 + 1` travels to the `x^2` of `y = x^2` as
|
|
115
|
+
* one, instead of lending its `2` to whichever `2` comes first. What is left
|
|
116
|
+
* is matched greedily by character alone.
|
|
117
|
+
* Returns three lists: matched pairs, deleted tokens (only in from), added tokens (only in to).
|
|
118
|
+
*/
|
|
119
|
+
function matchTokens(from, to) {
|
|
120
|
+
const remaining = [...to];
|
|
121
|
+
const partner = new Map();
|
|
122
|
+
// Synthetic shapes (rects/paths) have no natural token key.
|
|
123
|
+
const keyed = (t) => !t.token.startsWith("__");
|
|
124
|
+
const pair = (same) => {
|
|
125
|
+
for (const ft of from) {
|
|
126
|
+
if (!keyed(ft) || partner.has(ft))
|
|
127
|
+
continue;
|
|
128
|
+
const idx = remaining.findIndex(t => keyed(t) && same(ft, t));
|
|
129
|
+
if (idx === -1)
|
|
130
|
+
continue;
|
|
131
|
+
partner.set(ft, remaining[idx]);
|
|
132
|
+
remaining.splice(idx, 1);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
pair((f, t) => f.token === t.token && f.term !== undefined && f.term === t.term);
|
|
136
|
+
pair((f, t) => f.token === t.token);
|
|
137
|
+
const matched = [];
|
|
138
|
+
const deleted = [];
|
|
139
|
+
for (const ft of from) {
|
|
140
|
+
const tt = partner.get(ft);
|
|
141
|
+
if (tt)
|
|
142
|
+
matched.push({ from: ft, to: tt });
|
|
143
|
+
else
|
|
144
|
+
deleted.push(ft);
|
|
145
|
+
}
|
|
146
|
+
return { matched, deleted, added: remaining };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Precompute a formula-change morph and return a pure `t → AnimatedToken[]`
|
|
150
|
+
* frame function:
|
|
151
|
+
* - Deleted tokens fade out over the first half of `t`.
|
|
152
|
+
* - Matched tokens are interpolated — place *and* size — across the full range
|
|
153
|
+
* of `t`.
|
|
154
|
+
* - Added tokens fade in over the second half of `t`.
|
|
155
|
+
*
|
|
156
|
+
* A matched glyph is rarely the same size at both ends: the `2` of `b^2` is set
|
|
157
|
+
* at script size and the `2` of `2a` at full size, and a `\frac`'s arguments
|
|
158
|
+
* come back a step smaller than the same symbols on a baseline. So the
|
|
159
|
+
* interpolation has to carry the glyph's *geometry*, not just where it sits.
|
|
160
|
+
* Sliding the target outline from one centroid to the other — which is all this
|
|
161
|
+
* used to do — put the whole size change between the last static frame and the
|
|
162
|
+
* morph's first one: a snap to the new size, then a smooth glide to the new
|
|
163
|
+
* place. Point-by-point lerping (see {@link lerpPath}) is that same
|
|
164
|
+
* interpolation generalised from a glyph's average point to all of them, and it
|
|
165
|
+
* costs nothing extra — the path was already being rebuilt every frame to apply
|
|
166
|
+
* the slide.
|
|
167
|
+
*
|
|
168
|
+
* `t` is normalized `[0, 1]` and already eased — the caller (a `Command`'s
|
|
169
|
+
* `at`) applies easing once, up front, the same eased value driving every
|
|
170
|
+
* concurrent aspect of the morph (props, intrinsic size, tokens) in lockstep.
|
|
171
|
+
*/
|
|
172
|
+
export function prepareLatexTween(from, to) {
|
|
173
|
+
const { matched, deleted, added } = matchTokens(from, to);
|
|
174
|
+
// Per-match interpolation data. Structure compatibility, and the centroids
|
|
175
|
+
// and extents behind the fallback, are properties of the pair rather than
|
|
176
|
+
// of `t`, so they are settled once here instead of at every frame.
|
|
177
|
+
const fromIndex = new Map(from.map((token, i) => [token, i]));
|
|
178
|
+
const toIndex = new Map(to.map((token, i) => [token, i]));
|
|
179
|
+
const matchedData = matched.map(({ from: f, to: t }) => {
|
|
180
|
+
const toExtent = extent(t.path);
|
|
181
|
+
return {
|
|
182
|
+
from: fromIndex.get(f),
|
|
183
|
+
to: toIndex.get(t),
|
|
184
|
+
pointwise: isPointwiseCompatible(f.path, t.path),
|
|
185
|
+
fromPath: f.path,
|
|
186
|
+
toPath: t.path,
|
|
187
|
+
token: t.token,
|
|
188
|
+
fromCenter: centroid(f.path),
|
|
189
|
+
toCenter: centroid(t.path),
|
|
190
|
+
/** Only the fallback needs it, and only as a ratio. */
|
|
191
|
+
fromScale: toExtent > 0 ? extent(f.path) / toExtent : 1,
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
return (t) => {
|
|
195
|
+
const tokens = [];
|
|
196
|
+
// Matched tokens: interpolate place and size across the full duration.
|
|
197
|
+
for (const m of matchedData) {
|
|
198
|
+
if (m.pointwise) {
|
|
199
|
+
tokens.push({
|
|
200
|
+
token: m.token,
|
|
201
|
+
path: lerpPath(m.fromPath, m.toPath, t),
|
|
202
|
+
opacity: 1,
|
|
203
|
+
// Baked into the path above: the lerp carries every point,
|
|
204
|
+
// which includes where the glyph sits.
|
|
205
|
+
x: 0,
|
|
206
|
+
y: 0,
|
|
207
|
+
from: m.from,
|
|
208
|
+
to: m.to,
|
|
209
|
+
});
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const s = lerpNumber(m.fromScale, 1, t);
|
|
213
|
+
const cx = lerpNumber(m.fromCenter.x, m.toCenter.x, t);
|
|
214
|
+
const cy = lerpNumber(m.fromCenter.y, m.toCenter.y, t);
|
|
215
|
+
tokens.push({
|
|
216
|
+
token: m.token,
|
|
217
|
+
path: scaleAbout(m.toPath, m.toCenter.x, m.toCenter.y, s, cx - m.toCenter.x, cy - m.toCenter.y),
|
|
218
|
+
opacity: 1,
|
|
219
|
+
x: 0,
|
|
220
|
+
y: 0,
|
|
221
|
+
from: m.from,
|
|
222
|
+
to: m.to,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// Deleted tokens: fade out over the first half, gone by t=0.5
|
|
226
|
+
for (const d of deleted) {
|
|
227
|
+
const fadeT = Math.min(t * 2, 1);
|
|
228
|
+
tokens.push({
|
|
229
|
+
token: d.token,
|
|
230
|
+
path: d.path,
|
|
231
|
+
opacity: lerpNumber(1, 0, fadeT),
|
|
232
|
+
x: 0,
|
|
233
|
+
y: 0,
|
|
234
|
+
from: fromIndex.get(d),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
// Added tokens: fade in over the second half, starting at t=0.5
|
|
238
|
+
for (const a of added) {
|
|
239
|
+
const fadeT = Math.max(t * 2 - 1, 0);
|
|
240
|
+
tokens.push({
|
|
241
|
+
token: a.token,
|
|
242
|
+
path: a.path,
|
|
243
|
+
opacity: lerpNumber(0, 1, fadeT),
|
|
244
|
+
x: 0,
|
|
245
|
+
y: 0,
|
|
246
|
+
to: toIndex.get(a),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return tokens;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
export { prepareLatexTween as defaultLatexMorph };
|
|
253
|
+
//# sourceMappingURL=tween.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tween.js","sourceRoot":"","sources":["../../src/tex/tween.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAoB,MAAM,mBAAmB,CAAC;AA2BjE,6EAA6E;AAC7E,MAAM,YAAY,GAAG,C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C,EAAE,CAAC,CAAC,CAAC;YACrC,MAAM,CAAC,IAAI,CAAC;gBACR,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC;gBAChC,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,CAAC;gBACJ,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;aACrB,CAAC,CAAC;QACP,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;AACN,CAAC;AAED,OAAO,EAAE,iBAAiB,IAAI,iBAAiB,EAAE,CAAC","sourcesContent":["import { lerpNumber, type PathCommand } from \"@motionscript/sdk\";\nimport type { LatexToken } from \"./geometry\";\n\nexport interface AnimatedToken {\n token: string;\n path: LatexToken[\"path\"];\n /** The top-level term it belongs to at rest; a morph matches on it. */\n term?: string;\n /** 0 = invisible, 1 = fully visible */\n opacity: number;\n /** Interpolated position offset applied during morph (x, y in formula space). */\n x: number;\n y: number;\n /** Mid-morph: the index of the token it was in the formula left, and of the one it becomes. */\n from?: number;\n to?: number;\n}\n\n/**\n * How a `Latex` node interpolates between two formulas: given the tokens it\n * currently holds and the tokens the target formula resolves to, return a\n * pure `t → AnimatedToken[]` frame function. `prepareLatexTween` below is the\n * default implementation (exported as `defaultLatexMorph`) — pass a `morph`\n * of this shape to `<Latex>` to replace it with your own.\n */\nexport type LatexMorphStrategy = (from: LatexToken[], to: LatexToken[]) => (t: number) => AnimatedToken[];\n\n/** The coordinate pairs a `PathCommand` can carry, as (x, y) field names. */\nconst POINT_FIELDS = [[\"x\", \"y\"], [\"x1\", \"y1\"], [\"x2\", \"y2\"]] as const;\n\n/**\n * Compute the centroid of a token's path for position-based interpolation.\n */\nfunction centroid(path: LatexToken[\"path\"]): { x: number; y: number } {\n let sx = 0, sy = 0, n = 0;\n for (const cmd of path) {\n if (\"x\" in cmd && \"y\" in cmd) {\n sx += (cmd as any).x;\n sy += (cmd as any).y;\n n++;\n }\n }\n return n > 0 ? { x: sx / n, y: sy / n } : { x: 0, y: 0 };\n}\n\n/**\n * A glyph's on-screen extent, as the diagonal of its control-point bbox.\n *\n * Only ever used as a *ratio* between the two ends of a match, so the fact that\n * control points overshoot the true outline doesn't matter: both ends overshoot\n * by the same proportion, because they are the same outline.\n */\nfunction extent(path: LatexToken[\"path\"]): number {\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const cmd of path) {\n const c = cmd as any;\n for (const [kx, ky] of POINT_FIELDS) {\n if (kx in c) {\n if (c[kx] < minX) minX = c[kx];\n if (c[kx] > maxX) maxX = c[kx];\n if (c[ky] < minY) minY = c[ky];\n if (c[ky] > maxY) maxY = c[ky];\n }\n }\n }\n if (minX > maxX) return 0;\n return Math.hypot(maxX - minX, maxY - minY);\n}\n\n/**\n * Whether two paths can be interpolated point by point: same command count,\n * same command types in the same order.\n *\n * For a matched pair this is the overwhelmingly common case, and not by luck.\n * Tokens are matched on the character their MathJax glyph id decodes to, and\n * that id *is* the key into the `<defs>` dictionary — so the same character in\n * two formulas is the same outline, emitted twice under two different\n * transforms. Same commands, different numbers.\n */\nfunction isPointwiseCompatible(from: PathCommand[], to: PathCommand[]): boolean {\n if (from.length !== to.length) return false;\n for (let i = 0; i < from.length; i++) {\n if (from[i].type !== to[i].type) return false;\n }\n return true;\n}\n\n/**\n * Lerp two structurally identical paths point by point.\n *\n * When the two ends are the same outline under two affine transforms — which is\n * what a matched glyph is — this is exact at both ends *and* correct in\n * between: `(1-t)·A·q + t·B·q = ((1-t)A + tB)·q`, and a blend of two\n * uniform-scale-plus-translate transforms is another one. The intermediate is a\n * properly formed glyph at an intermediate size, not a smeared one.\n */\nfunction lerpPath(from: PathCommand[], to: PathCommand[], t: number): PathCommand[] {\n const out: PathCommand[] = new Array(from.length);\n for (let i = 0; i < from.length; i++) {\n const f = from[i] as any;\n const g = to[i] as any;\n const c: any = { ...g };\n for (const [kx, ky] of POINT_FIELDS) {\n if (kx in g && kx in f) {\n c[kx] = lerpNumber(f[kx], g[kx], t);\n c[ky] = lerpNumber(f[ky], g[ky], t);\n }\n }\n out[i] = c as PathCommand;\n }\n return out;\n}\n\n/**\n * Scale a path uniformly about (cx, cy), then translate by (dx, dy).\n *\n * The fallback for a matched pair whose paths *aren't* structurally identical —\n * a stretchy delimiter assembled from a different number of pieces at the two\n * sizes, say. Point-by-point lerping is impossible there, so the target outline\n * is shrunk to the source's size instead and grown back over the morph: the\n * size still changes continuously, which is the whole point, at the cost of\n * showing the target's shape from the start.\n */\nfunction scaleAbout(\n path: PathCommand[],\n cx: number,\n cy: number,\n s: number,\n dx: number,\n dy: number,\n): PathCommand[] {\n return path.map(cmd => {\n const c: any = { ...(cmd as any) };\n for (const [kx, ky] of POINT_FIELDS) {\n if (kx in c) {\n c[kx] = cx + (c[kx] - cx) * s + dx;\n c[ky] = cy + (c[ky] - cy) * s + dy;\n }\n }\n return c as PathCommand;\n });\n}\n\n/**\n * Match tokens from `from` to `to` by character key, a term that both formulas\n * write first: the `x^2` of `x^2 + 1` travels to the `x^2` of `y = x^2` as\n * one, instead of lending its `2` to whichever `2` comes first. What is left\n * is matched greedily by character alone.\n * Returns three lists: matched pairs, deleted tokens (only in from), added tokens (only in to).\n */\nfunction matchTokens(\n from: LatexToken[],\n to: LatexToken[],\n): {\n matched: Array<{ from: LatexToken; to: LatexToken }>;\n deleted: LatexToken[];\n added: LatexToken[];\n} {\n const remaining = [...to];\n const partner = new Map<LatexToken, LatexToken>();\n // Synthetic shapes (rects/paths) have no natural token key.\n const keyed = (t: LatexToken) => !t.token.startsWith(\"__\");\n const pair = (same: (f: LatexToken, t: LatexToken) => boolean) => {\n for (const ft of from) {\n if (!keyed(ft) || partner.has(ft)) continue;\n const idx = remaining.findIndex(t => keyed(t) && same(ft, t));\n if (idx === -1) continue;\n partner.set(ft, remaining[idx]);\n remaining.splice(idx, 1);\n }\n };\n pair((f, t) => f.token === t.token && f.term !== undefined && f.term === t.term);\n pair((f, t) => f.token === t.token);\n\n const matched: Array<{ from: LatexToken; to: LatexToken }> = [];\n const deleted: LatexToken[] = [];\n for (const ft of from) {\n const tt = partner.get(ft);\n if (tt) matched.push({ from: ft, to: tt });\n else deleted.push(ft);\n }\n\n return { matched, deleted, added: remaining };\n}\n\n/**\n * Precompute a formula-change morph and return a pure `t → AnimatedToken[]`\n * frame function:\n * - Deleted tokens fade out over the first half of `t`.\n * - Matched tokens are interpolated — place *and* size — across the full range\n * of `t`.\n * - Added tokens fade in over the second half of `t`.\n *\n * A matched glyph is rarely the same size at both ends: the `2` of `b^2` is set\n * at script size and the `2` of `2a` at full size, and a `\\frac`'s arguments\n * come back a step smaller than the same symbols on a baseline. So the\n * interpolation has to carry the glyph's *geometry*, not just where it sits.\n * Sliding the target outline from one centroid to the other — which is all this\n * used to do — put the whole size change between the last static frame and the\n * morph's first one: a snap to the new size, then a smooth glide to the new\n * place. Point-by-point lerping (see {@link lerpPath}) is that same\n * interpolation generalised from a glyph's average point to all of them, and it\n * costs nothing extra — the path was already being rebuilt every frame to apply\n * the slide.\n *\n * `t` is normalized `[0, 1]` and already eased — the caller (a `Command`'s\n * `at`) applies easing once, up front, the same eased value driving every\n * concurrent aspect of the morph (props, intrinsic size, tokens) in lockstep.\n */\nexport function prepareLatexTween(\n from: LatexToken[],\n to: LatexToken[],\n): (t: number) => AnimatedToken[] {\n const { matched, deleted, added } = matchTokens(from, to);\n\n // Per-match interpolation data. Structure compatibility, and the centroids\n // and extents behind the fallback, are properties of the pair rather than\n // of `t`, so they are settled once here instead of at every frame.\n const fromIndex = new Map(from.map((token, i) => [token, i]));\n const toIndex = new Map(to.map((token, i) => [token, i]));\n const matchedData = matched.map(({ from: f, to: t }) => {\n const toExtent = extent(t.path);\n return {\n from: fromIndex.get(f),\n to: toIndex.get(t),\n pointwise: isPointwiseCompatible(f.path, t.path),\n fromPath: f.path,\n toPath: t.path,\n token: t.token,\n fromCenter: centroid(f.path),\n toCenter: centroid(t.path),\n /** Only the fallback needs it, and only as a ratio. */\n fromScale: toExtent > 0 ? extent(f.path) / toExtent : 1,\n };\n });\n\n return (t: number): AnimatedToken[] => {\n const tokens: AnimatedToken[] = [];\n\n // Matched tokens: interpolate place and size across the full duration.\n for (const m of matchedData) {\n if (m.pointwise) {\n tokens.push({\n token: m.token,\n path: lerpPath(m.fromPath, m.toPath, t),\n opacity: 1,\n // Baked into the path above: the lerp carries every point,\n // which includes where the glyph sits.\n x: 0,\n y: 0,\n from: m.from,\n to: m.to,\n });\n continue;\n }\n\n const s = lerpNumber(m.fromScale, 1, t);\n const cx = lerpNumber(m.fromCenter.x, m.toCenter.x, t);\n const cy = lerpNumber(m.fromCenter.y, m.toCenter.y, t);\n tokens.push({\n token: m.token,\n path: scaleAbout(\n m.toPath,\n m.toCenter.x,\n m.toCenter.y,\n s,\n cx - m.toCenter.x,\n cy - m.toCenter.y,\n ),\n opacity: 1,\n x: 0,\n y: 0,\n from: m.from,\n to: m.to,\n });\n }\n\n // Deleted tokens: fade out over the first half, gone by t=0.5\n for (const d of deleted) {\n const fadeT = Math.min(t * 2, 1);\n tokens.push({\n token: d.token,\n path: d.path,\n opacity: lerpNumber(1, 0, fadeT),\n x: 0,\n y: 0,\n from: fromIndex.get(d),\n });\n }\n\n // Added tokens: fade in over the second half, starting at t=0.5\n for (const a of added) {\n const fadeT = Math.max(t * 2 - 1, 0);\n tokens.push({\n token: a.token,\n path: a.path,\n opacity: lerpNumber(0, 1, fadeT),\n x: 0,\n y: 0,\n to: toIndex.get(a),\n });\n }\n\n return tokens;\n };\n}\n\nexport { prepareLatexTween as defaultLatexMorph };\n"]}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Flow, type BoxBounds, type ChildView, type Fill, type FillResolved, type InsetsResolved, type Loader, type Placement2D, type RenderContext, type ShadowResolved, type Size2D, type StrokeResolved, type Values, type Alignment as _Alignment, type FlowMode as _FlowMode, type FlowResolved as _FlowResolved, type GapSize as _GapSize, type Shadow as _Shadow, type Stroke as _Stroke, type Vector2 as _Vector2 } from "@motionscript/sdk";
|
|
2
|
+
import { type LatexPart } from "./geometry.js";
|
|
3
|
+
import { type AnimatedToken, type LatexMorphStrategy } from "./tween.js";
|
|
4
|
+
import { type PartFill, type PartFillResolved } from "../kit/part-fills.js";
|
|
5
|
+
/**
|
|
6
|
+
* A formula typeset to glyph paths: what `latex` and `latexMatrix` share. A
|
|
7
|
+
* node says where its formula comes from (`formula`); this lays it out, draws
|
|
8
|
+
* it, writes it on, paints its parts, and morphs it into another.
|
|
9
|
+
*
|
|
10
|
+
* A morph is held by the entries the formula is written from: mid-tween each
|
|
11
|
+
* holds both ends ({@link Morph}), so a seek to any time draws the morph there
|
|
12
|
+
* from the node's own state, and a plain `to({ latex })` morphs as `morphTo` does.
|
|
13
|
+
*/
|
|
14
|
+
/** A value on its way to another: what an entry the formula is written from holds mid-tween. */
|
|
15
|
+
export declare class Morph<T> {
|
|
16
|
+
readonly from: T;
|
|
17
|
+
readonly to: T;
|
|
18
|
+
readonly t: number;
|
|
19
|
+
constructor(from: T, to: T, t: number);
|
|
20
|
+
}
|
|
21
|
+
export type Morphing<T> = T | Morph<T>;
|
|
22
|
+
/** The end a value rests at, or is nearer to mid-tween: where a tween that starts from it starts. */
|
|
23
|
+
export declare function settled<T>(value: Morphing<T>): T;
|
|
24
|
+
export declare function lerpMorph<T>(from: Morphing<T>, to: Morphing<T>, t: number): Morphing<T>;
|
|
25
|
+
/** `parts` combined into one value at each end, when any of them is on its way: a matrix's source from its entries and brackets. */
|
|
26
|
+
export declare function morphOf<T>(parts: readonly Morphing<unknown>[], combine: (ends: readonly unknown[]) => T): Morphing<T>;
|
|
27
|
+
/** What every formula has: the glyphs' paint, the flow its children are laid out in, its size, its part fills and how much of it is written. */
|
|
28
|
+
export declare const TYPESET: {
|
|
29
|
+
fontSize: number;
|
|
30
|
+
/** Paints for parts of the formula, named by their source. Later entries win where two name a glyph. */
|
|
31
|
+
partFills: import("@motionscript/sdk").Type<PartFill[], PartFillResolved[], false>;
|
|
32
|
+
/**
|
|
33
|
+
* How much of the formula is written, 0 to 1: its glyphs are drawn one after
|
|
34
|
+
* another, each outlined and then filled.
|
|
35
|
+
*/
|
|
36
|
+
written: import("@motionscript/sdk").Type<number, number, false>;
|
|
37
|
+
/** Reported for a host that read it; the morph is held by the formula's own entries. */
|
|
38
|
+
morphProgress: import("@motionscript/sdk").Type<number, number, false>;
|
|
39
|
+
flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
40
|
+
gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
41
|
+
wrap: boolean;
|
|
42
|
+
crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
43
|
+
columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
44
|
+
align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
|
|
45
|
+
fill: import("@motionscript/sdk").Attribute<Fill, FillResolved[]>;
|
|
46
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
|
|
47
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
|
|
48
|
+
overlay: import("@motionscript/sdk").Attribute<Fill, FillResolved[]>;
|
|
49
|
+
};
|
|
50
|
+
export declare const TYPESET_COMMANDS: {
|
|
51
|
+
writeTo: {
|
|
52
|
+
readonly args: readonly ["written"];
|
|
53
|
+
readonly run?: undefined;
|
|
54
|
+
};
|
|
55
|
+
partFillTo: {
|
|
56
|
+
readonly args: {
|
|
57
|
+
readonly part: import("@motionscript/sdk").Type<string, string, false>;
|
|
58
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, Fill, false>;
|
|
59
|
+
readonly occurrence: import("@motionscript/sdk").Type<number, number, false>;
|
|
60
|
+
};
|
|
61
|
+
run(timeline: any, state: any, children: any): import("@motionscript/sdk").Piece;
|
|
62
|
+
};
|
|
63
|
+
overlayTo: {
|
|
64
|
+
readonly args: readonly ["overlay"];
|
|
65
|
+
readonly run?: undefined;
|
|
66
|
+
};
|
|
67
|
+
fillTo: {
|
|
68
|
+
readonly args: readonly ["fill"];
|
|
69
|
+
readonly run?: undefined;
|
|
70
|
+
};
|
|
71
|
+
strokeTo: {
|
|
72
|
+
readonly args: readonly ["stroke"];
|
|
73
|
+
readonly run?: undefined;
|
|
74
|
+
};
|
|
75
|
+
shadowTo: {
|
|
76
|
+
readonly args: readonly ["shadow"];
|
|
77
|
+
readonly run?: undefined;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
type TypesetValues = Values<typeof TYPESET>;
|
|
81
|
+
/** What is drawn of a formula now: its glyphs, its parts, its centre frame and size, and mid-morph each end's part fills. */
|
|
82
|
+
export interface FormulaFrame {
|
|
83
|
+
readonly tokens: readonly AnimatedToken[];
|
|
84
|
+
readonly parts: readonly LatexPart[];
|
|
85
|
+
readonly bounds: [number, number, number, number];
|
|
86
|
+
readonly width: number;
|
|
87
|
+
readonly height: number;
|
|
88
|
+
readonly morph: {
|
|
89
|
+
readonly from: TokenFills;
|
|
90
|
+
readonly to: TokenFills;
|
|
91
|
+
readonly t: number;
|
|
92
|
+
} | null;
|
|
93
|
+
}
|
|
94
|
+
/** One part fill per token, or none: the last entry that names it. */
|
|
95
|
+
type TokenFills = (PartFillResolved | undefined)[];
|
|
96
|
+
/** The formula drawn now, from where it comes from: at rest, or `t` of the way through a morph. */
|
|
97
|
+
export declare function formulaFrame(source: Morphing<string>, fontSize: number, partFills: readonly PartFillResolved[], morph?: LatexMorphStrategy): FormulaFrame;
|
|
98
|
+
/** Its formula's size and its padding, hugging; the factory applies a set or filling size. */
|
|
99
|
+
export declare function measureFormula(frame: FormulaFrame, s: {
|
|
100
|
+
readonly padding: InsetsResolved;
|
|
101
|
+
}): Size2D;
|
|
102
|
+
/** Its children, laid out in its box clear of its stroke, as a shape lays out its own. */
|
|
103
|
+
export declare function layoutFormula(box: BoxBounds, s: Flow.FlowState & {
|
|
104
|
+
readonly stroke: StrokeResolved[];
|
|
105
|
+
}, children: readonly ChildView<any>[]): readonly Placement2D[];
|
|
106
|
+
/** MathJax, before this node is laid out: a scene with no formula in it never loads it. */
|
|
107
|
+
export declare function loadFormula(loader: Loader): void;
|
|
108
|
+
/**
|
|
109
|
+
* The glyphs, in a node's paint order: each one's shadow, fill and stroke
|
|
110
|
+
* (the shadow op first, so the paint after it casts it), the pen's line while
|
|
111
|
+
* it is being written, then the children, then the overlay through the glyphs.
|
|
112
|
+
*/
|
|
113
|
+
export declare function drawFormula(ctx: RenderContext, s: TypesetValues, frame: FormulaFrame): void;
|
|
114
|
+
/**
|
|
115
|
+
* The box around one part of the formula, centred on the node's own centre and
|
|
116
|
+
* y-up, or `null` when the formula does not write `part` (or is mid-morph).
|
|
117
|
+
* `occurrence` counts from 1.
|
|
118
|
+
*/
|
|
119
|
+
export declare function partBoundsIn(frame: FormulaFrame, part: string, occurrence?: number): BoxBounds | null;
|
|
120
|
+
/** Where a node's formula comes from, by the class its component generated. */
|
|
121
|
+
type SourceOf = (values: never) => Morphing<string>;
|
|
122
|
+
/** Declare `component` a formula written from `source`: a mark can then point at its parts. */
|
|
123
|
+
export declare function formula<C extends {
|
|
124
|
+
readonly node: object;
|
|
125
|
+
}>(component: C, source: SourceOf): C;
|
|
126
|
+
/** Whether `node` draws a formula, and so has parts a mark can point at. */
|
|
127
|
+
export declare function isFormula(node: object): boolean;
|
|
128
|
+
/** The formula `node` draws now, or `null` when it is no formula. */
|
|
129
|
+
export declare function formulaOf(node: object): FormulaFrame | null;
|
|
130
|
+
/** The box around a part of the formula `node` draws (see {@link partBoundsIn}); `undefined` when it is no formula. */
|
|
131
|
+
export declare function latexPartBounds(node: object, part: string, occurrence?: number): BoxBounds | null | undefined;
|
|
132
|
+
export type { TypesetValues };
|
|
133
|
+
//# sourceMappingURL=typeset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeset.d.ts","s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