@things-factory/figure-viewer 10.1.246 → 10.1.253

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/client/data-connection.ts +82 -0
  2. package/client/data-words.ts +31 -0
  3. package/client/figure-asset-viewer.ts +124 -10
  4. package/client/figure-data-list.ts +87 -0
  5. package/client/figure-data-report.ts +142 -0
  6. package/client/index.ts +5 -0
  7. package/client/unit-words.ts +11 -0
  8. package/dist-client/data-connection.d.ts +32 -0
  9. package/dist-client/data-connection.js +49 -0
  10. package/dist-client/data-connection.js.map +1 -0
  11. package/dist-client/data-words.d.ts +9 -0
  12. package/dist-client/data-words.js +25 -0
  13. package/dist-client/data-words.js.map +1 -0
  14. package/dist-client/figure-asset-viewer.d.ts +13 -3
  15. package/dist-client/figure-asset-viewer.js +115 -7
  16. package/dist-client/figure-asset-viewer.js.map +1 -1
  17. package/dist-client/figure-data-list.d.ts +25 -0
  18. package/dist-client/figure-data-list.js +88 -0
  19. package/dist-client/figure-data-list.js.map +1 -0
  20. package/dist-client/figure-data-report.d.ts +59 -0
  21. package/dist-client/figure-data-report.js +96 -0
  22. package/dist-client/figure-data-report.js.map +1 -0
  23. package/dist-client/index.d.ts +5 -0
  24. package/dist-client/index.js +5 -0
  25. package/dist-client/index.js.map +1 -1
  26. package/dist-client/tsconfig.tsbuildinfo +1 -1
  27. package/dist-client/unit-words.d.ts +5 -0
  28. package/dist-client/unit-words.js +12 -0
  29. package/dist-client/unit-words.js.map +1 -0
  30. package/package.json +4 -4
  31. package/test/data-connection.test.ts +35 -0
  32. package/test/detail-motion.test.ts +3 -1
  33. package/test/figure-data-report.test.ts +88 -0
  34. package/translations/en.json +68 -1
  35. package/translations/es.json +68 -1
  36. package/translations/ja.json +68 -1
  37. package/translations/ko.json +68 -1
  38. package/translations/ms.json +68 -1
  39. package/translations/zh.json +68 -1
@@ -0,0 +1,82 @@
1
+ import { figureDataRows, type FigureAsset, type FigureDataBehavior, type FigureDataBinding, type FigureDataNode, type FigureDataTargets } from '@hatiolab/figure-model'
2
+
3
+ /*
4
+ * A figure's connections as a person reads them (ADR-0051 §8, ADR-0166): for each, the data field, what it moves and how
5
+ * -- the line the modeller's 「연결」 heads each connection with, the preview's 「데이터」 tab lists, and the board's
6
+ * 「피규어 데이터」 says beside a field. Words are the screens'; this reads the asset only, so it is tested without one.
7
+ */
8
+
9
+ /** How a value becomes what it moves: as it is, scaled, or a table by code or by interval. */
10
+ export type DataMethod = 'value' | 'scale' | 'code' | 'ranges'
11
+ export const methodOf = (b: FigureDataBinding): DataMethod => (b.rule === 'table' ? (b.lookup === 'code' ? 'code' : 'ranges') : b.rule)
12
+
13
+ /**
14
+ * What a connection moves and the name a person knows it by: a control's label, a colour token, a motion group's label,
15
+ * an axis, the places the items go into; a table's targets, joined.
16
+ */
17
+ export interface DataMove {
18
+ kind: FigureDataBehavior['kind'] | 'table'
19
+ name: string
20
+ }
21
+
22
+ export function dataMoveOf(asset: FigureAsset, move: FigureDataBehavior | { kind: 'table'; targets: FigureDataTargets }): DataMove {
23
+ const groupLabel = (id: string) => (asset.motionGroups ?? []).find(g => g.id === id)?.label ?? id
24
+ const inputLabel = (id: string) => asset.stateInputs?.[id]?.label ?? id
25
+ switch (move.kind) {
26
+ case 'table':
27
+ return {
28
+ kind: 'table',
29
+ name: [...(move.targets.parts ?? []), ...(move.targets.inputs ?? []).map(inputLabel), ...(move.targets.group ? [groupLabel(move.targets.group)] : [])].join(', ')
30
+ }
31
+ case 'state':
32
+ return { kind: move.kind, name: inputLabel(move.input) }
33
+ case 'palette':
34
+ return { kind: move.kind, name: move.token }
35
+ case 'pose':
36
+ return { kind: move.kind, name: move.axis }
37
+ case 'items':
38
+ return { kind: move.kind, name: move.slot ?? asset.document.capabilities.slotLayout?.label ?? 'items' }
39
+ default:
40
+ return { kind: move.kind, name: groupLabel(move.group) }
41
+ }
42
+ }
43
+
44
+ /** What a field of an items list's element says of the item (FigureDataBehavior `items`). */
45
+ export type FigureItemField = 'id' | 'type' | 'place' | 'stack' | 'status'
46
+ export const ITEM_FIELDS: readonly FigureItemField[] = ['id', 'type', 'place', 'stack', 'status']
47
+
48
+ export interface DataConnection {
49
+ id: string
50
+ /** The connection's label, else its accessor. */
51
+ field: string
52
+ accessor: string
53
+ /** What the data has at the accessor; absent when the shape does not reach it. */
54
+ node?: FigureDataNode
55
+ method: DataMethod
56
+ move: DataMove
57
+ /** An items connection: the element's field that says each part of an item. */
58
+ itemFields?: Partial<Record<FigureItemField, string>>
59
+ }
60
+
61
+ export function dataConnectionsOf(asset: FigureAsset): DataConnection[] {
62
+ const di = asset.dataInterface
63
+ if (!di) return []
64
+ const nodes = new Map(figureDataRows(di).map(r => [r.path, r.node] as const))
65
+ return di.bindings.map((b): DataConnection => {
66
+ const node = nodes.get(b.accessor.replace(/\[\d+\]/g, '[]'))
67
+ const out: DataConnection = {
68
+ id: b.id,
69
+ field: b.label ?? b.accessor,
70
+ accessor: b.accessor,
71
+ ...(node ? { node } : {}),
72
+ method: methodOf(b),
73
+ move: dataMoveOf(asset, b.rule === 'table' ? { kind: 'table', targets: b.targets } : b.behavior)
74
+ }
75
+ if (b.rule !== 'table' && b.behavior.kind === 'items') {
76
+ const behavior = b.behavior
77
+ const fields = Object.fromEntries(ITEM_FIELDS.flatMap(f => (behavior[f] ? [[f, behavior[f]!]] : [])))
78
+ if (Object.keys(fields).length) out.itemFields = fields
79
+ }
80
+ return out
81
+ })
82
+ }
@@ -0,0 +1,31 @@
1
+ import { i18next } from '@operato/i18n'
2
+ import type { FigureDataNode } from '@hatiolab/figure-model'
3
+
4
+ import type { DataMethod, DataMove, FigureItemField } from './data-connection.js'
5
+ import { unitWord } from './unit-words.js'
6
+
7
+ /*
8
+ * The words a figure's data is said in, one set for every screen: the modeller's 「연결」, the preview's 「데이터」 and the
9
+ * board's 「피규어 데이터」.
10
+ */
11
+
12
+ /** What a connection moves: 「조작값 리프트」, 「몸체 색」, 「이동 클립」; a table's targets as they are. */
13
+ export const moveWords = (m: DataMove): string =>
14
+ m.kind === 'table' ? m.name : i18next.t('figure.label.data-behavior-' + m.kind, { name: m.kind === 'pose' ? i18next.t('figure.label.data-axis-' + m.name) : m.name })
15
+
16
+ export const methodWords = (m: DataMethod): string => i18next.t('figure.label.data-method-' + m)
17
+
18
+ /** A field's kind, with a number's unit and range, a closed text's values and a list's element kind. */
19
+ export function kindWords(node: FigureDataNode): string {
20
+ const kind = i18next.t('figure.label.data-kind-' + node.kind)
21
+ if (node.kind === 'number') {
22
+ const range = node.min !== undefined || node.max !== undefined ? ` ${node.min ?? ''}~${node.max ?? ''}` : ''
23
+ return `${kind}${node.unit ? ` ${unitWord(node.unit)}` : ''}${range}`
24
+ }
25
+ if (node.kind === 'text' && node.values) return `${kind} (${node.values.join(', ')})`
26
+ if (node.kind === 'list') return `${kind} · ${i18next.t('figure.label.data-kind-' + node.item.kind)}`
27
+ return kind
28
+ }
29
+
30
+ /** The part of an item a list element's field says: 「아이템 ID」, 「놓일 자리」. */
31
+ export const itemFieldWords = (f: FigureItemField): string => i18next.t('figure.label.data-item-' + f)
@@ -4,18 +4,35 @@ import { customElement, property, query, state } from 'lit/decorators.js'
4
4
  import { i18next, localize } from '@operato/i18n'
5
5
  import { ScrollbarStyles } from '@operato/styles'
6
6
  import { SurfaceStyles } from '@things-factory/styles'
7
- import { compileFigureAsset, type FigureAsset } from '@hatiolab/figure-model'
7
+ import { compileFigureAsset, figureDataExample, type FigureAsset } from '@hatiolab/figure-model'
8
8
  import { create, registerFigure, unregisterFigure } from '@hatiolab/things-scene'
9
9
  import { authoredSizeOf, bodyAtSize, previewOneInstance, sizeSpanOf, sizeWithinRange } from './preview-model.js'
10
10
  import { controlsOf } from './controls.js'
11
11
  import { DEFAULT_VIEW, previewBoardDepth, sceneLook } from './figure-view.js'
12
12
  import { SidePanelStyles } from './side-panel-styles.js'
13
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'
14
16
 
15
17
  type Axis = 'x' | 'y' | 'z'
16
- /** What the view's tabs show under it: the figure's facts, its size, its motion. */
17
- export type FigureViewerTab = 'info' | 'size' | 'motion'
18
- export const FIGURE_VIEWER_TABS: readonly FigureViewerTab[] = ['info', 'size', 'motion']
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']
19
36
  interface Scene {
20
37
  dispose?(): void
21
38
  resize?(): void
@@ -24,7 +41,7 @@ interface Scene {
24
41
  fitCameraToModel?(): void
25
42
  snapshot3d?(width?: number, height?: number, type?: string, quality?: number): Promise<string | undefined>
26
43
 
27
- components?: Array<{ model?: { width?: number; height?: number }; set(props: string | Record<string, unknown>, value?: unknown): void }>
44
+ components?: Array<{ model?: { width?: number; height?: number }; nature?: { properties?: BoardProperty[] }; set(props: string | Record<string, unknown>, value?: unknown): void }>
28
45
  }
29
46
  }
30
47
 
@@ -68,6 +85,12 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
68
85
  section + section { border-top: 1px solid var(--md-sys-color-outline-variant); }
69
86
  section:last-child { border-bottom: none; }
70
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; }
71
94
  /*
72
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
73
96
  unit (「j2-shoulder · deg」) and wraps rather than cutting it; a row grows with its name. A clip's row is its name
@@ -89,6 +112,12 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
89
112
  button[icon] md-icon { --md-icon-size: 16px; }
90
113
  button[icon][aria-pressed='true'] { color: var(--md-sys-color-primary); }
91
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; }
92
121
  p[error] { margin: 0; padding: 8px 16px; color: var(--md-sys-color-error); }
93
122
  `]
94
123
  @property({ attribute: false }) asset?: FigureAsset
@@ -102,11 +131,14 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
102
131
  @state() private values: Record<string, number> = {}
103
132
  @state() private playing = ''
104
133
  @state() private error = ''
134
+ @state() private copied = false
105
135
  private scene?: Scene
106
136
  private registered?: string
107
137
  private observer?: ResizeObserver
108
138
  private needsScene = false
109
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[] = []
110
142
  /** The board the instance stands on, set when the scene is built; its centre is the grid's origin. */
111
143
  private board = { x: 0, z: 0 }
112
144
 
@@ -158,10 +190,11 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
158
190
  ${this.tab === 'info' ? html`<slot name="facts"></slot>` : nothing}
159
191
  ${asset && this.tab === 'size' ? this.renderSize(asset) : nothing}
160
192
  ${asset && this.tab === 'motion' ? this.renderMotion(asset, controls, clips) : nothing}
193
+ ${asset && this.tab === 'data' ? this.renderData(asset) : nothing}
161
194
  </div>`
162
195
  }
163
196
 
164
- /** The tab strip: the facts, the size, the motion. Arrow keys move along it, as the suite's tabs do. */
197
+ /** The tab strip: the facts, the size, the motion, the data. Arrow keys move along it, as the suite's tabs do. */
165
198
  private renderTabs() {
166
199
  return html`<nav class="ui-tabs" role="tablist" @keydown=${(e: KeyboardEvent) => this.stepTab(e)}>
167
200
  ${FIGURE_VIEWER_TABS.map(tab => {
@@ -204,7 +237,29 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
204
237
  <span></span>
205
238
  </div>`
206
239
  })}
207
- </section>`
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>`
208
263
  }
209
264
 
210
265
  /*
@@ -214,7 +269,15 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
214
269
  is not shown until it is dragged.
215
270
  */
216
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)))
217
279
  return html`<section>
280
+ ${controls.length ? heading('parameters') : nothing}
218
281
  ${controls.map(c => {
219
282
  const driving = clipsDriving(asset, c.id)
220
283
  const moving = driving.includes(this.playing)
@@ -226,9 +289,58 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
226
289
  })}
227
290
  ${!controls.length && !clips.length ? html`<p hint>${i18next.t('figure.text.detail-no-motion')}</p>` : nothing}
228
291
  </section>
229
- ${clips.length ? html`<section>
230
- ${clips.map(name => html`<div slide clip><span title=${name}>${name}</span>${this.playButton(name)}</div>`)}
231
- </section>` : nothing}`
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
+ }
232
344
  }
233
345
 
234
346
  /**
@@ -320,6 +432,7 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
320
432
  const asset = this.asset
321
433
  if (!asset) return
322
434
  this.values = {}
435
+ this.exposed = []
323
436
  this.playing = ''
324
437
  this.shot = ''
325
438
  this.played.clear()
@@ -344,6 +457,7 @@ export class FigureAssetViewer extends localize(i18next)(LitElement) {
344
457
  this.centre()
345
458
  this.scene.resize?.()
346
459
  this.fit()
460
+ this.exposed = this.scene.root?.components?.[0]?.nature?.properties ?? []
347
461
  } catch (error) {
348
462
  this.error = (error as Error).message
349
463
  this.teardown()
@@ -0,0 +1,87 @@
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
+ }
@@ -0,0 +1,142 @@
1
+ /*
2
+ * What a figure's data list shows (data binding design, decision 3) -- the board's 「피규어 데이터」 section for a placed
3
+ * figure, the preview's 「데이터」 tab for a release with no data given: the figure's data
4
+ * shape as a tree, each value now and where it came from -- the component's data, a value saved on the board, the
5
+ * shape's default, or none -- what it moves, a control the board's own state values hold over the data, why data was
6
+ * refused, the fields the data has that the shape does not name, and an example to copy.
7
+ *
8
+ * Nothing here reads data: the values and their sources are things-scene's figure inputs', given in. Kept apart from the
9
+ * element so it is tested without a board.
10
+ */
11
+ import { figureDataExample, figureDataRows } from '@hatiolab/figure-model'
12
+ import { ITEM_FIELDS, type FigureItemField } from './data-connection.js'
13
+ import type { FigureAsset, FigureDataBehavior, FigureDataBinding, FigureDataNode, FigureDataTargets, FigureDataValue, FigureDataValueIssue } from '@hatiolab/figure-model'
14
+
15
+ /** Where a value came from, as things-scene's figure inputs say. */
16
+ export type FigureDataSource = 'live' | 'manual' | 'default' | 'absent'
17
+
18
+ /** A placed figure as the section reads it: its asset, its state, and what its figure inputs worked out. */
19
+ export interface FigureDataSnapshot {
20
+ asset: FigureAsset
21
+ /** The component's data, as the board's data source or a mapping gave it. */
22
+ data: unknown
23
+ /** The board's own state values (`parameters`), by control. */
24
+ parameters?: Record<string, unknown> | null
25
+ /** Each binding's value now and its source, by binding id (figure inputs' `dataValues`). */
26
+ values: Readonly<Record<string, { value: FigureDataValue | undefined; source: FigureDataSource }>>
27
+ /** Why the last things given were refused (figure inputs' `diagnostics()`). */
28
+ refused: ReadonlyArray<{ source: string; reason: string; issues?: FigureDataValueIssue[] }>
29
+ }
30
+
31
+ export interface FigureDataReportRow {
32
+ path: string
33
+ depth: number
34
+ name: string
35
+ label?: string
36
+ node: FigureDataNode
37
+ /** A value field's value now; a list's element count in the data. */
38
+ value?: FigureDataValue
39
+ count?: number
40
+ source?: FigureDataSource
41
+ /** What the bindings reading it move: a behavior each, or a table and its targets. */
42
+ behaviors: FigureDataMove[]
43
+ /** Controls it moves that the board's state values hold instead. */
44
+ heldByBoard: string[]
45
+ /**
46
+ * A field inside an items list's element, the part of an item it says: its id, its type, the place it is in, its
47
+ * height in the stack, its status. Its row says that instead of repeating the list's behavior.
48
+ */
49
+ itemField?: FigureItemField
50
+ }
51
+
52
+
53
+ /** What one binding moves: a value binding's behavior, or a table's targets (ADR-0166 3). */
54
+ export type FigureDataMove = FigureDataBehavior | { kind: 'table'; targets: FigureDataTargets }
55
+
56
+ export interface FigureDataReport {
57
+ /** The figure, for the names of what its fields move (dataMoveOf). */
58
+ asset: FigureAsset
59
+ rows: FigureDataReportRow[]
60
+ /** Fields the data has that the shape does not name, as paths (`[]` for a list's elements). */
61
+ unused: string[]
62
+ refused: FigureDataSnapshot['refused']
63
+ /** Data with every field of the shape, to copy. */
64
+ example: Record<string, unknown>
65
+ }
66
+
67
+ const isRecord = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v)
68
+
69
+ /** The value at a path with no list in it (`A.B`), or undefined. */
70
+ function valueAt(data: unknown, path: string): unknown {
71
+ let at: unknown = data
72
+ for (const name of path.split('.')) {
73
+ if (!isRecord(at)) return undefined
74
+ at = at[name]
75
+ }
76
+ return at
77
+ }
78
+
79
+ /** Every field path the data has that the shape does not name. A JSON text in place of an object or a list is not looked into. */
80
+ function unusedOf(data: unknown, fields: ReadonlyArray<{ name: string } & FigureDataNode>, at: string, out: Set<string>): void {
81
+ if (!isRecord(data)) return
82
+ for (const [key, value] of Object.entries(data)) {
83
+ const path = at ? `${at}.${key}` : key
84
+ const field = fields.find(f => f.name === key)
85
+ if (!field) {
86
+ out.add(path)
87
+ continue
88
+ }
89
+ let node: FigureDataNode = field
90
+ let value_: unknown = value
91
+ let p = path
92
+ while (node.kind === 'list' && Array.isArray(value_)) {
93
+ const item: FigureDataNode = node.item
94
+ p = `${p}[]`
95
+ for (const element of value_) if (item.kind === 'object') unusedOf(element, item.fields, p, out)
96
+ value_ = undefined
97
+ node = item
98
+ }
99
+ if (node.kind === 'object' && isRecord(value_)) unusedOf(value_, node.fields, p, out)
100
+ }
101
+ }
102
+
103
+ export function figureDataReportOf(s: FigureDataSnapshot): FigureDataReport | null {
104
+ const di = s.asset.dataInterface
105
+ if (!di) return null
106
+ const bindings = new Map(di.bindings.map(b => [b.id, b] as const))
107
+ const held = new Set(Object.keys(s.parameters ?? {}))
108
+ /* The row path of each field an items binding reads inside its list's element, as figureDataRows writes it. */
109
+ const asRow = (accessor: string) => accessor.replace(/\[\d+\]/g, '[]')
110
+ const itemFields = new Map<string, FigureItemField>()
111
+ for (const b of di.bindings)
112
+ if (b.rule !== 'table' && b.behavior.kind === 'items')
113
+ for (const field of ITEM_FIELDS) {
114
+ const rel = b.behavior[field]
115
+ if (rel) itemFields.set(`${asRow(b.accessor)}[].${asRow(rel)}`, field)
116
+ }
117
+ const rows = figureDataRows(di).map((row): FigureDataReportRow => {
118
+ const itemField = itemFields.get(row.path)
119
+ /* An item's field says its part of the item; the list's own row says the items go into the places. */
120
+ const reading = row.bindings.map(id => bindings.get(id))
121
+ .filter((b): b is FigureDataBinding => !!b && !(itemField && b.rule !== 'table' && b.behavior.kind === 'items'))
122
+ const behaviors = reading.map((b): FigureDataMove => (b.rule === 'table' ? { kind: 'table', targets: b.targets } : b.behavior))
123
+ const heldByBoard = behaviors.flatMap(b => (b.kind === 'state' ? [b.input] : b.kind === 'table' ? (b.targets.inputs ?? []) : []).filter(input => held.has(input)))
124
+ const out: FigureDataReportRow = { path: row.path, depth: row.depth, name: row.name, ...(row.label ? { label: row.label } : {}), node: row.node, behaviors, heldByBoard, ...(itemField ? { itemField } : {}) }
125
+ if (row.node.kind === 'list') {
126
+ const list = row.path.includes('[]') ? undefined : valueAt(s.data, row.path)
127
+ if (Array.isArray(list)) out.count = list.length
128
+ } else if (row.node.kind !== 'object') {
129
+ /* The value a binding read: the first that reads this place and is not an items binding (items read the list). */
130
+ const read = reading.find(b => (b.rule === 'table' || b.behavior.kind !== 'items') && s.values[b.id])
131
+ if (read) {
132
+ const { value, source } = s.values[read.id]!
133
+ out.source = source
134
+ if (value !== undefined) out.value = value
135
+ }
136
+ }
137
+ return out
138
+ })
139
+ const unused = new Set<string>()
140
+ unusedOf(s.data, di.schema, '', unused)
141
+ return { asset: s.asset, rows, unused: [...unused], refused: s.refused, example: figureDataExample(di) }
142
+ }
package/client/index.ts CHANGED
@@ -4,11 +4,16 @@
4
4
  */
5
5
  export * from './capability-rung.js'
6
6
  export * from './controls.js'
7
+ export * from './data-connection.js'
8
+ export * from './data-words.js'
7
9
  export * from './detail-facts.js'
8
10
  export * from './detail-motion.js'
11
+ export * from './figure-data-list.js'
12
+ export * from './figure-data-report.js'
9
13
  export * from './figure-asset-viewer.js'
10
14
  export * from './figure-facts-list.js'
11
15
  export * from './figure-thumb-mark.js'
12
16
  export * from './figure-view.js'
13
17
  export * from './preview-model.js'
14
18
  export * from './side-panel-styles.js'
19
+ export * from './unit-words.js'
@@ -0,0 +1,11 @@
1
+ import { i18next } from '@operato/i18n'
2
+
3
+ /**
4
+ * A unit as the screen names it: the graph's codes (deg, percent, count …) are not words a person reads, and a unit
5
+ * typed by the author (rpm) stays as typed (sweep 2026-10-27 U9).
6
+ */
7
+ export function unitWord(unit: string | undefined): string {
8
+ if (!unit) return ''
9
+ const key = `figure.label.unit-${unit}`
10
+ return i18next.exists(key) ? i18next.t(key) : unit
11
+ }
@@ -0,0 +1,32 @@
1
+ import { type FigureAsset, type FigureDataBehavior, type FigureDataBinding, type FigureDataNode, type FigureDataTargets } from '@hatiolab/figure-model';
2
+ /** How a value becomes what it moves: as it is, scaled, or a table by code or by interval. */
3
+ export type DataMethod = 'value' | 'scale' | 'code' | 'ranges';
4
+ export declare const methodOf: (b: FigureDataBinding) => DataMethod;
5
+ /**
6
+ * What a connection moves and the name a person knows it by: a control's label, a colour token, a motion group's label,
7
+ * an axis, the places the items go into; a table's targets, joined.
8
+ */
9
+ export interface DataMove {
10
+ kind: FigureDataBehavior['kind'] | 'table';
11
+ name: string;
12
+ }
13
+ export declare function dataMoveOf(asset: FigureAsset, move: FigureDataBehavior | {
14
+ kind: 'table';
15
+ targets: FigureDataTargets;
16
+ }): DataMove;
17
+ /** What a field of an items list's element says of the item (FigureDataBehavior `items`). */
18
+ export type FigureItemField = 'id' | 'type' | 'place' | 'stack' | 'status';
19
+ export declare const ITEM_FIELDS: readonly FigureItemField[];
20
+ export interface DataConnection {
21
+ id: string;
22
+ /** The connection's label, else its accessor. */
23
+ field: string;
24
+ accessor: string;
25
+ /** What the data has at the accessor; absent when the shape does not reach it. */
26
+ node?: FigureDataNode;
27
+ method: DataMethod;
28
+ move: DataMove;
29
+ /** An items connection: the element's field that says each part of an item. */
30
+ itemFields?: Partial<Record<FigureItemField, string>>;
31
+ }
32
+ export declare function dataConnectionsOf(asset: FigureAsset): DataConnection[];