@motionscript/math 0.1.0-alpha.4 → 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.
Files changed (233) hide show
  1. package/CHANGELOG.md +132 -92
  2. package/README.md +39 -33
  3. package/dist/annotate/angle-mark.d.ts +52 -27
  4. package/dist/annotate/angle-mark.d.ts.map +1 -1
  5. package/dist/annotate/angle-mark.js +80 -115
  6. package/dist/annotate/angle-mark.js.map +1 -1
  7. package/dist/annotate/curly-brace.d.ts +59 -25
  8. package/dist/annotate/curly-brace.d.ts.map +1 -1
  9. package/dist/annotate/curly-brace.js +85 -100
  10. package/dist/annotate/curly-brace.js.map +1 -1
  11. package/dist/annotate/emphasis-mark.d.ts +43 -9
  12. package/dist/annotate/emphasis-mark.d.ts.map +1 -1
  13. package/dist/annotate/emphasis-mark.js +33 -34
  14. package/dist/annotate/emphasis-mark.js.map +1 -1
  15. package/dist/browser/chunks/chunk-ABYBW64J.js +2 -0
  16. package/dist/browser/chunks/chunk-ABYBW64J.js.map +7 -0
  17. package/dist/browser/chunks/chunk-K77KLQX4.js +2 -0
  18. package/dist/browser/chunks/chunk-K77KLQX4.js.map +7 -0
  19. package/dist/browser/index.js +1 -1
  20. package/dist/browser/index.js.map +3 -3
  21. package/dist/browser/kit.js +1 -1
  22. package/dist/browser/manifest.json +1 -1
  23. package/dist/browser/tex.js +1 -1
  24. package/dist/browser/tex.js.map +2 -2
  25. package/dist/engine.d.ts +26 -19
  26. package/dist/engine.d.ts.map +1 -1
  27. package/dist/engine.js +17 -14
  28. package/dist/engine.js.map +1 -1
  29. package/dist/kit/component.d.ts +51 -0
  30. package/dist/kit/component.d.ts.map +1 -0
  31. package/dist/kit/component.js +30 -0
  32. package/dist/kit/component.js.map +1 -0
  33. package/dist/kit/curve.d.ts +22 -11
  34. package/dist/kit/curve.d.ts.map +1 -1
  35. package/dist/kit/curve.js +25 -18
  36. package/dist/kit/curve.js.map +1 -1
  37. package/dist/kit/field-mark.d.ts +58 -35
  38. package/dist/kit/field-mark.d.ts.map +1 -1
  39. package/dist/kit/field-mark.js +100 -120
  40. package/dist/kit/field-mark.js.map +1 -1
  41. package/dist/kit/follow.d.ts +67 -29
  42. package/dist/kit/follow.d.ts.map +1 -1
  43. package/dist/kit/follow.js +114 -110
  44. package/dist/kit/follow.js.map +1 -1
  45. package/dist/kit/furniture.d.ts +3 -1
  46. package/dist/kit/furniture.d.ts.map +1 -1
  47. package/dist/kit/furniture.js +5 -0
  48. package/dist/kit/furniture.js.map +1 -1
  49. package/dist/kit/graph.d.ts +46 -0
  50. package/dist/kit/graph.d.ts.map +1 -0
  51. package/dist/kit/graph.js +90 -0
  52. package/dist/kit/graph.js.map +1 -0
  53. package/dist/kit/mark.d.ts +64 -39
  54. package/dist/kit/mark.d.ts.map +1 -1
  55. package/dist/kit/mark.js +80 -96
  56. package/dist/kit/mark.js.map +1 -1
  57. package/dist/kit/place.d.ts +10 -8
  58. package/dist/kit/place.d.ts.map +1 -1
  59. package/dist/kit/place.js +28 -30
  60. package/dist/kit/place.js.map +1 -1
  61. package/dist/kit/system.d.ts +27 -29
  62. package/dist/kit/system.d.ts.map +1 -1
  63. package/dist/kit/system.js +62 -58
  64. package/dist/kit/system.js.map +1 -1
  65. package/dist/kit/withdrawn.d.ts +3 -3
  66. package/dist/kit/withdrawn.js +3 -3
  67. package/dist/kit/withdrawn.js.map +1 -1
  68. package/dist/marks/curve-area.d.ts +24 -18
  69. package/dist/marks/curve-area.d.ts.map +1 -1
  70. package/dist/marks/curve-area.js +50 -73
  71. package/dist/marks/curve-area.js.map +1 -1
  72. package/dist/marks/drop-lines.d.ts +28 -10
  73. package/dist/marks/drop-lines.d.ts.map +1 -1
  74. package/dist/marks/drop-lines.js +37 -52
  75. package/dist/marks/drop-lines.js.map +1 -1
  76. package/dist/marks/plot-point.d.ts +37 -20
  77. package/dist/marks/plot-point.d.ts.map +1 -1
  78. package/dist/marks/plot-point.js +65 -91
  79. package/dist/marks/plot-point.js.map +1 -1
  80. package/dist/marks/riemann-sum.d.ts +30 -26
  81. package/dist/marks/riemann-sum.d.ts.map +1 -1
  82. package/dist/marks/riemann-sum.js +57 -85
  83. package/dist/marks/riemann-sum.js.map +1 -1
  84. package/dist/marks/tangent-line.d.ts +38 -14
  85. package/dist/marks/tangent-line.d.ts.map +1 -1
  86. package/dist/marks/tangent-line.js +73 -87
  87. package/dist/marks/tangent-line.js.map +1 -1
  88. package/dist/marks/vector-arrow.d.ts +30 -20
  89. package/dist/marks/vector-arrow.d.ts.map +1 -1
  90. package/dist/marks/vector-arrow.js +58 -78
  91. package/dist/marks/vector-arrow.js.map +1 -1
  92. package/dist/nodes.d.ts +13 -5
  93. package/dist/nodes.d.ts.map +1 -1
  94. package/dist/nodes.js +0 -6
  95. package/dist/nodes.js.map +1 -1
  96. package/dist/plots/function-plot.d.ts +107 -43
  97. package/dist/plots/function-plot.d.ts.map +1 -1
  98. package/dist/plots/function-plot.js +146 -177
  99. package/dist/plots/function-plot.js.map +1 -1
  100. package/dist/plots/points-plot.d.ts +34 -19
  101. package/dist/plots/points-plot.d.ts.map +1 -1
  102. package/dist/plots/points-plot.js +31 -58
  103. package/dist/plots/points-plot.js.map +1 -1
  104. package/dist/plots/stream-lines.d.ts +38 -19
  105. package/dist/plots/stream-lines.d.ts.map +1 -1
  106. package/dist/plots/stream-lines.js +60 -79
  107. package/dist/plots/stream-lines.js.map +1 -1
  108. package/dist/plots/traced-path.d.ts +34 -15
  109. package/dist/plots/traced-path.d.ts.map +1 -1
  110. package/dist/plots/traced-path.js +33 -48
  111. package/dist/plots/traced-path.js.map +1 -1
  112. package/dist/plots/vector-field.d.ts +31 -11
  113. package/dist/plots/vector-field.d.ts.map +1 -1
  114. package/dist/plots/vector-field.js +50 -64
  115. package/dist/plots/vector-field.js.map +1 -1
  116. package/dist/structures/network-graph.d.ts +99 -49
  117. package/dist/structures/network-graph.d.ts.map +1 -1
  118. package/dist/structures/network-graph.js +168 -217
  119. package/dist/structures/network-graph.js.map +1 -1
  120. package/dist/structures/sample-space.d.ts +69 -38
  121. package/dist/structures/sample-space.d.ts.map +1 -1
  122. package/dist/structures/sample-space.js +132 -170
  123. package/dist/structures/sample-space.js.map +1 -1
  124. package/dist/systems/axes2d.d.ts +126 -37
  125. package/dist/systems/axes2d.d.ts.map +1 -1
  126. package/dist/systems/axes2d.js +147 -183
  127. package/dist/systems/axes2d.js.map +1 -1
  128. package/dist/systems/number-line.d.ts +51 -28
  129. package/dist/systems/number-line.d.ts.map +1 -1
  130. package/dist/systems/number-line.js +82 -118
  131. package/dist/systems/number-line.js.map +1 -1
  132. package/dist/systems/number-plane.d.ts +92 -31
  133. package/dist/systems/number-plane.d.ts.map +1 -1
  134. package/dist/systems/number-plane.js +142 -149
  135. package/dist/systems/number-plane.js.map +1 -1
  136. package/dist/systems/polar-plane.d.ts +47 -26
  137. package/dist/systems/polar-plane.d.ts.map +1 -1
  138. package/dist/systems/polar-plane.js +107 -133
  139. package/dist/systems/polar-plane.js.map +1 -1
  140. package/dist/tex/index.d.ts.map +1 -1
  141. package/dist/tex/index.js +1 -0
  142. package/dist/tex/index.js.map +1 -1
  143. package/dist/tex/matrix.d.ts +56 -18
  144. package/dist/tex/matrix.d.ts.map +1 -1
  145. package/dist/tex/matrix.js +33 -50
  146. package/dist/tex/matrix.js.map +1 -1
  147. package/dist/tex/node.d.ts +55 -201
  148. package/dist/tex/node.d.ts.map +1 -1
  149. package/dist/tex/node.js +23 -593
  150. package/dist/tex/node.js.map +1 -1
  151. package/dist/tex/typeset.d.ts +133 -0
  152. package/dist/tex/typeset.d.ts.map +1 -0
  153. package/dist/tex/typeset.js +403 -0
  154. package/dist/tex/typeset.js.map +1 -0
  155. package/dist/three/axes3d.d.ts +140 -54
  156. package/dist/three/axes3d.d.ts.map +1 -1
  157. package/dist/three/axes3d.js +159 -204
  158. package/dist/three/axes3d.js.map +1 -1
  159. package/dist/three/curve-plot3d.d.ts +70 -42
  160. package/dist/three/curve-plot3d.d.ts.map +1 -1
  161. package/dist/three/curve-plot3d.js +97 -132
  162. package/dist/three/curve-plot3d.js.map +1 -1
  163. package/dist/three/entries.d.ts +17 -0
  164. package/dist/three/entries.d.ts.map +1 -0
  165. package/dist/three/entries.js +15 -0
  166. package/dist/three/entries.js.map +1 -0
  167. package/dist/three/plot-point3d.d.ts +57 -12
  168. package/dist/three/plot-point3d.d.ts.map +1 -1
  169. package/dist/three/plot-point3d.js +27 -53
  170. package/dist/three/plot-point3d.js.map +1 -1
  171. package/dist/three/space.d.ts +17 -2
  172. package/dist/three/space.d.ts.map +1 -1
  173. package/dist/three/space.js +19 -8
  174. package/dist/three/space.js.map +1 -1
  175. package/dist/three/surface-plot3d.d.ts +131 -49
  176. package/dist/three/surface-plot3d.d.ts.map +1 -1
  177. package/dist/three/surface-plot3d.js +227 -261
  178. package/dist/three/surface-plot3d.js.map +1 -1
  179. package/dist/three/vector-arrow3d.d.ts +58 -16
  180. package/dist/three/vector-arrow3d.d.ts.map +1 -1
  181. package/dist/three/vector-arrow3d.js +48 -67
  182. package/dist/three/vector-arrow3d.js.map +1 -1
  183. package/package.json +4 -4
  184. package/src/annotate/angle-mark.ts +95 -105
  185. package/src/annotate/curly-brace.ts +107 -85
  186. package/src/annotate/emphasis-mark.ts +55 -26
  187. package/src/engine.ts +35 -21
  188. package/src/kit/component.ts +57 -0
  189. package/src/kit/curve.ts +38 -20
  190. package/src/kit/field-mark.ts +124 -108
  191. package/src/kit/follow.ts +146 -120
  192. package/src/kit/furniture.ts +6 -1
  193. package/src/kit/graph.ts +116 -0
  194. package/src/kit/mark.ts +135 -114
  195. package/src/kit/place.ts +32 -56
  196. package/src/kit/system.ts +77 -71
  197. package/src/kit/withdrawn.ts +3 -3
  198. package/src/marks/curve-area.ts +65 -65
  199. package/src/marks/drop-lines.ts +50 -42
  200. package/src/marks/plot-point.ts +77 -82
  201. package/src/marks/riemann-sum.ts +73 -72
  202. package/src/marks/tangent-line.ts +87 -71
  203. package/src/marks/vector-arrow.ts +73 -73
  204. package/src/nodes.ts +41 -5
  205. package/src/plots/function-plot.ts +155 -171
  206. package/src/plots/points-plot.ts +46 -50
  207. package/src/plots/stream-lines.ts +75 -66
  208. package/src/plots/traced-path.ts +51 -33
  209. package/src/plots/vector-field.ts +68 -49
  210. package/src/structures/network-graph.ts +168 -185
  211. package/src/structures/sample-space.ts +149 -148
  212. package/src/systems/axes2d.ts +165 -156
  213. package/src/systems/number-line.ts +91 -92
  214. package/src/systems/number-plane.ts +149 -120
  215. package/src/systems/polar-plane.ts +117 -116
  216. package/src/tex/index.ts +2 -1
  217. package/src/tex/matrix.ts +62 -40
  218. package/src/tex/node.ts +54 -621
  219. package/src/tex/typeset.ts +461 -0
  220. package/src/three/axes3d.ts +182 -161
  221. package/src/three/curve-plot3d.ts +107 -110
  222. package/src/three/entries.ts +42 -0
  223. package/src/three/plot-point3d.ts +42 -45
  224. package/src/three/space.ts +34 -9
  225. package/src/three/surface-plot3d.ts +312 -323
  226. package/src/three/vector-arrow3d.ts +65 -54
  227. package/dist/browser/chunks/chunk-3GJB6AVO.js +0 -2
  228. package/dist/browser/chunks/chunk-3GJB6AVO.js.map +0 -7
  229. package/dist/browser/chunks/chunk-D5WHCVBC.js +0 -2
  230. package/dist/browser/chunks/chunk-D5WHCVBC.js.map +0 -7
  231. package/dist/browser/chunks/chunk-WL4KEX7Y.js +0 -2
  232. package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +0 -7
  233. package/src/kit/placement.ts +0 -8
@@ -1,14 +1,8 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { colorProperty, command, Graphics2D, node, PaintNode, pathOps, property, strokeProperty, withdraw, } from "@motionscript/sdk";
8
- import { declareFormulas, drawLabels } from "../kit/furniture.js";
9
- import { stated } from "../kit/geometry.js";
10
- import { FILL_PAINT } from "../kit/withdrawn.js";
11
- const OWN_FRAME = [-1, -1, 1, 1];
1
+ import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
2
+ import { listed, omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component.js";
3
+ import { outlineBounds, OWN_FRAME } from "../kit/follow.js";
4
+ import { drawLabels, loadFormulas } from "../kit/furniture.js";
5
+ import { strokeShape } from "../kit/mark.js";
12
6
  /** Degrees of arc per drawn segment. */
13
7
  const ARC_STEP = 4;
14
8
  /** How close to a right angle `auto` draws the square. */
@@ -17,116 +11,87 @@ const point = (radius, degrees) => {
17
11
  const turn = (degrees * Math.PI) / 180;
18
12
  return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };
19
13
  };
14
+ const state = {
15
+ // It is only an outline.
16
+ ...omit(PAINT, "fill"),
17
+ fromAngle: Types.number(0, { unit: "°" }),
18
+ toAngle: Types.number(60, { unit: "°" }),
19
+ radius: Types.number(48, { min: 0, unit: "px" }),
20
+ /** `auto` draws the square where the angle is a right one. */
21
+ corner: listed(["auto", "arc", "square"], "auto", { animatable: false }),
22
+ /** Text, a formula between dollar signs, or `°` for the angle's own size. */
23
+ label: Types.text("", { animatable: false }),
24
+ labelSize: Types.number(24, { min: 1, unit: "px" }),
25
+ labelColor: Types.color("#e5e7eb"),
26
+ fontFamily: Types.text("", { animatable: false }),
27
+ /** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */
28
+ value: Types.number(0, { private: true }),
29
+ };
20
30
  /**
21
31
  * The mark of an angle at the node's own position: an arc from one direction
22
32
  * to another, or the small square of a right angle, with an optional label.
23
33
  * Directions are degrees counter-clockwise from the right, so binding one to a
24
34
  * variable opens and closes the angle. A label of `°` shows the angle's size.
25
35
  */
26
- let AngleMark = class AngleMark extends PaintNode {
27
- constructor(props) {
28
- super(props ?? {});
29
- }
30
- /** Grow or shrink the mark. */
31
- radiusTo(args) {
32
- return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
33
- }
34
- /** The angle marked, in degrees: positive counter-clockwise. */
35
- get value() {
36
- return this.toAngle - this.fromAngle;
37
- }
38
- declareAssets(assets) {
39
- super.declareAssets(assets);
40
- if (this.label !== "" && this.fontFamily !== "")
41
- assets.font(this.fontFamily);
42
- declareFormulas(assets, [this.label]);
36
+ export const AngleMark = component2d({
37
+ key: "angleMark",
38
+ state,
39
+ defaults: { stroke: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" }, width: "hug", height: "hug", value: (s) => angleOf(s) },
40
+ load: (loader, s) => {
41
+ if (s.label !== "" && s.fontFamily !== "")
42
+ loader.font(s.fontFamily);
43
+ loadFormulas(loader, [s.label]);
44
+ },
45
+ commands: {
46
+ ...omit(PAINT_COMMANDS, "fillTo"),
47
+ /** Grow or shrink the mark. */
48
+ radiusTo: { args: ["radius"] },
49
+ },
50
+ measure: () => ({ width: 0, height: 0 }),
51
+ bounds: (_size, s) => outlineBounds(outline(s)),
52
+ render: (ctx, s) => {
53
+ const data = outline(s);
54
+ const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;
55
+ painted(ctx, () => {
56
+ if (shape)
57
+ ctx.draw(shape().shadow(s.shadow).fill([]));
58
+ if (s.label === "" || s.radius <= 0)
59
+ return;
60
+ const text = s.label === "°" ? `${Math.round(Math.abs(s.value) * 10) / 10}°` : s.label;
61
+ const at = point(s.radius + s.labelSize * 0.9, (s.fromAngle + s.toAngle) / 2);
62
+ const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor };
63
+ ctx.draw(drawLabels([{ text, at, align: "center" }], style));
64
+ }, () => {
65
+ if (shape)
66
+ strokeShape(ctx, shape, s);
67
+ });
68
+ },
69
+ });
70
+ /** The angle a mark marks, in degrees: positive counter-clockwise. */
71
+ export function angleOf(s) {
72
+ return s.toAngle - s.fromAngle;
73
+ }
74
+ function outline({ fromAngle, toAngle, radius, corner }) {
75
+ const sweep = toAngle - fromAngle;
76
+ if (radius <= 0 || sweep === 0)
77
+ return [];
78
+ const square = corner === "square" || (corner === "auto" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);
79
+ if (square) {
80
+ const side = radius * 0.6;
81
+ const a = point(side, fromAngle);
82
+ const b = point(side, toAngle);
83
+ return [
84
+ { type: "M", x: a.x, y: a.y },
85
+ { type: "L", x: a.x + b.x, y: a.y + b.y },
86
+ { type: "L", x: b.x, y: b.y },
87
+ ];
43
88
  }
44
- measure() {
45
- return { width: 0, height: 0 };
89
+ const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));
90
+ const out = [];
91
+ for (let i = 0; i <= steps; i++) {
92
+ const p = point(radius, fromAngle + (sweep * i) / steps);
93
+ out.push({ type: i === 0 ? "M" : "L", x: p.x, y: p.y });
46
94
  }
47
- shapeGraphics() {
48
- const data = this._outline();
49
- return data.length === 0 ? null : new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });
50
- }
51
- renderSelf(ctx) {
52
- super.renderSelf(ctx);
53
- if (this.label === "" || this.radius <= 0)
54
- return;
55
- const text = this.label === "°" ? `${Math.round(Math.abs(this.value) * 10) / 10}°` : this.label;
56
- const at = point(this.radius + this.labelSize * 0.9, (this.fromAngle + this.toAngle) / 2);
57
- const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor };
58
- for (const part of drawLabels([{ text, at, align: "center" }], style))
59
- ctx.draw(part);
60
- }
61
- _localBounds() {
62
- const ink = pathOps.bounds(this._outline());
63
- if (!ink)
64
- return { x: 0, y: 0, width: 0, height: 0 };
65
- return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };
66
- }
67
- _outline() {
68
- const { fromAngle, toAngle, radius } = this;
69
- const sweep = toAngle - fromAngle;
70
- if (radius <= 0 || sweep === 0)
71
- return [];
72
- const square = this.corner === "square" || (this.corner === "auto" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);
73
- if (square) {
74
- const side = radius * 0.6;
75
- const a = point(side, fromAngle);
76
- const b = point(side, toAngle);
77
- return [
78
- { type: "M", x: a.x, y: a.y },
79
- { type: "L", x: a.x + b.x, y: a.y + b.y },
80
- { type: "L", x: b.x, y: b.y },
81
- ];
82
- }
83
- const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));
84
- const out = [];
85
- for (let i = 0; i <= steps; i++) {
86
- const p = point(radius, fromAngle + (sweep * i) / steps);
87
- out.push({ type: i === 0 ? "M" : "L", x: p.x, y: p.y });
88
- }
89
- return out;
90
- }
91
- };
92
- __decorate([
93
- property({ default: 0, unit: "°" })
94
- ], AngleMark.prototype, "fromAngle", void 0);
95
- __decorate([
96
- property({ default: 60, unit: "°" })
97
- ], AngleMark.prototype, "toAngle", void 0);
98
- __decorate([
99
- property({ default: 48, min: 0, unit: "px" })
100
- ], AngleMark.prototype, "radius", void 0);
101
- __decorate([
102
- property({ default: "auto", options: ["auto", "arc", "square"], animatable: false })
103
- ], AngleMark.prototype, "corner", void 0);
104
- __decorate([
105
- property({ default: "", animatable: false })
106
- ], AngleMark.prototype, "label", void 0);
107
- __decorate([
108
- property({ default: 24, min: 1, unit: "px" })
109
- ], AngleMark.prototype, "labelSize", void 0);
110
- __decorate([
111
- colorProperty({ default: "#e5e7eb" })
112
- ], AngleMark.prototype, "labelColor", void 0);
113
- __decorate([
114
- property({ default: "", animatable: false })
115
- ], AngleMark.prototype, "fontFamily", void 0);
116
- __decorate([
117
- strokeProperty({ default: { weight: 3, fill: "#e5e7eb", align: "center", cap: "round", join: "round" } })
118
- ], AngleMark.prototype, "stroke", void 0);
119
- __decorate([
120
- command({ args: ["radius"] })
121
- ], AngleMark.prototype, "radiusTo", null);
122
- AngleMark = __decorate([
123
- node({
124
- key: "angleMark",
125
- parentKey: "shape",
126
- forkable: true,
127
- layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
128
- }),
129
- withdraw(...FILL_PAINT)
130
- ], AngleMark);
131
- export { AngleMark };
95
+ return out;
96
+ }
132
97
  //# sourceMappingURL=angle-mark.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"angle-mark.js","sourceRoot":"","sources":["../../src/annotate/angle-mark.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,aAAa,EACb,OAAO,EACP,UAAU,EACV,IAAI,EACJ,SAAS,EACT,OAAO,EACP,QAAQ,EACR,cAAc,EACd,QAAQ,GAaX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAa9C,MAAM,SAAS,GAAqC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACnE,wCAAwC;AACxC,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,0DAA0D;AAC1D,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE;IAC9C,MAAM,IAAI,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;IACvC,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;AACtE,CAAC,CAAC;AAEF;;;;;GAKG;AA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wCAAuB;AACb;IAAtD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;4CAA2B;AAC1B;IAA9C,aAAa,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;6CAA2B;AACX;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;6CAA4B;AAGjE;IADP,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC;yCACnF;AAQvB;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;yCAG7B;AAxBQ,SAAS;IAPrB,IAAI,CAAC;QACF,GAAG,EAAE,WAAW;QAChB,SAAS,EAAE,OAAO;QAClB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE;KAC9G,CAAC;IACD,QAAQ,CAAC,GAAG,UAAU,CAAC;GACX,SAAS,CAoFrB","sourcesContent":["import {\r\n colorProperty,\r\n command,\r\n Graphics2D,\r\n node,\r\n PaintNode,\r\n pathOps,\r\n property,\r\n strokeProperty,\r\n withdraw,\r\n type AssetScope,\r\n type BoxBounds,\r\n type Color,\r\n type Command,\r\n type CommandArgs,\r\n type NodeConfig,\r\n type NormalizedColor,\r\n type PaintProps,\r\n type PathCommand,\r\n type RenderContext2D,\r\n type Size2D,\r\n type Stroke,\r\n} from \"@motionscript/sdk\";\r\nimport { declareFormulas, drawLabels } from \"../kit/furniture\";\r\nimport { stated } from \"../kit/geometry\";\r\nimport { FILL_PAINT } from \"../kit/withdrawn\";\r\n\r\nexport interface AngleMarkProps extends PaintProps {\r\n fromAngle?: number;\r\n toAngle?: number;\r\n radius?: number;\r\n corner?: \"arc\" | \"square\" | \"auto\";\r\n label?: string;\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n}\r\n\r\nconst OWN_FRAME: [number, number, number, number] = [-1, -1, 1, 1];\r\n/** Degrees of arc per drawn segment. */\r\nconst ARC_STEP = 4;\r\n/** How close to a right angle `auto` draws the square. */\r\nconst RIGHT_SLOP = 0.5;\r\n\r\nconst point = (radius: number, degrees: number) => {\r\n const turn = (degrees * Math.PI) / 180;\r\n return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };\r\n};\r\n\r\n/**\r\n * The mark of an angle at the node's own position: an arc from one direction\r\n * to another, or the small square of a right angle, with an optional label.\r\n * Directions are degrees counter-clockwise from the right, so binding one to a\r\n * variable opens and closes the angle. A label of `°` shows the angle's size.\r\n */\r\n@node({\r\n key: \"angleMark\",\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n})\r\n@withdraw(...FILL_PAINT)\r\nexport class AngleMark extends PaintNode<AngleMarkProps> {\r\n @property({ default: 0, unit: \"°\" }) declare fromAngle: number;\r\n @property({ default: 60, unit: \"°\" }) declare toAngle: number;\r\n @property({ default: 48, min: 0, unit: \"px\" }) declare radius: number;\r\n /** `auto` draws the square where the angle is a right one. */\r\n @property({ default: \"auto\", options: [\"auto\", \"arc\", \"square\"], animatable: false }) declare corner: \"arc\" | \"square\" | \"auto\";\r\n\r\n /** Text, a formula between dollar signs, or `°` for the angle's own size. */\r\n @property({ default: \"\", animatable: false }) declare label: string;\r\n @property({ default: 24, min: 1, unit: \"px\" }) declare labelSize: number;\r\n @colorProperty({ default: \"#e5e7eb\" }) declare labelColor: Color;\r\n @property({ default: \"\", animatable: false }) declare fontFamily: string;\r\n\r\n @strokeProperty({ default: { weight: 3, fill: \"#e5e7eb\", align: \"center\", cap: \"round\", join: \"round\" } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<AngleMark, AngleMarkProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** Grow or shrink the mark. */\r\n @command({ args: [\"radius\"] })\r\n radiusTo(args: CommandArgs<{ radius: number }> & { duration: number }): Command<AngleMarkProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** The angle marked, in degrees: positive counter-clockwise. */\r\n get value(): number {\r\n return this.toAngle - this.fromAngle;\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n if (this.label !== \"\" && this.fontFamily !== \"\") assets.font(this.fontFamily);\r\n declareFormulas(assets, [this.label]);\r\n }\r\n\r\n override measure(): Partial<Size2D> {\r\n return { width: 0, height: 0 };\r\n }\r\n\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const data = this._outline();\r\n return data.length === 0 ? null : new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });\r\n }\r\n\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n super.renderSelf(ctx);\r\n if (this.label === \"\" || this.radius <= 0) return;\r\n const text = this.label === \"°\" ? `${Math.round(Math.abs(this.value) * 10) / 10}°` : this.label;\r\n const at = point(this.radius + this.labelSize * 0.9, (this.fromAngle + this.toAngle) / 2);\r\n const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor };\r\n for (const part of drawLabels([{ text, at, align: \"center\" }], style)) ctx.draw(part);\r\n }\r\n\r\n override _localBounds(): BoxBounds {\r\n const ink = pathOps.bounds(this._outline());\r\n if (!ink) return { x: 0, y: 0, width: 0, height: 0 };\r\n return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };\r\n }\r\n\r\n private _outline(): PathCommand[] {\r\n const { fromAngle, toAngle, radius } = this;\r\n const sweep = toAngle - fromAngle;\r\n if (radius <= 0 || sweep === 0) return [];\r\n const square = this.corner === \"square\" || (this.corner === \"auto\" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);\r\n if (square) {\r\n const side = radius * 0.6;\r\n const a = point(side, fromAngle);\r\n const b = point(side, toAngle);\r\n return [\r\n { type: \"M\", x: a.x, y: a.y },\r\n { type: \"L\", x: a.x + b.x, y: a.y + b.y },\r\n { type: \"L\", x: b.x, y: b.y },\r\n ];\r\n }\r\n const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));\r\n const out: PathCommand[] = [];\r\n for (let i = 0; i <= steps; i++) {\r\n const p = point(radius, fromAngle + (sweep * i) / steps);\r\n out.push({ type: i === 0 ? \"M\" : \"L\", x: p.x, y: p.y });\r\n }\r\n return out;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"angle-mark.js","sourceRoot":"","sources":["../../src/annotate/angle-mark.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAaR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAa1C,wCAAwC;AACxC,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,0DAA0D;AAC1D,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,OAAe,EAAE,EAAE;IAC9C,MAAM,IAAI,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;IACvC,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I,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;IACjE,MAAM,GAAG,GAAkB,EAAE,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QACzD,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import {\r\n component2d,\r\n Graphics2D,\r\n Types,\r\n type Color,\r\n type NodeOf,\r\n type NormalizedColor,\r\n type PaintProps,\r\n type PathCommand,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { listed, omit, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\r\nimport { outlineBounds, OWN_FRAME } from \"../kit/follow\";\r\nimport { drawLabels, loadFormulas } from \"../kit/furniture\";\r\nimport { strokeShape } from \"../kit/mark\";\r\n\r\nexport interface AngleMarkProps extends PaintProps {\r\n fromAngle?: number;\r\n toAngle?: number;\r\n radius?: number;\r\n corner?: \"arc\" | \"square\" | \"auto\";\r\n label?: string;\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n}\r\n\r\n/** Degrees of arc per drawn segment. */\r\nconst ARC_STEP = 4;\r\n/** How close to a right angle `auto` draws the square. */\r\nconst RIGHT_SLOP = 0.5;\r\n\r\nconst point = (radius: number, degrees: number) => {\r\n const turn = (degrees * Math.PI) / 180;\r\n return { x: radius * Math.cos(turn), y: radius * Math.sin(turn) };\r\n};\r\n\r\nconst state = {\r\n // It is only an outline.\r\n ...omit(PAINT, \"fill\"),\r\n fromAngle: Types.number(0, { unit: \"°\" }),\r\n toAngle: Types.number(60, { unit: \"°\" }),\r\n radius: Types.number(48, { min: 0, unit: \"px\" }),\r\n /** `auto` draws the square where the angle is a right one. */\r\n corner: listed([\"auto\", \"arc\", \"square\"], \"auto\", { animatable: false }),\r\n /** Text, a formula between dollar signs, or `°` for the angle's own size. */\r\n label: Types.text(\"\", { animatable: false }),\r\n labelSize: Types.number(24, { min: 1, unit: \"px\" }),\r\n labelColor: Types.color(\"#e5e7eb\"),\r\n fontFamily: Types.text(\"\", { animatable: false }),\r\n /** The angle marked, in degrees: positive counter-clockwise. A formula reads it back as `[key.value]`. */\r\n value: Types.number(0, { private: true }),\r\n};\r\n\r\ninterface AngleValues {\r\n readonly fromAngle: number;\r\n readonly toAngle: number;\r\n readonly radius: number;\r\n readonly corner: \"arc\" | \"square\" | \"auto\";\r\n}\r\n\r\n/**\r\n * The mark of an angle at the node's own position: an arc from one direction\r\n * to another, or the small square of a right angle, with an optional label.\r\n * Directions are degrees counter-clockwise from the right, so binding one to a\r\n * variable opens and closes the angle. A label of `°` shows the angle's size.\r\n */\r\nexport const AngleMark = component2d({\r\n key: \"angleMark\",\r\n state,\r\n defaults: { stroke: { weight: 3, fill: \"#e5e7eb\", align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\", value: (s) => angleOf(s) },\r\n load: (loader, s) => {\r\n if (s.label !== \"\" && s.fontFamily !== \"\") loader.font(s.fontFamily);\r\n loadFormulas(loader, [s.label]);\r\n },\r\n commands: {\r\n ...omit(PAINT_COMMANDS, \"fillTo\"),\r\n /** Grow or shrink the mark. */\r\n radiusTo: { args: [\"radius\"] },\r\n },\r\n measure: () => ({ width: 0, height: 0 }),\r\n bounds: (_size, s) => outlineBounds(outline(s)),\r\n render: (ctx, s) => {\r\n const data = outline(s);\r\n const shape = data.length > 0 ? () => new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: s.start, end: s.end }) : null;\r\n painted(\r\n ctx,\r\n () => {\r\n if (shape) ctx.draw(shape().shadow(s.shadow).fill([]));\r\n if (s.label === \"\" || s.radius <= 0) return;\r\n const text = s.label === \"°\" ? `${Math.round(Math.abs(s.value) * 10) / 10}°` : s.label;\r\n const at = point(s.radius + s.labelSize * 0.9, (s.fromAngle + s.toAngle) / 2);\r\n const style = { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor };\r\n ctx.draw(drawLabels([{ text, at, align: \"center\" }], style));\r\n },\r\n () => {\r\n if (shape) strokeShape(ctx, shape, s);\r\n },\r\n );\r\n },\r\n});\r\n\r\nexport type AngleMark = NodeOf<typeof AngleMark>;\r\n\r\n/** The angle a mark marks, in degrees: positive counter-clockwise. */\r\nexport function angleOf(s: Pick<AngleValues, \"fromAngle\" | \"toAngle\">): number {\r\n return s.toAngle - s.fromAngle;\r\n}\r\n\r\nfunction outline({ fromAngle, toAngle, radius, corner }: AngleValues): PathCommand[] {\r\n const sweep = toAngle - fromAngle;\r\n if (radius <= 0 || sweep === 0) return [];\r\n const square = corner === \"square\" || (corner === \"auto\" && Math.abs(Math.abs(sweep) - 90) < RIGHT_SLOP);\r\n if (square) {\r\n const side = radius * 0.6;\r\n const a = point(side, fromAngle);\r\n const b = point(side, toAngle);\r\n return [\r\n { type: \"M\", x: a.x, y: a.y },\r\n { type: \"L\", x: a.x + b.x, y: a.y + b.y },\r\n { type: \"L\", x: b.x, y: b.y },\r\n ];\r\n }\r\n const steps = Math.max(2, Math.ceil(Math.abs(sweep) / ARC_STEP));\r\n const out: PathCommand[] = [];\r\n for (let i = 0; i <= steps; i++) {\r\n const p = point(radius, fromAngle + (sweep * i) / steps);\r\n out.push({ type: i === 0 ? \"M\" : \"L\", x: p.x, y: p.y });\r\n }\r\n return out;\r\n}\r\n"]}
@@ -1,5 +1,5 @@
1
- import { type AssetScope, type Color, type NodeConfig, type NodeHandle, type PathCommand, type RenderContext2D, type Stroke, type Vector2 } from "@motionscript/sdk";
2
- import { FollowMark, type FollowProps, type Quad } from "../kit/follow.js";
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 class CurlyBrace extends FollowMark<CurlyBraceProps> {
21
- side: BraceSide;
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
- stroke: Stroke;
34
- constructor(props?: NodeConfig<CurlyBrace, CurlyBraceProps>);
35
- declareAssets(assets: AssetScope): void;
36
- protected quad(): Quad | null;
37
- /** Whether the brace follows nothing, and so spans its own two points. */
38
- private _spans;
39
- protected outline(quad: Quad): PathCommand[];
40
- protected renderSelf(ctx: RenderContext2D): void;
41
- /** The edge the brace runs along, pushed out by the gap, and the way it bulges. */
42
- private _span;
43
- _handles(): readonly NodeHandle[];
44
- _handleValue(prop: string, at: Vector2): Vector2 | null;
45
- }
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,EAMH,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,UAAU,EAEf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,OAAO,EACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAA0B,UAAU,EAAW,KAAK,WAAW,EAAE,KAAK,IAAI,EAAE,MAAM,eAAe,CAAC;AAGzG,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;AAUD;;;;GAIG;AACH,qBAMa,UAAW,SAAQ,UAAU,CAAC,eAAe,CAAC;IACkD,IAAI,EAAE,SAAS,CAAC;IACzH,0HAA0H;IAClE,IAAI,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACrE,wEAAwE;IAClB,SAAS,EAAE,MAAM,CAAC;IACxE,6FAA6F;IACtC,KAAK,EAAE,MAAM,CAAC;IAEf,KAAK,EAAE,MAAM,CAAC;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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
- 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";
1
+ import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
8
2
  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";
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
- 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 };
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