@dxos/react-ui-canvas 0.13.0 → 0.14.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 (341) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/index.mjs +9044 -1135
  3. package/dist/lib/index.mjs.map +1 -1
  4. package/dist/types/src/components/About/About.d.ts +13 -0
  5. package/dist/types/src/components/About/About.d.ts.map +1 -0
  6. package/dist/types/src/components/About/About.stories.d.ts +7 -0
  7. package/dist/types/src/components/About/About.stories.d.ts.map +1 -0
  8. package/dist/types/src/components/About/index.d.ts +2 -0
  9. package/dist/types/src/components/About/index.d.ts.map +1 -0
  10. package/dist/types/src/components/Breadcrumbs/Breadcrumbs.d.ts.map +1 -1
  11. package/dist/types/src/components/ControlFrame/ControlFrame.d.ts +8 -2
  12. package/dist/types/src/components/ControlFrame/ControlFrame.d.ts.map +1 -1
  13. package/dist/types/src/components/Layers/Layers.d.ts +30 -0
  14. package/dist/types/src/components/Layers/Layers.d.ts.map +1 -0
  15. package/dist/types/src/components/Layers/Layers.stories.d.ts +11 -0
  16. package/dist/types/src/components/Layers/Layers.stories.d.ts.map +1 -0
  17. package/dist/types/src/components/Layers/index.d.ts +2 -0
  18. package/dist/types/src/components/Layers/index.d.ts.map +1 -0
  19. package/dist/types/src/components/Palette/Palette.d.ts +20 -4
  20. package/dist/types/src/components/Palette/Palette.d.ts.map +1 -1
  21. package/dist/types/src/components/Palette/Palette.stories.d.ts +22 -0
  22. package/dist/types/src/components/Palette/Palette.stories.d.ts.map +1 -0
  23. package/dist/types/src/components/PartEditor/PartEditor.d.ts.map +1 -1
  24. package/dist/types/src/components/Properties/AlignField.d.ts +23 -0
  25. package/dist/types/src/components/Properties/AlignField.d.ts.map +1 -0
  26. package/dist/types/src/components/Properties/ClassField.d.ts +23 -0
  27. package/dist/types/src/components/Properties/ClassField.d.ts.map +1 -0
  28. package/dist/types/src/components/Properties/FontField.d.ts +7 -0
  29. package/dist/types/src/components/Properties/FontField.d.ts.map +1 -0
  30. package/dist/types/src/components/Properties/LayerField.d.ts +17 -0
  31. package/dist/types/src/components/Properties/LayerField.d.ts.map +1 -0
  32. package/dist/types/src/components/Properties/Properties.d.ts +27 -3
  33. package/dist/types/src/components/Properties/Properties.d.ts.map +1 -1
  34. package/dist/types/src/components/Properties/Properties.stories.d.ts +20 -0
  35. package/dist/types/src/components/Properties/Properties.stories.d.ts.map +1 -0
  36. package/dist/types/src/components/Properties/SceneField.d.ts +8 -0
  37. package/dist/types/src/components/Properties/SceneField.d.ts.map +1 -0
  38. package/dist/types/src/components/Properties/StyleGrid.d.ts +15 -5
  39. package/dist/types/src/components/Properties/StyleGrid.d.ts.map +1 -1
  40. package/dist/types/src/components/Properties/StyleGrid.stories.d.ts +7 -0
  41. package/dist/types/src/components/Properties/StyleGrid.stories.d.ts.map +1 -0
  42. package/dist/types/src/components/SceneLayer/SceneLayer.d.ts +31 -7
  43. package/dist/types/src/components/SceneLayer/SceneLayer.d.ts.map +1 -1
  44. package/dist/types/src/components/SceneView/Dock.d.ts +22 -0
  45. package/dist/types/src/components/SceneView/Dock.d.ts.map +1 -0
  46. package/dist/types/src/components/SceneView/Dock.stories.d.ts +15 -0
  47. package/dist/types/src/components/SceneView/Dock.stories.d.ts.map +1 -0
  48. package/dist/types/src/components/SceneView/SceneView.d.ts +33 -7
  49. package/dist/types/src/components/SceneView/SceneView.d.ts.map +1 -1
  50. package/dist/types/src/components/SceneView/SceneView.stories.d.ts +16 -6
  51. package/dist/types/src/components/SceneView/SceneView.stories.d.ts.map +1 -1
  52. package/dist/types/src/components/SceneView/SceneViewContext.d.ts +36 -4
  53. package/dist/types/src/components/SceneView/SceneViewContext.d.ts.map +1 -1
  54. package/dist/types/src/components/SceneView/Scored.stories.d.ts +4 -4
  55. package/dist/types/src/components/SceneView/Scored.stories.d.ts.map +1 -1
  56. package/dist/types/src/components/SceneView/usePointerMachine.d.ts +3 -1
  57. package/dist/types/src/components/SceneView/usePointerMachine.d.ts.map +1 -1
  58. package/dist/types/src/components/SceneView/useSceneCamera.d.ts +2 -2
  59. package/dist/types/src/components/SceneView/useSceneCamera.d.ts.map +1 -1
  60. package/dist/types/src/components/SceneView/useSceneClipboard.d.ts.map +1 -1
  61. package/dist/types/src/components/SceneView/useSceneKeys.d.ts.map +1 -1
  62. package/dist/types/src/components/SceneView/useSceneNavigation.d.ts +7 -4
  63. package/dist/types/src/components/SceneView/useSceneNavigation.d.ts.map +1 -1
  64. package/dist/types/src/components/Toolbar/Toolbar.d.ts +2 -0
  65. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  66. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  67. package/dist/types/src/components/index.d.ts +2 -0
  68. package/dist/types/src/components/index.d.ts.map +1 -1
  69. package/dist/types/src/hooks/useWheel.d.ts +5 -0
  70. package/dist/types/src/hooks/useWheel.d.ts.map +1 -1
  71. package/dist/types/src/index.d.ts +4 -1
  72. package/dist/types/src/index.d.ts.map +1 -1
  73. package/dist/types/src/model/atoms.d.ts +21 -3
  74. package/dist/types/src/model/atoms.d.ts.map +1 -1
  75. package/dist/types/src/model/projection.d.ts.map +1 -1
  76. package/dist/types/src/model/projections/constrained.d.ts +2 -1
  77. package/dist/types/src/model/projections/constrained.d.ts.map +1 -1
  78. package/dist/types/src/model/projections/dynamic.d.ts.map +1 -1
  79. package/dist/types/src/model/projections/lattice.d.ts.map +1 -1
  80. package/dist/types/src/model/registry.d.ts +21 -3
  81. package/dist/types/src/model/registry.d.ts.map +1 -1
  82. package/dist/types/src/model/store.d.ts +10 -2
  83. package/dist/types/src/model/store.d.ts.map +1 -1
  84. package/dist/types/src/model/types.d.ts +699 -338
  85. package/dist/types/src/model/types.d.ts.map +1 -1
  86. package/dist/types/src/playwright/SceneManager.d.ts +1 -1
  87. package/dist/types/src/playwright/SceneManager.d.ts.map +1 -1
  88. package/dist/types/src/utils/builder.d.ts +22 -41
  89. package/dist/types/src/utils/builder.d.ts.map +1 -1
  90. package/dist/types/src/utils/camera.d.ts +19 -10
  91. package/dist/types/src/utils/camera.d.ts.map +1 -1
  92. package/dist/types/src/utils/clipboard.d.ts +4 -2
  93. package/dist/types/src/utils/clipboard.d.ts.map +1 -1
  94. package/dist/types/src/utils/diagram.d.ts.map +1 -1
  95. package/dist/types/src/utils/group.d.ts +14 -0
  96. package/dist/types/src/utils/group.d.ts.map +1 -0
  97. package/dist/types/src/utils/group.test.d.ts +2 -0
  98. package/dist/types/src/utils/group.test.d.ts.map +1 -0
  99. package/dist/types/src/utils/gutter-route.d.ts +7 -0
  100. package/dist/types/src/utils/gutter-route.d.ts.map +1 -1
  101. package/dist/types/src/utils/hit.d.ts +3 -20
  102. package/dist/types/src/utils/hit.d.ts.map +1 -1
  103. package/dist/types/src/utils/index.d.ts +3 -0
  104. package/dist/types/src/utils/index.d.ts.map +1 -1
  105. package/dist/types/src/utils/lattice.d.ts +5 -0
  106. package/dist/types/src/utils/lattice.d.ts.map +1 -1
  107. package/dist/types/src/utils/layers.d.ts +35 -0
  108. package/dist/types/src/utils/layers.d.ts.map +1 -0
  109. package/dist/types/src/utils/layers.test.d.ts +2 -0
  110. package/dist/types/src/utils/layers.test.d.ts.map +1 -0
  111. package/dist/types/src/utils/parts.d.ts +25 -9
  112. package/dist/types/src/utils/parts.d.ts.map +1 -1
  113. package/dist/types/src/utils/ports.d.ts +2 -0
  114. package/dist/types/src/utils/ports.d.ts.map +1 -1
  115. package/dist/types/src/utils/properties.d.ts +4 -3
  116. package/dist/types/src/utils/properties.d.ts.map +1 -1
  117. package/dist/types/src/utils/route.d.ts +5 -0
  118. package/dist/types/src/utils/route.d.ts.map +1 -1
  119. package/dist/types/src/utils/scenes.d.ts +14 -0
  120. package/dist/types/src/utils/scenes.d.ts.map +1 -0
  121. package/dist/types/src/utils/scenes.test.d.ts +2 -0
  122. package/dist/types/src/utils/scenes.test.d.ts.map +1 -0
  123. package/dist/types/src/utils/shapes.d.ts +23 -9
  124. package/dist/types/src/utils/shapes.d.ts.map +1 -1
  125. package/dist/types/src/utils/style.d.ts +29 -6
  126. package/dist/types/src/utils/style.d.ts.map +1 -1
  127. package/dist/types/src/utils/style.test.d.ts +2 -0
  128. package/dist/types/src/utils/style.test.d.ts.map +1 -0
  129. package/dist/types/src/utils/testing.d.ts +2 -2
  130. package/dist/types/src/utils/testing.d.ts.map +1 -1
  131. package/dist/types/src/utils/undo.d.ts +15 -4
  132. package/dist/types/src/utils/undo.d.ts.map +1 -1
  133. package/dist/types/tsconfig.tsbuildinfo +1 -1
  134. package/package.json +20 -26
  135. package/src/components/About/About.stories.tsx +32 -0
  136. package/src/components/About/About.tsx +38 -0
  137. package/src/components/About/index.ts +5 -0
  138. package/src/components/Breadcrumbs/Breadcrumbs.tsx +17 -3
  139. package/src/components/ControlFrame/ControlFrame.tsx +138 -82
  140. package/src/components/Grid/Grid.stories.tsx +1 -1
  141. package/src/components/Layers/Layers.stories.tsx +131 -0
  142. package/src/components/Layers/Layers.tsx +216 -0
  143. package/src/components/Layers/index.ts +5 -0
  144. package/src/components/Palette/Palette.stories.tsx +135 -0
  145. package/src/components/Palette/Palette.tsx +230 -39
  146. package/src/components/PartEditor/PartEditor.tsx +4 -3
  147. package/src/components/Properties/AlignField.tsx +117 -0
  148. package/src/components/Properties/ClassField.tsx +44 -0
  149. package/src/components/Properties/FontField.tsx +73 -0
  150. package/src/components/Properties/LayerField.tsx +61 -0
  151. package/src/components/Properties/Properties.stories.tsx +113 -0
  152. package/src/components/Properties/Properties.tsx +240 -60
  153. package/src/components/Properties/SceneField.tsx +22 -0
  154. package/src/components/Properties/StyleGrid.stories.tsx +50 -0
  155. package/src/components/Properties/StyleGrid.tsx +54 -26
  156. package/src/components/SceneLayer/SceneLayer.tsx +497 -188
  157. package/src/components/SceneView/Constrained.stories.tsx +1 -1
  158. package/src/components/SceneView/Dock.stories.tsx +95 -0
  159. package/src/components/SceneView/Dock.tsx +146 -0
  160. package/src/components/SceneView/Dynamic.stories.tsx +1 -1
  161. package/src/components/SceneView/SceneView.stories.tsx +170 -18
  162. package/src/components/SceneView/SceneView.tsx +565 -151
  163. package/src/components/SceneView/SceneViewContext.ts +23 -2
  164. package/src/components/SceneView/Scored.stories.tsx +11 -11
  165. package/src/components/SceneView/usePointerMachine.ts +80 -20
  166. package/src/components/SceneView/useSceneCamera.ts +15 -8
  167. package/src/components/SceneView/useSceneClipboard.ts +4 -0
  168. package/src/components/SceneView/useSceneKeys.ts +6 -4
  169. package/src/components/SceneView/useSceneNavigation.ts +44 -33
  170. package/src/components/Toolbar/Toolbar.stories.tsx +14 -15
  171. package/src/components/Toolbar/Toolbar.tsx +15 -4
  172. package/src/components/index.ts +2 -0
  173. package/src/hooks/useWheel.ts +35 -0
  174. package/src/index.ts +4 -3
  175. package/src/model/atoms.ts +27 -3
  176. package/src/model/projection.ts +5 -0
  177. package/src/model/projections/constrained.test.ts +18 -10
  178. package/src/model/projections/constrained.ts +19 -8
  179. package/src/model/projections/dynamic.ts +5 -2
  180. package/src/model/projections/lattice.ts +15 -3
  181. package/src/model/registry.test.ts +14 -9
  182. package/src/model/registry.ts +39 -34
  183. package/src/model/store.ts +12 -2
  184. package/src/model/types.ts +124 -36
  185. package/src/playwright/SceneManager.ts +2 -2
  186. package/src/playwright/create.spec.ts +5 -3
  187. package/src/playwright/demo.spec.ts +2 -2
  188. package/src/playwright/lattice.spec.ts +4 -5
  189. package/src/playwright/scene.spec.ts +27 -25
  190. package/src/utils/builder.test.ts +46 -9
  191. package/src/utils/builder.ts +42 -18
  192. package/src/utils/camera.test.ts +22 -51
  193. package/src/utils/camera.ts +39 -32
  194. package/src/utils/clipboard.test.ts +23 -2
  195. package/src/utils/clipboard.ts +8 -4
  196. package/src/utils/diagram.test.ts +3 -1
  197. package/src/utils/diagram.ts +3 -25
  198. package/src/utils/group.test.ts +69 -0
  199. package/src/utils/group.ts +94 -0
  200. package/src/utils/gutter-route.test.ts +49 -0
  201. package/src/utils/gutter-route.ts +142 -16
  202. package/src/utils/hit.test.ts +4 -38
  203. package/src/utils/hit.ts +4 -26
  204. package/src/utils/index.ts +3 -0
  205. package/src/utils/lattice.ts +7 -1
  206. package/src/utils/layers.test.ts +139 -0
  207. package/src/utils/layers.ts +175 -0
  208. package/src/utils/parts.test.ts +66 -32
  209. package/src/utils/parts.ts +63 -41
  210. package/src/utils/ports.ts +7 -4
  211. package/src/utils/properties.test.ts +23 -6
  212. package/src/utils/properties.ts +66 -16
  213. package/src/utils/route.test.ts +51 -2
  214. package/src/utils/route.ts +133 -23
  215. package/src/utils/scenes.test.ts +38 -0
  216. package/src/utils/scenes.ts +54 -0
  217. package/src/utils/shapes.test.ts +33 -8
  218. package/src/utils/shapes.ts +51 -35
  219. package/src/utils/style.test.ts +54 -0
  220. package/src/utils/style.ts +153 -40
  221. package/src/utils/testing.test.ts +3 -3
  222. package/src/utils/testing.ts +21 -30
  223. package/src/utils/undo.test.ts +25 -2
  224. package/src/utils/undo.ts +50 -13
  225. package/dist/lib/chunk-Grid.mjs +0 -99
  226. package/dist/lib/chunk-Grid.mjs.map +0 -1
  227. package/dist/lib/scene.mjs +0 -6835
  228. package/dist/lib/scene.mjs.map +0 -1
  229. package/dist/lib/types.mjs +0 -16
  230. package/dist/lib/types.mjs.map +0 -1
  231. package/dist/types/src/archive/components/Canvas/Canvas.d.ts +0 -15
  232. package/dist/types/src/archive/components/Canvas/Canvas.d.ts.map +0 -1
  233. package/dist/types/src/archive/components/Canvas/Canvas.stories.d.ts +0 -18
  234. package/dist/types/src/archive/components/Canvas/Canvas.stories.d.ts.map +0 -1
  235. package/dist/types/src/archive/components/Canvas/index.d.ts +0 -2
  236. package/dist/types/src/archive/components/Canvas/index.d.ts.map +0 -1
  237. package/dist/types/src/archive/components/CellGrid/CellGrid.d.ts +0 -21
  238. package/dist/types/src/archive/components/CellGrid/CellGrid.d.ts.map +0 -1
  239. package/dist/types/src/archive/components/CellGrid/CellGrid.stories.d.ts +0 -21
  240. package/dist/types/src/archive/components/CellGrid/CellGrid.stories.d.ts.map +0 -1
  241. package/dist/types/src/archive/components/CellGrid/headers/Ruler.d.ts +0 -15
  242. package/dist/types/src/archive/components/CellGrid/headers/Ruler.d.ts.map +0 -1
  243. package/dist/types/src/archive/components/CellGrid/headers/TrackHeader.d.ts +0 -19
  244. package/dist/types/src/archive/components/CellGrid/headers/TrackHeader.d.ts.map +0 -1
  245. package/dist/types/src/archive/components/CellGrid/headers/index.d.ts +0 -3
  246. package/dist/types/src/archive/components/CellGrid/headers/index.d.ts.map +0 -1
  247. package/dist/types/src/archive/components/CellGrid/index.d.ts +0 -6
  248. package/dist/types/src/archive/components/CellGrid/index.d.ts.map +0 -1
  249. package/dist/types/src/archive/components/CellGrid/input/index.d.ts +0 -3
  250. package/dist/types/src/archive/components/CellGrid/input/index.d.ts.map +0 -1
  251. package/dist/types/src/archive/components/CellGrid/input/pointer.d.ts +0 -33
  252. package/dist/types/src/archive/components/CellGrid/input/pointer.d.ts.map +0 -1
  253. package/dist/types/src/archive/components/CellGrid/input/wheel.d.ts +0 -14
  254. package/dist/types/src/archive/components/CellGrid/input/wheel.d.ts.map +0 -1
  255. package/dist/types/src/archive/components/CellGrid/render/index.d.ts +0 -3
  256. package/dist/types/src/archive/components/CellGrid/render/index.d.ts.map +0 -1
  257. package/dist/types/src/archive/components/CellGrid/render/overlay-layer.d.ts +0 -21
  258. package/dist/types/src/archive/components/CellGrid/render/overlay-layer.d.ts.map +0 -1
  259. package/dist/types/src/archive/components/CellGrid/render/static-layer.d.ts +0 -36
  260. package/dist/types/src/archive/components/CellGrid/render/static-layer.d.ts.map +0 -1
  261. package/dist/types/src/archive/components/CellGrid/state/atoms.d.ts +0 -23
  262. package/dist/types/src/archive/components/CellGrid/state/atoms.d.ts.map +0 -1
  263. package/dist/types/src/archive/components/CellGrid/state/index.d.ts +0 -4
  264. package/dist/types/src/archive/components/CellGrid/state/index.d.ts.map +0 -1
  265. package/dist/types/src/archive/components/CellGrid/state/types.d.ts +0 -39
  266. package/dist/types/src/archive/components/CellGrid/state/types.d.ts.map +0 -1
  267. package/dist/types/src/archive/components/CellGrid/state/viewport.d.ts +0 -52
  268. package/dist/types/src/archive/components/CellGrid/state/viewport.d.ts.map +0 -1
  269. package/dist/types/src/archive/components/CellGrid/state/viewport.test.d.ts +0 -2
  270. package/dist/types/src/archive/components/CellGrid/state/viewport.test.d.ts.map +0 -1
  271. package/dist/types/src/archive/components/FPS.d.ts +0 -9
  272. package/dist/types/src/archive/components/FPS.d.ts.map +0 -1
  273. package/dist/types/src/archive/components/Grid/Grid.d.ts +0 -6
  274. package/dist/types/src/archive/components/Grid/Grid.d.ts.map +0 -1
  275. package/dist/types/src/archive/components/Grid/index.d.ts +0 -2
  276. package/dist/types/src/archive/components/Grid/index.d.ts.map +0 -1
  277. package/dist/types/src/archive/components/index.d.ts +0 -5
  278. package/dist/types/src/archive/components/index.d.ts.map +0 -1
  279. package/dist/types/src/archive/hooks/index.d.ts +0 -5
  280. package/dist/types/src/archive/hooks/index.d.ts.map +0 -1
  281. package/dist/types/src/archive/hooks/projection.d.ts +0 -60
  282. package/dist/types/src/archive/hooks/projection.d.ts.map +0 -1
  283. package/dist/types/src/archive/hooks/useCanvasContext.d.ts +0 -13
  284. package/dist/types/src/archive/hooks/useCanvasContext.d.ts.map +0 -1
  285. package/dist/types/src/archive/hooks/useDrag.d.ts +0 -6
  286. package/dist/types/src/archive/hooks/useDrag.d.ts.map +0 -1
  287. package/dist/types/src/archive/hooks/useWheel.d.ts +0 -8
  288. package/dist/types/src/archive/hooks/useWheel.d.ts.map +0 -1
  289. package/dist/types/src/archive/index.d.ts +0 -5
  290. package/dist/types/src/archive/index.d.ts.map +0 -1
  291. package/dist/types/src/archive/types.d.ts +0 -19
  292. package/dist/types/src/archive/types.d.ts.map +0 -1
  293. package/dist/types/src/archive/util/index.d.ts +0 -4
  294. package/dist/types/src/archive/util/index.d.ts.map +0 -1
  295. package/dist/types/src/archive/util/svg-path.d.ts +0 -4
  296. package/dist/types/src/archive/util/svg-path.d.ts.map +0 -1
  297. package/dist/types/src/archive/util/svg.d.ts +0 -32
  298. package/dist/types/src/archive/util/svg.d.ts.map +0 -1
  299. package/dist/types/src/archive/util/svg.stories.d.ts +0 -15
  300. package/dist/types/src/archive/util/svg.stories.d.ts.map +0 -1
  301. package/dist/types/src/archive/util/util.d.ts +0 -17
  302. package/dist/types/src/archive/util/util.d.ts.map +0 -1
  303. package/dist/types/src/scene.d.ts +0 -5
  304. package/dist/types/src/scene.d.ts.map +0 -1
  305. package/src/archive/components/Canvas/Canvas.stories.tsx +0 -111
  306. package/src/archive/components/Canvas/Canvas.tsx +0 -87
  307. package/src/archive/components/Canvas/index.ts +0 -5
  308. package/src/archive/components/CellGrid/CellGrid.stories.tsx +0 -239
  309. package/src/archive/components/CellGrid/CellGrid.tsx +0 -270
  310. package/src/archive/components/CellGrid/headers/Ruler.tsx +0 -71
  311. package/src/archive/components/CellGrid/headers/TrackHeader.tsx +0 -58
  312. package/src/archive/components/CellGrid/headers/index.ts +0 -6
  313. package/src/archive/components/CellGrid/index.ts +0 -9
  314. package/src/archive/components/CellGrid/input/index.ts +0 -6
  315. package/src/archive/components/CellGrid/input/pointer.ts +0 -236
  316. package/src/archive/components/CellGrid/input/wheel.ts +0 -68
  317. package/src/archive/components/CellGrid/render/index.ts +0 -6
  318. package/src/archive/components/CellGrid/render/overlay-layer.ts +0 -66
  319. package/src/archive/components/CellGrid/render/static-layer.ts +0 -112
  320. package/src/archive/components/CellGrid/state/atoms.ts +0 -43
  321. package/src/archive/components/CellGrid/state/index.ts +0 -7
  322. package/src/archive/components/CellGrid/state/types.ts +0 -40
  323. package/src/archive/components/CellGrid/state/viewport.test.ts +0 -50
  324. package/src/archive/components/CellGrid/state/viewport.ts +0 -94
  325. package/src/archive/components/FPS.tsx +0 -98
  326. package/src/archive/components/Grid/Grid.tsx +0 -17
  327. package/src/archive/components/Grid/index.ts +0 -5
  328. package/src/archive/components/index.ts +0 -8
  329. package/src/archive/hooks/index.ts +0 -8
  330. package/src/archive/hooks/projection.tsx +0 -156
  331. package/src/archive/hooks/useCanvasContext.ts +0 -32
  332. package/src/archive/hooks/useDrag.tsx +0 -96
  333. package/src/archive/hooks/useWheel.tsx +0 -80
  334. package/src/archive/index.ts +0 -8
  335. package/src/archive/types.ts +0 -14
  336. package/src/archive/util/index.ts +0 -7
  337. package/src/archive/util/svg-path.ts +0 -13
  338. package/src/archive/util/svg.stories.tsx +0 -46
  339. package/src/archive/util/svg.tsx +0 -128
  340. package/src/archive/util/util.ts +0 -50
  341. package/src/scene.ts +0 -9
@@ -1,156 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { easeSinOut, interpolate, interpolateObject, transition } from 'd3';
6
- import {
7
- type Matrix,
8
- applyToPoints,
9
- compose,
10
- identity,
11
- inverse,
12
- scale as scaleMatrix,
13
- translate as translateMatrix,
14
- } from 'transformation-matrix';
15
-
16
- import { type Dimension, type Point } from '../types.ts';
17
-
18
- export const defaultOrigin: Point = { x: 0, y: 0 };
19
-
20
- // TODO(burdon): Rotation also?
21
- export type ProjectionState = {
22
- scale: number;
23
- offset: Point;
24
- };
25
-
26
- /**
27
- * Maps between screen and model coordinates.
28
- */
29
- export interface Projection {
30
- get bounds(): Dimension;
31
- get scale(): number;
32
- get offset(): Point;
33
-
34
- /**
35
- * Maps the model space to the screen offset (from the top-left of the element).
36
- */
37
- toScreen(points: Point[]): Point[];
38
-
39
- /**
40
- * Maps the pointer coordinate (from the top-left of the element) to the model space.
41
- */
42
- toModel(points: Point[]): Point[];
43
- }
44
-
45
- export class ProjectionMapper implements Projection {
46
- private _bounds: Dimension = { width: 0, height: 0 };
47
- private _scale: number = 1;
48
- private _offset: Point = defaultOrigin;
49
- private _toScreen: Matrix = identity();
50
- private _toModel: Matrix = identity();
51
-
52
- constructor(bounds?: Dimension, scale?: number, offset?: Point) {
53
- if (bounds && scale && offset) {
54
- this.update(bounds, scale, offset);
55
- }
56
- }
57
-
58
- update(bounds: Dimension, scale: number, offset: Point): this {
59
- this._bounds = bounds;
60
- this._scale = scale;
61
- this._offset = offset;
62
- this._toScreen = compose(
63
- // NOTE: Order is important.
64
- translateMatrix(this._offset.x, this._offset.y),
65
- scaleMatrix(this._scale),
66
- // TODO(burdon): Flip.
67
- // flipX(),
68
- );
69
- this._toModel = inverse(this._toScreen);
70
- return this;
71
- }
72
-
73
- get bounds() {
74
- return this._bounds;
75
- }
76
-
77
- get scale() {
78
- return this._scale;
79
- }
80
-
81
- get offset() {
82
- return this._offset;
83
- }
84
-
85
- toScreen(points: Point[]): Point[] {
86
- return applyToPoints(this._toScreen, points);
87
- }
88
-
89
- toModel(points: Point[]): Point[] {
90
- return applyToPoints(this._toModel, points);
91
- }
92
- }
93
-
94
- /**
95
- * Maintain position while zooming.
96
- */
97
- export const getZoomTransform = ({
98
- scale,
99
- offset,
100
- pos,
101
- newScale,
102
- }: ProjectionState & { pos: Point; newScale: number }): ProjectionState => {
103
- return {
104
- scale: newScale,
105
- offset: {
106
- x: pos.x - (pos.x - offset.x) * (newScale / scale),
107
- y: pos.y - (pos.y - offset.y) * (newScale / scale),
108
- },
109
- };
110
- };
111
-
112
- /**
113
- * Zoom while keeping the specified position in place.
114
- */
115
- // TODO(burdon): Convert to object.
116
- export const zoomInPlace = (
117
- setTransform: (state: ProjectionState) => void,
118
- pos: Point,
119
- offset: Point,
120
- current: number,
121
- next: number,
122
- delay = 200,
123
- ) => {
124
- const is = interpolate(current, next);
125
- transition()
126
- .ease(easeSinOut)
127
- .duration(delay)
128
- .tween('zoom', () => (t) => {
129
- const newScale = is(t);
130
- setTransform(getZoomTransform({ scale: current, newScale, offset, pos }));
131
- });
132
- };
133
-
134
- const noop = () => {};
135
-
136
- /**
137
- * Zoom to new scale and position.
138
- */
139
- // TODO(burdon): Convert to object.
140
- export const zoomTo = (
141
- setTransform: (state: ProjectionState) => void,
142
- current: ProjectionState,
143
- next: ProjectionState,
144
- delay = 200,
145
- cb = noop,
146
- ) => {
147
- const is = interpolateObject({ scale: current.scale, ...current.offset }, { scale: next.scale, ...next.offset });
148
- transition()
149
- .ease(easeSinOut)
150
- .duration(delay)
151
- .tween('zoom', () => (t) => {
152
- const { scale, x, y } = is(t);
153
- setTransform({ scale, offset: { x, y } });
154
- })
155
- .on('end', cb);
156
- };
@@ -1,32 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type CSSProperties, type Dispatch, type SetStateAction, createContext, useContext } from 'react';
6
-
7
- import { raise } from '@dxos/debug';
8
-
9
- import { type Projection, type ProjectionState } from './projection.tsx';
10
-
11
- // Kept out of the canvas components: react-refresh only fast-refreshes a module whose exports are all
12
- // components, so a context and hook exported beside one force a full page reload on every edit.
13
-
14
- export type CanvasContext = ProjectionState & {
15
- root: HTMLDivElement;
16
- ready: boolean;
17
- width: number;
18
- height: number;
19
- styles: CSSProperties;
20
- projection: Projection;
21
- setProjection: Dispatch<SetStateAction<ProjectionState>>;
22
- };
23
-
24
- /**
25
- * @internal
26
- */
27
- // TODO(burdon): Use `createContext` from `@dxos/react-hooks`?
28
- export const CanvasContext = createContext<CanvasContext | null>(null);
29
-
30
- export const useCanvasContext = (): CanvasContext => {
31
- return useContext(CanvasContext) ?? raise(new Error('Missing CanvasContext'));
32
- };
@@ -1,96 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { bind } from 'bind-event-listener';
6
- import { useEffect, useRef } from 'react';
7
-
8
- import { useCanvasContext } from './useCanvasContext.ts';
9
-
10
- export type DragOptions = {
11
- // TODO(burdon): Add constraints?
12
- };
13
-
14
- /**
15
- * Handle drag events to update the transform state (offset).
16
- */
17
- export const useDrag = (_options: DragOptions = {}) => {
18
- const { root, setProjection } = useCanvasContext();
19
-
20
- // Track drag state.
21
- const state = useRef<{
22
- panning: boolean;
23
- x: number;
24
- y: number;
25
- }>({ panning: false, x: 0, y: 0 });
26
-
27
- useEffect(() => {
28
- if (!root) {
29
- return;
30
- }
31
-
32
- // TODO(burdon): Use d3-drag?
33
- return bind(root, {
34
- type: 'pointerdown',
35
- listener: (ev: PointerEvent) => {
36
- // Only left click.
37
- if (ev.button !== 0) {
38
- return;
39
- }
40
-
41
- if (ev.defaultPrevented) {
42
- return;
43
- }
44
-
45
- if (ev.target !== root || ev.shiftKey) {
46
- return;
47
- }
48
-
49
- // Check if clicking on an interactive element?
50
- // For now, assume if it bubbled to root, it's fair game unless prevented.
51
-
52
- ev.preventDefault(); // Prevent text selection.
53
- root.setPointerCapture(ev.pointerId);
54
- state.current = { panning: true, x: ev.clientX, y: ev.clientY };
55
-
56
- const moveUnbind = bind(root, {
57
- type: 'pointermove',
58
- listener: (ev: PointerEvent) => {
59
- if (!state.current.panning) {
60
- return;
61
- }
62
-
63
- // Calculate delta.
64
- const dx = ev.clientX - state.current.x;
65
- const dy = ev.clientY - state.current.y;
66
-
67
- state.current.x = ev.clientX;
68
- state.current.y = ev.clientY;
69
-
70
- setProjection((prev) => ({
71
- ...prev,
72
- offset: {
73
- x: prev.offset.x + dx,
74
- y: prev.offset.y + dy,
75
- },
76
- }));
77
- },
78
- });
79
-
80
- const upUnbind = bind(root, {
81
- type: 'pointerup',
82
- listener: (ev: PointerEvent) => {
83
- state.current.panning = false;
84
- root.releasePointerCapture(ev.pointerId);
85
- moveUnbind();
86
- upUnbind();
87
- // Clean up lostpointercapture as well?
88
- },
89
- });
90
-
91
- // Handle cancellation/lost capture just in case?
92
- // Using setPointerCapture usually handles this well on the element.
93
- },
94
- });
95
- }, [root]);
96
- };
@@ -1,80 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { bindAll } from 'bind-event-listener';
6
- import { useEffect } from 'react';
7
-
8
- import { getRelativePoint } from '../util/index.ts';
9
- import { getZoomTransform } from './projection.tsx';
10
- import { useCanvasContext } from './useCanvasContext.ts';
11
-
12
- export type WheelOptions = {
13
- zoom?: boolean;
14
- };
15
-
16
- const defaultOptions: WheelOptions = {
17
- zoom: true,
18
- };
19
-
20
- /**
21
- * Handle wheel events to update the transform state (zoom and offset).
22
- */
23
- export const useWheel = (options: WheelOptions = defaultOptions) => {
24
- const { root, setProjection } = useCanvasContext();
25
- useEffect(() => {
26
- if (!root) {
27
- return;
28
- }
29
-
30
- return bindAll(root, [
31
- {
32
- type: 'wheel',
33
- options: { capture: true, passive: false },
34
- listener: (ev: WheelEvent) => {
35
- const zooming = isWheelZooming(ev);
36
-
37
- ev.preventDefault();
38
- if (zooming && !options.zoom) {
39
- return;
40
- }
41
-
42
- // Zoom or pan.
43
- if (ev.ctrlKey) {
44
- if (!root) {
45
- return;
46
- }
47
-
48
- // Keep centered while zooming.
49
- setProjection(({ scale, offset }) => {
50
- const pos = getRelativePoint(root, ev);
51
- const scaleSensitivity = 0.01;
52
- const newScale = scale * Math.exp(-ev.deltaY * scaleSensitivity);
53
- return getZoomTransform({ scale, offset, newScale, pos });
54
- });
55
- } else {
56
- setProjection(({ scale, offset: { x, y } }) => {
57
- return {
58
- scale,
59
- offset: {
60
- x: x - ev.deltaX,
61
- y: y - ev.deltaY,
62
- },
63
- };
64
- });
65
- }
66
- },
67
- },
68
- ]);
69
- }, [root]);
70
- };
71
-
72
- const isWheelZooming = (ev: WheelEvent): boolean => {
73
- // Check for ctrl/cmd key + wheel action.
74
- if (ev.ctrlKey || ev.metaKey) {
75
- // Some browsers use deltaY, others deltaZ for zoom.
76
- return Math.abs(ev.deltaY) > 0 || Math.abs(ev.deltaZ) > 0;
77
- }
78
-
79
- return false;
80
- };
@@ -1,8 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export * from './components/index.ts';
6
- export * from './hooks/index.ts';
7
- export * from './types.ts';
8
- export * from './util/index.ts';
@@ -1,14 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
- import * as Struct from 'effect/Struct';
7
-
8
- export const Point = Schema.Struct({ x: Schema.Number, y: Schema.Number });
9
- export const Dimension = Schema.Struct({ width: Schema.Number, height: Schema.Number });
10
- export const Rect = Point.mapFields(Struct.assign(Dimension.fields));
11
-
12
- export type Point = Schema.Schema.Type<typeof Point>;
13
- export type Dimension = Schema.Schema.Type<typeof Dimension>;
14
- export type Rect = Schema.Schema.Type<typeof Rect>;
@@ -1,7 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export * from './svg.tsx';
6
- export * from './svg-path.ts';
7
- export * from './util.ts';
@@ -1,13 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type Point } from '../types.ts';
6
-
7
- // Kept out of `svg.tsx`: react-refresh only fast-refreshes a module whose exports are all components,
8
- // so a helper exported beside them forces a full page reload on every edit.
9
-
10
- /** https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths */
11
- export const createPath = (points: Point[], join = false) => {
12
- return ['M', points.map(({ x, y }) => `${x},${y}`).join(' L '), join ? 'Z' : ''].join(' ');
13
- };
@@ -1,46 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type Meta, type StoryObj } from '@storybook/react-vite';
6
- import React from 'react';
7
-
8
- import { withTheme } from '@dxos/react-ui/testing';
9
-
10
- import { createPath } from './svg-path.ts';
11
- import { Arrow } from './svg.tsx';
12
- import { testId } from './util.ts';
13
-
14
- const DefaultStory = () => (
15
- <svg className='border border-separator w-[30rem] h-[400px]'>
16
- <defs>
17
- <Arrow id='arrow-start' classNames='fill-none stroke-red-500' dir='start' />
18
- <Arrow id='arrow-end' classNames='fill-none stroke-red-500' dir='end' />
19
- </defs>
20
- <path
21
- {...testId('dx-storybook', true)}
22
- className={'stroke-red-500'}
23
- d={createPath([
24
- { x: 100, y: 300 },
25
- { x: 300, y: 100 },
26
- ])}
27
- markerStart={'url(#arrow-start)'}
28
- markerEnd={'url(#arrow-end)'}
29
- />
30
- </svg>
31
- );
32
-
33
- const meta = {
34
- title: 'ui/react-ui-canvas/svg',
35
- render: DefaultStory,
36
- decorators: [withTheme()],
37
- parameters: {
38
- layout: 'centered',
39
- },
40
- } satisfies Meta;
41
-
42
- export default meta;
43
-
44
- type Story = StoryObj<typeof meta>;
45
-
46
- export const Default: Story = {};
@@ -1,128 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import React, { type PropsWithChildren, type SVGProps } from 'react';
6
-
7
- import type * as Util from '@dxos/react-ui/Util';
8
- import { mx } from '@dxos/ui-theme';
9
-
10
- import { type Dimension, type Point } from '../types.ts';
11
- import { createPath } from './svg-path.ts';
12
-
13
- // Refs
14
- // - https://airbnb.io/visx/gallery
15
- // - https://github.com/tldraw/tldraw/blob/main/packages/editor/src/lib/primitives/Vec.ts
16
-
17
- /**
18
- * https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths
19
- * NOTE: Leave space around shape for line width.
20
- */
21
- export const Markers = ({ id = 'dx-marker', classNames }: Util.ThemedClassName<{ id?: string }>) => {
22
- return (
23
- <>
24
- <Arrow id={`${id}-arrow-start`} dir='start' classNames={classNames} />
25
- <Arrow id={`${id}-arrow-end`} dir='end' classNames={classNames} />
26
- <Arrow id={`${id}-triangle-start`} dir='start' closed classNames={classNames} />
27
- <Arrow id={`${id}-triangle-end`} dir='end' closed classNames={classNames} />
28
- <Marker id={`${id}-circle`} pos={{ x: 8, y: 8 }} size={{ width: 16, height: 16 }}>
29
- <circle cx={8} cy={8} r={5} stroke={'context-stroke'} className={mx(classNames)} />
30
- </Marker>
31
- </>
32
- );
33
- };
34
-
35
- export type MarkerProps = SVGProps<SVGMarkerElement> &
36
- PropsWithChildren<
37
- Util.ThemedClassName<{
38
- id: string;
39
- pos: Point;
40
- size: Dimension;
41
- fill?: boolean;
42
- }>
43
- >;
44
-
45
- /**
46
- * https://www.w3.org/TR/SVG2/painting.html#Markers
47
- */
48
- export const Marker = ({
49
- id,
50
- className,
51
- children,
52
- pos: { x: refX, y: refY },
53
- size: { width: markerWidth, height: markerHeight },
54
- fill,
55
- ...rest
56
- }: MarkerProps) => (
57
- <marker
58
- id={id}
59
- className={className}
60
- {...{
61
- refX,
62
- refY,
63
- markerWidth,
64
- markerHeight,
65
- markerUnits: 'strokeWidth',
66
- orient: 'auto',
67
- ...rest,
68
- }}
69
- >
70
- {children}
71
- </marker>
72
- );
73
-
74
- export const Arrow = ({
75
- classNames,
76
- id,
77
- size = 16,
78
- dir = 'end',
79
- closed = false,
80
- }: Util.ThemedClassName<{ id: string; size?: number; dir?: 'start' | 'end'; closed?: boolean }>) => (
81
- <Marker
82
- id={id}
83
- size={{ width: size, height: size }}
84
- pos={dir === 'end' ? { x: size, y: size / 2 } : { x: 0, y: size / 2 }}
85
- >
86
- <path
87
- fill={closed ? undefined : 'none'}
88
- stroke={'context-stroke'}
89
- className={mx(classNames)}
90
- d={createPath(
91
- dir === 'end'
92
- ? [
93
- { x: 1, y: 1 },
94
- { x: size, y: size / 2 },
95
- { x: 1, y: size - 1 },
96
- ]
97
- : [
98
- { x: size - 1, y: 1 },
99
- { x: 0, y: size / 2 },
100
- { x: size - 1, y: size - 1 },
101
- ],
102
- closed,
103
- )}
104
- />
105
- </Marker>
106
- );
107
-
108
- export const GridPattern = ({
109
- classNames,
110
- id,
111
- size,
112
- offset,
113
- }: Util.ThemedClassName<{ id: string; size: number; offset: Point }>) => (
114
- <pattern
115
- id={id}
116
- x={(size / 2 + offset.x) % size}
117
- y={(size / 2 + offset.y) % size}
118
- width={size}
119
- height={size}
120
- patternUnits='userSpaceOnUse'
121
- >
122
- {/* TODO(burdon): vars. */}
123
- <g className={mx(classNames)}>
124
- <line x1={0} y1={size / 2} x2={size} y2={size / 2} />
125
- <line x1={size / 2} y1={0} x2={size / 2} y2={size} />
126
- </g>
127
- </pattern>
128
- );
@@ -1,50 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- let logged = false;
6
-
7
- /**
8
- * Get the relative point of the cursor.
9
- * NOTE: ev.offset returns the position relative to the target.
10
- */
11
- export const getRelativePoint = (el: HTMLElement, ev: MouseEvent) => {
12
- const rect = el.getBoundingClientRect();
13
- return { x: ev.clientX - rect.x, y: ev.clientY - rect.top };
14
- };
15
-
16
- /**
17
- *
18
- */
19
- // TODO(burdon): Factor out.
20
- export const testId = <ID = string>(id: ID, inspect = false) => {
21
- if (inspect) {
22
- if (!logged) {
23
- // eslint-disable-next-line no-console
24
- console.log('Open storybook in expanded window;\nthen run INSPECT()');
25
- logged = true;
26
- }
27
-
28
- (window as any).INSPECT = () => {
29
- const el = document.querySelector(`[data-test-id="${id}"]`);
30
- (window as any).inspect(el);
31
- // eslint-disable-next-line no-console
32
- console.log(el);
33
- };
34
- }
35
-
36
- return { [DATA_TEST_ID]: id };
37
- };
38
-
39
- export const inspectElement = (el: Element) => {
40
- (window as any).INSPECT = () => {
41
- (window as any).inspect(el);
42
- (window as any).element = el;
43
- // eslint-disable-next-line no-console
44
- console.log('Open storybook in expanded window;\nthen run INSPECT()');
45
- // eslint-disable-next-line no-console
46
- console.log(el);
47
- };
48
- };
49
-
50
- export const DATA_TEST_ID = 'data-test-id';
package/src/scene.ts DELETED
@@ -1,9 +0,0 @@
1
- //
2
- // Copyright 2026 DXOS.org
3
- //
4
-
5
- // The scene engine, exported as `@dxos/react-ui-canvas/scene` until it replaces the archived canvas.
6
- export * from './components/index.ts';
7
- export * from './hooks/index.ts';
8
- export * from './model/index.ts';
9
- export * from './utils/index.ts';