@things-factory/figure-ui 10.1.43 → 10.1.45

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 (128) hide show
  1. package/client/modeller/figure-v3-links.ts +303 -0
  2. package/client/modeller/modeller-route.ts +6 -21
  3. package/client/modeller/v3-editor.ts +44 -3
  4. package/client/modeller/v3-gizmo.ts +13 -2
  5. package/client/modeller/v3-links.ts +138 -0
  6. package/client/pages/figure-v3-modeller-page.ts +2 -5
  7. package/client/route.ts +2 -6
  8. package/dist-client/modeller/figure-v3-links.d.ts +42 -0
  9. package/dist-client/modeller/figure-v3-links.js +306 -0
  10. package/dist-client/modeller/figure-v3-links.js.map +1 -0
  11. package/dist-client/modeller/modeller-route.d.ts +4 -11
  12. package/dist-client/modeller/modeller-route.js +5 -22
  13. package/dist-client/modeller/modeller-route.js.map +1 -1
  14. package/dist-client/modeller/v3-editor.d.ts +5 -0
  15. package/dist-client/modeller/v3-editor.js +46 -2
  16. package/dist-client/modeller/v3-editor.js.map +1 -1
  17. package/dist-client/modeller/v3-gizmo.js +11 -1
  18. package/dist-client/modeller/v3-gizmo.js.map +1 -1
  19. package/dist-client/modeller/v3-links.d.ts +54 -0
  20. package/dist-client/modeller/v3-links.js +110 -0
  21. package/dist-client/modeller/v3-links.js.map +1 -0
  22. package/dist-client/pages/figure-v3-modeller-page.d.ts +2 -5
  23. package/dist-client/pages/figure-v3-modeller-page.js +2 -5
  24. package/dist-client/pages/figure-v3-modeller-page.js.map +1 -1
  25. package/dist-client/route.d.ts +1 -1
  26. package/dist-client/route.js +2 -5
  27. package/dist-client/route.js.map +1 -1
  28. package/dist-client/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +4 -4
  30. package/test/ai-proposal-contract.test.ts +0 -88
  31. package/test/figure-source.test.ts +0 -102
  32. package/test/i18n-prefix-guard.test.ts +0 -24
  33. package/test/modeller-route.test.ts +14 -25
  34. package/test/part-edits.test.ts +0 -7
  35. package/test/scene-budget.test.ts +0 -7
  36. package/test/v3-gizmo.test.ts +10 -0
  37. package/test/v3-links.test.ts +123 -0
  38. package/things-factory.config.js +2 -5
  39. package/translations/en.json +6 -0
  40. package/translations/ja.json +11 -1
  41. package/translations/ko.json +6 -0
  42. package/translations/ms.json +11 -1
  43. package/translations/zh.json +11 -1
  44. package/client/modeller/angle-dial.ts +0 -70
  45. package/client/modeller/base-box.ts +0 -175
  46. package/client/modeller/figure-animations.ts +0 -1249
  47. package/client/modeller/figure-canvas.ts +0 -567
  48. package/client/modeller/figure-capabilities.ts +0 -379
  49. package/client/modeller/figure-inspector.ts +0 -2208
  50. package/client/modeller/figure-parts.ts +0 -479
  51. package/client/modeller/figure-preview.ts +0 -598
  52. package/client/modeller/figure-report.ts +0 -966
  53. package/client/modeller/figure-settings.ts +0 -328
  54. package/client/modeller/figure-side.ts +0 -272
  55. package/client/modeller/figure-thumbnail.ts +0 -123
  56. package/client/modeller/figure-view.ts +0 -152
  57. package/client/modeller/joint-edits.ts +0 -262
  58. package/client/modeller/joint-gizmo.ts +0 -180
  59. package/client/modeller/maturity.ts +0 -288
  60. package/client/modeller/new-figure-entry.ts +0 -4
  61. package/client/modeller/pose-defaults.ts +0 -67
  62. package/client/pages/figure-modeller-page.ts +0 -2082
  63. package/dist-client/modeller/angle-dial.d.ts +0 -32
  64. package/dist-client/modeller/angle-dial.js +0 -41
  65. package/dist-client/modeller/angle-dial.js.map +0 -1
  66. package/dist-client/modeller/base-box.d.ts +0 -71
  67. package/dist-client/modeller/base-box.js +0 -110
  68. package/dist-client/modeller/base-box.js.map +0 -1
  69. package/dist-client/modeller/figure-animations.d.ts +0 -159
  70. package/dist-client/modeller/figure-animations.js +0 -1132
  71. package/dist-client/modeller/figure-animations.js.map +0 -1
  72. package/dist-client/modeller/figure-canvas.d.ts +0 -150
  73. package/dist-client/modeller/figure-canvas.js +0 -506
  74. package/dist-client/modeller/figure-canvas.js.map +0 -1
  75. package/dist-client/modeller/figure-capabilities.d.ts +0 -42
  76. package/dist-client/modeller/figure-capabilities.js +0 -349
  77. package/dist-client/modeller/figure-capabilities.js.map +0 -1
  78. package/dist-client/modeller/figure-inspector.d.ts +0 -329
  79. package/dist-client/modeller/figure-inspector.js +0 -2095
  80. package/dist-client/modeller/figure-inspector.js.map +0 -1
  81. package/dist-client/modeller/figure-parts.d.ts +0 -64
  82. package/dist-client/modeller/figure-parts.js +0 -478
  83. package/dist-client/modeller/figure-parts.js.map +0 -1
  84. package/dist-client/modeller/figure-preview.d.ts +0 -138
  85. package/dist-client/modeller/figure-preview.js +0 -549
  86. package/dist-client/modeller/figure-preview.js.map +0 -1
  87. package/dist-client/modeller/figure-report.d.ts +0 -165
  88. package/dist-client/modeller/figure-report.js +0 -952
  89. package/dist-client/modeller/figure-report.js.map +0 -1
  90. package/dist-client/modeller/figure-settings.d.ts +0 -39
  91. package/dist-client/modeller/figure-settings.js +0 -317
  92. package/dist-client/modeller/figure-settings.js.map +0 -1
  93. package/dist-client/modeller/figure-side.d.ts +0 -78
  94. package/dist-client/modeller/figure-side.js +0 -317
  95. package/dist-client/modeller/figure-side.js.map +0 -1
  96. package/dist-client/modeller/figure-thumbnail.d.ts +0 -3
  97. package/dist-client/modeller/figure-thumbnail.js +0 -95
  98. package/dist-client/modeller/figure-thumbnail.js.map +0 -1
  99. package/dist-client/modeller/figure-view.d.ts +0 -118
  100. package/dist-client/modeller/figure-view.js +0 -78
  101. package/dist-client/modeller/figure-view.js.map +0 -1
  102. package/dist-client/modeller/joint-edits.d.ts +0 -49
  103. package/dist-client/modeller/joint-edits.js +0 -223
  104. package/dist-client/modeller/joint-edits.js.map +0 -1
  105. package/dist-client/modeller/joint-gizmo.d.ts +0 -34
  106. package/dist-client/modeller/joint-gizmo.js +0 -158
  107. package/dist-client/modeller/joint-gizmo.js.map +0 -1
  108. package/dist-client/modeller/maturity.d.ts +0 -55
  109. package/dist-client/modeller/maturity.js +0 -212
  110. package/dist-client/modeller/maturity.js.map +0 -1
  111. package/dist-client/modeller/new-figure-entry.d.ts +0 -2
  112. package/dist-client/modeller/new-figure-entry.js +0 -5
  113. package/dist-client/modeller/new-figure-entry.js.map +0 -1
  114. package/dist-client/modeller/pose-defaults.d.ts +0 -9
  115. package/dist-client/modeller/pose-defaults.js +0 -35
  116. package/dist-client/modeller/pose-defaults.js.map +0 -1
  117. package/dist-client/pages/figure-modeller-page.d.ts +0 -419
  118. package/dist-client/pages/figure-modeller-page.js +0 -2060
  119. package/dist-client/pages/figure-modeller-page.js.map +0 -1
  120. package/test/angle-dial.test.ts +0 -78
  121. package/test/base-box.test.ts +0 -235
  122. package/test/joint-edits.test.ts +0 -165
  123. package/test/joint-gizmo.test.ts +0 -174
  124. package/test/joint-needle.test.ts +0 -162
  125. package/test/modeller-undo-redo.test.ts +0 -33
  126. package/test/new-figure-entry.test.ts +0 -15
  127. package/test/pose-defaults.test.ts +0 -71
  128. package/test/preview-board-depth.test.ts +0 -27
@@ -1,1249 +0,0 @@
1
- import { css, html, LitElement, nothing, type TemplateResult } from 'lit'
2
- import { customElement, property, state } from 'lit/decorators.js'
3
- import { live } from 'lit/directives/live.js'
4
-
5
- import { i18next, localize } from '@operato/i18n'
6
- import { ScrollbarStyles } from '@operato/styles'
7
-
8
- import { AXES, CHANNEL_PATHS, INTERPOLATIONS, LIMITS } from '@hatiolab/figure-model'
9
- import type { ChannelPath, JointChannel, PartChannel, Vec3 } from '@hatiolab/figure-model'
10
-
11
- import type { FigureDraft, PartModel } from './figure-source.js'
12
-
13
- /**
14
- * 이 도형이 **어떻게 움직이는가.**
15
- *
16
- * ## 왜 탭 하나가 필요한가
17
- *
18
- * 움직임은 형식에 있고 런타임까지 서 있었다 — 검증이 촘촘히 보고, 청사진이 움직이는 부품을
19
- * 단독 묶음으로 빼고(합치면 따로 못 움직인다), 씬이 frameClock 을 구독해 실제로 돌린다.
20
- * 미리보기에도 clip 마다 슬라이더가 있었다.
21
- *
22
- * **만들 자리만 없었다.** 그래서 움직이는 도형을 얻는 길이 「AI 가 후보로 내놓는 것」 하나였고,
23
- * 채널 하나를 고치려면 손댈 화면이 없었다.
24
- *
25
- * ## 부품이 아니라 도형의 것이다
26
- *
27
- * clip 하나가 부품 여럿을 함께 움직인다 — 문 열림은 왼짝과 오른짝이 반대로 미끄러지는 것
28
- * 하나다. 그래서 부품을 고르고 「이 부품의 움직임」을 적는 형태가 될 수 없고, 속성 탭이 아니라
29
- * 자기 탭에 산다.
30
- *
31
- * ## 트윈은 타임라인을 재생하지 않는다
32
- *
33
- * 「문 열기 clip 을 재생하라」가 아니라 **「지금 40% 열려 있다」**다. 그 둘은 다른 것이라
34
- * 이 탭도 둘로 나뉜다.
35
- *
36
- * 애니메이션 시각이 흐른다. 인스턴스가 주는 수는 배속이다 — 도는 롤러
37
- * 파라미터 값이 자세를 만든다. 인스턴스가 주는 수는 물리량이다 — 1200mm 내려온 호이스트
38
- *
39
- * 한동안 뒤엣것이 애니메이션 안에 `drive: 'hold'` 로 숨어 있었다. 형식의 판단은 맞았는데
40
- * **자리와 이름이 틀려서**, 「길이값을 변수로 노출하라」는 요청에 저작자도 AI 도 이것을
41
- * 못 찾았다 — 애니메이션 칸에 있을 거라고 생각하지 않는다(ADR-0051).
42
- */
43
-
44
- type Clip = NonNullable<FigureDraft['animations']>[number]
45
- type Parameter = NonNullable<FigureDraft['parameters']>[number]
46
- type Channel = Clip['channels'][number]
47
- type Keyframe = PartChannel['keys'][number]
48
- type JointKey = JointChannel['keys'][number]
49
-
50
- /** A channel that drives a joint names the joint and carries one number per key (ADR-0066). */
51
- function isJointChannel(channel: Channel): channel is JointChannel {
52
- return channel.path === undefined
53
- }
54
-
55
- /** 어느 목록의 몇째인가. 채널·키 편집기가 둘을 함께 쓴다. */
56
- type MotionKind = 'clip' | 'parameter'
57
-
58
- /** A first-success motion: intent first, raw channel editing second. */
59
- interface MotionRecipe {
60
- id: 'conveyor' | 'gate' | 'pusher' | 'lift'
61
- name: string
62
- kind: MotionKind
63
- path: ChannelPath
64
- end: Vec3
65
- pivot?: Vec3
66
- /** 파라미터 레시피만. 인스턴스가 주고받는 물리량이다. */
67
- range?: Parameter['range']
68
- }
69
-
70
- /*
71
- 레시피의 `end` 가 곧 그 범위의 끝 자세다 — 리프트가 100mm 올라가는 곡선이면 범위도
72
- 0~100mm 다. 둘이 어긋나면 저작자가 1200 을 주고도 100 만 올라가는 것을 보게 된다.
73
- */
74
- const MOTION_RECIPES: readonly MotionRecipe[] = [
75
- { id: 'conveyor', name: 'conveyor-running', kind: 'clip', path: 'rotation', end: { x: 360, y: 0, z: 0 } },
76
- {
77
- id: 'gate',
78
- name: 'gate-open',
79
- kind: 'parameter',
80
- path: 'rotation',
81
- end: { x: 0, y: 90, z: 0 },
82
- pivot: { x: 0, y: 0, z: 0 },
83
- range: { unit: '%', min: 0, max: 100 }
84
- },
85
- {
86
- id: 'pusher',
87
- name: 'pusher-position',
88
- kind: 'parameter',
89
- path: 'translation',
90
- end: { x: 100, y: 0, z: 0 },
91
- range: { unit: 'mm', min: 0, max: 100 }
92
- },
93
- {
94
- id: 'lift',
95
- name: 'lift-height',
96
- kind: 'parameter',
97
- path: 'translation',
98
- end: { x: 0, y: 100, z: 0 },
99
- range: { unit: 'mm', min: 0, max: 100 }
100
- }
101
- ]
102
-
103
- /** 새 파라미터의 범위. 단위는 저작자가 고쳐 쓴다 — 형식은 단위를 해석하지 않는다. */
104
- const NEW_RANGE: Parameter['range'] = { unit: 'mm', min: 0, max: 1000 }
105
-
106
- /** 새 clip 의 키 둘. **하나로 만들지 않는다** — 키 하나는 움직임이 아니라 자세다. */
107
- const NEW_KEYS: Keyframe[] = [
108
- { at: 0, value: { x: 0, y: 0, z: 0 } },
109
- { at: 1, value: { x: 0, y: 0, z: 0 } }
110
- ]
111
-
112
- /** `scale` 만 1 에서 시작한다 — 0 은 부품을 지운다. */
113
- function startValue(path: ChannelPath): Vec3 {
114
- return path === 'scale' ? { x: 1, y: 1, z: 1 } : { x: 0, y: 0, z: 0 }
115
- }
116
-
117
- function keysFor(path: ChannelPath): Keyframe[] {
118
- return NEW_KEYS.map(key => ({ at: key.at, value: startValue(path) }))
119
- }
120
-
121
- /**
122
- * 이미 쓴 이름을 비켜 간다.
123
- *
124
- * **두 목록을 함께 본다.** 인스턴스는 이름 하나로 값을 주므로 애니메이션과 파라미터가
125
- * 같은 이름을 가지면 어느 쪽에 준 것인지 알 수 없고, 형식이 그것을 오류로 막는다.
126
- */
127
- function freeName(taken: readonly { name: string }[], stem: string): string {
128
- const used = new Set(taken.map(one => one.name))
129
- if (!used.has(stem)) return stem
130
- for (let n = 2; ; n++) if (!used.has(`${stem}-${n}`)) return `${stem}-${n}`
131
- }
132
-
133
- /**
134
- * 파라미터 범위에 적히는 단위 — **권하는 것이지 가두는 것이 아니다.**
135
- *
136
- * 관절이 만드는 파라미터가 `deg` 와 `mm` 을 쓰고(회전과 직선), 그리퍼·문 같은 값은 `%` 를 쓴다.
137
- * 속도는 `mm/s` 와 `rpm`, 시간은 `s` 다. 이 여섯이 지금 쓰이는 전부이고, 목록에 없는 말을 적는
138
- * 길은 그대로 열려 있다.
139
- */
140
- const PARAMETER_UNITS = ['deg', 'mm', '%', 'mm/s', 'rpm', 's'] as const
141
-
142
- /** 목록 대신 손으로 적겠다는 표. `select` 의 값으로 쓴다. */
143
- const UNIT_TYPE_IT = '__type-it'
144
-
145
- @customElement('figure-animations')
146
- export class FigureAnimations extends localize(i18next)(LitElement) {
147
- static styles = [
148
- ScrollbarStyles,
149
- css`
150
- :host {
151
- display: flex;
152
- flex-direction: column;
153
- min-height: 0;
154
- overflow-y: auto;
155
- background-color: var(--md-sys-color-surface-container-lowest);
156
- color: var(--md-sys-color-on-surface);
157
- font: var(--label-font, inherit);
158
- font-size: 0.76rem;
159
- }
160
-
161
- section {
162
- display: flex;
163
- flex-direction: column;
164
- gap: var(--spacing-medium, 8px);
165
- padding: var(--spacing-large, 12px);
166
- border-bottom: 1px solid var(--md-sys-color-outline-variant);
167
- }
168
-
169
- /* 다른 탭들과 같은 눈금이다 */
170
- h3 {
171
- margin: 0 0 2px 0;
172
- font-size: var(--ui-t-micro, 11px);
173
- font-weight: 700;
174
- letter-spacing: 0.04em;
175
- text-transform: uppercase;
176
- color: var(--md-sys-color-on-surface-variant, var(--md-sys-color-on-surface));
177
- }
178
-
179
- p[quiet] {
180
- margin: 0;
181
- font-size: 0.72rem;
182
- line-height: 1.5;
183
- color: var(--md-sys-color-on-surface-variant);
184
- }
185
-
186
- div[recipes] { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
187
- button[recipe] { min-height: 54px; align-items: flex-start; flex-direction: column; text-align: left; }
188
- button[recipe] strong { font-size: 0.74rem; }
189
- button[recipe] span { color: var(--md-sys-color-on-surface-variant); font-size: 0.68rem; line-height: 1.35; }
190
-
191
- /* ── clip ─────────────────────────────────────────────────────── */
192
-
193
- div[clip] {
194
- display: flex;
195
- flex-direction: column;
196
- gap: var(--spacing-medium, 8px);
197
- padding: 8px;
198
- border: 1px solid var(--md-sys-color-outline-variant);
199
- border-radius: 4px;
200
- }
201
- div[clip][on] {
202
- border-color: var(--md-sys-color-primary);
203
- background-color: var(--md-sys-color-surface-container-low);
204
- }
205
-
206
- div[head] {
207
- display: flex;
208
- align-items: center;
209
- gap: 6px;
210
- }
211
- div[head] input[name] {
212
- flex: 1;
213
- min-width: 0;
214
- }
215
-
216
- /* ── channel ──────────────────────────────────────────────────── */
217
-
218
- div[channel] {
219
- display: flex;
220
- flex-direction: column;
221
- gap: 6px;
222
- padding: 6px 8px;
223
- border-left: 2px solid var(--md-sys-color-outline-variant);
224
- background-color: var(--md-sys-color-surface-container-lowest);
225
- }
226
- div[channel][orphan] {
227
- border-left-color: var(--md-sys-color-error);
228
- }
229
-
230
- div[row] {
231
- display: flex;
232
- align-items: center;
233
- gap: 6px;
234
- }
235
- div[row] > label {
236
- flex: none;
237
- min-width: 3.2em;
238
- color: var(--md-sys-color-on-surface-variant);
239
- }
240
- /*
241
- 칸이 줄어들 줄 알아야 한다. 숫자 입력칸은 제 기본 너비(20자 남짓)를 갖고 있고 flex 는
242
- 기본 크기 아래로는 안 줄이므로, 범위처럼 한 줄에 셋이 서는 줄은 패널 밖으로 밀려
243
- 오른쪽 칸이 잘렸다.
244
- */
245
- div[row] > input {
246
- flex: 1 1 0;
247
- min-width: 0;
248
- }
249
- /* 단위는 「mm」 정도의 짧은 말이라 숫자 칸보다 좁게 둔다. 고르는 칸도 같은 폭이다. */
250
- div[row] > input[unit],
251
- div[row] > select[unit] {
252
- flex: 0 1 5.5em;
253
- min-width: 0;
254
- }
255
-
256
- /* ── keyframe ─────────────────────────────────────────────────── */
257
-
258
- table[keys] {
259
- width: 100%;
260
- border-collapse: collapse;
261
- }
262
- table[keys] th {
263
- padding: 0 2px 2px;
264
- font-size: 0.68rem;
265
- font-weight: 600;
266
- text-align: left;
267
- color: var(--md-sys-color-on-surface-variant);
268
- }
269
- table[keys] td {
270
- padding: 1px 2px;
271
- }
272
- table[keys] input {
273
- width: 100%;
274
- min-width: 0;
275
- }
276
- table[keys] td[drop] {
277
- width: 1.6em;
278
- }
279
-
280
- input,
281
- select {
282
- box-sizing: border-box;
283
- padding: 3px 5px;
284
- font: inherit;
285
- font-size: 0.74rem;
286
- color: var(--md-sys-color-on-surface);
287
- background-color: var(--md-sys-color-surface-container-lowest);
288
- border: 1px solid var(--md-sys-color-outline-variant);
289
- border-radius: 3px;
290
- }
291
- input:focus,
292
- select:focus {
293
- outline: none;
294
- border-color: var(--md-sys-color-primary);
295
- }
296
- input[bad] {
297
- border-color: var(--md-sys-color-error);
298
- }
299
-
300
- button {
301
- display: inline-flex;
302
- align-items: center;
303
- gap: 3px;
304
- padding: 3px 8px;
305
- font: inherit;
306
- font-size: 0.72rem;
307
- color: var(--md-sys-color-on-surface);
308
- background-color: var(--md-sys-color-surface-container);
309
- border: 1px solid var(--md-sys-color-outline-variant);
310
- border-radius: 3px;
311
- cursor: pointer;
312
- }
313
- button:hover:not(:disabled) {
314
- background-color: var(--md-sys-color-surface-container-high);
315
- }
316
- button:disabled {
317
- opacity: 0.4;
318
- cursor: default;
319
- }
320
- button[plain] {
321
- padding: 1px 4px;
322
- background: none;
323
- border: none;
324
- color: var(--md-sys-color-on-surface-variant);
325
- }
326
- button[plain]:hover:not(:disabled) {
327
- color: var(--md-sys-color-error);
328
- background: none;
329
- }
330
- button md-icon {
331
- font-size: 14px;
332
- width: 14px;
333
- height: 14px;
334
- }
335
-
336
- /* ── 예산 ─────────────────────────────────────────────────────── */
337
-
338
- div[budget] {
339
- display: flex;
340
- align-items: baseline;
341
- gap: 6px;
342
- }
343
- div[budget] strong {
344
- font-size: 0.86rem;
345
- font-weight: 700;
346
- }
347
- div[budget][over] strong {
348
- color: var(--md-sys-color-error);
349
- }
350
-
351
- p[warn] {
352
- margin: 0;
353
- font-size: 0.7rem;
354
- line-height: 1.5;
355
- color: var(--md-sys-color-error);
356
- }
357
- `
358
- ]
359
-
360
- @property({ type: Object }) draft?: FigureDraft
361
- @property({ type: Array }) parts: PartModel[] = []
362
-
363
- /**
364
- * 펼쳐 둔 것. 이름이 아니라 **목록과 자리**로 잡는다 — 이름은 편집 중에 바뀐다.
365
- *
366
- * 목록이 둘이므로 자리 하나로는 모자란다. `clip:0` 과 `parameter:0` 은 다른 것이다.
367
- */
368
- @state() private open = ''
369
- @state() private recipeTarget = ''
370
-
371
- /** 단위를 손으로 적는 중인 파라미터. 목록에 없는 말을 적으려고 연 칸이다. */
372
- @state() private typingUnit = new Set<number>()
373
-
374
- private get clips(): Clip[] {
375
- return this.draft?.animations ?? []
376
- }
377
-
378
- private get parameters(): Parameter[] {
379
- return this.draft?.parameters ?? []
380
- }
381
-
382
- /** 두 목록의 이름을 한자리에서 본다 — 인스턴스가 이름 하나로 값을 준다. */
383
- private get allNames(): { name: string }[] {
384
- return [...this.clips, ...this.parameters]
385
- }
386
-
387
- private channelsOf(kind: MotionKind, at: number): Channel[] {
388
- return (kind === 'clip' ? this.clips[at]?.channels : this.parameters[at]?.clip?.channels) ?? []
389
- }
390
-
391
- /** 부품 이름 — 채널이 이것을 가리킨다. */
392
- private get partNames(): string[] {
393
- return this.parts.map(part => part.name).filter(name => !!name)
394
- }
395
-
396
- /** Joints a channel can drive instead of a part (ADR-0066). */
397
- private get joints(): NonNullable<FigureDraft['joints']> {
398
- return this.draft?.joints ?? []
399
- }
400
-
401
- /**
402
- * 몇 부품이 움직이나 — 채널이 가리키는 **서로 다른 부품**의 수.
403
- *
404
- * clip 수가 아니다. 한 부품을 세 clip 이 움직여도 그 부품 하나가 단독 묶음이 될 뿐이다.
405
- * 청사진이 묶음을 가르는 기준과 같은 셈이어야 화면의 수와 판정의 수가 맞는다.
406
- */
407
- private get movingParts(): number {
408
- const moving = new Set<string>()
409
- for (const clip of this.clips) for (const channel of clip.channels) moving.add(channel.target)
410
- for (const parameter of this.parameters) {
411
- for (const channel of parameter.clip?.channels ?? []) moving.add(channel.target)
412
- }
413
- return moving.size
414
- }
415
-
416
- render(): TemplateResult {
417
- if (!this.draft) return html``
418
-
419
- const nameless = this.partNames.length === 0
420
-
421
- return html`
422
- <section>
423
- <h3>${i18next.t('figure.label.animation')}</h3>
424
- </section>
425
-
426
- ${this.renderRecipes()}
427
-
428
- <section>
429
- <h3>${i18next.t('figure.label.parameters')}</h3>
430
- <p quiet>${i18next.t('figure.text.parameter-is-a-value-not-a-timeline')}</p>
431
- ${this.parameters.map((parameter, at) => this.renderParameter(parameter, at))}
432
- <button @click=${() => this.addParameter()} ?disabled=${nameless}>
433
- <md-icon>add</md-icon>${i18next.t('figure.button.add-parameter')}
434
- </button>
435
- </section>
436
-
437
- <section>
438
- <h3>${i18next.t('figure.label.clips')}</h3>
439
- <p quiet>${i18next.t('figure.text.clip-is-time-running')}</p>
440
- ${this.clips.map((clip, at) => this.renderClip(clip, at))}
441
- <button @click=${() => this.addClip()} ?disabled=${nameless}>
442
- <md-icon>add</md-icon>${i18next.t('figure.button.add-clip')}
443
- </button>
444
- ${nameless ? html`<p quiet>${i18next.t('figure.text.animation-needs-a-named-part')}</p>` : nothing}
445
- </section>
446
-
447
- ${this.movingParts === 0 ? nothing : this.renderBudget()}
448
- `
449
- }
450
-
451
- /**
452
- * 빈 화면 — **이 탭이 무엇인지 가르치는 자리다.**
453
- *
454
- * 「clip 을 추가하세요」라고만 쓰면 처음 여는 사람은 clip 이 무엇인지 모른 채 단추를 누른다.
455
- * 그래서 무엇을 만들 수 있는지 예를 들고, 그것이 어떻게 움직이는지(사실이 들어온다)를 적는다.
456
- */
457
- private renderRecipes(): TemplateResult {
458
- return html`
459
- <section>
460
- <h3>${i18next.t('figure.label.motion-intent')}</h3>
461
- <p quiet>${i18next.t('figure.text.motion-intent-help')}</p>
462
- ${this.partNames.length
463
- ? html`<select .value=${this.recipeTarget} @change=${(e: Event) => (this.recipeTarget = (e.target as HTMLSelectElement).value)}>
464
- ${this.partNames.map(name => html`<option value=${name}>${name}</option>`)}
465
- </select>
466
- <div recipes>
467
- ${MOTION_RECIPES.map(recipe => html`
468
- <button recipe @click=${() => this.addRecipe(recipe)}>
469
- <strong>${i18next.t('figure.label.recipe-' + recipe.id)}</strong>
470
- <span>${i18next.t('figure.text.recipe-' + recipe.id)}</span>
471
- </button>
472
- `)}
473
- </div>`
474
- : html`<p quiet>${i18next.t('figure.text.animation-needs-a-named-part')}</p>`}
475
- </section>
476
- `
477
- }
478
-
479
- /** 이름이 다른 것과 겹치나. 두 목록을 함께 본다 — 인스턴스는 이름 하나로 값을 준다. */
480
- private taken(kind: MotionKind, at: number, name: string): boolean {
481
- const mine = kind === 'clip' ? this.clips[at] : this.parameters[at]
482
- return this.allNames.some(one => one !== mine && one.name === name)
483
- }
484
-
485
- private renderClip(clip: Clip, at: number): TemplateResult {
486
- const key = `clip:${at}`
487
- const on = this.open === key
488
- const duplicate = this.taken('clip', at, clip.name)
489
- const nameless = !clip.name?.trim()
490
-
491
- return html`
492
- <div clip ?on=${on}>
493
- <div head>
494
- <button plain @click=${() => (this.open = on ? '' : key)} title=${i18next.t('figure.label.channels')}>
495
- <md-icon>${on ? 'expand_more' : 'chevron_right'}</md-icon>
496
- </button>
497
- <input
498
- name
499
- .value=${live(clip.name ?? '')}
500
- ?bad=${duplicate || nameless}
501
- placeholder=${i18next.t('figure.label.clip-name')}
502
- title=${duplicate ? i18next.t('figure.text.clip-name-taken') : i18next.t('figure.text.clip-name-is-how-it-is-driven')}
503
- @change=${(e: Event) => this.renameClip(at, (e.target as HTMLInputElement).value)}
504
- />
505
- <button plain @click=${() => this.removeClip(at)} title=${i18next.t('figure.button.remove')}>
506
- <md-icon>close</md-icon>
507
- </button>
508
- </div>
509
-
510
- ${duplicate ? html`<p warn>${i18next.t('figure.text.clip-name-taken')}</p>` : nothing}
511
- ${nameless ? html`<p warn>${i18next.t('figure.text.clip-needs-a-name')}</p>` : nothing}
512
- ${on ? this.renderChannels('clip', at) : nothing}
513
- </div>
514
- `
515
- }
516
-
517
- /**
518
- * 파라미터 하나 — **이름·범위·자세.**
519
- *
520
- * 범위가 화면에 있어야 하는 이유는 그것이 **인스턴스와 주고받는 말**이기 때문이다.
521
- * 곡선은 0~1 이고 인스턴스는 mm 로 준다. 그 사이를 런타임이 맵하는데, 무엇부터 무엇
522
- * 까지인지 저작자가 정하지 않으면 값을 줄 수가 없다.
523
- */
524
- private renderParameter(parameter: Parameter, at: number): TemplateResult {
525
- const key = `parameter:${at}`
526
- const on = this.open === key
527
- const duplicate = this.taken('parameter', at, parameter.name)
528
- const nameless = !parameter.name?.trim()
529
- const range = parameter.range ?? NEW_RANGE
530
- const backwards = !(range.max > range.min)
531
- const slowness = parameter.clip?.duration ?? 0
532
-
533
- return html`
534
- <div clip ?on=${on}>
535
- <div head>
536
- <button plain @click=${() => (this.open = on ? '' : key)} title=${i18next.t('figure.label.channels')}>
537
- <md-icon>${on ? 'expand_more' : 'chevron_right'}</md-icon>
538
- </button>
539
- <input
540
- name
541
- .value=${live(parameter.name ?? '')}
542
- ?bad=${duplicate || nameless}
543
- placeholder=${i18next.t('figure.label.parameter-name')}
544
- title=${duplicate
545
- ? i18next.t('figure.text.clip-name-taken')
546
- : i18next.t('figure.text.parameter-name-is-how-a-value-arrives')}
547
- @change=${(e: Event) => this.renameParameter(at, (e.target as HTMLInputElement).value)}
548
- />
549
- <button plain @click=${() => this.removeParameter(at)} title=${i18next.t('figure.button.remove')}>
550
- <md-icon>close</md-icon>
551
- </button>
552
- </div>
553
-
554
- ${duplicate ? html`<p warn>${i18next.t('figure.text.clip-name-taken')}</p>` : nothing}
555
- ${nameless ? html`<p warn>${i18next.t('figure.text.parameter-needs-a-name')}</p>` : nothing}
556
-
557
- <div row>
558
- <label>${i18next.t('figure.label.parameter-range')}</label>
559
- <input
560
- type="number"
561
- step="1"
562
- ?bad=${backwards}
563
- .value=${live(String(range.min))}
564
- aria-label="min"
565
- @change=${(e: Event) => this.setRange(at, { min: Number((e.target as HTMLInputElement).value) || 0 })}
566
- />
567
- <input
568
- type="number"
569
- step="1"
570
- ?bad=${backwards}
571
- .value=${live(String(range.max))}
572
- aria-label="max"
573
- @change=${(e: Event) => this.setRange(at, { max: Number((e.target as HTMLInputElement).value) || 0 })}
574
- />
575
- ${this.renderUnit(at, range.unit ?? '')}
576
- </div>
577
- ${backwards ? html`<p warn>${i18next.t('figure.text.range-needs-room')}</p>` : nothing}
578
-
579
- <div row>
580
- <label>${i18next.t('figure.label.parameter-default')}</label>
581
- <input
582
- type="number"
583
- step="1"
584
- .value=${live(String(parameter.default ?? range.min))}
585
- @change=${(e: Event) => this.setDefault(at, Number((e.target as HTMLInputElement).value) || 0)}
586
- />
587
- </div>
588
-
589
- <div row>
590
- <label>${i18next.t('figure.label.parameter-duration')}</label>
591
- <input
592
- type="number"
593
- step="0.1"
594
- min="0"
595
- ?bad=${slowness < 0}
596
- .value=${live(parameter.clip?.duration === undefined ? '' : String(parameter.clip.duration))}
597
- placeholder="0"
598
- aria-label="duration"
599
- @change=${(e: Event) => this.setDuration(at, (e.target as HTMLInputElement).value)}
600
- />
601
- </div>
602
- <p quiet>${i18next.t('figure.text.parameter-duration-empty-is-instant')}</p>
603
-
604
- ${on ? this.renderChannels('parameter', at) : nothing}
605
- </div>
606
- `
607
- }
608
-
609
- private renderChannels(kind: MotionKind, at: number): TemplateResult {
610
- const channels = this.channelsOf(kind, at)
611
-
612
- return html`
613
- <p quiet>${i18next.t(kind === 'clip' ? 'figure.text.clip-is-time-running' : 'figure.text.parameter-curve-is-the-value-axis')}</p>
614
-
615
- ${channels.length === 0 ? html`<p warn>${i18next.t('figure.text.clip-needs-a-channel')}</p>` : nothing}
616
- ${channels.map((channel, j) => this.renderChannel(kind, channel, at, j))}
617
-
618
- <button @click=${() => this.addChannel(kind, at)}>
619
- <md-icon>add</md-icon>${i18next.t('figure.button.add-channel')}
620
- </button>
621
- `
622
- }
623
-
624
- /**
625
- * 채널 하나 — 어느 부품의 어느 속성을 움직이나.
626
- *
627
- * 없는 부품을 가리키는 채널은 붉게 낸다. 부품 이름을 바꾸면 그 순간 이렇게 되는데,
628
- * 검증은 저장할 때 말하고 여기서는 **그 자리에서** 보여 준다.
629
- */
630
- private renderChannel(kind: MotionKind, channel: Channel, at: number, j: number): TemplateResult {
631
- const joint = this.joints.find(one => one.name === channel.target)
632
- const orphan = !this.partNames.includes(channel.target) && !joint
633
- const target = html`
634
- <div row>
635
- <label>${i18next.t('figure.label.channel-target')}</label>
636
- <select
637
- .value=${live(channel.target ?? '')}
638
- @change=${(e: Event) => this.retarget(kind, at, j, (e.target as HTMLSelectElement).value)}
639
- >
640
- ${orphan ? html`<option value=${channel.target}>${channel.target}</option>` : nothing}
641
- <optgroup label=${i18next.t('figure.label.channel-target-parts')}>
642
- ${this.partNames.map(name => html`<option value=${name}>${name}</option>`)}
643
- </optgroup>
644
- ${this.joints.length > 0
645
- ? html`<optgroup label=${i18next.t('figure.label.channel-target-joints')}>
646
- ${this.joints.map(one => html`<option value=${one.name}>${one.name}</option>`)}
647
- </optgroup>`
648
- : nothing}
649
- </select>
650
- <button plain @click=${() => this.removeChannel(kind, at, j)} title=${i18next.t('figure.button.remove')}>
651
- <md-icon>close</md-icon>
652
- </button>
653
- </div>
654
- `
655
-
656
- /* A joint channel has no path or pivot: the joint says what moves. Each key is the joint coordinate. */
657
- if (isJointChannel(channel)) {
658
- const unit = joint?.type === 'prismatic' ? 'mm' : 'deg'
659
- return html`
660
- <div channel ?orphan=${orphan}>
661
- ${target} ${orphan ? html`<p warn>${i18next.t('figure.text.channel-target-is-gone')}</p>` : nothing}
662
- <p quiet>${i18next.t('figure.text.joint-channel-value-' + unit)}</p>
663
- ${this.renderJointKeys(kind, channel, at, j, joint?.limits)}
664
- </div>
665
- `
666
- }
667
-
668
- const turning = channel.path === 'rotation'
669
-
670
- return html`
671
- <div channel ?orphan=${orphan}>
672
- ${target}
673
-
674
- ${orphan ? html`<p warn>${i18next.t('figure.text.channel-target-is-gone')}</p>` : nothing}
675
-
676
- <div row>
677
- <label>${i18next.t('figure.label.channel-path')}</label>
678
- <select
679
- .value=${live(channel.path)}
680
- @change=${(e: Event) => this.setPath(kind, at, j, (e.target as HTMLSelectElement).value as ChannelPath)}
681
- >
682
- ${CHANNEL_PATHS.map(path => html`<option value=${path}>${i18next.t('figure.label.path-' + path)}</option>`)}
683
- </select>
684
- <select
685
- .value=${live(channel.interpolation ?? 'linear')}
686
- title=${i18next.t('figure.text.interpolation-explained')}
687
- @change=${(e: Event) =>
688
- this.setChannel(kind, at, j, { interpolation: (e.target as HTMLSelectElement).value as Channel['interpolation'] })}
689
- >
690
- ${INTERPOLATIONS.map(
691
- one => html`<option value=${one}>${i18next.t('figure.label.interpolation-' + one)}</option>`
692
- )}
693
- </select>
694
- </div>
695
-
696
- <p quiet>${i18next.t('figure.text.path-' + channel.path + '-unit')}</p>
697
-
698
- ${turning ? this.renderPivot(kind, channel, at, j) : nothing}
699
- ${this.renderKeys(kind, channel, at, j)}
700
- </div>
701
- `
702
- }
703
-
704
- /**
705
- * 회전 중심 — **`rotation` 에서만 뜻이 있다.**
706
- *
707
- * 그래서 경로가 rotation 일 때만 낸다. 언제나 내면 저작자가 옮김·배율에도 적고, 검증이
708
- * 저장할 때 「쓰이지 않는다」고 알린다. 안 보이면 적을 일이 없다.
709
- */
710
- private renderPivot(kind: MotionKind, channel: PartChannel, at: number, j: number): TemplateResult {
711
- const pivot = channel.pivot
712
- const on = pivot !== undefined
713
-
714
- return html`
715
- <div row>
716
- <label>${i18next.t('figure.label.channel-pivot')}</label>
717
- <button
718
- @click=${() => this.setChannel(kind, at, j, { pivot: on ? undefined : { x: 0, y: 0, z: 0 } })}
719
- title=${i18next.t('figure.text.pivot-defaults-to-the-part-centre')}
720
- >
721
- ${i18next.t(on ? 'figure.button.pivot-clear' : 'figure.button.pivot-set')}
722
- </button>
723
- ${on
724
- ? AXES.map(
725
- axis => html`
726
- <input
727
- type="number"
728
- step="1"
729
- .value=${live(String(pivot![axis]))}
730
- aria-label=${axis}
731
- @change=${(e: Event) =>
732
- this.setChannel(kind, at, j, {
733
- pivot: { ...pivot!, [axis]: Number((e.target as HTMLInputElement).value) || 0 }
734
- })}
735
- />
736
- `
737
- )
738
- : nothing}
739
- </div>
740
- `
741
- }
742
-
743
- /**
744
- * 키프레임 표.
745
- *
746
- * **둘 미만으로 못 내려간다.** 하나뿐이면 움직이는 것이 아니라 자세 하나이고, 형식이
747
- * 오류로 막는다. 저장하고 나서 알려 주는 것보다 지우는 단추를 죽이는 것이 낫다.
748
- *
749
- * 시각이 오름차순이어야 하는 것도 형식의 규칙이다. 여기서는 어긋난 줄을 붉게 내고 값을
750
- * 고치지는 않는다 — 저작자가 3 을 1 로 고치던 중일 수 있다.
751
- */
752
- /**
753
- * Keys of a joint channel: a position and one joint coordinate each. A value outside the joint's limits
754
- * is marked and left as typed; the format refuses it on save.
755
- */
756
- private renderJointKeys(
757
- kind: MotionKind,
758
- channel: JointChannel,
759
- at: number,
760
- j: number,
761
- limits?: { min: number; max: number }
762
- ): TemplateResult {
763
- const keys = channel.keys ?? []
764
- const onValues = kind === 'parameter'
765
- const beyond = (key: JointKey) => !!limits && (key.value < limits.min || key.value > limits.max)
766
-
767
- return html`
768
- <table keys>
769
- <tr>
770
- <th>${i18next.t(onValues ? 'figure.label.key-at-value' : 'figure.label.key-at')}</th>
771
- <th>${i18next.t('figure.label.joint-value')}</th>
772
- <th></th>
773
- </tr>
774
- ${keys.map((key, k) => {
775
- const backwards = k > 0 && key.at <= (keys[k - 1]!.at ?? 0)
776
- return html`
777
- <tr>
778
- <td>
779
- <input
780
- type="number"
781
- step=${onValues ? '0.05' : '0.1'}
782
- min="0"
783
- max=${onValues ? '1' : nothing}
784
- ?bad=${backwards || key.at < 0 || (onValues && key.at > 1)}
785
- .value=${live(String(key.at))}
786
- @change=${(e: Event) =>
787
- this.setJointKey(kind, at, j, k, { at: Math.max(0, Number((e.target as HTMLInputElement).value) || 0) })}
788
- />
789
- </td>
790
- <td>
791
- <input
792
- type="number"
793
- step="1"
794
- ?bad=${beyond(key)}
795
- .value=${live(String(key.value))}
796
- title=${beyond(key) ? i18next.t('figure.text.joint-value-beyond-limits') : ''}
797
- @change=${(e: Event) => this.setJointKey(kind, at, j, k, { value: Number((e.target as HTMLInputElement).value) || 0 })}
798
- />
799
- </td>
800
- <td drop>
801
- <button
802
- plain
803
- ?disabled=${keys.length <= 2}
804
- title=${keys.length <= 2 ? i18next.t('figure.text.two-keys-at-least') : i18next.t('figure.button.remove')}
805
- @click=${() => this.removeKey(kind, at, j, k)}
806
- >
807
- <md-icon>close</md-icon>
808
- </button>
809
- </td>
810
- </tr>
811
- `
812
- })}
813
- </table>
814
- ${keys.some(beyond) ? html`<p warn>${i18next.t('figure.text.joint-value-beyond-limits')}</p>` : nothing}
815
- <button @click=${() => this.addKey(kind, at, j)}>
816
- <md-icon>add</md-icon>${i18next.t('figure.button.add-key')}
817
- </button>
818
- `
819
- }
820
-
821
- private renderKeys(kind: MotionKind, channel: PartChannel, at: number, j: number): TemplateResult {
822
- const keys = channel.keys ?? []
823
- /*
824
- Keys on a parameter curve sit on the 0..1 value span (ADR-0051). A key above 1 is unreachable and
825
- the format refuses it. The screen marks it and leaves the number alone: rewriting what the author
826
- typed would hide what they wrote.
827
- */
828
- const onValues = kind === 'parameter'
829
- const outside = (key: Keyframe) => onValues && key.at > 1
830
-
831
- return html`
832
- <table keys>
833
- <tr>
834
- <th>${i18next.t(onValues ? 'figure.label.key-at-value' : 'figure.label.key-at')}</th>
835
- ${AXES.map(axis => html`<th>${axis}</th>`)}
836
- <th></th>
837
- </tr>
838
- ${keys.map((key, k) => {
839
- const backwards = k > 0 && key.at <= (keys[k - 1]!.at ?? 0)
840
- return html`
841
- <tr>
842
- <td>
843
- <input
844
- type="number"
845
- step=${onValues ? '0.05' : '0.1'}
846
- min="0"
847
- max=${onValues ? '1' : nothing}
848
- ?bad=${backwards || key.at < 0 || outside(key)}
849
- .value=${live(String(key.at))}
850
- title=${backwards
851
- ? i18next.t('figure.text.keys-must-rise')
852
- : outside(key)
853
- ? i18next.t('figure.text.parameter-key-within-span')
854
- : ''}
855
- @change=${(e: Event) =>
856
- this.setKey(kind, at, j, k, { at: Math.max(0, Number((e.target as HTMLInputElement).value) || 0) })}
857
- />
858
- </td>
859
- ${AXES.map(
860
- axis => html`
861
- <td>
862
- <input
863
- type="number"
864
- step=${channel.path === 'scale' ? '0.1' : '1'}
865
- .value=${live(String(key.value[axis]))}
866
- aria-label=${axis}
867
- @change=${(e: Event) =>
868
- this.setKey(kind, at, j, k, {
869
- value: { ...key.value, [axis]: Number((e.target as HTMLInputElement).value) || 0 }
870
- })}
871
- />
872
- </td>
873
- `
874
- )}
875
- <td drop>
876
- <button
877
- plain
878
- ?disabled=${keys.length <= 2}
879
- title=${keys.length <= 2 ? i18next.t('figure.text.two-keys-at-least') : i18next.t('figure.button.remove')}
880
- @click=${() => this.removeKey(kind, at, j, k)}
881
- >
882
- <md-icon>close</md-icon>
883
- </button>
884
- </td>
885
- </tr>
886
- `
887
- })}
888
- </table>
889
-
890
- ${keys.some((key, k) => k > 0 && key.at <= (keys[k - 1]!.at ?? 0))
891
- ? html`<p warn>${i18next.t('figure.text.keys-must-rise')}</p>`
892
- : nothing}
893
- ${keys.some(outside) ? html`<p warn>${i18next.t('figure.text.parameter-key-within-span')}</p>` : nothing}
894
-
895
- <button @click=${() => this.addKey(kind, at, j)}>
896
- <md-icon>add</md-icon>${i18next.t('figure.button.add-key')}
897
- </button>
898
- `
899
- }
900
-
901
- /**
902
- * 따로 움직이는 부품 예산.
903
- *
904
- * **넘어도 막지 않는다.** 제 변환을 지는 부품은 저마다 단독 묶음이라 draw call 이 늘고,
905
- * 그만큼 한 화면에 함께 세울 수 있는 대수가 준다 — 그 대가가 수로 보이면 저작자가 아낀다.
906
- * 랜드마크 설비 하나는 정교해도 되고, 그 값이 도면 예산에 드러나면 된다.
907
- */
908
- private renderBudget(): TemplateResult {
909
- const used = this.movingParts
910
- const over = used > LIMITS.independentParts
911
-
912
- return html`
913
- <section>
914
- <h3>${i18next.t('figure.label.budget-independent')}</h3>
915
- <div budget ?over=${over}>
916
- <strong>${used}</strong>
917
- <span quiet>/ ${LIMITS.independentParts}</span>
918
- </div>
919
- <p quiet>${i18next.t('figure.text.independent-parts-cost')}</p>
920
- ${over ? html`<p warn>${i18next.t('figure.text.independent-parts-over')}</p>` : nothing}
921
- </section>
922
- `
923
- }
924
-
925
- // ─── 고치기 ───────────────────────────────────────────────────────────────
926
-
927
- /**
928
- * 초안에 실어 올려보낸다.
929
- *
930
- * `animations` 는 도형 전체의 것이므로 부품 편집(`update-part`)이 아니라 `update-draft` 로
931
- * 간다. 빈 배열은 칸을 지운다 — clip 을 다 지운 도형은 `animations: []` 가 아니라 없는 것이다.
932
- */
933
- private tell(over: { animations?: Clip[]; parameters?: Parameter[] }): void {
934
- if (!this.draft) return
935
-
936
- const draft: FigureDraft = { ...this.draft, ...over }
937
- if (!draft.animations?.length) delete draft.animations
938
- if (!draft.parameters?.length) delete draft.parameters
939
-
940
- this.dispatchEvent(new CustomEvent('update-draft', { detail: { draft }, bubbles: true, composed: true }))
941
- }
942
-
943
- private patchClip(at: number, patch: Partial<Clip>): void {
944
- this.tell({ animations: this.clips.map((clip, i) => (i === at ? { ...clip, ...patch } : clip)) })
945
- }
946
-
947
- private patchParameter(at: number, patch: Partial<Parameter>): void {
948
- this.tell({ parameters: this.parameters.map((one, i) => (i === at ? { ...one, ...patch } : one)) })
949
- }
950
-
951
- /** 채널 묶음을 통째로 얹는다. **어느 목록이든 같은 자리에 닿는다.** */
952
- private setChannels(kind: MotionKind, at: number, channels: Channel[]): void {
953
- if (kind === 'clip') this.patchClip(at, { channels })
954
- else {
955
- const parameter = this.parameters[at]
956
- if (!parameter) return
957
- this.patchParameter(at, { clip: { ...parameter.clip, channels } })
958
- }
959
- }
960
-
961
- private patchChannel(kind: MotionKind, at: number, j: number, next: Channel): void {
962
- this.setChannels(
963
- kind,
964
- at,
965
- this.channelsOf(kind, at).map((channel, i) => (i === j ? next : channel))
966
- )
967
- }
968
-
969
- private addClip(): void {
970
- const target = this.partNames[0]
971
- if (!target) return
972
-
973
- const clip: Clip = {
974
- name: freeName(this.allNames, 'clip-1'),
975
- channels: [{ target, path: 'translation', keys: keysFor('translation') }]
976
- }
977
-
978
- this.open = `clip:${this.clips.length}`
979
- this.tell({ animations: [...this.clips, clip] })
980
- }
981
-
982
- private addParameter(): void {
983
- const target = this.partNames[0]
984
- if (!target) return
985
-
986
- const parameter: Parameter = {
987
- name: freeName(this.allNames, 'parameter-1'),
988
- range: { ...NEW_RANGE },
989
- clip: { channels: [{ target, path: 'translation', keys: keysFor('translation') }] }
990
- }
991
-
992
- this.open = `parameter:${this.parameters.length}`
993
- this.tell({ parameters: [...this.parameters, parameter] })
994
- }
995
-
996
- /**
997
- * Recipe creates a valid, editable two-pose motion; it never saves or publishes the Figure.
998
- *
999
- * 어느 목록으로 가는지는 레시피가 안다 — 도는 롤러는 애니메이션이고 열리는 문은
1000
- * 파라미터다. 저작자에게 그 갈래를 먼저 고르게 하지 않는 이유가 이것이다.
1001
- */
1002
- private addRecipe(recipe: MotionRecipe): void {
1003
- const target = this.recipeTarget || this.partNames[0]
1004
- if (!target) return
1005
-
1006
- const channel: Channel = {
1007
- target,
1008
- path: recipe.path,
1009
- keys: [{ at: 0, value: startValue(recipe.path) }, { at: 1, value: { ...recipe.end } }]
1010
- }
1011
- if (recipe.pivot) channel.pivot = { ...recipe.pivot }
1012
-
1013
- const name = freeName(this.allNames, recipe.name)
1014
-
1015
- if (recipe.kind === 'clip') {
1016
- this.open = `clip:${this.clips.length}`
1017
- this.tell({ animations: [...this.clips, { name, channels: [channel] }] })
1018
- return
1019
- }
1020
-
1021
- this.open = `parameter:${this.parameters.length}`
1022
- this.tell({
1023
- parameters: [...this.parameters, { name, range: { ...(recipe.range ?? NEW_RANGE) }, clip: { channels: [channel] } }]
1024
- })
1025
- }
1026
-
1027
- private renameClip(at: number, name: string): void {
1028
- this.patchClip(at, { name: name.trim() })
1029
- }
1030
-
1031
- private renameParameter(at: number, name: string): void {
1032
- this.patchParameter(at, { name: name.trim() })
1033
- }
1034
-
1035
- /**
1036
- * 단위 칸 — **목록이 보이는 채로, 적는 길도 열어 둔다.**
1037
- *
1038
- * 처음에는 `datalist` 를 붙였다. 그것은 브라우저가 쥐고 있는 기능이라 **눌러 보기 전에는 목록이
1039
- * 있는지조차 안 보인다** — 화살표도 없고, 어디에 어떻게 뜨는지도 브라우저가 정한다. 고를 수
1040
- * 있다는 것을 알리는 것이 이 칸의 목적이므로 `select` 로 바꿨다.
1041
- *
1042
- * 형식은 단위를 규칙으로 쓰지 않으므로(표시용 말이다) 목록에 가두지 않는다. 마지막 줄이
1043
- * 「직접 적기」이고, 목록에 없는 말이 이미 적혀 있으면 처음부터 적는 칸으로 연다.
1044
- */
1045
- private renderUnit(at: number, unit: string) {
1046
- const listed = (PARAMETER_UNITS as readonly string[]).includes(unit)
1047
- const typing = this.typingUnit.has(at) || (unit !== '' && !listed)
1048
-
1049
- if (typing) {
1050
- return html`<input
1051
- unit
1052
- .value=${live(unit)}
1053
- placeholder="mm"
1054
- aria-label="unit"
1055
- title=${i18next.t('figure.text.unit-is-a-word-not-a-rule')}
1056
- @change=${(e: Event) => this.setRange(at, { unit: (e.target as HTMLInputElement).value.trim() })}
1057
- />`
1058
- }
1059
-
1060
- return html`<select
1061
- unit
1062
- aria-label="unit"
1063
- title=${i18next.t('figure.text.unit-is-a-word-not-a-rule')}
1064
- @change=${(e: Event) => this.chooseUnit(at, (e.target as HTMLSelectElement).value)}
1065
- >
1066
- <option value="" ?selected=${unit === ''}>${i18next.t('figure.label.unit-none')}</option>
1067
- ${PARAMETER_UNITS.map(one => html`<option value=${one} ?selected=${one === unit}>${one}</option>`)}
1068
- <option value=${UNIT_TYPE_IT}>${i18next.t('figure.label.unit-type-it')}</option>
1069
- </select>`
1070
- }
1071
-
1072
- /** 고른 것을 넣는다. 「직접 적기」는 값이 아니라 **칸을 바꾸는 것**이다. */
1073
- private chooseUnit(at: number, value: string): void {
1074
- if (value === UNIT_TYPE_IT) {
1075
- this.typingUnit = new Set([...this.typingUnit, at])
1076
- return
1077
- }
1078
-
1079
- const next = new Set(this.typingUnit)
1080
- next.delete(at)
1081
- this.typingUnit = next
1082
- this.setRange(at, { unit: value })
1083
- }
1084
-
1085
- private setRange(at: number, patch: Partial<Parameter['range']>): void {
1086
- const parameter = this.parameters[at]
1087
- if (!parameter) return
1088
- this.patchParameter(at, { range: { ...(parameter.range ?? NEW_RANGE), ...patch } })
1089
- }
1090
-
1091
- /**
1092
- * Transition time. Clearing the input removes the field, which means instant. 0 is instant too, but
1093
- * a stored 0 and a missing field are different sources, so an empty input is never saved as 0.
1094
- */
1095
- private setDuration(at: number, raw: string): void {
1096
- const parameter = this.parameters[at]
1097
- if (!parameter) return
1098
- const { duration: _dropped, ...rest } = parameter.clip
1099
- const text = raw.trim()
1100
- const clip = text === '' || !Number.isFinite(Number(text)) ? rest : { ...rest, duration: Number(text) }
1101
- this.patchParameter(at, { clip })
1102
- }
1103
-
1104
- private setDefault(at: number, value: number): void {
1105
- this.patchParameter(at, { default: value })
1106
- }
1107
-
1108
- private removeClip(at: number): void {
1109
- this.open = ''
1110
- this.tell({ animations: this.clips.filter((_, i) => i !== at) })
1111
- }
1112
-
1113
- private removeParameter(at: number): void {
1114
- this.open = ''
1115
- this.tell({ parameters: this.parameters.filter((_, i) => i !== at) })
1116
- }
1117
-
1118
- private addChannel(kind: MotionKind, at: number): void {
1119
- const target = this.partNames[0]
1120
- if (!target) return
1121
-
1122
- this.setChannels(kind, at, [
1123
- ...this.channelsOf(kind, at),
1124
- { target, path: 'translation', keys: keysFor('translation') }
1125
- ])
1126
- }
1127
-
1128
- /**
1129
- * Points a channel at another part or joint. Crossing between the two changes the channel's shape: a
1130
- * joint channel has no path and one number per key, a part channel a path and a vector. The key positions
1131
- * are kept, since they are the author's timing; values restart at the rest pose.
1132
- */
1133
- private retarget(kind: MotionKind, at: number, j: number, target: string): void {
1134
- const channel = this.channelsOf(kind, at)[j]
1135
- if (!channel) return
1136
- const toJoint = this.joints.some(one => one.name === target)
1137
-
1138
- if (toJoint && !isJointChannel(channel)) {
1139
- const next: JointChannel = { target, keys: channel.keys.map(key => ({ at: key.at, value: 0 })) }
1140
- if (channel.interpolation !== undefined) next.interpolation = channel.interpolation
1141
- this.patchChannel(kind, at, j, next)
1142
- return
1143
- }
1144
- if (!toJoint && isJointChannel(channel)) {
1145
- const next: PartChannel = { target, path: 'translation', keys: channel.keys.map(key => ({ at: key.at, value: startValue('translation') })) }
1146
- if (channel.interpolation !== undefined) next.interpolation = channel.interpolation
1147
- this.patchChannel(kind, at, j, next)
1148
- return
1149
- }
1150
- this.patchChannel(kind, at, j, { ...channel, target } as Channel)
1151
- }
1152
-
1153
- private setChannel(kind: MotionKind, at: number, j: number, patch: Partial<PartChannel>): void {
1154
- const channel = this.channelsOf(kind, at)[j]
1155
- if (!channel || isJointChannel(channel)) return
1156
-
1157
- const next: PartChannel = { ...channel, ...patch }
1158
- /* `undefined` 를 얹는 것은 지우는 뜻이다. 남겨 두면 저장 형식에 빈 칸이 실린다. */
1159
- if ('pivot' in patch && patch.pivot === undefined) delete next.pivot
1160
- this.patchChannel(kind, at, j, next)
1161
- }
1162
-
1163
- /**
1164
- * 경로를 바꾼다 — **값까지 함께 옮긴다.**
1165
- *
1166
- * 옮김·회전의 0 은 「제자리」인데 배율의 0 은 **부품을 지운다.** 경로만 바꾸고 값을 그대로
1167
- * 두면 저작자는 부품이 사라진 것을 보고 도구가 고장 난 줄 안다. 그래서 옮김·회전 ↔ 배율을
1168
- * 건널 때 시작값을 그 경로의 제자리로 되돌린다. 시각은 지킨다 — 저작자가 짠 박자다.
1169
- */
1170
- private setPath(kind: MotionKind, at: number, j: number, path: ChannelPath): void {
1171
- const channel = this.channelsOf(kind, at)[j]
1172
- if (!channel || isJointChannel(channel)) return
1173
-
1174
- const crossing = (channel.path === 'scale') !== (path === 'scale')
1175
- const next: PartChannel = {
1176
- ...channel,
1177
- path,
1178
- keys: crossing ? channel.keys.map(key => ({ at: key.at, value: startValue(path) })) : channel.keys
1179
- }
1180
- /* 회전이 아니면 회전 중심은 쓰이지 않는다. 남겨 두면 검증이 「쓰이지 않는다」고 알린다. */
1181
- if (path !== 'rotation') delete next.pivot
1182
-
1183
- this.patchChannel(kind, at, j, next)
1184
- }
1185
-
1186
- private removeChannel(kind: MotionKind, at: number, j: number): void {
1187
- this.setChannels(
1188
- kind,
1189
- at,
1190
- this.channelsOf(kind, at).filter((_, i) => i !== j)
1191
- )
1192
- }
1193
-
1194
- /** 마지막 키에서 1 초 뒤. 값은 그 키를 그대로 받는다 — 붙여 놓고 고치는 것이 짜기 쉽다. */
1195
- private addKey(kind: MotionKind, at: number, j: number): void {
1196
- const channel = this.channelsOf(kind, at)[j]
1197
- if (!channel) return
1198
-
1199
- if (isJointChannel(channel)) {
1200
- const keys = channel.keys
1201
- const end = keys[keys.length - 1]
1202
- if (kind === 'parameter' && keys.length >= 2) {
1203
- const before = keys[keys.length - 2]!
1204
- const middle: JointKey = { at: (before.at + end!.at) / 2, value: before.value }
1205
- this.patchChannel(kind, at, j, { ...channel, keys: [...keys.slice(0, -1), middle, end!] })
1206
- return
1207
- }
1208
- this.patchChannel(kind, at, j, { ...channel, keys: [...keys, { at: (end?.at ?? 0) + 1, value: end?.value ?? 0 }] })
1209
- return
1210
- }
1211
-
1212
- const last = channel.keys[channel.keys.length - 1]
1213
-
1214
- /*
1215
- A parameter curve ends at 1, so appending a key would make it unreachable. Insert it between the last two keys.
1216
- */
1217
- if (kind === 'parameter' && channel.keys.length >= 2) {
1218
- const before = channel.keys[channel.keys.length - 2]!
1219
- const middle: Keyframe = { at: (before.at + last!.at) / 2, value: { ...before.value } }
1220
- this.patchChannel(kind, at, j, { ...channel, keys: [...channel.keys.slice(0, -1), middle, last!] })
1221
- return
1222
- }
1223
-
1224
- const key: Keyframe = { at: (last?.at ?? 0) + 1, value: { ...(last?.value ?? startValue(channel.path)) } }
1225
- this.patchChannel(kind, at, j, { ...channel, keys: [...channel.keys, key] })
1226
- }
1227
-
1228
- private setJointKey(kind: MotionKind, at: number, j: number, k: number, patch: Partial<JointKey>): void {
1229
- const channel = this.channelsOf(kind, at)[j]
1230
- if (!channel || !isJointChannel(channel)) return
1231
- this.patchChannel(kind, at, j, { ...channel, keys: channel.keys.map((key, i) => (i === k ? { ...key, ...patch } : key)) })
1232
- }
1233
-
1234
- private setKey(kind: MotionKind, at: number, j: number, k: number, patch: Partial<Keyframe>): void {
1235
- const channel = this.channelsOf(kind, at)[j]
1236
- if (!channel || isJointChannel(channel)) return
1237
- this.patchChannel(kind, at, j, {
1238
- ...channel,
1239
- keys: channel.keys.map((key, i) => (i === k ? { ...key, ...patch } : key))
1240
- })
1241
- }
1242
-
1243
- /** 둘 미만으로 내려가지 않는다 — 단추가 이미 죽어 있지만 밖에서 불릴 수 있다. */
1244
- private removeKey(kind: MotionKind, at: number, j: number, k: number): void {
1245
- const channel = this.channelsOf(kind, at)[j]
1246
- if (!channel || channel.keys.length <= 2) return
1247
- this.patchChannel(kind, at, j, { ...channel, keys: (channel.keys as { at: number }[]).filter((_, i) => i !== k) } as Channel)
1248
- }
1249
- }