@m3ui-vue/m3ui-vue 1.3.0 → 1.3.2

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 (68) hide show
  1. package/dist/API.md +215 -4
  2. package/dist/{MButton-CuNzpoxm.js → MButton-Bl_BSUep.js} +2 -2
  3. package/dist/{MButton-CuNzpoxm.js.map → MButton-Bl_BSUep.js.map} +1 -1
  4. package/dist/{MDialog-HxEL-m58.js → MDialog-D_Yik8ou.js} +2 -2
  5. package/dist/{MDialog-HxEL-m58.js.map → MDialog-D_Yik8ou.js.map} +1 -1
  6. package/dist/{MListItem-DnPtv-hY.js → MListItem-BxifHJdU.js} +2 -2
  7. package/dist/{MListItem-DnPtv-hY.js.map → MListItem-BxifHJdU.js.map} +1 -1
  8. package/dist/{MLoadingIndicator-BQMNX6Dx.js → MLoadingIndicator-BxbFhSX6.js} +2 -2
  9. package/dist/{MLoadingIndicator-BQMNX6Dx.js.map → MLoadingIndicator-BxbFhSX6.js.map} +1 -1
  10. package/dist/{MSeekBar-LURE1Ah7.js → MSeekBar-BeN9QcB3.js} +2 -2
  11. package/dist/{MSeekBar-LURE1Ah7.js.map → MSeekBar-BeN9QcB3.js.map} +1 -1
  12. package/dist/{MSlider-_J4IS2_z.js → MSlider-BVSbJlGS.js} +2 -2
  13. package/dist/{MSlider-_J4IS2_z.js.map → MSlider-BVSbJlGS.js.map} +1 -1
  14. package/dist/{MSpinner-BhkMYKOM.js → MSpinner-C2SUnWk4.js} +2 -2
  15. package/dist/{MSpinner-BhkMYKOM.js.map → MSpinner-C2SUnWk4.js.map} +1 -1
  16. package/dist/{MTextField-CkzwNBWS.js → MTextField-CEkWSZ2v.js} +2 -2
  17. package/dist/{MTextField-CkzwNBWS.js.map → MTextField-CEkWSZ2v.js.map} +1 -1
  18. package/dist/{MTooltip-B67ZDSGp.js → MTooltip-CodJGEO-.js} +4 -4
  19. package/dist/{MTooltip-B67ZDSGp.js.map → MTooltip-CodJGEO-.js.map} +1 -1
  20. package/dist/api.json +1 -1
  21. package/dist/code-editor.js +1 -1
  22. package/dist/components/MDrawCanvas.vue.d.ts +3 -1
  23. package/dist/components/MFloorPlan.vue.d.ts +100 -2
  24. package/dist/components/MFloorPlanInspector.vue.d.ts +56 -0
  25. package/dist/components/MFloorPlanToolbar.vue.d.ts +51 -0
  26. package/dist/components/MFlow.vue.d.ts +13 -0
  27. package/dist/composables/useFloorPlan.d.ts +58 -0
  28. package/dist/composables/useLocale.d.ts +41 -0
  29. package/dist/draw.js +11 -9
  30. package/dist/draw.js.map +1 -1
  31. package/dist/flow.js +6 -1
  32. package/dist/flow.js.map +1 -1
  33. package/dist/gantt.js +1 -1
  34. package/dist/index.d.ts +6 -1
  35. package/dist/locales/index.js +287 -0
  36. package/dist/locales/index.js.map +1 -1
  37. package/dist/m3ui-vue.css +1 -1
  38. package/dist/m3ui.js +2938 -1945
  39. package/dist/m3ui.js.map +1 -1
  40. package/dist/map.js +5 -5
  41. package/dist/media.js +31 -31
  42. package/dist/pdf.js +5 -5
  43. package/dist/pdf.js.map +1 -1
  44. package/dist/rich-text-editor.js +4 -4
  45. package/dist/styles.css +1 -1
  46. package/dist/{useLocale-BpGxplLV.js → useLocale-CaWwi-b6.js} +42 -1
  47. package/dist/useLocale-CaWwi-b6.js.map +1 -0
  48. package/package.json +1 -1
  49. package/src/__tests__/MDrawCanvas.test.ts +8 -0
  50. package/src/__tests__/MFloorPlan.test.ts +235 -3
  51. package/src/__tests__/MFlow.test.ts +15 -0
  52. package/src/components/MDrawCanvas.vue +9 -3
  53. package/src/components/MFloorPlan.vue +586 -74
  54. package/src/components/MFloorPlanInspector.vue +169 -0
  55. package/src/components/MFloorPlanToolbar.vue +128 -0
  56. package/src/components/MFlow.vue +11 -0
  57. package/src/components/MPdfViewer.vue +2 -1
  58. package/src/composables/useFloorPlan.ts +73 -0
  59. package/src/composables/useLocale.ts +82 -0
  60. package/src/index.ts +6 -1
  61. package/src/locales/de.ts +41 -0
  62. package/src/locales/es.ts +41 -0
  63. package/src/locales/fr.ts +41 -0
  64. package/src/locales/ja.ts +41 -0
  65. package/src/locales/ko.ts +41 -0
  66. package/src/locales/pt.ts +41 -0
  67. package/src/locales/zh.ts +41 -0
  68. package/dist/useLocale-BpGxplLV.js.map +0 -1
@@ -44,7 +44,8 @@ export interface FloorWall {
44
44
  /** Something on the plan that isn't a table: a door, a window, a plant, a column, the register, a text label… */
45
45
  export interface FloorDecor {
46
46
  id: string | number
47
- kind: 'door' | 'window' | 'plant' | 'column' | 'restroom' | 'kitchen' | 'register' | 'stairs' | 'label'
47
+ /** A built-in kind, or one of yours from `decorKinds` */
48
+ kind: FloorDecorBuiltin | (string & {})
48
49
  x: number
49
50
  y: number
50
51
  width?: number
@@ -53,6 +54,21 @@ export interface FloorDecor {
53
54
  /** The text of a label (or a caption under the others) */
54
55
  label?: string
55
56
  }
57
+ export type FloorDecorBuiltin = 'door' | 'window' | 'plant' | 'column' | 'restroom' | 'kitchen' | 'register' | 'stairs' | 'label'
58
+ /** How a decor kind looks: its default size, an icon, a shape and fill; yours or a built-in one restyled */
59
+ export interface FloorDecorKind {
60
+ /** Name, for the accessible label */
61
+ label?: string
62
+ icon?: string
63
+ width: number
64
+ 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'
67
+ /** Fill: an M3 color role (`surface`, `primary`…) or any CSS color */
68
+ color?: string
69
+ }
70
+ /** What's picked on the plan besides tables: a zone, a wall (and one of its corners) or a decor item */
71
+ export type FloorPick = { kind: 'area' | 'wall' | 'decor'; id: string | number; vertex?: number } | null
56
72
  /** How a status looks: an M3 color role ('primary', 'tertiary', 'error'…) or any CSS color, an icon, a name */
57
73
  export interface FloorStatus {
58
74
  label: string
@@ -68,12 +84,19 @@ export interface FloorStatus {
68
84
  * group. Positions are plan units scaled to the component's width, so the same plan fits a phone and a wall screen.
69
85
  * Not an M3 spec component.
70
86
  *
87
+ * Editing: drag tables (Shift-click picks several), zones (resize by any corner), walls (drag a corner once picked;
88
+ * double-click a wall for a new corner) and decor (resize by its corner); rotate the picked table or decor by the handle
89
+ * above it (15° steps, Shift for free). Arrows nudge, Delete removes what's picked (a wall's picked corner, or the
90
+ * selected tables), Ctrl+D duplicates, Ctrl+Z / Ctrl+Shift+Z undo and redo. `v-model:picked` says which zone, wall or
91
+ * decor is picked, for an inspector of your own.
92
+ *
71
93
  * @slot table The inside of a table: `{ table, status, selected }`
72
94
  * @event table-click A table was clicked or opened with Enter (not after a drag)
73
95
  * @event move Tables moved by a drag or the arrows, with their new positions (`{ id, x, y }[]`), to save them
74
96
  */
75
- import { computed, onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'
97
+ import { computed, onBeforeUnmount, onMounted, provide, ref, shallowRef } from 'vue'
76
98
  import { useLocale } from '../composables/useLocale'
99
+ import { FLOOR_PLAN_KEY, type FloorItemKind, type FloorPlanContext } from '../composables/useFloorPlan'
77
100
  import MIcon from './MIcon.vue'
78
101
 
79
102
  const props = withDefaults(defineProps<{
@@ -90,6 +113,16 @@ const props = withDefaults(defineProps<{
90
113
  showGrid?: boolean
91
114
  /** Draw chairs from `seats` */
92
115
  chairs?: boolean
116
+ /** Decor kinds of yours, or the built-in ones restyled (merged over them by name) */
117
+ decorKinds?: Record<string, FloorDecorKind>
118
+ /** The handle that turns the picked table or decor (off when your app doesn't keep angles) */
119
+ rotatable?: boolean
120
+ /** Dragging (or nudging) a merged table moves its whole merge with it */
121
+ dragMerged?: boolean
122
+ /** Outside editing, what a click on a table selects: nothing, one, or several (toggling; to merge them) */
123
+ selectable?: 'none' | 'single' | 'multiple'
124
+ /** Whether these tables may be merged: `true`, or `false` / a reason to refuse (shown by `merge-refused`) */
125
+ canMerge?: (ids: (string | number)[]) => boolean | string
93
126
  /** Accessible name */
94
127
  label?: string
95
128
  }>(), {
@@ -105,6 +138,9 @@ const props = withDefaults(defineProps<{
105
138
  grid: 10,
106
139
  showGrid: true,
107
140
  chairs: true,
141
+ selectable: 'none',
142
+ dragMerged: false,
143
+ rotatable: true,
108
144
  })
109
145
  const tables = defineModel<FloorTable[]>('tables', { default: () => [] })
110
146
  const merges = defineModel<FloorMerge[]>('merges', { default: () => [] })
@@ -114,10 +150,52 @@ const walls = defineModel<FloorWall[]>('walls', { default: () => [] })
114
150
  const decor = defineModel<FloorDecor[]>('decor', { default: () => [] })
115
151
  /** While editing: `select` moves things, `wall` draws a wall (click each corner, double-click or Enter to end), `area` drags out a zone */
116
152
  const tool = defineModel<'select' | 'wall' | 'area'>('tool', { default: 'select' })
117
- const emit = defineEmits<{ 'table-click': [table: FloorTable, event: MouseEvent | KeyboardEvent]; move: [moved: { id: string | number; x: number; y: number }[]] }>()
153
+ /** While editing: the zone, wall (and corner) or decor item picked, for an inspector of your own */
154
+ const picked = defineModel<FloorPick>('picked', { default: null })
155
+ // ── History: every edit the plan makes is a step Ctrl+Z takes back ──
156
+ type Snap = { tables: FloorTable[]; areas: FloorArea[]; walls: FloorWall[]; decor: FloorDecor[]; merges: FloorMerge[] }
157
+ const past = shallowRef<Snap[]>([])
158
+ const future = shallowRef<Snap[]>([])
159
+ const snap0 = (): Snap => ({ tables: tables.value, areas: areas.value, walls: walls.value, decor: decor.value, merges: merges.value })
160
+ /** Called before an edit: what it changes can be undone */
161
+ function record() {
162
+ past.value = [...past.value, snap0()].slice(-100)
163
+ future.value = []
164
+ }
165
+ function restore(sn: Snap) {
166
+ const now = snap0()
167
+ if (sn.tables !== now.tables) tables.value = sn.tables
168
+ if (sn.areas !== now.areas) areas.value = sn.areas
169
+ if (sn.walls !== now.walls) walls.value = sn.walls
170
+ if (sn.decor !== now.decor) decor.value = sn.decor
171
+ if (sn.merges !== now.merges) merges.value = sn.merges
172
+ }
173
+ function undo() {
174
+ const sn = past.value[past.value.length - 1]
175
+ if (!sn) return
176
+ future.value = [snap0(), ...future.value]
177
+ past.value = past.value.slice(0, -1)
178
+ restore(sn)
179
+ }
180
+ function redo() {
181
+ const sn = future.value[0]
182
+ if (!sn) return
183
+ past.value = [...past.value, snap0()]
184
+ future.value = future.value.slice(1)
185
+ restore(sn)
186
+ }
187
+ const emit = defineEmits<{
188
+ merge: [merge: FloorMerge]
189
+ split: [merge: FloorMerge]
190
+ 'merge-refused': [ids: (string | number)[], reason: string]
191
+ 'table-click': [table: FloorTable, event: MouseEvent | KeyboardEvent]
192
+ move: [moved: { id: string | number; x: number; y: number }[]]
193
+ }>()
118
194
  const locale = useLocale()
119
195
 
120
196
  const root = ref<HTMLElement>()
197
+ /** A finger: bigger handles */
198
+ const coarse = ref(typeof matchMedia !== 'undefined' && matchMedia('(pointer: coarse)').matches)
121
199
  const scale = ref(1)
122
200
  let ro: ResizeObserver | null = null
123
201
  onMounted(() => {
@@ -184,34 +262,75 @@ function look(st?: FloorStatus) {
184
262
  if (ROLES.has(st.color)) return { background: `var(--color-${st.color}-container)`, color: `var(--color-on-${st.color}-container)` }
185
263
  return { background: st.color, color: '#fff' }
186
264
  }
187
- const mergeBoxes = computed(() =>
265
+ /**
266
+ * How a merge is drawn: tables that sit together share one outline (a cluster); clusters apart from each other get
267
+ * an outline each, joined by a dashed line, so a merge across the room doesn't swallow the tables in between
268
+ */
269
+ const mergeShapes = computed(() =>
188
270
  merges.value.map((m) => {
189
271
  const ms = placed.value.filter((p) => m.tables.includes(p.t.id))
190
272
  if (!ms.length) return null
191
273
  const pad = CHAIR + 10
192
- const x1 = Math.min(...ms.map((p) => p.x - p.size.w / 2)) - pad
193
- const y1 = Math.min(...ms.map((p) => p.y - p.size.h / 2)) - pad
194
- const x2 = Math.max(...ms.map((p) => p.x + p.size.w / 2)) + pad
195
- const y2 = Math.max(...ms.map((p) => p.y + p.size.h / 2)) + pad
196
- return { m, x: x1, y: y1, w: x2 - x1, h: y2 - y1 }
274
+ const boxes = ms.map((p) => ({ x1: p.x - p.size.w / 2 - pad, y1: p.y - p.size.h / 2 - pad, x2: p.x + p.size.w / 2 + pad, y2: p.y + p.size.h / 2 + pad }))
275
+ // Union-find over touching boxes
276
+ const parent = boxes.map((_, i) => i)
277
+ const find = (i: number): number => (parent[i] === i ? i : (parent[i] = find(parent[i]!)))
278
+ for (let i = 0; i < boxes.length; i++)
279
+ for (let j = i + 1; j < boxes.length; j++) {
280
+ const a = boxes[i]!
281
+ const b = boxes[j]!
282
+ if (a.x1 <= b.x2 && b.x1 <= a.x2 && a.y1 <= b.y2 && b.y1 <= a.y2) parent[find(i)] = find(j)
283
+ }
284
+ const groups = new Map<number, typeof boxes>()
285
+ boxes.forEach((b, i) => groups.set(find(i), [...(groups.get(find(i)) ?? []), b]))
286
+ const clusters = [...groups.values()].map((bs) => {
287
+ const x1 = Math.min(...bs.map((b) => b.x1))
288
+ const y1 = Math.min(...bs.map((b) => b.y1))
289
+ const x2 = Math.max(...bs.map((b) => b.x2))
290
+ const y2 = Math.max(...bs.map((b) => b.y2))
291
+ return { x: x1, y: y1, w: x2 - x1, h: y2 - y1, cx: (x1 + x2) / 2, cy: (y1 + y2) / 2 }
292
+ })
293
+ // Each cluster linked to the nearest one already linked (a small spanning tree)
294
+ const links: [number, number, number, number][] = []
295
+ for (let i = 1; i < clusters.length; i++) {
296
+ let best = 0
297
+ for (let j = 1; j < i; j++) if (Math.hypot(clusters[j]!.cx - clusters[i]!.cx, clusters[j]!.cy - clusters[i]!.cy) < Math.hypot(clusters[best]!.cx - clusters[i]!.cx, clusters[best]!.cy - clusters[i]!.cy)) best = j
298
+ links.push([clusters[best]!.cx, clusters[best]!.cy, clusters[i]!.cx, clusters[i]!.cy])
299
+ }
300
+ return { m, clusters, links }
197
301
  }).filter((b) => !!b),
198
302
  )
199
303
 
200
304
  // ── Dragging ────────────────────────────────────────────────────────────────────────────────────────────
201
- let drag: { id: number; sx: number; sy: number; start: Map<string | number, { x: number; y: number }>; moved: boolean } | null = null
305
+ let drag: { id: number; sx: number; sy: number; start: Map<string | number, { x: number; y: number }>; moved: boolean; pick?: string | number } | null = null
202
306
  let suppressClick = false
203
307
  const snap = (v: number) => (props.grid ? Math.round(v / props.grid) * props.grid : v)
204
308
  function clamp(t: FloorTable, x: number, y: number) {
205
309
  const s = sizeOf(t)
206
310
  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)) }
207
311
  }
312
+ // A finger has no Shift: holding a table down adds it to the selection (or takes it out)
313
+ const LONG_PRESS = 450
314
+ let longPress = 0
315
+ let longPressed = false
208
316
  function onDown(e: PointerEvent, t: FloorTable) {
209
317
  if (!props.editable || e.button !== 0 || tool.value !== 'select') return
210
318
  e.stopPropagation()
211
319
  picked.value = null
212
- if (!selection.value.includes(t.id)) selection.value = e.shiftKey || e.ctrlKey || e.metaKey ? [...selection.value, t.id] : [t.id]
213
- const ids = selection.value.includes(t.id) ? selection.value : [t.id]
214
- 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 }
320
+ const touch = e.pointerType === 'touch'
321
+ longPressed = false
322
+ clearTimeout(longPress)
323
+ if (touch) {
324
+ longPress = window.setTimeout(() => {
325
+ if (!drag || drag.moved) return
326
+ longPressed = true
327
+ selection.value = selection.value.includes(t.id) ? selection.value.filter((x) => x !== t.id) : [...selection.value, t.id]
328
+ navigator.vibrate?.(10)
329
+ }, LONG_PRESS)
330
+ } else if (!selection.value.includes(t.id)) selection.value = e.shiftKey || e.ctrlKey || e.metaKey ? [...selection.value, t.id] : [t.id]
331
+ // A touch picks the table once it moves (or on release), so a long press can add to what's picked
332
+ const ids = withMerged(selection.value.includes(t.id) ? selection.value : [t.id])
333
+ 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 && !selection.value.includes(t.id) ? t.id : undefined }
215
334
  window.addEventListener('pointermove', onMove)
216
335
  window.addEventListener('pointerup', onUp)
217
336
  window.addEventListener('pointercancel', onUp)
@@ -220,7 +339,11 @@ function onMove(e: PointerEvent) {
220
339
  if (!drag || e.pointerId !== drag.id) return
221
340
  const dx = (e.clientX - drag.sx) / scale.value
222
341
  const dy = (e.clientY - drag.sy) / scale.value
223
- if (!drag.moved && Math.hypot(e.clientX - drag.sx, e.clientY - drag.sy) < 4) return
342
+ if (!drag.moved && Math.hypot(e.clientX - drag.sx, e.clientY - drag.sy) < (e.pointerType === 'touch' ? 8 : 4)) return
343
+ if (!drag.moved) {
344
+ clearTimeout(longPress)
345
+ if (drag.pick !== undefined) selection.value = [drag.pick]
346
+ }
224
347
  drag.moved = true
225
348
  const next = new Map<string | number, { x: number; y: number }>()
226
349
  for (const [id, p] of drag.start) next.set(id, clamp(tables.value.find((x) => x.id === id)!, p.x + dx, p.y + dy))
@@ -228,6 +351,11 @@ function onMove(e: PointerEvent) {
228
351
  }
229
352
  function onUp(e: PointerEvent) {
230
353
  if (!drag || e.pointerId !== drag.id) return
354
+ clearTimeout(longPress)
355
+ if (longPressed) {
356
+ suppressClick = true
357
+ setTimeout(() => (suppressClick = false))
358
+ }
231
359
  window.removeEventListener('pointermove', onMove)
232
360
  window.removeEventListener('pointerup', onUp)
233
361
  window.removeEventListener('pointercancel', onUp)
@@ -241,14 +369,25 @@ function onUp(e: PointerEvent) {
241
369
  commitMoves(new Map([...d!].map(([id, p]) => [id, clamp(tables.value.find((x) => x.id === id)!, snap(p.x), snap(p.y))])))
242
370
  }
243
371
  function commitMoves(next: Map<string | number, { x: number; y: number }>) {
372
+ record()
244
373
  tables.value = tables.value.map((t) => (next.has(t.id) ? { ...t, ...next.get(t.id)! } : t))
245
374
  emit('move', [...next].map(([id, p]) => ({ id, ...p })))
246
375
  }
247
376
  function onClick(e: MouseEvent, t: FloorTable) {
248
377
  if (suppressClick) return
249
378
  if (props.editable && !(e.shiftKey || e.ctrlKey || e.metaKey)) selection.value = [t.id]
379
+ else if (!props.editable && props.selectable === 'single') selection.value = selection.value.length === 1 && selection.value[0] === t.id ? [] : [t.id]
380
+ else if (!props.editable && props.selectable === 'multiple')
381
+ selection.value = selection.value.includes(t.id) ? selection.value.filter((x) => x !== t.id) : [...selection.value, t.id]
250
382
  emit('table-click', t, e)
251
383
  }
384
+ /** With `dragMerged`, the tables merged with these come along */
385
+ function withMerged(ids: (string | number)[]) {
386
+ if (!props.dragMerged) return ids
387
+ const all = new Set(ids)
388
+ for (const id of ids) for (const m of merges.value) if (m.tables.includes(id)) m.tables.forEach((x) => all.add(x))
389
+ return [...all]
390
+ }
252
391
  function onKey(e: KeyboardEvent, t: FloorTable) {
253
392
  if (e.key === 'Enter' || e.key === ' ') {
254
393
  e.preventDefault()
@@ -259,7 +398,7 @@ function onKey(e: KeyboardEvent, t: FloorTable) {
259
398
  if (!dir || !props.editable) return
260
399
  e.preventDefault()
261
400
  const step = (props.grid || 1) * (e.shiftKey ? 5 : 1)
262
- const ids = selection.value.includes(t.id) ? selection.value : [t.id]
401
+ const ids = withMerged(selection.value.includes(t.id) ? selection.value : [t.id])
263
402
  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)])))
264
403
  }
265
404
  onBeforeUnmount(() => {
@@ -268,24 +407,38 @@ onBeforeUnmount(() => {
268
407
  window.removeEventListener('pointercancel', onUp)
269
408
  })
270
409
  // ── Zones, walls and decor ───────────────────────────────────────────────────────────────────────────────
271
- const DECOR: Record<FloorDecor['kind'], { icon?: string; w: number; h: number }> = {
272
- door: { icon: 'door_front', w: 60, h: 14 },
273
- window: { icon: 'window', w: 80, h: 10 },
274
- plant: { icon: 'potted_plant', w: 40, h: 40 },
275
- column: { w: 30, h: 30 },
276
- restroom: { icon: 'wc', w: 48, h: 48 },
277
- kitchen: { icon: 'skillet', w: 48, h: 48 },
278
- register: { icon: 'point_of_sale', w: 48, h: 48 },
279
- stairs: { icon: 'stairs', w: 60, h: 60 },
280
- label: { w: 120, h: 30 },
281
- }
282
- const decorSize = (d: FloorDecor) => ({ w: d.width ?? DECOR[d.kind].w, h: d.height ?? DECOR[d.kind].h })
410
+ const BUILTIN_DECOR: Record<FloorDecorBuiltin, FloorDecorKind> = {
411
+ door: { label: 'Door', icon: 'door_front', width: 60, height: 14, shape: 'bar' },
412
+ window: { label: 'Window', icon: 'window', width: 80, height: 10, shape: 'bar' },
413
+ plant: { label: 'Plant', icon: 'potted_plant', width: 40, height: 40 },
414
+ column: { label: 'Column', width: 30, height: 30, shape: 'round', color: 'var(--color-outline)' },
415
+ restroom: { label: 'Restroom', icon: 'wc', width: 48, height: 48 },
416
+ kitchen: { label: 'Kitchen', icon: 'skillet', width: 48, height: 48 },
417
+ register: { label: 'Register', icon: 'point_of_sale', width: 48, height: 48 },
418
+ stairs: { label: 'Stairs', icon: 'stairs', width: 60, height: 60 },
419
+ label: { label: 'Label', width: 120, height: 30, shape: 'text' },
420
+ }
421
+ const kinds = computed<Record<string, FloorDecorKind>>(() => {
422
+ const out: Record<string, FloorDecorKind> = { ...BUILTIN_DECOR }
423
+ for (const [k, v] of Object.entries(props.decorKinds ?? {})) out[k] = { ...out[k], ...v }
424
+ return out
425
+ })
426
+ const kindOf = (d: FloorDecor): FloorDecorKind => kinds.value[d.kind] ?? { width: 40, height: 40 }
427
+ const decorSize = (d: FloorDecor) => ({ w: d.width ?? kindOf(d).width, h: d.height ?? kindOf(d).height })
428
+ function decorLook(k: FloorDecorKind) {
429
+ const shape = k.shape ?? 'box'
430
+ if (shape === 'text') return {}
431
+ const c = k.color ?? (shape === 'bar' ? 'surface-container-highest' : 'surface-container-high')
432
+ const bg = c.startsWith('surface') || c.startsWith('var(') || c.startsWith('#') || c.startsWith('rgb') || c.startsWith('hsl')
433
+ ? (c.startsWith('surface') ? `var(--color-${c})` : c)
434
+ : `var(--color-${c}-container)`
435
+ return { background: bg, borderRadius: shape === 'round' ? '9999px' : shape === 'bar' ? '2px' : '8px' }
436
+ }
283
437
  function areaLook(color?: string) {
284
438
  const c = color ?? 'secondary'
285
439
  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 }
286
440
  }
287
- /** What's picked while editing, besides tables: an area, a wall or a decor item */
288
- const picked = ref<{ kind: 'area' | 'wall' | 'decor'; id: string | number } | null>(null)
441
+ // `picked` (a v-model) is declared with the other models
289
442
  const isPicked = (kind: 'area' | 'wall' | 'decor', id: string | number) => picked.value?.kind === kind && picked.value.id === id
290
443
  const toPlan = (e: { clientX: number; clientY: number }) => {
291
444
  const r = root.value!.getBoundingClientRect()
@@ -317,32 +470,45 @@ function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: ()
317
470
  }
318
471
  const areaDraft = shallowRef<FloorArea | null>(null)
319
472
  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] : []))
320
- function onAreaDown(e: PointerEvent, a: FloorArea, resize: boolean) {
473
+ type Corner = 'nw' | 'ne' | 'sw' | 'se'
474
+ function onAreaDown(e: PointerEvent, a: FloorArea, corner: Corner | null) {
321
475
  if (!props.editable || tool.value !== 'select' || e.button !== 0) return
322
476
  e.stopPropagation()
323
477
  picked.value = { kind: 'area', id: a.id }
324
478
  selection.value = []
325
479
  follow(e, (dx, dy) => {
326
- areaDraft.value = resize
327
- ? { ...a, width: Math.max(props.grid || 20, a.width + dx), height: Math.max(props.grid || 20, a.height + dy) }
328
- : { ...a, x: a.x + dx, y: a.y + dy }
480
+ if (!corner) {
481
+ areaDraft.value = { ...a, x: a.x + dx, y: a.y + dy }
482
+ return
483
+ }
484
+ // The opposite corner stays put
485
+ const min = props.grid || 20
486
+ const left = corner.includes('w')
487
+ const top = corner[0] === 'n'
488
+ const w = Math.max(min, a.width + (left ? -dx : dx))
489
+ const h = Math.max(min, a.height + (top ? -dy : dy))
490
+ areaDraft.value = { ...a, x: left ? a.x + a.width - w : a.x, y: top ? a.y + a.height - h : a.y, width: w, height: h }
329
491
  }, () => {
330
492
  const d = areaDraft.value!
331
493
  areaDraft.value = null
494
+ record()
332
495
  areas.value = areas.value.map((x) => (x.id === a.id ? { ...d, x: snap(d.x), y: snap(d.y), width: snap(d.width) || d.width, height: snap(d.height) || d.height } : x))
333
496
  })
334
497
  }
335
498
  const decorDraft = shallowRef<FloorDecor | null>(null)
336
499
  const shownDecor = computed(() => decor.value.map((d) => (decorDraft.value?.id === d.id ? decorDraft.value : d)))
337
- function onDecorDown(e: PointerEvent, d: FloorDecor) {
500
+ function onDecorDown(e: PointerEvent, d: FloorDecor, resize = false) {
338
501
  if (!props.editable || tool.value !== 'select' || e.button !== 0) return
339
502
  e.stopPropagation()
340
503
  picked.value = { kind: 'decor', id: d.id }
341
504
  selection.value = []
342
- follow(e, (dx, dy) => (decorDraft.value = { ...d, x: d.x + dx, y: d.y + dy }), () => {
505
+ const s0 = decorSize(d)
506
+ // Resizing from the bottom-right corner keeps it centered where it is, growing both ways
507
+ 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 }), () => {
343
508
  const n = decorDraft.value!
344
509
  decorDraft.value = null
345
- decor.value = decor.value.map((x) => (x.id === d.id ? { ...n, x: snap(n.x), y: snap(n.y) } : x))
510
+ record()
511
+ 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))
346
512
  })
347
513
  }
348
514
  const wallDraft = shallowRef<FloorWall | null>(null)
@@ -351,13 +517,14 @@ const wallPath = (w: FloorWall) => w.points.map(([x, y], i) => `${i ? 'L' : 'M'}
351
517
  function onWallDown(e: PointerEvent, w: FloorWall, vertex = -1) {
352
518
  if (!props.editable || tool.value !== 'select' || e.button !== 0) return
353
519
  e.stopPropagation()
354
- picked.value = { kind: 'wall', id: w.id }
520
+ picked.value = { kind: 'wall', id: w.id, ...(vertex >= 0 && { vertex }) }
355
521
  selection.value = []
356
522
  follow(e, (dx, dy) => {
357
523
  wallDraft.value = { ...w, points: w.points.map(([x, y], i) => (vertex < 0 || i === vertex ? [x + dx, y + dy] : [x, y])) }
358
524
  }, () => {
359
525
  const n = wallDraft.value!
360
526
  wallDraft.value = null
527
+ record()
361
528
  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))
362
529
  })
363
530
  }
@@ -387,6 +554,7 @@ function onPlanPointer(e: PointerEvent) {
387
554
  const d = areaDraft.value!
388
555
  areaDraft.value = null
389
556
  if (d.width > 10 && d.height > 10) {
557
+ record()
390
558
  areas.value = [...areas.value, { ...d, x: snap(d.x), y: snap(d.y), width: snap(d.width) || d.width, height: snap(d.height) || d.height }]
391
559
  picked.value = { kind: 'area', id }
392
560
  }
@@ -402,6 +570,7 @@ function finishWall() {
402
570
  const pts = drawing.value?.filter((p, i, a) => !i || p[0] !== a[i - 1]![0] || p[1] !== a[i - 1]![1])
403
571
  drawing.value = null
404
572
  hover.value = null
573
+ if (pts && pts.length > 1) record()
405
574
  if (pts && pts.length > 1) walls.value = [...walls.value, { id: newId('wall'), points: pts }]
406
575
  }
407
576
  function onPlanKey(e: KeyboardEvent) {
@@ -411,15 +580,254 @@ function onPlanKey(e: KeyboardEvent) {
411
580
  else drawing.value = null
412
581
  return
413
582
  }
414
- if (!props.editable || (e.key !== 'Delete' && e.key !== 'Backspace') || !picked.value) return
415
- const { kind, id } = picked.value
583
+ if (!props.editable) return
584
+ const mod = e.ctrlKey || e.metaKey
585
+ const key = e.key.toLowerCase()
586
+ if (mod && key === 'z') {
587
+ e.preventDefault()
588
+ if (e.shiftKey) redo()
589
+ else undo()
590
+ return
591
+ }
592
+ if (mod && key === 'y') {
593
+ e.preventDefault()
594
+ redo()
595
+ return
596
+ }
597
+ if (mod && key === 'd') {
598
+ e.preventDefault()
599
+ duplicate()
600
+ return
601
+ }
602
+ if (e.key !== 'Delete' && e.key !== 'Backspace') return
603
+ if (!picked.value && !selection.value.length) return
416
604
  e.preventDefault()
605
+ removeSelected()
606
+ }
607
+ function removeSelected() {
608
+ if (!picked.value) {
609
+ if (selection.value.length) removeTables(selection.value)
610
+ return
611
+ }
612
+ const { kind, id, vertex } = picked.value
613
+ record()
417
614
  if (kind === 'area') areas.value = areas.value.filter((a) => a.id !== id)
418
- if (kind === 'wall') walls.value = walls.value.filter((w) => w.id !== id)
615
+ if (kind === 'wall') {
616
+ const w = walls.value.find((x) => x.id === id)
617
+ // A picked corner goes (a wall keeps at least two); otherwise the whole wall
618
+ if (w && vertex !== undefined && w.points.length > 2) {
619
+ walls.value = walls.value.map((x) => (x.id === id ? { ...x, points: x.points.filter((_, i) => i !== vertex) } : x))
620
+ picked.value = { kind: 'wall', id }
621
+ return
622
+ }
623
+ walls.value = walls.value.filter((x) => x.id !== id)
624
+ }
419
625
  if (kind === 'decor') decor.value = decor.value.filter((d) => d.id !== id)
420
626
  picked.value = null
421
627
  }
422
628
  const svgEl = ref<SVGSVGElement>()
629
+ /** Removes tables (and takes them out of their merges; a merge left with one table goes) */
630
+ function removeTables(ids: (string | number)[]) {
631
+ record()
632
+ tables.value = tables.value.filter((t) => !ids.includes(t.id))
633
+ merges.value = merges.value.map((m) => ({ ...m, tables: m.tables.filter((x) => !ids.includes(x)) })).filter((m) => m.tables.length > 1)
634
+ selection.value = []
635
+ }
636
+ /** A copy of the selected tables, or of the picked zone or decor, a grid step or two away */
637
+ function duplicate() {
638
+ const off = Math.max(20, (props.grid || 10) * 2)
639
+ if (selection.value.length) {
640
+ 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 }))
641
+ record()
642
+ tables.value = [...tables.value, ...copies]
643
+ selection.value = copies.map((t) => t.id)
644
+ return
645
+ }
646
+ const pk = picked.value
647
+ if (pk?.kind === 'area') {
648
+ const a = areas.value.find((x) => x.id === pk.id)
649
+ if (!a) return
650
+ const c = { ...a, id: newId('area'), x: a.x + off, y: a.y + off }
651
+ record()
652
+ areas.value = [...areas.value, c]
653
+ picked.value = { kind: 'area', id: c.id }
654
+ } else if (pk?.kind === 'decor') {
655
+ const d = decor.value.find((x) => x.id === pk.id)
656
+ if (!d) return
657
+ const c = { ...d, id: newId('decor'), x: d.x + off, y: d.y + off }
658
+ record()
659
+ decor.value = [...decor.value, c]
660
+ picked.value = { kind: 'decor', id: c.id }
661
+ }
662
+ }
663
+ // ── Rotating a table or a decor item by its handle (15° steps; Shift: free) ──
664
+ const rotateDraft = shallowRef<{ id: string | number; kind: 'table' | 'decor'; deg: number } | null>(null)
665
+ function onRotateDown(e: PointerEvent, kind: 'table' | 'decor', id: string | number, cx: number, cy: number) {
666
+ if (!props.editable || e.button !== 0) return
667
+ e.stopPropagation()
668
+ e.preventDefault()
669
+ const r = root.value!.getBoundingClientRect()
670
+ const angle = (ev: PointerEvent) => (Math.atan2(ev.clientY - (r.top + cy * scale.value), ev.clientX - (r.left + cx * scale.value)) * 180) / Math.PI + 90
671
+ const mv = (ev: PointerEvent) => {
672
+ if (ev.pointerId !== e.pointerId) return
673
+ let deg = ((angle(ev) % 360) + 360) % 360
674
+ if (!ev.shiftKey) deg = Math.round(deg / 15) * 15 % 360
675
+ rotateDraft.value = { id, kind, deg }
676
+ }
677
+ const up = (ev: PointerEvent) => {
678
+ if (ev.pointerId !== e.pointerId) return
679
+ window.removeEventListener('pointermove', mv)
680
+ window.removeEventListener('pointerup', up)
681
+ window.removeEventListener('pointercancel', up)
682
+ const d = rotateDraft.value
683
+ rotateDraft.value = null
684
+ if (!d) return
685
+ record()
686
+ if (kind === 'table') tables.value = tables.value.map((t) => (t.id === id ? { ...t, rotation: d.deg } : t))
687
+ else decor.value = decor.value.map((x) => (x.id === id ? { ...x, rotation: d.deg } : x))
688
+ }
689
+ window.addEventListener('pointermove', mv)
690
+ window.addEventListener('pointerup', up)
691
+ window.addEventListener('pointercancel', up)
692
+ }
693
+ const rotationOf = (kind: 'table' | 'decor', id: string | number, base?: number) => (rotateDraft.value?.kind === kind && rotateDraft.value.id === id ? rotateDraft.value.deg : base ?? 0)
694
+
695
+ /**
696
+ * Merges tables (the selection by default, with what they're already merged with) into one group. `canMerge` can
697
+ * refuse (the `merge-refused` event says why). Returns the merge, or null.
698
+ */
699
+ function merge(ids: (string | number)[] = selection.value, label?: string): FloorMerge | null {
700
+ const all = [...new Set(ids.flatMap((id) => merges.value.find((m) => m.tables.includes(id))?.tables ?? [id]))]
701
+ if (all.length < 2) return null
702
+ const ok = props.canMerge?.(all) ?? true
703
+ if (ok !== true) {
704
+ emit('merge-refused', all, typeof ok === 'string' ? ok : '')
705
+ return null
706
+ }
707
+ const name = label ?? all.map((id) => tables.value.find((t) => t.id === id)?.label ?? id).join(' + ')
708
+ const m: FloorMerge = { id: newId('merge'), tables: all, label: name }
709
+ record()
710
+ merges.value = [...merges.value.filter((x) => !x.tables.some((id) => all.includes(id))), m]
711
+ selection.value = []
712
+ emit('merge', m)
713
+ return m
714
+ }
715
+ /** Splits a merge (by its id, or the one a table is in) back into its tables */
716
+ function split(idOrTable: string | number) {
717
+ const m = merges.value.find((x) => x.id === idOrTable) ?? merges.value.find((x) => x.tables.includes(idOrTable))
718
+ if (!m) return
719
+ record()
720
+ merges.value = merges.value.filter((x) => x !== m)
721
+ emit('split', m)
722
+ }
723
+ // ── The context the toolbar, the inspector and your own controls work through ──
724
+ let lastEdit = { key: '', at: 0 }
725
+ function update(kind: FloorItemKind, id: string | number, patch: Record<string, unknown>) {
726
+ // Typing a label or dragging a slider is one undo step, not one per keystroke
727
+ const key = `${kind}:${id}:${Object.keys(patch).sort().join()}`
728
+ const now = performance.now()
729
+ if (key !== lastEdit.key || now - lastEdit.at > 1000) record()
730
+ lastEdit = { key, at: now }
731
+ const apply = <T extends { id: string | number }>(list: T[]) => list.map((x) => (x.id === id ? { ...x, ...patch } : x))
732
+ if (kind === 'table') tables.value = apply(tables.value)
733
+ else if (kind === 'area') areas.value = apply(areas.value)
734
+ else if (kind === 'wall') walls.value = apply(walls.value)
735
+ else decor.value = apply(decor.value)
736
+ }
737
+ function addTable(t: Partial<FloorTable> = {}): FloorTable {
738
+ const n = Math.max(0, ...tables.value.map((x) => Number(x.label)).filter((x) => Number.isFinite(x))) + 1
739
+ const table: FloorTable = { id: newId('table'), label: String(n), x: snap(props.width / 2), y: snap(props.height / 2), shape: 'square', seats: 4, ...t }
740
+ record()
741
+ tables.value = [...tables.value, table]
742
+ selection.value = [table.id]
743
+ picked.value = null
744
+ return table
745
+ }
746
+ function addDecor(kind: string, d: Partial<FloorDecor> = {}): FloorDecor {
747
+ 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 }
748
+ record()
749
+ decor.value = [...decor.value, item]
750
+ picked.value = { kind: 'decor', id: item.id }
751
+ selection.value = []
752
+ return item
753
+ }
754
+ const context: FloorPlanContext = {
755
+ tables,
756
+ areas,
757
+ walls,
758
+ decor,
759
+ merges,
760
+ selection,
761
+ picked,
762
+ tool,
763
+ editable: computed(() => props.editable),
764
+ drawingWall: computed(() => !!drawing.value),
765
+ finishWall,
766
+ cancelWall: () => {
767
+ drawing.value = null
768
+ hover.value = null
769
+ },
770
+ kinds,
771
+ statuses: computed(() => props.statuses),
772
+ size: computed(() => ({ width: props.width, height: props.height })),
773
+ canUndo: computed(() => past.value.length > 0),
774
+ canRedo: computed(() => future.value.length > 0),
775
+ undo,
776
+ redo,
777
+ addTable,
778
+ addDecor,
779
+ update: update as FloorPlanContext['update'],
780
+ removeSelected,
781
+ removeTables,
782
+ duplicate,
783
+ merge,
784
+ split,
785
+ }
786
+ provide(FLOOR_PLAN_KEY, context)
787
+
788
+ defineExpose({
789
+ /** Everything above and more, for MFloorPlanToolbar / MFloorPlanInspector outside the plan (`:plan="plan"`) */
790
+ context,
791
+ addTable,
792
+ addDecor,
793
+ update,
794
+ removeSelected,
795
+ /** Merge tables (default: the selection) / split a merge (by its id or a table's) */
796
+ merge,
797
+ split,
798
+ /** Undo / redo the plan's own edits (also Ctrl+Z, Ctrl+Shift+Z or Ctrl+Y) */
799
+ undo,
800
+ redo,
801
+ canUndo: computed(() => past.value.length > 0),
802
+ canRedo: computed(() => future.value.length > 0),
803
+ /** Copy the selected tables, or the picked zone or decor (also Ctrl+D) */
804
+ duplicate,
805
+ /** Remove tables, taking them out of their merges (Delete does it for the selection) */
806
+ removeTables,
807
+ })
808
+ /** Double-click on a wall: a new corner there, on the nearest segment */
809
+ function onWallDblclick(e: MouseEvent, w: FloorWall) {
810
+ if (!props.editable || tool.value !== 'select') return
811
+ e.stopPropagation()
812
+ const p = toPlan(e)
813
+ let best = 0
814
+ let bestD = Infinity
815
+ for (let i = 1; i < w.points.length; i++) {
816
+ const [ax, ay] = w.points[i - 1]!
817
+ const [bx, by] = w.points[i]!
818
+ const len = (bx - ax) ** 2 + (by - ay) ** 2
819
+ const t = len ? Math.max(0, Math.min(1, ((p.x - ax) * (bx - ax) + (p.y - ay) * (by - ay)) / len)) : 0
820
+ const d = Math.hypot(ax + t * (bx - ax) - p.x, ay + t * (by - ay) - p.y)
821
+ if (d < bestD) {
822
+ bestD = d
823
+ best = i
824
+ }
825
+ }
826
+ const pt: [number, number] = [snap(p.x), snap(p.y)]
827
+ record()
828
+ walls.value = walls.value.map((x) => (x.id === w.id ? { ...x, points: [...x.points.slice(0, best), pt, ...x.points.slice(best)] } : x))
829
+ picked.value = { kind: 'wall', id: w.id, vertex: best }
830
+ }
423
831
 
424
832
  const ariaOf = (p: (typeof placed.value)[number]) =>
425
833
  [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(', ')
@@ -434,7 +842,7 @@ const gridStyle = computed(() => {
434
842
  <template>
435
843
  <div
436
844
  ref="root"
437
- class="m3-floor-plan relative overflow-hidden rounded-xl bg-surface-container-low select-none"
845
+ class="m3-floor-plan select-none"
438
846
  :style="{ aspectRatio: `${width} / ${height}`, ...gridStyle }"
439
847
  role="group"
440
848
  tabindex="-1"
@@ -450,16 +858,23 @@ const gridStyle = computed(() => {
450
858
  v-for="a in shownAreas"
451
859
  :key="`a${a.id}`"
452
860
  class="absolute rounded-lg border"
453
- :class="[editable && tool === 'select' ? 'cursor-move' : 'pointer-events-none', isPicked('area', a.id) && 'ring-2 ring-primary']"
861
+ :class="[editable && tool === 'select' ? 'cursor-move touch-none' : 'pointer-events-none', isPicked('area', a.id) && 'ring-2 ring-primary']"
454
862
  :style="{ left: `${a.x * scale}px`, top: `${a.y * scale}px`, width: `${a.width * scale}px`, height: `${a.height * scale}px`, ...areaLook(a.color) }"
455
- @pointerdown="onAreaDown($event, a, false)"
863
+ @pointerdown="onAreaDown($event, a, null)"
456
864
  >
457
- <span v-if="a.label" class="absolute top-1 left-2 text-label-medium text-on-surface-variant">{{ a.label }}</span>
458
- <span
459
- v-if="editable && isPicked('area', a.id)"
460
- class="absolute -right-1.5 -bottom-1.5 size-3 cursor-nwse-resize rounded-xs border-2 border-primary bg-surface"
461
- @pointerdown="onAreaDown($event, a, true)"
462
- />
865
+ <slot name="area" :area="a" :picked="isPicked('area', a.id)" :scale="scale">
866
+ <span v-if="a.label" class="absolute top-1 left-2 text-label-medium text-on-surface-variant">{{ a.label }}</span>
867
+ </slot>
868
+ <template v-if="editable && isPicked('area', a.id)">
869
+ <span
870
+ v-for="c in (['nw', 'ne', 'sw', 'se'] as const)"
871
+ :key="c"
872
+ class="m3-floor-handle absolute size-3 rounded-xs border-2 border-primary bg-surface"
873
+ :class="[c[0] === 'n' ? '-top-1.5' : '-bottom-1.5', c[1] === 'w' ? '-left-1.5' : '-right-1.5', c === 'nw' || c === 'se' ? 'cursor-nwse-resize' : 'cursor-nesw-resize']"
874
+ :data-corner="c"
875
+ @pointerdown="onAreaDown($event, a, c)"
876
+ />
877
+ </template>
463
878
  </div>
464
879
 
465
880
  <!-- Walls -->
@@ -470,10 +885,11 @@ const gridStyle = computed(() => {
470
885
  fill="none"
471
886
  stroke-linecap="round"
472
887
  stroke-linejoin="round"
473
- class="stroke-on-surface-variant"
474
- :class="[editable && tool === 'select' && 'pointer-events-auto cursor-move', isPicked('wall', w.id) && 'stroke-primary']"
888
+ class="m3-floor-wall"
889
+ :class="[editable && tool === 'select' && 'pointer-events-auto cursor-move touch-none', isPicked('wall', w.id) && 'm3-floor-wall-picked']"
475
890
  :stroke-width="(w.thickness ?? 8) * scale"
476
891
  @pointerdown="onWallDown($event, w)"
892
+ @dblclick="onWallDblclick($event, w)"
477
893
  />
478
894
  <template v-if="editable && isPicked('wall', w.id)">
479
895
  <circle
@@ -481,8 +897,9 @@ const gridStyle = computed(() => {
481
897
  :key="i"
482
898
  :cx="pt[0] * scale"
483
899
  :cy="pt[1] * scale"
484
- r="6"
485
- class="pointer-events-auto cursor-move fill-surface stroke-primary"
900
+ :r="(picked?.vertex === i ? 8 : 6) * (coarse ? 1.6 : 1)"
901
+ class="pointer-events-auto cursor-move touch-none stroke-primary"
902
+ :class="picked?.vertex === i ? 'fill-primary' : 'fill-surface'"
486
903
  stroke-width="2"
487
904
  @pointerdown="onWallDown($event, w, i)"
488
905
  />
@@ -505,40 +922,83 @@ const gridStyle = computed(() => {
505
922
  :key="`d${d.id}`"
506
923
  class="absolute flex -translate-x-1/2 -translate-y-1/2 items-center justify-center text-on-surface-variant"
507
924
  :class="[
508
- d.kind === 'column' ? 'rounded-full bg-outline' : d.kind === 'door' || d.kind === 'window' ? 'rounded-xs bg-surface-container-highest' : d.kind === 'label' ? '' : 'rounded-lg bg-surface-container-high',
509
- editable && tool === 'select' ? 'cursor-move' : 'pointer-events-none',
925
+ editable && tool === 'select' ? 'cursor-move touch-none' : 'pointer-events-none',
510
926
  isPicked('decor', d.id) && 'ring-2 ring-primary',
511
927
  ]"
512
- :style="{ left: `${d.x * scale}px`, top: `${d.y * scale}px`, width: `${decorSize(d).w * scale}px`, height: `${decorSize(d).h * scale}px`, rotate: `${d.rotation ?? 0}deg` }"
513
- :aria-label="d.label ?? d.kind"
928
+ :style="{ left: `${d.x * scale}px`, top: `${d.y * scale}px`, width: `${decorSize(d).w * scale}px`, height: `${decorSize(d).h * scale}px`, rotate: `${rotationOf('decor', d.id, d.rotation)}deg`, ...decorLook(kindOf(d)) }"
929
+ :aria-label="d.label ?? kindOf(d).label ?? d.kind"
514
930
  role="img"
515
931
  @pointerdown="onDecorDown($event, d)"
516
932
  >
517
- <MIcon v-if="DECOR[d.kind].icon && d.kind !== 'door' && d.kind !== 'window'" :name="DECOR[d.kind].icon!" :size="Math.max(12, Math.min(decorSize(d).w, decorSize(d).h) * 0.6 * scale)" />
518
- <span v-if="d.kind === 'label'" class="truncate text-title-small text-on-surface-variant" :style="{ fontSize: `${Math.max(10, 16 * scale)}px` }">{{ d.label }}</span>
933
+ <slot name="decor" :item="d" :kind="kindOf(d)" :picked="isPicked('decor', d.id)" :scale="scale">
934
+ <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)" />
935
+ <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>
936
+ </slot>
937
+ <span
938
+ v-if="editable && isPicked('decor', d.id)"
939
+ class="m3-floor-handle absolute -right-1.5 -bottom-1.5 size-3 cursor-nwse-resize rounded-xs border-2 border-primary bg-surface"
940
+ data-resize
941
+ @pointerdown="onDecorDown($event, d, true)"
942
+ />
943
+ <span
944
+ v-if="editable && rotatable && isPicked('decor', d.id)"
945
+ 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"
946
+ :aria-label="locale.floorRotate"
947
+ data-rotate
948
+ @pointerdown="onRotateDown($event, 'decor', d.id, d.x, d.y)"
949
+ />
519
950
  </div>
520
951
 
521
952
  <!-- Merged tables: one outline around the group -->
522
- <div
523
- v-for="b in mergeBoxes"
524
- :key="`m${b!.m.id}`"
525
- class="pointer-events-none absolute rounded-2xl border-2 border-dashed border-primary/60 bg-primary/5"
526
- :style="{ left: `${b!.x * scale}px`, top: `${b!.y * scale}px`, width: `${b!.w * scale}px`, height: `${b!.h * scale}px` }"
527
- >
528
- <span v-if="b!.m.label" class="absolute -top-2.5 left-3 rounded-full bg-primary px-2 text-label-small text-on-primary">{{ b!.m.label }}</span>
529
- </div>
953
+ <svg v-if="mergeShapes.some((ms) => ms!.links.length)" class="pointer-events-none absolute inset-0 size-full overflow-visible">
954
+ <template v-for="ms in mergeShapes" :key="`ml${ms!.m.id}`">
955
+ <line
956
+ v-for="(l, i) in ms!.links"
957
+ :key="i"
958
+ class="m3-floor-merge-link"
959
+ :x1="l[0] * scale"
960
+ :y1="l[1] * scale"
961
+ :x2="l[2] * scale"
962
+ :y2="l[3] * scale"
963
+ stroke-width="2"
964
+ stroke-dasharray="6 5"
965
+ stroke-linecap="round"
966
+ />
967
+ </template>
968
+ </svg>
969
+ <template v-for="ms in mergeShapes" :key="`m${ms!.m.id}`">
970
+ <div
971
+ v-for="(b, i) in ms!.clusters"
972
+ :key="i"
973
+ class="m3-floor-merge pointer-events-none absolute rounded-2xl border-2 border-dashed"
974
+ :style="{ left: `${b.x * scale}px`, top: `${b.y * scale}px`, width: `${b.w * scale}px`, height: `${b.h * scale}px` }"
975
+ >
976
+ <slot v-if="i === 0" name="merge" :merge="ms!.m" :tables="ms!.m.tables">
977
+ <span v-if="ms!.m.label" class="m3-floor-merge-label absolute -top-2.5 left-3 rounded-full px-2 text-label-small whitespace-nowrap">{{ ms!.m.label }}</span>
978
+ </slot>
979
+ </div>
980
+ </template>
530
981
 
531
982
  <div
532
983
  v-for="p in placed"
533
984
  :key="p.t.id"
534
985
  class="absolute"
535
986
  :class="!draft?.has(p.t.id) && 'transition-[left,top] duration-200 ease-out'"
536
- :style="{ left: `${p.x * scale}px`, top: `${p.y * scale}px`, transform: `rotate(${p.t.rotation ?? 0}deg)` }"
987
+ :style="{ left: `${p.x * scale}px`, top: `${p.y * scale}px`, transform: `rotate(${rotationOf('table', p.t.id, p.t.rotation)}deg)` }"
537
988
  >
989
+ <!-- Rotation handle of the one table picked while editing -->
990
+ <span
991
+ v-if="editable && rotatable && selection.length === 1 && selection[0] === p.t.id && tool === 'select'"
992
+ 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"
993
+ :style="{ left: '0px', top: `${-(p.size.h / 2 + CHAIR + 18) * scale}px` }"
994
+ :aria-label="locale.floorRotate"
995
+ data-rotate
996
+ @pointerdown="onRotateDown($event, 'table', p.t.id, p.x, p.y)"
997
+ />
538
998
  <span
539
999
  v-for="(ch, i) in p.chairs"
540
1000
  :key="i"
541
- class="pointer-events-none absolute rounded-md bg-outline-variant"
1001
+ class="m3-floor-chair pointer-events-none absolute rounded-md"
542
1002
  :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)` }"
543
1003
  />
544
1004
  <div
@@ -558,24 +1018,76 @@ const gridStyle = computed(() => {
558
1018
  @click="onClick($event, p.t)"
559
1019
  @keydown="onKey($event, p.t)"
560
1020
  >
561
- <slot name="table" :table="p.t" :status="p.status" :selected="selection.includes(p.t.id)">
562
- <MIcon v-if="p.status?.icon && scale > 0.5" :name="p.status.icon" :size="Math.max(12, 18 * scale)" class="opacity-80" />
563
- <span class="max-w-full truncate px-1 leading-tight font-medium">{{ p.t.label }}</span>
564
- </slot>
1021
+ <!-- The inside stays upright however the table turns -->
1022
+ <span class="flex flex-col items-center justify-center gap-0.5" :style="{ transform: `rotate(${-rotationOf('table', p.t.id, p.t.rotation)}deg)` }">
1023
+ <slot name="table" :table="p.t" :status="p.status" :selected="selection.includes(p.t.id)">
1024
+ <MIcon v-if="p.status?.icon && scale > 0.5" :name="p.status.icon" :size="Math.max(12, 18 * scale)" class="opacity-80" />
1025
+ <span class="max-w-full truncate px-1 leading-tight font-medium">{{ p.t.label }}</span>
1026
+ </slot>
1027
+ </span>
565
1028
  <span
566
1029
  v-if="p.t.badge !== undefined"
567
1030
  class="absolute -top-2 -right-2 min-w-5 rounded-full bg-error px-1.5 text-center text-label-small leading-5 text-on-error"
568
- :style="{ transform: `rotate(${-(p.t.rotation ?? 0)}deg)` }"
1031
+ :style="{ transform: `rotate(${-rotationOf('table', p.t.id, p.t.rotation)}deg)` }"
569
1032
  >{{ p.t.badge }}</span>
570
1033
  </div>
571
1034
  </div>
1035
+ <!-- Anything of yours over the plan, placed in plan units with toPx -->
1036
+ <slot name="overlay" :scale="scale" :to-px="(v: number) => v * scale" />
572
1037
  </div>
573
1038
  </template>
574
1039
 
575
1040
  <style>
1041
+ /* Defaults a consumer's own utilities override: none on the root itself. The colors are custom properties to restyle:
1042
+ --m3-floor-wall, --m3-floor-wall-picked, --m3-floor-chair, --m3-floor-merge, --m3-floor-merge-label */
576
1043
  @layer base {
577
1044
  .m3-floor-plan {
1045
+ --m3-floor-wall: var(--color-on-surface-variant);
1046
+ --m3-floor-wall-picked: var(--color-primary);
1047
+ --m3-floor-chair: var(--color-outline-variant);
1048
+ --m3-floor-merge: var(--color-primary);
1049
+ --m3-floor-merge-label: var(--color-on-primary);
1050
+ position: relative;
1051
+ overflow: hidden;
578
1052
  width: 100%;
1053
+ border-radius: var(--radius-xl, 12px);
1054
+ background-color: var(--color-surface-container-low);
1055
+ }
1056
+ }
1057
+ @layer base {
1058
+ /* Handles: never a scroll, and a finger-sized target around the small mark */
1059
+ .m3-floor-handle {
1060
+ touch-action: none;
1061
+ }
1062
+ .m3-floor-handle::after {
1063
+ content: '';
1064
+ position: absolute;
1065
+ inset: -6px;
1066
+ }
1067
+ @media (pointer: coarse) {
1068
+ .m3-floor-handle::after {
1069
+ inset: -16px;
1070
+ }
1071
+ }
1072
+ .m3-floor-wall {
1073
+ stroke: var(--m3-floor-wall);
1074
+ }
1075
+ .m3-floor-wall-picked {
1076
+ stroke: var(--m3-floor-wall-picked);
1077
+ }
1078
+ .m3-floor-chair {
1079
+ background: var(--m3-floor-chair);
1080
+ }
1081
+ .m3-floor-merge {
1082
+ border-color: color-mix(in srgb, var(--m3-floor-merge) 60%, transparent);
1083
+ background: color-mix(in srgb, var(--m3-floor-merge) 5%, transparent);
1084
+ }
1085
+ .m3-floor-merge-link {
1086
+ stroke: color-mix(in srgb, var(--m3-floor-merge) 60%, transparent);
1087
+ }
1088
+ .m3-floor-merge-label {
1089
+ background: var(--m3-floor-merge);
1090
+ color: var(--m3-floor-merge-label);
579
1091
  }
580
1092
  }
581
1093
  </style>