@things-factory/figure-viewer 0.0.0-stage → 10.1.155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/capability-rung.ts +22 -0
- package/client/controls.ts +54 -0
- package/client/detail-facts.ts +87 -0
- package/client/detail-motion.ts +11 -0
- package/client/figure-asset-viewer.ts +284 -0
- package/client/figure-facts-list.ts +59 -0
- package/client/figure-thumb-mark.ts +34 -0
- package/client/figure-view.ts +151 -0
- package/client/index.ts +14 -0
- package/client/preview-model.ts +89 -0
- package/client/side-panel-styles.ts +374 -0
- package/client/tsconfig.json +19 -0
- package/dist-client/capability-rung.d.ts +5 -0
- package/dist-client/capability-rung.js +16 -0
- package/dist-client/capability-rung.js.map +1 -0
- package/dist-client/controls.d.ts +28 -0
- package/dist-client/controls.js +28 -0
- package/dist-client/controls.js.map +1 -0
- package/dist-client/detail-facts.d.ts +37 -0
- package/dist-client/detail-facts.js +58 -0
- package/dist-client/detail-facts.js.map +1 -0
- package/dist-client/detail-motion.d.ts +6 -0
- package/dist-client/detail-motion.js +9 -0
- package/dist-client/detail-motion.js.map +1 -0
- package/dist-client/figure-asset-viewer.d.ts +51 -0
- package/dist-client/figure-asset-viewer.js +313 -0
- package/dist-client/figure-asset-viewer.js.map +1 -0
- package/dist-client/figure-facts-list.d.ts +17 -0
- package/dist-client/figure-facts-list.js +63 -0
- package/dist-client/figure-facts-list.js.map +1 -0
- package/dist-client/figure-thumb-mark.d.ts +12 -0
- package/dist-client/figure-thumb-mark.js +42 -0
- package/dist-client/figure-thumb-mark.js.map +1 -0
- package/dist-client/figure-view.d.ts +117 -0
- package/dist-client/figure-view.js +78 -0
- package/dist-client/figure-view.js.map +1 -0
- package/dist-client/index.d.ts +10 -0
- package/dist-client/index.js +15 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/preview-model.d.ts +54 -0
- package/dist-client/preview-model.js +79 -0
- package/dist-client/preview-model.js.map +1 -0
- package/dist-client/side-panel-styles.d.ts +27 -0
- package/dist-client/side-panel-styles.js +374 -0
- package/dist-client/side-panel-styles.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-server/index.d.ts +1 -0
- package/dist-server/index.js +3 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +35 -4
- package/server/index.ts +4 -0
- package/server/tsconfig.json +10 -0
- package/test/controls.test.ts +51 -0
- package/test/detail-facts.test.ts +79 -0
- package/test/detail-motion.test.ts +26 -0
- package/test/joints.ts +35 -0
- package/test/preview.test.ts +53 -0
- package/test/resolve-ts-siblings.mjs +85 -0
- package/test/view.test.ts +13 -0
- package/things-factory.config.js +5 -0
- package/translations/en.json +37 -0
- package/translations/es.json +37 -0
- package/translations/ja.json +37 -0
- package/translations/ko.json +37 -0
- package/translations/ms.json +37 -0
- package/translations/zh.json +37 -0
- package/README.md +0 -3
|
@@ -0,0 +1,22 @@
|
|
|
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. */
|
|
15
|
+
export function rungOf(names: readonly string[] | undefined): Rung | null {
|
|
16
|
+
const has = new Set(names ?? [])
|
|
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
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { FIGURE_INSTANCE_SIZE_INPUTS, figureBindingsOf, figureJointsOf, type FigureAsset } from '@hatiolab/figure-model'
|
|
2
|
+
|
|
3
|
+
import { rungOf } from './capability-rung.js'
|
|
4
|
+
import { authoredSizeOf } 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」.
|
|
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
|
+
say('figure.text.place-accepts', { accepts: place.accepts.join(', ') }),
|
|
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 input = asset.document.model.inputs.find(input => input.id === FIGURE_INSTANCE_SIZE_INPUTS[axis])
|
|
58
|
+
const open = input && Number.isFinite(input.min) && Number.isFinite(input.max) && input.max > input.min
|
|
59
|
+
return `${axis.toUpperCase()} ${open ? `${number(input!.min)}–${number(input!.max)}` : number(base[axis])}`
|
|
60
|
+
})
|
|
61
|
+
facts.push({ key: 'size', label: say('figure.label.instance-range'), value: `${axes.join(' · ')} mm` })
|
|
62
|
+
if (asset.sizing === 'uniform') facts.push({ key: 'sizing', label: say('figure.label.sizing-rule'), value: say('figure.label.sizing-uniform') })
|
|
63
|
+
|
|
64
|
+
const names = asset.document.capabilities.names ?? []
|
|
65
|
+
const rung = rungOf(names)
|
|
66
|
+
facts.push({ key: 'does', label: say('figure.label.what-this-does'), value: rung ? say(`figure.label.rung-${rung}`) : names.join(' · ') })
|
|
67
|
+
|
|
68
|
+
const places = figureBindingsOf(asset)
|
|
69
|
+
facts.push({
|
|
70
|
+
key: 'places',
|
|
71
|
+
label: say('figure.label.places'),
|
|
72
|
+
value: places.length ? String(places.length) : dash,
|
|
73
|
+
lines: places.map(place => `${place.label} · ${placeTerms(place, say)}`)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
facts.push({ key: 'joints', label: say('figure.label.joint'), value: String(figureJointsOf(asset).joints.length) })
|
|
77
|
+
const extensions = Object.keys((asset as { extensions?: Record<string, unknown> }).extensions ?? {})
|
|
78
|
+
if (extensions.length) facts.push({ key: 'extensions', label: say('figure.label.extensions'), value: extensions.join(', ') })
|
|
79
|
+
|
|
80
|
+
if ('score' in row)
|
|
81
|
+
facts.push({ key: 'maturity', label: say('figure.label.maturity'), value: row.score == null ? say('figure.text.not-measured-yet') : String(Math.round(row.score)) })
|
|
82
|
+
if (row.updatedAt) {
|
|
83
|
+
const at = new Date(row.updatedAt).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })
|
|
84
|
+
facts.push({ key: 'updated', label: say('field.updated_at'), value: row.updater?.name ? `${at} · ${row.updater.name}` : at })
|
|
85
|
+
}
|
|
86
|
+
return facts
|
|
87
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FigureAsset } 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
|
+
export function clipForControl(asset: FigureAsset, id: string) {
|
|
10
|
+
return asset.drivers?.find(d => d.state === id)?.clip
|
|
11
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import '@material/web/icon/icon.js'
|
|
2
|
+
import { css, html, LitElement, nothing, type PropertyValues } from 'lit'
|
|
3
|
+
import { customElement, property, query, state } from 'lit/decorators.js'
|
|
4
|
+
import { i18next, localize } from '@operato/i18n'
|
|
5
|
+
import { compileFigureAsset, FIGURE_INSTANCE_SIZE_INPUTS, type FigureAsset } from '@hatiolab/figure-model'
|
|
6
|
+
import { create, registerFigure, unregisterFigure } from '@hatiolab/things-scene'
|
|
7
|
+
import { authoredSizeOf } from './preview-model.js'
|
|
8
|
+
import { controlsOf } from './controls.js'
|
|
9
|
+
import { DEFAULT_VIEW, previewBoardDepth, sceneLook } from './figure-view.js'
|
|
10
|
+
import { SidePanelStyles } from './side-panel-styles.js'
|
|
11
|
+
import { clipForControl, parametersForClip } from './detail-motion.js'
|
|
12
|
+
|
|
13
|
+
type Axis = 'x' | 'y' | 'z'
|
|
14
|
+
interface Scene {
|
|
15
|
+
dispose?(): void
|
|
16
|
+
resize?(): void
|
|
17
|
+
fit?(type?: string): void
|
|
18
|
+
root?: {
|
|
19
|
+
fitCameraToModel?(): void
|
|
20
|
+
snapshot3d?(width?: number, height?: number, type?: string, quality?: number): Promise<string | undefined>
|
|
21
|
+
|
|
22
|
+
components?: Array<{ model?: { width?: number; height?: number }; set(props: string | Record<string, unknown>, value?: unknown): void }>
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A single board instance. Sizes and poses are transient, and never change the asset or call a mutation. */
|
|
27
|
+
@customElement('figure-asset-viewer')
|
|
28
|
+
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; }
|
|
32
|
+
/* The card's own 4:3, so the picture taken is what is seen. */
|
|
33
|
+
[viewport] { aspect-ratio: 4 / 3; position: relative; background: #858585; }
|
|
34
|
+
[stage] { position: absolute; inset: 0; width: 100%; height: 100%; }
|
|
35
|
+
/*
|
|
36
|
+
The view's own marks in its corner, not buttons beside it: fit the whole figure in view (the modeller's fit, the
|
|
37
|
+
same icon and words), and taking the picture when the screen keeps one.
|
|
38
|
+
*/
|
|
39
|
+
div[marks] { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; }
|
|
40
|
+
div[marks] button { display: inline-grid; place-items: center; width: 28px; height: 28px;
|
|
41
|
+
padding: 0; border: none; border-radius: 50%; background: rgb(0 0 0 / 22%); color: rgb(255 255 255 / 85%); cursor: pointer; }
|
|
42
|
+
div[marks] button:hover:not(:disabled) { background: rgb(0 0 0 / 45%); color: #fff; }
|
|
43
|
+
div[marks] button:disabled { cursor: default; }
|
|
44
|
+
div[marks] md-icon { --md-icon-size: 16px; }
|
|
45
|
+
section { gap: 4px; padding: 10px 16px; }
|
|
46
|
+
section + section { border-top: 1px solid var(--md-sys-color-outline-variant); }
|
|
47
|
+
section:last-child { border-bottom: none; }
|
|
48
|
+
h3 { justify-content: space-between; margin: 0 0 2px; }
|
|
49
|
+
/* A slider row: its name, the line to drag, and the number -- one 22px line, the number read as text. */
|
|
50
|
+
/*
|
|
51
|
+
A slider row: its name, the line to drag, the number, and a play mark. The name column is wide enough for a joint's
|
|
52
|
+
name and unit (「j2-shoulder · deg」) and wraps rather than cutting it; a row grows with its name.
|
|
53
|
+
*/
|
|
54
|
+
div[slide] { display: grid; grid-template-columns: 120px minmax(64px, 1fr) 52px 22px; align-items: center; gap: 8px; min-height: 22px; }
|
|
55
|
+
div[slide] > span { color: var(--md-sys-color-on-surface-variant); overflow-wrap: anywhere; line-height: 1.3; }
|
|
56
|
+
div[slide] input[type='number'] { min-height: 0; height: 20px; padding: 0 2px; border: none; border-bottom: 1px solid transparent; border-radius: 0;
|
|
57
|
+
background: none; text-align: right; font-family: var(--mono-font, monospace); -moz-appearance: textfield; }
|
|
58
|
+
div[slide] input[type='number']::-webkit-inner-spin-button, div[slide] input[type='number']::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
|
|
59
|
+
div[slide] input[type='number']:hover:not(:disabled) { border-bottom-color: var(--md-sys-color-outline-variant); }
|
|
60
|
+
div[slide] input[type='number']:focus { outline: none; border-bottom-color: var(--md-sys-color-primary); }
|
|
61
|
+
div[slide] input:disabled { opacity: 0.45; }
|
|
62
|
+
div[slide] output { text-align: right; color: var(--md-sys-color-on-surface-variant); font-variant-numeric: tabular-nums; }
|
|
63
|
+
button[icon] { display: inline-grid; place-items: center; width: 22px; height: 22px; padding: 0; border: none; border-radius: 4px;
|
|
64
|
+
background: transparent; color: var(--md-sys-color-on-surface-variant); cursor: pointer; }
|
|
65
|
+
button[icon]:hover { background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface); }
|
|
66
|
+
button[icon] md-icon { --md-icon-size: 16px; }
|
|
67
|
+
button[icon][aria-pressed='true'] { color: var(--md-sys-color-primary); }
|
|
68
|
+
p[hint] { margin: 0; }
|
|
69
|
+
p[error] { margin: 0; padding: 8px 16px; color: var(--md-sys-color-error); }
|
|
70
|
+
`]
|
|
71
|
+
@property({ attribute: false }) asset?: FigureAsset
|
|
72
|
+
/** Keeps a picture of the view as the figure's thumbnail. Without it there is no picture to take. */
|
|
73
|
+
@property({ attribute: false }) keepShot?: (dataUrl: string) => Promise<unknown>
|
|
74
|
+
@query('[stage]') private stage!: HTMLElement
|
|
75
|
+
@state() private shot: '' | 'saving' | 'saved' | 'failed' = ''
|
|
76
|
+
@state() private sizes: Record<Axis, number> = { x: 1, y: 1, z: 1 }
|
|
77
|
+
@state() private values: Record<string, number> = {}
|
|
78
|
+
@state() private playing = ''
|
|
79
|
+
@state() private error = ''
|
|
80
|
+
private scene?: Scene
|
|
81
|
+
private registered?: string
|
|
82
|
+
private observer?: ResizeObserver
|
|
83
|
+
private needsScene = false
|
|
84
|
+
private played = new Set<string>()
|
|
85
|
+
/** The board the instance stands on, set when the scene is built; its centre is the grid's origin. */
|
|
86
|
+
private board = { x: 0, z: 0 }
|
|
87
|
+
|
|
88
|
+
connectedCallback() {
|
|
89
|
+
super.connectedCallback()
|
|
90
|
+
this.needsScene = true
|
|
91
|
+
if (this.hasUpdated) this.observer?.observe(this.stage)
|
|
92
|
+
this.requestUpdate()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
protected updated(changed: PropertyValues) {
|
|
96
|
+
// Reconnection and a new asset can arrive in the same update. Build exactly once.
|
|
97
|
+
if (changed.has('asset') || this.needsScene) {
|
|
98
|
+
this.needsScene = false
|
|
99
|
+
this.standUp()
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
firstUpdated() {
|
|
103
|
+
this.observer = new ResizeObserver(() => this.scene?.resize?.())
|
|
104
|
+
this.observer.observe(this.stage)
|
|
105
|
+
}
|
|
106
|
+
disconnectedCallback() {
|
|
107
|
+
super.disconnectedCallback()
|
|
108
|
+
this.observer?.disconnect()
|
|
109
|
+
this.teardown()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
render() {
|
|
113
|
+
const asset = this.asset
|
|
114
|
+
const clips = asset ? [...new Set((asset.drivers ?? []).map(d => d.clip))] : []
|
|
115
|
+
const controls = asset ? controlsOf(asset, this.values) : []
|
|
116
|
+
const shotLabel = this.shot === 'saved' ? i18next.t('figure.text.detail-thumbnail-saved') : i18next.t('figure.button.detail-save-thumbnail')
|
|
117
|
+
const fitLabel = i18next.t('button.fit-view')
|
|
118
|
+
return html`<div viewport><div stage></div>
|
|
119
|
+
${this.asset && !this.error
|
|
120
|
+
? html`<div marks>
|
|
121
|
+
<button fit aria-label=${fitLabel} title=${fitLabel} @click=${() => this.fit()}><md-icon>fit_screen</md-icon></button>
|
|
122
|
+
${this.keepShot
|
|
123
|
+
? html`<button shoot aria-label=${shotLabel} title=${shotLabel} ?disabled=${this.shot === 'saving'}
|
|
124
|
+
@click=${() => this.takeShot()}><md-icon>${this.shot === 'saved' ? 'check' : 'photo_camera'}</md-icon></button>`
|
|
125
|
+
: nothing}
|
|
126
|
+
</div>`
|
|
127
|
+
: nothing}
|
|
128
|
+
</div>
|
|
129
|
+
${this.error ? html`<p error role="alert">${this.error}</p>` : nothing}
|
|
130
|
+
${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>
|
|
133
|
+
<h3>${i18next.t('figure.label.detail-size')} · mm
|
|
134
|
+
<button icon reset aria-label=${i18next.t('figure.button.detail-reset')} title=${i18next.t('figure.button.detail-reset')}
|
|
135
|
+
@click=${() => this.reset()}><md-icon>restart_alt</md-icon></button></h3>
|
|
136
|
+
${(['x', 'y', 'z'] as const).map(axis => {
|
|
137
|
+
const input = asset.document.model.inputs.find(input => input.id === FIGURE_INSTANCE_SIZE_INPUTS[axis])
|
|
138
|
+
const fixed = !input || input.min === input.max
|
|
139
|
+
return html`<div slide><span>${axis.toUpperCase()}</span>
|
|
140
|
+
<input type="range" aria-label=${`${axis.toUpperCase()} mm`} min=${input?.min ?? this.sizes[axis]} max=${input?.max ?? this.sizes[axis]} step="any"
|
|
141
|
+
.value=${String(this.sizes[axis])} ?disabled=${fixed}
|
|
142
|
+
@input=${(e: Event) => this.resize(axis, (e.target as HTMLInputElement).valueAsNumber)}>
|
|
143
|
+
<input type="number" aria-label=${`${axis.toUpperCase()} mm value`} min=${input?.min ?? this.sizes[axis]} max=${input?.max ?? this.sizes[axis]} step="any"
|
|
144
|
+
.value=${String(this.sizes[axis])} ?disabled=${fixed}
|
|
145
|
+
@change=${(e: Event) => this.resize(axis, (e.target as HTMLInputElement).valueAsNumber)}>
|
|
146
|
+
<span></span>
|
|
147
|
+
</div>`
|
|
148
|
+
})}
|
|
149
|
+
<p hint>${i18next.t('figure.text.detail-transient')}</p>
|
|
150
|
+
</section>
|
|
151
|
+
<section><h3>${i18next.t('figure.label.motion')}</h3>
|
|
152
|
+
${controls.map(c => {
|
|
153
|
+
const clip = clipForControl(asset, c.id)
|
|
154
|
+
const on = !!clip && this.playing === clip
|
|
155
|
+
return html`<div slide><span title=${`${c.label} · ${c.unit}`}>${c.label} · ${c.unit}</span>
|
|
156
|
+
<input type="range" aria-label=${c.label} min=${c.min} max=${c.max} step=${c.step || 'any'} .value=${String(c.value)} ?disabled=${on}
|
|
157
|
+
@input=${(e: Event) => this.pose(c.id, (e.target as HTMLInputElement).valueAsNumber)}>
|
|
158
|
+
<output>${on ? i18next.t('figure.text.detail-playing')
|
|
159
|
+
: this.played.has(clip ?? '') && !(c.id in this.values) ? i18next.t('figure.text.detail-paused') : Math.round(c.value * 100) / 100}</output>
|
|
160
|
+
${clip ? this.playButton(clip) : html`<span></span>`}</div>`
|
|
161
|
+
})}
|
|
162
|
+
${/* A clip that drives no control shown here still gets its line. */ ''}
|
|
163
|
+
${clips.filter(name => !controls.some(c => clipForControl(asset, c.id) === name)).map(name => html`<div slide>
|
|
164
|
+
<span title=${name}>${name}</span><span></span>
|
|
165
|
+
<output>${this.playing === name ? i18next.t('figure.text.detail-playing') : ''}</output>${this.playButton(name)}</div>`)}
|
|
166
|
+
${!controls.length && !clips.length ? html`<p hint>${i18next.t('figure.text.detail-no-motion')}</p>` : nothing}
|
|
167
|
+
</section>` : nothing}`
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The view as it stands -- turned, zoomed and sized by the person -- as the card's picture, at the size and in the
|
|
172
|
+
* format the modeller's own picture uses (`thumbnail.ts`). Nothing is taken when the view cannot be drawn.
|
|
173
|
+
*/
|
|
174
|
+
private async takeShot() {
|
|
175
|
+
const layer = this.scene?.root
|
|
176
|
+
if (!this.keepShot || !layer?.snapshot3d) return
|
|
177
|
+
this.shot = 'saving'
|
|
178
|
+
try {
|
|
179
|
+
const url = await layer.snapshot3d(480, 360, 'image/webp', 0.85)
|
|
180
|
+
if (typeof url !== 'string' || !url.startsWith('data:')) throw Error('no picture')
|
|
181
|
+
await this.keepShot(url)
|
|
182
|
+
this.shot = 'saved'
|
|
183
|
+
setTimeout(() => this.shot === 'saved' && (this.shot = ''), 1500)
|
|
184
|
+
} catch {
|
|
185
|
+
this.shot = 'failed'
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/** The whole figure in view: the board's fit, then the 3D camera's own (as the modeller canvas fits). */
|
|
189
|
+
fit() {
|
|
190
|
+
this.scene?.fit?.('ratio')
|
|
191
|
+
this.scene?.root?.fitCameraToModel?.()
|
|
192
|
+
}
|
|
193
|
+
/** Play or pause a clip, at the end of the line it moves. */
|
|
194
|
+
private playButton(clip: string) {
|
|
195
|
+
const on = this.playing === clip
|
|
196
|
+
return html`<button icon play aria-pressed=${String(on)} aria-label=${clip} title=${clip} @click=${() => this.play(clip)}>
|
|
197
|
+
<md-icon>${on ? 'pause' : 'play_arrow'}</md-icon></button>`
|
|
198
|
+
}
|
|
199
|
+
private tell(key: string, value: unknown) {
|
|
200
|
+
this.scene?.root?.components?.[0]?.set(key, value)
|
|
201
|
+
}
|
|
202
|
+
private resize(axis: Axis, value: number) {
|
|
203
|
+
const input = this.asset?.document.model.inputs.find(input => input.id === FIGURE_INSTANCE_SIZE_INPUTS[axis])
|
|
204
|
+
if (!input || !Number.isFinite(value)) { this.requestUpdate(); return }
|
|
205
|
+
const used = Math.min(input.max, Math.max(input.min, value))
|
|
206
|
+
this.sizes = { ...this.sizes, [axis]: used }
|
|
207
|
+
/*
|
|
208
|
+
The model grows about its own centre, which stays on the board's centre -- the origin of the ground grid. A
|
|
209
|
+
board instance is placed by its corner, so the corner moves with the size. The camera stays where the person
|
|
210
|
+
turned it: refitting on every step slid the grid under the model as if the axes had moved.
|
|
211
|
+
*/
|
|
212
|
+
this.scene?.root?.components?.[0]?.set(axis === 'x' ? { width: used } : axis === 'y' ? { depth: used } : { height: used })
|
|
213
|
+
this.centre()
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The instance's box on the board's centre. The figure fits its box to the room it declares (its motion included),
|
|
217
|
+
* which can be wider than the size asked, so the box is read back rather than computed here.
|
|
218
|
+
*/
|
|
219
|
+
private centre() {
|
|
220
|
+
const instance = this.scene?.root?.components?.[0]
|
|
221
|
+
if (!instance?.model) return
|
|
222
|
+
const { width = 0, height = 0 } = instance.model
|
|
223
|
+
instance.set({ left: this.board.x / 2 - width / 2, top: this.board.z / 2 - height / 2 })
|
|
224
|
+
}
|
|
225
|
+
private pose(id: string, value: number) {
|
|
226
|
+
if (!Number.isFinite(value)) return
|
|
227
|
+
this.values = { ...this.values, [id]: value }
|
|
228
|
+
this.tell('parameters', this.values)
|
|
229
|
+
}
|
|
230
|
+
private play(name: string) {
|
|
231
|
+
this.playing = this.playing === name ? '' : name
|
|
232
|
+
if (this.playing && this.asset) {
|
|
233
|
+
this.played.add(name)
|
|
234
|
+
this.values = parametersForClip(this.asset, this.values, name)
|
|
235
|
+
this.tell('parameters', this.values)
|
|
236
|
+
}
|
|
237
|
+
this.tell('clips', Object.fromEntries([...new Set((this.asset?.drivers ?? []).map(d => d.clip))].map(key => [key, key === this.playing ? 1 : 0])))
|
|
238
|
+
}
|
|
239
|
+
private reset() {
|
|
240
|
+
if (!this.asset) return
|
|
241
|
+
// A new instance also resets driver clocks. Clearing speeds alone freezes the last pose.
|
|
242
|
+
this.standUp()
|
|
243
|
+
}
|
|
244
|
+
private standUp() {
|
|
245
|
+
this.teardown()
|
|
246
|
+
this.error = ''
|
|
247
|
+
const asset = this.asset
|
|
248
|
+
if (!asset) return
|
|
249
|
+
this.values = {}
|
|
250
|
+
this.playing = ''
|
|
251
|
+
this.shot = ''
|
|
252
|
+
this.played.clear()
|
|
253
|
+
try {
|
|
254
|
+
compileFigureAsset(asset)
|
|
255
|
+
if (!asset.appearance.length) throw Error(i18next.t('figure.text.preview-needs-a-part'))
|
|
256
|
+
this.sizes = authoredSizeOf(asset)
|
|
257
|
+
const type = `figure-detail-${crypto.randomUUID()}`
|
|
258
|
+
registerFigure(type, asset)
|
|
259
|
+
this.registered = type
|
|
260
|
+
const size = this.sizes
|
|
261
|
+
this.board = { x: size.x * 2, z: size.z * 2 }
|
|
262
|
+
this.scene = create({ target: this.stage, mode: 0, model: {
|
|
263
|
+
type: 'model-layer', width: size.x * 2, height: size.z * 2,
|
|
264
|
+
depth: previewBoardDepth({ placement: asset.placement, base: { y: size.y } }, DEFAULT_VIEW.ceilingHeight, 1),
|
|
265
|
+
threed: true, sky: 'color', ...sceneLook(DEFAULT_VIEW),
|
|
266
|
+
placement: DEFAULT_VIEW.placement, heights: { floor: 0, ceiling: DEFAULT_VIEW.ceilingHeight },
|
|
267
|
+
pixelRatio: Math.min(3, (window.devicePixelRatio || 1) * 2),
|
|
268
|
+
components: [{ type, id: 'detail-instance', left: size.x / 2, top: size.z / 2, width: size.x, height: size.z, depth: size.y }]
|
|
269
|
+
} }) as Scene
|
|
270
|
+
this.centre()
|
|
271
|
+
this.scene.resize?.()
|
|
272
|
+
this.fit()
|
|
273
|
+
} catch (error) {
|
|
274
|
+
this.error = (error as Error).message
|
|
275
|
+
this.teardown()
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
private teardown() {
|
|
279
|
+
this.scene?.dispose?.()
|
|
280
|
+
this.scene = undefined
|
|
281
|
+
if (this.registered) unregisterFigure(this.registered)
|
|
282
|
+
this.registered = undefined
|
|
283
|
+
}
|
|
284
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { css, html, LitElement, nothing } from 'lit'
|
|
2
|
+
import { customElement, property } from 'lit/decorators.js'
|
|
3
|
+
|
|
4
|
+
import { i18next, localize } from '@operato/i18n'
|
|
5
|
+
import type { FigureAsset } from '@hatiolab/figure-model'
|
|
6
|
+
|
|
7
|
+
import { detailFactsOf, type DetailFactsRow } from './detail-facts.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What a figure is, as labelled lines under its live canvas: category, tags, placement, the sizes a board may give it,
|
|
11
|
+
* what it does, its places (one line each: name · role · accepts · how many), joints, extensions, and the score and the
|
|
12
|
+
* last change when the row keeps them. operato-figure's catalogue preview and a board server's release compare show it
|
|
13
|
+
* alike; it goes into figure-asset-viewer's `facts` slot.
|
|
14
|
+
*/
|
|
15
|
+
@customElement('figure-facts-list')
|
|
16
|
+
export class FigureFactsList extends localize(i18next)(LitElement) {
|
|
17
|
+
static styles = css`
|
|
18
|
+
:host {
|
|
19
|
+
display: block;
|
|
20
|
+
border-bottom: 1px solid var(--md-sys-color-outline-variant);
|
|
21
|
+
}
|
|
22
|
+
dl {
|
|
23
|
+
display: grid;
|
|
24
|
+
grid-template-columns: 96px minmax(0, 1fr);
|
|
25
|
+
gap: 3px 12px;
|
|
26
|
+
margin: 0;
|
|
27
|
+
padding: 10px 16px;
|
|
28
|
+
line-height: 1.45;
|
|
29
|
+
}
|
|
30
|
+
dt {
|
|
31
|
+
overflow: hidden;
|
|
32
|
+
text-overflow: ellipsis;
|
|
33
|
+
white-space: nowrap;
|
|
34
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
35
|
+
}
|
|
36
|
+
dd {
|
|
37
|
+
margin: 0;
|
|
38
|
+
overflow-wrap: anywhere;
|
|
39
|
+
}
|
|
40
|
+
dd small {
|
|
41
|
+
display: block;
|
|
42
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
43
|
+
}
|
|
44
|
+
`
|
|
45
|
+
|
|
46
|
+
@property({ attribute: false }) asset?: FigureAsset
|
|
47
|
+
@property({ attribute: false }) row?: DetailFactsRow
|
|
48
|
+
|
|
49
|
+
render() {
|
|
50
|
+
if (!this.asset || !this.row) return nothing
|
|
51
|
+
const facts = detailFactsOf(this.asset, this.row, (key, params) => i18next.t(key, params))
|
|
52
|
+
return html`<dl>
|
|
53
|
+
${facts.map(
|
|
54
|
+
fact => html`<dt title=${fact.label}>${fact.label}</dt>
|
|
55
|
+
<dd>${fact.value}${fact.lines?.map(line => html`<small>${line}</small>`)}</dd>`
|
|
56
|
+
)}
|
|
57
|
+
</dl>`
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import '@material/web/icon/icon.js'
|
|
2
|
+
|
|
3
|
+
import { css, html, LitElement } from 'lit'
|
|
4
|
+
import { customElement, property } from 'lit/decorators.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A figure without a thumbnail: a faint 3D mark filling most of the picture's height, no text (the sentence is the
|
|
8
|
+
* label a screen reader reads). Its own element because a card draws its picture inside the card, out of the page's
|
|
9
|
+
* styles. operato-figure's catalog card (figure-ui figure-thumb) draws the same mark at the same size.
|
|
10
|
+
*/
|
|
11
|
+
@customElement('figure-thumb-mark')
|
|
12
|
+
export class FigureThumbMark extends LitElement {
|
|
13
|
+
static styles = css`
|
|
14
|
+
:host {
|
|
15
|
+
display: grid;
|
|
16
|
+
place-items: center;
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 100%;
|
|
19
|
+
container-type: size;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
md-icon {
|
|
23
|
+
--md-icon-size: 60cqh;
|
|
24
|
+
color: var(--md-sys-color-on-surface);
|
|
25
|
+
opacity: 0.12;
|
|
26
|
+
}
|
|
27
|
+
`
|
|
28
|
+
|
|
29
|
+
@property() label = ''
|
|
30
|
+
|
|
31
|
+
render() {
|
|
32
|
+
return html`<md-icon role="img" aria-label=${this.label}>deployed_code</md-icon>`
|
|
33
|
+
}
|
|
34
|
+
}
|