@open-draw/canvas 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +77 -2
- package/dist/a11y.d.ts +13 -0
- package/dist/a11y.d.ts.map +1 -0
- package/dist/a11y.js +41 -0
- package/dist/a11y.js.map +1 -0
- package/dist/camera.d.ts +96 -0
- package/dist/camera.d.ts.map +1 -0
- package/dist/camera.js +208 -0
- package/dist/camera.js.map +1 -0
- package/dist/capabilities/clipping/defs.d.ts +7 -0
- package/dist/capabilities/clipping/defs.d.ts.map +1 -0
- package/dist/capabilities/clipping/defs.js +2 -0
- package/dist/capabilities/clipping/defs.js.map +1 -0
- package/dist/capabilities/clipping/index.d.ts +3 -0
- package/dist/capabilities/clipping/index.d.ts.map +1 -0
- package/dist/capabilities/clipping/index.js +3 -0
- package/dist/capabilities/clipping/index.js.map +1 -0
- package/dist/capabilities/clipping/manager.d.ts +14 -0
- package/dist/capabilities/clipping/manager.d.ts.map +1 -0
- package/dist/capabilities/clipping/manager.js +75 -0
- package/dist/capabilities/clipping/manager.js.map +1 -0
- package/dist/capabilities/connector/defs.d.ts +9 -0
- package/dist/capabilities/connector/defs.d.ts.map +1 -0
- package/dist/capabilities/connector/defs.js +2 -0
- package/dist/capabilities/connector/defs.js.map +1 -0
- package/dist/capabilities/connector/index.d.ts +3 -0
- package/dist/capabilities/connector/index.d.ts.map +1 -0
- package/dist/capabilities/connector/index.js +3 -0
- package/dist/capabilities/connector/index.js.map +1 -0
- package/dist/capabilities/connector/manager.d.ts +19 -0
- package/dist/capabilities/connector/manager.d.ts.map +1 -0
- package/dist/capabilities/connector/manager.js +108 -0
- package/dist/capabilities/connector/manager.js.map +1 -0
- package/dist/capabilities/text-editing/defs.d.ts +2 -0
- package/dist/capabilities/text-editing/defs.d.ts.map +1 -0
- package/dist/capabilities/text-editing/defs.js +2 -0
- package/dist/capabilities/text-editing/defs.js.map +1 -0
- package/dist/capabilities/text-editing/index.d.ts +3 -0
- package/dist/capabilities/text-editing/index.d.ts.map +1 -0
- package/dist/capabilities/text-editing/index.js +3 -0
- package/dist/capabilities/text-editing/index.js.map +1 -0
- package/dist/capabilities/text-editing/manager.d.ts +20 -0
- package/dist/capabilities/text-editing/manager.d.ts.map +1 -0
- package/dist/capabilities/text-editing/manager.js +153 -0
- package/dist/capabilities/text-editing/manager.js.map +1 -0
- package/dist/editor.d.ts +94 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +241 -0
- package/dist/editor.js.map +1 -0
- package/dist/eraser/eraser.d.ts +21 -0
- package/dist/eraser/eraser.d.ts.map +1 -0
- package/dist/eraser/eraser.js +147 -0
- package/dist/eraser/eraser.js.map +1 -0
- package/dist/eraser/index.d.ts +2 -0
- package/dist/eraser/index.d.ts.map +1 -0
- package/dist/eraser/index.js +2 -0
- package/dist/eraser/index.js.map +1 -0
- package/dist/export/index.d.ts +2 -0
- package/dist/export/index.d.ts.map +1 -0
- package/dist/export/index.js +2 -0
- package/dist/export/index.js.map +1 -0
- package/dist/export/png.d.ts +17 -0
- package/dist/export/png.d.ts.map +1 -0
- package/dist/export/png.js +130 -0
- package/dist/export/png.js.map +1 -0
- package/dist/gesture/gesture.d.ts +36 -0
- package/dist/gesture/gesture.d.ts.map +1 -0
- package/dist/gesture/gesture.js +268 -0
- package/dist/gesture/gesture.js.map +1 -0
- package/dist/gesture/index.d.ts +2 -0
- package/dist/gesture/index.d.ts.map +1 -0
- package/dist/gesture/index.js +2 -0
- package/dist/gesture/index.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/input/commands.d.ts +12 -0
- package/dist/input/commands.d.ts.map +1 -0
- package/dist/input/commands.js +195 -0
- package/dist/input/commands.js.map +1 -0
- package/dist/input/index.d.ts +5 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/index.js +5 -0
- package/dist/input/index.js.map +1 -0
- package/dist/input/keyboard.d.ts +13 -0
- package/dist/input/keyboard.d.ts.map +1 -0
- package/dist/input/keyboard.js +83 -0
- package/dist/input/keyboard.js.map +1 -0
- package/dist/input/keymap.d.ts +10 -0
- package/dist/input/keymap.d.ts.map +1 -0
- package/dist/input/keymap.js +75 -0
- package/dist/input/keymap.js.map +1 -0
- package/dist/input/utils.d.ts +5 -0
- package/dist/input/utils.d.ts.map +1 -0
- package/dist/input/utils.js +4 -0
- package/dist/input/utils.js.map +1 -0
- package/dist/interaction.d.ts +29 -0
- package/dist/interaction.d.ts.map +1 -0
- package/dist/interaction.js +248 -0
- package/dist/interaction.js.map +1 -0
- package/dist/perf/index.d.ts +2 -0
- package/dist/perf/index.d.ts.map +1 -0
- package/dist/perf/index.js +2 -0
- package/dist/perf/index.js.map +1 -0
- package/dist/perf/telemetry.d.ts +33 -0
- package/dist/perf/telemetry.d.ts.map +1 -0
- package/dist/perf/telemetry.js +145 -0
- package/dist/perf/telemetry.js.map +1 -0
- package/dist/registry.d.ts +68 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +34 -0
- package/dist/registry.js.map +1 -0
- package/dist/renderer.d.ts +29 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +257 -0
- package/dist/renderer.js.map +1 -0
- package/dist/selection/defs.d.ts +6 -0
- package/dist/selection/defs.d.ts.map +1 -0
- package/dist/selection/defs.js +2 -0
- package/dist/selection/defs.js.map +1 -0
- package/dist/selection/group.d.ts +7 -0
- package/dist/selection/group.d.ts.map +1 -0
- package/dist/selection/group.js +25 -0
- package/dist/selection/group.js.map +1 -0
- package/dist/selection/handles.d.ts +9 -0
- package/dist/selection/handles.d.ts.map +1 -0
- package/dist/selection/handles.js +19 -0
- package/dist/selection/handles.js.map +1 -0
- package/dist/selection/handlesView.d.ts +4 -0
- package/dist/selection/handlesView.d.ts.map +1 -0
- package/dist/selection/handlesView.js +98 -0
- package/dist/selection/handlesView.js.map +1 -0
- package/dist/selection/index.d.ts +10 -0
- package/dist/selection/index.d.ts.map +1 -0
- package/dist/selection/index.js +10 -0
- package/dist/selection/index.js.map +1 -0
- package/dist/selection/manager.d.ts +29 -0
- package/dist/selection/manager.d.ts.map +1 -0
- package/dist/selection/manager.js +195 -0
- package/dist/selection/manager.js.map +1 -0
- package/dist/selection/marquee.d.ts +11 -0
- package/dist/selection/marquee.d.ts.map +1 -0
- package/dist/selection/marquee.js +52 -0
- package/dist/selection/marquee.js.map +1 -0
- package/dist/selection/reparent.d.ts +12 -0
- package/dist/selection/reparent.d.ts.map +1 -0
- package/dist/selection/reparent.js +57 -0
- package/dist/selection/reparent.js.map +1 -0
- package/dist/selection/resize.d.ts +10 -0
- package/dist/selection/resize.d.ts.map +1 -0
- package/dist/selection/resize.js +66 -0
- package/dist/selection/resize.js.map +1 -0
- package/dist/selection/rotate.d.ts +18 -0
- package/dist/selection/rotate.d.ts.map +1 -0
- package/dist/selection/rotate.js +39 -0
- package/dist/selection/rotate.js.map +1 -0
- package/dist/shapes/arrow/defs.d.ts +17 -0
- package/dist/shapes/arrow/defs.d.ts.map +1 -0
- package/dist/shapes/arrow/defs.js +7 -0
- package/dist/shapes/arrow/defs.js.map +1 -0
- package/dist/shapes/arrow/geometry.d.ts +11 -0
- package/dist/shapes/arrow/geometry.d.ts.map +1 -0
- package/dist/shapes/arrow/geometry.js +77 -0
- package/dist/shapes/arrow/geometry.js.map +1 -0
- package/dist/shapes/arrow/index.d.ts +7 -0
- package/dist/shapes/arrow/index.d.ts.map +1 -0
- package/dist/shapes/arrow/index.js +23 -0
- package/dist/shapes/arrow/index.js.map +1 -0
- package/dist/shapes/arrow/render.d.ts +6 -0
- package/dist/shapes/arrow/render.d.ts.map +1 -0
- package/dist/shapes/arrow/render.js +84 -0
- package/dist/shapes/arrow/render.js.map +1 -0
- package/dist/shapes/ellipse/defs.d.ts +8 -0
- package/dist/shapes/ellipse/defs.d.ts.map +1 -0
- package/dist/shapes/ellipse/defs.js +2 -0
- package/dist/shapes/ellipse/defs.js.map +1 -0
- package/dist/shapes/ellipse/geometry.d.ts +9 -0
- package/dist/shapes/ellipse/geometry.d.ts.map +1 -0
- package/dist/shapes/ellipse/geometry.js +74 -0
- package/dist/shapes/ellipse/geometry.js.map +1 -0
- package/dist/shapes/ellipse/index.d.ts +7 -0
- package/dist/shapes/ellipse/index.d.ts.map +1 -0
- package/dist/shapes/ellipse/index.js +21 -0
- package/dist/shapes/ellipse/index.js.map +1 -0
- package/dist/shapes/ellipse/render.d.ts +6 -0
- package/dist/shapes/ellipse/render.d.ts.map +1 -0
- package/dist/shapes/ellipse/render.js +39 -0
- package/dist/shapes/ellipse/render.js.map +1 -0
- package/dist/shapes/frame/defs.d.ts +9 -0
- package/dist/shapes/frame/defs.d.ts.map +1 -0
- package/dist/shapes/frame/defs.js +8 -0
- package/dist/shapes/frame/defs.js.map +1 -0
- package/dist/shapes/frame/geometry.d.ts +4 -0
- package/dist/shapes/frame/geometry.d.ts.map +1 -0
- package/dist/shapes/frame/geometry.js +66 -0
- package/dist/shapes/frame/geometry.js.map +1 -0
- package/dist/shapes/frame/index.d.ts +7 -0
- package/dist/shapes/frame/index.d.ts.map +1 -0
- package/dist/shapes/frame/index.js +20 -0
- package/dist/shapes/frame/index.js.map +1 -0
- package/dist/shapes/frame/render.d.ts +6 -0
- package/dist/shapes/frame/render.d.ts.map +1 -0
- package/dist/shapes/frame/render.js +73 -0
- package/dist/shapes/frame/render.js.map +1 -0
- package/dist/shapes/group/defs.d.ts +6 -0
- package/dist/shapes/group/defs.d.ts.map +1 -0
- package/dist/shapes/group/defs.js +2 -0
- package/dist/shapes/group/defs.js.map +1 -0
- package/dist/shapes/group/geometry.d.ts +8 -0
- package/dist/shapes/group/geometry.d.ts.map +1 -0
- package/dist/shapes/group/geometry.js +19 -0
- package/dist/shapes/group/geometry.js.map +1 -0
- package/dist/shapes/group/index.d.ts +7 -0
- package/dist/shapes/group/index.d.ts.map +1 -0
- package/dist/shapes/group/index.js +23 -0
- package/dist/shapes/group/index.js.map +1 -0
- package/dist/shapes/group/render.d.ts +6 -0
- package/dist/shapes/group/render.d.ts.map +1 -0
- package/dist/shapes/group/render.js +9 -0
- package/dist/shapes/group/render.js.map +1 -0
- package/dist/shapes/image/defs.d.ts +10 -0
- package/dist/shapes/image/defs.d.ts.map +1 -0
- package/dist/shapes/image/defs.js +2 -0
- package/dist/shapes/image/defs.js.map +1 -0
- package/dist/shapes/image/geometry.d.ts +21 -0
- package/dist/shapes/image/geometry.d.ts.map +1 -0
- package/dist/shapes/image/geometry.js +79 -0
- package/dist/shapes/image/geometry.js.map +1 -0
- package/dist/shapes/image/handlers.d.ts +10 -0
- package/dist/shapes/image/handlers.d.ts.map +1 -0
- package/dist/shapes/image/handlers.js +85 -0
- package/dist/shapes/image/handlers.js.map +1 -0
- package/dist/shapes/image/index.d.ts +8 -0
- package/dist/shapes/image/index.d.ts.map +1 -0
- package/dist/shapes/image/index.js +21 -0
- package/dist/shapes/image/index.js.map +1 -0
- package/dist/shapes/image/render.d.ts +6 -0
- package/dist/shapes/image/render.d.ts.map +1 -0
- package/dist/shapes/image/render.js +28 -0
- package/dist/shapes/image/render.js.map +1 -0
- package/dist/shapes/ink/defs.d.ts +10 -0
- package/dist/shapes/ink/defs.d.ts.map +1 -0
- package/dist/shapes/ink/defs.js +13 -0
- package/dist/shapes/ink/defs.js.map +1 -0
- package/dist/shapes/ink/geometry.d.ts +4 -0
- package/dist/shapes/ink/geometry.d.ts.map +1 -0
- package/dist/shapes/ink/geometry.js +67 -0
- package/dist/shapes/ink/geometry.js.map +1 -0
- package/dist/shapes/ink/index.d.ts +9 -0
- package/dist/shapes/ink/index.d.ts.map +1 -0
- package/dist/shapes/ink/index.js +22 -0
- package/dist/shapes/ink/index.js.map +1 -0
- package/dist/shapes/ink/rdp.d.ts +2 -0
- package/dist/shapes/ink/rdp.d.ts.map +1 -0
- package/dist/shapes/ink/rdp.js +37 -0
- package/dist/shapes/ink/rdp.js.map +1 -0
- package/dist/shapes/ink/render.d.ts +7 -0
- package/dist/shapes/ink/render.d.ts.map +1 -0
- package/dist/shapes/ink/render.js +81 -0
- package/dist/shapes/ink/render.js.map +1 -0
- package/dist/shapes/note/defs.d.ts +7 -0
- package/dist/shapes/note/defs.d.ts.map +1 -0
- package/dist/shapes/note/defs.js +2 -0
- package/dist/shapes/note/defs.js.map +1 -0
- package/dist/shapes/note/geometry.d.ts +11 -0
- package/dist/shapes/note/geometry.d.ts.map +1 -0
- package/dist/shapes/note/geometry.js +70 -0
- package/dist/shapes/note/geometry.js.map +1 -0
- package/dist/shapes/note/index.d.ts +7 -0
- package/dist/shapes/note/index.d.ts.map +1 -0
- package/dist/shapes/note/index.js +41 -0
- package/dist/shapes/note/index.js.map +1 -0
- package/dist/shapes/note/render.d.ts +6 -0
- package/dist/shapes/note/render.d.ts.map +1 -0
- package/dist/shapes/note/render.js +38 -0
- package/dist/shapes/note/render.js.map +1 -0
- package/dist/shapes/rect/defs.d.ts +9 -0
- package/dist/shapes/rect/defs.d.ts.map +1 -0
- package/dist/shapes/rect/defs.js +2 -0
- package/dist/shapes/rect/defs.js.map +1 -0
- package/dist/shapes/rect/geometry.d.ts +9 -0
- package/dist/shapes/rect/geometry.d.ts.map +1 -0
- package/dist/shapes/rect/geometry.js +68 -0
- package/dist/shapes/rect/geometry.js.map +1 -0
- package/dist/shapes/rect/index.d.ts +7 -0
- package/dist/shapes/rect/index.d.ts.map +1 -0
- package/dist/shapes/rect/index.js +22 -0
- package/dist/shapes/rect/index.js.map +1 -0
- package/dist/shapes/rect/render.d.ts +6 -0
- package/dist/shapes/rect/render.d.ts.map +1 -0
- package/dist/shapes/rect/render.js +42 -0
- package/dist/shapes/rect/render.js.map +1 -0
- package/dist/shapes/text/defs.d.ts +9 -0
- package/dist/shapes/text/defs.d.ts.map +1 -0
- package/dist/shapes/text/defs.js +2 -0
- package/dist/shapes/text/defs.js.map +1 -0
- package/dist/shapes/text/geometry.d.ts +9 -0
- package/dist/shapes/text/geometry.d.ts.map +1 -0
- package/dist/shapes/text/geometry.js +68 -0
- package/dist/shapes/text/geometry.js.map +1 -0
- package/dist/shapes/text/index.d.ts +7 -0
- package/dist/shapes/text/index.d.ts.map +1 -0
- package/dist/shapes/text/index.js +43 -0
- package/dist/shapes/text/index.js.map +1 -0
- package/dist/shapes/text/render.d.ts +6 -0
- package/dist/shapes/text/render.d.ts.map +1 -0
- package/dist/shapes/text/render.js +23 -0
- package/dist/shapes/text/render.js.map +1 -0
- package/dist/store/index.d.ts +5 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +5 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/snapshot.d.ts +5 -0
- package/dist/store/snapshot.d.ts.map +1 -0
- package/dist/store/snapshot.js +76 -0
- package/dist/store/snapshot.js.map +1 -0
- package/dist/store/store.d.ts +52 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +252 -0
- package/dist/store/store.js.map +1 -0
- package/dist/store/types.d.ts +13 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/types.js +2 -0
- package/dist/store/types.js.map +1 -0
- package/dist/store/zorder.d.ts +4 -0
- package/dist/store/zorder.d.ts.map +1 -0
- package/dist/store/zorder.js +53 -0
- package/dist/store/zorder.js.map +1 -0
- package/package.json +29 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chandra Shekhar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @open-draw/canvas
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://www.npmjs.com/package/@open-draw/canvas)
|
|
5
|
+
|
|
6
|
+
> DOM Canvas engine — an infinite canvas where every shape is a real SVG element.
|
|
7
|
+
|
|
8
|
+
`@open-draw/canvas` provides a high-performance, pure SVG DOM canvas engine. It powers infinite pan and zoom, reactive transactions, undo/redo history, shape registration, live preview transforms, inline text editing, and export to PNG, all while maintaining strict zero runtime dependencies outside of `@open-draw/schema`.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
### Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @open-draw/canvas @open-draw/schema
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
### Minimal Example (30 lines)
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { CanvasEditor } from '@open-draw/canvas';
|
|
24
|
+
|
|
25
|
+
// 1. Initialize and mount canvas
|
|
26
|
+
const container = document.getElementById('canvas-container')!;
|
|
27
|
+
const editor = new CanvasEditor();
|
|
28
|
+
editor.mount(container);
|
|
29
|
+
|
|
30
|
+
// 2. Create shapes via reactive transactions
|
|
31
|
+
const note = editor.createShape({
|
|
32
|
+
type: 'note',
|
|
33
|
+
x: 100,
|
|
34
|
+
y: 100,
|
|
35
|
+
props: { width: 180, height: 120, color: '#fef08a', text: 'Important Note' },
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 3. Attach custom HTML/SVG badges into the shape's overlay slot
|
|
39
|
+
const slot = editor.getOverlaySlot(note.id);
|
|
40
|
+
if (slot) {
|
|
41
|
+
const badge = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
42
|
+
badge.setAttribute('x', '10');
|
|
43
|
+
badge.setAttribute('y', '24');
|
|
44
|
+
badge.textContent = 'STATUS: REVIEW';
|
|
45
|
+
slot.appendChild(badge);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 4. Undo and redo with single-step atomic transactions
|
|
49
|
+
editor.undo();
|
|
50
|
+
editor.redo();
|
|
51
|
+
|
|
52
|
+
// 5. Export canvas to PNG Blob
|
|
53
|
+
const pngBlob = await editor.exportPNG({ chips: true });
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
### Try the Playground
|
|
59
|
+
|
|
60
|
+
You can run the interactive development playground locally from the repository root:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npx vite --config packages/canvas/e2e/playground/vite.config.ts packages/canvas/e2e/playground --host 127.0.0.1 --port 5173
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Navigate to `http://127.0.0.1:5173/` in your browser to interact with the live canvas, test gestures, and benchmark FPS.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
### Semver Statement
|
|
71
|
+
|
|
72
|
+
Starting from version `0.1.0`, the public API surface of `@open-draw/canvas` is frozen under CI surveillance. No public export or contract will be changed or removed without an advance minor-version deprecation cycle.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
### License
|
|
77
|
+
|
|
78
|
+
MIT © Chandu4221
|
package/dist/a11y.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ShapeRecord } from '@open-draw/schema';
|
|
2
|
+
import type { ShapeDefinition } from './registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* Computes semantic role and accessible label for SVG shape wrappers.
|
|
5
|
+
* Containers (shapes with clipping or group capability) receive 'group' to prevent nested-interactive violations.
|
|
6
|
+
* Shapes with visible text (props.text, props.label, or text capability) include visible text in accessible name (WCAG 2.5.3).
|
|
7
|
+
*/
|
|
8
|
+
export declare function computeShapeAria(shape: ShapeRecord, def?: ShapeDefinition): {
|
|
9
|
+
role: string;
|
|
10
|
+
ariaLabel: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const A11Y_FOCUS_STYLES = "\n .od-canvas-root:focus-visible { outline: 2px solid #3b82f6; outline-offset: -2px; }\n .od-shape:focus-visible { outline: 2px solid #3b82f6; outline-offset: 2px; }\n";
|
|
13
|
+
//# sourceMappingURL=a11y.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a11y.d.ts","sourceRoot":"","sources":["../src/a11y.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,WAAW,EAClB,GAAG,CAAC,EAAE,eAAe,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CA8BrC;AAED,eAAO,MAAM,iBAAiB,8KAG7B,CAAC"}
|
package/dist/a11y.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes semantic role and accessible label for SVG shape wrappers.
|
|
3
|
+
* Containers (shapes with clipping or group capability) receive 'group' to prevent nested-interactive violations.
|
|
4
|
+
* Shapes with visible text (props.text, props.label, or text capability) include visible text in accessible name (WCAG 2.5.3).
|
|
5
|
+
*/
|
|
6
|
+
export function computeShapeAria(shape, def) {
|
|
7
|
+
const isContainer = Boolean(def?.capabilities?.clipping || def?.capabilities?.group);
|
|
8
|
+
const role = isContainer ? 'group' : 'button';
|
|
9
|
+
let visibleText = '';
|
|
10
|
+
if (def?.capabilities?.text?.canEditText(shape)) {
|
|
11
|
+
visibleText = def.capabilities.text.getText(shape).trim();
|
|
12
|
+
}
|
|
13
|
+
else if (typeof shape.props['text'] === 'string' && shape.props['text'].trim()) {
|
|
14
|
+
visibleText = shape.props['text'].trim();
|
|
15
|
+
}
|
|
16
|
+
else if (typeof shape.props['label'] === 'string' && shape.props['label'].trim()) {
|
|
17
|
+
visibleText = shape.props['label'].trim();
|
|
18
|
+
}
|
|
19
|
+
const metaName = typeof shape.meta['name'] === 'string' && shape.meta['name'].trim()
|
|
20
|
+
? shape.meta['name'].trim()
|
|
21
|
+
: '';
|
|
22
|
+
let ariaLabel;
|
|
23
|
+
if (visibleText && metaName) {
|
|
24
|
+
ariaLabel = `${visibleText} (${shape.type} ${metaName})`;
|
|
25
|
+
}
|
|
26
|
+
else if (visibleText) {
|
|
27
|
+
ariaLabel = `${visibleText} (${shape.type})`;
|
|
28
|
+
}
|
|
29
|
+
else if (metaName) {
|
|
30
|
+
ariaLabel = `${shape.type} ${metaName}`;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
ariaLabel = shape.type;
|
|
34
|
+
}
|
|
35
|
+
return { role, ariaLabel };
|
|
36
|
+
}
|
|
37
|
+
export const A11Y_FOCUS_STYLES = `
|
|
38
|
+
.od-canvas-root:focus-visible { outline: 2px solid #3b82f6; outline-offset: -2px; }
|
|
39
|
+
.od-shape:focus-visible { outline: 2px solid #3b82f6; outline-offset: 2px; }
|
|
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AAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE;QACjE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE;QAC3B,CAAC,CAAC,EAAE,CAAC;IAET,IAAI,SAAiB,CAAC;IACtB,IAAI,WAAW,IAAI,QAAQ,EAAE,CAAC;QAC5B,SAAS,GAAG,GAAG,WAAW,KAAK,KAAK,CAAC,IAAI,IAAI,QAAQ,GAAG,CAAC;IAC3D,CAAC;SAAM,IAAI,WAAW,EAAE,CAAC;QACvB,SAAS,GAAG,GAAG,WAAW,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC;IAC/C,CAAC;SAAM,IAAI,QAAQ,EAAE,CAAC;QACpB,SAAS,GAAG,GAAG,KAAK,CAAC,IAAI,IAAI,QAAQ,EAAE,CAAC;IAC1C,CAAC;SAAM,CAAC;QACN,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;CAGhC,CAAC"}
|
package/dist/camera.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { Camera, Point } from '@open-draw/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when camera parameters are invalid (e.g. non-finite or non-positive zoom).
|
|
4
|
+
*/
|
|
5
|
+
export declare class InvalidCameraError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when an invalid zoom factor is supplied.
|
|
10
|
+
*/
|
|
11
|
+
export declare class InvalidZoomError extends Error {
|
|
12
|
+
readonly factor: number;
|
|
13
|
+
constructor(factor: number, message?: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Default camera state positioned at origin with 1x zoom.
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEFAULT_CAMERA: Camera;
|
|
19
|
+
/**
|
|
20
|
+
* Options for zoom operations.
|
|
21
|
+
*/
|
|
22
|
+
export interface ZoomOptions {
|
|
23
|
+
readonly minZoom?: number;
|
|
24
|
+
readonly maxZoom?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validates and creates an immutable Camera state object.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createCamera(initial?: Partial<Camera>): Camera;
|
|
30
|
+
/**
|
|
31
|
+
* Converts a point from page (canvas world) coordinates to screen (viewport) coordinates.
|
|
32
|
+
* Screen point = point * camera.zoom + camera.offset
|
|
33
|
+
*/
|
|
34
|
+
export declare function pageToScreen(point: Point, camera: Camera): Point;
|
|
35
|
+
/**
|
|
36
|
+
* Converts a point from screen (viewport) coordinates to page (canvas world) coordinates.
|
|
37
|
+
* Page point = (screen point - camera.offset) / camera.zoom
|
|
38
|
+
*/
|
|
39
|
+
export declare function screenToPage(point: Point, camera: Camera): Point;
|
|
40
|
+
/**
|
|
41
|
+
* Pans the camera by a delta in screen space.
|
|
42
|
+
*/
|
|
43
|
+
export declare function panCamera(camera: Camera, delta: Point): Camera;
|
|
44
|
+
/**
|
|
45
|
+
* Zooms the camera around a specific anchor point on the screen (cursor-anchored zoom).
|
|
46
|
+
* The canvas page point currently under screenPoint remains under screenPoint after zooming.
|
|
47
|
+
*/
|
|
48
|
+
export declare function zoomAroundPoint(camera: Camera, screenPoint: Point, factor: number, options?: ZoomOptions): Camera;
|
|
49
|
+
/**
|
|
50
|
+
* Fits the camera to focus on given bounds within a viewport.
|
|
51
|
+
*/
|
|
52
|
+
export declare function fitToBounds(bounds: {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
}, viewportSize: {
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
}, padding?: number): Camera;
|
|
61
|
+
/**
|
|
62
|
+
* Produces the SVG transform string for the root viewport group:
|
|
63
|
+
* translate(x, y) scale(zoom)
|
|
64
|
+
*/
|
|
65
|
+
export declare function cameraToTransform(camera: Camera): string;
|
|
66
|
+
/**
|
|
67
|
+
* Stateful controller for managing camera state, coordinate transforms, and change listeners.
|
|
68
|
+
*/
|
|
69
|
+
export declare class CameraController {
|
|
70
|
+
private _camera;
|
|
71
|
+
private readonly _listeners;
|
|
72
|
+
constructor(initial?: Partial<Camera>);
|
|
73
|
+
get camera(): Camera;
|
|
74
|
+
get x(): number;
|
|
75
|
+
get y(): number;
|
|
76
|
+
get zoom(): number;
|
|
77
|
+
setCamera(camera: Camera): void;
|
|
78
|
+
pageToScreen(point: Point): Point;
|
|
79
|
+
screenToPage(point: Point): Point;
|
|
80
|
+
pan(dx: number, dy: number): Camera;
|
|
81
|
+
zoomAroundPoint(screenPoint: Point, factor: number, options?: ZoomOptions): Camera;
|
|
82
|
+
toTransform(): string;
|
|
83
|
+
reset(): Camera;
|
|
84
|
+
fitToBounds(bounds: {
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
width: number;
|
|
88
|
+
height: number;
|
|
89
|
+
}, viewportSize: {
|
|
90
|
+
width: number;
|
|
91
|
+
height: number;
|
|
92
|
+
}, padding?: number): Camera;
|
|
93
|
+
subscribe(listener: (camera: Camera) => void): () => void;
|
|
94
|
+
private _notify;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=camera.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,YAAY,MAAM,EA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CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuC;IAElE,YAAY,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAEpC;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,CAAC,IAAI,MAAM,CAEd;IAED,IAAI,CAAC,IAAI,MAAM,CAEd;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAM9B;IAED,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAEhC;IAED,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAEhC;IAED,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAKlC;IAED,eAAe,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,CAKjF;IAED,WAAW,IAAI,MAAM,CAEpB;IAED,KAAK,IAAI,MAAM,CAGd;IAED,WAAW,CAAC,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,YAAY,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAItJ;IAED,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAKxD;IAED,OAAO,CAAC,OAAO;CAKhB"}
|
package/dist/camera.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when camera parameters are invalid (e.g. non-finite or non-positive zoom).
|
|
3
|
+
*/
|
|
4
|
+
export class InvalidCameraError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'InvalidCameraError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when an invalid zoom factor is supplied.
|
|
12
|
+
*/
|
|
13
|
+
export class InvalidZoomError extends Error {
|
|
14
|
+
factor;
|
|
15
|
+
constructor(factor, message) {
|
|
16
|
+
super(message ?? `Invalid zoom factor: ${factor}. Zoom factor must be a finite positive number.`);
|
|
17
|
+
this.name = 'InvalidZoomError';
|
|
18
|
+
this.factor = factor;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Default camera state positioned at origin with 1x zoom.
|
|
23
|
+
*/
|
|
24
|
+
export const DEFAULT_CAMERA = Object.freeze({
|
|
25
|
+
x: 0,
|
|
26
|
+
y: 0,
|
|
27
|
+
zoom: 1,
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Validates and creates an immutable Camera state object.
|
|
31
|
+
*/
|
|
32
|
+
export function createCamera(initial) {
|
|
33
|
+
const x = initial?.x ?? DEFAULT_CAMERA.x;
|
|
34
|
+
const y = initial?.y ?? DEFAULT_CAMERA.y;
|
|
35
|
+
const zoom = initial?.zoom ?? DEFAULT_CAMERA.zoom;
|
|
36
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
37
|
+
throw new InvalidCameraError(`Camera coordinates must be finite numbers: x=${x}, y=${y}`);
|
|
38
|
+
}
|
|
39
|
+
if (!Number.isFinite(zoom) || zoom <= 0) {
|
|
40
|
+
throw new InvalidCameraError(`Camera zoom must be a finite positive number: zoom=${zoom}`);
|
|
41
|
+
}
|
|
42
|
+
return Object.freeze({ x, y, zoom });
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Converts a point from page (canvas world) coordinates to screen (viewport) coordinates.
|
|
46
|
+
* Screen point = point * camera.zoom + camera.offset
|
|
47
|
+
*/
|
|
48
|
+
export function pageToScreen(point, camera) {
|
|
49
|
+
if (!Number.isFinite(point.x) || !Number.isFinite(point.y)) {
|
|
50
|
+
throw new InvalidCameraError(`Point coordinates must be finite numbers: x=${point.x}, y=${point.y}`);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
x: point.x * camera.zoom + camera.x,
|
|
54
|
+
y: point.y * camera.zoom + camera.y,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Converts a point from screen (viewport) coordinates to page (canvas world) coordinates.
|
|
59
|
+
* Page point = (screen point - camera.offset) / camera.zoom
|
|
60
|
+
*/
|
|
61
|
+
export function screenToPage(point, camera) {
|
|
62
|
+
if (!Number.isFinite(point.x) || !Number.isFinite(point.y)) {
|
|
63
|
+
throw new InvalidCameraError(`Point coordinates must be finite numbers: x=${point.x}, y=${point.y}`);
|
|
64
|
+
}
|
|
65
|
+
if (!Number.isFinite(camera.zoom) || camera.zoom <= 0) {
|
|
66
|
+
throw new InvalidCameraError(`Camera zoom must be a finite positive number: zoom=${camera.zoom}`);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
x: (point.x - camera.x) / camera.zoom,
|
|
70
|
+
y: (point.y - camera.y) / camera.zoom,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Pans the camera by a delta in screen space.
|
|
75
|
+
*/
|
|
76
|
+
export function panCamera(camera, delta) {
|
|
77
|
+
if (!Number.isFinite(delta.x) || !Number.isFinite(delta.y)) {
|
|
78
|
+
throw new InvalidCameraError(`Pan delta coordinates must be finite numbers: dx=${delta.x}, dy=${delta.y}`);
|
|
79
|
+
}
|
|
80
|
+
return createCamera({
|
|
81
|
+
x: camera.x + delta.x,
|
|
82
|
+
y: camera.y + delta.y,
|
|
83
|
+
zoom: camera.zoom,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Zooms the camera around a specific anchor point on the screen (cursor-anchored zoom).
|
|
88
|
+
* The canvas page point currently under screenPoint remains under screenPoint after zooming.
|
|
89
|
+
*/
|
|
90
|
+
export function zoomAroundPoint(camera, screenPoint, factor, options) {
|
|
91
|
+
if (!Number.isFinite(factor) || factor <= 0) {
|
|
92
|
+
throw new InvalidZoomError(factor);
|
|
93
|
+
}
|
|
94
|
+
if (!Number.isFinite(screenPoint.x) || !Number.isFinite(screenPoint.y)) {
|
|
95
|
+
throw new InvalidCameraError(`Screen anchor coordinates must be finite: x=${screenPoint.x}, y=${screenPoint.y}`);
|
|
96
|
+
}
|
|
97
|
+
let targetZoom = camera.zoom * factor;
|
|
98
|
+
if (options?.minZoom !== undefined && Number.isFinite(options.minZoom)) {
|
|
99
|
+
targetZoom = Math.max(targetZoom, options.minZoom);
|
|
100
|
+
}
|
|
101
|
+
if (options?.maxZoom !== undefined && Number.isFinite(options.maxZoom)) {
|
|
102
|
+
targetZoom = Math.min(targetZoom, options.maxZoom);
|
|
103
|
+
}
|
|
104
|
+
const effectiveFactor = targetZoom / camera.zoom;
|
|
105
|
+
const newX = screenPoint.x - (screenPoint.x - camera.x) * effectiveFactor;
|
|
106
|
+
const newY = screenPoint.y - (screenPoint.y - camera.y) * effectiveFactor;
|
|
107
|
+
return createCamera({
|
|
108
|
+
x: newX,
|
|
109
|
+
y: newY,
|
|
110
|
+
zoom: targetZoom,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Fits the camera to focus on given bounds within a viewport.
|
|
115
|
+
*/
|
|
116
|
+
export function fitToBounds(bounds, viewportSize, padding = 40) {
|
|
117
|
+
if (bounds.width <= 0 || bounds.height <= 0 || viewportSize.width <= 0 || viewportSize.height <= 0) {
|
|
118
|
+
return DEFAULT_CAMERA;
|
|
119
|
+
}
|
|
120
|
+
const availableW = Math.max(10, viewportSize.width - padding * 2);
|
|
121
|
+
const availableH = Math.max(10, viewportSize.height - padding * 2);
|
|
122
|
+
const zoomX = availableW / bounds.width;
|
|
123
|
+
const zoomY = availableH / bounds.height;
|
|
124
|
+
const clampedZoom = Math.max(0.1, Math.min(2, Math.min(zoomX, zoomY)));
|
|
125
|
+
const centerX = bounds.x + bounds.width / 2;
|
|
126
|
+
const centerY = bounds.y + bounds.height / 2;
|
|
127
|
+
const x = viewportSize.width / 2 - centerX * clampedZoom;
|
|
128
|
+
const y = viewportSize.height / 2 - centerY * clampedZoom;
|
|
129
|
+
return createCamera({ x, y, zoom: clampedZoom });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Produces the SVG transform string for the root viewport group:
|
|
133
|
+
* translate(x, y) scale(zoom)
|
|
134
|
+
*/
|
|
135
|
+
export function cameraToTransform(camera) {
|
|
136
|
+
return `translate(${camera.x}, ${camera.y}) scale(${camera.zoom})`;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Stateful controller for managing camera state, coordinate transforms, and change listeners.
|
|
140
|
+
*/
|
|
141
|
+
export class CameraController {
|
|
142
|
+
_camera;
|
|
143
|
+
_listeners = new Set();
|
|
144
|
+
constructor(initial) {
|
|
145
|
+
this._camera = createCamera(initial);
|
|
146
|
+
}
|
|
147
|
+
get camera() {
|
|
148
|
+
return this._camera;
|
|
149
|
+
}
|
|
150
|
+
get x() {
|
|
151
|
+
return this._camera.x;
|
|
152
|
+
}
|
|
153
|
+
get y() {
|
|
154
|
+
return this._camera.y;
|
|
155
|
+
}
|
|
156
|
+
get zoom() {
|
|
157
|
+
return this._camera.zoom;
|
|
158
|
+
}
|
|
159
|
+
setCamera(camera) {
|
|
160
|
+
const next = createCamera(camera);
|
|
161
|
+
if (next.x !== this._camera.x || next.y !== this._camera.y || next.zoom !== this._camera.zoom) {
|
|
162
|
+
this._camera = next;
|
|
163
|
+
this._notify();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
pageToScreen(point) {
|
|
167
|
+
return pageToScreen(point, this._camera);
|
|
168
|
+
}
|
|
169
|
+
screenToPage(point) {
|
|
170
|
+
return screenToPage(point, this._camera);
|
|
171
|
+
}
|
|
172
|
+
pan(dx, dy) {
|
|
173
|
+
const next = panCamera(this._camera, { x: dx, y: dy });
|
|
174
|
+
this._camera = next;
|
|
175
|
+
this._notify();
|
|
176
|
+
return next;
|
|
177
|
+
}
|
|
178
|
+
zoomAroundPoint(screenPoint, factor, options) {
|
|
179
|
+
const next = zoomAroundPoint(this._camera, screenPoint, factor, options);
|
|
180
|
+
this._camera = next;
|
|
181
|
+
this._notify();
|
|
182
|
+
return next;
|
|
183
|
+
}
|
|
184
|
+
toTransform() {
|
|
185
|
+
return cameraToTransform(this._camera);
|
|
186
|
+
}
|
|
187
|
+
reset() {
|
|
188
|
+
this.setCamera(DEFAULT_CAMERA);
|
|
189
|
+
return this._camera;
|
|
190
|
+
}
|
|
191
|
+
fitToBounds(bounds, viewportSize, padding) {
|
|
192
|
+
const next = fitToBounds(bounds, viewportSize, padding);
|
|
193
|
+
this.setCamera(next);
|
|
194
|
+
return next;
|
|
195
|
+
}
|
|
196
|
+
subscribe(listener) {
|
|
197
|
+
this._listeners.add(listener);
|
|
198
|
+
return () => {
|
|
199
|
+
this._listeners.delete(listener);
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
_notify() {
|
|
203
|
+
for (const listener of this._listeners) {
|
|
204
|
+
listener(this._camera);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=camera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera.js","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,MAAM,CAAS;IAExB,YAAY,MAAc,EAAE,OA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C/B,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,WAAW,CAAC,MAA+D,EAAE,YAA+C,EAAE,OAAgB;QAC5I,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,CAAC,QAAkC;QAC1C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC,CAAC;IACJ,CAAC;IAEO,OAAO;QACb,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACvC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/capabilities/clipping/defs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;CACpC;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defs.js","sourceRoot":"","sources":["../../../src/capabilities/clipping/defs.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/capabilities/clipping/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/capabilities/clipping/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Bounds, ShapeId, ShapeRecord } from '@open-draw/schema';
|
|
2
|
+
import type { ShapeRegistry } from '../../registry.js';
|
|
3
|
+
import type { CanvasStore } from '../../store/index.js';
|
|
4
|
+
import type { ChildOrphanedEvent, OrphanListener } from './defs.js';
|
|
5
|
+
export declare function isContainedWithin(child: Bounds, container: Bounds): boolean;
|
|
6
|
+
export declare function findSuggestedParent(childBounds: Bounds, shapes: Iterable<ShapeRecord>, registry: ShapeRegistry, excludeId?: ShapeId): ShapeRecord | null;
|
|
7
|
+
export declare class ClippingManager {
|
|
8
|
+
private orphanListeners;
|
|
9
|
+
onChildOrphaned(listener: OrphanListener): () => void;
|
|
10
|
+
emitOrphaned(event: ChildOrphanedEvent): void;
|
|
11
|
+
handleParentDeletion(deletedParentId: ShapeId, store: CanvasStore): void;
|
|
12
|
+
detachChild(childId: ShapeId, store: CanvasStore): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/capabilities/clipping/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEpE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAO3E;AAED,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,EAC7B,QAAQ,EAAE,aAAa,EACvB,SAAS,CAAC,EAAE,OAAO,GAClB,WAAW,GAAG,IAAI,CAuBpB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,eAAe,CAAkC;IAEzD,eAAe,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAGpD;IAED,YAAY,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAQ5C;IAED,oBAAoB,CAAC,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAkBvE;IAED,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAUtD;CACF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export function isContainedWithin(child, container) {
|
|
2
|
+
return (child.x >= container.x &&
|
|
3
|
+
child.y >= container.y &&
|
|
4
|
+
child.x + child.width <= container.x + container.width &&
|
|
5
|
+
child.y + child.height <= container.y + container.height);
|
|
6
|
+
}
|
|
7
|
+
export function findSuggestedParent(childBounds, shapes, registry, excludeId) {
|
|
8
|
+
let bestCandidate = null;
|
|
9
|
+
let smallestArea = Infinity;
|
|
10
|
+
for (const candidate of shapes) {
|
|
11
|
+
if (candidate.id === excludeId)
|
|
12
|
+
continue;
|
|
13
|
+
const def = registry.get(candidate.type);
|
|
14
|
+
if (!def?.capabilities?.clipping?.isMask(candidate)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const containerBounds = def.geometry.bounds(candidate);
|
|
18
|
+
if (isContainedWithin(childBounds, containerBounds)) {
|
|
19
|
+
const area = containerBounds.width * containerBounds.height;
|
|
20
|
+
if (area < smallestArea) {
|
|
21
|
+
smallestArea = area;
|
|
22
|
+
bestCandidate = candidate;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return bestCandidate;
|
|
27
|
+
}
|
|
28
|
+
export class ClippingManager {
|
|
29
|
+
orphanListeners = new Set();
|
|
30
|
+
onChildOrphaned(listener) {
|
|
31
|
+
this.orphanListeners.add(listener);
|
|
32
|
+
return () => this.orphanListeners.delete(listener);
|
|
33
|
+
}
|
|
34
|
+
emitOrphaned(event) {
|
|
35
|
+
for (const listener of this.orphanListeners) {
|
|
36
|
+
try {
|
|
37
|
+
listener(event);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.error('Orphan listener error:', err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
handleParentDeletion(deletedParentId, store) {
|
|
45
|
+
const orphaned = [];
|
|
46
|
+
for (const shape of store.listShapes()) {
|
|
47
|
+
if (shape.meta['parent'] === deletedParentId || shape.meta['parentId'] === deletedParentId) {
|
|
48
|
+
orphaned.push(shape);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (orphaned.length === 0)
|
|
52
|
+
return;
|
|
53
|
+
store.transact(() => {
|
|
54
|
+
for (const child of orphaned) {
|
|
55
|
+
store.updateShape(child.id, {
|
|
56
|
+
meta: { parent: undefined, parentId: undefined },
|
|
57
|
+
});
|
|
58
|
+
this.emitOrphaned({ childId: child.id, previousParentId: deletedParentId });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
detachChild(childId, store) {
|
|
63
|
+
const child = store.getShape(childId);
|
|
64
|
+
if (!child)
|
|
65
|
+
return;
|
|
66
|
+
const parentId = (child.meta['parent'] ?? child.meta['parentId']);
|
|
67
|
+
if (!parentId || typeof parentId !== 'string')
|
|
68
|
+
return;
|
|
69
|
+
store.updateShape(childId, {
|
|
70
|
+
meta: { parent: undefined, parentId: undefined },
|
|
71
|
+
});
|
|
72
|
+
this.emitOrphaned({ childId, previousParentId: parentId });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/capabilities/clipping/manager.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,iBAAiB,CAAC,KAAa,EAAE,SAAiB;IAChE,OAAO,CACL,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC;QACtB,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC;QACtB,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK;QACtD,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CACzD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,WAAmB,EACnB,MAA6B,EAC7B,QAAuB,EACvB,SAAmB;IAEnB,IAAI,aAAa,GAAuB,IAAI,CAAC;IAC7C,IAAI,YAAY,GAAG,QAAQ,CAAC;IAE5B,KAAK,MAAM,SAAS,IAAI,MAAM,EAAE,CAAC;QAC/B,IAAI,SAAS,CAAC,EAAE,KAAK,SAAS;YAAE,SAAS;QAEzC,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACpD,SAAS;QACX,CAAC;QAED,MAAM,eAAe,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACvD,IAAI,iBAAiB,CAAC,WAAW,EAAE,eAAe,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC;YAC5D,IAAI,IAAI,GAAG,YA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oBAC1B,IAAI,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE;iBACjD,CAAC,CAAC;gBACH,IAAI,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC,CAAC;YAC9E,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,WAAW,CAAC,OAAgB,EAAE,KAAkB;QAC9C,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,CAAC,KAAK;YAAE,OAAO;QACnB,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAuB,CAAC;QACxF,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ;YAAE,OAAO;QAEtD,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE;YACzB,IAAI,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE;SACjD,CAAC,CAAC;QACH,IAAI,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Point, ShapeId } from '@open-draw/schema';
|
|
2
|
+
export interface TargetUnboundEvent {
|
|
3
|
+
readonly arrowId: ShapeId;
|
|
4
|
+
readonly which: 'start' | 'end';
|
|
5
|
+
readonly previousTargetId: ShapeId;
|
|
6
|
+
readonly fallbackPoint: Point;
|
|
7
|
+
}
|
|
8
|
+
export type UnbindListener = (event: TargetUnboundEvent) => void;
|
|
9
|
+
//# sourceMappingURL=defs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/capabilities/connector/defs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAExD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAAC;IAChC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC;CAC/B;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defs.js","sourceRoot":"","sources":["../../../src/capabilities/connector/defs.ts"],"names":[],"mappings":""}
|