@things-factory/figure-ui 10.1.74 → 10.1.76

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 (244) hide show
  1. package/client/figure-assistant.ts +3 -3
  2. package/client/graphql/{v3-store.ts → store.ts} +6 -6
  3. package/client/modeller/{v3-ai-proposal.ts → ai-proposal.ts} +8 -8
  4. package/client/modeller/{v3-align.ts → align.ts} +14 -14
  5. package/client/modeller/{v3-canvas.ts → canvas.ts} +13 -13
  6. package/client/modeller/{v3-clips.ts → clips.ts} +5 -5
  7. package/client/modeller/{v3-controls.ts → controls.ts} +2 -2
  8. package/client/modeller/{v3-editor.ts → editor.ts} +137 -126
  9. package/client/modeller/{figure-v3-capability.ts → figure-capability-panel.ts} +7 -7
  10. package/client/modeller/{figure-v3-clips.ts → figure-clips.ts} +10 -10
  11. package/client/modeller/{figure-v3-controls.ts → figure-controls.ts} +9 -9
  12. package/client/modeller/{v3-figure-facts.ts → figure-facts.ts} +11 -11
  13. package/client/modeller/{figure-v3-first-save.ts → figure-first-save.ts} +3 -3
  14. package/client/modeller/figure-history-panel.ts +1 -1
  15. package/client/modeller/{figure-v3-links.ts → figure-links.ts} +35 -35
  16. package/client/modeller/{figure-v3-material.ts → figure-material-panel.ts} +20 -20
  17. package/client/modeller/{figure-v3-parts.ts → figure-parts.ts} +15 -15
  18. package/client/modeller/{figure-v3-preview.ts → figure-preview.ts} +14 -14
  19. package/client/modeller/{figure-v3-properties.ts → figure-properties.ts} +25 -25
  20. package/client/modeller/{figure-v3-recipe-catalog.ts → figure-recipe-catalog.ts} +10 -10
  21. package/client/modeller/{figure-v3-verdict.ts → figure-verdict.ts} +24 -24
  22. package/client/modeller/gate-findings.ts +2 -2
  23. package/client/modeller/{v3-gizmo.ts → gizmo.ts} +11 -11
  24. package/client/modeller/{v3-joint-drag.ts → joint-drag.ts} +11 -11
  25. package/client/modeller/{v3-joint-fan.ts → joint-fan.ts} +13 -13
  26. package/client/modeller/{v3-links.ts → links.ts} +59 -59
  27. package/client/modeller/{v3-live.ts → live.ts} +9 -9
  28. package/client/modeller/{v3-maturity.ts → maturity.ts} +65 -65
  29. package/client/modeller/modeller-route.ts +1 -1
  30. package/client/modeller/{v3-occupancy.ts → occupancy.ts} +6 -6
  31. package/client/modeller/{v3-palette.ts → palette.ts} +3 -3
  32. package/client/modeller/{v3-preview-model.ts → preview-model.ts} +8 -8
  33. package/client/modeller/{v3-product-session.ts → product-session.ts} +25 -25
  34. package/client/modeller/{v3-recipe-source.ts → recipe-source.ts} +2 -2
  35. package/client/modeller/{v3-recipes.ts → recipes.ts} +9 -9
  36. package/client/modeller/{v3-refusals.ts → refusals.ts} +62 -13
  37. package/client/modeller/{v3-renderer.ts → renderer.ts} +16 -16
  38. package/client/modeller/{v3-stage-model.ts → stage-model.ts} +15 -15
  39. package/client/modeller/{v3-thumbnail.ts → thumbnail.ts} +8 -8
  40. package/client/pages/figure-list-page.ts +4 -4
  41. package/client/pages/{figure-v3-modeller-page.ts → figure-modeller-page.ts} +37 -37
  42. package/client/route.ts +1 -5
  43. package/dist-client/figure-assistant.js +3 -3
  44. package/dist-client/figure-assistant.js.map +1 -1
  45. package/dist-client/graphql/store.d.ts +3 -0
  46. package/dist-client/graphql/store.js +39 -0
  47. package/dist-client/graphql/store.js.map +1 -0
  48. package/dist-client/modeller/ai-proposal.d.ts +51 -0
  49. package/dist-client/modeller/ai-proposal.js +64 -0
  50. package/dist-client/modeller/ai-proposal.js.map +1 -0
  51. package/dist-client/modeller/align.d.ts +30 -0
  52. package/dist-client/modeller/align.js +75 -0
  53. package/dist-client/modeller/align.js.map +1 -0
  54. package/dist-client/modeller/canvas.d.ts +72 -0
  55. package/dist-client/modeller/canvas.js +379 -0
  56. package/dist-client/modeller/canvas.js.map +1 -0
  57. package/dist-client/modeller/clips.d.ts +39 -0
  58. package/dist-client/modeller/clips.js +58 -0
  59. package/dist-client/modeller/clips.js.map +1 -0
  60. package/dist-client/modeller/controls.d.ts +28 -0
  61. package/dist-client/modeller/controls.js +28 -0
  62. package/dist-client/modeller/controls.js.map +1 -0
  63. package/dist-client/modeller/editor.d.ts +203 -0
  64. package/dist-client/modeller/editor.js +1526 -0
  65. package/dist-client/modeller/editor.js.map +1 -0
  66. package/dist-client/modeller/fields.d.ts +45 -0
  67. package/dist-client/modeller/fields.js +83 -0
  68. package/dist-client/modeller/fields.js.map +1 -0
  69. package/dist-client/modeller/figure-capability-panel.d.ts +22 -0
  70. package/dist-client/modeller/figure-capability-panel.js +141 -0
  71. package/dist-client/modeller/figure-capability-panel.js.map +1 -0
  72. package/dist-client/modeller/figure-clips.d.ts +31 -0
  73. package/dist-client/modeller/figure-clips.js +268 -0
  74. package/dist-client/modeller/figure-clips.js.map +1 -0
  75. package/dist-client/modeller/figure-controls.d.ts +36 -0
  76. package/dist-client/modeller/figure-controls.js +226 -0
  77. package/dist-client/modeller/figure-controls.js.map +1 -0
  78. package/dist-client/modeller/figure-facts.d.ts +35 -0
  79. package/dist-client/modeller/figure-facts.js +55 -0
  80. package/dist-client/modeller/figure-facts.js.map +1 -0
  81. package/dist-client/modeller/figure-first-save.d.ts +20 -0
  82. package/dist-client/modeller/figure-first-save.js +118 -0
  83. package/dist-client/modeller/figure-first-save.js.map +1 -0
  84. package/dist-client/modeller/figure-history-panel.d.ts +1 -1
  85. package/dist-client/modeller/figure-history-panel.js.map +1 -1
  86. package/dist-client/modeller/figure-links.d.ts +77 -0
  87. package/dist-client/modeller/figure-links.js +649 -0
  88. package/dist-client/modeller/figure-links.js.map +1 -0
  89. package/dist-client/modeller/figure-material-panel.d.ts +39 -0
  90. package/dist-client/modeller/figure-material-panel.js +323 -0
  91. package/dist-client/modeller/figure-material-panel.js.map +1 -0
  92. package/dist-client/modeller/figure-parts.d.ts +69 -0
  93. package/dist-client/modeller/figure-parts.js +559 -0
  94. package/dist-client/modeller/figure-parts.js.map +1 -0
  95. package/dist-client/modeller/figure-preview.d.ts +34 -0
  96. package/dist-client/modeller/figure-preview.js +346 -0
  97. package/dist-client/modeller/figure-preview.js.map +1 -0
  98. package/dist-client/modeller/figure-properties.d.ts +45 -0
  99. package/dist-client/modeller/figure-properties.js +239 -0
  100. package/dist-client/modeller/figure-properties.js.map +1 -0
  101. package/dist-client/modeller/figure-recipe-catalog.d.ts +38 -0
  102. package/dist-client/modeller/figure-recipe-catalog.js +399 -0
  103. package/dist-client/modeller/figure-recipe-catalog.js.map +1 -0
  104. package/dist-client/modeller/figure-verdict.d.ts +64 -0
  105. package/dist-client/modeller/figure-verdict.js +787 -0
  106. package/dist-client/modeller/figure-verdict.js.map +1 -0
  107. package/dist-client/modeller/first-save.d.ts +17 -0
  108. package/dist-client/modeller/first-save.js +26 -0
  109. package/dist-client/modeller/first-save.js.map +1 -0
  110. package/dist-client/modeller/gate-findings.d.ts +2 -2
  111. package/dist-client/modeller/gate-findings.js +2 -2
  112. package/dist-client/modeller/gate-findings.js.map +1 -1
  113. package/dist-client/modeller/gizmo.d.ts +72 -0
  114. package/dist-client/modeller/gizmo.js +111 -0
  115. package/dist-client/modeller/gizmo.js.map +1 -0
  116. package/dist-client/modeller/help.d.ts +18 -0
  117. package/dist-client/modeller/help.js +37 -0
  118. package/dist-client/modeller/help.js.map +1 -0
  119. package/dist-client/modeller/joint-drag.d.ts +19 -0
  120. package/dist-client/modeller/joint-drag.js +97 -0
  121. package/dist-client/modeller/joint-drag.js.map +1 -0
  122. package/dist-client/modeller/joint-fan.d.ts +9 -0
  123. package/dist-client/modeller/joint-fan.js +276 -0
  124. package/dist-client/modeller/joint-fan.js.map +1 -0
  125. package/dist-client/modeller/keys.d.ts +22 -0
  126. package/dist-client/modeller/keys.js +26 -0
  127. package/dist-client/modeller/keys.js.map +1 -0
  128. package/dist-client/modeller/links.d.ts +267 -0
  129. package/dist-client/modeller/links.js +480 -0
  130. package/dist-client/modeller/links.js.map +1 -0
  131. package/dist-client/modeller/live.d.ts +37 -0
  132. package/dist-client/modeller/live.js +68 -0
  133. package/dist-client/modeller/live.js.map +1 -0
  134. package/dist-client/modeller/maturity.d.ts +120 -0
  135. package/dist-client/modeller/maturity.js +313 -0
  136. package/dist-client/modeller/maturity.js.map +1 -0
  137. package/dist-client/modeller/modeller-route.d.ts +1 -1
  138. package/dist-client/modeller/modeller-route.js +1 -1
  139. package/dist-client/modeller/modeller-route.js.map +1 -1
  140. package/dist-client/modeller/occupancy.d.ts +18 -0
  141. package/dist-client/modeller/occupancy.js +24 -0
  142. package/dist-client/modeller/occupancy.js.map +1 -0
  143. package/dist-client/modeller/palette.d.ts +7 -0
  144. package/dist-client/modeller/palette.js +46 -0
  145. package/dist-client/modeller/palette.js.map +1 -0
  146. package/dist-client/modeller/preview-model.d.ts +47 -0
  147. package/dist-client/modeller/preview-model.js +68 -0
  148. package/dist-client/modeller/preview-model.js.map +1 -0
  149. package/dist-client/modeller/product-session.d.ts +510 -0
  150. package/dist-client/modeller/product-session.js +157 -0
  151. package/dist-client/modeller/product-session.js.map +1 -0
  152. package/dist-client/modeller/recipe-source.d.ts +8 -0
  153. package/dist-client/modeller/recipe-source.js +14 -0
  154. package/dist-client/modeller/recipe-source.js.map +1 -0
  155. package/dist-client/modeller/recipes.d.ts +37 -0
  156. package/dist-client/modeller/recipes.js +103 -0
  157. package/dist-client/modeller/recipes.js.map +1 -0
  158. package/dist-client/modeller/refusals.d.ts +68 -0
  159. package/dist-client/modeller/refusals.js +142 -0
  160. package/dist-client/modeller/refusals.js.map +1 -0
  161. package/dist-client/modeller/renderer.d.ts +40 -0
  162. package/dist-client/modeller/renderer.js +73 -0
  163. package/dist-client/modeller/renderer.js.map +1 -0
  164. package/dist-client/modeller/stage-model.d.ts +39 -0
  165. package/dist-client/modeller/stage-model.js +147 -0
  166. package/dist-client/modeller/stage-model.js.map +1 -0
  167. package/dist-client/modeller/thumbnail.d.ts +3 -0
  168. package/dist-client/modeller/thumbnail.js +75 -0
  169. package/dist-client/modeller/thumbnail.js.map +1 -0
  170. package/dist-client/modeller/v3-clips.d.ts +1 -1
  171. package/dist-client/modeller/v3-editor.d.ts +5 -0
  172. package/dist-client/modeller/v3-editor.js +21 -10
  173. package/dist-client/modeller/v3-editor.js.map +1 -1
  174. package/dist-client/modeller/v3-product-session.d.ts +31 -0
  175. package/dist-client/modeller/v3-refusals.d.ts +37 -5
  176. package/dist-client/modeller/v3-refusals.js +59 -16
  177. package/dist-client/modeller/v3-refusals.js.map +1 -1
  178. package/dist-client/pages/figure-list-page.d.ts +1 -1
  179. package/dist-client/pages/figure-list-page.js +4 -4
  180. package/dist-client/pages/figure-list-page.js.map +1 -1
  181. package/dist-client/pages/figure-modeller-page.d.ts +102 -0
  182. package/dist-client/pages/figure-modeller-page.js +548 -0
  183. package/dist-client/pages/figure-modeller-page.js.map +1 -0
  184. package/dist-client/route.d.ts +1 -1
  185. package/dist-client/route.js +1 -5
  186. package/dist-client/route.js.map +1 -1
  187. package/dist-client/tsconfig.tsbuildinfo +1 -1
  188. package/docs/product-cutover.md +25 -0
  189. package/package.json +5 -5
  190. package/test/{v3-ai-proposal.test.ts → ai-proposal.test.ts} +6 -6
  191. package/test/{v3-align.test.ts → align.test.ts} +8 -8
  192. package/test/browser/modeller-page.js +30 -30
  193. package/test/browser/modeller.check.mjs +17 -16
  194. package/test/browser/serve.mjs +1 -1
  195. package/test/browser/thumbnail-page.js +6 -6
  196. package/test/{v3-clips.test.ts → clips.test.ts} +18 -18
  197. package/test/{v3-controls.test.ts → controls.test.ts} +15 -15
  198. package/test/{v3-fields.test.ts → fields.test.ts} +13 -13
  199. package/test/figure-assistant-surface.test.ts +3 -3
  200. package/test/{v3-first-save.test.ts → first-save.test.ts} +10 -10
  201. package/test/fixtures/joint-column.json +2 -2
  202. package/test/fixtures/joint-roller.json +2 -2
  203. package/test/fixtures/robot-arm-6dof.json +2 -2
  204. package/test/{v3-gizmo.test.ts → gizmo.test.ts} +33 -33
  205. package/test/{v3-joint-drag.test.ts → joint-drag.test.ts} +17 -17
  206. package/test/{v3-joint-fan.test.ts → joint-fan.test.ts} +18 -18
  207. package/test/joints.ts +6 -6
  208. package/test/{v3-keys.test.ts → keys.test.ts} +2 -2
  209. package/test/{v3-layout.test.ts → layout.test.ts} +8 -8
  210. package/test/{v3-links.test.ts → links.test.ts} +201 -201
  211. package/test/{v3-live.test.ts → live.test.ts} +18 -18
  212. package/test/{v3-material.test.ts → material.test.ts} +12 -12
  213. package/test/{v3-maturity.test.ts → maturity.test.ts} +74 -74
  214. package/test/modeller-route.test.ts +5 -6
  215. package/test/{v3-palette-icons.test.ts → palette-icons.test.ts} +1 -1
  216. package/test/{v3-parts-wiring.test.ts → parts-wiring.test.ts} +11 -7
  217. package/test/{v3-preview.test.ts → preview.test.ts} +12 -12
  218. package/test/{v3-product-session.test.ts → product-session.test.ts} +17 -17
  219. package/test/{v3-product-write.test.ts → product-write.test.ts} +20 -20
  220. package/test/{v3-properties.test.ts → properties.test.ts} +24 -24
  221. package/test/{v3-recipes.test.ts → recipes.test.ts} +10 -10
  222. package/test/refusals.test.ts +166 -0
  223. package/test/{v3-release-panel.test.ts → release-panel.test.ts} +21 -21
  224. package/test/renderer.test.ts +24 -0
  225. package/test/resolve-ts-siblings.mjs +1 -1
  226. package/test/{v3-scene-canvas.test.ts → scene-canvas.test.ts} +6 -6
  227. package/test/{v3-stage-model.test.ts → stage-model.test.ts} +5 -5
  228. package/test/{v3-theme.test.ts → theme.test.ts} +4 -4
  229. package/test/{v3-thumbnail.test.ts → thumbnail.test.ts} +4 -4
  230. package/test/{v3-verdict.test.ts → verdict.test.ts} +17 -17
  231. package/test/{v3-view.test.ts → view.test.ts} +2 -2
  232. package/things-factory.config.js +2 -3
  233. package/translations/en.json +15 -7
  234. package/translations/ja.json +15 -7
  235. package/translations/ko.json +15 -7
  236. package/translations/ms.json +15 -7
  237. package/translations/zh.json +15 -7
  238. package/docs/v3-product-cutover.md +0 -25
  239. package/test/v3-refusals.test.ts +0 -136
  240. package/test/v3-renderer.test.ts +0 -24
  241. /package/client/modeller/{v3-fields.ts → fields.ts} +0 -0
  242. /package/client/modeller/{v3-first-save.ts → first-save.ts} +0 -0
  243. /package/client/modeller/{v3-help.ts → help.ts} +0 -0
  244. /package/client/modeller/{v3-keys.ts → keys.ts} +0 -0
@@ -0,0 +1,379 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { LitElement, html, css, nothing, unsafeCSS } from 'lit';
3
+ import { customElement, property, query } from 'lit/decorators.js';
4
+ import { i18next } from '@operato/i18n';
5
+ import { create, Model, niceGridStep } from '@hatiolab/things-scene';
6
+ import { DEFAULT_VIEW, sceneLook, WORKBENCH } from './figure-view.js';
7
+ import { boardFor, changedKeys, componentOf, gizmoResultOf } from './stage-model.js';
8
+ import { JOINT_FAN } from './joint-fan.js';
9
+ import { ownerOf } from './fields.js';
10
+ /* The fan's colour when the figure's palette names no accent. */
11
+ const FAN_COLOUR = '#ff8a00';
12
+ /* The 2D side of the board, which the author never sees on this page but the scene paints. */
13
+ const PAPER = '#ffffff';
14
+ let FigureCanvas = class FigureCanvas extends LitElement {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.parts = [];
18
+ this.palette = {};
19
+ /** Which figure is open. Another one stands the board up again. */
20
+ this.context = '';
21
+ this.selected = '';
22
+ /** What the gizmo may write for the selected part; a change beyond it is not applied and the part springs back. */
23
+ this.reach = { translate: false, rotate: false, scale: false };
24
+ this.view = DEFAULT_VIEW;
25
+ /**
26
+ * View only: nothing that happens on the board is told out. The card's picture is taken from a second canvas stood up
27
+ * off screen (`thumbnail.ts`); the scene settles its components as it builds them, and a change told from there
28
+ * would reach the editor as an edit.
29
+ */
30
+ this.viewOnly = false;
31
+ /** Where the selected part turns and how far (`joint-fan`): shown, never picked, never saved. */
32
+ this.fan = null;
33
+ /** Set while this canvas writes to components, so the scene's echo of it is not taken for a drag. */
34
+ this.writing = false;
35
+ /** Components the gizmo changed since the last commit, by part name. */
36
+ this.pending = new Map();
37
+ this.pointerDown = false;
38
+ this.onPointerDown = () => {
39
+ this.pointerDown = true;
40
+ };
41
+ this.onPointerUp = () => {
42
+ if (!this.pointerDown)
43
+ return;
44
+ this.pointerDown = false;
45
+ /* After the scene's own drag end (it settles the depth and rebuilds the geometry on release). */
46
+ this.commitSoon(0);
47
+ };
48
+ }
49
+ static { this.styles = css `
50
+ :host {
51
+ position: relative;
52
+ display: flex;
53
+ min-height: 0;
54
+ overflow: hidden;
55
+ background-color: ${unsafeCSS(WORKBENCH)};
56
+ }
57
+ /* The scene sets position: relative inline on its target; the size is given so it still fills the host. */
58
+ div[stage] {
59
+ position: absolute;
60
+ inset: 0;
61
+ width: 100%;
62
+ height: 100%;
63
+ }
64
+ p {
65
+ position: absolute;
66
+ inset: 45% 1rem auto;
67
+ margin: 0;
68
+ text-align: center;
69
+ pointer-events: none;
70
+ color: #f4f4f4;
71
+ }
72
+ `; }
73
+ render() {
74
+ return html `<div stage></div>${this.parts.length ? nothing : html `<p>${i18next.t('figure.text.add-a-shape-to-start')}</p>`}`;
75
+ }
76
+ firstUpdated() {
77
+ this.standUp();
78
+ this.watcher = new ResizeObserver(() => this.scene?.resize?.());
79
+ this.watcher.observe(this);
80
+ }
81
+ updated(changed) {
82
+ if (!this.hasUpdated)
83
+ return;
84
+ if (changed.has('parts') || changed.has('palette') || changed.has('context') || changed.has('fan'))
85
+ this.standUp();
86
+ if (changed.has('view'))
87
+ this.applyView();
88
+ if (changed.has('selected'))
89
+ this.showSelected();
90
+ }
91
+ disconnectedCallback() {
92
+ super.disconnectedCallback();
93
+ this.watcher?.disconnect();
94
+ this.watcher = undefined;
95
+ this.teardown();
96
+ }
97
+ /**
98
+ * The board as a picture, for the card: the 3D view at this size, or nothing when it cannot be taken. The scene's
99
+ * `toDataURL` renders the 2D board (a white sheet), and the 3D renderer keeps no drawing buffer, so the
100
+ * scene's own `snapshot3d` draws and reads in one task. A picture that cannot be taken is not an error and is not
101
+ * faked (user, 2026-09-24: no card had a picture after this canvas moved onto the scene).
102
+ */
103
+ async snapshot(width = 480, height = 360) {
104
+ const layer = this.scene?.root;
105
+ if (!layer?.snapshot3d)
106
+ return undefined;
107
+ try {
108
+ /* webp: a card needs no alpha, and png is three or four times heavier in every list response. */
109
+ const url = await layer.snapshot3d(width, height, 'image/webp', 0.85);
110
+ return typeof url === 'string' && url.startsWith('data:') ? url : undefined;
111
+ }
112
+ catch (e) {
113
+ console.warn(`[thumbnail] could not take the picture -- ${e.message}`);
114
+ return undefined;
115
+ }
116
+ }
117
+ /** The whole figure in view: the board's fit, then the 3D camera's own. */
118
+ fit() {
119
+ this.scene?.fit?.('ratio');
120
+ this.scene?.root?.fitCameraToModel?.();
121
+ }
122
+ /** The gizmo in a mode on the selected part, as W, E and R do with the canvas focused -- the scene's toggle. */
123
+ gizmo(mode) {
124
+ this.scene?.root?.setGizmoMode?.(mode);
125
+ }
126
+ /**
127
+ * Stand the board up for this figure, or bring the one standing up to date. A new board only for another figure or
128
+ * one that has outgrown it -- standing up again loses the selection and the camera.
129
+ */
130
+ standUp() {
131
+ if (!this.stage)
132
+ return;
133
+ const needed = boardFor(this.parts, this.board);
134
+ const outgrown = !this.board || needed.width > this.board.width || needed.height > this.board.height || needed.depth > this.board.depth;
135
+ if (this.scene && this.standingFor === this.context) {
136
+ /*
137
+ A part dragged past the board's edge grows the board where it stands. Standing it up again lost the selection,
138
+ the gizmo and the camera after every such drag -- the gizmo seemed not to work at all (user, 2026-09-24).
139
+ */
140
+ if (outgrown)
141
+ this.grow(needed);
142
+ this.sync();
143
+ return;
144
+ }
145
+ this.teardown();
146
+ if (!this.parts.length)
147
+ return;
148
+ this.board = needed;
149
+ try {
150
+ this.scene = create({
151
+ target: this.stage,
152
+ model: {
153
+ type: 'model-layer',
154
+ width: needed.width,
155
+ height: needed.height,
156
+ depth: needed.depth,
157
+ threed: true,
158
+ /* Two samples a pixel: MSAA alone leaves steps on the silhouettes of one asset shown large. */
159
+ pixelRatio: Math.min(3, (window.devicePixelRatio || 1) * 2),
160
+ ...sceneLook(this.view ?? DEFAULT_VIEW),
161
+ gridStep: niceGridStep(Math.max(needed.width, needed.height)),
162
+ sky: 'color',
163
+ fillStyle: PAPER,
164
+ components: this.components()
165
+ },
166
+ /* Editing mode: the camera view buttons, gizmo modes, help and keys. */
167
+ mode: 1
168
+ });
169
+ this.standingFor = this.context;
170
+ this.watchScene();
171
+ this.scene.resize?.();
172
+ this.fit();
173
+ this.showSelected();
174
+ }
175
+ catch (error) {
176
+ this.dispatchEvent(new CustomEvent('render-error', { detail: error, bubbles: true, composed: true }));
177
+ }
178
+ }
179
+ components() {
180
+ const parts = this.parts.map(part => componentOf(part, this.palette, this.board)).filter((c) => !!c);
181
+ /* The fan in the accent colour, translucent; `capturable: false` keeps clicks, the marquee and the gizmo off it. */
182
+ const fan = this.fan ? componentOf(this.fan, { ...this.palette, [JOINT_FAN]: this.palette['palette.accent'] ?? FAN_COLOUR }, this.board) : null;
183
+ return fan ? [...parts, { ...fan, capturable: false, locked: true }] : parts;
184
+ }
185
+ /** The components standing now, by name. Not held between calls: the scene stands its board up again at times. */
186
+ standing() {
187
+ const found = new Map();
188
+ for (const component of this.scene?.root?.components ?? []) {
189
+ const name = component.state?.name;
190
+ if (typeof name === 'string')
191
+ found.set(name, component);
192
+ }
193
+ return found;
194
+ }
195
+ /** A larger board under the same scene: its size, and the grid that suits it. Components are re-placed by `sync`. */
196
+ grow(needed) {
197
+ const layer = this.scene?.root;
198
+ this.board = needed;
199
+ if (!layer)
200
+ return;
201
+ this.writing = true;
202
+ try {
203
+ layer.set({ width: needed.width, height: needed.height, depth: needed.depth, gridStep: niceGridStep(Math.max(needed.width, needed.height)) });
204
+ }
205
+ finally {
206
+ this.writing = false;
207
+ }
208
+ }
209
+ /** Bring the components to the evaluation: remove the gone, write only what differs, add the new. */
210
+ sync() {
211
+ const layer = this.scene?.root;
212
+ if (!layer || !this.board)
213
+ return;
214
+ const wanted = new Map(this.components().map(c => [c.name, c]));
215
+ const standing = this.standing();
216
+ this.writing = true;
217
+ try {
218
+ for (const [name, component] of standing) {
219
+ if (wanted.has(name))
220
+ continue;
221
+ layer.removeComponent?.(component);
222
+ component.dispose?.();
223
+ }
224
+ for (const [name, state] of wanted) {
225
+ const found = standing.get(name);
226
+ if (found) {
227
+ const diff = changedKeys(found.state, state);
228
+ if (diff)
229
+ found.set(diff);
230
+ continue;
231
+ }
232
+ const made = Model.compile({ ...state }, layer.app);
233
+ if (made)
234
+ layer.addComponent?.(made);
235
+ }
236
+ }
237
+ finally {
238
+ this.writing = false;
239
+ }
240
+ layer.invalidate?.();
241
+ }
242
+ /** Selection and drags, told out by the part's name -- never by its place in the list, which may change meanwhile. */
243
+ watchScene() {
244
+ const layer = this.scene?.root;
245
+ const root = layer?.root;
246
+ if (!layer || !root?.on || this.viewOnly)
247
+ return;
248
+ root.on('selected', (after) => {
249
+ const name = after?.[0]?.state?.name;
250
+ const id = typeof name === 'string' ? name : '';
251
+ if (ownerOf(id) !== this.selected)
252
+ this.dispatchEvent(new CustomEvent('part-selected', { detail: id, bubbles: true, composed: true }));
253
+ });
254
+ /*
255
+ A change comes up to the board with the component in the last argument's `origin` (the scene appends
256
+ { origin, name, deliverer } as it bubbles). Reading the first argument as the component does nothing.
257
+ */
258
+ /*
259
+ A drag is written once, when it ends. The scene's gizmo writes the component on every move -- a size anchored on
260
+ the opposite face, from the scale it captured when the drag began -- and writing each move back through the
261
+ editor (and the evaluation back onto the component) fought it: the scale gizmo did not work (user, 2026-09-24).
262
+ While a pointer is down the changes are only kept; on release the last one is told, and the board is brought to
263
+ the evaluation. A change with no pointer down (the arrow keys) is told after a short pause.
264
+ */
265
+ layer.on?.('change', (...args) => {
266
+ if (this.writing)
267
+ return;
268
+ const origin = args[args.length - 1]?.origin;
269
+ const name = origin?.state?.name;
270
+ if (typeof name !== 'string' || !this.parts.some(p => p.id === name))
271
+ return;
272
+ this.pending.set(name, origin);
273
+ if (!this.pointerDown)
274
+ this.commitSoon(80);
275
+ });
276
+ this.stage.addEventListener('pointerdown', this.onPointerDown, true);
277
+ window.addEventListener('pointerup', this.onPointerUp, true);
278
+ window.addEventListener('pointercancel', this.onPointerUp, true);
279
+ }
280
+ commitSoon(delay) {
281
+ clearTimeout(this.commitTimer);
282
+ this.commitTimer = setTimeout(() => this.commit(), delay);
283
+ }
284
+ /** Tell each changed part once, in the inputs' terms; then put the board where the inputs say (a refusal springs back). */
285
+ commit() {
286
+ /*
287
+ Not while a pointer is down: a pause set by a change just before the press (the arrow keys, the scene settling
288
+ the pick) fired in the middle of the drag and wrote where the part was then -- a drag on a part placed by a rule
289
+ became two steps, the first one a few millimetres in (browser check, 2026-09-25). What is pending waits for the release.
290
+ */
291
+ if (this.pointerDown || !this.board || !this.pending.size)
292
+ return;
293
+ const changed = [...this.pending];
294
+ this.pending.clear();
295
+ for (const [name, component] of changed) {
296
+ const part = this.parts.find(p => p.id === name);
297
+ if (!part)
298
+ continue;
299
+ const result = gizmoResultOf(part, component.state, this.board);
300
+ if (!result.position && !result.rotation && !result.scale)
301
+ continue;
302
+ this.dispatchEvent(new CustomEvent('part-transformed', { detail: { id: part.id, result }, bubbles: true, composed: true }));
303
+ }
304
+ setTimeout(() => this.sync());
305
+ }
306
+ showSelected() {
307
+ const layer = this.scene?.root;
308
+ const root = layer?.root;
309
+ if (!layer || !root)
310
+ return;
311
+ /* A repeat is selected whole: every copy of it (the editor selects the part the author made). */
312
+ const wanted = this.selected ? [...this.standing()].filter(([name]) => ownerOf(name) === this.selected).map(([, component]) => component) : [];
313
+ const now = root.selected ?? [];
314
+ if (now.length === wanted.length && wanted.every((one, i) => now[i] === one))
315
+ return;
316
+ root.selected = wanted;
317
+ layer.invalidate?.();
318
+ }
319
+ /** View settings go into the scene as they are: they are the board's own state names. Nothing is stood up again. */
320
+ applyView() {
321
+ const layer = this.scene?.root;
322
+ if (!layer)
323
+ return;
324
+ layer.set(sceneLook(this.view ?? DEFAULT_VIEW));
325
+ layer.invalidate?.();
326
+ }
327
+ teardown() {
328
+ clearTimeout(this.commitTimer);
329
+ this.pending.clear();
330
+ this.stage?.removeEventListener('pointerdown', this.onPointerDown, true);
331
+ window.removeEventListener('pointerup', this.onPointerUp, true);
332
+ window.removeEventListener('pointercancel', this.onPointerUp, true);
333
+ this.scene?.dispose?.();
334
+ this.scene = undefined;
335
+ this.standingFor = undefined;
336
+ this.board = undefined;
337
+ }
338
+ };
339
+ __decorate([
340
+ property({ attribute: false }),
341
+ __metadata("design:type", Array)
342
+ ], FigureCanvas.prototype, "parts", void 0);
343
+ __decorate([
344
+ property({ attribute: false }),
345
+ __metadata("design:type", Object)
346
+ ], FigureCanvas.prototype, "palette", void 0);
347
+ __decorate([
348
+ property(),
349
+ __metadata("design:type", Object)
350
+ ], FigureCanvas.prototype, "context", void 0);
351
+ __decorate([
352
+ property(),
353
+ __metadata("design:type", Object)
354
+ ], FigureCanvas.prototype, "selected", void 0);
355
+ __decorate([
356
+ property({ attribute: false }),
357
+ __metadata("design:type", Object)
358
+ ], FigureCanvas.prototype, "reach", void 0);
359
+ __decorate([
360
+ property({ attribute: false }),
361
+ __metadata("design:type", Object)
362
+ ], FigureCanvas.prototype, "view", void 0);
363
+ __decorate([
364
+ property({ type: Boolean }),
365
+ __metadata("design:type", Object)
366
+ ], FigureCanvas.prototype, "viewOnly", void 0);
367
+ __decorate([
368
+ property({ attribute: false }),
369
+ __metadata("design:type", Object)
370
+ ], FigureCanvas.prototype, "fan", void 0);
371
+ __decorate([
372
+ query('div[stage]'),
373
+ __metadata("design:type", HTMLDivElement)
374
+ ], FigureCanvas.prototype, "stage", void 0);
375
+ FigureCanvas = __decorate([
376
+ customElement('figure-canvas')
377
+ ], FigureCanvas);
378
+ export { FigureCanvas };
379
+ //# sourceMappingURL=canvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../client/modeller/canvas.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAuB,MAAM,KAAK,CAAA;AACpF,OAAO,EAAE,aA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CAAC;;0CAAkC;AAMpC;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;8CAAiB;AAEb;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;;yCAAoC;AAEtC;IAA5B,KAAK,CAAC,YAAY,CAAC;8BAAiB,cAAc;2CAAA;AA1CxC,YAAY;IADxB,aAAa,CAAC,eAAe,CAAC;GAClB,YAAY,CA4TxB","sourcesContent":["import { LitElement, html, css, nothing, unsafeCSS, type PropertyValues } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport { i18next } from '@operato/i18n'\nimport { create, Model, niceGridStep } from '@hatiolab/things-scene'\n\nimport type { GizmoReach } from './gizmo.js'\nimport type { FigureRenderPart } from './renderer.js'\nimport { DEFAULT_VIEW, sceneLook, WORKBENCH, type ViewSettings } from './figure-view.js'\nimport { boardFor, changedKeys, componentOf, gizmoResultOf, type Board } from './stage-model.js'\nimport { JOINT_FAN } from './joint-fan.js'\nimport { ownerOf } from './fields.js'\n\n/*\n * The modeller's canvas -- a things-scene board in editing mode.\n *\n * Each body figure-model evaluates stands on the board as a `figure-part` component, so everything the canvas\n * has comes from the scene, not from code of our own: picking and the orange outline, the gizmo with its snapping and\n * live readout, box and shift selection, the camera (damping, zoom toward the cursor, double-click to fit, the six\n * view presets and their keys), the studio environment, the coordinate ground, lights and shadows, supersampling.\n * An earlier canvas drew the bodies with three.js directly and lost all of that (user, 2026-09-24: \"why nerf it?\").\n *\n * What the gizmo writes back to a component comes out as `part-transformed` in the inputs' terms (`stage-model`),\n * and the editor turns it into one step of the history; the next evaluation puts the component where the inputs say,\n * so a change a part cannot take (a fastened part moved) springs back.\n */\n\ninterface SceneComponent {\n state: Record<string, unknown>\n set: (props: Record<string, unknown>) => void\n dispose?: () => void\n}\ninterface SceneLayer extends SceneComponent {\n components?: SceneComponent[]\n root?: { on?: (event: string, handler: (...args: unknown[]) => void) => void; selected?: SceneComponent[] }\n on?: (event: string, handler: (...args: unknown[]) => void) => void\n addComponent?: (component: SceneComponent) => void\n removeComponent?: (component: SceneComponent) => void\n invalidate?: () => void\n fitCameraToModel?: () => void\n setGizmoMode?: (mode: 'translate' | 'rotate' | 'scale') => void\n app?: unknown\n}\ninterface SceneHandle {\n dispose?: () => void\n resize?: () => void\n fit?: (type?: string) => void\n root?: SceneLayer\n}\n\n/* The fan's colour when the figure's palette names no accent. */\nconst FAN_COLOUR = '#ff8a00'\n\n/* The 2D side of the board, which the author never sees on this page but the scene paints. */\nconst PAPER = '#ffffff'\n\n@customElement('figure-canvas')\nexport class FigureCanvas extends LitElement {\n static styles = css`\n :host {\n position: relative;\n display: flex;\n min-height: 0;\n overflow: hidden;\n background-color: ${unsafeCSS(WORKBENCH)};\n }\n /* The scene sets position: relative inline on its target; the size is given so it still fills the host. */\n div[stage] {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n }\n p {\n position: absolute;\n inset: 45% 1rem auto;\n margin: 0;\n text-align: center;\n pointer-events: none;\n color: #f4f4f4;\n }\n `\n @property({ attribute: false }) parts: FigureRenderPart[] = []\n @property({ attribute: false }) palette: Record<string, string> = {}\n /** Which figure is open. Another one stands the board up again. */\n @property() context = ''\n @property() selected = ''\n /** What the gizmo may write for the selected part; a change beyond it is not applied and the part springs back. */\n @property({ attribute: false }) reach: GizmoReach = { translate: false, rotate: false, scale: false }\n @property({ attribute: false }) view: ViewSettings = DEFAULT_VIEW\n /**\n * View only: nothing that happens on the board is told out. The card's picture is taken from a second canvas stood up\n * off screen (`thumbnail.ts`); the scene settles its components as it builds them, and a change told from there\n * would reach the editor as an edit.\n */\n @property({ type: Boolean }) viewOnly = false\n /** Where the selected part turns and how far (`joint-fan`): shown, never picked, never saved. */\n @property({ attribute: false }) fan: FigureRenderPart | null = null\n\n @query('div[stage]') private stage!: HTMLDivElement\n\n private scene?: SceneHandle\n private board?: Board & { depth: number }\n private standingFor?: string\n private watcher?: ResizeObserver\n /** Set while this canvas writes to components, so the scene's echo of it is not taken for a drag. */\n private writing = false\n\n render() {\n return html`<div stage></div>${this.parts.length ? nothing : html`<p>${i18next.t('figure.text.add-a-shape-to-start')}</p>`}`\n }\n\n firstUpdated() {\n this.standUp()\n this.watcher = new ResizeObserver(() => this.scene?.resize?.())\n this.watcher.observe(this)\n }\n\n protected updated(changed: PropertyValues) {\n if (!this.hasUpdated) return\n if (changed.has('parts') || changed.has('palette') || changed.has('context') || changed.has('fan')) this.standUp()\n if (changed.has('view')) this.applyView()\n if (changed.has('selected')) this.showSelected()\n }\n\n disconnectedCallback() {\n super.disconnectedCallback()\n this.watcher?.disconnect()\n this.watcher = undefined\n this.teardown()\n }\n\n /**\n * The board as a picture, for the card: the 3D view at this size, or nothing when it cannot be taken. The scene's\n * `toDataURL` renders the 2D board (a white sheet), and the 3D renderer keeps no drawing buffer, so the\n * scene's own `snapshot3d` draws and reads in one task. A picture that cannot be taken is not an error and is not\n * faked (user, 2026-09-24: no card had a picture after this canvas moved onto the scene).\n */\n async snapshot(width = 480, height = 360): Promise<string | undefined> {\n const layer = this.scene?.root as (SceneLayer & { snapshot3d?: (w?: number, h?: number, type?: string, quality?: number) => Promise<string | undefined> }) | undefined\n if (!layer?.snapshot3d) return undefined\n try {\n /* webp: a card needs no alpha, and png is three or four times heavier in every list response. */\n const url = await layer.snapshot3d(width, height, 'image/webp', 0.85)\n return typeof url === 'string' && url.startsWith('data:') ? url : undefined\n } catch (e) {\n console.warn(`[thumbnail] could not take the picture -- ${(e as Error).message}`)\n return undefined\n }\n }\n\n /** The whole figure in view: the board's fit, then the 3D camera's own. */\n fit() {\n this.scene?.fit?.('ratio')\n this.scene?.root?.fitCameraToModel?.()\n }\n\n /** The gizmo in a mode on the selected part, as W, E and R do with the canvas focused -- the scene's toggle. */\n gizmo(mode: 'translate' | 'rotate' | 'scale') {\n this.scene?.root?.setGizmoMode?.(mode)\n }\n\n /**\n * Stand the board up for this figure, or bring the one standing up to date. A new board only for another figure or\n * one that has outgrown it -- standing up again loses the selection and the camera.\n */\n private standUp() {\n if (!this.stage) return\n const needed = boardFor(this.parts, this.board)\n const outgrown = !this.board || needed.width > this.board.width || needed.height > this.board.height || needed.depth > this.board.depth\n if (this.scene && this.standingFor === this.context) {\n /*\n A part dragged past the board's edge grows the board where it stands. Standing it up again lost the selection,\n the gizmo and the camera after every such drag -- the gizmo seemed not to work at all (user, 2026-09-24).\n */\n if (outgrown) this.grow(needed)\n this.sync()\n return\n }\n this.teardown()\n if (!this.parts.length) return\n this.board = needed\n try {\n this.scene = create({\n target: this.stage,\n model: {\n type: 'model-layer',\n width: needed.width,\n height: needed.height,\n depth: needed.depth,\n threed: true,\n /* Two samples a pixel: MSAA alone leaves steps on the silhouettes of one asset shown large. */\n pixelRatio: Math.min(3, (window.devicePixelRatio || 1) * 2),\n ...sceneLook(this.view ?? DEFAULT_VIEW),\n gridStep: niceGridStep(Math.max(needed.width, needed.height)),\n sky: 'color',\n fillStyle: PAPER,\n components: this.components()\n },\n /* Editing mode: the camera view buttons, gizmo modes, help and keys. */\n mode: 1\n }) as SceneHandle\n this.standingFor = this.context\n this.watchScene()\n this.scene.resize?.()\n this.fit()\n this.showSelected()\n } catch (error) {\n this.dispatchEvent(new CustomEvent('render-error', { detail: error, bubbles: true, composed: true }))\n }\n }\n\n private components(): Record<string, unknown>[] {\n const parts = this.parts.map(part => componentOf(part, this.palette, this.board!)).filter((c): c is Record<string, unknown> => !!c)\n /* The fan in the accent colour, translucent; `capturable: false` keeps clicks, the marquee and the gizmo off it. */\n const fan = this.fan ? componentOf(this.fan, { ...this.palette, [JOINT_FAN]: this.palette['palette.accent'] ?? FAN_COLOUR }, this.board!) : null\n return fan ? [...parts, { ...fan, capturable: false, locked: true }] : parts\n }\n\n /** The components standing now, by name. Not held between calls: the scene stands its board up again at times. */\n private standing(): Map<string, SceneComponent> {\n const found = new Map<string, SceneComponent>()\n for (const component of this.scene?.root?.components ?? []) {\n const name = component.state?.name\n if (typeof name === 'string') found.set(name, component)\n }\n return found\n }\n\n /** A larger board under the same scene: its size, and the grid that suits it. Components are re-placed by `sync`. */\n private grow(needed: Board & { depth: number }) {\n const layer = this.scene?.root\n this.board = needed\n if (!layer) return\n this.writing = true\n try {\n layer.set({ width: needed.width, height: needed.height, depth: needed.depth, gridStep: niceGridStep(Math.max(needed.width, needed.height)) })\n } finally {\n this.writing = false\n }\n }\n\n /** Bring the components to the evaluation: remove the gone, write only what differs, add the new. */\n private sync() {\n const layer = this.scene?.root\n if (!layer || !this.board) return\n const wanted = new Map(this.components().map(c => [c.name as string, c]))\n const standing = this.standing()\n this.writing = true\n try {\n for (const [name, component] of standing) {\n if (wanted.has(name)) continue\n layer.removeComponent?.(component)\n component.dispose?.()\n }\n for (const [name, state] of wanted) {\n const found = standing.get(name)\n if (found) {\n const diff = changedKeys(found.state, state)\n if (diff) found.set(diff)\n continue\n }\n const made = Model.compile({ ...state }, layer.app as never) as SceneComponent | null\n if (made) layer.addComponent?.(made)\n }\n } finally {\n this.writing = false\n }\n layer.invalidate?.()\n }\n\n /** Selection and drags, told out by the part's name -- never by its place in the list, which may change meanwhile. */\n private watchScene() {\n const layer = this.scene?.root\n const root = layer?.root\n if (!layer || !root?.on || this.viewOnly) return\n root.on('selected', (after: unknown) => {\n const name = (after as SceneComponent[] | undefined)?.[0]?.state?.name\n const id = typeof name === 'string' ? name : ''\n if (ownerOf(id) !== this.selected) this.dispatchEvent(new CustomEvent('part-selected', { detail: id, bubbles: true, composed: true }))\n })\n /*\n A change comes up to the board with the component in the last argument's `origin` (the scene appends\n { origin, name, deliverer } as it bubbles). Reading the first argument as the component does nothing.\n */\n /*\n A drag is written once, when it ends. The scene's gizmo writes the component on every move -- a size anchored on\n the opposite face, from the scale it captured when the drag began -- and writing each move back through the\n editor (and the evaluation back onto the component) fought it: the scale gizmo did not work (user, 2026-09-24).\n While a pointer is down the changes are only kept; on release the last one is told, and the board is brought to\n the evaluation. A change with no pointer down (the arrow keys) is told after a short pause.\n */\n layer.on?.('change', (...args: unknown[]) => {\n if (this.writing) return\n const origin = (args[args.length - 1] as { origin?: SceneComponent } | undefined)?.origin\n const name = origin?.state?.name\n if (typeof name !== 'string' || !this.parts.some(p => p.id === name)) return\n this.pending.set(name, origin!)\n if (!this.pointerDown) this.commitSoon(80)\n })\n this.stage.addEventListener('pointerdown', this.onPointerDown, true)\n window.addEventListener('pointerup', this.onPointerUp, true)\n window.addEventListener('pointercancel', this.onPointerUp, true)\n }\n\n /** Components the gizmo changed since the last commit, by part name. */\n private pending = new Map<string, SceneComponent>()\n private pointerDown = false\n private commitTimer?: ReturnType<typeof setTimeout>\n private onPointerDown = () => {\n this.pointerDown = true\n }\n private onPointerUp = () => {\n if (!this.pointerDown) return\n this.pointerDown = false\n /* After the scene's own drag end (it settles the depth and rebuilds the geometry on release). */\n this.commitSoon(0)\n }\n private commitSoon(delay: number) {\n clearTimeout(this.commitTimer)\n this.commitTimer = setTimeout(() => this.commit(), delay)\n }\n /** Tell each changed part once, in the inputs' terms; then put the board where the inputs say (a refusal springs back). */\n private commit() {\n /*\n Not while a pointer is down: a pause set by a change just before the press (the arrow keys, the scene settling\n the pick) fired in the middle of the drag and wrote where the part was then -- a drag on a part placed by a rule\n became two steps, the first one a few millimetres in (browser check, 2026-09-25). What is pending waits for the release.\n */\n if (this.pointerDown || !this.board || !this.pending.size) return\n const changed = [...this.pending]\n this.pending.clear()\n for (const [name, component] of changed) {\n const part = this.parts.find(p => p.id === name)\n if (!part) continue\n const result = gizmoResultOf(part, component.state, this.board)\n if (!result.position && !result.rotation && !result.scale) continue\n this.dispatchEvent(new CustomEvent('part-transformed', { detail: { id: part.id, result }, bubbles: true, composed: true }))\n }\n setTimeout(() => this.sync())\n }\n\n private showSelected() {\n const layer = this.scene?.root\n const root = layer?.root\n if (!layer || !root) return\n /* A repeat is selected whole: every copy of it (the editor selects the part the author made). */\n const wanted = this.selected ? [...this.standing()].filter(([name]) => ownerOf(name) === this.selected).map(([, component]) => component) : []\n const now = root.selected ?? []\n if (now.length === wanted.length && wanted.every((one, i) => now[i] === one)) return\n root.selected = wanted\n layer.invalidate?.()\n }\n\n /** View settings go into the scene as they are: they are the board's own state names. Nothing is stood up again. */\n private applyView() {\n const layer = this.scene?.root\n if (!layer) return\n layer.set(sceneLook(this.view ?? DEFAULT_VIEW))\n layer.invalidate?.()\n }\n\n private teardown() {\n clearTimeout(this.commitTimer)\n this.pending.clear()\n this.stage?.removeEventListener('pointerdown', this.onPointerDown, true)\n window.removeEventListener('pointerup', this.onPointerUp, true)\n window.removeEventListener('pointercancel', this.onPointerUp, true)\n this.scene?.dispose?.()\n this.scene = undefined\n this.standingFor = undefined\n this.board = undefined\n }\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import type { FigureAsset, FigureInputChange } from '@hatiolab/figure-model';
2
+ export interface ClipKey {
3
+ seconds: number;
4
+ value: number;
5
+ }
6
+ export interface ClipTrack {
7
+ state: string;
8
+ label: string;
9
+ unit: string;
10
+ min: number;
11
+ max: number;
12
+ keys: ClipKey[];
13
+ interpolation: 'linear' | 'step';
14
+ loop: 'wrap' | 'hold';
15
+ accumulates: boolean;
16
+ }
17
+ export interface Clip {
18
+ name: string;
19
+ duration: number;
20
+ tracks: ClipTrack[];
21
+ }
22
+ export declare function clipsOf(asset: FigureAsset): Clip[];
23
+ /** The controls no clip plays yet -- the ones a new track can take. One driver per control. */
24
+ export declare function undrivenOf(asset: FigureAsset): string[];
25
+ /** The pose a clip gives at a moment, as one batch of state changes -- one step of the history. */
26
+ export declare function poseAt(asset: FigureAsset, clip: string, seconds: number): FigureInputChange[];
27
+ /** A key added at a moment, replacing one already there; the keys stay in time order. */
28
+ export declare function withKey(keys: readonly ClipKey[], key: ClipKey): ClipKey[];
29
+ /** A track's keys without one; a track keeps at least its two ends, as the format asks. */
30
+ export declare function withoutKey(keys: readonly ClipKey[], index: number): ClipKey[] | null;
31
+ /** The edit that writes a track back. */
32
+ export declare const trackEdit: (clip: Clip, track: ClipTrack, patch?: Partial<Pick<ClipTrack, "keys" | "loop" | "interpolation">>) => {
33
+ kind: "set-driver";
34
+ state: string;
35
+ clip: string;
36
+ keys: ClipKey[];
37
+ loop: "wrap" | "hold";
38
+ interpolation: "linear" | "step";
39
+ };
@@ -0,0 +1,58 @@
1
+ import { driverValue } from '@hatiolab/figure-model';
2
+ const round = (n) => Math.round(n * 1000) / 1000;
3
+ export function clipsOf(asset) {
4
+ const inputs = new Map(asset.document.model.inputs.map(i => [i.id, i]));
5
+ const clips = new Map();
6
+ for (const d of asset.drivers ?? []) {
7
+ const input = inputs.get(d.state);
8
+ const clip = clips.get(d.clip) ?? { name: d.clip, duration: d.time.duration, tracks: [] };
9
+ clip.tracks.push({
10
+ state: d.state,
11
+ label: asset.stateInputs?.[d.state]?.label ?? d.state,
12
+ unit: input?.unit ?? '',
13
+ min: input?.min ?? 0,
14
+ max: input?.max ?? 0,
15
+ keys: d.keys.map(k => ({ seconds: round(k.at * d.time.duration), value: k.value })),
16
+ interpolation: d.interpolation,
17
+ loop: d.loop,
18
+ accumulates: d.accumulates
19
+ });
20
+ clips.set(d.clip, clip);
21
+ }
22
+ return [...clips.values()];
23
+ }
24
+ /** The controls no clip plays yet -- the ones a new track can take. One driver per control. */
25
+ export function undrivenOf(asset) {
26
+ const driven = new Set((asset.drivers ?? []).map(d => d.state));
27
+ return asset.document.model.inputs.filter(i => i.role === 'state' && !driven.has(i.id)).map(i => i.id);
28
+ }
29
+ /** The pose a clip gives at a moment, as one batch of state changes -- one step of the history. */
30
+ export function poseAt(asset, clip, seconds) {
31
+ const units = new Map(asset.document.model.inputs.map(i => [i.id, i.unit]));
32
+ return (asset.drivers ?? [])
33
+ .filter((d) => d.clip === clip)
34
+ .map(d => {
35
+ const unit = units.get(d.state);
36
+ return { kind: 'set-state', input: d.state, unit, value: driverValue(d, seconds, unit === 'deg' || unit === 'rad' ? unit : 'other') };
37
+ });
38
+ }
39
+ /** A key added at a moment, replacing one already there; the keys stay in time order. */
40
+ export function withKey(keys, key) {
41
+ return [...keys.filter(k => k.seconds !== key.seconds), key].sort((a, b) => a.seconds - b.seconds);
42
+ }
43
+ /** A track's keys without one; a track keeps at least its two ends, as the format asks. */
44
+ export function withoutKey(keys, index) {
45
+ if (keys.length <= 2 || index === 0)
46
+ return null;
47
+ return keys.filter((_, i) => i !== index);
48
+ }
49
+ /** The edit that writes a track back. */
50
+ export const trackEdit = (clip, track, patch = {}) => ({
51
+ kind: 'set-driver',
52
+ state: track.state,
53
+ clip: clip.name,
54
+ keys: patch.keys ?? track.keys,
55
+ loop: patch.loop ?? track.loop,
56
+ interpolation: patch.interpolation ?? track.interpolation
57
+ });
58
+ //# sourceMappingURL=clips.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clips.js","sourceRoot":"","sources":["../../client/modeller/clips.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AA4BpD,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;AAExD,MAAM,UAAU,OAAO,CAAC,KAAkB;IACxC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACvE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAA;IACrC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;QACjC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,C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,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAA;AACpG,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,UAAU,CAAC,IAAwB,EAAE,KAAa;IAChE,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAChD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAA;AAC3C,CAAC;AAED,yCAAyC;AACzC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAU,EAAE,KAAgB,EAAE,QAAqE,EAAE,EAAE,EAAE,CAAC,CAAC;IACnI,IAAI,EAAE,YAAqB;IAC3B,KAAK,EAAE,KAAK,CAAC,KAAK;IAClB,IAAI,EAAE,IAAI,CAAC,IAAI;IACf,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI;IAC9B,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI;IAC9B,aAAa,EAAE,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa;CAC1D,CAAC,CAAA","sourcesContent":["import { driverValue } from '@hatiolab/figure-model'\nimport type { FigureAsset, FigureDriver, FigureInputChange } from '@hatiolab/figure-model'\n\n/*\n * The figure's clips: controls played by keys over time, grouped into clips that each run on one\n * clock. Kept apart from the element so the reading is tested without a browser.\n */\nexport interface ClipKey {\n seconds: number\n value: number\n}\nexport interface ClipTrack {\n state: string\n label: string\n unit: string\n min: number\n max: number\n keys: ClipKey[]\n interpolation: 'linear' | 'step'\n loop: 'wrap' | 'hold'\n accumulates: boolean\n}\nexport interface Clip {\n name: string\n duration: number\n tracks: ClipTrack[]\n}\n\nconst round = (n: number) => Math.round(n * 1000) / 1000\n\nexport function clipsOf(asset: FigureAsset): Clip[] {\n const inputs = new Map(asset.document.model.inputs.map(i => [i.id, i]))\n const clips = new Map<string, Clip>()\n for (const d of asset.drivers ?? []) {\n const input = inputs.get(d.state)\n const clip = clips.get(d.clip) ?? { name: d.clip, duration: d.time.duration, tracks: [] }\n clip.tracks.push({\n state: d.state,\n label: asset.stateInputs?.[d.state]?.label ?? d.state,\n unit: input?.unit ?? '',\n min: input?.min ?? 0,\n max: input?.max ?? 0,\n keys: d.keys.map(k => ({ seconds: round(k.at * d.time.duration), value: k.value })),\n interpolation: d.interpolation,\n loop: d.loop,\n accumulates: d.accumulates\n })\n clips.set(d.clip, clip)\n }\n return [...clips.values()]\n}\n\n/** The controls no clip plays yet -- the ones a new track can take. One driver per control. */\nexport function undrivenOf(asset: FigureAsset): string[] {\n const driven = new Set((asset.drivers ?? []).map(d => d.state))\n return asset.document.model.inputs.filter(i => i.role === 'state' && !driven.has(i.id)).map(i => i.id)\n}\n\n/** The pose a clip gives at a moment, as one batch of state changes -- one step of the history. */\nexport function poseAt(asset: FigureAsset, clip: string, seconds: number): FigureInputChange[] {\n const units = new Map(asset.document.model.inputs.map(i => [i.id, i.unit]))\n return (asset.drivers ?? [])\n .filter((d: FigureDriver) => d.clip === clip)\n .map(d => {\n const unit = units.get(d.state)!\n return { kind: 'set-state' as const, input: d.state, unit, value: driverValue(d, seconds, unit === 'deg' || unit === 'rad' ? unit : 'other') }\n })\n}\n\n/** A key added at a moment, replacing one already there; the keys stay in time order. */\nexport function withKey(keys: readonly ClipKey[], key: ClipKey): ClipKey[] {\n return [...keys.filter(k => k.seconds !== key.seconds), key].sort((a, b) => a.seconds - b.seconds)\n}\n\n/** A track's keys without one; a track keeps at least its two ends, as the format asks. */\nexport function withoutKey(keys: readonly ClipKey[], index: number): ClipKey[] | null {\n if (keys.length <= 2 || index === 0) return null\n return keys.filter((_, i) => i !== index)\n}\n\n/** The edit that writes a track back. */\nexport const trackEdit = (clip: Clip, track: ClipTrack, patch: Partial<Pick<ClipTrack, 'keys' | 'loop' | 'interpolation'>> = {}) => ({\n kind: 'set-driver' as const,\n state: track.state,\n clip: clip.name,\n keys: patch.keys ?? track.keys,\n loop: patch.loop ?? track.loop,\n interpolation: patch.interpolation ?? track.interpolation\n})\n"]}
@@ -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/modeller/controls.ts"],"names":[],"mappings":"AAyBA,MAAM,UAAU,UAAU,CAAC,KAAkB,EAAE,SAAiC,EAAE;IAChF,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM;SAC/B,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC;SACvC,GAAG,CAAC,KAAK,CAAC,EAAE;QACX,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,GAAG,CAAA;QACxD,OAAO;YACL,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,KAAK,CAAC,EAAE;YAChC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,KAAK;YAChC,KAAK;YACL,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;YACzB,IAAI,EAAE,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG;SAC/D,CAAA;IACH,CAAC,CAAC,CAAA;AACN,CAAC;AAED,2GAA2G;AAC3G,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAA4B,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC,CAAA;AAEpG,uEAAuE;AACvE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAA4B,EAAE,EAAE,CAAC,CAAC;IAC9D,IAAI,EAAE,oBAA6B;IACnC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,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"]}