@motionscript/math 0.1.0-alpha.5 → 0.1.0-alpha.6
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 +22 -0
- package/README.md +39 -33
- package/dist/annotate/angle-mark.d.ts +52 -27
- package/dist/annotate/angle-mark.d.ts.map +1 -1
- package/dist/annotate/angle-mark.js +80 -115
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +59 -25
- package/dist/annotate/curly-brace.d.ts.map +1 -1
- package/dist/annotate/curly-brace.js +85 -100
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +43 -9
- package/dist/annotate/emphasis-mark.d.ts.map +1 -1
- package/dist/annotate/emphasis-mark.js +33 -34
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/chunk-ABYBW64J.js +2 -0
- package/dist/browser/chunks/chunk-ABYBW64J.js.map +7 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js +2 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/browser/tex.js.map +2 -2
- package/dist/engine.d.ts +26 -19
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +17 -14
- package/dist/engine.js.map +1 -1
- 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/curve.d.ts +22 -11
- package/dist/kit/curve.d.ts.map +1 -1
- package/dist/kit/curve.js +25 -18
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/field-mark.d.ts +58 -35
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js +100 -120
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/follow.d.ts +67 -29
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js +114 -110
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.d.ts +3 -1
- package/dist/kit/furniture.d.ts.map +1 -1
- package/dist/kit/furniture.js +5 -0
- package/dist/kit/furniture.js.map +1 -1
- 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 +64 -39
- package/dist/kit/mark.d.ts.map +1 -1
- package/dist/kit/mark.js +80 -96
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/place.d.ts +10 -8
- package/dist/kit/place.d.ts.map +1 -1
- package/dist/kit/place.js +28 -30
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/system.d.ts +27 -29
- package/dist/kit/system.d.ts.map +1 -1
- package/dist/kit/system.js +62 -58
- package/dist/kit/system.js.map +1 -1
- package/dist/kit/withdrawn.d.ts +3 -3
- package/dist/kit/withdrawn.js +3 -3
- package/dist/kit/withdrawn.js.map +1 -1
- package/dist/marks/curve-area.d.ts +24 -18
- package/dist/marks/curve-area.d.ts.map +1 -1
- package/dist/marks/curve-area.js +50 -73
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +28 -10
- package/dist/marks/drop-lines.d.ts.map +1 -1
- package/dist/marks/drop-lines.js +37 -52
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +37 -20
- package/dist/marks/plot-point.d.ts.map +1 -1
- package/dist/marks/plot-point.js +65 -91
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +30 -26
- package/dist/marks/riemann-sum.d.ts.map +1 -1
- package/dist/marks/riemann-sum.js +57 -85
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +38 -14
- package/dist/marks/tangent-line.d.ts.map +1 -1
- package/dist/marks/tangent-line.js +73 -87
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +30 -20
- package/dist/marks/vector-arrow.d.ts.map +1 -1
- package/dist/marks/vector-arrow.js +58 -78
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.d.ts +13 -5
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -6
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +107 -43
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js +146 -177
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.d.ts +34 -19
- package/dist/plots/points-plot.d.ts.map +1 -1
- package/dist/plots/points-plot.js +31 -58
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.d.ts +38 -19
- package/dist/plots/stream-lines.d.ts.map +1 -1
- package/dist/plots/stream-lines.js +60 -79
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.d.ts +34 -15
- package/dist/plots/traced-path.d.ts.map +1 -1
- package/dist/plots/traced-path.js +33 -48
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.d.ts +31 -11
- package/dist/plots/vector-field.d.ts.map +1 -1
- package/dist/plots/vector-field.js +50 -64
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/network-graph.d.ts +99 -49
- package/dist/structures/network-graph.d.ts.map +1 -1
- package/dist/structures/network-graph.js +168 -217
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.d.ts +69 -38
- package/dist/structures/sample-space.d.ts.map +1 -1
- package/dist/structures/sample-space.js +132 -170
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts +126 -37
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js +147 -183
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.d.ts +51 -28
- package/dist/systems/number-line.d.ts.map +1 -1
- package/dist/systems/number-line.js +82 -118
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.d.ts +92 -31
- package/dist/systems/number-plane.d.ts.map +1 -1
- package/dist/systems/number-plane.js +142 -149
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.d.ts +47 -26
- package/dist/systems/polar-plane.d.ts.map +1 -1
- package/dist/systems/polar-plane.js +107 -133
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/index.d.ts.map +1 -1
- package/dist/tex/index.js +1 -0
- package/dist/tex/index.js.map +1 -1
- package/dist/tex/matrix.d.ts +56 -18
- package/dist/tex/matrix.d.ts.map +1 -1
- package/dist/tex/matrix.js +33 -50
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/node.d.ts +55 -201
- package/dist/tex/node.d.ts.map +1 -1
- package/dist/tex/node.js +23 -593
- package/dist/tex/node.js.map +1 -1
- 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 +140 -54
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +159 -204
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +70 -42
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js +97 -132
- package/dist/three/curve-plot3d.js.map +1 -1
- 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/plot-point3d.d.ts +57 -12
- package/dist/three/plot-point3d.d.ts.map +1 -1
- package/dist/three/plot-point3d.js +27 -53
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.d.ts +17 -2
- package/dist/three/space.d.ts.map +1 -1
- package/dist/three/space.js +19 -8
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +131 -49
- package/dist/three/surface-plot3d.d.ts.map +1 -1
- package/dist/three/surface-plot3d.js +227 -261
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +58 -16
- package/dist/three/vector-arrow3d.d.ts.map +1 -1
- package/dist/three/vector-arrow3d.js +48 -67
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/src/annotate/angle-mark.ts +95 -105
- package/src/annotate/curly-brace.ts +107 -85
- package/src/annotate/emphasis-mark.ts +55 -26
- package/src/engine.ts +35 -21
- package/src/kit/component.ts +57 -0
- package/src/kit/curve.ts +38 -20
- package/src/kit/field-mark.ts +124 -108
- package/src/kit/follow.ts +146 -120
- package/src/kit/furniture.ts +6 -1
- package/src/kit/graph.ts +116 -0
- package/src/kit/mark.ts +135 -114
- package/src/kit/place.ts +32 -56
- package/src/kit/system.ts +77 -71
- package/src/kit/withdrawn.ts +3 -3
- package/src/marks/curve-area.ts +65 -65
- package/src/marks/drop-lines.ts +50 -42
- package/src/marks/plot-point.ts +77 -82
- package/src/marks/riemann-sum.ts +73 -72
- package/src/marks/tangent-line.ts +87 -71
- package/src/marks/vector-arrow.ts +73 -73
- package/src/nodes.ts +41 -5
- package/src/plots/function-plot.ts +155 -171
- package/src/plots/points-plot.ts +46 -50
- package/src/plots/stream-lines.ts +75 -66
- package/src/plots/traced-path.ts +51 -33
- package/src/plots/vector-field.ts +68 -49
- package/src/structures/network-graph.ts +168 -185
- package/src/structures/sample-space.ts +149 -148
- package/src/systems/axes2d.ts +165 -156
- package/src/systems/number-line.ts +91 -92
- package/src/systems/number-plane.ts +149 -120
- package/src/systems/polar-plane.ts +117 -116
- package/src/tex/index.ts +2 -1
- package/src/tex/matrix.ts +62 -40
- package/src/tex/node.ts +54 -621
- package/src/tex/typeset.ts +461 -0
- package/src/three/axes3d.ts +182 -161
- package/src/three/curve-plot3d.ts +107 -110
- package/src/three/entries.ts +42 -0
- package/src/three/plot-point3d.ts +42 -45
- package/src/three/space.ts +34 -9
- package/src/three/surface-plot3d.ts +312 -323
- package/src/three/vector-arrow3d.ts +65 -54
- package/dist/browser/chunks/chunk-3GJB6AVO.js +0 -2
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +0 -7
- package/dist/browser/chunks/chunk-D5WHCVBC.js +0 -2
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +0 -7
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +0 -2
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +0 -7
- package/src/kit/placement.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @motionscript/math
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.6
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 163b708: Node types are components: one spec object handed to `component2d`, `component3d` or `componentAudio`, with no classes, decorators or JSX.
|
|
8
|
+
|
|
9
|
+
- **Writing a node type.** A component is one object literal: `key`, `state` (literals and `Types`), `defaults`, `commands`, `children`, `allowedChildren`/`allowedParents`, `provide`, `load`, and its tree's own fields (`measure`, `layout`, `render` for 2D). Behaviour comes from modules you spread in and call: `Paint`, `Flow`, `Shapes`, `Typeface`, `TextLayout`, `Aim`, `Material`, `View3D`. ADR 0007 and the custom-node docs cover it.
|
|
10
|
+
- **Building nodes in code** uses calls: `Rect({ fill: 'tomato', children: [Text({ text: 'Hi' })] })`, or `new Rect({...})` for the node itself.
|
|
11
|
+
- **Every built-in and every kit node is a component**, under the same document key. Code that tested `instanceof` a class now uses the component's `.is`, or `instanceof X.node`. Changed members:
|
|
12
|
+
- `SurfacePlot3d.valueAt` and `FunctionPlot.valueAt` are now the functions `surfaceValueAt` and `curveValue`.
|
|
13
|
+
- A system's `coordinates` is replaced by `planeMap`/`axesMap`/`systemMap`.
|
|
14
|
+
- `PieChart.isSelected` is replaced by `isSliceSelected`.
|
|
15
|
+
- `ItemGrid` is a kit module (`ItemGrid.isGrid`, `ItemGrid.define`), not a base class.
|
|
16
|
+
- **The sdk no longer exports the class surface:**
|
|
17
|
+
- the decorators: `node`, `property` and every `*Property`, `command`, `withdraw`, `driveCommand`;
|
|
18
|
+
- the authoring bases: `PaintNode`, `ShapeNode`, `TextBase`, `Mesh3DBase`, `Canvas3DBase` and the `*Base` geometry classes;
|
|
19
|
+
- `asCommand`, `compose`, `drive` and `declarePaints` from `@motionscript/sdk/component`;
|
|
20
|
+
- the `jsx-runtime` and `jsx-dev-runtime` subpaths.
|
|
21
|
+
- `Node`, `Node2D`, `Node3D` and `NodeAudio` remain as types.
|
|
22
|
+
- **Editor metadata leaves the engine.** The kits no longer declare `parentKey`, `forkable`, `layout`, `seed`, `within`, `beside` or `closed`; a host keeps those in its own configs. `describe()` now reports `holds`, the trees a type takes children from, and the placement checks use it, so a 2D viewport of your own that takes 3D children places them.
|
|
23
|
+
- A command called from code with no argument runs, and a refused child is told what its parent takes (`allowedChildren`) or where it goes (`allowedParents`).
|
|
24
|
+
|
|
3
25
|
## 0.1.0-alpha.5
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ export const nodes = NODES;
|
|
|
18
18
|
|
|
19
19
|
| Entry | Holds |
|
|
20
20
|
| --- | --- |
|
|
21
|
-
| `@motionscript/math` | Every
|
|
22
|
-
| `@motionscript/math/kit` | What the nodes share and a copied node imports rather than copies: `
|
|
21
|
+
| `@motionscript/math` | Every component, `NODES`, and the kit below |
|
|
22
|
+
| `@motionscript/math/kit` | What the nodes share and a copied node imports rather than copies: the systems' and marks' helpers (`systemLayout`, `traced`, `drawMark`, the plane a system hands its marks), the coordinate map, the equation language, the sampler, and the LaTeX helpers |
|
|
23
23
|
| `@motionscript/math/tex` | The typeset-math half alone: `Latex`, `TEX_NODES` and its helpers |
|
|
24
24
|
|
|
25
25
|
## Nodes
|
|
@@ -57,16 +57,15 @@ Every node also has the shape commands (`moveTo`, `fadeTo`, `fillTo`,
|
|
|
57
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
58
|
| `sampleSpace` | A probability's whole cut into parts whose areas are their probabilities | anywhere | `divideTo({ columnShares, rowShares })` |
|
|
59
59
|
|
|
60
|
-
A system is a `numberLine`, an `axes2d`, a `numberPlane` or a `polarPlane`.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
checks it when a document builds: a plot outside a system builds and
|
|
64
|
-
nothing.
|
|
60
|
+
A system is a `numberLine`, an `axes2d`, a `numberPlane` or a `polarPlane`. The
|
|
61
|
+
Goes in column is where each node is made to go; offering it only there is the
|
|
62
|
+
host's to do, since the engine is told only a node's key, entries and commands.
|
|
63
|
+
Nothing checks it when a document builds: a plot outside a system builds and
|
|
64
|
+
draws nothing.
|
|
65
65
|
|
|
66
|
-
Each node takes only the paints it draws. A
|
|
67
|
-
trim
|
|
68
|
-
use for
|
|
69
|
-
writing it changes nothing: a plot, a tangent, an arrow or a brace is a line with
|
|
66
|
+
Each node takes only the paints it draws. A node spreads the shape paints
|
|
67
|
+
(`fill`, `stroke` and the outline trim `start`, `end`, `progressTo`, `flash`) it
|
|
68
|
+
has a use for and leaves the rest out, so they are not offered: a plot, a tangent, an arrow or a brace is a line with
|
|
70
69
|
no fill; an area is a fill with no outline; a field is one stroke for every arrow
|
|
71
70
|
or line; a formula and a traced path reveal themselves (`writeTo`, `traceTo`)
|
|
72
71
|
rather than by trimming; a dot, a sample space and a Riemann sum have nothing a
|
|
@@ -99,16 +98,16 @@ const document = {
|
|
|
99
98
|
size; `moveTo` moves it in graph units; a range tween carries it. On a
|
|
100
99
|
`numberLine`, `x` is a value on the line and `y` is pixels above it.
|
|
101
100
|
- **A mark is drawn through the system's map.** `functionPlot`, `pointsPlot`,
|
|
102
|
-
`vectorArrow`, `curveArea`, `riemannSum`, `tangentLine` and `dropLines`
|
|
103
|
-
`
|
|
101
|
+
`vectorArrow`, `curveArea`, `riemannSum`, `tangentLine` and `dropLines` are
|
|
102
|
+
marks (`traced`): their geometry is in graph coordinates and their box is the tight box of
|
|
104
103
|
their ink. A plot's or an arrow's own `x`/`y` shift it in graph units; a
|
|
105
104
|
`tangentLine`'s and a `dropLines`'s `x` is where along the graph they are.
|
|
106
105
|
Outside a system a graph unit is a pixel and a plot draws nothing.
|
|
107
106
|
- **Riding a plot.** A `plotPoint`, `tangentLine` or `dropLines` inside a
|
|
108
107
|
`functionPlot` follows that plot, appears, moves and leaves with it, and is
|
|
109
108
|
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 `
|
|
111
|
-
own way
|
|
109
|
+
rather than last as a shape's outline is (a mark drawn with `drawMark` that
|
|
110
|
+
strokes its ink its own way passes its own `ink`). In the system instead, a
|
|
112
111
|
point or guide names a plot by id in `on`, or none and is free. `curveArea`
|
|
113
112
|
and `riemannSum` sit in the system beside the plots they read and name one in
|
|
114
113
|
`on` (an area a second in `under`). A point that rides a plot
|
|
@@ -160,8 +159,11 @@ commands: [
|
|
|
160
159
|
drawn at its edge, and one with no value is drawn flat, so a pole does not tear
|
|
161
160
|
the mesh. Left out, `uDomain` and `vDomain` are the axes' x and y ranges for a
|
|
162
161
|
height and 0 to 1 for a parametric surface.
|
|
162
|
+
- **A point put inside a surface rides it**: its `x` and `y` say where, and its
|
|
163
|
+
height is the surface's, which `surfaceValueAt(surface, x, y)` reads.
|
|
163
164
|
- **`colorScale` colours a surface by height** over the axes' z range, lowest
|
|
164
|
-
first; without one it is painted in its `fill
|
|
165
|
+
first; without one it is painted in its `fill`, the plot blue unless given one
|
|
166
|
+
(a `curvePlot3d` too). `meshLines` rules it each way.
|
|
165
167
|
- **A surface takes the mesh material props** (`opacity`, `roughness`, `wireframe`,
|
|
166
168
|
…) and is lit by the axes' lights; it is drawn from both sides.
|
|
167
169
|
- **Lines are tubes and labels are cards.** A `curvePlot3d`'s and an axis's
|
|
@@ -251,7 +253,7 @@ A `functionPlot`'s `expression` is read the way it is written:
|
|
|
251
253
|
`tree` (levels down from `root`, a parent over its children), `grid`. A vertex
|
|
252
254
|
in `positions` is placed by hand, from -1 to 1 each way. `arrangeTo` moves every
|
|
253
255
|
vertex to where another arrangement puts it. (`layout` is every node's own box,
|
|
254
|
-
hence the other word.)
|
|
256
|
+
hence the other word.) `vertexPoints(graph, size)` says where each vertex is drawn.
|
|
255
257
|
- **`partFillTo({ part, fill })` paints a vertex by its name, or an edge written
|
|
256
258
|
`a-b`**, arriving over the graph's own paint, as a formula's parts are painted;
|
|
257
259
|
`partFills` holds them.
|
|
@@ -260,6 +262,7 @@ A `functionPlot`'s `expression` is read the way it is written:
|
|
|
260
262
|
(its upper share, 0 to 1), so each part's area is its probability. Braces name
|
|
261
263
|
the columns below (`columnLabels`) and the rows on the left (`rowLabels`);
|
|
262
264
|
`values` writes each part's probability in it; `divideTo` moves the cuts.
|
|
265
|
+
`sampleParts(space, size)` gives each part's box and probability.
|
|
263
266
|
|
|
264
267
|
## Annotations
|
|
265
268
|
|
|
@@ -270,8 +273,8 @@ the two are in the tree; `retargetTo` slides it to another. A brace with no
|
|
|
270
273
|
`on` spans `tail` to `head`. An angle mark sits at its own position and sweeps
|
|
271
274
|
`fromAngle` to `toAngle` in degrees, so binding one to a variable opens it.
|
|
272
275
|
A label written between dollar signs is typeset, on these and on a plot point
|
|
273
|
-
or an axis. `
|
|
274
|
-
custom mark of this kind is built on.
|
|
276
|
+
or an axis. `FOLLOW_STATE`, `FOLLOW_COMMANDS` and `followedQuad` in
|
|
277
|
+
`@motionscript/math/kit` are what a custom mark of this kind is built on.
|
|
275
278
|
|
|
276
279
|
## Latex
|
|
277
280
|
|
|
@@ -295,10 +298,10 @@ export default {
|
|
|
295
298
|
} satisfies CompositionDocument;
|
|
296
299
|
```
|
|
297
300
|
|
|
298
|
-
- **`Latex`** node, a
|
|
301
|
+
- **`Latex`** node, a component that draws a formula as fillable, strokable
|
|
299
302
|
glyph paths. Set `latex` to the TeX source and `fontSize` to scale it; `fill`,
|
|
300
303
|
`stroke`, `shadow`, and `padding` work like any other shape.
|
|
301
|
-
- **Formula morphing**: `morphTo` (or
|
|
304
|
+
- **Formula morphing**: `morphTo` (or any `to` that names `latex`) interpolates each
|
|
302
305
|
glyph between the current and target formula, matching tokens that persist,
|
|
303
306
|
fading out tokens that leave, and fading in tokens that arrive. A persisting
|
|
304
307
|
glyph is carried by its geometry, so one that changes size on the way — the
|
|
@@ -307,7 +310,7 @@ export default {
|
|
|
307
310
|
resizes smoothly along with it.
|
|
308
311
|
- **Parts**: every piece of the source is a part, named by that source
|
|
309
312
|
(`a^2`, `\frac{d}{dx}`, or neighbours that spell it together). `partFills`
|
|
310
|
-
and `partFillTo` paint one with any paint, `
|
|
313
|
+
and `partFillTo` paint one with any paint, `latexPartBounds(node, part)` says where it is,
|
|
311
314
|
and a morph carries a term both formulas write as one, with its fill.
|
|
312
315
|
- **`written`** writes the formula on glyph by glyph, each outlined and then
|
|
313
316
|
filled; `writeTo` animates it. It is how a formula appears, so a formula has
|
|
@@ -324,8 +327,8 @@ packages enabled. Rendering is synchronous and browser-only.
|
|
|
324
327
|
|
|
325
328
|
A formula MathJax cannot typeset (`\frac{a`, `\fra`, a stray `{`, or `\require`,
|
|
326
329
|
since only the packages above are loaded) throws a `LatexError` from
|
|
327
|
-
`buildLatexPath`, from a `Latex` node that holds it
|
|
328
|
-
|
|
330
|
+
`buildLatexPath`, and from a `Latex` node that holds it whenever it is laid out
|
|
331
|
+
(a document holding one fails to build). The error carries the `latex` source and MathJax's `reason`. It is the same
|
|
329
332
|
in a browser and in Node; nothing is drawn in place of the formula.
|
|
330
333
|
|
|
331
334
|
This package is written against [`@motionscript/sdk`](https://github.com/motionscript-dev/motionscript/tree/main/packages/sdk), which it
|
|
@@ -334,17 +337,20 @@ scene, such as [`@motionscript/browser`](https://github.com/motionscript-dev/mot
|
|
|
334
337
|
|
|
335
338
|
## Morphing, fills and what the host supplies
|
|
336
339
|
|
|
337
|
-
- **`morphTo({ latex })` is the document command, and every `to` is a morph.**
|
|
338
|
-
`
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
340
|
+
- **`morphTo({ latex })` is the document command, and every `to` of `latex` is a morph.**
|
|
341
|
+
Mid-tween `latex` (a matrix's `entries` and `brackets`) holds both ends, a
|
|
342
|
+
`Morph`, and the glyphs are drawn that far between them, so a seek to any time
|
|
343
|
+
draws the morph there. A `to` of `fontSize` alone sets the formula again at
|
|
344
|
+
each size. A morph reads its from-state on its **first evaluation**, not when
|
|
345
|
+
the command is built, so two morphs in sequence start the second from the
|
|
346
|
+
first's end.
|
|
342
347
|
- **Glyphs match by key.** A token's key is the character its MathJax glyph id
|
|
343
348
|
decodes to (a mathematical italic `𝑥` is not `x`); a rule or fraction bar is
|
|
344
349
|
`__rect_N` and a bare path `__path_N`, and those never match. `defaultLatexMorph`
|
|
345
350
|
pairs keys greedily in order, fades deleted tokens over the first half and added
|
|
346
|
-
ones over the second. A custom `morph` (`LatexStrategies
|
|
347
|
-
|
|
351
|
+
ones over the second. A custom `morph` (`LatexStrategies`) replaces it, for a
|
|
352
|
+
node built on the typeset helpers, which take it as an argument
|
|
353
|
+
(`formulaFrame(source, fontSize, partFills, morph)`); a document cannot set it.
|
|
348
354
|
- **A `latex` row needs a `fill` or a `stroke` to draw anything**; `fill` defaults
|
|
349
355
|
to none. The formula is typeset in display style, so double each backslash inside
|
|
350
356
|
a JSON string.
|
|
@@ -362,8 +368,8 @@ scene, such as [`@motionscript/browser`](https://github.com/motionscript-dev/mot
|
|
|
362
368
|
(typeset geometry by formula, 128 entries; paths by size and formula, 64).
|
|
363
369
|
Importing the module registers MathJax's HTML handler, with the DOM-free adaptor
|
|
364
370
|
when there is no `window` or `document`.
|
|
365
|
-
- **`ms add latex` copies only `tex/node.ts`** (`registry.json`); typesetting
|
|
366
|
-
morph stay in this package behind `src/engine.ts`.
|
|
371
|
+
- **`ms add latex` copies only `tex/node.ts`** (`registry.json`); typesetting, the
|
|
372
|
+
morph and the drawing (`tex/typeset.ts`) stay in this package behind `src/engine.ts`.
|
|
367
373
|
|
|
368
374
|
## Usage
|
|
369
375
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Color, type NodeOf, type NormalizedColor, type PaintProps, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
|
|
2
2
|
export interface AngleMarkProps extends PaintProps {
|
|
3
3
|
fromAngle?: number;
|
|
4
4
|
toAngle?: number;
|
|
@@ -9,38 +9,63 @@ export interface AngleMarkProps extends PaintProps {
|
|
|
9
9
|
labelColor?: Color;
|
|
10
10
|
fontFamily?: string;
|
|
11
11
|
}
|
|
12
|
+
interface AngleValues {
|
|
13
|
+
readonly fromAngle: number;
|
|
14
|
+
readonly toAngle: number;
|
|
15
|
+
readonly radius: number;
|
|
16
|
+
readonly corner: "arc" | "square" | "auto";
|
|
17
|
+
}
|
|
12
18
|
/**
|
|
13
19
|
* The mark of an angle at the node's own position: an arc from one direction
|
|
14
20
|
* to another, or the small square of a right angle, with an optional label.
|
|
15
21
|
* Directions are degrees counter-clockwise from the right, so binding one to a
|
|
16
22
|
* variable opens and closes the angle. A label of `°` shows the angle's size.
|
|
17
23
|
*/
|
|
18
|
-
export declare
|
|
19
|
-
fromAngle: number
|
|
20
|
-
toAngle: number
|
|
21
|
-
radius: number
|
|
24
|
+
export declare const AngleMark: import("@motionscript/sdk").Component<"angleMark", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
25
|
+
fromAngle: import("@motionscript/sdk").Type<number, number, false>;
|
|
26
|
+
toAngle: import("@motionscript/sdk").Type<number, number, false>;
|
|
27
|
+
radius: import("@motionscript/sdk").Type<number, number, false>;
|
|
22
28
|
/** `auto` draws the square where the angle is a right one. */
|
|
23
|
-
corner: "
|
|
29
|
+
corner: import("@motionscript/sdk").Type<"auto" | "square" | "arc", "auto" | "square" | "arc", false>;
|
|
24
30
|
/** 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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
label: import("@motionscript/sdk").Type<string, string, false>;
|
|
32
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
33
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
34
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
35
|
+
/** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */
|
|
36
|
+
value: import("@motionscript/sdk").Type<number, number, true>;
|
|
37
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
38
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
39
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
40
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
41
|
+
}>, {
|
|
42
|
+
readonly radiusTo: readonly ["radius"];
|
|
43
|
+
readonly strokeTo: readonly ["stroke"];
|
|
44
|
+
readonly shadowTo: readonly ["shadow"];
|
|
45
|
+
readonly progressTo: readonly ["start", "end"];
|
|
46
|
+
readonly flash: {
|
|
47
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
48
|
+
};
|
|
49
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
50
|
+
fromAngle: import("@motionscript/sdk").Type<number, number, false>;
|
|
51
|
+
toAngle: import("@motionscript/sdk").Type<number, number, false>;
|
|
52
|
+
radius: import("@motionscript/sdk").Type<number, number, false>;
|
|
53
|
+
/** `auto` draws the square where the angle is a right one. */
|
|
54
|
+
corner: import("@motionscript/sdk").Type<"auto" | "square" | "arc", "auto" | "square" | "arc", false>;
|
|
55
|
+
/** Text, a formula between dollar signs, or `°` for the angle's own size. */
|
|
56
|
+
label: import("@motionscript/sdk").Type<string, string, false>;
|
|
57
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
58
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
59
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
60
|
+
/** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */
|
|
61
|
+
value: import("@motionscript/sdk").Type<number, number, true>;
|
|
62
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
63
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
64
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
65
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
66
|
+
}>, null>>;
|
|
67
|
+
export type AngleMark = NodeOf<typeof AngleMark>;
|
|
68
|
+
/** The angle a mark marks, in degrees: positive counter-clockwise. */
|
|
69
|
+
export declare function angleOf(s: Pick<AngleValues, "fromAngle" | "toAngle">): number;
|
|
70
|
+
export {};
|
|
46
71
|
//# sourceMappingURL=angle-mark.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angle-mark.d.ts","sourceRoot":"","sources":["../../src/annotate/angle-mark.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"angle-mark.d.ts","sourceRoot":"","sources":["../../src/annotate/angle-mark.ts"],"names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AAS,CAAC,GAAG,MAAM,CAE7E"}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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];
|
|
1
|
+
import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { listed, omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component.js";
|
|
3
|
+
import { outlineBounds, OWN_FRAME } from "../kit/follow.js";
|
|
4
|
+
import { drawLabels, loadFormulas } from "../kit/furniture.js";
|
|
5
|
+
import { strokeShape } from "../kit/mark.js";
|
|
12
6
|
/** Degrees of arc per drawn segment. */
|
|
13
7
|
const ARC_STEP = 4;
|
|
14
8
|
/** How close to a right angle `auto` draws the square. */
|
|
@@ -17,116 +11,87 @@ const point = (radius, degrees) => {
|
|
|
17
11
|
const turn = (degrees * Math.PI) / 180;
|
|
18
12
|
return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };
|
|
19
13
|
};
|
|
14
|
+
const state = {
|
|
15
|
+
// It is only an outline.
|
|
16
|
+
...omit(PAINT, "fill"),
|
|
17
|
+
fromAngle: Types.number(0, { unit: "°" }),
|
|
18
|
+
toAngle: Types.number(60, { unit: "°" }),
|
|
19
|
+
radius: Types.number(48, { min: 0, unit: "px" }),
|
|
20
|
+
/** `auto` draws the square where the angle is a right one. */
|
|
21
|
+
corner: listed(["auto", "arc", "square"], "auto", { animatable: false }),
|
|
22
|
+
/** Text, a formula between dollar signs, or `°` for the angle's own size. */
|
|
23
|
+
label: Types.text("", { animatable: false }),
|
|
24
|
+
labelSize: Types.number(24, { min: 1, unit: "px" }),
|
|
25
|
+
labelColor: Types.color("#e5e7eb"),
|
|
26
|
+
fontFamily: Types.text("", { animatable: false }),
|
|
27
|
+
/** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */
|
|
28
|
+
value: Types.number(0, { private: true }),
|
|
29
|
+
};
|
|
20
30
|
/**
|
|
21
31
|
* The mark of an angle at the node's own position: an arc from one direction
|
|
22
32
|
* to another, or the small square of a right angle, with an optional label.
|
|
23
33
|
* Directions are degrees counter-clockwise from the right, so binding one to a
|
|
24
34
|
* variable opens and closes the angle. A label of `°` shows the angle's size.
|
|
25
35
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
export const AngleMark = component2d({
|
|
37
|
+
key: "angleMark",
|
|
38
|
+
state,
|
|
39
|
+
defaults: { stroke: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" }, width: "hug", height: "hug", value: (s) => angleOf(s) },
|
|
40
|
+
load: (loader, s) => {
|
|
41
|
+
if (s.label !== "" && s.fontFamily !== "")
|
|
42
|
+
loader.font(s.fontFamily);
|
|
43
|
+
loadFormulas(loader, [s.label]);
|
|
44
|
+
},
|
|
45
|
+
commands: {
|
|
46
|
+
...omit(PAINT_COMMANDS, "fillTo"),
|
|
47
|
+
/** Grow or shrink the mark. */
|
|
48
|
+
radiusTo: { args: ["radius"] },
|
|
49
|
+
},
|
|
50
|
+
measure: () => ({ width: 0, height: 0 }),
|
|
51
|
+
bounds: (_size, s) => outlineBounds(outline(s)),
|
|
52
|
+
render: (ctx, s) => {
|
|
53
|
+
const data = outline(s);
|
|
54
|
+
const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;
|
|
55
|
+
painted(ctx, () => {
|
|
56
|
+
if (shape)
|
|
57
|
+
ctx.draw(shape().shadow(s.shadow).fill([]));
|
|
58
|
+
if (s.label === "" || s.radius <= 0)
|
|
59
|
+
return;
|
|
60
|
+
const text = s.label === "°" ? `${Math.round(Math.abs(s.value) * 10) / 10}°` : s.label;
|
|
61
|
+
const at = point(s.radius + s.labelSize * 0.9, (s.fromAngle + s.toAngle) / 2);
|
|
62
|
+
const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor };
|
|
63
|
+
ctx.draw(drawLabels([{ text, at, align: "center" }], style));
|
|
64
|
+
}, () => {
|
|
65
|
+
if (shape)
|
|
66
|
+
strokeShape(ctx, shape, s);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
/** The angle a mark marks, in degrees: positive counter-clockwise. */
|
|
71
|
+
export function angleOf(s) {
|
|
72
|
+
return s.toAngle - s.fromAngle;
|
|
73
|
+
}
|
|
74
|
+
function outline({ fromAngle, toAngle, radius, corner }) {
|
|
75
|
+
const sweep = toAngle - fromAngle;
|
|
76
|
+
if (radius <= 0 || sweep === 0)
|
|
77
|
+
return [];
|
|
78
|
+
const square = corner === "square" || (corner === "auto" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);
|
|
79
|
+
if (square) {
|
|
80
|
+
const side = radius * 0.6;
|
|
81
|
+
const a = point(side, fromAngle);
|
|
82
|
+
const b = point(side, toAngle);
|
|
83
|
+
return [
|
|
84
|
+
{ type: "M", x: a.x, y: a.y },
|
|
85
|
+
{ type: "L", x: a.x + b.x, y: a.y + b.y },
|
|
86
|
+
{ type: "L", x: b.x, y: b.y },
|
|
87
|
+
];
|
|
43
88
|
}
|
|
44
|
-
|
|
45
|
-
|
|
89
|
+
const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));
|
|
90
|
+
const out = [];
|
|
91
|
+
for (let i = 0; i <= steps; i++) {
|
|
92
|
+
const p = point(radius, fromAngle + (sweep * i) / steps);
|
|
93
|
+
out.push({ type: i === 0 ? "M" : "L", x: p.x, y: p.y });
|
|
46
94
|
}
|
|
47
|
-
|
|
48
|
-
|
|
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 };
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
132
97
|
//# sourceMappingURL=angle-mark.js.map
|
|
@@ -1 +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,C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QAAQ,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;yCAA2C;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"]}
|
|
1
|
+
{"version":3,"file":"angle-mark.js","sourceRoot":"","sources":["../../src/annotate/angle-mark.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAaR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAa1C,wCAAwC;AACxC,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,0DAA0D;AAC1D,MAAM,UAAU,GAAG,GAAG,CAAC;A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EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;SAChC,CAAC;IACN,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;IACjE,MAAM,GAAG,GAAkB,EAAE,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QACzD,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import {\r\n component2d,\r\n Graphics2D,\r\n Types,\r\n type Color,\r\n type NodeOf,\r\n type NormalizedColor,\r\n type PaintProps,\r\n type PathCommand,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { listed, omit, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\r\nimport { outlineBounds, OWN_FRAME } from \"../kit/follow\";\r\nimport { drawLabels, loadFormulas } from \"../kit/furniture\";\r\nimport { strokeShape } from \"../kit/mark\";\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\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\nconst state = {\r\n // It is only an outline.\r\n ...omit(PAINT, \"fill\"),\r\n fromAngle: Types.number(0, { unit: \"°\" }),\r\n toAngle: Types.number(60, { unit: \"°\" }),\r\n radius: Types.number(48, { min: 0, unit: \"px\" }),\r\n /** `auto` draws the square where the angle is a right one. */\r\n corner: listed([\"auto\", \"arc\", \"square\"], \"auto\", { animatable: false }),\r\n /** Text, a formula between dollar signs, or `°` for the angle's own size. */\r\n label: Types.text(\"\", { animatable: false }),\r\n labelSize: Types.number(24, { min: 1, unit: \"px\" }),\r\n labelColor: Types.color(\"#e5e7eb\"),\r\n fontFamily: Types.text(\"\", { animatable: false }),\r\n /** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */\r\n value: Types.number(0, { private: true }),\r\n};\r\n\r\ninterface AngleValues {\r\n readonly fromAngle: number;\r\n readonly toAngle: number;\r\n readonly radius: number;\r\n readonly corner: \"arc\" | \"square\" | \"auto\";\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\nexport const AngleMark = component2d({\r\n key: \"angleMark\",\r\n state,\r\n defaults: { stroke: { weight: 3, fill: \"#e5e7eb\", align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\", value: (s) => angleOf(s) },\r\n load: (loader, s) => {\r\n if (s.label !== \"\" && s.fontFamily !== \"\") loader.font(s.fontFamily);\r\n loadFormulas(loader, [s.label]);\r\n },\r\n commands: {\r\n ...omit(PAINT_COMMANDS, \"fillTo\"),\r\n /** Grow or shrink the mark. */\r\n radiusTo: { args: [\"radius\"] },\r\n },\r\n measure: () => ({ width: 0, height: 0 }),\r\n bounds: (_size, s) => outlineBounds(outline(s)),\r\n render: (ctx, s) => {\r\n const data = outline(s);\r\n const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;\r\n painted(\r\n ctx,\r\n () => {\r\n if (shape) ctx.draw(shape().shadow(s.shadow).fill([]));\r\n if (s.label === \"\" || s.radius <= 0) return;\r\n const text = s.label === \"°\" ? `${Math.round(Math.abs(s.value) * 10) / 10}°` : s.label;\r\n const at = point(s.radius + s.labelSize * 0.9, (s.fromAngle + s.toAngle) / 2);\r\n const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor };\r\n ctx.draw(drawLabels([{ text, at, align: \"center\" }], style));\r\n },\r\n () => {\r\n if (shape) strokeShape(ctx, shape, s);\r\n },\r\n );\r\n },\r\n});\r\n\r\nexport type AngleMark = NodeOf<typeof AngleMark>;\r\n\r\n/** The angle a mark marks, in degrees: positive counter-clockwise. */\r\nexport function angleOf(s: Pick<AngleValues, \"fromAngle\" | \"toAngle\">): number {\r\n return s.toAngle - s.fromAngle;\r\n}\r\n\r\nfunction outline({ fromAngle, toAngle, radius, corner }: AngleValues): PathCommand[] {\r\n const sweep = toAngle - fromAngle;\r\n if (radius <= 0 || sweep === 0) return [];\r\n const square = corner === \"square\" || (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"]}
|