@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.
Files changed (233) hide show
  1. package/CHANGELOG.md +22 -0
  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,4 +1,4 @@
1
- import { PaintNode, type AssetScope, type Color, type Command, type CommandArgs, type Fill, type NodeConfig, type PaintProps, type RenderContext2D, type Stroke } from "@motionscript/sdk";
1
+ import { type Color, type Fill, type FillResolved, type NodeOf, type NormalizedColor, type PaintProps, type ShadowResolved, type Size2D, type StrokeResolved, type Values, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type Stroke as _Stroke } from "@motionscript/sdk";
2
2
  export interface SampleSpaceProps extends PaintProps {
3
3
  columnShares?: number[];
4
4
  rowShares?: number[];
@@ -10,6 +10,36 @@ export interface SampleSpaceProps extends PaintProps {
10
10
  labelColor?: Color;
11
11
  fontFamily?: string;
12
12
  }
13
+ declare const state: {
14
+ /** How the whole is shared across, left to right; any numbers, read as shares of their sum. */
15
+ columnShares: import("@motionscript/sdk").Type<number[], number[], false>;
16
+ /** Each column's upper share, 0 to 1; a column without one is not cut across. */
17
+ rowShares: import("@motionscript/sdk").Type<number[], number[], false>;
18
+ /** Each column's paint, left to right, round again past the last; its lower part shows it fainter. */
19
+ columnFills: import("@motionscript/sdk").Type<Fill[], FillResolved[][], false>;
20
+ columnLabels: import("@motionscript/sdk").Type<string[], string[], false>;
21
+ /** The upper part's name and the lower's, written on the left. */
22
+ rowLabels: import("@motionscript/sdk").Type<string[], string[], false>;
23
+ /** Write each part's probability in it. */
24
+ values: import("@motionscript/sdk").Type<boolean, boolean, false>;
25
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
26
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
27
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
28
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
29
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
30
+ };
31
+ /** What a sample space is drawn from: its own entries, as its fields and its node both read them. */
32
+ export type SampleSpaceValues = Values<typeof state>;
33
+ /** One part of a sample space: its box in pixels from the node's centre, y up, and its probability. */
34
+ export interface SamplePart {
35
+ x: number;
36
+ y: number;
37
+ width: number;
38
+ height: number;
39
+ probability: number;
40
+ column: number;
41
+ upper: boolean;
42
+ }
13
43
  /**
14
44
  * A probability's whole, as a box cut into columns by `columnShares` (shares of
15
45
  * the whole, P(A) and P(not A)) and each column cut again by its `rowShares` entry
@@ -17,46 +47,47 @@ export interface SampleSpaceProps extends PaintProps {
17
47
  * Braces name the columns below and the rows on the left; `divideTo` moves the
18
48
  * cuts.
19
49
  */
20
- export declare class SampleSpace extends PaintNode<SampleSpaceProps> {
50
+ export declare const SampleSpace: import("@motionscript/sdk").Component<"sampleSpace", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
21
51
  /** How the whole is shared across, left to right; any numbers, read as shares of their sum. */
22
- columnShares: number[];
52
+ columnShares: import("@motionscript/sdk").Type<number[], number[], false>;
23
53
  /** Each column's upper share, 0 to 1; a column without one is not cut across. */
24
- rowShares: number[];
54
+ rowShares: import("@motionscript/sdk").Type<number[], number[], false>;
25
55
  /** Each column's paint, left to right, round again past the last; its lower part shows it fainter. */
26
- columnFills: Fill[];
27
- columnLabels: string[];
56
+ columnFills: import("@motionscript/sdk").Type<Fill[], FillResolved[][], false>;
57
+ columnLabels: import("@motionscript/sdk").Type<string[], string[], false>;
28
58
  /** The upper part's name and the lower's, written on the left. */
29
- rowLabels: string[];
59
+ rowLabels: import("@motionscript/sdk").Type<string[], string[], false>;
30
60
  /** Write each part's probability in it. */
31
- values: boolean;
32
- labelSize: number;
33
- labelColor: Color;
34
- fontFamily: string;
35
- stroke: Stroke;
36
- constructor(props?: NodeConfig<SampleSpace, SampleSpaceProps>);
37
- /** Move the cuts: the columns' shares, each column's upper share, or both. */
38
- divideTo(args: CommandArgs<{
39
- columnShares?: number[];
40
- rowShares?: number[];
41
- }> & {
42
- duration: number;
43
- }): Command<SampleSpaceProps>;
44
- declareAssets(assets: AssetScope): void;
45
- /** Each part's box in pixels from the node's centre, y up, and its probability: columns left to right, upper part first. */
46
- parts(): {
47
- x: number;
48
- y: number;
49
- width: number;
50
- height: number;
51
- probability: number;
52
- column: number;
53
- upper: boolean;
54
- }[];
55
- protected renderSelf(ctx: RenderContext2D): void;
56
- protected renderStroke(): void;
57
- /** Room for the braces and their names, below and on the left, taken from the box. */
58
- private _box;
59
- /** Braces under each column and beside the first column's parts, and the labels that name them. */
60
- private _braces;
61
- }
61
+ values: import("@motionscript/sdk").Type<boolean, boolean, false>;
62
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
63
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
64
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
65
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
66
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
67
+ }>, {
68
+ readonly divideTo: readonly ["columnShares", "rowShares"];
69
+ readonly strokeTo: readonly ["stroke"];
70
+ readonly shadowTo: readonly ["shadow"];
71
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
72
+ /** How the whole is shared across, left to right; any numbers, read as shares of their sum. */
73
+ columnShares: import("@motionscript/sdk").Type<number[], number[], false>;
74
+ /** Each column's upper share, 0 to 1; a column without one is not cut across. */
75
+ rowShares: import("@motionscript/sdk").Type<number[], number[], false>;
76
+ /** Each column's paint, left to right, round again past the last; its lower part shows it fainter. */
77
+ columnFills: import("@motionscript/sdk").Type<Fill[], FillResolved[][], false>;
78
+ columnLabels: import("@motionscript/sdk").Type<string[], string[], false>;
79
+ /** The upper part's name and the lower's, written on the left. */
80
+ rowLabels: import("@motionscript/sdk").Type<string[], string[], false>;
81
+ /** Write each part's probability in it. */
82
+ values: import("@motionscript/sdk").Type<boolean, boolean, false>;
83
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
84
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
85
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
86
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
87
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, ShadowResolved[]>;
88
+ }>, null>>;
89
+ export type SampleSpace = NodeOf<typeof SampleSpace>;
90
+ /** Each part of a sample space of `size`: columns left to right, upper part first. */
91
+ export declare function sampleParts(space: SampleSpaceValues, size: Size2D): SamplePart[];
92
+ export {};
62
93
  //# sourceMappingURL=sample-space.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sample-space.d.ts","sourceRoot":"","sources":["../../src/structures/sample-space.ts"],"names":[],"mappings":"AAAA,OAAO,EAMH,SAAS,EAIT,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,IAAI,EAET,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,MAAM,EAGd,MAAM,mBAAmB,CAAC;AAO3B,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAChD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAkBD;;;;;;GAMG;AACH,qBAQa,WAAY,SAAQ,SAAS,CAAC,gBAAgB,CAAC;IACxD,+FAA+F;IACJ,YAAY,EAAE,MAAM,EAAE,CAAC;IAClH,iFAAiF;IACS,SAAS,EAAE,MAAM,EAAE,CAAC;IAC9G,sGAAsG;IACN,WAAW,EAAE,IAAI,EAAE,CAAC;IAC9C,YAAY,EAAE,MAAM,EAAE,CAAC;IAC7F,kEAAkE;IACI,SAAS,EAAE,MAAM,EAAE,CAAC;IAC1F,2CAA2C;IACc,MAAM,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,KAAK,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IAEa,MAAM,EAAE,MAAM,CAAC;gBAEzF,KAAK,CAAC,EAAE,UAA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(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, fillOps, Graphics2D, node, PaintNode, property, strokeProperty, withdraw, } from "@motionscript/sdk";
1
+ import { component2d, fillOps, Graphics2D, Types, } from "@motionscript/sdk";
8
2
  import { braceOutline } from "../kit/brace.js";
9
- import { declareFormulas, drawLabels } from "../kit/furniture.js";
3
+ import { omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component.js";
4
+ import { drawLabels, loadFormulas } from "../kit/furniture.js";
10
5
  import { lerpFillScale, readFillScale } from "../kit/scale.js";
11
6
  import { formatTick } from "../kit/ticks.js";
12
- import { FILL_PAINT, OUTLINE_TRIM } from "../kit/withdrawn.js";
13
7
  /** The parts' paints until told otherwise, a column each, round again past the last. */
14
8
  const PALETTE = ["#58a6ff", "#f59e0b", "#4ade80", "#f472b6", "#a78bfa", "#2dd4bf"];
15
9
  /** How strongly the lower part of a split column shows its paint. */
@@ -23,6 +17,24 @@ function lerpShares(from, to, t) {
23
17
  return t < 1 ? from : to;
24
18
  return to.map((share, i) => from[i] + (share - from[i]) * t);
25
19
  }
20
+ const state = {
21
+ // Its parts are painted from `columnFills`, and it trims no outline of its own.
22
+ ...omit(PAINT, "fill", "start", "end"),
23
+ /** How the whole is shared across, left to right; any numbers, read as shares of their sum. */
24
+ columnShares: Types.custom([1], { resolve: readShares, lerp: lerpShares, kind: "vector" }),
25
+ /** Each column's upper share, 0 to 1; a column without one is not cut across. */
26
+ rowShares: Types.custom([], { resolve: readShares, lerp: lerpShares, kind: "vector" }),
27
+ /** Each column's paint, left to right, round again past the last; its lower part shows it fainter. */
28
+ columnFills: Types.custom([], { resolve: readFillScale, lerp: lerpFillScale, kind: "vector" }),
29
+ columnLabels: Types.custom([], { animatable: false, kind: "vector" }),
30
+ /** The upper part's name and the lower's, written on the left. */
31
+ rowLabels: Types.custom([], { animatable: false, kind: "vector" }),
32
+ /** Write each part's probability in it. */
33
+ values: Types.boolean(false, { animatable: false }),
34
+ labelSize: Types.number(20, { min: 1, unit: "px" }),
35
+ labelColor: Types.color("#e5e7eb"),
36
+ fontFamily: Types.text("", { animatable: false }),
37
+ };
26
38
  /**
27
39
  * A probability's whole, as a box cut into columns by `columnShares` (shares of
28
40
  * the whole, P(A) and P(not A)) and each column cut again by its `rowShares` entry
@@ -30,170 +42,120 @@ function lerpShares(from, to, t) {
30
42
  * Braces name the columns below and the rows on the left; `divideTo` moves the
31
43
  * cuts.
32
44
  */
33
- let SampleSpace = class SampleSpace extends PaintNode {
34
- constructor(props) {
35
- super(props ?? {});
36
- }
37
- /** Move the cuts: the columns' shares, each column's upper share, or both. */
38
- divideTo(args) {
39
- const data = {};
40
- if (args.data?.columnShares !== undefined)
41
- data.columnShares = args.data.columnShares;
42
- if (args.data?.rowShares !== undefined)
43
- data.rowShares = args.data.rowShares;
44
- return this.to({ data, duration: args.duration, easing: args.easing });
45
- }
46
- declareAssets(assets) {
47
- super.declareAssets(assets);
48
- if (this.fontFamily !== "")
49
- assets.font(this.fontFamily);
50
- declareFormulas(assets, [...this.columnLabels, ...this.rowLabels]);
51
- }
52
- /** Each part's box in pixels from the node's centre, y up, and its probability: columns left to right, upper part first. */
53
- parts() {
54
- const box = this._box();
55
- const shares = this.columnShares;
56
- const total = shares.reduce((sum, share) => sum + share, 0);
57
- if (!(total > 0) || box.width <= 0 || box.height <= 0)
58
- return [];
59
- const out = [];
60
- let left = box.x - box.width / 2;
61
- shares.forEach((share, column) => {
62
- const width = (box.width * share) / total;
63
- const p = share / total;
64
- const cut = this.rowShares[column];
65
- const top = box.y + box.height / 2;
66
- if (cut === undefined) {
67
- out.push({ x: left + width / 2, y: box.y, width, height: box.height, probability: p, column, upper: true });
68
- }
69
- else {
70
- const upper = Math.min(1, Math.max(0, cut));
71
- const h = box.height * upper;
72
- out.push({ x: left + width / 2, y: top - h / 2, width, height: h, probability: p * upper, column, upper: true });
73
- out.push({ x: left + width / 2, y: top - h - (box.height - h) / 2, width, height: box.height - h, probability: p * (1 - upper), column, upper: false });
74
- }
75
- left += width;
76
- });
77
- return out;
45
+ export const SampleSpace = component2d({
46
+ key: "sampleSpace",
47
+ state,
48
+ defaults: { stroke: { weight: 2, fill: "#0b0d12", align: "center" } },
49
+ load: (loader, s) => {
50
+ if (s.fontFamily !== "")
51
+ loader.font(s.fontFamily);
52
+ loadFormulas(loader, [...s.columnLabels, ...s.rowLabels]);
53
+ },
54
+ commands: {
55
+ ...omit(PAINT_COMMANDS, "fillTo", "progressTo", "flash"),
56
+ /** Move the cuts: the columns' shares, each column's upper share, or both. */
57
+ divideTo: { args: ["columnShares", "rowShares"] },
58
+ },
59
+ render: (ctx, s) => painted(ctx, () => drawSpace(ctx, s)),
60
+ });
61
+ /** Each part of a sample space of `size`: columns left to right, upper part first. */
62
+ export function sampleParts(space, size) {
63
+ const box = boxOf(space, size);
64
+ const shares = space.columnShares;
65
+ const total = shares.reduce((sum, share) => sum + share, 0);
66
+ if (!(total > 0) || box.width <= 0 || box.height <= 0)
67
+ return [];
68
+ const out = [];
69
+ let left = box.x - box.width / 2;
70
+ shares.forEach((share, column) => {
71
+ const width = (box.width * share) / total;
72
+ const p = share / total;
73
+ const cut = space.rowShares[column];
74
+ const top = box.y + box.height / 2;
75
+ if (cut === undefined) {
76
+ out.push({ x: left + width / 2, y: box.y, width, height: box.height, probability: p, column, upper: true });
77
+ }
78
+ else {
79
+ const upper = Math.min(1, Math.max(0, cut));
80
+ const h = box.height * upper;
81
+ out.push({ x: left + width / 2, y: top - h / 2, width, height: h, probability: p * upper, column, upper: true });
82
+ out.push({ x: left + width / 2, y: top - h - (box.height - h) / 2, width, height: box.height - h, probability: p * (1 - upper), column, upper: false });
83
+ }
84
+ left += width;
85
+ });
86
+ return out;
87
+ }
88
+ function drawSpace(ctx, space) {
89
+ const parts = sampleParts(space, ctx.size);
90
+ if (parts.length === 0)
91
+ return;
92
+ const fills = space.columnFills;
93
+ const stroke = space.stroke;
94
+ const labels = [];
95
+ for (const part of parts) {
96
+ if (!(part.width > 0) || !(part.height > 0))
97
+ continue;
98
+ const base = fills.length > 0 ? fills[part.column % fills.length] : fillOps.resolve(PALETTE[part.column % PALETTE.length]);
99
+ const paint = part.upper ? base : base.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * LOWER }));
100
+ const g = new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height });
101
+ ctx.draw(g.shadow(space.shadow).fill(paint));
102
+ if (stroke.length > 0)
103
+ ctx.draw(new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height }).stroke(stroke));
104
+ if (space.values && part.height > space.labelSize && part.width > space.labelSize) {
105
+ labels.push({ text: formatTick(Math.round(part.probability * 1000) / 1000, 0.001), at: { x: part.x, y: part.y }, align: "center" });
106
+ }
78
107
  }
79
- renderSelf(ctx) {
80
- const parts = this.parts();
81
- if (parts.length === 0)
108
+ labels.push(...braces(ctx, space, parts));
109
+ const style = { fontSize: space.labelSize, fontFamily: space.fontFamily, color: space.labelColor };
110
+ for (const part of drawLabels(labels, style))
111
+ ctx.draw(part);
112
+ }
113
+ /** Room for the braces and their names, below and on the left, taken from the box. */
114
+ function boxOf(space, size) {
115
+ const { width, height } = size;
116
+ const room = space.labelSize * 2.6;
117
+ const below = space.columnLabels.some((label) => label !== "") ? room : 0;
118
+ const left = space.rowLabels.some((label) => label !== "") ? room * 1.6 : 0;
119
+ return { x: left / 2, y: below / 2, width: Math.max(0, width - left), height: Math.max(0, height - below) };
120
+ }
121
+ /** Braces under each column and beside the first column's parts, and the labels that name them. */
122
+ function braces(ctx, space, parts) {
123
+ const box = boxOf(space, ctx.size);
124
+ const reach = space.labelSize * 0.8;
125
+ const gap = 6;
126
+ const runs = new Graphics2D();
127
+ const labels = [];
128
+ let drawn = false;
129
+ const brace = (from, to, out, text, align) => {
130
+ if (text === "")
82
131
  return;
83
- const fills = this.columnFills;
84
- const stroke = this.stroke;
85
- const labels = [];
86
- for (const part of parts) {
87
- if (!(part.width > 0) || !(part.height > 0))
88
- continue;
89
- const base = fills.length > 0 ? fills[part.column % fills.length] : fillOps.resolve(PALETTE[part.column % PALETTE.length]);
90
- const paint = part.upper ? base : base.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * LOWER }));
91
- const g = new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height });
92
- ctx.draw(g.shadow(this.shadow).fill(paint));
93
- if (stroke.length > 0)
94
- ctx.draw(new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height }).stroke(stroke));
95
- if (this.values && part.height > this.labelSize && part.width > this.labelSize) {
96
- labels.push({ text: formatTick(Math.round(part.probability * 1000) / 1000, 0.001), at: { x: part.x, y: part.y }, align: "center" });
97
- }
98
- }
99
- labels.push(...this._braces(ctx, parts));
100
- const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor };
101
- for (const part of drawLabels(labels, style))
102
- ctx.draw(part);
132
+ // A frame centred on the node's own centre, so the path is drawn where it is and not moved onto it.
133
+ runs.path({ data: braceOutline(from, to, out, reach), centerBounds: [-1, -1, 1, 1] });
134
+ drawn = true;
135
+ const mid = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 };
136
+ const far = reach + space.labelSize * 0.75;
137
+ labels.push({ text, at: { x: mid.x + out.x * far, y: mid.y + out.y * far }, align });
138
+ };
139
+ const bottom = box.y - box.height / 2 - gap;
140
+ for (const part of parts) {
141
+ if (!part.upper && space.rowShares[part.column] !== undefined)
142
+ continue;
143
+ const text = space.columnLabels[part.column] ?? "";
144
+ // Left to right along the bottom, so the bulge, to the edge's right, points down.
145
+ brace({ x: part.x + part.width / 2, y: bottom }, { x: part.x - part.width / 2, y: bottom }, { x: 0, y: -1 }, text, "center");
103
146
  }
104
- // The outlines are drawn with the parts, and there is no outline of the node's own.
105
- renderStroke() { }
106
- /** Room for the braces and their names, below and on the left, taken from the box. */
107
- _box() {
108
- const { width, height } = this.layoutBounds;
109
- const room = this.labelSize * 2.6;
110
- const below = this.columnLabels.some((label) => label !== "") ? room : 0;
111
- const left = this.rowLabels.some((label) => label !== "") ? room * 1.6 : 0;
112
- return { x: left / 2, y: below / 2, width: Math.max(0, width - left), height: Math.max(0, height - below) };
147
+ const first = parts.filter((part) => part.column === 0);
148
+ const left = box.x - box.width / 2 - gap;
149
+ if (space.rowShares[0] !== undefined) {
150
+ first.forEach((part) => {
151
+ const text = space.rowLabels[part.upper ? 0 : 1] ?? "";
152
+ brace({ x: left, y: part.y - part.height / 2 }, { x: left, y: part.y + part.height / 2 }, { x: -1, y: 0 }, text, "right");
153
+ });
113
154
  }
114
- /** Braces under each column and beside the first column's parts, and the labels that name them. */
115
- _braces(ctx, parts) {
116
- const box = this._box();
117
- const reach = this.labelSize * 0.8;
118
- const gap = 6;
119
- const runs = new Graphics2D();
120
- const labels = [];
121
- let drawn = false;
122
- const brace = (from, to, out, text, align) => {
123
- if (text === "")
124
- return;
125
- // A frame centred on the node's own centre, so the path is drawn where it is and not moved onto it.
126
- runs.path({ data: braceOutline(from, to, out, reach), centerBounds: [-1, -1, 1, 1] });
127
- drawn = true;
128
- const mid = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 };
129
- const far = reach + this.labelSize * 0.75;
130
- labels.push({ text, at: { x: mid.x + out.x * far, y: mid.y + out.y * far }, align });
131
- };
132
- const bottom = box.y - box.height / 2 - gap;
133
- for (const part of parts) {
134
- if (!part.upper && this.rowShares[part.column] !== undefined)
135
- continue;
136
- const text = this.columnLabels[part.column] ?? "";
137
- // Left to right along the bottom, so the bulge, to the edge's right, points down.
138
- brace({ x: part.x + part.width / 2, y: bottom }, { x: part.x - part.width / 2, y: bottom }, { x: 0, y: -1 }, text, "center");
139
- }
140
- const first = parts.filter((part) => part.column === 0);
141
- const left = box.x - box.width / 2 - gap;
142
- if (this.rowShares[0] !== undefined) {
143
- first.forEach((part) => {
144
- const text = this.rowLabels[part.upper ? 0 : 1] ?? "";
145
- brace({ x: left, y: part.y - part.height / 2 }, { x: left, y: part.y + part.height / 2 }, { x: -1, y: 0 }, text, "right");
146
- });
147
- }
148
- if (drawn) {
149
- const fill = fillOps.resolve({ type: "solid", color: this.labelColor });
150
- ctx.draw(runs.stroke({ weight: 2, fill, align: "center", cap: "round", join: "round" }));
151
- }
152
- return labels;
155
+ if (drawn) {
156
+ const fill = fillOps.resolve({ type: "solid", color: space.labelColor });
157
+ ctx.draw(runs.stroke({ weight: 2, fill, align: "center", cap: "round", join: "round" }));
153
158
  }
154
- };
155
- __decorate([
156
- property({ default: [1], mapper: readShares, tween: lerpShares, kind: "vector" })
157
- ], SampleSpace.prototype, "columnShares", void 0);
158
- __decorate([
159
- property({ default: [], mapper: readShares, tween: lerpShares, kind: "vector" })
160
- ], SampleSpace.prototype, "rowShares", void 0);
161
- __decorate([
162
- property({ default: [], mapper: readFillScale, tween: lerpFillScale, kind: "vector" })
163
- ], SampleSpace.prototype, "columnFills", void 0);
164
- __decorate([
165
- property({ default: [], animatable: false, kind: "vector" })
166
- ], SampleSpace.prototype, "columnLabels", void 0);
167
- __decorate([
168
- property({ default: [], animatable: false, kind: "vector" })
169
- ], SampleSpace.prototype, "rowLabels", void 0);
170
- __decorate([
171
- property({ default: false, animatable: false })
172
- ], SampleSpace.prototype, "values", void 0);
173
- __decorate([
174
- property({ default: 20, min: 1, unit: "px" })
175
- ], SampleSpace.prototype, "labelSize", void 0);
176
- __decorate([
177
- colorProperty({ default: "#e5e7eb" })
178
- ], SampleSpace.prototype, "labelColor", void 0);
179
- __decorate([
180
- property({ default: "", animatable: false })
181
- ], SampleSpace.prototype, "fontFamily", void 0);
182
- __decorate([
183
- strokeProperty({ default: { weight: 2, fill: "#0b0d12", align: "center" } })
184
- ], SampleSpace.prototype, "stroke", void 0);
185
- __decorate([
186
- command({ args: ["columnShares", "rowShares"] })
187
- ], SampleSpace.prototype, "divideTo", null);
188
- SampleSpace = __decorate([
189
- node({
190
- key: "sampleSpace",
191
- parentKey: "shape",
192
- forkable: true,
193
- layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: false },
194
- seed: { width: 520, height: 420, columnShares: [0.4, 0.6], rowShares: [0.7, 0.25], columnLabels: ["A", "not A"], rowLabels: ["B", "not B"] },
195
- }),
196
- withdraw(...FILL_PAINT, ...OUTLINE_TRIM)
197
- ], SampleSpace);
198
- export { SampleSpace };
159
+ return labels;
160
+ }
199
161
  //# sourceMappingURL=sample-space.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sample-space.js","sourceRoot":"","sources":["../../src/structures/sample-space.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,aAAa,EACb,OAAO,EACP,OAAO,EACP,UAAU,EACV,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,cAAc,EACd,QAAQ,GAcX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,UAAU,EAAc,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAc5D,wFAAwF;AACxF,MAAM,OAAO,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAEnF,qEAAqE;AACrE,MAAM,KAAK,GAAG,IAAI,CAAC;AAEnB,SAAS,UAAU,CAAC,KA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C,aAAa,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;+CAA2B;AACX;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;+CAA4B;AAEa;IAArF,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC;2CAAwB;AAQrG;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,cAAc,EAAE,WAAW,CAAC,EAAE,CAAC;2CAMhD;AA7BQ,WAAW;IARvB,IAAI,CAAC;QACF,GAAG,EAAE,aAAa;QAClB,SAAS,EAAE,OAAO;QAClB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,gBAAgB,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE;QAC/G,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE;KAC/I,CAAC;IACD,QAAQ,CAAC,GAAG,UAAU,EAAE,GAAG,YAAY,CAAC;GAC5B,WAAW,CAuIvB","sourcesContent":["import {\r\n colorProperty,\r\n command,\r\n fillOps,\r\n Graphics2D,\r\n node,\r\n PaintNode,\r\n property,\r\n strokeProperty,\r\n withdraw,\r\n type AssetScope,\r\n type Color,\r\n type Command,\r\n type CommandArgs,\r\n type Fill,\r\n type FillResolved,\r\n type NodeConfig,\r\n type NormalizedColor,\r\n type PaintProps,\r\n type RenderContext2D,\r\n type Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { braceOutline } from \"../kit/brace\";\r\nimport { declareFormulas, drawLabels, type Label } from \"../kit/furniture\";\r\nimport { lerpFillScale, readFillScale } from \"../kit/scale\";\r\nimport { formatTick } from \"../kit/ticks\";\r\nimport { FILL_PAINT, OUTLINE_TRIM } from \"../kit/withdrawn\";\r\n\r\nexport interface SampleSpaceProps extends PaintProps {\r\n columnShares?: number[];\r\n rowShares?: number[];\r\n columnFills?: Fill[];\r\n columnLabels?: string[];\r\n rowLabels?: string[];\r\n values?: boolean;\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n}\r\n\r\n/** The parts' paints until told otherwise, a column each, round again past the last. */\r\nconst PALETTE = [\"#58a6ff\", \"#f59e0b\", \"#4ade80\", \"#f472b6\", \"#a78bfa\", \"#2dd4bf\"];\r\n\r\n/** How strongly the lower part of a split column shows its paint. */\r\nconst LOWER = 0.45;\r\n\r\nfunction readShares(value: readonly number[] | undefined): number[] {\r\n return (Array.isArray(value) ? value : []).map((share) => (Number.isFinite(share) && share > 0 ? share : 0));\r\n}\r\n\r\n// Shares tween one by one; a different count has nothing to pair with, and changes at the end.\r\nfunction lerpShares(from: number[], to: number[], t: number): number[] {\r\n if (from.length !== to.length) return t < 1 ? from : to;\r\n return to.map((share, i) => from[i] + (share - from[i]) * t);\r\n}\r\n\r\n/**\r\n * A probability's whole, as a box cut into columns by `columnShares` (shares of\r\n * the whole, P(A) and P(not A)) and each column cut again by its `rowShares` entry\r\n * (P(B | A) above, the rest below): each part's area is its probability.\r\n * Braces name the columns below and the rows on the left; `divideTo` moves the\r\n * cuts.\r\n */\r\n@node({\r\n key: \"sampleSpace\",\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"fixed\", defaultHeightMode: \"fixed\", acceptsChildren: false },\r\n seed: { width: 520, height: 420, columnShares: [0.4, 0.6], rowShares: [0.7, 0.25], columnLabels: [\"A\", \"not A\"], rowLabels: [\"B\", \"not B\"] },\r\n})\r\n@withdraw(...FILL_PAINT, ...OUTLINE_TRIM)\r\nexport class SampleSpace extends PaintNode<SampleSpaceProps> {\r\n /** How the whole is shared across, left to right; any numbers, read as shares of their sum. */\r\n @property({ default: [1], mapper: readShares, tween: lerpShares, kind: \"vector\" }) declare columnShares: number[];\r\n /** Each column's upper share, 0 to 1; a column without one is not cut across. */\r\n @property({ default: [], mapper: readShares, tween: lerpShares, kind: \"vector\" }) declare rowShares: number[];\r\n /** Each column's paint, left to right, round again past the last; its lower part shows it fainter. */\r\n @property({ default: [], mapper: readFillScale, tween: lerpFillScale, kind: \"vector\" }) declare columnFills: Fill[];\r\n @property({ default: [], animatable: false, kind: \"vector\" }) declare columnLabels: string[];\r\n /** The upper part's name and the lower's, written on the left. */\r\n @property({ default: [], animatable: false, kind: \"vector\" }) declare rowLabels: string[];\r\n /** Write each part's probability in it. */\r\n @property({ default: false, animatable: false }) declare values: boolean;\r\n @property({ default: 20, 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: 2, fill: \"#0b0d12\", align: \"center\" } }) declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<SampleSpace, SampleSpaceProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** Move the cuts: the columns' shares, each column's upper share, or both. */\r\n @command({ args: [\"columnShares\", \"rowShares\"] })\r\n divideTo(args: CommandArgs<{ columnShares?: number[]; rowShares?: number[] }> & { duration: number }): Command<SampleSpaceProps> {\r\n const data: Partial<SampleSpaceProps> = {};\r\n if (args.data?.columnShares !== undefined) data.columnShares = args.data.columnShares;\r\n if (args.data?.rowShares !== undefined) data.rowShares = args.data.rowShares;\r\n return this.to({ data, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n if (this.fontFamily !== \"\") assets.font(this.fontFamily);\r\n declareFormulas(assets, [...this.columnLabels, ...this.rowLabels]);\r\n }\r\n\r\n /** Each part's box in pixels from the node's centre, y up, and its probability: columns left to right, upper part first. */\r\n parts(): { x: number; y: number; width: number; height: number; probability: number; column: number; upper: boolean }[] {\r\n const box = this._box();\r\n const shares = this.columnShares;\r\n const total = shares.reduce((sum, share) => sum + share, 0);\r\n if (!(total > 0) || box.width <= 0 || box.height <= 0) return [];\r\n const out: ReturnType<SampleSpace[\"parts\"]> = [];\r\n let left = box.x - box.width / 2;\r\n shares.forEach((share, column) => {\r\n const width = (box.width * share) / total;\r\n const p = share / total;\r\n const cut = this.rowShares[column];\r\n const top = box.y + box.height / 2;\r\n if (cut === undefined) {\r\n out.push({ x: left + width / 2, y: box.y, width, height: box.height, probability: p, column, upper: true });\r\n } else {\r\n const upper = Math.min(1, Math.max(0, cut));\r\n const h = box.height * upper;\r\n out.push({ x: left + width / 2, y: top - h / 2, width, height: h, probability: p * upper, column, upper: true });\r\n out.push({ x: left + width / 2, y: top - h - (box.height - h) / 2, width, height: box.height - h, probability: p * (1 - upper), column, upper: false });\r\n }\r\n left += width;\r\n });\r\n return out;\r\n }\r\n\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n const parts = this.parts();\r\n if (parts.length === 0) return;\r\n const fills = this.columnFills as unknown as FillResolved[][];\r\n const stroke = this.stroke as StrokeResolved[];\r\n const labels: Label[] = [];\r\n for (const part of parts) {\r\n if (!(part.width > 0) || !(part.height > 0)) continue;\r\n const base = fills.length > 0 ? fills[part.column % fills.length] : fillOps.resolve(PALETTE[part.column % PALETTE.length]);\r\n const paint = part.upper ? base : base.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * LOWER }));\r\n const g = new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height });\r\n ctx.draw(g.shadow(this.shadow).fill(paint));\r\n if (stroke.length > 0) ctx.draw(new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height }).stroke(stroke));\r\n if (this.values && part.height > this.labelSize && part.width > this.labelSize) {\r\n labels.push({ text: formatTick(Math.round(part.probability * 1000) / 1000, 0.001), at: { x: part.x, y: part.y }, align: \"center\" });\r\n }\r\n }\r\n labels.push(...this._braces(ctx, parts));\r\n const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor };\r\n for (const part of drawLabels(labels, style)) ctx.draw(part);\r\n }\r\n\r\n // The outlines are drawn with the parts, and there is no outline of the node's own.\r\n protected override renderStroke(): void {}\r\n\r\n /** Room for the braces and their names, below and on the left, taken from the box. */\r\n private _box(): { x: number; y: number; width: number; height: number } {\r\n const { width, height } = this.layoutBounds;\r\n const room = this.labelSize * 2.6;\r\n const below = this.columnLabels.some((label) => label !== \"\") ? room : 0;\r\n const left = this.rowLabels.some((label) => label !== \"\") ? room * 1.6 : 0;\r\n return { x: left / 2, y: below / 2, width: Math.max(0, width - left), height: Math.max(0, height - below) };\r\n }\r\n\r\n /** Braces under each column and beside the first column's parts, and the labels that name them. */\r\n private _braces(ctx: RenderContext2D, parts: ReturnType<SampleSpace[\"parts\"]>): Label[] {\r\n const box = this._box();\r\n const reach = this.labelSize * 0.8;\r\n const gap = 6;\r\n const runs = new Graphics2D();\r\n const labels: Label[] = [];\r\n let drawn = false;\r\n const brace = (from: Vector2, to: Vector2, out: Vector2, text: string, align: Label[\"align\"]) => {\r\n if (text === \"\") return;\r\n // A frame centred on the node's own centre, so the path is drawn where it is and not moved onto it.\r\n runs.path({ data: braceOutline(from, to, out, reach), centerBounds: [-1, -1, 1, 1] });\r\n drawn = true;\r\n const mid = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 };\r\n const far = reach + this.labelSize * 0.75;\r\n labels.push({ text, at: { x: mid.x + out.x * far, y: mid.y + out.y * far }, align });\r\n };\r\n const bottom = box.y - box.height / 2 - gap;\r\n for (const part of parts) {\r\n if (!part.upper && this.rowShares[part.column] !== undefined) continue;\r\n const text = this.columnLabels[part.column] ?? \"\";\r\n // Left to right along the bottom, so the bulge, to the edge's right, points down.\r\n brace({ x: part.x + part.width / 2, y: bottom }, { x: part.x - part.width / 2, y: bottom }, { x: 0, y: -1 }, text, \"center\");\r\n }\r\n const first = parts.filter((part) => part.column === 0);\r\n const left = box.x - box.width / 2 - gap;\r\n if (this.rowShares[0] !== undefined) {\r\n first.forEach((part) => {\r\n const text = this.rowLabels[part.upper ? 0 : 1] ?? \"\";\r\n brace({ x: left, y: part.y - part.height / 2 }, { x: left, y: part.y + part.height / 2 }, { x: -1, y: 0 }, text, \"right\");\r\n });\r\n }\r\n if (drawn) {\r\n const fill = fillOps.resolve({ type: \"solid\", color: this.labelColor as NormalizedColor });\r\n ctx.draw(runs.stroke({ weight: 2, fill, align: \"center\", cap: \"round\", join: \"round\" }));\r\n }\r\n return labels;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"sample-space.js","sourceRoot":"","sources":["../../src/structures/sample-space.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,OAAO,EACP,UAAU,EACV,KAAK,GAkBR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAc,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAc1C,wFAAwF;AACxF,MAAM,OAAO,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAEnF,qEAAqE;AACrE,MAAM,KAAK,GAAG,IAAI,CAAC;AAEnB,SAAS,UAAU,CAAC,KAAoC;IACpD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OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,UAA6B,EAAE,CAAC,CAAC;QAC5F,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import {\r\n component2d,\r\n fillOps,\r\n Graphics2D,\r\n Types,\r\n type Color,\r\n type Fill,\r\n type FillResolved,\r\n type NodeOf,\r\n type NormalizedColor,\r\n type PaintProps,\r\n type RenderContext,\r\n type ShadowResolved,\r\n type Size2D,\r\n type StrokeResolved,\r\n type Values,\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 Stroke as _Stroke,\r\n} from \"@motionscript/sdk\";\r\nimport { braceOutline } from \"../kit/brace\";\r\nimport { omit, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\r\nimport { drawLabels, loadFormulas, type Label } from \"../kit/furniture\";\r\nimport { lerpFillScale, readFillScale } from \"../kit/scale\";\r\nimport { formatTick } from \"../kit/ticks\";\r\n\r\nexport interface SampleSpaceProps extends PaintProps {\r\n columnShares?: number[];\r\n rowShares?: number[];\r\n columnFills?: Fill[];\r\n columnLabels?: string[];\r\n rowLabels?: string[];\r\n values?: boolean;\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n}\r\n\r\n/** The parts' paints until told otherwise, a column each, round again past the last. */\r\nconst PALETTE = [\"#58a6ff\", \"#f59e0b\", \"#4ade80\", \"#f472b6\", \"#a78bfa\", \"#2dd4bf\"];\r\n\r\n/** How strongly the lower part of a split column shows its paint. */\r\nconst LOWER = 0.45;\r\n\r\nfunction readShares(value: readonly number[] | undefined): number[] {\r\n return (Array.isArray(value) ? value : []).map((share) => (Number.isFinite(share) && share > 0 ? share : 0));\r\n}\r\n\r\n// Shares tween one by one; a different count has nothing to pair with, and changes at the end.\r\nfunction lerpShares(from: number[], to: number[], t: number): number[] {\r\n if (from.length !== to.length) return t < 1 ? from : to;\r\n return to.map((share, i) => from[i] + (share - from[i]) * t);\r\n}\r\n\r\nconst state = {\r\n // Its parts are painted from `columnFills`, and it trims no outline of its own.\r\n ...omit(PAINT, \"fill\", \"start\", \"end\"),\r\n /** How the whole is shared across, left to right; any numbers, read as shares of their sum. */\r\n columnShares: Types.custom<number[]>([1], { resolve: readShares, lerp: lerpShares, kind: \"vector\" }),\r\n /** Each column's upper share, 0 to 1; a column without one is not cut across. */\r\n rowShares: Types.custom<number[]>([], { resolve: readShares, lerp: lerpShares, kind: \"vector\" }),\r\n /** Each column's paint, left to right, round again past the last; its lower part shows it fainter. */\r\n columnFills: Types.custom<Fill[], FillResolved[][]>([], { resolve: readFillScale, lerp: lerpFillScale, kind: \"vector\" }),\r\n columnLabels: Types.custom<string[]>([], { animatable: false, kind: \"vector\" }),\r\n /** The upper part's name and the lower's, written on the left. */\r\n rowLabels: Types.custom<string[]>([], { animatable: false, kind: \"vector\" }),\r\n /** Write each part's probability in it. */\r\n values: Types.boolean(false, { animatable: false }),\r\n labelSize: Types.number(20, { min: 1, unit: \"px\" }),\r\n labelColor: Types.color(\"#e5e7eb\"),\r\n fontFamily: Types.text(\"\", { animatable: false }),\r\n};\r\n\r\n/** What a sample space is drawn from: its own entries, as its fields and its node both read them. */\r\nexport type SampleSpaceValues = Values<typeof state>;\r\n\r\n/** One part of a sample space: its box in pixels from the node's centre, y up, and its probability. */\r\nexport interface SamplePart {\r\n x: number;\r\n y: number;\r\n width: number;\r\n height: number;\r\n probability: number;\r\n column: number;\r\n upper: boolean;\r\n}\r\n\r\n/**\r\n * A probability's whole, as a box cut into columns by `columnShares` (shares of\r\n * the whole, P(A) and P(not A)) and each column cut again by its `rowShares` entry\r\n * (P(B | A) above, the rest below): each part's area is its probability.\r\n * Braces name the columns below and the rows on the left; `divideTo` moves the\r\n * cuts.\r\n */\r\nexport const SampleSpace = component2d({\r\n key: \"sampleSpace\",\r\n state,\r\n defaults: { stroke: { weight: 2, fill: \"#0b0d12\", align: \"center\" } },\r\n load: (loader, s) => {\r\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\r\n loadFormulas(loader, [...s.columnLabels, ...s.rowLabels]);\r\n },\r\n commands: {\r\n ...omit(PAINT_COMMANDS, \"fillTo\", \"progressTo\", \"flash\"),\r\n /** Move the cuts: the columns' shares, each column's upper share, or both. */\r\n divideTo: { args: [\"columnShares\", \"rowShares\"] },\r\n },\r\n render: (ctx, s) => painted(ctx, () => drawSpace(ctx, s)),\r\n});\r\n\r\nexport type SampleSpace = NodeOf<typeof SampleSpace>;\r\n\r\n/** Each part of a sample space of `size`: columns left to right, upper part first. */\r\nexport function sampleParts(space: SampleSpaceValues, size: Size2D): SamplePart[] {\r\n const box = boxOf(space, size);\r\n const shares = space.columnShares;\r\n const total = shares.reduce((sum, share) => sum + share, 0);\r\n if (!(total > 0) || box.width <= 0 || box.height <= 0) return [];\r\n const out: SamplePart[] = [];\r\n let left = box.x - box.width / 2;\r\n shares.forEach((share, column) => {\r\n const width = (box.width * share) / total;\r\n const p = share / total;\r\n const cut = space.rowShares[column];\r\n const top = box.y + box.height / 2;\r\n if (cut === undefined) {\r\n out.push({ x: left + width / 2, y: box.y, width, height: box.height, probability: p, column, upper: true });\r\n } else {\r\n const upper = Math.min(1, Math.max(0, cut));\r\n const h = box.height * upper;\r\n out.push({ x: left + width / 2, y: top - h / 2, width, height: h, probability: p * upper, column, upper: true });\r\n out.push({ x: left + width / 2, y: top - h - (box.height - h) / 2, width, height: box.height - h, probability: p * (1 - upper), column, upper: false });\r\n }\r\n left += width;\r\n });\r\n return out;\r\n}\r\n\r\nfunction drawSpace(ctx: RenderContext, space: SampleSpaceValues): void {\r\n const parts = sampleParts(space, ctx.size);\r\n if (parts.length === 0) return;\r\n const fills = space.columnFills;\r\n const stroke = space.stroke as StrokeResolved[];\r\n const labels: Label[] = [];\r\n for (const part of parts) {\r\n if (!(part.width > 0) || !(part.height > 0)) continue;\r\n const base = fills.length > 0 ? fills[part.column % fills.length] : fillOps.resolve(PALETTE[part.column % PALETTE.length]);\r\n const paint = part.upper ? base : base.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * LOWER }));\r\n const g = new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height });\r\n ctx.draw(g.shadow(space.shadow as ShadowResolved[]).fill(paint));\r\n if (stroke.length > 0) ctx.draw(new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height }).stroke(stroke));\r\n if (space.values && part.height > space.labelSize && part.width > space.labelSize) {\r\n labels.push({ text: formatTick(Math.round(part.probability * 1000) / 1000, 0.001), at: { x: part.x, y: part.y }, align: \"center\" });\r\n }\r\n }\r\n labels.push(...braces(ctx, space, parts));\r\n const style = { fontSize: space.labelSize, fontFamily: space.fontFamily, color: space.labelColor as NormalizedColor };\r\n for (const part of drawLabels(labels, style)) ctx.draw(part);\r\n}\r\n\r\n/** Room for the braces and their names, below and on the left, taken from the box. */\r\nfunction boxOf(space: SampleSpaceValues, size: Size2D): { x: number; y: number; width: number; height: number } {\r\n const { width, height } = size;\r\n const room = space.labelSize * 2.6;\r\n const below = space.columnLabels.some((label) => label !== \"\") ? room : 0;\r\n const left = space.rowLabels.some((label) => label !== \"\") ? room * 1.6 : 0;\r\n return { x: left / 2, y: below / 2, width: Math.max(0, width - left), height: Math.max(0, height - below) };\r\n}\r\n\r\n/** Braces under each column and beside the first column's parts, and the labels that name them. */\r\nfunction braces(ctx: RenderContext, space: SampleSpaceValues, parts: readonly SamplePart[]): Label[] {\r\n const box = boxOf(space, ctx.size);\r\n const reach = space.labelSize * 0.8;\r\n const gap = 6;\r\n const runs = new Graphics2D();\r\n const labels: Label[] = [];\r\n let drawn = false;\r\n const brace = (from: Vector2, to: Vector2, out: Vector2, text: string, align: Label[\"align\"]) => {\r\n if (text === \"\") return;\r\n // A frame centred on the node's own centre, so the path is drawn where it is and not moved onto it.\r\n runs.path({ data: braceOutline(from, to, out, reach), centerBounds: [-1, -1, 1, 1] });\r\n drawn = true;\r\n const mid = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 };\r\n const far = reach + space.labelSize * 0.75;\r\n labels.push({ text, at: { x: mid.x + out.x * far, y: mid.y + out.y * far }, align });\r\n };\r\n const bottom = box.y - box.height / 2 - gap;\r\n for (const part of parts) {\r\n if (!part.upper && space.rowShares[part.column] !== undefined) continue;\r\n const text = space.columnLabels[part.column] ?? \"\";\r\n // Left to right along the bottom, so the bulge, to the edge's right, points down.\r\n brace({ x: part.x + part.width / 2, y: bottom }, { x: part.x - part.width / 2, y: bottom }, { x: 0, y: -1 }, text, \"center\");\r\n }\r\n const first = parts.filter((part) => part.column === 0);\r\n const left = box.x - box.width / 2 - gap;\r\n if (space.rowShares[0] !== undefined) {\r\n first.forEach((part) => {\r\n const text = space.rowLabels[part.upper ? 0 : 1] ?? \"\";\r\n brace({ x: left, y: part.y - part.height / 2 }, { x: left, y: part.y + part.height / 2 }, { x: -1, y: 0 }, text, \"right\");\r\n });\r\n }\r\n if (drawn) {\r\n const fill = fillOps.resolve({ type: \"solid\", color: space.labelColor as NormalizedColor });\r\n ctx.draw(runs.stroke({ weight: 2, fill, align: \"center\", cap: \"round\", join: \"round\" }));\r\n }\r\n return labels;\r\n}\r\n"]}