@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.
- package/README.md +1 -1
- package/dist/lib/index.mjs +9044 -1135
- package/dist/lib/index.mjs.map +1 -1
- package/dist/types/src/components/About/About.d.ts +13 -0
- package/dist/types/src/components/About/About.d.ts.map +1 -0
- package/dist/types/src/components/About/About.stories.d.ts +7 -0
- package/dist/types/src/components/About/About.stories.d.ts.map +1 -0
- package/dist/types/src/components/About/index.d.ts +2 -0
- package/dist/types/src/components/About/index.d.ts.map +1 -0
- package/dist/types/src/components/Breadcrumbs/Breadcrumbs.d.ts.map +1 -1
- package/dist/types/src/components/ControlFrame/ControlFrame.d.ts +8 -2
- package/dist/types/src/components/ControlFrame/ControlFrame.d.ts.map +1 -1
- package/dist/types/src/components/Layers/Layers.d.ts +30 -0
- package/dist/types/src/components/Layers/Layers.d.ts.map +1 -0
- package/dist/types/src/components/Layers/Layers.stories.d.ts +11 -0
- package/dist/types/src/components/Layers/Layers.stories.d.ts.map +1 -0
- package/dist/types/src/components/Layers/index.d.ts +2 -0
- package/dist/types/src/components/Layers/index.d.ts.map +1 -0
- package/dist/types/src/components/Palette/Palette.d.ts +20 -4
- package/dist/types/src/components/Palette/Palette.d.ts.map +1 -1
- package/dist/types/src/components/Palette/Palette.stories.d.ts +22 -0
- package/dist/types/src/components/Palette/Palette.stories.d.ts.map +1 -0
- package/dist/types/src/components/PartEditor/PartEditor.d.ts.map +1 -1
- package/dist/types/src/components/Properties/AlignField.d.ts +23 -0
- package/dist/types/src/components/Properties/AlignField.d.ts.map +1 -0
- package/dist/types/src/components/Properties/ClassField.d.ts +23 -0
- package/dist/types/src/components/Properties/ClassField.d.ts.map +1 -0
- package/dist/types/src/components/Properties/FontField.d.ts +7 -0
- package/dist/types/src/components/Properties/FontField.d.ts.map +1 -0
- package/dist/types/src/components/Properties/LayerField.d.ts +17 -0
- package/dist/types/src/components/Properties/LayerField.d.ts.map +1 -0
- package/dist/types/src/components/Properties/Properties.d.ts +27 -3
- package/dist/types/src/components/Properties/Properties.d.ts.map +1 -1
- package/dist/types/src/components/Properties/Properties.stories.d.ts +20 -0
- package/dist/types/src/components/Properties/Properties.stories.d.ts.map +1 -0
- package/dist/types/src/components/Properties/SceneField.d.ts +8 -0
- package/dist/types/src/components/Properties/SceneField.d.ts.map +1 -0
- package/dist/types/src/components/Properties/StyleGrid.d.ts +15 -5
- package/dist/types/src/components/Properties/StyleGrid.d.ts.map +1 -1
- package/dist/types/src/components/Properties/StyleGrid.stories.d.ts +7 -0
- package/dist/types/src/components/Properties/StyleGrid.stories.d.ts.map +1 -0
- package/dist/types/src/components/SceneLayer/SceneLayer.d.ts +31 -7
- package/dist/types/src/components/SceneLayer/SceneLayer.d.ts.map +1 -1
- package/dist/types/src/components/SceneView/Dock.d.ts +22 -0
- package/dist/types/src/components/SceneView/Dock.d.ts.map +1 -0
- package/dist/types/src/components/SceneView/Dock.stories.d.ts +15 -0
- package/dist/types/src/components/SceneView/Dock.stories.d.ts.map +1 -0
- package/dist/types/src/components/SceneView/SceneView.d.ts +33 -7
- package/dist/types/src/components/SceneView/SceneView.d.ts.map +1 -1
- package/dist/types/src/components/SceneView/SceneView.stories.d.ts +16 -6
- package/dist/types/src/components/SceneView/SceneView.stories.d.ts.map +1 -1
- package/dist/types/src/components/SceneView/SceneViewContext.d.ts +36 -4
- package/dist/types/src/components/SceneView/SceneViewContext.d.ts.map +1 -1
- package/dist/types/src/components/SceneView/Scored.stories.d.ts +4 -4
- package/dist/types/src/components/SceneView/Scored.stories.d.ts.map +1 -1
- package/dist/types/src/components/SceneView/usePointerMachine.d.ts +3 -1
- package/dist/types/src/components/SceneView/usePointerMachine.d.ts.map +1 -1
- package/dist/types/src/components/SceneView/useSceneCamera.d.ts +2 -2
- package/dist/types/src/components/SceneView/useSceneCamera.d.ts.map +1 -1
- package/dist/types/src/components/SceneView/useSceneClipboard.d.ts.map +1 -1
- package/dist/types/src/components/SceneView/useSceneKeys.d.ts.map +1 -1
- package/dist/types/src/components/SceneView/useSceneNavigation.d.ts +7 -4
- package/dist/types/src/components/SceneView/useSceneNavigation.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +2 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useWheel.d.ts +5 -0
- package/dist/types/src/hooks/useWheel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +4 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/model/atoms.d.ts +21 -3
- package/dist/types/src/model/atoms.d.ts.map +1 -1
- package/dist/types/src/model/projection.d.ts.map +1 -1
- package/dist/types/src/model/projections/constrained.d.ts +2 -1
- package/dist/types/src/model/projections/constrained.d.ts.map +1 -1
- package/dist/types/src/model/projections/dynamic.d.ts.map +1 -1
- package/dist/types/src/model/projections/lattice.d.ts.map +1 -1
- package/dist/types/src/model/registry.d.ts +21 -3
- package/dist/types/src/model/registry.d.ts.map +1 -1
- package/dist/types/src/model/store.d.ts +10 -2
- package/dist/types/src/model/store.d.ts.map +1 -1
- package/dist/types/src/model/types.d.ts +699 -338
- package/dist/types/src/model/types.d.ts.map +1 -1
- package/dist/types/src/playwright/SceneManager.d.ts +1 -1
- package/dist/types/src/playwright/SceneManager.d.ts.map +1 -1
- package/dist/types/src/utils/builder.d.ts +22 -41
- package/dist/types/src/utils/builder.d.ts.map +1 -1
- package/dist/types/src/utils/camera.d.ts +19 -10
- package/dist/types/src/utils/camera.d.ts.map +1 -1
- package/dist/types/src/utils/clipboard.d.ts +4 -2
- package/dist/types/src/utils/clipboard.d.ts.map +1 -1
- package/dist/types/src/utils/diagram.d.ts.map +1 -1
- package/dist/types/src/utils/group.d.ts +14 -0
- package/dist/types/src/utils/group.d.ts.map +1 -0
- package/dist/types/src/utils/group.test.d.ts +2 -0
- package/dist/types/src/utils/group.test.d.ts.map +1 -0
- package/dist/types/src/utils/gutter-route.d.ts +7 -0
- package/dist/types/src/utils/gutter-route.d.ts.map +1 -1
- package/dist/types/src/utils/hit.d.ts +3 -20
- package/dist/types/src/utils/hit.d.ts.map +1 -1
- package/dist/types/src/utils/index.d.ts +3 -0
- package/dist/types/src/utils/index.d.ts.map +1 -1
- package/dist/types/src/utils/lattice.d.ts +5 -0
- package/dist/types/src/utils/lattice.d.ts.map +1 -1
- package/dist/types/src/utils/layers.d.ts +35 -0
- package/dist/types/src/utils/layers.d.ts.map +1 -0
- package/dist/types/src/utils/layers.test.d.ts +2 -0
- package/dist/types/src/utils/layers.test.d.ts.map +1 -0
- package/dist/types/src/utils/parts.d.ts +25 -9
- package/dist/types/src/utils/parts.d.ts.map +1 -1
- package/dist/types/src/utils/ports.d.ts +2 -0
- package/dist/types/src/utils/ports.d.ts.map +1 -1
- package/dist/types/src/utils/properties.d.ts +4 -3
- package/dist/types/src/utils/properties.d.ts.map +1 -1
- package/dist/types/src/utils/route.d.ts +5 -0
- package/dist/types/src/utils/route.d.ts.map +1 -1
- package/dist/types/src/utils/scenes.d.ts +14 -0
- package/dist/types/src/utils/scenes.d.ts.map +1 -0
- package/dist/types/src/utils/scenes.test.d.ts +2 -0
- package/dist/types/src/utils/scenes.test.d.ts.map +1 -0
- package/dist/types/src/utils/shapes.d.ts +23 -9
- package/dist/types/src/utils/shapes.d.ts.map +1 -1
- package/dist/types/src/utils/style.d.ts +29 -6
- package/dist/types/src/utils/style.d.ts.map +1 -1
- package/dist/types/src/utils/style.test.d.ts +2 -0
- package/dist/types/src/utils/style.test.d.ts.map +1 -0
- package/dist/types/src/utils/testing.d.ts +2 -2
- package/dist/types/src/utils/testing.d.ts.map +1 -1
- package/dist/types/src/utils/undo.d.ts +15 -4
- package/dist/types/src/utils/undo.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -26
- package/src/components/About/About.stories.tsx +32 -0
- package/src/components/About/About.tsx +38 -0
- package/src/components/About/index.ts +5 -0
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +17 -3
- package/src/components/ControlFrame/ControlFrame.tsx +138 -82
- package/src/components/Grid/Grid.stories.tsx +1 -1
- package/src/components/Layers/Layers.stories.tsx +131 -0
- package/src/components/Layers/Layers.tsx +216 -0
- package/src/components/Layers/index.ts +5 -0
- package/src/components/Palette/Palette.stories.tsx +135 -0
- package/src/components/Palette/Palette.tsx +230 -39
- package/src/components/PartEditor/PartEditor.tsx +4 -3
- package/src/components/Properties/AlignField.tsx +117 -0
- package/src/components/Properties/ClassField.tsx +44 -0
- package/src/components/Properties/FontField.tsx +73 -0
- package/src/components/Properties/LayerField.tsx +61 -0
- package/src/components/Properties/Properties.stories.tsx +113 -0
- package/src/components/Properties/Properties.tsx +240 -60
- package/src/components/Properties/SceneField.tsx +22 -0
- package/src/components/Properties/StyleGrid.stories.tsx +50 -0
- package/src/components/Properties/StyleGrid.tsx +54 -26
- package/src/components/SceneLayer/SceneLayer.tsx +497 -188
- package/src/components/SceneView/Constrained.stories.tsx +1 -1
- package/src/components/SceneView/Dock.stories.tsx +95 -0
- package/src/components/SceneView/Dock.tsx +146 -0
- package/src/components/SceneView/Dynamic.stories.tsx +1 -1
- package/src/components/SceneView/SceneView.stories.tsx +170 -18
- package/src/components/SceneView/SceneView.tsx +565 -151
- package/src/components/SceneView/SceneViewContext.ts +23 -2
- package/src/components/SceneView/Scored.stories.tsx +11 -11
- package/src/components/SceneView/usePointerMachine.ts +80 -20
- package/src/components/SceneView/useSceneCamera.ts +15 -8
- package/src/components/SceneView/useSceneClipboard.ts +4 -0
- package/src/components/SceneView/useSceneKeys.ts +6 -4
- package/src/components/SceneView/useSceneNavigation.ts +44 -33
- package/src/components/Toolbar/Toolbar.stories.tsx +14 -15
- package/src/components/Toolbar/Toolbar.tsx +15 -4
- package/src/components/index.ts +2 -0
- package/src/hooks/useWheel.ts +35 -0
- package/src/index.ts +4 -3
- package/src/model/atoms.ts +27 -3
- package/src/model/projection.ts +5 -0
- package/src/model/projections/constrained.test.ts +18 -10
- package/src/model/projections/constrained.ts +19 -8
- package/src/model/projections/dynamic.ts +5 -2
- package/src/model/projections/lattice.ts +15 -3
- package/src/model/registry.test.ts +14 -9
- package/src/model/registry.ts +39 -34
- package/src/model/store.ts +12 -2
- package/src/model/types.ts +124 -36
- package/src/playwright/SceneManager.ts +2 -2
- package/src/playwright/create.spec.ts +5 -3
- package/src/playwright/demo.spec.ts +2 -2
- package/src/playwright/lattice.spec.ts +4 -5
- package/src/playwright/scene.spec.ts +27 -25
- package/src/utils/builder.test.ts +46 -9
- package/src/utils/builder.ts +42 -18
- package/src/utils/camera.test.ts +22 -51
- package/src/utils/camera.ts +39 -32
- package/src/utils/clipboard.test.ts +23 -2
- package/src/utils/clipboard.ts +8 -4
- package/src/utils/diagram.test.ts +3 -1
- package/src/utils/diagram.ts +3 -25
- package/src/utils/group.test.ts +69 -0
- package/src/utils/group.ts +94 -0
- package/src/utils/gutter-route.test.ts +49 -0
- package/src/utils/gutter-route.ts +142 -16
- package/src/utils/hit.test.ts +4 -38
- package/src/utils/hit.ts +4 -26
- package/src/utils/index.ts +3 -0
- package/src/utils/lattice.ts +7 -1
- package/src/utils/layers.test.ts +139 -0
- package/src/utils/layers.ts +175 -0
- package/src/utils/parts.test.ts +66 -32
- package/src/utils/parts.ts +63 -41
- package/src/utils/ports.ts +7 -4
- package/src/utils/properties.test.ts +23 -6
- package/src/utils/properties.ts +66 -16
- package/src/utils/route.test.ts +51 -2
- package/src/utils/route.ts +133 -23
- package/src/utils/scenes.test.ts +38 -0
- package/src/utils/scenes.ts +54 -0
- package/src/utils/shapes.test.ts +33 -8
- package/src/utils/shapes.ts +51 -35
- package/src/utils/style.test.ts +54 -0
- package/src/utils/style.ts +153 -40
- package/src/utils/testing.test.ts +3 -3
- package/src/utils/testing.ts +21 -30
- package/src/utils/undo.test.ts +25 -2
- package/src/utils/undo.ts +50 -13
- package/dist/lib/chunk-Grid.mjs +0 -99
- package/dist/lib/chunk-Grid.mjs.map +0 -1
- package/dist/lib/scene.mjs +0 -6835
- package/dist/lib/scene.mjs.map +0 -1
- package/dist/lib/types.mjs +0 -16
- package/dist/lib/types.mjs.map +0 -1
- package/dist/types/src/archive/components/Canvas/Canvas.d.ts +0 -15
- package/dist/types/src/archive/components/Canvas/Canvas.d.ts.map +0 -1
- package/dist/types/src/archive/components/Canvas/Canvas.stories.d.ts +0 -18
- package/dist/types/src/archive/components/Canvas/Canvas.stories.d.ts.map +0 -1
- package/dist/types/src/archive/components/Canvas/index.d.ts +0 -2
- package/dist/types/src/archive/components/Canvas/index.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/CellGrid.d.ts +0 -21
- package/dist/types/src/archive/components/CellGrid/CellGrid.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/CellGrid.stories.d.ts +0 -21
- package/dist/types/src/archive/components/CellGrid/CellGrid.stories.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/headers/Ruler.d.ts +0 -15
- package/dist/types/src/archive/components/CellGrid/headers/Ruler.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/headers/TrackHeader.d.ts +0 -19
- package/dist/types/src/archive/components/CellGrid/headers/TrackHeader.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/headers/index.d.ts +0 -3
- package/dist/types/src/archive/components/CellGrid/headers/index.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/index.d.ts +0 -6
- package/dist/types/src/archive/components/CellGrid/index.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/input/index.d.ts +0 -3
- package/dist/types/src/archive/components/CellGrid/input/index.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/input/pointer.d.ts +0 -33
- package/dist/types/src/archive/components/CellGrid/input/pointer.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/input/wheel.d.ts +0 -14
- package/dist/types/src/archive/components/CellGrid/input/wheel.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/render/index.d.ts +0 -3
- package/dist/types/src/archive/components/CellGrid/render/index.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/render/overlay-layer.d.ts +0 -21
- package/dist/types/src/archive/components/CellGrid/render/overlay-layer.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/render/static-layer.d.ts +0 -36
- package/dist/types/src/archive/components/CellGrid/render/static-layer.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/state/atoms.d.ts +0 -23
- package/dist/types/src/archive/components/CellGrid/state/atoms.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/state/index.d.ts +0 -4
- package/dist/types/src/archive/components/CellGrid/state/index.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/state/types.d.ts +0 -39
- package/dist/types/src/archive/components/CellGrid/state/types.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/state/viewport.d.ts +0 -52
- package/dist/types/src/archive/components/CellGrid/state/viewport.d.ts.map +0 -1
- package/dist/types/src/archive/components/CellGrid/state/viewport.test.d.ts +0 -2
- package/dist/types/src/archive/components/CellGrid/state/viewport.test.d.ts.map +0 -1
- package/dist/types/src/archive/components/FPS.d.ts +0 -9
- package/dist/types/src/archive/components/FPS.d.ts.map +0 -1
- package/dist/types/src/archive/components/Grid/Grid.d.ts +0 -6
- package/dist/types/src/archive/components/Grid/Grid.d.ts.map +0 -1
- package/dist/types/src/archive/components/Grid/index.d.ts +0 -2
- package/dist/types/src/archive/components/Grid/index.d.ts.map +0 -1
- package/dist/types/src/archive/components/index.d.ts +0 -5
- package/dist/types/src/archive/components/index.d.ts.map +0 -1
- package/dist/types/src/archive/hooks/index.d.ts +0 -5
- package/dist/types/src/archive/hooks/index.d.ts.map +0 -1
- package/dist/types/src/archive/hooks/projection.d.ts +0 -60
- package/dist/types/src/archive/hooks/projection.d.ts.map +0 -1
- package/dist/types/src/archive/hooks/useCanvasContext.d.ts +0 -13
- package/dist/types/src/archive/hooks/useCanvasContext.d.ts.map +0 -1
- package/dist/types/src/archive/hooks/useDrag.d.ts +0 -6
- package/dist/types/src/archive/hooks/useDrag.d.ts.map +0 -1
- package/dist/types/src/archive/hooks/useWheel.d.ts +0 -8
- package/dist/types/src/archive/hooks/useWheel.d.ts.map +0 -1
- package/dist/types/src/archive/index.d.ts +0 -5
- package/dist/types/src/archive/index.d.ts.map +0 -1
- package/dist/types/src/archive/types.d.ts +0 -19
- package/dist/types/src/archive/types.d.ts.map +0 -1
- package/dist/types/src/archive/util/index.d.ts +0 -4
- package/dist/types/src/archive/util/index.d.ts.map +0 -1
- package/dist/types/src/archive/util/svg-path.d.ts +0 -4
- package/dist/types/src/archive/util/svg-path.d.ts.map +0 -1
- package/dist/types/src/archive/util/svg.d.ts +0 -32
- package/dist/types/src/archive/util/svg.d.ts.map +0 -1
- package/dist/types/src/archive/util/svg.stories.d.ts +0 -15
- package/dist/types/src/archive/util/svg.stories.d.ts.map +0 -1
- package/dist/types/src/archive/util/util.d.ts +0 -17
- package/dist/types/src/archive/util/util.d.ts.map +0 -1
- package/dist/types/src/scene.d.ts +0 -5
- package/dist/types/src/scene.d.ts.map +0 -1
- package/src/archive/components/Canvas/Canvas.stories.tsx +0 -111
- package/src/archive/components/Canvas/Canvas.tsx +0 -87
- package/src/archive/components/Canvas/index.ts +0 -5
- package/src/archive/components/CellGrid/CellGrid.stories.tsx +0 -239
- package/src/archive/components/CellGrid/CellGrid.tsx +0 -270
- package/src/archive/components/CellGrid/headers/Ruler.tsx +0 -71
- package/src/archive/components/CellGrid/headers/TrackHeader.tsx +0 -58
- package/src/archive/components/CellGrid/headers/index.ts +0 -6
- package/src/archive/components/CellGrid/index.ts +0 -9
- package/src/archive/components/CellGrid/input/index.ts +0 -6
- package/src/archive/components/CellGrid/input/pointer.ts +0 -236
- package/src/archive/components/CellGrid/input/wheel.ts +0 -68
- package/src/archive/components/CellGrid/render/index.ts +0 -6
- package/src/archive/components/CellGrid/render/overlay-layer.ts +0 -66
- package/src/archive/components/CellGrid/render/static-layer.ts +0 -112
- package/src/archive/components/CellGrid/state/atoms.ts +0 -43
- package/src/archive/components/CellGrid/state/index.ts +0 -7
- package/src/archive/components/CellGrid/state/types.ts +0 -40
- package/src/archive/components/CellGrid/state/viewport.test.ts +0 -50
- package/src/archive/components/CellGrid/state/viewport.ts +0 -94
- package/src/archive/components/FPS.tsx +0 -98
- package/src/archive/components/Grid/Grid.tsx +0 -17
- package/src/archive/components/Grid/index.ts +0 -5
- package/src/archive/components/index.ts +0 -8
- package/src/archive/hooks/index.ts +0 -8
- package/src/archive/hooks/projection.tsx +0 -156
- package/src/archive/hooks/useCanvasContext.ts +0 -32
- package/src/archive/hooks/useDrag.tsx +0 -96
- package/src/archive/hooks/useWheel.tsx +0 -80
- package/src/archive/index.ts +0 -8
- package/src/archive/types.ts +0 -14
- package/src/archive/util/index.ts +0 -7
- package/src/archive/util/svg-path.ts +0 -13
- package/src/archive/util/svg.stories.tsx +0 -46
- package/src/archive/util/svg.tsx +0 -128
- package/src/archive/util/util.ts +0 -50
- package/src/scene.ts +0 -9
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type CSSProperties, type Dispatch, type SetStateAction } from 'react';
|
|
2
|
-
import { type Projection, type ProjectionState } from './projection.tsx';
|
|
3
|
-
export type CanvasContext = ProjectionState & {
|
|
4
|
-
root: HTMLDivElement;
|
|
5
|
-
ready: boolean;
|
|
6
|
-
width: number;
|
|
7
|
-
height: number;
|
|
8
|
-
styles: CSSProperties;
|
|
9
|
-
projection: Projection;
|
|
10
|
-
setProjection: Dispatch<SetStateAction<ProjectionState>>;
|
|
11
|
-
};
|
|
12
|
-
export declare const useCanvasContext: () => CanvasContext;
|
|
13
|
-
//# sourceMappingURL=useCanvasContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCanvasContext.d.ts","sourceRoot":"","sources":["../../../../../src/archive/hooks/useCanvasContext.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAA6B,MAAM,OAAO,CAAC;AAI1G,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKzE,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG;IAC5C,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;IACvB,aAAa,EAAE,QAAQ,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC;CAC1D,CAAC;AAQF,eAAO,MAAM,gBAAgB,QAAO,aAEnC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDrag.d.ts","sourceRoot":"","sources":["../../../../../src/archive/hooks/useDrag.tsx"],"names":[],"mappings":"AASA,MAAM,MAAM,WAAW,GAAG,EAEzB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,cAAc,WAAW,SA+E5C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useWheel.d.ts","sourceRoot":"","sources":["../../../../../src/archive/hooks/useWheel.tsx"],"names":[],"mappings":"AAWA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,QAAQ,aAAa,YAAY,SA+C7C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/archive/index.ts"],"names":[],"mappings":"AAIA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as Schema from 'effect/Schema';
|
|
2
|
-
export declare const Point: Schema.Struct<{
|
|
3
|
-
readonly x: Schema.Number;
|
|
4
|
-
readonly y: Schema.Number;
|
|
5
|
-
}>;
|
|
6
|
-
export declare const Dimension: Schema.Struct<{
|
|
7
|
-
readonly width: Schema.Number;
|
|
8
|
-
readonly height: Schema.Number;
|
|
9
|
-
}>;
|
|
10
|
-
export declare const Rect: Schema.Struct<{
|
|
11
|
-
readonly x: Schema.Number;
|
|
12
|
-
readonly y: Schema.Number;
|
|
13
|
-
readonly width: Schema.Number;
|
|
14
|
-
readonly height: Schema.Number;
|
|
15
|
-
}>;
|
|
16
|
-
export type Point = Schema.Schema.Type<typeof Point>;
|
|
17
|
-
export type Dimension = Schema.Schema.Type<typeof Dimension>;
|
|
18
|
-
export type Rect = Schema.Schema.Type<typeof Rect>;
|
|
19
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/archive/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,eAAO,MAAM,KAAK;;;EAAwD,CAAC;AAC3E,eAAO,MAAM,SAAS;;;EAAiE,CAAC;AACxF,eAAO,MAAM,IAAI;;;;;EAAmD,CAAC;AAErE,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,CAAC,CAAC;AACrD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC,CAAC;AAC7D,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/archive/util/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svg-path.d.ts","sourceRoot":"","sources":["../../../../../src/archive/util/svg-path.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAKzC,sEAAsE;AACtE,eAAO,MAAM,UAAU,WAAY,KAAK,EAAE,2BAEzC,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React, { type PropsWithChildren, type SVGProps } from 'react';
|
|
2
|
-
import type * as Util from '@dxos/react-ui/Util';
|
|
3
|
-
import { type Dimension, type Point } from '../types.ts';
|
|
4
|
-
/**
|
|
5
|
-
* https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths
|
|
6
|
-
* NOTE: Leave space around shape for line width.
|
|
7
|
-
*/
|
|
8
|
-
export declare const Markers: ({ id, classNames }: Util.ThemedClassName<{
|
|
9
|
-
id?: string;
|
|
10
|
-
}>) => React.JSX.Element;
|
|
11
|
-
export type MarkerProps = SVGProps<SVGMarkerElement> & PropsWithChildren<Util.ThemedClassName<{
|
|
12
|
-
id: string;
|
|
13
|
-
pos: Point;
|
|
14
|
-
size: Dimension;
|
|
15
|
-
fill?: boolean;
|
|
16
|
-
}>>;
|
|
17
|
-
/**
|
|
18
|
-
* https://www.w3.org/TR/SVG2/painting.html#Markers
|
|
19
|
-
*/
|
|
20
|
-
export declare const Marker: ({ id, className, children, pos: { x: refX, y: refY }, size: { width: markerWidth, height: markerHeight }, fill, ...rest }: MarkerProps) => React.JSX.Element;
|
|
21
|
-
export declare const Arrow: ({ classNames, id, size, dir, closed, }: Util.ThemedClassName<{
|
|
22
|
-
id: string;
|
|
23
|
-
size?: number;
|
|
24
|
-
dir?: 'start' | 'end';
|
|
25
|
-
closed?: boolean;
|
|
26
|
-
}>) => React.JSX.Element;
|
|
27
|
-
export declare const GridPattern: ({ classNames, id, size, offset, }: Util.ThemedClassName<{
|
|
28
|
-
id: string;
|
|
29
|
-
size: number;
|
|
30
|
-
offset: Point;
|
|
31
|
-
}>) => React.JSX.Element;
|
|
32
|
-
//# sourceMappingURL=svg.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../../../../../src/archive/util/svg.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAE,KAAK,QAAQ,EAAE,MAAM,OAAO,CAAC;AAErE,OAAO,KAAK,KAAK,IAAI,MAAM,qBAAqB,CAAC;AAGjD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAOzD;;;GAGG;AACH,eAAO,MAAM,OAAO,uBAAsC,IAAI,CAAC,eAAe,CAAC;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,sBAY9F,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,gBAAgB,CAAC,GAClD,iBAAiB,CACf,IAAI,CAAC,eAAe,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,KAAK,CAAC;IACX,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC,CACH,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,MAAM,8HAQhB,WAAW,sBAgBb,CAAC;AAEF,eAAO,MAAM,KAAK,2CAMf,IAAI,CAAC,eAAe,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,sBA0B9F,CAAC;AAEF,eAAO,MAAM,WAAW,sCAKrB,IAAI,CAAC,eAAe,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,CAAA;CAAE,CAAC,sBAenE,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type StoryObj } from '@storybook/react-vite';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
declare const DefaultStory: () => React.JSX.Element;
|
|
4
|
-
declare const meta: {
|
|
5
|
-
title: string;
|
|
6
|
-
render: typeof DefaultStory;
|
|
7
|
-
decorators: import("@storybook/react").Decorator[];
|
|
8
|
-
parameters: {
|
|
9
|
-
layout: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export default meta;
|
|
13
|
-
type Story = StoryObj<typeof meta>;
|
|
14
|
-
export declare const Default: Story;
|
|
15
|
-
//# sourceMappingURL=svg.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svg.stories.d.ts","sourceRoot":"","sources":["../../../../../src/archive/util/svg.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,QAAA,MAAM,YAAY,yBAiBjB,CAAC;AAEF,QAAA,MAAM,IAAI;;;;;QAKN,MAAM;;CAEM,CAAC;eAEF,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the relative point of the cursor.
|
|
3
|
-
* NOTE: ev.offset returns the position relative to the target.
|
|
4
|
-
*/
|
|
5
|
-
export declare const getRelativePoint: (el: HTMLElement, ev: MouseEvent) => {
|
|
6
|
-
x: number;
|
|
7
|
-
y: number;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
export declare const testId: <ID = string>(id: ID, inspect?: boolean) => {
|
|
13
|
-
"data-test-id": ID;
|
|
14
|
-
};
|
|
15
|
-
export declare const inspectElement: (el: Element) => void;
|
|
16
|
-
export declare const DATA_TEST_ID = "data-test-id";
|
|
17
|
-
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../../src/archive/util/util.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,eAAO,MAAM,gBAAgB,OAAQ,WAAW,MAAM,UAAU;IAErD,CAAC;IAAuB,CAAC;CACnC,CAAC;AAEF;;GAEG;AAEH,eAAO,MAAM,MAAM,GAAI,EAAE,eAAe,EAAE;;CAiBzC,CAAC;AAEF,eAAO,MAAM,cAAc,OAAQ,OAAO,SASzC,CAAC;AAEF,eAAO,MAAM,YAAY,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../../src/scene.ts"],"names":[],"mappings":"AAKA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
|
-
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
9
|
-
|
|
10
|
-
import { useCanvasContext, useDrag, useWheel } from '../../hooks/index.ts';
|
|
11
|
-
import { type Point } from '../../types.ts';
|
|
12
|
-
import { testId } from '../../util/index.ts';
|
|
13
|
-
import { Grid, type GridProps } from '../Grid/index.ts';
|
|
14
|
-
import { Canvas } from './Canvas.tsx';
|
|
15
|
-
|
|
16
|
-
const size = 128;
|
|
17
|
-
|
|
18
|
-
const points: Point[] = [0, (2 * Math.PI) / 3, (2 * Math.PI * 2) / 3].map((a, i) => ({
|
|
19
|
-
x: Math.round(Math.cos(a - Math.PI / 2) * size * 1.5),
|
|
20
|
-
y: Math.round(Math.sin(a - Math.PI / 2) * size * 1.5),
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
const DefaultStory = (props: GridProps) => {
|
|
24
|
-
return (
|
|
25
|
-
<Canvas>
|
|
26
|
-
<Grid {...props} />
|
|
27
|
-
<Content />
|
|
28
|
-
</Canvas>
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const TwoCanvases = (props: GridProps) => {
|
|
33
|
-
return (
|
|
34
|
-
<div className='grid grid-cols-2 gap-2 dx-fill'>
|
|
35
|
-
<div className='h-full relative'>
|
|
36
|
-
<Canvas>
|
|
37
|
-
<Grid {...props} />
|
|
38
|
-
<Content />
|
|
39
|
-
</Canvas>
|
|
40
|
-
</div>
|
|
41
|
-
<div className='h-full relative'>
|
|
42
|
-
<Canvas>
|
|
43
|
-
<Grid {...props} />
|
|
44
|
-
<Content />
|
|
45
|
-
</Canvas>
|
|
46
|
-
</div>
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const Content = () => {
|
|
52
|
-
useWheel();
|
|
53
|
-
useDrag();
|
|
54
|
-
return (
|
|
55
|
-
<div>
|
|
56
|
-
{points.map(({ x, y }, i) => (
|
|
57
|
-
<Item key={i} x={x} y={y} />
|
|
58
|
-
))}
|
|
59
|
-
</div>
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const Item = (p: Point) => {
|
|
64
|
-
const { projection } = useCanvasContext();
|
|
65
|
-
const r = (projection.scale * size) / 2;
|
|
66
|
-
const [{ x, y }] = projection.toScreen([p]);
|
|
67
|
-
const rect = {
|
|
68
|
-
left: x - size / 2,
|
|
69
|
-
top: y - size / 2,
|
|
70
|
-
width: size,
|
|
71
|
-
height: size,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<div {...testId('dx-test', true)}>
|
|
76
|
-
<div className='absolute flex justify-center items-center' style={rect}>
|
|
77
|
-
<div className='font-mono'>
|
|
78
|
-
({p.x},{p.y})
|
|
79
|
-
</div>
|
|
80
|
-
</div>
|
|
81
|
-
|
|
82
|
-
{/* NOTE: Width and height are not important since overflow-visible. */}
|
|
83
|
-
<svg className='absolute overflow-visible'>
|
|
84
|
-
<circle cx={x} cy={y} r={r} className='stroke-red-500 storke-width-2 fill-none' />
|
|
85
|
-
</svg>
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const meta = {
|
|
91
|
-
title: 'ui/react-ui-canvas/Canvas',
|
|
92
|
-
component: Grid,
|
|
93
|
-
render: DefaultStory,
|
|
94
|
-
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
95
|
-
parameters: {
|
|
96
|
-
layout: 'fullscreen',
|
|
97
|
-
},
|
|
98
|
-
} satisfies Meta<typeof Grid>;
|
|
99
|
-
|
|
100
|
-
export default meta;
|
|
101
|
-
|
|
102
|
-
type Story = StoryObj<typeof meta>;
|
|
103
|
-
|
|
104
|
-
export const Default: Story = {
|
|
105
|
-
args: { size: 16 },
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export const SideBySide: Story = {
|
|
109
|
-
render: TwoCanvases,
|
|
110
|
-
args: { size: 16 },
|
|
111
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, {
|
|
6
|
-
type CSSProperties,
|
|
7
|
-
type HTMLAttributes,
|
|
8
|
-
type PropsWithChildren,
|
|
9
|
-
forwardRef,
|
|
10
|
-
useEffect,
|
|
11
|
-
useImperativeHandle,
|
|
12
|
-
useMemo,
|
|
13
|
-
useState,
|
|
14
|
-
} from 'react';
|
|
15
|
-
import { useResizeDetector } from 'react-resize-detector';
|
|
16
|
-
|
|
17
|
-
import type * as Util from '@dxos/react-ui/Util';
|
|
18
|
-
import { mx } from '@dxos/ui-theme';
|
|
19
|
-
|
|
20
|
-
import { CanvasContext, ProjectionMapper, type ProjectionState, defaultOrigin } from '../../hooks/index.ts';
|
|
21
|
-
|
|
22
|
-
export interface CanvasController {
|
|
23
|
-
setProjection(projection: ProjectionState): Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type CanvasProps = Util.ThemedClassName<
|
|
27
|
-
PropsWithChildren<Partial<ProjectionState> & HTMLAttributes<HTMLDivElement>>
|
|
28
|
-
>;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Root canvas component.
|
|
32
|
-
* Manages CSS projection.
|
|
33
|
-
*/
|
|
34
|
-
export const Canvas = forwardRef<CanvasController, CanvasProps>(
|
|
35
|
-
({ children, classNames, scale: scaleProp = 1, offset: offsetProp = defaultOrigin, ...props }, forwardedRef) => {
|
|
36
|
-
// Size.
|
|
37
|
-
const { ref, width = 0, height = 0 } = useResizeDetector();
|
|
38
|
-
|
|
39
|
-
// Ready when initially resized.
|
|
40
|
-
const [ready, setReady] = useState(false);
|
|
41
|
-
|
|
42
|
-
// Projection.
|
|
43
|
-
const [{ scale, offset }, setProjection] = useState<ProjectionState>({ scale: scaleProp, offset: offsetProp });
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
if (width && height && offset === defaultOrigin) {
|
|
46
|
-
setProjection({ scale, offset: { x: width / 2, y: height / 2 } });
|
|
47
|
-
}
|
|
48
|
-
}, [width, height, scale, offset]);
|
|
49
|
-
|
|
50
|
-
// Projection mapper.
|
|
51
|
-
const projection = useMemo(() => new ProjectionMapper(), []);
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
projection.update({ width, height }, scale, offset);
|
|
54
|
-
if (offset !== defaultOrigin) {
|
|
55
|
-
setReady(true);
|
|
56
|
-
}
|
|
57
|
-
}, [projection, scale, offset, width, height]);
|
|
58
|
-
|
|
59
|
-
// CSS transforms.
|
|
60
|
-
const styles = useMemo<CSSProperties>(() => {
|
|
61
|
-
return {
|
|
62
|
-
// NOTE: Order is important.
|
|
63
|
-
transform: `translate(${offset.x}px, ${offset.y}px) scale(${scale})`,
|
|
64
|
-
visibility: width && height ? 'visible' : 'hidden',
|
|
65
|
-
};
|
|
66
|
-
}, [scale, offset]);
|
|
67
|
-
|
|
68
|
-
// Controller.
|
|
69
|
-
useImperativeHandle(forwardedRef, () => {
|
|
70
|
-
return {
|
|
71
|
-
setProjection: async (projection: ProjectionState) => {
|
|
72
|
-
setProjection(projection);
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}, [ref]);
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<CanvasContext.Provider
|
|
79
|
-
value={{ root: ref.current, ready, width, height, scale, offset, styles, projection, setProjection }}
|
|
80
|
-
>
|
|
81
|
-
<div {...props} className={mx('dx-cover overflow-hidden', classNames)} ref={ref}>
|
|
82
|
-
{ready ? children : null}
|
|
83
|
-
</div>
|
|
84
|
-
</CanvasContext.Provider>
|
|
85
|
-
);
|
|
86
|
-
},
|
|
87
|
-
);
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2026 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { RegistryContext } from '@effect/atom-react/RegistryContext';
|
|
6
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
|
-
import * as Registry from 'effect/reactivity/AtomRegistry';
|
|
8
|
-
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
9
|
-
|
|
10
|
-
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
|
-
|
|
12
|
-
import { CellGrid, type CellGridProps } from './CellGrid.tsx';
|
|
13
|
-
import { toggleCell } from './input/index.ts';
|
|
14
|
-
import { type RenderCell } from './render/index.ts';
|
|
15
|
-
import { createCellGridAtoms } from './state/atoms.ts';
|
|
16
|
-
import type { Cell, CellCoord, Row, Tool } from './state/types.ts';
|
|
17
|
-
|
|
18
|
-
type SequencerData = { velocity: number };
|
|
19
|
-
|
|
20
|
-
const trackColors = [
|
|
21
|
-
'#ef4444', // red
|
|
22
|
-
'#f97316', // orange
|
|
23
|
-
'#eab308', // yellow
|
|
24
|
-
'#22c55e', // green
|
|
25
|
-
'#06b6d4', // cyan
|
|
26
|
-
'#3b82f6', // blue
|
|
27
|
-
'#a855f7', // purple
|
|
28
|
-
'#ec4899', // pink
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
const renderSequencerCell: RenderCell<SequencerData> = ({ ctx, x, y, w, h, cell }) => {
|
|
32
|
-
const inset = 1;
|
|
33
|
-
const radius = 4;
|
|
34
|
-
const color = trackColors[cell.row % trackColors.length];
|
|
35
|
-
const velocity = cell.data?.velocity ?? 0.8;
|
|
36
|
-
ctx.fillStyle = color;
|
|
37
|
-
ctx.globalAlpha = 0.3 + velocity * 0.7;
|
|
38
|
-
roundedRect(ctx, x + inset, y + inset, w - inset * 2, h - inset * 2, radius);
|
|
39
|
-
ctx.fill();
|
|
40
|
-
ctx.globalAlpha = 1;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const renderDataVizCell: RenderCell<{ magnitude: number }> = ({ ctx, x, y, w, h, cell }) => {
|
|
44
|
-
const magnitude = cell.data?.magnitude ?? 0.5;
|
|
45
|
-
const cx = x + w / 2;
|
|
46
|
-
const cy = y + h / 2;
|
|
47
|
-
const r = Math.max(2, (Math.min(w, h) / 2 - 2) * magnitude);
|
|
48
|
-
ctx.fillStyle = `hsl(${(cell.row * 30) % 360}, 70%, 55%)`;
|
|
49
|
-
ctx.globalAlpha = 0.85;
|
|
50
|
-
ctx.beginPath();
|
|
51
|
-
ctx.arc(cx, cy, r, 0, Math.PI * 2);
|
|
52
|
-
ctx.fill();
|
|
53
|
-
ctx.globalAlpha = 1;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const roundedRect = (ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number): void => {
|
|
57
|
-
const radius = Math.min(r, w / 2, h / 2);
|
|
58
|
-
ctx.beginPath();
|
|
59
|
-
ctx.moveTo(x + radius, y);
|
|
60
|
-
ctx.lineTo(x + w - radius, y);
|
|
61
|
-
ctx.quadraticCurveTo(x + w, y, x + w, y + radius);
|
|
62
|
-
ctx.lineTo(x + w, y + h - radius);
|
|
63
|
-
ctx.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
|
|
64
|
-
ctx.lineTo(x + radius, y + h);
|
|
65
|
-
ctx.quadraticCurveTo(x, y + h, x, y + h - radius);
|
|
66
|
-
ctx.lineTo(x, y + radius);
|
|
67
|
-
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
68
|
-
ctx.closePath();
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
// Deterministic 0..1 random — Linear Congruential Generator. Used in story
|
|
72
|
-
// seeding so the same args produce the same grid every render.
|
|
73
|
-
const makeLcg = (seed: number) => {
|
|
74
|
-
let state = seed >>> 0;
|
|
75
|
-
return () => {
|
|
76
|
-
state = (state * 1664525 + 1013904223) >>> 0;
|
|
77
|
-
return state / 0xffffffff;
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
type Variant = 'sequencer' | 'data-viz';
|
|
82
|
-
|
|
83
|
-
type StoryArgs = Pick<CellGridProps, 'headers'> & {
|
|
84
|
-
variant: Variant;
|
|
85
|
-
tool: Tool;
|
|
86
|
-
numCols: number;
|
|
87
|
-
numRows: number;
|
|
88
|
-
cellWidth: number;
|
|
89
|
-
cellHeight: number;
|
|
90
|
-
playback: boolean;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const DefaultStory = ({ variant, tool, numCols, numRows, cellWidth, cellHeight, playback, headers }: StoryArgs) => {
|
|
94
|
-
const registry = useContext(RegistryContext);
|
|
95
|
-
|
|
96
|
-
const atoms = useMemo(
|
|
97
|
-
() => createCellGridAtoms<SequencerData | { magnitude: number }>({ cellWidth, cellHeight }),
|
|
98
|
-
[cellWidth, cellHeight],
|
|
99
|
-
);
|
|
100
|
-
const rows: Row[] = useMemo(
|
|
101
|
-
() =>
|
|
102
|
-
Array.from({ length: numRows }, (_, index) => ({
|
|
103
|
-
id: `r${index}`,
|
|
104
|
-
label: variant === 'sequencer' ? `Track ${index + 1}` : `Series ${index + 1}`,
|
|
105
|
-
})),
|
|
106
|
-
[numRows, variant],
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
// Set tool whenever it changes.
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
registry.set(atoms.tool, tool);
|
|
112
|
-
}, [registry, atoms.tool, tool]);
|
|
113
|
-
|
|
114
|
-
// Seed with sample data. Use a deterministic LCG instead of Math.random so
|
|
115
|
-
// story renders are stable across runs (helpful for visual review / snapshots).
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
const next = new Map<string, Cell<SequencerData | { magnitude: number }>>();
|
|
118
|
-
const lcg = makeLcg(0xc0ffee);
|
|
119
|
-
if (variant === 'sequencer') {
|
|
120
|
-
for (let row = 0; row < numRows; row++) {
|
|
121
|
-
for (let col = 0; col < numCols; col += row + 2) {
|
|
122
|
-
if (col % (row + 1) === 0) {
|
|
123
|
-
next.set(`${col},${row}`, { col, row, length: 1, data: { velocity: 0.5 + lcg() * 0.5 } });
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
for (let row = 0; row < numRows; row++) {
|
|
129
|
-
for (let col = 0; col < numCols; col++) {
|
|
130
|
-
if (lcg() < 0.35) {
|
|
131
|
-
next.set(`${col},${row}`, { col, row, length: 1, data: { magnitude: lcg() } });
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
registry.set(atoms.cells, next);
|
|
137
|
-
}, [registry, atoms.cells, variant, numCols, numRows]);
|
|
138
|
-
|
|
139
|
-
// Animated playhead.
|
|
140
|
-
const playRef = useRef<number | null>(null);
|
|
141
|
-
useEffect(() => {
|
|
142
|
-
if (!playback) {
|
|
143
|
-
registry.set(atoms.playhead, null);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const start = performance.now();
|
|
147
|
-
const period = 4_000; // ms to traverse numCols.
|
|
148
|
-
const tick = (now: number) => {
|
|
149
|
-
const t = ((now - start) % period) / period;
|
|
150
|
-
registry.set(atoms.playhead, t * numCols);
|
|
151
|
-
playRef.current = requestAnimationFrame(tick);
|
|
152
|
-
};
|
|
153
|
-
playRef.current = requestAnimationFrame(tick);
|
|
154
|
-
return () => {
|
|
155
|
-
if (playRef.current !== null) {
|
|
156
|
-
cancelAnimationFrame(playRef.current);
|
|
157
|
-
}
|
|
158
|
-
registry.set(atoms.playhead, null);
|
|
159
|
-
};
|
|
160
|
-
}, [registry, atoms.playhead, playback, numCols]);
|
|
161
|
-
|
|
162
|
-
const renderCell = variant === 'sequencer' ? (renderSequencerCell as RenderCell) : (renderDataVizCell as RenderCell);
|
|
163
|
-
|
|
164
|
-
const handleToggle = (coord: CellCoord) => {
|
|
165
|
-
toggleCell(registry, atoms, coord, ({ col, row }) => ({
|
|
166
|
-
col,
|
|
167
|
-
row,
|
|
168
|
-
length: 1,
|
|
169
|
-
data: variant === 'sequencer' ? { velocity: 0.8 } : { magnitude: 0.7 },
|
|
170
|
-
}));
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
return (
|
|
174
|
-
<div className='dx-cover'>
|
|
175
|
-
<CellGrid
|
|
176
|
-
atoms={atoms as any}
|
|
177
|
-
rows={rows}
|
|
178
|
-
renderCell={renderCell}
|
|
179
|
-
headers={headers}
|
|
180
|
-
onCellToggle={handleToggle}
|
|
181
|
-
/>
|
|
182
|
-
</div>
|
|
183
|
-
);
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const RegistryWrapper = ({ children }: { children: React.ReactNode }) => {
|
|
187
|
-
const [registry] = useState(() => Registry.make());
|
|
188
|
-
return <RegistryContext.Provider value={registry}>{children}</RegistryContext.Provider>;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const meta: Meta<typeof DefaultStory> = {
|
|
192
|
-
title: 'ui/react-ui-canvas/CellGrid',
|
|
193
|
-
component: DefaultStory,
|
|
194
|
-
render: (args) => (
|
|
195
|
-
<RegistryWrapper>
|
|
196
|
-
<DefaultStory {...args} />
|
|
197
|
-
</RegistryWrapper>
|
|
198
|
-
),
|
|
199
|
-
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
200
|
-
parameters: { layout: 'fullscreen' },
|
|
201
|
-
argTypes: {
|
|
202
|
-
variant: { control: { type: 'inline-radio' }, options: ['sequencer', 'data-viz'] },
|
|
203
|
-
// 'resize' is deferred (PR description "Deferred / out of v1") — hide from controls.
|
|
204
|
-
tool: { control: { type: 'inline-radio' }, options: ['toggle', 'select'] },
|
|
205
|
-
numCols: { control: { type: 'number', min: 16, max: 1024, step: 16 } },
|
|
206
|
-
numRows: { control: { type: 'number', min: 1, max: 64, step: 1 } },
|
|
207
|
-
cellWidth: { control: { type: 'number', min: 8, max: 64, step: 1 } },
|
|
208
|
-
cellHeight: { control: { type: 'number', min: 12, max: 64, step: 1 } },
|
|
209
|
-
playback: { control: 'boolean' },
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
export default meta;
|
|
214
|
-
|
|
215
|
-
type Story = StoryObj<typeof meta>;
|
|
216
|
-
|
|
217
|
-
export const Sequencer: Story = {
|
|
218
|
-
args: {
|
|
219
|
-
variant: 'sequencer',
|
|
220
|
-
tool: 'toggle',
|
|
221
|
-
numCols: 64,
|
|
222
|
-
numRows: 8,
|
|
223
|
-
cellWidth: 24,
|
|
224
|
-
cellHeight: 24,
|
|
225
|
-
playback: true,
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
export const DataViz: Story = {
|
|
230
|
-
args: {
|
|
231
|
-
variant: 'data-viz',
|
|
232
|
-
tool: 'select',
|
|
233
|
-
numCols: 256,
|
|
234
|
-
numRows: 12,
|
|
235
|
-
cellWidth: 20,
|
|
236
|
-
cellHeight: 20,
|
|
237
|
-
playback: false,
|
|
238
|
-
},
|
|
239
|
-
};
|