dotquilt 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +64 -2
- package/dist/animations.d.ts +105 -0
- package/dist/animations.js +107 -0
- package/dist/catalog-styles.d.ts +4 -0
- package/dist/catalog-styles.js +12 -0
- package/dist/chart-animations.d.ts +36 -0
- package/dist/chart-animations.js +25 -0
- package/dist/chart-styles.d.ts +3 -0
- package/dist/chart-styles.js +23 -0
- package/dist/chart.css +4 -0
- package/dist/chart.d.ts +73 -0
- package/dist/chart.js +80 -0
- package/dist/circle.css +5 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +9 -0
- package/dist/internal/binding.d.ts +13 -0
- package/dist/internal/binding.js +21 -0
- package/dist/internal/capture.d.ts +4 -0
- package/dist/internal/capture.js +13 -0
- package/dist/internal/chart-appearance.d.ts +12 -0
- package/dist/internal/chart-appearance.js +2 -0
- package/dist/internal/chart-definitions.d.ts +19 -0
- package/dist/internal/chart-definitions.js +149 -0
- package/dist/internal/chart-factory.d.ts +12 -0
- package/dist/internal/chart-factory.js +31 -0
- package/dist/internal/chart-field.d.ts +22 -0
- package/dist/internal/chart-field.js +74 -0
- package/dist/internal/chart-idle.d.ts +3 -0
- package/dist/internal/chart-idle.js +96 -0
- package/dist/internal/chart-math.d.ts +8 -0
- package/dist/internal/chart-math.js +19 -0
- package/dist/internal/chart-participant.d.ts +8 -0
- package/dist/internal/chart-participant.js +4 -0
- package/dist/internal/chart-projection.d.ts +11 -0
- package/dist/internal/chart-projection.js +69 -0
- package/dist/internal/content-box.d.ts +11 -0
- package/dist/internal/content-box.js +36 -0
- package/dist/internal/coordinated-handoff.d.ts +4 -0
- package/dist/internal/coordinated-handoff.js +158 -0
- package/dist/internal/count.d.ts +3 -0
- package/dist/internal/count.js +20 -0
- package/dist/internal/defaults.d.ts +11 -0
- package/dist/internal/defaults.js +11 -0
- package/dist/internal/dense/managed-painter.d.ts +4 -0
- package/dist/internal/dense/managed-painter.js +361 -0
- package/dist/internal/dense/runner.d.ts +2 -0
- package/dist/internal/dense/runner.js +5 -0
- package/dist/internal/dense-loader.d.ts +83 -0
- package/dist/internal/dense-loader.js +331 -0
- package/dist/internal/dissolve.d.ts +27 -0
- package/dist/internal/dissolve.js +216 -0
- package/dist/internal/dom.d.ts +23 -0
- package/dist/internal/dom.js +104 -0
- package/dist/internal/effect.d.ts +2 -0
- package/dist/internal/effect.js +17 -0
- package/dist/internal/element.d.ts +89 -0
- package/dist/internal/element.js +384 -0
- package/dist/internal/event-element.d.ts +8 -0
- package/dist/internal/event-element.js +20 -0
- package/dist/internal/frames.d.ts +1 -0
- package/dist/internal/frames.js +51 -0
- package/dist/internal/handoff.d.ts +56 -0
- package/dist/internal/handoff.js +102 -0
- package/dist/internal/ledger.d.ts +13 -0
- package/dist/internal/ledger.js +78 -0
- package/dist/internal/loading-controller.d.ts +62 -0
- package/dist/internal/loading-controller.js +694 -0
- package/dist/internal/marks.d.ts +153 -0
- package/dist/internal/marks.js +227 -0
- package/dist/internal/math.d.ts +2 -0
- package/dist/internal/math.js +2 -0
- package/dist/internal/morph-marks.d.ts +62 -0
- package/dist/internal/morph-marks.js +205 -0
- package/dist/internal/morph.d.ts +35 -0
- package/dist/internal/morph.js +488 -0
- package/dist/internal/paint.d.ts +29 -0
- package/dist/internal/paint.js +1 -0
- package/dist/internal/painter.d.ts +20 -0
- package/dist/internal/painter.js +155 -0
- package/dist/internal/preset-data.d.ts +12 -0
- package/dist/internal/preset-data.js +31 -0
- package/dist/internal/preset.d.ts +22 -0
- package/dist/internal/preset.js +86 -0
- package/dist/internal/pulse.d.ts +7 -0
- package/dist/internal/pulse.js +74 -0
- package/dist/internal/reveal-effect.d.ts +7 -0
- package/dist/internal/reveal-effect.js +24 -0
- package/dist/internal/reveal.d.ts +5 -0
- package/dist/internal/reveal.js +11 -0
- package/dist/internal/runner.d.ts +9 -0
- package/dist/internal/runner.js +70 -0
- package/dist/internal/services.d.ts +12 -0
- package/dist/internal/services.js +159 -0
- package/dist/internal/skeleton-handoff.d.ts +26 -0
- package/dist/internal/skeleton-handoff.js +6 -0
- package/dist/internal/skeleton-source.d.ts +5 -0
- package/dist/internal/skeleton-source.js +106 -0
- package/dist/internal/surface.d.ts +4 -0
- package/dist/internal/surface.js +21 -0
- package/dist/internal/table-definitions.d.ts +27 -0
- package/dist/internal/table-definitions.js +139 -0
- package/dist/internal/table-factory.d.ts +12 -0
- package/dist/internal/table-factory.js +44 -0
- package/dist/internal/table-field.d.ts +12 -0
- package/dist/internal/table-field.js +75 -0
- package/dist/internal/table-model.d.ts +21 -0
- package/dist/internal/table-model.js +117 -0
- package/dist/internal/table-projection.d.ts +7 -0
- package/dist/internal/table-projection.js +110 -0
- package/dist/internal/target-changes.d.ts +3 -0
- package/dist/internal/target-changes.js +2 -0
- package/dist/internal/target-tracker.d.ts +18 -0
- package/dist/internal/target-tracker.js +33 -0
- package/dist/internal/targets.d.ts +3 -0
- package/dist/internal/targets.js +15 -0
- package/dist/internal/text-definitions.d.ts +141 -0
- package/dist/internal/text-definitions.js +228 -0
- package/dist/internal/text-glyphs.d.ts +4 -0
- package/dist/internal/text-glyphs.js +32 -0
- package/dist/internal/text-morph.d.ts +32 -0
- package/dist/internal/text-morph.js +113 -0
- package/dist/internal/text-playback.d.ts +4 -0
- package/dist/internal/text-playback.js +119 -0
- package/dist/internal/text-scramble.d.ts +18 -0
- package/dist/internal/text-scramble.js +47 -0
- package/dist/internal/time.d.ts +9 -0
- package/dist/internal/time.js +13 -0
- package/dist/internal/unstyled.d.ts +8 -0
- package/dist/internal/unstyled.js +8 -0
- package/dist/line.css +5 -0
- package/dist/region-css.d.ts +1 -0
- package/dist/region-css.js +6 -0
- package/dist/region-styles.d.ts +3 -0
- package/dist/region-styles.js +15 -0
- package/dist/region.css +1 -0
- package/dist/region.d.ts +31 -0
- package/dist/region.js +100 -0
- package/dist/register-all.d.ts +2 -0
- package/dist/register-all.js +33 -0
- package/dist/server.d.ts +63 -0
- package/dist/server.js +141 -0
- package/dist/skeleton-animations.d.ts +10 -0
- package/dist/skeleton-animations.js +35 -0
- package/dist/skeleton-block.d.ts +50 -0
- package/dist/skeleton-block.js +260 -0
- package/dist/skeleton-circle.d.ts +5 -0
- package/dist/skeleton-circle.js +11 -0
- package/dist/skeleton-family.css +13 -0
- package/dist/skeleton-line.d.ts +5 -0
- package/dist/skeleton-line.js +11 -0
- package/dist/skeleton-text.css +5 -0
- package/dist/skeleton-text.d.ts +22 -0
- package/dist/skeleton-text.js +115 -0
- package/dist/skeleton.css +4 -0
- package/dist/skeleton.d.ts +5 -0
- package/dist/skeleton.js +4 -0
- package/dist/static-catalog-styles.d.ts +8 -0
- package/dist/static-catalog-styles.js +44 -0
- package/dist/styles.d.ts +4 -0
- package/dist/styles.js +18 -0
- package/dist/table-animations.d.ts +11 -0
- package/dist/table-animations.js +4 -0
- package/dist/table-styles.d.ts +2 -0
- package/dist/table-styles.js +12 -0
- package/dist/table.css +3 -0
- package/dist/table.d.ts +88 -0
- package/dist/table.js +126 -0
- package/dist/text-animations.d.ts +31 -0
- package/dist/text-animations.js +40 -0
- package/dist/text-styles.d.ts +3 -0
- package/dist/text-styles.js +24 -0
- package/dist/text.css +3 -0
- package/dist/text.d.ts +42 -0
- package/dist/text.js +402 -0
- package/dist/types.d.ts +56 -0
- package/dist/types.js +18 -0
- package/dist/typing-styles.d.ts +1 -0
- package/dist/typing-styles.js +7 -0
- package/dist/typing.css +4 -0
- package/dist/typing.d.ts +35 -0
- package/dist/typing.js +164 -0
- package/package.json +100 -4
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { definitionOf, validateBindings } from './binding.js';
|
|
2
|
+
import { chartHandoff, richHandoff, } from './chart-participant.js';
|
|
3
|
+
import { contentBox, surfaceEnvironment } from './content-box.js';
|
|
4
|
+
import { coordinatedHandoff } from './coordinated-handoff.js';
|
|
5
|
+
import { installDensePainter, invalidateDensePainter, } from './dense/managed-painter.js';
|
|
6
|
+
import { ancestors, media, motionRestricted, upgradeProperties, } from './dom.js';
|
|
7
|
+
import { ManagedElement } from './element.js';
|
|
8
|
+
import { EventElement } from './event-element.js';
|
|
9
|
+
import { runHandoff, } from './handoff.js';
|
|
10
|
+
import { dotRadius, markOf } from './marks.js';
|
|
11
|
+
import { denseParts, morphMarks } from './morph-marks.js';
|
|
12
|
+
import { pointer } from './painter.js';
|
|
13
|
+
import { readSurface } from './surface.js';
|
|
14
|
+
const empty = /* @__PURE__ */ Object.freeze([]);
|
|
15
|
+
/**
|
|
16
|
+
* Shared behaviour of the dot-field loaders (ChartLoader, TableLoader): one
|
|
17
|
+
* dense painter per element, an idle runner while pending, and a rich
|
|
18
|
+
* handoff whose target geometry comes from the caller's `targetProvider`.
|
|
19
|
+
* Subclasses supply the family-specific pieces through the abstract hooks.
|
|
20
|
+
*/
|
|
21
|
+
export class DenseLoader extends EventElement {
|
|
22
|
+
static observedAttributes = [
|
|
23
|
+
...ManagedElement.observedAttributes,
|
|
24
|
+
'speed',
|
|
25
|
+
'pointer-response',
|
|
26
|
+
];
|
|
27
|
+
/** Input used when the handoff has not projected one yet. */
|
|
28
|
+
surfaceInput(input, _width) {
|
|
29
|
+
return input;
|
|
30
|
+
}
|
|
31
|
+
/** Runs once per connection, before the shadow surface is built. */
|
|
32
|
+
prepareConnection() { }
|
|
33
|
+
/** Runs on each render while the owning region is not pending. */
|
|
34
|
+
settled() { }
|
|
35
|
+
#bindings = {};
|
|
36
|
+
#provider;
|
|
37
|
+
#runner;
|
|
38
|
+
#createRunner;
|
|
39
|
+
#source = empty;
|
|
40
|
+
#input;
|
|
41
|
+
#geometry;
|
|
42
|
+
#environment;
|
|
43
|
+
upgrade() {
|
|
44
|
+
upgradeProperties(this, [
|
|
45
|
+
'stylePolicy',
|
|
46
|
+
'preset',
|
|
47
|
+
'animations',
|
|
48
|
+
'motion',
|
|
49
|
+
'speed',
|
|
50
|
+
'pointerResponse',
|
|
51
|
+
'targetProvider',
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
get speed() {
|
|
55
|
+
const n = Number(this.getAttribute('speed') ?? this.preset?.speed ?? 1);
|
|
56
|
+
return Number.isFinite(n) && n > 0 ? Math.min(4, n) : 1;
|
|
57
|
+
}
|
|
58
|
+
set speed(value) {
|
|
59
|
+
if (value === undefined)
|
|
60
|
+
this.removeAttribute('speed');
|
|
61
|
+
else
|
|
62
|
+
this.setAttribute('speed', String(value));
|
|
63
|
+
}
|
|
64
|
+
get pointerResponse() {
|
|
65
|
+
return (this.getAttribute('pointer-response') ??
|
|
66
|
+
this.preset?.pointerResponse) === 'lift'
|
|
67
|
+
? 'lift'
|
|
68
|
+
: 'none';
|
|
69
|
+
}
|
|
70
|
+
set pointerResponse(value) {
|
|
71
|
+
if (value === undefined)
|
|
72
|
+
this.removeAttribute('pointer-response');
|
|
73
|
+
else
|
|
74
|
+
this.setAttribute('pointer-response', value);
|
|
75
|
+
}
|
|
76
|
+
get animations() {
|
|
77
|
+
return this.#bindings;
|
|
78
|
+
}
|
|
79
|
+
set animations(value) {
|
|
80
|
+
try {
|
|
81
|
+
validateBindings(value, this.family);
|
|
82
|
+
this.#bindings = Object.freeze({ ...value });
|
|
83
|
+
this.#runner?.reset?.();
|
|
84
|
+
this.accept('animations');
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
this.#bindings = {};
|
|
88
|
+
this.report('invalid-binding', 'animations');
|
|
89
|
+
}
|
|
90
|
+
this.requestRender();
|
|
91
|
+
}
|
|
92
|
+
get targetProvider() {
|
|
93
|
+
return this.#provider;
|
|
94
|
+
}
|
|
95
|
+
set targetProvider(value) {
|
|
96
|
+
this.#provider = typeof value === 'function' ? value : undefined;
|
|
97
|
+
if (value !== undefined && !this.#provider)
|
|
98
|
+
this.report('invalid-provider', 'targetProvider');
|
|
99
|
+
else
|
|
100
|
+
this.accept('targetProvider');
|
|
101
|
+
}
|
|
102
|
+
/** The region this loader is the placeholder of, if any. */
|
|
103
|
+
get owner() {
|
|
104
|
+
return this.cachedOwner(() => {
|
|
105
|
+
const owner = ancestors(this).find((e) => e.localName === 'dotquilt-region');
|
|
106
|
+
if (!owner)
|
|
107
|
+
return undefined;
|
|
108
|
+
let top = this;
|
|
109
|
+
while (top.parentElement && top.parentElement !== owner)
|
|
110
|
+
top = top.parentElement;
|
|
111
|
+
return top.getAttribute('slot') === 'placeholder' ? owner : undefined;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
get activity() {
|
|
115
|
+
return this.owner?.activity ?? this.ownActivity;
|
|
116
|
+
}
|
|
117
|
+
get optionNames() {
|
|
118
|
+
return [
|
|
119
|
+
...super.optionNames,
|
|
120
|
+
'speed',
|
|
121
|
+
'pointerResponse',
|
|
122
|
+
'animations',
|
|
123
|
+
'targetProvider',
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
presetChanged() {
|
|
127
|
+
this.#runner?.reset?.();
|
|
128
|
+
}
|
|
129
|
+
attributeChangedCallback(name, old, value) {
|
|
130
|
+
if (value !== null &&
|
|
131
|
+
((name === 'pointer-response' && !['none', 'lift'].includes(value)) ||
|
|
132
|
+
(name === 'speed' &&
|
|
133
|
+
!(Number.isFinite(Number(value)) && Number(value) > 0))))
|
|
134
|
+
this.invalidOption(name);
|
|
135
|
+
super.attributeChangedCallback(name, old, value);
|
|
136
|
+
// Another mark has another size and pitch, so the field is rebuilt.
|
|
137
|
+
if (name === 'mark' && old !== value && this.shadowRoot)
|
|
138
|
+
this.refresh();
|
|
139
|
+
}
|
|
140
|
+
connectedCallback() {
|
|
141
|
+
installDensePainter(this);
|
|
142
|
+
this.prepareConnection();
|
|
143
|
+
super.connectedCallback();
|
|
144
|
+
this.setAttribute('data-dotquilt-surface', '');
|
|
145
|
+
this.setAttribute('aria-hidden', 'true');
|
|
146
|
+
if (!this.shadowRoot)
|
|
147
|
+
this.attachStyledShadow(this.styles, true).append(this.createSurface(this.ownerDocument));
|
|
148
|
+
// Server-rendered fallback markup is replaced by the live surface.
|
|
149
|
+
this.whenStyled(() => {
|
|
150
|
+
for (const child of this.querySelectorAll(':scope > [data-dotquilt-style],:scope > [data-dotquilt-static]'))
|
|
151
|
+
child.remove();
|
|
152
|
+
});
|
|
153
|
+
this.listen(this.shadowRoot, 'load', () => this.refresh(), true);
|
|
154
|
+
const pointerHost = this.owner ?? this;
|
|
155
|
+
this.listen(pointerHost, 'pointermove', this.#pointer);
|
|
156
|
+
this.listen(pointerHost, 'pointerleave', this.#clearPointer);
|
|
157
|
+
}
|
|
158
|
+
disconnectedCallback() {
|
|
159
|
+
super.disconnectedCallback();
|
|
160
|
+
this.#runner?.dispose();
|
|
161
|
+
this.#provider = undefined;
|
|
162
|
+
this.#clearPointer();
|
|
163
|
+
this.clearSurface();
|
|
164
|
+
}
|
|
165
|
+
refresh() {
|
|
166
|
+
invalidateDensePainter(this);
|
|
167
|
+
this.#runner?.reset?.();
|
|
168
|
+
this.clearSurface();
|
|
169
|
+
this.resources?.eligible(true);
|
|
170
|
+
this.requestRender();
|
|
171
|
+
}
|
|
172
|
+
[readSurface](_family, ids = []) {
|
|
173
|
+
if (!this.#geometry) {
|
|
174
|
+
const { width, height } = contentBox(this);
|
|
175
|
+
// Let CSS resolve lengths/calc once per invalidation, never per frame.
|
|
176
|
+
const field = this.shadowRoot?.querySelector('.surface');
|
|
177
|
+
const resolved = field && this.ownerDocument.defaultView?.getComputedStyle(field);
|
|
178
|
+
// The tile is the pitch across and down; dashes have different ones.
|
|
179
|
+
const [across = 0, down = across] = (resolved?.backgroundSize ?? '')
|
|
180
|
+
.split(/\s+/)
|
|
181
|
+
.map(parseFloat);
|
|
182
|
+
const pitch = across || 6, rows = down || pitch, gap = parseFloat(resolved?.gap ?? ''),
|
|
183
|
+
// Dots take their size from the CSS; squares and dashes have a fixed
|
|
184
|
+
// spec size, drawn at the default radius.
|
|
185
|
+
size = markOf(this) === 'dot'
|
|
186
|
+
? Math.max(0, pitch - (gap >= 0 ? gap : 4))
|
|
187
|
+
: 2 * dotRadius;
|
|
188
|
+
this.#geometry = Object.freeze({
|
|
189
|
+
family: this.family,
|
|
190
|
+
width,
|
|
191
|
+
height,
|
|
192
|
+
input: this.surfaceInput(this.#input ?? this.emptyInput, width),
|
|
193
|
+
source: this.#source,
|
|
194
|
+
revealTargetIds: Object.freeze([...ids]),
|
|
195
|
+
[this.appearanceKey]: Object.freeze({
|
|
196
|
+
pitch: Math.max(2, Math.min(64, pitch)),
|
|
197
|
+
rows: Math.max(2, Math.min(64, rows)),
|
|
198
|
+
scale: Math.max(0.1, Math.min(8, size / 2)),
|
|
199
|
+
mark: markOf(this),
|
|
200
|
+
}),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return this.#geometry;
|
|
204
|
+
}
|
|
205
|
+
/** Its marks as last drawn, for the region's morph handoff (morph.ts). */
|
|
206
|
+
[morphMarks](origin) {
|
|
207
|
+
return denseParts(this, origin, this.#runner?.capture?.() ?? empty);
|
|
208
|
+
}
|
|
209
|
+
/** Whether it needs its rich handoff: real geometry from a provider, or a chosen animation. */
|
|
210
|
+
get [richHandoff]() {
|
|
211
|
+
return !!(this.#provider ??
|
|
212
|
+
this.#bindings.handoff ??
|
|
213
|
+
this.preset?.animations?.handoff);
|
|
214
|
+
}
|
|
215
|
+
[chartHandoff](owner, participants) {
|
|
216
|
+
if (participants && participants.length > 1)
|
|
217
|
+
return coordinatedHandoff(owner, participants.map((child) => child[chartHandoff](owner)));
|
|
218
|
+
this.#clearPointer();
|
|
219
|
+
const binding = this.#bindings.handoff ??
|
|
220
|
+
this.preset?.animations?.handoff ??
|
|
221
|
+
this.defaultHandoff();
|
|
222
|
+
const project = this.projector(this.#provider), easing = owner.timing.easing;
|
|
223
|
+
return {
|
|
224
|
+
binding,
|
|
225
|
+
host: this,
|
|
226
|
+
animation: binding.id,
|
|
227
|
+
prepare: (selected, request) => {
|
|
228
|
+
this.#input = project(Object.freeze(contentBox(this)), request.report);
|
|
229
|
+
this.#source = this.#runner?.capture?.() ?? empty;
|
|
230
|
+
// Release the outgoing painter before admitting the handoff painter.
|
|
231
|
+
// The captured dot snapshot keeps continuity without a double peak.
|
|
232
|
+
this.#runner?.dispose();
|
|
233
|
+
this.#geometry = undefined;
|
|
234
|
+
const captured = selected ?? binding;
|
|
235
|
+
let driver;
|
|
236
|
+
try {
|
|
237
|
+
driver = runHandoff(undefined, captured, {
|
|
238
|
+
...request,
|
|
239
|
+
// The handoff also ends when this loader leaves its region.
|
|
240
|
+
current: () => request.current() && this.isConnected && this.owner === owner,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
this.clearSurface();
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
...driver,
|
|
249
|
+
restricted: () => motionRestricted(this),
|
|
250
|
+
draw: (linear, eased) => driver.draw?.(linear, easing === undefined ? linear : eased),
|
|
251
|
+
dispose: () => {
|
|
252
|
+
driver.dispose();
|
|
253
|
+
this.clearSurface();
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
environmentChanged() {
|
|
260
|
+
const environment = surfaceEnvironment(this);
|
|
261
|
+
if (environment === this.#environment) {
|
|
262
|
+
// Nothing the drawing depends on changed: only re-check eligibility.
|
|
263
|
+
this.resources?.eligible(true);
|
|
264
|
+
this.requestRender();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
this.#environment = environment;
|
|
268
|
+
this.refresh();
|
|
269
|
+
}
|
|
270
|
+
/** Drops the measured surface and the handoff's projected input. */
|
|
271
|
+
clearSurface() {
|
|
272
|
+
this.#geometry = undefined;
|
|
273
|
+
this.#source = empty;
|
|
274
|
+
this.#input = undefined;
|
|
275
|
+
}
|
|
276
|
+
#clearPointer = () => Reflect.deleteProperty(this, pointer);
|
|
277
|
+
#pointer = (event) => {
|
|
278
|
+
if (this.pointerResponse !== 'lift' ||
|
|
279
|
+
!this.hasAttribute('data-moving') ||
|
|
280
|
+
event.pointerType === 'touch' ||
|
|
281
|
+
!media(this.ownerDocument.defaultView, '(hover:hover) and (pointer:fine)')) {
|
|
282
|
+
// Lift no longer applies (touch, no hover, paused): drop the old position
|
|
283
|
+
// so the drawing does not stay lifted at a stale point.
|
|
284
|
+
this.#clearPointer();
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const r = (this.shadowRoot?.querySelector('svg[data-dotquilt-painter]') ?? this).getBoundingClientRect();
|
|
288
|
+
if (!r.width || !r.height)
|
|
289
|
+
return;
|
|
290
|
+
Reflect.set(this, pointer, {
|
|
291
|
+
x: (event.clientX - r.left) *
|
|
292
|
+
((this.#geometry?.width ?? r.width) / r.width),
|
|
293
|
+
y: (event.clientY - r.top) *
|
|
294
|
+
((this.#geometry?.height ?? r.height) / r.height),
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
render() {
|
|
298
|
+
const owner = this.owner;
|
|
299
|
+
if (owner && owner.presentation !== 'pending') {
|
|
300
|
+
this.#clearPointer();
|
|
301
|
+
this.removeAttribute('data-moving');
|
|
302
|
+
this.#runner?.dispose();
|
|
303
|
+
this.settled();
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const moving = this.allowed(this.activity);
|
|
307
|
+
if (media(this.ownerDocument.defaultView, '(forced-colors: active)')) {
|
|
308
|
+
this.#runner?.dispose();
|
|
309
|
+
this.removeAttribute('data-moving');
|
|
310
|
+
this.#clearPointer();
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
this.toggleAttribute('data-moving', moving);
|
|
314
|
+
if (!moving || this.pointerResponse !== 'lift')
|
|
315
|
+
this.#clearPointer();
|
|
316
|
+
if (moving && (this.activity.started === undefined || !this.deadline))
|
|
317
|
+
this.arm(this.activity);
|
|
318
|
+
const binding = this.#bindings.idle ??
|
|
319
|
+
this.preset?.animations?.idle ??
|
|
320
|
+
this.defaultIdle();
|
|
321
|
+
const createRunner = definitionOf(binding).runner;
|
|
322
|
+
if (this.#runner && this.#createRunner !== createRunner) {
|
|
323
|
+
// A different idle definition may need a different renderer.
|
|
324
|
+
this.#runner.dispose();
|
|
325
|
+
this.#runner = undefined;
|
|
326
|
+
}
|
|
327
|
+
this.#createRunner = createRunner;
|
|
328
|
+
this.#runner ??= createRunner?.(this, (code) => this.report(code, 'animations'), () => this.requestRender());
|
|
329
|
+
this.#runner?.draw(binding, !moving, this.speed);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Departure } from './skeleton-handoff.js';
|
|
2
|
+
/**
|
|
3
|
+
* Where a CSS-painted surface draws its marks, relative to `bounds`: its box,
|
|
4
|
+
* the mark size and pitch, and the grid offsets that reproduce the pattern.
|
|
5
|
+
*/
|
|
6
|
+
export declare function measureSurface(win: Window, surface: HTMLElement, bounds: DOMRect): {
|
|
7
|
+
size: number;
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
across: number;
|
|
13
|
+
down: number;
|
|
14
|
+
columnOffset: number;
|
|
15
|
+
columnStep: number;
|
|
16
|
+
rowOffset: number;
|
|
17
|
+
rowStep: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The marks leave from left to right (design/SPEC.md): the field is cut into
|
|
21
|
+
* vertical bands, and each band's marks dim, shrink and drift over half the
|
|
22
|
+
* handoff, starting later the further right the band is. No per-dot loop.
|
|
23
|
+
*/
|
|
24
|
+
export declare function dissolveSkeleton(host: HTMLElement, duration: number, easing: string | undefined, departure: Departure, own: (animation: Animation) => void, invalidate: () => void, report: (code: string) => void): {
|
|
25
|
+
dispose(): void;
|
|
26
|
+
check(): void;
|
|
27
|
+
};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a skeleton's marks leave during a region handoff, and where its CSS
|
|
3
|
+
* grid draws them. Only a region hands a skeleton over, so this is the
|
|
4
|
+
* region's code (skeleton-source.ts): a skeleton on its own never loads it.
|
|
5
|
+
*/
|
|
6
|
+
import { media } from './dom.js';
|
|
7
|
+
import { lease } from './ledger.js';
|
|
8
|
+
import { curves, markOf, shapes as markShapes, restOpacity } from './marks.js';
|
|
9
|
+
/** Each band of marks takes this share of the handoff; later bands start later. */
|
|
10
|
+
const exitWindow = 0.5;
|
|
11
|
+
/** The offset of a repeating tile of `tile` px placed at `position` in `box` px. */
|
|
12
|
+
function gridOffset(position, box, tile) {
|
|
13
|
+
const value = parseFloat(position) || 0;
|
|
14
|
+
const px = position.trim().endsWith('%')
|
|
15
|
+
? (value / 100) * (box - tile)
|
|
16
|
+
: value;
|
|
17
|
+
return tile > 0 ? ((px % tile) + tile) % tile : 0;
|
|
18
|
+
}
|
|
19
|
+
/** Plain numbers, so the resize check can compare measurements with `!==`. */
|
|
20
|
+
function flat(axis, { step, offset }) {
|
|
21
|
+
return { [`${axis}Step`]: step, [`${axis}Offset`]: offset };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Where the CSS grid puts its marks along one axis: the distance between
|
|
25
|
+
* mark centres and the pattern offset that reproduces them. `space` draws
|
|
26
|
+
* only whole tiles, the first and last touching the edges.
|
|
27
|
+
*/
|
|
28
|
+
function gridAxis(repeat, position, box, tile) {
|
|
29
|
+
const count = Math.floor(box / tile);
|
|
30
|
+
if (repeat === 'space' && count >= 2) {
|
|
31
|
+
const step = (box - tile) / (count - 1);
|
|
32
|
+
return { step, offset: (tile - step) / 2 };
|
|
33
|
+
}
|
|
34
|
+
return { step: tile, offset: gridOffset(position, box, tile) };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Where a CSS-painted surface draws its marks, relative to `bounds`: its box,
|
|
38
|
+
* the mark size and pitch, and the grid offsets that reproduce the pattern.
|
|
39
|
+
*/
|
|
40
|
+
export function measureSurface(win, surface, bounds) {
|
|
41
|
+
const box = surface.getBoundingClientRect();
|
|
42
|
+
const css = win.getComputedStyle(surface);
|
|
43
|
+
// The tile is the pitch across and down; dashes have different ones.
|
|
44
|
+
const [across = Number.NaN, down = across] = css.backgroundSize
|
|
45
|
+
.split(/\s+/)
|
|
46
|
+
.map(parseFloat);
|
|
47
|
+
const repeat = css.backgroundRepeat.split(/\s+/);
|
|
48
|
+
return {
|
|
49
|
+
size: parseFloat(css.getPropertyValue('--s')) || across / 2,
|
|
50
|
+
x: box.left - bounds.left,
|
|
51
|
+
y: box.top - bounds.top,
|
|
52
|
+
width: box.width,
|
|
53
|
+
height: box.height,
|
|
54
|
+
across,
|
|
55
|
+
down,
|
|
56
|
+
// Where the CSS grid puts its marks, so the fields line up with them.
|
|
57
|
+
...flat('column', gridAxis(repeat[0] ?? 'repeat', css.backgroundPositionX, box.width, across)),
|
|
58
|
+
...flat('row', gridAxis(repeat[1] ?? repeat[0] ?? 'repeat', css.backgroundPositionY, box.height, down)),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The marks leave from left to right (design/SPEC.md): the field is cut into
|
|
63
|
+
* vertical bands, and each band's marks dim, shrink and drift over half the
|
|
64
|
+
* handoff, starting later the further right the band is. No per-dot loop.
|
|
65
|
+
*/
|
|
66
|
+
export function dissolveSkeleton(host, duration, easing, departure, own, invalidate, report) {
|
|
67
|
+
const root = host.shadowRoot;
|
|
68
|
+
const win = host.ownerDocument.defaultView;
|
|
69
|
+
if (!root || !win || media(win, '(forced-colors: active)'))
|
|
70
|
+
return { dispose() { }, check() { } };
|
|
71
|
+
const surfaces = [...root.querySelectorAll('.surface')].filter((surface) => !surface.closest('.pulse,.lift'));
|
|
72
|
+
const bounds = host.getBoundingClientRect();
|
|
73
|
+
// Squares and dashes have a fixed spec size; dots follow --dotquilt-dot-size.
|
|
74
|
+
const mark = markOf(host);
|
|
75
|
+
const measure = (surface, bounds) => measureSurface(win, surface, bounds);
|
|
76
|
+
const shapes = surfaces.map((surface) => measure(surface, bounds));
|
|
77
|
+
if (!shapes.length ||
|
|
78
|
+
shapes.length > 50 ||
|
|
79
|
+
shapes.some((shape) => ![
|
|
80
|
+
shape.x,
|
|
81
|
+
shape.y,
|
|
82
|
+
shape.width,
|
|
83
|
+
shape.height,
|
|
84
|
+
shape.across,
|
|
85
|
+
shape.down,
|
|
86
|
+
].every(Number.isFinite) ||
|
|
87
|
+
shape.across < 1 ||
|
|
88
|
+
shape.down < 1))
|
|
89
|
+
throw new TypeError();
|
|
90
|
+
const count = shapes.reduce((sum, shape) => sum +
|
|
91
|
+
Math.ceil(shape.width / shape.across) *
|
|
92
|
+
Math.ceil(shape.height / shape.down), 0);
|
|
93
|
+
const doc = host.ownerDocument;
|
|
94
|
+
const budget = lease(doc, () => { });
|
|
95
|
+
if (!budget.set('dots', count)) {
|
|
96
|
+
budget.close();
|
|
97
|
+
report('dot-limit');
|
|
98
|
+
return { dispose() { }, check() { } };
|
|
99
|
+
}
|
|
100
|
+
const node = (tag, attributes) => {
|
|
101
|
+
const element = doc.createElementNS('http://www.w3.org/2000/svg', tag);
|
|
102
|
+
for (const [key, value] of Object.entries(attributes))
|
|
103
|
+
element.setAttribute(key, String(value));
|
|
104
|
+
return element;
|
|
105
|
+
};
|
|
106
|
+
const svg = node('svg', {
|
|
107
|
+
'aria-hidden': 'true',
|
|
108
|
+
'data-dotquilt-dissolve': '',
|
|
109
|
+
});
|
|
110
|
+
let resize;
|
|
111
|
+
let closed = false;
|
|
112
|
+
const dispose = () => {
|
|
113
|
+
if (closed)
|
|
114
|
+
return;
|
|
115
|
+
closed = true;
|
|
116
|
+
resize?.disconnect();
|
|
117
|
+
svg.remove();
|
|
118
|
+
host.removeAttribute('data-custom');
|
|
119
|
+
budget.close();
|
|
120
|
+
};
|
|
121
|
+
const check = () => {
|
|
122
|
+
if (closed)
|
|
123
|
+
return;
|
|
124
|
+
const next = host.getBoundingClientRect();
|
|
125
|
+
if (next.width !== bounds.width ||
|
|
126
|
+
next.height !== bounds.height ||
|
|
127
|
+
surfaces.some((surface, index) => {
|
|
128
|
+
const before = shapes[index];
|
|
129
|
+
const after = measure(surface, next);
|
|
130
|
+
return (!before ||
|
|
131
|
+
!surface.isConnected ||
|
|
132
|
+
Object.keys(before).some((key) => before[key] !== after[key]));
|
|
133
|
+
}))
|
|
134
|
+
invalidate();
|
|
135
|
+
};
|
|
136
|
+
try {
|
|
137
|
+
for (const [index, shape] of shapes.entries()) {
|
|
138
|
+
const field = node('svg', {
|
|
139
|
+
x: shape.x,
|
|
140
|
+
y: shape.y,
|
|
141
|
+
width: shape.width,
|
|
142
|
+
height: shape.height,
|
|
143
|
+
});
|
|
144
|
+
const bands = Math.max(1, Math.min(12, Math.round(shape.width / (shape.across * 4))));
|
|
145
|
+
const width = shape.width / bands;
|
|
146
|
+
for (let band = 0; band < bands; band++) {
|
|
147
|
+
const id = `d${index}-${band}`;
|
|
148
|
+
const pattern = node('pattern', {
|
|
149
|
+
id,
|
|
150
|
+
patternUnits: 'userSpaceOnUse',
|
|
151
|
+
x: shape.columnOffset,
|
|
152
|
+
y: shape.rowOffset,
|
|
153
|
+
width: shape.columnStep,
|
|
154
|
+
height: shape.rowStep,
|
|
155
|
+
});
|
|
156
|
+
// A dot's radius comes from the stylesheet; squares and dashes shrink
|
|
157
|
+
// about their own centre.
|
|
158
|
+
const glyph = mark === 'dot'
|
|
159
|
+
? node('circle', {
|
|
160
|
+
cx: shape.columnStep / 2,
|
|
161
|
+
cy: shape.rowStep / 2,
|
|
162
|
+
})
|
|
163
|
+
: node('rect', {
|
|
164
|
+
x: (shape.columnStep - markShapes[mark].width) / 2,
|
|
165
|
+
y: (shape.rowStep - markShapes[mark].height) / 2,
|
|
166
|
+
width: markShapes[mark].width,
|
|
167
|
+
height: markShapes[mark].height,
|
|
168
|
+
rx: markShapes[mark].radius,
|
|
169
|
+
});
|
|
170
|
+
pattern.append(glyph);
|
|
171
|
+
const rect = node('rect', {
|
|
172
|
+
x: band * width,
|
|
173
|
+
width,
|
|
174
|
+
height: shape.height,
|
|
175
|
+
fill: `url(#${id})`,
|
|
176
|
+
});
|
|
177
|
+
field.append(pattern, rect);
|
|
178
|
+
const timing = {
|
|
179
|
+
duration: duration * exitWindow,
|
|
180
|
+
delay: bands > 1 ? (band / (bands - 1)) * (1 - exitWindow) * duration : 0,
|
|
181
|
+
fill: 'both',
|
|
182
|
+
};
|
|
183
|
+
own(rect.animate([
|
|
184
|
+
{
|
|
185
|
+
opacity: restOpacity,
|
|
186
|
+
transform: 'translateY(0px)',
|
|
187
|
+
easing: easing ?? curves.sine,
|
|
188
|
+
},
|
|
189
|
+
{ opacity: 0, transform: `translateY(${departure.driftPx}px)` },
|
|
190
|
+
], timing));
|
|
191
|
+
if (departure.shrink)
|
|
192
|
+
own(glyph.animate(mark === 'dot'
|
|
193
|
+
? [
|
|
194
|
+
{ r: `${shape.size / 2}px`, easing: easing ?? curves.sine },
|
|
195
|
+
{ r: `${(shape.size / 2) * (1 - departure.shrink)}px` },
|
|
196
|
+
]
|
|
197
|
+
: [
|
|
198
|
+
{ scale: 1, easing: easing ?? curves.sine },
|
|
199
|
+
{ scale: 1 - departure.shrink },
|
|
200
|
+
], timing));
|
|
201
|
+
}
|
|
202
|
+
svg.append(field);
|
|
203
|
+
}
|
|
204
|
+
root.append(svg);
|
|
205
|
+
host.setAttribute('data-custom', '');
|
|
206
|
+
resize = new win.ResizeObserver(check);
|
|
207
|
+
resize.observe(host);
|
|
208
|
+
for (const surface of surfaces)
|
|
209
|
+
resize.observe(surface);
|
|
210
|
+
return { dispose, check };
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
dispose();
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type StylePolicy } from '../types.js';
|
|
2
|
+
/** Lets a host's Canvas painter re-read colours after a stylesheet change. */
|
|
3
|
+
export declare const styleRefresh: unique symbol;
|
|
4
|
+
export type RefreshHost = HTMLElement & {
|
|
5
|
+
[styleRefresh]?: () => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const BaseElement: typeof HTMLElement;
|
|
8
|
+
export declare function register(name: string, elementClass: CustomElementConstructor): void;
|
|
9
|
+
export declare function node<K extends keyof HTMLElementTagNameMap>(doc: Document, tag: K, attrs?: Record<string, string>): HTMLElementTagNameMap[K];
|
|
10
|
+
export declare function installStyles(root: ShadowRoot, css: readonly string[], policy: StylePolicy): void;
|
|
11
|
+
export declare function upgradeProperties(host: HTMLElement, keys: readonly string[]): void;
|
|
12
|
+
export declare function emit(host: HTMLElement, type: string, detail: object): void;
|
|
13
|
+
export declare function composedParent(node: Node): Node | null;
|
|
14
|
+
export declare function motionRestricted(host: HTMLElement): boolean;
|
|
15
|
+
export declare function ancestors(host: HTMLElement): HTMLElement[];
|
|
16
|
+
export declare function activeWithin(host: HTMLElement): boolean;
|
|
17
|
+
/** Whether a media query matches, reusing one MediaQueryList per window and query. */
|
|
18
|
+
export declare function media(win: Window | null | undefined, query: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Where painters append their drawing: the host's frame when it has one (a
|
|
21
|
+
* grid spanning exactly the content box), otherwise the shadow root itself.
|
|
22
|
+
*/
|
|
23
|
+
export declare function paintLayer(root: ShadowRoot): ParentNode;
|