@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
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
command,
|
|
2
|
+
component2d,
|
|
4
3
|
Graphics2D,
|
|
5
|
-
|
|
6
|
-
PaintNode,
|
|
7
|
-
pathOps,
|
|
8
|
-
property,
|
|
9
|
-
strokeProperty,
|
|
10
|
-
withdraw,
|
|
11
|
-
type AssetScope,
|
|
12
|
-
type BoxBounds,
|
|
4
|
+
Types,
|
|
13
5
|
type Color,
|
|
14
|
-
type
|
|
15
|
-
type CommandArgs,
|
|
16
|
-
type NodeConfig,
|
|
6
|
+
type NodeOf,
|
|
17
7
|
type NormalizedColor,
|
|
18
8
|
type PaintProps,
|
|
19
9
|
type PathCommand,
|
|
20
|
-
|
|
21
|
-
type
|
|
22
|
-
type
|
|
10
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
11
|
+
type Node2D as _Node2D,
|
|
12
|
+
type Node2DProps as _Node2DProps,
|
|
13
|
+
type Shadow as _Shadow,
|
|
14
|
+
type ShadowResolved as _ShadowResolved,
|
|
15
|
+
type Stroke as _Stroke,
|
|
16
|
+
type StrokeResolved as _StrokeResolved,
|
|
23
17
|
} from "@motionscript/sdk";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
18
|
+
import { listed, omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component";
|
|
19
|
+
import { outlineBounds, OWN_FRAME } from "../kit/follow";
|
|
20
|
+
import { drawLabels, loadFormulas } from "../kit/furniture";
|
|
21
|
+
import { strokeShape } from "../kit/mark";
|
|
27
22
|
|
|
28
23
|
export interface AngleMarkProps extends PaintProps {
|
|
29
24
|
fromAngle?: number;
|
|
@@ -36,7 +31,6 @@ export interface AngleMarkProps extends PaintProps {
|
|
|
36
31
|
fontFamily?: string;
|
|
37
32
|
}
|
|
38
33
|
|
|
39
|
-
const OWN_FRAME: [number, number, number, number] = [-1, -1, 1, 1];
|
|
40
34
|
/** Degrees of arc per drawn segment. */
|
|
41
35
|
const ARC_STEP = 4;
|
|
42
36
|
/** How close to a right angle `auto` draws the square. */
|
|
@@ -47,101 +41,97 @@ const point = (radius: number, degrees: number) => {
|
|
|
47
41
|
return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };
|
|
48
42
|
};
|
|
49
43
|
|
|
44
|
+
const state = {
|
|
45
|
+
// It is only an outline.
|
|
46
|
+
...omit(PAINT, "fill"),
|
|
47
|
+
fromAngle: Types.number(0, { unit: "°" }),
|
|
48
|
+
toAngle: Types.number(60, { unit: "°" }),
|
|
49
|
+
radius: Types.number(48, { min: 0, unit: "px" }),
|
|
50
|
+
/** `auto` draws the square where the angle is a right one. */
|
|
51
|
+
corner: listed(["auto", "arc", "square"], "auto", { animatable: false }),
|
|
52
|
+
/** Text, a formula between dollar signs, or `°` for the angle's own size. */
|
|
53
|
+
label: Types.text("", { animatable: false }),
|
|
54
|
+
labelSize: Types.number(24, { min: 1, unit: "px" }),
|
|
55
|
+
labelColor: Types.color("#e5e7eb"),
|
|
56
|
+
fontFamily: Types.text("", { animatable: false }),
|
|
57
|
+
/** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */
|
|
58
|
+
value: Types.number(0, { private: true }),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
interface AngleValues {
|
|
62
|
+
readonly fromAngle: number;
|
|
63
|
+
readonly toAngle: number;
|
|
64
|
+
readonly radius: number;
|
|
65
|
+
readonly corner: "arc" | "square" | "auto";
|
|
66
|
+
}
|
|
67
|
+
|
|
50
68
|
/**
|
|
51
69
|
* The mark of an angle at the node's own position: an arc from one direction
|
|
52
70
|
* to another, or the small square of a right angle, with an optional label.
|
|
53
71
|
* Directions are degrees counter-clockwise from the right, so binding one to a
|
|
54
72
|
* variable opens and closes the angle. A label of `°` shows the angle's size.
|
|
55
73
|
*/
|
|
56
|
-
|
|
74
|
+
export const AngleMark = component2d({
|
|
57
75
|
key: "angleMark",
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
state,
|
|
77
|
+
defaults: { stroke: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" }, width: "hug", height: "hug", value: (s) => angleOf(s) },
|
|
78
|
+
load: (loader, s) => {
|
|
79
|
+
if (s.label !== "" && s.fontFamily !== "") loader.font(s.fontFamily);
|
|
80
|
+
loadFormulas(loader, [s.label]);
|
|
81
|
+
},
|
|
82
|
+
commands: {
|
|
83
|
+
...omit(PAINT_COMMANDS, "fillTo"),
|
|
84
|
+
/** Grow or shrink the mark. */
|
|
85
|
+
radiusTo: { args: ["radius"] },
|
|
86
|
+
},
|
|
87
|
+
measure: () => ({ width: 0, height: 0 }),
|
|
88
|
+
bounds: (_size, s) => outlineBounds(outline(s)),
|
|
89
|
+
render: (ctx, s) => {
|
|
90
|
+
const data = outline(s);
|
|
91
|
+
const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;
|
|
92
|
+
painted(
|
|
93
|
+
ctx,
|
|
94
|
+
() => {
|
|
95
|
+
if (shape) ctx.draw(shape().shadow(s.shadow).fill([]));
|
|
96
|
+
if (s.label === "" || s.radius <= 0) return;
|
|
97
|
+
const text = s.label === "°" ? `${Math.round(Math.abs(s.value) * 10) / 10}°` : s.label;
|
|
98
|
+
const at = point(s.radius + s.labelSize * 0.9, (s.fromAngle + s.toAngle) / 2);
|
|
99
|
+
const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor };
|
|
100
|
+
ctx.draw(drawLabels([{ text, at, align: "center" }], style));
|
|
101
|
+
},
|
|
102
|
+
() => {
|
|
103
|
+
if (shape) strokeShape(ctx, shape, s);
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
},
|
|
107
|
+
});
|
|
82
108
|
|
|
83
|
-
|
|
84
|
-
@command({ args: ["radius"] })
|
|
85
|
-
radiusTo(args: CommandArgs<{ radius: number }> & { duration: number }): Command<AngleMarkProps> {
|
|
86
|
-
return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** The angle marked, in degrees: positive counter-clockwise. */
|
|
90
|
-
get value(): number {
|
|
91
|
-
return this.toAngle - this.fromAngle;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
override declareAssets(assets: AssetScope): void {
|
|
95
|
-
super.declareAssets(assets);
|
|
96
|
-
if (this.label !== "" && this.fontFamily !== "") assets.font(this.fontFamily);
|
|
97
|
-
declareFormulas(assets, [this.label]);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
override measure(): Partial<Size2D> {
|
|
101
|
-
return { width: 0, height: 0 };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
protected override shapeGraphics(): Graphics2D | null {
|
|
105
|
-
const data = this._outline();
|
|
106
|
-
return data.length === 0 ? null : new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });
|
|
107
|
-
}
|
|
109
|
+
export type AngleMark = NodeOf<typeof AngleMark>;
|
|
108
110
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const at = point(this.radius + this.labelSize * 0.9, (this.fromAngle + this.toAngle) / 2);
|
|
114
|
-
const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor };
|
|
115
|
-
for (const part of drawLabels([{ text, at, align: "center" }], style)) ctx.draw(part);
|
|
116
|
-
}
|
|
111
|
+
/** The angle a mark marks, in degrees: positive counter-clockwise. */
|
|
112
|
+
export function angleOf(s: Pick<AngleValues, "fromAngle" | "toAngle">): number {
|
|
113
|
+
return s.toAngle - s.fromAngle;
|
|
114
|
+
}
|
|
117
115
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
function outline({ fromAngle, toAngle, radius, corner }: AngleValues): PathCommand[] {
|
|
117
|
+
const sweep = toAngle - fromAngle;
|
|
118
|
+
if (radius <= 0 || sweep === 0) return [];
|
|
119
|
+
const square = corner === "square" || (corner === "auto" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);
|
|
120
|
+
if (square) {
|
|
121
|
+
const side = radius * 0.6;
|
|
122
|
+
const a = point(side, fromAngle);
|
|
123
|
+
const b = point(side, toAngle);
|
|
124
|
+
return [
|
|
125
|
+
{ type: "M", x: a.x, y: a.y },
|
|
126
|
+
{ type: "L", x: a.x + b.x, y: a.y + b.y },
|
|
127
|
+
{ type: "L", x: b.x, y: b.y },
|
|
128
|
+
];
|
|
122
129
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
const square = this.corner === "square" || (this.corner === "auto" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);
|
|
129
|
-
if (square) {
|
|
130
|
-
const side = radius * 0.6;
|
|
131
|
-
const a = point(side, fromAngle);
|
|
132
|
-
const b = point(side, toAngle);
|
|
133
|
-
return [
|
|
134
|
-
{ type: "M", x: a.x, y: a.y },
|
|
135
|
-
{ type: "L", x: a.x + b.x, y: a.y + b.y },
|
|
136
|
-
{ type: "L", x: b.x, y: b.y },
|
|
137
|
-
];
|
|
138
|
-
}
|
|
139
|
-
const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));
|
|
140
|
-
const out: PathCommand[] = [];
|
|
141
|
-
for (let i = 0; i <= steps; i++) {
|
|
142
|
-
const p = point(radius, fromAngle + (sweep * i) / steps);
|
|
143
|
-
out.push({ type: i === 0 ? "M" : "L", x: p.x, y: p.y });
|
|
144
|
-
}
|
|
145
|
-
return out;
|
|
130
|
+
const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));
|
|
131
|
+
const out: PathCommand[] = [];
|
|
132
|
+
for (let i = 0; i <= steps; i++) {
|
|
133
|
+
const p = point(radius, fromAngle + (sweep * i) / steps);
|
|
134
|
+
out.push({ type: i === 0 ? "M" : "L", x: p.x, y: p.y });
|
|
146
135
|
}
|
|
136
|
+
return out;
|
|
147
137
|
}
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
strokeProperty,
|
|
6
|
-
vector2Property,
|
|
7
|
-
type AssetScope,
|
|
2
|
+
component2d,
|
|
3
|
+
Graphics2D,
|
|
4
|
+
Types,
|
|
8
5
|
type Color,
|
|
9
|
-
type
|
|
10
|
-
type
|
|
6
|
+
type NodeOf,
|
|
7
|
+
type NodeView,
|
|
11
8
|
type NormalizedColor,
|
|
12
9
|
type PathCommand,
|
|
13
|
-
type RenderContext2D,
|
|
14
|
-
type Stroke,
|
|
15
10
|
type Vector2,
|
|
11
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
12
|
+
type Node2D as _Node2D,
|
|
13
|
+
type Node2DProps as _Node2DProps,
|
|
14
|
+
type Shadow as _Shadow,
|
|
15
|
+
type ShadowResolved as _ShadowResolved,
|
|
16
|
+
type Stroke as _Stroke,
|
|
17
|
+
type StrokeResolved as _StrokeResolved,
|
|
16
18
|
} from "@motionscript/sdk";
|
|
17
19
|
import { braceOutline } from "../kit/brace";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
+
import { listed, painted } from "../kit/component";
|
|
21
|
+
import {
|
|
22
|
+
add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, heading, outlineBounds, OWN_FRAME, resting,
|
|
23
|
+
type FollowProps, type FollowValues, type Quad,
|
|
24
|
+
} from "../kit/follow";
|
|
25
|
+
import { drawLabels, loadFormulas } from "../kit/furniture";
|
|
26
|
+
import { strokeShape } from "../kit/mark";
|
|
20
27
|
|
|
21
28
|
export type BraceSide = "below" | "above" | "left" | "right";
|
|
22
29
|
|
|
@@ -40,87 +47,102 @@ const EDGE: Record<BraceSide, [number, number]> = {
|
|
|
40
47
|
right: [1, 2],
|
|
41
48
|
};
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* written between dollar signs is typeset.
|
|
47
|
-
*/
|
|
48
|
-
@node({
|
|
49
|
-
key: "curlyBrace",
|
|
50
|
-
parentKey: "shape",
|
|
51
|
-
forkable: true,
|
|
52
|
-
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
53
|
-
})
|
|
54
|
-
export class CurlyBrace extends FollowMark<CurlyBraceProps> {
|
|
55
|
-
@property({ default: "below", options: ["below", "above", "left", "right"], animatable: false }) declare side: BraceSide;
|
|
50
|
+
const state = {
|
|
51
|
+
...FOLLOW_STATE,
|
|
52
|
+
side: listed(["below", "above", "left", "right"], "below", { animatable: false }),
|
|
56
53
|
/** The two ends of a brace that follows nothing, from the brace's own position. It bulges to the left of tail to head. */
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
tail: Types.vector2({ x: -80, y: 0 }),
|
|
55
|
+
head: Types.vector2({ x: 80, y: 0 }),
|
|
59
56
|
/** The room between the target and the brace. (`gap` is a layout's.) */
|
|
60
|
-
|
|
57
|
+
clearance: Types.number(8, { min: 0, unit: "px" }),
|
|
61
58
|
/** How far the brace reaches from its ends to its tip. (`depth` is a node's place in 3D.) */
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
@strokeProperty({ default: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" } })
|
|
70
|
-
declare stroke: Stroke;
|
|
71
|
-
|
|
72
|
-
constructor(props?: NodeConfig<CurlyBrace, CurlyBraceProps>) {
|
|
73
|
-
super(props ?? {});
|
|
74
|
-
}
|
|
59
|
+
reach: Types.number(18, { min: 2, unit: "px" }),
|
|
60
|
+
label: Types.text("", { animatable: false }),
|
|
61
|
+
labelSize: Types.number(28, { min: 1, unit: "px" }),
|
|
62
|
+
labelColor: Types.color("#e5e7eb"),
|
|
63
|
+
fontFamily: Types.text("", { animatable: false }),
|
|
64
|
+
};
|
|
75
65
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
66
|
+
interface BraceValues extends FollowValues {
|
|
67
|
+
readonly side: BraceSide;
|
|
68
|
+
readonly tail: Vector2;
|
|
69
|
+
readonly head: Vector2;
|
|
70
|
+
readonly clearance: number;
|
|
71
|
+
readonly reach: number;
|
|
72
|
+
}
|
|
81
73
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
/** Whether the brace follows nothing, and so spans its own two points. */
|
|
75
|
+
function spans(s: BraceValues, parted: NodeView | null): boolean {
|
|
76
|
+
return !s.retarget && resting(s, parted) === null;
|
|
77
|
+
}
|
|
86
78
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
79
|
+
/** No target: the span itself, as an edge with nothing above it. */
|
|
80
|
+
function quadOf(s: BraceValues, parted: NodeView | null): Quad | null {
|
|
81
|
+
return spans(s, parted) ? [s.head, s.tail, s.tail, s.head] : followedQuad(s, parted);
|
|
82
|
+
}
|
|
91
83
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
84
|
+
/** The edge the brace runs along, pushed out by the gap, and the way it bulges. */
|
|
85
|
+
function edgeOf(s: BraceValues, parted: NodeView | null, quad: Quad): { from: Vector2; to: Vector2; out: Vector2 } {
|
|
86
|
+
const [i, j] = spans(s, parted) ? [1, 0] : EDGE[s.side];
|
|
87
|
+
const { unit } = heading(quad[i], quad[j]);
|
|
88
|
+
// Left of the edge's own direction, in a y-up frame.
|
|
89
|
+
const out = { x: -unit.y, y: unit.x };
|
|
90
|
+
return { from: add(quad[i], out, s.clearance), to: add(quad[j], out, s.clearance), out };
|
|
91
|
+
}
|
|
96
92
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const reach = Math.min(this.reach, heading(from, to).length / 2) + this.labelSize * 0.75;
|
|
104
|
-
const at = add(between(from, to), out, reach);
|
|
105
|
-
const align = out.x > 0.5 ? "left" : out.x < -0.5 ? "right" : "center";
|
|
106
|
-
const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor };
|
|
107
|
-
for (const part of drawLabels([{ text: this.label, at, align }], style)) ctx.draw(part);
|
|
108
|
-
}
|
|
93
|
+
function outline(s: BraceValues, parted: NodeView | null): PathCommand[] {
|
|
94
|
+
const quad = quadOf(s, parted);
|
|
95
|
+
if (!quad) return [];
|
|
96
|
+
const { from, to, out } = edgeOf(s, parted, quad);
|
|
97
|
+
return braceOutline(from, to, out, s.reach);
|
|
98
|
+
}
|
|
109
99
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const out = { x: -unit.y, y: unit.x };
|
|
116
|
-
return { from: add(quad[i], out, this.clearance), to: add(quad[j], out, this.clearance), out };
|
|
117
|
-
}
|
|
100
|
+
/** One of the two ends to drag, while the brace spans them. */
|
|
101
|
+
const end = (which: "tail" | "head") => ({
|
|
102
|
+
at: (s: BraceValues) => (spans(s, container(null, s)) ? s[which] : null),
|
|
103
|
+
value: (at: Vector2) => ({ x: at.x, y: at.y }),
|
|
104
|
+
});
|
|
118
105
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
106
|
+
/**
|
|
107
|
+
* A curly brace along one side of a node or of a part of a formula, or between
|
|
108
|
+
* two points when it names neither, with an optional label at its tip. A label
|
|
109
|
+
* written between dollar signs is typeset.
|
|
110
|
+
*/
|
|
111
|
+
export const CurlyBrace = component2d({
|
|
112
|
+
key: "curlyBrace",
|
|
113
|
+
state,
|
|
114
|
+
defaults: { stroke: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" }, width: "hug", height: "hug" },
|
|
115
|
+
load: (loader, s) => {
|
|
116
|
+
if (s.label !== "" && s.fontFamily !== "") loader.font(s.fontFamily);
|
|
117
|
+
loadFormulas(loader, [s.label]);
|
|
118
|
+
},
|
|
119
|
+
commands: FOLLOW_COMMANDS,
|
|
120
|
+
handles: { tail: end("tail"), head: end("head") },
|
|
121
|
+
measure: () => ({ width: 0, height: 0 }),
|
|
122
|
+
bounds: (_size, s) => outlineBounds(outline(s, container(null, s))),
|
|
123
|
+
render: (ctx, s) => {
|
|
124
|
+
const parted = container(ctx, s);
|
|
125
|
+
const data = outline(s, parted);
|
|
126
|
+
const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;
|
|
127
|
+
painted(
|
|
128
|
+
ctx,
|
|
129
|
+
() => {
|
|
130
|
+
if (shape) ctx.draw(shape().shadow(s.shadow).fill([]));
|
|
131
|
+
if (s.label === "") return;
|
|
132
|
+
const quad = quadOf(s, parted);
|
|
133
|
+
if (!quad) return;
|
|
134
|
+
const { from, to, out } = edgeOf(s, parted, quad);
|
|
135
|
+
const reach = Math.min(s.reach, heading(from, to).length / 2) + s.labelSize * 0.75;
|
|
136
|
+
const at = add(between(from, to), out, reach);
|
|
137
|
+
const align = out.x > 0.5 ? "left" : out.x < -0.5 ? "right" : "center";
|
|
138
|
+
const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor };
|
|
139
|
+
ctx.draw(drawLabels([{ text: s.label, at, align }], style));
|
|
140
|
+
},
|
|
141
|
+
() => {
|
|
142
|
+
if (shape) strokeShape(ctx, shape, s);
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
},
|
|
146
|
+
});
|
|
122
147
|
|
|
123
|
-
|
|
124
|
-
return this._spans() && (prop === "tail" || prop === "head") ? { x: at.x, y: at.y } : null;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
148
|
+
export type CurlyBrace = NodeOf<typeof CurlyBrace>;
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type
|
|
2
|
+
component2d,
|
|
3
|
+
Graphics2D,
|
|
4
|
+
Types,
|
|
5
|
+
type NodeOf,
|
|
6
|
+
type NodeView,
|
|
6
7
|
type PathCommand,
|
|
7
|
-
type Stroke,
|
|
8
8
|
type Vector2,
|
|
9
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
10
|
+
type Node2D as _Node2D,
|
|
11
|
+
type Node2DProps as _Node2DProps,
|
|
12
|
+
type Shadow as _Shadow,
|
|
13
|
+
type ShadowResolved as _ShadowResolved,
|
|
14
|
+
type Stroke as _Stroke,
|
|
15
|
+
type StrokeResolved as _StrokeResolved,
|
|
9
16
|
} from "@motionscript/sdk";
|
|
10
|
-
import {
|
|
17
|
+
import { listed, painted } from "../kit/component";
|
|
18
|
+
import {
|
|
19
|
+
add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, grown, heading, outlineBounds, OWN_FRAME, type FollowProps, type FollowValues, type Quad,
|
|
20
|
+
} from "../kit/follow";
|
|
21
|
+
import { strokeShape } from "../kit/mark";
|
|
11
22
|
|
|
12
23
|
export type EmphasisShape = "box" | "circle" | "underline" | "cross";
|
|
13
24
|
|
|
@@ -61,29 +72,47 @@ const SHAPES: Record<EmphasisShape, (quad: Quad, gap: number) => PathCommand[]>
|
|
|
61
72
|
},
|
|
62
73
|
};
|
|
63
74
|
|
|
75
|
+
const state = {
|
|
76
|
+
...FOLLOW_STATE,
|
|
77
|
+
shape: listed(["box", "circle", "underline", "cross"], "box", { animatable: false }),
|
|
78
|
+
/** The room between the target and the mark. (`gap` is a layout's.) */
|
|
79
|
+
clearance: Types.number(10, { unit: "px" }),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
interface EmphasisValues extends FollowValues {
|
|
83
|
+
readonly shape: EmphasisShape;
|
|
84
|
+
readonly clearance: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function outline(s: EmphasisValues, parted: NodeView | null): PathCommand[] {
|
|
88
|
+
const quad = followedQuad(s, parted);
|
|
89
|
+
return quad ? SHAPES[s.shape](quad, s.clearance) : [];
|
|
90
|
+
}
|
|
91
|
+
|
|
64
92
|
/**
|
|
65
93
|
* A box, a circle, an underline or a cross drawn on a node, or on one part of
|
|
66
94
|
* a formula. `progressTo` draws it on, and `retargetTo` slides it to another.
|
|
67
95
|
*/
|
|
68
|
-
|
|
96
|
+
export const EmphasisMark = component2d({
|
|
69
97
|
key: "emphasisMark",
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
98
|
+
state,
|
|
99
|
+
defaults: { stroke: { weight: 3, fill: "#facc15", align: "center", cap: "round", join: "round" }, width: "hug", height: "hug" },
|
|
100
|
+
commands: FOLLOW_COMMANDS,
|
|
101
|
+
measure: () => ({ width: 0, height: 0 }),
|
|
102
|
+
bounds: (_size, s) => outlineBounds(outline(s, container(null, s))),
|
|
103
|
+
render: (ctx, s) => {
|
|
104
|
+
const data = outline(s, container(ctx, s));
|
|
105
|
+
const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;
|
|
106
|
+
painted(
|
|
107
|
+
ctx,
|
|
108
|
+
() => {
|
|
109
|
+
if (shape) ctx.draw(shape().shadow(s.shadow).fill([]));
|
|
110
|
+
},
|
|
111
|
+
() => {
|
|
112
|
+
if (shape) strokeShape(ctx, shape, s);
|
|
113
|
+
},
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
});
|
|
85
117
|
|
|
86
|
-
|
|
87
|
-
return SHAPES[this.shape](quad, this.clearance);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
118
|
+
export type EmphasisMark = NodeOf<typeof EmphasisMark>;
|