@canvas-commons/2d 0.2.0

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 (183) hide show
  1. package/LICENSE +22 -0
  2. package/editor/index.css +40 -0
  3. package/editor/index.js +525 -0
  4. package/editor/index.js.map +1 -0
  5. package/lib/index-OvpZ-GsA.d.ts +5673 -0
  6. package/lib/index-OvpZ-GsA.d.ts.map +1 -0
  7. package/lib/index.d.ts +2 -0
  8. package/lib/index.js +10326 -0
  9. package/lib/index.js.map +1 -0
  10. package/lib/jsx-dev-runtime.d.ts +2 -0
  11. package/lib/jsx-dev-runtime.js +2 -0
  12. package/lib/jsx-runtime.d.ts +2 -0
  13. package/lib/jsx-runtime.js +28 -0
  14. package/lib/jsx-runtime.js.map +1 -0
  15. package/package.json +79 -0
  16. package/src/editor/NodeInspectorConfig.tsx +76 -0
  17. package/src/editor/PreviewOverlayConfig.tsx +65 -0
  18. package/src/editor/Provider.tsx +109 -0
  19. package/src/editor/SceneGraphTabConfig.tsx +87 -0
  20. package/src/editor/icons/CircleIcon.tsx +7 -0
  21. package/src/editor/icons/CodeIcon.tsx +8 -0
  22. package/src/editor/icons/CurveIcon.tsx +7 -0
  23. package/src/editor/icons/GridIcon.tsx +7 -0
  24. package/src/editor/icons/IconMap.ts +35 -0
  25. package/src/editor/icons/ImgIcon.tsx +8 -0
  26. package/src/editor/icons/LayoutIcon.tsx +9 -0
  27. package/src/editor/icons/LineIcon.tsx +7 -0
  28. package/src/editor/icons/NodeIcon.tsx +7 -0
  29. package/src/editor/icons/RayIcon.tsx +7 -0
  30. package/src/editor/icons/RectIcon.tsx +7 -0
  31. package/src/editor/icons/ShapeIcon.tsx +7 -0
  32. package/src/editor/icons/TxtIcon.tsx +8 -0
  33. package/src/editor/icons/VideoIcon.tsx +7 -0
  34. package/src/editor/icons/View2DIcon.tsx +10 -0
  35. package/src/editor/index.css +0 -0
  36. package/src/editor/index.ts +19 -0
  37. package/src/editor/shortcuts.ts +27 -0
  38. package/src/editor/tree/DetachedRoot.tsx +27 -0
  39. package/src/editor/tree/NodeElement.tsx +72 -0
  40. package/src/editor/tree/TreeElement.tsx +70 -0
  41. package/src/editor/tree/TreeRoot.tsx +10 -0
  42. package/src/editor/tree/ViewRoot.tsx +20 -0
  43. package/src/editor/tree/index.module.scss +45 -0
  44. package/src/editor/tree/index.ts +4 -0
  45. package/src/editor/tree/navigation.ts +145 -0
  46. package/src/editor/tsconfig.build.json +5 -0
  47. package/src/editor/tsconfig.json +12 -0
  48. package/src/editor/tsdoc.json +4 -0
  49. package/src/editor/utils/SignalSet.ts +37 -0
  50. package/src/editor/utils/index.ts +1 -0
  51. package/src/editor/vite-env.d.ts +1 -0
  52. package/src/lib/code/CodeCursor.ts +468 -0
  53. package/src/lib/code/CodeDiffer.ts +77 -0
  54. package/src/lib/code/CodeFragment.ts +96 -0
  55. package/src/lib/code/CodeHighlighter.ts +73 -0
  56. package/src/lib/code/CodeMetrics.ts +47 -0
  57. package/src/lib/code/CodeRange.test.ts +113 -0
  58. package/src/lib/code/CodeRange.ts +222 -0
  59. package/src/lib/code/CodeScope.ts +100 -0
  60. package/src/lib/code/CodeSelection.ts +28 -0
  61. package/src/lib/code/CodeSignal.ts +348 -0
  62. package/src/lib/code/CodeTokenizer.ts +54 -0
  63. package/src/lib/code/DefaultHighlightStyle.ts +98 -0
  64. package/src/lib/code/LezerHighlighter.ts +113 -0
  65. package/src/lib/code/diff.test.ts +311 -0
  66. package/src/lib/code/diff.ts +319 -0
  67. package/src/lib/code/extractRange.ts +125 -0
  68. package/src/lib/code/index.ts +13 -0
  69. package/src/lib/components/Bezier.ts +103 -0
  70. package/src/lib/components/Camera.ts +401 -0
  71. package/src/lib/components/Circle.ts +310 -0
  72. package/src/lib/components/Code.ts +532 -0
  73. package/src/lib/components/CubicBezier.ts +115 -0
  74. package/src/lib/components/Curve.ts +460 -0
  75. package/src/lib/components/Grid.ts +134 -0
  76. package/src/lib/components/Icon.ts +153 -0
  77. package/src/lib/components/Img.ts +328 -0
  78. package/src/lib/components/Knot.ts +156 -0
  79. package/src/lib/components/Latex.ts +537 -0
  80. package/src/lib/components/Layout.ts +1101 -0
  81. package/src/lib/components/Line.ts +394 -0
  82. package/src/lib/components/Node.ts +1941 -0
  83. package/src/lib/components/Path.ts +132 -0
  84. package/src/lib/components/Polygon.ts +266 -0
  85. package/src/lib/components/QuadBezier.ts +103 -0
  86. package/src/lib/components/Ray.ts +126 -0
  87. package/src/lib/components/Rect.ts +219 -0
  88. package/src/lib/components/SVG.ts +853 -0
  89. package/src/lib/components/Shape.ts +322 -0
  90. package/src/lib/components/Spline.ts +318 -0
  91. package/src/lib/components/Txt.test.tsx +81 -0
  92. package/src/lib/components/Txt.ts +204 -0
  93. package/src/lib/components/TxtLeaf.ts +210 -0
  94. package/src/lib/components/Video.ts +368 -0
  95. package/src/lib/components/View2D.ts +85 -0
  96. package/src/lib/components/__logs__/image-without-source.ts +18 -0
  97. package/src/lib/components/__logs__/line-without-points.ts +31 -0
  98. package/src/lib/components/__logs__/reactive-playback-rate.ts +22 -0
  99. package/src/lib/components/__logs__/spline-with-insufficient-knots.ts +25 -0
  100. package/src/lib/components/__tests__/Camera.test.tsx +73 -0
  101. package/src/lib/components/__tests__/children.test.tsx +142 -0
  102. package/src/lib/components/__tests__/clone.test.tsx +126 -0
  103. package/src/lib/components/__tests__/fontInheritance.test.tsx +102 -0
  104. package/src/lib/components/__tests__/generatorTest.ts +27 -0
  105. package/src/lib/components/__tests__/mockScene2D.ts +50 -0
  106. package/src/lib/components/__tests__/query.test.tsx +122 -0
  107. package/src/lib/components/__tests__/state.test.tsx +60 -0
  108. package/src/lib/components/index.ts +26 -0
  109. package/src/lib/components/types.ts +35 -0
  110. package/src/lib/curves/ArcSegment.ts +169 -0
  111. package/src/lib/curves/CircleSegment.ts +99 -0
  112. package/src/lib/curves/CubicBezierSegment.ts +80 -0
  113. package/src/lib/curves/CurveDrawingInfo.ts +11 -0
  114. package/src/lib/curves/CurvePoint.ts +15 -0
  115. package/src/lib/curves/CurveProfile.ts +28 -0
  116. package/src/lib/curves/KnotInfo.ts +10 -0
  117. package/src/lib/curves/LineSegment.ts +75 -0
  118. package/src/lib/curves/Polynomial.ts +355 -0
  119. package/src/lib/curves/Polynomial2D.ts +62 -0
  120. package/src/lib/curves/PolynomialSegment.ts +151 -0
  121. package/src/lib/curves/QuadBezierSegment.ts +66 -0
  122. package/src/lib/curves/Segment.ts +31 -0
  123. package/src/lib/curves/UniformPolynomialCurveSampler.ts +93 -0
  124. package/src/lib/curves/createCurveProfileLerp.ts +471 -0
  125. package/src/lib/curves/getBezierSplineProfile.ts +227 -0
  126. package/src/lib/curves/getCircleProfile.ts +86 -0
  127. package/src/lib/curves/getPathProfile.ts +177 -0
  128. package/src/lib/curves/getPointAtDistance.ts +21 -0
  129. package/src/lib/curves/getPolylineProfile.test.ts +21 -0
  130. package/src/lib/curves/getPolylineProfile.ts +88 -0
  131. package/src/lib/curves/getRectProfile.ts +138 -0
  132. package/src/lib/curves/index.ts +16 -0
  133. package/src/lib/decorators/canvasStyleSignal.ts +15 -0
  134. package/src/lib/decorators/colorSignal.ts +9 -0
  135. package/src/lib/decorators/compound.ts +85 -0
  136. package/src/lib/decorators/computed.ts +18 -0
  137. package/src/lib/decorators/defaultStyle.ts +15 -0
  138. package/src/lib/decorators/filtersSignal.ts +133 -0
  139. package/src/lib/decorators/index.ts +10 -0
  140. package/src/lib/decorators/initializers.ts +32 -0
  141. package/src/lib/decorators/nodeName.ts +13 -0
  142. package/src/lib/decorators/signal.test.ts +89 -0
  143. package/src/lib/decorators/signal.ts +348 -0
  144. package/src/lib/decorators/spacingSignal.ts +15 -0
  145. package/src/lib/decorators/transformSignals.test.ts +858 -0
  146. package/src/lib/decorators/transformSignals.ts +1633 -0
  147. package/src/lib/decorators/vector2Signal.ts +35 -0
  148. package/src/lib/globals.d.ts +2 -0
  149. package/src/lib/index.ts +9 -0
  150. package/src/lib/jsx-dev-runtime.ts +2 -0
  151. package/src/lib/jsx-runtime.ts +45 -0
  152. package/src/lib/morphers/PathMorpher.ts +8 -0
  153. package/src/lib/morphers/defaultMorpher.ts +43 -0
  154. package/src/lib/morphers/index.ts +4 -0
  155. package/src/lib/morphers/manimMorpher.ts +658 -0
  156. package/src/lib/parse-svg-path.d.ts +14 -0
  157. package/src/lib/partials/Filter.ts +185 -0
  158. package/src/lib/partials/Gradient.ts +103 -0
  159. package/src/lib/partials/Pattern.ts +35 -0
  160. package/src/lib/partials/RoughConfig.ts +180 -0
  161. package/src/lib/partials/ShaderConfig.ts +122 -0
  162. package/src/lib/partials/index.ts +5 -0
  163. package/src/lib/partials/types.ts +58 -0
  164. package/src/lib/scenes/Scene2D.ts +167 -0
  165. package/src/lib/scenes/index.ts +3 -0
  166. package/src/lib/scenes/makeScene2D.ts +19 -0
  167. package/src/lib/scenes/useScene2D.ts +6 -0
  168. package/src/lib/tsconfig.build.json +5 -0
  169. package/src/lib/tsconfig.json +11 -0
  170. package/src/lib/tsdoc.json +4 -0
  171. package/src/lib/utils/CanvasUtils.ts +304 -0
  172. package/src/lib/utils/PathDataBuilder.ts +320 -0
  173. package/src/lib/utils/diff.test.ts +453 -0
  174. package/src/lib/utils/diff.ts +148 -0
  175. package/src/lib/utils/index.ts +5 -0
  176. package/src/lib/utils/is.ts +11 -0
  177. package/src/lib/utils/makeSignalExtensions.ts +29 -0
  178. package/src/lib/utils/rough.ts +513 -0
  179. package/src/lib/utils/withDefaults.tsx +26 -0
  180. package/src/tsconfig.base.json +18 -0
  181. package/src/tsconfig.build.json +8 -0
  182. package/src/tsconfig.json +5 -0
  183. package/tsconfig.project.json +7 -0
@@ -0,0 +1,1101 @@
1
+ import {
2
+ BBox,
3
+ DEFAULT,
4
+ Direction,
5
+ InterpolationFunction,
6
+ Origin,
7
+ PossibleSpacing,
8
+ PossibleVector2,
9
+ SerializedVector2,
10
+ Signal,
11
+ SignalValue,
12
+ SimpleSignal,
13
+ SpacingSignal,
14
+ ThreadGenerator,
15
+ TimingFunction,
16
+ Vector2,
17
+ Vector2Signal,
18
+ boolLerp,
19
+ deepLerp,
20
+ modify,
21
+ originToOffset,
22
+ threadable,
23
+ tween,
24
+ } from '@canvas-commons/core';
25
+ import {
26
+ Vector2LengthSignal,
27
+ addInitializer,
28
+ cloneable,
29
+ computed,
30
+ defaultStyle,
31
+ initial,
32
+ interpolation,
33
+ nodeName,
34
+ signal,
35
+ vector2Signal,
36
+ wrapper,
37
+ } from '../decorators';
38
+ import {spacingSignal} from '../decorators/spacingSignal';
39
+ import {
40
+ LayoutPositionSignal,
41
+ LayoutPositionSignalContext,
42
+ } from '../decorators/transformSignals';
43
+ import {
44
+ DesiredLength,
45
+ FlexBasis,
46
+ FlexContent,
47
+ FlexDirection,
48
+ FlexItems,
49
+ FlexWrap,
50
+ LayoutMode,
51
+ Length,
52
+ LengthLimit,
53
+ TextWrap,
54
+ } from '../partials';
55
+ import {drawLine, drawPivot, is} from '../utils';
56
+ import {Node, NodeProps} from './Node';
57
+
58
+ export interface LayoutProps extends NodeProps {
59
+ layout?: LayoutMode;
60
+ tagName?: keyof HTMLElementTagNameMap;
61
+
62
+ width?: SignalValue<Length>;
63
+ height?: SignalValue<Length>;
64
+ maxWidth?: SignalValue<LengthLimit>;
65
+ maxHeight?: SignalValue<LengthLimit>;
66
+ minWidth?: SignalValue<LengthLimit>;
67
+ minHeight?: SignalValue<LengthLimit>;
68
+ ratio?: SignalValue<number>;
69
+
70
+ marginTop?: SignalValue<number>;
71
+ marginBottom?: SignalValue<number>;
72
+ marginLeft?: SignalValue<number>;
73
+ marginRight?: SignalValue<number>;
74
+ margin?: SignalValue<PossibleSpacing>;
75
+
76
+ paddingTop?: SignalValue<number>;
77
+ paddingBottom?: SignalValue<number>;
78
+ paddingLeft?: SignalValue<number>;
79
+ paddingRight?: SignalValue<number>;
80
+ padding?: SignalValue<PossibleSpacing>;
81
+
82
+ direction?: SignalValue<FlexDirection>;
83
+ basis?: SignalValue<FlexBasis>;
84
+ grow?: SignalValue<number>;
85
+ shrink?: SignalValue<number>;
86
+ wrap?: SignalValue<FlexWrap>;
87
+
88
+ justifyContent?: SignalValue<FlexContent>;
89
+ alignContent?: SignalValue<FlexContent>;
90
+ alignItems?: SignalValue<FlexItems>;
91
+ alignSelf?: SignalValue<FlexItems>;
92
+ rowGap?: SignalValue<Length>;
93
+ columnGap?: SignalValue<Length>;
94
+ gap?: SignalValue<PossibleVector2<Length>>;
95
+
96
+ fontFamily?: SignalValue<string>;
97
+ fontSize?: SignalValue<number>;
98
+ fontStyle?: SignalValue<string>;
99
+ fontWeight?: SignalValue<number>;
100
+ lineHeight?: SignalValue<Length>;
101
+ letterSpacing?: SignalValue<number>;
102
+ textWrap?: SignalValue<TextWrap>;
103
+ textDirection?: SignalValue<CanvasDirection>;
104
+ textAlign?: SignalValue<CanvasTextAlign>;
105
+
106
+ size?: SignalValue<PossibleVector2<Length>>;
107
+ anchorX?: SignalValue<number>;
108
+ anchorY?: SignalValue<number>;
109
+ anchor?: SignalValue<PossibleVector2>;
110
+ /**
111
+ * The position of the center of this node.
112
+ *
113
+ * @remarks
114
+ * This shortcut property will set the node's position so that the center ends
115
+ * up in the given place.
116
+ * If present, overrides the {@link NodeProps.position} property.
117
+ * When {@link anchor} is not set, this will be the same as the
118
+ * {@link NodeProps.position}.
119
+ */
120
+ middle?: SignalValue<PossibleVector2>;
121
+ /**
122
+ * The position of the top edge of this node.
123
+ *
124
+ * @remarks
125
+ * This shortcut property will set the node's position so that the top edge
126
+ * ends up in the given place.
127
+ * If present, overrides the {@link NodeProps.position} property.
128
+ */
129
+ top?: SignalValue<PossibleVector2>;
130
+ /**
131
+ * The position of the bottom edge of this node.
132
+ *
133
+ * @remarks
134
+ * This shortcut property will set the node's position so that the bottom edge
135
+ * ends up in the given place.
136
+ * If present, overrides the {@link NodeProps.position} property.
137
+ */
138
+ bottom?: SignalValue<PossibleVector2>;
139
+ /**
140
+ * The position of the left edge of this node.
141
+ *
142
+ * @remarks
143
+ * This shortcut property will set the node's position so that the left edge
144
+ * ends up in the given place.
145
+ * If present, overrides the {@link NodeProps.position} property.
146
+ */
147
+ left?: SignalValue<PossibleVector2>;
148
+ /**
149
+ * The position of the right edge of this node.
150
+ *
151
+ * @remarks
152
+ * This shortcut property will set the node's position so that the right edge
153
+ * ends up in the given place.
154
+ * If present, overrides the {@link NodeProps.position} property.
155
+ */
156
+ right?: SignalValue<PossibleVector2>;
157
+ /**
158
+ * The position of the top left corner of this node.
159
+ *
160
+ * @remarks
161
+ * This shortcut property will set the node's position so that the top left
162
+ * corner ends up in the given place.
163
+ * If present, overrides the {@link NodeProps.position} property.
164
+ */
165
+ topLeft?: SignalValue<PossibleVector2>;
166
+ /**
167
+ * The position of the top right corner of this node.
168
+ *
169
+ * @remarks
170
+ * This shortcut property will set the node's position so that the top right
171
+ * corner ends up in the given place.
172
+ * If present, overrides the {@link NodeProps.position} property.
173
+ */
174
+ topRight?: SignalValue<PossibleVector2>;
175
+ /**
176
+ * The position of the bottom left corner of this node.
177
+ *
178
+ * @remarks
179
+ * This shortcut property will set the node's position so that the bottom left
180
+ * corner ends up in the given place.
181
+ * If present, overrides the {@link NodeProps.position} property.
182
+ */
183
+ bottomLeft?: SignalValue<PossibleVector2>;
184
+ /**
185
+ * The position of the bottom right corner of this node.
186
+ *
187
+ * @remarks
188
+ * This shortcut property will set the node's position so that the bottom
189
+ * right corner ends up in the given place.
190
+ * If present, overrides the {@link NodeProps.position} property.
191
+ */
192
+ bottomRight?: SignalValue<PossibleVector2>;
193
+ clip?: SignalValue<boolean>;
194
+ }
195
+
196
+ @nodeName('Layout')
197
+ export class Layout extends Node {
198
+ @initial(null)
199
+ @interpolation(boolLerp)
200
+ @signal()
201
+ declare public readonly layout: SimpleSignal<LayoutMode, this>;
202
+
203
+ @initial(null)
204
+ @signal()
205
+ declare public readonly maxWidth: SimpleSignal<LengthLimit, this>;
206
+ @initial(null)
207
+ @signal()
208
+ declare public readonly maxHeight: SimpleSignal<LengthLimit, this>;
209
+ @initial(null)
210
+ @signal()
211
+ declare public readonly minWidth: SimpleSignal<LengthLimit, this>;
212
+ @initial(null)
213
+ @signal()
214
+ declare public readonly minHeight: SimpleSignal<LengthLimit, this>;
215
+ @initial(null)
216
+ @signal()
217
+ declare public readonly ratio: SimpleSignal<number | null, this>;
218
+
219
+ @spacingSignal('margin')
220
+ declare public readonly margin: SpacingSignal<this>;
221
+
222
+ @spacingSignal('padding')
223
+ declare public readonly padding: SpacingSignal<this>;
224
+
225
+ @initial('row')
226
+ @signal()
227
+ declare public readonly direction: SimpleSignal<FlexDirection, this>;
228
+ @initial(null)
229
+ @signal()
230
+ declare public readonly basis: SimpleSignal<FlexBasis, this>;
231
+ @initial(0)
232
+ @signal()
233
+ declare public readonly grow: SimpleSignal<number, this>;
234
+ @initial(1)
235
+ @signal()
236
+ declare public readonly shrink: SimpleSignal<number, this>;
237
+ @initial('nowrap')
238
+ @signal()
239
+ declare public readonly wrap: SimpleSignal<FlexWrap, this>;
240
+
241
+ @initial('start')
242
+ @signal()
243
+ declare public readonly justifyContent: SimpleSignal<FlexContent, this>;
244
+ @initial('normal')
245
+ @signal()
246
+ declare public readonly alignContent: SimpleSignal<FlexContent, this>;
247
+ @initial('stretch')
248
+ @signal()
249
+ declare public readonly alignItems: SimpleSignal<FlexItems, this>;
250
+ @initial('auto')
251
+ @signal()
252
+ declare public readonly alignSelf: SimpleSignal<FlexItems, this>;
253
+ @initial(0)
254
+ @vector2Signal({x: 'columnGap', y: 'rowGap'})
255
+ declare public readonly gap: Vector2LengthSignal<this>;
256
+ public get columnGap(): Signal<Length, number, this> {
257
+ return this.gap.x;
258
+ }
259
+ public get rowGap(): Signal<Length, number, this> {
260
+ return this.gap.y;
261
+ }
262
+
263
+ @defaultStyle('Roboto')
264
+ @signal()
265
+ declare public readonly fontFamily: SimpleSignal<string, this>;
266
+ @defaultStyle(48)
267
+ @signal()
268
+ declare public readonly fontSize: SimpleSignal<number, this>;
269
+ @defaultStyle('normal')
270
+ @signal()
271
+ declare public readonly fontStyle: SimpleSignal<string, this>;
272
+ @defaultStyle(500)
273
+ @signal()
274
+ declare public readonly fontWeight: SimpleSignal<number, this>;
275
+ @defaultStyle('120%')
276
+ @signal()
277
+ declare public readonly lineHeight: SimpleSignal<Length, this>;
278
+ @defaultStyle(0)
279
+ @signal()
280
+ declare public readonly letterSpacing: SimpleSignal<number, this>;
281
+
282
+ @defaultStyle(false)
283
+ @signal()
284
+ declare public readonly textWrap: SimpleSignal<TextWrap, this>;
285
+ @initial('ltr')
286
+ @signal()
287
+ declare public readonly textDirection: SimpleSignal<CanvasDirection, this>;
288
+ @defaultStyle('start')
289
+ @signal()
290
+ declare public readonly textAlign: SimpleSignal<CanvasTextAlign, this>;
291
+
292
+ protected getX(): number {
293
+ if (this.isLayoutRoot()) {
294
+ return this.x.context.getter();
295
+ }
296
+
297
+ return this.computedPosition().x;
298
+ }
299
+ protected setX(value: SignalValue<number>) {
300
+ this.x.context.setter(value);
301
+ }
302
+
303
+ protected getY(): number {
304
+ if (this.isLayoutRoot()) {
305
+ return this.y.context.getter();
306
+ }
307
+
308
+ return this.computedPosition().y;
309
+ }
310
+ protected setY(value: SignalValue<number>) {
311
+ this.y.context.setter(value);
312
+ }
313
+
314
+ /**
315
+ * Represents the size of this node.
316
+ *
317
+ * @remarks
318
+ * A size is a two-dimensional vector, where `x` represents the `width`, and `y`
319
+ * represents the `height`.
320
+ *
321
+ * The value of both x and y is of type {@link partials.Length} which is
322
+ * either:
323
+ * - `number` - the desired length in pixels
324
+ * - `${number}%` - a string with the desired length in percents, for example
325
+ * `'50%'`
326
+ * - `null` - an automatic length
327
+ *
328
+ * When retrieving the size, all units are converted to pixels, using the
329
+ * current state of the layout. For example, retrieving the width set to
330
+ * `'50%'`, while the parent has a width of `200px` will result in the number
331
+ * `100` being returned.
332
+ *
333
+ * When the node is not part of the layout, setting its size using percents
334
+ * refers to the size of the entire scene.
335
+ *
336
+ * @example
337
+ * Initializing the size:
338
+ * ```tsx
339
+ * // with a possible vector:
340
+ * <Node size={['50%', 200]} />
341
+ * // with individual components:
342
+ * <Node width={'50%'} height={200} />
343
+ * ```
344
+ *
345
+ * Accessing the size:
346
+ * ```tsx
347
+ * // retrieving the vector:
348
+ * const size = node.size();
349
+ * // retrieving an individual component:
350
+ * const width = node.size.x();
351
+ * ```
352
+ *
353
+ * Setting the size:
354
+ * ```tsx
355
+ * // with a possible vector:
356
+ * node.size(['50%', 200]);
357
+ * node.size(() => ['50%', 200]);
358
+ * // with individual components:
359
+ * node.size.x('50%');
360
+ * node.size.x(() => '50%');
361
+ * ```
362
+ */
363
+ @initial({x: null, y: null})
364
+ @vector2Signal({x: 'width', y: 'height'})
365
+ declare public readonly size: Vector2LengthSignal<this>;
366
+ public get width(): Signal<Length, number, this> {
367
+ return this.size.x;
368
+ }
369
+ public get height(): Signal<Length, number, this> {
370
+ return this.size.y;
371
+ }
372
+
373
+ protected getWidth(): number {
374
+ return this.computedSize().width;
375
+ }
376
+ protected setWidth(value: SignalValue<Length>) {
377
+ this.width.context.setter(value);
378
+ }
379
+
380
+ @threadable()
381
+ protected *tweenWidth(
382
+ value: SignalValue<Length>,
383
+ time: number,
384
+ timingFunction: TimingFunction,
385
+ interpolationFunction: InterpolationFunction<Length>,
386
+ ): ThreadGenerator {
387
+ const width = this.desiredSize().x;
388
+ const lock = typeof width !== 'number' || typeof value !== 'number';
389
+ let from: number;
390
+ if (lock) {
391
+ from = this.size.x();
392
+ } else {
393
+ from = width;
394
+ }
395
+
396
+ let to: number;
397
+ if (lock) {
398
+ this.size.x(value);
399
+ to = this.size.x();
400
+ } else {
401
+ to = value;
402
+ }
403
+
404
+ this.size.x(from);
405
+ lock && this.lockSize();
406
+ yield* tween(time, value =>
407
+ this.size.x(interpolationFunction(from, to, timingFunction(value))),
408
+ );
409
+ this.size.x(value);
410
+ lock && this.releaseSize();
411
+ }
412
+
413
+ protected getHeight(): number {
414
+ return this.computedSize().height;
415
+ }
416
+ protected setHeight(value: SignalValue<Length>) {
417
+ this.height.context.setter(value);
418
+ }
419
+
420
+ @threadable()
421
+ protected *tweenHeight(
422
+ value: SignalValue<Length>,
423
+ time: number,
424
+ timingFunction: TimingFunction,
425
+ interpolationFunction: InterpolationFunction<Length>,
426
+ ): ThreadGenerator {
427
+ const height = this.desiredSize().y;
428
+ const lock = typeof height !== 'number' || typeof value !== 'number';
429
+
430
+ let from: number;
431
+ if (lock) {
432
+ from = this.size.y();
433
+ } else {
434
+ from = height;
435
+ }
436
+
437
+ let to: number;
438
+ if (lock) {
439
+ this.size.y(value);
440
+ to = this.size.y();
441
+ } else {
442
+ to = value;
443
+ }
444
+
445
+ this.size.y(from);
446
+ lock && this.lockSize();
447
+ yield* tween(time, value =>
448
+ this.size.y(interpolationFunction(from, to, timingFunction(value))),
449
+ );
450
+ this.size.y(value);
451
+ lock && this.releaseSize();
452
+ }
453
+
454
+ /**
455
+ * Get the desired size of this node.
456
+ *
457
+ * @remarks
458
+ * This method can be used to control the size using external factors.
459
+ * By default, the returned size is the same as the one declared by the user.
460
+ */
461
+ @computed()
462
+ protected desiredSize(): SerializedVector2<DesiredLength> {
463
+ return {
464
+ x: this.width.context.getter(),
465
+ y: this.height.context.getter(),
466
+ };
467
+ }
468
+
469
+ @threadable()
470
+ protected *tweenSize(
471
+ value: SignalValue<SerializedVector2<Length>>,
472
+ time: number,
473
+ timingFunction: TimingFunction,
474
+ interpolationFunction: InterpolationFunction<Vector2>,
475
+ ): ThreadGenerator {
476
+ const size = this.desiredSize();
477
+ let from: Vector2;
478
+ if (typeof size.x !== 'number' || typeof size.y !== 'number') {
479
+ from = this.size();
480
+ } else {
481
+ from = new Vector2(<Vector2>size);
482
+ }
483
+
484
+ let to: Vector2;
485
+ if (
486
+ typeof value === 'object' &&
487
+ typeof value.x === 'number' &&
488
+ typeof value.y === 'number'
489
+ ) {
490
+ to = new Vector2(<Vector2>value);
491
+ } else {
492
+ this.size(value);
493
+ to = this.size();
494
+ }
495
+
496
+ this.size(from);
497
+ this.lockSize();
498
+ yield* tween(time, value =>
499
+ this.size(interpolationFunction(from, to, timingFunction(value))),
500
+ );
501
+ this.releaseSize();
502
+ this.size(value);
503
+ }
504
+
505
+ /**
506
+ * Represents the offset of this node's origin.
507
+ *
508
+ * @remarks
509
+ * By default, the origin of a node is located at its center. The origin
510
+ * serves as the pivot point when rotating and scaling a node, but it doesn't
511
+ * affect the placement of its children.
512
+ *
513
+ * The value is relative to the size of this node. A value of `1` means as far
514
+ * to the right/bottom as possible. Here are a few examples of anchors:
515
+ * - `[-1, -1]` - top left corner
516
+ * - `[1, -1]` - top right corner
517
+ * - `[0, 1]` - bottom edge
518
+ * - `[-1, 1]` - bottom left corner
519
+ */
520
+ @vector2Signal('anchor')
521
+ declare public readonly anchor: Vector2Signal<this>;
522
+
523
+ /**
524
+ * The position of the center of this node.
525
+ *
526
+ * @remarks
527
+ * When set, this shortcut property will modify the node's position so that
528
+ * the center ends up in the given place.
529
+ *
530
+ * If the {@link anchor} has not been changed, this will be the same as the
531
+ * {@link position}.
532
+ *
533
+ * When retrieved, it will return the position of the center in the parent
534
+ * space.
535
+ */
536
+ @originSignal(Origin.Middle)
537
+ declare public readonly middle: LayoutPositionSignal<this>;
538
+
539
+ /**
540
+ * The position of the top edge of this node.
541
+ *
542
+ * @remarks
543
+ * When set, this shortcut property will modify the node's position so that
544
+ * the top edge ends up in the given place.
545
+ *
546
+ * When retrieved, it will return the position of the top edge in the parent
547
+ * space.
548
+ */
549
+ @originSignal(Origin.Top)
550
+ declare public readonly top: LayoutPositionSignal<this>;
551
+ /**
552
+ * The position of the bottom edge of this node.
553
+ *
554
+ * @remarks
555
+ * When set, this shortcut property will modify the node's position so that
556
+ * the bottom edge ends up in the given place.
557
+ *
558
+ * When retrieved, it will return the position of the bottom edge in the
559
+ * parent space.
560
+ */
561
+ @originSignal(Origin.Bottom)
562
+ declare public readonly bottom: LayoutPositionSignal<this>;
563
+ /**
564
+ * The position of the left edge of this node.
565
+ *
566
+ * @remarks
567
+ * When set, this shortcut property will modify the node's position so that
568
+ * the left edge ends up in the given place.
569
+ *
570
+ * When retrieved, it will return the position of the left edge in the parent
571
+ * space.
572
+ */
573
+ @originSignal(Origin.Left)
574
+ declare public readonly left: LayoutPositionSignal<this>;
575
+ /**
576
+ * The position of the right edge of this node.
577
+ *
578
+ * @remarks
579
+ * When set, this shortcut property will modify the node's position so that
580
+ * the right edge ends up in the given place.
581
+ *
582
+ * When retrieved, it will return the position of the right edge in the parent
583
+ * space.
584
+ */
585
+ @originSignal(Origin.Right)
586
+ declare public readonly right: LayoutPositionSignal<this>;
587
+ /**
588
+ * The position of the top left corner of this node.
589
+ *
590
+ * @remarks
591
+ * When set, this shortcut property will modify the node's position so that
592
+ * the top left corner ends up in the given place.
593
+ *
594
+ * When retrieved, it will return the position of the top left corner in the
595
+ * parent space.
596
+ */
597
+ @originSignal(Origin.TopLeft)
598
+ declare public readonly topLeft: LayoutPositionSignal<this>;
599
+ /**
600
+ * The position of the top right corner of this node.
601
+ *
602
+ * @remarks
603
+ * When set, this shortcut property will modify the node's position so that
604
+ * the top right corner ends up in the given place.
605
+ *
606
+ * When retrieved, it will return the position of the top right corner in the
607
+ * parent space.
608
+ */
609
+ @originSignal(Origin.TopRight)
610
+ declare public readonly topRight: LayoutPositionSignal<this>;
611
+ /**
612
+ * The position of the bottom left corner of this node.
613
+ *
614
+ * @remarks
615
+ * When set, this shortcut property will modify the node's position so that
616
+ * the bottom left corner ends up in the given place.
617
+ *
618
+ * When retrieved, it will return the position of the bottom left corner in
619
+ * the parent space.
620
+ */
621
+ @originSignal(Origin.BottomLeft)
622
+ declare public readonly bottomLeft: LayoutPositionSignal<this>;
623
+ /**
624
+ * The position of the bottom right corner of this node.
625
+ *
626
+ * @remarks
627
+ * When set, this shortcut property will modify the node's position so that
628
+ * the bottom right corner ends up in the given place.
629
+ *
630
+ * When retrieved, it will return the position of the bottom right corner in
631
+ * the parent space.
632
+ */
633
+ @originSignal(Origin.BottomRight)
634
+ declare public readonly bottomRight: LayoutPositionSignal<this>;
635
+
636
+ /**
637
+ * Get the cardinal point corresponding to the given origin.
638
+ *
639
+ * @param origin - The origin or direction of the point.
640
+ */
641
+ public cardinalPoint(origin: Origin | Direction): LayoutPositionSignal<this> {
642
+ switch (origin) {
643
+ case Origin.TopLeft:
644
+ return this.topLeft;
645
+ case Origin.TopRight:
646
+ return this.topRight;
647
+ case Origin.BottomLeft:
648
+ return this.bottomLeft;
649
+ case Origin.BottomRight:
650
+ return this.bottomRight;
651
+ case Origin.Top:
652
+ case Direction.Top:
653
+ return this.top;
654
+ case Origin.Bottom:
655
+ case Direction.Bottom:
656
+ return this.bottom;
657
+ case Origin.Left:
658
+ case Direction.Left:
659
+ return this.left;
660
+ case Origin.Right:
661
+ case Direction.Right:
662
+ return this.right;
663
+ default:
664
+ return this.middle;
665
+ }
666
+ }
667
+
668
+ @initial(false)
669
+ @signal()
670
+ declare public readonly clip: SimpleSignal<boolean, this>;
671
+
672
+ declare public element: HTMLElement;
673
+ declare public styles: CSSStyleDeclaration;
674
+
675
+ @initial(0)
676
+ @signal()
677
+ declare protected readonly sizeLockCounter: SimpleSignal<number, this>;
678
+
679
+ public constructor(props: LayoutProps) {
680
+ super(props);
681
+ this.element.dataset.canvasCommonsKey = this.key;
682
+ }
683
+
684
+ public lockSize() {
685
+ this.sizeLockCounter(this.sizeLockCounter() + 1);
686
+ }
687
+
688
+ public releaseSize() {
689
+ this.sizeLockCounter(this.sizeLockCounter() - 1);
690
+ }
691
+
692
+ @computed()
693
+ protected parentTransform(): Layout | null {
694
+ return this.findAncestor(is(Layout));
695
+ }
696
+
697
+ @computed()
698
+ public anchorPosition() {
699
+ const size = this.computedSize();
700
+ const offset = this.anchor();
701
+
702
+ return size.scale(0.5).mul(offset);
703
+ }
704
+
705
+ /**
706
+ * Get the resolved layout mode of this node.
707
+ *
708
+ * @remarks
709
+ * When the mode is `null`, its value will be inherited from the parent.
710
+ *
711
+ * Use {@link layout} to get the raw mode set for this node (without
712
+ * inheritance).
713
+ */
714
+ @computed()
715
+ public layoutEnabled(): boolean {
716
+ return this.layout() ?? this.parentTransform()?.layoutEnabled() ?? false;
717
+ }
718
+
719
+ @computed()
720
+ public isLayoutRoot(): boolean {
721
+ return !this.layoutEnabled() || !this.parentTransform()?.layoutEnabled();
722
+ }
723
+
724
+ public override localToParent(): DOMMatrix {
725
+ const matrix = super.localToParent();
726
+ const offset = this.anchor();
727
+ if (!offset.exactlyEquals(Vector2.zero)) {
728
+ const translate = this.size().mul(offset).scale(-0.5);
729
+ matrix.translateSelf(translate.x, translate.y);
730
+ }
731
+
732
+ return matrix;
733
+ }
734
+
735
+ /**
736
+ * A simplified version of {@link localToParent} matrix used for transforming
737
+ * direction vectors.
738
+ *
739
+ * @internal
740
+ */
741
+ @computed()
742
+ protected scalingRotationMatrix(): DOMMatrix {
743
+ const matrix = new DOMMatrix();
744
+
745
+ matrix.rotateSelf(0, 0, this.rotation());
746
+ matrix.scaleSelf(this.scale.x(), this.scale.y());
747
+
748
+ const offset = this.anchor();
749
+ if (!offset.exactlyEquals(Vector2.zero)) {
750
+ const translate = this.size().mul(offset).scale(-0.5);
751
+ matrix.translateSelf(translate.x, translate.y);
752
+ }
753
+
754
+ return matrix;
755
+ }
756
+
757
+ protected getComputedLayout(): BBox {
758
+ return new BBox(this.element.getBoundingClientRect());
759
+ }
760
+
761
+ @computed()
762
+ public computedPosition(): Vector2 {
763
+ this.requestLayoutUpdate();
764
+ const box = this.getComputedLayout();
765
+
766
+ const position = new Vector2(
767
+ box.x + (box.width / 2) * this.anchor.x(),
768
+ box.y + (box.height / 2) * this.anchor.y(),
769
+ );
770
+
771
+ const parent = this.parentTransform();
772
+ if (parent) {
773
+ const parentRect = parent.getComputedLayout();
774
+ position.x -= parentRect.x + (parentRect.width - box.width) / 2;
775
+ position.y -= parentRect.y + (parentRect.height - box.height) / 2;
776
+ }
777
+
778
+ return position;
779
+ }
780
+
781
+ @computed()
782
+ protected computedSize(): Vector2 {
783
+ this.requestLayoutUpdate();
784
+ return this.getComputedLayout().size;
785
+ }
786
+
787
+ /**
788
+ * Find the closest layout root and apply any new layout changes.
789
+ */
790
+ @computed()
791
+ protected requestLayoutUpdate() {
792
+ const parent = this.parentTransform();
793
+ if (this.appendedToView()) {
794
+ parent?.requestFontUpdate();
795
+ this.updateLayout();
796
+ } else {
797
+ parent!.requestLayoutUpdate();
798
+ }
799
+ }
800
+
801
+ @computed()
802
+ protected appendedToView() {
803
+ const root = this.isLayoutRoot();
804
+ if (root) {
805
+ this.view().element.append(this.element);
806
+ }
807
+
808
+ return root;
809
+ }
810
+
811
+ /**
812
+ * Apply any new layout changes to this node and its children.
813
+ */
814
+ @computed()
815
+ protected updateLayout() {
816
+ this.applyFont();
817
+ this.applyFlex();
818
+ if (this.layoutEnabled()) {
819
+ const children = this.layoutChildren();
820
+ for (const child of children) {
821
+ child.updateLayout();
822
+ }
823
+ }
824
+ }
825
+
826
+ @computed()
827
+ protected layoutChildren(): Layout[] {
828
+ const queue = [...this.children()];
829
+ const result: Layout[] = [];
830
+ const elements: HTMLElement[] = [];
831
+ while (queue.length) {
832
+ const child = queue.shift();
833
+ if (child instanceof Layout) {
834
+ if (child.layoutEnabled()) {
835
+ result.push(child);
836
+ elements.push(child.element);
837
+ }
838
+ } else if (child) {
839
+ queue.unshift(...child.children());
840
+ }
841
+ }
842
+ this.element.replaceChildren(...elements);
843
+
844
+ return result;
845
+ }
846
+
847
+ /**
848
+ * Apply any new font changes to this node and all of its ancestors.
849
+ */
850
+ @computed()
851
+ protected requestFontUpdate() {
852
+ this.appendedToView();
853
+ this.parentTransform()?.requestFontUpdate();
854
+ this.applyFont();
855
+ }
856
+
857
+ protected override getCacheBBox(): BBox {
858
+ return BBox.fromSizeCentered(this.computedSize());
859
+ }
860
+
861
+ protected override draw(context: CanvasRenderingContext2D) {
862
+ if (this.clip()) {
863
+ const size = this.computedSize();
864
+ if (size.width === 0 || size.height === 0) {
865
+ return;
866
+ }
867
+
868
+ context.beginPath();
869
+ context.rect(size.width / -2, size.height / -2, size.width, size.height);
870
+ context.closePath();
871
+ context.clip();
872
+ }
873
+
874
+ this.drawChildren(context);
875
+ }
876
+
877
+ public override drawOverlay(
878
+ context: CanvasRenderingContext2D,
879
+ matrix: DOMMatrix,
880
+ ) {
881
+ const size = this.computedSize();
882
+ const offset = size.mul(this.anchor()).scale(0.5).transformAsPoint(matrix);
883
+ const box = BBox.fromSizeCentered(size);
884
+ const layout = box.transformCorners(matrix);
885
+ const padding = box
886
+ .addSpacing(this.padding().scale(-1))
887
+ .transformCorners(matrix);
888
+ const margin = box.addSpacing(this.margin()).transformCorners(matrix);
889
+
890
+ context.beginPath();
891
+ drawLine(context, margin);
892
+ drawLine(context, layout);
893
+ context.closePath();
894
+ context.fillStyle = 'rgba(255,193,125,0.6)';
895
+ context.fill('evenodd');
896
+
897
+ context.beginPath();
898
+ drawLine(context, layout);
899
+ drawLine(context, padding);
900
+ context.closePath();
901
+ context.fillStyle = 'rgba(180,255,147,0.6)';
902
+ context.fill('evenodd');
903
+
904
+ context.beginPath();
905
+ drawLine(context, layout);
906
+ context.closePath();
907
+ context.lineWidth = 1;
908
+ context.strokeStyle = 'white';
909
+ context.stroke();
910
+
911
+ context.beginPath();
912
+ drawPivot(context, offset);
913
+ context.stroke();
914
+ }
915
+
916
+ public getOriginDelta(origin: Origin) {
917
+ const size = this.computedSize().scale(0.5);
918
+ const offset = this.anchor().mul(size);
919
+ if (origin === Origin.Middle) {
920
+ return offset.flipped;
921
+ }
922
+
923
+ const newOffset = originToOffset(origin).mul(size);
924
+ return newOffset.sub(offset);
925
+ }
926
+
927
+ /**
928
+ * Update the offset of this node and adjust the position to keep it in the
929
+ * same place.
930
+ *
931
+ * @param offset - The new offset.
932
+ */
933
+ public moveOffset(offset: Vector2) {
934
+ const size = this.computedSize().scale(0.5);
935
+ const oldOffset = this.anchor().mul(size);
936
+ const newOffset = offset.mul(size);
937
+ this.anchor(offset);
938
+ this.position(this.position().add(newOffset).sub(oldOffset));
939
+ }
940
+
941
+ protected parsePixels(value: number | null): string {
942
+ return value === null ? '' : `${value}px`;
943
+ }
944
+
945
+ protected parseLength(value: number | string | null): string {
946
+ if (value === null) {
947
+ return '';
948
+ }
949
+ if (typeof value === 'string') {
950
+ return value;
951
+ }
952
+ return `${value}px`;
953
+ }
954
+
955
+ @computed()
956
+ protected applyFlex() {
957
+ this.element.style.position = this.isLayoutRoot() ? 'absolute' : 'relative';
958
+
959
+ const size = this.desiredSize();
960
+ this.element.style.width = this.parseLength(size.x);
961
+ this.element.style.height = this.parseLength(size.y);
962
+ this.element.style.maxWidth = this.parseLength(this.maxWidth());
963
+ this.element.style.minWidth = this.parseLength(this.minWidth());
964
+ this.element.style.maxHeight = this.parseLength(this.maxHeight());
965
+ this.element.style.minHeight = this.parseLength(this.minHeight()!);
966
+ this.element.style.aspectRatio =
967
+ this.ratio() === null ? '' : this.ratio()!.toString();
968
+
969
+ this.element.style.marginTop = this.parsePixels(this.margin.top());
970
+ this.element.style.marginBottom = this.parsePixels(this.margin.bottom());
971
+ this.element.style.marginLeft = this.parsePixels(this.margin.left());
972
+ this.element.style.marginRight = this.parsePixels(this.margin.right());
973
+
974
+ this.element.style.paddingTop = this.parsePixels(this.padding.top());
975
+ this.element.style.paddingBottom = this.parsePixels(this.padding.bottom());
976
+ this.element.style.paddingLeft = this.parsePixels(this.padding.left());
977
+ this.element.style.paddingRight = this.parsePixels(this.padding.right());
978
+
979
+ this.element.style.flexDirection = this.direction();
980
+ this.element.style.flexBasis = this.parseLength(this.basis()!);
981
+ this.element.style.flexWrap = this.wrap();
982
+
983
+ this.element.style.justifyContent = this.justifyContent();
984
+ this.element.style.alignContent = this.alignContent();
985
+ this.element.style.alignItems = this.alignItems();
986
+ this.element.style.alignSelf = this.alignSelf();
987
+ this.element.style.columnGap = this.parseLength(this.gap.x());
988
+ this.element.style.rowGap = this.parseLength(this.gap.y());
989
+
990
+ if (this.sizeLockCounter() > 0) {
991
+ this.element.style.flexGrow = '0';
992
+ this.element.style.flexShrink = '0';
993
+ } else {
994
+ this.element.style.flexGrow = this.grow().toString();
995
+ this.element.style.flexShrink = this.shrink().toString();
996
+ }
997
+ }
998
+
999
+ @computed()
1000
+ protected applyFont() {
1001
+ this.element.style.fontFamily = this.fontFamily();
1002
+ this.element.style.fontSize = `${this.fontSize()}px`;
1003
+ this.element.style.fontStyle = this.fontStyle();
1004
+
1005
+ const lineHeight = this.lineHeight();
1006
+ this.element.style.lineHeight =
1007
+ typeof lineHeight === 'number'
1008
+ ? `${lineHeight}px`
1009
+ : (parseFloat(lineHeight as string) / 100).toString();
1010
+
1011
+ this.element.style.fontWeight = this.fontWeight().toString();
1012
+ this.element.style.letterSpacing = `${this.letterSpacing()}px`;
1013
+ this.element.style.textAlign = this.textAlign();
1014
+
1015
+ const wrap = this.textWrap();
1016
+ if (typeof wrap === 'boolean') {
1017
+ this.element.style.whiteSpace = wrap ? 'normal' : 'nowrap';
1018
+ } else {
1019
+ this.element.style.whiteSpace = wrap;
1020
+ }
1021
+ }
1022
+
1023
+ public override dispose() {
1024
+ super.dispose();
1025
+ this.sizeLockCounter?.context.dispose();
1026
+ if (this.element) {
1027
+ this.element.remove();
1028
+ this.element.innerHTML = '';
1029
+ }
1030
+ this.element = null as unknown as HTMLElement;
1031
+ this.styles = null as unknown as CSSStyleDeclaration;
1032
+ }
1033
+
1034
+ public override hit(position: Vector2): Node | null {
1035
+ const local = position.transformAsPoint(this.localToParent().inverse());
1036
+ if (this.cacheBBox().includes(local)) {
1037
+ return super.hit(position) ?? this;
1038
+ }
1039
+
1040
+ return null;
1041
+ }
1042
+ }
1043
+
1044
+ function originSignal(origin: Origin): PropertyDecorator {
1045
+ return (target, key) => {
1046
+ signal<PossibleVector2>()(target, key);
1047
+ cloneable(false)(target, key);
1048
+ wrapper(Vector2)(target, key);
1049
+
1050
+ addInitializer(target, (instance: Layout) => {
1051
+ const parser = (value: PossibleVector2) => new Vector2(value);
1052
+
1053
+ const signalContext = new LayoutPositionSignalContext(
1054
+ undefined,
1055
+ deepLerp,
1056
+ instance,
1057
+ parser,
1058
+ {
1059
+ getter: function (this: Layout) {
1060
+ return this.computedSize()
1061
+ .getOriginOffset(origin)
1062
+ .transformAsPoint(this.localToParent());
1063
+ }.bind(instance),
1064
+ },
1065
+ );
1066
+
1067
+ signalContext.setCustomSetter(
1068
+ function (
1069
+ this: Layout,
1070
+ value: SignalValue<PossibleVector2> | typeof DEFAULT,
1071
+ ) {
1072
+ if (value === DEFAULT) {
1073
+ return this;
1074
+ }
1075
+ this.position(
1076
+ modify(value, unwrapped =>
1077
+ this.getOriginDelta(origin)
1078
+ .transform(this.scalingRotationMatrix())
1079
+ .flipped.add(unwrapped),
1080
+ ),
1081
+ );
1082
+ return this;
1083
+ }.bind(instance),
1084
+ );
1085
+
1086
+ Object.defineProperty(instance, key, {
1087
+ value: signalContext.toSignal(),
1088
+ writable: false,
1089
+ enumerable: true,
1090
+ configurable: false,
1091
+ });
1092
+ });
1093
+ };
1094
+ }
1095
+
1096
+ addInitializer<Layout>(Layout.prototype, instance => {
1097
+ instance.element = document.createElement('div');
1098
+ instance.element.style.display = 'flex';
1099
+ instance.element.style.boxSizing = 'border-box';
1100
+ instance.styles = getComputedStyle(instance.element);
1101
+ });