@pencil-lang/figure 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -4
- package/astro/Figure.astro +27 -2
- package/astro/build.d.ts +29 -1
- package/astro/build.js +9 -3
- package/package.json +2 -1
- package/pkg/pencil-figure.min.js +82 -11
- package/pkg/pencil_web.js +558 -349
- package/pkg/pencil_web_bg.wasm +0 -0
- package/src/controls.js +449 -0
- package/src/element.js +334 -52
- package/src/host.js +5 -0
- package/src/wiring.js +398 -0
package/src/wiring.js
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
// What makes a figure's controls work: its defaults in `<pencil-controls>`, or a page's own in the
|
|
2
|
+
// `controls` slot. Either way, each control is marked with what it sets and each output with what
|
|
3
|
+
// it shows, and this sets their ranges, steps and values from the figure, follows them each frame,
|
|
4
|
+
// and hands what a reader does to the figure, through its public API only:
|
|
5
|
+
//
|
|
6
|
+
// input[type=range][data-param="q"] a slider: its min, max, step and value are the figure's
|
|
7
|
+
// select[data-param="along"] a choice's options, filled in if it has none
|
|
8
|
+
// input[type=radio][data-param="along"][value="1"] one option, by its place from 0
|
|
9
|
+
// input[type=checkbox][data-param="glow"] a choice of off and on: checked is on
|
|
10
|
+
// output[data-param="q"] the param's value, as its control says it
|
|
11
|
+
// [data-readout="ratio"] what a readout says, laid out as the figure lays it out
|
|
12
|
+
// button[data-play] plays and pauses; input[type=range][data-time] and
|
|
13
|
+
// output[data-time] are the time
|
|
14
|
+
// button[data-step="1"], [data-step="-1"], output[data-beat], [data-captions] beats
|
|
15
|
+
//
|
|
16
|
+
// A choice's `data-param` is the name its value has, `along`, or its param, `along.index`.
|
|
17
|
+
import { PHONE, paramNamed, valueText, timeText, beatAt, steps, readoutHtml } from './controls.js';
|
|
18
|
+
|
|
19
|
+
const ATTRIBUTES = ['data-play', 'data-time', 'data-step', 'data-param', 'data-readout'];
|
|
20
|
+
|
|
21
|
+
/** What a control is, as a selector that finds the same control in controls written again: its
|
|
22
|
+
* `id`, or what it's marked as being for, or the menu's button. None for anything else. */
|
|
23
|
+
export function identity(el) {
|
|
24
|
+
if (el.id) return `#${CSS.escape(el.id)}`;
|
|
25
|
+
for (const name of ATTRIBUTES) {
|
|
26
|
+
if (!el.hasAttribute(name)) continue;
|
|
27
|
+
const value = el.getAttribute(name);
|
|
28
|
+
let key = `${el.localName}[${name}${value ? `="${CSS.escape(value)}"` : ''}]`;
|
|
29
|
+
if (el.type === 'radio') key += `[value="${CSS.escape(el.value)}"]`;
|
|
30
|
+
return key;
|
|
31
|
+
}
|
|
32
|
+
return el.classList.contains('more') ? '.more' : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** How near the edges of the screen an opened menu is shown, in CSS pixels. */
|
|
36
|
+
const EDGE = 8;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The defaults' menu on a phone, which drops down from under their bar over the page. It's an auto
|
|
40
|
+
* popover, so it's in the top layer, where with `position: absolute` its containing block is the
|
|
41
|
+
* initial containing block, which is the page's own coordinates. Placed there where the controls
|
|
42
|
+
* end, it scrolls with the page and stays under its bar with nothing to catch up. While it's open
|
|
43
|
+
* it looks once a frame for where the controls are, and moves only when that has changed: when
|
|
44
|
+
* something above them grows, or a fixed or sticky box carries them, or a scrolling box they're in
|
|
45
|
+
* scrolls, which it follows a frame behind. It closes when its controls leave the screen, or the
|
|
46
|
+
* page becomes too wide for a menu, and stops looking once it's closed or gone from the page.
|
|
47
|
+
* Opened by a reader, it scrolls the page just enough to show it, if it runs past the bottom of the
|
|
48
|
+
* screen, but never so far that the bar leaves the top.
|
|
49
|
+
*/
|
|
50
|
+
function dropDown(menu, signal) {
|
|
51
|
+
const controls = menu.parentElement;
|
|
52
|
+
const bar = controls.querySelector(':scope > .bar') ?? controls;
|
|
53
|
+
const phone = matchMedia(PHONE);
|
|
54
|
+
const still = matchMedia('(prefers-reduced-motion: reduce)');
|
|
55
|
+
let frame = 0;
|
|
56
|
+
let at = '';
|
|
57
|
+
const place = () => {
|
|
58
|
+
const box = controls.getBoundingClientRect();
|
|
59
|
+
const where = [box.bottom + scrollY, box.left + scrollX, box.width];
|
|
60
|
+
if (where.join() !== at) {
|
|
61
|
+
at = where.join();
|
|
62
|
+
menu.style.setProperty('--menu-top', `${where[0]}px`);
|
|
63
|
+
menu.style.setProperty('--menu-left', `${where[1]}px`);
|
|
64
|
+
menu.style.setProperty('--menu-width', `${where[2]}px`);
|
|
65
|
+
}
|
|
66
|
+
return box;
|
|
67
|
+
};
|
|
68
|
+
const stop = () => {
|
|
69
|
+
cancelAnimationFrame(frame);
|
|
70
|
+
frame = 0;
|
|
71
|
+
};
|
|
72
|
+
const look = () => {
|
|
73
|
+
frame = 0;
|
|
74
|
+
if (!menu.isConnected || !menu.matches(':popover-open')) return;
|
|
75
|
+
const box = place();
|
|
76
|
+
const gone = box.bottom <= 0 || box.top >= innerHeight || box.right <= 0 || box.left >= innerWidth;
|
|
77
|
+
if (gone || !phone.matches) menu.hidePopover();
|
|
78
|
+
else frame = requestAnimationFrame(look);
|
|
79
|
+
};
|
|
80
|
+
const follow = () => {
|
|
81
|
+
place();
|
|
82
|
+
if (!frame) frame = requestAnimationFrame(look);
|
|
83
|
+
};
|
|
84
|
+
const show = () => {
|
|
85
|
+
const below = menu.getBoundingClientRect().bottom + EDGE - innerHeight;
|
|
86
|
+
const by = Math.min(below, bar.getBoundingClientRect().top - EDGE);
|
|
87
|
+
// At the end of a page the open menu adds to its height, which closing it gives back, so the
|
|
88
|
+
// page can jump up then.
|
|
89
|
+
if (by > 0) scrollBy({ top: by, behavior: still.matches ? 'instant' : 'smooth' });
|
|
90
|
+
};
|
|
91
|
+
signal.addEventListener('abort', stop);
|
|
92
|
+
return { follow, stop, show };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class Wiring {
|
|
96
|
+
#figure;
|
|
97
|
+
#roots = [];
|
|
98
|
+
#off = null;
|
|
99
|
+
#parts = null;
|
|
100
|
+
#sized = null; // watches the bars, which hold one row on a phone
|
|
101
|
+
#beatSaid = undefined; // the beat last said, by its caption's place
|
|
102
|
+
|
|
103
|
+
constructor(figure) {
|
|
104
|
+
this.#figure = figure;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Listens on these roots, a shadow root or a page's own element, and looks for what's in them
|
|
108
|
+
* again. */
|
|
109
|
+
attach(roots) {
|
|
110
|
+
this.#beatSaid = undefined;
|
|
111
|
+
this.#off?.abort();
|
|
112
|
+
this.#off = new AbortController();
|
|
113
|
+
this.#roots = roots;
|
|
114
|
+
this.#parts = null;
|
|
115
|
+
const signal = this.#off.signal;
|
|
116
|
+
for (const root of roots) {
|
|
117
|
+
root.addEventListener('input', (e) => this.#input(e.target), { signal });
|
|
118
|
+
root.addEventListener('change', (e) => this.#change(e.target), { signal });
|
|
119
|
+
root.addEventListener('click', (e) => this.#click(e.target.closest?.('button')), { signal });
|
|
120
|
+
this.#menus(root, signal);
|
|
121
|
+
}
|
|
122
|
+
this.#sized?.disconnect();
|
|
123
|
+
this.#sized = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(() => this.fit());
|
|
124
|
+
for (const root of roots) for (const bar of root.querySelectorAll('.bar')) this.#sized?.observe(bar);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** A menu that closes with the focus in it, on Escape, gives the focus back to its button, as a
|
|
128
|
+
* menu should, where a browser can leave it nowhere. The defaults' menu drops down from their
|
|
129
|
+
* bar, and opening it shows it. */
|
|
130
|
+
#menus(root, signal) {
|
|
131
|
+
const scope = root.getRootNode?.() ?? document;
|
|
132
|
+
for (const menu of root.querySelectorAll('[popover][id]')) {
|
|
133
|
+
const button = root.querySelector(`[popovertarget="${CSS.escape(menu.id)}"]`);
|
|
134
|
+
const drops = root instanceof ShadowRoot && menu.matches('.controls > .rest') ? dropDown(menu, signal) : null;
|
|
135
|
+
let inside = false;
|
|
136
|
+
// Whether this heard it begin to open. A menu that controls written again open again opens
|
|
137
|
+
// before this is listening, and only a reader's opening scrolls the page to show it.
|
|
138
|
+
let opening = false;
|
|
139
|
+
menu.addEventListener(
|
|
140
|
+
'beforetoggle',
|
|
141
|
+
(e) => {
|
|
142
|
+
opening = e.newState === 'open';
|
|
143
|
+
if (e.newState === 'open') drops?.follow();
|
|
144
|
+
if (e.newState === 'closed') {
|
|
145
|
+
inside = menu.contains(scope.activeElement);
|
|
146
|
+
drops?.stop();
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
{ signal },
|
|
150
|
+
);
|
|
151
|
+
menu.addEventListener(
|
|
152
|
+
'toggle',
|
|
153
|
+
(e) => {
|
|
154
|
+
if (e.newState === 'open') {
|
|
155
|
+
if (opening) drops?.show();
|
|
156
|
+
opening = false;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!inside) return;
|
|
160
|
+
inside = false;
|
|
161
|
+
const now = scope.activeElement;
|
|
162
|
+
if (!now || now === document.body || menu.contains(now)) button?.focus();
|
|
163
|
+
},
|
|
164
|
+
{ signal },
|
|
165
|
+
);
|
|
166
|
+
// Controls written again open their menu again before this hears of it.
|
|
167
|
+
if (menu.matches(':popover-open')) drops?.follow();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* On a phone a bar keeps one row on one line, and one that doesn't fit, as radios with long
|
|
173
|
+
* words or a long caption, or that's taller than the bar, as a fraction at a large size or radios
|
|
174
|
+
* whose legend WebKit sets on a line of its own, goes behind the menu with the rest, so nothing in
|
|
175
|
+
* the bar is cut off. The bar is as tall either way, so nothing moves. Its button is
|
|
176
|
+
* called what it opens: "More controls" beside a row, and "Controls" alone.
|
|
177
|
+
*/
|
|
178
|
+
fit() {
|
|
179
|
+
const phone = typeof matchMedia !== 'undefined' && matchMedia(PHONE).matches;
|
|
180
|
+
for (const root of this.#roots) {
|
|
181
|
+
const bar = root.querySelector('.bar');
|
|
182
|
+
const menu = root.querySelector('.rest');
|
|
183
|
+
const controls = root.querySelector('.controls');
|
|
184
|
+
if (!bar || !menu || !controls) continue;
|
|
185
|
+
const scope = root.getRootNode?.() ?? document;
|
|
186
|
+
const focused = scope.activeElement;
|
|
187
|
+
// A row the bar gave up comes back to see whether it fits now, as when a phone turns.
|
|
188
|
+
const moved = menu.querySelector(':scope > .row[data-moved]');
|
|
189
|
+
if (moved) {
|
|
190
|
+
moved.removeAttribute('data-moved');
|
|
191
|
+
bar.insertBefore(moved, bar.querySelector(':scope > .more'));
|
|
192
|
+
controls.toggleAttribute('data-more', controls.hasAttribute('data-menu'));
|
|
193
|
+
this.#parts = null;
|
|
194
|
+
}
|
|
195
|
+
const row = bar.querySelector(':scope > .row');
|
|
196
|
+
if (phone && row && (row.scrollWidth > row.clientWidth + 0.5 || row.getBoundingClientRect().height > bar.clientHeight + 0.5)) {
|
|
197
|
+
menu.prepend(row);
|
|
198
|
+
row.setAttribute('data-moved', '');
|
|
199
|
+
controls.setAttribute('data-more', '');
|
|
200
|
+
this.#parts = null;
|
|
201
|
+
}
|
|
202
|
+
const more = bar.querySelector(':scope > .more');
|
|
203
|
+
const name = bar.querySelector(':scope > .row') ? 'More controls' : 'Controls';
|
|
204
|
+
if (more && more.getAttribute('aria-label') !== name) {
|
|
205
|
+
more.setAttribute('aria-label', name);
|
|
206
|
+
more.title = name;
|
|
207
|
+
}
|
|
208
|
+
// Moving what has the focus takes it away, so it's given back.
|
|
209
|
+
if (focused && focused !== scope.activeElement && focused.isConnected) focused.focus({ preventScroll: true });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
get roots() {
|
|
214
|
+
return this.#roots;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Whether the controls say each new beat themselves, so the figure needn't say a key's. */
|
|
218
|
+
get speaks() {
|
|
219
|
+
return this.#roots.length > 0 && !!this.#figure.info && this.#find().said.length > 0;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** What's in them changed: look again. */
|
|
223
|
+
forget() {
|
|
224
|
+
this.#parts = null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
#all(selector) {
|
|
228
|
+
return this.#roots.flatMap((root) => [...root.querySelectorAll(selector)]);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
#find() {
|
|
232
|
+
const info = this.#figure.info;
|
|
233
|
+
return (this.#parts ??= {
|
|
234
|
+
play: this.#all('[data-play]'),
|
|
235
|
+
times: this.#all('input[data-time]'),
|
|
236
|
+
timeOuts: this.#all('[data-time]:not(input)'),
|
|
237
|
+
beatOuts: this.#all('[data-beat]'),
|
|
238
|
+
back: this.#all('[data-step="-1"]'),
|
|
239
|
+
next: this.#all('[data-step="1"]'),
|
|
240
|
+
captions: this.#all('[data-captions]').map((list) => [...list.children]),
|
|
241
|
+
params: this.#all('[data-param]')
|
|
242
|
+
.map((el) => ({ el, param: paramNamed(info, el.dataset.param), said: null }))
|
|
243
|
+
.filter((each) => each.param),
|
|
244
|
+
readouts: this.#all('[data-readout]').map((el) => ({ el, id: el.dataset.readout, said: null })),
|
|
245
|
+
said: this.#all('[data-said]'),
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** The figure has loaded: everything can be worked, and shows the figure as it stands. */
|
|
250
|
+
enable() {
|
|
251
|
+
for (const root of this.#roots) {
|
|
252
|
+
// Only what's marked as the figure's: a page's other controls are the page's.
|
|
253
|
+
for (const control of root.querySelectorAll('[data-param], [data-time], [data-play], [data-step]')) {
|
|
254
|
+
if ('disabled' in control) control.disabled = false;
|
|
255
|
+
}
|
|
256
|
+
// And the defaults' menu button, which a build writes disabled with the rest.
|
|
257
|
+
if (root instanceof ShadowRoot) for (const more of root.querySelectorAll('.bar > .more')) more.disabled = false;
|
|
258
|
+
}
|
|
259
|
+
this.#parts = null;
|
|
260
|
+
const info = this.#figure.info;
|
|
261
|
+
for (const { el, param } of this.#find().params) {
|
|
262
|
+
if (el.localName === 'select' && el.options.length === 0 && param.choice) {
|
|
263
|
+
param.choice.options.forEach((text, i) => el.append(new Option(text, String(i))));
|
|
264
|
+
}
|
|
265
|
+
if (el.localName === 'input' && el.type === 'range') {
|
|
266
|
+
const [min, max] = this.#figure.range(param.id);
|
|
267
|
+
Object.assign(el, { min, max, step: param.step ?? ((param.max - param.min) / 1000 || 0.001) });
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
for (const input of this.#find().times) Object.assign(input, { min: 0, max: this.#figure.duration, step: 0.001 });
|
|
271
|
+
if (info) this.paintPlay();
|
|
272
|
+
this.fit();
|
|
273
|
+
this.read();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
#input(target) {
|
|
277
|
+
const figure = this.#figure;
|
|
278
|
+
if (!figure.info || !target?.matches) return;
|
|
279
|
+
if (target.matches('input[type=range][data-time]')) {
|
|
280
|
+
figure.pause();
|
|
281
|
+
figure.time = Number(target.value);
|
|
282
|
+
} else if (target.matches('input[type=range][data-param]')) {
|
|
283
|
+
const param = paramNamed(figure.info, target.dataset.param);
|
|
284
|
+
if (!param) return;
|
|
285
|
+
figure.pause();
|
|
286
|
+
figure.hold(param.id, Number(target.value));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
#change(target) {
|
|
291
|
+
const figure = this.#figure;
|
|
292
|
+
if (!figure.info || !target?.matches?.('select[data-param], input[type=radio][data-param], input[type=checkbox][data-param]')) return;
|
|
293
|
+
const param = paramNamed(figure.info, target.dataset.param);
|
|
294
|
+
if (!param) return;
|
|
295
|
+
if (target.type === 'checkbox') figure.hold(param.id, target.checked ? 1 : 0);
|
|
296
|
+
else if (target.type !== 'radio' || target.checked) figure.hold(param.id, Number(target.value));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
#click(button) {
|
|
300
|
+
if (!button || button.disabled || !this.#figure.info) return;
|
|
301
|
+
const figure = this.#figure;
|
|
302
|
+
if (button.matches('[data-play]')) figure.paused ? figure.play() : figure.pause();
|
|
303
|
+
else if (button.dataset.step) figure.step(Number(button.dataset.step));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Says Play or Pause. A button with a word for each shows the one that applies. */
|
|
307
|
+
paintPlay() {
|
|
308
|
+
const paused = this.#figure.paused;
|
|
309
|
+
for (const button of this.#find().play) {
|
|
310
|
+
const words = button.querySelectorAll(':scope > span');
|
|
311
|
+
if (words.length === 2) {
|
|
312
|
+
words[0].toggleAttribute('data-on', paused);
|
|
313
|
+
words[1].toggleAttribute('data-on', !paused);
|
|
314
|
+
} else {
|
|
315
|
+
const text = paused ? 'Play' : 'Pause';
|
|
316
|
+
if (button.textContent !== text) button.textContent = text;
|
|
317
|
+
}
|
|
318
|
+
button.setAttribute('aria-label', paused ? 'Play' : 'Pause');
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Reads the figure back, so the controls show what's drawn. Only what changed is written. */
|
|
323
|
+
read() {
|
|
324
|
+
const figure = this.#figure;
|
|
325
|
+
const info = figure.info;
|
|
326
|
+
if (!info || !this.#roots.length) return;
|
|
327
|
+
const parts = this.#find();
|
|
328
|
+
const say = (el, text) => {
|
|
329
|
+
if (el.textContent !== text) el.textContent = text;
|
|
330
|
+
};
|
|
331
|
+
const time = figure.time;
|
|
332
|
+
for (const input of parts.times) {
|
|
333
|
+
if (!input.matches(':focus')) input.value = String(time);
|
|
334
|
+
input.setAttribute('aria-valuetext', timeText(time));
|
|
335
|
+
}
|
|
336
|
+
for (const out of parts.timeOuts) say(out, timeText(time));
|
|
337
|
+
for (const each of parts.params) {
|
|
338
|
+
const { el, param } = each;
|
|
339
|
+
const value = figure.value(param.id);
|
|
340
|
+
if (el.localName === 'input' && el.type === 'range') {
|
|
341
|
+
// A range that follows another param is read as it stands, so the control stops where
|
|
342
|
+
// the figure does.
|
|
343
|
+
if (param.follows?.length) [el.min, el.max] = figure.range(param.id);
|
|
344
|
+
if (!el.matches(':focus') && Number.isFinite(value)) el.value = String(value);
|
|
345
|
+
const text = valueText(param, value);
|
|
346
|
+
if (each.said !== text) el.setAttribute('aria-valuetext', text);
|
|
347
|
+
each.said = text;
|
|
348
|
+
} else if (el.localName === 'input' && el.type === 'radio') {
|
|
349
|
+
el.checked = Number(el.value) === Math.round(value);
|
|
350
|
+
} else if (el.localName === 'input' && el.type === 'checkbox') {
|
|
351
|
+
el.checked = Math.round(value) === 1;
|
|
352
|
+
} else if (el.localName === 'select') {
|
|
353
|
+
if (!el.matches(':focus') && Number.isFinite(value)) el.value = String(Math.round(value));
|
|
354
|
+
} else if (el.localName !== 'input') {
|
|
355
|
+
say(el, valueText(param, value));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (steps(info) && (parts.beatOuts.length || parts.captions.length)) {
|
|
359
|
+
const range = info.params.find((p) => p.id === 'beat');
|
|
360
|
+
const beat = Number.isFinite(figure.beat) ? figure.beat : 0;
|
|
361
|
+
const at = beatAt(info, beat);
|
|
362
|
+
for (const out of parts.beatOuts) say(out, at.text);
|
|
363
|
+
for (const list of parts.captions) list.forEach((caption, i) => caption.toggleAttribute('data-on', i === at.caption));
|
|
364
|
+
// A beat that changes is said, however it changed: which it is, and its caption, in the
|
|
365
|
+
// words the element says a key's step in, which it leaves to this. Not the first, which is
|
|
366
|
+
// where the figure starts and isn't news. Beats with lengths are at their start before the
|
|
367
|
+
// first is done.
|
|
368
|
+
const step = (info.beatLengths?.length ?? 0) > 0 && beat < 1e-6 ? 0 : at.caption + 1;
|
|
369
|
+
if (this.#beatSaid !== undefined && this.#beatSaid !== step) {
|
|
370
|
+
const caption = info.beats[step - 1];
|
|
371
|
+
const words = step < 1 ? 'Start' : `Step ${step} of ${info.beats.length}${caption ? `: ${caption}` : ''}`;
|
|
372
|
+
for (const said of parts.said) say(said, words);
|
|
373
|
+
}
|
|
374
|
+
this.#beatSaid = step;
|
|
375
|
+
for (const button of parts.back) button.disabled = beat <= range.min;
|
|
376
|
+
for (const button of parts.next) button.disabled = beat >= range.max;
|
|
377
|
+
}
|
|
378
|
+
if (parts.readouts.length) {
|
|
379
|
+
const said = new Map(figure.readouts.map((readout) => [readout.id, readout]));
|
|
380
|
+
for (const each of parts.readouts) {
|
|
381
|
+
const readout = said.get(each.id);
|
|
382
|
+
const key = readout ? readout.text : '';
|
|
383
|
+
if (each.said === key) continue;
|
|
384
|
+
each.said = key;
|
|
385
|
+
each.el.innerHTML = readoutHtml(readout);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
detach() {
|
|
391
|
+
this.#off?.abort();
|
|
392
|
+
this.#off = null;
|
|
393
|
+
this.#sized?.disconnect();
|
|
394
|
+
this.#sized = null;
|
|
395
|
+
this.#roots = [];
|
|
396
|
+
this.#parts = null;
|
|
397
|
+
}
|
|
398
|
+
}
|