@things-factory/figure-viewer 10.1.291 → 10.1.303

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.
@@ -8,10 +8,10 @@ import { SurfaceStyles } from '@things-factory/styles';
8
8
  import { compileFigureAsset, figureDataExample } from '@hatiolab/figure-model';
9
9
  import { create, registerFigure, unregisterFigure } from '@hatiolab/things-scene';
10
10
  import { authoredSizeOf, bodyAtSize, previewOneInstance, sizeSpanOf, sizeWithinRange } from './preview-model.js';
11
- import { controlsOf } from './controls.js';
12
11
  import { DEFAULT_VIEW, previewBoardDepth, sceneLook } from './figure-view.js';
13
12
  import { SidePanelStyles } from './side-panel-styles.js';
14
- import { clipPlayOf, clipsDriving, parametersForClip, playSettingsOf } from './detail-motion.js';
13
+ import './figure-motion-controls.js';
14
+ import { followTravelFloor, PREVIEW_CLIP_TRAVEL } from './travel-floor.js';
15
15
  import { dataConnectionsOf, ITEM_FIELDS } from './data-connection.js';
16
16
  import { itemFieldWords, kindWords, methodWords, moveWords } from './data-words.js';
17
17
  export const FIGURE_VIEWER_TABS = ['info', 'size', 'motion', 'data'];
@@ -20,6 +20,7 @@ export const FIGURE_VIEWER_TABS = ['info', 'size', 'motion', 'data'];
20
20
  data's are the data tab's own, from the connections.
21
21
  */
22
22
  const DESIGN_KEYS = ['designInputs', 'slotLayout'];
23
+ const MOTION_KEYS = ['figureValues', 'motion', 'clips', 'parameters'];
23
24
  /**
24
25
  * A single board instance. Sizes and poses are transient, and never change the asset or call a mutation.
25
26
  *
@@ -36,12 +37,9 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
36
37
  this.tab = 'info';
37
38
  this.shot = '';
38
39
  this.sizes = { x: 1, y: 1, z: 1 };
39
- this.values = {};
40
- this.playing = '';
41
40
  this.error = '';
42
41
  this.copied = false;
43
42
  this.needsScene = false;
44
- this.played = new Set();
45
43
  /** The board component's properties, read from the instance standing here as the board's panel reads them. */
46
44
  this.exposed = [];
47
45
  /** The board the instance stands on, set when the scene is built; its centre is the grid's origin. */
@@ -89,7 +87,6 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
89
87
  */
90
88
  div[slide] { display: grid; grid-template-columns: 120px minmax(64px, 1fr) 52px 22px; align-items: center; gap: 8px; min-height: 22px; }
91
89
  div[slide] > span { color: var(--md-sys-color-on-surface-variant); overflow-wrap: anywhere; line-height: 1.3; }
92
- div[slide][clip] > span { grid-column: 1 / 4; }
93
90
  div[slide] input[type='number'] { min-height: 0; height: 20px; padding: 0 2px; border: none; border-bottom: 1px solid transparent; border-radius: 0;
94
91
  background: none; text-align: right; font-family: var(--ui-mono, ui-monospace, monospace); -moz-appearance: textfield; }
95
92
  div[slide] input[type='number']::-webkit-inner-spin-button, div[slide] input[type='number']::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
@@ -101,8 +98,12 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
101
98
  background: transparent; color: var(--md-sys-color-on-surface-variant); cursor: pointer; }
102
99
  button[icon]:hover { background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface); }
103
100
  button[icon] md-icon { --md-icon-size: 16px; }
104
- button[icon][aria-pressed='true'] { color: var(--md-sys-color-primary); }
105
101
  p[hint] { margin: 0; }
102
+ section[hidden] { display: none; }
103
+ /* The board's keys for what moves the figure, on one line over its controls. */
104
+ div[keys] { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-bottom: 6px; font-weight: 600; }
105
+ /* The shared motion controls in the panel's colour, their slider as wide as the panel lets it. */
106
+ figure-motion-controls { --figure-motion-slider: minmax(64px, 1fr); color: var(--md-sys-color-on-surface); }
106
107
  /* A connection: its field, what it moves and how on one line; under it, where the data has it and of what kind. */
107
108
  div[connection] { display: grid; gap: 1px; padding: 3px 0; }
108
109
  div[connection] [method] { color: var(--md-sys-color-on-surface-variant); margin-left: 6px; }
@@ -136,8 +137,6 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
136
137
  }
137
138
  render() {
138
139
  const asset = this.asset;
139
- const clips = asset ? [...new Set((asset.drivers ?? []).map(d => d.clip))] : [];
140
- const controls = asset ? controlsOf(asset, this.values) : [];
141
140
  const shotLabel = this.shot === 'saved' ? i18next.t('figure.text.detail-thumbnail-saved') : i18next.t('figure.button.detail-save-thumbnail');
142
141
  const fitLabel = i18next.t('button.fit-view');
143
142
  return html `<div viewport><div stage></div>
@@ -157,8 +156,8 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
157
156
  <div tab-body role="tabpanel" aria-labelledby=${`tab-${this.tab}`}>
158
157
  ${this.tab === 'info' ? html `<slot name="facts"></slot>` : nothing}
159
158
  ${asset && this.tab === 'size' ? this.renderSize(asset) : nothing}
160
- ${asset && this.tab === 'motion' ? this.renderMotion(asset, controls, clips) : nothing}
161
159
  ${asset && this.tab === 'data' ? this.renderData(asset) : nothing}
160
+ ${asset ? this.renderMotion(asset) : nothing}
162
161
  </div>`;
163
162
  }
164
163
  /** The tab strip: the facts, the size, the motion, the data. Arrow keys move along it, as the suite's tabs do. */
@@ -226,43 +225,17 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
226
225
  </section>`;
227
226
  }
228
227
  /*
229
- The inputs, then the clips. A clip can move many inputs -- the robot dog's walk moves all eight leg joints -- so it
230
- 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
231
- clip playing moves cannot be dragged; one a clip played and let go of stands where the clip left it, so its number
232
- is not shown until it is dragged.
228
+ How the figure moves, the same controls as the modeller's preview (figure-motion-controls): the data's states, then
229
+ the clips, then the joints (the user, 2026-11-21: 「상태, 애니메이션과 관절 순서를 모델러의 미리보기와 같이」). Over them,
230
+ the board's word and key for each that a board sets and binds (user 2026-11-05).
233
231
  */
234
- renderMotion(asset, controls, clips) {
235
- /* Each part under the board's word for it and the key a board sets and binds (user 2026-11-05). */
236
- const heading = (name) => {
237
- const p = this.exposed.find(x => x.name === name);
238
- return p ? html `<h3>${this.boardName(p)}</h3>` : nothing;
239
- };
240
- const groups = asset.motionGroups ?? [];
241
- const free = clips.filter(clip => !groups.some(g => g.clips.includes(clip)));
242
- return html `<section>
243
- ${controls.length ? heading('parameters') : nothing}
244
- ${controls.map(c => {
245
- const driving = clipsDriving(asset, c.id);
246
- const moving = driving.includes(this.playing);
247
- const held = moving || (driving.some(clip => this.played.has(clip)) && !(c.id in this.values));
248
- return html `<div slide><span title=${`${c.label} · ${c.unit}`}>${c.label} · ${c.unit}</span>
249
- <input type="range" aria-label=${c.label} min=${c.min} max=${c.max} step=${c.step || 'any'} .value=${String(c.value)} ?disabled=${moving}
250
- @input=${(e) => this.pose(c.id, e.target.valueAsNumber)}>
251
- <output>${held ? '' : Math.round(c.value * 100) / 100}</output><span></span></div>`;
252
- })}
253
- ${!controls.length && !clips.length ? html `<p hint>${i18next.t('figure.text.detail-no-motion')}</p>` : nothing}
254
- </section>
255
- ${free.length ? html `<section>${heading('clips')}${free.map(name => this.clipRow(name))}</section>` : nothing}
256
- ${groups.some(g => g.clips.some(c => clips.includes(c)))
257
- ? html `<section>
258
- ${heading('motion')}
259
- ${groups.map(g => html `<h4>${g.label}</h4>${g.clips.filter(c => clips.includes(c)).map(name => this.clipRow(name))}`)}
260
- </section>`
261
- : nothing}`;
262
- }
263
- /** A clip on its own row, played by the mark at its end. */
264
- clipRow(name) {
265
- return html `<div slide clip><span title=${name}>${name}</span>${this.playButton(name)}</div>`;
232
+ renderMotion(asset) {
233
+ const keys = MOTION_KEYS.flatMap(key => this.exposed.filter(p => p.name === key));
234
+ /* Kept standing on the other tabs, hidden: what plays goes on playing, and the controls still say what it is. */
235
+ return html `<section motion ?hidden=${this.tab !== 'motion'}>
236
+ ${keys.length ? html `<div keys>${keys.map(p => html `<span>${this.boardName(p)}</span>`)}</div>` : nothing}
237
+ <figure-motion-controls .asset=${asset} @motion-tell=${(e) => this.tell(e.detail.key, e.detail.values)}></figure-motion-controls>
238
+ </section>`;
266
239
  }
267
240
  /*
268
241
  The connections the author declared (the modeller's 「연결」): for each, the data field, what it moves and how, then
@@ -331,15 +304,6 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
331
304
  this.scene?.fit?.('ratio');
332
305
  this.scene?.root?.fitCameraToModel?.();
333
306
  }
334
- /** Play or pause a clip, at the end of the line it moves. */
335
- playButton(clip) {
336
- const on = this.playing === clip;
337
- /* A clip the figure's data never turns into cannot be chosen here; it says so instead of pressing to no effect. */
338
- const unreachable = !!this.asset && clipPlayOf(this.asset, clip).kind === 'unreachable';
339
- const title = unreachable ? i18next.t('figure.text.detail-clip-by-data', { clip }) : clip;
340
- return html `<button icon play aria-pressed=${String(on)} aria-label=${clip} title=${title} ?disabled=${unreachable} @click=${() => this.play(clip)}>
341
- <md-icon>${on ? 'pause' : 'play_arrow'}</md-icon></button>`;
342
- }
343
307
  tell(key, value) {
344
308
  this.scene?.root?.components?.[0]?.set(key, value);
345
309
  }
@@ -371,27 +335,6 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
371
335
  const { width = 0, height = 0 } = instance.model;
372
336
  instance.set({ left: this.board.x / 2 - width / 2, top: this.board.z / 2 - height / 2 });
373
337
  }
374
- pose(id, value) {
375
- if (!Number.isFinite(value))
376
- return;
377
- this.values = { ...this.values, [id]: value };
378
- this.tell('parameters', this.values);
379
- }
380
- play(name) {
381
- this.playing = this.playing === name ? '' : name;
382
- if (this.playing && this.asset) {
383
- this.played.add(name);
384
- this.values = parametersForClip(this.asset, this.values, name);
385
- this.tell('parameters', this.values);
386
- }
387
- if (!this.asset)
388
- return;
389
- /* A clip of a motion group is the group's to choose -- through the data when the data chooses it (detail-motion). */
390
- const { clips, motion, figureValues } = playSettingsOf(this.asset, this.playing);
391
- this.tell('clips', clips);
392
- this.tell('motion', motion);
393
- this.tell('figureValues', figureValues);
394
- }
395
338
  reset() {
396
339
  if (!this.asset)
397
340
  return;
@@ -404,11 +347,9 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
404
347
  const asset = this.asset;
405
348
  if (!asset)
406
349
  return;
407
- this.values = {};
350
+ this.motionControls?.reset();
408
351
  this.exposed = [];
409
- this.playing = '';
410
352
  this.shot = '';
411
- this.played.clear();
412
353
  try {
413
354
  compileFigureAsset(asset);
414
355
  if (!asset.appearance.length)
@@ -418,7 +359,9 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
418
359
  registerFigure(type, asset);
419
360
  this.registered = type;
420
361
  const size = bodyAtSize(asset, this.sizes) ?? this.sizes;
421
- const { board, components } = previewOneInstance(type, size);
362
+ const { board, components: placed } = previewOneInstance(type, size);
363
+ /* A run that travels stays in view, its floor flowing under it, as in the modeller's preview (travel-floor). */
364
+ const components = placed.map(c => ({ ...c, clipTravel: PREVIEW_CLIP_TRAVEL }));
422
365
  this.board = { x: board.width, z: board.height };
423
366
  this.scene = create({ target: this.stage, mode: 0, model: {
424
367
  type: 'model-layer', width: board.width, height: board.height,
@@ -432,6 +375,7 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
432
375
  this.scene.resize?.();
433
376
  this.fit();
434
377
  this.exposed = this.scene.root?.components?.[0]?.nature?.properties ?? [];
378
+ this.stopTravel = followTravelFloor(() => this.scene?.root);
435
379
  }
436
380
  catch (error) {
437
381
  this.error = error.message;
@@ -439,6 +383,8 @@ let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitEle
439
383
  }
440
384
  }
441
385
  teardown() {
386
+ this.stopTravel?.();
387
+ this.stopTravel = undefined;
442
388
  this.scene?.dispose?.();
443
389
  this.scene = undefined;
444
390
  if (this.registered)
@@ -462,6 +408,10 @@ __decorate([
462
408
  query('[stage]'),
463
409
  __metadata("design:type", HTMLElement)
464
410
  ], FigureAssetViewer.prototype, "stage", void 0);
411
+ __decorate([
412
+ query('figure-motion-controls'),
413
+ __metadata("design:type", Function)
414
+ ], FigureAssetViewer.prototype, "motionControls", void 0);
465
415
  __decorate([
466
416
  state(),
467
417
  __metadata("design:type", String)
@@ -470,14 +420,6 @@ __decorate([
470
420
  state(),
471
421
  __metadata("design:type", Object)
472
422
  ], FigureAssetViewer.prototype, "sizes", void 0);
473
- __decorate([
474
- state(),
475
- __metadata("design:type", Object)
476
- ], FigureAssetViewer.prototype, "values", void 0);
477
- __decorate([
478
- state(),
479
- __metadata("design:type", Object)
480
- ], FigureAssetViewer.prototype, "playing", void 0);
481
423
  __decorate([
482
424
  state(),
483
425
  __metadata("design:type", Object)
@@ -0,0 +1,80 @@
1
+ import '@material/web/icon/icon.js';
2
+ import { LitElement, nothing } from 'lit';
3
+ import type { FigureAsset } from '@hatiolab/figure-model';
4
+ /** What a preview tells the figures standing in it, in the board's words: a board sets the same keys on a figure. */
5
+ export type MotionKey = 'clips' | 'parameters' | 'motion' | 'figureValues';
6
+ declare const FigureMotionControls_base: (new (...args: any[]) => LitElement) & typeof LitElement;
7
+ /**
8
+ * How a figure moves in a preview: the one set of controls every preview of a figure shows -- the modeller's and the
9
+ * catalogue's (figure-asset-viewer), a board server's library among them. Two previews played a figure two ways: the
10
+ * catalogue's played one clip at a time with a mark per clip, put the joints first and knew nothing of the data's states
11
+ * (the user, 2026-11-21: 「다른 미리보기에는 클립과 상태 우선이 적용이 안 되어 있다」).
12
+ *
13
+ * What plays comes first -- the data's states, each motion group's clips and speed, the clips of their own -- and the
14
+ * joints under it, folded from ten on (the user, 2026-11-21: 「클립위주로 배치를 바꿔주면 어떤가」). A group field the data
15
+ * writes is moved by the data's value, not offered on the group, as on a board (ADR-0051 §8).
16
+ *
17
+ * The values are the preview's, never the figure's: each change is told to the figures standing in the host as a
18
+ * `motion-tell` event (detail `{ key, values }`, the board's key and its whole value), and the host sets it on them.
19
+ * The look takes the host's colour (`currentColor`): light text on the modeller's stage, the panel's on the catalogue.
20
+ */
21
+ export declare class FigureMotionControls extends FigureMotionControls_base {
22
+ static styles: import("lit").CSSResult;
23
+ asset?: FigureAsset;
24
+ /** Data tried in the modeller's data tab, given to the figures as their `data`: a row it sets is said, not offered. */
25
+ sample: unknown;
26
+ /** Clip speeds of the clips in no group, by clip -- as a board's `clips`. */
27
+ private driving;
28
+ /** Control values tried, by input -- as a board's `parameters`. */
29
+ private giving;
30
+ /** Per motion group, the clip played and how fast (ADR-0051 §3.2) -- as a board's `motion`. */
31
+ private moving;
32
+ /** Data values given by accessor, as a board's saved `figureValues`: what moves a group whose clip or speed the data writes. */
33
+ private valuing;
34
+ private jointsFolded?;
35
+ /** The clip speeds tried here, by clip. */
36
+ get clipsTried(): Record<string, number>;
37
+ /** The control values tried here, by input. */
38
+ get controlsTried(): Record<string, number>;
39
+ /** The controls tried away from the default pose, those a starting-pose hold solves left out: a pose to keep. */
40
+ get poseChanged(): string[];
41
+ /** Every value tried let go: the figure stands in its default pose, and its clips move it again. */
42
+ clearTried(): void;
43
+ /**
44
+ * The values tried as the pose to keep, and let go here: the controls a starting-pose hold solves are left out -- the
45
+ * kernel refuses them (HOLD_OWNED) and solves them again for the pose kept (2026-11-21).
46
+ */
47
+ takePose(): Record<string, number>;
48
+ /** What plays let go, for figures stood up again: their clocks start over. The control values tried stay. */
49
+ stopPlaying(): void;
50
+ /** Everything tried let go, for another figure. */
51
+ reset(): void;
52
+ render(): typeof nothing | import("lit-html").TemplateResult<1>;
53
+ private renderControl;
54
+ /**
55
+ * A row's name that scrubs its value when dragged sideways, as the property panel's names do (\`scrubLabel\`): Shift for
56
+ * finer steps, held within the row's range. The values are tried, not recorded, so each move is the value. The sliders
57
+ * ran 360 degrees over 96 pixels, too coarse to land an angle (user 2026-11-12).
58
+ */
59
+ private scrubName;
60
+ /**
61
+ * A slider's value as a box to type in, the same on every row: the value a slider cannot land on, typed (a step of the
62
+ * range's hundredth, robot dog 2026-11-03); one column of boxes, not boxes over plain numbers (user 2026-11-12).
63
+ */
64
+ private typedBox;
65
+ /** A value the data's bindings read, as the board's saved values give it: a number on a slider when it has a range, a choice when it is closed. */
66
+ private renderDataValue;
67
+ private renderDial;
68
+ private value;
69
+ private move;
70
+ private drive;
71
+ private release;
72
+ private give;
73
+ private tell;
74
+ }
75
+ declare global {
76
+ interface HTMLElementTagNameMap {
77
+ 'figure-motion-controls': FigureMotionControls;
78
+ }
79
+ }
80
+ export {};