dotquilt 0.0.0-stage → 0.1.1
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 +698 -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,35 @@
|
|
|
1
|
+
import type { HandoffDriver, HandoffRequest } from './handoff.js';
|
|
2
|
+
import { type Box, type Seed } from './morph-marks.js';
|
|
3
|
+
interface Travel {
|
|
4
|
+
readonly from: Seed;
|
|
5
|
+
readonly x: number;
|
|
6
|
+
readonly y: number;
|
|
7
|
+
readonly r: number;
|
|
8
|
+
readonly born: boolean;
|
|
9
|
+
readonly dies: boolean;
|
|
10
|
+
/** Stays where it is until the front passes: a mark with nowhere to go. */
|
|
11
|
+
readonly holds?: boolean;
|
|
12
|
+
/** 0 at the front's start, 1 at its end: when this mark sets off. */
|
|
13
|
+
readonly order: number;
|
|
14
|
+
}
|
|
15
|
+
export interface MorphPlan {
|
|
16
|
+
readonly travels: readonly Travel[];
|
|
17
|
+
readonly width: number;
|
|
18
|
+
readonly height: number;
|
|
19
|
+
readonly rtl: boolean;
|
|
20
|
+
readonly shell?: {
|
|
21
|
+
readonly element: HTMLElement;
|
|
22
|
+
readonly from: Box;
|
|
23
|
+
readonly to: Box;
|
|
24
|
+
} | undefined;
|
|
25
|
+
}
|
|
26
|
+
/** Reads the placeholder and the content and decides where every mark goes. */
|
|
27
|
+
export declare function planMorph(region: HTMLElement, participants: readonly HTMLElement[]): MorphPlan;
|
|
28
|
+
/**
|
|
29
|
+
* The default region handoff for skeleton and typing placeholders, and for
|
|
30
|
+
* any placeholder without an animation of its own. Paints both layers itself.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createMorph(region: HTMLElement, participants: readonly HTMLElement[], placeholder: HTMLElement, request: HandoffRequest, duration: number): HandoffDriver & {
|
|
33
|
+
readonly paints: true;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { createEffect } from './effect.js';
|
|
2
|
+
import { frames } from './frames.js';
|
|
3
|
+
import { lease } from './ledger.js';
|
|
4
|
+
import { markBox, morphTiming } from './marks.js';
|
|
5
|
+
import { clamp } from './math.js';
|
|
6
|
+
import { inside, morphMarks, radiusOf, relative, round, skeletonParts, typingPart, } from './morph-marks.js';
|
|
7
|
+
/**
|
|
8
|
+
* The region handoff (design/SPEC.md, "take shape, then hand over"), the
|
|
9
|
+
* chart's handoff for every other placeholder:
|
|
10
|
+
*
|
|
11
|
+
* 1. Take shape. Each mark travels in a wave to where the real content is:
|
|
12
|
+
* lines grow or shrink to the length of each real text line, blocks and
|
|
13
|
+
* circles reshape to the real image or avatar, typing dots unroll into the
|
|
14
|
+
* message, and a placeholder card or bubble grows to the real one's size.
|
|
15
|
+
* 2. Hand over. The content wipes in along a soft front at the idle glow's
|
|
16
|
+
* angle, and the marks leave exactly where the front passes them.
|
|
17
|
+
*
|
|
18
|
+
* Geometry is read once, when the region becomes ready; the content is
|
|
19
|
+
* already laid out (hidden) while pending, so its lines and boxes are known.
|
|
20
|
+
*/
|
|
21
|
+
/** The front's direction: the idle glow's 104°, so lower lines follow a little later. */
|
|
22
|
+
const ax = Math.sin((104 * Math.PI) / 180), ay = -Math.cos((104 * Math.PI) / 180);
|
|
23
|
+
const front = (x, y) => x * ax + y * ay;
|
|
24
|
+
const sine = (t) => 0.5 - Math.cos(Math.PI * clamp(t)) / 2;
|
|
25
|
+
const settle = (t) => 1 - (1 - clamp(t)) ** 3;
|
|
26
|
+
const mix = (a, b, t) => a + (b - a) * t;
|
|
27
|
+
const svgns = 'http://www.w3.org/2000/svg';
|
|
28
|
+
const centre = (box) => [box.x + box.w / 2, box.y + box.h / 2];
|
|
29
|
+
const transparent = (value) => value === 'transparent' || /[,/]\s*0\)$/.test(value);
|
|
30
|
+
/** Has a background, a shadow or a full border: something you can see as a shape. */
|
|
31
|
+
function visual(css) {
|
|
32
|
+
return (css.backgroundImage !== 'none' ||
|
|
33
|
+
!transparent(css.backgroundColor) ||
|
|
34
|
+
css.boxShadow !== 'none' ||
|
|
35
|
+
['top', 'right', 'bottom', 'left'].every((side) => parseFloat(css.getPropertyValue(`border-${side}-width`)) > 0));
|
|
36
|
+
}
|
|
37
|
+
/** The region's content nodes: everything not slotted elsewhere. */
|
|
38
|
+
function contentNodes(region) {
|
|
39
|
+
return [...region.childNodes].filter((node) => !(node instanceof Element) ||
|
|
40
|
+
(!node.slot &&
|
|
41
|
+
!node.matches('style,script,template,[data-dotquilt-placeholder],[data-dotquilt-style],[data-dotquilt-static]')));
|
|
42
|
+
}
|
|
43
|
+
/** Lines of text, as runs of words that sit together, in reading order. */
|
|
44
|
+
function textRuns(nodes, origin) {
|
|
45
|
+
const doc = nodes[0]?.ownerDocument;
|
|
46
|
+
if (!doc)
|
|
47
|
+
return [];
|
|
48
|
+
const rects = [];
|
|
49
|
+
const range = doc.createRange();
|
|
50
|
+
const collect = (text) => {
|
|
51
|
+
if (!/\S/.test(text.data) || rects.length > 600)
|
|
52
|
+
return;
|
|
53
|
+
const parent = text.parentElement;
|
|
54
|
+
if (parent?.closest('[aria-hidden=true] svg, script, style'))
|
|
55
|
+
return;
|
|
56
|
+
range.selectNodeContents(text);
|
|
57
|
+
for (const rect of range.getClientRects())
|
|
58
|
+
if (rect.width > 0.5 && rect.height > 0.5)
|
|
59
|
+
rects.push(rect);
|
|
60
|
+
};
|
|
61
|
+
for (const node of nodes) {
|
|
62
|
+
if (node instanceof Text)
|
|
63
|
+
collect(node);
|
|
64
|
+
else if (node instanceof Element) {
|
|
65
|
+
const walker = doc.createTreeWalker(node, NodeFilter.SHOW_TEXT);
|
|
66
|
+
for (let text = walker.nextNode(); text; text = walker.nextNode())
|
|
67
|
+
collect(text);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
rects.sort((a, b) => Math.round((a.top + a.height / 2) / 4) -
|
|
71
|
+
Math.round((b.top + b.height / 2) / 4) || a.left - b.left);
|
|
72
|
+
const runs = [];
|
|
73
|
+
for (const rect of rects) {
|
|
74
|
+
const run = runs.find((run) => Math.min(run.b, rect.bottom) - Math.max(run.t, rect.top) >=
|
|
75
|
+
0.5 * Math.min(run.b - run.t, rect.height) &&
|
|
76
|
+
rect.left - run.r <= 0.6 * rect.height &&
|
|
77
|
+
rect.left - run.r >= -2);
|
|
78
|
+
if (run) {
|
|
79
|
+
run.r = Math.max(run.r, rect.right);
|
|
80
|
+
run.t = Math.min(run.t, rect.top);
|
|
81
|
+
run.b = Math.max(run.b, rect.bottom);
|
|
82
|
+
}
|
|
83
|
+
else
|
|
84
|
+
runs.push({ l: rect.left, t: rect.top, r: rect.right, b: rect.bottom });
|
|
85
|
+
}
|
|
86
|
+
return runs.slice(0, 80).map((run) => ({
|
|
87
|
+
x: run.l - origin.left,
|
|
88
|
+
y: run.t - origin.top,
|
|
89
|
+
w: run.r - run.l,
|
|
90
|
+
h: run.b - run.t,
|
|
91
|
+
r: 0,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
/** Images, avatars, badges: boxes in the content a block or circle can become. */
|
|
95
|
+
function contentBoxes(nodes, origin, area) {
|
|
96
|
+
const win = nodes[0]?.ownerDocument?.defaultView;
|
|
97
|
+
if (!win)
|
|
98
|
+
return [];
|
|
99
|
+
const atoms = [];
|
|
100
|
+
let seen = 0;
|
|
101
|
+
for (const node of nodes) {
|
|
102
|
+
if (!(node instanceof Element))
|
|
103
|
+
continue;
|
|
104
|
+
for (const element of [node, ...node.querySelectorAll('*')]) {
|
|
105
|
+
if (++seen > 240)
|
|
106
|
+
return atoms;
|
|
107
|
+
if (element.parentElement?.closest('svg'))
|
|
108
|
+
continue;
|
|
109
|
+
const rect = element.getBoundingClientRect();
|
|
110
|
+
if (rect.width < 14 || rect.height < 14)
|
|
111
|
+
continue;
|
|
112
|
+
// A container around most of the content is not a shape to become.
|
|
113
|
+
if (rect.width * rect.height > 0.6 * area &&
|
|
114
|
+
/\S/.test(element.textContent ?? ''))
|
|
115
|
+
continue;
|
|
116
|
+
const css = win.getComputedStyle(element);
|
|
117
|
+
if (!element.matches('img,svg,video,canvas,iframe,object') &&
|
|
118
|
+
!visual(css))
|
|
119
|
+
continue;
|
|
120
|
+
const r = radiusOf(css, rect.width, rect.height);
|
|
121
|
+
const box = relative(rect, origin, r);
|
|
122
|
+
atoms.push({
|
|
123
|
+
kind: round(box) ? 'round' : 'box',
|
|
124
|
+
box,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return atoms;
|
|
129
|
+
}
|
|
130
|
+
/** Destination marks for an atom, laid out at the part's pitch. */
|
|
131
|
+
function layout(atom, part) {
|
|
132
|
+
const { box } = atom, pitch = part.pitch, r = part.radius;
|
|
133
|
+
const points = [];
|
|
134
|
+
const across = (width, rows, top) => {
|
|
135
|
+
const count = Math.max(1, Math.floor((width - 2 * r) / pitch) + 1);
|
|
136
|
+
const step = count > 1 ? (width - 2 * r) / (count - 1) : 0;
|
|
137
|
+
for (let j = 0; j < rows; j++)
|
|
138
|
+
for (let i = 0; i < count; i++)
|
|
139
|
+
points.push({
|
|
140
|
+
x: box.x + r + (count > 1 ? i * step : (width - 2 * r) / 2),
|
|
141
|
+
y: top + j * pitch,
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
if (atom.kind === 'run') {
|
|
145
|
+
// A text line: as many rows of marks as cover its letters (two for body
|
|
146
|
+
// text, more for large figures), centred on the line.
|
|
147
|
+
const rows = Math.max(1, Math.min(5, Math.round(box.h / pitch)));
|
|
148
|
+
across(box.w, rows, box.y + box.h / 2 - ((rows - 1) * pitch) / 2);
|
|
149
|
+
return points;
|
|
150
|
+
}
|
|
151
|
+
const rows = Math.max(1, Math.floor((box.h - 2 * r) / pitch) + 1);
|
|
152
|
+
const step = rows > 1 ? (box.h - 2 * r) / (rows - 1) : 0;
|
|
153
|
+
const count = Math.max(1, Math.floor((box.w - 2 * r) / pitch) + 1);
|
|
154
|
+
const stepX = count > 1 ? (box.w - 2 * r) / (count - 1) : 0;
|
|
155
|
+
for (let j = 0; j < rows; j++)
|
|
156
|
+
for (let i = 0; i < count; i++) {
|
|
157
|
+
const x = box.x + r + i * stepX, y = box.y + r + j * step;
|
|
158
|
+
if (inside(box, x, y, r * 0.15))
|
|
159
|
+
points.push({ x, y });
|
|
160
|
+
}
|
|
161
|
+
return points;
|
|
162
|
+
}
|
|
163
|
+
const distance = (a, b) => {
|
|
164
|
+
const [ax0, ay0] = centre(a), [bx0, by0] = centre(b);
|
|
165
|
+
return Math.hypot(ax0 - bx0, ay0 - by0);
|
|
166
|
+
};
|
|
167
|
+
/** Pairs each item of `from` with at most one of `to`, cheapest first. */
|
|
168
|
+
function pair(from, to, cost) {
|
|
169
|
+
const options = from.flatMap((a) => to.map((b) => ({ a, b, c: cost(a, b) })));
|
|
170
|
+
options.sort((x, y) => x.c - y.c);
|
|
171
|
+
const pairs = new Map(), taken = new Set();
|
|
172
|
+
for (const { a, b, c } of options)
|
|
173
|
+
if (Number.isFinite(c) && !pairs.has(a) && !taken.has(b)) {
|
|
174
|
+
pairs.set(a, b);
|
|
175
|
+
taken.add(b);
|
|
176
|
+
}
|
|
177
|
+
return pairs;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A placeholder's marks: chart and table hand over what they painted;
|
|
181
|
+
* skeletons and TypingDots are read from where their CSS draws them.
|
|
182
|
+
*/
|
|
183
|
+
function partsOf(participant, origin) {
|
|
184
|
+
if (morphMarks in participant)
|
|
185
|
+
return participant[morphMarks](origin);
|
|
186
|
+
if (participant.localName === 'dotquilt-typing-dots')
|
|
187
|
+
return typingPart(participant, origin);
|
|
188
|
+
if (participant.localName.startsWith('dotquilt-skeleton-'))
|
|
189
|
+
return skeletonParts(participant, origin);
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
/** Reads the placeholder and the content and decides where every mark goes. */
|
|
193
|
+
export function planMorph(region, participants) {
|
|
194
|
+
const origin = region.getBoundingClientRect();
|
|
195
|
+
const parts = participants.flatMap((participant) => partsOf(participant, origin));
|
|
196
|
+
const nodes = contentNodes(region);
|
|
197
|
+
const area = Math.max(1, origin.width * origin.height);
|
|
198
|
+
const runs = textRuns(nodes, origin);
|
|
199
|
+
const boxes = contentBoxes(nodes, origin, area);
|
|
200
|
+
// Blocks and circles become the content's boxes: a circle prefers a round
|
|
201
|
+
// one, and a box much bigger or smaller than the block is not its match.
|
|
202
|
+
const shapes = parts.filter((part) => part.kind !== 'row');
|
|
203
|
+
const shapePairs = pair(shapes, boxes, (part, atom) => {
|
|
204
|
+
const ratio = (atom.box.w * atom.box.h) / (part.box.w * part.box.h);
|
|
205
|
+
if (ratio < 0.12 || ratio > 8)
|
|
206
|
+
return Number.POSITIVE_INFINITY;
|
|
207
|
+
const mismatch = (part.kind === 'round') !== (atom.kind === 'round');
|
|
208
|
+
return (distance(part.box, atom.box) +
|
|
209
|
+
Math.abs(Math.log(ratio)) * 40 +
|
|
210
|
+
(mismatch ? 120 : 0));
|
|
211
|
+
});
|
|
212
|
+
const covered = [...shapePairs.values()].map((atom) => atom.box);
|
|
213
|
+
const free = runs
|
|
214
|
+
.filter((run) => !covered.some((box) => inside(box, ...centre(run), 0) && box !== run))
|
|
215
|
+
.map((box) => ({ kind: 'run', box }));
|
|
216
|
+
// Lines become text lines: the nearest in height first, then along the line.
|
|
217
|
+
// The two blocks are aligned first, so a placeholder that sits lower or
|
|
218
|
+
// further in than its content still pairs its lines in reading order.
|
|
219
|
+
const rows = parts.filter((part) => part.kind === 'row');
|
|
220
|
+
const edge = (boxes, key) => boxes.length ? Math.min(...boxes.map((box) => box[key])) : 0;
|
|
221
|
+
const lines = free.map((atom) => atom.box), marks = rows.map((part) => part.box);
|
|
222
|
+
const dx = edge(lines, 'x') - edge(marks, 'x'), dy = edge(lines, 'y') - edge(marks, 'y');
|
|
223
|
+
const rowPairs = pair(rows, free, (part, atom) => {
|
|
224
|
+
const [, py] = centre(part.box), [, ay0] = centre(atom.box);
|
|
225
|
+
return (Math.abs(py + dy - ay0) + 0.4 * Math.abs(part.box.x + dx - atom.box.x));
|
|
226
|
+
});
|
|
227
|
+
// Every destination gets a source part: its pair, or the nearest part.
|
|
228
|
+
const jobs = [];
|
|
229
|
+
for (const [part, atom] of shapePairs)
|
|
230
|
+
jobs.push({ part, atom });
|
|
231
|
+
for (const [part, atom] of rowPairs)
|
|
232
|
+
jobs.push({ part, atom });
|
|
233
|
+
const paired = new Set([...rowPairs.values()]);
|
|
234
|
+
const sources = parts.filter((part) => part.kind === 'row' || !shapePairs.has(part));
|
|
235
|
+
for (const atom of free) {
|
|
236
|
+
if (paired.has(atom) || !parts.length)
|
|
237
|
+
continue;
|
|
238
|
+
const nearest = (sources.length ? sources : parts).reduce((best, part) => distance(part.box, atom.box) < distance(best.box, atom.box) ? part : best);
|
|
239
|
+
jobs.push({ part: nearest, atom });
|
|
240
|
+
}
|
|
241
|
+
const width = origin.width, height = origin.height;
|
|
242
|
+
// Right-to-left text reads, and so wipes, from the right edge.
|
|
243
|
+
const rtl = region.ownerDocument.defaultView?.getComputedStyle(region).direction ===
|
|
244
|
+
'rtl';
|
|
245
|
+
const along = (x, y) => front(rtl ? width - x : x, y);
|
|
246
|
+
const span = Math.max(1, front(width, height));
|
|
247
|
+
const used = new Set();
|
|
248
|
+
const travels = [];
|
|
249
|
+
const nearestSeed = (part, x, y) => {
|
|
250
|
+
let best = part.seeds[0], d = Number.POSITIVE_INFINITY;
|
|
251
|
+
for (const seed of part.seeds) {
|
|
252
|
+
const e = (seed.x - x) ** 2 + (seed.y - y) ** 2;
|
|
253
|
+
if (e < d) {
|
|
254
|
+
d = e;
|
|
255
|
+
best = seed;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return best;
|
|
259
|
+
};
|
|
260
|
+
const destinations = new Map();
|
|
261
|
+
for (const { part, atom } of jobs) {
|
|
262
|
+
const points = layout(atom, part);
|
|
263
|
+
destinations.set(part, [...(destinations.get(part) ?? []), ...points]);
|
|
264
|
+
for (const point of points) {
|
|
265
|
+
// The source mark at the same place, relative to each shape.
|
|
266
|
+
const u = (point.x - atom.box.x) / Math.max(1, atom.box.w), v = (point.y - atom.box.y) / Math.max(1, atom.box.h);
|
|
267
|
+
const seed = nearestSeed(part, part.box.x + u * part.box.w, part.box.y + v * part.box.h);
|
|
268
|
+
travels.push({
|
|
269
|
+
from: seed,
|
|
270
|
+
x: point.x,
|
|
271
|
+
y: point.y,
|
|
272
|
+
r: part.radius,
|
|
273
|
+
born: used.has(seed),
|
|
274
|
+
dies: false,
|
|
275
|
+
order: clamp(along(point.x, point.y) / span),
|
|
276
|
+
});
|
|
277
|
+
used.add(seed);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// Marks nobody needs fold into the nearest destination and fade: their own
|
|
281
|
+
// part's, or for a spare line any line's, so the whole skeleton becomes the
|
|
282
|
+
// content. A spare block or circle stays put until the front passes.
|
|
283
|
+
const everywhere = [...destinations.values()].flat();
|
|
284
|
+
for (const part of parts) {
|
|
285
|
+
const points = destinations.get(part) ?? (part.kind === 'row' ? everywhere : undefined);
|
|
286
|
+
for (const seed of part.seeds) {
|
|
287
|
+
if (used.has(seed))
|
|
288
|
+
continue;
|
|
289
|
+
let to;
|
|
290
|
+
let d = Number.POSITIVE_INFINITY;
|
|
291
|
+
for (const point of points ?? []) {
|
|
292
|
+
const e = (point.x - seed.x) ** 2 + (point.y - seed.y) ** 2;
|
|
293
|
+
if (e < d) {
|
|
294
|
+
d = e;
|
|
295
|
+
to = point;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
travels.push({
|
|
299
|
+
from: seed,
|
|
300
|
+
x: to?.x ?? seed.x,
|
|
301
|
+
y: to?.y ?? seed.y,
|
|
302
|
+
r: to ? part.radius : seed.r,
|
|
303
|
+
born: false,
|
|
304
|
+
dies: !!to,
|
|
305
|
+
holds: !to,
|
|
306
|
+
order: clamp(along(seed.x, seed.y) / span),
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// A card or bubble around the placeholder grows into the content's own:
|
|
311
|
+
// the first element, down a chain of only children, that you can see.
|
|
312
|
+
let shell;
|
|
313
|
+
const win = region.ownerDocument.defaultView;
|
|
314
|
+
const shellOf = (element) => {
|
|
315
|
+
for (let depth = 0; element && win && depth < 4; depth++) {
|
|
316
|
+
if (element.localName.startsWith('dotquilt-'))
|
|
317
|
+
return undefined;
|
|
318
|
+
if (visual(win.getComputedStyle(element)))
|
|
319
|
+
return element;
|
|
320
|
+
element = element.children.length === 1 ? element.children[0] : undefined;
|
|
321
|
+
}
|
|
322
|
+
return undefined;
|
|
323
|
+
};
|
|
324
|
+
const elements = nodes.filter((node) => node instanceof Element || (node instanceof Text && /\S/.test(node.data)));
|
|
325
|
+
const own = shellOf(region.querySelector(':scope > [slot=placeholder]') ?? undefined);
|
|
326
|
+
const theirs = shellOf(elements.length === 1 && elements[0] instanceof Element
|
|
327
|
+
? elements[0]
|
|
328
|
+
: undefined);
|
|
329
|
+
if (own && theirs) {
|
|
330
|
+
const from = relative(own.getBoundingClientRect(), origin), to = relative(theirs.getBoundingClientRect(), origin);
|
|
331
|
+
if (Math.abs(from.w - to.w) +
|
|
332
|
+
Math.abs(from.h - to.h) +
|
|
333
|
+
Math.abs(from.x - to.x) +
|
|
334
|
+
Math.abs(from.y - to.y) >
|
|
335
|
+
1)
|
|
336
|
+
shell = { element: own, from, to };
|
|
337
|
+
}
|
|
338
|
+
return { travels, width, height, rtl, shell };
|
|
339
|
+
}
|
|
340
|
+
/** Draws the plan's marks on one overlay, a CSP-safe SVG in the region. */
|
|
341
|
+
function overlay(region, travels) {
|
|
342
|
+
const doc = region.ownerDocument;
|
|
343
|
+
const svg = doc.createElementNS(svgns, 'svg');
|
|
344
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
345
|
+
svg.setAttribute('width', '100%');
|
|
346
|
+
svg.setAttribute('height', '100%');
|
|
347
|
+
svg.setAttribute('overflow', 'visible');
|
|
348
|
+
svg.setAttribute('data-dotquilt-morph', '');
|
|
349
|
+
const entries = travels.map((travel) => {
|
|
350
|
+
const entry = doc.createElementNS(svgns, travel.from.mark === 'dot' ? 'circle' : 'rect');
|
|
351
|
+
svg.append(entry);
|
|
352
|
+
return entry;
|
|
353
|
+
});
|
|
354
|
+
region.shadowRoot?.append(svg);
|
|
355
|
+
return {
|
|
356
|
+
place(index, x, y, r, opacity, accent) {
|
|
357
|
+
const entry = entries[index], travel = travels[index];
|
|
358
|
+
if (!entry || !travel)
|
|
359
|
+
return;
|
|
360
|
+
const mark = travel.from.mark;
|
|
361
|
+
const fill = accent ? travel.from.accent : travel.from.fill;
|
|
362
|
+
const key = `${x.toFixed(2)} ${y.toFixed(2)} ${r.toFixed(2)} ${opacity.toFixed(3)} ${fill}`;
|
|
363
|
+
if (entry.k === key)
|
|
364
|
+
return;
|
|
365
|
+
entry.k = key;
|
|
366
|
+
if (mark === 'dot') {
|
|
367
|
+
entry.setAttribute('cx', x.toFixed(2));
|
|
368
|
+
entry.setAttribute('cy', y.toFixed(2));
|
|
369
|
+
entry.setAttribute('r', r.toFixed(2));
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
const box = markBox(mark, r);
|
|
373
|
+
entry.setAttribute('x', (x - box.width / 2).toFixed(2));
|
|
374
|
+
entry.setAttribute('y', (y - box.height / 2).toFixed(2));
|
|
375
|
+
entry.setAttribute('width', box.width.toFixed(2));
|
|
376
|
+
entry.setAttribute('height', box.height.toFixed(2));
|
|
377
|
+
entry.setAttribute('rx', box.radius.toFixed(2));
|
|
378
|
+
}
|
|
379
|
+
entry.setAttribute('opacity', opacity.toFixed(3));
|
|
380
|
+
entry.setAttribute('fill', fill);
|
|
381
|
+
},
|
|
382
|
+
dispose() {
|
|
383
|
+
svg.remove();
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* The default region handoff for skeleton and typing placeholders, and for
|
|
389
|
+
* any placeholder without an animation of its own. Paints both layers itself.
|
|
390
|
+
*/
|
|
391
|
+
export function createMorph(region, participants, placeholder, request, duration) {
|
|
392
|
+
const plan = planMorph(region, participants);
|
|
393
|
+
const doc = region.ownerDocument;
|
|
394
|
+
const budget = lease(doc, request.report);
|
|
395
|
+
if (!budget.set('dots', plan.travels.length)) {
|
|
396
|
+
budget.close();
|
|
397
|
+
throw new RangeError('dot-limit');
|
|
398
|
+
}
|
|
399
|
+
const { content, own, current } = request;
|
|
400
|
+
const paint = overlay(region, plan.travels);
|
|
401
|
+
// The masks ride on the controller's own clock animations for the two
|
|
402
|
+
// layers (attach), so each layer has exactly one animation.
|
|
403
|
+
let layers;
|
|
404
|
+
const masked = (layer) => {
|
|
405
|
+
let previous = '';
|
|
406
|
+
return (mask) => {
|
|
407
|
+
const animation = layers?.[layer];
|
|
408
|
+
if (!animation || mask === previous)
|
|
409
|
+
return;
|
|
410
|
+
previous = mask;
|
|
411
|
+
animation.effect?.setKeyframes({
|
|
412
|
+
opacity: [1, 1],
|
|
413
|
+
maskImage: [mask, mask],
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
};
|
|
417
|
+
const reveal = masked('incoming'), conceal = masked('outgoing');
|
|
418
|
+
const shell = plan.shell && createEffect(plan.shell.element, own);
|
|
419
|
+
const origin = region.getBoundingClientRect();
|
|
420
|
+
const offset = (element) => {
|
|
421
|
+
const box = element.getBoundingClientRect();
|
|
422
|
+
return plan.rtl
|
|
423
|
+
? front(origin.right - box.right, box.top - origin.top)
|
|
424
|
+
: front(box.left - origin.left, box.top - origin.top);
|
|
425
|
+
};
|
|
426
|
+
const contentOffset = offset(content), placeholderOffset = offset(placeholder);
|
|
427
|
+
const span = front(plan.width, plan.height);
|
|
428
|
+
const { travel, stagger, wipeStart, edge, arrive } = morphTiming;
|
|
429
|
+
let release;
|
|
430
|
+
let hidden = false;
|
|
431
|
+
const draw = (p) => {
|
|
432
|
+
if (!current())
|
|
433
|
+
return;
|
|
434
|
+
// The placeholder's own marks hide while the overlay draws them. Created
|
|
435
|
+
// on the first frame, once the controller owns this handoff's animations.
|
|
436
|
+
if (!hidden) {
|
|
437
|
+
hidden = true;
|
|
438
|
+
for (const participant of participants)
|
|
439
|
+
own(participant.animate({ visibility: ['hidden', 'hidden'] }, { duration, fill: 'both' }));
|
|
440
|
+
}
|
|
441
|
+
const at = -edge + (span + 2 * edge) * sine((p - wipeStart) / (1 - wipeStart));
|
|
442
|
+
const wipe = (from, to, shift) => `linear-gradient(${plan.rtl ? 256 : 104}deg,${from} ${(at - edge - shift).toFixed(1)}px,${to} ${(at - shift).toFixed(1)}px)`;
|
|
443
|
+
reveal(wipe('#000', '#0000', contentOffset));
|
|
444
|
+
conceal(wipe('#0000', '#000', placeholderOffset));
|
|
445
|
+
if (shell && plan.shell) {
|
|
446
|
+
const q = settle(p / (wipeStart + 0.1));
|
|
447
|
+
const { from, to } = plan.shell;
|
|
448
|
+
shell({
|
|
449
|
+
width: `${mix(from.w, to.w, q).toFixed(1)}px`,
|
|
450
|
+
height: `${mix(from.h, to.h, q).toFixed(1)}px`,
|
|
451
|
+
translate: `${(mix(from.x, to.x, q) - from.x).toFixed(1)}px ${(mix(from.y, to.y, q) - from.y).toFixed(1)}px`,
|
|
452
|
+
boxSizing: 'border-box',
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
plan.travels.forEach((item, index) => {
|
|
456
|
+
const q = sine((p - stagger * item.order) / travel);
|
|
457
|
+
const x = mix(item.from.x, item.x, q), y = mix(item.from.y, item.y, q);
|
|
458
|
+
const start = item.born ? 0 : item.from.o;
|
|
459
|
+
const opacity = item.holds
|
|
460
|
+
? start
|
|
461
|
+
: item.dies
|
|
462
|
+
? mix(start, 0, clamp(q * 1.4))
|
|
463
|
+
: mix(start, arrive, q);
|
|
464
|
+
// Ahead of the front a mark stays; inside the soft edge it gives way.
|
|
465
|
+
const stay = clamp((front(plan.rtl ? plan.width - x : x, y) - at + edge) / edge);
|
|
466
|
+
paint.place(index, x, y, mix(item.from.r, item.r, q), opacity * stay,
|
|
467
|
+
// Lit while travelling, as if the idle glow carried it; ink on arrival.
|
|
468
|
+
!item.holds && q > 0.08 && q < 0.82);
|
|
469
|
+
});
|
|
470
|
+
};
|
|
471
|
+
return {
|
|
472
|
+
duration,
|
|
473
|
+
paints: true,
|
|
474
|
+
draw,
|
|
475
|
+
attach(outgoing, incoming) {
|
|
476
|
+
layers = { outgoing, incoming };
|
|
477
|
+
},
|
|
478
|
+
activate(callback) {
|
|
479
|
+
release ??= frames(region, callback);
|
|
480
|
+
},
|
|
481
|
+
dispose() {
|
|
482
|
+
release?.();
|
|
483
|
+
release = undefined;
|
|
484
|
+
paint.dispose();
|
|
485
|
+
budget.close();
|
|
486
|
+
},
|
|
487
|
+
};
|
|
488
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AnimationFamily, AnimationSurface, Dot, RevealFrame } from '../animations.js';
|
|
2
|
+
/** One idle frame: draw the placeholder's dots at `timeMs`. */
|
|
3
|
+
export interface IdleFrame<F extends AnimationFamily = AnimationFamily, O extends object = object> {
|
|
4
|
+
readonly surface: AnimationSurface<F>;
|
|
5
|
+
readonly options: Readonly<O>;
|
|
6
|
+
/** Speed-scaled time since the idle motion started. */
|
|
7
|
+
readonly timeMs: number;
|
|
8
|
+
readonly deltaMs: number;
|
|
9
|
+
/** Draw a still frame (motion paused, reduced or restricted). */
|
|
10
|
+
readonly still: boolean;
|
|
11
|
+
readonly dot: (value: Dot) => void;
|
|
12
|
+
}
|
|
13
|
+
export type IdlePaint = (frame: IdleFrame) => void;
|
|
14
|
+
/** One handoff frame: draw outgoing dots and reveal the content. */
|
|
15
|
+
export interface HandoffFrame<F extends AnimationFamily = AnimationFamily, O extends object = object, P = unknown> {
|
|
16
|
+
readonly surface: AnimationSurface<F>;
|
|
17
|
+
readonly options: Readonly<O>;
|
|
18
|
+
/** What the definition's `prepare` returned for this handoff. */
|
|
19
|
+
readonly prepared: P;
|
|
20
|
+
readonly linear: number;
|
|
21
|
+
/** `linear` after the handoff's easing. */
|
|
22
|
+
readonly progress: number;
|
|
23
|
+
readonly duration: number;
|
|
24
|
+
readonly deltaMs: number;
|
|
25
|
+
readonly dot: (value: Dot) => void;
|
|
26
|
+
readonly reveal: (frame: RevealFrame) => void;
|
|
27
|
+
readonly revealTarget: (id: string, frame: RevealFrame) => void;
|
|
28
|
+
}
|
|
29
|
+
export type HandoffPaint = (frame: HandoffFrame) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Dot } from '../animations.js';
|
|
2
|
+
export interface Painter {
|
|
3
|
+
draw(callback: (dot: (value: Dot) => void) => void): void;
|
|
4
|
+
dispose(): void;
|
|
5
|
+
capture?(limit?: number): readonly Dot[];
|
|
6
|
+
readonly points?: readonly PaintEntry[];
|
|
7
|
+
}
|
|
8
|
+
export type PaintEntry = Partial<Record<0 | 1 | 2 | 3 | 5, number>> & {
|
|
9
|
+
4?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const pointer: unique symbol;
|
|
12
|
+
/**
|
|
13
|
+
* The pointer lift (design/SPEC.md): marks within 56 px of the pointer light
|
|
14
|
+
* up in the accent, strongest at the pointer, like the skeleton's lift layer.
|
|
15
|
+
* Returns the accent's opacity at offset (dx, dy).
|
|
16
|
+
*/
|
|
17
|
+
export declare function liftAt(dx: number, dy: number): number;
|
|
18
|
+
export declare function createPainter(host: HTMLElement, report: (code: string) => void, part?: string,
|
|
19
|
+
/** Draws glyph marks (TextLoader), fitted to their matrix. */
|
|
20
|
+
glyphs?: boolean): Painter;
|