@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
|
@@ -0,0 +1,114 @@
|
|
|
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, node, property, strokeProperty, vector2Property, } from "@motionscript/sdk";
|
|
8
|
+
import { braceOutline } from "../kit/brace.js";
|
|
9
|
+
import { add, between, followed, FollowMark, heading } from "../kit/follow.js";
|
|
10
|
+
import { declareFormulas, drawLabels } from "../kit/furniture.js";
|
|
11
|
+
/** The edge of a target a brace runs along, as two corner indexes of its quad, read with the brace's bulge to the left. */
|
|
12
|
+
const EDGE = {
|
|
13
|
+
below: [2, 3],
|
|
14
|
+
above: [0, 1],
|
|
15
|
+
left: [3, 0],
|
|
16
|
+
right: [1, 2],
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A curly brace along one side of a node or of a part of a formula, or between
|
|
20
|
+
* two points when it names neither, with an optional label at its tip. A label
|
|
21
|
+
* written between dollar signs is typeset.
|
|
22
|
+
*/
|
|
23
|
+
let CurlyBrace = class CurlyBrace extends FollowMark {
|
|
24
|
+
constructor(props) {
|
|
25
|
+
super(props ?? {});
|
|
26
|
+
}
|
|
27
|
+
declareAssets(assets) {
|
|
28
|
+
super.declareAssets(assets);
|
|
29
|
+
if (this.label !== "" && this.fontFamily !== "")
|
|
30
|
+
assets.font(this.fontFamily);
|
|
31
|
+
declareFormulas(assets, [this.label]);
|
|
32
|
+
}
|
|
33
|
+
quad() {
|
|
34
|
+
// No target: the span itself, as an edge with nothing above it.
|
|
35
|
+
return this._spans() ? [this.head, this.tail, this.tail, this.head] : super.quad();
|
|
36
|
+
}
|
|
37
|
+
/** Whether the brace follows nothing, and so spans its own two points. */
|
|
38
|
+
_spans() {
|
|
39
|
+
return !this.retarget && followed(this, this.on) === null;
|
|
40
|
+
}
|
|
41
|
+
outline(quad) {
|
|
42
|
+
const { from, to, out } = this._span(quad);
|
|
43
|
+
return braceOutline(from, to, out, this.reach);
|
|
44
|
+
}
|
|
45
|
+
renderSelf(ctx) {
|
|
46
|
+
super.renderSelf(ctx);
|
|
47
|
+
if (this.label === "")
|
|
48
|
+
return;
|
|
49
|
+
const quad = this.quad();
|
|
50
|
+
if (!quad)
|
|
51
|
+
return;
|
|
52
|
+
const { from, to, out } = this._span(quad);
|
|
53
|
+
const reach = Math.min(this.reach, heading(from, to).length / 2) + this.labelSize * 0.75;
|
|
54
|
+
const at = add(between(from, to), out, reach);
|
|
55
|
+
const align = out.x > 0.5 ? "left" : out.x < -0.5 ? "right" : "center";
|
|
56
|
+
const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor };
|
|
57
|
+
for (const part of drawLabels([{ text: this.label, at, align }], style))
|
|
58
|
+
ctx.draw(part);
|
|
59
|
+
}
|
|
60
|
+
/** The edge the brace runs along, pushed out by the gap, and the way it bulges. */
|
|
61
|
+
_span(quad) {
|
|
62
|
+
const [i, j] = this._spans() ? [1, 0] : EDGE[this.side];
|
|
63
|
+
const { unit } = heading(quad[i], quad[j]);
|
|
64
|
+
// Left of the edge's own direction, in a y-up frame.
|
|
65
|
+
const out = { x: -unit.y, y: unit.x };
|
|
66
|
+
return { from: add(quad[i], out, this.clearance), to: add(quad[j], out, this.clearance), out };
|
|
67
|
+
}
|
|
68
|
+
_handles() {
|
|
69
|
+
return this._spans() ? [{ prop: "tail", at: this.tail }, { prop: "head", at: this.head }] : [];
|
|
70
|
+
}
|
|
71
|
+
_handleValue(prop, at) {
|
|
72
|
+
return this._spans() && (prop === "tail" || prop === "head") ? { x: at.x, y: at.y } : null;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
__decorate([
|
|
76
|
+
property({ default: "below", options: ["below", "above", "left", "right"], animatable: false })
|
|
77
|
+
], CurlyBrace.prototype, "side", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
vector2Property({ default: { x: -80, y: 0 } })
|
|
80
|
+
], CurlyBrace.prototype, "tail", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
vector2Property({ default: { x: 80, y: 0 } })
|
|
83
|
+
], CurlyBrace.prototype, "head", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
property({ default: 8, min: 0, unit: "px" })
|
|
86
|
+
], CurlyBrace.prototype, "clearance", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
property({ default: 18, min: 2, unit: "px" })
|
|
89
|
+
], CurlyBrace.prototype, "reach", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
property({ default: "", animatable: false })
|
|
92
|
+
], CurlyBrace.prototype, "label", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
property({ default: 28, min: 1, unit: "px" })
|
|
95
|
+
], CurlyBrace.prototype, "labelSize", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
colorProperty({ default: "#e5e7eb" })
|
|
98
|
+
], CurlyBrace.prototype, "labelColor", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
property({ default: "", animatable: false })
|
|
101
|
+
], CurlyBrace.prototype, "fontFamily", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
strokeProperty({ default: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" } })
|
|
104
|
+
], CurlyBrace.prototype, "stroke", void 0);
|
|
105
|
+
CurlyBrace = __decorate([
|
|
106
|
+
node({
|
|
107
|
+
key: "curlyBrace",
|
|
108
|
+
parentKey: "shape",
|
|
109
|
+
forkable: true,
|
|
110
|
+
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
111
|
+
})
|
|
112
|
+
], CurlyBrace);
|
|
113
|
+
export { CurlyBrace };
|
|
114
|
+
//# sourceMappingURL=curly-brace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curly-brace.js","sourceRoot":"","sources":["../../src/annotate/curly-brace.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,aAAa,EACb,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,eAAe,GAUlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAA+B,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAgB/D,2HAA2H;AAC3H,MAAM,IAAI,GAAwC;IAC9C,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACb,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AAOI,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,UAA2B;IAkBvD,YAAY,KAA+C;QACvD,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACvB,CAAC;IAEQ,aAAa,CAAC,MAAkB;QACrC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,IAAI,CAAC,KAAK,KAAK,EAAE,IAAI,IAAI,CAAC,UAAU,KAAK,EAAE;YA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EjB;IAAtD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;yCAAuB;AAEf;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;yCAAuB;AACb;IAAtD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;6CAA2B;AAC1B;IAA9C,aAAa,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;8CAA2B;AACX;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;8CAA4B;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;0CACnF;AAhBd,UAAU;IANtB,IAAI,CAAC;QACF,GAAG,EAAE,YAAY;QACjB,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;GACW,UAAU,CAwEtB","sourcesContent":["import {\r\n colorProperty,\r\n node,\r\n property,\r\n strokeProperty,\r\n vector2Property,\r\n type AssetScope,\r\n type Color,\r\n type NodeConfig,\r\n type NodeHandle,\r\n type NormalizedColor,\r\n type PathCommand,\r\n type RenderContext2D,\r\n type Stroke,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { braceOutline } from \"../kit/brace\";\r\nimport { add, between, followed, FollowMark, heading, type FollowProps, type Quad } from \"../kit/follow\";\r\nimport { declareFormulas, drawLabels } from \"../kit/furniture\";\r\n\r\nexport type BraceSide = \"below\" | \"above\" | \"left\" | \"right\";\r\n\r\nexport interface CurlyBraceProps extends FollowProps {\r\n side?: BraceSide;\r\n tail?: Vector2;\r\n head?: Vector2;\r\n clearance?: number;\r\n reach?: number;\r\n label?: string;\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n}\r\n\r\n/** The edge of a target a brace runs along, as two corner indexes of its quad, read with the brace's bulge to the left. */\r\nconst EDGE: Record<BraceSide, [number, number]> = {\r\n below: [2, 3],\r\n above: [0, 1],\r\n left: [3, 0],\r\n right: [1, 2],\r\n};\r\n\r\n/**\r\n * A curly brace along one side of a node or of a part of a formula, or between\r\n * two points when it names neither, with an optional label at its tip. A label\r\n * written between dollar signs is typeset.\r\n */\r\n@node({\r\n key: \"curlyBrace\",\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n})\r\nexport class CurlyBrace extends FollowMark<CurlyBraceProps> {\r\n @property({ default: \"below\", options: [\"below\", \"above\", \"left\", \"right\"], animatable: false }) declare side: BraceSide;\r\n /** The two ends of a brace that follows nothing, from the brace's own position. It bulges to the left of tail to head. */\r\n @vector2Property({ default: { x: -80, y: 0 } }) declare tail: Vector2;\r\n @vector2Property({ default: { x: 80, y: 0 } }) declare head: Vector2;\r\n /** The room between the target and the brace. (`gap` is a layout's.) */\r\n @property({ default: 8, min: 0, unit: \"px\" }) declare clearance: number;\r\n /** How far the brace reaches from its ends to its tip. (`depth` is a node's place in 3D.) */\r\n @property({ default: 18, min: 2, unit: \"px\" }) declare reach: number;\r\n\r\n @property({ default: \"\", animatable: false }) declare label: string;\r\n @property({ default: 28, 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<CurlyBrace, CurlyBraceProps>) {\r\n super(props ?? {});\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 protected override quad(): Quad | null {\r\n // No target: the span itself, as an edge with nothing above it.\r\n return this._spans() ? [this.head, this.tail, this.tail, this.head] : super.quad();\r\n }\r\n\r\n /** Whether the brace follows nothing, and so spans its own two points. */\r\n private _spans(): boolean {\r\n return !this.retarget && followed(this, this.on) === null;\r\n }\r\n\r\n protected outline(quad: Quad): PathCommand[] {\r\n const { from, to, out } = this._span(quad);\r\n return braceOutline(from, to, out, this.reach);\r\n }\r\n\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n super.renderSelf(ctx);\r\n if (this.label === \"\") return;\r\n const quad = this.quad();\r\n if (!quad) return;\r\n const { from, to, out } = this._span(quad);\r\n const reach = Math.min(this.reach, heading(from, to).length / 2) + this.labelSize * 0.75;\r\n const at = add(between(from, to), out, reach);\r\n const align = out.x > 0.5 ? \"left\" : out.x < -0.5 ? \"right\" : \"center\";\r\n const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor };\r\n for (const part of drawLabels([{ text: this.label, at, align }], style)) ctx.draw(part);\r\n }\r\n\r\n /** The edge the brace runs along, pushed out by the gap, and the way it bulges. */\r\n private _span(quad: Quad): { from: Vector2; to: Vector2; out: Vector2 } {\r\n const [i, j] = this._spans() ? [1, 0] : EDGE[this.side];\r\n const { unit } = heading(quad[i], quad[j]);\r\n // Left of the edge's own direction, in a y-up frame.\r\n const out = { x: -unit.y, y: unit.x };\r\n return { from: add(quad[i], out, this.clearance), to: add(quad[j], out, this.clearance), out };\r\n }\r\n\r\n override _handles(): readonly NodeHandle[] {\r\n return this._spans() ? [{ prop: \"tail\", at: this.tail }, { prop: \"head\", at: this.head }] : [];\r\n }\r\n\r\n override _handleValue(prop: string, at: Vector2): Vector2 | null {\r\n return this._spans() && (prop === \"tail\" || prop === \"head\") ? { x: at.x, y: at.y } : null;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type NodeConfig, type PathCommand, type Stroke } from "@motionscript/sdk";
|
|
2
|
+
import { FollowMark, type FollowProps, type Quad } from "../kit/follow.js";
|
|
3
|
+
export type EmphasisShape = "box" | "circle" | "underline" | "cross";
|
|
4
|
+
export interface EmphasisMarkProps extends FollowProps {
|
|
5
|
+
shape?: EmphasisShape;
|
|
6
|
+
clearance?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A box, a circle, an underline or a cross drawn on a node, or on one part of
|
|
10
|
+
* a formula. `progressTo` draws it on, and `retargetTo` slides it to another.
|
|
11
|
+
*/
|
|
12
|
+
export declare class EmphasisMark extends FollowMark<EmphasisMarkProps> {
|
|
13
|
+
shape: EmphasisShape;
|
|
14
|
+
/** The room between the target and the mark. (`gap` is a layout's.) */
|
|
15
|
+
clearance: number;
|
|
16
|
+
stroke: Stroke;
|
|
17
|
+
constructor(props?: NodeConfig<EmphasisMark, EmphasisMarkProps>);
|
|
18
|
+
protected outline(quad: Quad): PathCommand[];
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=emphasis-mark.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emphasis-mark.d.ts","sourceRoot":"","sources":["../../src/annotate/emphasis-mark.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,MAAM,EAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAgB,UAAU,EAAkB,KAAK,WAAW,EAAE,KAAK,IAAI,EAAE,MAAM,eAAe,CAAC;AAEtG,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,QAAQ,GAAG,WAAW,GAAG,OAAO,CAAC;AAErE,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IAClD,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AA+CD;;;GAGG;AACH,qBAMa,YAAa,SAAQ,UAAU,CAAC,iBAAiB,CAAC;IACgD,KAAK,EAAE,aAAa,CAAC;IAChI,uEAAuE;IACxB,SAAS,EAAE,MAAM,CAAC;IAGzD,MAAM,EAAE,MAAM,CAAC;gBAEX,KAAK,CAAC,EAAE,UAAU,CAAC,YAAY,EAAE,iBAAiB,CAAC;IAI/D,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,EAAE;CAG/C"}
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { node, property, strokeProperty, } from "@motionscript/sdk";
|
|
8
|
+
import { add, between, FollowMark, grown, heading } from "../kit/follow.js";
|
|
9
|
+
/** How far a cubic's handle reaches to draw a quarter of an ellipse. */
|
|
10
|
+
const QUARTER = 0.5523;
|
|
11
|
+
const line = (a, b) => [
|
|
12
|
+
{ type: "M", x: a.x, y: a.y },
|
|
13
|
+
{ type: "L", x: b.x, y: b.y },
|
|
14
|
+
];
|
|
15
|
+
const SHAPES = {
|
|
16
|
+
box: (quad, gap) => {
|
|
17
|
+
const [tl, tr, br, bl] = grown(quad, gap);
|
|
18
|
+
return [{ type: "M", x: tl.x, y: tl.y }, ...[tr, br, bl].map((p) => ({ type: "L", x: p.x, y: p.y })), { type: "Z" }];
|
|
19
|
+
},
|
|
20
|
+
// The ellipse through the grown box's corners.
|
|
21
|
+
circle: (quad, gap) => {
|
|
22
|
+
const [tl, tr, br, bl] = grown(quad, gap);
|
|
23
|
+
const centre = between(tl, br);
|
|
24
|
+
const across = { x: ((tr.x - tl.x) / 2) * Math.SQRT2, y: ((tr.y - tl.y) / 2) * Math.SQRT2 };
|
|
25
|
+
const up = { x: ((tl.x - bl.x) / 2) * Math.SQRT2, y: ((tl.y - bl.y) / 2) * Math.SQRT2 };
|
|
26
|
+
const at = (a, u) => add(add(centre, across, a), up, u);
|
|
27
|
+
const arc = (c1, c2, end) => ({
|
|
28
|
+
type: "C", x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: end.x, y: end.y,
|
|
29
|
+
});
|
|
30
|
+
const k = QUARTER;
|
|
31
|
+
const start = at(0, 1);
|
|
32
|
+
return [
|
|
33
|
+
{ type: "M", x: start.x, y: start.y },
|
|
34
|
+
arc(at(k, 1), at(1, k), at(1, 0)),
|
|
35
|
+
arc(at(1, -k), at(k, -1), at(0, -1)),
|
|
36
|
+
arc(at(-k, -1), at(-1, -k), at(-1, 0)),
|
|
37
|
+
arc(at(-1, k), at(-k, 1), start),
|
|
38
|
+
{ type: "Z" },
|
|
39
|
+
];
|
|
40
|
+
},
|
|
41
|
+
underline: (quad, gap) => {
|
|
42
|
+
const [, , br, bl] = quad;
|
|
43
|
+
const down = heading(quad[0], bl).unit;
|
|
44
|
+
return line(add(bl, down, gap), add(br, down, gap));
|
|
45
|
+
},
|
|
46
|
+
cross: (quad, gap) => {
|
|
47
|
+
const [tl, tr, br, bl] = grown(quad, gap);
|
|
48
|
+
return [...line(tl, br), ...line(bl, tr)];
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A box, a circle, an underline or a cross drawn on a node, or on one part of
|
|
53
|
+
* a formula. `progressTo` draws it on, and `retargetTo` slides it to another.
|
|
54
|
+
*/
|
|
55
|
+
let EmphasisMark = class EmphasisMark extends FollowMark {
|
|
56
|
+
constructor(props) {
|
|
57
|
+
super(props ?? {});
|
|
58
|
+
}
|
|
59
|
+
outline(quad) {
|
|
60
|
+
return SHAPES[this.shape](quad, this.clearance);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
__decorate([
|
|
64
|
+
property({ default: "box", options: ["box", "circle", "underline", "cross"], animatable: false })
|
|
65
|
+
], EmphasisMark.prototype, "shape", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
property({ default: 10, unit: "px" })
|
|
68
|
+
], EmphasisMark.prototype, "clearance", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
strokeProperty({ default: { weight: 3, fill: "#facc15", align: "center", cap: "round", join: "round" } })
|
|
71
|
+
], EmphasisMark.prototype, "stroke", void 0);
|
|
72
|
+
EmphasisMark = __decorate([
|
|
73
|
+
node({
|
|
74
|
+
key: "emphasisMark",
|
|
75
|
+
parentKey: "shape",
|
|
76
|
+
forkable: true,
|
|
77
|
+
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
78
|
+
})
|
|
79
|
+
], EmphasisMark);
|
|
80
|
+
export { EmphasisMark };
|
|
81
|
+
//# sourceMappingURL=emphasis-mark.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emphasis-mark.js","sourceRoot":"","sources":["../../src/annotate/emphasis-mark.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,IAAI,EACJ,QAAQ,EACR,cAAc,GAKjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAA+B,MAAM,eAAe,CAAC;AAStG,wEAAwE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"@motionscript/sdk\";\r\nimport { add, between, FollowMark, grown, heading, type FollowProps, type Quad } from \"../kit/follow\";\r\n\r\nexport type EmphasisShape = \"box\" | \"circle\" | \"underline\" | \"cross\";\r\n\r\nexport interface EmphasisMarkProps extends FollowProps {\r\n shape?: EmphasisShape;\r\n clearance?: number;\r\n}\r\n\r\n/** How far a cubic's handle reaches to draw a quarter of an ellipse. */\r\nconst QUARTER = 0.5523;\r\n\r\nconst line = (a: Vector2, b: Vector2): PathCommand[] => [\r\n { type: \"M\", x: a.x, y: a.y },\r\n { type: \"L\", x: b.x, y: b.y },\r\n];\r\n\r\nconst SHAPES: Record<EmphasisShape, (quad: Quad, gap: number) => PathCommand[]> = {\r\n box: (quad, gap) => {\r\n const [tl, tr, br, bl] = grown(quad, gap);\r\n return [{ type: \"M\", x: tl.x, y: tl.y }, ...[tr, br, bl].map((p): PathCommand => ({ type: \"L\", x: p.x, y: p.y })), { type: \"Z\" }];\r\n },\r\n // The ellipse through the grown box's corners.\r\n circle: (quad, gap) => {\r\n const [tl, tr, br, bl] = grown(quad, gap);\r\n const centre = between(tl, br);\r\n const across = { x: ((tr.x - tl.x) / 2) * Math.SQRT2, y: ((tr.y - tl.y) / 2) * Math.SQRT2 };\r\n const up = { x: ((tl.x - bl.x) / 2) * Math.SQRT2, y: ((tl.y - bl.y) / 2) * Math.SQRT2 };\r\n const at = (a: number, u: number) => add(add(centre, across, a), up, u);\r\n const arc = (c1: Vector2, c2: Vector2, end: Vector2): PathCommand => ({\r\n type: \"C\", x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: end.x, y: end.y,\r\n });\r\n const k = QUARTER;\r\n const start = at(0, 1);\r\n return [\r\n { type: \"M\", x: start.x, y: start.y },\r\n arc(at(k, 1), at(1, k), at(1, 0)),\r\n arc(at(1, -k), at(k, -1), at(0, -1)),\r\n arc(at(-k, -1), at(-1, -k), at(-1, 0)),\r\n arc(at(-1, k), at(-k, 1), start),\r\n { type: \"Z\" },\r\n ];\r\n },\r\n underline: (quad, gap) => {\r\n const [, , br, bl] = quad;\r\n const down = heading(quad[0], bl).unit;\r\n return line(add(bl, down, gap), add(br, down, gap));\r\n },\r\n cross: (quad, gap) => {\r\n const [tl, tr, br, bl] = grown(quad, gap);\r\n return [...line(tl, br), ...line(bl, tr)];\r\n },\r\n};\r\n\r\n/**\r\n * A box, a circle, an underline or a cross drawn on a node, or on one part of\r\n * a formula. `progressTo` draws it on, and `retargetTo` slides it to another.\r\n */\r\n@node({\r\n key: \"emphasisMark\",\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n})\r\nexport class EmphasisMark extends FollowMark<EmphasisMarkProps> {\r\n @property({ default: \"box\", options: [\"box\", \"circle\", \"underline\", \"cross\"], animatable: false }) declare shape: EmphasisShape;\r\n /** The room between the target and the mark. (`gap` is a layout's.) */\r\n @property({ default: 10, unit: \"px\" }) declare clearance: number;\r\n\r\n @strokeProperty({ default: { weight: 3, fill: \"#facc15\", align: \"center\", cap: \"round\", join: \"round\" } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<EmphasisMark, EmphasisMarkProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n protected outline(quad: Quad): PathCommand[] {\r\n return SHAPES[this.shape](quad, this.clearance);\r\n }\r\n}\r\n"]}
|