@nightshadeui/canvas 2.22.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CanvasController.d.ts +3 -1
- package/dist/CanvasController.d.ts.map +1 -1
- package/dist/canvas.css +1 -1
- package/dist/canvas.mjs +825 -823
- package/package.json +4 -3
- package/src/CanvasBoxSelect.ts +129 -0
- package/src/CanvasConfig.ts +24 -0
- package/src/CanvasController.ts +74 -0
- package/src/CanvasEvents.ts +14 -0
- package/src/CanvasMove.ts +62 -0
- package/src/CanvasObjectController.ts +368 -0
- package/src/CanvasObjectRegistry.ts +23 -0
- package/src/CanvasPan.ts +49 -0
- package/src/CanvasSelection.ts +104 -0
- package/src/CanvasSpace.ts +69 -0
- package/src/CanvasViewport.ts +166 -0
- package/src/CanvasZoom.ts +59 -0
- package/src/components/CanvasBoxSelect.vue +44 -0
- package/src/components/CanvasDebugCoords.vue +85 -0
- package/src/components/CanvasObject.vue +142 -0
- package/src/components/CanvasObjectResize.vue +95 -0
- package/src/components/CanvasView.vue +104 -0
- package/src/index.ts +24 -0
- package/src/types.ts +3 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
ref="rootEl"
|
|
4
|
+
class="CanvasObject"
|
|
5
|
+
:style="canvasObject.getStyle()"
|
|
6
|
+
@uiclick.stop.prevent="canvasObject.onUiClick"
|
|
7
|
+
@uidragstart.stop.prevent="canvasObject.onUiDragStart"
|
|
8
|
+
@uidragmove.stop.prevent="canvasObject.onUiDragMove"
|
|
9
|
+
@uidragend.stop.prevent="canvasObject.onUiDragEnd">
|
|
10
|
+
<slot v-bind="slotProps" />
|
|
11
|
+
<CanvasObjectResize
|
|
12
|
+
v-for="direction in resizeDirections"
|
|
13
|
+
:key="direction"
|
|
14
|
+
:canvasObject="canvasObject"
|
|
15
|
+
:direction="direction" />
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script>
|
|
20
|
+
import CanvasObjectResize from './CanvasObjectResize.vue';
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
|
|
24
|
+
components: {
|
|
25
|
+
CanvasObjectResize,
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
props: {
|
|
29
|
+
canvas: { type: Object, required: true },
|
|
30
|
+
objectId: { type: String, required: true },
|
|
31
|
+
pos: { type: Object, required: true },
|
|
32
|
+
isSelected: { type: Boolean, default: false },
|
|
33
|
+
selectable: { type: Boolean, default: true },
|
|
34
|
+
movable: { type: Boolean, default: true },
|
|
35
|
+
snapToGrid: { type: Boolean, default: true },
|
|
36
|
+
resizable: { type: String, default: 'none' },
|
|
37
|
+
bounds: { type: Array },
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
emits: [
|
|
41
|
+
'update:pos',
|
|
42
|
+
'update:isSelected',
|
|
43
|
+
],
|
|
44
|
+
|
|
45
|
+
data() {
|
|
46
|
+
return {
|
|
47
|
+
canvasObject: null,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
computed: {
|
|
52
|
+
|
|
53
|
+
coords() {
|
|
54
|
+
return this.canvasObject.getCanvasCoords();
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
slotProps() {
|
|
58
|
+
return {
|
|
59
|
+
canvas: this.canvas,
|
|
60
|
+
objectId: this.objectId,
|
|
61
|
+
isSelected: this.canvas.selection.isSelected(this.objectId),
|
|
62
|
+
coords: this.coords,
|
|
63
|
+
pos: this.pos,
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
resizeDirections() {
|
|
68
|
+
return this.canvasObject.getResizeDirections();
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
watch: {
|
|
74
|
+
|
|
75
|
+
pos(newPos) {
|
|
76
|
+
this.canvasObject.setPos(newPos);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
isSelected(newSelected) {
|
|
80
|
+
this.canvasObject.setSelected(newSelected);
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
selectable(newSelectable) {
|
|
84
|
+
this.canvasObject.setSelectable(newSelectable);
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
movable(newMovable) {
|
|
88
|
+
this.canvasObject.setMovable(newMovable);
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
snapToGrid(newSnapToGrid) {
|
|
92
|
+
this.canvasObject.setSnapToGrid(newSnapToGrid);
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
resizable(newResizable) {
|
|
96
|
+
this.canvasObject.setResizable(newResizable);
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
bounds(newBounds) {
|
|
100
|
+
this.canvasObject.setBounds(newBounds);
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
created() {
|
|
106
|
+
this.canvasObject = this.canvas.createObjectController(this.objectId);
|
|
107
|
+
this.canvas.events.objectPosUpdated.on(({ objectId, pos }) => {
|
|
108
|
+
if (objectId === this.objectId) {
|
|
109
|
+
this.$emit('update:pos', pos);
|
|
110
|
+
}
|
|
111
|
+
}, this);
|
|
112
|
+
this.canvas.events.selectionChanged.on(selectedIds => {
|
|
113
|
+
const isSelected = selectedIds.includes(this.objectId);
|
|
114
|
+
if (this.isSelected !== isSelected) {
|
|
115
|
+
this.$emit('update:isSelected', isSelected);
|
|
116
|
+
}
|
|
117
|
+
}, this);
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
mounted() {
|
|
121
|
+
const ctl = this.canvasObject;
|
|
122
|
+
this.canvas.objectRegistry.register(ctl);
|
|
123
|
+
ctl.setElement(this.$refs.rootEl);
|
|
124
|
+
ctl.setPos(this.pos);
|
|
125
|
+
ctl.setSelectable(this.selectable);
|
|
126
|
+
ctl.setMovable(this.movable);
|
|
127
|
+
ctl.setSnapToGrid(this.snapToGrid);
|
|
128
|
+
ctl.setResizable(this.resizable);
|
|
129
|
+
ctl.setBounds(this.bounds);
|
|
130
|
+
ctl.setSelected(this.isSelected);
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
unmounted() {
|
|
134
|
+
this.canvas.objectRegistry.unregister(this.objectId);
|
|
135
|
+
this.canvasObject.setElement(null);
|
|
136
|
+
this.canvas.selection.removeFromSelection(this.objectId);
|
|
137
|
+
this.canvas.events.objectPosUpdated.removeAll(this);
|
|
138
|
+
this.canvas.events.selectionChanged.removeAll(this);
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
};
|
|
142
|
+
</script>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:class="['ResizeHandle', `ResizeHandle-${direction}`]"
|
|
4
|
+
@uidragstart.stop.prevent="canvasObject.startResizing(direction)"
|
|
5
|
+
@uidragmove.stop.prevent="canvasObject.onResizeMove"
|
|
6
|
+
@uidragend.stop.prevent="canvasObject.onResizeEnd" />
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
export default {
|
|
11
|
+
|
|
12
|
+
props: {
|
|
13
|
+
canvasObject: { type: Object, required: true },
|
|
14
|
+
direction: { type: String, required: true },
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
};
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<style scoped>
|
|
21
|
+
.ResizeHandle {
|
|
22
|
+
--CanvasObjectResize-handle-size: var(--sp2);
|
|
23
|
+
--CanvasObjectResize-handle-offset: calc(-.5 * var(--CanvasObjectResize-handle-size));
|
|
24
|
+
position: absolute;
|
|
25
|
+
z-index: 3;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.ResizeHandle-n {
|
|
29
|
+
top: var(--CanvasObjectResize-handle-offset);
|
|
30
|
+
left: var(--CanvasObjectResize-handle-offset);
|
|
31
|
+
right: var(--CanvasObjectResize-handle-offset);
|
|
32
|
+
height: var(--CanvasObjectResize-handle-size);
|
|
33
|
+
cursor: ns-resize;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.ResizeHandle-ne {
|
|
37
|
+
top: var(--CanvasObjectResize-handle-offset);
|
|
38
|
+
right: var(--CanvasObjectResize-handle-offset);
|
|
39
|
+
width: var(--CanvasObjectResize-handle-size);
|
|
40
|
+
height: var(--CanvasObjectResize-handle-size);
|
|
41
|
+
cursor: nesw-resize;
|
|
42
|
+
z-index: 4;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.ResizeHandle-e {
|
|
46
|
+
top: var(--CanvasObjectResize-handle-offset);
|
|
47
|
+
bottom: var(--CanvasObjectResize-handle-offset);
|
|
48
|
+
right: var(--CanvasObjectResize-handle-offset);
|
|
49
|
+
width: var(--CanvasObjectResize-handle-size);
|
|
50
|
+
cursor: ew-resize;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.ResizeHandle-se {
|
|
54
|
+
bottom: var(--CanvasObjectResize-handle-offset);
|
|
55
|
+
right: var(--CanvasObjectResize-handle-offset);
|
|
56
|
+
width: var(--CanvasObjectResize-handle-size);
|
|
57
|
+
height: var(--CanvasObjectResize-handle-size);
|
|
58
|
+
cursor: nwse-resize;
|
|
59
|
+
z-index: 4;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.ResizeHandle-s {
|
|
63
|
+
bottom: var(--CanvasObjectResize-handle-offset);
|
|
64
|
+
left: var(--CanvasObjectResize-handle-offset);
|
|
65
|
+
right: var(--CanvasObjectResize-handle-offset);
|
|
66
|
+
height: var(--CanvasObjectResize-handle-size);
|
|
67
|
+
cursor: ns-resize;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.ResizeHandle-sw {
|
|
71
|
+
bottom: var(--CanvasObjectResize-handle-offset);
|
|
72
|
+
left: var(--CanvasObjectResize-handle-offset);
|
|
73
|
+
width: var(--CanvasObjectResize-handle-size);
|
|
74
|
+
height: var(--CanvasObjectResize-handle-size);
|
|
75
|
+
cursor: nesw-resize;
|
|
76
|
+
z-index: 4;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.ResizeHandle-w {
|
|
80
|
+
top: var(--CanvasObjectResize-handle-offset);
|
|
81
|
+
bottom: var(--CanvasObjectResize-handle-offset);
|
|
82
|
+
left: var(--CanvasObjectResize-handle-offset);
|
|
83
|
+
width: var(--CanvasObjectResize-handle-size);
|
|
84
|
+
cursor: ew-resize;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.ResizeHandle-nw {
|
|
88
|
+
top: var(--CanvasObjectResize-handle-offset);
|
|
89
|
+
left: var(--CanvasObjectResize-handle-offset);
|
|
90
|
+
width: var(--CanvasObjectResize-handle-size);
|
|
91
|
+
height: var(--CanvasObjectResize-handle-size);
|
|
92
|
+
cursor: nwse-resize;
|
|
93
|
+
z-index: 4;
|
|
94
|
+
}
|
|
95
|
+
</style>
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="CanvasView">
|
|
3
|
+
<div
|
|
4
|
+
ref="viewport"
|
|
5
|
+
class="Viewport"
|
|
6
|
+
@mousedown="canvas.pan.onMouseDown"
|
|
7
|
+
@uidragstart="canvas.boxSelect.onUiDragStart"
|
|
8
|
+
@uidragmove="canvas.boxSelect.onUiDragMove"
|
|
9
|
+
@uidragend="canvas.boxSelect.onUiDragEnd"
|
|
10
|
+
@uiclick="onCanvasUiClick"
|
|
11
|
+
@scroll="canvas.viewport.onScroll"
|
|
12
|
+
@wheel="canvas.zoom.onWheel">
|
|
13
|
+
<div
|
|
14
|
+
class="Sizer"
|
|
15
|
+
:style="canvas.viewport.getSizerStyle()" />
|
|
16
|
+
<div
|
|
17
|
+
class="Canvas"
|
|
18
|
+
:style="canvas.viewport.getCanvasStyle()">
|
|
19
|
+
<slot />
|
|
20
|
+
<div
|
|
21
|
+
class="Origin"
|
|
22
|
+
:style="canvas.viewport.getOriginStyle()">
|
|
23
|
+
<slot name="origin" />
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
<CanvasBoxSelect :canvas="canvas" />
|
|
27
|
+
</div>
|
|
28
|
+
<slot name="overlays" />
|
|
29
|
+
</div>
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script>
|
|
33
|
+
import CanvasBoxSelect from './CanvasBoxSelect.vue';
|
|
34
|
+
|
|
35
|
+
export default {
|
|
36
|
+
|
|
37
|
+
components: {
|
|
38
|
+
CanvasBoxSelect,
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
props: {
|
|
42
|
+
canvas: { type: Object, required: true },
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
mounted() {
|
|
46
|
+
this.canvas.mount(this.$refs.viewport);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
unmounted() {
|
|
50
|
+
this.canvas.unmount();
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
methods: {
|
|
54
|
+
|
|
55
|
+
onCanvasUiClick() {
|
|
56
|
+
this.canvas.selection.deselectAll();
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
};
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<style scoped>
|
|
65
|
+
.CanvasView {
|
|
66
|
+
--CanvasView-background: var(--surface-base);
|
|
67
|
+
--CanvasView-margin-cells: 64;
|
|
68
|
+
--CanvasView-grid-cell-size: 32px;
|
|
69
|
+
--CanvasView-grid-subdivisions: 4;
|
|
70
|
+
--CanvasView-grid-major-fill: var(--border-deep);
|
|
71
|
+
--CanvasView-grid-major-radius: 2px;
|
|
72
|
+
--CanvasView-grid-minor-fill: var(--border-base);
|
|
73
|
+
--CanvasView-grid-minor-radius: 1px;
|
|
74
|
+
|
|
75
|
+
position: relative;
|
|
76
|
+
display: flex;
|
|
77
|
+
user-select: none;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.Viewport {
|
|
81
|
+
position: relative;
|
|
82
|
+
z-index: 1;
|
|
83
|
+
flex: 1;
|
|
84
|
+
overflow: auto;
|
|
85
|
+
cursor: crosshair;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.Sizer {
|
|
89
|
+
position: relative;
|
|
90
|
+
z-index: 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.Canvas {
|
|
94
|
+
position: absolute;
|
|
95
|
+
top: 0;
|
|
96
|
+
left: 0;
|
|
97
|
+
overflow: hidden;
|
|
98
|
+
background: var(--CanvasView-background);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.Origin {
|
|
102
|
+
position: absolute;
|
|
103
|
+
}
|
|
104
|
+
</style>
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import CanvasBoxSelect from './components/CanvasBoxSelect.vue';
|
|
2
|
+
import CanvasDebugCoords from './components/CanvasDebugCoords.vue';
|
|
3
|
+
import CanvasObject from './components/CanvasObject.vue';
|
|
4
|
+
import CanvasView from './components/CanvasView.vue';
|
|
5
|
+
|
|
6
|
+
export * from './CanvasBoxSelect.js';
|
|
7
|
+
export * from './CanvasConfig.js';
|
|
8
|
+
export * from './CanvasController.js';
|
|
9
|
+
export * from './CanvasEvents.js';
|
|
10
|
+
export * from './CanvasObjectController.js';
|
|
11
|
+
export * from './CanvasObjectRegistry.js';
|
|
12
|
+
export * from './CanvasPan.js';
|
|
13
|
+
export * from './CanvasSelection.js';
|
|
14
|
+
export * from './CanvasSpace.js';
|
|
15
|
+
export * from './CanvasViewport.js';
|
|
16
|
+
export * from './CanvasZoom.js';
|
|
17
|
+
export { InputStateManager } from '@nightshadeui/util';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
CanvasBoxSelect,
|
|
21
|
+
CanvasDebugCoords,
|
|
22
|
+
CanvasObject,
|
|
23
|
+
CanvasView,
|
|
24
|
+
};
|
package/src/types.ts
ADDED