@whzxc/agent-design-gallery 0.14.1 → 0.16.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/README.md +29 -16
- package/package.json +2 -1
- package/public/access.css +15 -2
- package/public/app.js +1284 -521
- package/public/arrangement-worker.js +7 -7
- package/public/arrangement.js +35 -30
- package/public/assets.js +85 -48
- package/public/auth.js +59 -4
- package/public/boards.js +129 -0
- package/public/comment-anchors.js +50 -0
- package/public/comments.css +400 -0
- package/public/comments.js +1106 -0
- package/public/context-menu.js +97 -0
- package/public/frame-identity.js +51 -14
- package/public/hub.css +25 -3
- package/public/hub.html +10 -2
- package/public/hub.js +127 -23
- package/public/icons.js +9 -0
- package/public/index.html +26 -10
- package/public/instance-actions.js +9 -2
- package/public/layout.js +156 -86
- package/public/motion-flow.js +28 -0
- package/public/motion-identity.js +100 -0
- package/public/motion-paint.js +332 -0
- package/public/motion-scene.js +165 -0
- package/public/motion-specimens.js +335 -0
- package/public/player.css +270 -0
- package/public/player.js +753 -0
- package/public/recent-updates.js +535 -0
- package/public/selection.js +1 -1
- package/public/style.css +91 -154
- package/public/switcher.css +5 -4
- package/public/switcher.js +109 -34
- package/public/token-catalog.js +8 -3
- package/public/tokens.css +20 -1
- package/public/view-boards.css +131 -0
- package/public/view-boards.js +350 -0
- package/public/view-route.js +1 -2
- package/src/boards/board.mjs +30 -0
- package/src/boards/motion-board.mjs +202 -0
- package/src/boards/token-board.mjs +200 -0
- package/src/cli-output.mjs +10 -5
- package/src/cli.mjs +89 -35
- package/src/comments.mjs +293 -0
- package/src/http.mjs +7 -5
- package/src/hub/project-link.mjs +41 -0
- package/src/hub/registry.mjs +5 -0
- package/src/hub.mjs +14 -10
- package/src/link.mjs +13 -1
- package/src/recent-frames.mjs +295 -0
- package/src/recent-history.mjs +100 -0
- package/src/recent-job.mjs +63 -0
- package/src/recent-worker.mjs +171 -0
- package/src/server.mjs +285 -110
- package/src/service.mjs +46 -12
- package/src/toolkit/arch-git.mjs +8 -14
- package/src/toolkit/arch.mjs +3 -2
- package/src/toolkit/asset-rules.mjs +24 -1
- package/src/toolkit/browser.mjs +1 -13
- package/src/toolkit/build-store.mjs +9 -1
- package/src/toolkit/build-worker.mjs +6 -0
- package/src/toolkit/build.mjs +22 -16
- package/src/toolkit/commands.mjs +105 -9
- package/src/toolkit/compare.mjs +13 -11
- package/src/toolkit/config.mjs +2 -2
- package/{public/review.js → src/toolkit/diff-document.mjs} +137 -43
- package/src/toolkit/diff-inputs.mjs +97 -52
- package/src/toolkit/diff.mjs +198 -43
- package/src/toolkit/frame-declarations.mjs +36 -0
- package/src/toolkit/git-blobs.mjs +50 -0
- package/src/toolkit/impact-inputs.mjs +11 -19
- package/src/toolkit/impact-selection.mjs +27 -12
- package/src/toolkit/impact.mjs +49 -15
- package/src/toolkit/implementation-map.mjs +17 -6
- package/src/toolkit/input-generation.mjs +15 -0
- package/src/toolkit/inspect-output.mjs +1 -1
- package/src/toolkit/inspect.d.ts +9 -1
- package/src/toolkit/inspect.mjs +25 -1
- package/src/toolkit/motion-check.mjs +382 -0
- package/src/toolkit/motion-css.mjs +105 -0
- package/src/toolkit/motion-flows.mjs +95 -0
- package/src/toolkit/motion-impact.mjs +87 -0
- package/src/toolkit/motion-inventory.mjs +202 -0
- package/src/toolkit/motion-label.mjs +111 -0
- package/src/toolkit/motion-patterns.mjs +216 -0
- package/src/toolkit/motion-primitives.mjs +94 -0
- package/src/toolkit/motion-queries.mjs +169 -0
- package/src/toolkit/motion.mjs +300 -0
- package/src/toolkit/move-pairing.mjs +140 -0
- package/src/toolkit/owner.mjs +19 -6
- package/src/toolkit/play-endpoint.mjs +66 -0
- package/src/toolkit/project-index.mjs +4 -4
- package/src/toolkit/recent-structure.mjs +201 -0
- package/src/toolkit/results.mjs +3 -3
- package/src/toolkit/review-document.mjs +440 -0
- package/src/toolkit/review-embed-document.mjs +671 -0
- package/src/toolkit/review-filmstrip.mjs +76 -0
- package/src/toolkit/review-groups.mjs +29 -0
- package/src/toolkit/review-motion-card.mjs +51 -0
- package/src/toolkit/review-motion.mjs +159 -0
- package/src/toolkit/review-observation.mjs +131 -0
- package/src/toolkit/review-playback.js +123 -0
- package/src/toolkit/review-sheet.mjs +125 -0
- package/src/toolkit/review-specimens.mjs +60 -0
- package/src/toolkit/review.mjs +240 -0
- package/src/toolkit/runtime.mjs +8 -2
- package/src/toolkit/theme.mjs +16 -0
- package/src/viewer-cache.mjs +48 -12
- package/public/annotations.js +0 -816
- package/public/labels.js +0 -122
- package/src/annotations.mjs +0 -238
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { matchRoots, candidates } from './motion-identity.js';
|
|
2
|
+
|
|
3
|
+
const properties = ['x', 'y', 'width', 'height', 'opacity'];
|
|
4
|
+
const blend = (a, b, t) => a + (b - a) * t;
|
|
5
|
+
function unique(rows, target) {
|
|
6
|
+
const found = candidates(rows, target);
|
|
7
|
+
if (found.length !== 1) throw Error('Unresolved playback target ' + JSON.stringify(target));
|
|
8
|
+
return found[0];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Each paint root has its own frame-coordinate layer. Nested roots are cut out of
|
|
12
|
+
// the parent copy, so their composed world transform is applied exactly once.
|
|
13
|
+
export function preparePaint(stage, from, to, edge, pin) {
|
|
14
|
+
const doc = stage.ownerDocument,
|
|
15
|
+
tracks = [],
|
|
16
|
+
boundaries = [],
|
|
17
|
+
clocks = new Map(),
|
|
18
|
+
oldClaim = new Set(),
|
|
19
|
+
newClaim = new Set();
|
|
20
|
+
const layer = doc.createElement('div');
|
|
21
|
+
layer.inert = true;
|
|
22
|
+
layer.setAttribute('aria-hidden', 'true');
|
|
23
|
+
Object.assign(layer.style, { position: 'fixed', inset: '0', pointerEvents: 'none', overflow: 'hidden' });
|
|
24
|
+
const sheet = layer.attachShadow({ mode: 'open' });
|
|
25
|
+
const defaultTime = { start: 0, duration: edge.timings['/duration'], easing: edge.timings['/easing'] };
|
|
26
|
+
let start = 0,
|
|
27
|
+
total = 0;
|
|
28
|
+
function add(left, right, mode, props, time, fromOpacity) {
|
|
29
|
+
let track = mode === 'match' && tracks.find((t) => t.mode === 'match' && t.left === left && t.right === right);
|
|
30
|
+
if (!track) {
|
|
31
|
+
track = { left, right, mode, props: {}, fromOpacity };
|
|
32
|
+
tracks.push(track);
|
|
33
|
+
}
|
|
34
|
+
for (const prop of props) track.props[prop] = time;
|
|
35
|
+
if (left) oldClaim.add(left.i);
|
|
36
|
+
if (right) newClaim.add(right.i);
|
|
37
|
+
}
|
|
38
|
+
const covered = (rows, claimed) =>
|
|
39
|
+
new Set(
|
|
40
|
+
rows
|
|
41
|
+
.filter((row) => {
|
|
42
|
+
for (let r = row; r; r = rows[r.parent]) if (claimed.has(r.i)) return true;
|
|
43
|
+
return false;
|
|
44
|
+
})
|
|
45
|
+
.map((r) => r.i)
|
|
46
|
+
);
|
|
47
|
+
const subtrees = { from: new Set(), to: new Set() };
|
|
48
|
+
edge.phases.forEach((phase, i) => {
|
|
49
|
+
let length = 0;
|
|
50
|
+
phase.forEach((t, j) => {
|
|
51
|
+
const path = '/phases/' + i + '/' + j,
|
|
52
|
+
time = {
|
|
53
|
+
start,
|
|
54
|
+
duration: edge.timings[path + '/duration'] ?? defaultTime.duration,
|
|
55
|
+
easing: edge.timings[path + '/easing'] ?? defaultTime.easing
|
|
56
|
+
};
|
|
57
|
+
length = Math.max(length, time.duration);
|
|
58
|
+
for (const target of t.targets) {
|
|
59
|
+
const left = t.mode === 'enter' && !candidates(from, target).length ? null : unique(from, target);
|
|
60
|
+
const right = t.mode === 'exit' ? null : unique(to, target);
|
|
61
|
+
add(left, right, t.mode, t.properties, time, t.fromOpacity);
|
|
62
|
+
if (t.mode !== 'match') {
|
|
63
|
+
if (left) subtrees.from.add(left.i);
|
|
64
|
+
if (right) subtrees.to.add(right.i);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
start += length;
|
|
69
|
+
boundaries.push(start);
|
|
70
|
+
});
|
|
71
|
+
total = start;
|
|
72
|
+
const excluded = { from: covered(from, subtrees.from), to: covered(to, subtrees.to) };
|
|
73
|
+
const { pairs, ambiguous } = matchRoots(from, to, excluded);
|
|
74
|
+
function implicit(left, right, mode) {
|
|
75
|
+
add(left, right, mode, properties, defaultTime);
|
|
76
|
+
if (
|
|
77
|
+
!left ||
|
|
78
|
+
!right ||
|
|
79
|
+
left.text !== right.text ||
|
|
80
|
+
left.opacity !== right.opacity ||
|
|
81
|
+
left.box.some((v, i) => v !== right.box[i])
|
|
82
|
+
)
|
|
83
|
+
total = Math.max(total, defaultTime.duration);
|
|
84
|
+
}
|
|
85
|
+
if (pin) {
|
|
86
|
+
const left = candidates(from, pin), right = candidates(to, pin);
|
|
87
|
+
if (left.length === 1 && right.length === 1 && !oldClaim.has(left[0].i) && !newClaim.has(right[0].i))
|
|
88
|
+
implicit(left[0], right[0], 'match');
|
|
89
|
+
}
|
|
90
|
+
for (const pair of pairs)
|
|
91
|
+
if (!oldClaim.has(pair.from) && !newClaim.has(pair.to)) implicit(from[pair.from], to[pair.to], 'match');
|
|
92
|
+
for (const [rows, claimed, skip, side] of [
|
|
93
|
+
[from, oldClaim, excluded.from, 'from'],
|
|
94
|
+
[to, newClaim, excluded.to, 'to']
|
|
95
|
+
]) {
|
|
96
|
+
for (const r of rows)
|
|
97
|
+
if (r.parts.length && !claimed.has(r.i) && !skip.has(r.i))
|
|
98
|
+
implicit(side === 'from' ? r : null, side === 'to' ? r : null, side === 'from' ? 'exit' : 'enter');
|
|
99
|
+
}
|
|
100
|
+
// Keep the unowned endpoint shell and its decorations in the composition.
|
|
101
|
+
if (!newClaim.has(0)) add(oldClaim.has(0) ? null : from[0], to[0], 'match', [], defaultTime);
|
|
102
|
+
const oldRoots = new Set(tracks.flatMap((t) => (t.left ? [t.left.i] : []))),
|
|
103
|
+
newRoots = new Set(tracks.flatMap((t) => (t.right ? [t.right.i] : [])));
|
|
104
|
+
function picture(rows, row, roots) {
|
|
105
|
+
const host = doc.createElement('div'),
|
|
106
|
+
shadow = host.attachShadow({ mode: 'open' }),
|
|
107
|
+
styles = [],
|
|
108
|
+
runs = new Map();
|
|
109
|
+
Object.assign(host.style, {
|
|
110
|
+
position: 'absolute',
|
|
111
|
+
left: '0',
|
|
112
|
+
top: '0',
|
|
113
|
+
width: row.box[2] + 'px',
|
|
114
|
+
height: row.box[3] + 'px',
|
|
115
|
+
transformOrigin: '0 0',
|
|
116
|
+
pointerEvents: 'none'
|
|
117
|
+
});
|
|
118
|
+
if (row.clip.some((x) => x > 0)) host.style.clipPath = 'inset(' + row.clip.map((x) => x + 'px').join(' ') + ')';
|
|
119
|
+
function copy(r, path) {
|
|
120
|
+
const node = r.paint.cloneNode(false);
|
|
121
|
+
if (r.pseudos.length) {
|
|
122
|
+
node.dataset.paintNode = r.i;
|
|
123
|
+
for (const { pseudo, css } of r.pseudos)
|
|
124
|
+
styles.push('[data-paint-node="' + r.i + '"]::' + pseudo + '{' + css + '}');
|
|
125
|
+
}
|
|
126
|
+
for (const [index, child] of r.children.entries()) {
|
|
127
|
+
const key = path + '.' + index;
|
|
128
|
+
if (typeof child === 'string') {
|
|
129
|
+
const text = doc.createTextNode(child);
|
|
130
|
+
node.append(text);
|
|
131
|
+
const run = r.runs.find((v) => v.index === index);
|
|
132
|
+
if (run) runs.set(key, { ...run, textNode: text, style: r.paint.style });
|
|
133
|
+
} else if (!roots.has(child)) node.append(copy(rows[child], key));
|
|
134
|
+
else {
|
|
135
|
+
const spacer = rows[child].paint.cloneNode(false);
|
|
136
|
+
spacer.style.visibility = 'hidden';
|
|
137
|
+
node.append(spacer);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return node;
|
|
141
|
+
}
|
|
142
|
+
const content = copy(row, '');
|
|
143
|
+
Object.assign(content.style, {
|
|
144
|
+
position: 'absolute',
|
|
145
|
+
margin: '0',
|
|
146
|
+
inset: 'auto',
|
|
147
|
+
left: '0',
|
|
148
|
+
top: '0',
|
|
149
|
+
opacity: '1',
|
|
150
|
+
transformOrigin: '0 0'
|
|
151
|
+
});
|
|
152
|
+
// Transform the local paint inside the measured world-space rectangle.
|
|
153
|
+
const m = DOMMatrix.fromMatrix(row.matrix),
|
|
154
|
+
[w, h] = row.localSize;
|
|
155
|
+
const corners = [
|
|
156
|
+
[0, 0],
|
|
157
|
+
[w, 0],
|
|
158
|
+
[0, h],
|
|
159
|
+
[w, h]
|
|
160
|
+
].map(([x, y]) => m.transformPoint({ x, y }));
|
|
161
|
+
m.e -= Math.min(...corners.map((p) => p.x));
|
|
162
|
+
m.f -= Math.min(...corners.map((p) => p.y));
|
|
163
|
+
content.style.transform = m.toString();
|
|
164
|
+
shadow.append(content);
|
|
165
|
+
if (styles.length) {
|
|
166
|
+
const style = doc.createElement('style');
|
|
167
|
+
style.textContent = styles.join('');
|
|
168
|
+
shadow.append(style);
|
|
169
|
+
}
|
|
170
|
+
return { host, content, runs };
|
|
171
|
+
}
|
|
172
|
+
function glyph(run) {
|
|
173
|
+
if (!run) return;
|
|
174
|
+
const spacer = doc.createElement('span');
|
|
175
|
+
spacer.style.visibility = 'hidden';
|
|
176
|
+
run.textNode.replaceWith(spacer);
|
|
177
|
+
spacer.append(run.textNode);
|
|
178
|
+
const node = doc.createElement('span');
|
|
179
|
+
for (const prop of run.style)
|
|
180
|
+
if (/^(font|text|line-height|letter-spacing|word-|white-space|direction|writing-mode|color)/.test(prop))
|
|
181
|
+
node.style.setProperty(prop, run.style.getPropertyValue(prop));
|
|
182
|
+
Object.assign(node.style, {
|
|
183
|
+
position: 'absolute',
|
|
184
|
+
left: '0',
|
|
185
|
+
top: '0',
|
|
186
|
+
margin: '0',
|
|
187
|
+
pointerEvents: 'none',
|
|
188
|
+
width: run.box[2] + 0.5 + 'px',
|
|
189
|
+
lineHeight: run.style.lineHeight
|
|
190
|
+
});
|
|
191
|
+
node.textContent = run.text;
|
|
192
|
+
sheet.append(node);
|
|
193
|
+
return node;
|
|
194
|
+
}
|
|
195
|
+
// Underlays precede their children even when explicitly choreographed later.
|
|
196
|
+
tracks.sort((a, b) => (a.right?.i ?? a.left.i) - (b.right?.i ?? b.left.i));
|
|
197
|
+
const alpha = (rows, row) => {
|
|
198
|
+
let opacity = 1;
|
|
199
|
+
for (let p = row; p; p = rows[p.parent]) opacity *= p.opacity;
|
|
200
|
+
return opacity;
|
|
201
|
+
};
|
|
202
|
+
for (const t of tracks) {
|
|
203
|
+
const { left, right } = t;
|
|
204
|
+
if (left) {
|
|
205
|
+
t.old = picture(from, left, oldRoots);
|
|
206
|
+
t.oldAlpha = alpha(from, left);
|
|
207
|
+
}
|
|
208
|
+
if (right) {
|
|
209
|
+
t.next = picture(to, right, newRoots);
|
|
210
|
+
t.newAlpha = alpha(to, right);
|
|
211
|
+
}
|
|
212
|
+
t.flat =
|
|
213
|
+
left &&
|
|
214
|
+
right &&
|
|
215
|
+
(!left.box[2] || !left.box[3] || !right.box[2] || !right.box[3] || left.clipped || right.clipped);
|
|
216
|
+
if (t.old && (t.mode !== 'match' || t.flat || !t.next)) sheet.append(t.old.host);
|
|
217
|
+
if (t.next) sheet.append(t.next.host);
|
|
218
|
+
t.text = [];
|
|
219
|
+
if (t.mode === 'match' && t.old && t.next && !t.flat) {
|
|
220
|
+
for (const key of new Set([...t.old.runs.keys(), ...t.next.runs.keys()])) {
|
|
221
|
+
const a = t.old.runs.get(key),
|
|
222
|
+
b = t.next.runs.get(key);
|
|
223
|
+
const unchanged = a?.text === b?.text;
|
|
224
|
+
if (unchanged && left.box[2] === right.box[2] && left.box[3] === right.box[3]) continue;
|
|
225
|
+
t.text.push({ a, b, unchanged, old: unchanged ? null : glyph(a), next: glyph(b) });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const original = stage.style.opacity;
|
|
230
|
+
stage.style.opacity = '0';
|
|
231
|
+
doc.body.append(layer);
|
|
232
|
+
function progress(time, ms) {
|
|
233
|
+
if (!time) return 1;
|
|
234
|
+
if (ms < time.start) return 0;
|
|
235
|
+
if (!time.duration || ms >= time.start + time.duration) return 1;
|
|
236
|
+
let anim = clocks.get(time.easing);
|
|
237
|
+
if (!anim) {
|
|
238
|
+
anim = new doc.defaultView.Animation(
|
|
239
|
+
new doc.defaultView.KeyframeEffect(null, [], { duration: 1, easing: time.easing, fill: 'both' }),
|
|
240
|
+
doc.timeline
|
|
241
|
+
);
|
|
242
|
+
clocks.set(time.easing, anim);
|
|
243
|
+
}
|
|
244
|
+
anim.currentTime = (ms - time.start) / time.duration;
|
|
245
|
+
return anim.effect.getComputedTiming().progress;
|
|
246
|
+
}
|
|
247
|
+
function draw(picture, base, box, opacity) {
|
|
248
|
+
const node = picture?.host;
|
|
249
|
+
if (!node?.parentNode) return;
|
|
250
|
+
const sx = base[2] ? box[2] / base[2] : 1,
|
|
251
|
+
sy = base[3] ? box[3] / base[3] : 1;
|
|
252
|
+
node.style.transform = 'translate(' + box[0] + 'px,' + box[1] + 'px) scale(' + sx + ',' + sy + ')';
|
|
253
|
+
node.style.opacity = String(Math.min(1, Math.max(0, opacity)));
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
duration: total,
|
|
257
|
+
boundaries,
|
|
258
|
+
fallback: [
|
|
259
|
+
...(tracks.some(t => t.mode === 'match' && t.flat) ? ['Opacity fallback for clipped or degenerate geometry'] : []),
|
|
260
|
+
...(ambiguous.length ? [ambiguous.length + ' ambiguous match groups fade independently'] : [])
|
|
261
|
+
].join(' · ') || null,
|
|
262
|
+
seek(fraction) {
|
|
263
|
+
const ms = fraction * total;
|
|
264
|
+
stage.style.opacity = fraction === 1 ? original : '0';
|
|
265
|
+
layer.style.visibility = fraction === 1 ? 'hidden' : 'visible';
|
|
266
|
+
for (const t of tracks) {
|
|
267
|
+
const { left, right, mode } = t,
|
|
268
|
+
time = Object.values(t.props)[0] ?? defaultTime;
|
|
269
|
+
const p = progress(t.props.opacity ?? time, ms),
|
|
270
|
+
started = ms >= time.start;
|
|
271
|
+
if (mode === 'match' && left && right) {
|
|
272
|
+
if (t.flat) {
|
|
273
|
+
draw(t.old, left.box, left.box, t.oldAlpha * (1 - p));
|
|
274
|
+
draw(t.next, right.box, right.box, t.newAlpha * p);
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const box = right.box.map((v, i) =>
|
|
278
|
+
blend(left.box[i], v, t.props[properties[i]] ? progress(t.props[properties[i]], ms) : Number(started))
|
|
279
|
+
);
|
|
280
|
+
const opacity = blend(t.oldAlpha, t.newAlpha, t.props.opacity ? p : Number(started));
|
|
281
|
+
draw(t.next, right.box, box, opacity);
|
|
282
|
+
// Move only the changed glyph runs. Their shell, icon and border keep full paint.
|
|
283
|
+
for (const run of t.text) {
|
|
284
|
+
const pos = [0, 1].map((i) => {
|
|
285
|
+
const first = run.a ? run.a.box[i] - left.box[i] : run.b.box[i] - right.box[i];
|
|
286
|
+
const last = run.b ? run.b.box[i] - right.box[i] : first;
|
|
287
|
+
return box[i] + blend(first, last, p);
|
|
288
|
+
});
|
|
289
|
+
for (const [node, amount] of [
|
|
290
|
+
[run.old, 1 - p],
|
|
291
|
+
[run.next, run.unchanged ? 1 : p]
|
|
292
|
+
])
|
|
293
|
+
if (node) {
|
|
294
|
+
node.style.transform = 'translate(' + pos[0] + 'px,' + pos[1] + 'px)';
|
|
295
|
+
node.style.opacity = String(opacity * amount);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
if (left) draw(t.old, left.box, left.box, t.oldAlpha * (mode === 'enter' ? Number(!started) : 1 - p));
|
|
300
|
+
if (right) {
|
|
301
|
+
const first = (t.fromOpacity ?? 0) * (t.right.opacity ? t.newAlpha / t.right.opacity : 1);
|
|
302
|
+
draw(
|
|
303
|
+
t.next,
|
|
304
|
+
right.box,
|
|
305
|
+
right.box,
|
|
306
|
+
mode === 'match' ? t.newAlpha : started ? blend(first, t.newAlpha, p) : 0
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
dispose() {
|
|
313
|
+
stage.style.opacity = original;
|
|
314
|
+
layer.remove();
|
|
315
|
+
for (const a of clocks.values()) a.cancel();
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// A caller owns the clock. Painting always seeks the frozen pair by absolute progress.
|
|
321
|
+
export function playTimeline(duration, initial, speed, draw, finish) {
|
|
322
|
+
const origin = performance.now();
|
|
323
|
+
let raf;
|
|
324
|
+
function tick(now) {
|
|
325
|
+
const p = Math.min(1, initial + Math.max(0, now - origin) * speed / duration);
|
|
326
|
+
draw(p);
|
|
327
|
+
if (p === 1) finish();
|
|
328
|
+
else raf = requestAnimationFrame(tick);
|
|
329
|
+
}
|
|
330
|
+
raf = requestAnimationFrame(tick);
|
|
331
|
+
return () => cancelAnimationFrame(raf);
|
|
332
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
export const nativeTextEntry = 'textarea,input:is(:not([type]),[type="text" i],[type="search" i],[type="email" i],[type="tel" i],[type="url" i],[type="password" i])';
|
|
2
|
+
|
|
3
|
+
// Only the viewer writes to the document. Parse in an inert template before attachment.
|
|
4
|
+
export async function createStage(parent) {
|
|
5
|
+
const frame = document.createElement('iframe');
|
|
6
|
+
frame.title = 'Transition specimen';
|
|
7
|
+
frame.setAttribute('sandbox', 'allow-same-origin');
|
|
8
|
+
const loaded = new Promise((resolve) => frame.addEventListener('load', resolve, { once: true }));
|
|
9
|
+
frame.srcdoc = `<!doctype html><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src data:; base-uri 'none'; form-action 'none'; frame-src 'none'"><style></style><body></body>`;
|
|
10
|
+
parent.append(frame);
|
|
11
|
+
await loaded;
|
|
12
|
+
return frame;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function mountScene(doc, endpoint, theme, { parent = doc.body, offset } = {}) {
|
|
16
|
+
const template = doc.createElement('template');
|
|
17
|
+
template.innerHTML = endpoint.html;
|
|
18
|
+
const fragment = template.content;
|
|
19
|
+
for (const el of fragment.querySelectorAll(
|
|
20
|
+
'script,style,meta,base,link,iframe,frame,object,embed,portal,fencedframe,foreignObject,template,audio,video,animate,animateTransform,animateMotion,set'
|
|
21
|
+
))
|
|
22
|
+
el.remove();
|
|
23
|
+
for (const el of fragment.querySelectorAll('*')) {
|
|
24
|
+
el.removeAttribute('data-player-text-entry');
|
|
25
|
+
for (const attr of [...el.attributes]) {
|
|
26
|
+
const name = attr.name.toLowerCase();
|
|
27
|
+
if (name === 'contenteditable' && attr.value.toLowerCase() === 'false') continue;
|
|
28
|
+
if (name === 'contenteditable' && ['', 'true', 'plaintext-only'].includes(attr.value.toLowerCase()))
|
|
29
|
+
el.dataset.playerTextEntry = 'editable';
|
|
30
|
+
if (name === 'href' && el.localName === 'a' && !el.hasAttribute('tabindex')) el.tabIndex = 0;
|
|
31
|
+
if (
|
|
32
|
+
/^on/.test(name) ||
|
|
33
|
+
[
|
|
34
|
+
'action',
|
|
35
|
+
'formaction',
|
|
36
|
+
'target',
|
|
37
|
+
'srcset',
|
|
38
|
+
'srcdoc',
|
|
39
|
+
'ping',
|
|
40
|
+
'download',
|
|
41
|
+
'autofocus',
|
|
42
|
+
'popover',
|
|
43
|
+
'popovertarget',
|
|
44
|
+
'contenteditable',
|
|
45
|
+
'is'
|
|
46
|
+
].includes(name) ||
|
|
47
|
+
(['href', 'xlink:href', 'src'].includes(name) &&
|
|
48
|
+
!(
|
|
49
|
+
(el.localName === 'use' && attr.value.startsWith('#')) ||
|
|
50
|
+
(['img', 'image'].includes(el.localName) && /^data:image\//i.test(attr.value))
|
|
51
|
+
))
|
|
52
|
+
)
|
|
53
|
+
el.removeAttribute(attr.name);
|
|
54
|
+
}
|
|
55
|
+
if (el.matches('input,textarea')) {
|
|
56
|
+
if (!el.readOnly && el.matches(nativeTextEntry)) el.dataset.playerTextEntry = 'input';
|
|
57
|
+
el.readOnly = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
doc.documentElement.dataset.theme = theme;
|
|
61
|
+
doc.head.querySelector('style').textContent =
|
|
62
|
+
endpoint.css +
|
|
63
|
+
'\n*,*::before,*::after {animation:none!important;transition:none!important;caret-color:transparent!important} [data-player-text-entry]:read-write {caret-color:auto!important}';
|
|
64
|
+
const stage = doc.createElement('div');
|
|
65
|
+
stage.dataset.adgFrame = endpoint.frame;
|
|
66
|
+
Object.assign(stage.style, {
|
|
67
|
+
width: endpoint.width ? endpoint.width + 'px' : 'max-content',
|
|
68
|
+
height: endpoint.height ? endpoint.height + 'px' : ''
|
|
69
|
+
});
|
|
70
|
+
if (offset) {
|
|
71
|
+
const [x, y] = offset;
|
|
72
|
+
Object.assign(stage.style, { position: 'absolute', left: x + 'px', top: y + 'px' });
|
|
73
|
+
}
|
|
74
|
+
stage.append(fragment);
|
|
75
|
+
parent.replaceChildren(stage);
|
|
76
|
+
await Promise.all([doc.fonts.ready, ...[...doc.images].map((img) => img.decode().catch(() => {}))]);
|
|
77
|
+
return stage;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function observeScene(stage, design, freeze = false) {
|
|
81
|
+
const root = stage.firstElementChild,
|
|
82
|
+
doc = stage.ownerDocument;
|
|
83
|
+
const elements = [root, ...root.querySelectorAll('*')],
|
|
84
|
+
indexes = new Map(elements.map((el, i) => [el, i]));
|
|
85
|
+
return elements.map((el, i) => {
|
|
86
|
+
const rect = el.getBoundingClientRect(),
|
|
87
|
+
css = doc.defaultView.getComputedStyle(el);
|
|
88
|
+
const row = {
|
|
89
|
+
el,
|
|
90
|
+
i,
|
|
91
|
+
parent: indexes.get(el.parentElement) ?? -1,
|
|
92
|
+
box: [rect.x, rect.y, rect.width, rect.height],
|
|
93
|
+
parts: JSON.parse(el.dataset.adgOwners ?? '[]').map(
|
|
94
|
+
(o) => (design ? design + '/' : '') + o.source + '#' + o.export
|
|
95
|
+
),
|
|
96
|
+
keys: JSON.parse(el.dataset.adgKeys ?? '[]'),
|
|
97
|
+
anchor: el.dataset.adgId ?? null,
|
|
98
|
+
opacity: Number(css.opacity)
|
|
99
|
+
};
|
|
100
|
+
if (freeze) {
|
|
101
|
+
row.paint = el.cloneNode(false);
|
|
102
|
+
for (const name of ['data-adg-id', 'data-adg-owners', 'data-adg-keys']) row.paint.removeAttribute(name);
|
|
103
|
+
if (el.localName === 'input') row.paint.value = el.value;
|
|
104
|
+
const cssText = (style) => Array.from(style, (prop) => prop + ':' + style.getPropertyValue(prop) + ';').join('');
|
|
105
|
+
row.paint.style.cssText = cssText(css);
|
|
106
|
+
row.pseudos = [];
|
|
107
|
+
for (const pseudo of ['before', 'after']) {
|
|
108
|
+
const style = doc.defaultView.getComputedStyle(el, '::' + pseudo);
|
|
109
|
+
if (!['none', 'normal'].includes(style.content)) row.pseudos.push({ pseudo, css: cssText(style) });
|
|
110
|
+
}
|
|
111
|
+
row.children = [...el.childNodes].map((n) =>
|
|
112
|
+
n.nodeType === 1 ? indexes.get(n) : n.nodeType === 3 ? n.textContent : ''
|
|
113
|
+
);
|
|
114
|
+
row.runs = [];
|
|
115
|
+
for (const [index, n] of [...el.childNodes].entries())
|
|
116
|
+
if (n.nodeType === 3 && n.textContent.trim()) {
|
|
117
|
+
const range = doc.createRange();
|
|
118
|
+
range.selectNodeContents(n);
|
|
119
|
+
const r = range.getBoundingClientRect();
|
|
120
|
+
row.runs.push({ index, text: n.textContent, box: [r.x, r.y, r.width, r.height] });
|
|
121
|
+
}
|
|
122
|
+
row.text = el.textContent;
|
|
123
|
+
row.localSize = [el.offsetWidth ?? rect.width, el.offsetHeight ?? rect.height];
|
|
124
|
+
row.matrix = new DOMMatrix();
|
|
125
|
+
let clip = [-Infinity, -Infinity, Infinity, Infinity];
|
|
126
|
+
for (let p = el; p; p = p.parentElement) {
|
|
127
|
+
const style = doc.defaultView.getComputedStyle(p);
|
|
128
|
+
if (style.transform !== 'none') row.matrix = new DOMMatrix(style.transform).multiply(row.matrix);
|
|
129
|
+
if (style.clipPath !== 'none') row.clipped = true;
|
|
130
|
+
if (p === el) continue;
|
|
131
|
+
const b = p.getBoundingClientRect();
|
|
132
|
+
if (/hidden|clip|auto|scroll/.test(style.overflowX)) {
|
|
133
|
+
clip[0] = Math.max(clip[0], b.left);
|
|
134
|
+
clip[2] = Math.min(clip[2], b.right);
|
|
135
|
+
}
|
|
136
|
+
if (/hidden|clip|auto|scroll/.test(style.overflowY)) {
|
|
137
|
+
clip[1] = Math.max(clip[1], b.top);
|
|
138
|
+
clip[3] = Math.min(clip[3], b.bottom);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
row.clip = [
|
|
142
|
+
Math.max(0, clip[1] - rect.top),
|
|
143
|
+
Math.max(0, rect.right - clip[2]),
|
|
144
|
+
Math.max(0, rect.bottom - clip[3]),
|
|
145
|
+
Math.max(0, clip[0] - rect.left)
|
|
146
|
+
];
|
|
147
|
+
row.clipped ||= row.clip.some((x) => x > 0) || !Number.isFinite(row.matrix.inverse().a);
|
|
148
|
+
}
|
|
149
|
+
return row;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function readySceneResources(doc = document) {
|
|
154
|
+
await doc.fonts.ready;
|
|
155
|
+
await Promise.all([...doc.images].map(image => image.decode()));
|
|
156
|
+
const urls = new Set();
|
|
157
|
+
for (const element of doc.querySelectorAll('*')) {
|
|
158
|
+
for (const match of doc.defaultView.getComputedStyle(element).backgroundImage.matchAll(/url\(["']?(.+?)["']?\)/g)) urls.add(match[1]);
|
|
159
|
+
}
|
|
160
|
+
for (const element of doc.querySelectorAll('svg image')) {
|
|
161
|
+
const href = element.getAttribute('href') ?? element.getAttribute('xlink:href');
|
|
162
|
+
if (href) urls.add(href);
|
|
163
|
+
}
|
|
164
|
+
await Promise.all([...urls].map(async url => { const image = new doc.defaultView.Image(); image.src = url; await image.decode(); }));
|
|
165
|
+
}
|