@things-factory/figure-ui 10.1.92 → 10.1.94

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 +412 -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 +460 -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,412 @@
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 type { FigureFace } from '@hatiolab/figure-model'
6
+
7
+ import { alignmentAt, offsetOf, overhangOf, screenOf, type FaceView, type FastenMode } from './fasten-geometry.js'
8
+ import type { Alignment } from './links.js'
9
+
10
+ type Axis = 'x' | 'y' | 'z'
11
+
12
+ /** A change the drawing asks of the fastening form. */
13
+ export type FastenChange =
14
+ | { targetFace: string }
15
+ | { mode: FastenMode }
16
+ | { axis: Axis; how: Alignment; mm?: number }
17
+ | { gap: number }
18
+
19
+ const SEEN: Array<[FigureFace, string]> = [
20
+ ['top', 'M60 30 L100 10 L200 10 L160 30 Z'],
21
+ ['front', 'M60 30 L160 30 L160 100 L60 100 Z'],
22
+ ['right', 'M160 30 L200 10 L200 80 L160 100 Z']
23
+ ]
24
+ /** The faces the drawing cannot show on the box, as tags beside it where they are. */
25
+ /* The box is drawn a little left of its picture's middle, and the viewBox shifts it back to the panel's centre. */
26
+ const HIDDEN: Array<[FigureFace, number, number]> = [
27
+ ['bottom', 30, 114],
28
+ ['left', 24, 62],
29
+ ['back', 236, 14]
30
+ ]
31
+ const PANEL_W = 300
32
+
33
+
34
+ /**
35
+ * 붙이기 그림 (user 2026-10-01) — which face of what the part is fastened to, how, and where on it; each of them chosen
36
+ * by pressing or dragging the drawing, none by a list of faces.
37
+ *
38
+ * The target is drawn as a box whose faces are pressed (the three it hides as tags beside it), or as the one plane the
39
+ * figure stands by. How is three small side views -- set on it, flush with it, its centre on it (only for a part that
40
+ * turns about a joint) -- and the chosen one's gap is dragged. Where is the face seen from above with the part's
41
+ * footprint on it: dragged, caught at the centre and at the edges from inside and outside, a guide drawn where it is
42
+ * caught and a dimension where it is not, which is pressed to type the number. It may go past the edges: the part that
43
+ * does is shaded, and a part off the face altogether is said so. Nothing is decided here: every change goes to the form
44
+ * (`fasten-change`), and a press or a drag let go says so (`fasten-release`), for the form to apply a fastening it holds.
45
+ */
46
+ @customElement('figure-fasten-drawing')
47
+ export class FigureFastenDrawing extends localize(i18next)(LitElement) {
48
+ static styles = css`
49
+ :host {
50
+ display: grid;
51
+ gap: 8px;
52
+ outline: none;
53
+ }
54
+ svg {
55
+ width: 100%;
56
+ display: block;
57
+ touch-action: none;
58
+ user-select: none;
59
+ }
60
+ svg text {
61
+ font: inherit;
62
+ }
63
+ div[modes] {
64
+ display: grid;
65
+ grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
66
+ gap: 6px;
67
+ }
68
+ div[modes] svg {
69
+ width: 64px;
70
+ height: 44px;
71
+ }
72
+ div[modes] button {
73
+ display: grid;
74
+ justify-items: center;
75
+ align-content: center;
76
+ gap: 2px;
77
+ padding: 2px 4px 4px;
78
+ font: inherit;
79
+ font-size: 0.72rem;
80
+ color: var(--md-sys-color-on-surface);
81
+ background: none;
82
+ border: 1px solid var(--md-sys-color-outline-variant);
83
+ border-radius: 8px;
84
+ cursor: pointer;
85
+ }
86
+ div[modes] button[on] {
87
+ border: 1.5px solid var(--md-sys-color-primary);
88
+ background: var(--md-sys-color-primary-container);
89
+ color: var(--md-sys-color-on-primary-container);
90
+ }
91
+ div[where] {
92
+ position: relative;
93
+ }
94
+ div[where] input {
95
+ position: absolute;
96
+ width: 72px;
97
+ font: inherit;
98
+ font-size: 0.75rem;
99
+ }
100
+ small[warn] {
101
+ color: var(--md-sys-color-tertiary);
102
+ }
103
+ small[off] {
104
+ color: var(--md-sys-color-error);
105
+ }
106
+ `
107
+
108
+ /** The target's name, or empty for the plane the figure stands by. */
109
+ @property() target = ''
110
+ /** The plane's name by the figure's placement: 바닥 · 천장 · 벽 · 중심. */
111
+ @property() planeWord = ''
112
+ @property({ attribute: false }) faces: string[] = []
113
+ @property() face = ''
114
+ @property({ attribute: false }) modes: FastenMode[] = ['meet', 'flush']
115
+ @property() mode: FastenMode = 'meet'
116
+ @property({ attribute: false }) view?: FaceView
117
+ @property({ attribute: false }) align: Partial<Record<Axis, Alignment>> = {}
118
+ @property({ attribute: false }) alignMm: Partial<Record<Axis, number>> = {}
119
+ @property({ type: Number }) gap = 0
120
+ /** The part being fastened (not `part`: that is every element's own). */
121
+ @property() partName = ''
122
+ @property({ type: Boolean }) locked = false
123
+ /** The form already says how the fastening it has lies on the face: the drawing says it only while dragging. */
124
+ @property({ type: Boolean }) said = false
125
+
126
+ /** Where the footprint is while dragging, and what it is caught by; undefined when nothing is dragged. */
127
+ @state() private dragged?: { at: Record<Axis, number>; caught: Partial<Record<Axis, string>> }
128
+ @state() private typing?: Axis
129
+ private scale = 1
130
+ private gapFrom?: { y: number; gap: number }
131
+
132
+ private change(detail: FastenChange) {
133
+ this.dispatchEvent(new CustomEvent('fasten-change', { detail, bubbles: true, composed: true }))
134
+ }
135
+ private released() {
136
+ this.dispatchEvent(new CustomEvent('fasten-release', { bubbles: true, composed: true }))
137
+ }
138
+
139
+ render() {
140
+ return html`${this.renderTarget()}${this.renderModes()}${this.renderWhere()}`
141
+ }
142
+
143
+ /** The target box, its faces pressed; or the plane. */
144
+ private renderTarget() {
145
+ /* The plane is one face, named in the list and on the face drawn below: nothing to pick, so no picture of it. */
146
+ if (!this.target) return nothing
147
+ const has = (f: string) => this.faces.includes(f)
148
+ /* A press is a whole change, as a drag let go is: the form applies a fastening the part already has. */
149
+ const pick = (f: string) => () => {
150
+ if (this.locked || !has(f) || f === this.face) return
151
+ this.change({ targetFace: f })
152
+ this.released()
153
+ }
154
+ const seen = SEEN.map(([f, d]) => {
155
+ const on = this.face === f
156
+ return svg`<path face=${f} d=${d} @click=${pick(f)}
157
+ style=${`cursor:${has(f) ? 'pointer' : 'default'};fill:${on ? 'var(--md-sys-color-primary-container)' : 'var(--md-sys-color-surface-container)'};fill-opacity:${has(f) ? 1 : 0.4};stroke:${on ? 'var(--md-sys-color-primary)' : 'var(--md-sys-color-outline)'};stroke-width:${on ? 2 : 1}`}>
158
+ <title>${i18next.t('figure.label.face-' + f)}</title></path>`
159
+ })
160
+ const hidden = HIDDEN.map(([f, x, y]) => {
161
+ const on = this.face === f
162
+ return svg`<g face=${f} @click=${pick(f)} style=${`cursor:${has(f) ? 'pointer' : 'default'};opacity:${has(f) ? 1 : 0.35}`}>
163
+ <rect x=${x - 26} y=${y - 10} width="52" height="20" rx="10"
164
+ style=${`fill:${on ? 'var(--md-sys-color-primary-container)' : 'transparent'};stroke:${on ? 'var(--md-sys-color-primary)' : 'var(--md-sys-color-outline)'};stroke-dasharray:${on ? '' : '3 2'}`} />
165
+ <text x=${x} y=${y + 4} text-anchor="middle" font-size="11" style=${`fill:${on ? 'var(--md-sys-color-on-primary-container)' : 'var(--md-sys-color-on-surface-variant)'}`}>${i18next.t('figure.label.face-' + f)}</text>
166
+ </g>`
167
+ })
168
+ /* A shape's faces beyond its six outer ones -- a door frame's opening -- are tags of their own under the box. */
169
+ const others = this.faces.filter(f => !SEEN.some(([s]) => s === f) && !HIDDEN.some(([h]) => h === f))
170
+ return html`${svg`<svg viewBox="-20 0 ${PANEL_W} 126" role="img" aria-label=${this.target}>
171
+ ${seen}
172
+ <text x="110" y="70" text-anchor="middle" font-size="12" pointer-events="none" style="fill:var(--md-sys-color-on-surface)">${this.target}</text>
173
+ ${hidden}
174
+ </svg>`}
175
+ ${others.length
176
+ ? html`<div modes>
177
+ ${others.map(f => html`<button ?on=${f === this.face} ?disabled=${this.locked} @click=${pick(f)}>${i18next.t('figure.label.face-' + f, { defaultValue: f })}</button>`)}
178
+ </div>`
179
+ : nothing}`
180
+ }
181
+
182
+ /** How: three side views; the chosen one's gap is dragged. */
183
+ private renderModes() {
184
+ /* One way only (the plane is set on): the sentence says it; a single choice is not offered as a button. */
185
+ if (this.modes.length < 2) return nothing
186
+ const icon = (m: FastenMode, on: boolean) => {
187
+ const g = on && m !== 'centre' ? Math.min(this.gap / 4, 10) : 0
188
+ const base = svg`<rect x="6" y="30" width="52" height="14" style="fill:var(--md-sys-color-primary-container);stroke:var(--md-sys-color-primary)" />`
189
+ const gapDrag = on && !this.locked ? 'ns-resize' : 'pointer'
190
+ if (m === 'meet')
191
+ return svg`<svg viewBox="0 0 64 48">${base}<rect gap x="22" y=${18 - g} width="20" height="12" style=${`fill:var(--md-sys-color-surface);stroke:currentColor;cursor:${gapDrag}`} />
192
+ ${g ? svg`<text x="46" y=${26 - g / 2} font-size="10" style="fill:currentColor">${this.gap}</text>` : nothing}</svg>`
193
+ if (m === 'flush')
194
+ return svg`<svg viewBox="0 0 64 48">${base}<rect gap x="22" y=${30 - g} width="20" height="10" style=${`fill:var(--md-sys-color-surface);stroke:currentColor;cursor:${gapDrag}`} />
195
+ <line x1="4" y1="30" x2="60" y2="30" style="stroke:currentColor;stroke-dasharray:2 2" /></svg>`
196
+ return svg`<svg viewBox="0 0 64 48">${base}<circle cx="32" cy="30" r="11" style="fill:var(--md-sys-color-surface);fill-opacity:.85;stroke:currentColor" /><circle cx="32" cy="30" r="2" style="fill:currentColor" /></svg>`
197
+ }
198
+ return html`<div modes>
199
+ ${this.modes.map(m => {
200
+ const on = m === this.mode
201
+ return html`<button mode=${m} ?on=${on} ?disabled=${this.locked}
202
+ @click=${() => {
203
+ if (on) return
204
+ this.change({ mode: m })
205
+ this.released()
206
+ }}
207
+ @pointerdown=${(ev: PointerEvent) => {
208
+ if (!on || this.locked || !(ev.target as Element).hasAttribute?.('gap')) return
209
+ ev.preventDefault()
210
+ ;(ev.currentTarget as Element).setPointerCapture(ev.pointerId)
211
+ this.gapFrom = { y: ev.clientY, gap: this.gap }
212
+ }}
213
+ @pointermove=${(ev: PointerEvent) => {
214
+ if (!this.gapFrom) return
215
+ this.change({ gap: Math.max(0, Math.round(this.gapFrom.gap + (this.gapFrom.y - ev.clientY) * 2)) })
216
+ }}
217
+ @pointerup=${() => {
218
+ if (!this.gapFrom) return
219
+ this.gapFrom = undefined
220
+ this.released()
221
+ }}>
222
+ ${icon(m, on)}<span>${i18next.t('figure.label.fasten-mode-' + m)}</span>
223
+ </button>`
224
+ })}
225
+ </div>`
226
+ }
227
+
228
+ /** Where the part's centre is on each axis now: the drag's, or the form's. */
229
+ private centreOf(view: FaceView): Record<Axis, number> {
230
+ if (this.dragged) return this.dragged.at
231
+ const at = { x: 0, y: 0, z: 0 }
232
+ for (const a of view.axes) at[a] = offsetOf(this.align[a], this.alignMm[a], view.face[a], view.part[a])
233
+ return at
234
+ }
235
+
236
+ /** What each axis is caught by now: at the centre, level with an edge, touching one from outside, or nothing. */
237
+ private caughtOf(view: FaceView, at: Record<Axis, number>): Partial<Record<Axis, string>> {
238
+ if (this.dragged) return this.dragged.caught
239
+ const out: Partial<Record<Axis, string>> = {}
240
+ for (const a of view.axes) {
241
+ const how = this.align[a] ?? 'centre'
242
+ if (how === 'centre') out[a] = 'centre'
243
+ else if (how === 'min' || how === 'max') out[a] = 'inside'
244
+ else if (view.face[a] !== undefined && Math.abs(Math.abs(at[a]) - (view.face[a]! + view.part[a]) / 2) < 0.5) out[a] = 'outside'
245
+ }
246
+ return out
247
+ }
248
+
249
+ private renderWhere() {
250
+ const view = this.view
251
+ if (!view) return nothing
252
+ const { h, v, sign } = screenOf(view.axes)
253
+ const W = PANEL_W,
254
+ H = 180
255
+ /* Room around the face for the part to go past its edges by about half itself; a plane with no size, three parts wide. */
256
+ const span = (a: Axis) => (view.face[a] !== undefined ? view.face[a]! + view.part[a] : view.part[a] * 3)
257
+ const k = Math.min((W - 40) / span(h), (H - 40) / span(v))
258
+ this.scale = k
259
+ const cx = W / 2,
260
+ cy = H / 2
261
+ const at = this.centreOf(view)
262
+ const caught = this.caughtOf(view, at)
263
+ const fw = (view.face[h] ?? 0) * k,
264
+ fh = (view.face[v] ?? 0) * k
265
+ const pw = view.part[h] * k,
266
+ ph = view.part[v] * k
267
+ const px = cx + sign[h] * at[h] * k - pw / 2,
268
+ py = cy + sign[v] * at[v] * k - ph / 2
269
+ const faceSized = view.face[h] !== undefined && view.face[v] !== undefined
270
+ const fx = cx - fw / 2,
271
+ fy = cy - fh / 2
272
+ const ix = Math.max(fx, px),
273
+ iy = Math.max(fy, py)
274
+ const iw = Math.min(fx + fw, px + pw) - ix,
275
+ ih = Math.min(fy + fh, py + ph) - iy
276
+ const { touching, sides } = faceSized ? overhangOf(view, at) : { touching: true, sides: [] as ReturnType<typeof overhangOf>['sides'] }
277
+ const round = this.mode === 'centre'
278
+ const guide = (a: Axis) => {
279
+ const c = caught[a]
280
+ if (!c) return nothing
281
+ const along = a === h
282
+ const edge = c === 'centre' ? 0 : Math.sign(at[a]) * (view.face[a] ?? 0) / 2
283
+ const pos = (along ? cx : cy) + sign[a] * edge * k
284
+ const style = `stroke:var(--md-sys-color-primary);stroke-width:${c === 'centre' ? 1 : 2.5};stroke-dasharray:${c === 'centre' ? '4 3' : ''}`
285
+ return along ? svg`<line x1=${pos} y1="4" x2=${pos} y2=${H - 4} style=${style} />` : svg`<line x1="4" y1=${pos} x2=${W - 4} y2=${pos} style=${style} />`
286
+ }
287
+ const dim = (a: Axis) => {
288
+ /* Caught by the centre or an edge, the guide says where it is; a number only where nothing caught it. */
289
+ if (caught[a]) return nothing
290
+ const along = a === h
291
+ const mm = Math.round(at[a])
292
+ const label = `${mm > 0 ? '+' : ''}${mm} mm`
293
+ const to = sign[a] * at[a] * k
294
+ const tx = along ? cx + to / 2 : 8,
295
+ ty = along ? H - 6 : cy + to / 2 + 4
296
+ return svg`${along
297
+ ? svg`<line x1=${cx} y1=${H - 16} x2=${cx + to} y2=${H - 16} style="stroke:var(--md-sys-color-on-surface)" />`
298
+ : svg`<line x1="20" y1=${cy} x2="20" y2=${cy + to} style="stroke:var(--md-sys-color-on-surface)" />`}
299
+ <text dim=${a} x=${tx} y=${ty} font-size="11" text-anchor=${along ? 'middle' : 'start'}
300
+ style="fill:var(--md-sys-color-primary);cursor:text;text-decoration:underline dotted" @click=${() => !this.locked && (this.typing = a)}>${label}</text>`
301
+ }
302
+ const faceName = this.target ? `${this.target} ${i18next.t('figure.label.face-' + this.face)}` : this.planeWord
303
+ const sizeWords = faceSized ? ` ${Math.round(view.face[h]!)} × ${Math.round(view.face[v]!)}` : ''
304
+ return html`<div where tabindex="0" @keydown=${(ev: KeyboardEvent) => this.keys(ev, view)}>
305
+ ${svg`<svg viewBox="0 0 ${W} ${H}" role="img" aria-label=${faceName}
306
+ @pointermove=${(ev: PointerEvent) => this.drag(ev, view, cx, cy)}
307
+ @pointerup=${() => this.drop()} @pointercancel=${() => this.drop()}>
308
+ ${faceSized
309
+ ? svg`<rect x=${fx} y=${fy} width=${fw} height=${fh} rx="4" style="fill:var(--md-sys-color-primary-container);stroke:var(--md-sys-color-primary);stroke-width:2" />`
310
+ : svg`<rect x="1" y="1" width=${W - 2} height=${H - 2} rx="8" style="fill:var(--md-sys-color-primary-container);stroke:var(--md-sys-color-primary);stroke-width:2" />`}
311
+ <text x=${faceSized ? fx + 4 : 10} y=${faceSized ? fy + fh - 6 : 18} font-size="11" pointer-events="none" style="fill:var(--md-sys-color-primary)">${faceName}${sizeWords}</text>
312
+ ${guide(h)}${guide(v)}
313
+ <g footprint style=${`cursor:${this.locked ? 'default' : 'grab'}`} @pointerdown=${(ev: PointerEvent) => this.grab(ev, at, caught)}>
314
+ <rect x=${px} y=${py} width=${pw} height=${ph} rx=${round ? pw / 2 : 2} style="fill:var(--md-sys-color-tertiary-container)" />
315
+ ${faceSized && iw > 0 && ih > 0
316
+ ? svg`<rect x=${ix} y=${iy} width=${iw} height=${ih} rx=${round ? Math.min(iw, ih) / 2 : 2} style="fill:var(--md-sys-color-surface)" />`
317
+ : !faceSized
318
+ ? svg`<rect x=${px} y=${py} width=${pw} height=${ph} rx=${round ? pw / 2 : 2} style="fill:var(--md-sys-color-surface)" />`
319
+ : nothing}
320
+ <rect x=${px} y=${py} width=${pw} height=${ph} rx=${round ? pw / 2 : 2}
321
+ style=${`fill:none;stroke:var(--md-sys-color-on-surface);stroke-width:1.5;stroke-dasharray:${touching ? '' : '4 3'}`} />
322
+ <text x=${px + pw / 2} y=${py + ph / 2 + 4} text-anchor="middle" font-size="12" pointer-events="none" style="fill:var(--md-sys-color-on-surface)">${this.partName}</text>
323
+ </g>
324
+ ${dim(h)}${dim(v)}
325
+ </svg>`}
326
+ ${this.typing ? this.renderTyping(view, this.typing, at) : nothing}
327
+ </div>
328
+ ${this.said && !this.dragged
329
+ ? nothing
330
+ : !touching
331
+ ? html`<small off role="status">${i18next.t('figure.text.fasten-off-face', { face: faceName })}</small>`
332
+ : sides.length
333
+ ? html`<small warn role="status">${i18next.t('figure.text.fasten-past-edges', {
334
+ sides: sides.map(s => i18next.t(`figure.text.overhang-side-${s.side}`, { axis: s.axis.toUpperCase(), mm: String(s.mm) })).join(' · ')
335
+ })}</small>`
336
+ : nothing}`
337
+ }
338
+
339
+ private renderTyping(view: FaceView, a: Axis, at: Record<Axis, number>) {
340
+ const along = a === screenOf(view.axes).h
341
+ return html`<input type="number" step="1" aria-label=${`${a.toUpperCase()} mm`} .value=${String(Math.round(at[a]))}
342
+ style=${along ? 'left: calc(50% - 36px); bottom: 0' : 'left: 4px; top: calc(50% - 12px)'}
343
+ @keydown=${(ev: KeyboardEvent) => {
344
+ ev.stopPropagation()
345
+ if (ev.key === 'Escape') this.typing = undefined
346
+ if (ev.key !== 'Enter') return
347
+ const value = Number((ev.target as HTMLInputElement).value)
348
+ this.typing = undefined
349
+ if (!Number.isFinite(value)) return
350
+ this.change({ axis: a, how: 'mm', mm: Math.round(value) })
351
+ this.released()
352
+ }}
353
+ @blur=${() => (this.typing = undefined)} />`
354
+ }
355
+
356
+ private grab(ev: PointerEvent, at: Record<Axis, number>, caught: Partial<Record<Axis, string>>) {
357
+ if (this.locked) return
358
+ ;(ev.currentTarget as Element).closest('svg')!.setPointerCapture(ev.pointerId)
359
+ this.dragged = { at: { ...at }, caught: { ...caught } }
360
+ }
361
+
362
+ /** The footprint follows the pointer, caught at the centre and edges within a few pixels. */
363
+ private drag(ev: PointerEvent, view: FaceView, cx: number, cy: number) {
364
+ if (!this.dragged) return
365
+ const svgEl = ev.currentTarget as SVGSVGElement
366
+ const pt = svgEl.createSVGPoint()
367
+ pt.x = ev.clientX
368
+ pt.y = ev.clientY
369
+ const p = pt.matrixTransform(svgEl.getScreenCTM()!.inverse())
370
+ const { h, v, sign } = screenOf(view.axes)
371
+ const at = { ...this.dragged.at },
372
+ caught: Partial<Record<Axis, string>> = {}
373
+ for (const [a, d] of [
374
+ [h, (sign[h] * (p.x - cx)) / this.scale],
375
+ [v, (sign[v] * (p.y - cy)) / this.scale]
376
+ ] as const) {
377
+ const got = alignmentAt(d, view.face[a], view.part[a], view.edges[a], 8 / this.scale)
378
+ at[a] = offsetOf(got.how, got.mm, view.face[a], view.part[a])
379
+ if (got.caught) caught[a] = got.caught
380
+ }
381
+ this.dragged = { at, caught }
382
+ }
383
+
384
+ private drop() {
385
+ const d = this.dragged
386
+ if (!d || !this.view) return
387
+ this.dragged = undefined
388
+ for (const a of this.view.axes) {
389
+ const got = alignmentAt(d.at[a], this.view.face[a], this.view.part[a], this.view.edges[a], 0.5)
390
+ this.change({ axis: a, how: got.how, ...(got.how === 'mm' ? { mm: got.mm } : {}) })
391
+ }
392
+ this.released()
393
+ }
394
+
395
+ /** Arrows move the part a millimetre, ten with Shift; the centre and edges still catch it. */
396
+ private keys(ev: KeyboardEvent, view: FaceView) {
397
+ const step = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }[ev.key]
398
+ if (!step || this.locked || this.typing) return
399
+ ev.preventDefault()
400
+ ev.stopPropagation()
401
+ const by = ev.shiftKey ? 10 : 1
402
+ const at = this.centreOf(view)
403
+ const { h, v, sign } = screenOf(view.axes)
404
+ ;[h, v].forEach((a, i) => {
405
+ if (!step[i]) return
406
+ /* Up the screen is up the face: a Y that rises goes up with the arrow. */
407
+ const got = alignmentAt(at[a] + sign[a] * step[i]! * by, view.face[a], view.part[a], view.edges[a], by / 2)
408
+ this.change({ axis: a, how: got.how, ...(got.how === 'mm' ? { mm: got.mm } : {}) })
409
+ })
410
+ this.released()
411
+ }
412
+ }
@@ -50,9 +50,14 @@ import {
50
50
  type MotionForm
51
51
  } from './links.js'
52
52
  import { SidePanelStyles } from './side-panel-styles.js'
53
+ import './figure-fasten-drawing.js'
54
+ import type { FastenChange } from './figure-fasten-drawing.js'
55
+ import { faceViewOf, modeOf, myFaceFor, turnsInPlace, type FastenMode } from './fasten-geometry.js'
53
56
  import { HelpToggles } from './help.js'
54
57
 
55
58
  const FACES = Object.keys(FIGURE_FACES) as FigureFace[]
59
+ /** The target list's entry for the plane the figure stands by. */
60
+ const PLANE = '__plane'
56
61
 
57
62
  const freshFasten = () => ({
58
63
  face: 'bottom' as FigureFace | 'centre',
@@ -521,15 +526,19 @@ export class FigureLinks extends localize(i18next)(LitElement) {
521
526
  /* The faces are the ones each shape declares: a part is fastened by one of its outer faces, to any face of the target. */
522
527
  /* On the mounting plane only the faces it takes: a bottom or a top on the floor, a back on a wall. */
523
528
  const plane = mountingPlaneOf(asset)
529
+ const planeWord = i18next.t('figure.label.resize-place-' + (asset.placement ?? 'floor'))
524
530
  /* Its outer faces, and its centre -- a roller spins about its middle (ADR-0093); the mounting plane takes a face. */
525
531
  const mineFaces: Array<FigureFace | 'centre'> = [
526
532
  ...(facesOf(asset, this.partId).filter(face => FACES.includes(face as FigureFace) && (!f.toPlane || plane.faces.includes(face as FigureFace))) as FigureFace[]),
527
533
  ...(f.toPlane ? [] : (['centre'] as const))
528
534
  ]
529
- const myFace = mineFaces.includes(f.face) ? f.face : mineFaces[0]!
530
535
  const theirFaces = f.target ? facesOf(asset, f.target) : FACES
531
536
  const targetFace = theirFaces.includes(f.targetFace) ? f.targetFace : theirFaces[0]!
532
537
  const aim = f.toPlane ? ('plane' as const) : { part: f.target, face: targetFace }
538
+ /* The part's own face is not chosen: the target's face and how give it (user 2026-10-01; the kernel takes no other). */
539
+ const mode: FastenMode = f.toPlane ? 'meet' : modeOf(f.face, f.facing)
540
+ const derived = f.toPlane || f.target ? myFaceFor(asset, this.partId, aim, mode) : undefined
541
+ const myFace = derived ?? (mineFaces.includes(f.face) ? f.face : mineFaces[0]!)
533
542
  const align = f.target || f.toPlane ? alignOf(asset, this.partId, aim, f.align, f.alignMm, !!f.twist, f.alignInput) : undefined
534
543
  const action =
535
544
  f.toPlane || f.target
@@ -599,42 +608,43 @@ export class FigureLinks extends localize(i18next)(LitElement) {
599
608
  </div>
600
609
  ${this.renderDetachWords()}`
601
610
  : nothing}
602
- ${f.toPlane
603
- ? html`<p hint>${i18next.t('figure.text.fasten-edit-on-plane')}</p>`
604
- : html`<div form>
605
- <span>${i18next.t('figure.label.target-part')}</span>
606
- <select @change=${(e: Event) => this.aimAt(asset, { ...f, target: (e.target as HTMLSelectElement).value })}>
607
- <option value="" ?selected=${!f.target}>${i18next.t('figure.label.target-part-placeholder')}</option>
608
- ${targets.map(one =>
609
- loops(one)
610
- ? html`<option value=${one} disabled>${i18next.t('figure.text.target-would-loop', { part: one, mine: this.partId })}</option>`
611
- : html`<option value=${one} ?selected=${one === f.target}>${one}</option>`
612
- )}
613
- </select>
614
- </div>
615
- ${f.target
616
- ? html`<div form>
617
- <span>${i18next.t('figure.label.my-face')}</span>
618
- <select @change=${(e: Event) => (this.fasten = { ...f, face: (e.target as HTMLSelectElement).value as FigureFace | 'centre' })}>
619
- ${mineFaces.map(face => html`<option value=${face} ?selected=${face === myFace}>${i18next.t('figure.label.face-' + face)}</option>`)}
620
- </select>
621
- <span>${i18next.t('figure.label.target-face')}</span>
622
- <select @change=${(e: Event) => this.aimAt(asset, { ...f, targetFace: (e.target as HTMLSelectElement).value as FigureFace })}>
623
- ${theirFaces.map(face => html`<option value=${face} ?selected=${face === targetFace}>${i18next.t('figure.label.face-' + face)}</option>`)}
624
- </select>
625
- </div>`
626
- : html`<p hint>${i18next.t('figure.text.fasten-target-first')}</p>`}`}
611
+ <div form>
612
+ <span>${i18next.t('figure.label.target-part')}</span>
613
+ <select @change=${(e: Event) => {
614
+ const value = (e.target as HTMLSelectElement).value
615
+ this.aimAt(asset, value === PLANE ? { ...f, toPlane: true, target: '' } : { ...f, toPlane: false, target: value })
616
+ }}>
617
+ <option value="" ?selected=${!f.target && !f.toPlane}>${i18next.t('figure.label.target-part-placeholder')}</option>
618
+ <option value=${PLANE} ?selected=${f.toPlane}>${planeWord}</option>
619
+ ${targets.map(one =>
620
+ loops(one)
621
+ ? html`<option value=${one} disabled>${i18next.t('figure.text.target-would-loop', { part: one, mine: this.partId })}</option>`
622
+ : html`<option value=${one} ?selected=${one === f.target && !f.toPlane}>${one}</option>`
623
+ )}
624
+ </select>
625
+ </div>
626
+ ${f.toPlane || f.target
627
+ ? html`<p fasten-sentence>${this.sentenceOf(myFace, f.toPlane ? planeWord : `${f.target}의 ${i18next.t('figure.label.face-' + targetFace)}`, mode)}</p>
628
+ <figure-fasten-drawing
629
+ .target=${f.toPlane ? '' : f.target}
630
+ .planeWord=${planeWord}
631
+ .faces=${theirFaces}
632
+ .face=${targetFace}
633
+ .modes=${f.toPlane ? (['meet'] as FastenMode[]) : ([...(['meet', 'flush'] as FastenMode[]), ...(turnsInPlace(asset, this.partId) ? (['centre'] as FastenMode[]) : [])])}
634
+ .mode=${mode}
635
+ .view=${faceViewOf(asset, this.partId, aim)}
636
+ .align=${f.align}
637
+ .alignMm=${f.alignMm}
638
+ .gap=${f.gap}
639
+ .partName=${this.partId}
640
+ ?locked=${this.locked}
641
+ ?said=${!!held}
642
+ @fasten-change=${(e: CustomEvent<FastenChange>) => this.onFastenChange(asset, e.detail)}
643
+ @fasten-release=${() => this.onFastenRelease(!!held)}
644
+ ></figure-fasten-drawing>`
645
+ : html`<p hint>${i18next.t('figure.text.fasten-target-first')}</p>`}
627
646
  ${(f.toPlane || f.target) ? html`<details fasten-detail>
628
647
  <summary>${i18next.t('figure.label.fasten-detail')} · <span fasten-summary>${detail.length ? detail.join(' · ') : i18next.t('figure.text.fasten-summary-default')}</span></summary>
629
- ${f.toPlane
630
- ? nothing
631
- : html`<div form>
632
- <span>${i18next.t('figure.label.facing')}</span>
633
- <select @change=${(e: Event) => (this.fasten = { ...f, facing: (e.target as HTMLSelectElement).value as 'meet' | 'flush' })}>
634
- <option value="meet" ?selected=${f.facing === 'meet'}>${i18next.t('figure.label.facing-meet')}</option>
635
- <option value="flush" ?selected=${f.facing === 'flush'}>${i18next.t('figure.label.facing-flush')}</option>
636
- </select>
637
- </div>`}
638
648
  ${this.renderAlignment(f.toPlane || f.target ? alignAxesOf(asset, this.partId, aim, !!f.twist) : [])}
639
649
  <div form>
640
650
  <span>${i18next.t('figure.label.gap')}</span>
@@ -650,6 +660,32 @@ export class FigureLinks extends localize(i18next)(LitElement) {
650
660
  `
651
661
  }
652
662
 
663
+ /** 「lid 의 아랫면을 bin 의 윗면에 맞닿게」: what the fastening is, in one line, the part's own face said as a result. */
664
+ private sentenceOf(myFace: string, to: string, mode: FastenMode) {
665
+ return i18next.t(`figure.text.fasten-sentence-${mode}`, { part: this.partId, face: i18next.t('figure.label.face-' + myFace), to })
666
+ }
667
+
668
+ /** A change the drawing asks: to the form only; the preview behind follows the form. */
669
+ private onFastenChange(asset: FigureAsset, c: FastenChange) {
670
+ const f = this.fasten
671
+ if ('targetFace' in c) this.aimAt(asset, { ...f, targetFace: c.targetFace as FigureFace })
672
+ else if ('mode' in c) this.fasten = { ...f, face: c.mode === 'centre' ? 'centre' : f.face === 'centre' ? 'bottom' : f.face, facing: c.mode === 'flush' ? 'flush' : 'meet' }
673
+ else if ('gap' in c) this.fasten = { ...f, gap: c.gap }
674
+ else
675
+ this.fasten = {
676
+ ...f,
677
+ align: { ...f.align, [c.axis]: c.how },
678
+ alignMm: c.how === 'mm' ? { ...f.alignMm, [c.axis]: c.mm ?? 0 } : f.alignMm
679
+ }
680
+ }
681
+
682
+ /** Let go: a fastening the part already has is applied as it now is (one step); a new one waits for 붙이기. */
683
+ private async onFastenRelease(held: boolean) {
684
+ if (!held) return
685
+ await this.updateComplete
686
+ if (this.fastenCandidate) this.command(this.fastenCandidate.action)
687
+ }
688
+
653
689
  private renderDetachWords() {
654
690
  return this.detachWords.length ? html`<ul detach-words>${this.detachWords.map(line => html`<li>${line}</li>`)}</ul>` : nothing
655
691
  }
@@ -6,6 +6,7 @@ import { i18next, localize } from '@operato/i18n'
6
6
  import type { FigureAuthoringAction, FigureCavityRequest, FigureEvaluatedShape } from '@hatiolab/figure-model'
7
7
  import { SidePanelStyles } from './side-panel-styles.js'
8
8
  import { drawnOf } from './section-drawing.js'
9
+ import './figure-cavity-drawing.js'
9
10
  import {
10
11
  END_FACE,
11
12
  SIDE_FACE,
@@ -188,6 +189,7 @@ export class FigureSectionPanel extends localize(i18next)(LitElement) {
188
189
  </small>`
189
190
  : nothing}
190
191
  </div>
192
+ ${cavity ? html`<figure-cavity-drawing .body=${body} .perSide=${this.perSide} ?locked=${this.locked}></figure-cavity-drawing>` : nothing}
191
193
  ${cavity
192
194
  ? html`<div field>
193
195
  <label>${i18next.t('figure.label.section-wall')}</label>
@@ -113,3 +113,22 @@ export function cavityDepthOf(shape: FigureEvaluatedShape): number {
113
113
  const closed = (x: typeof c.start) => (x === 'open' ? 0 : x.closed)
114
114
  return mm(e.end - e.start - closed(c.start) - closed(c.end))
115
115
  }
116
+
117
+ /** The inside as it stands, every side's wall written out. */
118
+ export function cavityWorkingOf(shape: FigureEvaluatedShape): { wall: Record<string, number>; start: FigureCavityRequest['start']; end: FigureCavityRequest['end'] } | undefined {
119
+ const c = shape.cavity
120
+ const e = shape.extrusion
121
+ if (!c || !e) return undefined
122
+ return { wall: Object.fromEntries(sidesOf(e.axis).map(s => [s, c.wall[s]!])), start: c.start, end: c.end }
123
+ }
124
+
125
+ /** A wall dragged to `value`: that side alone, or every side when the walls are one. */
126
+ export function wallDragged(wall: Record<string, number>, side: string, value: number, perSide: boolean): Record<string, number> {
127
+ const v = Math.max(1, Math.round(value))
128
+ return perSide ? { ...wall, [side]: v } : Object.fromEntries(Object.keys(wall).map(s => [s, v]))
129
+ }
130
+
131
+ /** An end pressed: open becomes closed by the default wall, closed becomes open. */
132
+ export function endToggled(shape: FigureEvaluatedShape, now: FigureCavityRequest['start']): FigureCavityRequest['start'] {
133
+ return now === 'open' ? { closed: defaultWallOf(shape) } : 'open'
134
+ }
@@ -0,0 +1,60 @@
1
+ import type { FigureAsset, FigureFace } from '@hatiolab/figure-model';
2
+ import { type Alignment } from './links.js';
3
+ type Axis = 'x' | 'y' | 'z';
4
+ export type FastenMode = 'meet' | 'flush' | 'centre';
5
+ export type FastenTarget = {
6
+ part: string;
7
+ face: string;
8
+ } | 'plane';
9
+ /**
10
+ * The part's own face a fastening takes: the one looking against the target's face (올려놓기), with it (같은 면), or its
11
+ * centre. Read from where each face looks now, so a part standing turned offers the face that is really there.
12
+ * Undefined when the part has no such face.
13
+ */
14
+ export declare function myFaceFor(asset: FigureAsset, part: string, target: FastenTarget, mode: FastenMode): FigureFace | 'centre' | undefined;
15
+ /** Which way the fastening is, read back from the part's face and facing. */
16
+ export declare const modeOf: (face: string, facing: "meet" | "flush") => FastenMode;
17
+ /**
18
+ * The face seen from above: its two axes across (as the form's alignment names them), the face's size on each -- none
19
+ * for a plane with no declared size -- the part's footprint on each, and whether its edges can be lined up with.
20
+ */
21
+ export interface FaceView {
22
+ axes: [Axis, Axis];
23
+ face: Partial<Record<Axis, number>>;
24
+ part: Record<Axis, number>;
25
+ edges: Record<Axis, boolean>;
26
+ }
27
+ export declare function faceViewOf(asset: FigureAsset, part: string, target: FastenTarget): FaceView | undefined;
28
+ /** Where the part's centre is from the face's centre along one axis, for the way it is aligned there. */
29
+ export declare function offsetOf(how: Alignment | undefined, mm: number | undefined, face: number | undefined, part: number): number;
30
+ /**
31
+ * A place dropped on the face, as the form's alignment: caught at the centre, at an edge from inside (level with it:
32
+ * `min` / `max`, where the edges can be lined up with), or at an edge from outside (touching it, as a distance), when
33
+ * within `catchMm`; anywhere else a distance off centre, whole millimetres.
34
+ */
35
+ export declare function alignmentAt(d: number, face: number | undefined, part: number, edges: boolean, catchMm: number): {
36
+ how: Alignment;
37
+ mm?: number;
38
+ caught?: 'centre' | 'inside' | 'outside';
39
+ };
40
+ /** How far the footprint comes past the face's edges, per side, and whether it touches the face at all. */
41
+ export declare function overhangOf(view: FaceView, at: Record<Axis, number>): {
42
+ touching: boolean;
43
+ sides: Array<{
44
+ axis: Axis;
45
+ side: 'low' | 'high';
46
+ mm: number;
47
+ }>;
48
+ };
49
+ /** Whether the part turns about a joint: then 가운데를 면에 is offered -- a roller spinning in place. */
50
+ export declare const turnsInPlace: (asset: FigureAsset, part: string) => boolean;
51
+ /**
52
+ * 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
53
+ * for Y, which rises, so a front face is seen as it stands and not upside down.
54
+ */
55
+ export declare function screenOf(axes: readonly [Axis, Axis]): {
56
+ h: Axis;
57
+ v: Axis;
58
+ sign: Record<Axis, 1 | -1>;
59
+ };
60
+ export {};