@m3ui-vue/m3ui-vue 1.3.5 → 1.3.7
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/API.md +76 -16
- package/dist/{MButton-Bl_BSUep.js → MButton-D5eJiDza.js} +2 -2
- package/dist/{MButton-Bl_BSUep.js.map → MButton-D5eJiDza.js.map} +1 -1
- package/dist/{MDialog-D_Yik8ou.js → MDialog-WqB0jewp.js} +2 -2
- package/dist/{MDialog-D_Yik8ou.js.map → MDialog-WqB0jewp.js.map} +1 -1
- package/dist/{MListItem-BxifHJdU.js → MListItem-Cf-C2Ru-.js} +2 -2
- package/dist/{MListItem-BxifHJdU.js.map → MListItem-Cf-C2Ru-.js.map} +1 -1
- package/dist/{MLoadingIndicator-BxbFhSX6.js → MLoadingIndicator-D4GzEZoH.js} +2 -2
- package/dist/{MLoadingIndicator-BxbFhSX6.js.map → MLoadingIndicator-D4GzEZoH.js.map} +1 -1
- package/dist/{MSeekBar-BeN9QcB3.js → MSeekBar-B19xoWE3.js} +2 -2
- package/dist/{MSeekBar-BeN9QcB3.js.map → MSeekBar-B19xoWE3.js.map} +1 -1
- package/dist/{MSlider-BVSbJlGS.js → MSlider-9RoiuebS.js} +2 -2
- package/dist/{MSlider-BVSbJlGS.js.map → MSlider-9RoiuebS.js.map} +1 -1
- package/dist/{MSpinner-C2SUnWk4.js → MSpinner-BNF8MN-L.js} +2 -2
- package/dist/{MSpinner-C2SUnWk4.js.map → MSpinner-BNF8MN-L.js.map} +1 -1
- package/dist/{MTextField-CEkWSZ2v.js → MTextField-CuG0T3qh.js} +2 -2
- package/dist/{MTextField-CEkWSZ2v.js.map → MTextField-CuG0T3qh.js.map} +1 -1
- package/dist/{MTooltip-CodJGEO-.js → MTooltip-Bv7yxngk.js} +4 -4
- package/dist/{MTooltip-CodJGEO-.js.map → MTooltip-Bv7yxngk.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MFloorPlan.vue.d.ts +192 -14
- package/dist/components/MFloorPlanInspector.vue.d.ts +12 -12
- package/dist/components/MMap.vue.d.ts +2 -2
- package/dist/components/MPdfViewer.vue.d.ts +2 -2
- package/dist/composables/useFloorPlan.d.ts +10 -3
- package/dist/composables/useLocale.d.ts +9 -0
- package/dist/draw.js +2 -2
- package/dist/flow.js +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/locales/index.js +56 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +3076 -1955
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +5 -5
- package/dist/media.js +4 -4
- package/dist/pdf.js +4 -4
- package/dist/rich-text-editor.js +4 -4
- package/dist/styles.css +1 -1
- package/dist/{useLocale-CaWwi-b6.js → useLocale-D2ucaY-l.js} +9 -1
- package/dist/useLocale-D2ucaY-l.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MFloorPlan.test.ts +423 -0
- package/src/components/MFloorPlan.vue +1337 -101
- package/src/components/MFloorPlanInspector.vue +21 -6
- package/src/components/MFloorPlanToolbar.vue +4 -3
- package/src/composables/useFloorPlan.ts +7 -3
- package/src/composables/useLocale.ts +17 -0
- package/src/index.ts +1 -1
- package/src/locales/de.ts +8 -0
- package/src/locales/es.ts +8 -0
- package/src/locales/fr.ts +8 -0
- package/src/locales/ja.ts +8 -0
- package/src/locales/ko.ts +8 -0
- package/src/locales/pt.ts +8 -0
- package/src/locales/zh.ts +8 -0
- package/dist/useLocale-CaWwi-b6.js.map +0 -1
|
@@ -16,6 +16,8 @@ export interface FloorTable {
|
|
|
16
16
|
status?: string
|
|
17
17
|
/** A small badge: minutes seated, the total, a count… */
|
|
18
18
|
badge?: string | number
|
|
19
|
+
/** Seats taken (numbered from 1, clockwise from the top-left), drawn in the status color */
|
|
20
|
+
activeSeats?: number[]
|
|
19
21
|
data?: Record<string, unknown>
|
|
20
22
|
}
|
|
21
23
|
/** Tables joined together (drawn as one group) */
|
|
@@ -34,6 +36,11 @@ export interface FloorArea {
|
|
|
34
36
|
height: number
|
|
35
37
|
/** An M3 color role or any CSS color */
|
|
36
38
|
color?: string
|
|
39
|
+
/**
|
|
40
|
+
* A zone of any shape (an L-shaped room): its corners. x / y / width / height are then the box around them, kept up
|
|
41
|
+
* to date. Double-click a rectangular zone's edge to give it corners
|
|
42
|
+
*/
|
|
43
|
+
points?: [number, number][]
|
|
37
44
|
}
|
|
38
45
|
/** A wall: a line through its points */
|
|
39
46
|
export interface FloorWall {
|
|
@@ -51,6 +58,8 @@ export interface FloorDecor {
|
|
|
51
58
|
width?: number
|
|
52
59
|
height?: number
|
|
53
60
|
rotation?: number
|
|
61
|
+
/** Mirrored across its length: a door hinged on the other side */
|
|
62
|
+
flip?: boolean
|
|
54
63
|
/** The text of a label (or a caption under the others) */
|
|
55
64
|
label?: string
|
|
56
65
|
}
|
|
@@ -62,12 +71,22 @@ export interface FloorDecorKind {
|
|
|
62
71
|
icon?: string
|
|
63
72
|
width: number
|
|
64
73
|
height: number
|
|
65
|
-
/**
|
|
66
|
-
|
|
74
|
+
/**
|
|
75
|
+
* `box` a rounded rectangle, `round` a circle, `bar` a thin slab, `door` an opening with its leaf and swing (as on an
|
|
76
|
+
* architect's plan), `window` a framed pane, `text` the item's label only. A door or window cuts the wall it sits on
|
|
77
|
+
*/
|
|
78
|
+
shape?: 'box' | 'round' | 'bar' | 'door' | 'window' | 'text'
|
|
67
79
|
/** Fill: an M3 color role (`surface`, `primary`…) or any CSS color */
|
|
68
80
|
color?: string
|
|
69
81
|
}
|
|
70
|
-
/**
|
|
82
|
+
/** Real lengths for the plan: `per` plan units make one `unit` (100 and 'm': a plan unit is a centimeter) */
|
|
83
|
+
export interface FloorMeasure {
|
|
84
|
+
unit: string
|
|
85
|
+
per: number
|
|
86
|
+
/** Decimals shown (default 2) */
|
|
87
|
+
decimals?: number
|
|
88
|
+
}
|
|
89
|
+
/** What's picked on the plan besides tables: a zone, a wall (and one of its corners, as a zone of any shape) or a decor item */
|
|
71
90
|
export type FloorPick = { kind: 'area' | 'wall' | 'decor'; id: string | number; vertex?: number } | null
|
|
72
91
|
/** How a status looks: an M3 color role ('primary', 'tertiary', 'error'…) or any CSS color, an icon, a name */
|
|
73
92
|
export interface FloorStatus {
|
|
@@ -94,7 +113,7 @@ export interface FloorStatus {
|
|
|
94
113
|
* @event table-click A table was clicked or opened with Enter (not after a drag)
|
|
95
114
|
* @event move Tables moved by a drag or the arrows, with their new positions (`{ id, x, y }[]`), to save them
|
|
96
115
|
*/
|
|
97
|
-
import { computed, onBeforeUnmount, onMounted, provide, ref, shallowRef } from 'vue'
|
|
116
|
+
import { computed, onBeforeUnmount, onMounted, provide, ref, shallowRef, watch } from 'vue'
|
|
98
117
|
import { useLocale } from '../composables/useLocale'
|
|
99
118
|
import { FLOOR_PLAN_KEY, type FloorItemKind, type FloorPlanContext } from '../composables/useFloorPlan'
|
|
100
119
|
import MIcon from './MIcon.vue'
|
|
@@ -116,12 +135,58 @@ const props = withDefaults(defineProps<{
|
|
|
116
135
|
* the squares between the points while walls, zones and decor snap to the points (a plan of cells)
|
|
117
136
|
*/
|
|
118
137
|
tableSnap?: 'point' | 'cell'
|
|
138
|
+
/**
|
|
139
|
+
* Snapping steps per grid square for walls, zones and decor: 2 puts them on the points and halfway between them
|
|
140
|
+
* (tables keep to the grid). Drawn as smaller dots
|
|
141
|
+
*/
|
|
142
|
+
subgrid?: number
|
|
119
143
|
/** Draw chairs from `seats` */
|
|
120
144
|
chairs?: boolean
|
|
145
|
+
/**
|
|
146
|
+
* Real lengths: while editing, the picked wall's or zone's sides, the wall being drawn, and the picked table's or
|
|
147
|
+
* decor's size are labeled in your unit (the inspector's sizes too)
|
|
148
|
+
*/
|
|
149
|
+
measure?: FloorMeasure
|
|
150
|
+
/** Number the chairs (1 from the top-left, clockwise); in service a click on one emits `seat-click` */
|
|
151
|
+
seatNumbers?: boolean
|
|
121
152
|
/** Decor kinds of yours, or the built-in ones restyled (merged over them by name) */
|
|
122
153
|
decorKinds?: Record<string, FloorDecorKind>
|
|
123
|
-
/**
|
|
124
|
-
rotatable?: boolean
|
|
154
|
+
/** What the turning handle turns: everything (`true`), nothing, or only these kinds (`['decor']` when your app keeps no tables' angles) */
|
|
155
|
+
rotatable?: boolean | ('table' | 'decor')[]
|
|
156
|
+
/**
|
|
157
|
+
* Tables placed by cell: their `x` / `y` are a column and a row (whole numbers from 0), each cell this many plan
|
|
158
|
+
* units wide. A table's middle sits in the middle of its cell and steps a cell at a time, and every table you get
|
|
159
|
+
* back (`update:tables`, `move`, events, slots) is in columns and rows. Zones, walls and decor stay in plan units
|
|
160
|
+
*/
|
|
161
|
+
cellSize?: number
|
|
162
|
+
/**
|
|
163
|
+
* Zoom and pan: Ctrl + wheel or a pinch zooms (from the plan's own size up to `maxZoom`), the wheel, two fingers,
|
|
164
|
+
* a middle-button drag or (outside editing, or with a finger) a drag on empty floor pans, with + / − / fit buttons
|
|
165
|
+
*/
|
|
166
|
+
zoomable?: boolean
|
|
167
|
+
maxZoom?: number
|
|
168
|
+
/** The zoom buttons, when zoomable */
|
|
169
|
+
zoomControls?: boolean
|
|
170
|
+
/** An image under everything (a scanned floor plan to trace over), placed in plan units (default: the whole plan) */
|
|
171
|
+
backgroundImage?: string
|
|
172
|
+
backgroundBox?: { x: number; y: number; width: number; height: number }
|
|
173
|
+
/** Its opacity */
|
|
174
|
+
backgroundOpacity?: number
|
|
175
|
+
/** Which point of a table `x` / `y` name: its middle (default) or its top-left corner (unturned), as your data keeps it */
|
|
176
|
+
tableOrigin?: 'center' | 'corner'
|
|
177
|
+
/**
|
|
178
|
+
* Tables that overlap while editing: `warn` outlines them (default), `prevent` also undoes a move or a resize that
|
|
179
|
+
* would make one overlap another, `allow` says nothing
|
|
180
|
+
*/
|
|
181
|
+
overlap?: 'allow' | 'warn' | 'prevent'
|
|
182
|
+
/**
|
|
183
|
+
* How a resize handle steps (tables and decor): `grid` whole grid squares, `subgrid` the snapping step of walls
|
|
184
|
+
* and zones (`subgrid`), `free` not at all. The change steps, not the size: a table drawn a little smaller than its
|
|
185
|
+
* square keeps that margin and grows by whole squares
|
|
186
|
+
*/
|
|
187
|
+
resizeSnap?: 'grid' | 'subgrid' | 'free'
|
|
188
|
+
/** The handle that resizes the selected table (off when your tables keep one size) */
|
|
189
|
+
resizable?: boolean
|
|
125
190
|
/** Dragging (or nudging) a merged table moves its whole merge with it */
|
|
126
191
|
dragMerged?: boolean
|
|
127
192
|
/**
|
|
@@ -130,6 +195,13 @@ const props = withDefaults(defineProps<{
|
|
|
130
195
|
* on its own (to bring the ones being merged together)
|
|
131
196
|
*/
|
|
132
197
|
selectable?: 'none' | 'single' | 'multiple'
|
|
198
|
+
/**
|
|
199
|
+
* In service, a table carried onto another one emits `transfer` (to move its party, its bill): a mouse drags it, a
|
|
200
|
+
* finger holds it down first. The table itself doesn't move
|
|
201
|
+
*/
|
|
202
|
+
transferable?: boolean
|
|
203
|
+
/** Whether a table's party may go to another table: `true`, or `false` / a reason (`transfer-refused` carries it) */
|
|
204
|
+
canTransfer?: (from: FloorTable, to: FloorTable) => boolean | string
|
|
133
205
|
/** Whether these tables may be merged: `true`, or `false` / a reason to refuse (shown by `merge-refused`) */
|
|
134
206
|
canMerge?: (ids: (string | number)[]) => boolean | string
|
|
135
207
|
/** Accessible name */
|
|
@@ -147,19 +219,69 @@ const props = withDefaults(defineProps<{
|
|
|
147
219
|
grid: 10,
|
|
148
220
|
showGrid: true,
|
|
149
221
|
tableSnap: 'point',
|
|
222
|
+
subgrid: 1,
|
|
150
223
|
chairs: true,
|
|
151
224
|
selectable: 'none',
|
|
152
225
|
dragMerged: false,
|
|
153
226
|
rotatable: true,
|
|
227
|
+
resizable: true,
|
|
228
|
+
resizeSnap: 'free',
|
|
229
|
+
overlap: 'warn',
|
|
230
|
+
tableOrigin: 'center',
|
|
231
|
+
zoomable: false,
|
|
232
|
+
maxZoom: 4,
|
|
233
|
+
zoomControls: true,
|
|
234
|
+
backgroundOpacity: 0.5,
|
|
154
235
|
})
|
|
155
|
-
|
|
236
|
+
/** The tables as you keep them: plan units, or cells (`cellSize`), by their middle or corner (`tableOrigin`) */
|
|
237
|
+
const outerTables = defineModel<FloorTable[]>('tables', { default: () => [] })
|
|
238
|
+
// Inside, a table's x / y are always its middle in plan units; these convert at the edge
|
|
239
|
+
/**
|
|
240
|
+
* With `cellSize`, how far a table's middle sits from its cell's top-left corner along one axis: the middle of the
|
|
241
|
+
* cell for a table no bigger than it, else half its own size (a 2-cell table covers its cell and the next one)
|
|
242
|
+
*/
|
|
243
|
+
const cellReach = (size: number) => Math.max(size, props.cellSize!) / 2
|
|
244
|
+
function toInner(t: FloorTable): FloorTable {
|
|
245
|
+
const c = props.cellSize
|
|
246
|
+
if (c) {
|
|
247
|
+
const s = sizeOf(t)
|
|
248
|
+
return { ...t, x: t.x * c + cellReach(s.w), y: t.y * c + cellReach(s.h) }
|
|
249
|
+
}
|
|
250
|
+
if (props.tableOrigin !== 'corner') return t
|
|
251
|
+
const s = sizeOf(t)
|
|
252
|
+
return { ...t, x: t.x + s.w / 2, y: t.y + s.h / 2 }
|
|
253
|
+
}
|
|
254
|
+
function toOuterXY(t: FloorTable, x: number, y: number) {
|
|
255
|
+
const c = props.cellSize
|
|
256
|
+
if (c) {
|
|
257
|
+
const s = sizeOf(t)
|
|
258
|
+
const cell = (v: number, span: number, size: number) => Math.min(Math.max(Math.round((v - cellReach(span)) / c), 0), Math.max(0, Math.floor(size / c) - 1))
|
|
259
|
+
return { x: cell(x, s.w, props.width), y: cell(y, s.h, props.height) }
|
|
260
|
+
}
|
|
261
|
+
if (props.tableOrigin !== 'corner') return { x, y }
|
|
262
|
+
const s = sizeOf(t)
|
|
263
|
+
return { x: x - s.w / 2, y: y - s.h / 2 }
|
|
264
|
+
}
|
|
265
|
+
const toOuter = (t: FloorTable): FloorTable => ({ ...t, ...toOuterXY(t, t.x, t.y) })
|
|
266
|
+
const passThrough = () => !props.cellSize && props.tableOrigin !== 'corner'
|
|
267
|
+
const tables = computed<FloorTable[]>({
|
|
268
|
+
get: () => (passThrough() ? outerTables.value : outerTables.value.map(toInner)),
|
|
269
|
+
set: (list) => (outerTables.value = passThrough() ? list : list.map(toOuter)),
|
|
270
|
+
})
|
|
271
|
+
/** A table as you keep it, by id (what events and slots hand back) */
|
|
272
|
+
const outerById = computed(() => new Map(outerTables.value.map((t) => [t.id, t])))
|
|
273
|
+
const outerOf = (t: FloorTable) => outerById.value.get(t.id) ?? toOuter(t)
|
|
156
274
|
const merges = defineModel<FloorMerge[]>('merges', { default: () => [] })
|
|
157
275
|
const selection = defineModel<(string | number)[]>('selection', { default: () => [] })
|
|
158
276
|
const areas = defineModel<FloorArea[]>('areas', { default: () => [] })
|
|
159
277
|
const walls = defineModel<FloorWall[]>('walls', { default: () => [] })
|
|
160
278
|
const decor = defineModel<FloorDecor[]>('decor', { default: () => [] })
|
|
161
|
-
/**
|
|
162
|
-
|
|
279
|
+
/**
|
|
280
|
+
* While editing: `select` moves things, `wall` draws a wall (click each corner, double-click or Enter to end), `area`
|
|
281
|
+
* drags out a rectangular zone, `polygon` draws a zone of any shape corner by corner (click the first corner, double-click
|
|
282
|
+
* or Enter to close it)
|
|
283
|
+
*/
|
|
284
|
+
const tool = defineModel<'select' | 'wall' | 'area' | 'polygon'>('tool', { default: 'select' })
|
|
163
285
|
/** While editing: the zone, wall (and corner) or decor item picked, for an inspector of your own */
|
|
164
286
|
const picked = defineModel<FloorPick>('picked', { default: null })
|
|
165
287
|
// ── History: every edit the plan makes is a step Ctrl+Z takes back ──
|
|
@@ -181,6 +303,13 @@ function restore(sn: Snap) {
|
|
|
181
303
|
if (sn.merges !== now.merges) merges.value = sn.merges
|
|
182
304
|
}
|
|
183
305
|
function undo() {
|
|
306
|
+
// While drawing, the last corner placed goes (the first one, the whole drawing)
|
|
307
|
+
if (drawing.value) {
|
|
308
|
+
const pts = distinct(drawing.value)
|
|
309
|
+
drawing.value = pts.length > 1 ? pts.slice(0, -1) : null
|
|
310
|
+
if (!drawing.value) hover.value = null
|
|
311
|
+
return
|
|
312
|
+
}
|
|
184
313
|
const sn = past.value[past.value.length - 1]
|
|
185
314
|
if (!sn) return
|
|
186
315
|
future.value = [snap0(), ...future.value]
|
|
@@ -198,6 +327,9 @@ const emit = defineEmits<{
|
|
|
198
327
|
merge: [merge: FloorMerge]
|
|
199
328
|
split: [merge: FloorMerge]
|
|
200
329
|
'merge-refused': [ids: (string | number)[], reason: string]
|
|
330
|
+
transfer: [from: FloorTable, to: FloorTable]
|
|
331
|
+
'seat-click': [table: FloorTable, seat: number, event: MouseEvent]
|
|
332
|
+
'transfer-refused': [from: FloorTable, to: FloorTable, reason: string]
|
|
201
333
|
'table-click': [table: FloorTable, event: MouseEvent | KeyboardEvent]
|
|
202
334
|
move: [moved: { id: string | number; x: number; y: number }[]]
|
|
203
335
|
}>()
|
|
@@ -206,14 +338,222 @@ const locale = useLocale()
|
|
|
206
338
|
const root = ref<HTMLElement>()
|
|
207
339
|
/** A finger: bigger handles */
|
|
208
340
|
const coarse = ref(typeof matchMedia !== 'undefined' && matchMedia('(pointer: coarse)').matches)
|
|
209
|
-
|
|
341
|
+
/** Px per plan unit at zoom 1: the plan fits the component's width */
|
|
342
|
+
const base = ref(1)
|
|
343
|
+
/** Zoom (1: the whole plan; up to `maxZoom`), with `zoomable` */
|
|
344
|
+
const zoom = defineModel<number>('zoom', { default: 1 })
|
|
345
|
+
/** Where the zoomed plan sits in the component, px (0 or less: the plan covers the view) */
|
|
346
|
+
const pan = ref({ x: 0, y: 0 })
|
|
347
|
+
const zoomed = computed(() => (props.zoomable ? Math.min(Math.max(zoom.value, 1), props.maxZoom) : 1))
|
|
348
|
+
/** Px per plan unit, zoom included: everything is drawn and measured with it */
|
|
349
|
+
const scale = computed(() => base.value * zoomed.value)
|
|
350
|
+
/**
|
|
351
|
+
* True while the scale changes (zoom, the component resized) and a moment after: tables slide when they move, not
|
|
352
|
+
* when the whole plan grows or shrinks around them (the transition is off in the same render as the new positions)
|
|
353
|
+
*/
|
|
354
|
+
const rescaling = ref(false)
|
|
355
|
+
let rescaleTimer = 0
|
|
356
|
+
watch(scale, () => {
|
|
357
|
+
rescaling.value = true
|
|
358
|
+
clearTimeout(rescaleTimer)
|
|
359
|
+
rescaleTimer = window.setTimeout(() => (rescaling.value = false), 150)
|
|
360
|
+
}, { flush: 'sync' })
|
|
361
|
+
onBeforeUnmount(() => clearTimeout(rescaleTimer))
|
|
210
362
|
let ro: ResizeObserver | null = null
|
|
211
363
|
onMounted(() => {
|
|
212
|
-
ro = new ResizeObserver(() =>
|
|
364
|
+
ro = new ResizeObserver(() => {
|
|
365
|
+
base.value = (root.value?.clientWidth || props.width) / props.width
|
|
366
|
+
pan.value = clampPan(pan.value)
|
|
367
|
+
})
|
|
213
368
|
ro.observe(root.value!)
|
|
214
|
-
|
|
369
|
+
base.value = (root.value!.clientWidth || props.width) / props.width
|
|
370
|
+
root.value!.addEventListener('wheel', onWheel, { passive: false })
|
|
371
|
+
// Added by hand rather than in the template: a Vue listener on the way down would stamp the event, and Vue skips
|
|
372
|
+
// handlers attached the same instant (the tables' own pointerdown, under a frozen test clock)
|
|
373
|
+
root.value!.addEventListener('pointerdown', onFingerDown, { capture: true })
|
|
374
|
+
root.value!.addEventListener('touchmove', onTouchMove, { passive: false })
|
|
375
|
+
})
|
|
376
|
+
onBeforeUnmount(() => {
|
|
377
|
+
ro?.disconnect()
|
|
378
|
+
root.value?.removeEventListener('wheel', onWheel)
|
|
379
|
+
root.value?.removeEventListener('pointerdown', onFingerDown, { capture: true })
|
|
380
|
+
root.value?.removeEventListener('touchmove', onTouchMove)
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
// ── Zoom and pan ────────────────────────────────────────────────────────────────────────────────────────
|
|
384
|
+
const viewSize = () => ({ w: props.width * base.value, h: props.height * base.value })
|
|
385
|
+
/** The pan kept so the zoomed plan always covers the view */
|
|
386
|
+
function clampPan(p: { x: number; y: number }, z = zoomed.value) {
|
|
387
|
+
const { w, h } = viewSize()
|
|
388
|
+
return { x: Math.min(0, Math.max(w - w * z, p.x)), y: Math.min(0, Math.max(h - h * z, p.y)) }
|
|
389
|
+
}
|
|
390
|
+
// The zoom the pan was last worked out for (a v-model change from outside zooms about the middle)
|
|
391
|
+
let panZoom = 1
|
|
392
|
+
/** Zooms to `z`, keeping the plan point under (px, py) (px in the component; default its middle) where it is */
|
|
393
|
+
function zoomTo(z: number, px?: number, py?: number) {
|
|
394
|
+
if (!props.zoomable) return
|
|
395
|
+
const next = Math.min(Math.max(z, 1), props.maxZoom)
|
|
396
|
+
const { w, h } = viewSize()
|
|
397
|
+
// (a pointer without coordinates, as some synthetic events come, zooms about the middle)
|
|
398
|
+
const ax = Number.isFinite(px) ? px! : w / 2
|
|
399
|
+
const ay = Number.isFinite(py) ? py! : h / 2
|
|
400
|
+
const ux = (ax - pan.value.x) / (base.value * panZoom)
|
|
401
|
+
const uy = (ay - pan.value.y) / (base.value * panZoom)
|
|
402
|
+
pan.value = clampPan({ x: ax - ux * base.value * next, y: ay - uy * base.value * next }, next)
|
|
403
|
+
panZoom = next
|
|
404
|
+
zoom.value = next
|
|
405
|
+
}
|
|
406
|
+
watch(zoomed, (z) => {
|
|
407
|
+
if (z !== panZoom) zoomTo(z)
|
|
408
|
+
})
|
|
409
|
+
/** Centers the view on a plan point (in plan units), zooming to `z` if given */
|
|
410
|
+
function centerOn(x: number, y: number, z = zoomed.value) {
|
|
411
|
+
zoomTo(z)
|
|
412
|
+
const { w, h } = viewSize()
|
|
413
|
+
pan.value = clampPan({ x: w / 2 - x * scale.value, y: h / 2 - y * scale.value })
|
|
414
|
+
}
|
|
415
|
+
function onWheel(e: WheelEvent) {
|
|
416
|
+
if (!props.zoomable) return
|
|
417
|
+
const r = root.value!.getBoundingClientRect()
|
|
418
|
+
const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? r.height : 1
|
|
419
|
+
if (e.ctrlKey || e.metaKey) {
|
|
420
|
+
// Ctrl + wheel, and a trackpad's pinch (which comes as one)
|
|
421
|
+
e.preventDefault()
|
|
422
|
+
zoomTo(zoomed.value * Math.exp(-e.deltaY * unit * 0.002), e.clientX - r.left, e.clientY - r.top)
|
|
423
|
+
} else if (zoomed.value > 1) {
|
|
424
|
+
e.preventDefault()
|
|
425
|
+
pan.value = clampPan({ x: pan.value.x - (e.shiftKey ? e.deltaY : e.deltaX) * unit, y: pan.value.y - (e.shiftKey ? 0 : e.deltaY) * unit })
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
/** A drag that pans the view */
|
|
429
|
+
function startPan(e: PointerEvent) {
|
|
430
|
+
e.preventDefault()
|
|
431
|
+
const p0 = { ...pan.value }
|
|
432
|
+
const mv = (ev: PointerEvent) => {
|
|
433
|
+
if (ev.pointerId !== e.pointerId || gesture) return
|
|
434
|
+
pan.value = clampPan({ x: p0.x + ev.clientX - e.clientX, y: p0.y + ev.clientY - e.clientY })
|
|
435
|
+
}
|
|
436
|
+
const up = (ev: PointerEvent) => {
|
|
437
|
+
if (ev.pointerId !== e.pointerId) return
|
|
438
|
+
window.removeEventListener('pointermove', mv)
|
|
439
|
+
window.removeEventListener('pointerup', up)
|
|
440
|
+
window.removeEventListener('pointercancel', up)
|
|
441
|
+
}
|
|
442
|
+
window.addEventListener('pointermove', mv)
|
|
443
|
+
window.addEventListener('pointerup', up)
|
|
444
|
+
window.addEventListener('pointercancel', up)
|
|
445
|
+
}
|
|
446
|
+
// Two fingers pinch and pan, whatever they land on; a drag they interrupt is dropped
|
|
447
|
+
const fingers = new Map<number, { x: number; y: number }>()
|
|
448
|
+
let gesture: { d: number; z: number; mid: { x: number; y: number }; u: { x: number; y: number } } | null = null
|
|
449
|
+
/** Bumped when two fingers take over, so a drag that started with one of them lets go without committing */
|
|
450
|
+
let gestureRun = 0
|
|
451
|
+
function onFingerDown(e: PointerEvent) {
|
|
452
|
+
if (!props.zoomable || e.pointerType !== 'touch') return
|
|
453
|
+
fingers.set(e.pointerId, { x: e.clientX, y: e.clientY })
|
|
454
|
+
if (fingers.size === 1) {
|
|
455
|
+
window.addEventListener('pointermove', onFingerMove)
|
|
456
|
+
window.addEventListener('pointerup', onFingerUp)
|
|
457
|
+
window.addEventListener('pointercancel', onFingerUp)
|
|
458
|
+
}
|
|
459
|
+
if (fingers.size === 2) startGesture()
|
|
460
|
+
}
|
|
461
|
+
function startGesture() {
|
|
462
|
+
const [a, b] = [...fingers.values()]
|
|
463
|
+
const r = root.value!.getBoundingClientRect()
|
|
464
|
+
const mid = { x: (a!.x + b!.x) / 2 - r.left, y: (a!.y + b!.y) / 2 - r.top }
|
|
465
|
+
gesture = { d: Math.hypot(a!.x - b!.x, a!.y - b!.y) || 1, z: zoomed.value, mid, u: { x: (mid.x - pan.value.x) / scale.value, y: (mid.y - pan.value.y) / scale.value } }
|
|
466
|
+
gestureRun++
|
|
467
|
+
// Whatever one finger was dragging goes back
|
|
468
|
+
draft.value = null
|
|
469
|
+
areaDraft.value = null
|
|
470
|
+
decorDraft.value = null
|
|
471
|
+
wallDraft.value = null
|
|
472
|
+
sizeDraft.value = null
|
|
473
|
+
marquee.value = null
|
|
474
|
+
transferDrag.value = null
|
|
475
|
+
}
|
|
476
|
+
function onFingerMove(e: PointerEvent) {
|
|
477
|
+
if (!fingers.has(e.pointerId)) return
|
|
478
|
+
fingers.set(e.pointerId, { x: e.clientX, y: e.clientY })
|
|
479
|
+
if (!gesture || fingers.size < 2) return
|
|
480
|
+
const [a, b] = [...fingers.values()]
|
|
481
|
+
const r = root.value!.getBoundingClientRect()
|
|
482
|
+
const mid = { x: (a!.x + b!.x) / 2 - r.left, y: (a!.y + b!.y) / 2 - r.top }
|
|
483
|
+
const z = Math.min(Math.max(gesture.z * (Math.hypot(a!.x - b!.x, a!.y - b!.y) / gesture.d), 1), props.maxZoom)
|
|
484
|
+
// The plan point first under the fingers' middle stays under it
|
|
485
|
+
pan.value = clampPan({ x: mid.x - gesture.u.x * base.value * z, y: mid.y - gesture.u.y * base.value * z }, z)
|
|
486
|
+
panZoom = z
|
|
487
|
+
zoom.value = z
|
|
488
|
+
}
|
|
489
|
+
function onFingerUp(e: PointerEvent) {
|
|
490
|
+
fingers.delete(e.pointerId)
|
|
491
|
+
if (fingers.size < 2) gesture = null
|
|
492
|
+
if (!fingers.size) {
|
|
493
|
+
window.removeEventListener('pointermove', onFingerMove)
|
|
494
|
+
window.removeEventListener('pointerup', onFingerUp)
|
|
495
|
+
window.removeEventListener('pointercancel', onFingerUp)
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Fingers dragging something on the plan (a corner, a wall, a zone…). Its `touch-action: none` isn't enough: Chrome
|
|
500
|
+
* ignores it on SVG shapes (walls and corners are), so the page scrolled under the finger and the drag was cancelled
|
|
501
|
+
*/
|
|
502
|
+
let holding = 0
|
|
503
|
+
/** While two fingers zoom, a finger drags something, or a table is carried to another one, the page doesn't scroll */
|
|
504
|
+
function onTouchMove(e: TouchEvent) {
|
|
505
|
+
if (holding || gesture || transferDrag.value || (props.zoomable && zoomed.value > 1 && e.touches.length > 1)) e.preventDefault()
|
|
506
|
+
}
|
|
507
|
+
// While drawing (walls, zones), a finger draws: the page doesn't scroll under it
|
|
508
|
+
const touchAction = computed(() => (props.editable && tool.value !== 'select' ? 'none' : !props.zoomable ? undefined : zoomed.value > 1 ? 'none' : 'pan-x pan-y'))
|
|
509
|
+
/**
|
|
510
|
+
* Near the view's edges while something is dragged in, the zoomed plan scrolls (as MFlow's canvas does), so a corner
|
|
511
|
+
* or a table can be taken past what's on screen. `.at(ev)` arms it with where the pointer is; `onPan` runs after each
|
|
512
|
+
* scroll, for the drag to bring what it holds along
|
|
513
|
+
*/
|
|
514
|
+
const EDGE_ZONE = 40
|
|
515
|
+
function edgePan(onPan: () => void) {
|
|
516
|
+
let x = 0
|
|
517
|
+
let y = 0
|
|
518
|
+
let armed = false
|
|
519
|
+
let last = 0
|
|
520
|
+
let raf = 0
|
|
521
|
+
const speed = (p: number, lo: number, hi: number) =>
|
|
522
|
+
p < lo + EDGE_ZONE ? Math.min(1, 1 - (p - lo) / EDGE_ZONE) : p > hi - EDGE_ZONE ? -Math.min(1, 1 - (hi - p) / EDGE_ZONE) : 0
|
|
523
|
+
const tick = () => {
|
|
524
|
+
raf = requestAnimationFrame(tick)
|
|
525
|
+
const t = performance.now()
|
|
526
|
+
const dt = last ? Math.min((t - last) / 1000, 1 / 30) : 1 / 60
|
|
527
|
+
last = t
|
|
528
|
+
if (!armed || !props.zoomable || zoomed.value <= 1 || !root.value) return
|
|
529
|
+
// The part of the plan on screen: a plan taller than the window scrolls at the window's edge
|
|
530
|
+
const r = root.value.getBoundingClientRect()
|
|
531
|
+
const [x1, x2] = [Math.max(r.left, 0), Math.min(r.right, window.innerWidth || r.right)]
|
|
532
|
+
const [y1, y2] = [Math.max(r.top, 0), Math.min(r.bottom, window.innerHeight || r.bottom)]
|
|
533
|
+
if (x2 - x1 < EDGE_ZONE * 3 || y2 - y1 < EDGE_ZONE * 3) return
|
|
534
|
+
const vx = speed(x, x1, x2)
|
|
535
|
+
const vy = speed(y, y1, y2)
|
|
536
|
+
if (!vx && !vy) return
|
|
537
|
+
const next = clampPan({ x: pan.value.x + vx * 600 * dt, y: pan.value.y + vy * 600 * dt })
|
|
538
|
+
if (next.x === pan.value.x && next.y === pan.value.y) return
|
|
539
|
+
pan.value = next
|
|
540
|
+
onPan()
|
|
541
|
+
}
|
|
542
|
+
raf = requestAnimationFrame(tick)
|
|
543
|
+
return {
|
|
544
|
+
at(ev: { clientX: number; clientY: number }) {
|
|
545
|
+
x = ev.clientX
|
|
546
|
+
y = ev.clientY
|
|
547
|
+
armed = true
|
|
548
|
+
},
|
|
549
|
+
stop: () => cancelAnimationFrame(raf),
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
onBeforeUnmount(() => {
|
|
553
|
+
window.removeEventListener('pointermove', onFingerMove)
|
|
554
|
+
window.removeEventListener('pointerup', onFingerUp)
|
|
555
|
+
window.removeEventListener('pointercancel', onFingerUp)
|
|
215
556
|
})
|
|
216
|
-
onBeforeUnmount(() => ro?.disconnect())
|
|
217
557
|
|
|
218
558
|
// ── Geometry ────────────────────────────────────────────────────────────────────────────────────────────
|
|
219
559
|
const CHAIR = 16
|
|
@@ -254,19 +594,30 @@ function chairsOf(t: FloorTable, s: FloorBox): { x: number; y: number; r: number
|
|
|
254
594
|
else if (n > 2 && i >= n - 2 && n % 2 === 0 && n >= 6) per[i === n - 2 ? 2 : 3]!++
|
|
255
595
|
else per[i % 2]!++
|
|
256
596
|
}
|
|
257
|
-
|
|
597
|
+
const list = sides.flatMap((side, k) => Array.from({ length: per[k]! }, (_, i) => side.at((i + 1) / (per[k]! + 1))))
|
|
598
|
+
// Numbered clockwise from the top-left corner, as people count round a table
|
|
599
|
+
const start = Math.atan2(-s.h / 2, -s.w / 2)
|
|
600
|
+
const turn = (c: { x: number; y: number }) => (Math.atan2(c.y, c.x) - start + Math.PI * 4) % (Math.PI * 2)
|
|
601
|
+
return list.sort((a, b) => turn(a) - turn(b))
|
|
258
602
|
}
|
|
259
603
|
|
|
260
604
|
// While a drag moves tables, their positions live here until the drop
|
|
261
605
|
const draft = shallowRef<Map<string | number, { x: number; y: number }> | null>(null)
|
|
606
|
+
/** A table being resized by its handle: its size until the drop */
|
|
607
|
+
const sizeDraft = shallowRef<{ id: string | number; w: number; h: number } | null>(null)
|
|
262
608
|
const placed = computed(() =>
|
|
263
609
|
tables.value.map((t) => {
|
|
264
610
|
const at = draft.value?.get(t.id) ?? { x: t.x, y: t.y }
|
|
265
|
-
const size = sizeOf(t)
|
|
611
|
+
const size = sizeDraft.value?.id === t.id ? { w: sizeDraft.value.w, h: sizeDraft.value.h } : sizeOf(t)
|
|
266
612
|
return { t, x: at.x, y: at.y, size, chairs: chairsOf(t, size), status: t.status ? props.statuses[t.status] : undefined }
|
|
267
613
|
}),
|
|
268
614
|
)
|
|
269
615
|
const ROLES = new Set(['primary', 'secondary', 'tertiary', 'error', 'success', 'surface'])
|
|
616
|
+
/** A taken chair: the table's status color, full strength (primary when it has none) */
|
|
617
|
+
function seatTaken(st?: FloorStatus) {
|
|
618
|
+
const c = !st || st.color === 'surface' ? 'primary' : st.color
|
|
619
|
+
return ROLES.has(c) ? { background: `var(--color-${c})`, color: `var(--color-on-${c})` } : { background: c, color: '#fff' }
|
|
620
|
+
}
|
|
270
621
|
function look(st?: FloorStatus) {
|
|
271
622
|
if (!st || st.color === 'surface') return { background: 'var(--color-surface-container-highest)', color: 'var(--color-on-surface)' }
|
|
272
623
|
if (ROLES.has(st.color)) return { background: `var(--color-${st.color}-container)`, color: `var(--color-on-${st.color}-container)` }
|
|
@@ -312,15 +663,36 @@ const mergeShapes = computed(() =>
|
|
|
312
663
|
)
|
|
313
664
|
|
|
314
665
|
// ── Dragging ────────────────────────────────────────────────────────────────────────────────────────────
|
|
315
|
-
let drag: { id: number; sx: number; sy: number; start: Map<string | number, { x: number; y: number }>; moved: boolean; pick?: string | number } | null = null
|
|
666
|
+
let drag: { id: number; sx: number; sy: number; start: Map<string | number, { x: number; y: number }>; moved: boolean; pick?: string | number; run: number; pan0: { x: number; y: number }; last: { clientX: number; clientY: number }; edge: ReturnType<typeof edgePan> } | null = null
|
|
316
667
|
let suppressClick = false
|
|
317
|
-
|
|
318
|
-
|
|
668
|
+
/** The step walls, zones and decor snap to: the grid, or a part of it (`subgrid`) */
|
|
669
|
+
const step = computed(() => (props.grid ? props.grid / Math.max(1, Math.round(props.subgrid)) : 0))
|
|
670
|
+
const snap = (v: number) => (step.value ? Math.round(v / step.value) * step.value : v)
|
|
671
|
+
/** The step a table moves by: its cell, or the grid */
|
|
672
|
+
const tableStep = computed(() => props.cellSize || props.grid)
|
|
673
|
+
/** A table's middle: on a grid point, or with `tableSnap="cell"` (or `cellSize`) in the middle of a grid square */
|
|
319
674
|
const snapTable = (v: number) => {
|
|
320
|
-
const g =
|
|
321
|
-
if (!g
|
|
675
|
+
const g = tableStep.value
|
|
676
|
+
if (!g) return v
|
|
677
|
+
if (props.tableSnap !== 'cell' && !props.cellSize) return Math.round(v / g) * g
|
|
322
678
|
return Math.round((v - g / 2) / g) * g + g / 2
|
|
323
679
|
}
|
|
680
|
+
/** The step a resize handle moves by (0: free) */
|
|
681
|
+
const resizeStep = computed(() => (props.resizeSnap === 'grid' ? props.grid || 0 : props.resizeSnap === 'subgrid' ? step.value : 0))
|
|
682
|
+
/** A size changed by `delta`, in whole steps of `unit` (0: as is), never below `min` */
|
|
683
|
+
function steppedSize(size: number, delta: number, unit: number, min: number) {
|
|
684
|
+
if (!unit) return Math.max(min, size + delta)
|
|
685
|
+
let n = Math.round(delta / unit)
|
|
686
|
+
while (n < 0 && size + n * unit < min) n++
|
|
687
|
+
return size + n * unit
|
|
688
|
+
}
|
|
689
|
+
/** Where a dropped table's middle lands: snapped as above, or with `cellSize` so it covers whole cells from its own */
|
|
690
|
+
function snapTableAt(t: FloorTable, x: number, y: number) {
|
|
691
|
+
const c = props.cellSize
|
|
692
|
+
if (!c) return { x: snapTable(x), y: snapTable(y) }
|
|
693
|
+
const s = sizeOf(t)
|
|
694
|
+
return { x: Math.round((x - cellReach(s.w)) / c) * c + cellReach(s.w), y: Math.round((y - cellReach(s.h)) / c) * c + cellReach(s.h) }
|
|
695
|
+
}
|
|
324
696
|
function clamp(t: FloorTable, x: number, y: number) {
|
|
325
697
|
const s = sizeOf(t)
|
|
326
698
|
return { x: Math.min(props.width - s.w / 2, Math.max(s.w / 2, x)), y: Math.min(props.height - s.h / 2, Math.max(s.h / 2, y)) }
|
|
@@ -330,6 +702,7 @@ const LONG_PRESS = 450
|
|
|
330
702
|
let longPress = 0
|
|
331
703
|
let longPressed = false
|
|
332
704
|
function onDown(e: PointerEvent, t: FloorTable) {
|
|
705
|
+
if (!props.editable && props.transferable && e.button === 0) return startTransfer(e, t)
|
|
333
706
|
if (!props.editable || e.button !== 0 || tool.value !== 'select') return
|
|
334
707
|
e.stopPropagation()
|
|
335
708
|
picked.value = null
|
|
@@ -348,21 +721,28 @@ function onDown(e: PointerEvent, t: FloorTable) {
|
|
|
348
721
|
// `selectable="multiple"` the selection is the click's to change, and a drag moves only the table pressed (not the
|
|
349
722
|
// rest of the selection nor its merge): to bring the tables being merged together one by one
|
|
350
723
|
const ids = toggling.value ? [t.id] : withMerged(selection.value.includes(t.id) ? selection.value : [t.id])
|
|
351
|
-
drag = { id: e.pointerId, sx: e.clientX, sy: e.clientY, start: new Map(tables.value.filter((x) => ids.includes(x.id)).map((x) => [x.id, { x: x.x, y: x.y }])), moved: false, pick: touch && !toggling.value && !selection.value.includes(t.id) ? t.id : undefined }
|
|
724
|
+
drag = { id: e.pointerId, sx: e.clientX, sy: e.clientY, start: new Map(tables.value.filter((x) => ids.includes(x.id)).map((x) => [x.id, { x: x.x, y: x.y }])), moved: false, pick: touch && !toggling.value && !selection.value.includes(t.id) ? t.id : undefined, run: gestureRun, pan0: { ...pan.value }, last: e, edge: edgePan(() => drag?.moved && drag.run === gestureRun && dragTables()) }
|
|
352
725
|
window.addEventListener('pointermove', onMove)
|
|
353
726
|
window.addEventListener('pointerup', onUp)
|
|
354
727
|
window.addEventListener('pointercancel', onUp)
|
|
355
728
|
}
|
|
356
729
|
function onMove(e: PointerEvent) {
|
|
357
|
-
if (!drag || e.pointerId !== drag.id) return
|
|
358
|
-
const dx = (e.clientX - drag.sx) / scale.value
|
|
359
|
-
const dy = (e.clientY - drag.sy) / scale.value
|
|
730
|
+
if (!drag || e.pointerId !== drag.id || drag.run !== gestureRun) return
|
|
360
731
|
if (!drag.moved && Math.hypot(e.clientX - drag.sx, e.clientY - drag.sy) < (e.pointerType === 'touch' ? 8 : 4)) return
|
|
361
732
|
if (!drag.moved) {
|
|
362
733
|
clearTimeout(longPress)
|
|
363
734
|
if (drag.pick !== undefined) selection.value = [drag.pick]
|
|
364
735
|
}
|
|
365
736
|
drag.moved = true
|
|
737
|
+
drag.last = e
|
|
738
|
+
drag.edge.at(e)
|
|
739
|
+
dragTables()
|
|
740
|
+
}
|
|
741
|
+
/** The dragged tables under the pointer (the view may have scrolled since the drag began) */
|
|
742
|
+
function dragTables() {
|
|
743
|
+
if (!drag) return
|
|
744
|
+
const dx = (drag.last.clientX - drag.sx - (pan.value.x - drag.pan0.x)) / scale.value
|
|
745
|
+
const dy = (drag.last.clientY - drag.sy - (pan.value.y - drag.pan0.y)) / scale.value
|
|
366
746
|
const next = new Map<string | number, { x: number; y: number }>()
|
|
367
747
|
for (const [id, p] of drag.start) next.set(id, clamp(tables.value.find((x) => x.id === id)!, p.x + dx, p.y + dy))
|
|
368
748
|
draft.value = next
|
|
@@ -377,19 +757,167 @@ function onUp(e: PointerEvent) {
|
|
|
377
757
|
window.removeEventListener('pointermove', onMove)
|
|
378
758
|
window.removeEventListener('pointerup', onUp)
|
|
379
759
|
window.removeEventListener('pointercancel', onUp)
|
|
760
|
+
drag.edge.stop()
|
|
380
761
|
const d = draft.value
|
|
381
|
-
const moved = drag.moved && d && e.type !== 'pointercancel'
|
|
762
|
+
const moved = drag.moved && d && e.type !== 'pointercancel' && drag.run === gestureRun
|
|
382
763
|
drag = null
|
|
383
764
|
draft.value = null
|
|
384
765
|
if (!moved) return
|
|
385
766
|
suppressClick = true
|
|
386
767
|
setTimeout(() => (suppressClick = false))
|
|
387
|
-
commitMoves(new Map([...d!].map(([id, p]) =>
|
|
768
|
+
commitMoves(new Map([...d!].map(([id, p]) => {
|
|
769
|
+
const t = tables.value.find((x) => x.id === id)!
|
|
770
|
+
const at = snapTableAt(t, p.x, p.y)
|
|
771
|
+
return [id, clamp(t, at.x, at.y)]
|
|
772
|
+
})))
|
|
773
|
+
}
|
|
774
|
+
/** Two boxes overlap (touching edges don't) */
|
|
775
|
+
const crosses = (a: { x1: number; y1: number; x2: number; y2: number }, b: typeof a) => a.x1 < b.x2 - 0.5 && b.x1 < a.x2 - 0.5 && a.y1 < b.y2 - 0.5 && b.y1 < a.y2 - 0.5
|
|
776
|
+
/** The tables that overlap another one (their turned boxes), while editing */
|
|
777
|
+
const overlapping = computed(() => {
|
|
778
|
+
const out = new Set<string | number>()
|
|
779
|
+
if (!props.editable || props.overlap === 'allow') return out
|
|
780
|
+
const boxes = placed.value.map((p) => ({ id: p.t.id, b: boxOf(p) }))
|
|
781
|
+
for (let i = 0; i < boxes.length; i++)
|
|
782
|
+
for (let j = i + 1; j < boxes.length; j++)
|
|
783
|
+
if (crosses(boxes[i]!.b, boxes[j]!.b)) {
|
|
784
|
+
out.add(boxes[i]!.id)
|
|
785
|
+
out.add(boxes[j]!.id)
|
|
786
|
+
}
|
|
787
|
+
return out
|
|
788
|
+
})
|
|
789
|
+
/** With `overlap="prevent"`: whether tables moved or resized like this would overlap one another or the rest */
|
|
790
|
+
function wouldOverlap(changed: Map<string | number, { x?: number; y?: number; w?: number; h?: number }>) {
|
|
791
|
+
if (props.overlap !== 'prevent') return false
|
|
792
|
+
const boxes = tables.value.map((t) => {
|
|
793
|
+
const c = changed.get(t.id)
|
|
794
|
+
const s0 = sizeOf(t)
|
|
795
|
+
const size = { w: c?.w ?? s0.w, h: c?.h ?? s0.h }
|
|
796
|
+
return { id: t.id, b: boxOf({ t, x: c?.x ?? t.x, y: c?.y ?? t.y, size }) }
|
|
797
|
+
})
|
|
798
|
+
return boxes.some((a) => changed.has(a.id) && boxes.some((b) => b.id !== a.id && crosses(a.b, b.b)))
|
|
388
799
|
}
|
|
389
800
|
function commitMoves(next: Map<string | number, { x: number; y: number }>) {
|
|
801
|
+
// Refused: the tables go back where they were
|
|
802
|
+
if (wouldOverlap(next)) return navigator.vibrate?.(30)
|
|
390
803
|
record()
|
|
391
804
|
tables.value = tables.value.map((t) => (next.has(t.id) ? { ...t, ...next.get(t.id)! } : t))
|
|
392
|
-
emit('move', [...next].map(([id, p]) => ({ id, ...p })))
|
|
805
|
+
emit('move', [...next].map(([id, p]) => ({ id, ...toOuterXY(tables.value.find((t) => t.id === id)!, p.x, p.y) })))
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Resizing the selected table by its corner handle: the drag read along the table's own axes, growing it both ways so
|
|
809
|
+
* its middle stays on its grid point or cell; a round table with Shift (or one that is a circle) stays a circle
|
|
810
|
+
*/
|
|
811
|
+
function onTableResize(e: PointerEvent, t: FloorTable) {
|
|
812
|
+
if (!props.editable || e.button !== 0) return
|
|
813
|
+
e.stopPropagation()
|
|
814
|
+
e.preventDefault()
|
|
815
|
+
const s0 = sizeOf(t)
|
|
816
|
+
const rad = ((t.rotation ?? 0) * Math.PI) / 180
|
|
817
|
+
const cos = Math.cos(rad)
|
|
818
|
+
const sin = Math.sin(rad)
|
|
819
|
+
const circle = (t.shape ?? 'square') === 'round' && s0.w === s0.h
|
|
820
|
+
let shift = false
|
|
821
|
+
const key = (ev: KeyboardEvent) => (shift = ev.shiftKey)
|
|
822
|
+
window.addEventListener('keydown', key)
|
|
823
|
+
window.addEventListener('keyup', key)
|
|
824
|
+
// By cell, the table keeps its cell and grows right and down over the next ones; else about its middle
|
|
825
|
+
const c = props.cellSize
|
|
826
|
+
const corner = c ? { x: t.x - cellReach(s0.w), y: t.y - cellReach(s0.h) } : null
|
|
827
|
+
const middleFor = (w: number, h: number) => (corner ? { x: corner.x + cellReach(w), y: corner.y + cellReach(h) } : { x: t.x, y: t.y })
|
|
828
|
+
follow(e, (dx, dy) => {
|
|
829
|
+
// Growing both ways (about its middle), each side moves a whole step: twice a step in all
|
|
830
|
+
const k = corner ? 1 : 2
|
|
831
|
+
const unit = resizeStep.value * k
|
|
832
|
+
let w = steppedSize(s0.w, k * (dx * cos + dy * sin), unit, 20)
|
|
833
|
+
let h = steppedSize(s0.h, k * (-dx * sin + dy * cos), unit, 20)
|
|
834
|
+
if (circle !== shift) w = h = Math.max(w, h)
|
|
835
|
+
sizeDraft.value = { id: t.id, w, h }
|
|
836
|
+
if (corner) draft.value = new Map([[t.id, middleFor(w, h)]])
|
|
837
|
+
}, () => {
|
|
838
|
+
const d = sizeDraft.value!
|
|
839
|
+
sizeDraft.value = null
|
|
840
|
+
draft.value = null
|
|
841
|
+
const at = middleFor(d.w, d.h)
|
|
842
|
+
if (wouldOverlap(new Map([[t.id, { ...at, w: d.w, h: d.h }]]))) return
|
|
843
|
+
record()
|
|
844
|
+
tables.value = tables.value.map((x) => (x.id === t.id ? { ...x, ...at, width: Math.round(d.w), height: Math.round(d.h) } : x))
|
|
845
|
+
})
|
|
846
|
+
const off = () => {
|
|
847
|
+
window.removeEventListener('keydown', key)
|
|
848
|
+
window.removeEventListener('keyup', key)
|
|
849
|
+
window.removeEventListener('pointerup', off)
|
|
850
|
+
}
|
|
851
|
+
window.addEventListener('pointerup', off)
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// ── In service: carrying a table's party to another table ──
|
|
855
|
+
/** The table being carried: where the pointer is (plan units) and the table under it, if any */
|
|
856
|
+
const transferDrag = shallowRef<{ id: string | number; label: string; x: number; y: number; over: string | number | null; ok: boolean } | null>(null)
|
|
857
|
+
const tableAt = (x: number, y: number, skip: string | number) =>
|
|
858
|
+
placed.value.find((p) => {
|
|
859
|
+
if (p.t.id === skip) return false
|
|
860
|
+
const b = boxOf(p)
|
|
861
|
+
return x >= b.x1 && x <= b.x2 && y >= b.y1 && y <= b.y2
|
|
862
|
+
})?.t
|
|
863
|
+
function transferCheck(from: FloorTable, to: FloorTable) {
|
|
864
|
+
return props.canTransfer?.(outerOf(from), outerOf(to)) ?? true
|
|
865
|
+
}
|
|
866
|
+
function startTransfer(e: PointerEvent, t: FloorTable) {
|
|
867
|
+
const touch = e.pointerType === 'touch'
|
|
868
|
+
const sx = e.clientX
|
|
869
|
+
const sy = e.clientY
|
|
870
|
+
const run = gestureRun
|
|
871
|
+
let active = false
|
|
872
|
+
const at = (ev: PointerEvent) => {
|
|
873
|
+
const p = toPlan(ev)
|
|
874
|
+
const over = tableAt(p.x, p.y, t.id)
|
|
875
|
+
transferDrag.value = { id: t.id, label: t.label, x: p.x, y: p.y, over: over?.id ?? null, ok: !over || transferCheck(t, over) === true }
|
|
876
|
+
}
|
|
877
|
+
const begin = (ev: PointerEvent) => {
|
|
878
|
+
active = true
|
|
879
|
+
document.body.style.userSelect = 'none'
|
|
880
|
+
navigator.vibrate?.(10)
|
|
881
|
+
at(ev)
|
|
882
|
+
}
|
|
883
|
+
// A finger holds the table down first, so a swipe still scrolls the page
|
|
884
|
+
const timer = touch ? window.setTimeout(() => begin(e), LONG_PRESS) : 0
|
|
885
|
+
const mv = (ev: PointerEvent) => {
|
|
886
|
+
if (ev.pointerId !== e.pointerId) return
|
|
887
|
+
if (run !== gestureRun) return end()
|
|
888
|
+
if (!active) {
|
|
889
|
+
if (Math.hypot(ev.clientX - sx, ev.clientY - sy) < (touch ? 8 : 4)) return
|
|
890
|
+
if (touch) return end()
|
|
891
|
+
begin(ev)
|
|
892
|
+
}
|
|
893
|
+
at(ev)
|
|
894
|
+
}
|
|
895
|
+
const up = (ev: PointerEvent) => {
|
|
896
|
+
if (ev.pointerId !== e.pointerId) return
|
|
897
|
+
const d = transferDrag.value
|
|
898
|
+
const was = active
|
|
899
|
+
end()
|
|
900
|
+
if (!was || !d || ev.type === 'pointercancel') return
|
|
901
|
+
suppressClick = true
|
|
902
|
+
setTimeout(() => (suppressClick = false))
|
|
903
|
+
const to = d.over !== null ? tables.value.find((x) => x.id === d.over) : undefined
|
|
904
|
+
if (!to) return
|
|
905
|
+
const ok = transferCheck(t, to)
|
|
906
|
+
if (ok === true) emit('transfer', outerOf(t), outerOf(to))
|
|
907
|
+
else emit('transfer-refused', outerOf(t), outerOf(to), typeof ok === 'string' ? ok : '')
|
|
908
|
+
}
|
|
909
|
+
function end() {
|
|
910
|
+
clearTimeout(timer)
|
|
911
|
+
if (active) document.body.style.userSelect = ''
|
|
912
|
+
active = false
|
|
913
|
+
transferDrag.value = null
|
|
914
|
+
window.removeEventListener('pointermove', mv)
|
|
915
|
+
window.removeEventListener('pointerup', up)
|
|
916
|
+
window.removeEventListener('pointercancel', up)
|
|
917
|
+
}
|
|
918
|
+
window.addEventListener('pointermove', mv)
|
|
919
|
+
window.addEventListener('pointerup', up)
|
|
920
|
+
window.addEventListener('pointercancel', up)
|
|
393
921
|
}
|
|
394
922
|
/** Editing with `selectable="multiple"`: a click toggles a table in the selection (to merge them), a drag moves that table alone */
|
|
395
923
|
const toggling = computed(() => props.editable && props.selectable === 'multiple')
|
|
@@ -400,7 +928,7 @@ function onClick(e: MouseEvent, t: FloorTable) {
|
|
|
400
928
|
else if (!props.editable && props.selectable === 'single') selection.value = selection.value.length === 1 && selection.value[0] === t.id ? [] : [t.id]
|
|
401
929
|
else if (!props.editable && props.selectable === 'multiple')
|
|
402
930
|
selection.value = selection.value.includes(t.id) ? selection.value.filter((x) => x !== t.id) : [...selection.value, t.id]
|
|
403
|
-
emit('table-click', t, e)
|
|
931
|
+
emit('table-click', outerOf(t), e)
|
|
404
932
|
}
|
|
405
933
|
/** With `dragMerged`, the tables merged with these come along */
|
|
406
934
|
function withMerged(ids: (string | number)[]) {
|
|
@@ -412,13 +940,13 @@ function withMerged(ids: (string | number)[]) {
|
|
|
412
940
|
function onKey(e: KeyboardEvent, t: FloorTable) {
|
|
413
941
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
414
942
|
e.preventDefault()
|
|
415
|
-
emit('table-click', t, e)
|
|
943
|
+
emit('table-click', outerOf(t), e)
|
|
416
944
|
return
|
|
417
945
|
}
|
|
418
946
|
const dir = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }[e.key]
|
|
419
947
|
if (!dir || !props.editable) return
|
|
420
948
|
e.preventDefault()
|
|
421
|
-
const step = (
|
|
949
|
+
const step = (tableStep.value || 1) * (e.shiftKey ? 5 : 1)
|
|
422
950
|
const ids = withMerged(selection.value.includes(t.id) ? selection.value : [t.id])
|
|
423
951
|
commitMoves(new Map(tables.value.filter((x) => ids.includes(x.id)).map((x) => [x.id, clamp(x, x.x + dir[0]! * step, x.y + dir[1]! * step)])))
|
|
424
952
|
}
|
|
@@ -429,8 +957,8 @@ onBeforeUnmount(() => {
|
|
|
429
957
|
})
|
|
430
958
|
// ── Zones, walls and decor ───────────────────────────────────────────────────────────────────────────────
|
|
431
959
|
const BUILTIN_DECOR: Record<FloorDecorBuiltin, FloorDecorKind> = {
|
|
432
|
-
door: { label: 'Door', icon: 'door_front', width: 60, height: 14, shape: '
|
|
433
|
-
window: { label: 'Window', icon: 'window', width: 80, height: 10, shape: '
|
|
960
|
+
door: { label: 'Door', icon: 'door_front', width: 60, height: 14, shape: 'door' },
|
|
961
|
+
window: { label: 'Window', icon: 'window', width: 80, height: 10, shape: 'window' },
|
|
434
962
|
plant: { label: 'Plant', icon: 'potted_plant', width: 40, height: 40 },
|
|
435
963
|
column: { label: 'Column', width: 30, height: 30, shape: 'round', color: 'var(--color-outline)' },
|
|
436
964
|
restroom: { label: 'Restroom', icon: 'wc', width: 48, height: 48 },
|
|
@@ -449,12 +977,16 @@ const decorSize = (d: FloorDecor) => ({ w: d.width ?? kindOf(d).width, h: d.heig
|
|
|
449
977
|
function decorLook(k: FloorDecorKind) {
|
|
450
978
|
const shape = k.shape ?? 'box'
|
|
451
979
|
if (shape === 'text') return {}
|
|
980
|
+
// Doors and windows take the plan's own color, so the wall they sit on looks cut there
|
|
981
|
+
if ((shape === 'door' || shape === 'window') && !k.color) return { backgroundColor: 'inherit' }
|
|
452
982
|
const c = k.color ?? (shape === 'bar' ? 'surface-container-highest' : 'surface-container-high')
|
|
453
983
|
const bg = c.startsWith('surface') || c.startsWith('var(') || c.startsWith('#') || c.startsWith('rgb') || c.startsWith('hsl')
|
|
454
984
|
? (c.startsWith('surface') ? `var(--color-${c})` : c)
|
|
455
985
|
: `var(--color-${c}-container)`
|
|
456
|
-
return { background: bg, borderRadius: shape === 'round' ? '9999px' : shape === 'bar' ? '2px' : '8px' }
|
|
986
|
+
return { background: bg, borderRadius: shape === 'round' ? '9999px' : shape === 'bar' || shape === 'door' || shape === 'window' ? '2px' : '8px' }
|
|
457
987
|
}
|
|
988
|
+
/** A door's swing: the quarter circle its leaf sweeps, from the open leaf down to the far jamb, in px */
|
|
989
|
+
const doorSwing = (w: number) => `M0 0 L0 ${-w} A${w} ${w} 0 0 1 ${w} 0 Z`
|
|
458
990
|
function areaLook(color?: string) {
|
|
459
991
|
const c = color ?? 'secondary'
|
|
460
992
|
return ROLES.has(c) ? { background: `color-mix(in srgb, var(--color-${c}-container) 45%, transparent)`, borderColor: `var(--color-${c})` } : { background: `color-mix(in srgb, ${c} 18%, transparent)`, borderColor: c }
|
|
@@ -463,27 +995,42 @@ function areaLook(color?: string) {
|
|
|
463
995
|
const isPicked = (kind: 'area' | 'wall' | 'decor', id: string | number) => picked.value?.kind === kind && picked.value.id === id
|
|
464
996
|
const toPlan = (e: { clientX: number; clientY: number }) => {
|
|
465
997
|
const r = root.value!.getBoundingClientRect()
|
|
466
|
-
return { x: (e.clientX - r.left) / scale.value, y: (e.clientY - r.top) / scale.value }
|
|
998
|
+
return { x: (e.clientX - r.left - pan.value.x) / scale.value, y: (e.clientY - r.top - pan.value.y) / scale.value }
|
|
467
999
|
}
|
|
468
1000
|
/** A generic drag in plan units: `move` gets the offset from where it started, `end` runs once if it moved */
|
|
469
|
-
function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: () => void) {
|
|
1001
|
+
function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: () => void, opts: { tap?: () => void; cancel?: () => void } = {}) {
|
|
470
1002
|
// Keys (Delete, Enter) reach the plan while something on it is being edited
|
|
471
1003
|
root.value?.focus({ preventScroll: true })
|
|
472
1004
|
const sx = e.clientX
|
|
473
1005
|
const sy = e.clientY
|
|
474
1006
|
let moved = false
|
|
1007
|
+
const run = gestureRun
|
|
1008
|
+
// Near the edges the zoomed view scrolls, and the offset counts what it scrolled
|
|
1009
|
+
const pan0 = { ...pan.value }
|
|
1010
|
+
let last: { clientX: number; clientY: number } = e
|
|
1011
|
+
const report = () => move((last.clientX - sx - (pan.value.x - pan0.x)) / scale.value, (last.clientY - sy - (pan.value.y - pan0.y)) / scale.value)
|
|
1012
|
+
const edge = edgePan(() => moved && run === gestureRun && report())
|
|
1013
|
+
const touch = e.pointerType === 'touch'
|
|
1014
|
+
if (touch) holding++
|
|
475
1015
|
const mv = (ev: PointerEvent) => {
|
|
476
|
-
if (ev.pointerId !== e.pointerId) return
|
|
477
|
-
if (!moved && Math.hypot(ev.clientX - sx, ev.clientY - sy) < 4) return
|
|
1016
|
+
if (ev.pointerId !== e.pointerId || run !== gestureRun) return
|
|
1017
|
+
if (!moved && Math.hypot(ev.clientX - sx, ev.clientY - sy) < (ev.pointerType === 'touch' ? 6 : 4)) return
|
|
478
1018
|
moved = true
|
|
479
|
-
|
|
1019
|
+
last = ev
|
|
1020
|
+
edge.at(ev)
|
|
1021
|
+
report()
|
|
480
1022
|
}
|
|
481
1023
|
const up = (ev: PointerEvent) => {
|
|
482
1024
|
if (ev.pointerId !== e.pointerId) return
|
|
483
1025
|
window.removeEventListener('pointermove', mv)
|
|
484
1026
|
window.removeEventListener('pointerup', up)
|
|
485
1027
|
window.removeEventListener('pointercancel', up)
|
|
486
|
-
|
|
1028
|
+
edge.stop()
|
|
1029
|
+
if (touch) holding = Math.max(0, holding - 1)
|
|
1030
|
+
const ok = run === gestureRun && ev.type !== 'pointercancel'
|
|
1031
|
+
if (moved && ok) end()
|
|
1032
|
+
else if (!moved && ok) opts.tap?.()
|
|
1033
|
+
else opts.cancel?.()
|
|
487
1034
|
}
|
|
488
1035
|
window.addEventListener('pointermove', mv)
|
|
489
1036
|
window.addEventListener('pointerup', up)
|
|
@@ -492,22 +1039,144 @@ function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: ()
|
|
|
492
1039
|
const areaDraft = shallowRef<FloorArea | null>(null)
|
|
493
1040
|
const shownAreas = computed(() => areas.value.map((a) => (areaDraft.value?.id === a.id ? areaDraft.value : a)).concat(areaDraft.value && !areas.value.some((a) => a.id === areaDraft.value!.id) ? [areaDraft.value] : []))
|
|
494
1041
|
type Corner = 'nw' | 'ne' | 'sw' | 'se'
|
|
1042
|
+
/** The box around a zone's corners */
|
|
1043
|
+
function boxAround(pts: [number, number][]) {
|
|
1044
|
+
const xs = pts.map((p) => p[0])
|
|
1045
|
+
const ys = pts.map((p) => p[1])
|
|
1046
|
+
const x = Math.min(...xs)
|
|
1047
|
+
const y = Math.min(...ys)
|
|
1048
|
+
return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y }
|
|
1049
|
+
}
|
|
1050
|
+
/** A zone of any shape with its box brought up to date */
|
|
1051
|
+
const shaped = (a: FloorArea, points: [number, number][]): FloorArea => ({ ...a, points, ...boxAround(points) })
|
|
1052
|
+
const rectCorners = (a: FloorArea): [number, number][] => [[a.x, a.y], [a.x + a.width, a.y], [a.x + a.width, a.y + a.height], [a.x, a.y + a.height]]
|
|
1053
|
+
const polyPath = (pts: [number, number][]) => pts.map(([x, y], i) => `${i ? 'L' : 'M'}${x * scale.value} ${y * scale.value}`).join('') + 'Z'
|
|
1054
|
+
function areaSvgLook(color?: string) {
|
|
1055
|
+
const c = color ?? 'secondary'
|
|
1056
|
+
return ROLES.has(c) ? { fill: `color-mix(in srgb, var(--color-${c}-container) 45%, transparent)`, stroke: `var(--color-${c})` } : { fill: `color-mix(in srgb, ${c} 18%, transparent)`, stroke: c }
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Where a corner being placed lands: on a wall's corner or a zone's (yours, not the one moving) within a few px, so
|
|
1060
|
+
* walls join end to end; else on the snapping step
|
|
1061
|
+
*/
|
|
1062
|
+
function snapPoint(x: number, y: number, skip?: { kind: 'wall' | 'area'; id: string | number; vertex?: number }): [number, number] {
|
|
1063
|
+
let best: [number, number] | null = null
|
|
1064
|
+
// A finger covers more than a mouse's tip: it reaches farther
|
|
1065
|
+
let bestD = (coarse.value ? 24 : 12) / scale.value
|
|
1066
|
+
const consider = (pts: [number, number][], kind: 'wall' | 'area', id: string | number | null) =>
|
|
1067
|
+
pts.forEach((p, i) => {
|
|
1068
|
+
if (skip && skip.kind === kind && skip.id === id && (skip.vertex === undefined || skip.vertex === i)) return
|
|
1069
|
+
const d = Math.hypot(p[0] - x, p[1] - y)
|
|
1070
|
+
if (d < bestD) {
|
|
1071
|
+
bestD = d
|
|
1072
|
+
best = p
|
|
1073
|
+
}
|
|
1074
|
+
})
|
|
1075
|
+
for (const w of walls.value) consider(w.points, 'wall', w.id)
|
|
1076
|
+
for (const a of areas.value) consider(a.points ?? rectCorners(a), 'area', a.id)
|
|
1077
|
+
// The wall or zone being drawn closes on its own corners (but not the one just placed)
|
|
1078
|
+
if (drawing.value) consider(drawing.value.slice(0, -1), 'wall', null)
|
|
1079
|
+
if (best) return [best[0], best[1]]
|
|
1080
|
+
// Close to the plan's edge it lands on it (in its corner, on both), and never past it: a finger can't reach the
|
|
1081
|
+
// screen's very edge, where the phone takes the swipe for itself
|
|
1082
|
+
const reach = (coarse.value ? 24 : 6) / scale.value
|
|
1083
|
+
const onEdge = (v: number, max: number) => (v < reach ? 0 : v > max - reach ? max : Math.min(max, Math.max(0, snap(v))))
|
|
1084
|
+
return [onEdge(x, props.width), onEdge(y, props.height)]
|
|
1085
|
+
}
|
|
1086
|
+
/** A move (dx, dy) of something whose box is `b`, cut short at the plan's edges (what already sits past one may stay) */
|
|
1087
|
+
function keepIn(dx: number, dy: number, b: { x1: number; y1: number; x2: number; y2: number }): [number, number] {
|
|
1088
|
+
return [
|
|
1089
|
+
Math.min(Math.max(dx, Math.min(0, -b.x1)), Math.max(0, props.width - b.x2)),
|
|
1090
|
+
Math.min(Math.max(dy, Math.min(0, -b.y1)), Math.max(0, props.height - b.y2)),
|
|
1091
|
+
]
|
|
1092
|
+
}
|
|
1093
|
+
/** A snapped coordinate kept inside the plan, unless it already sat outside */
|
|
1094
|
+
const inPlan = (v: number, was: number, max: number) => (was < 0 || was > max ? v : Math.min(max, Math.max(0, v)))
|
|
1095
|
+
const pointsBox = (pts: [number, number][]) => {
|
|
1096
|
+
const xs = pts.map((p) => p[0])
|
|
1097
|
+
const ys = pts.map((p) => p[1])
|
|
1098
|
+
return { x1: Math.min(...xs), y1: Math.min(...ys), x2: Math.max(...xs), y2: Math.max(...ys) }
|
|
1099
|
+
}
|
|
1100
|
+
/** The segment of a line (closed: a zone's outline) nearest a point: the index to insert a corner before */
|
|
1101
|
+
function nearestSegment(pts: [number, number][], p: { x: number; y: number }, closed: boolean) {
|
|
1102
|
+
let best = 1
|
|
1103
|
+
let bestD = Infinity
|
|
1104
|
+
const n = closed ? pts.length + 1 : pts.length
|
|
1105
|
+
for (let i = 1; i < n; i++) {
|
|
1106
|
+
const [ax, ay] = pts[i - 1]!
|
|
1107
|
+
const [bx, by] = pts[i % pts.length]!
|
|
1108
|
+
const len = (bx - ax) ** 2 + (by - ay) ** 2
|
|
1109
|
+
const t = len ? Math.max(0, Math.min(1, ((p.x - ax) * (bx - ax) + (p.y - ay) * (by - ay)) / len)) : 0
|
|
1110
|
+
const d = Math.hypot(ax + t * (bx - ax) - p.x, ay + t * (by - ay) - p.y)
|
|
1111
|
+
if (d < bestD) {
|
|
1112
|
+
bestD = d
|
|
1113
|
+
best = i
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
return best
|
|
1117
|
+
}
|
|
1118
|
+
/** Double-click on a zone: a new corner on its nearest edge (a rectangle becomes a zone of any shape) */
|
|
1119
|
+
function onAreaDblclick(e: MouseEvent, a: FloorArea) {
|
|
1120
|
+
if (!props.editable || tool.value !== 'select') return
|
|
1121
|
+
e.stopPropagation()
|
|
1122
|
+
const p = toPlan(e)
|
|
1123
|
+
const pts = a.points ?? rectCorners(a)
|
|
1124
|
+
const at = nearestSegment(pts, p, true)
|
|
1125
|
+
record()
|
|
1126
|
+
areas.value = areas.value.map((x) => (x.id === a.id ? shaped(x, [...pts.slice(0, at), [snap(p.x), snap(p.y)], ...pts.slice(at)]) : x))
|
|
1127
|
+
picked.value = { kind: 'area', id: a.id, vertex: at }
|
|
1128
|
+
}
|
|
1129
|
+
/** Dragging a corner of a zone of any shape */
|
|
1130
|
+
function onAreaVertexDown(e: PointerEvent, a: FloorArea, vertex: number) {
|
|
1131
|
+
if (!props.editable || tool.value !== 'select' || e.button !== 0 || !a.points) return
|
|
1132
|
+
e.stopPropagation()
|
|
1133
|
+
picked.value = { kind: 'area', id: a.id, vertex }
|
|
1134
|
+
const p0 = a.points[vertex]!
|
|
1135
|
+
follow(e, (dx, dy) => {
|
|
1136
|
+
const at = snapPoint(p0[0] + dx, p0[1] + dy, { kind: 'area', id: a.id, vertex })
|
|
1137
|
+
areaDraft.value = shaped(a, a.points!.map((p, i) => (i === vertex ? at : p)))
|
|
1138
|
+
}, () => {
|
|
1139
|
+
const d = areaDraft.value!
|
|
1140
|
+
areaDraft.value = null
|
|
1141
|
+
record()
|
|
1142
|
+
areas.value = areas.value.map((x) => (x.id === a.id ? d : x))
|
|
1143
|
+
})
|
|
1144
|
+
}
|
|
495
1145
|
function onAreaDown(e: PointerEvent, a: FloorArea, corner: Corner | null) {
|
|
496
1146
|
if (!props.editable || tool.value !== 'select' || e.button !== 0) return
|
|
497
1147
|
e.stopPropagation()
|
|
498
1148
|
picked.value = { kind: 'area', id: a.id }
|
|
499
1149
|
selection.value = []
|
|
500
|
-
|
|
1150
|
+
if (a.points) {
|
|
1151
|
+
const box = pointsBox(a.points)
|
|
1152
|
+
follow(e, (mx, my) => {
|
|
1153
|
+
const [dx, dy] = keepIn(mx, my, box)
|
|
1154
|
+
areaDraft.value = shaped(a, a.points!.map(([x, y]) => [x + dx, y + dy]))
|
|
1155
|
+
}, () => {
|
|
1156
|
+
const d = areaDraft.value!
|
|
1157
|
+
areaDraft.value = null
|
|
1158
|
+
// Moved by whole steps, so its corners stay where they snapped
|
|
1159
|
+
const ox = snap(d.points![0]![0]) - d.points![0]![0]
|
|
1160
|
+
const oy = snap(d.points![0]![1]) - d.points![0]![1]
|
|
1161
|
+
record()
|
|
1162
|
+
areas.value = areas.value.map((x) => (x.id === a.id ? shaped(d, d.points!.map(([px, py]) => [px + ox, py + oy])) : x))
|
|
1163
|
+
})
|
|
1164
|
+
return
|
|
1165
|
+
}
|
|
1166
|
+
follow(e, (mx, my) => {
|
|
501
1167
|
if (!corner) {
|
|
1168
|
+
const [dx, dy] = keepIn(mx, my, { x1: a.x, y1: a.y, x2: a.x + a.width, y2: a.y + a.height })
|
|
502
1169
|
areaDraft.value = { ...a, x: a.x + dx, y: a.y + dy }
|
|
503
1170
|
return
|
|
504
1171
|
}
|
|
505
|
-
// The opposite corner stays put
|
|
506
|
-
const min =
|
|
1172
|
+
// The opposite corner stays put; the one dragged stops at the plan's edge
|
|
1173
|
+
const min = step.value || 20
|
|
507
1174
|
const left = corner.includes('w')
|
|
508
1175
|
const top = corner[0] === 'n'
|
|
509
|
-
const
|
|
510
|
-
const
|
|
1176
|
+
const maxW = Math.max(a.width, left ? a.x + a.width : props.width - a.x)
|
|
1177
|
+
const maxH = Math.max(a.height, top ? a.y + a.height : props.height - a.y)
|
|
1178
|
+
const w = Math.min(maxW, Math.max(min, a.width + (left ? -mx : mx)))
|
|
1179
|
+
const h = Math.min(maxH, Math.max(min, a.height + (top ? -my : my)))
|
|
511
1180
|
areaDraft.value = { ...a, x: left ? a.x + a.width - w : a.x, y: top ? a.y + a.height - h : a.y, width: w, height: h }
|
|
512
1181
|
}, () => {
|
|
513
1182
|
const d = areaDraft.value!
|
|
@@ -524,14 +1193,56 @@ function onDecorDown(e: PointerEvent, d: FloorDecor, resize = false) {
|
|
|
524
1193
|
picked.value = { kind: 'decor', id: d.id }
|
|
525
1194
|
selection.value = []
|
|
526
1195
|
const s0 = decorSize(d)
|
|
527
|
-
//
|
|
528
|
-
|
|
1196
|
+
// Its turned box, so it stops at the plan's edges
|
|
1197
|
+
const rad = ((d.rotation ?? 0) * Math.PI) / 180
|
|
1198
|
+
const hw = (s0.w * Math.abs(Math.cos(rad)) + s0.h * Math.abs(Math.sin(rad))) / 2
|
|
1199
|
+
const hh = (s0.w * Math.abs(Math.sin(rad)) + s0.h * Math.abs(Math.cos(rad))) / 2
|
|
1200
|
+
const box = { x1: d.x - hw, y1: d.y - hh, x2: d.x + hw, y2: d.y + hh }
|
|
1201
|
+
follow(e, (mx, my) => {
|
|
1202
|
+
if (resize) return (decorDraft.value = resizedDecor(d, s0, mx, my))
|
|
1203
|
+
const [dx, dy] = keepIn(mx, my, box)
|
|
1204
|
+
decorDraft.value = { ...d, x: d.x + dx, y: d.y + dy }
|
|
1205
|
+
}, () => {
|
|
529
1206
|
const n = decorDraft.value!
|
|
530
1207
|
decorDraft.value = null
|
|
531
1208
|
record()
|
|
532
|
-
decor.value = decor.value.map((x) => (x.id === d.id ? (resize ?
|
|
1209
|
+
decor.value = decor.value.map((x) => (x.id === d.id ? (resize ? resizedDecor(d, s0, 0, 0, Math.round(n.width!), Math.round(n.height!)) : { ...n, x: snap(n.x), y: snap(n.y) }) : x))
|
|
533
1210
|
})
|
|
534
1211
|
}
|
|
1212
|
+
/**
|
|
1213
|
+
* Decor resized by its corner handle, dragged by (dx, dy) on the plan: the drag is read along the item's own axes
|
|
1214
|
+
* (it may be turned), its corner follows the pointer and the opposite corner stays where it was. Or straight to a
|
|
1215
|
+
* size `w` × `h`, from the same corner
|
|
1216
|
+
*/
|
|
1217
|
+
function resizedDecor(d: FloorDecor, s0: { w: number; h: number }, dx: number, dy: number, w?: number, h?: number): FloorDecor {
|
|
1218
|
+
const rad = ((d.rotation ?? 0) * Math.PI) / 180
|
|
1219
|
+
const cos = Math.cos(rad)
|
|
1220
|
+
const sin = Math.sin(rad)
|
|
1221
|
+
const width = w ?? steppedSize(s0.w, dx * cos + dy * sin, resizeStep.value, 10)
|
|
1222
|
+
const height = h ?? steppedSize(s0.h, -dx * sin + dy * cos, resizeStep.value, 6)
|
|
1223
|
+
// The middle moves half the growth, turned back onto the plan
|
|
1224
|
+
const gx = (width - s0.w) / 2
|
|
1225
|
+
const gy = (height - s0.h) / 2
|
|
1226
|
+
return { ...d, width, height, x: d.x + gx * cos - gy * sin, y: d.y + gx * sin + gy * cos }
|
|
1227
|
+
}
|
|
1228
|
+
/** The resize cursor that matches the corner handle's direction once the item is turned */
|
|
1229
|
+
const RESIZE_CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize']
|
|
1230
|
+
const resizeCursor = (deg = 0) => RESIZE_CURSORS[Math.round((((45 + deg) % 180) + 180) % 180 / 45) % 4]
|
|
1231
|
+
/** Arrows move the picked zone, decor or wall (or the wall's picked corner) by a snapping step; Shift by five */
|
|
1232
|
+
function nudgePicked(dx: number, dy: number) {
|
|
1233
|
+
const pk = picked.value!
|
|
1234
|
+
if (pk.kind === 'area') {
|
|
1235
|
+
const a = areas.value.find((x) => x.id === pk.id)
|
|
1236
|
+
if (a?.points) update('area', a.id, { ...shaped(a, a.points.map(([x, y], i) => (pk.vertex === undefined || i === pk.vertex ? [x + dx, y + dy] : [x, y]))) })
|
|
1237
|
+
else if (a) update('area', a.id, { x: a.x + dx, y: a.y + dy })
|
|
1238
|
+
} else if (pk.kind === 'decor') {
|
|
1239
|
+
const d = decor.value.find((x) => x.id === pk.id)
|
|
1240
|
+
if (d) update('decor', d.id, { x: d.x + dx, y: d.y + dy })
|
|
1241
|
+
} else {
|
|
1242
|
+
const w = walls.value.find((x) => x.id === pk.id)
|
|
1243
|
+
if (w) update('wall', w.id, { points: w.points.map(([x, y], i) => (pk.vertex === undefined || i === pk.vertex ? [x + dx, y + dy] : [x, y])) })
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
535
1246
|
const wallDraft = shallowRef<FloorWall | null>(null)
|
|
536
1247
|
const shownWalls = computed(() => walls.value.map((w) => (wallDraft.value?.id === w.id ? wallDraft.value : w)))
|
|
537
1248
|
const wallPath = (w: FloorWall) => w.points.map(([x, y], i) => `${i ? 'L' : 'M'}${x * scale.value} ${y * scale.value}`).join('')
|
|
@@ -540,13 +1251,20 @@ function onWallDown(e: PointerEvent, w: FloorWall, vertex = -1) {
|
|
|
540
1251
|
e.stopPropagation()
|
|
541
1252
|
picked.value = { kind: 'wall', id: w.id, ...(vertex >= 0 && { vertex }) }
|
|
542
1253
|
selection.value = []
|
|
543
|
-
|
|
544
|
-
|
|
1254
|
+
const box = pointsBox(w.points)
|
|
1255
|
+
follow(e, (mx, my) => {
|
|
1256
|
+
// A wall stops at the plan's edges; a corner lands on another wall's corner nearby (they join), on the plan's
|
|
1257
|
+
// edge, or on the step
|
|
1258
|
+
const [dx, dy] = keepIn(mx, my, box)
|
|
1259
|
+
wallDraft.value = vertex < 0
|
|
1260
|
+
? { ...w, points: w.points.map(([x, y]) => [x + dx, y + dy]) }
|
|
1261
|
+
: { ...w, points: w.points.map((p, i) => (i === vertex ? snapPoint(p[0] + mx, p[1] + my, { kind: 'wall', id: w.id, vertex }) : p)) }
|
|
545
1262
|
}, () => {
|
|
546
1263
|
const n = wallDraft.value!
|
|
547
1264
|
wallDraft.value = null
|
|
548
1265
|
record()
|
|
549
|
-
|
|
1266
|
+
// A moved corner already sits where it snapped (maybe on another wall's corner); a moved wall steps
|
|
1267
|
+
walls.value = walls.value.map((x) => (x.id === w.id ? (vertex >= 0 ? n : { ...n, points: n.points.map(([x, y]) => [inPlan(snap(x), x, props.width), inPlan(snap(y), y, props.height)] as [number, number]) }) : x))
|
|
550
1268
|
})
|
|
551
1269
|
}
|
|
552
1270
|
// Drawing new walls and zones
|
|
@@ -554,24 +1272,79 @@ const drawing = ref<[number, number][] | null>(null)
|
|
|
554
1272
|
const hover = ref<[number, number] | null>(null)
|
|
555
1273
|
let made = 0
|
|
556
1274
|
const newId = (p: string) => `${p}${Date.now().toString(36)}${made++}`
|
|
1275
|
+
/** The rectangle being dragged out on empty floor to select the tables it touches, in plan units */
|
|
1276
|
+
const marquee = shallowRef<{ x: number; y: number; w: number; h: number } | null>(null)
|
|
1277
|
+
/** A table's box on the plan, turned (the box around it), in plan units */
|
|
1278
|
+
function boxOf(p: { x: number; y: number; size: FloorBox; t: FloorTable }) {
|
|
1279
|
+
const rad = ((rotationOf('table', p.t.id, p.t.rotation) ?? 0) * Math.PI) / 180
|
|
1280
|
+
const c = Math.abs(Math.cos(rad))
|
|
1281
|
+
const sn = Math.abs(Math.sin(rad))
|
|
1282
|
+
const hw = (p.size.w * c + p.size.h * sn) / 2
|
|
1283
|
+
const hh = (p.size.w * sn + p.size.h * c) / 2
|
|
1284
|
+
return { x1: p.x - hw, y1: p.y - hh, x2: p.x + hw, y2: p.y + hh }
|
|
1285
|
+
}
|
|
1286
|
+
/** Empty floor: the plan itself, its zones' and walls' layers, the background — not a table, zone, wall or decor */
|
|
1287
|
+
const isFloor = (e: Event) => {
|
|
1288
|
+
const el = e.target as Element
|
|
1289
|
+
return el === e.currentTarget || el === viewEl.value || el === svgEl.value || el === zoneSvg.value || el.hasAttribute?.('data-floor-bg')
|
|
1290
|
+
}
|
|
557
1291
|
function onPlanPointer(e: PointerEvent) {
|
|
1292
|
+
// The second finger of a pinch only zooms
|
|
1293
|
+
if (gesture) return
|
|
1294
|
+
const floor = isFloor(e)
|
|
1295
|
+
const onTable = !!(e.target as Element).closest?.('[data-floor-table]')
|
|
1296
|
+
// Panning: the middle button anywhere; on empty floor (or, outside editing, on a table) once zoomed in, outside
|
|
1297
|
+
// editing or with a finger picking (while drawing, one finger draws and two pan)
|
|
1298
|
+
if (props.zoomable && (e.button === 1 || (e.button === 0 && zoomed.value > 1 && (floor || (!props.editable && onTable && !props.transferable)) && (!props.editable || (e.pointerType === 'touch' && tool.value === 'select'))))) {
|
|
1299
|
+
startPan(e)
|
|
1300
|
+
return
|
|
1301
|
+
}
|
|
558
1302
|
if (!props.editable) return
|
|
559
1303
|
if (tool.value === 'select') {
|
|
560
|
-
if (
|
|
1304
|
+
if (!floor) return
|
|
1305
|
+
const adding = e.shiftKey || e.ctrlKey || e.metaKey
|
|
1306
|
+
if (!adding) {
|
|
561
1307
|
selection.value = []
|
|
562
1308
|
picked.value = null
|
|
563
1309
|
}
|
|
1310
|
+
// A mouse or a pen drags out a rectangle (a finger scrolls, or holds a table down to add it)
|
|
1311
|
+
if (e.pointerType === 'touch' || e.button !== 0) return
|
|
1312
|
+
const p0 = toPlan(e)
|
|
1313
|
+
const before = adding ? selection.value : []
|
|
1314
|
+
follow(e, (dx, dy) => {
|
|
1315
|
+
const m = { x: Math.min(p0.x, p0.x + dx), y: Math.min(p0.y, p0.y + dy), w: Math.abs(dx), h: Math.abs(dy) }
|
|
1316
|
+
marquee.value = m
|
|
1317
|
+
const hit = placed.value.filter((p) => {
|
|
1318
|
+
const b = boxOf(p)
|
|
1319
|
+
return b.x1 < m.x + m.w && b.x2 > m.x && b.y1 < m.y + m.h && b.y2 > m.y
|
|
1320
|
+
}).map((p) => p.t.id)
|
|
1321
|
+
const next = [...new Set([...before, ...hit])]
|
|
1322
|
+
if (next.length !== selection.value.length || next.some((id, i) => id !== selection.value[i])) selection.value = next
|
|
1323
|
+
}, () => {
|
|
1324
|
+
marquee.value = null
|
|
1325
|
+
suppressClick = true
|
|
1326
|
+
setTimeout(() => (suppressClick = false))
|
|
1327
|
+
})
|
|
564
1328
|
return
|
|
565
1329
|
}
|
|
566
1330
|
const p = toPlan(e)
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
1331
|
+
if (tool.value === 'wall' || tool.value === 'polygon') {
|
|
1332
|
+
if (e.button !== 0) return
|
|
1333
|
+
const at = snapPoint(p.x, p.y)
|
|
1334
|
+
if (e.pointerType === 'touch') return drawByFinger(e, p, at)
|
|
1335
|
+
placeCorner(at)
|
|
570
1336
|
return
|
|
571
1337
|
}
|
|
1338
|
+
const at = snapPoint(p.x, p.y)
|
|
572
1339
|
const id = newId('area')
|
|
573
1340
|
areaDraft.value = { id, x: at[0], y: at[1], width: 0, height: 0 }
|
|
574
|
-
follow(e, (
|
|
1341
|
+
follow(e, (mx, my) => {
|
|
1342
|
+
// The far corner stops at the plan's edge, and lands on it nearby
|
|
1343
|
+
const [ex, ey] = snapPoint(at[0] + mx, at[1] + my)
|
|
1344
|
+
const dx = ex - at[0]
|
|
1345
|
+
const dy = ey - at[1]
|
|
1346
|
+
areaDraft.value = { id, x: Math.min(at[0], at[0] + dx), y: Math.min(at[1], at[1] + dy), width: Math.abs(dx), height: Math.abs(dy) }
|
|
1347
|
+
}, () => {
|
|
575
1348
|
const d = areaDraft.value!
|
|
576
1349
|
areaDraft.value = null
|
|
577
1350
|
if (d.width > 10 && d.height > 10) {
|
|
@@ -581,18 +1354,75 @@ function onPlanPointer(e: PointerEvent) {
|
|
|
581
1354
|
}
|
|
582
1355
|
})
|
|
583
1356
|
}
|
|
1357
|
+
const samePoint = (a: [number, number], b: [number, number]) => a[0] === b[0] && a[1] === b[1]
|
|
1358
|
+
/**
|
|
1359
|
+
* A corner of the wall or zone being drawn. A zone closes when its first corner is placed again; placing the last
|
|
1360
|
+
* corner again ends what's drawn (a double-click does the same with a mouse, a second tap there with a finger)
|
|
1361
|
+
*/
|
|
1362
|
+
function placeCorner(at: [number, number]) {
|
|
1363
|
+
const pts = drawing.value
|
|
1364
|
+
if (pts) {
|
|
1365
|
+
const n = distinct(pts).length
|
|
1366
|
+
if (tool.value === 'polygon' && n >= 3 && samePoint(at, pts[0]!)) return finishWall()
|
|
1367
|
+
if (n >= (tool.value === 'polygon' ? 3 : 2) && samePoint(at, pts[pts.length - 1]!)) return finishWall()
|
|
1368
|
+
}
|
|
1369
|
+
drawing.value = [...(pts ?? [at]), at]
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* A finger draws where it lifts, not where it lands: while it's down the next side follows it (snapped, as a mouse's
|
|
1373
|
+
* hover shows it), so it can be put right before it counts, also on a corner the finger itself covers. A tap places a
|
|
1374
|
+
* corner where it is; a second finger (a pinch) drops what this one was doing
|
|
1375
|
+
*/
|
|
1376
|
+
function drawByFinger(e: PointerEvent, p: { x: number; y: number }, at: [number, number]) {
|
|
1377
|
+
const fresh = !drawing.value
|
|
1378
|
+
if (fresh) drawing.value = [at]
|
|
1379
|
+
hover.value = at
|
|
1380
|
+
follow(e, (dx, dy) => (hover.value = snapPoint(p.x + dx, p.y + dy)), () => {
|
|
1381
|
+
const h = hover.value
|
|
1382
|
+
hover.value = null
|
|
1383
|
+
if (drawing.value && h) placeCorner(h)
|
|
1384
|
+
}, {
|
|
1385
|
+
// The first tap is the first corner, already down
|
|
1386
|
+
tap: () => {
|
|
1387
|
+
hover.value = null
|
|
1388
|
+
if (!fresh) placeCorner(at)
|
|
1389
|
+
},
|
|
1390
|
+
cancel: () => {
|
|
1391
|
+
hover.value = null
|
|
1392
|
+
if (fresh) drawing.value = null
|
|
1393
|
+
},
|
|
1394
|
+
})
|
|
1395
|
+
}
|
|
584
1396
|
function onPlanMove(e: PointerEvent) {
|
|
585
|
-
|
|
1397
|
+
// A finger's preview is its drag's
|
|
1398
|
+
if (drawing.value && e.pointerType !== 'touch') {
|
|
586
1399
|
const p = toPlan(e)
|
|
587
|
-
hover.value =
|
|
1400
|
+
hover.value = snapPoint(p.x, p.y)
|
|
588
1401
|
}
|
|
589
1402
|
}
|
|
1403
|
+
/** Corners without one repeated right after itself (a double-click places the last one twice) */
|
|
1404
|
+
const distinct = (pts: [number, number][]) => pts.filter((p, i, a) => !i || p[0] !== a[i - 1]![0] || p[1] !== a[i - 1]![1])
|
|
1405
|
+
/** Ends what's being drawn: a wall (two corners or more) or, with the polygon tool, a zone (three or more) */
|
|
590
1406
|
function finishWall() {
|
|
591
|
-
|
|
1407
|
+
let pts = drawing.value ? distinct(drawing.value) : null
|
|
592
1408
|
drawing.value = null
|
|
593
1409
|
hover.value = null
|
|
594
|
-
if (pts
|
|
595
|
-
if (
|
|
1410
|
+
if (!pts) return
|
|
1411
|
+
if (tool.value === 'polygon') {
|
|
1412
|
+
// Closing on the first corner doesn't repeat it
|
|
1413
|
+
const [f, l] = [pts[0]!, pts[pts.length - 1]!]
|
|
1414
|
+
if (pts.length > 1 && f[0] === l[0] && f[1] === l[1]) pts = pts.slice(0, -1)
|
|
1415
|
+
if (pts.length < 3) return
|
|
1416
|
+
const id = newId('area')
|
|
1417
|
+
record()
|
|
1418
|
+
areas.value = [...areas.value, shaped({ id, x: 0, y: 0, width: 0, height: 0 }, pts)]
|
|
1419
|
+
picked.value = { kind: 'area', id }
|
|
1420
|
+
return
|
|
1421
|
+
}
|
|
1422
|
+
if (pts.length > 1) {
|
|
1423
|
+
record()
|
|
1424
|
+
walls.value = [...walls.value, { id: newId('wall'), points: pts }]
|
|
1425
|
+
}
|
|
596
1426
|
}
|
|
597
1427
|
function onPlanKey(e: KeyboardEvent) {
|
|
598
1428
|
if (drawing.value && (e.key === 'Enter' || e.key === 'Escape')) {
|
|
@@ -620,6 +1450,13 @@ function onPlanKey(e: KeyboardEvent) {
|
|
|
620
1450
|
duplicate()
|
|
621
1451
|
return
|
|
622
1452
|
}
|
|
1453
|
+
const dir = ({ ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] } as Record<string, number[]>)[e.key]
|
|
1454
|
+
if (dir && picked.value && tool.value === 'select') {
|
|
1455
|
+
e.preventDefault()
|
|
1456
|
+
const by = (step.value || 1) * (e.shiftKey ? 5 : 1)
|
|
1457
|
+
nudgePicked(dir[0]! * by, dir[1]! * by)
|
|
1458
|
+
return
|
|
1459
|
+
}
|
|
623
1460
|
if (e.key !== 'Delete' && e.key !== 'Backspace') return
|
|
624
1461
|
if (!picked.value && !selection.value.length) return
|
|
625
1462
|
e.preventDefault()
|
|
@@ -632,7 +1469,16 @@ function removeSelected() {
|
|
|
632
1469
|
}
|
|
633
1470
|
const { kind, id, vertex } = picked.value
|
|
634
1471
|
record()
|
|
635
|
-
if (kind === 'area')
|
|
1472
|
+
if (kind === 'area') {
|
|
1473
|
+
const a = areas.value.find((x) => x.id === id)
|
|
1474
|
+
// A picked corner of a zone of any shape goes (it keeps at least three)
|
|
1475
|
+
if (a?.points && vertex !== undefined && a.points.length > 3) {
|
|
1476
|
+
areas.value = areas.value.map((x) => (x.id === id ? shaped(x, x.points!.filter((_, i) => i !== vertex)) : x))
|
|
1477
|
+
picked.value = { kind: 'area', id }
|
|
1478
|
+
return
|
|
1479
|
+
}
|
|
1480
|
+
areas.value = areas.value.filter((x) => x.id !== id)
|
|
1481
|
+
}
|
|
636
1482
|
if (kind === 'wall') {
|
|
637
1483
|
const w = walls.value.find((x) => x.id === id)
|
|
638
1484
|
// A picked corner goes (a wall keeps at least two); otherwise the whole wall
|
|
@@ -647,6 +1493,8 @@ function removeSelected() {
|
|
|
647
1493
|
picked.value = null
|
|
648
1494
|
}
|
|
649
1495
|
const svgEl = ref<SVGSVGElement>()
|
|
1496
|
+
const zoneSvg = ref<SVGSVGElement>()
|
|
1497
|
+
const viewEl = ref<HTMLElement>()
|
|
650
1498
|
/** Removes tables (and takes them out of their merges; a merge left with one table goes) */
|
|
651
1499
|
function removeTables(ids: (string | number)[]) {
|
|
652
1500
|
record()
|
|
@@ -658,7 +1506,13 @@ function removeTables(ids: (string | number)[]) {
|
|
|
658
1506
|
function duplicate() {
|
|
659
1507
|
const off = Math.max(20, (props.grid || 10) * 2)
|
|
660
1508
|
if (selection.value.length) {
|
|
661
|
-
const
|
|
1509
|
+
const toff = props.cellSize || off
|
|
1510
|
+
// Past it, or back the other way when it would leave the plan
|
|
1511
|
+
const by = (v: number, half: number, max: number) => (v + toff + half <= max ? v + toff : v - toff)
|
|
1512
|
+
const copies = tables.value.filter((t) => selection.value.includes(t.id)).map((t) => {
|
|
1513
|
+
const sz = sizeOf(t)
|
|
1514
|
+
return { ...t, id: newId('table'), ...clamp(t, by(t.x, sz.w / 2, props.width), by(t.y, sz.h / 2, props.height)), status: undefined, badge: undefined }
|
|
1515
|
+
})
|
|
662
1516
|
record()
|
|
663
1517
|
tables.value = [...tables.value, ...copies]
|
|
664
1518
|
selection.value = copies.map((t) => t.id)
|
|
@@ -668,14 +1522,19 @@ function duplicate() {
|
|
|
668
1522
|
if (pk?.kind === 'area') {
|
|
669
1523
|
const a = areas.value.find((x) => x.id === pk.id)
|
|
670
1524
|
if (!a) return
|
|
671
|
-
|
|
1525
|
+
// Inside the plan: back up and to the left when there's no room past it
|
|
1526
|
+
const dx = a.x + a.width + off <= props.width ? off : Math.max(-a.x, -off)
|
|
1527
|
+
const dy = a.y + a.height + off <= props.height ? off : Math.max(-a.y, -off)
|
|
1528
|
+
const c: FloorArea = a.points ? shaped({ ...a, id: newId('area') }, a.points.map(([x, y]) => [x + dx, y + dy])) : { ...a, id: newId('area'), x: a.x + dx, y: a.y + dy }
|
|
672
1529
|
record()
|
|
673
1530
|
areas.value = [...areas.value, c]
|
|
674
1531
|
picked.value = { kind: 'area', id: c.id }
|
|
675
1532
|
} else if (pk?.kind === 'decor') {
|
|
676
1533
|
const d = decor.value.find((x) => x.id === pk.id)
|
|
677
1534
|
if (!d) return
|
|
678
|
-
const
|
|
1535
|
+
const s = decorSize(d)
|
|
1536
|
+
const inside = (v: number, half: number, max: number) => (v + off + half <= max ? v + off : Math.max(half, v - off))
|
|
1537
|
+
const c = { ...d, id: newId('decor'), x: inside(d.x, s.w / 2, props.width), y: inside(d.y, s.h / 2, props.height) }
|
|
679
1538
|
record()
|
|
680
1539
|
decor.value = [...decor.value, c]
|
|
681
1540
|
picked.value = { kind: 'decor', id: c.id }
|
|
@@ -688,7 +1547,7 @@ function onRotateDown(e: PointerEvent, kind: 'table' | 'decor', id: string | num
|
|
|
688
1547
|
e.stopPropagation()
|
|
689
1548
|
e.preventDefault()
|
|
690
1549
|
const r = root.value!.getBoundingClientRect()
|
|
691
|
-
const angle = (ev: PointerEvent) => (Math.atan2(ev.clientY - (r.top + cy * scale.value), ev.clientX - (r.left + cx * scale.value)) * 180) / Math.PI + 90
|
|
1550
|
+
const angle = (ev: PointerEvent) => (Math.atan2(ev.clientY - (r.top + pan.value.y + cy * scale.value), ev.clientX - (r.left + pan.value.x + cx * scale.value)) * 180) / Math.PI + 90
|
|
692
1551
|
const mv = (ev: PointerEvent) => {
|
|
693
1552
|
if (ev.pointerId !== e.pointerId) return
|
|
694
1553
|
let deg = ((angle(ev) % 360) + 360) % 360
|
|
@@ -711,6 +1570,7 @@ function onRotateDown(e: PointerEvent, kind: 'table' | 'decor', id: string | num
|
|
|
711
1570
|
window.addEventListener('pointerup', up)
|
|
712
1571
|
window.addEventListener('pointercancel', up)
|
|
713
1572
|
}
|
|
1573
|
+
const canRotate = (kind: 'table' | 'decor') => props.rotatable === true || (Array.isArray(props.rotatable) && props.rotatable.includes(kind))
|
|
714
1574
|
const rotationOf = (kind: 'table' | 'decor', id: string | number, base?: number) => (rotateDraft.value?.kind === kind && rotateDraft.value.id === id ? rotateDraft.value.deg : base ?? 0)
|
|
715
1575
|
|
|
716
1576
|
/**
|
|
@@ -750,19 +1610,23 @@ function update(kind: FloorItemKind, id: string | number, patch: Record<string,
|
|
|
750
1610
|
if (key !== lastEdit.key || now - lastEdit.at > 1000) record()
|
|
751
1611
|
lastEdit = { key, at: now }
|
|
752
1612
|
const apply = <T extends { id: string | number }>(list: T[]) => list.map((x) => (x.id === id ? { ...x, ...patch } : x))
|
|
753
|
-
|
|
1613
|
+
// A table's patch is in your units (cells, a corner): applied to your list as it is
|
|
1614
|
+
if (kind === 'table') outerTables.value = apply(outerTables.value)
|
|
754
1615
|
else if (kind === 'area') areas.value = apply(areas.value)
|
|
755
1616
|
else if (kind === 'wall') walls.value = apply(walls.value)
|
|
756
1617
|
else decor.value = apply(decor.value)
|
|
757
1618
|
}
|
|
758
1619
|
function addTable(t: Partial<FloorTable> = {}): FloorTable {
|
|
759
1620
|
const n = Math.max(0, ...tables.value.map((x) => Number(x.label)).filter((x) => Number.isFinite(x))) + 1
|
|
760
|
-
const
|
|
1621
|
+
const draft: FloorTable = { id: newId('table'), label: String(n), x: 0, y: 0, shape: 'square', seats: 4, ...t }
|
|
1622
|
+
// A position given is in your units; otherwise the plan's middle
|
|
1623
|
+
const at = toInner(draft)
|
|
1624
|
+
const table: FloorTable = { ...draft, x: t.x !== undefined ? at.x : snapTable(props.width / 2), y: t.y !== undefined ? at.y : snapTable(props.height / 2) }
|
|
761
1625
|
record()
|
|
762
1626
|
tables.value = [...tables.value, table]
|
|
763
1627
|
selection.value = [table.id]
|
|
764
1628
|
picked.value = null
|
|
765
|
-
return table
|
|
1629
|
+
return outerOf(table)
|
|
766
1630
|
}
|
|
767
1631
|
function addDecor(kind: string, d: Partial<FloorDecor> = {}): FloorDecor {
|
|
768
1632
|
const item: FloorDecor = { id: newId('decor'), kind, x: snap(props.width / 2), y: snap(props.height / 2), ...(kinds.value[kind]?.shape === 'text' && { label: kinds.value[kind]?.label ?? kind }), ...d }
|
|
@@ -773,7 +1637,8 @@ function addDecor(kind: string, d: Partial<FloorDecor> = {}): FloorDecor {
|
|
|
773
1637
|
return item
|
|
774
1638
|
}
|
|
775
1639
|
const context: FloorPlanContext = {
|
|
776
|
-
|
|
1640
|
+
// In your units, as you keep them
|
|
1641
|
+
tables: outerTables,
|
|
777
1642
|
areas,
|
|
778
1643
|
walls,
|
|
779
1644
|
decor,
|
|
@@ -789,9 +1654,11 @@ const context: FloorPlanContext = {
|
|
|
789
1654
|
hover.value = null
|
|
790
1655
|
},
|
|
791
1656
|
kinds,
|
|
1657
|
+
tableSize: (t: FloorTable) => sizeOf(t),
|
|
1658
|
+
measure: computed(() => props.measure),
|
|
792
1659
|
statuses: computed(() => props.statuses),
|
|
793
1660
|
size: computed(() => ({ width: props.width, height: props.height })),
|
|
794
|
-
canUndo: computed(() => past.value.length > 0),
|
|
1661
|
+
canUndo: computed(() => past.value.length > 0 || !!drawing.value),
|
|
795
1662
|
canRedo: computed(() => future.value.length > 0),
|
|
796
1663
|
undo,
|
|
797
1664
|
redo,
|
|
@@ -819,44 +1686,180 @@ defineExpose({
|
|
|
819
1686
|
/** Undo / redo the plan's own edits (also Ctrl+Z, Ctrl+Shift+Z or Ctrl+Y) */
|
|
820
1687
|
undo,
|
|
821
1688
|
redo,
|
|
822
|
-
canUndo: computed(() => past.value.length > 0),
|
|
1689
|
+
canUndo: computed(() => past.value.length > 0 || !!drawing.value),
|
|
823
1690
|
canRedo: computed(() => future.value.length > 0),
|
|
824
1691
|
/** Copy the selected tables, or the picked zone or decor (also Ctrl+D) */
|
|
825
1692
|
duplicate,
|
|
826
1693
|
/** Remove tables, taking them out of their merges (Delete does it for the selection) */
|
|
827
1694
|
removeTables,
|
|
1695
|
+
/** Zoom (with `zoomable`): to a level, keeping the plan point under (px, py) in place; and centering on a plan point */
|
|
1696
|
+
zoomTo,
|
|
1697
|
+
centerOn,
|
|
1698
|
+
/** The plan as a standalone SVG string, or a PNG Blob (`pixelRatio` px per plan unit) */
|
|
1699
|
+
toSVG,
|
|
1700
|
+
toPNG,
|
|
828
1701
|
})
|
|
829
1702
|
/** Double-click on a wall: a new corner there, on the nearest segment */
|
|
830
1703
|
function onWallDblclick(e: MouseEvent, w: FloorWall) {
|
|
831
1704
|
if (!props.editable || tool.value !== 'select') return
|
|
832
1705
|
e.stopPropagation()
|
|
833
1706
|
const p = toPlan(e)
|
|
834
|
-
|
|
835
|
-
let bestD = Infinity
|
|
836
|
-
for (let i = 1; i < w.points.length; i++) {
|
|
837
|
-
const [ax, ay] = w.points[i - 1]!
|
|
838
|
-
const [bx, by] = w.points[i]!
|
|
839
|
-
const len = (bx - ax) ** 2 + (by - ay) ** 2
|
|
840
|
-
const t = len ? Math.max(0, Math.min(1, ((p.x - ax) * (bx - ax) + (p.y - ay) * (by - ay)) / len)) : 0
|
|
841
|
-
const d = Math.hypot(ax + t * (bx - ax) - p.x, ay + t * (by - ay) - p.y)
|
|
842
|
-
if (d < bestD) {
|
|
843
|
-
bestD = d
|
|
844
|
-
best = i
|
|
845
|
-
}
|
|
846
|
-
}
|
|
1707
|
+
const best = nearestSegment(w.points, p, false)
|
|
847
1708
|
const pt: [number, number] = [snap(p.x), snap(p.y)]
|
|
848
1709
|
record()
|
|
849
1710
|
walls.value = walls.value.map((x) => (x.id === w.id ? { ...x, points: [...x.points.slice(0, best), pt, ...x.points.slice(best)] } : x))
|
|
850
1711
|
picked.value = { kind: 'wall', id: w.id, vertex: best }
|
|
851
1712
|
}
|
|
852
1713
|
|
|
1714
|
+
// ── Export: the plan as a picture ──
|
|
1715
|
+
const esc = (t: unknown) => String(t ?? '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
|
|
1716
|
+
/**
|
|
1717
|
+
* The plan as a standalone SVG (plan units, its own colors resolved from the theme): zones, walls, decor, merges,
|
|
1718
|
+
* tables with their chairs and labels, and the background image if any. Icons are left out (they're a font)
|
|
1719
|
+
*/
|
|
1720
|
+
function toSVG(): string {
|
|
1721
|
+
const cs = getComputedStyle(root.value!)
|
|
1722
|
+
const v = (name: string) => cs.getPropertyValue(name).trim()
|
|
1723
|
+
// Theme variables to the colors they hold, so the file looks the same anywhere
|
|
1724
|
+
const resolve = (c: string) => c.replace(/var\((--[\w-]+)\)/g, (_, n: string) => v(n) || 'currentColor')
|
|
1725
|
+
const role = (c: string, suffix = '') => (ROLES.has(c) ? v(`--color-${c}${suffix}`) : resolve(c))
|
|
1726
|
+
const font = cs.fontFamily.replace(/"/g, "'")
|
|
1727
|
+
const out: string[] = []
|
|
1728
|
+
const W = props.width
|
|
1729
|
+
const H = props.height
|
|
1730
|
+
out.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`)
|
|
1731
|
+
out.push(`<rect width="${W}" height="${H}" fill="${esc(cs.backgroundColor)}"/>`)
|
|
1732
|
+
if (props.backgroundImage) {
|
|
1733
|
+
const b = props.backgroundBox ?? { x: 0, y: 0, width: W, height: H }
|
|
1734
|
+
out.push(`<image href="${esc(props.backgroundImage)}" x="${b.x}" y="${b.y}" width="${b.width}" height="${b.height}" opacity="${props.backgroundOpacity}" preserveAspectRatio="none"/>`)
|
|
1735
|
+
}
|
|
1736
|
+
const labelColor = v('--color-on-surface-variant')
|
|
1737
|
+
for (const a of areas.value) {
|
|
1738
|
+
const c = a.color ?? 'secondary'
|
|
1739
|
+
const fill = ROLES.has(c) ? role(c, '-container') : resolve(c)
|
|
1740
|
+
const paint = `fill="${esc(fill)}" fill-opacity="${ROLES.has(c) ? 0.45 : 0.18}" stroke="${esc(role(c))}"`
|
|
1741
|
+
if (a.points) out.push(`<polygon points="${a.points.map((p) => p.join(',')).join(' ')}" ${paint}/>`)
|
|
1742
|
+
else out.push(`<rect x="${a.x}" y="${a.y}" width="${a.width}" height="${a.height}" rx="8" ${paint}/>`)
|
|
1743
|
+
const at = a.points?.[0] ?? [a.x, a.y]
|
|
1744
|
+
if (a.label) out.push(`<text x="${at[0] + 8}" y="${at[1] + 18}" font-size="12" fill="${esc(labelColor)}">${esc(a.label)}</text>`)
|
|
1745
|
+
}
|
|
1746
|
+
const wall = v('--m3-floor-wall')
|
|
1747
|
+
for (const w of walls.value) out.push(`<polyline points="${w.points.map((p) => p.join(',')).join(' ')}" fill="none" stroke="${esc(wall)}" stroke-width="${w.thickness ?? 8}" stroke-linecap="round" stroke-linejoin="round"/>`)
|
|
1748
|
+
const planBg = cs.backgroundColor
|
|
1749
|
+
for (const d of decor.value) {
|
|
1750
|
+
const k = kindOf(d)
|
|
1751
|
+
const { w, h } = decorSize(d)
|
|
1752
|
+
const shape = k.shape ?? 'box'
|
|
1753
|
+
out.push(`<g transform="translate(${d.x} ${d.y}) rotate(${d.rotation ?? 0})${d.flip ? ' scale(-1 1)' : ''}">`)
|
|
1754
|
+
if (shape === 'text') out.push(`<text text-anchor="middle" dominant-baseline="central" font-size="16" fill="${esc(labelColor)}">${esc(d.label)}</text>`)
|
|
1755
|
+
else if (shape === 'door') {
|
|
1756
|
+
out.push(`<rect x="${-w / 2}" y="${-h / 2}" width="${w}" height="${h}" fill="${esc(k.color ? resolve(k.color) : planBg)}"/>`)
|
|
1757
|
+
out.push(`<path d="M${-w / 2} ${-h / 2} L${-w / 2} ${-h / 2 - w} A${w} ${w} 0 0 1 ${w / 2} ${-h / 2} Z" fill="${esc(wall)}" fill-opacity="0.06" stroke="${esc(wall)}" stroke-opacity="0.55" stroke-dasharray="3 3"/>`)
|
|
1758
|
+
out.push(`<line x1="${-w / 2}" y1="${-h / 2}" x2="${-w / 2}" y2="${-h / 2 - w}" stroke="${esc(wall)}" stroke-width="2"/>`)
|
|
1759
|
+
out.push(`<rect x="${-w / 2}" y="${-h / 2}" width="3" height="${h}" fill="${esc(wall)}"/><rect x="${w / 2 - 3}" y="${-h / 2}" width="3" height="${h}" fill="${esc(wall)}"/>`)
|
|
1760
|
+
} else if (shape === 'window') {
|
|
1761
|
+
out.push(`<rect x="${-w / 2}" y="${-h / 2}" width="${w}" height="${h}" fill="${esc(k.color ? resolve(k.color) : planBg)}" stroke="${esc(wall)}" stroke-width="1.5"/>`)
|
|
1762
|
+
out.push(`<line x1="${-w / 2}" y1="0" x2="${w / 2}" y2="0" stroke="${esc(v('--m3-floor-window') || v('--color-primary'))}" stroke-width="1.5"/>`)
|
|
1763
|
+
} else {
|
|
1764
|
+
const look = decorLook(k) as { background?: string }
|
|
1765
|
+
out.push(`<rect x="${-w / 2}" y="${-h / 2}" width="${w}" height="${h}" rx="${shape === 'round' ? Math.min(w, h) / 2 : shape === 'bar' ? 2 : 8}" fill="${esc(resolve(look.background ?? 'transparent'))}"/>`)
|
|
1766
|
+
if (d.label) out.push(`<text y="${h / 2 + 12}" text-anchor="middle" font-size="11" fill="${esc(labelColor)}">${esc(d.label)}</text>`)
|
|
1767
|
+
}
|
|
1768
|
+
out.push('</g>')
|
|
1769
|
+
}
|
|
1770
|
+
const merge = v('--m3-floor-merge')
|
|
1771
|
+
for (const ms of mergeShapes.value) {
|
|
1772
|
+
for (const b of ms!.clusters) out.push(`<rect x="${b.x}" y="${b.y}" width="${b.w}" height="${b.h}" rx="16" fill="none" stroke="${esc(merge)}" stroke-opacity="0.6" stroke-width="2" stroke-dasharray="6 5"/>`)
|
|
1773
|
+
for (const l of ms!.links) out.push(`<line x1="${l[0]}" y1="${l[1]}" x2="${l[2]}" y2="${l[3]}" stroke="${esc(merge)}" stroke-opacity="0.6" stroke-width="2" stroke-dasharray="6 5"/>`)
|
|
1774
|
+
}
|
|
1775
|
+
const chair = v('--m3-floor-chair')
|
|
1776
|
+
for (const p of placed.value) {
|
|
1777
|
+
const r = p.t.rotation ?? 0
|
|
1778
|
+
const lk = look(p.status)
|
|
1779
|
+
out.push(`<g transform="translate(${p.x} ${p.y}) rotate(${r})">`)
|
|
1780
|
+
p.chairs.forEach((ch, i) => {
|
|
1781
|
+
const taken = p.t.activeSeats?.includes(i + 1) ? (seatTaken(p.status) as { background: string }).background : chair
|
|
1782
|
+
out.push(`<rect x="${-CHAIR / 2}" y="${(-CHAIR * 0.75) / 2}" width="${CHAIR}" height="${CHAIR * 0.75}" rx="4" fill="${esc(resolve(taken))}" transform="translate(${ch.x} ${ch.y}) rotate(${ch.r})"/>`)
|
|
1783
|
+
})
|
|
1784
|
+
const { w, h } = p.size
|
|
1785
|
+
if ((p.t.shape ?? 'square') === 'round') out.push(`<ellipse rx="${w / 2}" ry="${h / 2}" fill="${esc(resolve(lk.background))}"/>`)
|
|
1786
|
+
else out.push(`<rect x="${-w / 2}" y="${-h / 2}" width="${w}" height="${h}" rx="8" fill="${esc(resolve(lk.background))}"/>`)
|
|
1787
|
+
out.push(`<text transform="rotate(${-r})" text-anchor="middle" dominant-baseline="central" font-size="14" font-weight="500" fill="${esc(resolve(lk.color))}">${esc(p.t.label)}</text>`)
|
|
1788
|
+
out.push('</g>')
|
|
1789
|
+
}
|
|
1790
|
+
out.push('</svg>')
|
|
1791
|
+
return out.join('')
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* The plan as a PNG, `pixelRatio` px per plan unit. A background image from another origin without CORS taints the
|
|
1795
|
+
* canvas, and then this rejects
|
|
1796
|
+
*/
|
|
1797
|
+
async function toPNG(pixelRatio = 2): Promise<Blob> {
|
|
1798
|
+
const img = new Image()
|
|
1799
|
+
img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(toSVG())}`
|
|
1800
|
+
await img.decode()
|
|
1801
|
+
const canvas = document.createElement('canvas')
|
|
1802
|
+
canvas.width = Math.round(props.width * pixelRatio)
|
|
1803
|
+
canvas.height = Math.round(props.height * pixelRatio)
|
|
1804
|
+
canvas.getContext('2d')!.drawImage(img, 0, 0, canvas.width, canvas.height)
|
|
1805
|
+
return new Promise((res, rej) => canvas.toBlob((b) => (b ? res(b) : rej(new Error('toPNG: the canvas gave no image'))), 'image/png'))
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
// ── Measurements: lengths in your unit while editing ──
|
|
1809
|
+
const measured = (v: number) => {
|
|
1810
|
+
const m = props.measure!
|
|
1811
|
+
return `${(v / m.per).toFixed(m.decimals ?? 2)} ${m.unit}`
|
|
1812
|
+
}
|
|
1813
|
+
const measureLabels = computed(() => {
|
|
1814
|
+
const out: { x: number; y: number; text: string }[] = []
|
|
1815
|
+
if (!props.measure || !props.editable) return out
|
|
1816
|
+
const sides = (pts: [number, number][], closed: boolean) => {
|
|
1817
|
+
const n = closed ? pts.length : pts.length - 1
|
|
1818
|
+
for (let i = 0; i < n; i++) {
|
|
1819
|
+
const [ax, ay] = pts[i]!
|
|
1820
|
+
const [bx, by] = pts[(i + 1) % pts.length]!
|
|
1821
|
+
const len = Math.hypot(bx - ax, by - ay)
|
|
1822
|
+
if (len > 0) out.push({ x: (ax + bx) / 2, y: (ay + by) / 2, text: measured(len) })
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
const pk = picked.value
|
|
1826
|
+
if (pk?.kind === 'wall') {
|
|
1827
|
+
const w = shownWalls.value.find((x) => x.id === pk.id)
|
|
1828
|
+
if (w) sides(w.points, false)
|
|
1829
|
+
} else if (pk?.kind === 'area') {
|
|
1830
|
+
const a = shownAreas.value.find((x) => x.id === pk.id)
|
|
1831
|
+
if (a) sides(a.points ?? rectCorners(a), true)
|
|
1832
|
+
} else if (pk?.kind === 'decor') {
|
|
1833
|
+
const d = shownDecor.value.find((x) => x.id === pk.id)
|
|
1834
|
+
if (d) {
|
|
1835
|
+
const sz = decorSize(d)
|
|
1836
|
+
out.push({ x: d.x, y: d.y + Math.max(sz.w, sz.h) / 2 + 14 / scale.value, text: `${measured(sz.w)} × ${measured(sz.h)}` })
|
|
1837
|
+
}
|
|
1838
|
+
} else if (selection.value.length === 1) {
|
|
1839
|
+
const p = placed.value.find((x) => x.t.id === selection.value[0])
|
|
1840
|
+
if (p) out.push({ x: p.x, y: boxOf(p).y2 + (props.chairs && p.t.seats ? CHAIR + 12 : 12) / scale.value, text: `${measured(p.size.w)} × ${measured(p.size.h)}` })
|
|
1841
|
+
}
|
|
1842
|
+
if (drawing.value && hover.value) {
|
|
1843
|
+
const last = drawing.value[drawing.value.length - 1]!
|
|
1844
|
+
sides([last, hover.value], false)
|
|
1845
|
+
}
|
|
1846
|
+
return out
|
|
1847
|
+
})
|
|
853
1848
|
const ariaOf = (p: (typeof placed.value)[number]) =>
|
|
854
|
-
[p.t.label, p.status?.label, p.t.seats ? locale.floorSeats.replace('{n}', String(p.t.seats)) : '', p.t.badge !== undefined ? String(p.t.badge) : ''].filter(Boolean).join(', ')
|
|
1849
|
+
[p.t.label, p.status?.label, p.t.seats ? locale.floorSeats.replace('{n}', String(p.t.seats)) : '', p.t.badge !== undefined ? String(p.t.badge) : '', overlapping.value.has(p.t.id) ? locale.floorOverlaps : ''].filter(Boolean).join(', ')
|
|
1850
|
+
// A radial gradient draws its dot in the middle of each tile: moved back half a tile so the dots sit on the points
|
|
855
1851
|
const gridStyle = computed(() => {
|
|
1852
|
+
if (!props.editable || !props.showGrid || !props.grid) return {}
|
|
856
1853
|
const g = (props.grid >= 10 ? props.grid : props.grid * Math.ceil(10 / Math.max(1, props.grid))) * scale.value
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
1854
|
+
const dot = 'radial-gradient(circle, var(--color-outline-variant) 1px, transparent 1.2px)'
|
|
1855
|
+
const sub = Math.max(1, Math.round(props.subgrid))
|
|
1856
|
+
const fine = g / sub
|
|
1857
|
+
if (sub === 1 || props.grid < 10 || fine < 6) return { backgroundImage: dot, backgroundSize: `${g}px ${g}px`, backgroundPosition: `${-g / 2}px ${-g / 2}px` }
|
|
1858
|
+
return {
|
|
1859
|
+
backgroundImage: `${dot}, radial-gradient(circle, color-mix(in srgb, var(--color-outline-variant) 70%, transparent) 0.6px, transparent 0.9px)`,
|
|
1860
|
+
backgroundSize: `${g}px ${g}px, ${fine}px ${fine}px`,
|
|
1861
|
+
backgroundPosition: `${-g / 2}px ${-g / 2}px, ${-fine / 2}px ${-fine / 2}px`,
|
|
1862
|
+
}
|
|
860
1863
|
})
|
|
861
1864
|
</script>
|
|
862
1865
|
|
|
@@ -864,7 +1867,7 @@ const gridStyle = computed(() => {
|
|
|
864
1867
|
<div
|
|
865
1868
|
ref="root"
|
|
866
1869
|
class="m3-floor-plan select-none"
|
|
867
|
-
:style="{ aspectRatio: `${width} / ${height}`,
|
|
1870
|
+
:style="{ aspectRatio: `${width} / ${height}`, touchAction }"
|
|
868
1871
|
role="group"
|
|
869
1872
|
tabindex="-1"
|
|
870
1873
|
:aria-label="label ?? locale.floorPlan"
|
|
@@ -874,14 +1877,36 @@ const gridStyle = computed(() => {
|
|
|
874
1877
|
@dblclick="drawing && finishWall()"
|
|
875
1878
|
@keydown="onPlanKey"
|
|
876
1879
|
>
|
|
1880
|
+
<!-- Everything on the plan, as big as the zoom makes it, moved by the pan -->
|
|
1881
|
+
<div
|
|
1882
|
+
ref="viewEl"
|
|
1883
|
+
class="m3-floor-view absolute top-0 left-0"
|
|
1884
|
+
:style="{ width: `${width * scale}px`, height: `${height * scale}px`, transform: pan.x || pan.y ? `translate(${pan.x}px, ${pan.y}px)` : undefined, ...gridStyle }"
|
|
1885
|
+
>
|
|
1886
|
+
<img
|
|
1887
|
+
v-if="backgroundImage"
|
|
1888
|
+
:src="backgroundImage"
|
|
1889
|
+
alt=""
|
|
1890
|
+
draggable="false"
|
|
1891
|
+
data-floor-bg
|
|
1892
|
+
class="absolute max-w-none select-none"
|
|
1893
|
+
:style="{
|
|
1894
|
+
left: `${(backgroundBox?.x ?? 0) * scale}px`,
|
|
1895
|
+
top: `${(backgroundBox?.y ?? 0) * scale}px`,
|
|
1896
|
+
width: `${(backgroundBox?.width ?? width) * scale}px`,
|
|
1897
|
+
height: `${(backgroundBox?.height ?? height) * scale}px`,
|
|
1898
|
+
opacity: backgroundOpacity,
|
|
1899
|
+
}"
|
|
1900
|
+
/>
|
|
877
1901
|
<!-- Zones -->
|
|
878
1902
|
<div
|
|
879
|
-
v-for="a in shownAreas"
|
|
1903
|
+
v-for="a in shownAreas.filter((x) => !x.points)"
|
|
880
1904
|
:key="`a${a.id}`"
|
|
881
1905
|
class="absolute rounded-lg border"
|
|
882
1906
|
:class="[editable && tool === 'select' ? 'cursor-move touch-none' : 'pointer-events-none', isPicked('area', a.id) && 'ring-2 ring-primary']"
|
|
883
1907
|
:style="{ left: `${a.x * scale}px`, top: `${a.y * scale}px`, width: `${a.width * scale}px`, height: `${a.height * scale}px`, ...areaLook(a.color) }"
|
|
884
1908
|
@pointerdown="onAreaDown($event, a, null)"
|
|
1909
|
+
@dblclick="onAreaDblclick($event, a)"
|
|
885
1910
|
>
|
|
886
1911
|
<slot name="area" :area="a" :picked="isPicked('area', a.id)" :scale="scale">
|
|
887
1912
|
<span v-if="a.label" class="absolute top-1 left-2 text-label-medium text-on-surface-variant">{{ a.label }}</span>
|
|
@@ -898,9 +1923,67 @@ const gridStyle = computed(() => {
|
|
|
898
1923
|
</template>
|
|
899
1924
|
</div>
|
|
900
1925
|
|
|
1926
|
+
<!-- Zones of any shape: their outline, then their label (or your #area) in the box around them -->
|
|
1927
|
+
<svg ref="zoneSvg" class="pointer-events-none absolute inset-0 size-full overflow-visible">
|
|
1928
|
+
<g v-for="a in shownAreas.filter((x) => x.points)" :key="`ap${a.id}`">
|
|
1929
|
+
<path
|
|
1930
|
+
:d="polyPath(a.points!)"
|
|
1931
|
+
stroke-width="1"
|
|
1932
|
+
stroke-linejoin="round"
|
|
1933
|
+
:style="areaSvgLook(a.color)"
|
|
1934
|
+
:class="[editable && tool === 'select' && 'pointer-events-auto cursor-move touch-none', isPicked('area', a.id) && 'm3-floor-zone-picked']"
|
|
1935
|
+
:data-zone="a.id"
|
|
1936
|
+
@pointerdown="onAreaDown($event, a, null)"
|
|
1937
|
+
@dblclick="onAreaDblclick($event, a)"
|
|
1938
|
+
/>
|
|
1939
|
+
<template v-if="editable && isPicked('area', a.id)">
|
|
1940
|
+
<circle
|
|
1941
|
+
v-for="(pt, i) in a.points"
|
|
1942
|
+
:key="i"
|
|
1943
|
+
:cx="pt[0] * scale"
|
|
1944
|
+
:cy="pt[1] * scale"
|
|
1945
|
+
:r="(picked?.vertex === i ? 7 : 5) * (coarse ? 1.6 : 1)"
|
|
1946
|
+
class="pointer-events-auto cursor-move touch-none stroke-primary"
|
|
1947
|
+
:class="picked?.vertex === i ? 'fill-primary' : 'fill-surface'"
|
|
1948
|
+
stroke-width="2"
|
|
1949
|
+
:data-zone-corner="i"
|
|
1950
|
+
@pointerdown="onAreaVertexDown($event, a, i)"
|
|
1951
|
+
/>
|
|
1952
|
+
</template>
|
|
1953
|
+
</g>
|
|
1954
|
+
</svg>
|
|
1955
|
+
<div
|
|
1956
|
+
v-for="a in shownAreas.filter((x) => x.points)"
|
|
1957
|
+
:key="`al${a.id}`"
|
|
1958
|
+
class="pointer-events-none absolute"
|
|
1959
|
+
:style="{ left: `${a.x * scale}px`, top: `${a.y * scale}px`, width: `${a.width * scale}px`, height: `${a.height * scale}px` }"
|
|
1960
|
+
>
|
|
1961
|
+
<slot name="area" :area="a" :picked="isPicked('area', a.id)" :scale="scale">
|
|
1962
|
+
<span
|
|
1963
|
+
v-if="a.label"
|
|
1964
|
+
class="absolute text-label-medium whitespace-nowrap text-on-surface-variant"
|
|
1965
|
+
:style="{ left: `${(a.points![0]![0] - a.x) * scale + 8}px`, top: `${(a.points![0]![1] - a.y) * scale + 4}px` }"
|
|
1966
|
+
>{{ a.label }}</span>
|
|
1967
|
+
</slot>
|
|
1968
|
+
</div>
|
|
1969
|
+
|
|
901
1970
|
<!-- Walls -->
|
|
902
1971
|
<svg ref="svgEl" class="pointer-events-none absolute inset-0 size-full overflow-visible">
|
|
903
1972
|
<g v-for="w in shownWalls" :key="`w${w.id}`">
|
|
1973
|
+
<!-- With a finger, a wall is a thin line: a wider, unseen band takes the touch -->
|
|
1974
|
+
<path
|
|
1975
|
+
v-if="coarse && editable && tool === 'select'"
|
|
1976
|
+
:d="wallPath(w)"
|
|
1977
|
+
fill="none"
|
|
1978
|
+
stroke="transparent"
|
|
1979
|
+
stroke-linecap="round"
|
|
1980
|
+
stroke-linejoin="round"
|
|
1981
|
+
class="pointer-events-auto cursor-move touch-none"
|
|
1982
|
+
data-wall-hit
|
|
1983
|
+
:stroke-width="Math.max((w.thickness ?? 8) * scale, 28)"
|
|
1984
|
+
@pointerdown="onWallDown($event, w)"
|
|
1985
|
+
@dblclick="onWallDblclick($event, w)"
|
|
1986
|
+
/>
|
|
904
1987
|
<path
|
|
905
1988
|
:d="wallPath(w)"
|
|
906
1989
|
fill="none"
|
|
@@ -927,7 +2010,14 @@ const gridStyle = computed(() => {
|
|
|
927
2010
|
</template>
|
|
928
2011
|
</g>
|
|
929
2012
|
<path
|
|
930
|
-
v-if="drawing"
|
|
2013
|
+
v-if="drawing && tool === 'polygon'"
|
|
2014
|
+
:d="polyPath(hover ? [...drawing, hover] : drawing)"
|
|
2015
|
+
class="m3-floor-zone-draft stroke-primary"
|
|
2016
|
+
stroke-dasharray="6 4"
|
|
2017
|
+
stroke-width="2"
|
|
2018
|
+
/>
|
|
2019
|
+
<path
|
|
2020
|
+
v-else-if="drawing"
|
|
931
2021
|
:d="wallPath({ id: 'new', points: hover ? [...drawing, hover] : drawing })"
|
|
932
2022
|
fill="none"
|
|
933
2023
|
class="stroke-primary"
|
|
@@ -952,17 +2042,35 @@ const gridStyle = computed(() => {
|
|
|
952
2042
|
@pointerdown="onDecorDown($event, d)"
|
|
953
2043
|
>
|
|
954
2044
|
<slot name="decor" :item="d" :kind="kindOf(d)" :picked="isPicked('decor', d.id)" :scale="scale">
|
|
955
|
-
|
|
2045
|
+
<!-- A door: the jambs, the leaf standing open and its swing, as an architect draws it -->
|
|
2046
|
+
<svg
|
|
2047
|
+
v-if="kindOf(d).shape === 'door'"
|
|
2048
|
+
class="pointer-events-none absolute inset-0 size-full overflow-visible"
|
|
2049
|
+
:style="d.flip ? { transform: 'scaleX(-1)' } : undefined"
|
|
2050
|
+
aria-hidden="true"
|
|
2051
|
+
>
|
|
2052
|
+
<path :d="doorSwing(decorSize(d).w * scale)" class="m3-floor-door-swing" stroke-width="1" stroke-dasharray="3 3" />
|
|
2053
|
+
<line x1="0" y1="0" x2="0" :y2="-decorSize(d).w * scale" class="m3-floor-door" stroke-width="2" stroke-linecap="round" />
|
|
2054
|
+
<rect x="0" y="0" :width="Math.max(2, 3 * scale)" height="100%" class="m3-floor-door-jamb" />
|
|
2055
|
+
<rect :x="decorSize(d).w * scale - Math.max(2, 3 * scale)" y="0" :width="Math.max(2, 3 * scale)" height="100%" class="m3-floor-door-jamb" />
|
|
2056
|
+
</svg>
|
|
2057
|
+
<!-- A window: its frame and the pane down the middle -->
|
|
2058
|
+
<svg v-else-if="kindOf(d).shape === 'window'" class="pointer-events-none absolute inset-0 size-full overflow-visible" aria-hidden="true">
|
|
2059
|
+
<rect x="0.75" y="0.75" :width="Math.max(0, decorSize(d).w * scale - 1.5)" :height="Math.max(0, decorSize(d).h * scale - 1.5)" class="m3-floor-window" stroke-width="1.5" fill="none" />
|
|
2060
|
+
<line x1="0" :y1="(decorSize(d).h * scale) / 2" :x2="decorSize(d).w * scale" :y2="(decorSize(d).h * scale) / 2" class="m3-floor-window-pane" stroke-width="1.5" />
|
|
2061
|
+
</svg>
|
|
2062
|
+
<MIcon v-else-if="kindOf(d).icon && kindOf(d).shape !== 'bar'" :name="kindOf(d).icon!" :size="Math.max(12, Math.min(decorSize(d).w, decorSize(d).h) * 0.6 * scale)" />
|
|
956
2063
|
<span v-if="kindOf(d).shape === 'text'" class="truncate text-title-small text-on-surface-variant" :style="{ fontSize: `${Math.max(10, 16 * scale)}px` }">{{ d.label }}</span>
|
|
957
2064
|
</slot>
|
|
958
2065
|
<span
|
|
959
2066
|
v-if="editable && isPicked('decor', d.id)"
|
|
960
|
-
class="m3-floor-handle absolute -right-1.5 -bottom-1.5 size-3
|
|
2067
|
+
class="m3-floor-handle absolute -right-1.5 -bottom-1.5 size-3 rounded-xs border-2 border-primary bg-surface"
|
|
2068
|
+
:style="{ cursor: resizeCursor(rotationOf('decor', d.id, d.rotation)) }"
|
|
961
2069
|
data-resize
|
|
962
2070
|
@pointerdown="onDecorDown($event, d, true)"
|
|
963
2071
|
/>
|
|
964
2072
|
<span
|
|
965
|
-
v-if="editable &&
|
|
2073
|
+
v-if="editable && canRotate('decor') && isPicked('decor', d.id)"
|
|
966
2074
|
class="m3-floor-handle absolute -top-6 left-1/2 size-3.5 -translate-x-1/2 cursor-grab rounded-full border-2 border-primary bg-surface"
|
|
967
2075
|
:aria-label="locale.floorRotate"
|
|
968
2076
|
data-rotate
|
|
@@ -1004,44 +2112,74 @@ const gridStyle = computed(() => {
|
|
|
1004
2112
|
v-for="p in placed"
|
|
1005
2113
|
:key="p.t.id"
|
|
1006
2114
|
class="absolute"
|
|
1007
|
-
:class="!draft?.has(p.t.id) && 'transition-[left,top] duration-200 ease-out'"
|
|
2115
|
+
:class="!draft?.has(p.t.id) && !rescaling && 'transition-[left,top] duration-200 ease-out'"
|
|
1008
2116
|
:style="{ left: `${p.x * scale}px`, top: `${p.y * scale}px`, transform: `rotate(${rotationOf('table', p.t.id, p.t.rotation)}deg)` }"
|
|
1009
2117
|
>
|
|
1010
2118
|
<!-- Rotation handle of the one table picked while editing -->
|
|
1011
2119
|
<span
|
|
1012
|
-
v-if="editable &&
|
|
2120
|
+
v-if="editable && canRotate('table') && selection.length === 1 && selection[0] === p.t.id && tool === 'select'"
|
|
1013
2121
|
class="m3-floor-handle absolute z-10 size-3.5 -translate-x-1/2 -translate-y-1/2 cursor-grab rounded-full border-2 border-primary bg-surface"
|
|
1014
2122
|
:style="{ left: '0px', top: `${-(p.size.h / 2 + CHAIR + 18) * scale}px` }"
|
|
1015
2123
|
:aria-label="locale.floorRotate"
|
|
1016
2124
|
data-rotate
|
|
1017
2125
|
@pointerdown="onRotateDown($event, 'table', p.t.id, p.x, p.y)"
|
|
1018
2126
|
/>
|
|
2127
|
+
<!-- Size handle of the one table picked while editing (at its corner, turning with it) -->
|
|
2128
|
+
<span
|
|
2129
|
+
v-if="editable && resizable && selection.length === 1 && selection[0] === p.t.id && tool === 'select'"
|
|
2130
|
+
class="m3-floor-handle absolute z-10 size-3 -translate-x-1/2 -translate-y-1/2 rounded-xs border-2 border-primary bg-surface"
|
|
2131
|
+
:style="{ left: `${(p.size.w / 2) * scale}px`, top: `${(p.size.h / 2) * scale}px`, cursor: resizeCursor(rotationOf('table', p.t.id, p.t.rotation)) }"
|
|
2132
|
+
data-table-resize
|
|
2133
|
+
@pointerdown="onTableResize($event, p.t)"
|
|
2134
|
+
/>
|
|
1019
2135
|
<span
|
|
1020
2136
|
v-for="(ch, i) in p.chairs"
|
|
1021
2137
|
:key="i"
|
|
1022
|
-
class="m3-floor-chair
|
|
1023
|
-
:
|
|
1024
|
-
|
|
2138
|
+
class="m3-floor-chair absolute flex items-center justify-center rounded-md"
|
|
2139
|
+
:class="[seatNumbers && !editable ? 'cursor-pointer' : 'pointer-events-none', p.t.activeSeats?.includes(i + 1) && 'm3-floor-chair-taken']"
|
|
2140
|
+
:style="{
|
|
2141
|
+
width: `${CHAIR * scale}px`,
|
|
2142
|
+
height: `${CHAIR * 0.75 * scale}px`,
|
|
2143
|
+
left: `${ch.x * scale}px`,
|
|
2144
|
+
top: `${ch.y * scale}px`,
|
|
2145
|
+
transform: `translate(-50%, -50%) rotate(${ch.r}deg)`,
|
|
2146
|
+
...(p.t.activeSeats?.includes(i + 1) && seatTaken(p.status)),
|
|
2147
|
+
}"
|
|
2148
|
+
:data-seat="i + 1"
|
|
2149
|
+
:aria-label="seatNumbers ? locale.floorSeatN.replace('{n}', String(i + 1)) : undefined"
|
|
2150
|
+
@click="seatNumbers && !editable && emit('seat-click', outerOf(p.t), i + 1, $event)"
|
|
2151
|
+
>
|
|
2152
|
+
<span
|
|
2153
|
+
v-if="seatNumbers && scale * CHAIR >= 10"
|
|
2154
|
+
class="pointer-events-none leading-none font-medium"
|
|
2155
|
+
:style="{ fontSize: `${Math.max(7, 9 * scale)}px`, transform: `rotate(${-ch.r - rotationOf('table', p.t.id, p.t.rotation)}deg)` }"
|
|
2156
|
+
>{{ i + 1 }}</span>
|
|
2157
|
+
</span>
|
|
1025
2158
|
<div
|
|
1026
2159
|
role="button"
|
|
1027
2160
|
tabindex="0"
|
|
2161
|
+
data-floor-table
|
|
1028
2162
|
class="absolute flex -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center gap-0.5 text-center shadow-elevation-1 outline-none transition-[box-shadow] duration-150 focus-visible:ring-2 focus-visible:ring-secondary"
|
|
1029
2163
|
:class="[
|
|
1030
2164
|
(p.t.shape ?? 'square') === 'round' ? 'rounded-full' : 'rounded-lg',
|
|
1031
2165
|
editable ? 'cursor-grab touch-none active:cursor-grabbing' : 'cursor-pointer hover:shadow-elevation-2',
|
|
1032
2166
|
selection.includes(p.t.id) && 'ring-2 ring-primary',
|
|
1033
2167
|
draft?.has(p.t.id) && 'shadow-elevation-3',
|
|
2168
|
+
transferDrag?.id === p.t.id && 'opacity-50',
|
|
2169
|
+
overlapping.has(p.t.id) && 'm3-floor-overlap',
|
|
2170
|
+
transferDrag?.over === p.t.id && (transferDrag.ok ? 'ring-4 ring-primary' : 'ring-4 ring-error'),
|
|
1034
2171
|
]"
|
|
1035
2172
|
:style="{ width: `${p.size.w * scale}px`, height: `${p.size.h * scale}px`, ...look(p.status), fontSize: `${Math.max(9, 14 * scale)}px` }"
|
|
1036
2173
|
:aria-label="ariaOf(p)"
|
|
1037
2174
|
:aria-pressed="editable ? selection.includes(p.t.id) : undefined"
|
|
1038
2175
|
@pointerdown="onDown($event, p.t)"
|
|
2176
|
+
@contextmenu="transferable && !editable && $event.preventDefault()"
|
|
1039
2177
|
@click="onClick($event, p.t)"
|
|
1040
2178
|
@keydown="onKey($event, p.t)"
|
|
1041
2179
|
>
|
|
1042
2180
|
<!-- The inside stays upright however the table turns -->
|
|
1043
2181
|
<span class="flex flex-col items-center justify-center gap-0.5" :style="{ transform: `rotate(${-rotationOf('table', p.t.id, p.t.rotation)}deg)` }">
|
|
1044
|
-
<slot name="table" :table="p.t" :status="p.status" :selected="selection.includes(p.t.id)">
|
|
2182
|
+
<slot name="table" :table="outerOf(p.t)" :status="p.status" :selected="selection.includes(p.t.id)">
|
|
1045
2183
|
<MIcon v-if="p.status?.icon && scale > 0.5" :name="p.status.icon" :size="Math.max(12, 18 * scale)" class="opacity-80" />
|
|
1046
2184
|
<span class="max-w-full truncate px-1 leading-tight font-medium">{{ p.t.label }}</span>
|
|
1047
2185
|
</slot>
|
|
@@ -1053,14 +2191,41 @@ const gridStyle = computed(() => {
|
|
|
1053
2191
|
>{{ p.t.badge }}</span>
|
|
1054
2192
|
</div>
|
|
1055
2193
|
</div>
|
|
2194
|
+
<!-- A table being carried to another one (its party moves there) -->
|
|
2195
|
+
<div
|
|
2196
|
+
v-if="transferDrag"
|
|
2197
|
+
class="m3-floor-carry pointer-events-none absolute z-20 flex -translate-x-1/2 -translate-y-1/2 items-center gap-1 rounded-full px-3 py-1.5 text-label-large shadow-elevation-3"
|
|
2198
|
+
:style="{ left: `${transferDrag.x * scale}px`, top: `${transferDrag.y * scale}px` }"
|
|
2199
|
+
><MIcon name="move_down" :size="18" />{{ transferDrag.label }}</div>
|
|
2200
|
+
<!-- Lengths in your unit (measure) -->
|
|
2201
|
+
<span
|
|
2202
|
+
v-for="(m, i) in measureLabels"
|
|
2203
|
+
:key="`ms${i}`"
|
|
2204
|
+
class="m3-floor-measure pointer-events-none absolute z-20 -translate-x-1/2 -translate-y-1/2 rounded-full px-1.5 py-px text-label-small whitespace-nowrap"
|
|
2205
|
+
:style="{ left: `${m.x * scale}px`, top: `${m.y * scale}px` }"
|
|
2206
|
+
>{{ m.text }}</span>
|
|
2207
|
+
<!-- The rectangle a mouse drags out to select tables -->
|
|
2208
|
+
<div
|
|
2209
|
+
v-if="marquee"
|
|
2210
|
+
class="m3-floor-marquee pointer-events-none absolute rounded-xs border border-dashed"
|
|
2211
|
+
:style="{ left: `${marquee.x * scale}px`, top: `${marquee.y * scale}px`, width: `${marquee.w * scale}px`, height: `${marquee.h * scale}px` }"
|
|
2212
|
+
/>
|
|
1056
2213
|
<!-- Anything of yours over the plan, placed in plan units with toPx -->
|
|
1057
2214
|
<slot name="overlay" :scale="scale" :to-px="(v: number) => v * scale" />
|
|
2215
|
+
</div>
|
|
2216
|
+
<!-- Zoom: in, out, the whole plan (they don't move with the pan) -->
|
|
2217
|
+
<div v-if="zoomable && zoomControls" class="m3-floor-zoom absolute right-2 bottom-2 flex flex-col overflow-hidden rounded-full shadow-elevation-1" @pointerdown.stop>
|
|
2218
|
+
<button type="button" class="m3-floor-zoom-btn" :aria-label="locale.floorZoomIn" :disabled="zoomed >= maxZoom" @click="zoomTo(zoomed * 1.5)"><MIcon name="add" :size="20" /></button>
|
|
2219
|
+
<button type="button" class="m3-floor-zoom-btn" :aria-label="locale.floorZoomOut" :disabled="zoomed <= 1" @click="zoomTo(zoomed / 1.5)"><MIcon name="remove" :size="20" /></button>
|
|
2220
|
+
<button type="button" class="m3-floor-zoom-btn" :aria-label="locale.floorZoomFit" :disabled="zoomed <= 1" @click="zoomTo(1)"><MIcon name="fit_screen" :size="20" /></button>
|
|
2221
|
+
</div>
|
|
1058
2222
|
</div>
|
|
1059
2223
|
</template>
|
|
1060
2224
|
|
|
1061
2225
|
<style>
|
|
1062
2226
|
/* Defaults a consumer's own utilities override: none on the root itself. The colors are custom properties to restyle:
|
|
1063
|
-
--m3-floor-wall, --m3-floor-wall-picked, --m3-floor-
|
|
2227
|
+
--m3-floor-wall (walls, doors, window frames), --m3-floor-wall-picked, --m3-floor-window (a window's pane),
|
|
2228
|
+
--m3-floor-chair, --m3-floor-merge, --m3-floor-merge-label */
|
|
1064
2229
|
@layer base {
|
|
1065
2230
|
.m3-floor-plan {
|
|
1066
2231
|
--m3-floor-wall: var(--color-on-surface-variant);
|
|
@@ -1096,8 +2261,79 @@ const gridStyle = computed(() => {
|
|
|
1096
2261
|
.m3-floor-wall-picked {
|
|
1097
2262
|
stroke: var(--m3-floor-wall-picked);
|
|
1098
2263
|
}
|
|
2264
|
+
.m3-floor-door {
|
|
2265
|
+
stroke: var(--m3-floor-wall);
|
|
2266
|
+
}
|
|
2267
|
+
.m3-floor-door-jamb {
|
|
2268
|
+
fill: var(--m3-floor-wall);
|
|
2269
|
+
}
|
|
2270
|
+
.m3-floor-door-swing {
|
|
2271
|
+
stroke: color-mix(in srgb, var(--m3-floor-wall) 55%, transparent);
|
|
2272
|
+
fill: color-mix(in srgb, var(--m3-floor-wall) 6%, transparent);
|
|
2273
|
+
}
|
|
2274
|
+
.m3-floor-window {
|
|
2275
|
+
stroke: var(--m3-floor-wall);
|
|
2276
|
+
}
|
|
2277
|
+
.m3-floor-window-pane {
|
|
2278
|
+
stroke: var(--m3-floor-window, var(--color-primary));
|
|
2279
|
+
}
|
|
2280
|
+
.m3-floor-view {
|
|
2281
|
+
/* Doors and windows take this color to cut the wall they sit on */
|
|
2282
|
+
background-color: inherit;
|
|
2283
|
+
}
|
|
2284
|
+
.m3-floor-carry {
|
|
2285
|
+
background: var(--color-inverse-surface);
|
|
2286
|
+
color: var(--color-inverse-on-surface);
|
|
2287
|
+
}
|
|
2288
|
+
.m3-floor-zone-picked {
|
|
2289
|
+
stroke: var(--color-primary);
|
|
2290
|
+
stroke-width: 2;
|
|
2291
|
+
}
|
|
2292
|
+
.m3-floor-zone-draft {
|
|
2293
|
+
fill: color-mix(in srgb, var(--color-primary) 8%, transparent);
|
|
2294
|
+
}
|
|
2295
|
+
/* On a pseudo-element: the table's own outline and shadow are utilities, which win over this layer */
|
|
2296
|
+
.m3-floor-overlap::after {
|
|
2297
|
+
content: '';
|
|
2298
|
+
position: absolute;
|
|
2299
|
+
inset: -5px;
|
|
2300
|
+
border: 2px dashed var(--color-error);
|
|
2301
|
+
border-radius: inherit;
|
|
2302
|
+
pointer-events: none;
|
|
2303
|
+
}
|
|
2304
|
+
.m3-floor-measure {
|
|
2305
|
+
background: var(--color-inverse-surface);
|
|
2306
|
+
color: var(--color-inverse-on-surface);
|
|
2307
|
+
}
|
|
2308
|
+
.m3-floor-marquee {
|
|
2309
|
+
border-color: var(--color-primary);
|
|
2310
|
+
background: color-mix(in srgb, var(--color-primary) 8%, transparent);
|
|
2311
|
+
}
|
|
2312
|
+
.m3-floor-zoom {
|
|
2313
|
+
background: var(--color-surface-container-high);
|
|
2314
|
+
}
|
|
2315
|
+
.m3-floor-zoom-btn {
|
|
2316
|
+
display: flex;
|
|
2317
|
+
width: 40px;
|
|
2318
|
+
height: 40px;
|
|
2319
|
+
align-items: center;
|
|
2320
|
+
justify-content: center;
|
|
2321
|
+
color: var(--color-on-surface-variant);
|
|
2322
|
+
transition: background-color 150ms;
|
|
2323
|
+
}
|
|
2324
|
+
.m3-floor-zoom-btn:hover:not(:disabled) {
|
|
2325
|
+
background: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
|
|
2326
|
+
}
|
|
2327
|
+
.m3-floor-zoom-btn:focus-visible {
|
|
2328
|
+
outline: 2px solid var(--color-secondary);
|
|
2329
|
+
outline-offset: -2px;
|
|
2330
|
+
}
|
|
2331
|
+
.m3-floor-zoom-btn:disabled {
|
|
2332
|
+
color: color-mix(in srgb, var(--color-on-surface) 38%, transparent);
|
|
2333
|
+
}
|
|
1099
2334
|
.m3-floor-chair {
|
|
1100
2335
|
background: var(--m3-floor-chair);
|
|
2336
|
+
color: var(--color-on-surface-variant);
|
|
1101
2337
|
}
|
|
1102
2338
|
.m3-floor-merge {
|
|
1103
2339
|
border-color: color-mix(in srgb, var(--m3-floor-merge) 60%, transparent);
|