@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,5 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
1
|
+
import { type Color, type NodeOf, type NodeView, type NormalizedColor, type Vector2, 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
|
+
import { type FollowProps } from "../kit/follow.js";
|
|
3
3
|
export type BraceSide = "below" | "above" | "left" | "right";
|
|
4
4
|
export interface CurlyBraceProps extends FollowProps {
|
|
5
5
|
side?: BraceSide;
|
|
@@ -17,30 +17,64 @@ export interface CurlyBraceProps extends FollowProps {
|
|
|
17
17
|
* two points when it names neither, with an optional label at its tip. A label
|
|
18
18
|
* written between dollar signs is typeset.
|
|
19
19
|
*/
|
|
20
|
-
export declare
|
|
21
|
-
side:
|
|
20
|
+
export declare const CurlyBrace: import("@motionscript/sdk").Component<"curlyBrace", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
21
|
+
side: import("@motionscript/sdk").Type<"left" | "right" | "below" | "above", "left" | "right" | "below" | "above", false>;
|
|
22
22
|
/** The two ends of a brace that follows nothing, from the brace's own position. It bulges to the left of tail to head. */
|
|
23
|
-
tail: Vector2
|
|
24
|
-
head: Vector2
|
|
23
|
+
tail: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
24
|
+
head: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
25
25
|
/** The room between the target and the brace. (`gap` is a layout's.) */
|
|
26
|
-
clearance: number
|
|
26
|
+
clearance: import("@motionscript/sdk").Type<number, number, false>;
|
|
27
27
|
/** How far the brace reaches from its ends to its tip. (`depth` is a node's place in 3D.) */
|
|
28
|
-
reach: number
|
|
29
|
-
label: string
|
|
30
|
-
labelSize: number
|
|
31
|
-
labelColor: Color
|
|
32
|
-
fontFamily: string
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
28
|
+
reach: import("@motionscript/sdk").Type<number, number, false>;
|
|
29
|
+
label: import("@motionscript/sdk").Type<string, string, false>;
|
|
30
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
31
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
32
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
33
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
34
|
+
part: import("@motionscript/sdk").Type<string, string, false>;
|
|
35
|
+
occurrence: import("@motionscript/sdk").Type<number, number, false>;
|
|
36
|
+
retarget: import("@motionscript/sdk").Type<import("../index.js").Retarget | null, import("../index.js").Retarget | null, false>;
|
|
37
|
+
retargetOn: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, true>;
|
|
38
|
+
retargetFrom: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, true>;
|
|
39
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
40
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
41
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
42
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
43
|
+
}>, {
|
|
44
|
+
retargetTo: {
|
|
45
|
+
readonly on: import("@motionscript/sdk").Type<string | undefined, string | undefined, false>;
|
|
46
|
+
readonly part: import("@motionscript/sdk").Type<string | undefined, string | undefined, false>;
|
|
47
|
+
readonly occurrence: import("@motionscript/sdk").Type<number, number, false>;
|
|
48
|
+
};
|
|
49
|
+
strokeTo: readonly ["stroke"];
|
|
50
|
+
shadowTo: readonly ["shadow"];
|
|
51
|
+
progressTo: readonly ["start", "end"];
|
|
52
|
+
flash: {
|
|
53
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
54
|
+
};
|
|
55
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
56
|
+
side: import("@motionscript/sdk").Type<"left" | "right" | "below" | "above", "left" | "right" | "below" | "above", false>;
|
|
57
|
+
/** The two ends of a brace that follows nothing, from the brace's own position. It bulges to the left of tail to head. */
|
|
58
|
+
tail: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
59
|
+
head: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
|
|
60
|
+
/** The room between the target and the brace. (`gap` is a layout's.) */
|
|
61
|
+
clearance: import("@motionscript/sdk").Type<number, number, false>;
|
|
62
|
+
/** How far the brace reaches from its ends to its tip. (`depth` is a node's place in 3D.) */
|
|
63
|
+
reach: import("@motionscript/sdk").Type<number, number, false>;
|
|
64
|
+
label: import("@motionscript/sdk").Type<string, string, false>;
|
|
65
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
66
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
67
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
68
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
69
|
+
part: import("@motionscript/sdk").Type<string, string, false>;
|
|
70
|
+
occurrence: import("@motionscript/sdk").Type<number, number, false>;
|
|
71
|
+
retarget: import("@motionscript/sdk").Type<import("../index.js").Retarget | null, import("../index.js").Retarget | null, false>;
|
|
72
|
+
retargetOn: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, true>;
|
|
73
|
+
retargetFrom: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, true>;
|
|
74
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
75
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
76
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
77
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
78
|
+
}>, null>>;
|
|
79
|
+
export type CurlyBrace = NodeOf<typeof CurlyBrace>;
|
|
46
80
|
//# sourceMappingURL=curly-brace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curly-brace.d.ts","sourceRoot":"","sources":["../../src/annotate/curly-brace.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"curly-brace.d.ts","sourceRoot":"","sources":["../../src/annotate/curly-brace.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,eAAe,EAEpB,KAAK,OAAO,EAEZ,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAEH,KAAK,WAAW,EACnB,MAAM,eAAe,CAAC;AAIvB,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;AAE7D,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAChD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAkED;;;;GAIG;AACH,eAAO,MAAM,UAAU;;IA1DnB,0HAA0H;;;IAG1H,wEAAwE;;IAExE,6FAA6F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAL7F,0HAA0H;;;IAG1H,wEAAwE;;IAExE,6FAA6F;;;;;;;;;;;;;;;;UAwF/F,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
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";
|
|
1
|
+
import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
|
|
8
2
|
import { braceOutline } from "../kit/brace.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
3
|
+
import { listed, painted } from "../kit/component.js";
|
|
4
|
+
import { add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, heading, outlineBounds, OWN_FRAME, resting, } from "../kit/follow.js";
|
|
5
|
+
import { drawLabels, loadFormulas } from "../kit/furniture.js";
|
|
6
|
+
import { strokeShape } from "../kit/mark.js";
|
|
11
7
|
/** 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
8
|
const EDGE = {
|
|
13
9
|
below: [2, 3],
|
|
@@ -15,100 +11,89 @@ const EDGE = {
|
|
|
15
11
|
left: [3, 0],
|
|
16
12
|
right: [1, 2],
|
|
17
13
|
};
|
|
14
|
+
const state = {
|
|
15
|
+
...FOLLOW_STATE,
|
|
16
|
+
side: listed(["below", "above", "left", "right"], "below", { animatable: false }),
|
|
17
|
+
/** The two ends of a brace that follows nothing, from the brace's own position. It bulges to the left of tail to head. */
|
|
18
|
+
tail: Types.vector2({ x: -80, y: 0 }),
|
|
19
|
+
head: Types.vector2({ x: 80, y: 0 }),
|
|
20
|
+
/** The room between the target and the brace. (`gap` is a layout's.) */
|
|
21
|
+
clearance: Types.number(8, { min: 0, unit: "px" }),
|
|
22
|
+
/** How far the brace reaches from its ends to its tip. (`depth` is a node's place in 3D.) */
|
|
23
|
+
reach: Types.number(18, { min: 2, unit: "px" }),
|
|
24
|
+
label: Types.text("", { animatable: false }),
|
|
25
|
+
labelSize: Types.number(28, { min: 1, unit: "px" }),
|
|
26
|
+
labelColor: Types.color("#e5e7eb"),
|
|
27
|
+
fontFamily: Types.text("", { animatable: false }),
|
|
28
|
+
};
|
|
29
|
+
/** Whether the brace follows nothing, and so spans its own two points. */
|
|
30
|
+
function spans(s, parted) {
|
|
31
|
+
return !s.retarget && resting(s, parted) === null;
|
|
32
|
+
}
|
|
33
|
+
/** No target: the span itself, as an edge with nothing above it. */
|
|
34
|
+
function quadOf(s, parted) {
|
|
35
|
+
return spans(s, parted) ? [s.head, s.tail, s.tail, s.head] : followedQuad(s, parted);
|
|
36
|
+
}
|
|
37
|
+
/** The edge the brace runs along, pushed out by the gap, and the way it bulges. */
|
|
38
|
+
function edgeOf(s, parted, quad) {
|
|
39
|
+
const [i, j] = spans(s, parted) ? [1, 0] : EDGE[s.side];
|
|
40
|
+
const { unit } = heading(quad[i], quad[j]);
|
|
41
|
+
// Left of the edge's own direction, in a y-up frame.
|
|
42
|
+
const out = { x: -unit.y, y: unit.x };
|
|
43
|
+
return { from: add(quad[i], out, s.clearance), to: add(quad[j], out, s.clearance), out };
|
|
44
|
+
}
|
|
45
|
+
function outline(s, parted) {
|
|
46
|
+
const quad = quadOf(s, parted);
|
|
47
|
+
if (!quad)
|
|
48
|
+
return [];
|
|
49
|
+
const { from, to, out } = edgeOf(s, parted, quad);
|
|
50
|
+
return braceOutline(from, to, out, s.reach);
|
|
51
|
+
}
|
|
52
|
+
/** One of the two ends to drag, while the brace spans them. */
|
|
53
|
+
const end = (which) => ({
|
|
54
|
+
at: (s) => (spans(s, container(null, s)) ? s[which] : null),
|
|
55
|
+
value: (at) => ({ x: at.x, y: at.y }),
|
|
56
|
+
});
|
|
18
57
|
/**
|
|
19
58
|
* A curly brace along one side of a node or of a part of a formula, or between
|
|
20
59
|
* two points when it names neither, with an optional label at its tip. A label
|
|
21
60
|
* written between dollar signs is typeset.
|
|
22
61
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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 };
|
|
62
|
+
export const CurlyBrace = component2d({
|
|
63
|
+
key: "curlyBrace",
|
|
64
|
+
state,
|
|
65
|
+
defaults: { stroke: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" }, width: "hug", height: "hug" },
|
|
66
|
+
load: (loader, s) => {
|
|
67
|
+
if (s.label !== "" && s.fontFamily !== "")
|
|
68
|
+
loader.font(s.fontFamily);
|
|
69
|
+
loadFormulas(loader, [s.label]);
|
|
70
|
+
},
|
|
71
|
+
commands: FOLLOW_COMMANDS,
|
|
72
|
+
handles: { tail: end("tail"), head: end("head") },
|
|
73
|
+
measure: () => ({ width: 0, height: 0 }),
|
|
74
|
+
bounds: (_size, s) => outlineBounds(outline(s, container(null, s))),
|
|
75
|
+
render: (ctx, s) => {
|
|
76
|
+
const parted = container(ctx, s);
|
|
77
|
+
const data = outline(s, parted);
|
|
78
|
+
const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;
|
|
79
|
+
painted(ctx, () => {
|
|
80
|
+
if (shape)
|
|
81
|
+
ctx.draw(shape().shadow(s.shadow).fill([]));
|
|
82
|
+
if (s.label === "")
|
|
83
|
+
return;
|
|
84
|
+
const quad = quadOf(s, parted);
|
|
85
|
+
if (!quad)
|
|
86
|
+
return;
|
|
87
|
+
const { from, to, out } = edgeOf(s, parted, quad);
|
|
88
|
+
const reach = Math.min(s.reach, heading(from, to).length / 2) + s.labelSize * 0.75;
|
|
89
|
+
const at = add(between(from, to), out, reach);
|
|
90
|
+
const align = out.x > 0.5 ? "left" : out.x < -0.5 ? "right" : "center";
|
|
91
|
+
const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor };
|
|
92
|
+
ctx.draw(drawLabels([{ text: s.label, at, align }], style));
|
|
93
|
+
}, () => {
|
|
94
|
+
if (shape)
|
|
95
|
+
strokeShape(ctx, shape, s);
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
});
|
|
114
99
|
//# sourceMappingURL=curly-brace.js.map
|
|
@@ -1 +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,CAA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E,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"]}
|
|
1
|
+
{"version":3,"file":"curly-brace.js","sourceRoot":"","sources":["../../src/annotate/curly-brace.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAcR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EACH,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,GAEnH,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAgB1C,2HAA2H;AAC3H,MAAM,IAAI,GAAwC;IAC9C,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC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C,CAAC;YAC/B,IAAI,CAAC,IAAI;gBAAE,OAAO;YAClB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;YAClD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC;YACnF,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAC9C,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;YACvE,MAAM,KAAK,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,UAA6B,EAAE,CAAC;YAC1G,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;QAChE,CAAC,EACD,GAAG,EAAE;YACD,IAAI,KAAK;gBAAE,WAAW,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAC1C,CAAC,CACJ,CAAC;IACN,CAAC;CACJ,CAAC,CAAC","sourcesContent":["import {\r\n component2d,\r\n Graphics2D,\r\n Types,\r\n type Color,\r\n type NodeOf,\r\n type NodeView,\r\n type NormalizedColor,\r\n type PathCommand,\r\n type Vector2,\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 { braceOutline } from \"../kit/brace\";\r\nimport { listed, painted } from \"../kit/component\";\r\nimport {\r\n add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, heading, outlineBounds, OWN_FRAME, resting,\r\n type FollowProps, type FollowValues, type Quad,\r\n} from \"../kit/follow\";\r\nimport { drawLabels, loadFormulas } from \"../kit/furniture\";\r\nimport { strokeShape } from \"../kit/mark\";\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\nconst state = {\r\n ...FOLLOW_STATE,\r\n side: listed([\"below\", \"above\", \"left\", \"right\"], \"below\", { animatable: false }),\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 tail: Types.vector2({ x: -80, y: 0 }),\r\n head: Types.vector2({ x: 80, y: 0 }),\r\n /** The room between the target and the brace. (`gap` is a layout's.) */\r\n clearance: Types.number(8, { min: 0, unit: \"px\" }),\r\n /** How far the brace reaches from its ends to its tip. (`depth` is a node's place in 3D.) */\r\n reach: Types.number(18, { min: 2, unit: \"px\" }),\r\n label: Types.text(\"\", { animatable: false }),\r\n labelSize: Types.number(28, { min: 1, unit: \"px\" }),\r\n labelColor: Types.color(\"#e5e7eb\"),\r\n fontFamily: Types.text(\"\", { animatable: false }),\r\n};\r\n\r\ninterface BraceValues extends FollowValues {\r\n readonly side: BraceSide;\r\n readonly tail: Vector2;\r\n readonly head: Vector2;\r\n readonly clearance: number;\r\n readonly reach: number;\r\n}\r\n\r\n/** Whether the brace follows nothing, and so spans its own two points. */\r\nfunction spans(s: BraceValues, parted: NodeView | null): boolean {\r\n return !s.retarget && resting(s, parted) === null;\r\n}\r\n\r\n/** No target: the span itself, as an edge with nothing above it. */\r\nfunction quadOf(s: BraceValues, parted: NodeView | null): Quad | null {\r\n return spans(s, parted) ? [s.head, s.tail, s.tail, s.head] : followedQuad(s, parted);\r\n}\r\n\r\n/** The edge the brace runs along, pushed out by the gap, and the way it bulges. */\r\nfunction edgeOf(s: BraceValues, parted: NodeView | null, quad: Quad): { from: Vector2; to: Vector2; out: Vector2 } {\r\n const [i, j] = spans(s, parted) ? [1, 0] : EDGE[s.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, s.clearance), to: add(quad[j], out, s.clearance), out };\r\n}\r\n\r\nfunction outline(s: BraceValues, parted: NodeView | null): PathCommand[] {\r\n const quad = quadOf(s, parted);\r\n if (!quad) return [];\r\n const { from, to, out } = edgeOf(s, parted, quad);\r\n return braceOutline(from, to, out, s.reach);\r\n}\r\n\r\n/** One of the two ends to drag, while the brace spans them. */\r\nconst end = (which: \"tail\" | \"head\") => ({\r\n at: (s: BraceValues) => (spans(s, container(null, s)) ? s[which] : null),\r\n value: (at: Vector2) => ({ x: at.x, y: at.y }),\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\nexport const CurlyBrace = component2d({\r\n key: \"curlyBrace\",\r\n state,\r\n defaults: { stroke: { weight: 3, fill: \"#e5e7eb\", align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\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: FOLLOW_COMMANDS,\r\n handles: { tail: end(\"tail\"), head: end(\"head\") },\r\n measure: () => ({ width: 0, height: 0 }),\r\n bounds: (_size, s) => outlineBounds(outline(s, container(null, s))),\r\n render: (ctx, s) => {\r\n const parted = container(ctx, s);\r\n const data = outline(s, parted);\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 === \"\") return;\r\n const quad = quadOf(s, parted);\r\n if (!quad) return;\r\n const { from, to, out } = edgeOf(s, parted, quad);\r\n const reach = Math.min(s.reach, heading(from, to).length / 2) + s.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: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor };\r\n ctx.draw(drawLabels([{ text: s.label, at, align }], 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 CurlyBrace = NodeOf<typeof CurlyBrace>;\r\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
1
|
+
import { type NodeOf, type NodeView, 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
|
+
import { type FollowProps } from "../kit/follow.js";
|
|
3
3
|
export type EmphasisShape = "box" | "circle" | "underline" | "cross";
|
|
4
4
|
export interface EmphasisMarkProps extends FollowProps {
|
|
5
5
|
shape?: EmphasisShape;
|
|
@@ -9,12 +9,46 @@ export interface EmphasisMarkProps extends FollowProps {
|
|
|
9
9
|
* A box, a circle, an underline or a cross drawn on a node, or on one part of
|
|
10
10
|
* a formula. `progressTo` draws it on, and `retargetTo` slides it to another.
|
|
11
11
|
*/
|
|
12
|
-
export declare
|
|
13
|
-
shape:
|
|
12
|
+
export declare const EmphasisMark: import("@motionscript/sdk").Component<"emphasisMark", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
13
|
+
shape: import("@motionscript/sdk").Type<"box" | "circle" | "underline" | "cross", "box" | "circle" | "underline" | "cross", false>;
|
|
14
14
|
/** The room between the target and the mark. (`gap` is a layout's.) */
|
|
15
|
-
clearance: number
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
clearance: import("@motionscript/sdk").Type<number, number, false>;
|
|
16
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
17
|
+
part: import("@motionscript/sdk").Type<string, string, false>;
|
|
18
|
+
occurrence: import("@motionscript/sdk").Type<number, number, false>;
|
|
19
|
+
retarget: import("@motionscript/sdk").Type<import("../index.js").Retarget | null, import("../index.js").Retarget | null, false>;
|
|
20
|
+
retargetOn: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, true>;
|
|
21
|
+
retargetFrom: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, true>;
|
|
22
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
23
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
24
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
25
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
26
|
+
}>, {
|
|
27
|
+
retargetTo: {
|
|
28
|
+
readonly on: import("@motionscript/sdk").Type<string | undefined, string | undefined, false>;
|
|
29
|
+
readonly part: import("@motionscript/sdk").Type<string | undefined, string | undefined, false>;
|
|
30
|
+
readonly occurrence: import("@motionscript/sdk").Type<number, number, false>;
|
|
31
|
+
};
|
|
32
|
+
strokeTo: readonly ["stroke"];
|
|
33
|
+
shadowTo: readonly ["shadow"];
|
|
34
|
+
progressTo: readonly ["start", "end"];
|
|
35
|
+
flash: {
|
|
36
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
37
|
+
};
|
|
38
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
39
|
+
shape: import("@motionscript/sdk").Type<"box" | "circle" | "underline" | "cross", "box" | "circle" | "underline" | "cross", false>;
|
|
40
|
+
/** The room between the target and the mark. (`gap` is a layout's.) */
|
|
41
|
+
clearance: import("@motionscript/sdk").Type<number, number, false>;
|
|
42
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
43
|
+
part: import("@motionscript/sdk").Type<string, string, false>;
|
|
44
|
+
occurrence: import("@motionscript/sdk").Type<number, number, false>;
|
|
45
|
+
retarget: import("@motionscript/sdk").Type<import("../index.js").Retarget | null, import("../index.js").Retarget | null, false>;
|
|
46
|
+
retargetOn: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, true>;
|
|
47
|
+
retargetFrom: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, true>;
|
|
48
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
49
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
50
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
51
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
52
|
+
}>, null>>;
|
|
53
|
+
export type EmphasisMark = NodeOf<typeof EmphasisMark>;
|
|
20
54
|
//# sourceMappingURL=emphasis-mark.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emphasis-mark.d.ts","sourceRoot":"","sources":["../../src/annotate/emphasis-mark.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,
|
|
1
|
+
{"version":3,"file":"emphasis-mark.d.ts","sourceRoot":"","sources":["../../src/annotate/emphasis-mark.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,MAAM,EACX,KAAK,QAAQ,EAIb,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAC6G,KAAK,WAAW,EACnI,MAAM,eAAe,CAAC;AAGvB,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;AAgED;;;GAGG;AACH,eAAO,MAAM,YAAY;;IAlBrB,uEAAuE;;;;;;;;;;;;;;;;;;;;;;;;;;IAAvE,uEAAuE;;;;;;;;;;;;UAsCzE,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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";
|
|
1
|
+
import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { listed, painted } from "../kit/component.js";
|
|
3
|
+
import { add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, grown, heading, outlineBounds, OWN_FRAME, } from "../kit/follow.js";
|
|
4
|
+
import { strokeShape } from "../kit/mark.js";
|
|
9
5
|
/** How far a cubic's handle reaches to draw a quarter of an ellipse. */
|
|
10
6
|
const QUARTER = 0.5523;
|
|
11
7
|
const line = (a, b) => [
|
|
@@ -48,34 +44,37 @@ const SHAPES = {
|
|
|
48
44
|
return [...line(tl, br), ...line(bl, tr)];
|
|
49
45
|
},
|
|
50
46
|
};
|
|
47
|
+
const state = {
|
|
48
|
+
...FOLLOW_STATE,
|
|
49
|
+
shape: listed(["box", "circle", "underline", "cross"], "box", { animatable: false }),
|
|
50
|
+
/** The room between the target and the mark. (`gap` is a layout's.) */
|
|
51
|
+
clearance: Types.number(10, { unit: "px" }),
|
|
52
|
+
};
|
|
53
|
+
function outline(s, parted) {
|
|
54
|
+
const quad = followedQuad(s, parted);
|
|
55
|
+
return quad ? SHAPES[s.shape](quad, s.clearance) : [];
|
|
56
|
+
}
|
|
51
57
|
/**
|
|
52
58
|
* A box, a circle, an underline or a cross drawn on a node, or on one part of
|
|
53
59
|
* a formula. `progressTo` draws it on, and `retargetTo` slides it to another.
|
|
54
60
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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 };
|
|
61
|
+
export const EmphasisMark = component2d({
|
|
62
|
+
key: "emphasisMark",
|
|
63
|
+
state,
|
|
64
|
+
defaults: { stroke: { weight: 3, fill: "#facc15", align: "center", cap: "round", join: "round" }, width: "hug", height: "hug" },
|
|
65
|
+
commands: FOLLOW_COMMANDS,
|
|
66
|
+
measure: () => ({ width: 0, height: 0 }),
|
|
67
|
+
bounds: (_size, s) => outlineBounds(outline(s, container(null, s))),
|
|
68
|
+
render: (ctx, s) => {
|
|
69
|
+
const data = outline(s, container(ctx, s));
|
|
70
|
+
const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;
|
|
71
|
+
painted(ctx, () => {
|
|
72
|
+
if (shape)
|
|
73
|
+
ctx.draw(shape().shadow(s.shadow).fill([]));
|
|
74
|
+
}, () => {
|
|
75
|
+
if (shape)
|
|
76
|
+
strokeShape(ctx, shape, s);
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
});
|
|
81
80
|
//# sourceMappingURL=emphasis-mark.js.map
|
|
@@ -1 +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;AACxE,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,MAAM,IAAI,GAAG,CAAC,CAAU,EAAE,CAAU,EAAiB,EAAE,CAAC;IACpD,EAAE,IAAI,EAAE,GAAG,EAAE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G;AAOI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,UAA6B;IAQ3D,YAAY,KAAmD;QAC3D,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACvB,CAAC;IAES,OAAO,CAAC,IAAU;QACxB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACJ,CAAA;AAd8G;IAA1G,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;2CAA8B;AAEjF;IAA9C,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;+CAA2B;AAGzD;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;4CACnF;AANd,YAAY;IANxB,IAAI,CAAC;QACF,GAAG,EAAE,cAAc;QACnB,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,YAAY,CAexB","sourcesContent":["import {\r\n node,\r\n property,\r\n strokeProperty,\r\n type NodeConfig,\r\n type PathCommand,\r\n type Stroke,\r\n type Vector2,\r\n} from \"@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"]}
|
|
1
|
+
{"version":3,"file":"emphasis-mark.js","sourceRoot":"","sources":["../../src/annotate/emphasis-mark.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAYR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EACH,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,GACjH,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAS1C,wEAAwE;AACxE,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,MAAM,IAAI,GAAG,CAAC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CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QACf,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAClI,OAAO,CACH,GAAG,EACH,GAAG,EAAE;YACD,IAAI,KAAK;gBAAE,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3D,CAAC,EACD,GAAG,EAAE;YACD,IAAI,KAAK;gBAAE,WAAW,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAC1C,CAAC,CACJ,CAAC;IACN,CAAC;CACJ,CAAC,CAAC","sourcesContent":["import {\r\n component2d,\r\n Graphics2D,\r\n Types,\r\n type NodeOf,\r\n type NodeView,\r\n type PathCommand,\r\n type Vector2,\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, painted } from \"../kit/component\";\r\nimport {\r\n add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, grown, heading, outlineBounds, OWN_FRAME, type FollowProps, type FollowValues, type Quad,\r\n} from \"../kit/follow\";\r\nimport { strokeShape } from \"../kit/mark\";\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\nconst state = {\r\n ...FOLLOW_STATE,\r\n shape: listed([\"box\", \"circle\", \"underline\", \"cross\"], \"box\", { animatable: false }),\r\n /** The room between the target and the mark. (`gap` is a layout's.) */\r\n clearance: Types.number(10, { unit: \"px\" }),\r\n};\r\n\r\ninterface EmphasisValues extends FollowValues {\r\n readonly shape: EmphasisShape;\r\n readonly clearance: number;\r\n}\r\n\r\nfunction outline(s: EmphasisValues, parted: NodeView | null): PathCommand[] {\r\n const quad = followedQuad(s, parted);\r\n return quad ? SHAPES[s.shape](quad, s.clearance) : [];\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\nexport const EmphasisMark = component2d({\r\n key: \"emphasisMark\",\r\n state,\r\n defaults: { stroke: { weight: 3, fill: \"#facc15\", align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\r\n commands: FOLLOW_COMMANDS,\r\n measure: () => ({ width: 0, height: 0 }),\r\n bounds: (_size, s) => outlineBounds(outline(s, container(null, s))),\r\n render: (ctx, s) => {\r\n const data = outline(s, container(ctx, 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 },\r\n () => {\r\n if (shape) strokeShape(ctx, shape, s);\r\n },\r\n );\r\n },\r\n});\r\n\r\nexport type EmphasisMark = NodeOf<typeof EmphasisMark>;\r\n"]}
|