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