@motionscript/math 0.0.0-stage → 0.1.0-alpha.4
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 +92 -0
- package/LICENSE +201 -0
- package/NOTICE +48 -0
- package/README.md +385 -3
- package/dist/annotate/angle-mark.d.ts +46 -0
- package/dist/annotate/angle-mark.d.ts.map +1 -0
- package/dist/annotate/angle-mark.js +132 -0
- package/dist/annotate/angle-mark.js.map +1 -0
- package/dist/annotate/curly-brace.d.ts +46 -0
- package/dist/annotate/curly-brace.d.ts.map +1 -0
- package/dist/annotate/curly-brace.js +114 -0
- package/dist/annotate/curly-brace.js.map +1 -0
- package/dist/annotate/emphasis-mark.d.ts +20 -0
- package/dist/annotate/emphasis-mark.d.ts.map +1 -0
- package/dist/annotate/emphasis-mark.js +81 -0
- package/dist/annotate/emphasis-mark.js.map +1 -0
- package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js +2 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.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 +64 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +42 -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/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 +17 -0
- package/dist/kit/curve.d.ts.map +1 -0
- package/dist/kit/curve.js +22 -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 +58 -0
- package/dist/kit/field-mark.d.ts.map +1 -0
- package/dist/kit/field-mark.js +129 -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 +71 -0
- package/dist/kit/follow.d.ts.map +1 -0
- package/dist/kit/follow.js +159 -0
- package/dist/kit/follow.js.map +1 -0
- package/dist/kit/furniture.d.ts +30 -0
- package/dist/kit/furniture.d.ts.map +1 -0
- package/dist/kit/furniture.js +87 -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/mark.d.ts +47 -0
- package/dist/kit/mark.d.ts.map +1 -0
- package/dist/kit/mark.js +103 -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 +18 -0
- package/dist/kit/place.d.ts.map +1 -0
- package/dist/kit/place.js +68 -0
- package/dist/kit/place.js.map +1 -0
- package/dist/kit/placement.d.ts +8 -0
- package/dist/kit/placement.d.ts.map +1 -0
- package/dist/kit/placement.js +8 -0
- package/dist/kit/placement.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 +33 -0
- package/dist/kit/system.d.ts.map +1 -0
- package/dist/kit/system.js +67 -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 +32 -0
- package/dist/marks/curve-area.d.ts.map +1 -0
- package/dist/marks/curve-area.js +82 -0
- package/dist/marks/curve-area.js.map +1 -0
- package/dist/marks/drop-lines.d.ts +22 -0
- package/dist/marks/drop-lines.d.ts.map +1 -0
- package/dist/marks/drop-lines.js +58 -0
- package/dist/marks/drop-lines.js.map +1 -0
- package/dist/marks/plot-point.d.ts +35 -0
- package/dist/marks/plot-point.d.ts.map +1 -0
- package/dist/marks/plot-point.js +97 -0
- package/dist/marks/plot-point.js.map +1 -0
- package/dist/marks/riemann-sum.d.ts +37 -0
- package/dist/marks/riemann-sum.d.ts.map +1 -0
- package/dist/marks/riemann-sum.js +91 -0
- package/dist/marks/riemann-sum.js.map +1 -0
- package/dist/marks/tangent-line.d.ts +27 -0
- package/dist/marks/tangent-line.d.ts.map +1 -0
- package/dist/marks/tangent-line.js +103 -0
- package/dist/marks/tangent-line.js.map +1 -0
- package/dist/marks/vector-arrow.d.ts +32 -0
- package/dist/marks/vector-arrow.d.ts.map +1 -0
- package/dist/marks/vector-arrow.js +87 -0
- package/dist/marks/vector-arrow.js.map +1 -0
- package/dist/nodes.d.ts +35 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +63 -0
- package/dist/nodes.js.map +1 -0
- package/dist/plots/function-plot.d.ts +67 -0
- package/dist/plots/function-plot.d.ts.map +1 -0
- package/dist/plots/function-plot.js +215 -0
- package/dist/plots/function-plot.js.map +1 -0
- package/dist/plots/points-plot.d.ts +28 -0
- package/dist/plots/points-plot.d.ts.map +1 -0
- package/dist/plots/points-plot.js +99 -0
- package/dist/plots/points-plot.js.map +1 -0
- package/dist/plots/stream-lines.d.ts +35 -0
- package/dist/plots/stream-lines.d.ts.map +1 -0
- package/dist/plots/stream-lines.js +141 -0
- package/dist/plots/stream-lines.js.map +1 -0
- package/dist/plots/traced-path.d.ts +31 -0
- package/dist/plots/traced-path.d.ts.map +1 -0
- package/dist/plots/traced-path.js +56 -0
- package/dist/plots/traced-path.js.map +1 -0
- package/dist/plots/vector-field.d.ts +23 -0
- package/dist/plots/vector-field.d.ts.map +1 -0
- package/dist/plots/vector-field.js +91 -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 +83 -0
- package/dist/structures/network-graph.d.ts.map +1 -0
- package/dist/structures/network-graph.js +289 -0
- package/dist/structures/network-graph.js.map +1 -0
- package/dist/structures/sample-space.d.ts +62 -0
- package/dist/structures/sample-space.d.ts.map +1 -0
- package/dist/structures/sample-space.js +199 -0
- package/dist/structures/sample-space.js.map +1 -0
- package/dist/systems/axes2d.d.ts +75 -0
- package/dist/systems/axes2d.d.ts.map +1 -0
- package/dist/systems/axes2d.js +193 -0
- package/dist/systems/axes2d.js.map +1 -0
- package/dist/systems/number-line.d.ts +49 -0
- package/dist/systems/number-line.d.ts.map +1 -0
- package/dist/systems/number-line.js +127 -0
- package/dist/systems/number-line.js.map +1 -0
- package/dist/systems/number-plane.d.ts +59 -0
- package/dist/systems/number-plane.d.ts.map +1 -0
- package/dist/systems/number-plane.js +193 -0
- package/dist/systems/number-plane.js.map +1 -0
- package/dist/systems/polar-plane.d.ts +48 -0
- package/dist/systems/polar-plane.d.ts.map +1 -0
- package/dist/systems/polar-plane.js +165 -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 +9 -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 +31 -0
- package/dist/tex/matrix.d.ts.map +1 -0
- package/dist/tex/matrix.js +73 -0
- package/dist/tex/matrix.js.map +1 -0
- package/dist/tex/node.d.ts +215 -0
- package/dist/tex/node.d.ts.map +1 -0
- package/dist/tex/node.js +595 -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/three/axes3d.d.ts +87 -0
- package/dist/three/axes3d.d.ts.map +1 -0
- package/dist/three/axes3d.js +228 -0
- package/dist/three/axes3d.js.map +1 -0
- package/dist/three/curve-plot3d.d.ts +60 -0
- package/dist/three/curve-plot3d.d.ts.map +1 -0
- package/dist/three/curve-plot3d.js +143 -0
- package/dist/three/curve-plot3d.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 +40 -0
- package/dist/three/label3d.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +26 -0
- package/dist/three/plot-point3d.d.ts.map +1 -0
- package/dist/three/plot-point3d.js +60 -0
- package/dist/three/plot-point3d.js.map +1 -0
- package/dist/three/space.d.ts +28 -0
- package/dist/three/space.d.ts.map +1 -0
- package/dist/three/space.js +47 -0
- package/dist/three/space.js.map +1 -0
- package/dist/three/surface-plot3d.d.ts +80 -0
- package/dist/three/surface-plot3d.d.ts.map +1 -0
- package/dist/three/surface-plot3d.js +290 -0
- package/dist/three/surface-plot3d.js.map +1 -0
- package/dist/three/vector-arrow3d.d.ts +25 -0
- package/dist/three/vector-arrow3d.d.ts.map +1 -0
- package/dist/three/vector-arrow3d.js +72 -0
- package/dist/three/vector-arrow3d.js.map +1 -0
- package/package.json +79 -3
- package/registry.json +251 -0
- package/src/annotate/angle-mark.ts +147 -0
- package/src/annotate/curly-brace.ts +126 -0
- package/src/annotate/emphasis-mark.ts +89 -0
- package/src/engine.ts +72 -0
- package/src/index.ts +29 -0
- package/src/kit/brace.ts +37 -0
- package/src/kit/cache.ts +61 -0
- package/src/kit/contour.ts +94 -0
- package/src/kit/coords.ts +278 -0
- package/src/kit/curve.ts +29 -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 +155 -0
- package/src/kit/field.ts +50 -0
- package/src/kit/follow.ts +203 -0
- package/src/kit/furniture.ts +108 -0
- package/src/kit/geometry.ts +49 -0
- package/src/kit/mark.ts +131 -0
- package/src/kit/part-fills.ts +61 -0
- package/src/kit/place.ts +101 -0
- package/src/kit/placement.ts +8 -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 +99 -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 +63 -0
- package/src/marks/plot-point.ts +107 -0
- package/src/marks/riemann-sum.ts +98 -0
- package/src/marks/tangent-line.ts +103 -0
- package/src/marks/vector-arrow.ts +98 -0
- package/src/nodes.ts +63 -0
- package/src/plots/function-plot.ts +236 -0
- package/src/plots/points-plot.ts +107 -0
- package/src/plots/stream-lines.ts +151 -0
- package/src/plots/traced-path.ts +52 -0
- package/src/plots/vector-field.ts +88 -0
- package/src/structures/graph-layout.ts +145 -0
- package/src/structures/network-graph.ts +308 -0
- package/src/structures/sample-space.ts +209 -0
- package/src/systems/axes2d.ts +217 -0
- package/src/systems/number-line.ts +131 -0
- package/src/systems/number-plane.ts +203 -0
- package/src/systems/polar-plane.ts +176 -0
- package/src/tex/geometry.ts +703 -0
- package/src/tex/index.ts +14 -0
- package/src/tex/mathjax.ts +82 -0
- package/src/tex/matrix.ts +75 -0
- package/src/tex/node.ts +641 -0
- package/src/tex/tween.ts +308 -0
- package/src/three/axes3d.ts +240 -0
- package/src/three/curve-plot3d.ts +147 -0
- package/src/three/label3d.ts +50 -0
- package/src/three/plot-point3d.ts +66 -0
- package/src/three/space.ts +67 -0
- package/src/three/surface-plot3d.ts +323 -0
- package/src/three/vector-arrow3d.ts +77 -0
package/README.md
CHANGED
|
@@ -1,3 +1,385 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @motionscript/math
|
|
2
|
+
|
|
3
|
+
Math for [Motion Script](https://motionscript.dev): coordinate systems whose
|
|
4
|
+
children sit in graph coordinates, plots of equations, the marks that go on a
|
|
5
|
+
graph, and typeset formulas that morph into one another.
|
|
6
|
+
|
|
7
|
+
Hand the kit's nodes to the engine through your project entry's `nodes`, and any
|
|
8
|
+
document that engine opens can name them by key:
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
// src/project.ts
|
|
12
|
+
import { NODES } from '@motionscript/math';
|
|
13
|
+
|
|
14
|
+
export const nodes = NODES;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Exports
|
|
18
|
+
|
|
19
|
+
| Entry | Holds |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `@motionscript/math` | Every node class, `NODES`, and the kit below |
|
|
22
|
+
| `@motionscript/math/kit` | What the nodes share and a copied node imports rather than copies: `CoordinateSystem`, `Mark`, the coordinate map, the equation language, the sampler, and the LaTeX helpers |
|
|
23
|
+
| `@motionscript/math/tex` | The typeset-math half alone: `Latex`, `TEX_NODES` and its helpers |
|
|
24
|
+
|
|
25
|
+
## Nodes
|
|
26
|
+
|
|
27
|
+
Every node also has the shape commands (`moveTo`, `fadeTo`, `fillTo`,
|
|
28
|
+
`strokeTo`, `progressTo`, …).
|
|
29
|
+
|
|
30
|
+
| Key | What it is | Goes in | Own commands |
|
|
31
|
+
| --- | --- | --- | --- |
|
|
32
|
+
| `numberLine` | One axis with ticks and numbers | anywhere | `rangeTo({ range })` |
|
|
33
|
+
| `axes2d` | An x and a y axis, linear or log | anywhere | `rangeTo({ xRange, yRange })` |
|
|
34
|
+
| `numberPlane` | Axes over a full grid, square units | anywhere | `rangeTo`, `transformTo({ matrix })`, `warpTo({ warp })` |
|
|
35
|
+
| `polarPlane` | Rings and spokes about an origin | anywhere | `rangeTo({ radius })` |
|
|
36
|
+
| `functionPlot` | The curve of an equation | a system | `morphTo({ expression })`, `paramsTo({ params })`, `domainTo({ domain })` |
|
|
37
|
+
| `pointsPlot` | A line or closed shape through listed graph points | a system | `pointsTo({ points })` |
|
|
38
|
+
| `plotPoint` | A labelled dot, free or riding a plot | a system or a `functionPlot` | |
|
|
39
|
+
| `vectorArrow` | An arrow from `tail` to `head` | a system | `endpointsTo({ tail, head })` |
|
|
40
|
+
| `curveArea` | The region under a plot, or between two | a system, beside a `functionPlot` | `domainTo({ domain })` |
|
|
41
|
+
| `riemannSum` | Rectangles approximating that region | a system, beside a `functionPlot` | `refineTo({ dx })`, `domainTo({ domain })` |
|
|
42
|
+
| `tangentLine` | The tangent to a plot, or a secant with its run and rise | a `functionPlot` | |
|
|
43
|
+
| `dropLines` | Guides from a graph point to the axes | a system or a `functionPlot` | |
|
|
44
|
+
| `latex` | A typeset formula with nameable parts | anywhere | `morphTo({ latex })`, `partFillTo({ part, fill })`, `writeTo({ written })` |
|
|
45
|
+
| `latexMatrix` | A matrix typeset from its entries | anywhere | `entriesTo({ entries })`, and a formula's |
|
|
46
|
+
| `curlyBrace` | A brace along a node, a part of a formula, or two points | anywhere | `retargetTo({ on, part })` |
|
|
47
|
+
| `emphasisMark` | A box, circle, underline or cross on a node or a part | anywhere | `retargetTo({ on, part })` |
|
|
48
|
+
| `angleMark` | An angle's arc or square, with its label | anywhere | `radiusTo({ radius })` |
|
|
49
|
+
| `axes3d` | A 3D graph: three axes through a box of graph coordinates, z up, seen through its own camera | anywhere 2D (it is a `canvas3d`) | `rangeTo({ xRange, yRange, zRange })`, and a `canvas3d`'s `orbitTo` |
|
|
50
|
+
| `surfacePlot3d` | A surface: a height over x and y, or three parts in u and v | an `axes3d` | `morphTo({ expression })`, `paramsTo({ params })`, `domainTo({ uDomain, vDomain })` |
|
|
51
|
+
| `curvePlot3d` | A curve through space, three parts in t | an `axes3d` | `morphTo`, `paramsTo`, `domainTo({ domain })`, `progressTo({ start, end })` |
|
|
52
|
+
| `plotPoint3d` | A labelled dot, free or riding a surface | an `axes3d` or a `surfacePlot3d` | |
|
|
53
|
+
| `vectorArrow3d` | An arrow from `tail` to `head` | an `axes3d` | `endpointsTo({ tail, head })` |
|
|
54
|
+
| `vectorField` | A grid of arrows showing a field, `(P, Q)` in x and y | a system | `morphTo({ expression })`, `paramsTo({ params })` |
|
|
55
|
+
| `streamLines` | The lines a field carries a point along | a system | `flowTo({ phase })`, `morphTo`, `paramsTo` |
|
|
56
|
+
| `tracedPath` | The trail a point leaves as a value changes | a system | `traceTo({ value })`, and a plot's |
|
|
57
|
+
| `networkGraph` | Vertices and edges, arranged in a circle, by springs, as a tree or in a grid | anywhere | `arrangeTo({ arrangement })`, `partFillTo({ part, fill })` |
|
|
58
|
+
| `sampleSpace` | A probability's whole cut into parts whose areas are their probabilities | anywhere | `divideTo({ columnShares, rowShares })` |
|
|
59
|
+
|
|
60
|
+
A system is a `numberLine`, an `axes2d`, a `numberPlane` or a `polarPlane`. Where a node goes is
|
|
61
|
+
written on its class (`@node({ within, beside, closed })`), so a host can offer
|
|
62
|
+
it only there; a `functionPlot` takes only the marks made for it. Nothing
|
|
63
|
+
checks it when a document builds: a plot outside a system builds and draws
|
|
64
|
+
nothing.
|
|
65
|
+
|
|
66
|
+
Each node takes only the paints it draws. A shape's `fill`, `stroke` and outline
|
|
67
|
+
trim (`start`, `end`, `progressTo`, `flash`) are inherited, and a node that has no
|
|
68
|
+
use for one withdraws it (`withdraw` from the SDK), so it is not offered and
|
|
69
|
+
writing it changes nothing: a plot, a tangent, an arrow or a brace is a line with
|
|
70
|
+
no fill; an area is a fill with no outline; a field is one stroke for every arrow
|
|
71
|
+
or line; a formula and a traced path reveal themselves (`writeTo`, `traceTo`)
|
|
72
|
+
rather than by trimming; a dot, a sample space and a Riemann sum have nothing a
|
|
73
|
+
trim would draw on. `shadow` stays on all of them.
|
|
74
|
+
|
|
75
|
+
## Coordinate systems
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const document = {
|
|
79
|
+
kind: 'composition',
|
|
80
|
+
variables: [{ id: 't', value: 0 }],
|
|
81
|
+
nodes: [
|
|
82
|
+
{ id: 'axes', type: 'axes2d', parentId: null, layerOrder: 0,
|
|
83
|
+
props: { width: 800, height: 450, xRange: [-4, 4], yRange: [-2, 2], fontFamily: 'Inter' } },
|
|
84
|
+
{ id: 'curve', type: 'functionPlot', parentId: 'axes', layerOrder: 0, props: { expression: 'sin(x)' } },
|
|
85
|
+
{ id: 'dot', type: 'plotPoint', parentId: 'curve', layerOrder: 0, props: { x: '=[t]' } },
|
|
86
|
+
{ id: 'note', type: 'text', parentId: 'axes', layerOrder: 1,
|
|
87
|
+
props: { x: 2, y: 1.5, text: 'y = sin x', fontSize: 24, fontFamily: 'Inter', fill: 'white' } },
|
|
88
|
+
],
|
|
89
|
+
commands: [
|
|
90
|
+
{ id: 'a', type: 'progressTo', targetId: 'curve', at: 0, duration: 1, args: { end: 1 } },
|
|
91
|
+
{ id: 'b', type: 'variableTo', targetId: 't', at: 1, duration: 2, args: { value: 3.14 } },
|
|
92
|
+
{ id: 'c', type: 'rangeTo', targetId: 'axes', at: 3, duration: 1, args: { xRange: [0, 8] } },
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- **A child's `x`/`y` are graph units, whatever the child is.** A text, an image
|
|
98
|
+
or a shape dropped in a system sits at graph coordinates and keeps its own
|
|
99
|
+
size; `moveTo` moves it in graph units; a range tween carries it. On a
|
|
100
|
+
`numberLine`, `x` is a value on the line and `y` is pixels above it.
|
|
101
|
+
- **A mark is drawn through the system's map.** `functionPlot`, `pointsPlot`,
|
|
102
|
+
`vectorArrow`, `curveArea`, `riemannSum`, `tangentLine` and `dropLines` extend
|
|
103
|
+
`Mark`: their geometry is in graph coordinates and their box is the tight box of
|
|
104
|
+
their ink. A plot's or an arrow's own `x`/`y` shift it in graph units; a
|
|
105
|
+
`tangentLine`'s and a `dropLines`'s `x` is where along the graph they are.
|
|
106
|
+
Outside a system a graph unit is a pixel and a plot draws nothing.
|
|
107
|
+
- **Riding a plot.** A `plotPoint`, `tangentLine` or `dropLines` inside a
|
|
108
|
+
`functionPlot` follows that plot, appears, moves and leaves with it, and is
|
|
109
|
+
drawn over the curve: a mark's stroke is its ink, painted before its children
|
|
110
|
+
rather than last as a shape's outline is (a `Mark` that strokes its ink its
|
|
111
|
+
own way overrides `renderInk`, not `renderStroke`). In the system instead, a
|
|
112
|
+
point or guide names a plot by id in `on`, or none and is free. `curveArea`
|
|
113
|
+
and `riemannSum` sit in the system beside the plots they read and name one in
|
|
114
|
+
`on` (an area a second in `under`). A point that rides a plot
|
|
115
|
+
takes its height from the curve and keeps its own `y` only where the curve has
|
|
116
|
+
no value.
|
|
117
|
+
- **One value drives a scene through a variable.** Bind any graph prop with
|
|
118
|
+
`"=[t]"` and animate `t` with `variableTo`; a formula may sit at any depth, so
|
|
119
|
+
a `pointsPlot` corner can be `{ x: '=[t]', y: '=25/[t]' }`. `plotPoint.value`
|
|
120
|
+
and `tangentLine.slope` can be read back as `[key.value]` and `[key.slope]`.
|
|
121
|
+
- **A system's `stroke` is its axis line and its `fill` its backdrop.** So
|
|
122
|
+
`stroke.endCap` is the axis tip. Ticks, grid lines and numbers are drawn by the
|
|
123
|
+
system itself; they are not child nodes. Drawn on with `progressTo`, the ticks
|
|
124
|
+
and numbers appear as the line reaches them.
|
|
125
|
+
- **Numbers need a font.** A system's `fontFamily` is empty by default, which
|
|
126
|
+
takes the scene's default text style; a scene with none has to set it, as any
|
|
127
|
+
text does.
|
|
128
|
+
- **An axis crosses the other at its zero**, or at the nearest edge when zero is
|
|
129
|
+
out of range or the other axis is logarithmic. A `step` of `0` picks a tidy
|
|
130
|
+
spacing for the axis's length; a log axis is marked at the powers of ten.
|
|
131
|
+
|
|
132
|
+
## 3D graphs
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
nodes: [
|
|
136
|
+
{ id: 'axes', type: 'axes3d', parentId: null, layerOrder: 0, props: { width: 960, height: 540, labels: true, fontFamily: 'Inter' } },
|
|
137
|
+
{ id: 'bump', type: 'surfacePlot3d', parentId: 'axes', layerOrder: 0,
|
|
138
|
+
props: { expression: '1.8 exp(-(x^2 + y^2) / 2)', colorScale: ['#1d4ed8', '#22c55e', '#facc15', '#ef4444'] } },
|
|
139
|
+
{ id: 'dot', type: 'plotPoint3d', parentId: 'bump', layerOrder: 0, props: { x: 0.8, y: -0.6, label: 'P' } },
|
|
140
|
+
],
|
|
141
|
+
commands: [
|
|
142
|
+
{ id: 'a', type: 'orbitTo', targetId: 'axes', at: 0, duration: 2, args: { orbit: 80, elevation: 32 } },
|
|
143
|
+
{ id: 'b', type: 'morphTo', targetId: 'bump', at: 2, duration: 1, args: { expression: '(x^2 - y^2) / 5' } },
|
|
144
|
+
],
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
- **A 3D graph is right-handed with z up.** The scene has y up, so graph x, y and
|
|
148
|
+
z run along the scene's z, x and y: seen head-on, y is to the right and z is
|
|
149
|
+
up, and the axes' default camera shows x coming toward the viewer.
|
|
150
|
+
- **An `axes3d` is its own viewport.** It is a `canvas3d` (camera, lights,
|
|
151
|
+
`orbitTo`, a box on the stage), so it needs no canvas around it and cannot go
|
|
152
|
+
inside one; a 3D shape you want beside the graph goes inside it instead.
|
|
153
|
+
- **The axes are a box, `xLength` by `yLength` by `zLength` scene units, centred
|
|
154
|
+
in the scene**, showing the three ranges. An axis crosses the others at their
|
|
155
|
+
zero, or at the nearest end of a range without one.
|
|
156
|
+
- **A child's `x`/`y`/`z` are graph units, whatever the child is**, and it keeps
|
|
157
|
+
its own size and turn: a `sphere3d` at `x: 1, y: 2, z: 0.5` sits at that graph
|
|
158
|
+
point, the built-in `moveTo` moves it in graph units, and `rangeTo` carries it.
|
|
159
|
+
- **A surface is held inside the axes.** A height that leaves the z range is
|
|
160
|
+
drawn at its edge, and one with no value is drawn flat, so a pole does not tear
|
|
161
|
+
the mesh. Left out, `uDomain` and `vDomain` are the axes' x and y ranges for a
|
|
162
|
+
height and 0 to 1 for a parametric surface.
|
|
163
|
+
- **`colorScale` colours a surface by height** over the axes' z range, lowest
|
|
164
|
+
first; without one it is painted in its `fill`. `meshLines` rules it each way.
|
|
165
|
+
- **A surface takes the mesh material props** (`opacity`, `roughness`, `wireframe`,
|
|
166
|
+
…) and is lit by the axes' lights; it is drawn from both sides.
|
|
167
|
+
- **Lines are tubes and labels are cards.** A `curvePlot3d`'s and an axis's
|
|
168
|
+
`thickness`, a point's `radius` and a label's `labelSize` are scene units, so
|
|
169
|
+
they keep their size when a range changes. A label always faces the camera.
|
|
170
|
+
- **Moving the camera** is the canvas's `orbitTo({ orbit, elevation, zoom })`, or a
|
|
171
|
+
`camera3d`'s `orbitTo` and `lookTo` when the scene has one.
|
|
172
|
+
|
|
173
|
+
| Written as | Is | Variables |
|
|
174
|
+
| --- | --- | --- |
|
|
175
|
+
| `sin(x) * cos(y)`, `z = x^2 - y^2` | a surface, as a height | `x`, `y` |
|
|
176
|
+
| `(cos(u) sin(v), sin(u) sin(v), cos(v))` | a parametric surface | `u`, `v` |
|
|
177
|
+
| `(cos(t), sin(t), t / 4)` | a space curve | `t` |
|
|
178
|
+
|
|
179
|
+
Any other name is a named value, as in a 2D plot (`surfaceParams`,
|
|
180
|
+
`spaceCurveParams`); `surfaceError` and `spaceCurveError` say why text will not draw.
|
|
181
|
+
|
|
182
|
+
## Equations
|
|
183
|
+
|
|
184
|
+
A `functionPlot`'s `expression` is read the way it is written:
|
|
185
|
+
|
|
186
|
+
| Written as | Is | Free variable, `domain` when not given |
|
|
187
|
+
| --- | --- | --- |
|
|
188
|
+
| `sin(x)`, `y = sin(x)` | a function of `x` | `x`, the system's width |
|
|
189
|
+
| `x = y^2` | a function of `y` | `y`, the system's height |
|
|
190
|
+
| `r = 1 + cos(theta)` | polar | `theta`, one turn |
|
|
191
|
+
| `(cos(t), sin(t))` | parametric | `t`, 0 to 1 |
|
|
192
|
+
| `x^2 + y^2 = 4` | implicit | drawn where it holds, over what the system shows |
|
|
193
|
+
|
|
194
|
+
- **The language is the engine's expression grammar under its own dialect**:
|
|
195
|
+
bare names, trig in radians, `ln`, `log2`, `log10`, the hyperbolics, and the
|
|
196
|
+
constants `pi`, `e`, `tau`, `phi`. Implicit multiplication (`2x`, `2(x + 1)`)
|
|
197
|
+
and `^` work as in a document formula. It never evaluates text as code.
|
|
198
|
+
- **A name the equation does not know is a named value**, held in `params`:
|
|
199
|
+
`{ expression: 'a * sin(k * x)', params: { a: 2, k: '=[speed]' } }`. One left
|
|
200
|
+
unset is 1, so an equation draws as soon as it is written; `equationParams(source)`
|
|
201
|
+
lists them for a host that draws a field for each. `paramsTo` animates them.
|
|
202
|
+
- **`morphTo` bends one curve into another**, of any kind into any kind: the two
|
|
203
|
+
are blended point for point along their parameters.
|
|
204
|
+
- **Text that is not an equation draws nothing** and throws nothing, so a host can
|
|
205
|
+
commit on every keystroke; `equationError(source)` gives the reason.
|
|
206
|
+
- **A curve is sampled adaptively** and broken at an asymptote or the edge of its
|
|
207
|
+
domain, so `1/x`, `tan(x)` and `sqrt(x)` draw as they should.
|
|
208
|
+
|
|
209
|
+
## Planes, fields and trails
|
|
210
|
+
|
|
211
|
+
- **A number plane can be transformed.** `matrix` (`[[a, b], [c, d]]`, or flat)
|
|
212
|
+
sends every point of the plane through a linear map about its origin, and
|
|
213
|
+
`warp` (two parts in x and y, `(x + sin(y), y + sin(x))`) bends it by a
|
|
214
|
+
function of its own points. The grid, the axes and everything on the plane go
|
|
215
|
+
with it: a child's position, a plot's curve, a vector's ends. `transformTo`
|
|
216
|
+
and `warpTo` animate them, each point travelling straight to where it ends up,
|
|
217
|
+
and `warpTo({ warp: "" })` flattens the plane again. While it is transformed
|
|
218
|
+
the plane leaves its flat self behind, faintly (`ghost`). The grid is ruled
|
|
219
|
+
over whatever of the plane then falls in the box, up to four times its own
|
|
220
|
+
ranges, so it stays full under a turn, a shear or a fourfold shrink, and a
|
|
221
|
+
plane squeezed onto a line folds its grid into a narrowing band.
|
|
222
|
+
- **A polar plane is a plane with another ruling.** Its children are still at x
|
|
223
|
+
and y, in the units its rings count, so `r = 1 + cos(theta)` in a
|
|
224
|
+
`functionPlot`, a point or an arrow goes on it as on axes. `radius` is its
|
|
225
|
+
outer ring, `spokes` how many divide the turn, and `angleUnit` writes them in
|
|
226
|
+
degrees or as fractions of π.
|
|
227
|
+
- **An implicit equation is drawn where it holds.** `x^2 + y^2 = 4` in a
|
|
228
|
+
`functionPlot` is traced over what the system shows. It has no parameter to
|
|
229
|
+
bend along, so a morph to or from one changes over half way.
|
|
230
|
+
- **A field is two parts in x and y**, `(-y, x)`. A `vectorField` centres an
|
|
231
|
+
arrow on each point of a grid `spacing` apart, as long as the field is strong
|
|
232
|
+
there times `arrowScale` and never longer than the spacing; a `streamLines`
|
|
233
|
+
follows the field from each of those points for `length` graph units. With a
|
|
234
|
+
list of `strengthFills` both are painted by the field's strength, weakest
|
|
235
|
+
first; without one, in the stroke's own paint.
|
|
236
|
+
`streamLines.window` shows a stretch of each line and `flowTo({ phase })` sends
|
|
237
|
+
the stretches along: one whole turn of `phase` runs every line end to end.
|
|
238
|
+
- **A traced path is a plot whose end follows a value.** It draws its equation
|
|
239
|
+
from `from` to `value`; bind `value` to a variable (`"=[t]"`) and the trail
|
|
240
|
+
grows as the variable is driven, or drive it with `traceTo({ value })`. `tail`
|
|
241
|
+
keeps only its most recent stretch.
|
|
242
|
+
|
|
243
|
+
## Graphs and sample spaces
|
|
244
|
+
|
|
245
|
+
- **A network graph is its `vertices` (names) and `edges` (`{ from, to }`, or
|
|
246
|
+
pairs).** Its `fill` paints the vertices and its `stroke` the edges; with
|
|
247
|
+
`directed` each edge ends in an arrowhead, and an edge each way between two
|
|
248
|
+
vertices bows apart. Labels are the vertices' names.
|
|
249
|
+
- **`arrangement` places the vertices**: `circular` (the first at the top,
|
|
250
|
+
clockwise), `spring` (edges pull, every pair pushes; the same every time),
|
|
251
|
+
`tree` (levels down from `root`, a parent over its children), `grid`. A vertex
|
|
252
|
+
in `positions` is placed by hand, from -1 to 1 each way. `arrangeTo` moves every
|
|
253
|
+
vertex to where another arrangement puts it. (`layout` is every node's own box,
|
|
254
|
+
hence the other word.)
|
|
255
|
+
- **`partFillTo({ part, fill })` paints a vertex by its name, or an edge written
|
|
256
|
+
`a-b`**, arriving over the graph's own paint, as a formula's parts are painted;
|
|
257
|
+
`partFills` holds them.
|
|
258
|
+
- **A sample space's `columnShares` cut it across** (any numbers, read as shares
|
|
259
|
+
of their sum) **and each column's entry in `rowShares` cuts that column**
|
|
260
|
+
(its upper share, 0 to 1), so each part's area is its probability. Braces name
|
|
261
|
+
the columns below (`columnLabels`) and the rows on the left (`rowLabels`);
|
|
262
|
+
`values` writes each part's probability in it; `divideTo` moves the cuts.
|
|
263
|
+
|
|
264
|
+
## Annotations
|
|
265
|
+
|
|
266
|
+
`curlyBrace`, `emphasisMark` (box, circle, underline, cross) and `angleMark`
|
|
267
|
+
work anywhere, not only on a graph. A brace or an emphasis mark names a node
|
|
268
|
+
in `on`, and optionally one `part` of a formula, and is drawn on it wherever
|
|
269
|
+
the two are in the tree; `retargetTo` slides it to another. A brace with no
|
|
270
|
+
`on` spans `tail` to `head`. An angle mark sits at its own position and sweeps
|
|
271
|
+
`fromAngle` to `toAngle` in degrees, so binding one to a variable opens it.
|
|
272
|
+
A label written between dollar signs is typeset, on these and on a plot point
|
|
273
|
+
or an axis. `FollowMark` and `quadOf` in `@motionscript/math/kit` are what a
|
|
274
|
+
custom mark of this kind is built on.
|
|
275
|
+
|
|
276
|
+
## Latex
|
|
277
|
+
|
|
278
|
+
The formulas below were published as `@motionscript/latex` up to
|
|
279
|
+
`0.1.0-alpha.3`; that package is no longer updated, and the same node, key and
|
|
280
|
+
exports are here.
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
import type { CompositionDocument } from '@motionscript/sdk';
|
|
284
|
+
|
|
285
|
+
export default {
|
|
286
|
+
kind: 'composition',
|
|
287
|
+
nodes: [
|
|
288
|
+
{ id: 'eq', type: 'latex', parentId: null, layerOrder: 0,
|
|
289
|
+
props: { latex: 'a^2 + b^2 = c^2', fontSize: 64, fill: 'white' } },
|
|
290
|
+
],
|
|
291
|
+
commands: [
|
|
292
|
+
{ id: 'solve', type: 'morphTo', targetId: 'eq', at: 0, duration: 1.2,
|
|
293
|
+
args: { latex: 'c = \\sqrt{a^2 + b^2}' } },
|
|
294
|
+
],
|
|
295
|
+
} satisfies CompositionDocument;
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
- **`Latex`** node, a `ShapeNode` that draws a formula as fillable, strokable
|
|
299
|
+
glyph paths. Set `latex` to the TeX source and `fontSize` to scale it; `fill`,
|
|
300
|
+
`stroke`, `shadow`, and `padding` work like any other shape.
|
|
301
|
+
- **Formula morphing**: `morphTo` (or a `to` on `latex` or `fontSize`) interpolates each
|
|
302
|
+
glyph between the current and target formula, matching tokens that persist,
|
|
303
|
+
fading out tokens that leave, and fading in tokens that arrive. A persisting
|
|
304
|
+
glyph is carried by its geometry, so one that changes size on the way — the
|
|
305
|
+
`2` of `b^2` becoming the `2` of `2a`, or a symbol dropping into a `\frac` —
|
|
306
|
+
grows or shrinks across the transition instead of snapping. The hugging box
|
|
307
|
+
resizes smoothly along with it.
|
|
308
|
+
- **Parts**: every piece of the source is a part, named by that source
|
|
309
|
+
(`a^2`, `\frac{d}{dx}`, or neighbours that spell it together). `partFills`
|
|
310
|
+
and `partFillTo` paint one with any paint, `partBounds(part)` says where it is,
|
|
311
|
+
and a morph carries a term both formulas write as one, with its fill.
|
|
312
|
+
- **`written`** writes the formula on glyph by glyph, each outlined and then
|
|
313
|
+
filled; `writeTo` animates it. It is how a formula appears, so a formula has
|
|
314
|
+
no outline trim (`start`, `end`, `progressTo`, `flash`).
|
|
315
|
+
- **`latexMatrix`** typesets `entries` in the `brackets` it is given. Each entry
|
|
316
|
+
is a part; `entriesTo` morphs to new ones.
|
|
317
|
+
- **`buildLatexPath(latex, fontSize)`**, the underlying helper that turns TeX
|
|
318
|
+
into positioned `LatexToken` glyph paths plus intrinsic size and bounds, for
|
|
319
|
+
callers that want the geometry directly.
|
|
320
|
+
|
|
321
|
+
TeX is parsed through MathJax with the `base`, `ams`, `boldsymbol`,
|
|
322
|
+
`newcommand`, `cancel`, `color`, `mhchem`, `physics`, `bbox`, and `mathtools`
|
|
323
|
+
packages enabled. Rendering is synchronous and browser-only.
|
|
324
|
+
|
|
325
|
+
A formula MathJax cannot typeset (`\frac{a`, `\fra`, a stray `{`, or `\require`,
|
|
326
|
+
since only the packages above are loaded) throws a `LatexError` from
|
|
327
|
+
`buildLatexPath`, from a `Latex` node that holds it and from a `to` that targets
|
|
328
|
+
it. The error carries the `latex` source and MathJax's `reason`. It is the same
|
|
329
|
+
in a browser and in Node; nothing is drawn in place of the formula.
|
|
330
|
+
|
|
331
|
+
This package is written against [`@motionscript/sdk`](https://github.com/motionscript-dev/motionscript/tree/main/packages/sdk), which it
|
|
332
|
+
takes as a peer dependency, and renders through whatever backend draws the
|
|
333
|
+
scene, such as [`@motionscript/browser`](https://github.com/motionscript-dev/motionscript/tree/main/packages/browser).
|
|
334
|
+
|
|
335
|
+
## Morphing, fills and what the host supplies
|
|
336
|
+
|
|
337
|
+
- **`morphTo({ latex })` is the document command, and every `to` is a morph.**
|
|
338
|
+
`Latex` overrides `to`, so a `to` that names only `fontSize` or `fill` goes
|
|
339
|
+
through the same path as one that names `latex`. A morph reads its from-state on
|
|
340
|
+
its **first evaluation**, not when the command is built, so two morphs in
|
|
341
|
+
sequence start the second from the first's end.
|
|
342
|
+
- **Glyphs match by key.** A token's key is the character its MathJax glyph id
|
|
343
|
+
decodes to (a mathematical italic `𝑥` is not `x`); a rule or fraction bar is
|
|
344
|
+
`__rect_N` and a bare path `__path_N`, and those never match. `defaultLatexMorph`
|
|
345
|
+
pairs keys greedily in order, fades deleted tokens over the first half and added
|
|
346
|
+
ones over the second. A custom `morph` (`LatexStrategies`, a constructor option,
|
|
347
|
+
not a prop, so a document cannot set it) replaces all of it, including paint order.
|
|
348
|
+
- **A `latex` row needs a `fill` or a `stroke` to draw anything**; `fill` defaults
|
|
349
|
+
to none. The formula is typeset in display style, so double each backslash inside
|
|
350
|
+
a JSON string.
|
|
351
|
+
- **MathJax loads only for a scene that typesets.** It and its default font,
|
|
352
|
+
including the `\mathbb`, `\mathcal`, `\mathfrak`, `\mathscr`, `\mathsf` and
|
|
353
|
+
`\mathtt` ranges, are bundled in a module of their own that `loadMathJax()`
|
|
354
|
+
imports once. A `latex` or `latexMatrix`, and a graph, a point, a brace or an
|
|
355
|
+
angle whose label is written between dollar signs, declares the
|
|
356
|
+
`math:mathjax` loader (`MATHJAX_LOADER`), which the host waits for before
|
|
357
|
+
layout; a scene with no formula never loads it. Until it is there a formula
|
|
358
|
+
draws nothing and is asked again. Code that typesets outside a scene (a tool, a
|
|
359
|
+
test) awaits `loadMathJax()` first: `buildLatexPath` throws `LatexNotLoaded`
|
|
360
|
+
before then, and `latexPartNames` answers with nothing.
|
|
361
|
+
- **Module state is shared per process**: one MathJax document, and two LRU memos
|
|
362
|
+
(typeset geometry by formula, 128 entries; paths by size and formula, 64).
|
|
363
|
+
Importing the module registers MathJax's HTML handler, with the DOM-free adaptor
|
|
364
|
+
when there is no `window` or `document`.
|
|
365
|
+
- **`ms add latex` copies only `tex/node.ts`** (`registry.json`); typesetting and the
|
|
366
|
+
morph stay in this package behind `src/engine.ts`.
|
|
367
|
+
|
|
368
|
+
## Usage
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
npm install @motionscript/math @motionscript/sdk
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Or copy the node's source into your project with `ms add latex`
|
|
375
|
+
(see [`@motionscript/cli`](https://github.com/motionscript-dev/motionscript/tree/main/packages/cli)). See the [docs](https://motionscript.dev/docs) for the full feature set and API
|
|
376
|
+
reference.
|
|
377
|
+
|
|
378
|
+
## Development
|
|
379
|
+
|
|
380
|
+
From the monorepo root:
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
pnpm --filter @motionscript/math build
|
|
384
|
+
pnpm --filter @motionscript/math test
|
|
385
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Graphics2D, PaintNode, type AssetScope, type BoxBounds, type Color, type Command, type CommandArgs, type NodeConfig, type PaintProps, type RenderContext2D, type Size2D, type Stroke } from "@motionscript/sdk";
|
|
2
|
+
export interface AngleMarkProps extends PaintProps {
|
|
3
|
+
fromAngle?: number;
|
|
4
|
+
toAngle?: number;
|
|
5
|
+
radius?: number;
|
|
6
|
+
corner?: "arc" | "square" | "auto";
|
|
7
|
+
label?: string;
|
|
8
|
+
labelSize?: number;
|
|
9
|
+
labelColor?: Color;
|
|
10
|
+
fontFamily?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The mark of an angle at the node's own position: an arc from one direction
|
|
14
|
+
* to another, or the small square of a right angle, with an optional label.
|
|
15
|
+
* Directions are degrees counter-clockwise from the right, so binding one to a
|
|
16
|
+
* variable opens and closes the angle. A label of `°` shows the angle's size.
|
|
17
|
+
*/
|
|
18
|
+
export declare class AngleMark extends PaintNode<AngleMarkProps> {
|
|
19
|
+
fromAngle: number;
|
|
20
|
+
toAngle: number;
|
|
21
|
+
radius: number;
|
|
22
|
+
/** `auto` draws the square where the angle is a right one. */
|
|
23
|
+
corner: "arc" | "square" | "auto";
|
|
24
|
+
/** Text, a formula between dollar signs, or `°` for the angle's own size. */
|
|
25
|
+
label: string;
|
|
26
|
+
labelSize: number;
|
|
27
|
+
labelColor: Color;
|
|
28
|
+
fontFamily: string;
|
|
29
|
+
stroke: Stroke;
|
|
30
|
+
constructor(props?: NodeConfig<AngleMark, AngleMarkProps>);
|
|
31
|
+
/** Grow or shrink the mark. */
|
|
32
|
+
radiusTo(args: CommandArgs<{
|
|
33
|
+
radius: number;
|
|
34
|
+
}> & {
|
|
35
|
+
duration: number;
|
|
36
|
+
}): Command<AngleMarkProps>;
|
|
37
|
+
/** The angle marked, in degrees: positive counter-clockwise. */
|
|
38
|
+
get value(): number;
|
|
39
|
+
declareAssets(assets: AssetScope): void;
|
|
40
|
+
measure(): Partial<Size2D>;
|
|
41
|
+
protected shapeGraphics(): Graphics2D | null;
|
|
42
|
+
protected renderSelf(ctx: RenderContext2D): void;
|
|
43
|
+
_localBounds(): BoxBounds;
|
|
44
|
+
private _outline;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=angle-mark.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angle-mark.d.ts","sourceRoot":"","sources":["../../src/annotate/angle-mark.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,UAAU,EAEV,SAAS,EAKT,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,UAAU,EAEf,KAAK,UAAU,EAEf,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,MAAM,EACd,MAAM,mBAAmB,CAAC;AAK3B,MAAM,WAAW,cAAe,SAAQ,UAAU;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAaD;;;;;GAKG;AACH,qBAOa,SAAU,SAAQ,SAAS,CAAC,cAAc,CAAC;IACP,SAAS,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IACP,MAAM,EAAE,MAAM,CAAC;IACtE,8DAA8D;IACgC,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IAEhI,6EAA6E;IACvB,KAAK,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,KAAK,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IAGjE,MAAM,EAAE,MAAM,CAAC;gBAEX,KAAK,CAAC,EAAE,UAAU,CAAC,SAAS,EAAE,cAAc,CAAC;IAIzD,+BAA+B;IAE/B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAI/F,gEAAgE;IAChE,IAAI,KAAK,IAAI,MAAM,CAElB;IAEQ,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAMvC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;cAIhB,aAAa,IAAI,UAAU,GAAG,IAAI;cAKlC,UAAU,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;IAShD,YAAY,IAAI,SAAS;IAMlC,OAAO,CAAC,QAAQ;CAuBnB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { colorProperty, command, Graphics2D, node, PaintNode, pathOps, property, strokeProperty, withdraw, } from "@motionscript/sdk";
|
|
8
|
+
import { declareFormulas, drawLabels } from "../kit/furniture.js";
|
|
9
|
+
import { stated } from "../kit/geometry.js";
|
|
10
|
+
import { FILL_PAINT } from "../kit/withdrawn.js";
|
|
11
|
+
const OWN_FRAME = [-1, -1, 1, 1];
|
|
12
|
+
/** Degrees of arc per drawn segment. */
|
|
13
|
+
const ARC_STEP = 4;
|
|
14
|
+
/** How close to a right angle `auto` draws the square. */
|
|
15
|
+
const RIGHT_SLOP = 0.5;
|
|
16
|
+
const point = (radius, degrees) => {
|
|
17
|
+
const turn = (degrees * Math.PI) / 180;
|
|
18
|
+
return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The mark of an angle at the node's own position: an arc from one direction
|
|
22
|
+
* to another, or the small square of a right angle, with an optional label.
|
|
23
|
+
* Directions are degrees counter-clockwise from the right, so binding one to a
|
|
24
|
+
* variable opens and closes the angle. A label of `°` shows the angle's size.
|
|
25
|
+
*/
|
|
26
|
+
let AngleMark = class AngleMark extends PaintNode {
|
|
27
|
+
constructor(props) {
|
|
28
|
+
super(props ?? {});
|
|
29
|
+
}
|
|
30
|
+
/** Grow or shrink the mark. */
|
|
31
|
+
radiusTo(args) {
|
|
32
|
+
return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
|
|
33
|
+
}
|
|
34
|
+
/** The angle marked, in degrees: positive counter-clockwise. */
|
|
35
|
+
get value() {
|
|
36
|
+
return this.toAngle - this.fromAngle;
|
|
37
|
+
}
|
|
38
|
+
declareAssets(assets) {
|
|
39
|
+
super.declareAssets(assets);
|
|
40
|
+
if (this.label !== "" && this.fontFamily !== "")
|
|
41
|
+
assets.font(this.fontFamily);
|
|
42
|
+
declareFormulas(assets, [this.label]);
|
|
43
|
+
}
|
|
44
|
+
measure() {
|
|
45
|
+
return { width: 0, height: 0 };
|
|
46
|
+
}
|
|
47
|
+
shapeGraphics() {
|
|
48
|
+
const data = this._outline();
|
|
49
|
+
return data.length === 0 ? null : new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });
|
|
50
|
+
}
|
|
51
|
+
renderSelf(ctx) {
|
|
52
|
+
super.renderSelf(ctx);
|
|
53
|
+
if (this.label === "" || this.radius <= 0)
|
|
54
|
+
return;
|
|
55
|
+
const text = this.label === "°" ? `${Math.round(Math.abs(this.value) * 10) / 10}°` : this.label;
|
|
56
|
+
const at = point(this.radius + this.labelSize * 0.9, (this.fromAngle + this.toAngle) / 2);
|
|
57
|
+
const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor };
|
|
58
|
+
for (const part of drawLabels([{ text, at, align: "center" }], style))
|
|
59
|
+
ctx.draw(part);
|
|
60
|
+
}
|
|
61
|
+
_localBounds() {
|
|
62
|
+
const ink = pathOps.bounds(this._outline());
|
|
63
|
+
if (!ink)
|
|
64
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
65
|
+
return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };
|
|
66
|
+
}
|
|
67
|
+
_outline() {
|
|
68
|
+
const { fromAngle, toAngle, radius } = this;
|
|
69
|
+
const sweep = toAngle - fromAngle;
|
|
70
|
+
if (radius <= 0 || sweep === 0)
|
|
71
|
+
return [];
|
|
72
|
+
const square = this.corner === "square" || (this.corner === "auto" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);
|
|
73
|
+
if (square) {
|
|
74
|
+
const side = radius * 0.6;
|
|
75
|
+
const a = point(side, fromAngle);
|
|
76
|
+
const b = point(side, toAngle);
|
|
77
|
+
return [
|
|
78
|
+
{ type: "M", x: a.x, y: a.y },
|
|
79
|
+
{ type: "L", x: a.x + b.x, y: a.y + b.y },
|
|
80
|
+
{ type: "L", x: b.x, y: b.y },
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));
|
|
84
|
+
const out = [];
|
|
85
|
+
for (let i = 0; i <= steps; i++) {
|
|
86
|
+
const p = point(radius, fromAngle + (sweep * i) / steps);
|
|
87
|
+
out.push({ type: i === 0 ? "M" : "L", x: p.x, y: p.y });
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
__decorate([
|
|
93
|
+
property({ default: 0, unit: "°" })
|
|
94
|
+
], AngleMark.prototype, "fromAngle", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
property({ default: 60, unit: "°" })
|
|
97
|
+
], AngleMark.prototype, "toAngle", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
property({ default: 48, min: 0, unit: "px" })
|
|
100
|
+
], AngleMark.prototype, "radius", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
property({ default: "auto", options: ["auto", "arc", "square"], animatable: false })
|
|
103
|
+
], AngleMark.prototype, "corner", void 0);
|
|
104
|
+
__decorate([
|
|
105
|
+
property({ default: "", animatable: false })
|
|
106
|
+
], AngleMark.prototype, "label", void 0);
|
|
107
|
+
__decorate([
|
|
108
|
+
property({ default: 24, min: 1, unit: "px" })
|
|
109
|
+
], AngleMark.prototype, "labelSize", void 0);
|
|
110
|
+
__decorate([
|
|
111
|
+
colorProperty({ default: "#e5e7eb" })
|
|
112
|
+
], AngleMark.prototype, "labelColor", void 0);
|
|
113
|
+
__decorate([
|
|
114
|
+
property({ default: "", animatable: false })
|
|
115
|
+
], AngleMark.prototype, "fontFamily", void 0);
|
|
116
|
+
__decorate([
|
|
117
|
+
strokeProperty({ default: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" } })
|
|
118
|
+
], AngleMark.prototype, "stroke", void 0);
|
|
119
|
+
__decorate([
|
|
120
|
+
command({ args: ["radius"] })
|
|
121
|
+
], AngleMark.prototype, "radiusTo", null);
|
|
122
|
+
AngleMark = __decorate([
|
|
123
|
+
node({
|
|
124
|
+
key: "angleMark",
|
|
125
|
+
parentKey: "shape",
|
|
126
|
+
forkable: true,
|
|
127
|
+
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
128
|
+
}),
|
|
129
|
+
withdraw(...FILL_PAINT)
|
|
130
|
+
], AngleMark);
|
|
131
|
+
export { AngleMark };
|
|
132
|
+
//# sourceMappingURL=angle-mark.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angle-mark.js","sourceRoot":"","sources":["../../src/annotate/angle-mark.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,aAAa,EACb,OAAO,EACP,UAAU,EACV,IAAI,EACJ,SAAS,EACT,OAAO,EACP,QAAQ,EACR,cAAc,EACd,QAAQ,GAaX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAa9C,MAAM,SAAS,GAAqC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACnE,wCAAwC;AACxC,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,0DAA0D;AAC1D,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE;IAC9C,MAAM,IAAI,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;IACvC,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,G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2C;AAG1E;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;wCAAuB;AACb;IAAtD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;4CAA2B;AAC1B;IAA9C,aAAa,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;6CAA2B;AACX;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;6CAA4B;AAGjE;IADP,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC;yCACnF;AAQvB;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;yCAG7B;AAxBQ,SAAS;IAPrB,IAAI,CAAC;QACF,GAAG,EAAE,WAAW;QAChB,SAAS,EAAE,OAAO;QAClB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE;KAC9G,CAAC;IACD,QAAQ,CAAC,GAAG,UAAU,CAAC;GACX,SAAS,CAoFrB","sourcesContent":["import {\r\n colorProperty,\r\n command,\r\n Graphics2D,\r\n node,\r\n PaintNode,\r\n pathOps,\r\n property,\r\n strokeProperty,\r\n withdraw,\r\n type AssetScope,\r\n type BoxBounds,\r\n type Color,\r\n type Command,\r\n type CommandArgs,\r\n type NodeConfig,\r\n type NormalizedColor,\r\n type PaintProps,\r\n type PathCommand,\r\n type RenderContext2D,\r\n type Size2D,\r\n type Stroke,\r\n} from \"@motionscript/sdk\";\r\nimport { declareFormulas, drawLabels } from \"../kit/furniture\";\r\nimport { stated } from \"../kit/geometry\";\r\nimport { FILL_PAINT } from \"../kit/withdrawn\";\r\n\r\nexport interface AngleMarkProps extends PaintProps {\r\n fromAngle?: number;\r\n toAngle?: number;\r\n radius?: number;\r\n corner?: \"arc\" | \"square\" | \"auto\";\r\n label?: string;\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n}\r\n\r\nconst OWN_FRAME: [number, number, number, number] = [-1, -1, 1, 1];\r\n/** Degrees of arc per drawn segment. */\r\nconst ARC_STEP = 4;\r\n/** How close to a right angle `auto` draws the square. */\r\nconst RIGHT_SLOP = 0.5;\r\n\r\nconst point = (radius: number, degrees: number) => {\r\n const turn = (degrees * Math.PI) / 180;\r\n return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };\r\n};\r\n\r\n/**\r\n * The mark of an angle at the node's own position: an arc from one direction\r\n * to another, or the small square of a right angle, with an optional label.\r\n * Directions are degrees counter-clockwise from the right, so binding one to a\r\n * variable opens and closes the angle. A label of `°` shows the angle's size.\r\n */\r\n@node({\r\n key: \"angleMark\",\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n})\r\n@withdraw(...FILL_PAINT)\r\nexport class AngleMark extends PaintNode<AngleMarkProps> {\r\n @property({ default: 0, unit: \"°\" }) declare fromAngle: number;\r\n @property({ default: 60, unit: \"°\" }) declare toAngle: number;\r\n @property({ default: 48, min: 0, unit: \"px\" }) declare radius: number;\r\n /** `auto` draws the square where the angle is a right one. */\r\n @property({ default: \"auto\", options: [\"auto\", \"arc\", \"square\"], animatable: false }) declare corner: \"arc\" | \"square\" | \"auto\";\r\n\r\n /** Text, a formula between dollar signs, or `°` for the angle's own size. */\r\n @property({ default: \"\", animatable: false }) declare label: string;\r\n @property({ default: 24, min: 1, unit: \"px\" }) declare labelSize: number;\r\n @colorProperty({ default: \"#e5e7eb\" }) declare labelColor: Color;\r\n @property({ default: \"\", animatable: false }) declare fontFamily: string;\r\n\r\n @strokeProperty({ default: { weight: 3, fill: \"#e5e7eb\", align: \"center\", cap: \"round\", join: \"round\" } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<AngleMark, AngleMarkProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** Grow or shrink the mark. */\r\n @command({ args: [\"radius\"] })\r\n radiusTo(args: CommandArgs<{ radius: number }> & { duration: number }): Command<AngleMarkProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** The angle marked, in degrees: positive counter-clockwise. */\r\n get value(): number {\r\n return this.toAngle - this.fromAngle;\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n if (this.label !== \"\" && this.fontFamily !== \"\") assets.font(this.fontFamily);\r\n declareFormulas(assets, [this.label]);\r\n }\r\n\r\n override measure(): Partial<Size2D> {\r\n return { width: 0, height: 0 };\r\n }\r\n\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const data = this._outline();\r\n return data.length === 0 ? null : new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });\r\n }\r\n\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n super.renderSelf(ctx);\r\n if (this.label === \"\" || this.radius <= 0) return;\r\n const text = this.label === \"°\" ? `${Math.round(Math.abs(this.value) * 10) / 10}°` : this.label;\r\n const at = point(this.radius + this.labelSize * 0.9, (this.fromAngle + this.toAngle) / 2);\r\n const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor };\r\n for (const part of drawLabels([{ text, at, align: \"center\" }], style)) ctx.draw(part);\r\n }\r\n\r\n override _localBounds(): BoxBounds {\r\n const ink = pathOps.bounds(this._outline());\r\n if (!ink) return { x: 0, y: 0, width: 0, height: 0 };\r\n return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };\r\n }\r\n\r\n private _outline(): PathCommand[] {\r\n const { fromAngle, toAngle, radius } = this;\r\n const sweep = toAngle - fromAngle;\r\n if (radius <= 0 || sweep === 0) return [];\r\n const square = this.corner === \"square\" || (this.corner === \"auto\" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);\r\n if (square) {\r\n const side = radius * 0.6;\r\n const a = point(side, fromAngle);\r\n const b = point(side, toAngle);\r\n return [\r\n { type: \"M\", x: a.x, y: a.y },\r\n { type: \"L\", x: a.x + b.x, y: a.y + b.y },\r\n { type: \"L\", x: b.x, y: b.y },\r\n ];\r\n }\r\n const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));\r\n const out: PathCommand[] = [];\r\n for (let i = 0; i <= steps; i++) {\r\n const p = point(radius, fromAngle + (sweep * i) / steps);\r\n out.push({ type: i === 0 ? \"M\" : \"L\", x: p.x, y: p.y });\r\n }\r\n return out;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type AssetScope, type Color, type NodeConfig, type NodeHandle, type PathCommand, type RenderContext2D, type Stroke, type Vector2 } from "@motionscript/sdk";
|
|
2
|
+
import { FollowMark, type FollowProps, type Quad } from "../kit/follow.js";
|
|
3
|
+
export type BraceSide = "below" | "above" | "left" | "right";
|
|
4
|
+
export interface CurlyBraceProps extends FollowProps {
|
|
5
|
+
side?: BraceSide;
|
|
6
|
+
tail?: Vector2;
|
|
7
|
+
head?: Vector2;
|
|
8
|
+
clearance?: number;
|
|
9
|
+
reach?: number;
|
|
10
|
+
label?: string;
|
|
11
|
+
labelSize?: number;
|
|
12
|
+
labelColor?: Color;
|
|
13
|
+
fontFamily?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A curly brace along one side of a node or of a part of a formula, or between
|
|
17
|
+
* two points when it names neither, with an optional label at its tip. A label
|
|
18
|
+
* written between dollar signs is typeset.
|
|
19
|
+
*/
|
|
20
|
+
export declare class CurlyBrace extends FollowMark<CurlyBraceProps> {
|
|
21
|
+
side: BraceSide;
|
|
22
|
+
/** The two ends of a brace that follows nothing, from the brace's own position. It bulges to the left of tail to head. */
|
|
23
|
+
tail: Vector2;
|
|
24
|
+
head: Vector2;
|
|
25
|
+
/** The room between the target and the brace. (`gap` is a layout's.) */
|
|
26
|
+
clearance: number;
|
|
27
|
+
/** How far the brace reaches from its ends to its tip. (`depth` is a node's place in 3D.) */
|
|
28
|
+
reach: number;
|
|
29
|
+
label: string;
|
|
30
|
+
labelSize: number;
|
|
31
|
+
labelColor: Color;
|
|
32
|
+
fontFamily: string;
|
|
33
|
+
stroke: Stroke;
|
|
34
|
+
constructor(props?: NodeConfig<CurlyBrace, CurlyBraceProps>);
|
|
35
|
+
declareAssets(assets: AssetScope): void;
|
|
36
|
+
protected quad(): Quad | null;
|
|
37
|
+
/** Whether the brace follows nothing, and so spans its own two points. */
|
|
38
|
+
private _spans;
|
|
39
|
+
protected outline(quad: Quad): PathCommand[];
|
|
40
|
+
protected renderSelf(ctx: RenderContext2D): void;
|
|
41
|
+
/** The edge the brace runs along, pushed out by the gap, and the way it bulges. */
|
|
42
|
+
private _span;
|
|
43
|
+
_handles(): readonly NodeHandle[];
|
|
44
|
+
_handleValue(prop: string, at: Vector2): Vector2 | null;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=curly-brace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curly-brace.d.ts","sourceRoot":"","sources":["../../src/annotate/curly-brace.ts"],"names":[],"mappings":"AAAA,OAAO,EAMH,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,UAAU,EAEf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,OAAO,EACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAA0B,UAAU,EAAW,KAAK,WAAW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