@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,28 @@
|
|
|
1
|
+
import type { FigureAsset } from '@hatiolab/figure-model';
|
|
2
|
+
export interface Control {
|
|
3
|
+
id: string;
|
|
4
|
+
/** The name a person reads, or the id when none is given. */
|
|
5
|
+
label: string;
|
|
6
|
+
named: boolean;
|
|
7
|
+
unit: string;
|
|
8
|
+
min: number;
|
|
9
|
+
max: number;
|
|
10
|
+
/** Where it stands in the editor now -- the pose being looked at, not yet the default. */
|
|
11
|
+
value: number;
|
|
12
|
+
/** Where it starts when the figure is placed: the default pose. */
|
|
13
|
+
start: number;
|
|
14
|
+
/** Seconds to travel the whole range, 0 when it moves at once. */
|
|
15
|
+
sweep: number;
|
|
16
|
+
/** A slider step: one degree for an angle, else a hundredth of the range. */
|
|
17
|
+
step: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function controlsOf(asset: FigureAsset, values?: Record<string, number>): Control[];
|
|
20
|
+
/** Whether the pose being looked at differs from the default pose -- only then is there a pose to keep. */
|
|
21
|
+
export declare const poseDiffers: (controls: readonly Control[]) => boolean;
|
|
22
|
+
/** The current pose as the defaults: one `set-state-defaults` edit. */
|
|
23
|
+
export declare const poseAsDefault: (controls: readonly Control[]) => {
|
|
24
|
+
kind: "set-state-defaults";
|
|
25
|
+
values: {
|
|
26
|
+
[k: string]: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function controlsOf(asset, values = {}) {
|
|
2
|
+
return asset.document.model.inputs
|
|
3
|
+
.filter(input => input.role === 'state')
|
|
4
|
+
.map(input => {
|
|
5
|
+
const policy = asset.stateInputs?.[input.id];
|
|
6
|
+
const start = asset.stateDefaults[input.id] ?? input.min;
|
|
7
|
+
return {
|
|
8
|
+
id: input.id,
|
|
9
|
+
label: policy?.label ?? input.id,
|
|
10
|
+
named: !!policy?.label,
|
|
11
|
+
unit: input.unit,
|
|
12
|
+
min: input.min,
|
|
13
|
+
max: input.max,
|
|
14
|
+
value: values[input.id] ?? start,
|
|
15
|
+
start,
|
|
16
|
+
sweep: policy?.sweep ?? 0,
|
|
17
|
+
step: input.unit === 'deg' ? 1 : (input.max - input.min) / 100
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** Whether the pose being looked at differs from the default pose -- only then is there a pose to keep. */
|
|
22
|
+
export const poseDiffers = (controls) => controls.some(c => c.value !== c.start);
|
|
23
|
+
/** The current pose as the defaults: one `set-state-defaults` edit. */
|
|
24
|
+
export const poseAsDefault = (controls) => ({
|
|
25
|
+
kind: 'set-state-defaults',
|
|
26
|
+
values: Object.fromEntries(controls.map(c => [c.id, c.value]))
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controls.js","sourceRoot":"","sources":["../client/controls.ts"],"names":[],"mappings":"AAyBA,MAAM,UAAU,UAAU,CAAC,KAAkB,EAAE,SAAiC,EAAE;IAChF,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM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AAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;CAC/D,CAAC,CAAA","sourcesContent":["import type { FigureAsset } from '@hatiolab/figure-model'\n\n/*\n * The figure's controls -- its state inputs: the values a board or a connector sets to pose\n * the figure (a lift height, a joint angle, a gripper opening). Kept apart from the element so the reading is tested\n * without a browser.\n */\nexport interface Control {\n id: string\n /** The name a person reads, or the id when none is given. */\n label: string\n named: boolean\n unit: string\n min: number\n max: number\n /** Where it stands in the editor now -- the pose being looked at, not yet the default. */\n value: number\n /** Where it starts when the figure is placed: the default pose. */\n start: number\n /** Seconds to travel the whole range, 0 when it moves at once. */\n sweep: number\n /** A slider step: one degree for an angle, else a hundredth of the range. */\n step: number\n}\n\nexport function controlsOf(asset: FigureAsset, values: Record<string, number> = {}): Control[] {\n return asset.document.model.inputs\n .filter(input => input.role === 'state')\n .map(input => {\n const policy = asset.stateInputs?.[input.id]\n const start = asset.stateDefaults[input.id] ?? input.min\n return {\n id: input.id,\n label: policy?.label ?? input.id,\n named: !!policy?.label,\n unit: input.unit,\n min: input.min,\n max: input.max,\n value: values[input.id] ?? start,\n start,\n sweep: policy?.sweep ?? 0,\n step: input.unit === 'deg' ? 1 : (input.max - input.min) / 100\n }\n })\n}\n\n/** Whether the pose being looked at differs from the default pose -- only then is there a pose to keep. */\nexport const poseDiffers = (controls: readonly Control[]) => controls.some(c => c.value !== c.start)\n\n/** The current pose as the defaults: one `set-state-defaults` edit. */\nexport const poseAsDefault = (controls: readonly Control[]) => ({\n kind: 'set-state-defaults' as const,\n values: Object.fromEntries(controls.map(c => [c.id, c.value]))\n})\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type FigureAsset } from '@hatiolab/figure-model';
|
|
2
|
+
type Say = (key: string, params?: Record<string, unknown>) => string;
|
|
3
|
+
/**
|
|
4
|
+
* What the facts read off a figure's row besides its asset. figure-ui's catalogue row and figure-library's release both
|
|
5
|
+
* give it. `score` absent means the caller does not keep one (no line); null means not measured yet.
|
|
6
|
+
*/
|
|
7
|
+
export interface DetailFactsRow {
|
|
8
|
+
category?: string | null;
|
|
9
|
+
tags?: string[] | null;
|
|
10
|
+
score?: number | null;
|
|
11
|
+
updatedAt?: string | Date | null;
|
|
12
|
+
updater?: {
|
|
13
|
+
name?: string | null;
|
|
14
|
+
} | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A place in words, as every screen that lists places says it: its role (파지 · 안착), what it accepts and how many it
|
|
18
|
+
* holds -- 「파지 · 받는 것 BOX, WORKPIECE · 최대 1」.
|
|
19
|
+
*/
|
|
20
|
+
export declare function placeTerms(place: {
|
|
21
|
+
role: string;
|
|
22
|
+
accepts: readonly string[];
|
|
23
|
+
capacity: number;
|
|
24
|
+
}, say: Say): string;
|
|
25
|
+
/** One line of what the preview tells about a figure: its label, its value, and for places one line each. */
|
|
26
|
+
export interface DetailFact {
|
|
27
|
+
key: string;
|
|
28
|
+
label: string;
|
|
29
|
+
value: string;
|
|
30
|
+
lines?: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What a figure is, read off its asset and its row, in the words the modeller's properties already use. Nothing is
|
|
34
|
+
* defaulted: what the figure does not say reads as a dash, and a score not yet measured is said so, not 0.
|
|
35
|
+
*/
|
|
36
|
+
export declare function detailFactsOf(asset: FigureAsset, row: DetailFactsRow, say: Say): DetailFact[];
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { FIGURE_INSTANCE_SIZE_INPUTS, figureBindingsOf, figureJointsOf } from '@hatiolab/figure-model';
|
|
2
|
+
import { rungOf } from './capability-rung.js';
|
|
3
|
+
import { authoredSizeOf } from './preview-model.js';
|
|
4
|
+
/**
|
|
5
|
+
* A place in words, as every screen that lists places says it: its role (파지 · 안착), what it accepts and how many it
|
|
6
|
+
* holds -- 「파지 · 받는 것 BOX, WORKPIECE · 최대 1」.
|
|
7
|
+
*/
|
|
8
|
+
export function placeTerms(place, say) {
|
|
9
|
+
return [
|
|
10
|
+
say(`figure.label.role-${place.role}`),
|
|
11
|
+
say('figure.text.place-accepts', { accepts: place.accepts.join(', ') }),
|
|
12
|
+
say('figure.label.place-holds', { count: place.capacity })
|
|
13
|
+
].join(' · ');
|
|
14
|
+
}
|
|
15
|
+
const number = (n) => Math.round(n).toLocaleString();
|
|
16
|
+
/**
|
|
17
|
+
* What a figure is, read off its asset and its row, in the words the modeller's properties already use. Nothing is
|
|
18
|
+
* defaulted: what the figure does not say reads as a dash, and a score not yet measured is said so, not 0.
|
|
19
|
+
*/
|
|
20
|
+
export function detailFactsOf(asset, row, say) {
|
|
21
|
+
const facts = [];
|
|
22
|
+
const dash = '—';
|
|
23
|
+
facts.push({ key: 'category', label: say('figure.label.category'), value: row.category || dash });
|
|
24
|
+
facts.push({ key: 'tags', label: say('figure.label.tags'), value: row.tags?.length ? row.tags.join(', ') : dash });
|
|
25
|
+
facts.push({ key: 'placement', label: say('figure.label.figure-placement'), value: asset.placement ? say(`figure.label.placement-${asset.placement}`) : dash });
|
|
26
|
+
/* The sizes a board may give it: a range on an axis that opens one, the authored size on one that is fixed. */
|
|
27
|
+
const base = authoredSizeOf(asset);
|
|
28
|
+
const axes = ['x', 'y', 'z'].map(axis => {
|
|
29
|
+
const input = asset.document.model.inputs.find(input => input.id === FIGURE_INSTANCE_SIZE_INPUTS[axis]);
|
|
30
|
+
const open = input && Number.isFinite(input.min) && Number.isFinite(input.max) && input.max > input.min;
|
|
31
|
+
return `${axis.toUpperCase()} ${open ? `${number(input.min)}–${number(input.max)}` : number(base[axis])}`;
|
|
32
|
+
});
|
|
33
|
+
facts.push({ key: 'size', label: say('figure.label.instance-range'), value: `${axes.join(' · ')} mm` });
|
|
34
|
+
if (asset.sizing === 'uniform')
|
|
35
|
+
facts.push({ key: 'sizing', label: say('figure.label.sizing-rule'), value: say('figure.label.sizing-uniform') });
|
|
36
|
+
const names = asset.document.capabilities.names ?? [];
|
|
37
|
+
const rung = rungOf(names);
|
|
38
|
+
facts.push({ key: 'does', label: say('figure.label.what-this-does'), value: rung ? say(`figure.label.rung-${rung}`) : names.join(' · ') });
|
|
39
|
+
const places = figureBindingsOf(asset);
|
|
40
|
+
facts.push({
|
|
41
|
+
key: 'places',
|
|
42
|
+
label: say('figure.label.places'),
|
|
43
|
+
value: places.length ? String(places.length) : dash,
|
|
44
|
+
lines: places.map(place => `${place.label} · ${placeTerms(place, say)}`)
|
|
45
|
+
});
|
|
46
|
+
facts.push({ key: 'joints', label: say('figure.label.joint'), value: String(figureJointsOf(asset).joints.length) });
|
|
47
|
+
const extensions = Object.keys(asset.extensions ?? {});
|
|
48
|
+
if (extensions.length)
|
|
49
|
+
facts.push({ key: 'extensions', label: say('figure.label.extensions'), value: extensions.join(', ') });
|
|
50
|
+
if ('score' in row)
|
|
51
|
+
facts.push({ key: 'maturity', label: say('figure.label.maturity'), value: row.score == null ? say('figure.text.not-measured-yet') : String(Math.round(row.score)) });
|
|
52
|
+
if (row.updatedAt) {
|
|
53
|
+
const at = new Date(row.updatedAt).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' });
|
|
54
|
+
facts.push({ key: 'updated', label: say('field.updated_at'), value: row.updater?.name ? `${at} · ${row.updater.name}` : at });
|
|
55
|
+
}
|
|
56
|
+
return facts;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=detail-facts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detail-facts.js","sourceRoot":"","sources":["../client/detail-facts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,cAAc,EAAoB,MAAM,wBAAwB,CAAA;AAExH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAgBnD;;;GAGG;AACH,MAAM,U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GAAG,CAAC,yBAAyB,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAE7H,IAAI,OAAO,IAAI,GAAG;QAChB,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,CAAC,uBAAuB,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAA;IACtK,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;QAClB,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;QACzG,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC,kBAAkB,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAC/H,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { FIGURE_INSTANCE_SIZE_INPUTS, figureBindingsOf, figureJointsOf, type FigureAsset } from '@hatiolab/figure-model'\n\nimport { rungOf } from './capability-rung.js'\nimport { authoredSizeOf } from './preview-model.js'\n\ntype Say = (key: string, params?: Record<string, unknown>) => string\n\n/**\n * What the facts read off a figure's row besides its asset. figure-ui's catalogue row and figure-library's release both\n * give it. `score` absent means the caller does not keep one (no line); null means not measured yet.\n */\nexport interface DetailFactsRow {\n category?: string | null\n tags?: string[] | null\n score?: number | null\n updatedAt?: string | Date | null\n updater?: { name?: string | null } | null\n}\n\n/**\n * A place in words, as every screen that lists places says it: its role (파지 · 안착), what it accepts and how many it\n * holds -- 「파지 · 받는 것 BOX, WORKPIECE · 최대 1」.\n */\nexport function placeTerms(place: { role: string; accepts: readonly string[]; capacity: number }, say: Say): string {\n return [\n say(`figure.label.role-${place.role}`),\n say('figure.text.place-accepts', { accepts: place.accepts.join(', ') }),\n say('figure.label.place-holds', { count: place.capacity })\n ].join(' · ')\n}\n\n/** One line of what the preview tells about a figure: its label, its value, and for places one line each. */\nexport interface DetailFact {\n key: string\n label: string\n value: string\n lines?: string[]\n}\n\nconst number = (n: number) => Math.round(n).toLocaleString()\n\n/**\n * What a figure is, read off its asset and its row, in the words the modeller's properties already use. Nothing is\n * defaulted: what the figure does not say reads as a dash, and a score not yet measured is said so, not 0.\n */\nexport function detailFactsOf(asset: FigureAsset, row: DetailFactsRow, say: Say): DetailFact[] {\n const facts: DetailFact[] = []\n const dash = '—'\n\n facts.push({ key: 'category', label: say('figure.label.category'), value: row.category || dash })\n facts.push({ key: 'tags', label: say('figure.label.tags'), value: row.tags?.length ? row.tags.join(', ') : dash })\n facts.push({ key: 'placement', label: say('figure.label.figure-placement'), value: asset.placement ? say(`figure.label.placement-${asset.placement}`) : dash })\n\n /* The sizes a board may give it: a range on an axis that opens one, the authored size on one that is fixed. */\n const base = authoredSizeOf(asset)\n const axes = (['x', 'y', 'z'] as const).map(axis => {\n const input = asset.document.model.inputs.find(input => input.id === FIGURE_INSTANCE_SIZE_INPUTS[axis])\n const open = input && Number.isFinite(input.min) && Number.isFinite(input.max) && input.max > input.min\n return `${axis.toUpperCase()} ${open ? `${number(input!.min)}–${number(input!.max)}` : number(base[axis])}`\n })\n facts.push({ key: 'size', label: say('figure.label.instance-range'), value: `${axes.join(' · ')} mm` })\n if (asset.sizing === 'uniform') facts.push({ key: 'sizing', label: say('figure.label.sizing-rule'), value: say('figure.label.sizing-uniform') })\n\n const names = asset.document.capabilities.names ?? []\n const rung = rungOf(names)\n facts.push({ key: 'does', label: say('figure.label.what-this-does'), value: rung ? say(`figure.label.rung-${rung}`) : names.join(' · ') })\n\n const places = figureBindingsOf(asset)\n facts.push({\n key: 'places',\n label: say('figure.label.places'),\n value: places.length ? String(places.length) : dash,\n lines: places.map(place => `${place.label} · ${placeTerms(place, say)}`)\n })\n\n facts.push({ key: 'joints', label: say('figure.label.joint'), value: String(figureJointsOf(asset).joints.length) })\n const extensions = Object.keys((asset as { extensions?: Record<string, unknown> }).extensions ?? {})\n if (extensions.length) facts.push({ key: 'extensions', label: say('figure.label.extensions'), value: extensions.join(', ') })\n\n if ('score' in row)\n facts.push({ key: 'maturity', label: say('figure.label.maturity'), value: row.score == null ? say('figure.text.not-measured-yet') : String(Math.round(row.score)) })\n if (row.updatedAt) {\n const at = new Date(row.updatedAt).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })\n facts.push({ key: 'updated', label: say('field.updated_at'), value: row.updater?.name ? `${at} · ${row.updater.name}` : at })\n }\n return facts\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FigureAsset } from '@hatiolab/figure-model';
|
|
2
|
+
/** External values win over drivers; release only the controls owned by the chosen clip. */
|
|
3
|
+
export declare function parametersForClip(asset: FigureAsset, values: Record<string, number>, clip: string): {
|
|
4
|
+
[k: string]: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function clipForControl(asset: FigureAsset, id: string): string | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** External values win over drivers; release only the controls owned by the chosen clip. */
|
|
2
|
+
export function parametersForClip(asset, values, clip) {
|
|
3
|
+
const driven = new Set((asset.drivers ?? []).filter(d => d.clip === clip).map(d => d.state));
|
|
4
|
+
return Object.fromEntries(Object.entries(values).filter(([id]) => !driven.has(id)));
|
|
5
|
+
}
|
|
6
|
+
export function clipForControl(asset, id) {
|
|
7
|
+
return asset.drivers?.find(d => d.state === id)?.clip;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=detail-motion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detail-motion.js","sourceRoot":"","sources":["../client/detail-motion.ts"],"names":[],"mappings":"AAEA,4FAA4F;AAC5F,MAAM,UAAU,iBAAiB,CAAC,KAAkB,EAAE,MAA8B,EAAE,IAAY;IAChG,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;IAC5F,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AACrF,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAkB,EAAE,EAAU;IAC3D,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,EAAE,IAAI,CAAA;AACvD,CAAC","sourcesContent":["import type { FigureAsset } from '@hatiolab/figure-model'\n\n/** External values win over drivers; release only the controls owned by the chosen clip. */\nexport function parametersForClip(asset: FigureAsset, values: Record<string, number>, clip: string) {\n const driven = new Set((asset.drivers ?? []).filter(d => d.clip === clip).map(d => d.state))\n return Object.fromEntries(Object.entries(values).filter(([id]) => !driven.has(id)))\n}\n\nexport function clipForControl(asset: FigureAsset, id: string) {\n return asset.drivers?.find(d => d.state === id)?.clip\n}\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import '@material/web/icon/icon.js';
|
|
2
|
+
import { LitElement, type PropertyValues } from 'lit';
|
|
3
|
+
import { type FigureAsset } from '@hatiolab/figure-model';
|
|
4
|
+
declare const FigureAssetViewer_base: (new (...args: any[]) => LitElement) & typeof LitElement;
|
|
5
|
+
/** A single board instance. Sizes and poses are transient, and never change the asset or call a mutation. */
|
|
6
|
+
export declare class FigureAssetViewer extends FigureAssetViewer_base {
|
|
7
|
+
static styles: import("lit").CSSResult[];
|
|
8
|
+
asset?: FigureAsset;
|
|
9
|
+
/** Keeps a picture of the view as the figure's thumbnail. Without it there is no picture to take. */
|
|
10
|
+
keepShot?: (dataUrl: string) => Promise<unknown>;
|
|
11
|
+
private stage;
|
|
12
|
+
private shot;
|
|
13
|
+
private sizes;
|
|
14
|
+
private values;
|
|
15
|
+
private playing;
|
|
16
|
+
private error;
|
|
17
|
+
private scene?;
|
|
18
|
+
private registered?;
|
|
19
|
+
private observer?;
|
|
20
|
+
private needsScene;
|
|
21
|
+
private played;
|
|
22
|
+
/** The board the instance stands on, set when the scene is built; its centre is the grid's origin. */
|
|
23
|
+
private board;
|
|
24
|
+
connectedCallback(): void;
|
|
25
|
+
protected updated(changed: PropertyValues): void;
|
|
26
|
+
firstUpdated(): void;
|
|
27
|
+
disconnectedCallback(): void;
|
|
28
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
29
|
+
/**
|
|
30
|
+
* The view as it stands -- turned, zoomed and sized by the person -- as the card's picture, at the size and in the
|
|
31
|
+
* format the modeller's own picture uses (`thumbnail.ts`). Nothing is taken when the view cannot be drawn.
|
|
32
|
+
*/
|
|
33
|
+
private takeShot;
|
|
34
|
+
/** The whole figure in view: the board's fit, then the 3D camera's own (as the modeller canvas fits). */
|
|
35
|
+
fit(): void;
|
|
36
|
+
/** Play or pause a clip, at the end of the line it moves. */
|
|
37
|
+
private playButton;
|
|
38
|
+
private tell;
|
|
39
|
+
private resize;
|
|
40
|
+
/**
|
|
41
|
+
* The instance's box on the board's centre. The figure fits its box to the room it declares (its motion included),
|
|
42
|
+
* which can be wider than the size asked, so the box is read back rather than computed here.
|
|
43
|
+
*/
|
|
44
|
+
private centre;
|
|
45
|
+
private pose;
|
|
46
|
+
private play;
|
|
47
|
+
private reset;
|
|
48
|
+
private standUp;
|
|
49
|
+
private teardown;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import '@material/web/icon/icon.js';
|
|
3
|
+
import { css, html, LitElement, nothing } from 'lit';
|
|
4
|
+
import { customElement, property, query, state } from 'lit/decorators.js';
|
|
5
|
+
import { i18next, localize } from '@operato/i18n';
|
|
6
|
+
import { compileFigureAsset, FIGURE_INSTANCE_SIZE_INPUTS } from '@hatiolab/figure-model';
|
|
7
|
+
import { create, registerFigure, unregisterFigure } from '@hatiolab/things-scene';
|
|
8
|
+
import { authoredSizeOf } from './preview-model.js';
|
|
9
|
+
import { controlsOf } from './controls.js';
|
|
10
|
+
import { DEFAULT_VIEW, previewBoardDepth, sceneLook } from './figure-view.js';
|
|
11
|
+
import { SidePanelStyles } from './side-panel-styles.js';
|
|
12
|
+
import { clipForControl, parametersForClip } from './detail-motion.js';
|
|
13
|
+
/** A single board instance. Sizes and poses are transient, and never change the asset or call a mutation. */
|
|
14
|
+
let FigureAssetViewer = class FigureAssetViewer extends localize(i18next)(LitElement) {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
this.shot = '';
|
|
18
|
+
this.sizes = { x: 1, y: 1, z: 1 };
|
|
19
|
+
this.values = {};
|
|
20
|
+
this.playing = '';
|
|
21
|
+
this.error = '';
|
|
22
|
+
this.needsScene = false;
|
|
23
|
+
this.played = new Set();
|
|
24
|
+
/** The board the instance stands on, set when the scene is built; its centre is the grid's origin. */
|
|
25
|
+
this.board = { x: 0, z: 0 };
|
|
26
|
+
}
|
|
27
|
+
/* The modeller's side panel look (SidePanelStyles); only the viewport and the slider rows are this element's. */
|
|
28
|
+
static { this.styles = [SidePanelStyles, css `
|
|
29
|
+
:host { display: block; min-width: 0; }
|
|
30
|
+
/* The card's own 4:3, so the picture taken is what is seen. */
|
|
31
|
+
[viewport] { aspect-ratio: 4 / 3; position: relative; background: #858585; }
|
|
32
|
+
[stage] { position: absolute; inset: 0; width: 100%; height: 100%; }
|
|
33
|
+
/*
|
|
34
|
+
The view's own marks in its corner, not buttons beside it: fit the whole figure in view (the modeller's fit, the
|
|
35
|
+
same icon and words), and taking the picture when the screen keeps one.
|
|
36
|
+
*/
|
|
37
|
+
div[marks] { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; }
|
|
38
|
+
div[marks] button { display: inline-grid; place-items: center; width: 28px; height: 28px;
|
|
39
|
+
padding: 0; border: none; border-radius: 50%; background: rgb(0 0 0 / 22%); color: rgb(255 255 255 / 85%); cursor: pointer; }
|
|
40
|
+
div[marks] button:hover:not(:disabled) { background: rgb(0 0 0 / 45%); color: #fff; }
|
|
41
|
+
div[marks] button:disabled { cursor: default; }
|
|
42
|
+
div[marks] md-icon { --md-icon-size: 16px; }
|
|
43
|
+
section { gap: 4px; padding: 10px 16px; }
|
|
44
|
+
section + section { border-top: 1px solid var(--md-sys-color-outline-variant); }
|
|
45
|
+
section:last-child { border-bottom: none; }
|
|
46
|
+
h3 { justify-content: space-between; margin: 0 0 2px; }
|
|
47
|
+
/* A slider row: its name, the line to drag, and the number -- one 22px line, the number read as text. */
|
|
48
|
+
/*
|
|
49
|
+
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
|
|
50
|
+
name and unit (「j2-shoulder · deg」) and wraps rather than cutting it; a row grows with its name.
|
|
51
|
+
*/
|
|
52
|
+
div[slide] { display: grid; grid-template-columns: 120px minmax(64px, 1fr) 52px 22px; align-items: center; gap: 8px; min-height: 22px; }
|
|
53
|
+
div[slide] > span { color: var(--md-sys-color-on-surface-variant); overflow-wrap: anywhere; line-height: 1.3; }
|
|
54
|
+
div[slide] input[type='number'] { min-height: 0; height: 20px; padding: 0 2px; border: none; border-bottom: 1px solid transparent; border-radius: 0;
|
|
55
|
+
background: none; text-align: right; font-family: var(--mono-font, monospace); -moz-appearance: textfield; }
|
|
56
|
+
div[slide] input[type='number']::-webkit-inner-spin-button, div[slide] input[type='number']::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
|
|
57
|
+
div[slide] input[type='number']:hover:not(:disabled) { border-bottom-color: var(--md-sys-color-outline-variant); }
|
|
58
|
+
div[slide] input[type='number']:focus { outline: none; border-bottom-color: var(--md-sys-color-primary); }
|
|
59
|
+
div[slide] input:disabled { opacity: 0.45; }
|
|
60
|
+
div[slide] output { text-align: right; color: var(--md-sys-color-on-surface-variant); font-variant-numeric: tabular-nums; }
|
|
61
|
+
button[icon] { display: inline-grid; place-items: center; width: 22px; height: 22px; padding: 0; border: none; border-radius: 4px;
|
|
62
|
+
background: transparent; color: var(--md-sys-color-on-surface-variant); cursor: pointer; }
|
|
63
|
+
button[icon]:hover { background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface); }
|
|
64
|
+
button[icon] md-icon { --md-icon-size: 16px; }
|
|
65
|
+
button[icon][aria-pressed='true'] { color: var(--md-sys-color-primary); }
|
|
66
|
+
p[hint] { margin: 0; }
|
|
67
|
+
p[error] { margin: 0; padding: 8px 16px; color: var(--md-sys-color-error); }
|
|
68
|
+
`]; }
|
|
69
|
+
connectedCallback() {
|
|
70
|
+
super.connectedCallback();
|
|
71
|
+
this.needsScene = true;
|
|
72
|
+
if (this.hasUpdated)
|
|
73
|
+
this.observer?.observe(this.stage);
|
|
74
|
+
this.requestUpdate();
|
|
75
|
+
}
|
|
76
|
+
updated(changed) {
|
|
77
|
+
// Reconnection and a new asset can arrive in the same update. Build exactly once.
|
|
78
|
+
if (changed.has('asset') || this.needsScene) {
|
|
79
|
+
this.needsScene = false;
|
|
80
|
+
this.standUp();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
firstUpdated() {
|
|
84
|
+
this.observer = new ResizeObserver(() => this.scene?.resize?.());
|
|
85
|
+
this.observer.observe(this.stage);
|
|
86
|
+
}
|
|
87
|
+
disconnectedCallback() {
|
|
88
|
+
super.disconnectedCallback();
|
|
89
|
+
this.observer?.disconnect();
|
|
90
|
+
this.teardown();
|
|
91
|
+
}
|
|
92
|
+
render() {
|
|
93
|
+
const asset = this.asset;
|
|
94
|
+
const clips = asset ? [...new Set((asset.drivers ?? []).map(d => d.clip))] : [];
|
|
95
|
+
const controls = asset ? controlsOf(asset, this.values) : [];
|
|
96
|
+
const shotLabel = this.shot === 'saved' ? i18next.t('figure.text.detail-thumbnail-saved') : i18next.t('figure.button.detail-save-thumbnail');
|
|
97
|
+
const fitLabel = i18next.t('button.fit-view');
|
|
98
|
+
return html `<div viewport><div stage></div>
|
|
99
|
+
${this.asset && !this.error
|
|
100
|
+
? html `<div marks>
|
|
101
|
+
<button fit aria-label=${fitLabel} title=${fitLabel} @click=${() => this.fit()}><md-icon>fit_screen</md-icon></button>
|
|
102
|
+
${this.keepShot
|
|
103
|
+
? html `<button shoot aria-label=${shotLabel} title=${shotLabel} ?disabled=${this.shot === 'saving'}
|
|
104
|
+
@click=${() => this.takeShot()}><md-icon>${this.shot === 'saved' ? 'check' : 'photo_camera'}</md-icon></button>`
|
|
105
|
+
: nothing}
|
|
106
|
+
</div>`
|
|
107
|
+
: nothing}
|
|
108
|
+
</div>
|
|
109
|
+
${this.error ? html `<p error role="alert">${this.error}</p>` : nothing}
|
|
110
|
+
${this.shot === 'failed' ? html `<p error role="alert">${i18next.t('figure.text.detail-thumbnail-failed')}</p>` : nothing}
|
|
111
|
+
<slot name="facts"></slot>
|
|
112
|
+
${asset ? html `<section>
|
|
113
|
+
<h3>${i18next.t('figure.label.detail-size')} · mm
|
|
114
|
+
<button icon reset aria-label=${i18next.t('figure.button.detail-reset')} title=${i18next.t('figure.button.detail-reset')}
|
|
115
|
+
@click=${() => this.reset()}><md-icon>restart_alt</md-icon></button></h3>
|
|
116
|
+
${['x', 'y', 'z'].map(axis => {
|
|
117
|
+
const input = asset.document.model.inputs.find(input => input.id === FIGURE_INSTANCE_SIZE_INPUTS[axis]);
|
|
118
|
+
const fixed = !input || input.min === input.max;
|
|
119
|
+
return html `<div slide><span>${axis.toUpperCase()}</span>
|
|
120
|
+
<input type="range" aria-label=${`${axis.toUpperCase()} mm`} min=${input?.min ?? this.sizes[axis]} max=${input?.max ?? this.sizes[axis]} step="any"
|
|
121
|
+
.value=${String(this.sizes[axis])} ?disabled=${fixed}
|
|
122
|
+
@input=${(e) => this.resize(axis, e.target.valueAsNumber)}>
|
|
123
|
+
<input type="number" aria-label=${`${axis.toUpperCase()} mm value`} min=${input?.min ?? this.sizes[axis]} max=${input?.max ?? this.sizes[axis]} step="any"
|
|
124
|
+
.value=${String(this.sizes[axis])} ?disabled=${fixed}
|
|
125
|
+
@change=${(e) => this.resize(axis, e.target.valueAsNumber)}>
|
|
126
|
+
<span></span>
|
|
127
|
+
</div>`;
|
|
128
|
+
})}
|
|
129
|
+
<p hint>${i18next.t('figure.text.detail-transient')}</p>
|
|
130
|
+
</section>
|
|
131
|
+
<section><h3>${i18next.t('figure.label.motion')}</h3>
|
|
132
|
+
${controls.map(c => {
|
|
133
|
+
const clip = clipForControl(asset, c.id);
|
|
134
|
+
const on = !!clip && this.playing === clip;
|
|
135
|
+
return html `<div slide><span title=${`${c.label} · ${c.unit}`}>${c.label} · ${c.unit}</span>
|
|
136
|
+
<input type="range" aria-label=${c.label} min=${c.min} max=${c.max} step=${c.step || 'any'} .value=${String(c.value)} ?disabled=${on}
|
|
137
|
+
@input=${(e) => this.pose(c.id, e.target.valueAsNumber)}>
|
|
138
|
+
<output>${on ? i18next.t('figure.text.detail-playing')
|
|
139
|
+
: this.played.has(clip ?? '') && !(c.id in this.values) ? i18next.t('figure.text.detail-paused') : Math.round(c.value * 100) / 100}</output>
|
|
140
|
+
${clip ? this.playButton(clip) : html `<span></span>`}</div>`;
|
|
141
|
+
})}
|
|
142
|
+
${ /* A clip that drives no control shown here still gets its line. */''}
|
|
143
|
+
${clips.filter(name => !controls.some(c => clipForControl(asset, c.id) === name)).map(name => html `<div slide>
|
|
144
|
+
<span title=${name}>${name}</span><span></span>
|
|
145
|
+
<output>${this.playing === name ? i18next.t('figure.text.detail-playing') : ''}</output>${this.playButton(name)}</div>`)}
|
|
146
|
+
${!controls.length && !clips.length ? html `<p hint>${i18next.t('figure.text.detail-no-motion')}</p>` : nothing}
|
|
147
|
+
</section>` : nothing}`;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The view as it stands -- turned, zoomed and sized by the person -- as the card's picture, at the size and in the
|
|
151
|
+
* format the modeller's own picture uses (`thumbnail.ts`). Nothing is taken when the view cannot be drawn.
|
|
152
|
+
*/
|
|
153
|
+
async takeShot() {
|
|
154
|
+
const layer = this.scene?.root;
|
|
155
|
+
if (!this.keepShot || !layer?.snapshot3d)
|
|
156
|
+
return;
|
|
157
|
+
this.shot = 'saving';
|
|
158
|
+
try {
|
|
159
|
+
const url = await layer.snapshot3d(480, 360, 'image/webp', 0.85);
|
|
160
|
+
if (typeof url !== 'string' || !url.startsWith('data:'))
|
|
161
|
+
throw Error('no picture');
|
|
162
|
+
await this.keepShot(url);
|
|
163
|
+
this.shot = 'saved';
|
|
164
|
+
setTimeout(() => this.shot === 'saved' && (this.shot = ''), 1500);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
this.shot = 'failed';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** The whole figure in view: the board's fit, then the 3D camera's own (as the modeller canvas fits). */
|
|
171
|
+
fit() {
|
|
172
|
+
this.scene?.fit?.('ratio');
|
|
173
|
+
this.scene?.root?.fitCameraToModel?.();
|
|
174
|
+
}
|
|
175
|
+
/** Play or pause a clip, at the end of the line it moves. */
|
|
176
|
+
playButton(clip) {
|
|
177
|
+
const on = this.playing === clip;
|
|
178
|
+
return html `<button icon play aria-pressed=${String(on)} aria-label=${clip} title=${clip} @click=${() => this.play(clip)}>
|
|
179
|
+
<md-icon>${on ? 'pause' : 'play_arrow'}</md-icon></button>`;
|
|
180
|
+
}
|
|
181
|
+
tell(key, value) {
|
|
182
|
+
this.scene?.root?.components?.[0]?.set(key, value);
|
|
183
|
+
}
|
|
184
|
+
resize(axis, value) {
|
|
185
|
+
const input = this.asset?.document.model.inputs.find(input => input.id === FIGURE_INSTANCE_SIZE_INPUTS[axis]);
|
|
186
|
+
if (!input || !Number.isFinite(value)) {
|
|
187
|
+
this.requestUpdate();
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const used = Math.min(input.max, Math.max(input.min, value));
|
|
191
|
+
this.sizes = { ...this.sizes, [axis]: used };
|
|
192
|
+
/*
|
|
193
|
+
The model grows about its own centre, which stays on the board's centre -- the origin of the ground grid. A
|
|
194
|
+
board instance is placed by its corner, so the corner moves with the size. The camera stays where the person
|
|
195
|
+
turned it: refitting on every step slid the grid under the model as if the axes had moved.
|
|
196
|
+
*/
|
|
197
|
+
this.scene?.root?.components?.[0]?.set(axis === 'x' ? { width: used } : axis === 'y' ? { depth: used } : { height: used });
|
|
198
|
+
this.centre();
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The instance's box on the board's centre. The figure fits its box to the room it declares (its motion included),
|
|
202
|
+
* which can be wider than the size asked, so the box is read back rather than computed here.
|
|
203
|
+
*/
|
|
204
|
+
centre() {
|
|
205
|
+
const instance = this.scene?.root?.components?.[0];
|
|
206
|
+
if (!instance?.model)
|
|
207
|
+
return;
|
|
208
|
+
const { width = 0, height = 0 } = instance.model;
|
|
209
|
+
instance.set({ left: this.board.x / 2 - width / 2, top: this.board.z / 2 - height / 2 });
|
|
210
|
+
}
|
|
211
|
+
pose(id, value) {
|
|
212
|
+
if (!Number.isFinite(value))
|
|
213
|
+
return;
|
|
214
|
+
this.values = { ...this.values, [id]: value };
|
|
215
|
+
this.tell('parameters', this.values);
|
|
216
|
+
}
|
|
217
|
+
play(name) {
|
|
218
|
+
this.playing = this.playing === name ? '' : name;
|
|
219
|
+
if (this.playing && this.asset) {
|
|
220
|
+
this.played.add(name);
|
|
221
|
+
this.values = parametersForClip(this.asset, this.values, name);
|
|
222
|
+
this.tell('parameters', this.values);
|
|
223
|
+
}
|
|
224
|
+
this.tell('clips', Object.fromEntries([...new Set((this.asset?.drivers ?? []).map(d => d.clip))].map(key => [key, key === this.playing ? 1 : 0])));
|
|
225
|
+
}
|
|
226
|
+
reset() {
|
|
227
|
+
if (!this.asset)
|
|
228
|
+
return;
|
|
229
|
+
// A new instance also resets driver clocks. Clearing speeds alone freezes the last pose.
|
|
230
|
+
this.standUp();
|
|
231
|
+
}
|
|
232
|
+
standUp() {
|
|
233
|
+
this.teardown();
|
|
234
|
+
this.error = '';
|
|
235
|
+
const asset = this.asset;
|
|
236
|
+
if (!asset)
|
|
237
|
+
return;
|
|
238
|
+
this.values = {};
|
|
239
|
+
this.playing = '';
|
|
240
|
+
this.shot = '';
|
|
241
|
+
this.played.clear();
|
|
242
|
+
try {
|
|
243
|
+
compileFigureAsset(asset);
|
|
244
|
+
if (!asset.appearance.length)
|
|
245
|
+
throw Error(i18next.t('figure.text.preview-needs-a-part'));
|
|
246
|
+
this.sizes = authoredSizeOf(asset);
|
|
247
|
+
const type = `figure-detail-${crypto.randomUUID()}`;
|
|
248
|
+
registerFigure(type, asset);
|
|
249
|
+
this.registered = type;
|
|
250
|
+
const size = this.sizes;
|
|
251
|
+
this.board = { x: size.x * 2, z: size.z * 2 };
|
|
252
|
+
this.scene = create({ target: this.stage, mode: 0, model: {
|
|
253
|
+
type: 'model-layer', width: size.x * 2, height: size.z * 2,
|
|
254
|
+
depth: previewBoardDepth({ placement: asset.placement, base: { y: size.y } }, DEFAULT_VIEW.ceilingHeight, 1),
|
|
255
|
+
threed: true, sky: 'color', ...sceneLook(DEFAULT_VIEW),
|
|
256
|
+
placement: DEFAULT_VIEW.placement, heights: { floor: 0, ceiling: DEFAULT_VIEW.ceilingHeight },
|
|
257
|
+
pixelRatio: Math.min(3, (window.devicePixelRatio || 1) * 2),
|
|
258
|
+
components: [{ type, id: 'detail-instance', left: size.x / 2, top: size.z / 2, width: size.x, height: size.z, depth: size.y }]
|
|
259
|
+
} });
|
|
260
|
+
this.centre();
|
|
261
|
+
this.scene.resize?.();
|
|
262
|
+
this.fit();
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
this.error = error.message;
|
|
266
|
+
this.teardown();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
teardown() {
|
|
270
|
+
this.scene?.dispose?.();
|
|
271
|
+
this.scene = undefined;
|
|
272
|
+
if (this.registered)
|
|
273
|
+
unregisterFigure(this.registered);
|
|
274
|
+
this.registered = undefined;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
__decorate([
|
|
278
|
+
property({ attribute: false }),
|
|
279
|
+
__metadata("design:type", Object)
|
|
280
|
+
], FigureAssetViewer.prototype, "asset", void 0);
|
|
281
|
+
__decorate([
|
|
282
|
+
property({ attribute: false }),
|
|
283
|
+
__metadata("design:type", Function)
|
|
284
|
+
], FigureAssetViewer.prototype, "keepShot", void 0);
|
|
285
|
+
__decorate([
|
|
286
|
+
query('[stage]'),
|
|
287
|
+
__metadata("design:type", HTMLElement)
|
|
288
|
+
], FigureAssetViewer.prototype, "stage", void 0);
|
|
289
|
+
__decorate([
|
|
290
|
+
state(),
|
|
291
|
+
__metadata("design:type", String)
|
|
292
|
+
], FigureAssetViewer.prototype, "shot", void 0);
|
|
293
|
+
__decorate([
|
|
294
|
+
state(),
|
|
295
|
+
__metadata("design:type", Object)
|
|
296
|
+
], FigureAssetViewer.prototype, "sizes", void 0);
|
|
297
|
+
__decorate([
|
|
298
|
+
state(),
|
|
299
|
+
__metadata("design:type", Object)
|
|
300
|
+
], FigureAssetViewer.prototype, "values", void 0);
|
|
301
|
+
__decorate([
|
|
302
|
+
state(),
|
|
303
|
+
__metadata("design:type", Object)
|
|
304
|
+
], FigureAssetViewer.prototype, "playing", void 0);
|
|
305
|
+
__decorate([
|
|
306
|
+
state(),
|
|
307
|
+
__metadata("design:type", Object)
|
|
308
|
+
], FigureAssetViewer.prototype, "error", void 0);
|
|
309
|
+
FigureAssetViewer = __decorate([
|
|
310
|
+
customElement('figure-asset-viewer')
|
|
311
|
+
], FigureAssetViewer);
|
|
312
|
+
export { FigureAssetViewer };
|
|
313
|
+
//# sourceMappingURL=figure-asset-viewer.js.map
|