@things-factory/figure-viewer 10.1.163 → 10.1.165

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.
@@ -1,4 +1,4 @@
1
- import type { FigureAsset } from '@hatiolab/figure-model'
1
+ import { compileFigureDataInterface, type FigureAsset, type FigureDataValue } from '@hatiolab/figure-model'
2
2
 
3
3
  /** External values win over drivers; release only the controls owned by the chosen clip. */
4
4
  export function parametersForClip(asset: FigureAsset, values: Record<string, number>, clip: string) {
@@ -9,3 +9,49 @@ export function parametersForClip(asset: FigureAsset, values: Record<string, num
9
9
  export function clipForControl(asset: FigureAsset, id: string) {
10
10
  return asset.drivers?.find(d => d.state === id)?.clip
11
11
  }
12
+
13
+ /**
14
+ * How the detail view plays a clip (ADR-0051 §3.2, §8). A clip in no motion group plays at its own speed (the board's
15
+ * `clips`). A clip of a group is the group's selection (the board's `motion`); and when the figure's data chooses that
16
+ * group's clip, the data wins -- its default too -- so the clip is chosen through a data value the figure's own binding
17
+ * turns into it, given as a saved value (`figureValues`), the way a board would. A clip no data value turns into (a
18
+ * range, a scale, or only another value's fallback of an open field) cannot be chosen here.
19
+ */
20
+ export type ClipPlay =
21
+ | { kind: 'free' }
22
+ | { kind: 'group'; group: string }
23
+ | { kind: 'data'; group: string; accessor: string; value: FigureDataValue }
24
+ | { kind: 'unreachable'; group: string }
25
+
26
+ export function clipPlayOf(asset: FigureAsset, clip: string): ClipPlay {
27
+ const group = (asset.motionGroups ?? []).find(g => g.clips.includes(clip))
28
+ if (!group) return { kind: 'free' }
29
+ const plan = asset.dataInterface ? compileFigureDataInterface(asset) : null
30
+ const ready = plan?.bindings.find(r => r.binding.behavior.kind === 'motion-clip' && r.binding.behavior.group === group.id)
31
+ if (!ready) return { kind: 'group', group: group.id }
32
+ const { binding, node } = ready
33
+ const reached = (value: FigureDataValue): ClipPlay => ({ kind: 'data', group: group.id, accessor: binding.accessor, value })
34
+ const unreachable: ClipPlay = { kind: 'unreachable', group: group.id }
35
+ const closed = node.kind === 'boolean' ? ['false', 'true'] : node.kind === 'text' && node.values ? node.values : null
36
+ const typed = (key: string): FigureDataValue => (node.kind === 'boolean' ? key === 'true' : node.kind === 'number' ? Number(key) : key)
37
+ if (binding.rule === 'value') return node.kind === 'text' && (!closed || closed.includes(clip)) ? reached(clip) : unreachable
38
+ if (binding.rule !== 'map') return unreachable
39
+ const param = binding.param ?? {}
40
+ const key = Object.keys(param).find(k => k !== 'default' && param[k] === clip)
41
+ if (key !== undefined) return reached(typed(key))
42
+ /* Only the fallback turns into it: a value of a closed field the map does not name. */
43
+ const spare = param.default === clip ? closed?.find(v => !Object.hasOwn(param, v)) : undefined
44
+ return spare !== undefined ? reached(typed(spare)) : unreachable
45
+ }
46
+
47
+ /**
48
+ * What the board is told for the clip playing (none: ''): the free clips' speeds, the group's selection, and the saved
49
+ * data value that chooses it. Every key is written whole, so the clip played before is let go.
50
+ */
51
+ export function playSettingsOf(asset: FigureAsset, playing: string) {
52
+ const play = playing ? clipPlayOf(asset, playing) : null
53
+ const clips = Object.fromEntries([...new Set((asset.drivers ?? []).filter(d => !(asset.motionGroups ?? []).some(g => g.clips.includes(d.clip))).map(d => d.clip))].map(c => [c, c === playing ? 1 : 0]))
54
+ const motion = play && play.kind !== 'free' && play.kind !== 'unreachable' ? { [play.group]: { clip: playing, speed: 1, paused: false } } : {}
55
+ const figureValues = play?.kind === 'data' ? { [play.accessor]: play.value } : {}
56
+ return { clips, motion, figureValues }
57
+ }
@@ -2,15 +2,19 @@ import '@material/web/icon/icon.js'
2
2
  import { css, html, LitElement, nothing, type PropertyValues } from 'lit'
3
3
  import { customElement, property, query, state } from 'lit/decorators.js'
4
4
  import { i18next, localize } from '@operato/i18n'
5
+ import { SurfaceStyles } from '@things-factory/styles'
5
6
  import { compileFigureAsset, FIGURE_INSTANCE_SIZE_INPUTS, type FigureAsset } from '@hatiolab/figure-model'
6
7
  import { create, registerFigure, unregisterFigure } from '@hatiolab/things-scene'
7
8
  import { authoredSizeOf } from './preview-model.js'
8
9
  import { controlsOf } from './controls.js'
9
10
  import { DEFAULT_VIEW, previewBoardDepth, sceneLook } from './figure-view.js'
10
11
  import { SidePanelStyles } from './side-panel-styles.js'
11
- import { clipForControl, parametersForClip } from './detail-motion.js'
12
+ import { clipForControl, clipPlayOf, parametersForClip, playSettingsOf } from './detail-motion.js'
12
13
 
13
14
  type Axis = 'x' | 'y' | 'z'
15
+ /** What the view's tabs show under it: the figure's facts, its size, its motion. */
16
+ export type FigureViewerTab = 'info' | 'size' | 'motion'
17
+ export const FIGURE_VIEWER_TABS: readonly FigureViewerTab[] = ['info', 'size', 'motion']
14
18
  interface Scene {
15
19
  dispose?(): void
16
20
  resize?(): void
@@ -23,14 +27,27 @@ interface Scene {
23
27
  }
24
28
  }
25
29
 
26
- /** A single board instance. Sizes and poses are transient, and never change the asset or call a mutation. */
30
+ /**
31
+ * A single board instance. Sizes and poses are transient, and never change the asset or call a mutation.
32
+ *
33
+ * The canvas stands at the top and never scrolls away; under it, tabs show the facts, the size or the motion one at a
34
+ * time, and only that body scrolls (user 2026-10-15: the motion sat so far down that playing a clip scrolled the
35
+ * figure out of view). Given a bounded height, the element fills it; without one, it is as tall as what it shows.
36
+ * `tab` is the one shown; choosing another fires `tab-change` (detail `{ tab }`), so a screen showing two can keep them
37
+ * on the same tab.
38
+ */
27
39
  @customElement('figure-asset-viewer')
28
40
  export class FigureAssetViewer extends localize(i18next)(LitElement) {
29
- /* The modeller's side panel look (SidePanelStyles); only the viewport and the slider rows are this element's. */
30
- static styles = [SidePanelStyles, css`
31
- :host { display: block; min-width: 0; }
41
+ /*
42
+ The modeller's side panel look (SidePanelStyles) and the suite's tab strip (SurfaceStyles' .ui-tabs); only the
43
+ viewport, the tab body and the slider rows are this element's.
44
+ */
45
+ static styles = [SidePanelStyles, SurfaceStyles, css`
46
+ :host { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
32
47
  /* The card's own 4:3, so the picture taken is what is seen. */
33
- [viewport] { aspect-ratio: 4 / 3; position: relative; background: #858585; }
48
+ [viewport] { flex: none; aspect-ratio: 4 / 3; position: relative; background: #858585; }
49
+ nav.ui-tabs { flex: none; padding: 0 16px; }
50
+ [tab-body] { flex: 1; min-height: 0; overflow: auto; }
34
51
  [stage] { position: absolute; inset: 0; width: 100%; height: 100%; }
35
52
  /*
36
53
  The view's own marks in its corner, not buttons beside it: fit the whole figure in view (the modeller's fit, the
@@ -71,6 +88,8 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
71
88
  @property({ attribute: false }) asset?: FigureAsset
72
89
  /** Keeps a picture of the view as the figure's thumbnail. Without it there is no picture to take. */
73
90
  @property({ attribute: false }) keepShot?: (dataUrl: string) => Promise<unknown>
91
+ /** The tab shown under the view. */
92
+ @property({ reflect: true }) tab: FigureViewerTab = 'info'
74
93
  @query('[stage]') private stage!: HTMLElement
75
94
  @state() private shot: '' | 'saving' | 'saved' | 'failed' = ''
76
95
  @state() private sizes: Record<Axis, number> = { x: 1, y: 1, z: 1 }
@@ -128,8 +147,41 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
128
147
  </div>
129
148
  ${this.error ? html`<p error role="alert">${this.error}</p>` : nothing}
130
149
  ${this.shot === 'failed' ? html`<p error role="alert">${i18next.t('figure.text.detail-thumbnail-failed')}</p>` : nothing}
131
- <slot name="facts"></slot>
132
- ${asset ? html`<section>
150
+ ${this.renderTabs()}
151
+ <div tab-body role="tabpanel" aria-labelledby=${`tab-${this.tab}`}>
152
+ ${this.tab === 'info' ? html`<slot name="facts"></slot>` : nothing}
153
+ ${asset && this.tab === 'size' ? this.renderSize(asset) : nothing}
154
+ ${asset && this.tab === 'motion' ? this.renderMotion(asset, controls, clips) : nothing}
155
+ </div>`
156
+ }
157
+
158
+ /** The tab strip: the facts, the size, the motion. Arrow keys move along it, as the suite's tabs do. */
159
+ private renderTabs() {
160
+ return html`<nav class="ui-tabs" role="tablist" @keydown=${(e: KeyboardEvent) => this.stepTab(e)}>
161
+ ${FIGURE_VIEWER_TABS.map(tab => {
162
+ const on = this.tab === tab
163
+ return html`<button role="tab" id=${`tab-${tab}`} data-tab=${tab} ?data-selected=${on} aria-selected=${String(on)}
164
+ tabindex=${on ? 0 : -1} @click=${() => this.choose(tab)}>${i18next.t(`figure.label.detail-tab-${tab}`)}</button>`
165
+ })}
166
+ </nav>`
167
+ }
168
+ private choose(tab: FigureViewerTab) {
169
+ if (tab === this.tab) return
170
+ this.tab = tab
171
+ this.dispatchEvent(new CustomEvent('tab-change', { detail: { tab }, bubbles: true, composed: true }))
172
+ }
173
+ private stepTab(e: KeyboardEvent) {
174
+ const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0
175
+ if (!step) return
176
+ e.preventDefault()
177
+ const at = FIGURE_VIEWER_TABS.indexOf(this.tab)
178
+ const next = FIGURE_VIEWER_TABS[(at + step + FIGURE_VIEWER_TABS.length) % FIGURE_VIEWER_TABS.length]
179
+ this.choose(next)
180
+ this.updateComplete.then(() => this.renderRoot.querySelector<HTMLElement>(`button[data-tab="${next}"]`)?.focus())
181
+ }
182
+
183
+ private renderSize(asset: FigureAsset) {
184
+ return html`<section>
133
185
  <h3>${i18next.t('figure.label.detail-size')} · mm
134
186
  <button icon reset aria-label=${i18next.t('figure.button.detail-reset')} title=${i18next.t('figure.button.detail-reset')}
135
187
  @click=${() => this.reset()}><md-icon>restart_alt</md-icon></button></h3>
@@ -146,9 +198,11 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
146
198
  <span></span>
147
199
  </div>`
148
200
  })}
149
- <p hint>${i18next.t('figure.text.detail-transient')}</p>
150
- </section>
151
- <section><h3>${i18next.t('figure.label.motion')}</h3>
201
+ </section>`
202
+ }
203
+
204
+ private renderMotion(asset: FigureAsset, controls: ReturnType<typeof controlsOf>, clips: string[]) {
205
+ return html`<section>
152
206
  ${controls.map(c => {
153
207
  const clip = clipForControl(asset, c.id)
154
208
  const on = !!clip && this.playing === clip
@@ -164,7 +218,7 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
164
218
  <span title=${name}>${name}</span><span></span>
165
219
  <output>${this.playing === name ? i18next.t('figure.text.detail-playing') : ''}</output>${this.playButton(name)}</div>`)}
166
220
  ${!controls.length && !clips.length ? html`<p hint>${i18next.t('figure.text.detail-no-motion')}</p>` : nothing}
167
- </section>` : nothing}`
221
+ </section>`
168
222
  }
169
223
 
170
224
  /**
@@ -193,7 +247,10 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
193
247
  /** Play or pause a clip, at the end of the line it moves. */
194
248
  private playButton(clip: string) {
195
249
  const on = this.playing === clip
196
- return html`<button icon play aria-pressed=${String(on)} aria-label=${clip} title=${clip} @click=${() => this.play(clip)}>
250
+ /* A clip the figure's data never turns into cannot be chosen here; it says so instead of pressing to no effect. */
251
+ const unreachable = !!this.asset && clipPlayOf(this.asset, clip).kind === 'unreachable'
252
+ const title = unreachable ? i18next.t('figure.text.detail-clip-by-data', { clip }) : clip
253
+ return html`<button icon play aria-pressed=${String(on)} aria-label=${clip} title=${title} ?disabled=${unreachable} @click=${() => this.play(clip)}>
197
254
  <md-icon>${on ? 'pause' : 'play_arrow'}</md-icon></button>`
198
255
  }
199
256
  private tell(key: string, value: unknown) {
@@ -234,7 +291,12 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
234
291
  this.values = parametersForClip(this.asset, this.values, name)
235
292
  this.tell('parameters', this.values)
236
293
  }
237
- this.tell('clips', Object.fromEntries([...new Set((this.asset?.drivers ?? []).map(d => d.clip))].map(key => [key, key === this.playing ? 1 : 0])))
294
+ if (!this.asset) return
295
+ /* A clip of a motion group is the group's to choose -- through the data when the data chooses it (detail-motion). */
296
+ const { clips, motion, figureValues } = playSettingsOf(this.asset, this.playing)
297
+ this.tell('clips', clips)
298
+ this.tell('motion', motion)
299
+ this.tell('figureValues', figureValues)
238
300
  }
239
301
  private reset() {
240
302
  if (!this.asset) return
@@ -1,6 +1,47 @@
1
- import type { FigureAsset } from '@hatiolab/figure-model';
1
+ import { type FigureAsset, type FigureDataValue } from '@hatiolab/figure-model';
2
2
  /** External values win over drivers; release only the controls owned by the chosen clip. */
3
3
  export declare function parametersForClip(asset: FigureAsset, values: Record<string, number>, clip: string): {
4
4
  [k: string]: number;
5
5
  };
6
6
  export declare function clipForControl(asset: FigureAsset, id: string): string | undefined;
7
+ /**
8
+ * How the detail view plays a clip (ADR-0051 §3.2, §8). A clip in no motion group plays at its own speed (the board's
9
+ * `clips`). A clip of a group is the group's selection (the board's `motion`); and when the figure's data chooses that
10
+ * group's clip, the data wins -- its default too -- so the clip is chosen through a data value the figure's own binding
11
+ * turns into it, given as a saved value (`figureValues`), the way a board would. A clip no data value turns into (a
12
+ * range, a scale, or only another value's fallback of an open field) cannot be chosen here.
13
+ */
14
+ export type ClipPlay = {
15
+ kind: 'free';
16
+ } | {
17
+ kind: 'group';
18
+ group: string;
19
+ } | {
20
+ kind: 'data';
21
+ group: string;
22
+ accessor: string;
23
+ value: FigureDataValue;
24
+ } | {
25
+ kind: 'unreachable';
26
+ group: string;
27
+ };
28
+ export declare function clipPlayOf(asset: FigureAsset, clip: string): ClipPlay;
29
+ /**
30
+ * What the board is told for the clip playing (none: ''): the free clips' speeds, the group's selection, and the saved
31
+ * data value that chooses it. Every key is written whole, so the clip played before is let go.
32
+ */
33
+ export declare function playSettingsOf(asset: FigureAsset, playing: string): {
34
+ clips: {
35
+ [k: string]: number;
36
+ };
37
+ motion: {
38
+ [x: string]: {
39
+ clip: string;
40
+ speed: number;
41
+ paused: boolean;
42
+ };
43
+ };
44
+ figureValues: {
45
+ [x: string]: FigureDataValue;
46
+ };
47
+ };
@@ -1,3 +1,4 @@
1
+ import { compileFigureDataInterface } from '@hatiolab/figure-model';
1
2
  /** External values win over drivers; release only the controls owned by the chosen clip. */
2
3
  export function parametersForClip(asset, values, clip) {
3
4
  const driven = new Set((asset.drivers ?? []).filter(d => d.clip === clip).map(d => d.state));
@@ -6,4 +7,40 @@ export function parametersForClip(asset, values, clip) {
6
7
  export function clipForControl(asset, id) {
7
8
  return asset.drivers?.find(d => d.state === id)?.clip;
8
9
  }
10
+ export function clipPlayOf(asset, clip) {
11
+ const group = (asset.motionGroups ?? []).find(g => g.clips.includes(clip));
12
+ if (!group)
13
+ return { kind: 'free' };
14
+ const plan = asset.dataInterface ? compileFigureDataInterface(asset) : null;
15
+ const ready = plan?.bindings.find(r => r.binding.behavior.kind === 'motion-clip' && r.binding.behavior.group === group.id);
16
+ if (!ready)
17
+ return { kind: 'group', group: group.id };
18
+ const { binding, node } = ready;
19
+ const reached = (value) => ({ kind: 'data', group: group.id, accessor: binding.accessor, value });
20
+ const unreachable = { kind: 'unreachable', group: group.id };
21
+ const closed = node.kind === 'boolean' ? ['false', 'true'] : node.kind === 'text' && node.values ? node.values : null;
22
+ const typed = (key) => (node.kind === 'boolean' ? key === 'true' : node.kind === 'number' ? Number(key) : key);
23
+ if (binding.rule === 'value')
24
+ return node.kind === 'text' && (!closed || closed.includes(clip)) ? reached(clip) : unreachable;
25
+ if (binding.rule !== 'map')
26
+ return unreachable;
27
+ const param = binding.param ?? {};
28
+ const key = Object.keys(param).find(k => k !== 'default' && param[k] === clip);
29
+ if (key !== undefined)
30
+ return reached(typed(key));
31
+ /* Only the fallback turns into it: a value of a closed field the map does not name. */
32
+ const spare = param.default === clip ? closed?.find(v => !Object.hasOwn(param, v)) : undefined;
33
+ return spare !== undefined ? reached(typed(spare)) : unreachable;
34
+ }
35
+ /**
36
+ * What the board is told for the clip playing (none: ''): the free clips' speeds, the group's selection, and the saved
37
+ * data value that chooses it. Every key is written whole, so the clip played before is let go.
38
+ */
39
+ export function playSettingsOf(asset, playing) {
40
+ const play = playing ? clipPlayOf(asset, playing) : null;
41
+ const clips = Object.fromEntries([...new Set((asset.drivers ?? []).filter(d => !(asset.motionGroups ?? []).some(g => g.clips.includes(d.clip))).map(d => d.clip))].map(c => [c, c === playing ? 1 : 0]));
42
+ const motion = play && play.kind !== 'free' && play.kind !== 'unreachable' ? { [play.group]: { clip: playing, speed: 1, paused: false } } : {};
43
+ const figureValues = play?.kind === 'data' ? { [play.accessor]: play.value } : {};
44
+ return { clips, motion, figureValues };
45
+ }
9
46
  //# sourceMappingURL=detail-motion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"detail-motion.js","sourceRoot":"","sources":["../client/detail-motion.ts"],"names":[],"mappings":"AAEA,4FAA4F;AAC5F,MAAM,UAAU,iBAAiB,CAAC,KAAkB,EAAE,MAA8B,EAAE,IAAY;IAChG,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;IAC5F,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AACrF,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAkB,EAAE,EAAU;IAC3D,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,EAAE,IAAI,CAAA;AACvD,CAAC","sourcesContent":["import type { FigureAsset } from '@hatiolab/figure-model'\n\n/** External values win over drivers; release only the controls owned by the chosen clip. */\nexport function parametersForClip(asset: FigureAsset, values: Record<string, number>, clip: string) {\n const driven = new Set((asset.drivers ?? []).filter(d => d.clip === clip).map(d => d.state))\n return Object.fromEntries(Object.entries(values).filter(([id]) => !driven.has(id)))\n}\n\nexport function clipForControl(asset: FigureAsset, id: string) {\n return asset.drivers?.find(d => d.state === id)?.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AC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACxM,MAAM,MAAM,GAAG,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC9I,MAAM,YAAY,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACjF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,CAAA;AACxC,CAAC","sourcesContent":["import { compileFigureDataInterface, type FigureAsset, type FigureDataValue } from '@hatiolab/figure-model'\n\n/** External values win over drivers; release only the controls owned by the chosen clip. */\nexport function parametersForClip(asset: FigureAsset, values: Record<string, number>, clip: string) {\n const driven = new Set((asset.drivers ?? []).filter(d => d.clip === clip).map(d => d.state))\n return Object.fromEntries(Object.entries(values).filter(([id]) => !driven.has(id)))\n}\n\nexport function clipForControl(asset: FigureAsset, id: string) {\n return asset.drivers?.find(d => d.state === id)?.clip\n}\n\n/**\n * How the detail view plays a clip (ADR-0051 §3.2, §8). A clip in no motion group plays at its own speed (the board's\n * `clips`). A clip of a group is the group's selection (the board's `motion`); and when the figure's data chooses that\n * group's clip, the data wins -- its default too -- so the clip is chosen through a data value the figure's own binding\n * turns into it, given as a saved value (`figureValues`), the way a board would. A clip no data value turns into (a\n * range, a scale, or only another value's fallback of an open field) cannot be chosen here.\n */\nexport type ClipPlay =\n | { kind: 'free' }\n | { kind: 'group'; group: string }\n | { kind: 'data'; group: string; accessor: string; value: FigureDataValue }\n | { kind: 'unreachable'; group: string }\n\nexport function clipPlayOf(asset: FigureAsset, clip: string): ClipPlay {\n const group = (asset.motionGroups ?? []).find(g => g.clips.includes(clip))\n if (!group) return { kind: 'free' }\n const plan = asset.dataInterface ? compileFigureDataInterface(asset) : null\n const ready = plan?.bindings.find(r => r.binding.behavior.kind === 'motion-clip' && r.binding.behavior.group === group.id)\n if (!ready) return { kind: 'group', group: group.id }\n const { binding, node } = ready\n const reached = (value: FigureDataValue): ClipPlay => ({ kind: 'data', group: group.id, accessor: binding.accessor, value })\n const unreachable: ClipPlay = { kind: 'unreachable', group: group.id }\n const closed = node.kind === 'boolean' ? ['false', 'true'] : node.kind === 'text' && node.values ? node.values : null\n const typed = (key: string): FigureDataValue => (node.kind === 'boolean' ? key === 'true' : node.kind === 'number' ? Number(key) : key)\n if (binding.rule === 'value') return node.kind === 'text' && (!closed || closed.includes(clip)) ? reached(clip) : unreachable\n if (binding.rule !== 'map') return unreachable\n const param = binding.param ?? {}\n const key = Object.keys(param).find(k => k !== 'default' && param[k] === clip)\n if (key !== undefined) return reached(typed(key))\n /* Only the fallback turns into it: a value of a closed field the map does not name. */\n const spare = param.default === clip ? closed?.find(v => !Object.hasOwn(param, v)) : undefined\n return spare !== undefined ? reached(typed(spare)) : unreachable\n}\n\n/**\n * What the board is told for the clip playing (none: ''): the free clips' speeds, the group's selection, and the saved\n * data value that chooses it. Every key is written whole, so the clip played before is let go.\n */\nexport function playSettingsOf(asset: FigureAsset, playing: string) {\n const play = playing ? clipPlayOf(asset, playing) : null\n const clips = Object.fromEntries([...new Set((asset.drivers ?? []).filter(d => !(asset.motionGroups ?? []).some(g => g.clips.includes(d.clip))).map(d => d.clip))].map(c => [c, c === playing ? 1 : 0]))\n const motion = play && play.kind !== 'free' && play.kind !== 'unreachable' ? { [play.group]: { clip: playing, speed: 1, paused: false } } : {}\n const figureValues = play?.kind === 'data' ? { [play.accessor]: play.value } : {}\n return { clips, motion, figureValues }\n}\n"]}
@@ -1,13 +1,26 @@
1
1
  import '@material/web/icon/icon.js';
2
2
  import { LitElement, type PropertyValues } from 'lit';
3
3
  import { type FigureAsset } from '@hatiolab/figure-model';
4
+ /** What the view's tabs show under it: the figure's facts, its size, its motion. */
5
+ export type FigureViewerTab = 'info' | 'size' | 'motion';
6
+ export declare const FIGURE_VIEWER_TABS: readonly FigureViewerTab[];
4
7
  declare const FigureAssetViewer_base: (new (...args: any[]) => LitElement) & typeof LitElement;
5
- /** A single board instance. Sizes and poses are transient, and never change the asset or call a mutation. */
8
+ /**
9
+ * A single board instance. Sizes and poses are transient, and never change the asset or call a mutation.
10
+ *
11
+ * The canvas stands at the top and never scrolls away; under it, tabs show the facts, the size or the motion one at a
12
+ * time, and only that body scrolls (user 2026-10-15: the motion sat so far down that playing a clip scrolled the
13
+ * figure out of view). Given a bounded height, the element fills it; without one, it is as tall as what it shows.
14
+ * `tab` is the one shown; choosing another fires `tab-change` (detail `{ tab }`), so a screen showing two can keep them
15
+ * on the same tab.
16
+ */
6
17
  export declare class FigureAssetViewer extends FigureAssetViewer_base {
7
18
  static styles: import("lit").CSSResult[];
8
19
  asset?: FigureAsset;
9
20
  /** Keeps a picture of the view as the figure's thumbnail. Without it there is no picture to take. */
10
21
  keepShot?: (dataUrl: string) => Promise<unknown>;
22
+ /** The tab shown under the view. */
23
+ tab: FigureViewerTab;
11
24
  private stage;
12
25
  private shot;
13
26
  private sizes;
@@ -26,6 +39,12 @@ export declare class FigureAssetViewer extends FigureAssetViewer_base {
26
39
  firstUpdated(): void;
27
40
  disconnectedCallback(): void;
28
41
  render(): import("lit-html").TemplateResult<1>;
42
+ /** The tab strip: the facts, the size, the motion. Arrow keys move along it, as the suite's tabs do. */
43
+ private renderTabs;
44
+ private choose;
45
+ private stepTab;
46
+ private renderSize;
47
+ private renderMotion;
29
48
  /**
30
49
  * The view as it stands -- turned, zoomed and sized by the person -- as the card's picture, at the size and in the
31
50
  * format the modeller's own picture uses (`thumbnail.ts`). Nothing is taken when the view cannot be drawn.
@@ -3,17 +3,29 @@ import '@material/web/icon/icon.js';
3
3
  import { css, html, LitElement, nothing } from 'lit';
4
4
  import { customElement, property, query, state } from 'lit/decorators.js';
5
5
  import { i18next, localize } from '@operato/i18n';
6
+ import { SurfaceStyles } from '@things-factory/styles';
6
7
  import { compileFigureAsset, FIGURE_INSTANCE_SIZE_INPUTS } from '@hatiolab/figure-model';
7
8
  import { create, registerFigure, unregisterFigure } from '@hatiolab/things-scene';
8
9
  import { authoredSizeOf } from './preview-model.js';
9
10
  import { controlsOf } from './controls.js';
10
11
  import { DEFAULT_VIEW, previewBoardDepth, sceneLook } from './figure-view.js';
11
12
  import { SidePanelStyles } from './side-panel-styles.js';
12
- import { clipForControl, parametersForClip } from './detail-motion.js';
13
- /** A single board instance. Sizes and poses are transient, and never change the asset or call a mutation. */
13
+ import { clipForControl, clipPlayOf, parametersForClip, playSettingsOf } from './detail-motion.js';
14
+ export const FIGURE_VIEWER_TABS = ['info', 'size', 'motion'];
15
+ /**
16
+ * A single board instance. Sizes and poses are transient, and never change the asset or call a mutation.
17
+ *
18
+ * The canvas stands at the top and never scrolls away; under it, tabs show the facts, the size or the motion one at a
19
+ * time, and only that body scrolls (user 2026-10-15: the motion sat so far down that playing a clip scrolled the
20
+ * figure out of view). Given a bounded height, the element fills it; without one, it is as tall as what it shows.
21
+ * `tab` is the one shown; choosing another fires `tab-change` (detail `{ tab }`), so a screen showing two can keep them
22
+ * on the same tab.
23
+ */
14
24
  let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitElement) {
15
25
  constructor() {
16
26
  super(...arguments);
27
+ /** The tab shown under the view. */
28
+ this.tab = 'info';
17
29
  this.shot = '';
18
30
  this.sizes = { x: 1, y: 1, z: 1 };
19
31
  this.values = {};
@@ -24,11 +36,16 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
24
36
  /** The board the instance stands on, set when the scene is built; its centre is the grid's origin. */
25
37
  this.board = { x: 0, z: 0 };
26
38
  }
27
- /* The modeller's side panel look (SidePanelStyles); only the viewport and the slider rows are this element's. */
28
- static { this.styles = [SidePanelStyles, css `
29
- :host { display: block; min-width: 0; }
39
+ /*
40
+ The modeller's side panel look (SidePanelStyles) and the suite's tab strip (SurfaceStyles' .ui-tabs); only the
41
+ viewport, the tab body and the slider rows are this element's.
42
+ */
43
+ static { this.styles = [SidePanelStyles, SurfaceStyles, css `
44
+ :host { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
30
45
  /* The card's own 4:3, so the picture taken is what is seen. */
31
- [viewport] { aspect-ratio: 4 / 3; position: relative; background: #858585; }
46
+ [viewport] { flex: none; aspect-ratio: 4 / 3; position: relative; background: #858585; }
47
+ nav.ui-tabs { flex: none; padding: 0 16px; }
48
+ [tab-body] { flex: 1; min-height: 0; overflow: auto; }
32
49
  [stage] { position: absolute; inset: 0; width: 100%; height: 100%; }
33
50
  /*
34
51
  The view's own marks in its corner, not buttons beside it: fit the whole figure in view (the modeller's fit, the
@@ -108,8 +125,41 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
108
125
  </div>
109
126
  ${this.error ? html `<p error role="alert">${this.error}</p>` : nothing}
110
127
  ${this.shot === 'failed' ? html `<p error role="alert">${i18next.t('figure.text.detail-thumbnail-failed')}</p>` : nothing}
111
- <slot name="facts"></slot>
112
- ${asset ? html `<section>
128
+ ${this.renderTabs()}
129
+ <div tab-body role="tabpanel" aria-labelledby=${`tab-${this.tab}`}>
130
+ ${this.tab === 'info' ? html `<slot name="facts"></slot>` : nothing}
131
+ ${asset && this.tab === 'size' ? this.renderSize(asset) : nothing}
132
+ ${asset && this.tab === 'motion' ? this.renderMotion(asset, controls, clips) : nothing}
133
+ </div>`;
134
+ }
135
+ /** The tab strip: the facts, the size, the motion. Arrow keys move along it, as the suite's tabs do. */
136
+ renderTabs() {
137
+ return html `<nav class="ui-tabs" role="tablist" @keydown=${(e) => this.stepTab(e)}>
138
+ ${FIGURE_VIEWER_TABS.map(tab => {
139
+ const on = this.tab === tab;
140
+ return html `<button role="tab" id=${`tab-${tab}`} data-tab=${tab} ?data-selected=${on} aria-selected=${String(on)}
141
+ tabindex=${on ? 0 : -1} @click=${() => this.choose(tab)}>${i18next.t(`figure.label.detail-tab-${tab}`)}</button>`;
142
+ })}
143
+ </nav>`;
144
+ }
145
+ choose(tab) {
146
+ if (tab === this.tab)
147
+ return;
148
+ this.tab = tab;
149
+ this.dispatchEvent(new CustomEvent('tab-change', { detail: { tab }, bubbles: true, composed: true }));
150
+ }
151
+ stepTab(e) {
152
+ const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;
153
+ if (!step)
154
+ return;
155
+ e.preventDefault();
156
+ const at = FIGURE_VIEWER_TABS.indexOf(this.tab);
157
+ const next = FIGURE_VIEWER_TABS[(at + step + FIGURE_VIEWER_TABS.length) % FIGURE_VIEWER_TABS.length];
158
+ this.choose(next);
159
+ this.updateComplete.then(() => this.renderRoot.querySelector(`button[data-tab="${next}"]`)?.focus());
160
+ }
161
+ renderSize(asset) {
162
+ return html `<section>
113
163
  <h3>${i18next.t('figure.label.detail-size')} · mm
114
164
  <button icon reset aria-label=${i18next.t('figure.button.detail-reset')} title=${i18next.t('figure.button.detail-reset')}
115
165
  @click=${() => this.reset()}><md-icon>restart_alt</md-icon></button></h3>
@@ -126,9 +176,10 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
126
176
  <span></span>
127
177
  </div>`;
128
178
  })}
129
- <p hint>${i18next.t('figure.text.detail-transient')}</p>
130
- </section>
131
- <section><h3>${i18next.t('figure.label.motion')}</h3>
179
+ </section>`;
180
+ }
181
+ renderMotion(asset, controls, clips) {
182
+ return html `<section>
132
183
  ${controls.map(c => {
133
184
  const clip = clipForControl(asset, c.id);
134
185
  const on = !!clip && this.playing === clip;
@@ -144,7 +195,7 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
144
195
  <span title=${name}>${name}</span><span></span>
145
196
  <output>${this.playing === name ? i18next.t('figure.text.detail-playing') : ''}</output>${this.playButton(name)}</div>`)}
146
197
  ${!controls.length && !clips.length ? html `<p hint>${i18next.t('figure.text.detail-no-motion')}</p>` : nothing}
147
- </section>` : nothing}`;
198
+ </section>`;
148
199
  }
149
200
  /**
150
201
  * The view as it stands -- turned, zoomed and sized by the person -- as the card's picture, at the size and in the
@@ -175,7 +226,10 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
175
226
  /** Play or pause a clip, at the end of the line it moves. */
176
227
  playButton(clip) {
177
228
  const on = this.playing === clip;
178
- return html `<button icon play aria-pressed=${String(on)} aria-label=${clip} title=${clip} @click=${() => this.play(clip)}>
229
+ /* A clip the figure's data never turns into cannot be chosen here; it says so instead of pressing to no effect. */
230
+ const unreachable = !!this.asset && clipPlayOf(this.asset, clip).kind === 'unreachable';
231
+ const title = unreachable ? i18next.t('figure.text.detail-clip-by-data', { clip }) : clip;
232
+ return html `<button icon play aria-pressed=${String(on)} aria-label=${clip} title=${title} ?disabled=${unreachable} @click=${() => this.play(clip)}>
179
233
  <md-icon>${on ? 'pause' : 'play_arrow'}</md-icon></button>`;
180
234
  }
181
235
  tell(key, value) {
@@ -221,7 +275,13 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
221
275
  this.values = parametersForClip(this.asset, this.values, name);
222
276
  this.tell('parameters', this.values);
223
277
  }
224
- this.tell('clips', Object.fromEntries([...new Set((this.asset?.drivers ?? []).map(d => d.clip))].map(key => [key, key === this.playing ? 1 : 0])));
278
+ if (!this.asset)
279
+ return;
280
+ /* A clip of a motion group is the group's to choose -- through the data when the data chooses it (detail-motion). */
281
+ const { clips, motion, figureValues } = playSettingsOf(this.asset, this.playing);
282
+ this.tell('clips', clips);
283
+ this.tell('motion', motion);
284
+ this.tell('figureValues', figureValues);
225
285
  }
226
286
  reset() {
227
287
  if (!this.asset)
@@ -282,6 +342,10 @@ __decorate([
282
342
  property({ attribute: false }),
283
343
  __metadata("design:type", Function)
284
344
  ], FigureAssetViewer.prototype, "keepShot", void 0);
345
+ __decorate([
346
+ property({ reflect: true }),
347
+ __metadata("design:type", String)
348
+ ], FigureAssetViewer.prototype, "tab", void 0);
285
349
  __decorate([
286
350
  query('[stage]'),
287
351
  __metadata("design:type", HTMLElement)