@things-factory/figure-viewer 10.1.273 → 10.1.280

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 (50) hide show
  1. package/dist-client/figure-data-list.d.ts +1 -1
  2. package/dist-client/figure-facts-list.d.ts +1 -1
  3. package/package.json +17 -3
  4. package/client/capability-rung.ts +0 -22
  5. package/client/controls.ts +0 -54
  6. package/client/data-connection.ts +0 -82
  7. package/client/data-words.ts +0 -41
  8. package/client/detail-facts.ts +0 -86
  9. package/client/detail-motion.ts +0 -61
  10. package/client/figure-asset-viewer.ts +0 -472
  11. package/client/figure-data-list.ts +0 -87
  12. package/client/figure-data-report.ts +0 -142
  13. package/client/figure-facts-list.ts +0 -59
  14. package/client/figure-thumb-mark.ts +0 -34
  15. package/client/figure-view.ts +0 -151
  16. package/client/index.ts +0 -19
  17. package/client/preview-model.ts +0 -162
  18. package/client/side-panel-styles.ts +0 -480
  19. package/client/tsconfig.json +0 -19
  20. package/client/unit-words.ts +0 -11
  21. package/dist-client/capability-rung.js.map +0 -1
  22. package/dist-client/controls.js.map +0 -1
  23. package/dist-client/data-connection.js.map +0 -1
  24. package/dist-client/data-words.js.map +0 -1
  25. package/dist-client/detail-facts.js.map +0 -1
  26. package/dist-client/detail-motion.js.map +0 -1
  27. package/dist-client/figure-asset-viewer.js.map +0 -1
  28. package/dist-client/figure-data-list.js.map +0 -1
  29. package/dist-client/figure-data-report.js.map +0 -1
  30. package/dist-client/figure-facts-list.js.map +0 -1
  31. package/dist-client/figure-thumb-mark.js.map +0 -1
  32. package/dist-client/figure-view.js.map +0 -1
  33. package/dist-client/index.js.map +0 -1
  34. package/dist-client/preview-model.js.map +0 -1
  35. package/dist-client/side-panel-styles.js.map +0 -1
  36. package/dist-client/tsconfig.tsbuildinfo +0 -1
  37. package/dist-client/unit-words.js.map +0 -1
  38. package/dist-server/index.js.map +0 -1
  39. package/dist-server/tsconfig.tsbuildinfo +0 -1
  40. package/server/index.ts +0 -4
  41. package/server/tsconfig.json +0 -10
  42. package/test/controls.test.ts +0 -51
  43. package/test/data-connection.test.ts +0 -35
  44. package/test/detail-facts.test.ts +0 -89
  45. package/test/detail-motion.test.ts +0 -110
  46. package/test/figure-data-report.test.ts +0 -94
  47. package/test/joints.ts +0 -30
  48. package/test/preview.test.ts +0 -101
  49. package/test/resolve-ts-siblings.mjs +0 -85
  50. package/test/view.test.ts +0 -13
@@ -13,7 +13,7 @@ export declare class FigureDataList extends FigureDataList_base {
13
13
  static styles: import("lit").CSSResult[];
14
14
  report?: FigureDataReport;
15
15
  private copied;
16
- render(): typeof nothing | import("lit-html").TemplateResult<1>;
16
+ render(): import("lit-html").TemplateResult<1> | typeof nothing;
17
17
  private renderRow;
18
18
  private copy;
19
19
  }
@@ -12,6 +12,6 @@ export declare class FigureFactsList extends FigureFactsList_base {
12
12
  static styles: import("lit").CSSResult;
13
13
  asset?: FigureAsset;
14
14
  row?: DetailFactsRow;
15
- render(): typeof nothing | import("lit-html").TemplateResult<1>;
15
+ render(): import("lit-html").TemplateResult<1> | typeof nothing;
16
16
  }
17
17
  export {};
package/package.json CHANGED
@@ -1,8 +1,22 @@
1
1
  {
2
2
  "name": "@things-factory/figure-viewer",
3
- "version": "10.1.273",
3
+ "version": "10.1.280",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
+ "files": [
7
+ "dist-client",
8
+ "dist-server",
9
+ "things-factory.config.js",
10
+ "translations",
11
+ "!**/*.map",
12
+ "!**/*.test.*",
13
+ "!**/*.spec.*",
14
+ "!**/test/**",
15
+ "!**/tests/**",
16
+ "!**/__tests__/**",
17
+ "!**/*.tsbuildinfo",
18
+ "!**/.DS_Store"
19
+ ],
6
20
  "things-factory": true,
7
21
  "author": "heartyoh <heartyoh@hatiolab.com>",
8
22
  "description": "A released figure on a live canvas, as a board draws it: size within its ranges, poses and clips, its facts and places. Shared by the authoring catalogue (figure-ui) and a board server's library (figure-library); client only.",
@@ -32,8 +46,8 @@
32
46
  "@material/web": "^2.0.0",
33
47
  "@operato/i18n": "^10.0.0",
34
48
  "@operato/styles": "^10.0.0",
35
- "@things-factory/styles": "^10.1.123",
49
+ "@things-factory/styles": "^10.1.280",
36
50
  "lit": "^3.1.2"
37
51
  },
38
- "gitHead": "0ead3ad069edf9f1ef5076caec85916bdb26728f"
52
+ "gitHead": "14ce4b7f5957272d63115af316a7dc1ab030e152"
39
53
  }
@@ -1,22 +0,0 @@
1
- import type { FigureCapability } from '@hatiolab/figure-model'
2
-
3
- /*
4
- One rung per set of the format's capability names. Typed as the format's names, so a misspelt rung does not pass
5
- (ADR-0051 ④).
6
- */
7
- export type Rung = 'none' | 'hold' | 'flow'
8
- export const RUNGS: Readonly<Record<Rung, readonly FigureCapability[]>> = Object.freeze({
9
- none: [],
10
- hold: ['Capacity', 'Holdable'],
11
- flow: ['FlowNode']
12
- })
13
-
14
- /** Which rung a set of names is, or null when it is none of them -- not invented. A product's capability (`<namespace>.<Name>`, ADR-0167) is beside the ladder. */
15
- export function rungOf(names: readonly string[] | undefined): Rung | null {
16
- const has = new Set((names ?? []).filter(name => !name.includes('.')))
17
- if (has.size === 0) return 'none'
18
- for (const [rung, wanted] of Object.entries(RUNGS) as [Rung, readonly FigureCapability[]][])
19
- if (wanted.length === has.size && wanted.every(name => has.has(name))) return rung
20
- return null
21
- }
22
-
@@ -1,54 +0,0 @@
1
- import type { FigureAsset } from '@hatiolab/figure-model'
2
-
3
- /*
4
- * The figure's controls -- its state inputs: the values a board or a connector sets to pose
5
- * the figure (a lift height, a joint angle, a gripper opening). Kept apart from the element so the reading is tested
6
- * without a browser.
7
- */
8
- export interface Control {
9
- id: string
10
- /** The name a person reads, or the id when none is given. */
11
- label: string
12
- named: boolean
13
- unit: string
14
- min: number
15
- max: number
16
- /** Where it stands in the editor now -- the pose being looked at, not yet the default. */
17
- value: number
18
- /** Where it starts when the figure is placed: the default pose. */
19
- start: number
20
- /** Seconds to travel the whole range, 0 when it moves at once. */
21
- sweep: number
22
- /** A slider step: one degree for an angle, else a hundredth of the range. */
23
- step: number
24
- }
25
-
26
- export function controlsOf(asset: FigureAsset, values: Record<string, number> = {}): Control[] {
27
- return asset.document.model.inputs
28
- .filter(input => input.role === 'state')
29
- .map(input => {
30
- const policy = asset.stateInputs?.[input.id]
31
- const start = asset.stateDefaults[input.id] ?? input.min
32
- return {
33
- id: input.id,
34
- label: policy?.label ?? input.id,
35
- named: !!policy?.label,
36
- unit: input.unit,
37
- min: input.min,
38
- max: input.max,
39
- value: values[input.id] ?? start,
40
- start,
41
- sweep: policy?.sweep ?? 0,
42
- step: input.unit === 'deg' ? 1 : (input.max - input.min) / 100
43
- }
44
- })
45
- }
46
-
47
- /** Whether the pose being looked at differs from the default pose -- only then is there a pose to keep. */
48
- export const poseDiffers = (controls: readonly Control[]) => controls.some(c => c.value !== c.start)
49
-
50
- /** The current pose as the defaults: one `set-state-defaults` edit. */
51
- export const poseAsDefault = (controls: readonly Control[]) => ({
52
- kind: 'set-state-defaults' as const,
53
- values: Object.fromEntries(controls.map(c => [c.id, c.value]))
54
- })
@@ -1,82 +0,0 @@
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
- }
@@ -1,41 +0,0 @@
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 name = kindName(node)
21
- if (node.kind === 'number') {
22
- const range = node.min !== undefined || node.max !== undefined ? ` ${node.min ?? ''}~${node.max ?? ''}` : ''
23
- return `${name}${range}`
24
- }
25
- if (node.kind === 'text' && node.values) return `${name} (${node.values.join(', ')})`
26
- return name
27
- }
28
-
29
- /**
30
- * A field's kind alone -- a number with its unit, a list with what it lists -- without its range or values: what a
31
- * narrow column says on one line, the rest said where the field is opened (the modeller's data table, user 2026-11-12).
32
- */
33
- export function kindName(node: FigureDataNode): string {
34
- const kind = i18next.t('figure.label.data-kind-' + node.kind)
35
- if (node.kind === 'number') return `${kind}${node.unit ? ` ${unitWord(node.unit)}` : ''}`
36
- if (node.kind === 'list') return `${kind} · ${i18next.t('figure.label.data-kind-' + node.item.kind)}`
37
- return kind
38
- }
39
-
40
- /** The part of an item a list element's field says: 「아이템 ID」, 「놓일 자리」. */
41
- export const itemFieldWords = (f: FigureItemField): string => i18next.t('figure.label.data-item-' + f)
@@ -1,86 +0,0 @@
1
- import { figureBindingsOf, figureJointsOf, type FigureAsset } from '@hatiolab/figure-model'
2
-
3
- import { rungOf } from './capability-rung.js'
4
- import { authoredSizeOf, sizeRangeOf } from './preview-model.js'
5
-
6
- type Say = (key: string, params?: Record<string, unknown>) => string
7
-
8
- /**
9
- * What the facts read off a figure's row besides its asset. figure-ui's catalogue row and figure-library's release both
10
- * give it. `score` absent means the caller does not keep one (no line); null means not measured yet.
11
- */
12
- export interface DetailFactsRow {
13
- category?: string | null
14
- tags?: string[] | null
15
- score?: number | null
16
- updatedAt?: string | Date | null
17
- updater?: { name?: string | null } | null
18
- }
19
-
20
- /**
21
- * A place in words, as every screen that lists places says it: its role (파지 · 안착), what it accepts and how many it
22
- * holds -- 「파지 · 받는 것 BOX, WORKPIECE · 최대 1」, or 「받는 것 모든 아이템」 for a place that names no type.
23
- */
24
- export function placeTerms(place: { role: string; accepts?: readonly string[]; capacity: number }, say: Say): string {
25
- return [
26
- say(`figure.label.role-${place.role}`),
27
- place.accepts?.length ? say('figure.text.place-accepts', { accepts: place.accepts.join(', ') }) : say('figure.text.place-accepts-any'),
28
- say('figure.label.place-holds', { count: place.capacity })
29
- ].join(' · ')
30
- }
31
-
32
- /** One line of what the preview tells about a figure: its label, its value, and for places one line each. */
33
- export interface DetailFact {
34
- key: string
35
- label: string
36
- value: string
37
- lines?: string[]
38
- }
39
-
40
- const number = (n: number) => Math.round(n).toLocaleString()
41
-
42
- /**
43
- * What a figure is, read off its asset and its row, in the words the modeller's properties already use. Nothing is
44
- * defaulted: what the figure does not say reads as a dash, and a score not yet measured is said so, not 0.
45
- */
46
- export function detailFactsOf(asset: FigureAsset, row: DetailFactsRow, say: Say): DetailFact[] {
47
- const facts: DetailFact[] = []
48
- const dash = '—'
49
-
50
- facts.push({ key: 'category', label: say('figure.label.category'), value: row.category || dash })
51
- facts.push({ key: 'tags', label: say('figure.label.tags'), value: row.tags?.length ? row.tags.join(', ') : dash })
52
- facts.push({ key: 'placement', label: say('figure.label.figure-placement'), value: asset.placement ? say(`figure.label.placement-${asset.placement}`) : dash })
53
-
54
- /* The sizes a board may give it: a range on an axis that opens one, the authored size on one that is fixed. */
55
- const base = authoredSizeOf(asset)
56
- const axes = (['x', 'y', 'z'] as const).map(axis => {
57
- const range = sizeRangeOf(asset, axis)
58
- return `${axis.toUpperCase()} ${range ? `${number(range.min)}–${Number.isFinite(range.max) ? number(range.max) : '∞'}` : number(base[axis])}`
59
- })
60
- facts.push({ key: 'size', label: say('figure.label.instance-range'), value: `${axes.join(' · ')} mm` })
61
- if (asset.sizing === 'uniform') facts.push({ key: 'sizing', label: say('figure.label.sizing-rule'), value: say('figure.label.sizing-uniform') })
62
-
63
- const names = asset.document.capabilities.names ?? []
64
- const rung = rungOf(names)
65
- facts.push({ key: 'does', label: say('figure.label.what-this-does'), value: rung ? say(`figure.label.rung-${rung}`) : names.join(' · ') })
66
-
67
- const places = figureBindingsOf(asset)
68
- facts.push({
69
- key: 'places',
70
- label: say('figure.label.places'),
71
- value: places.length ? String(places.length) : dash,
72
- lines: places.map(place => `${place.label} · ${placeTerms(place, say)}`)
73
- })
74
-
75
- facts.push({ key: 'joints', label: say('figure.label.joint'), value: String(figureJointsOf(asset).joints.length) })
76
- const extensions = Object.keys((asset as { extensions?: Record<string, unknown> }).extensions ?? {})
77
- if (extensions.length) facts.push({ key: 'extensions', label: say('figure.label.extensions'), value: extensions.join(', ') })
78
-
79
- if ('score' in row)
80
- facts.push({ key: 'maturity', label: say('figure.label.maturity'), value: row.score == null ? say('figure.text.not-measured-yet') : String(Math.round(row.score)) })
81
- if (row.updatedAt) {
82
- const at = new Date(row.updatedAt).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })
83
- facts.push({ key: 'updated', label: say('field.updated_at'), value: row.updater?.name ? `${at} · ${row.updater.name}` : at })
84
- }
85
- return facts
86
- }
@@ -1,61 +0,0 @@
1
- import { compileFigureDataInterface, type FigureAsset, type FigureDataValue } from '@hatiolab/figure-model'
2
-
3
- /** External values win over drivers; release only the controls owned by the chosen clip. */
4
- export function parametersForClip(asset: FigureAsset, values: Record<string, number>, clip: string) {
5
- const driven = new Set((asset.drivers ?? []).filter(d => d.clip === clip).map(d => d.state))
6
- return Object.fromEntries(Object.entries(values).filter(([id]) => !driven.has(id)))
7
- }
8
-
9
- /** The clips that move an input. A clip can move many inputs, so it plays on its own row, never on an input's. */
10
- export function clipsDriving(asset: FigureAsset, id: string) {
11
- return [...new Set((asset.drivers ?? []).filter(d => d.state === id).map(d => d.clip))]
12
- }
13
-
14
- /**
15
- * 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
16
- * `clips`). A clip of a group is the group's selection (the board's `motion`); and when the figure's data chooses that
17
- * group's clip, the data wins -- its default too -- so the clip is chosen through a data value the figure's own binding
18
- * turns into it, given as a saved value (`figureValues`), the way a board would: the value itself, or the code of a
19
- * table whose look names the clip (ADR-0166). A clip no data value turns into (an interval, a scale, or only another
20
- * value's fallback of an open field) cannot be chosen here.
21
- */
22
- export type ClipPlay =
23
- | { kind: 'free' }
24
- | { kind: 'group'; group: string }
25
- | { kind: 'data'; group: string; accessor: string; value: FigureDataValue }
26
- | { kind: 'unreachable'; group: string }
27
-
28
- export function clipPlayOf(asset: FigureAsset, clip: string): ClipPlay {
29
- const group = (asset.motionGroups ?? []).find(g => g.clips.includes(clip))
30
- if (!group) return { kind: 'free' }
31
- const plan = asset.dataInterface ? compileFigureDataInterface(asset) : null
32
- const ready = plan?.bindings.find(({ binding: b }) =>
33
- b.rule === 'table' ? b.targets.group === group.id && Object.values(b.table).some(look => look.clip !== undefined) : b.behavior.kind === 'motion-clip' && b.behavior.group === group.id
34
- )
35
- if (!ready) return { kind: 'group', group: group.id }
36
- const { binding, node } = ready
37
- const reached = (value: FigureDataValue): ClipPlay => ({ kind: 'data', group: group.id, accessor: binding.accessor, value })
38
- const unreachable: ClipPlay = { kind: 'unreachable', group: group.id }
39
- const closed = node.kind === 'boolean' ? ['false', 'true'] : node.kind === 'text' && node.values ? node.values : null
40
- const typed = (key: string): FigureDataValue => (node.kind === 'boolean' ? key === 'true' : node.kind === 'number' ? Number(key) : key)
41
- if (binding.rule === 'value') return node.kind === 'text' && (!closed || closed.includes(clip)) ? reached(clip) : unreachable
42
- if (binding.rule !== 'table' || binding.lookup !== 'code') return unreachable
43
- const table = binding.table
44
- const key = Object.keys(table).find(k => k !== 'default' && table[k].clip === clip)
45
- if (key !== undefined) return reached(typed(key))
46
- /* Only the default turns into it: a value of a closed field the table does not name. */
47
- const spare = table.default?.clip === clip ? closed?.find(v => !Object.hasOwn(table, v)) : undefined
48
- return spare !== undefined ? reached(typed(spare)) : unreachable
49
- }
50
-
51
- /**
52
- * What the board is told for the clip playing (none: ''): the free clips' speeds, the group's selection, and the saved
53
- * data value that chooses it. Every key is written whole, so the clip played before is let go.
54
- */
55
- export function playSettingsOf(asset: FigureAsset, playing: string) {
56
- const play = playing ? clipPlayOf(asset, playing) : null
57
- 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]))
58
- const motion = play && play.kind !== 'free' && play.kind !== 'unreachable' ? { [play.group]: { clip: playing, speed: 1, paused: false } } : {}
59
- const figureValues = play?.kind === 'data' ? { [play.accessor]: play.value } : {}
60
- return { clips, motion, figureValues }
61
- }