@m3ui-vue/m3ui-vue 1.3.6 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/API.md +40 -9
- package/dist/api.json +1 -1
- package/dist/components/MBadge.vue.d.ts +1 -1
- package/dist/components/MFlow.vue.d.ts +13 -0
- package/dist/components/MSlider.vue.d.ts +2 -2
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MTour.vue.d.ts +52 -2
- package/dist/composables/flowPaths.d.ts +11 -3
- package/dist/composables/useFlow.d.ts +4 -0
- package/dist/flow.d.ts +1 -1
- package/dist/flow.js +525 -433
- package/dist/flow.js.map +1 -1
- package/dist/{flowPaths-DzW-aiET.js → flowPaths-CcWOKY4Z.js} +5 -5
- package/dist/flowPaths-CcWOKY4Z.js.map +1 -0
- package/dist/gantt.js +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +1851 -1660
- package/dist/m3ui.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/__tests__/MFloorPlan.test.ts +92 -0
- package/src/__tests__/MFlow.test.ts +69 -0
- package/src/__tests__/MTour.test.ts +102 -0
- package/src/components/MFloorPlan.vue +215 -36
- package/src/components/MFlow.vue +117 -17
- package/src/components/MTour.vue +145 -27
- package/src/composables/flowPaths.ts +16 -7
- package/src/composables/useFlow.ts +4 -0
- package/src/flow.ts +1 -1
- package/dist/flowPaths-DzW-aiET.js.map +0 -1
|
@@ -303,6 +303,13 @@ function restore(sn: Snap) {
|
|
|
303
303
|
if (sn.merges !== now.merges) merges.value = sn.merges
|
|
304
304
|
}
|
|
305
305
|
function undo() {
|
|
306
|
+
// While drawing, the last corner placed goes (the first one, the whole drawing)
|
|
307
|
+
if (drawing.value) {
|
|
308
|
+
const pts = distinct(drawing.value)
|
|
309
|
+
drawing.value = pts.length > 1 ? pts.slice(0, -1) : null
|
|
310
|
+
if (!drawing.value) hover.value = null
|
|
311
|
+
return
|
|
312
|
+
}
|
|
306
313
|
const sn = past.value[past.value.length - 1]
|
|
307
314
|
if (!sn) return
|
|
308
315
|
future.value = [snap0(), ...future.value]
|
|
@@ -387,8 +394,9 @@ function zoomTo(z: number, px?: number, py?: number) {
|
|
|
387
394
|
if (!props.zoomable) return
|
|
388
395
|
const next = Math.min(Math.max(z, 1), props.maxZoom)
|
|
389
396
|
const { w, h } = viewSize()
|
|
390
|
-
|
|
391
|
-
const
|
|
397
|
+
// (a pointer without coordinates, as some synthetic events come, zooms about the middle)
|
|
398
|
+
const ax = Number.isFinite(px) ? px! : w / 2
|
|
399
|
+
const ay = Number.isFinite(py) ? py! : h / 2
|
|
392
400
|
const ux = (ax - pan.value.x) / (base.value * panZoom)
|
|
393
401
|
const uy = (ay - pan.value.y) / (base.value * panZoom)
|
|
394
402
|
pan.value = clampPan({ x: ax - ux * base.value * next, y: ay - uy * base.value * next }, next)
|
|
@@ -487,11 +495,60 @@ function onFingerUp(e: PointerEvent) {
|
|
|
487
495
|
window.removeEventListener('pointercancel', onFingerUp)
|
|
488
496
|
}
|
|
489
497
|
}
|
|
490
|
-
/**
|
|
498
|
+
/**
|
|
499
|
+
* Fingers dragging something on the plan (a corner, a wall, a zone…). Its `touch-action: none` isn't enough: Chrome
|
|
500
|
+
* ignores it on SVG shapes (walls and corners are), so the page scrolled under the finger and the drag was cancelled
|
|
501
|
+
*/
|
|
502
|
+
let holding = 0
|
|
503
|
+
/** While two fingers zoom, a finger drags something, or a table is carried to another one, the page doesn't scroll */
|
|
491
504
|
function onTouchMove(e: TouchEvent) {
|
|
492
|
-
if (gesture || transferDrag.value || (props.zoomable && zoomed.value > 1 && e.touches.length > 1)) e.preventDefault()
|
|
505
|
+
if (holding || gesture || transferDrag.value || (props.zoomable && zoomed.value > 1 && e.touches.length > 1)) e.preventDefault()
|
|
506
|
+
}
|
|
507
|
+
// While drawing (walls, zones), a finger draws: the page doesn't scroll under it
|
|
508
|
+
const touchAction = computed(() => (props.editable && tool.value !== 'select' ? 'none' : !props.zoomable ? undefined : zoomed.value > 1 ? 'none' : 'pan-x pan-y'))
|
|
509
|
+
/**
|
|
510
|
+
* Near the view's edges while something is dragged in, the zoomed plan scrolls (as MFlow's canvas does), so a corner
|
|
511
|
+
* or a table can be taken past what's on screen. `.at(ev)` arms it with where the pointer is; `onPan` runs after each
|
|
512
|
+
* scroll, for the drag to bring what it holds along
|
|
513
|
+
*/
|
|
514
|
+
const EDGE_ZONE = 40
|
|
515
|
+
function edgePan(onPan: () => void) {
|
|
516
|
+
let x = 0
|
|
517
|
+
let y = 0
|
|
518
|
+
let armed = false
|
|
519
|
+
let last = 0
|
|
520
|
+
let raf = 0
|
|
521
|
+
const speed = (p: number, lo: number, hi: number) =>
|
|
522
|
+
p < lo + EDGE_ZONE ? Math.min(1, 1 - (p - lo) / EDGE_ZONE) : p > hi - EDGE_ZONE ? -Math.min(1, 1 - (hi - p) / EDGE_ZONE) : 0
|
|
523
|
+
const tick = () => {
|
|
524
|
+
raf = requestAnimationFrame(tick)
|
|
525
|
+
const t = performance.now()
|
|
526
|
+
const dt = last ? Math.min((t - last) / 1000, 1 / 30) : 1 / 60
|
|
527
|
+
last = t
|
|
528
|
+
if (!armed || !props.zoomable || zoomed.value <= 1 || !root.value) return
|
|
529
|
+
// The part of the plan on screen: a plan taller than the window scrolls at the window's edge
|
|
530
|
+
const r = root.value.getBoundingClientRect()
|
|
531
|
+
const [x1, x2] = [Math.max(r.left, 0), Math.min(r.right, window.innerWidth || r.right)]
|
|
532
|
+
const [y1, y2] = [Math.max(r.top, 0), Math.min(r.bottom, window.innerHeight || r.bottom)]
|
|
533
|
+
if (x2 - x1 < EDGE_ZONE * 3 || y2 - y1 < EDGE_ZONE * 3) return
|
|
534
|
+
const vx = speed(x, x1, x2)
|
|
535
|
+
const vy = speed(y, y1, y2)
|
|
536
|
+
if (!vx && !vy) return
|
|
537
|
+
const next = clampPan({ x: pan.value.x + vx * 600 * dt, y: pan.value.y + vy * 600 * dt })
|
|
538
|
+
if (next.x === pan.value.x && next.y === pan.value.y) return
|
|
539
|
+
pan.value = next
|
|
540
|
+
onPan()
|
|
541
|
+
}
|
|
542
|
+
raf = requestAnimationFrame(tick)
|
|
543
|
+
return {
|
|
544
|
+
at(ev: { clientX: number; clientY: number }) {
|
|
545
|
+
x = ev.clientX
|
|
546
|
+
y = ev.clientY
|
|
547
|
+
armed = true
|
|
548
|
+
},
|
|
549
|
+
stop: () => cancelAnimationFrame(raf),
|
|
550
|
+
}
|
|
493
551
|
}
|
|
494
|
-
const touchAction = computed(() => (!props.zoomable ? undefined : zoomed.value > 1 ? 'none' : 'pan-x pan-y'))
|
|
495
552
|
onBeforeUnmount(() => {
|
|
496
553
|
window.removeEventListener('pointermove', onFingerMove)
|
|
497
554
|
window.removeEventListener('pointerup', onFingerUp)
|
|
@@ -606,7 +663,7 @@ const mergeShapes = computed(() =>
|
|
|
606
663
|
)
|
|
607
664
|
|
|
608
665
|
// ── Dragging ────────────────────────────────────────────────────────────────────────────────────────────
|
|
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
|
|
666
|
+
let drag: { id: number; sx: number; sy: number; start: Map<string | number, { x: number; y: number }>; moved: boolean; pick?: string | number; run: number; pan0: { x: number; y: number }; last: { clientX: number; clientY: number }; edge: ReturnType<typeof edgePan> } | null = null
|
|
610
667
|
let suppressClick = false
|
|
611
668
|
/** The step walls, zones and decor snap to: the grid, or a part of it (`subgrid`) */
|
|
612
669
|
const step = computed(() => (props.grid ? props.grid / Math.max(1, Math.round(props.subgrid)) : 0))
|
|
@@ -664,21 +721,28 @@ function onDown(e: PointerEvent, t: FloorTable) {
|
|
|
664
721
|
// `selectable="multiple"` the selection is the click's to change, and a drag moves only the table pressed (not the
|
|
665
722
|
// rest of the selection nor its merge): to bring the tables being merged together one by one
|
|
666
723
|
const ids = toggling.value ? [t.id] : withMerged(selection.value.includes(t.id) ? selection.value : [t.id])
|
|
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 }
|
|
724
|
+
drag = { id: e.pointerId, sx: e.clientX, sy: e.clientY, start: new Map(tables.value.filter((x) => ids.includes(x.id)).map((x) => [x.id, { x: x.x, y: x.y }])), moved: false, pick: touch && !toggling.value && !selection.value.includes(t.id) ? t.id : undefined, run: gestureRun, pan0: { ...pan.value }, last: e, edge: edgePan(() => drag?.moved && drag.run === gestureRun && dragTables()) }
|
|
668
725
|
window.addEventListener('pointermove', onMove)
|
|
669
726
|
window.addEventListener('pointerup', onUp)
|
|
670
727
|
window.addEventListener('pointercancel', onUp)
|
|
671
728
|
}
|
|
672
729
|
function onMove(e: PointerEvent) {
|
|
673
730
|
if (!drag || e.pointerId !== drag.id || drag.run !== gestureRun) return
|
|
674
|
-
const dx = (e.clientX - drag.sx) / scale.value
|
|
675
|
-
const dy = (e.clientY - drag.sy) / scale.value
|
|
676
731
|
if (!drag.moved && Math.hypot(e.clientX - drag.sx, e.clientY - drag.sy) < (e.pointerType === 'touch' ? 8 : 4)) return
|
|
677
732
|
if (!drag.moved) {
|
|
678
733
|
clearTimeout(longPress)
|
|
679
734
|
if (drag.pick !== undefined) selection.value = [drag.pick]
|
|
680
735
|
}
|
|
681
736
|
drag.moved = true
|
|
737
|
+
drag.last = e
|
|
738
|
+
drag.edge.at(e)
|
|
739
|
+
dragTables()
|
|
740
|
+
}
|
|
741
|
+
/** The dragged tables under the pointer (the view may have scrolled since the drag began) */
|
|
742
|
+
function dragTables() {
|
|
743
|
+
if (!drag) return
|
|
744
|
+
const dx = (drag.last.clientX - drag.sx - (pan.value.x - drag.pan0.x)) / scale.value
|
|
745
|
+
const dy = (drag.last.clientY - drag.sy - (pan.value.y - drag.pan0.y)) / scale.value
|
|
682
746
|
const next = new Map<string | number, { x: number; y: number }>()
|
|
683
747
|
for (const [id, p] of drag.start) next.set(id, clamp(tables.value.find((x) => x.id === id)!, p.x + dx, p.y + dy))
|
|
684
748
|
draft.value = next
|
|
@@ -693,6 +757,7 @@ function onUp(e: PointerEvent) {
|
|
|
693
757
|
window.removeEventListener('pointermove', onMove)
|
|
694
758
|
window.removeEventListener('pointerup', onUp)
|
|
695
759
|
window.removeEventListener('pointercancel', onUp)
|
|
760
|
+
drag.edge.stop()
|
|
696
761
|
const d = draft.value
|
|
697
762
|
const moved = drag.moved && d && e.type !== 'pointercancel' && drag.run === gestureRun
|
|
698
763
|
drag = null
|
|
@@ -933,25 +998,39 @@ const toPlan = (e: { clientX: number; clientY: number }) => {
|
|
|
933
998
|
return { x: (e.clientX - r.left - pan.value.x) / scale.value, y: (e.clientY - r.top - pan.value.y) / scale.value }
|
|
934
999
|
}
|
|
935
1000
|
/** A generic drag in plan units: `move` gets the offset from where it started, `end` runs once if it moved */
|
|
936
|
-
function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: () => void) {
|
|
1001
|
+
function follow(e: PointerEvent, move: (dx: number, dy: number) => void, end: () => void, opts: { tap?: () => void; cancel?: () => void } = {}) {
|
|
937
1002
|
// Keys (Delete, Enter) reach the plan while something on it is being edited
|
|
938
1003
|
root.value?.focus({ preventScroll: true })
|
|
939
1004
|
const sx = e.clientX
|
|
940
1005
|
const sy = e.clientY
|
|
941
1006
|
let moved = false
|
|
942
1007
|
const run = gestureRun
|
|
1008
|
+
// Near the edges the zoomed view scrolls, and the offset counts what it scrolled
|
|
1009
|
+
const pan0 = { ...pan.value }
|
|
1010
|
+
let last: { clientX: number; clientY: number } = e
|
|
1011
|
+
const report = () => move((last.clientX - sx - (pan.value.x - pan0.x)) / scale.value, (last.clientY - sy - (pan.value.y - pan0.y)) / scale.value)
|
|
1012
|
+
const edge = edgePan(() => moved && run === gestureRun && report())
|
|
1013
|
+
const touch = e.pointerType === 'touch'
|
|
1014
|
+
if (touch) holding++
|
|
943
1015
|
const mv = (ev: PointerEvent) => {
|
|
944
1016
|
if (ev.pointerId !== e.pointerId || run !== gestureRun) return
|
|
945
|
-
if (!moved && Math.hypot(ev.clientX - sx, ev.clientY - sy) < 4) return
|
|
1017
|
+
if (!moved && Math.hypot(ev.clientX - sx, ev.clientY - sy) < (ev.pointerType === 'touch' ? 6 : 4)) return
|
|
946
1018
|
moved = true
|
|
947
|
-
|
|
1019
|
+
last = ev
|
|
1020
|
+
edge.at(ev)
|
|
1021
|
+
report()
|
|
948
1022
|
}
|
|
949
1023
|
const up = (ev: PointerEvent) => {
|
|
950
1024
|
if (ev.pointerId !== e.pointerId) return
|
|
951
1025
|
window.removeEventListener('pointermove', mv)
|
|
952
1026
|
window.removeEventListener('pointerup', up)
|
|
953
1027
|
window.removeEventListener('pointercancel', up)
|
|
954
|
-
|
|
1028
|
+
edge.stop()
|
|
1029
|
+
if (touch) holding = Math.max(0, holding - 1)
|
|
1030
|
+
const ok = run === gestureRun && ev.type !== 'pointercancel'
|
|
1031
|
+
if (moved && ok) end()
|
|
1032
|
+
else if (!moved && ok) opts.tap?.()
|
|
1033
|
+
else opts.cancel?.()
|
|
955
1034
|
}
|
|
956
1035
|
window.addEventListener('pointermove', mv)
|
|
957
1036
|
window.addEventListener('pointerup', up)
|
|
@@ -982,7 +1061,8 @@ function areaSvgLook(color?: string) {
|
|
|
982
1061
|
*/
|
|
983
1062
|
function snapPoint(x: number, y: number, skip?: { kind: 'wall' | 'area'; id: string | number; vertex?: number }): [number, number] {
|
|
984
1063
|
let best: [number, number] | null = null
|
|
985
|
-
|
|
1064
|
+
// A finger covers more than a mouse's tip: it reaches farther
|
|
1065
|
+
let bestD = (coarse.value ? 24 : 12) / scale.value
|
|
986
1066
|
const consider = (pts: [number, number][], kind: 'wall' | 'area', id: string | number | null) =>
|
|
987
1067
|
pts.forEach((p, i) => {
|
|
988
1068
|
if (skip && skip.kind === kind && skip.id === id && (skip.vertex === undefined || skip.vertex === i)) return
|
|
@@ -996,7 +1076,26 @@ function snapPoint(x: number, y: number, skip?: { kind: 'wall' | 'area'; id: str
|
|
|
996
1076
|
for (const a of areas.value) consider(a.points ?? rectCorners(a), 'area', a.id)
|
|
997
1077
|
// The wall or zone being drawn closes on its own corners (but not the one just placed)
|
|
998
1078
|
if (drawing.value) consider(drawing.value.slice(0, -1), 'wall', null)
|
|
999
|
-
|
|
1079
|
+
if (best) return [best[0], best[1]]
|
|
1080
|
+
// Close to the plan's edge it lands on it (in its corner, on both), and never past it: a finger can't reach the
|
|
1081
|
+
// screen's very edge, where the phone takes the swipe for itself
|
|
1082
|
+
const reach = (coarse.value ? 24 : 6) / scale.value
|
|
1083
|
+
const onEdge = (v: number, max: number) => (v < reach ? 0 : v > max - reach ? max : Math.min(max, Math.max(0, snap(v))))
|
|
1084
|
+
return [onEdge(x, props.width), onEdge(y, props.height)]
|
|
1085
|
+
}
|
|
1086
|
+
/** A move (dx, dy) of something whose box is `b`, cut short at the plan's edges (what already sits past one may stay) */
|
|
1087
|
+
function keepIn(dx: number, dy: number, b: { x1: number; y1: number; x2: number; y2: number }): [number, number] {
|
|
1088
|
+
return [
|
|
1089
|
+
Math.min(Math.max(dx, Math.min(0, -b.x1)), Math.max(0, props.width - b.x2)),
|
|
1090
|
+
Math.min(Math.max(dy, Math.min(0, -b.y1)), Math.max(0, props.height - b.y2)),
|
|
1091
|
+
]
|
|
1092
|
+
}
|
|
1093
|
+
/** A snapped coordinate kept inside the plan, unless it already sat outside */
|
|
1094
|
+
const inPlan = (v: number, was: number, max: number) => (was < 0 || was > max ? v : Math.min(max, Math.max(0, v)))
|
|
1095
|
+
const pointsBox = (pts: [number, number][]) => {
|
|
1096
|
+
const xs = pts.map((p) => p[0])
|
|
1097
|
+
const ys = pts.map((p) => p[1])
|
|
1098
|
+
return { x1: Math.min(...xs), y1: Math.min(...ys), x2: Math.max(...xs), y2: Math.max(...ys) }
|
|
1000
1099
|
}
|
|
1001
1100
|
/** The segment of a line (closed: a zone's outline) nearest a point: the index to insert a corner before */
|
|
1002
1101
|
function nearestSegment(pts: [number, number][], p: { x: number; y: number }, closed: boolean) {
|
|
@@ -1049,7 +1148,11 @@ function onAreaDown(e: PointerEvent, a: FloorArea, corner: Corner | null) {
|
|
|
1049
1148
|
picked.value = { kind: 'area', id: a.id }
|
|
1050
1149
|
selection.value = []
|
|
1051
1150
|
if (a.points) {
|
|
1052
|
-
|
|
1151
|
+
const box = pointsBox(a.points)
|
|
1152
|
+
follow(e, (mx, my) => {
|
|
1153
|
+
const [dx, dy] = keepIn(mx, my, box)
|
|
1154
|
+
areaDraft.value = shaped(a, a.points!.map(([x, y]) => [x + dx, y + dy]))
|
|
1155
|
+
}, () => {
|
|
1053
1156
|
const d = areaDraft.value!
|
|
1054
1157
|
areaDraft.value = null
|
|
1055
1158
|
// Moved by whole steps, so its corners stay where they snapped
|
|
@@ -1060,17 +1163,20 @@ function onAreaDown(e: PointerEvent, a: FloorArea, corner: Corner | null) {
|
|
|
1060
1163
|
})
|
|
1061
1164
|
return
|
|
1062
1165
|
}
|
|
1063
|
-
follow(e, (
|
|
1166
|
+
follow(e, (mx, my) => {
|
|
1064
1167
|
if (!corner) {
|
|
1168
|
+
const [dx, dy] = keepIn(mx, my, { x1: a.x, y1: a.y, x2: a.x + a.width, y2: a.y + a.height })
|
|
1065
1169
|
areaDraft.value = { ...a, x: a.x + dx, y: a.y + dy }
|
|
1066
1170
|
return
|
|
1067
1171
|
}
|
|
1068
|
-
// The opposite corner stays put
|
|
1172
|
+
// The opposite corner stays put; the one dragged stops at the plan's edge
|
|
1069
1173
|
const min = step.value || 20
|
|
1070
1174
|
const left = corner.includes('w')
|
|
1071
1175
|
const top = corner[0] === 'n'
|
|
1072
|
-
const
|
|
1073
|
-
const
|
|
1176
|
+
const maxW = Math.max(a.width, left ? a.x + a.width : props.width - a.x)
|
|
1177
|
+
const maxH = Math.max(a.height, top ? a.y + a.height : props.height - a.y)
|
|
1178
|
+
const w = Math.min(maxW, Math.max(min, a.width + (left ? -mx : mx)))
|
|
1179
|
+
const h = Math.min(maxH, Math.max(min, a.height + (top ? -my : my)))
|
|
1074
1180
|
areaDraft.value = { ...a, x: left ? a.x + a.width - w : a.x, y: top ? a.y + a.height - h : a.y, width: w, height: h }
|
|
1075
1181
|
}, () => {
|
|
1076
1182
|
const d = areaDraft.value!
|
|
@@ -1087,7 +1193,16 @@ function onDecorDown(e: PointerEvent, d: FloorDecor, resize = false) {
|
|
|
1087
1193
|
picked.value = { kind: 'decor', id: d.id }
|
|
1088
1194
|
selection.value = []
|
|
1089
1195
|
const s0 = decorSize(d)
|
|
1090
|
-
|
|
1196
|
+
// Its turned box, so it stops at the plan's edges
|
|
1197
|
+
const rad = ((d.rotation ?? 0) * Math.PI) / 180
|
|
1198
|
+
const hw = (s0.w * Math.abs(Math.cos(rad)) + s0.h * Math.abs(Math.sin(rad))) / 2
|
|
1199
|
+
const hh = (s0.w * Math.abs(Math.sin(rad)) + s0.h * Math.abs(Math.cos(rad))) / 2
|
|
1200
|
+
const box = { x1: d.x - hw, y1: d.y - hh, x2: d.x + hw, y2: d.y + hh }
|
|
1201
|
+
follow(e, (mx, my) => {
|
|
1202
|
+
if (resize) return (decorDraft.value = resizedDecor(d, s0, mx, my))
|
|
1203
|
+
const [dx, dy] = keepIn(mx, my, box)
|
|
1204
|
+
decorDraft.value = { ...d, x: d.x + dx, y: d.y + dy }
|
|
1205
|
+
}, () => {
|
|
1091
1206
|
const n = decorDraft.value!
|
|
1092
1207
|
decorDraft.value = null
|
|
1093
1208
|
record()
|
|
@@ -1136,17 +1251,20 @@ function onWallDown(e: PointerEvent, w: FloorWall, vertex = -1) {
|
|
|
1136
1251
|
e.stopPropagation()
|
|
1137
1252
|
picked.value = { kind: 'wall', id: w.id, ...(vertex >= 0 && { vertex }) }
|
|
1138
1253
|
selection.value = []
|
|
1139
|
-
|
|
1140
|
-
|
|
1254
|
+
const box = pointsBox(w.points)
|
|
1255
|
+
follow(e, (mx, my) => {
|
|
1256
|
+
// A wall stops at the plan's edges; a corner lands on another wall's corner nearby (they join), on the plan's
|
|
1257
|
+
// edge, or on the step
|
|
1258
|
+
const [dx, dy] = keepIn(mx, my, box)
|
|
1141
1259
|
wallDraft.value = vertex < 0
|
|
1142
1260
|
? { ...w, points: w.points.map(([x, y]) => [x + dx, y + dy]) }
|
|
1143
|
-
: { ...w, points: w.points.map((p, i) => (i === vertex ? snapPoint(p[0] +
|
|
1261
|
+
: { ...w, points: w.points.map((p, i) => (i === vertex ? snapPoint(p[0] + mx, p[1] + my, { kind: 'wall', id: w.id, vertex }) : p)) }
|
|
1144
1262
|
}, () => {
|
|
1145
1263
|
const n = wallDraft.value!
|
|
1146
1264
|
wallDraft.value = null
|
|
1147
1265
|
record()
|
|
1148
1266
|
// 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))
|
|
1267
|
+
walls.value = walls.value.map((x) => (x.id === w.id ? (vertex >= 0 ? n : { ...n, points: n.points.map(([x, y]) => [inPlan(snap(x), x, props.width), inPlan(snap(y), y, props.height)] as [number, number]) }) : x))
|
|
1150
1268
|
})
|
|
1151
1269
|
}
|
|
1152
1270
|
// Drawing new walls and zones
|
|
@@ -1171,11 +1289,13 @@ const isFloor = (e: Event) => {
|
|
|
1171
1289
|
return el === e.currentTarget || el === viewEl.value || el === svgEl.value || el === zoneSvg.value || el.hasAttribute?.('data-floor-bg')
|
|
1172
1290
|
}
|
|
1173
1291
|
function onPlanPointer(e: PointerEvent) {
|
|
1292
|
+
// The second finger of a pinch only zooms
|
|
1293
|
+
if (gesture) return
|
|
1174
1294
|
const floor = isFloor(e)
|
|
1175
1295
|
const onTable = !!(e.target as Element).closest?.('[data-floor-table]')
|
|
1176
1296
|
// 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')))) {
|
|
1297
|
+
// editing or with a finger picking (while drawing, one finger draws and two pan)
|
|
1298
|
+
if (props.zoomable && (e.button === 1 || (e.button === 0 && zoomed.value > 1 && (floor || (!props.editable && onTable && !props.transferable)) && (!props.editable || (e.pointerType === 'touch' && tool.value === 'select'))))) {
|
|
1179
1299
|
startPan(e)
|
|
1180
1300
|
return
|
|
1181
1301
|
}
|
|
@@ -1209,17 +1329,22 @@ function onPlanPointer(e: PointerEvent) {
|
|
|
1209
1329
|
}
|
|
1210
1330
|
const p = toPlan(e)
|
|
1211
1331
|
if (tool.value === 'wall' || tool.value === 'polygon') {
|
|
1332
|
+
if (e.button !== 0) return
|
|
1212
1333
|
const at = snapPoint(p.x, p.y)
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
if (tool.value === 'polygon' && first && distinct(drawing.value!).length >= 3 && at[0] === first[0] && at[1] === first[1]) return finishWall()
|
|
1216
|
-
drawing.value = [...(drawing.value ?? [at]), at]
|
|
1334
|
+
if (e.pointerType === 'touch') return drawByFinger(e, p, at)
|
|
1335
|
+
placeCorner(at)
|
|
1217
1336
|
return
|
|
1218
1337
|
}
|
|
1219
|
-
const at
|
|
1338
|
+
const at = snapPoint(p.x, p.y)
|
|
1220
1339
|
const id = newId('area')
|
|
1221
1340
|
areaDraft.value = { id, x: at[0], y: at[1], width: 0, height: 0 }
|
|
1222
|
-
follow(e, (
|
|
1341
|
+
follow(e, (mx, my) => {
|
|
1342
|
+
// The far corner stops at the plan's edge, and lands on it nearby
|
|
1343
|
+
const [ex, ey] = snapPoint(at[0] + mx, at[1] + my)
|
|
1344
|
+
const dx = ex - at[0]
|
|
1345
|
+
const dy = ey - at[1]
|
|
1346
|
+
areaDraft.value = { id, x: Math.min(at[0], at[0] + dx), y: Math.min(at[1], at[1] + dy), width: Math.abs(dx), height: Math.abs(dy) }
|
|
1347
|
+
}, () => {
|
|
1223
1348
|
const d = areaDraft.value!
|
|
1224
1349
|
areaDraft.value = null
|
|
1225
1350
|
if (d.width > 10 && d.height > 10) {
|
|
@@ -1229,8 +1354,48 @@ function onPlanPointer(e: PointerEvent) {
|
|
|
1229
1354
|
}
|
|
1230
1355
|
})
|
|
1231
1356
|
}
|
|
1357
|
+
const samePoint = (a: [number, number], b: [number, number]) => a[0] === b[0] && a[1] === b[1]
|
|
1358
|
+
/**
|
|
1359
|
+
* A corner of the wall or zone being drawn. A zone closes when its first corner is placed again; placing the last
|
|
1360
|
+
* corner again ends what's drawn (a double-click does the same with a mouse, a second tap there with a finger)
|
|
1361
|
+
*/
|
|
1362
|
+
function placeCorner(at: [number, number]) {
|
|
1363
|
+
const pts = drawing.value
|
|
1364
|
+
if (pts) {
|
|
1365
|
+
const n = distinct(pts).length
|
|
1366
|
+
if (tool.value === 'polygon' && n >= 3 && samePoint(at, pts[0]!)) return finishWall()
|
|
1367
|
+
if (n >= (tool.value === 'polygon' ? 3 : 2) && samePoint(at, pts[pts.length - 1]!)) return finishWall()
|
|
1368
|
+
}
|
|
1369
|
+
drawing.value = [...(pts ?? [at]), at]
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* A finger draws where it lifts, not where it lands: while it's down the next side follows it (snapped, as a mouse's
|
|
1373
|
+
* hover shows it), so it can be put right before it counts, also on a corner the finger itself covers. A tap places a
|
|
1374
|
+
* corner where it is; a second finger (a pinch) drops what this one was doing
|
|
1375
|
+
*/
|
|
1376
|
+
function drawByFinger(e: PointerEvent, p: { x: number; y: number }, at: [number, number]) {
|
|
1377
|
+
const fresh = !drawing.value
|
|
1378
|
+
if (fresh) drawing.value = [at]
|
|
1379
|
+
hover.value = at
|
|
1380
|
+
follow(e, (dx, dy) => (hover.value = snapPoint(p.x + dx, p.y + dy)), () => {
|
|
1381
|
+
const h = hover.value
|
|
1382
|
+
hover.value = null
|
|
1383
|
+
if (drawing.value && h) placeCorner(h)
|
|
1384
|
+
}, {
|
|
1385
|
+
// The first tap is the first corner, already down
|
|
1386
|
+
tap: () => {
|
|
1387
|
+
hover.value = null
|
|
1388
|
+
if (!fresh) placeCorner(at)
|
|
1389
|
+
},
|
|
1390
|
+
cancel: () => {
|
|
1391
|
+
hover.value = null
|
|
1392
|
+
if (fresh) drawing.value = null
|
|
1393
|
+
},
|
|
1394
|
+
})
|
|
1395
|
+
}
|
|
1232
1396
|
function onPlanMove(e: PointerEvent) {
|
|
1233
|
-
|
|
1397
|
+
// A finger's preview is its drag's
|
|
1398
|
+
if (drawing.value && e.pointerType !== 'touch') {
|
|
1234
1399
|
const p = toPlan(e)
|
|
1235
1400
|
hover.value = snapPoint(p.x, p.y)
|
|
1236
1401
|
}
|
|
@@ -1493,7 +1658,7 @@ const context: FloorPlanContext = {
|
|
|
1493
1658
|
measure: computed(() => props.measure),
|
|
1494
1659
|
statuses: computed(() => props.statuses),
|
|
1495
1660
|
size: computed(() => ({ width: props.width, height: props.height })),
|
|
1496
|
-
canUndo: computed(() => past.value.length > 0),
|
|
1661
|
+
canUndo: computed(() => past.value.length > 0 || !!drawing.value),
|
|
1497
1662
|
canRedo: computed(() => future.value.length > 0),
|
|
1498
1663
|
undo,
|
|
1499
1664
|
redo,
|
|
@@ -1521,7 +1686,7 @@ defineExpose({
|
|
|
1521
1686
|
/** Undo / redo the plan's own edits (also Ctrl+Z, Ctrl+Shift+Z or Ctrl+Y) */
|
|
1522
1687
|
undo,
|
|
1523
1688
|
redo,
|
|
1524
|
-
canUndo: computed(() => past.value.length > 0),
|
|
1689
|
+
canUndo: computed(() => past.value.length > 0 || !!drawing.value),
|
|
1525
1690
|
canRedo: computed(() => future.value.length > 0),
|
|
1526
1691
|
/** Copy the selected tables, or the picked zone or decor (also Ctrl+D) */
|
|
1527
1692
|
duplicate,
|
|
@@ -1805,6 +1970,20 @@ const gridStyle = computed(() => {
|
|
|
1805
1970
|
<!-- Walls -->
|
|
1806
1971
|
<svg ref="svgEl" class="pointer-events-none absolute inset-0 size-full overflow-visible">
|
|
1807
1972
|
<g v-for="w in shownWalls" :key="`w${w.id}`">
|
|
1973
|
+
<!-- With a finger, a wall is a thin line: a wider, unseen band takes the touch -->
|
|
1974
|
+
<path
|
|
1975
|
+
v-if="coarse && editable && tool === 'select'"
|
|
1976
|
+
:d="wallPath(w)"
|
|
1977
|
+
fill="none"
|
|
1978
|
+
stroke="transparent"
|
|
1979
|
+
stroke-linecap="round"
|
|
1980
|
+
stroke-linejoin="round"
|
|
1981
|
+
class="pointer-events-auto cursor-move touch-none"
|
|
1982
|
+
data-wall-hit
|
|
1983
|
+
:stroke-width="Math.max((w.thickness ?? 8) * scale, 28)"
|
|
1984
|
+
@pointerdown="onWallDown($event, w)"
|
|
1985
|
+
@dblclick="onWallDblclick($event, w)"
|
|
1986
|
+
/>
|
|
1808
1987
|
<path
|
|
1809
1988
|
:d="wallPath(w)"
|
|
1810
1989
|
fill="none"
|