@things-factory/figure-viewer 10.1.266 → 10.1.279
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-client/data-words.d.ts +5 -0
- package/dist-client/data-words.js +13 -3
- package/package.json +17 -3
- package/translations/en.json +1 -1
- package/translations/es.json +1 -1
- package/translations/ja.json +1 -1
- package/translations/ko.json +1 -1
- package/translations/ms.json +1 -1
- package/translations/zh.json +1 -1
- package/client/capability-rung.ts +0 -22
- package/client/controls.ts +0 -54
- package/client/data-connection.ts +0 -82
- package/client/data-words.ts +0 -31
- package/client/detail-facts.ts +0 -86
- package/client/detail-motion.ts +0 -61
- package/client/figure-asset-viewer.ts +0 -472
- package/client/figure-data-list.ts +0 -87
- package/client/figure-data-report.ts +0 -142
- package/client/figure-facts-list.ts +0 -59
- package/client/figure-thumb-mark.ts +0 -34
- package/client/figure-view.ts +0 -151
- package/client/index.ts +0 -19
- package/client/preview-model.ts +0 -162
- package/client/side-panel-styles.ts +0 -480
- package/client/tsconfig.json +0 -19
- package/client/unit-words.ts +0 -11
- package/dist-client/capability-rung.js.map +0 -1
- package/dist-client/controls.js.map +0 -1
- package/dist-client/data-connection.js.map +0 -1
- package/dist-client/data-words.js.map +0 -1
- package/dist-client/detail-facts.js.map +0 -1
- package/dist-client/detail-motion.js.map +0 -1
- package/dist-client/figure-asset-viewer.js.map +0 -1
- package/dist-client/figure-data-list.js.map +0 -1
- package/dist-client/figure-data-report.js.map +0 -1
- package/dist-client/figure-facts-list.js.map +0 -1
- package/dist-client/figure-thumb-mark.js.map +0 -1
- package/dist-client/figure-view.js.map +0 -1
- package/dist-client/index.js.map +0 -1
- package/dist-client/preview-model.js.map +0 -1
- package/dist-client/side-panel-styles.js.map +0 -1
- package/dist-client/tsconfig.tsbuildinfo +0 -1
- package/dist-client/unit-words.js.map +0 -1
- package/dist-server/index.js.map +0 -1
- package/dist-server/tsconfig.tsbuildinfo +0 -1
- package/server/index.ts +0 -4
- package/server/tsconfig.json +0 -10
- package/test/controls.test.ts +0 -51
- package/test/data-connection.test.ts +0 -35
- package/test/detail-facts.test.ts +0 -89
- package/test/detail-motion.test.ts +0 -110
- package/test/figure-data-report.test.ts +0 -88
- package/test/joints.ts +0 -30
- package/test/preview.test.ts +0 -101
- package/test/resolve-ts-siblings.mjs +0 -85
- package/test/view.test.ts +0 -13
|
@@ -1,472 +0,0 @@
|
|
|
1
|
-
import '@material/web/icon/icon.js'
|
|
2
|
-
import { css, html, LitElement, nothing, type PropertyValues } from 'lit'
|
|
3
|
-
import { customElement, property, query, state } from 'lit/decorators.js'
|
|
4
|
-
import { i18next, localize } from '@operato/i18n'
|
|
5
|
-
import { ScrollbarStyles } from '@operato/styles'
|
|
6
|
-
import { SurfaceStyles } from '@things-factory/styles'
|
|
7
|
-
import { compileFigureAsset, figureDataExample, type FigureAsset } from '@hatiolab/figure-model'
|
|
8
|
-
import { create, registerFigure, unregisterFigure } from '@hatiolab/things-scene'
|
|
9
|
-
import { authoredSizeOf, bodyAtSize, previewOneInstance, sizeSpanOf, sizeWithinRange } from './preview-model.js'
|
|
10
|
-
import { controlsOf } from './controls.js'
|
|
11
|
-
import { DEFAULT_VIEW, previewBoardDepth, sceneLook } from './figure-view.js'
|
|
12
|
-
import { SidePanelStyles } from './side-panel-styles.js'
|
|
13
|
-
import { clipPlayOf, clipsDriving, parametersForClip, playSettingsOf } from './detail-motion.js'
|
|
14
|
-
import { dataConnectionsOf, ITEM_FIELDS } from './data-connection.js'
|
|
15
|
-
import { itemFieldWords, kindWords, methodWords, moveWords } from './data-words.js'
|
|
16
|
-
|
|
17
|
-
type Axis = 'x' | 'y' | 'z'
|
|
18
|
-
/** What the view's tabs show under it: the figure's facts, its size, its motion, the data it takes. */
|
|
19
|
-
export type FigureViewerTab = 'info' | 'size' | 'motion' | 'data'
|
|
20
|
-
export const FIGURE_VIEWER_TABS: readonly FigureViewerTab[] = ['info', 'size', 'motion', 'data']
|
|
21
|
-
/**
|
|
22
|
-
* A property of the figure's board component, as the board's and fmsim's property panels show it (things-scene's
|
|
23
|
-
* \`nature.properties\`): its label word, the state key a board sets and binds, and for a map its entries.
|
|
24
|
-
*/
|
|
25
|
-
interface BoardProperty {
|
|
26
|
-
type: string
|
|
27
|
-
label: string
|
|
28
|
-
name: string
|
|
29
|
-
property?: { entries?: Array<{ key: string; label?: string; unit?: string; min?: number; max?: number; default?: unknown }> }
|
|
30
|
-
}
|
|
31
|
-
/*
|
|
32
|
-
Where the preview shows each: what a board sets once when placing it under the size, its motion under the motion. The
|
|
33
|
-
data's are the data tab's own, from the connections.
|
|
34
|
-
*/
|
|
35
|
-
const DESIGN_KEYS = ['designInputs', 'slotLayout']
|
|
36
|
-
interface Scene {
|
|
37
|
-
dispose?(): void
|
|
38
|
-
resize?(): void
|
|
39
|
-
fit?(type?: string): void
|
|
40
|
-
root?: {
|
|
41
|
-
fitCameraToModel?(): void
|
|
42
|
-
snapshot3d?(width?: number, height?: number, type?: string, quality?: number): Promise<string | undefined>
|
|
43
|
-
|
|
44
|
-
components?: Array<{ model?: { width?: number; height?: number }; nature?: { properties?: BoardProperty[] }; set(props: string | Record<string, unknown>, value?: unknown): void }>
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* A single board instance. Sizes and poses are transient, and never change the asset or call a mutation.
|
|
50
|
-
*
|
|
51
|
-
* The canvas stands at the top and never scrolls away; under it, tabs show the facts, the size or the motion one at a
|
|
52
|
-
* time, and only that body scrolls (user 2026-10-15: the motion sat so far down that playing a clip scrolled the
|
|
53
|
-
* figure out of view). Given a bounded height, the element fills it; without one, it is as tall as what it shows.
|
|
54
|
-
* `tab` is the one shown; choosing another fires `tab-change` (detail `{ tab }`), so a screen showing two can keep them
|
|
55
|
-
* on the same tab.
|
|
56
|
-
*/
|
|
57
|
-
@customElement('figure-asset-viewer')
|
|
58
|
-
export class FigureAssetViewer extends localize(i18next)(LitElement) {
|
|
59
|
-
/*
|
|
60
|
-
The modeller's side panel look (SidePanelStyles), the suite's tab strip (SurfaceStyles' .ui-tabs) and its scrollbar
|
|
61
|
-
for the tab body (ScrollbarStyles); only the viewport, the tab body and the slider rows are this element's.
|
|
62
|
-
*/
|
|
63
|
-
static styles = [SidePanelStyles, SurfaceStyles, ScrollbarStyles, css`
|
|
64
|
-
:host { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
|
|
65
|
-
/*
|
|
66
|
-
The card's own 4:3, so the picture taken is what is seen. A screen that shows the facts beside the view caps it
|
|
67
|
-
(--figure-asset-viewer-canvas-max, a share of the element's height): a wide column's 4:3 is taller than the
|
|
68
|
-
element and pushes the tabs out of sight (user 2026-10-22, the library's release popup).
|
|
69
|
-
*/
|
|
70
|
-
[viewport] { flex: none; aspect-ratio: 4 / 3; max-height: var(--figure-asset-viewer-canvas-max, none); position: relative; background: #858585; }
|
|
71
|
-
nav.ui-tabs { flex: none; padding: 0 16px; }
|
|
72
|
-
[tab-body] { flex: 1; min-height: 0; overflow: auto; }
|
|
73
|
-
[stage] { position: absolute; inset: 0; width: 100%; height: 100%; }
|
|
74
|
-
/*
|
|
75
|
-
The view's own marks in its corner, not buttons beside it: fit the whole figure in view (the modeller's fit, the
|
|
76
|
-
same icon and words), and taking the picture when the screen keeps one.
|
|
77
|
-
*/
|
|
78
|
-
div[marks] { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; }
|
|
79
|
-
div[marks] button { display: inline-grid; place-items: center; width: 28px; height: 28px;
|
|
80
|
-
padding: 0; border: none; border-radius: 50%; background: rgb(0 0 0 / 22%); color: rgb(255 255 255 / 85%); cursor: pointer; }
|
|
81
|
-
div[marks] button:hover:not(:disabled) { background: rgb(0 0 0 / 45%); color: #fff; }
|
|
82
|
-
div[marks] button:disabled { cursor: default; }
|
|
83
|
-
div[marks] md-icon { --md-icon-size: 16px; }
|
|
84
|
-
section { gap: 4px; padding: 10px 16px; }
|
|
85
|
-
section + section { border-top: 1px solid var(--md-sys-color-outline-variant); }
|
|
86
|
-
section:last-child { border-bottom: none; }
|
|
87
|
-
h3 { justify-content: space-between; margin: 0 0 2px; }
|
|
88
|
-
/* The key a board sets and binds, beside the panel's word for it: 「상태값 parameters」. */
|
|
89
|
-
h3 code[key] { margin-right: auto; margin-left: 6px; font-family: var(--ui-mono, ui-monospace, monospace); font-weight: normal; color: var(--md-sys-color-on-surface-variant); }
|
|
90
|
-
h4 { margin: 4px 0 0; font: inherit; color: var(--md-sys-color-on-surface-variant); }
|
|
91
|
-
/* A published design input: its board name and unit, its range, its default. */
|
|
92
|
-
div[entry] { display: grid; grid-template-columns: 1fr auto; gap: 8px; min-height: 22px; align-items: center; }
|
|
93
|
-
div[entry] > span:last-child { color: var(--md-sys-color-on-surface-variant); font-variant-numeric: tabular-nums; }
|
|
94
|
-
/*
|
|
95
|
-
A slider row: its name, the line to drag, and the number. The name column is wide enough for a joint's name and
|
|
96
|
-
unit (「j2-shoulder · deg」) and wraps rather than cutting it; a row grows with its name. A clip's row is its name
|
|
97
|
-
and its play mark.
|
|
98
|
-
*/
|
|
99
|
-
div[slide] { display: grid; grid-template-columns: 120px minmax(64px, 1fr) 52px 22px; align-items: center; gap: 8px; min-height: 22px; }
|
|
100
|
-
div[slide] > span { color: var(--md-sys-color-on-surface-variant); overflow-wrap: anywhere; line-height: 1.3; }
|
|
101
|
-
div[slide][clip] > span { grid-column: 1 / 4; }
|
|
102
|
-
div[slide] input[type='number'] { min-height: 0; height: 20px; padding: 0 2px; border: none; border-bottom: 1px solid transparent; border-radius: 0;
|
|
103
|
-
background: none; text-align: right; font-family: var(--ui-mono, ui-monospace, monospace); -moz-appearance: textfield; }
|
|
104
|
-
div[slide] input[type='number']::-webkit-inner-spin-button, div[slide] input[type='number']::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
|
|
105
|
-
div[slide] input[type='number']:hover:not(:disabled) { border-bottom-color: var(--md-sys-color-outline-variant); }
|
|
106
|
-
div[slide] input[type='number']:focus { outline: none; border-bottom-color: var(--md-sys-color-primary); }
|
|
107
|
-
div[slide] input:disabled { opacity: 0.45; }
|
|
108
|
-
div[slide] output { text-align: right; color: var(--md-sys-color-on-surface-variant); font-variant-numeric: tabular-nums; }
|
|
109
|
-
button[icon] { display: inline-grid; place-items: center; width: 22px; height: 22px; padding: 0; border: none; border-radius: 4px;
|
|
110
|
-
background: transparent; color: var(--md-sys-color-on-surface-variant); cursor: pointer; }
|
|
111
|
-
button[icon]:hover { background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface); }
|
|
112
|
-
button[icon] md-icon { --md-icon-size: 16px; }
|
|
113
|
-
button[icon][aria-pressed='true'] { color: var(--md-sys-color-primary); }
|
|
114
|
-
p[hint] { margin: 0; }
|
|
115
|
-
/* A connection: its field, what it moves and how on one line; under it, where the data has it and of what kind. */
|
|
116
|
-
div[connection] { display: grid; gap: 1px; padding: 3px 0; }
|
|
117
|
-
div[connection] [method] { color: var(--md-sys-color-on-surface-variant); margin-left: 6px; }
|
|
118
|
-
div[connection] [where] { color: var(--md-sys-color-on-surface-variant); overflow-wrap: anywhere; }
|
|
119
|
-
pre[example] { margin: 0; padding: 6px 8px; border-radius: 4px; background: var(--md-sys-color-surface-container); font-family: var(--ui-mono, ui-monospace, monospace);
|
|
120
|
-
font-size: var(--ui-t-micro, 10.5px); white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
121
|
-
p[error] { margin: 0; padding: 8px 16px; color: var(--md-sys-color-error); }
|
|
122
|
-
`]
|
|
123
|
-
@property({ attribute: false }) asset?: FigureAsset
|
|
124
|
-
/** Keeps a picture of the view as the figure's thumbnail. Without it there is no picture to take. */
|
|
125
|
-
@property({ attribute: false }) keepShot?: (dataUrl: string) => Promise<unknown>
|
|
126
|
-
/** The tab shown under the view. */
|
|
127
|
-
@property({ reflect: true }) tab: FigureViewerTab = 'info'
|
|
128
|
-
@query('[stage]') private stage!: HTMLElement
|
|
129
|
-
@state() private shot: '' | 'saving' | 'saved' | 'failed' = ''
|
|
130
|
-
@state() private sizes: Record<Axis, number> = { x: 1, y: 1, z: 1 }
|
|
131
|
-
@state() private values: Record<string, number> = {}
|
|
132
|
-
@state() private playing = ''
|
|
133
|
-
@state() private error = ''
|
|
134
|
-
@state() private copied = false
|
|
135
|
-
private scene?: Scene
|
|
136
|
-
private registered?: string
|
|
137
|
-
private observer?: ResizeObserver
|
|
138
|
-
private needsScene = false
|
|
139
|
-
private played = new Set<string>()
|
|
140
|
-
/** The board component's properties, read from the instance standing here as the board's panel reads them. */
|
|
141
|
-
@state() private exposed: BoardProperty[] = []
|
|
142
|
-
/** The board the instance stands on, set when the scene is built; its centre is the grid's origin. */
|
|
143
|
-
private board = { x: 0, z: 0 }
|
|
144
|
-
|
|
145
|
-
connectedCallback() {
|
|
146
|
-
super.connectedCallback()
|
|
147
|
-
this.needsScene = true
|
|
148
|
-
if (this.hasUpdated) this.observer?.observe(this.stage)
|
|
149
|
-
this.requestUpdate()
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
protected updated(changed: PropertyValues) {
|
|
153
|
-
// Reconnection and a new asset can arrive in the same update. Build exactly once.
|
|
154
|
-
if (changed.has('asset') || this.needsScene) {
|
|
155
|
-
this.needsScene = false
|
|
156
|
-
this.standUp()
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
firstUpdated() {
|
|
160
|
-
this.observer = new ResizeObserver(() => this.scene?.resize?.())
|
|
161
|
-
this.observer.observe(this.stage)
|
|
162
|
-
}
|
|
163
|
-
disconnectedCallback() {
|
|
164
|
-
super.disconnectedCallback()
|
|
165
|
-
this.observer?.disconnect()
|
|
166
|
-
this.teardown()
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
render() {
|
|
170
|
-
const asset = this.asset
|
|
171
|
-
const clips = asset ? [...new Set((asset.drivers ?? []).map(d => d.clip))] : []
|
|
172
|
-
const controls = asset ? controlsOf(asset, this.values) : []
|
|
173
|
-
const shotLabel = this.shot === 'saved' ? i18next.t('figure.text.detail-thumbnail-saved') : i18next.t('figure.button.detail-save-thumbnail')
|
|
174
|
-
const fitLabel = i18next.t('button.fit-view')
|
|
175
|
-
return html`<div viewport><div stage></div>
|
|
176
|
-
${this.asset && !this.error
|
|
177
|
-
? html`<div marks>
|
|
178
|
-
<button fit aria-label=${fitLabel} title=${fitLabel} @click=${() => this.fit()}><md-icon>fit_screen</md-icon></button>
|
|
179
|
-
${this.keepShot
|
|
180
|
-
? html`<button shoot aria-label=${shotLabel} title=${shotLabel} ?disabled=${this.shot === 'saving'}
|
|
181
|
-
@click=${() => this.takeShot()}><md-icon>${this.shot === 'saved' ? 'check' : 'photo_camera'}</md-icon></button>`
|
|
182
|
-
: nothing}
|
|
183
|
-
</div>`
|
|
184
|
-
: nothing}
|
|
185
|
-
</div>
|
|
186
|
-
${this.error ? html`<p error role="alert">${this.error}</p>` : nothing}
|
|
187
|
-
${this.shot === 'failed' ? html`<p error role="alert">${i18next.t('figure.text.detail-thumbnail-failed')}</p>` : nothing}
|
|
188
|
-
${this.renderTabs()}
|
|
189
|
-
<div tab-body role="tabpanel" aria-labelledby=${`tab-${this.tab}`}>
|
|
190
|
-
${this.tab === 'info' ? html`<slot name="facts"></slot>` : nothing}
|
|
191
|
-
${asset && this.tab === 'size' ? this.renderSize(asset) : nothing}
|
|
192
|
-
${asset && this.tab === 'motion' ? this.renderMotion(asset, controls, clips) : nothing}
|
|
193
|
-
${asset && this.tab === 'data' ? this.renderData(asset) : nothing}
|
|
194
|
-
</div>`
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** The tab strip: the facts, the size, the motion, the data. Arrow keys move along it, as the suite's tabs do. */
|
|
198
|
-
private renderTabs() {
|
|
199
|
-
return html`<nav class="ui-tabs" role="tablist" @keydown=${(e: KeyboardEvent) => this.stepTab(e)}>
|
|
200
|
-
${FIGURE_VIEWER_TABS.map(tab => {
|
|
201
|
-
const on = this.tab === tab
|
|
202
|
-
return html`<button role="tab" id=${`tab-${tab}`} data-tab=${tab} ?data-selected=${on} aria-selected=${String(on)}
|
|
203
|
-
tabindex=${on ? 0 : -1} @click=${() => this.choose(tab)}>${i18next.t(`figure.label.detail-tab-${tab}`)}</button>`
|
|
204
|
-
})}
|
|
205
|
-
</nav>`
|
|
206
|
-
}
|
|
207
|
-
private choose(tab: FigureViewerTab) {
|
|
208
|
-
if (tab === this.tab) return
|
|
209
|
-
this.tab = tab
|
|
210
|
-
this.dispatchEvent(new CustomEvent('tab-change', { detail: { tab }, bubbles: true, composed: true }))
|
|
211
|
-
}
|
|
212
|
-
private stepTab(e: KeyboardEvent) {
|
|
213
|
-
const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0
|
|
214
|
-
if (!step) return
|
|
215
|
-
e.preventDefault()
|
|
216
|
-
const at = FIGURE_VIEWER_TABS.indexOf(this.tab)
|
|
217
|
-
const next = FIGURE_VIEWER_TABS[(at + step + FIGURE_VIEWER_TABS.length) % FIGURE_VIEWER_TABS.length]
|
|
218
|
-
this.choose(next)
|
|
219
|
-
this.updateComplete.then(() => this.renderRoot.querySelector<HTMLElement>(`button[data-tab="${next}"]`)?.focus())
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private renderSize(asset: FigureAsset) {
|
|
223
|
-
return html`<section>
|
|
224
|
-
<h3>${i18next.t('figure.label.detail-size')} · mm
|
|
225
|
-
<button icon reset aria-label=${i18next.t('figure.button.detail-reset')} title=${i18next.t('figure.button.detail-reset')}
|
|
226
|
-
@click=${() => this.reset()}><md-icon>restart_alt</md-icon></button></h3>
|
|
227
|
-
${(['x', 'y', 'z'] as const).map(axis => {
|
|
228
|
-
const span = sizeSpanOf(asset, axis)
|
|
229
|
-
const fixed = !span
|
|
230
|
-
return html`<div slide><span>${axis.toUpperCase()}</span>
|
|
231
|
-
<input type="range" aria-label=${`${axis.toUpperCase()} mm`} min=${span?.min ?? this.sizes[axis]} max=${span?.max ?? this.sizes[axis]} step="any"
|
|
232
|
-
.value=${String(this.sizes[axis])} ?disabled=${fixed}
|
|
233
|
-
@input=${(e: Event) => this.resize(axis, (e.target as HTMLInputElement).valueAsNumber)}>
|
|
234
|
-
<input type="number" aria-label=${`${axis.toUpperCase()} mm value`} min=${span?.min ?? this.sizes[axis]} max=${span?.max ?? this.sizes[axis]} step="any"
|
|
235
|
-
.value=${String(this.sizes[axis])} ?disabled=${fixed}
|
|
236
|
-
@change=${(e: Event) => this.resize(axis, (e.target as HTMLInputElement).valueAsNumber)}>
|
|
237
|
-
<span></span>
|
|
238
|
-
</div>`
|
|
239
|
-
})}
|
|
240
|
-
</section>
|
|
241
|
-
${DESIGN_KEYS.flatMap(key => this.exposed.filter(p => p.name === key)).map(p => this.renderDesign(p, asset))}`
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/** The panel's word for a property and the key a board sets and binds it by. */
|
|
245
|
-
private boardName(property: BoardProperty) {
|
|
246
|
-
return html`${i18next.t('label.' + property.label)}<code key>${property.name}</code>`
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/*
|
|
250
|
-
What a board sets once when it places the figure, under its size (user 2026-11-05): the design inputs the author
|
|
251
|
-
published -- each by its board name, with its range and default -- and the slot layout a placement may override.
|
|
252
|
-
*/
|
|
253
|
-
private renderDesign(p: BoardProperty, asset: FigureAsset) {
|
|
254
|
-
const entries = p.property?.entries ?? []
|
|
255
|
-
return html`<section>
|
|
256
|
-
<h3>${this.boardName(p)}</h3>
|
|
257
|
-
${entries.map(
|
|
258
|
-
x => html`<div entry><span>${x.label ?? x.key}${x.unit ? ` · ${x.unit}` : ''}</span>
|
|
259
|
-
<span>${x.min ?? ''}~${x.max ?? ''}${x.default !== undefined ? ` · ${x.default}` : ''}</span></div>`
|
|
260
|
-
)}
|
|
261
|
-
${p.name === 'slotLayout' ? html`<p hint>${asset.document.capabilities.slotLayout?.label ?? ''}</p>` : nothing}
|
|
262
|
-
</section>`
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/*
|
|
266
|
-
The inputs, then the clips. A clip can move many inputs -- the robot dog's walk moves all eight leg joints -- so it
|
|
267
|
-
plays on its own row (user 2026-10-15: a play mark on fl-thigh played the walk and every leg moved). An input the
|
|
268
|
-
clip playing moves cannot be dragged; one a clip played and let go of stands where the clip left it, so its number
|
|
269
|
-
is not shown until it is dragged.
|
|
270
|
-
*/
|
|
271
|
-
private renderMotion(asset: FigureAsset, controls: ReturnType<typeof controlsOf>, clips: string[]) {
|
|
272
|
-
/* Each part under the board's word for it and the key a board sets and binds (user 2026-11-05). */
|
|
273
|
-
const heading = (name: string) => {
|
|
274
|
-
const p = this.exposed.find(x => x.name === name)
|
|
275
|
-
return p ? html`<h3>${this.boardName(p)}</h3>` : nothing
|
|
276
|
-
}
|
|
277
|
-
const groups = asset.motionGroups ?? []
|
|
278
|
-
const free = clips.filter(clip => !groups.some(g => g.clips.includes(clip)))
|
|
279
|
-
return html`<section>
|
|
280
|
-
${controls.length ? heading('parameters') : nothing}
|
|
281
|
-
${controls.map(c => {
|
|
282
|
-
const driving = clipsDriving(asset, c.id)
|
|
283
|
-
const moving = driving.includes(this.playing)
|
|
284
|
-
const held = moving || (driving.some(clip => this.played.has(clip)) && !(c.id in this.values))
|
|
285
|
-
return html`<div slide><span title=${`${c.label} · ${c.unit}`}>${c.label} · ${c.unit}</span>
|
|
286
|
-
<input type="range" aria-label=${c.label} min=${c.min} max=${c.max} step=${c.step || 'any'} .value=${String(c.value)} ?disabled=${moving}
|
|
287
|
-
@input=${(e: Event) => this.pose(c.id, (e.target as HTMLInputElement).valueAsNumber)}>
|
|
288
|
-
<output>${held ? '' : Math.round(c.value * 100) / 100}</output><span></span></div>`
|
|
289
|
-
})}
|
|
290
|
-
${!controls.length && !clips.length ? html`<p hint>${i18next.t('figure.text.detail-no-motion')}</p>` : nothing}
|
|
291
|
-
</section>
|
|
292
|
-
${free.length ? html`<section>${heading('clips')}${free.map(name => this.clipRow(name))}</section>` : nothing}
|
|
293
|
-
${groups.some(g => g.clips.some(c => clips.includes(c)))
|
|
294
|
-
? html`<section>
|
|
295
|
-
${heading('motion')}
|
|
296
|
-
${groups.map(g => html`<h4>${g.label}</h4>${g.clips.filter(c => clips.includes(c)).map(name => this.clipRow(name))}`)}
|
|
297
|
-
</section>`
|
|
298
|
-
: nothing}`
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/** A clip on its own row, played by the mark at its end. */
|
|
302
|
-
private clipRow(name: string) {
|
|
303
|
-
return html`<div slide clip><span title=${name}>${name}</span>${this.playButton(name)}</div>`
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/*
|
|
307
|
-
The connections the author declared (the modeller's 「연결」): for each, the data field, what it moves and how, then
|
|
308
|
-
where the data has it and of what kind -- an items list's fields by the part of an item each says. Under them, data
|
|
309
|
-
with every field, to copy (user 2026-11-05: what a board or a connector binds to, seen before placing the figure).
|
|
310
|
-
*/
|
|
311
|
-
private renderData(asset: FigureAsset) {
|
|
312
|
-
const connections = dataConnectionsOf(asset)
|
|
313
|
-
if (!connections.length) return html`<section><p hint>${i18next.t('figure.text.detail-no-data')}</p></section>`
|
|
314
|
-
const example = JSON.stringify(figureDataExample(asset.dataInterface!), null, 2)
|
|
315
|
-
const copyLabel = i18next.t(this.copied ? 'figure.button.board-data-copied' : 'figure.button.board-data-copy-example')
|
|
316
|
-
return html`<section>
|
|
317
|
-
<h3>${i18next.t('figure.label.data-bindings')}</h3>
|
|
318
|
-
${connections.map(c => {
|
|
319
|
-
const where = [
|
|
320
|
-
...(c.field !== c.accessor ? [c.accessor] : []),
|
|
321
|
-
...(c.node ? [kindWords(c.node)] : []),
|
|
322
|
-
...ITEM_FIELDS.flatMap(part => (c.itemFields?.[part] ? [`${itemFieldWords(part)} ${c.itemFields[part]}`] : []))
|
|
323
|
-
]
|
|
324
|
-
return html`<div connection>
|
|
325
|
-
<div><strong>${c.field}</strong> → ${moveWords(c.move)}<span method>${methodWords(c.method)}</span></div>
|
|
326
|
-
${where.length ? html`<div where>${where.join(' · ')}</div>` : nothing}
|
|
327
|
-
</div>`
|
|
328
|
-
})}
|
|
329
|
-
</section>
|
|
330
|
-
<section>
|
|
331
|
-
<h3>${i18next.t('figure.label.detail-example')}
|
|
332
|
-
<button icon copy aria-label=${copyLabel} title=${copyLabel} @click=${() => this.copyExample(example)}><md-icon>${this.copied ? 'check' : 'content_copy'}</md-icon></button></h3>
|
|
333
|
-
<pre example>${example}</pre>
|
|
334
|
-
</section>`
|
|
335
|
-
}
|
|
336
|
-
private async copyExample(text: string) {
|
|
337
|
-
try {
|
|
338
|
-
await navigator.clipboard.writeText(text)
|
|
339
|
-
this.copied = true
|
|
340
|
-
setTimeout(() => (this.copied = false), 1500)
|
|
341
|
-
} catch {
|
|
342
|
-
/* No clipboard here (an insecure page): the mark stays as it was. */
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* The view as it stands -- turned, zoomed and sized by the person -- as the card's picture, at the size and in the
|
|
348
|
-
* format the modeller's own picture uses (`thumbnail.ts`). Nothing is taken when the view cannot be drawn.
|
|
349
|
-
*/
|
|
350
|
-
private async takeShot() {
|
|
351
|
-
const layer = this.scene?.root
|
|
352
|
-
if (!this.keepShot || !layer?.snapshot3d) return
|
|
353
|
-
this.shot = 'saving'
|
|
354
|
-
try {
|
|
355
|
-
const url = await layer.snapshot3d(480, 360, 'image/webp', 0.85)
|
|
356
|
-
if (typeof url !== 'string' || !url.startsWith('data:')) throw Error('no picture')
|
|
357
|
-
await this.keepShot(url)
|
|
358
|
-
this.shot = 'saved'
|
|
359
|
-
setTimeout(() => this.shot === 'saved' && (this.shot = ''), 1500)
|
|
360
|
-
} catch {
|
|
361
|
-
this.shot = 'failed'
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
/** The whole figure in view: the board's fit, then the 3D camera's own (as the modeller canvas fits). */
|
|
365
|
-
fit() {
|
|
366
|
-
this.scene?.fit?.('ratio')
|
|
367
|
-
this.scene?.root?.fitCameraToModel?.()
|
|
368
|
-
}
|
|
369
|
-
/** Play or pause a clip, at the end of the line it moves. */
|
|
370
|
-
private playButton(clip: string) {
|
|
371
|
-
const on = this.playing === clip
|
|
372
|
-
/* A clip the figure's data never turns into cannot be chosen here; it says so instead of pressing to no effect. */
|
|
373
|
-
const unreachable = !!this.asset && clipPlayOf(this.asset, clip).kind === 'unreachable'
|
|
374
|
-
const title = unreachable ? i18next.t('figure.text.detail-clip-by-data', { clip }) : clip
|
|
375
|
-
return html`<button icon play aria-pressed=${String(on)} aria-label=${clip} title=${title} ?disabled=${unreachable} @click=${() => this.play(clip)}>
|
|
376
|
-
<md-icon>${on ? 'pause' : 'play_arrow'}</md-icon></button>`
|
|
377
|
-
}
|
|
378
|
-
private tell(key: string, value: unknown) {
|
|
379
|
-
this.scene?.root?.components?.[0]?.set(key, value)
|
|
380
|
-
}
|
|
381
|
-
private resize(axis: Axis, value: number) {
|
|
382
|
-
const used = this.asset ? sizeWithinRange(this.asset, axis, value) : undefined
|
|
383
|
-
if (used === undefined) { this.requestUpdate(); return }
|
|
384
|
-
this.sizes = { ...this.sizes, [axis]: used }
|
|
385
|
-
/*
|
|
386
|
-
The model grows about its own centre, which stays on the board's centre -- the origin of the ground grid. A
|
|
387
|
-
board instance is placed by its corner, so the corner moves with the size. The camera stays where the person
|
|
388
|
-
turned it: refitting on every step slid the grid under the model as if the axes had moved.
|
|
389
|
-
*/
|
|
390
|
-
/* The instance's box is the body at these sizes, not the sizes (bodyAtSize). */
|
|
391
|
-
const box = bodyAtSize(this.asset!, this.sizes) ?? this.sizes
|
|
392
|
-
this.scene?.root?.components?.[0]?.set({ width: box.x, depth: box.y, height: box.z })
|
|
393
|
-
this.centre()
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* The instance's box on the board's centre. The figure fits its box to the room it declares (its motion included),
|
|
397
|
-
* which can be wider than the size asked, so the box is read back rather than computed here.
|
|
398
|
-
*/
|
|
399
|
-
private centre() {
|
|
400
|
-
const instance = this.scene?.root?.components?.[0]
|
|
401
|
-
if (!instance?.model) return
|
|
402
|
-
const { width = 0, height = 0 } = instance.model
|
|
403
|
-
instance.set({ left: this.board.x / 2 - width / 2, top: this.board.z / 2 - height / 2 })
|
|
404
|
-
}
|
|
405
|
-
private pose(id: string, value: number) {
|
|
406
|
-
if (!Number.isFinite(value)) return
|
|
407
|
-
this.values = { ...this.values, [id]: value }
|
|
408
|
-
this.tell('parameters', this.values)
|
|
409
|
-
}
|
|
410
|
-
private play(name: string) {
|
|
411
|
-
this.playing = this.playing === name ? '' : name
|
|
412
|
-
if (this.playing && this.asset) {
|
|
413
|
-
this.played.add(name)
|
|
414
|
-
this.values = parametersForClip(this.asset, this.values, name)
|
|
415
|
-
this.tell('parameters', this.values)
|
|
416
|
-
}
|
|
417
|
-
if (!this.asset) return
|
|
418
|
-
/* A clip of a motion group is the group's to choose -- through the data when the data chooses it (detail-motion). */
|
|
419
|
-
const { clips, motion, figureValues } = playSettingsOf(this.asset, this.playing)
|
|
420
|
-
this.tell('clips', clips)
|
|
421
|
-
this.tell('motion', motion)
|
|
422
|
-
this.tell('figureValues', figureValues)
|
|
423
|
-
}
|
|
424
|
-
private reset() {
|
|
425
|
-
if (!this.asset) return
|
|
426
|
-
// A new instance also resets driver clocks. Clearing speeds alone freezes the last pose.
|
|
427
|
-
this.standUp()
|
|
428
|
-
}
|
|
429
|
-
private standUp() {
|
|
430
|
-
this.teardown()
|
|
431
|
-
this.error = ''
|
|
432
|
-
const asset = this.asset
|
|
433
|
-
if (!asset) return
|
|
434
|
-
this.values = {}
|
|
435
|
-
this.exposed = []
|
|
436
|
-
this.playing = ''
|
|
437
|
-
this.shot = ''
|
|
438
|
-
this.played.clear()
|
|
439
|
-
try {
|
|
440
|
-
compileFigureAsset(asset)
|
|
441
|
-
if (!asset.appearance.length) throw Error(i18next.t('figure.text.preview-needs-a-part'))
|
|
442
|
-
this.sizes = authoredSizeOf(asset)
|
|
443
|
-
const type = `figure-detail-${crypto.randomUUID()}`
|
|
444
|
-
registerFigure(type, asset)
|
|
445
|
-
this.registered = type
|
|
446
|
-
const size = bodyAtSize(asset, this.sizes) ?? this.sizes
|
|
447
|
-
const { board, components } = previewOneInstance(type, size)
|
|
448
|
-
this.board = { x: board.width, z: board.height }
|
|
449
|
-
this.scene = create({ target: this.stage, mode: 0, model: {
|
|
450
|
-
type: 'model-layer', width: board.width, height: board.height,
|
|
451
|
-
depth: previewBoardDepth({ placement: asset.placement, base: { y: size.y } }, DEFAULT_VIEW.ceilingHeight, 1),
|
|
452
|
-
threed: true, sky: 'color', ...sceneLook(DEFAULT_VIEW),
|
|
453
|
-
placement: DEFAULT_VIEW.placement, heights: { floor: 0, ceiling: DEFAULT_VIEW.ceilingHeight },
|
|
454
|
-
pixelRatio: Math.min(3, (window.devicePixelRatio || 1) * 2),
|
|
455
|
-
components
|
|
456
|
-
} }) as Scene
|
|
457
|
-
this.centre()
|
|
458
|
-
this.scene.resize?.()
|
|
459
|
-
this.fit()
|
|
460
|
-
this.exposed = this.scene.root?.components?.[0]?.nature?.properties ?? []
|
|
461
|
-
} catch (error) {
|
|
462
|
-
this.error = (error as Error).message
|
|
463
|
-
this.teardown()
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
private teardown() {
|
|
467
|
-
this.scene?.dispose?.()
|
|
468
|
-
this.scene = undefined
|
|
469
|
-
if (this.registered) unregisterFigure(this.registered)
|
|
470
|
-
this.registered = undefined
|
|
471
|
-
}
|
|
472
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import '@material/web/icon/icon.js'
|
|
2
|
-
import { css, html, LitElement, nothing } from 'lit'
|
|
3
|
-
import { customElement, property, state } from 'lit/decorators.js'
|
|
4
|
-
import { i18next, localize } from '@operato/i18n'
|
|
5
|
-
import type { FigureDataValue } from '@hatiolab/figure-model'
|
|
6
|
-
|
|
7
|
-
import { dataMoveOf } from './data-connection.js'
|
|
8
|
-
import { itemFieldWords, kindWords, moveWords } from './data-words.js'
|
|
9
|
-
import type { FigureDataReport } from './figure-data-report.js'
|
|
10
|
-
import { SidePanelStyles } from './side-panel-styles.js'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A figure's data as a person reads it (data binding design, decision 3): the shape as a tree, each value now and where
|
|
14
|
-
* it came from when there is one, what each field moves, a control the board's own state values hold, why data was
|
|
15
|
-
* refused, the fields the data has that the shape does not name, and an example to copy. The board's 「피규어 데이터」
|
|
16
|
-
* section shows a placed figure's; the preview's 「데이터」 tab shows a release's, with no data given, so each field
|
|
17
|
-
* says its kind (user 2026-11-05: what a board or a connector binds to, seen before placing it).
|
|
18
|
-
*/
|
|
19
|
-
@customElement('figure-data-list')
|
|
20
|
-
export class FigureDataList extends localize(i18next)(LitElement) {
|
|
21
|
-
/* The copy is the side panel's action under what it acts on (SidePanelStyles' button[act]), not a boxed button. */
|
|
22
|
-
static styles = [SidePanelStyles, css`
|
|
23
|
-
:host { display: grid; gap: 6px; }
|
|
24
|
-
ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
|
|
25
|
-
li { display: flex; flex-wrap: wrap; gap: 0 6px; align-items: baseline; }
|
|
26
|
-
li [meta] { margin-left: auto; color: var(--md-sys-color-on-surface-variant); text-align: right; }
|
|
27
|
-
[source] { padding: 0 4px; border-radius: 4px; background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface-variant); }
|
|
28
|
-
[moves], [hint] { width: 100%; color: var(--md-sys-color-on-surface-variant); }
|
|
29
|
-
p { margin: 0; }
|
|
30
|
-
[warn] { color: var(--md-sys-color-error); }
|
|
31
|
-
`]
|
|
32
|
-
|
|
33
|
-
@property({ attribute: false }) report?: FigureDataReport
|
|
34
|
-
@state() private copied = false
|
|
35
|
-
|
|
36
|
-
render() {
|
|
37
|
-
const report = this.report
|
|
38
|
-
if (!report) return nothing
|
|
39
|
-
return html`<ul>
|
|
40
|
-
${report.rows.map(row => this.renderRow(row))}
|
|
41
|
-
</ul>
|
|
42
|
-
${report.refused.length
|
|
43
|
-
? html`<p warn>
|
|
44
|
-
${report.refused.map(r =>
|
|
45
|
-
r.issues?.length
|
|
46
|
-
? r.issues.map(i => i18next.t('figure.text.board-data-value-' + i.reason, { path: i.path || '-' })).join(' · ')
|
|
47
|
-
: i18next.t('figure.text.board-data-refused', { reason: r.reason })
|
|
48
|
-
)}
|
|
49
|
-
</p>`
|
|
50
|
-
: nothing}
|
|
51
|
-
${report.unused.length ? html`<p hint>${i18next.t('figure.text.board-data-unused', { fields: report.unused.join(', ') })}</p>` : nothing}
|
|
52
|
-
<button act @click=${() => this.copy(report)}>
|
|
53
|
-
<md-icon>${this.copied ? 'check' : 'content_copy'}</md-icon>${i18next.t(this.copied ? 'figure.button.board-data-copied' : 'figure.button.board-data-copy-example')}
|
|
54
|
-
</button>`
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private renderRow(row: FigureDataReport['rows'][number]) {
|
|
58
|
-
const shown = (v: FigureDataValue) => (typeof v === 'boolean' ? i18next.t(v ? 'figure.label.board-data-true' : 'figure.label.board-data-false') : String(v))
|
|
59
|
-
return html`<li style="padding-left: ${row.depth * 12}px">
|
|
60
|
-
<span>${row.name}${row.label ? html` <small>${row.label}</small>` : nothing}</span>
|
|
61
|
-
<span meta>
|
|
62
|
-
${row.value !== undefined ? html`<b>${shown(row.value)}</b>` : row.count !== undefined ? html`<b>${i18next.t('figure.label.board-data-count', { count: row.count })}</b>` : nothing}
|
|
63
|
-
${row.source ? html`<span source>${i18next.t('figure.label.board-data-source-' + row.source)}</span>` : nothing}
|
|
64
|
-
${row.value === undefined && row.count === undefined ? kindWords(row.node) : nothing}
|
|
65
|
-
</span>
|
|
66
|
-
${row.itemField ? html`<span moves>${itemFieldWords(row.itemField)}</span>` : nothing}
|
|
67
|
-
${row.behaviors.length ? html`<span moves>→ ${row.behaviors.map(b => moveWords(dataMoveOf(this.report!.asset, b))).join(', ')}</span>` : nothing}
|
|
68
|
-
${row.heldByBoard.length ? html`<span warn moves>${i18next.t('figure.text.board-data-held', { controls: row.heldByBoard.join(', ') })}</span>` : nothing}
|
|
69
|
-
</li>`
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private async copy(report: FigureDataReport) {
|
|
73
|
-
try {
|
|
74
|
-
await navigator.clipboard.writeText(JSON.stringify(report.example, null, 2))
|
|
75
|
-
this.copied = true
|
|
76
|
-
setTimeout(() => (this.copied = false), 1500)
|
|
77
|
-
} catch {
|
|
78
|
-
/* No clipboard here (an insecure page): the button stays as it was. */
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
declare global {
|
|
84
|
-
interface HTMLElementTagNameMap {
|
|
85
|
-
'figure-data-list': FigureDataList
|
|
86
|
-
}
|
|
87
|
-
}
|