@m3ui-vue/m3ui-vue 1.3.5 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/API.md +76 -16
  2. package/dist/{MButton-Bl_BSUep.js → MButton-D5eJiDza.js} +2 -2
  3. package/dist/{MButton-Bl_BSUep.js.map → MButton-D5eJiDza.js.map} +1 -1
  4. package/dist/{MDialog-D_Yik8ou.js → MDialog-WqB0jewp.js} +2 -2
  5. package/dist/{MDialog-D_Yik8ou.js.map → MDialog-WqB0jewp.js.map} +1 -1
  6. package/dist/{MListItem-BxifHJdU.js → MListItem-Cf-C2Ru-.js} +2 -2
  7. package/dist/{MListItem-BxifHJdU.js.map → MListItem-Cf-C2Ru-.js.map} +1 -1
  8. package/dist/{MLoadingIndicator-BxbFhSX6.js → MLoadingIndicator-D4GzEZoH.js} +2 -2
  9. package/dist/{MLoadingIndicator-BxbFhSX6.js.map → MLoadingIndicator-D4GzEZoH.js.map} +1 -1
  10. package/dist/{MSeekBar-BeN9QcB3.js → MSeekBar-B19xoWE3.js} +2 -2
  11. package/dist/{MSeekBar-BeN9QcB3.js.map → MSeekBar-B19xoWE3.js.map} +1 -1
  12. package/dist/{MSlider-BVSbJlGS.js → MSlider-9RoiuebS.js} +2 -2
  13. package/dist/{MSlider-BVSbJlGS.js.map → MSlider-9RoiuebS.js.map} +1 -1
  14. package/dist/{MSpinner-C2SUnWk4.js → MSpinner-BNF8MN-L.js} +2 -2
  15. package/dist/{MSpinner-C2SUnWk4.js.map → MSpinner-BNF8MN-L.js.map} +1 -1
  16. package/dist/{MTextField-CEkWSZ2v.js → MTextField-CuG0T3qh.js} +2 -2
  17. package/dist/{MTextField-CEkWSZ2v.js.map → MTextField-CuG0T3qh.js.map} +1 -1
  18. package/dist/{MTooltip-CodJGEO-.js → MTooltip-Bv7yxngk.js} +4 -4
  19. package/dist/{MTooltip-CodJGEO-.js.map → MTooltip-Bv7yxngk.js.map} +1 -1
  20. package/dist/api.json +1 -1
  21. package/dist/code-editor.js +1 -1
  22. package/dist/components/MFloorPlan.vue.d.ts +192 -14
  23. package/dist/components/MFloorPlanInspector.vue.d.ts +12 -12
  24. package/dist/components/MMap.vue.d.ts +2 -2
  25. package/dist/components/MPdfViewer.vue.d.ts +2 -2
  26. package/dist/composables/useFloorPlan.d.ts +10 -3
  27. package/dist/composables/useLocale.d.ts +9 -0
  28. package/dist/draw.js +2 -2
  29. package/dist/flow.js +1 -1
  30. package/dist/gantt.js +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/dist/locales/index.js +56 -0
  33. package/dist/locales/index.js.map +1 -1
  34. package/dist/m3ui-vue.css +1 -1
  35. package/dist/m3ui.js +2796 -1797
  36. package/dist/m3ui.js.map +1 -1
  37. package/dist/map.js +5 -5
  38. package/dist/media.js +4 -4
  39. package/dist/pdf.js +4 -4
  40. package/dist/rich-text-editor.js +4 -4
  41. package/dist/styles.css +1 -1
  42. package/dist/{useLocale-CaWwi-b6.js → useLocale-D2ucaY-l.js} +9 -1
  43. package/dist/useLocale-D2ucaY-l.js.map +1 -0
  44. package/package.json +1 -1
  45. package/src/__tests__/MFloorPlan.test.ts +331 -0
  46. package/src/components/MFloorPlan.vue +1143 -86
  47. package/src/components/MFloorPlanInspector.vue +21 -6
  48. package/src/components/MFloorPlanToolbar.vue +4 -3
  49. package/src/composables/useFloorPlan.ts +7 -3
  50. package/src/composables/useLocale.ts +17 -0
  51. package/src/index.ts +1 -1
  52. package/src/locales/de.ts +8 -0
  53. package/src/locales/es.ts +8 -0
  54. package/src/locales/fr.ts +8 -0
  55. package/src/locales/ja.ts +8 -0
  56. package/src/locales/ko.ts +8 -0
  57. package/src/locales/pt.ts +8 -0
  58. package/src/locales/zh.ts +8 -0
  59. 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
- /** `box` a rounded rectangle, `round` a circle, `bar` a thin slab (doors, windows), `text` the item's label only */
66
- shape?: 'box' | 'round' | 'bar' | 'text'
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
- /** What's picked on the plan besides tables: a zone, a wall (and one of its corners) or a decor item */
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
- /** The handle that turns the picked table or decor (off when your app doesn't keep angles) */
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
- const tables = defineModel<FloorTable[]>('tables', { default: () => [] })
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
- /** While editing: `select` moves things, `wall` draws a wall (click each corner, double-click or Enter to end), `area` drags out a zone */
162
- const tool = defineModel<'select' | 'wall' | 'area'>('tool', { default: 'select' })
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 ──
@@ -198,6 +320,9 @@ const emit = defineEmits<{
198
320
  merge: [merge: FloorMerge]
199
321
  split: [merge: FloorMerge]
200
322
  'merge-refused': [ids: (string | number)[], reason: string]
323
+ transfer: [from: FloorTable, to: FloorTable]
324
+ 'seat-click': [table: FloorTable, seat: number, event: MouseEvent]
325
+ 'transfer-refused': [from: FloorTable, to: FloorTable, reason: string]
201
326
  'table-click': [table: FloorTable, event: MouseEvent | KeyboardEvent]
202
327
  move: [moved: { id: string | number; x: number; y: number }[]]
203
328
  }>()
@@ -206,14 +331,172 @@ const locale = useLocale()
206
331
  const root = ref<HTMLElement>()
207
332
  /** A finger: bigger handles */
208
333
  const coarse = ref(typeof matchMedia !== 'undefined' && matchMedia('(pointer: coarse)').matches)
209
- const scale = ref(1)
334
+ /** Px per plan unit at zoom 1: the plan fits the component's width */
335
+ const base = ref(1)
336
+ /** Zoom (1: the whole plan; up to `maxZoom`), with `zoomable` */
337
+ const zoom = defineModel<number>('zoom', { default: 1 })
338
+ /** Where the zoomed plan sits in the component, px (0 or less: the plan covers the view) */
339
+ const pan = ref({ x: 0, y: 0 })
340
+ const zoomed = computed(() => (props.zoomable ? Math.min(Math.max(zoom.value, 1), props.maxZoom) : 1))
341
+ /** Px per plan unit, zoom included: everything is drawn and measured with it */
342
+ const scale = computed(() => base.value * zoomed.value)
343
+ /**
344
+ * True while the scale changes (zoom, the component resized) and a moment after: tables slide when they move, not
345
+ * when the whole plan grows or shrinks around them (the transition is off in the same render as the new positions)
346
+ */
347
+ const rescaling = ref(false)
348
+ let rescaleTimer = 0
349
+ watch(scale, () => {
350
+ rescaling.value = true
351
+ clearTimeout(rescaleTimer)
352
+ rescaleTimer = window.setTimeout(() => (rescaling.value = false), 150)
353
+ }, { flush: 'sync' })
354
+ onBeforeUnmount(() => clearTimeout(rescaleTimer))
210
355
  let ro: ResizeObserver | null = null
211
356
  onMounted(() => {
212
- ro = new ResizeObserver(() => (scale.value = (root.value?.clientWidth || props.width) / props.width))
357
+ ro = new ResizeObserver(() => {
358
+ base.value = (root.value?.clientWidth || props.width) / props.width
359
+ pan.value = clampPan(pan.value)
360
+ })
213
361
  ro.observe(root.value!)
214
- scale.value = (root.value!.clientWidth || props.width) / props.width
362
+ base.value = (root.value!.clientWidth || props.width) / props.width
363
+ root.value!.addEventListener('wheel', onWheel, { passive: false })
364
+ // Added by hand rather than in the template: a Vue listener on the way down would stamp the event, and Vue skips
365
+ // handlers attached the same instant (the tables' own pointerdown, under a frozen test clock)
366
+ root.value!.addEventListener('pointerdown', onFingerDown, { capture: true })
367
+ root.value!.addEventListener('touchmove', onTouchMove, { passive: false })
368
+ })
369
+ onBeforeUnmount(() => {
370
+ ro?.disconnect()
371
+ root.value?.removeEventListener('wheel', onWheel)
372
+ root.value?.removeEventListener('pointerdown', onFingerDown, { capture: true })
373
+ root.value?.removeEventListener('touchmove', onTouchMove)
374
+ })
375
+
376
+ // ── Zoom and pan ────────────────────────────────────────────────────────────────────────────────────────
377
+ const viewSize = () => ({ w: props.width * base.value, h: props.height * base.value })
378
+ /** The pan kept so the zoomed plan always covers the view */
379
+ function clampPan(p: { x: number; y: number }, z = zoomed.value) {
380
+ const { w, h } = viewSize()
381
+ return { x: Math.min(0, Math.max(w - w * z, p.x)), y: Math.min(0, Math.max(h - h * z, p.y)) }
382
+ }
383
+ // The zoom the pan was last worked out for (a v-model change from outside zooms about the middle)
384
+ let panZoom = 1
385
+ /** Zooms to `z`, keeping the plan point under (px, py) (px in the component; default its middle) where it is */
386
+ function zoomTo(z: number, px?: number, py?: number) {
387
+ if (!props.zoomable) return
388
+ const next = Math.min(Math.max(z, 1), props.maxZoom)
389
+ const { w, h } = viewSize()
390
+ const ax = px ?? w / 2
391
+ const ay = py ?? h / 2
392
+ const ux = (ax - pan.value.x) / (base.value * panZoom)
393
+ const uy = (ay - pan.value.y) / (base.value * panZoom)
394
+ pan.value = clampPan({ x: ax - ux * base.value * next, y: ay - uy * base.value * next }, next)
395
+ panZoom = next
396
+ zoom.value = next
397
+ }
398
+ watch(zoomed, (z) => {
399
+ if (z !== panZoom) zoomTo(z)
400
+ })
401
+ /** Centers the view on a plan point (in plan units), zooming to `z` if given */
402
+ function centerOn(x: number, y: number, z = zoomed.value) {
403
+ zoomTo(z)
404
+ const { w, h } = viewSize()
405
+ pan.value = clampPan({ x: w / 2 - x * scale.value, y: h / 2 - y * scale.value })
406
+ }
407
+ function onWheel(e: WheelEvent) {
408
+ if (!props.zoomable) return
409
+ const r = root.value!.getBoundingClientRect()
410
+ const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? r.height : 1
411
+ if (e.ctrlKey || e.metaKey) {
412
+ // Ctrl + wheel, and a trackpad's pinch (which comes as one)
413
+ e.preventDefault()
414
+ zoomTo(zoomed.value * Math.exp(-e.deltaY * unit * 0.002), e.clientX - r.left, e.clientY - r.top)
415
+ } else if (zoomed.value > 1) {
416
+ e.preventDefault()
417
+ pan.value = clampPan({ x: pan.value.x - (e.shiftKey ? e.deltaY : e.deltaX) * unit, y: pan.value.y - (e.shiftKey ? 0 : e.deltaY) * unit })
418
+ }
419
+ }
420
+ /** A drag that pans the view */
421
+ function startPan(e: PointerEvent) {
422
+ e.preventDefault()
423
+ const p0 = { ...pan.value }
424
+ const mv = (ev: PointerEvent) => {
425
+ if (ev.pointerId !== e.pointerId || gesture) return
426
+ pan.value = clampPan({ x: p0.x + ev.clientX - e.clientX, y: p0.y + ev.clientY - e.clientY })
427
+ }
428
+ const up = (ev: PointerEvent) => {
429
+ if (ev.pointerId !== e.pointerId) return
430
+ window.removeEventListener('pointermove', mv)
431
+ window.removeEventListener('pointerup', up)
432
+ window.removeEventListener('pointercancel', up)
433
+ }
434
+ window.addEventListener('pointermove', mv)
435
+ window.addEventListener('pointerup', up)
436
+ window.addEventListener('pointercancel', up)
437
+ }
438
+ // Two fingers pinch and pan, whatever they land on; a drag they interrupt is dropped
439
+ const fingers = new Map<number, { x: number; y: number }>()
440
+ let gesture: { d: number; z: number; mid: { x: number; y: number }; u: { x: number; y: number } } | null = null
441
+ /** Bumped when two fingers take over, so a drag that started with one of them lets go without committing */
442
+ let gestureRun = 0
443
+ function onFingerDown(e: PointerEvent) {
444
+ if (!props.zoomable || e.pointerType !== 'touch') return
445
+ fingers.set(e.pointerId, { x: e.clientX, y: e.clientY })
446
+ if (fingers.size === 1) {
447
+ window.addEventListener('pointermove', onFingerMove)
448
+ window.addEventListener('pointerup', onFingerUp)
449
+ window.addEventListener('pointercancel', onFingerUp)
450
+ }
451
+ if (fingers.size === 2) startGesture()
452
+ }
453
+ function startGesture() {
454
+ const [a, b] = [...fingers.values()]
455
+ const r = root.value!.getBoundingClientRect()
456
+ const mid = { x: (a!.x + b!.x) / 2 - r.left, y: (a!.y + b!.y) / 2 - r.top }
457
+ 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 } }
458
+ gestureRun++
459
+ // Whatever one finger was dragging goes back
460
+ draft.value = null
461
+ areaDraft.value = null
462
+ decorDraft.value = null
463
+ wallDraft.value = null
464
+ sizeDraft.value = null
465
+ marquee.value = null
466
+ transferDrag.value = null
467
+ }
468
+ function onFingerMove(e: PointerEvent) {
469
+ if (!fingers.has(e.pointerId)) return
470
+ fingers.set(e.pointerId, { x: e.clientX, y: e.clientY })
471
+ if (!gesture || fingers.size < 2) return
472
+ const [a, b] = [...fingers.values()]
473
+ const r = root.value!.getBoundingClientRect()
474
+ const mid = { x: (a!.x + b!.x) / 2 - r.left, y: (a!.y + b!.y) / 2 - r.top }
475
+ const z = Math.min(Math.max(gesture.z * (Math.hypot(a!.x - b!.x, a!.y - b!.y) / gesture.d), 1), props.maxZoom)
476
+ // The plan point first under the fingers' middle stays under it
477
+ pan.value = clampPan({ x: mid.x - gesture.u.x * base.value * z, y: mid.y - gesture.u.y * base.value * z }, z)
478
+ panZoom = z
479
+ zoom.value = z
480
+ }
481
+ function onFingerUp(e: PointerEvent) {
482
+ fingers.delete(e.pointerId)
483
+ if (fingers.size < 2) gesture = null
484
+ if (!fingers.size) {
485
+ window.removeEventListener('pointermove', onFingerMove)
486
+ window.removeEventListener('pointerup', onFingerUp)
487
+ window.removeEventListener('pointercancel', onFingerUp)
488
+ }
489
+ }
490
+ /** While two fingers zoom, or a table is carried to another one, the page doesn't scroll */
491
+ function onTouchMove(e: TouchEvent) {
492
+ if (gesture || transferDrag.value || (props.zoomable && zoomed.value > 1 && e.touches.length > 1)) e.preventDefault()
493
+ }
494
+ const touchAction = computed(() => (!props.zoomable ? undefined : zoomed.value > 1 ? 'none' : 'pan-x pan-y'))
495
+ onBeforeUnmount(() => {
496
+ window.removeEventListener('pointermove', onFingerMove)
497
+ window.removeEventListener('pointerup', onFingerUp)
498
+ window.removeEventListener('pointercancel', onFingerUp)
215
499
  })
216
- onBeforeUnmount(() => ro?.disconnect())
217
500
 
218
501
  // ── Geometry ────────────────────────────────────────────────────────────────────────────────────────────
219
502
  const CHAIR = 16
@@ -254,19 +537,30 @@ function chairsOf(t: FloorTable, s: FloorBox): { x: number; y: number; r: number
254
537
  else if (n > 2 && i >= n - 2 && n % 2 === 0 && n >= 6) per[i === n - 2 ? 2 : 3]!++
255
538
  else per[i % 2]!++
256
539
  }
257
- return sides.flatMap((side, k) => Array.from({ length: per[k]! }, (_, i) => side.at((i + 1) / (per[k]! + 1))))
540
+ const list = sides.flatMap((side, k) => Array.from({ length: per[k]! }, (_, i) => side.at((i + 1) / (per[k]! + 1))))
541
+ // Numbered clockwise from the top-left corner, as people count round a table
542
+ const start = Math.atan2(-s.h / 2, -s.w / 2)
543
+ const turn = (c: { x: number; y: number }) => (Math.atan2(c.y, c.x) - start + Math.PI * 4) % (Math.PI * 2)
544
+ return list.sort((a, b) => turn(a) - turn(b))
258
545
  }
259
546
 
260
547
  // While a drag moves tables, their positions live here until the drop
261
548
  const draft = shallowRef<Map<string | number, { x: number; y: number }> | null>(null)
549
+ /** A table being resized by its handle: its size until the drop */
550
+ const sizeDraft = shallowRef<{ id: string | number; w: number; h: number } | null>(null)
262
551
  const placed = computed(() =>
263
552
  tables.value.map((t) => {
264
553
  const at = draft.value?.get(t.id) ?? { x: t.x, y: t.y }
265
- const size = sizeOf(t)
554
+ const size = sizeDraft.value?.id === t.id ? { w: sizeDraft.value.w, h: sizeDraft.value.h } : sizeOf(t)
266
555
  return { t, x: at.x, y: at.y, size, chairs: chairsOf(t, size), status: t.status ? props.statuses[t.status] : undefined }
267
556
  }),
268
557
  )
269
558
  const ROLES = new Set(['primary', 'secondary', 'tertiary', 'error', 'success', 'surface'])
559
+ /** A taken chair: the table's status color, full strength (primary when it has none) */
560
+ function seatTaken(st?: FloorStatus) {
561
+ const c = !st || st.color === 'surface' ? 'primary' : st.color
562
+ return ROLES.has(c) ? { background: `var(--color-${c})`, color: `var(--color-on-${c})` } : { background: c, color: '#fff' }
563
+ }
270
564
  function look(st?: FloorStatus) {
271
565
  if (!st || st.color === 'surface') return { background: 'var(--color-surface-container-highest)', color: 'var(--color-on-surface)' }
272
566
  if (ROLES.has(st.color)) return { background: `var(--color-${st.color}-container)`, color: `var(--color-on-${st.color}-container)` }
@@ -312,15 +606,36 @@ const mergeShapes = computed(() =>
312
606
  )
313
607
 
314
608
  // ── 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
609
+ let drag: { id: number; sx: number; sy: number; start: Map<string | number, { x: number; y: number }>; moved: boolean; pick?: string | number; run: number } | null = null
316
610
  let suppressClick = false
317
- const snap = (v: number) => (props.grid ? Math.round(v / props.grid) * props.grid : v)
318
- /** A table's middle: on a grid point, or with `tableSnap="cell"` in the middle of a grid square */
611
+ /** The step walls, zones and decor snap to: the grid, or a part of it (`subgrid`) */
612
+ const step = computed(() => (props.grid ? props.grid / Math.max(1, Math.round(props.subgrid)) : 0))
613
+ const snap = (v: number) => (step.value ? Math.round(v / step.value) * step.value : v)
614
+ /** The step a table moves by: its cell, or the grid */
615
+ const tableStep = computed(() => props.cellSize || props.grid)
616
+ /** A table's middle: on a grid point, or with `tableSnap="cell"` (or `cellSize`) in the middle of a grid square */
319
617
  const snapTable = (v: number) => {
320
- const g = props.grid
321
- if (!g || props.tableSnap !== 'cell') return snap(v)
618
+ const g = tableStep.value
619
+ if (!g) return v
620
+ if (props.tableSnap !== 'cell' && !props.cellSize) return Math.round(v / g) * g
322
621
  return Math.round((v - g / 2) / g) * g + g / 2
323
622
  }
623
+ /** The step a resize handle moves by (0: free) */
624
+ const resizeStep = computed(() => (props.resizeSnap === 'grid' ? props.grid || 0 : props.resizeSnap === 'subgrid' ? step.value : 0))
625
+ /** A size changed by `delta`, in whole steps of `unit` (0: as is), never below `min` */
626
+ function steppedSize(size: number, delta: number, unit: number, min: number) {
627
+ if (!unit) return Math.max(min, size + delta)
628
+ let n = Math.round(delta / unit)
629
+ while (n < 0 && size + n * unit < min) n++
630
+ return size + n * unit
631
+ }
632
+ /** Where a dropped table's middle lands: snapped as above, or with `cellSize` so it covers whole cells from its own */
633
+ function snapTableAt(t: FloorTable, x: number, y: number) {
634
+ const c = props.cellSize
635
+ if (!c) return { x: snapTable(x), y: snapTable(y) }
636
+ const s = sizeOf(t)
637
+ 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) }
638
+ }
324
639
  function clamp(t: FloorTable, x: number, y: number) {
325
640
  const s = sizeOf(t)
326
641
  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 +645,7 @@ const LONG_PRESS = 450
330
645
  let longPress = 0
331
646
  let longPressed = false
332
647
  function onDown(e: PointerEvent, t: FloorTable) {
648
+ if (!props.editable && props.transferable && e.button === 0) return startTransfer(e, t)
333
649
  if (!props.editable || e.button !== 0 || tool.value !== 'select') return
334
650
  e.stopPropagation()
335
651
  picked.value = null
@@ -348,13 +664,13 @@ function onDown(e: PointerEvent, t: FloorTable) {
348
664
  // `selectable="multiple"` the selection is the click's to change, and a drag moves only the table pressed (not the
349
665
  // rest of the selection nor its merge): to bring the tables being merged together one by one
350
666
  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 }
667
+ 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 }
352
668
  window.addEventListener('pointermove', onMove)
353
669
  window.addEventListener('pointerup', onUp)
354
670
  window.addEventListener('pointercancel', onUp)
355
671
  }
356
672
  function onMove(e: PointerEvent) {
357
- if (!drag || e.pointerId !== drag.id) return
673
+ if (!drag || e.pointerId !== drag.id || drag.run !== gestureRun) return
358
674
  const dx = (e.clientX - drag.sx) / scale.value
359
675
  const dy = (e.clientY - drag.sy) / scale.value
360
676
  if (!drag.moved && Math.hypot(e.clientX - drag.sx, e.clientY - drag.sy) < (e.pointerType === 'touch' ? 8 : 4)) return
@@ -378,18 +694,165 @@ function onUp(e: PointerEvent) {
378
694
  window.removeEventListener('pointerup', onUp)
379
695
  window.removeEventListener('pointercancel', onUp)
380
696
  const d = draft.value
381
- const moved = drag.moved && d && e.type !== 'pointercancel'
697
+ const moved = drag.moved && d && e.type !== 'pointercancel' && drag.run === gestureRun
382
698
  drag = null
383
699
  draft.value = null
384
700
  if (!moved) return
385
701
  suppressClick = true
386
702
  setTimeout(() => (suppressClick = false))
387
- commitMoves(new Map([...d!].map(([id, p]) => [id, clamp(tables.value.find((x) => x.id === id)!, snapTable(p.x), snapTable(p.y))])))
703
+ commitMoves(new Map([...d!].map(([id, p]) => {
704
+ const t = tables.value.find((x) => x.id === id)!
705
+ const at = snapTableAt(t, p.x, p.y)
706
+ return [id, clamp(t, at.x, at.y)]
707
+ })))
708
+ }
709
+ /** Two boxes overlap (touching edges don't) */
710
+ 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
711
+ /** The tables that overlap another one (their turned boxes), while editing */
712
+ const overlapping = computed(() => {
713
+ const out = new Set<string | number>()
714
+ if (!props.editable || props.overlap === 'allow') return out
715
+ const boxes = placed.value.map((p) => ({ id: p.t.id, b: boxOf(p) }))
716
+ for (let i = 0; i < boxes.length; i++)
717
+ for (let j = i + 1; j < boxes.length; j++)
718
+ if (crosses(boxes[i]!.b, boxes[j]!.b)) {
719
+ out.add(boxes[i]!.id)
720
+ out.add(boxes[j]!.id)
721
+ }
722
+ return out
723
+ })
724
+ /** With `overlap="prevent"`: whether tables moved or resized like this would overlap one another or the rest */
725
+ function wouldOverlap(changed: Map<string | number, { x?: number; y?: number; w?: number; h?: number }>) {
726
+ if (props.overlap !== 'prevent') return false
727
+ const boxes = tables.value.map((t) => {
728
+ const c = changed.get(t.id)
729
+ const s0 = sizeOf(t)
730
+ const size = { w: c?.w ?? s0.w, h: c?.h ?? s0.h }
731
+ return { id: t.id, b: boxOf({ t, x: c?.x ?? t.x, y: c?.y ?? t.y, size }) }
732
+ })
733
+ return boxes.some((a) => changed.has(a.id) && boxes.some((b) => b.id !== a.id && crosses(a.b, b.b)))
388
734
  }
389
735
  function commitMoves(next: Map<string | number, { x: number; y: number }>) {
736
+ // Refused: the tables go back where they were
737
+ if (wouldOverlap(next)) return navigator.vibrate?.(30)
390
738
  record()
391
739
  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 })))
740
+ emit('move', [...next].map(([id, p]) => ({ id, ...toOuterXY(tables.value.find((t) => t.id === id)!, p.x, p.y) })))
741
+ }
742
+ /**
743
+ * Resizing the selected table by its corner handle: the drag read along the table's own axes, growing it both ways so
744
+ * its middle stays on its grid point or cell; a round table with Shift (or one that is a circle) stays a circle
745
+ */
746
+ function onTableResize(e: PointerEvent, t: FloorTable) {
747
+ if (!props.editable || e.button !== 0) return
748
+ e.stopPropagation()
749
+ e.preventDefault()
750
+ const s0 = sizeOf(t)
751
+ const rad = ((t.rotation ?? 0) * Math.PI) / 180
752
+ const cos = Math.cos(rad)
753
+ const sin = Math.sin(rad)
754
+ const circle = (t.shape ?? 'square') === 'round' && s0.w === s0.h
755
+ let shift = false
756
+ const key = (ev: KeyboardEvent) => (shift = ev.shiftKey)
757
+ window.addEventListener('keydown', key)
758
+ window.addEventListener('keyup', key)
759
+ // By cell, the table keeps its cell and grows right and down over the next ones; else about its middle
760
+ const c = props.cellSize
761
+ const corner = c ? { x: t.x - cellReach(s0.w), y: t.y - cellReach(s0.h) } : null
762
+ const middleFor = (w: number, h: number) => (corner ? { x: corner.x + cellReach(w), y: corner.y + cellReach(h) } : { x: t.x, y: t.y })
763
+ follow(e, (dx, dy) => {
764
+ // Growing both ways (about its middle), each side moves a whole step: twice a step in all
765
+ const k = corner ? 1 : 2
766
+ const unit = resizeStep.value * k
767
+ let w = steppedSize(s0.w, k * (dx * cos + dy * sin), unit, 20)
768
+ let h = steppedSize(s0.h, k * (-dx * sin + dy * cos), unit, 20)
769
+ if (circle !== shift) w = h = Math.max(w, h)
770
+ sizeDraft.value = { id: t.id, w, h }
771
+ if (corner) draft.value = new Map([[t.id, middleFor(w, h)]])
772
+ }, () => {
773
+ const d = sizeDraft.value!
774
+ sizeDraft.value = null
775
+ draft.value = null
776
+ const at = middleFor(d.w, d.h)
777
+ if (wouldOverlap(new Map([[t.id, { ...at, w: d.w, h: d.h }]]))) return
778
+ record()
779
+ tables.value = tables.value.map((x) => (x.id === t.id ? { ...x, ...at, width: Math.round(d.w), height: Math.round(d.h) } : x))
780
+ })
781
+ const off = () => {
782
+ window.removeEventListener('keydown', key)
783
+ window.removeEventListener('keyup', key)
784
+ window.removeEventListener('pointerup', off)
785
+ }
786
+ window.addEventListener('pointerup', off)
787
+ }
788
+
789
+ // ── In service: carrying a table's party to another table ──
790
+ /** The table being carried: where the pointer is (plan units) and the table under it, if any */
791
+ const transferDrag = shallowRef<{ id: string | number; label: string; x: number; y: number; over: string | number | null; ok: boolean } | null>(null)
792
+ const tableAt = (x: number, y: number, skip: string | number) =>
793
+ placed.value.find((p) => {
794
+ if (p.t.id === skip) return false
795
+ const b = boxOf(p)
796
+ return x >= b.x1 && x <= b.x2 && y >= b.y1 && y <= b.y2
797
+ })?.t
798
+ function transferCheck(from: FloorTable, to: FloorTable) {
799
+ return props.canTransfer?.(outerOf(from), outerOf(to)) ?? true
800
+ }
801
+ function startTransfer(e: PointerEvent, t: FloorTable) {
802
+ const touch = e.pointerType === 'touch'
803
+ const sx = e.clientX
804
+ const sy = e.clientY
805
+ const run = gestureRun
806
+ let active = false
807
+ const at = (ev: PointerEvent) => {
808
+ const p = toPlan(ev)
809
+ const over = tableAt(p.x, p.y, t.id)
810
+ transferDrag.value = { id: t.id, label: t.label, x: p.x, y: p.y, over: over?.id ?? null, ok: !over || transferCheck(t, over) === true }
811
+ }
812
+ const begin = (ev: PointerEvent) => {
813
+ active = true
814
+ document.body.style.userSelect = 'none'
815
+ navigator.vibrate?.(10)
816
+ at(ev)
817
+ }
818
+ // A finger holds the table down first, so a swipe still scrolls the page
819
+ const timer = touch ? window.setTimeout(() => begin(e), LONG_PRESS) : 0
820
+ const mv = (ev: PointerEvent) => {
821
+ if (ev.pointerId !== e.pointerId) return
822
+ if (run !== gestureRun) return end()
823
+ if (!active) {
824
+ if (Math.hypot(ev.clientX - sx, ev.clientY - sy) < (touch ? 8 : 4)) return
825
+ if (touch) return end()
826
+ begin(ev)
827
+ }
828
+ at(ev)
829
+ }
830
+ const up = (ev: PointerEvent) => {
831
+ if (ev.pointerId !== e.pointerId) return
832
+ const d = transferDrag.value
833
+ const was = active
834
+ end()
835
+ if (!was || !d || ev.type === 'pointercancel') return
836
+ suppressClick = true
837
+ setTimeout(() => (suppressClick = false))
838
+ const to = d.over !== null ? tables.value.find((x) => x.id === d.over) : undefined
839
+ if (!to) return
840
+ const ok = transferCheck(t, to)
841
+ if (ok === true) emit('transfer', outerOf(t), outerOf(to))
842
+ else emit('transfer-refused', outerOf(t), outerOf(to), typeof ok === 'string' ? ok : '')
843
+ }
844
+ function end() {
845
+ clearTimeout(timer)
846
+ if (active) document.body.style.userSelect = ''
847
+ active = false
848
+ transferDrag.value = null
849
+ window.removeEventListener('pointermove', mv)
850
+ window.removeEventListener('pointerup', up)
851
+ window.removeEventListener('pointercancel', up)
852
+ }
853
+ window.addEventListener('pointermove', mv)
854
+ window.addEventListener('pointerup', up)
855
+ window.addEventListener('pointercancel', up)
393
856
  }
394
857
  /** Editing with `selectable="multiple"`: a click toggles a table in the selection (to merge them), a drag moves that table alone */
395
858
  const toggling = computed(() => props.editable && props.selectable === 'multiple')
@@ -400,7 +863,7 @@ function onClick(e: MouseEvent, t: FloorTable) {
400
863
  else if (!props.editable && props.selectable === 'single') selection.value = selection.value.length === 1 && selection.value[0] === t.id ? [] : [t.id]
401
864
  else if (!props.editable && props.selectable === 'multiple')
402
865
  selection.value = selection.value.includes(t.id) ? selection.value.filter((x) => x !== t.id) : [...selection.value, t.id]
403
- emit('table-click', t, e)
866
+ emit('table-click', outerOf(t), e)
404
867
  }
405
868
  /** With `dragMerged`, the tables merged with these come along */
406
869
  function withMerged(ids: (string | number)[]) {
@@ -412,13 +875,13 @@ function withMerged(ids: (string | number)[]) {
412
875
  function onKey(e: KeyboardEvent, t: FloorTable) {
413
876
  if (e.key === 'Enter' || e.key === ' ') {
414
877
  e.preventDefault()
415
- emit('table-click', t, e)
878
+ emit('table-click', outerOf(t), e)
416
879
  return
417
880
  }
418
881
  const dir = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }[e.key]
419
882
  if (!dir || !props.editable) return
420
883
  e.preventDefault()
421
- const step = (props.grid || 1) * (e.shiftKey ? 5 : 1)
884
+ const step = (tableStep.value || 1) * (e.shiftKey ? 5 : 1)
422
885
  const ids = withMerged(selection.value.includes(t.id) ? selection.value : [t.id])
423
886
  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
887
  }
@@ -429,8 +892,8 @@ onBeforeUnmount(() => {
429
892
  })
430
893
  // ── Zones, walls and decor ───────────────────────────────────────────────────────────────────────────────
431
894
  const BUILTIN_DECOR: Record<FloorDecorBuiltin, FloorDecorKind> = {
432
- door: { label: 'Door', icon: 'door_front', width: 60, height: 14, shape: 'bar' },
433
- window: { label: 'Window', icon: 'window', width: 80, height: 10, shape: 'bar' },
895
+ door: { label: 'Door', icon: 'door_front', width: 60, height: 14, shape: 'door' },
896
+ window: { label: 'Window', icon: 'window', width: 80, height: 10, shape: 'window' },
434
897
  plant: { label: 'Plant', icon: 'potted_plant', width: 40, height: 40 },
435
898
  column: { label: 'Column', width: 30, height: 30, shape: 'round', color: 'var(--color-outline)' },
436
899
  restroom: { label: 'Restroom', icon: 'wc', width: 48, height: 48 },
@@ -449,12 +912,16 @@ const decorSize = (d: FloorDecor) => ({ w: d.width ?? kindOf(d).width, h: d.heig
449
912
  function decorLook(k: FloorDecorKind) {
450
913
  const shape = k.shape ?? 'box'
451
914
  if (shape === 'text') return {}
915
+ // Doors and windows take the plan's own color, so the wall they sit on looks cut there
916
+ if ((shape === 'door' || shape === 'window') && !k.color) return { backgroundColor: 'inherit' }
452
917
  const c = k.color ?? (shape === 'bar' ? 'surface-container-highest' : 'surface-container-high')
453
918
  const bg = c.startsWith('surface') || c.startsWith('var(') || c.startsWith('#') || c.startsWith('rgb') || c.startsWith('hsl')
454
919
  ? (c.startsWith('surface') ? `var(--color-${c})` : c)
455
920
  : `var(--color-${c}-container)`
456
- return { background: bg, borderRadius: shape === 'round' ? '9999px' : shape === 'bar' ? '2px' : '8px' }
921
+ return { background: bg, borderRadius: shape === 'round' ? '9999px' : shape === 'bar' || shape === 'door' || shape === 'window' ? '2px' : '8px' }
457
922
  }
923
+ /** A door's swing: the quarter circle its leaf sweeps, from the open leaf down to the far jamb, in px */
924
+ const doorSwing = (w: number) => `M0 0 L0 ${-w} A${w} ${w} 0 0 1 ${w} 0 Z`
458
925
  function areaLook(color?: string) {
459
926
  const c = color ?? 'secondary'
460
927
  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,7 +930,7 @@ function areaLook(color?: string) {
463
930
  const isPicked = (kind: 'area' | 'wall' | 'decor', id: string | number) => picked.value?.kind === kind && picked.value.id === id
464
931
  const toPlan = (e: { clientX: number; clientY: number }) => {
465
932
  const r = root.value!.getBoundingClientRect()
466
- return { x: (e.clientX - r.left) / scale.value, y: (e.clientY - r.top) / scale.value }
933
+ return { x: (e.clientX - r.left - pan.value.x) / scale.value, y: (e.clientY - r.top - pan.value.y) / scale.value }
467
934
  }
468
935
  /** A generic drag in plan units: `move` gets the offset from where it started, `end` runs once if it moved */
469
936
  function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: () => void) {
@@ -472,8 +939,9 @@ function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: ()
472
939
  const sx = e.clientX
473
940
  const sy = e.clientY
474
941
  let moved = false
942
+ const run = gestureRun
475
943
  const mv = (ev: PointerEvent) => {
476
- if (ev.pointerId !== e.pointerId) return
944
+ if (ev.pointerId !== e.pointerId || run !== gestureRun) return
477
945
  if (!moved && Math.hypot(ev.clientX - sx, ev.clientY - sy) < 4) return
478
946
  moved = true
479
947
  move((ev.clientX - sx) / scale.value, (ev.clientY - sy) / scale.value)
@@ -483,7 +951,7 @@ function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: ()
483
951
  window.removeEventListener('pointermove', mv)
484
952
  window.removeEventListener('pointerup', up)
485
953
  window.removeEventListener('pointercancel', up)
486
- if (moved) end()
954
+ if (moved && run === gestureRun && ev.type !== 'pointercancel') end()
487
955
  }
488
956
  window.addEventListener('pointermove', mv)
489
957
  window.addEventListener('pointerup', up)
@@ -492,18 +960,113 @@ function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: ()
492
960
  const areaDraft = shallowRef<FloorArea | null>(null)
493
961
  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
962
  type Corner = 'nw' | 'ne' | 'sw' | 'se'
963
+ /** The box around a zone's corners */
964
+ function boxAround(pts: [number, number][]) {
965
+ const xs = pts.map((p) => p[0])
966
+ const ys = pts.map((p) => p[1])
967
+ const x = Math.min(...xs)
968
+ const y = Math.min(...ys)
969
+ return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y }
970
+ }
971
+ /** A zone of any shape with its box brought up to date */
972
+ const shaped = (a: FloorArea, points: [number, number][]): FloorArea => ({ ...a, points, ...boxAround(points) })
973
+ 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]]
974
+ const polyPath = (pts: [number, number][]) => pts.map(([x, y], i) => `${i ? 'L' : 'M'}${x * scale.value} ${y * scale.value}`).join('') + 'Z'
975
+ function areaSvgLook(color?: string) {
976
+ const c = color ?? 'secondary'
977
+ 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 }
978
+ }
979
+ /**
980
+ * 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
981
+ * walls join end to end; else on the snapping step
982
+ */
983
+ function snapPoint(x: number, y: number, skip?: { kind: 'wall' | 'area'; id: string | number; vertex?: number }): [number, number] {
984
+ let best: [number, number] | null = null
985
+ let bestD = 12 / scale.value
986
+ const consider = (pts: [number, number][], kind: 'wall' | 'area', id: string | number | null) =>
987
+ pts.forEach((p, i) => {
988
+ if (skip && skip.kind === kind && skip.id === id && (skip.vertex === undefined || skip.vertex === i)) return
989
+ const d = Math.hypot(p[0] - x, p[1] - y)
990
+ if (d < bestD) {
991
+ bestD = d
992
+ best = p
993
+ }
994
+ })
995
+ for (const w of walls.value) consider(w.points, 'wall', w.id)
996
+ for (const a of areas.value) consider(a.points ?? rectCorners(a), 'area', a.id)
997
+ // The wall or zone being drawn closes on its own corners (but not the one just placed)
998
+ if (drawing.value) consider(drawing.value.slice(0, -1), 'wall', null)
999
+ return best ? [best[0], best[1]] : [snap(x), snap(y)]
1000
+ }
1001
+ /** The segment of a line (closed: a zone's outline) nearest a point: the index to insert a corner before */
1002
+ function nearestSegment(pts: [number, number][], p: { x: number; y: number }, closed: boolean) {
1003
+ let best = 1
1004
+ let bestD = Infinity
1005
+ const n = closed ? pts.length + 1 : pts.length
1006
+ for (let i = 1; i < n; i++) {
1007
+ const [ax, ay] = pts[i - 1]!
1008
+ const [bx, by] = pts[i % pts.length]!
1009
+ const len = (bx - ax) ** 2 + (by - ay) ** 2
1010
+ const t = len ? Math.max(0, Math.min(1, ((p.x - ax) * (bx - ax) + (p.y - ay) * (by - ay)) / len)) : 0
1011
+ const d = Math.hypot(ax + t * (bx - ax) - p.x, ay + t * (by - ay) - p.y)
1012
+ if (d < bestD) {
1013
+ bestD = d
1014
+ best = i
1015
+ }
1016
+ }
1017
+ return best
1018
+ }
1019
+ /** Double-click on a zone: a new corner on its nearest edge (a rectangle becomes a zone of any shape) */
1020
+ function onAreaDblclick(e: MouseEvent, a: FloorArea) {
1021
+ if (!props.editable || tool.value !== 'select') return
1022
+ e.stopPropagation()
1023
+ const p = toPlan(e)
1024
+ const pts = a.points ?? rectCorners(a)
1025
+ const at = nearestSegment(pts, p, true)
1026
+ record()
1027
+ 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))
1028
+ picked.value = { kind: 'area', id: a.id, vertex: at }
1029
+ }
1030
+ /** Dragging a corner of a zone of any shape */
1031
+ function onAreaVertexDown(e: PointerEvent, a: FloorArea, vertex: number) {
1032
+ if (!props.editable || tool.value !== 'select' || e.button !== 0 || !a.points) return
1033
+ e.stopPropagation()
1034
+ picked.value = { kind: 'area', id: a.id, vertex }
1035
+ const p0 = a.points[vertex]!
1036
+ follow(e, (dx, dy) => {
1037
+ const at = snapPoint(p0[0] + dx, p0[1] + dy, { kind: 'area', id: a.id, vertex })
1038
+ areaDraft.value = shaped(a, a.points!.map((p, i) => (i === vertex ? at : p)))
1039
+ }, () => {
1040
+ const d = areaDraft.value!
1041
+ areaDraft.value = null
1042
+ record()
1043
+ areas.value = areas.value.map((x) => (x.id === a.id ? d : x))
1044
+ })
1045
+ }
495
1046
  function onAreaDown(e: PointerEvent, a: FloorArea, corner: Corner | null) {
496
1047
  if (!props.editable || tool.value !== 'select' || e.button !== 0) return
497
1048
  e.stopPropagation()
498
1049
  picked.value = { kind: 'area', id: a.id }
499
1050
  selection.value = []
1051
+ if (a.points) {
1052
+ follow(e, (dx, dy) => (areaDraft.value = shaped(a, a.points!.map(([x, y]) => [x + dx, y + dy]))), () => {
1053
+ const d = areaDraft.value!
1054
+ areaDraft.value = null
1055
+ // Moved by whole steps, so its corners stay where they snapped
1056
+ const ox = snap(d.points![0]![0]) - d.points![0]![0]
1057
+ const oy = snap(d.points![0]![1]) - d.points![0]![1]
1058
+ record()
1059
+ areas.value = areas.value.map((x) => (x.id === a.id ? shaped(d, d.points!.map(([px, py]) => [px + ox, py + oy])) : x))
1060
+ })
1061
+ return
1062
+ }
500
1063
  follow(e, (dx, dy) => {
501
1064
  if (!corner) {
502
1065
  areaDraft.value = { ...a, x: a.x + dx, y: a.y + dy }
503
1066
  return
504
1067
  }
505
1068
  // The opposite corner stays put
506
- const min = props.grid || 20
1069
+ const min = step.value || 20
507
1070
  const left = corner.includes('w')
508
1071
  const top = corner[0] === 'n'
509
1072
  const w = Math.max(min, a.width + (left ? -dx : dx))
@@ -524,14 +1087,47 @@ function onDecorDown(e: PointerEvent, d: FloorDecor, resize = false) {
524
1087
  picked.value = { kind: 'decor', id: d.id }
525
1088
  selection.value = []
526
1089
  const s0 = decorSize(d)
527
- // Resizing from the bottom-right corner keeps it centered where it is, growing both ways
528
- follow(e, (dx, dy) => (decorDraft.value = resize ? { ...d, width: Math.max(10, s0.w + dx * 2), height: Math.max(6, s0.h + dy * 2) } : { ...d, x: d.x + dx, y: d.y + dy }), () => {
1090
+ follow(e, (dx, dy) => (decorDraft.value = resize ? resizedDecor(d, s0, dx, dy) : { ...d, x: d.x + dx, y: d.y + dy }), () => {
529
1091
  const n = decorDraft.value!
530
1092
  decorDraft.value = null
531
1093
  record()
532
- decor.value = decor.value.map((x) => (x.id === d.id ? (resize ? { ...n, width: Math.round(n.width!), height: Math.round(n.height!) } : { ...n, x: snap(n.x), y: snap(n.y) }) : x))
1094
+ 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
1095
  })
534
1096
  }
1097
+ /**
1098
+ * Decor resized by its corner handle, dragged by (dx, dy) on the plan: the drag is read along the item's own axes
1099
+ * (it may be turned), its corner follows the pointer and the opposite corner stays where it was. Or straight to a
1100
+ * size `w` × `h`, from the same corner
1101
+ */
1102
+ function resizedDecor(d: FloorDecor, s0: { w: number; h: number }, dx: number, dy: number, w?: number, h?: number): FloorDecor {
1103
+ const rad = ((d.rotation ?? 0) * Math.PI) / 180
1104
+ const cos = Math.cos(rad)
1105
+ const sin = Math.sin(rad)
1106
+ const width = w ?? steppedSize(s0.w, dx * cos + dy * sin, resizeStep.value, 10)
1107
+ const height = h ?? steppedSize(s0.h, -dx * sin + dy * cos, resizeStep.value, 6)
1108
+ // The middle moves half the growth, turned back onto the plan
1109
+ const gx = (width - s0.w) / 2
1110
+ const gy = (height - s0.h) / 2
1111
+ return { ...d, width, height, x: d.x + gx * cos - gy * sin, y: d.y + gx * sin + gy * cos }
1112
+ }
1113
+ /** The resize cursor that matches the corner handle's direction once the item is turned */
1114
+ const RESIZE_CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize']
1115
+ const resizeCursor = (deg = 0) => RESIZE_CURSORS[Math.round((((45 + deg) % 180) + 180) % 180 / 45) % 4]
1116
+ /** Arrows move the picked zone, decor or wall (or the wall's picked corner) by a snapping step; Shift by five */
1117
+ function nudgePicked(dx: number, dy: number) {
1118
+ const pk = picked.value!
1119
+ if (pk.kind === 'area') {
1120
+ const a = areas.value.find((x) => x.id === pk.id)
1121
+ 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]))) })
1122
+ else if (a) update('area', a.id, { x: a.x + dx, y: a.y + dy })
1123
+ } else if (pk.kind === 'decor') {
1124
+ const d = decor.value.find((x) => x.id === pk.id)
1125
+ if (d) update('decor', d.id, { x: d.x + dx, y: d.y + dy })
1126
+ } else {
1127
+ const w = walls.value.find((x) => x.id === pk.id)
1128
+ 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])) })
1129
+ }
1130
+ }
535
1131
  const wallDraft = shallowRef<FloorWall | null>(null)
536
1132
  const shownWalls = computed(() => walls.value.map((w) => (wallDraft.value?.id === w.id ? wallDraft.value : w)))
537
1133
  const wallPath = (w: FloorWall) => w.points.map(([x, y], i) => `${i ? 'L' : 'M'}${x * scale.value} ${y * scale.value}`).join('')
@@ -541,12 +1137,16 @@ function onWallDown(e: PointerEvent, w: FloorWall, vertex = -1) {
541
1137
  picked.value = { kind: 'wall', id: w.id, ...(vertex >= 0 && { vertex }) }
542
1138
  selection.value = []
543
1139
  follow(e, (dx, dy) => {
544
- wallDraft.value = { ...w, points: w.points.map(([x, y], i) => (vertex < 0 || i === vertex ? [x + dx, y + dy] : [x, y])) }
1140
+ // A corner lands on another wall's corner nearby (they join), or on the step
1141
+ wallDraft.value = vertex < 0
1142
+ ? { ...w, points: w.points.map(([x, y]) => [x + dx, y + dy]) }
1143
+ : { ...w, points: w.points.map((p, i) => (i === vertex ? snapPoint(p[0] + dx, p[1] + dy, { kind: 'wall', id: w.id, vertex }) : p)) }
545
1144
  }, () => {
546
1145
  const n = wallDraft.value!
547
1146
  wallDraft.value = null
548
1147
  record()
549
- walls.value = walls.value.map((x) => (x.id === w.id ? { ...n, points: n.points.map(([x, y]) => [snap(x), snap(y)] as [number, number]) } : x))
1148
+ // A moved corner already sits where it snapped (maybe on another wall's corner); a moved wall steps
1149
+ walls.value = walls.value.map((x) => (x.id === w.id ? (vertex >= 0 ? n : { ...n, points: n.points.map(([x, y]) => [snap(x), snap(y)] as [number, number]) }) : x))
550
1150
  })
551
1151
  }
552
1152
  // Drawing new walls and zones
@@ -554,21 +1154,69 @@ const drawing = ref<[number, number][] | null>(null)
554
1154
  const hover = ref<[number, number] | null>(null)
555
1155
  let made = 0
556
1156
  const newId = (p: string) => `${p}${Date.now().toString(36)}${made++}`
1157
+ /** The rectangle being dragged out on empty floor to select the tables it touches, in plan units */
1158
+ const marquee = shallowRef<{ x: number; y: number; w: number; h: number } | null>(null)
1159
+ /** A table's box on the plan, turned (the box around it), in plan units */
1160
+ function boxOf(p: { x: number; y: number; size: FloorBox; t: FloorTable }) {
1161
+ const rad = ((rotationOf('table', p.t.id, p.t.rotation) ?? 0) * Math.PI) / 180
1162
+ const c = Math.abs(Math.cos(rad))
1163
+ const sn = Math.abs(Math.sin(rad))
1164
+ const hw = (p.size.w * c + p.size.h * sn) / 2
1165
+ const hh = (p.size.w * sn + p.size.h * c) / 2
1166
+ return { x1: p.x - hw, y1: p.y - hh, x2: p.x + hw, y2: p.y + hh }
1167
+ }
1168
+ /** Empty floor: the plan itself, its zones' and walls' layers, the background — not a table, zone, wall or decor */
1169
+ const isFloor = (e: Event) => {
1170
+ const el = e.target as Element
1171
+ return el === e.currentTarget || el === viewEl.value || el === svgEl.value || el === zoneSvg.value || el.hasAttribute?.('data-floor-bg')
1172
+ }
557
1173
  function onPlanPointer(e: PointerEvent) {
1174
+ const floor = isFloor(e)
1175
+ const onTable = !!(e.target as Element).closest?.('[data-floor-table]')
1176
+ // Panning: the middle button anywhere; on empty floor (or, outside editing, on a table) once zoomed in, outside
1177
+ // editing or with a finger
1178
+ if (props.zoomable && (e.button === 1 || (e.button === 0 && zoomed.value > 1 && (floor || (!props.editable && onTable && !props.transferable)) && (!props.editable || e.pointerType === 'touch')))) {
1179
+ startPan(e)
1180
+ return
1181
+ }
558
1182
  if (!props.editable) return
559
1183
  if (tool.value === 'select') {
560
- if (e.target === e.currentTarget || (e.target as Element).closest('svg') === svgEl.value) {
1184
+ if (!floor) return
1185
+ const adding = e.shiftKey || e.ctrlKey || e.metaKey
1186
+ if (!adding) {
561
1187
  selection.value = []
562
1188
  picked.value = null
563
1189
  }
1190
+ // A mouse or a pen drags out a rectangle (a finger scrolls, or holds a table down to add it)
1191
+ if (e.pointerType === 'touch' || e.button !== 0) return
1192
+ const p0 = toPlan(e)
1193
+ const before = adding ? selection.value : []
1194
+ follow(e, (dx, dy) => {
1195
+ 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) }
1196
+ marquee.value = m
1197
+ const hit = placed.value.filter((p) => {
1198
+ const b = boxOf(p)
1199
+ return b.x1 < m.x + m.w && b.x2 > m.x && b.y1 < m.y + m.h && b.y2 > m.y
1200
+ }).map((p) => p.t.id)
1201
+ const next = [...new Set([...before, ...hit])]
1202
+ if (next.length !== selection.value.length || next.some((id, i) => id !== selection.value[i])) selection.value = next
1203
+ }, () => {
1204
+ marquee.value = null
1205
+ suppressClick = true
1206
+ setTimeout(() => (suppressClick = false))
1207
+ })
564
1208
  return
565
1209
  }
566
1210
  const p = toPlan(e)
567
- const at: [number, number] = [snap(p.x), snap(p.y)]
568
- if (tool.value === 'wall') {
1211
+ if (tool.value === 'wall' || tool.value === 'polygon') {
1212
+ const at = snapPoint(p.x, p.y)
1213
+ const first = drawing.value?.[0]
1214
+ // A zone closes when its first corner is clicked again
1215
+ if (tool.value === 'polygon' && first && distinct(drawing.value!).length >= 3 && at[0] === first[0] && at[1] === first[1]) return finishWall()
569
1216
  drawing.value = [...(drawing.value ?? [at]), at]
570
1217
  return
571
1218
  }
1219
+ const at: [number, number] = [snap(p.x), snap(p.y)]
572
1220
  const id = newId('area')
573
1221
  areaDraft.value = { id, x: at[0], y: at[1], width: 0, height: 0 }
574
1222
  follow(e, (dx, dy) => (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) }), () => {
@@ -584,15 +1232,32 @@ function onPlanPointer(e: PointerEvent) {
584
1232
  function onPlanMove(e: PointerEvent) {
585
1233
  if (drawing.value) {
586
1234
  const p = toPlan(e)
587
- hover.value = [snap(p.x), snap(p.y)]
1235
+ hover.value = snapPoint(p.x, p.y)
588
1236
  }
589
1237
  }
1238
+ /** Corners without one repeated right after itself (a double-click places the last one twice) */
1239
+ const distinct = (pts: [number, number][]) => pts.filter((p, i, a) => !i || p[0] !== a[i - 1]![0] || p[1] !== a[i - 1]![1])
1240
+ /** Ends what's being drawn: a wall (two corners or more) or, with the polygon tool, a zone (three or more) */
590
1241
  function finishWall() {
591
- const pts = drawing.value?.filter((p, i, a) => !i || p[0] !== a[i - 1]![0] || p[1] !== a[i - 1]![1])
1242
+ let pts = drawing.value ? distinct(drawing.value) : null
592
1243
  drawing.value = null
593
1244
  hover.value = null
594
- if (pts && pts.length > 1) record()
595
- if (pts && pts.length > 1) walls.value = [...walls.value, { id: newId('wall'), points: pts }]
1245
+ if (!pts) return
1246
+ if (tool.value === 'polygon') {
1247
+ // Closing on the first corner doesn't repeat it
1248
+ const [f, l] = [pts[0]!, pts[pts.length - 1]!]
1249
+ if (pts.length > 1 && f[0] === l[0] && f[1] === l[1]) pts = pts.slice(0, -1)
1250
+ if (pts.length < 3) return
1251
+ const id = newId('area')
1252
+ record()
1253
+ areas.value = [...areas.value, shaped({ id, x: 0, y: 0, width: 0, height: 0 }, pts)]
1254
+ picked.value = { kind: 'area', id }
1255
+ return
1256
+ }
1257
+ if (pts.length > 1) {
1258
+ record()
1259
+ walls.value = [...walls.value, { id: newId('wall'), points: pts }]
1260
+ }
596
1261
  }
597
1262
  function onPlanKey(e: KeyboardEvent) {
598
1263
  if (drawing.value && (e.key === 'Enter' || e.key === 'Escape')) {
@@ -620,6 +1285,13 @@ function onPlanKey(e: KeyboardEvent) {
620
1285
  duplicate()
621
1286
  return
622
1287
  }
1288
+ const dir = ({ ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] } as Record<string, number[]>)[e.key]
1289
+ if (dir && picked.value && tool.value === 'select') {
1290
+ e.preventDefault()
1291
+ const by = (step.value || 1) * (e.shiftKey ? 5 : 1)
1292
+ nudgePicked(dir[0]! * by, dir[1]! * by)
1293
+ return
1294
+ }
623
1295
  if (e.key !== 'Delete' && e.key !== 'Backspace') return
624
1296
  if (!picked.value && !selection.value.length) return
625
1297
  e.preventDefault()
@@ -632,7 +1304,16 @@ function removeSelected() {
632
1304
  }
633
1305
  const { kind, id, vertex } = picked.value
634
1306
  record()
635
- if (kind === 'area') areas.value = areas.value.filter((a) => a.id !== id)
1307
+ if (kind === 'area') {
1308
+ const a = areas.value.find((x) => x.id === id)
1309
+ // A picked corner of a zone of any shape goes (it keeps at least three)
1310
+ if (a?.points && vertex !== undefined && a.points.length > 3) {
1311
+ areas.value = areas.value.map((x) => (x.id === id ? shaped(x, x.points!.filter((_, i) => i !== vertex)) : x))
1312
+ picked.value = { kind: 'area', id }
1313
+ return
1314
+ }
1315
+ areas.value = areas.value.filter((x) => x.id !== id)
1316
+ }
636
1317
  if (kind === 'wall') {
637
1318
  const w = walls.value.find((x) => x.id === id)
638
1319
  // A picked corner goes (a wall keeps at least two); otherwise the whole wall
@@ -647,6 +1328,8 @@ function removeSelected() {
647
1328
  picked.value = null
648
1329
  }
649
1330
  const svgEl = ref<SVGSVGElement>()
1331
+ const zoneSvg = ref<SVGSVGElement>()
1332
+ const viewEl = ref<HTMLElement>()
650
1333
  /** Removes tables (and takes them out of their merges; a merge left with one table goes) */
651
1334
  function removeTables(ids: (string | number)[]) {
652
1335
  record()
@@ -658,7 +1341,13 @@ function removeTables(ids: (string | number)[]) {
658
1341
  function duplicate() {
659
1342
  const off = Math.max(20, (props.grid || 10) * 2)
660
1343
  if (selection.value.length) {
661
- const copies = tables.value.filter((t) => selection.value.includes(t.id)).map((t) => ({ ...t, id: newId('table'), x: t.x + off, y: t.y + off, status: undefined, badge: undefined }))
1344
+ const toff = props.cellSize || off
1345
+ // Past it, or back the other way when it would leave the plan
1346
+ const by = (v: number, half: number, max: number) => (v + toff + half <= max ? v + toff : v - toff)
1347
+ const copies = tables.value.filter((t) => selection.value.includes(t.id)).map((t) => {
1348
+ const sz = sizeOf(t)
1349
+ 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 }
1350
+ })
662
1351
  record()
663
1352
  tables.value = [...tables.value, ...copies]
664
1353
  selection.value = copies.map((t) => t.id)
@@ -668,14 +1357,19 @@ function duplicate() {
668
1357
  if (pk?.kind === 'area') {
669
1358
  const a = areas.value.find((x) => x.id === pk.id)
670
1359
  if (!a) return
671
- const c = { ...a, id: newId('area'), x: a.x + off, y: a.y + off }
1360
+ // Inside the plan: back up and to the left when there's no room past it
1361
+ const dx = a.x + a.width + off <= props.width ? off : Math.max(-a.x, -off)
1362
+ const dy = a.y + a.height + off <= props.height ? off : Math.max(-a.y, -off)
1363
+ 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
1364
  record()
673
1365
  areas.value = [...areas.value, c]
674
1366
  picked.value = { kind: 'area', id: c.id }
675
1367
  } else if (pk?.kind === 'decor') {
676
1368
  const d = decor.value.find((x) => x.id === pk.id)
677
1369
  if (!d) return
678
- const c = { ...d, id: newId('decor'), x: d.x + off, y: d.y + off }
1370
+ const s = decorSize(d)
1371
+ const inside = (v: number, half: number, max: number) => (v + off + half <= max ? v + off : Math.max(half, v - off))
1372
+ 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
1373
  record()
680
1374
  decor.value = [...decor.value, c]
681
1375
  picked.value = { kind: 'decor', id: c.id }
@@ -688,7 +1382,7 @@ function onRotateDown(e: PointerEvent, kind: 'table' | 'decor', id: string | num
688
1382
  e.stopPropagation()
689
1383
  e.preventDefault()
690
1384
  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
1385
+ 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
1386
  const mv = (ev: PointerEvent) => {
693
1387
  if (ev.pointerId !== e.pointerId) return
694
1388
  let deg = ((angle(ev) % 360) + 360) % 360
@@ -711,6 +1405,7 @@ function onRotateDown(e: PointerEvent, kind: 'table' | 'decor', id: string | num
711
1405
  window.addEventListener('pointerup', up)
712
1406
  window.addEventListener('pointercancel', up)
713
1407
  }
1408
+ const canRotate = (kind: 'table' | 'decor') => props.rotatable === true || (Array.isArray(props.rotatable) && props.rotatable.includes(kind))
714
1409
  const rotationOf = (kind: 'table' | 'decor', id: string | number, base?: number) => (rotateDraft.value?.kind === kind && rotateDraft.value.id === id ? rotateDraft.value.deg : base ?? 0)
715
1410
 
716
1411
  /**
@@ -750,19 +1445,23 @@ function update(kind: FloorItemKind, id: string | number, patch: Record<string,
750
1445
  if (key !== lastEdit.key || now - lastEdit.at > 1000) record()
751
1446
  lastEdit = { key, at: now }
752
1447
  const apply = <T extends { id: string | number }>(list: T[]) => list.map((x) => (x.id === id ? { ...x, ...patch } : x))
753
- if (kind === 'table') tables.value = apply(tables.value)
1448
+ // A table's patch is in your units (cells, a corner): applied to your list as it is
1449
+ if (kind === 'table') outerTables.value = apply(outerTables.value)
754
1450
  else if (kind === 'area') areas.value = apply(areas.value)
755
1451
  else if (kind === 'wall') walls.value = apply(walls.value)
756
1452
  else decor.value = apply(decor.value)
757
1453
  }
758
1454
  function addTable(t: Partial<FloorTable> = {}): FloorTable {
759
1455
  const n = Math.max(0, ...tables.value.map((x) => Number(x.label)).filter((x) => Number.isFinite(x))) + 1
760
- const table: FloorTable = { id: newId('table'), label: String(n), x: snapTable(props.width / 2), y: snapTable(props.height / 2), shape: 'square', seats: 4, ...t }
1456
+ const draft: FloorTable = { id: newId('table'), label: String(n), x: 0, y: 0, shape: 'square', seats: 4, ...t }
1457
+ // A position given is in your units; otherwise the plan's middle
1458
+ const at = toInner(draft)
1459
+ 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
1460
  record()
762
1461
  tables.value = [...tables.value, table]
763
1462
  selection.value = [table.id]
764
1463
  picked.value = null
765
- return table
1464
+ return outerOf(table)
766
1465
  }
767
1466
  function addDecor(kind: string, d: Partial<FloorDecor> = {}): FloorDecor {
768
1467
  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 +1472,8 @@ function addDecor(kind: string, d: Partial<FloorDecor> = {}): FloorDecor {
773
1472
  return item
774
1473
  }
775
1474
  const context: FloorPlanContext = {
776
- tables,
1475
+ // In your units, as you keep them
1476
+ tables: outerTables,
777
1477
  areas,
778
1478
  walls,
779
1479
  decor,
@@ -789,6 +1489,8 @@ const context: FloorPlanContext = {
789
1489
  hover.value = null
790
1490
  },
791
1491
  kinds,
1492
+ tableSize: (t: FloorTable) => sizeOf(t),
1493
+ measure: computed(() => props.measure),
792
1494
  statuses: computed(() => props.statuses),
793
1495
  size: computed(() => ({ width: props.width, height: props.height })),
794
1496
  canUndo: computed(() => past.value.length > 0),
@@ -825,38 +1527,174 @@ defineExpose({
825
1527
  duplicate,
826
1528
  /** Remove tables, taking them out of their merges (Delete does it for the selection) */
827
1529
  removeTables,
1530
+ /** Zoom (with `zoomable`): to a level, keeping the plan point under (px, py) in place; and centering on a plan point */
1531
+ zoomTo,
1532
+ centerOn,
1533
+ /** The plan as a standalone SVG string, or a PNG Blob (`pixelRatio` px per plan unit) */
1534
+ toSVG,
1535
+ toPNG,
828
1536
  })
829
1537
  /** Double-click on a wall: a new corner there, on the nearest segment */
830
1538
  function onWallDblclick(e: MouseEvent, w: FloorWall) {
831
1539
  if (!props.editable || tool.value !== 'select') return
832
1540
  e.stopPropagation()
833
1541
  const p = toPlan(e)
834
- let best = 0
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
- }
1542
+ const best = nearestSegment(w.points, p, false)
847
1543
  const pt: [number, number] = [snap(p.x), snap(p.y)]
848
1544
  record()
849
1545
  walls.value = walls.value.map((x) => (x.id === w.id ? { ...x, points: [...x.points.slice(0, best), pt, ...x.points.slice(best)] } : x))
850
1546
  picked.value = { kind: 'wall', id: w.id, vertex: best }
851
1547
  }
852
1548
 
1549
+ // ── Export: the plan as a picture ──
1550
+ const esc = (t: unknown) => String(t ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
1551
+ /**
1552
+ * The plan as a standalone SVG (plan units, its own colors resolved from the theme): zones, walls, decor, merges,
1553
+ * tables with their chairs and labels, and the background image if any. Icons are left out (they're a font)
1554
+ */
1555
+ function toSVG(): string {
1556
+ const cs = getComputedStyle(root.value!)
1557
+ const v = (name: string) => cs.getPropertyValue(name).trim()
1558
+ // Theme variables to the colors they hold, so the file looks the same anywhere
1559
+ const resolve = (c: string) => c.replace(/var\((--[\w-]+)\)/g, (_, n: string) => v(n) || 'currentColor')
1560
+ const role = (c: string, suffix = '') => (ROLES.has(c) ? v(`--color-${c}${suffix}`) : resolve(c))
1561
+ const font = cs.fontFamily.replace(/"/g, "'")
1562
+ const out: string[] = []
1563
+ const W = props.width
1564
+ const H = props.height
1565
+ out.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`)
1566
+ out.push(`<rect width="${W}" height="${H}" fill="${esc(cs.backgroundColor)}"/>`)
1567
+ if (props.backgroundImage) {
1568
+ const b = props.backgroundBox ?? { x: 0, y: 0, width: W, height: H }
1569
+ out.push(`<image href="${esc(props.backgroundImage)}" x="${b.x}" y="${b.y}" width="${b.width}" height="${b.height}" opacity="${props.backgroundOpacity}" preserveAspectRatio="none"/>`)
1570
+ }
1571
+ const labelColor = v('--color-on-surface-variant')
1572
+ for (const a of areas.value) {
1573
+ const c = a.color ?? 'secondary'
1574
+ const fill = ROLES.has(c) ? role(c, '-container') : resolve(c)
1575
+ const paint = `fill="${esc(fill)}" fill-opacity="${ROLES.has(c) ? 0.45 : 0.18}" stroke="${esc(role(c))}"`
1576
+ if (a.points) out.push(`<polygon points="${a.points.map((p) => p.join(',')).join(' ')}" ${paint}/>`)
1577
+ else out.push(`<rect x="${a.x}" y="${a.y}" width="${a.width}" height="${a.height}" rx="8" ${paint}/>`)
1578
+ const at = a.points?.[0] ?? [a.x, a.y]
1579
+ if (a.label) out.push(`<text x="${at[0] + 8}" y="${at[1] + 18}" font-size="12" fill="${esc(labelColor)}">${esc(a.label)}</text>`)
1580
+ }
1581
+ const wall = v('--m3-floor-wall')
1582
+ 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"/>`)
1583
+ const planBg = cs.backgroundColor
1584
+ for (const d of decor.value) {
1585
+ const k = kindOf(d)
1586
+ const { w, h } = decorSize(d)
1587
+ const shape = k.shape ?? 'box'
1588
+ out.push(`<g transform="translate(${d.x} ${d.y}) rotate(${d.rotation ?? 0})${d.flip ? ' scale(-1 1)' : ''}">`)
1589
+ if (shape === 'text') out.push(`<text text-anchor="middle" dominant-baseline="central" font-size="16" fill="${esc(labelColor)}">${esc(d.label)}</text>`)
1590
+ else if (shape === 'door') {
1591
+ out.push(`<rect x="${-w / 2}" y="${-h / 2}" width="${w}" height="${h}" fill="${esc(k.color ? resolve(k.color) : planBg)}"/>`)
1592
+ 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"/>`)
1593
+ out.push(`<line x1="${-w / 2}" y1="${-h / 2}" x2="${-w / 2}" y2="${-h / 2 - w}" stroke="${esc(wall)}" stroke-width="2"/>`)
1594
+ 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)}"/>`)
1595
+ } else if (shape === 'window') {
1596
+ 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"/>`)
1597
+ 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"/>`)
1598
+ } else {
1599
+ const look = decorLook(k) as { background?: string }
1600
+ 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'))}"/>`)
1601
+ if (d.label) out.push(`<text y="${h / 2 + 12}" text-anchor="middle" font-size="11" fill="${esc(labelColor)}">${esc(d.label)}</text>`)
1602
+ }
1603
+ out.push('</g>')
1604
+ }
1605
+ const merge = v('--m3-floor-merge')
1606
+ for (const ms of mergeShapes.value) {
1607
+ 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"/>`)
1608
+ 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"/>`)
1609
+ }
1610
+ const chair = v('--m3-floor-chair')
1611
+ for (const p of placed.value) {
1612
+ const r = p.t.rotation ?? 0
1613
+ const lk = look(p.status)
1614
+ out.push(`<g transform="translate(${p.x} ${p.y}) rotate(${r})">`)
1615
+ p.chairs.forEach((ch, i) => {
1616
+ const taken = p.t.activeSeats?.includes(i + 1) ? (seatTaken(p.status) as { background: string }).background : chair
1617
+ 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})"/>`)
1618
+ })
1619
+ const { w, h } = p.size
1620
+ if ((p.t.shape ?? 'square') === 'round') out.push(`<ellipse rx="${w / 2}" ry="${h / 2}" fill="${esc(resolve(lk.background))}"/>`)
1621
+ else out.push(`<rect x="${-w / 2}" y="${-h / 2}" width="${w}" height="${h}" rx="8" fill="${esc(resolve(lk.background))}"/>`)
1622
+ 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>`)
1623
+ out.push('</g>')
1624
+ }
1625
+ out.push('</svg>')
1626
+ return out.join('')
1627
+ }
1628
+ /**
1629
+ * The plan as a PNG, `pixelRatio` px per plan unit. A background image from another origin without CORS taints the
1630
+ * canvas, and then this rejects
1631
+ */
1632
+ async function toPNG(pixelRatio = 2): Promise<Blob> {
1633
+ const img = new Image()
1634
+ img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(toSVG())}`
1635
+ await img.decode()
1636
+ const canvas = document.createElement('canvas')
1637
+ canvas.width = Math.round(props.width * pixelRatio)
1638
+ canvas.height = Math.round(props.height * pixelRatio)
1639
+ canvas.getContext('2d')!.drawImage(img, 0, 0, canvas.width, canvas.height)
1640
+ return new Promise((res, rej) => canvas.toBlob((b) => (b ? res(b) : rej(new Error('toPNG: the canvas gave no image'))), 'image/png'))
1641
+ }
1642
+
1643
+ // ── Measurements: lengths in your unit while editing ──
1644
+ const measured = (v: number) => {
1645
+ const m = props.measure!
1646
+ return `${(v / m.per).toFixed(m.decimals ?? 2)} ${m.unit}`
1647
+ }
1648
+ const measureLabels = computed(() => {
1649
+ const out: { x: number; y: number; text: string }[] = []
1650
+ if (!props.measure || !props.editable) return out
1651
+ const sides = (pts: [number, number][], closed: boolean) => {
1652
+ const n = closed ? pts.length : pts.length - 1
1653
+ for (let i = 0; i < n; i++) {
1654
+ const [ax, ay] = pts[i]!
1655
+ const [bx, by] = pts[(i + 1) % pts.length]!
1656
+ const len = Math.hypot(bx - ax, by - ay)
1657
+ if (len > 0) out.push({ x: (ax + bx) / 2, y: (ay + by) / 2, text: measured(len) })
1658
+ }
1659
+ }
1660
+ const pk = picked.value
1661
+ if (pk?.kind === 'wall') {
1662
+ const w = shownWalls.value.find((x) => x.id === pk.id)
1663
+ if (w) sides(w.points, false)
1664
+ } else if (pk?.kind === 'area') {
1665
+ const a = shownAreas.value.find((x) => x.id === pk.id)
1666
+ if (a) sides(a.points ?? rectCorners(a), true)
1667
+ } else if (pk?.kind === 'decor') {
1668
+ const d = shownDecor.value.find((x) => x.id === pk.id)
1669
+ if (d) {
1670
+ const sz = decorSize(d)
1671
+ 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)}` })
1672
+ }
1673
+ } else if (selection.value.length === 1) {
1674
+ const p = placed.value.find((x) => x.t.id === selection.value[0])
1675
+ 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)}` })
1676
+ }
1677
+ if (drawing.value && hover.value) {
1678
+ const last = drawing.value[drawing.value.length - 1]!
1679
+ sides([last, hover.value], false)
1680
+ }
1681
+ return out
1682
+ })
853
1683
  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(', ')
1684
+ [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(', ')
1685
+ // 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
1686
  const gridStyle = computed(() => {
1687
+ if (!props.editable || !props.showGrid || !props.grid) return {}
856
1688
  const g = (props.grid >= 10 ? props.grid : props.grid * Math.ceil(10 / Math.max(1, props.grid))) * scale.value
857
- return props.editable && props.showGrid && props.grid
858
- ? { backgroundImage: 'radial-gradient(circle, var(--color-outline-variant) 1px, transparent 1.2px)', backgroundSize: `${g}px ${g}px` }
859
- : {}
1689
+ const dot = 'radial-gradient(circle, var(--color-outline-variant) 1px, transparent 1.2px)'
1690
+ const sub = Math.max(1, Math.round(props.subgrid))
1691
+ const fine = g / sub
1692
+ if (sub === 1 || props.grid < 10 || fine < 6) return { backgroundImage: dot, backgroundSize: `${g}px ${g}px`, backgroundPosition: `${-g / 2}px ${-g / 2}px` }
1693
+ return {
1694
+ backgroundImage: `${dot}, radial-gradient(circle, color-mix(in srgb, var(--color-outline-variant) 70%, transparent) 0.6px, transparent 0.9px)`,
1695
+ backgroundSize: `${g}px ${g}px, ${fine}px ${fine}px`,
1696
+ backgroundPosition: `${-g / 2}px ${-g / 2}px, ${-fine / 2}px ${-fine / 2}px`,
1697
+ }
860
1698
  })
861
1699
  </script>
862
1700
 
@@ -864,7 +1702,7 @@ const gridStyle = computed(() => {
864
1702
  <div
865
1703
  ref="root"
866
1704
  class="m3-floor-plan select-none"
867
- :style="{ aspectRatio: `${width} / ${height}`, ...gridStyle }"
1705
+ :style="{ aspectRatio: `${width} / ${height}`, touchAction }"
868
1706
  role="group"
869
1707
  tabindex="-1"
870
1708
  :aria-label="label ?? locale.floorPlan"
@@ -874,14 +1712,36 @@ const gridStyle = computed(() => {
874
1712
  @dblclick="drawing && finishWall()"
875
1713
  @keydown="onPlanKey"
876
1714
  >
1715
+ <!-- Everything on the plan, as big as the zoom makes it, moved by the pan -->
1716
+ <div
1717
+ ref="viewEl"
1718
+ class="m3-floor-view absolute top-0 left-0"
1719
+ :style="{ width: `${width * scale}px`, height: `${height * scale}px`, transform: pan.x || pan.y ? `translate(${pan.x}px, ${pan.y}px)` : undefined, ...gridStyle }"
1720
+ >
1721
+ <img
1722
+ v-if="backgroundImage"
1723
+ :src="backgroundImage"
1724
+ alt=""
1725
+ draggable="false"
1726
+ data-floor-bg
1727
+ class="absolute max-w-none select-none"
1728
+ :style="{
1729
+ left: `${(backgroundBox?.x ?? 0) * scale}px`,
1730
+ top: `${(backgroundBox?.y ?? 0) * scale}px`,
1731
+ width: `${(backgroundBox?.width ?? width) * scale}px`,
1732
+ height: `${(backgroundBox?.height ?? height) * scale}px`,
1733
+ opacity: backgroundOpacity,
1734
+ }"
1735
+ />
877
1736
  <!-- Zones -->
878
1737
  <div
879
- v-for="a in shownAreas"
1738
+ v-for="a in shownAreas.filter((x) => !x.points)"
880
1739
  :key="`a${a.id}`"
881
1740
  class="absolute rounded-lg border"
882
1741
  :class="[editable && tool === 'select' ? 'cursor-move touch-none' : 'pointer-events-none', isPicked('area', a.id) && 'ring-2 ring-primary']"
883
1742
  :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
1743
  @pointerdown="onAreaDown($event, a, null)"
1744
+ @dblclick="onAreaDblclick($event, a)"
885
1745
  >
886
1746
  <slot name="area" :area="a" :picked="isPicked('area', a.id)" :scale="scale">
887
1747
  <span v-if="a.label" class="absolute top-1 left-2 text-label-medium text-on-surface-variant">{{ a.label }}</span>
@@ -898,6 +1758,50 @@ const gridStyle = computed(() => {
898
1758
  </template>
899
1759
  </div>
900
1760
 
1761
+ <!-- Zones of any shape: their outline, then their label (or your #area) in the box around them -->
1762
+ <svg ref="zoneSvg" class="pointer-events-none absolute inset-0 size-full overflow-visible">
1763
+ <g v-for="a in shownAreas.filter((x) => x.points)" :key="`ap${a.id}`">
1764
+ <path
1765
+ :d="polyPath(a.points!)"
1766
+ stroke-width="1"
1767
+ stroke-linejoin="round"
1768
+ :style="areaSvgLook(a.color)"
1769
+ :class="[editable && tool === 'select' && 'pointer-events-auto cursor-move touch-none', isPicked('area', a.id) && 'm3-floor-zone-picked']"
1770
+ :data-zone="a.id"
1771
+ @pointerdown="onAreaDown($event, a, null)"
1772
+ @dblclick="onAreaDblclick($event, a)"
1773
+ />
1774
+ <template v-if="editable && isPicked('area', a.id)">
1775
+ <circle
1776
+ v-for="(pt, i) in a.points"
1777
+ :key="i"
1778
+ :cx="pt[0] * scale"
1779
+ :cy="pt[1] * scale"
1780
+ :r="(picked?.vertex === i ? 7 : 5) * (coarse ? 1.6 : 1)"
1781
+ class="pointer-events-auto cursor-move touch-none stroke-primary"
1782
+ :class="picked?.vertex === i ? 'fill-primary' : 'fill-surface'"
1783
+ stroke-width="2"
1784
+ :data-zone-corner="i"
1785
+ @pointerdown="onAreaVertexDown($event, a, i)"
1786
+ />
1787
+ </template>
1788
+ </g>
1789
+ </svg>
1790
+ <div
1791
+ v-for="a in shownAreas.filter((x) => x.points)"
1792
+ :key="`al${a.id}`"
1793
+ class="pointer-events-none absolute"
1794
+ :style="{ left: `${a.x * scale}px`, top: `${a.y * scale}px`, width: `${a.width * scale}px`, height: `${a.height * scale}px` }"
1795
+ >
1796
+ <slot name="area" :area="a" :picked="isPicked('area', a.id)" :scale="scale">
1797
+ <span
1798
+ v-if="a.label"
1799
+ class="absolute text-label-medium whitespace-nowrap text-on-surface-variant"
1800
+ :style="{ left: `${(a.points![0]![0] - a.x) * scale + 8}px`, top: `${(a.points![0]![1] - a.y) * scale + 4}px` }"
1801
+ >{{ a.label }}</span>
1802
+ </slot>
1803
+ </div>
1804
+
901
1805
  <!-- Walls -->
902
1806
  <svg ref="svgEl" class="pointer-events-none absolute inset-0 size-full overflow-visible">
903
1807
  <g v-for="w in shownWalls" :key="`w${w.id}`">
@@ -927,7 +1831,14 @@ const gridStyle = computed(() => {
927
1831
  </template>
928
1832
  </g>
929
1833
  <path
930
- v-if="drawing"
1834
+ v-if="drawing && tool === 'polygon'"
1835
+ :d="polyPath(hover ? [...drawing, hover] : drawing)"
1836
+ class="m3-floor-zone-draft stroke-primary"
1837
+ stroke-dasharray="6 4"
1838
+ stroke-width="2"
1839
+ />
1840
+ <path
1841
+ v-else-if="drawing"
931
1842
  :d="wallPath({ id: 'new', points: hover ? [...drawing, hover] : drawing })"
932
1843
  fill="none"
933
1844
  class="stroke-primary"
@@ -952,17 +1863,35 @@ const gridStyle = computed(() => {
952
1863
  @pointerdown="onDecorDown($event, d)"
953
1864
  >
954
1865
  <slot name="decor" :item="d" :kind="kindOf(d)" :picked="isPicked('decor', d.id)" :scale="scale">
955
- <MIcon v-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)" />
1866
+ <!-- A door: the jambs, the leaf standing open and its swing, as an architect draws it -->
1867
+ <svg
1868
+ v-if="kindOf(d).shape === 'door'"
1869
+ class="pointer-events-none absolute inset-0 size-full overflow-visible"
1870
+ :style="d.flip ? { transform: 'scaleX(-1)' } : undefined"
1871
+ aria-hidden="true"
1872
+ >
1873
+ <path :d="doorSwing(decorSize(d).w * scale)" class="m3-floor-door-swing" stroke-width="1" stroke-dasharray="3 3" />
1874
+ <line x1="0" y1="0" x2="0" :y2="-decorSize(d).w * scale" class="m3-floor-door" stroke-width="2" stroke-linecap="round" />
1875
+ <rect x="0" y="0" :width="Math.max(2, 3 * scale)" height="100%" class="m3-floor-door-jamb" />
1876
+ <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" />
1877
+ </svg>
1878
+ <!-- A window: its frame and the pane down the middle -->
1879
+ <svg v-else-if="kindOf(d).shape === 'window'" class="pointer-events-none absolute inset-0 size-full overflow-visible" aria-hidden="true">
1880
+ <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" />
1881
+ <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" />
1882
+ </svg>
1883
+ <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
1884
  <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
1885
  </slot>
958
1886
  <span
959
1887
  v-if="editable && isPicked('decor', d.id)"
960
- class="m3-floor-handle absolute -right-1.5 -bottom-1.5 size-3 cursor-nwse-resize rounded-xs border-2 border-primary bg-surface"
1888
+ class="m3-floor-handle absolute -right-1.5 -bottom-1.5 size-3 rounded-xs border-2 border-primary bg-surface"
1889
+ :style="{ cursor: resizeCursor(rotationOf('decor', d.id, d.rotation)) }"
961
1890
  data-resize
962
1891
  @pointerdown="onDecorDown($event, d, true)"
963
1892
  />
964
1893
  <span
965
- v-if="editable && rotatable && isPicked('decor', d.id)"
1894
+ v-if="editable && canRotate('decor') && isPicked('decor', d.id)"
966
1895
  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
1896
  :aria-label="locale.floorRotate"
968
1897
  data-rotate
@@ -1004,44 +1933,74 @@ const gridStyle = computed(() => {
1004
1933
  v-for="p in placed"
1005
1934
  :key="p.t.id"
1006
1935
  class="absolute"
1007
- :class="!draft?.has(p.t.id) && 'transition-[left,top] duration-200 ease-out'"
1936
+ :class="!draft?.has(p.t.id) && !rescaling && 'transition-[left,top] duration-200 ease-out'"
1008
1937
  :style="{ left: `${p.x * scale}px`, top: `${p.y * scale}px`, transform: `rotate(${rotationOf('table', p.t.id, p.t.rotation)}deg)` }"
1009
1938
  >
1010
1939
  <!-- Rotation handle of the one table picked while editing -->
1011
1940
  <span
1012
- v-if="editable && rotatable && selection.length === 1 && selection[0] === p.t.id && tool === 'select'"
1941
+ v-if="editable && canRotate('table') && selection.length === 1 && selection[0] === p.t.id && tool === 'select'"
1013
1942
  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
1943
  :style="{ left: '0px', top: `${-(p.size.h / 2 + CHAIR + 18) * scale}px` }"
1015
1944
  :aria-label="locale.floorRotate"
1016
1945
  data-rotate
1017
1946
  @pointerdown="onRotateDown($event, 'table', p.t.id, p.x, p.y)"
1018
1947
  />
1948
+ <!-- Size handle of the one table picked while editing (at its corner, turning with it) -->
1949
+ <span
1950
+ v-if="editable && resizable && selection.length === 1 && selection[0] === p.t.id && tool === 'select'"
1951
+ 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"
1952
+ :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)) }"
1953
+ data-table-resize
1954
+ @pointerdown="onTableResize($event, p.t)"
1955
+ />
1019
1956
  <span
1020
1957
  v-for="(ch, i) in p.chairs"
1021
1958
  :key="i"
1022
- class="m3-floor-chair pointer-events-none absolute rounded-md"
1023
- :style="{ width: `${CHAIR * scale}px`, height: `${CHAIR * 0.75 * scale}px`, left: `${ch.x * scale}px`, top: `${ch.y * scale}px`, transform: `translate(-50%, -50%) rotate(${ch.r}deg)` }"
1024
- />
1959
+ class="m3-floor-chair absolute flex items-center justify-center rounded-md"
1960
+ :class="[seatNumbers && !editable ? 'cursor-pointer' : 'pointer-events-none', p.t.activeSeats?.includes(i + 1) && 'm3-floor-chair-taken']"
1961
+ :style="{
1962
+ width: `${CHAIR * scale}px`,
1963
+ height: `${CHAIR * 0.75 * scale}px`,
1964
+ left: `${ch.x * scale}px`,
1965
+ top: `${ch.y * scale}px`,
1966
+ transform: `translate(-50%, -50%) rotate(${ch.r}deg)`,
1967
+ ...(p.t.activeSeats?.includes(i + 1) && seatTaken(p.status)),
1968
+ }"
1969
+ :data-seat="i + 1"
1970
+ :aria-label="seatNumbers ? locale.floorSeatN.replace('{n}', String(i + 1)) : undefined"
1971
+ @click="seatNumbers && !editable && emit('seat-click', outerOf(p.t), i + 1, $event)"
1972
+ >
1973
+ <span
1974
+ v-if="seatNumbers && scale * CHAIR >= 10"
1975
+ class="pointer-events-none leading-none font-medium"
1976
+ :style="{ fontSize: `${Math.max(7, 9 * scale)}px`, transform: `rotate(${-ch.r - rotationOf('table', p.t.id, p.t.rotation)}deg)` }"
1977
+ >{{ i + 1 }}</span>
1978
+ </span>
1025
1979
  <div
1026
1980
  role="button"
1027
1981
  tabindex="0"
1982
+ data-floor-table
1028
1983
  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
1984
  :class="[
1030
1985
  (p.t.shape ?? 'square') === 'round' ? 'rounded-full' : 'rounded-lg',
1031
1986
  editable ? 'cursor-grab touch-none active:cursor-grabbing' : 'cursor-pointer hover:shadow-elevation-2',
1032
1987
  selection.includes(p.t.id) && 'ring-2 ring-primary',
1033
1988
  draft?.has(p.t.id) && 'shadow-elevation-3',
1989
+ transferDrag?.id === p.t.id && 'opacity-50',
1990
+ overlapping.has(p.t.id) && 'm3-floor-overlap',
1991
+ transferDrag?.over === p.t.id && (transferDrag.ok ? 'ring-4 ring-primary' : 'ring-4 ring-error'),
1034
1992
  ]"
1035
1993
  :style="{ width: `${p.size.w * scale}px`, height: `${p.size.h * scale}px`, ...look(p.status), fontSize: `${Math.max(9, 14 * scale)}px` }"
1036
1994
  :aria-label="ariaOf(p)"
1037
1995
  :aria-pressed="editable ? selection.includes(p.t.id) : undefined"
1038
1996
  @pointerdown="onDown($event, p.t)"
1997
+ @contextmenu="transferable && !editable && $event.preventDefault()"
1039
1998
  @click="onClick($event, p.t)"
1040
1999
  @keydown="onKey($event, p.t)"
1041
2000
  >
1042
2001
  <!-- The inside stays upright however the table turns -->
1043
2002
  <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)">
2003
+ <slot name="table" :table="outerOf(p.t)" :status="p.status" :selected="selection.includes(p.t.id)">
1045
2004
  <MIcon v-if="p.status?.icon && scale > 0.5" :name="p.status.icon" :size="Math.max(12, 18 * scale)" class="opacity-80" />
1046
2005
  <span class="max-w-full truncate px-1 leading-tight font-medium">{{ p.t.label }}</span>
1047
2006
  </slot>
@@ -1053,14 +2012,41 @@ const gridStyle = computed(() => {
1053
2012
  >{{ p.t.badge }}</span>
1054
2013
  </div>
1055
2014
  </div>
2015
+ <!-- A table being carried to another one (its party moves there) -->
2016
+ <div
2017
+ v-if="transferDrag"
2018
+ 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"
2019
+ :style="{ left: `${transferDrag.x * scale}px`, top: `${transferDrag.y * scale}px` }"
2020
+ ><MIcon name="move_down" :size="18" />{{ transferDrag.label }}</div>
2021
+ <!-- Lengths in your unit (measure) -->
2022
+ <span
2023
+ v-for="(m, i) in measureLabels"
2024
+ :key="`ms${i}`"
2025
+ 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"
2026
+ :style="{ left: `${m.x * scale}px`, top: `${m.y * scale}px` }"
2027
+ >{{ m.text }}</span>
2028
+ <!-- The rectangle a mouse drags out to select tables -->
2029
+ <div
2030
+ v-if="marquee"
2031
+ class="m3-floor-marquee pointer-events-none absolute rounded-xs border border-dashed"
2032
+ :style="{ left: `${marquee.x * scale}px`, top: `${marquee.y * scale}px`, width: `${marquee.w * scale}px`, height: `${marquee.h * scale}px` }"
2033
+ />
1056
2034
  <!-- Anything of yours over the plan, placed in plan units with toPx -->
1057
2035
  <slot name="overlay" :scale="scale" :to-px="(v: number) => v * scale" />
2036
+ </div>
2037
+ <!-- Zoom: in, out, the whole plan (they don't move with the pan) -->
2038
+ <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>
2039
+ <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>
2040
+ <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>
2041
+ <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>
2042
+ </div>
1058
2043
  </div>
1059
2044
  </template>
1060
2045
 
1061
2046
  <style>
1062
2047
  /* 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-chair, --m3-floor-merge, --m3-floor-merge-label */
2048
+ --m3-floor-wall (walls, doors, window frames), --m3-floor-wall-picked, --m3-floor-window (a window's pane),
2049
+ --m3-floor-chair, --m3-floor-merge, --m3-floor-merge-label */
1064
2050
  @layer base {
1065
2051
  .m3-floor-plan {
1066
2052
  --m3-floor-wall: var(--color-on-surface-variant);
@@ -1096,8 +2082,79 @@ const gridStyle = computed(() => {
1096
2082
  .m3-floor-wall-picked {
1097
2083
  stroke: var(--m3-floor-wall-picked);
1098
2084
  }
2085
+ .m3-floor-door {
2086
+ stroke: var(--m3-floor-wall);
2087
+ }
2088
+ .m3-floor-door-jamb {
2089
+ fill: var(--m3-floor-wall);
2090
+ }
2091
+ .m3-floor-door-swing {
2092
+ stroke: color-mix(in srgb, var(--m3-floor-wall) 55%, transparent);
2093
+ fill: color-mix(in srgb, var(--m3-floor-wall) 6%, transparent);
2094
+ }
2095
+ .m3-floor-window {
2096
+ stroke: var(--m3-floor-wall);
2097
+ }
2098
+ .m3-floor-window-pane {
2099
+ stroke: var(--m3-floor-window, var(--color-primary));
2100
+ }
2101
+ .m3-floor-view {
2102
+ /* Doors and windows take this color to cut the wall they sit on */
2103
+ background-color: inherit;
2104
+ }
2105
+ .m3-floor-carry {
2106
+ background: var(--color-inverse-surface);
2107
+ color: var(--color-inverse-on-surface);
2108
+ }
2109
+ .m3-floor-zone-picked {
2110
+ stroke: var(--color-primary);
2111
+ stroke-width: 2;
2112
+ }
2113
+ .m3-floor-zone-draft {
2114
+ fill: color-mix(in srgb, var(--color-primary) 8%, transparent);
2115
+ }
2116
+ /* On a pseudo-element: the table's own outline and shadow are utilities, which win over this layer */
2117
+ .m3-floor-overlap::after {
2118
+ content: '';
2119
+ position: absolute;
2120
+ inset: -5px;
2121
+ border: 2px dashed var(--color-error);
2122
+ border-radius: inherit;
2123
+ pointer-events: none;
2124
+ }
2125
+ .m3-floor-measure {
2126
+ background: var(--color-inverse-surface);
2127
+ color: var(--color-inverse-on-surface);
2128
+ }
2129
+ .m3-floor-marquee {
2130
+ border-color: var(--color-primary);
2131
+ background: color-mix(in srgb, var(--color-primary) 8%, transparent);
2132
+ }
2133
+ .m3-floor-zoom {
2134
+ background: var(--color-surface-container-high);
2135
+ }
2136
+ .m3-floor-zoom-btn {
2137
+ display: flex;
2138
+ width: 40px;
2139
+ height: 40px;
2140
+ align-items: center;
2141
+ justify-content: center;
2142
+ color: var(--color-on-surface-variant);
2143
+ transition: background-color 150ms;
2144
+ }
2145
+ .m3-floor-zoom-btn:hover:not(:disabled) {
2146
+ background: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
2147
+ }
2148
+ .m3-floor-zoom-btn:focus-visible {
2149
+ outline: 2px solid var(--color-secondary);
2150
+ outline-offset: -2px;
2151
+ }
2152
+ .m3-floor-zoom-btn:disabled {
2153
+ color: color-mix(in srgb, var(--color-on-surface) 38%, transparent);
2154
+ }
1099
2155
  .m3-floor-chair {
1100
2156
  background: var(--m3-floor-chair);
2157
+ color: var(--color-on-surface-variant);
1101
2158
  }
1102
2159
  .m3-floor-merge {
1103
2160
  border-color: color-mix(in srgb, var(--m3-floor-merge) 60%, transparent);