@things-factory/figure-ui 10.1.92 → 10.1.93

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 (36) hide show
  1. package/client/modeller/fasten-geometry.ts +152 -0
  2. package/client/modeller/figure-cavity-drawing.ts +259 -0
  3. package/client/modeller/figure-fasten-drawing.ts +406 -0
  4. package/client/modeller/figure-links.ts +71 -35
  5. package/client/modeller/figure-section-panel.ts +2 -0
  6. package/client/modeller/section-controls.ts +19 -0
  7. package/dist-client/modeller/fasten-geometry.d.ts +60 -0
  8. package/dist-client/modeller/fasten-geometry.js +138 -0
  9. package/dist-client/modeller/fasten-geometry.js.map +1 -0
  10. package/dist-client/modeller/figure-cavity-drawing.d.ts +48 -0
  11. package/dist-client/modeller/figure-cavity-drawing.js +253 -0
  12. package/dist-client/modeller/figure-cavity-drawing.js.map +1 -0
  13. package/dist-client/modeller/figure-fasten-drawing.d.ts +74 -0
  14. package/dist-client/modeller/figure-fasten-drawing.js +452 -0
  15. package/dist-client/modeller/figure-fasten-drawing.js.map +1 -0
  16. package/dist-client/modeller/figure-links.d.ts +7 -0
  17. package/dist-client/modeller/figure-links.js +70 -33
  18. package/dist-client/modeller/figure-links.js.map +1 -1
  19. package/dist-client/modeller/figure-section-panel.d.ts +1 -0
  20. package/dist-client/modeller/figure-section-panel.js +2 -0
  21. package/dist-client/modeller/figure-section-panel.js.map +1 -1
  22. package/dist-client/modeller/section-controls.d.ts +10 -0
  23. package/dist-client/modeller/section-controls.js +17 -0
  24. package/dist-client/modeller/section-controls.js.map +1 -1
  25. package/dist-client/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +2 -2
  27. package/test/browser/acceptance-page.js +10 -0
  28. package/test/cavity-drawing.test.ts +69 -0
  29. package/test/fasten-drawing.test.ts +45 -0
  30. package/test/fasten-geometry.test.ts +79 -0
  31. package/test/links.test.ts +3 -1
  32. package/translations/en.json +11 -1
  33. package/translations/ja.json +11 -1
  34. package/translations/ko.json +11 -1
  35. package/translations/ms.json +11 -1
  36. package/translations/zh.json +11 -1
@@ -0,0 +1,152 @@
1
+ import { figurePartFaceOf } from '@hatiolab/figure-model'
2
+ import type { FigureAsset, FigureFace } from '@hatiolab/figure-model'
3
+
4
+ import { boxOf } from './align.js'
5
+ import { alignAxesOf, facesOf, faceAxisOf, hasInstanceSize, mountingPlaneOf, type Alignment } from './links.js'
6
+
7
+ /*
8
+ * What the 붙이기 drawing reads (user 2026-10-01): the face a part is fastened to, seen from above, and where the part
9
+ * lies on it. A fastening is chosen by the target's face and how (올려놓기 · 같은 면에 맞추기 · 가운데를 면에); the part's
10
+ * own face follows from those -- the kernel takes no other pairing (figure-model `attach`: meet is the facing face,
11
+ * flush the same one, a face along another axis would need a turn).
12
+ */
13
+
14
+ type Axis = 'x' | 'y' | 'z'
15
+ const AXES: Axis[] = ['x', 'y', 'z']
16
+ export type FastenMode = 'meet' | 'flush' | 'centre'
17
+ export type FastenTarget = { part: string; face: string } | 'plane'
18
+
19
+ const OPPOSITE: Record<FigureFace, FigureFace> = { left: 'right', right: 'left', bottom: 'top', top: 'bottom', back: 'front', front: 'back' }
20
+ const NORMAL: Record<FigureFace, [Axis, 1 | -1]> = { left: ['x', -1], right: ['x', 1], bottom: ['y', -1], top: ['y', 1], back: ['z', -1], front: ['z', 1] }
21
+
22
+ /** The world direction a part's face looks along now, turns and all; by its name when the face's outline is not read. */
23
+ function directionOf(asset: FigureAsset, part: string, face: string): [Axis, 1 | -1] | undefined {
24
+ const area = (() => {
25
+ try {
26
+ return figurePartFaceOf(asset, part, face)
27
+ } catch {
28
+ return undefined
29
+ }
30
+ })()
31
+ if (area) {
32
+ const k = area.normal.findIndex(v => Math.abs(v) > 0.5)
33
+ if (k >= 0) return [AXES[k]!, area.normal[k]! > 0 ? 1 : -1]
34
+ }
35
+ return face in NORMAL ? NORMAL[face as FigureFace] : undefined
36
+ }
37
+
38
+ /**
39
+ * The part's own face a fastening takes: the one looking against the target's face (올려놓기), with it (같은 면), or its
40
+ * centre. Read from where each face looks now, so a part standing turned offers the face that is really there.
41
+ * Undefined when the part has no such face.
42
+ */
43
+ export function myFaceFor(asset: FigureAsset, part: string, target: FastenTarget, mode: FastenMode): FigureFace | 'centre' | undefined {
44
+ if (mode === 'centre') return target === 'plane' ? undefined : 'centre'
45
+ const want: [Axis, 1 | -1] | undefined =
46
+ target === 'plane'
47
+ ? /* The plane is met from above on a floor, from in front on a wall. */ [mountingPlaneOf(asset).normal, -1]
48
+ : (() => {
49
+ const d = directionOf(asset, target.part, target.face)
50
+ return d && [d[0], (mode === 'meet' ? -d[1] : d[1]) as 1 | -1]
51
+ })()
52
+ if (!want) return undefined
53
+ const mine = facesOf(asset, part).filter((f): f is FigureFace => f in NORMAL)
54
+ const hit = mine.find(f => {
55
+ const d = directionOf(asset, part, f)
56
+ return d && d[0] === want[0] && d[1] === want[1]
57
+ })
58
+ return hit ?? (target !== 'plane' && mode === 'meet' && target.face in OPPOSITE ? OPPOSITE[target.face as FigureFace] : undefined)
59
+ }
60
+
61
+ /** Which way the fastening is, read back from the part's face and facing. */
62
+ export const modeOf = (face: string, facing: 'meet' | 'flush'): FastenMode => (face === 'centre' ? 'centre' : facing)
63
+
64
+ /**
65
+ * The face seen from above: its two axes across (as the form's alignment names them), the face's size on each -- none
66
+ * for a plane with no declared size -- the part's footprint on each, and whether its edges can be lined up with.
67
+ */
68
+ export interface FaceView {
69
+ axes: [Axis, Axis]
70
+ face: Partial<Record<Axis, number>>
71
+ part: Record<Axis, number>
72
+ edges: Record<Axis, boolean>
73
+ }
74
+
75
+ export function faceViewOf(asset: FigureAsset, part: string, target: FastenTarget): FaceView | undefined {
76
+ const across = alignAxesOf(asset, part, target)
77
+ if (across.length !== 2) return undefined
78
+ const box = boxOf(asset, part)
79
+ if (!box) return undefined
80
+ const axes = [across[0]!.axis, across[1]!.axis] as [Axis, Axis]
81
+ const face: Partial<Record<Axis, number>> = {}
82
+ if (target === 'plane') {
83
+ for (const a of axes) if (hasInstanceSize(asset, a)) face[a] = asset.designInputs[`size.${a}`]!
84
+ } else {
85
+ const theirs = boxOf(asset, target.part)
86
+ const normal = faceAxisOf(asset, target.part, target.face)
87
+ for (const a of axes) if (theirs && a !== normal) face[a] = theirs.extent[a]
88
+ }
89
+ return {
90
+ axes,
91
+ face,
92
+ part: { x: box.extent.x, y: box.extent.y, z: box.extent.z },
93
+ edges: Object.fromEntries(across.map(o => [o.axis, o.edges])) as Record<Axis, boolean>
94
+ }
95
+ }
96
+
97
+ /** Where the part's centre is from the face's centre along one axis, for the way it is aligned there. */
98
+ export function offsetOf(how: Alignment | undefined, mm: number | undefined, face: number | undefined, part: number): number {
99
+ if (how === 'min' && face !== undefined) return -(face - part) / 2
100
+ if (how === 'max' && face !== undefined) return (face - part) / 2
101
+ if (how === 'mm' || how === 'share') return mm ?? 0
102
+ return 0
103
+ }
104
+
105
+ /**
106
+ * A place dropped on the face, as the form's alignment: caught at the centre, at an edge from inside (level with it:
107
+ * `min` / `max`, where the edges can be lined up with), or at an edge from outside (touching it, as a distance), when
108
+ * within `catchMm`; anywhere else a distance off centre, whole millimetres.
109
+ */
110
+ export function alignmentAt(d: number, face: number | undefined, part: number, edges: boolean, catchMm: number): { how: Alignment; mm?: number; caught?: 'centre' | 'inside' | 'outside' } {
111
+ if (Math.abs(d) <= catchMm) return { how: 'centre', caught: 'centre' }
112
+ if (face !== undefined) {
113
+ const inside = (face - part) / 2,
114
+ outside = (face + part) / 2
115
+ for (const [at, how] of [
116
+ [-inside, 'min'],
117
+ [inside, 'max']
118
+ ] as const)
119
+ if (Math.abs(d - at) <= catchMm && inside > 0) return edges ? { how, caught: 'inside' } : { how: 'mm', mm: Math.round(at), caught: 'inside' }
120
+ for (const at of [-outside, outside]) if (Math.abs(d - at) <= catchMm) return { how: 'mm', mm: Math.round(at), caught: 'outside' }
121
+ }
122
+ return { how: 'mm', mm: Math.round(d) }
123
+ }
124
+
125
+ /** How far the footprint comes past the face's edges, per side, and whether it touches the face at all. */
126
+ export function overhangOf(view: FaceView, at: Record<Axis, number>): { touching: boolean; sides: Array<{ axis: Axis; side: 'low' | 'high'; mm: number }> } {
127
+ const sides: Array<{ axis: Axis; side: 'low' | 'high'; mm: number }> = []
128
+ let touching = true
129
+ for (const a of view.axes) {
130
+ const face = view.face[a]
131
+ if (face === undefined) continue
132
+ const lo = at[a] - view.part[a] / 2,
133
+ hi = at[a] + view.part[a] / 2
134
+ if (lo >= face / 2 || hi <= -face / 2) touching = false
135
+ if (-face / 2 - lo > 0.5) sides.push({ axis: a, side: 'low', mm: Math.round(-face / 2 - lo) })
136
+ if (hi - face / 2 > 0.5) sides.push({ axis: a, side: 'high', mm: Math.round(hi - face / 2) })
137
+ }
138
+ return { touching, sides }
139
+ }
140
+
141
+ /** Whether the part turns about a joint: then 가운데를 면에 is offered -- a roller spinning in place. */
142
+ export const turnsInPlace = (asset: FigureAsset, part: string) => (asset.joints ?? []).some(j => j.body1.part === part && (j.type === 'revolute' || j.body1.face === 'centre'))
143
+
144
+ /**
145
+ * How the face lies on the screen: X across when it is one of the face's axes, else Z; the other down the screen -- up
146
+ * for Y, which rises, so a front face is seen as it stands and not upside down.
147
+ */
148
+ export function screenOf(axes: readonly [Axis, Axis]): { h: Axis; v: Axis; sign: Record<Axis, 1 | -1> } {
149
+ const h = axes.includes('x') ? 'x' : 'z'
150
+ const v = axes.find(a => a !== h)!
151
+ return { h, v, sign: { x: 1, y: 1, z: 1, [v]: v === 'y' ? -1 : 1 } as Record<Axis, 1 | -1> }
152
+ }
@@ -0,0 +1,259 @@
1
+ import { css, html, LitElement, nothing, svg } from 'lit'
2
+ import { customElement, property, state } from 'lit/decorators.js'
3
+
4
+ import { i18next, localize } from '@operato/i18n'
5
+ import { figureCavitySectionOf } from '@hatiolab/figure-model'
6
+ import type { FigureAuthoringAction, FigureCavityRequest, FigureEvaluatedShape, FigureSection } from '@hatiolab/figure-model'
7
+ import { cavityRefusalOf, cavityWorkingOf, END_FACE, endToggled, mm, SIDE_FACE, wallDragged } from './section-controls.js'
8
+
9
+ type Axis = 'x' | 'y' | 'z'
10
+ type End = 'start' | 'end'
11
+ type Body = { id: string; shape: FigureEvaluatedShape }
12
+
13
+ /** How the section is laid on the screen, by the axis it is pushed along: across to the right, then down. */
14
+ const SCREEN: Record<Axis, [Axis, Axis]> = { y: ['x', 'z'], x: ['z', 'y'], z: ['x', 'y'] }
15
+
16
+ /**
17
+ * 속 공간 그림 — the inside of a pushed part drawn, and edited by drawing (user 2026-10-01: 「이해와 편집이 직관적이지 않다」).
18
+ *
19
+ * Seen along the push, the section and its inside: a handle in the middle of each wall is dragged to its thickness,
20
+ * every wall together unless 면마다 벽 is on. Cut along the push, the walls and the two ends: an end pressed opens or
21
+ * closes it, a closed end's inner line is dragged to its thickness. While dragging, the figure behind shows what the
22
+ * inside makes (`command-live`); letting go sends one `set-cavity`. What the kernel would refuse is drawn in the error
23
+ * colour and said, by the kernel's own check, and is not sent.
24
+ */
25
+ @customElement('figure-cavity-drawing')
26
+ export class FigureCavityDrawing extends localize(i18next)(LitElement) {
27
+ static styles = css`
28
+ :host {
29
+ display: grid;
30
+ gap: 6px;
31
+ }
32
+ svg {
33
+ width: 100%;
34
+ display: block;
35
+ touch-action: none;
36
+ user-select: none;
37
+ }
38
+ svg text {
39
+ font: inherit;
40
+ }
41
+ small[refusal] {
42
+ color: var(--md-sys-color-error);
43
+ }
44
+ `
45
+
46
+ @property({ attribute: false }) body?: Body
47
+ @property({ type: Boolean }) locked = false
48
+ /** Walls one per side: a handle moves its own wall only. */
49
+ @property({ type: Boolean }) perSide = false
50
+
51
+ /** What is being dragged, and the inside it makes; undefined when nothing is. */
52
+ @state() private working?: ReturnType<typeof cavityWorkingOf>
53
+ @state() private refusal = ''
54
+ private dragging: { kind: 'wall'; side: string } | { kind: 'end'; end: End } | null = null
55
+ private pressedAt = 0
56
+
57
+ private get now() {
58
+ return this.working ?? (this.body ? cavityWorkingOf(this.body.shape) : undefined)
59
+ }
60
+
61
+ private request(w: NonNullable<ReturnType<typeof cavityWorkingOf>>): FigureCavityRequest {
62
+ return { wall: { ...w.wall }, start: w.start, end: w.end }
63
+ }
64
+
65
+ private action(w: NonNullable<ReturnType<typeof cavityWorkingOf>>): FigureAuthoringAction {
66
+ return { kind: 'set-cavity', part: this.body!.id, cavity: this.request(w) }
67
+ }
68
+
69
+ private judge(w: NonNullable<ReturnType<typeof cavityWorkingOf>>): string {
70
+ const ask = cavityRefusalOf(this.body!.shape, this.request(w))
71
+ if (!ask) return ''
72
+ if (ask.code === 'wall-too-thick') return i18next.t('figure.text.section-wall-over', { max: String(ask.max) })
73
+ if (ask.code === 'ends-too-thick') return i18next.t('figure.text.section-ends-over', { max: String(ask.max) })
74
+ return i18next.t('figure.text.section-not-positive')
75
+ }
76
+
77
+ /** The working inside while dragging: drawn, judged, and previewed behind when the kernel would take it. */
78
+ private hold(w: NonNullable<ReturnType<typeof cavityWorkingOf>>) {
79
+ this.working = w
80
+ this.refusal = this.judge(w)
81
+ this.emit('command-live', this.refusal ? null : this.action(w))
82
+ }
83
+
84
+ private release() {
85
+ const w = this.working
86
+ this.dragging = null
87
+ this.working = undefined
88
+ if (!w) return
89
+ /* Refused: nothing is sent, and the reason stays said until the next drag -- letting go must not look like taking it. */
90
+ if (this.refusal) {
91
+ this.emit('command-live', null)
92
+ return
93
+ }
94
+ this.emit('command', this.action(w))
95
+ }
96
+
97
+ private emit(name: 'command' | 'command-live', action: FigureAuthoringAction | null) {
98
+ this.dispatchEvent(new CustomEvent(name, { detail: { action }, bubbles: true, composed: true }))
99
+ }
100
+
101
+ private point(ev: PointerEvent, el: SVGSVGElement) {
102
+ const pt = el.createSVGPoint()
103
+ pt.x = ev.clientX
104
+ pt.y = ev.clientY
105
+ return pt.matrixTransform(el.getScreenCTM()!.inverse())
106
+ }
107
+
108
+ render() {
109
+ const e = this.body?.shape.extrusion
110
+ const w = this.now
111
+ if (!e || !w || (e.section.kind !== 'rectangle' && e.section.kind !== 'ellipse')) return nothing
112
+ return html`${this.top(e, w)}${this.side(e, w)}
113
+ ${this.refusal ? html`<small refusal role="alert">${this.refusal}</small>` : nothing}`
114
+ }
115
+
116
+ /** Seen along the push: the section, its inside and a handle on each wall. */
117
+ private top(e: NonNullable<FigureEvaluatedShape['extrusion']>, w: NonNullable<ReturnType<typeof cavityWorkingOf>>) {
118
+ const [h, v] = SCREEN[e.axis]
119
+ const s = e.section
120
+ const across = (a: Axis) => (s.kind === 'rectangle' ? s.size[a]! : 2 * (s as { radius: Record<string, number> }).radius[a]!)
121
+ const W = 300,
122
+ H = 170,
123
+ pad = 26
124
+ const k = Math.min((W - 2 * pad) / across(h), (H - 2 * pad) / across(v))
125
+ const ox = W / 2,
126
+ oy = H / 2
127
+ const inside = figureCavitySectionOf(s as FigureSection, e.axis, w.wall)
128
+ const bad = !!this.refusal || !('section' in inside)
129
+ const shape = (sec: FigureSection, c: Partial<Record<Axis, number>>, attrs: string) => {
130
+ const cx = ox + (c[h] ?? 0) * k,
131
+ cy = oy + (c[v] ?? 0) * k
132
+ if (sec.kind === 'ellipse') return svg`<ellipse cx=${cx} cy=${cy} rx=${sec.radius[h]! * k} ry=${sec.radius[v]! * k} style=${attrs} />`
133
+ const r = sec as { size: Record<string, number>; corner?: Record<string, number> }
134
+ return svg`<rect x=${cx - (r.size[h]! * k) / 2} y=${cy - (r.size[v]! * k) / 2} width=${r.size[h]! * k} height=${r.size[v]! * k}
135
+ rx=${(r.corner?.[h] ?? 0) * k} ry=${(r.corner?.[v] ?? 0) * k} style=${attrs} />`
136
+ }
137
+ const half = { [h]: (across(h) * k) / 2, [v]: (across(v) * k) / 2 } as Record<Axis, number>
138
+ /* Each wall's handle sits on the inside's edge, half way along it; the value is the wall's own. */
139
+ const handles = [`${h}-`, `${h}+`, `${v}-`, `${v}+`].map(side => {
140
+ const a = side[0] as Axis,
141
+ low = side[1] === '-'
142
+ const edge = (low ? -1 : 1) * (half[a] - w.wall[side]! * k)
143
+ const x = a === h ? ox + edge : ox,
144
+ y = a === v ? oy + edge : oy
145
+ /* The number stands in the wall itself, half way through it; a wall too thin for it has it just outside. */
146
+ const band = w.wall[side]! * k
147
+ const mid = (low ? -1 : 1) * (half[a] - (band < 16 ? -9 : band / 2))
148
+ const tx = a === h ? ox + mid : x + 14,
149
+ ty = a === v ? oy + mid + 4 : y - 10
150
+ return svg`<g wall=${side} style=${`cursor:${a === h ? 'ew-resize' : 'ns-resize'}`}
151
+ @pointerdown=${(ev: PointerEvent) => this.grab(ev, { kind: 'wall', side })}>
152
+ <rect x=${x - 6} y=${y - 6} width="12" height="12" rx="2" style="fill:var(--md-sys-color-surface);stroke:var(--md-sys-color-primary);stroke-width:1.5" />
153
+ <text x=${tx} y=${ty} font-size="11" text-anchor=${a === h ? 'middle' : 'start'} style="fill:var(--md-sys-color-on-surface)">${mm(w.wall[side]!)}</text>
154
+ <title>${i18next.t('figure.label.face-' + SIDE_FACE[side])} ${i18next.t('figure.label.section-wall')}</title>
155
+ </g>`
156
+ })
157
+ return svg`<svg viewBox=${`0 0 ${W} ${H}`} role="img" aria-label=${i18next.t('figure.label.section-cavity-top')}
158
+ @pointermove=${(ev: PointerEvent) => this.drag(ev, e, k, ox, oy, half)}
159
+ @pointerup=${() => this.release()} @pointercancel=${() => this.release()}>
160
+ ${shape(s as FigureSection, {}, 'fill:var(--md-sys-color-primary-container);stroke:var(--md-sys-color-primary);stroke-width:1.5')}
161
+ ${'section' in inside
162
+ ? shape(inside.section, inside.centre, `fill:var(--md-sys-color-surface);stroke:${bad ? 'var(--md-sys-color-error)' : 'var(--md-sys-color-primary)'};stroke-width:1.2;stroke-dasharray:4 3`)
163
+ : nothing}
164
+ ${this.locked ? nothing : handles}
165
+ </svg>`
166
+ }
167
+
168
+ /** Cut along the push: the walls across the first plane axis, and the two ends -- pressed to open or close. */
169
+ private side(e: NonNullable<FigureEvaluatedShape['extrusion']>, w: NonNullable<ReturnType<typeof cavityWorkingOf>>) {
170
+ const [h] = SCREEN[e.axis]
171
+ const s = e.section
172
+ const width = s.kind === 'rectangle' ? s.size[h]! : 2 * (s as { radius: Record<string, number> }).radius[h]!
173
+ const length = e.end - e.start
174
+ const W = 300,
175
+ H = 170,
176
+ padX = 40,
177
+ padY = 26
178
+ const k = Math.min((W - 2 * padX) / width, (H - 2 * padY) / length)
179
+ const x0 = W / 2 - (width * k) / 2,
180
+ x1 = W / 2 + (width * k) / 2,
181
+ yTop = H / 2 - (length * k) / 2,
182
+ yBot = H / 2 + (length * k) / 2
183
+ const wl = w.wall[`${h}-`]! * k,
184
+ wr = w.wall[`${h}+`]! * k
185
+ const thick = (end: End) => (w[end] === 'open' ? 0 : (w[end] as { closed: number }).closed * k)
186
+ /* The push's start is drawn at the bottom: a tote stands on its floor. */
187
+ const floor = thick('start'),
188
+ lid = thick('end')
189
+ const fill = 'fill:var(--md-sys-color-primary-container);stroke:var(--md-sys-color-primary);stroke-width:1.2'
190
+ const endZone = (end: End, y: number, t: number) => {
191
+ const open = w[end] === 'open'
192
+ const words = open
193
+ ? i18next.t('figure.label.section-end-open')
194
+ : `${i18next.t('figure.label.section-end-closed')} ${mm((w[end] as { closed: number }).closed)}`
195
+ const label = `${i18next.t('figure.label.face-' + END_FACE(e.axis, end))}: ${words}`
196
+ const inner = end === 'start' ? y - t : y + t
197
+ return svg`<g end=${end} style=${`cursor:${open ? 'pointer' : 'ns-resize'}`}
198
+ @pointerdown=${(ev: PointerEvent) => this.grab(ev, { kind: 'end', end })}>
199
+ <rect x=${x0 + wl} y=${Math.min(y, inner) - 8} width=${x1 - x0 - wl - wr} height=${Math.abs(t) + 16} style="fill:transparent" />
200
+ ${open ? svg`<line x1=${x0 + wl} y1=${y} x2=${x1 - wr} y2=${y} style="stroke:var(--md-sys-color-outline);stroke-dasharray:3 3" />` : nothing}
201
+ <text x=${W / 2} y=${end === 'start' ? yBot + 16 : yTop - 8} font-size="11" text-anchor="middle" style="fill:var(--md-sys-color-primary)">${label}</text>
202
+ <title>${label}</title>
203
+ </g>`
204
+ }
205
+ return svg`<svg viewBox=${`0 0 ${W} ${H + 8}`} role="img" aria-label=${i18next.t('figure.label.section-cavity-side')}
206
+ @pointermove=${(ev: PointerEvent) => this.dragEnd(ev, k, yTop, yBot)}
207
+ @pointerup=${(ev: PointerEvent) => this.releaseEnd(ev)} @pointercancel=${() => this.release()}>
208
+ <rect x=${x0} y=${yTop} width=${wl} height=${yBot - yTop} style=${fill} />
209
+ <rect x=${x1 - wr} y=${yTop} width=${wr} height=${yBot - yTop} style=${fill} />
210
+ ${floor ? svg`<rect x=${x0 + wl} y=${yBot - floor} width=${x1 - x0 - wl - wr} height=${floor} style=${fill} />` : nothing}
211
+ ${lid ? svg`<rect x=${x0 + wl} y=${yTop} width=${x1 - x0 - wl - wr} height=${lid} style=${fill} />` : nothing}
212
+ ${this.locked ? nothing : [endZone('start', yBot, floor), endZone('end', yTop, lid)]}
213
+ </svg>`
214
+ }
215
+
216
+ private grab(ev: PointerEvent, what: NonNullable<FigureCavityDrawing['dragging']>) {
217
+ if (this.locked) return
218
+ ev.stopPropagation()
219
+ ;(ev.currentTarget as Element).closest('svg')!.setPointerCapture(ev.pointerId)
220
+ this.dragging = what
221
+ this.pressedAt = ev.clientY
222
+ this.refusal = ''
223
+ }
224
+
225
+ private drag(ev: PointerEvent, e: NonNullable<FigureEvaluatedShape['extrusion']>, k: number, ox: number, oy: number, half: Record<Axis, number>) {
226
+ const d = this.dragging
227
+ if (d?.kind !== 'wall') return
228
+ const [h] = SCREEN[e.axis]
229
+ const p = this.point(ev, ev.currentTarget as SVGSVGElement)
230
+ const a = d.side[0] as Axis,
231
+ low = d.side[1] === '-'
232
+ const at = a === h ? p.x - ox : p.y - oy
233
+ const value = (half[a] - (low ? -at : at)) / k
234
+ this.hold({ ...this.now!, wall: wallDragged(this.now!.wall, d.side, value, this.perSide) })
235
+ }
236
+
237
+ private dragEnd(ev: PointerEvent, k: number, yTop: number, yBot: number) {
238
+ const d = this.dragging
239
+ if (d?.kind !== 'end' || this.now![d.end] === 'open') return
240
+ if (Math.abs(ev.clientY - this.pressedAt) < 3 && !this.working) return
241
+ const p = this.point(ev, ev.currentTarget as SVGSVGElement)
242
+ const t = d.end === 'start' ? (yBot - p.y) / k : (p.y - yTop) / k
243
+ this.hold({ ...this.now!, [d.end]: { closed: Math.max(1, Math.round(t)) } })
244
+ }
245
+
246
+ /** A press on an end that did not move is a toggle; a drag was a thickness. */
247
+ private releaseEnd(ev: PointerEvent) {
248
+ const d = this.dragging
249
+ if (d?.kind === 'end' && !this.working && Math.abs(ev.clientY - this.pressedAt) < 3) {
250
+ this.dragging = null
251
+ const next = { ...this.now!, [d.end]: endToggled(this.body!.shape, this.now![d.end]) }
252
+ this.refusal = this.judge(next)
253
+ if (!this.refusal) this.emit('command', this.action(next))
254
+ return
255
+ }
256
+ this.release()
257
+ }
258
+ }
259
+