@variance-authority/core 0.14.0 → 0.17.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/CHANGELOG.md +878 -0
- package/README.md +38 -17
- package/dist/attribute/component-hash.d.ts +14 -5
- package/dist/attribute/component-hash.js +14 -5
- package/dist/attribute/component-hash.js.map +1 -1
- package/dist/attribute/composition.d.ts +16 -0
- package/dist/attribute/composition.js +4 -6
- package/dist/attribute/composition.js.map +1 -1
- package/dist/attribute/index.d.ts +3 -1
- package/dist/attribute/index.js +2 -1
- package/dist/attribute/index.js.map +1 -1
- package/dist/attribute/movement.d.ts +1 -1
- package/dist/attribute/movement.js.map +1 -1
- package/dist/attribute/region.d.ts +47 -4
- package/dist/attribute/region.js +91 -22
- package/dist/attribute/region.js.map +1 -1
- package/dist/attribute/source.d.ts +10 -24
- package/dist/attribute/source.js +4 -38
- package/dist/attribute/source.js.map +1 -1
- package/dist/attribute/subject-pieces.d.ts +37 -0
- package/dist/attribute/subject-pieces.js +122 -0
- package/dist/attribute/subject-pieces.js.map +1 -0
- package/dist/compare/band.d.ts +8 -2
- package/dist/compare/band.js +7 -2
- package/dist/compare/band.js.map +1 -1
- package/dist/compare/diff/attribution.js +6 -4
- package/dist/compare/diff/attribution.js.map +1 -1
- package/dist/compare/diff/compare-nodes.js +9 -1
- package/dist/compare/diff/compare-nodes.js.map +1 -1
- package/dist/compare/diff/match.d.ts +2 -1
- package/dist/compare/diff/match.js +52 -0
- package/dist/compare/diff/match.js.map +1 -1
- package/dist/compare/parting.js +6 -4
- package/dist/compare/parting.js.map +1 -1
- package/dist/format/capture.d.ts +25 -0
- package/dist/format/capture.js +6 -0
- package/dist/format/capture.js.map +1 -1
- package/dist/format/document.d.ts +28 -5
- package/dist/format/document.js +8 -2
- package/dist/format/document.js.map +1 -1
- package/dist/format/drive.d.ts +191 -0
- package/dist/format/drive.js +343 -0
- package/dist/format/drive.js.map +1 -0
- package/dist/format/environment.d.ts +20 -2
- package/dist/format/environment.js +7 -0
- package/dist/format/environment.js.map +1 -1
- package/dist/format/index.d.ts +13 -3
- package/dist/format/index.js +8 -2
- package/dist/format/index.js.map +1 -1
- package/dist/format/intervention.d.ts +79 -0
- package/dist/format/intervention.js.map +1 -1
- package/dist/format/origin.d.ts +32 -0
- package/dist/format/origin.js +54 -0
- package/dist/format/origin.js.map +1 -0
- package/dist/format/packed.d.ts +32 -0
- package/dist/format/packed.js +23 -0
- package/dist/format/packed.js.map +1 -0
- package/dist/format/shape.d.ts +31 -0
- package/dist/format/shape.js +269 -0
- package/dist/format/shape.js.map +1 -0
- package/dist/format/snapshot.d.ts +2 -0
- package/dist/format/snapshot.js.map +1 -1
- package/dist/format/stabilize.d.ts +35 -6
- package/dist/format/stabilize.js +58 -103
- package/dist/format/stabilize.js.map +1 -1
- package/dist/format/steps.d.ts +44 -0
- package/dist/format/steps.js +67 -0
- package/dist/format/steps.js.map +1 -0
- package/dist/format/waits.d.ts +12 -0
- package/dist/format/waits.js +156 -0
- package/dist/format/waits.js.map +1 -0
- package/dist/format/width.d.ts +35 -0
- package/dist/format/width.js +38 -0
- package/dist/format/width.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/judge/docket.js +1 -0
- package/dist/judge/docket.js.map +1 -1
- package/dist/judge/index.d.ts +1 -0
- package/dist/judge/index.js +1 -0
- package/dist/judge/index.js.map +1 -1
- package/dist/judge/restamp.d.ts +20 -0
- package/dist/judge/restamp.js +20 -0
- package/dist/judge/restamp.js.map +1 -0
- package/dist/nearest.d.ts +46 -0
- package/dist/nearest.js +102 -0
- package/dist/nearest.js.map +1 -0
- package/dist/relate/before.d.ts +19 -24
- package/dist/relate/before.js +37 -39
- package/dist/relate/before.js.map +1 -1
- package/dist/relate/beyond.d.ts +59 -0
- package/dist/relate/beyond.js +98 -0
- package/dist/relate/beyond.js.map +1 -0
- package/dist/relate/carried.d.ts +122 -0
- package/dist/relate/carried.js +279 -0
- package/dist/relate/carried.js.map +1 -0
- package/dist/relate/graph.d.ts +14 -12
- package/dist/relate/graph.js +12 -11
- package/dist/relate/graph.js.map +1 -1
- package/dist/relate/index.d.ts +3 -1
- package/dist/relate/index.js +3 -1
- package/dist/relate/index.js.map +1 -1
- package/dist/relate/merkle.js +2 -11
- package/dist/relate/merkle.js.map +1 -1
- package/dist/relate/narrow.d.ts +2 -2
- package/dist/relate/narrow.js +26 -73
- package/dist/relate/narrow.js.map +1 -1
- package/dist/relate/reach.d.ts +6 -6
- package/dist/relate/reach.js +10 -53
- package/dist/relate/reach.js.map +1 -1
- package/dist/relate/records.d.ts +6 -5
- package/dist/relate/records.js +3 -2
- package/dist/relate/records.js.map +1 -1
- package/dist/rules/index.d.ts +3 -3
- package/dist/rules/index.js +3 -3
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/normalize/cascade.d.ts +12 -0
- package/dist/rules/normalize/cascade.js +34 -16
- package/dist/rules/normalize/cascade.js.map +1 -1
- package/dist/rules/normalize/fixture.d.ts +3 -0
- package/dist/rules/normalize/fixture.js +3 -1
- package/dist/rules/normalize/fixture.js.map +1 -1
- package/dist/rules/normalize/index.d.ts +2 -2
- package/dist/rules/normalize/index.js +9 -2
- package/dist/rules/normalize/index.js.map +1 -1
- package/dist/rules/normalize/value.d.ts +13 -2
- package/dist/rules/normalize/value.js +42 -8
- package/dist/rules/normalize/value.js.map +1 -1
- package/dist/rules/normalize/wrapper.js +5 -0
- package/dist/rules/normalize/wrapper.js.map +1 -1
- package/dist/rules/ruleset.d.ts +24 -4
- package/dist/rules/ruleset.js +24 -4
- package/dist/rules/ruleset.js.map +1 -1
- package/dist/segment/index.d.ts +20 -4
- package/dist/segment/index.js +28 -7
- package/dist/segment/index.js.map +1 -1
- package/dist/shard/index.d.ts +11 -0
- package/dist/shard/index.js +11 -0
- package/dist/shard/index.js.map +1 -0
- package/dist/shard/placement.d.ts +119 -0
- package/dist/shard/placement.js +156 -0
- package/dist/shard/placement.js.map +1 -0
- package/dist/share/index.d.ts +1 -1
- package/dist/share/index.js +1 -1
- package/dist/share/index.js.map +1 -1
- package/package.json +8 -1
package/dist/format/stabilize.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { digestValue } from './hash.js';
|
|
2
2
|
import { tierReaches } from './tier.js';
|
|
3
|
+
import { clockById, freezeClock, freezeClockAt, noFocus, noHover, reducedMotion, UNTOUCHED } from './drive.js';
|
|
4
|
+
import { waitForFonts, waitForImages } from './waits.js';
|
|
5
|
+
export { waitForFonts, waitForImages } from './waits.js';
|
|
3
6
|
/**
|
|
4
7
|
* Hand animations to the browser rather than emulating the hold in CSS.
|
|
5
8
|
*
|
|
@@ -109,108 +112,16 @@ export const hidePresentationalImages = {
|
|
|
109
112
|
css: 'img[role="presentation"],img[alt=""],[role="presentation"] img,[role="none"] img' +
|
|
110
113
|
'{visibility:hidden !important}',
|
|
111
114
|
};
|
|
112
|
-
export const waitForFonts = {
|
|
113
|
-
id: 'wait-for-fonts',
|
|
114
|
-
trick: 'wait',
|
|
115
|
-
needs: 'layout',
|
|
116
|
-
governs: 'fonts',
|
|
117
|
-
because: 'waited for web fonts, whose advances change every metric on the page',
|
|
118
|
-
// Written without a module-scope helper on purpose: a settle closure is
|
|
119
|
-
// shipped to a page as source text, so anything it names by identifier is a
|
|
120
|
-
// `ReferenceError` on the far side. Types are erased and therefore free.
|
|
121
|
-
settle: async (target) => {
|
|
122
|
-
await target.evaluate(async () => {
|
|
123
|
-
const view = globalThis;
|
|
124
|
-
await view.document.fonts?.ready;
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
export const waitForImages = {
|
|
129
|
-
id: 'wait-for-images',
|
|
130
|
-
trick: 'wait',
|
|
131
|
-
needs: 'layout',
|
|
132
|
-
governs: 'images',
|
|
133
|
-
because: 'waited for images to decode, since their intrinsic size participates in layout, and asked ' +
|
|
134
|
-
'for the ones the browser had deferred',
|
|
135
|
-
settle: async (target) => {
|
|
136
|
-
await target.evaluate(async () => {
|
|
137
|
-
const view = globalThis;
|
|
138
|
-
const pending = Array.from(view.document.images).filter((image) => !image.complete);
|
|
139
|
-
const arrived = Promise.all(pending.map((image) => new Promise((resolve) => {
|
|
140
|
-
image.addEventListener('load', () => resolve(), { once: true });
|
|
141
|
-
image.addEventListener('error', () => resolve(), { once: true });
|
|
142
|
-
})));
|
|
143
|
-
// Asked for, after the listeners are attached and before anything is
|
|
144
|
-
// awaited. A `loading="lazy"` image outside the viewport has not been
|
|
145
|
-
// requested and will not be until something scrolls, so waiting on it is
|
|
146
|
-
// waiting for a decision the browser has already taken the other way.
|
|
147
|
-
//
|
|
148
|
-
// This is the same act as pinning an animation, not a different kind of
|
|
149
|
-
// thing: what the page shows stops depending on where the viewport
|
|
150
|
-
// happens to be. It matters most for the readings that need it most — a
|
|
151
|
-
// full-page capture of a long page is exactly the case where most of the
|
|
152
|
-
// images are deferred, and photographing it without them yields a picture
|
|
153
|
-
// full of empty boxes whose contents change with the browser's loading
|
|
154
|
-
// heuristics rather than with the product.
|
|
155
|
-
const asServed = pending.map((image) => image.loading);
|
|
156
|
-
for (const image of pending)
|
|
157
|
-
image.loading = 'eager';
|
|
158
|
-
// Bounded, and it throws when the bound is reached.
|
|
159
|
-
//
|
|
160
|
-
// A response can stall: a CDN that never answers, an image endpoint that
|
|
161
|
-
// deadlocks under its own concurrency, an image the browser deferred and
|
|
162
|
-
// will not request from where the page is scrolled. None of those fire
|
|
163
|
-
// `load` and none fire `error`, so an unbounded wait turns one stuck
|
|
164
|
-
// request into a run that never ends and never says why — not a wrong
|
|
165
|
-
// answer, no answer.
|
|
166
|
-
//
|
|
167
|
-
// Giving up quietly would be worse than the hang in a subtler way: it
|
|
168
|
-
// photographs a page with holes in it and reports the holes as a change,
|
|
169
|
-
// inventing a regression out of the network this trick exists to hold
|
|
170
|
-
// still. Refused instead, naming what it was still waiting for, because
|
|
171
|
-
// "these two never answered" is a finding about the application.
|
|
172
|
-
//
|
|
173
|
-
// The bound is written twice — once as the delay, once in the sentence —
|
|
174
|
-
// because a settle closure is shipped to the page as source text and a
|
|
175
|
-
// constant it named would be a `ReferenceError` on the far side.
|
|
176
|
-
// Held so the loser can be cancelled. A timer left to fire after the
|
|
177
|
-
// images arrived rejects a promise nothing is waiting on any more, which
|
|
178
|
-
// the page reports as an unhandled rejection — this trick's own noise,
|
|
179
|
-
// arriving in the console of every subject it succeeded on.
|
|
180
|
-
let timer;
|
|
181
|
-
const expired = new Promise((_, reject) => {
|
|
182
|
-
timer = view.setTimeout(() => {
|
|
183
|
-
const stuck = pending.filter((image) => !image.complete);
|
|
184
|
-
reject(new Error(`${stuck.length} image(s) had not loaded after 15000ms, and neither answered ` +
|
|
185
|
-
`nor failed: ${stuck.map((image) => image.currentSrc || image.src).join(', ')}`));
|
|
186
|
-
}, 15000);
|
|
187
|
-
});
|
|
188
|
-
try {
|
|
189
|
-
await Promise.race([arrived, expired]);
|
|
190
|
-
}
|
|
191
|
-
finally {
|
|
192
|
-
view.clearTimeout(timer);
|
|
193
|
-
// Put back, because the trick has to be invisible to the tier that
|
|
194
|
-
// reads the page after it. `loading` is a reflected attribute, so a
|
|
195
|
-
// document whose deferred images were switched to `eager` and left that
|
|
196
|
-
// way is a document that no longer matches the one the product served —
|
|
197
|
-
// and which images were still undecoded when this ran is a question
|
|
198
|
-
// about the network, so the edit lands in some readings and not others.
|
|
199
|
-
// Left in, it makes the same page at two widths disagree about its own
|
|
200
|
-
// markup: this trick filed as a finding against the application.
|
|
201
|
-
for (let index = 0; index < pending.length; index += 1) {
|
|
202
|
-
pending[index].loading = asServed[index];
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
115
|
export const INTERVENTIONS = [
|
|
209
116
|
holdAnimations,
|
|
210
117
|
pinAnimations,
|
|
211
118
|
hideCaret,
|
|
212
119
|
hideScrollbars,
|
|
213
120
|
hidePresentationalImages,
|
|
121
|
+
noHover,
|
|
122
|
+
noFocus,
|
|
123
|
+
reducedMotion,
|
|
124
|
+
freezeClock,
|
|
214
125
|
waitForFonts,
|
|
215
126
|
waitForImages,
|
|
216
127
|
];
|
|
@@ -223,7 +134,18 @@ export const INTERVENTIONS = [
|
|
|
223
134
|
* rung the tier ladder exists to make cheap.
|
|
224
135
|
*/
|
|
225
136
|
export const SEMANTIC_RECIPE = [];
|
|
226
|
-
|
|
137
|
+
// TODO: a `<script>` inside a subject root runs in the render document under the
|
|
138
|
+
// real clock, which no trick in this recipe holds.
|
|
139
|
+
// TODO: a document is painted under this recipe whatever recipe it was read
|
|
140
|
+
// under: a `RenderDocument` carries no collection recipe to follow.
|
|
141
|
+
/**
|
|
142
|
+
* What a document is painted under, and of {@link UNTOUCHED} only `no-focus`: a
|
|
143
|
+
* collected `autofocus` takes focus again. The other three have nothing but a
|
|
144
|
+
* carried script to act on: the printed date and the animation's place are in
|
|
145
|
+
* the document already, its `@media` rules were resolved when it was read, and
|
|
146
|
+
* nothing moves the pointer over it.
|
|
147
|
+
*/
|
|
148
|
+
export const LAYOUT_RECIPE = [holdAnimations, hideScrollbars, noFocus, waitForFonts, waitForImages];
|
|
227
149
|
export const RASTER_RECIPE = [...LAYOUT_RECIPE, hideCaret];
|
|
228
150
|
/**
|
|
229
151
|
* What is applied to a live page *before a subject is observed*, as opposed to
|
|
@@ -260,9 +182,16 @@ export const COLLECT_RECIPE = [
|
|
|
260
182
|
// holding a focused input otherwise disagrees with itself between two
|
|
261
183
|
// screenshots taken 600ms apart, and is refused for blinking.
|
|
262
184
|
hideCaret,
|
|
185
|
+
...UNTOUCHED,
|
|
263
186
|
waitForFonts,
|
|
264
187
|
waitForImages,
|
|
265
188
|
];
|
|
189
|
+
/**
|
|
190
|
+
* The ids of {@link COLLECT_RECIPE}, as an absent `stabilize` means them. A list
|
|
191
|
+
* replaces the recipe, so one trick is turned off with this list without it:
|
|
192
|
+
* `stabilize: DEFAULT_STABILIZE.filter((id) => id !== 'freeze-clock')`.
|
|
193
|
+
*/
|
|
194
|
+
export const DEFAULT_STABILIZE = COLLECT_RECIPE.map((intervention) => intervention.id);
|
|
266
195
|
/**
|
|
267
196
|
* Resolve a trick by the name a caller wrote down.
|
|
268
197
|
*
|
|
@@ -274,7 +203,7 @@ export const COLLECT_RECIPE = [
|
|
|
274
203
|
* flake it has already paid to prevent.
|
|
275
204
|
*/
|
|
276
205
|
export function interventionById(id) {
|
|
277
|
-
return INTERVENTIONS.find((intervention) => intervention.id === id);
|
|
206
|
+
return INTERVENTIONS.find((intervention) => intervention.id === id) ?? clockById(id);
|
|
278
207
|
}
|
|
279
208
|
/**
|
|
280
209
|
* A recipe from the names it travels as.
|
|
@@ -290,11 +219,30 @@ export function recipeOf(ids) {
|
|
|
290
219
|
const intervention = interventionById(id);
|
|
291
220
|
if (intervention === undefined) {
|
|
292
221
|
throw new Error(`no stabilization trick is called \`${id}\`; this build knows ` +
|
|
293
|
-
INTERVENTIONS.map((known) => `\`${known.id}\``).join(', ')
|
|
222
|
+
INTERVENTIONS.map((known) => `\`${known.id}\``).join(', ') +
|
|
223
|
+
', and `freeze-clock@<instant>`');
|
|
294
224
|
}
|
|
295
225
|
return intervention;
|
|
296
226
|
});
|
|
297
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* The recipe a host that drives the browser applies, checked before it opens one:
|
|
230
|
+
* `stabilize` by id, or {@link COLLECT_RECIPE} when it is absent, with its clock
|
|
231
|
+
* fixed at `now`, which travels in the clock's id and lands in the digest. Throws
|
|
232
|
+
* on an unknown id, an instant with no zone, or a `now` with no clock to fix, so
|
|
233
|
+
* the operator hears about it before a page is loaded, not at the first subject.
|
|
234
|
+
*/
|
|
235
|
+
export function recipeToDrive(options) {
|
|
236
|
+
const recipe = options.stabilize === undefined ? COLLECT_RECIPE : recipeOf(options.stabilize);
|
|
237
|
+
if (options.now === undefined)
|
|
238
|
+
return recipe;
|
|
239
|
+
const clock = freezeClockAt(options.now);
|
|
240
|
+
if (!recipe.some((intervention) => intervention.driver?.clock !== undefined)) {
|
|
241
|
+
throw new Error(`\`now\` is the instant \`freeze-clock\` fixes, and this recipe has no \`freeze-clock\`: ` +
|
|
242
|
+
'add it to `stabilize`, or leave `now` out');
|
|
243
|
+
}
|
|
244
|
+
return recipe.map((intervention) => (intervention.driver?.clock === undefined ? intervention : clock));
|
|
245
|
+
}
|
|
298
246
|
/** Only the tricks a tier can observe the effect of. */
|
|
299
247
|
export function forTier(recipe, tier) {
|
|
300
248
|
return recipe.filter((intervention) => tierReaches(tier, intervention.needs));
|
|
@@ -328,10 +276,17 @@ export function recipeCss(recipe) {
|
|
|
328
276
|
export function recipeScreenshot(recipe) {
|
|
329
277
|
return recipe.reduce((options, intervention) => ({ ...options, ...intervention.screenshot }), {});
|
|
330
278
|
}
|
|
331
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Every wait the recipe holds, in order. Each is one step on `steps`, named by
|
|
281
|
+
* the intervention's id, so a run can say which wait a slow subject spent its
|
|
282
|
+
* time in.
|
|
283
|
+
*/
|
|
284
|
+
export async function settleRecipe(recipe, target, steps) {
|
|
332
285
|
for (const intervention of recipe) {
|
|
333
|
-
|
|
334
|
-
|
|
286
|
+
const settle = intervention.settle;
|
|
287
|
+
if (settle === undefined)
|
|
288
|
+
continue;
|
|
289
|
+
await (steps === undefined ? settle(target) : steps.time(intervention.id, async () => settle(target)));
|
|
335
290
|
}
|
|
336
291
|
}
|
|
337
292
|
/**
|
|
@@ -339,7 +294,7 @@ export async function settleRecipe(recipe, target) {
|
|
|
339
294
|
*
|
|
340
295
|
* Sorted, so the order tricks were composed in does not change the identity —
|
|
341
296
|
* only which ones are present. Folded into `RenderIdentity`, which is what makes
|
|
342
|
-
* a cross-recipe comparison
|
|
297
|
+
* a cross-recipe comparison name the recipe as its cause instead of inventing a
|
|
343
298
|
* component to blame.
|
|
344
299
|
*/
|
|
345
300
|
export function recipeDigest(recipe) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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AS;YAAE,MAAM,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC;QACxB,CAAC,CAAC,oCAAoC;QACtC,CAAC,CAAC,6CAA6C,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC7F,CAAC","sourcesContent":["import { digestValue, type Digest } from './hash.js';\nimport { tierReaches, type Tier } from './tier.js';\nimport type { Intervention, PageGlobals, ScreenshotOptions, SettleTarget } from './intervention.js';\n\n/**\n * Interventions as separate, nameable tricks — not a fixed set of switches.\n *\n * A subject that is still changing cannot be compared, so every system of this\n * kind reaches into the page: it holds animations, waits for fonts, hides a\n * caret, suppresses scrollbars. Written as one struct of booleans that becomes a\n * closed vocabulary: adding a trick edits a type every caller depends on, and a\n * project with a need nobody anticipated has to fork.\n *\n * So each is a value. It carries an id, the tier that can actually observe what\n * it fixes, what it costs, and how it is applied — and a *recipe* is any list of\n * them. Two tricks may express the same intent through different mechanisms and\n * remain separate values, because they produce different images and choosing\n * between them is the caller's business.\n *\n * ## What this buys\n *\n * A recipe can be filtered by tier, so the structure-and-style rung waits for\n * nothing; composed from another project's tricks alongside these; digested, so\n * a baseline made under one recipe is `incomparable` with a run made under\n * another rather than `changed`; and checked for tricks that fight each other.\n *\n * ## Where the damage lands\n *\n * Ordered by increasing cost, earliest sufficient option first:\n *\n * - **Outside the subject** — injected CSS, browser screenshot options. Nothing\n * in the product imports it and deleting the tool deletes the intervention.\n * - **Runtime substitution** — wrapping `Promise`, replacing a suspense\n * boundary. Buys the same knowledge without touching a component and is\n * deliberately not shipped here: it moves the damage from design into\n * semantics, where a difference caused by the patch cannot be told apart from\n * a difference caused by the code. Expressible as a trick if a project decides\n * the trade is worth it — that is the point of an open set.\n * - **A contract the subject implements** — a readiness marker. Real design\n * damage, and reserved for what the outside genuinely cannot know.\n *\n * ## Why this is in `format` and not in the raster package\n *\n * It was in `@variance-authority/raster` until 2026-08-06, on the reading that\n * holding a page still is something you do before you photograph it. That\n * reading was wrong in a way that cost correctness: an animation in flight is a\n * *computed style value*, so it reaches the cheap representation too — and the\n * allowlist excludes `animation-*` and `transition-*` precisely because it\n * assumed a snapshot is taken with animation already disabled. Nothing disabled\n * it. See {@link COLLECT_RECIPE} and ADR-0028.\n *\n * So a recipe is a render input on every tier, `EnvironmentInputs` carries its\n * digest, and the vocabulary belongs beside the key it is part of.\n */\n\n// Re-exported from here because this is where a reader arrives looking for the\n// vocabulary; [`intervention.ts`](./intervention.js) holds the declaration.\nexport type { Intervention, ScreenshotOptions, SettleTarget, Trick } from './intervention.js';\n\n/**\n * Hand animations to the browser rather than emulating the hold in CSS.\n *\n * A browser disabling animations for a screenshot fast-forwards a finite\n * animation to completion — the state a user comes to rest on — and cancels an\n * infinite one to its initial frame, replaying it afterwards. That is the\n * behaviour worth having, and CSS cannot express it.\n */\nexport const holdAnimations: Intervention = {\n id: 'hold-animations',\n trick: 'hold',\n needs: 'layout',\n governs: 'animations',\n because: 'animations settled by the browser: finite fast-forwarded, infinite reset',\n screenshot: { animations: 'disabled' },\n};\n\n/**\n * The same intent without a browser that can do it, and it is not equivalent.\n *\n * Pins every animation at its first frame, so a fade-in is captured at the\n * moment it is invisible. `animation: none` is avoided deliberately — removing\n * an animation drops whatever layout its keyframes contribute, which changes the\n * page rather than stopping it.\n */\nexport const pinAnimations: Intervention = {\n id: 'pin-animations',\n trick: 'hold',\n needs: 'layout',\n governs: 'animations',\n because: 'animations pinned at their first frame, which is not where a user sees them',\n css:\n '*,*::before,*::after{' +\n 'animation-play-state:paused !important;' +\n 'animation-delay:-0.0001s !important;' +\n 'transition-duration:0s !important;' +\n 'transition-delay:0s !important;' +\n 'scroll-behavior:auto !important}',\n};\n\n/**\n * A stylesheet rather than the driver's own caret switch, deliberately.\n *\n * Playwright and its peers hide a caret by writing `caret-color` onto every\n * focusable element and putting it back afterwards, and putting it back leaves\n * `style=\"\"` where there was no `style` attribute at all. Any capture that reads\n * the DOM on both sides of a screenshot — which is what the in-place path does\n * to prove the subject held still — then sees markup that moved, and reports the\n * driver's housekeeping as the page being unstable. A page with one text input\n * is enough.\n *\n * So this hold owns the caret the way {@link pinAnimations} owns animations: one\n * stylesheet, installed before the subject is read, removed with the rest of the\n * recipe.\n */\nexport const hideCaret: Intervention = {\n id: 'hide-caret',\n trick: 'support',\n // A caret paints and does not lay out, so a tier that never rasterizes cannot\n // see it and must not pay to hide it.\n needs: 'raster',\n governs: 'caret',\n because: 'text caret hidden, because it blinks on its own schedule',\n css: '*{caret-color:transparent !important}',\n};\n\nexport const hideScrollbars: Intervention = {\n id: 'hide-scrollbars',\n trick: 'support',\n needs: 'layout',\n governs: 'scrollbars',\n because: 'scrollbars hidden, removing a platform and preference difference — and their width',\n css: '*{scrollbar-width:none !important}\\n*::-webkit-scrollbar{display:none !important}',\n};\n\n/**\n * Drop the pixels of images the page itself called decorative, keeping their boxes.\n *\n * The other half of blanking, and it lives here because of what it needs to\n * know. A driver rewriting responses (`@variance-authority/playwright`'s\n * `blank` rules) can decide by URL and by intrinsic size, which answers \"every\n * illustration over 40,000 pixels\" and answers it before the bytes are even\n * fetched. It cannot answer `role=\"presentation\"`, because a request carries no\n * idea which element wanted it — that fact exists only in the document, so the\n * trick that uses it is a stylesheet.\n *\n * `visibility:hidden` rather than `display:none`, and the distinction is the\n * entire design: a hidden element still occupies exactly the box it would have,\n * so a page whose column height comes from an image's intrinsic size is\n * unchanged. `display:none` would collapse it and report a layout regression\n * this tool caused.\n *\n * **Opt-in, and it belongs in no default recipe.** Every other trick here\n * removes something that is not part of the assertion — a caret, a scrollbar, an\n * animation mid-flight. This one removes page content, which is a judgement\n * about what a suite is for, and a default that quietly stopped watching every\n * `alt=\"\"` image would hide real regressions under a green run.\n */\nexport const hidePresentationalImages: Intervention = {\n id: 'hide-presentational-images',\n trick: 'support',\n // `layout` rather than `raster`, and the difference is whether it runs at all.\n // A raster-tier trick is filtered out of every *collection* — `tierOfProfile`\n // never returns `raster` — so it would only reach a page through a renderer\n // option, which is not where an operator configures their suite. A collection\n // sheet is in force when the document is serialized, so hiding it here is what\n // makes the pixels absent from the render.\n needs: 'layout',\n governs: 'presentational-images',\n because:\n 'images the page marked decorative hidden, keeping their boxes — real changes inside them ' +\n 'are not reported',\n css:\n 'img[role=\"presentation\"],img[alt=\"\"],[role=\"presentation\"] img,[role=\"none\"] img' +\n '{visibility:hidden !important}',\n};\n\nexport const waitForFonts: Intervention = {\n id: 'wait-for-fonts',\n trick: 'wait',\n needs: 'layout',\n governs: 'fonts',\n because: 'waited for web fonts, whose advances change every metric on the page',\n // Written without a module-scope helper on purpose: a settle closure is\n // shipped to a page as source text, so anything it names by identifier is a\n // `ReferenceError` on the far side. Types are erased and therefore free.\n settle: async (target) => {\n await target.evaluate(async () => {\n const view = globalThis as unknown as PageGlobals;\n await view.document.fonts?.ready;\n });\n },\n};\n\nexport const waitForImages: Intervention = {\n id: 'wait-for-images',\n trick: 'wait',\n needs: 'layout',\n governs: 'images',\n because:\n 'waited for images to decode, since their intrinsic size participates in layout, and asked ' +\n 'for the ones the browser had deferred',\n settle: async (target) => {\n await target.evaluate(async () => {\n const view = globalThis as unknown as PageGlobals;\n const pending = Array.from(view.document.images).filter((image) => !image.complete);\n\n const arrived = Promise.all(\n pending.map(\n (image) =>\n new Promise<void>((resolve) => {\n image.addEventListener('load', () => resolve(), { once: true });\n image.addEventListener('error', () => resolve(), { once: true });\n }),\n ),\n );\n\n // Asked for, after the listeners are attached and before anything is\n // awaited. A `loading=\"lazy\"` image outside the viewport has not been\n // requested and will not be until something scrolls, so waiting on it is\n // waiting for a decision the browser has already taken the other way.\n //\n // This is the same act as pinning an animation, not a different kind of\n // thing: what the page shows stops depending on where the viewport\n // happens to be. It matters most for the readings that need it most — a\n // full-page capture of a long page is exactly the case where most of the\n // images are deferred, and photographing it without them yields a picture\n // full of empty boxes whose contents change with the browser's loading\n // heuristics rather than with the product.\n const asServed = pending.map((image) => image.loading);\n for (const image of pending) image.loading = 'eager';\n\n // Bounded, and it throws when the bound is reached.\n //\n // A response can stall: a CDN that never answers, an image endpoint that\n // deadlocks under its own concurrency, an image the browser deferred and\n // will not request from where the page is scrolled. None of those fire\n // `load` and none fire `error`, so an unbounded wait turns one stuck\n // request into a run that never ends and never says why — not a wrong\n // answer, no answer.\n //\n // Giving up quietly would be worse than the hang in a subtler way: it\n // photographs a page with holes in it and reports the holes as a change,\n // inventing a regression out of the network this trick exists to hold\n // still. Refused instead, naming what it was still waiting for, because\n // \"these two never answered\" is a finding about the application.\n //\n // The bound is written twice — once as the delay, once in the sentence —\n // because a settle closure is shipped to the page as source text and a\n // constant it named would be a `ReferenceError` on the far side.\n // Held so the loser can be cancelled. A timer left to fire after the\n // images arrived rejects a promise nothing is waiting on any more, which\n // the page reports as an unhandled rejection — this trick's own noise,\n // arriving in the console of every subject it succeeded on.\n let timer: unknown;\n\n const expired = new Promise<never>((_, reject) => {\n timer = view.setTimeout(() => {\n const stuck = pending.filter((image) => !image.complete);\n reject(\n new Error(\n `${stuck.length} image(s) had not loaded after 15000ms, and neither answered ` +\n `nor failed: ${stuck.map((image) => image.currentSrc || image.src).join(', ')}`,\n ),\n );\n }, 15000);\n });\n\n try {\n await Promise.race([arrived, expired]);\n } finally {\n view.clearTimeout(timer);\n\n // Put back, because the trick has to be invisible to the tier that\n // reads the page after it. `loading` is a reflected attribute, so a\n // document whose deferred images were switched to `eager` and left that\n // way is a document that no longer matches the one the product served —\n // and which images were still undecoded when this ran is a question\n // about the network, so the edit lands in some readings and not others.\n // Left in, it makes the same page at two widths disagree about its own\n // markup: this trick filed as a finding against the application.\n for (let index = 0; index < pending.length; index += 1) {\n pending[index]!.loading = asServed[index]!;\n }\n }\n });\n },\n};\n\nexport const INTERVENTIONS: readonly Intervention[] = [\n holdAnimations,\n pinAnimations,\n hideCaret,\n hideScrollbars,\n hidePresentationalImages,\n waitForFonts,\n waitForImages,\n];\n\nexport type Recipe = readonly Intervention[];\n\n/**\n * Nothing at all, and correct for the tier that reads structure and declared style.\n *\n * A font that has not loaded cannot change which rules match or what they\n * declare; an image that has not decoded cannot either. Waiting for both before\n * a structure-and-style hash buys nothing and costs the wait per subject, on the\n * rung the tier ladder exists to make cheap.\n */\nexport const SEMANTIC_RECIPE: Recipe = [];\n\nexport const LAYOUT_RECIPE: Recipe = [holdAnimations, hideScrollbars, waitForFonts, waitForImages];\n\nexport const RASTER_RECIPE: Recipe = [...LAYOUT_RECIPE, hideCaret];\n\n/**\n * What is applied to a live page *before a subject is observed*, as opposed to\n * before it is painted.\n *\n * The two are different recipes and it is not a preference. {@link\n * holdAnimations} is a *screenshot option* — it asks the browser to settle\n * animations for the image it is about to take — and there is no screenshot at\n * collection time, so it would be a trick that silently does nothing. The CSS\n * variant is the one that works where nobody is holding a camera, which is the\n * whole reason both exist as separate values rather than as one switch.\n *\n * ## Why the cheap tier needs this at all\n *\n * The claim in [`ruleset.ts`](../rules/ruleset.ts) that `transition-*` and\n * `animation-*` \"describe a journey the snapshot does not contain\" is only true\n * if the snapshot is taken with the journey stopped. `transform`, `opacity`,\n * `filter`, `color` and every geometric longhand *are* admitted, and an\n * animation in flight moves all of them — so an unstabilized collection turns a\n * 300ms fade into a component-attributed regression with a real file name on it,\n * which is worse than an unexplained pixel diff because it is credible.\n *\n * Filtered by {@link forTier}, so jsdom applies none of it: with no layout\n * engine and no animation clock there is nothing to hold still, and paying a\n * `fonts.ready` wait per subject on the rung that exists to be cheap is exactly\n * the trade {@link SEMANTIC_RECIPE} refuses.\n */\nexport const COLLECT_RECIPE: Recipe = [\n pinAnimations,\n hideScrollbars,\n // Here as well as in {@link RASTER_RECIPE}, because the in-place path\n // photographs the live page and applies no screenshot options of its own: the\n // only caret hold that reaches that image is one installed here. A subject\n // holding a focused input otherwise disagrees with itself between two\n // screenshots taken 600ms apart, and is refused for blinking.\n hideCaret,\n waitForFonts,\n waitForImages,\n];\n\n/**\n * Resolve a trick by the name a caller wrote down.\n *\n * The boundary a collection recipe crosses is a `page.evaluate`, and an\n * `Intervention` does not survive it — `settle` is a function. Ids do survive,\n * and the page holds this same registry, so a recipe travels as the list of\n * names it is. A name nothing answers to is a caller error worth failing on\n * rather than a trick to skip quietly: under-stabilizing is how a suite gets a\n * flake it has already paid to prevent.\n */\nexport function interventionById(id: string): Intervention | undefined {\n return INTERVENTIONS.find((intervention) => intervention.id === id);\n}\n\n/**\n * A recipe from the names it travels as.\n *\n * Throws on a name nothing answers to, and names it. The quiet alternative —\n * skip what cannot be resolved — turns a typo in a config into a suite that is\n * one trick less stable than its operator believes, discovered later as a flake\n * they have already paid to prevent. Failing here costs one run and one reading\n * of the message.\n */\nexport function recipeOf(ids: readonly string[]): Recipe {\n return ids.map((id) => {\n const intervention = interventionById(id);\n if (intervention === undefined) {\n throw new Error(\n `no stabilization trick is called \\`${id}\\`; this build knows ` +\n INTERVENTIONS.map((known) => `\\`${known.id}\\``).join(', '),\n );\n }\n return intervention;\n });\n}\n\n/** Only the tricks a tier can observe the effect of. */\nexport function forTier(recipe: Recipe, tier: Tier): Recipe {\n return recipe.filter((intervention) => tierReaches(tier, intervention.needs));\n}\n\n/**\n * Tricks in a recipe that claim the same property.\n *\n * Returned rather than thrown, so a caller can decide — an override is a\n * legitimate composition, and silently applying both is not. Two tricks over one\n * property means one of them wins by accident of ordering, and which one is\n * invisible in the result.\n */\nexport function conflicts(recipe: Recipe): readonly { governs: string; ids: readonly string[] }[] {\n const byProperty = new Map<string, string[]>();\n\n for (const intervention of recipe) {\n byProperty.set(intervention.governs, [\n ...(byProperty.get(intervention.governs) ?? []),\n intervention.id,\n ]);\n }\n\n return [...byProperty.entries()]\n .filter(([, ids]) => ids.length > 1)\n .map(([governs, ids]) => ({ governs, ids }));\n}\n\nexport function recipeCss(recipe: Recipe): string {\n return recipe\n .map((intervention) => intervention.css)\n .filter((css): css is string => css !== undefined)\n .join('\\n');\n}\n\nexport function recipeScreenshot(recipe: Recipe): ScreenshotOptions {\n return recipe.reduce<ScreenshotOptions>(\n (options, intervention) => ({ ...options, ...intervention.screenshot }),\n {},\n );\n}\n\nexport async function settleRecipe(recipe: Recipe, target: SettleTarget): Promise<void> {\n for (const intervention of recipe) {\n if (intervention.settle !== undefined) await intervention.settle(target);\n }\n}\n\n/**\n * The identity of a recipe.\n *\n * Sorted, so the order tricks were composed in does not change the identity —\n * only which ones are present. Folded into `RenderIdentity`, which is what makes\n * a cross-recipe comparison report `incomparable` instead of inventing a\n * component to blame.\n */\nexport function recipeDigest(recipe: Recipe): Digest {\n return digestValue(recipe.map((intervention) => intervention.id).sort());\n}\n\n/** The recipe as a sentence, so the gap between image and product stays visible. */\nexport function describeRecipe(recipe: Recipe): string {\n return recipe.length === 0\n ? 'the subject was observed untouched'\n : `the subject was altered to be observable: ${recipe.map((i) => i.because).join('; ')}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"stabilize.js","sourceRoot":"","sources":["../../src/format/stabilize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,WAAW,EAAa,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG/G,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAwDzD,OAAO,EAAE,YAAY,EAAE,aAAa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,GAAG,YAAY,CAAC,UAAU,EAAE,CAAC,EACvE,EAAE,CACH,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAc,EAAE,MAAoB,EAAE,KAAiB;IACxF,KAAK,MAAM,YAAY,IAAI,MAAM,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;QACnC,IAAI,MAAM,KAAK,SAAS;YAAE,SAAS;QACnC,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACzG,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC;QACxB,CAAC,CAAC,oCAAoC;QACtC,CAAC,CAAC,6CAA6C,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC7F,CAAC","sourcesContent":["import { digestValue, type Digest } from './hash.js';\nimport { tierReaches, type Tier } from './tier.js';\nimport { clockById, freezeClock, freezeClockAt, noFocus, noHover, reducedMotion, UNTOUCHED } from './drive.js';\nimport type { Intervention, ScreenshotOptions, SettleTarget } from './intervention.js';\nimport type { StepClock } from './steps.js';\nimport { waitForFonts, waitForImages } from './waits.js';\n\n/**\n * Interventions as separate, nameable tricks — not a fixed set of switches.\n *\n * A subject that is still changing cannot be compared, so every system of this\n * kind reaches into the page: it holds animations, waits for fonts, hides a\n * caret, suppresses scrollbars. Written as one struct of booleans that becomes a\n * closed vocabulary: adding a trick edits a type every caller depends on, and a\n * project with a need nobody anticipated has to fork.\n *\n * So each is a value. It carries an id, the tier that can actually observe what\n * it fixes, what it costs, and how it is applied — and a *recipe* is any list of\n * them. Two tricks may express the same intent through different mechanisms and\n * remain separate values, because they produce different images and choosing\n * between them is the caller's business.\n *\n * ## What this buys\n *\n * A recipe can be filtered by tier, so the structure-and-style rung waits for\n * nothing; composed from another project's tricks alongside these; digested, so\n * a run under another recipe than its baseline names the recipe as the cause;\n * and checked for tricks that fight each other.\n *\n * ## Where the damage lands\n *\n * Ordered by increasing cost, earliest sufficient option first:\n *\n * - **Outside the subject** — injected CSS, browser screenshot options. Nothing\n * in the product imports it and deleting the tool deletes the intervention.\n * - **Runtime substitution** — wrapping `Promise`, replacing a suspense\n * boundary. Buys the same knowledge without touching a component and is\n * deliberately not shipped here: it moves the damage from design into\n * semantics, where a difference caused by the patch cannot be told apart from\n * a difference caused by the code. Expressible as a trick if a project decides\n * the trade is worth it — that is the point of an open set.\n * - **A contract the subject implements** — a readiness marker. Real design\n * damage, and reserved for what the outside genuinely cannot know.\n *\n * ## Why this is in `format` and not in the raster package\n *\n * It was in `@variance-authority/raster` until 2026-08-06, on the reading that\n * holding a page still is something you do before you photograph it. That\n * reading was wrong in a way that cost correctness: an animation in flight is a\n * *computed style value*, so it reaches the cheap representation too — and the\n * allowlist excludes `animation-*` and `transition-*` precisely because it\n * assumed a snapshot is taken with animation already disabled. Nothing disabled\n * it. See {@link COLLECT_RECIPE} and ADR-0028.\n *\n * So a recipe is a render input on every tier, `EnvironmentInputs` carries its\n * digest, and the vocabulary belongs beside the key it is part of.\n */\n\n// Re-exported from here because this is where a reader arrives looking for the\n// vocabulary; [`intervention.ts`](./intervention.js) holds the declaration.\nexport type { Intervention, ScreenshotOptions, SettleTarget, Trick } from './intervention.js';\nexport { waitForFonts, waitForImages } from './waits.js';\n\n/**\n * Hand animations to the browser rather than emulating the hold in CSS.\n *\n * A browser disabling animations for a screenshot fast-forwards a finite\n * animation to completion — the state a user comes to rest on — and cancels an\n * infinite one to its initial frame, replaying it afterwards. That is the\n * behaviour worth having, and CSS cannot express it.\n */\nexport const holdAnimations: Intervention = {\n id: 'hold-animations',\n trick: 'hold',\n needs: 'layout',\n governs: 'animations',\n because: 'animations settled by the browser: finite fast-forwarded, infinite reset',\n screenshot: { animations: 'disabled' },\n};\n\n/**\n * The same intent without a browser that can do it, and it is not equivalent.\n *\n * Pins every animation at its first frame, so a fade-in is captured at the\n * moment it is invisible. `animation: none` is avoided deliberately — removing\n * an animation drops whatever layout its keyframes contribute, which changes the\n * page rather than stopping it.\n */\nexport const pinAnimations: Intervention = {\n id: 'pin-animations',\n trick: 'hold',\n needs: 'layout',\n governs: 'animations',\n because: 'animations pinned at their first frame, which is not where a user sees them',\n css:\n '*,*::before,*::after{' +\n 'animation-play-state:paused !important;' +\n 'animation-delay:-0.0001s !important;' +\n 'transition-duration:0s !important;' +\n 'transition-delay:0s !important;' +\n 'scroll-behavior:auto !important}',\n};\n\n/**\n * A stylesheet rather than the driver's own caret switch, deliberately.\n *\n * Playwright and its peers hide a caret by writing `caret-color` onto every\n * focusable element and putting it back afterwards, and putting it back leaves\n * `style=\"\"` where there was no `style` attribute at all. Any capture that reads\n * the DOM on both sides of a screenshot — which is what the in-place path does\n * to prove the subject held still — then sees markup that moved, and reports the\n * driver's housekeeping as the page being unstable. A page with one text input\n * is enough.\n *\n * So this hold owns the caret the way {@link pinAnimations} owns animations: one\n * stylesheet, installed before the subject is read, removed with the rest of the\n * recipe.\n */\nexport const hideCaret: Intervention = {\n id: 'hide-caret',\n trick: 'support',\n // A caret paints and does not lay out, so a tier that never rasterizes cannot\n // see it and must not pay to hide it.\n needs: 'raster',\n governs: 'caret',\n because: 'text caret hidden, because it blinks on its own schedule',\n css: '*{caret-color:transparent !important}',\n};\n\nexport const hideScrollbars: Intervention = {\n id: 'hide-scrollbars',\n trick: 'support',\n needs: 'layout',\n governs: 'scrollbars',\n because: 'scrollbars hidden, removing a platform and preference difference — and their width',\n css: '*{scrollbar-width:none !important}\\n*::-webkit-scrollbar{display:none !important}',\n};\n\n/**\n * Drop the pixels of images the page itself called decorative, keeping their boxes.\n *\n * The other half of blanking, and it lives here because of what it needs to\n * know. A driver rewriting responses (`@variance-authority/playwright`'s\n * `blank` rules) can decide by URL and by intrinsic size, which answers \"every\n * illustration over 40,000 pixels\" and answers it before the bytes are even\n * fetched. It cannot answer `role=\"presentation\"`, because a request carries no\n * idea which element wanted it — that fact exists only in the document, so the\n * trick that uses it is a stylesheet.\n *\n * `visibility:hidden` rather than `display:none`, and the distinction is the\n * entire design: a hidden element still occupies exactly the box it would have,\n * so a page whose column height comes from an image's intrinsic size is\n * unchanged. `display:none` would collapse it and report a layout regression\n * this tool caused.\n *\n * **Opt-in, and it belongs in no default recipe.** Every other trick here\n * removes something that is not part of the assertion — a caret, a scrollbar, an\n * animation mid-flight. This one removes page content, which is a judgement\n * about what a suite is for, and a default that quietly stopped watching every\n * `alt=\"\"` image would hide real regressions under a green run.\n */\nexport const hidePresentationalImages: Intervention = {\n id: 'hide-presentational-images',\n trick: 'support',\n // `layout` rather than `raster`, and the difference is whether it runs at all.\n // A raster-tier trick is filtered out of every *collection* — `tierOfProfile`\n // never returns `raster` — so it would only reach a page through a renderer\n // option, which is not where an operator configures their suite. A collection\n // sheet is in force when the document is serialized, so hiding it here is what\n // makes the pixels absent from the render.\n needs: 'layout',\n governs: 'presentational-images',\n because:\n 'images the page marked decorative hidden, keeping their boxes — real changes inside them ' +\n 'are not reported',\n css:\n 'img[role=\"presentation\"],img[alt=\"\"],[role=\"presentation\"] img,[role=\"none\"] img' +\n '{visibility:hidden !important}',\n};\n\nexport const INTERVENTIONS: readonly Intervention[] = [\n holdAnimations,\n pinAnimations,\n hideCaret,\n hideScrollbars,\n hidePresentationalImages,\n noHover,\n noFocus,\n reducedMotion,\n freezeClock,\n waitForFonts,\n waitForImages,\n];\n\nexport type Recipe = readonly Intervention[];\n\n/**\n * Nothing at all, and correct for the tier that reads structure and declared style.\n *\n * A font that has not loaded cannot change which rules match or what they\n * declare; an image that has not decoded cannot either. Waiting for both before\n * a structure-and-style hash buys nothing and costs the wait per subject, on the\n * rung the tier ladder exists to make cheap.\n */\nexport const SEMANTIC_RECIPE: Recipe = [];\n\n// TODO: a `<script>` inside a subject root runs in the render document under the\n// real clock, which no trick in this recipe holds.\n// TODO: a document is painted under this recipe whatever recipe it was read\n// under: a `RenderDocument` carries no collection recipe to follow.\n/**\n * What a document is painted under, and of {@link UNTOUCHED} only `no-focus`: a\n * collected `autofocus` takes focus again. The other three have nothing but a\n * carried script to act on: the printed date and the animation's place are in\n * the document already, its `@media` rules were resolved when it was read, and\n * nothing moves the pointer over it.\n */\nexport const LAYOUT_RECIPE: Recipe = [holdAnimations, hideScrollbars, noFocus, waitForFonts, waitForImages];\n\nexport const RASTER_RECIPE: Recipe = [...LAYOUT_RECIPE, hideCaret];\n\n/**\n * What is applied to a live page *before a subject is observed*, as opposed to\n * before it is painted.\n *\n * The two are different recipes and it is not a preference. {@link\n * holdAnimations} is a *screenshot option* — it asks the browser to settle\n * animations for the image it is about to take — and there is no screenshot at\n * collection time, so it would be a trick that silently does nothing. The CSS\n * variant is the one that works where nobody is holding a camera, which is the\n * whole reason both exist as separate values rather than as one switch.\n *\n * ## Why the cheap tier needs this at all\n *\n * The claim in [`ruleset.ts`](../rules/ruleset.ts) that `transition-*` and\n * `animation-*` \"describe a journey the snapshot does not contain\" is only true\n * if the snapshot is taken with the journey stopped. `transform`, `opacity`,\n * `filter`, `color` and every geometric longhand *are* admitted, and an\n * animation in flight moves all of them — so an unstabilized collection turns a\n * 300ms fade into a component-attributed regression with a real file name on it,\n * which is worse than an unexplained pixel diff because it is credible.\n *\n * Filtered by {@link forTier}, so jsdom applies none of it: with no layout\n * engine and no animation clock there is nothing to hold still, and paying a\n * `fonts.ready` wait per subject on the rung that exists to be cheap is exactly\n * the trade {@link SEMANTIC_RECIPE} refuses.\n */\nexport const COLLECT_RECIPE: Recipe = [\n pinAnimations,\n hideScrollbars,\n // Here as well as in {@link RASTER_RECIPE}, because the in-place path\n // photographs the live page and applies no screenshot options of its own: the\n // only caret hold that reaches that image is one installed here. A subject\n // holding a focused input otherwise disagrees with itself between two\n // screenshots taken 600ms apart, and is refused for blinking.\n hideCaret,\n ...UNTOUCHED,\n waitForFonts,\n waitForImages,\n];\n\n/**\n * The ids of {@link COLLECT_RECIPE}, as an absent `stabilize` means them. A list\n * replaces the recipe, so one trick is turned off with this list without it:\n * `stabilize: DEFAULT_STABILIZE.filter((id) => id !== 'freeze-clock')`.\n */\nexport const DEFAULT_STABILIZE: readonly string[] = COLLECT_RECIPE.map((intervention) => intervention.id);\n\n/**\n * Resolve a trick by the name a caller wrote down.\n *\n * The boundary a collection recipe crosses is a `page.evaluate`, and an\n * `Intervention` does not survive it — `settle` is a function. Ids do survive,\n * and the page holds this same registry, so a recipe travels as the list of\n * names it is. A name nothing answers to is a caller error worth failing on\n * rather than a trick to skip quietly: under-stabilizing is how a suite gets a\n * flake it has already paid to prevent.\n */\nexport function interventionById(id: string): Intervention | undefined {\n return INTERVENTIONS.find((intervention) => intervention.id === id) ?? clockById(id);\n}\n\n/**\n * A recipe from the names it travels as.\n *\n * Throws on a name nothing answers to, and names it. The quiet alternative —\n * skip what cannot be resolved — turns a typo in a config into a suite that is\n * one trick less stable than its operator believes, discovered later as a flake\n * they have already paid to prevent. Failing here costs one run and one reading\n * of the message.\n */\nexport function recipeOf(ids: readonly string[]): Recipe {\n return ids.map((id) => {\n const intervention = interventionById(id);\n if (intervention === undefined) {\n throw new Error(\n `no stabilization trick is called \\`${id}\\`; this build knows ` +\n INTERVENTIONS.map((known) => `\\`${known.id}\\``).join(', ') +\n ', and `freeze-clock@<instant>`',\n );\n }\n return intervention;\n });\n}\n\n/**\n * The recipe a host that drives the browser applies, checked before it opens one:\n * `stabilize` by id, or {@link COLLECT_RECIPE} when it is absent, with its clock\n * fixed at `now`, which travels in the clock's id and lands in the digest. Throws\n * on an unknown id, an instant with no zone, or a `now` with no clock to fix, so\n * the operator hears about it before a page is loaded, not at the first subject.\n */\nexport function recipeToDrive(options: { readonly stabilize?: readonly string[]; readonly now?: string }): Recipe {\n const recipe = options.stabilize === undefined ? COLLECT_RECIPE : recipeOf(options.stabilize);\n if (options.now === undefined) return recipe;\n const clock = freezeClockAt(options.now);\n if (!recipe.some((intervention) => intervention.driver?.clock !== undefined)) {\n throw new Error(\n `\\`now\\` is the instant \\`freeze-clock\\` fixes, and this recipe has no \\`freeze-clock\\`: ` +\n 'add it to `stabilize`, or leave `now` out',\n );\n }\n return recipe.map((intervention) => (intervention.driver?.clock === undefined ? intervention : clock));\n}\n\n/** Only the tricks a tier can observe the effect of. */\nexport function forTier(recipe: Recipe, tier: Tier): Recipe {\n return recipe.filter((intervention) => tierReaches(tier, intervention.needs));\n}\n\n/**\n * Tricks in a recipe that claim the same property.\n *\n * Returned rather than thrown, so a caller can decide — an override is a\n * legitimate composition, and silently applying both is not. Two tricks over one\n * property means one of them wins by accident of ordering, and which one is\n * invisible in the result.\n */\nexport function conflicts(recipe: Recipe): readonly { governs: string; ids: readonly string[] }[] {\n const byProperty = new Map<string, string[]>();\n\n for (const intervention of recipe) {\n byProperty.set(intervention.governs, [\n ...(byProperty.get(intervention.governs) ?? []),\n intervention.id,\n ]);\n }\n\n return [...byProperty.entries()]\n .filter(([, ids]) => ids.length > 1)\n .map(([governs, ids]) => ({ governs, ids }));\n}\n\nexport function recipeCss(recipe: Recipe): string {\n return recipe\n .map((intervention) => intervention.css)\n .filter((css): css is string => css !== undefined)\n .join('\\n');\n}\n\nexport function recipeScreenshot(recipe: Recipe): ScreenshotOptions {\n return recipe.reduce<ScreenshotOptions>(\n (options, intervention) => ({ ...options, ...intervention.screenshot }),\n {},\n );\n}\n\n/**\n * Every wait the recipe holds, in order. Each is one step on `steps`, named by\n * the intervention's id, so a run can say which wait a slow subject spent its\n * time in.\n */\nexport async function settleRecipe(recipe: Recipe, target: SettleTarget, steps?: StepClock): Promise<void> {\n for (const intervention of recipe) {\n const settle = intervention.settle;\n if (settle === undefined) continue;\n await (steps === undefined ? settle(target) : steps.time(intervention.id, async () => settle(target)));\n }\n}\n\n/**\n * The identity of a recipe.\n *\n * Sorted, so the order tricks were composed in does not change the identity —\n * only which ones are present. Folded into `RenderIdentity`, which is what makes\n * a cross-recipe comparison name the recipe as its cause instead of inventing a\n * component to blame.\n */\nexport function recipeDigest(recipe: Recipe): Digest {\n return digestValue(recipe.map((intervention) => intervention.id).sort());\n}\n\n/** The recipe as a sentence, so the gap between image and product stays visible. */\nexport function describeRecipe(recipe: Recipe): string {\n return recipe.length === 0\n ? 'the subject was observed untouched'\n : `the subject was altered to be observable: ${recipe.map((i) => i.because).join('; ')}`;\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long each step of reading one subject took.
|
|
3
|
+
*
|
|
4
|
+
* A step is a span of work the code already brackets as one phase — a
|
|
5
|
+
* navigation, one stabilization wait, the screenshot, the decode — named by the
|
|
6
|
+
* phase's own name. Each owner times only its own steps and hands the rest on
|
|
7
|
+
* as data, so a subject's steps never overlap and never sum to more than what
|
|
8
|
+
* the subject cost. A step that did not run is absent, never a zero: zero means
|
|
9
|
+
* it ran and finished under the clock's resolution.
|
|
10
|
+
*
|
|
11
|
+
* Durations only, on a monotonic clock, and the wall time of the span: with
|
|
12
|
+
* several worlds collecting side by side a step includes what the others cost
|
|
13
|
+
* it, which is what it cost this run. Steps describe a reading and are part of
|
|
14
|
+
* no digest, so a timing can never move an image, a key or a verdict.
|
|
15
|
+
*/
|
|
16
|
+
/** One step of one subject: the phase's own name and how long its span took. */
|
|
17
|
+
export interface Step {
|
|
18
|
+
readonly step: string;
|
|
19
|
+
/** Wall time of the span, in milliseconds, to a tenth. */
|
|
20
|
+
readonly ms: number;
|
|
21
|
+
}
|
|
22
|
+
/** One step over a run: summed over the subjects that ran it, and how many did. */
|
|
23
|
+
export interface StepTotal {
|
|
24
|
+
readonly step: string;
|
|
25
|
+
readonly ms: number;
|
|
26
|
+
readonly subjects: number;
|
|
27
|
+
}
|
|
28
|
+
/** Where one subject's steps are taken, in the order they ran; each owner times its own and passes the clock on. */
|
|
29
|
+
export interface StepClock {
|
|
30
|
+
/** Run `job` as `step`. Taken whether it resolves or throws. */
|
|
31
|
+
time<T>(step: string, job: () => Promise<T> | T): Promise<T>;
|
|
32
|
+
/** Steps another owner timed, appended as they arrive, each name behind `prefix`. */
|
|
33
|
+
add(steps: readonly Step[] | undefined, prefix?: string): void;
|
|
34
|
+
/** The same list, with every name this view takes behind `prefix`. */
|
|
35
|
+
within(prefix: string): StepClock;
|
|
36
|
+
readonly taken: readonly Step[];
|
|
37
|
+
}
|
|
38
|
+
/** `now` is the owner's monotonic clock, in milliseconds: `performance.now` wherever it runs. */
|
|
39
|
+
export declare function stepClock(now: () => number): StepClock;
|
|
40
|
+
/** `job` as `step` on `steps`, or just `job` when nothing is timing it. */
|
|
41
|
+
export declare function timeOn<T>(steps: StepClock | undefined, step: string, job: () => Promise<T> | T): Promise<T>;
|
|
42
|
+
/** Each step's total over every subject that ran it, by name in code-unit order. */
|
|
43
|
+
export declare function totalsOf(subjects: readonly (readonly Step[] | undefined)[]): readonly StepTotal[];
|
|
44
|
+
//# sourceMappingURL=steps.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long each step of reading one subject took.
|
|
3
|
+
*
|
|
4
|
+
* A step is a span of work the code already brackets as one phase — a
|
|
5
|
+
* navigation, one stabilization wait, the screenshot, the decode — named by the
|
|
6
|
+
* phase's own name. Each owner times only its own steps and hands the rest on
|
|
7
|
+
* as data, so a subject's steps never overlap and never sum to more than what
|
|
8
|
+
* the subject cost. A step that did not run is absent, never a zero: zero means
|
|
9
|
+
* it ran and finished under the clock's resolution.
|
|
10
|
+
*
|
|
11
|
+
* Durations only, on a monotonic clock, and the wall time of the span: with
|
|
12
|
+
* several worlds collecting side by side a step includes what the others cost
|
|
13
|
+
* it, which is what it cost this run. Steps describe a reading and are part of
|
|
14
|
+
* no digest, so a timing can never move an image, a key or a verdict.
|
|
15
|
+
*/
|
|
16
|
+
import { codeUnitOrder } from '../segment/index.js';
|
|
17
|
+
/** `now` is the owner's monotonic clock, in milliseconds: `performance.now` wherever it runs. */
|
|
18
|
+
export function stepClock(now) {
|
|
19
|
+
return viewOf([], now, '');
|
|
20
|
+
}
|
|
21
|
+
function viewOf(taken, now, prefix) {
|
|
22
|
+
return {
|
|
23
|
+
async time(step, job) {
|
|
24
|
+
const started = now();
|
|
25
|
+
try {
|
|
26
|
+
return await job();
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
taken.push({ step: prefix + step, ms: tenths(now() - started) });
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
add(steps, more = '') {
|
|
33
|
+
for (const { step, ms } of steps ?? [])
|
|
34
|
+
taken.push({ step: prefix + more + step, ms });
|
|
35
|
+
},
|
|
36
|
+
within(more) {
|
|
37
|
+
return viewOf(taken, now, prefix + more);
|
|
38
|
+
},
|
|
39
|
+
taken,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** `job` as `step` on `steps`, or just `job` when nothing is timing it. */
|
|
43
|
+
export async function timeOn(steps, step, job) {
|
|
44
|
+
return steps === undefined ? job() : steps.time(step, job);
|
|
45
|
+
}
|
|
46
|
+
/** Each step's total over every subject that ran it, by name in code-unit order. */
|
|
47
|
+
export function totalsOf(subjects) {
|
|
48
|
+
const totals = new Map();
|
|
49
|
+
for (const steps of subjects) {
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
for (const { step, ms } of steps ?? []) {
|
|
52
|
+
const total = totals.get(step) ?? { ms: 0, subjects: 0 };
|
|
53
|
+
total.ms += ms;
|
|
54
|
+
if (!seen.has(step))
|
|
55
|
+
total.subjects += 1;
|
|
56
|
+
seen.add(step);
|
|
57
|
+
totals.set(step, total);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return [...totals]
|
|
61
|
+
.sort(([left], [right]) => codeUnitOrder(left, right))
|
|
62
|
+
.map(([step, total]) => ({ step, ms: tenths(total.ms), subjects: total.subjects }));
|
|
63
|
+
}
|
|
64
|
+
function tenths(ms) {
|
|
65
|
+
return Math.round(ms * 10) / 10;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=steps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.js","sourceRoot":"","sources":["../../src/format/steps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AA2BpD,iGAAiG;AACjG,MAAM,UAAU,SAAS,CAAC,GAAiB;IACzC,OAAO,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,MAAM,CAAC,KAAa,EAAE,GAAiB,EAAE,MAAc;IAC9D,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG;YAClB,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC;YACtB,IAAI,CAAC;gBACH,OAAO,MAAM,GAAG,EAAE,CAAC;YACrB,CAAC;oBAAS,CAAC;gBACT,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;QACD,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE;YAClB,KAAK,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,KAAK,IAAI,EAAE;gBAAE,K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,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;SACrD,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;AACxF,CAAC;AAED,SAAS,MAAM,CAAC,EAAU;IACxB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;AAClC,CAAC","sourcesContent":["/**\n * How long each step of reading one subject took.\n *\n * A step is a span of work the code already brackets as one phase — a\n * navigation, one stabilization wait, the screenshot, the decode — named by the\n * phase's own name. Each owner times only its own steps and hands the rest on\n * as data, so a subject's steps never overlap and never sum to more than what\n * the subject cost. A step that did not run is absent, never a zero: zero means\n * it ran and finished under the clock's resolution.\n *\n * Durations only, on a monotonic clock, and the wall time of the span: with\n * several worlds collecting side by side a step includes what the others cost\n * it, which is what it cost this run. Steps describe a reading and are part of\n * no digest, so a timing can never move an image, a key or a verdict.\n */\n\nimport { codeUnitOrder } from '../segment/index.js';\n\n/** One step of one subject: the phase's own name and how long its span took. */\nexport interface Step {\n readonly step: string;\n /** Wall time of the span, in milliseconds, to a tenth. */\n readonly ms: number;\n}\n\n/** One step over a run: summed over the subjects that ran it, and how many did. */\nexport interface StepTotal {\n readonly step: string;\n readonly ms: number;\n readonly subjects: number;\n}\n\n/** Where one subject's steps are taken, in the order they ran; each owner times its own and passes the clock on. */\nexport interface StepClock {\n /** Run `job` as `step`. Taken whether it resolves or throws. */\n time<T>(step: string, job: () => Promise<T> | T): Promise<T>;\n /** Steps another owner timed, appended as they arrive, each name behind `prefix`. */\n add(steps: readonly Step[] | undefined, prefix?: string): void;\n /** The same list, with every name this view takes behind `prefix`. */\n within(prefix: string): StepClock;\n readonly taken: readonly Step[];\n}\n\n/** `now` is the owner's monotonic clock, in milliseconds: `performance.now` wherever it runs. */\nexport function stepClock(now: () => number): StepClock {\n return viewOf([], now, '');\n}\n\nfunction viewOf(taken: Step[], now: () => number, prefix: string): StepClock {\n return {\n async time(step, job) {\n const started = now();\n try {\n return await job();\n } finally {\n taken.push({ step: prefix + step, ms: tenths(now() - started) });\n }\n },\n add(steps, more = '') {\n for (const { step, ms } of steps ?? []) taken.push({ step: prefix + more + step, ms });\n },\n within(more) {\n return viewOf(taken, now, prefix + more);\n },\n taken,\n };\n}\n\n/** `job` as `step` on `steps`, or just `job` when nothing is timing it. */\nexport async function timeOn<T>(\n steps: StepClock | undefined,\n step: string,\n job: () => Promise<T> | T,\n): Promise<T> {\n return steps === undefined ? job() : steps.time(step, job);\n}\n\n/** Each step's total over every subject that ran it, by name in code-unit order. */\nexport function totalsOf(subjects: readonly (readonly Step[] | undefined)[]): readonly StepTotal[] {\n const totals = new Map<string, { ms: number; subjects: number }>();\n for (const steps of subjects) {\n const seen = new Set<string>();\n for (const { step, ms } of steps ?? []) {\n const total = totals.get(step) ?? { ms: 0, subjects: 0 };\n total.ms += ms;\n if (!seen.has(step)) total.subjects += 1;\n seen.add(step);\n totals.set(step, total);\n }\n }\n return [...totals]\n .sort(([left], [right]) => codeUnitOrder(left, right))\n .map(([step, total]) => ({ step, ms: tenths(total.ms), subjects: total.subjects }));\n}\n\nfunction tenths(ms: number): number {\n return Math.round(ms * 10) / 10;\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Intervention } from './intervention.js';
|
|
2
|
+
/**
|
|
3
|
+
* The two tricks that block until something outside the page has landed.
|
|
4
|
+
*
|
|
5
|
+
* Apart from [`stabilize.ts`](./stabilize.ts) because they are the tricks with
|
|
6
|
+
* the most page-side code: each ships a closure into the page, bounds its wait at
|
|
7
|
+
* 15000ms and names what never answered. The rest of the vocabulary is a line of
|
|
8
|
+
* CSS or a screenshot option.
|
|
9
|
+
*/
|
|
10
|
+
export declare const waitForFonts: Intervention;
|
|
11
|
+
export declare const waitForImages: Intervention;
|
|
12
|
+
//# sourceMappingURL=waits.d.ts.map
|