@variance-authority/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/LICENSE +21 -0
  3. package/README.md +169 -0
  4. package/dist/artifact.d.ts +47 -0
  5. package/dist/artifact.js +2 -0
  6. package/dist/artifact.js.map +1 -0
  7. package/dist/attribute/because.d.ts +43 -0
  8. package/dist/attribute/because.js +64 -0
  9. package/dist/attribute/because.js.map +1 -0
  10. package/dist/attribute/boundary.d.ts +191 -0
  11. package/dist/attribute/boundary.js +328 -0
  12. package/dist/attribute/boundary.js.map +1 -0
  13. package/dist/attribute/call-site.d.ts +96 -0
  14. package/dist/attribute/call-site.js +183 -0
  15. package/dist/attribute/call-site.js.map +1 -0
  16. package/dist/attribute/component-hash.d.ts +188 -0
  17. package/dist/attribute/component-hash.js +312 -0
  18. package/dist/attribute/component-hash.js.map +1 -0
  19. package/dist/attribute/composition-fixture.d.ts +18 -0
  20. package/dist/attribute/composition-fixture.js +53 -0
  21. package/dist/attribute/composition-fixture.js.map +1 -0
  22. package/dist/attribute/composition.d.ts +182 -0
  23. package/dist/attribute/composition.js +169 -0
  24. package/dist/attribute/composition.js.map +1 -0
  25. package/dist/attribute/control.d.ts +43 -0
  26. package/dist/attribute/control.js +54 -0
  27. package/dist/attribute/control.js.map +1 -0
  28. package/dist/attribute/coverage.d.ts +99 -0
  29. package/dist/attribute/coverage.js +86 -0
  30. package/dist/attribute/coverage.js.map +1 -0
  31. package/dist/attribute/divergence.d.ts +102 -0
  32. package/dist/attribute/divergence.js +152 -0
  33. package/dist/attribute/divergence.js.map +1 -0
  34. package/dist/attribute/index.d.ts +43 -0
  35. package/dist/attribute/index.js +29 -0
  36. package/dist/attribute/index.js.map +1 -0
  37. package/dist/attribute/instability.d.ts +89 -0
  38. package/dist/attribute/instability.js +183 -0
  39. package/dist/attribute/instability.js.map +1 -0
  40. package/dist/attribute/instances.d.ts +145 -0
  41. package/dist/attribute/instances.js +140 -0
  42. package/dist/attribute/instances.js.map +1 -0
  43. package/dist/attribute/locate.d.ts +22 -0
  44. package/dist/attribute/locate.js +100 -0
  45. package/dist/attribute/locate.js.map +1 -0
  46. package/dist/attribute/mask.d.ts +156 -0
  47. package/dist/attribute/mask.js +201 -0
  48. package/dist/attribute/mask.js.map +1 -0
  49. package/dist/attribute/movement.d.ts +211 -0
  50. package/dist/attribute/movement.js +181 -0
  51. package/dist/attribute/movement.js.map +1 -0
  52. package/dist/attribute/region.d.ts +188 -0
  53. package/dist/attribute/region.js +144 -0
  54. package/dist/attribute/region.js.map +1 -0
  55. package/dist/attribute/source-map.d.ts +98 -0
  56. package/dist/attribute/source-map.js +264 -0
  57. package/dist/attribute/source-map.js.map +1 -0
  58. package/dist/attribute/source.d.ts +77 -0
  59. package/dist/attribute/source.js +95 -0
  60. package/dist/attribute/source.js.map +1 -0
  61. package/dist/attribute/stack.d.ts +80 -0
  62. package/dist/attribute/stack.js +108 -0
  63. package/dist/attribute/stack.js.map +1 -0
  64. package/dist/compare/band.d.ts +85 -0
  65. package/dist/compare/band.js +70 -0
  66. package/dist/compare/band.js.map +1 -0
  67. package/dist/compare/cascade.d.ts +45 -0
  68. package/dist/compare/cascade.js +71 -0
  69. package/dist/compare/cascade.js.map +1 -0
  70. package/dist/compare/derive.d.ts +78 -0
  71. package/dist/compare/derive.js +39 -0
  72. package/dist/compare/derive.js.map +1 -0
  73. package/dist/compare/diff/attribution.d.ts +23 -0
  74. package/dist/compare/diff/attribution.js +244 -0
  75. package/dist/compare/diff/attribution.js.map +1 -0
  76. package/dist/compare/diff/compare-nodes.d.ts +15 -0
  77. package/dist/compare/diff/compare-nodes.js +227 -0
  78. package/dist/compare/diff/compare-nodes.js.map +1 -0
  79. package/dist/compare/diff/components.d.ts +20 -0
  80. package/dist/compare/diff/components.js +76 -0
  81. package/dist/compare/diff/components.js.map +1 -0
  82. package/dist/compare/diff/delta.d.ts +165 -0
  83. package/dist/compare/diff/delta.js +12 -0
  84. package/dist/compare/diff/delta.js.map +1 -0
  85. package/dist/compare/diff/index.d.ts +69 -0
  86. package/dist/compare/diff/index.js +101 -0
  87. package/dist/compare/diff/index.js.map +1 -0
  88. package/dist/compare/diff/match.d.ts +37 -0
  89. package/dist/compare/diff/match.js +167 -0
  90. package/dist/compare/diff/match.js.map +1 -0
  91. package/dist/compare/explain.d.ts +23 -0
  92. package/dist/compare/explain.js +190 -0
  93. package/dist/compare/explain.js.map +1 -0
  94. package/dist/compare/holding-diff.d.ts +25 -0
  95. package/dist/compare/holding-diff.js +74 -0
  96. package/dist/compare/holding-diff.js.map +1 -0
  97. package/dist/compare/impact.d.ts +56 -0
  98. package/dist/compare/impact.js +124 -0
  99. package/dist/compare/impact.js.map +1 -0
  100. package/dist/compare/index.d.ts +30 -0
  101. package/dist/compare/index.js +22 -0
  102. package/dist/compare/index.js.map +1 -0
  103. package/dist/compare/instance.d.ts +30 -0
  104. package/dist/compare/instance.js +145 -0
  105. package/dist/compare/instance.js.map +1 -0
  106. package/dist/compare/observability.d.ts +49 -0
  107. package/dist/compare/observability.js +57 -0
  108. package/dist/compare/observability.js.map +1 -0
  109. package/dist/compare/parting.d.ts +179 -0
  110. package/dist/compare/parting.js +244 -0
  111. package/dist/compare/parting.js.map +1 -0
  112. package/dist/compare/slice.d.ts +74 -0
  113. package/dist/compare/slice.js +79 -0
  114. package/dist/compare/slice.js.map +1 -0
  115. package/dist/compare/value.d.ts +60 -0
  116. package/dist/compare/value.js +111 -0
  117. package/dist/compare/value.js.map +1 -0
  118. package/dist/format/accessibility.d.ts +27 -0
  119. package/dist/format/accessibility.js +17 -0
  120. package/dist/format/accessibility.js.map +1 -0
  121. package/dist/format/canonical.d.ts +38 -0
  122. package/dist/format/canonical.js +65 -0
  123. package/dist/format/canonical.js.map +1 -0
  124. package/dist/format/capture.d.ts +212 -0
  125. package/dist/format/capture.js +2 -0
  126. package/dist/format/capture.js.map +1 -0
  127. package/dist/format/document.d.ts +279 -0
  128. package/dist/format/document.js +65 -0
  129. package/dist/format/document.js.map +1 -0
  130. package/dist/format/environment.d.ts +120 -0
  131. package/dist/format/environment.js +53 -0
  132. package/dist/format/environment.js.map +1 -0
  133. package/dist/format/hash.d.ts +45 -0
  134. package/dist/format/hash.js +41 -0
  135. package/dist/format/hash.js.map +1 -0
  136. package/dist/format/holding.d.ts +134 -0
  137. package/dist/format/holding.js +2 -0
  138. package/dist/format/holding.js.map +1 -0
  139. package/dist/format/index.d.ts +39 -0
  140. package/dist/format/index.js +25 -0
  141. package/dist/format/index.js.map +1 -0
  142. package/dist/format/intervention.d.ts +87 -0
  143. package/dist/format/intervention.js +11 -0
  144. package/dist/format/intervention.js.map +1 -0
  145. package/dist/format/profile.d.ts +59 -0
  146. package/dist/format/profile.js +66 -0
  147. package/dist/format/profile.js.map +1 -0
  148. package/dist/format/provenance.d.ts +179 -0
  149. package/dist/format/provenance.js +222 -0
  150. package/dist/format/provenance.js.map +1 -0
  151. package/dist/format/sha256.d.ts +34 -0
  152. package/dist/format/sha256.js +152 -0
  153. package/dist/format/sha256.js.map +1 -0
  154. package/dist/format/snapshot.d.ts +263 -0
  155. package/dist/format/snapshot.js +2 -0
  156. package/dist/format/snapshot.js.map +1 -0
  157. package/dist/format/stabilize.d.ts +190 -0
  158. package/dist/format/stabilize.js +333 -0
  159. package/dist/format/stabilize.js.map +1 -0
  160. package/dist/format/tier.d.ts +19 -0
  161. package/dist/format/tier.js +11 -0
  162. package/dist/format/tier.js.map +1 -0
  163. package/dist/format/value.d.ts +115 -0
  164. package/dist/format/value.js +182 -0
  165. package/dist/format/value.js.map +1 -0
  166. package/dist/format/wiring.d.ts +115 -0
  167. package/dist/format/wiring.js +60 -0
  168. package/dist/format/wiring.js.map +1 -0
  169. package/dist/index.d.ts +35 -0
  170. package/dist/index.js +35 -0
  171. package/dist/index.js.map +1 -0
  172. package/dist/judge/docket.d.ts +85 -0
  173. package/dist/judge/docket.js +162 -0
  174. package/dist/judge/docket.js.map +1 -0
  175. package/dist/judge/fingerprint.d.ts +53 -0
  176. package/dist/judge/fingerprint.js +144 -0
  177. package/dist/judge/fingerprint.js.map +1 -0
  178. package/dist/judge/ignore.d.ts +206 -0
  179. package/dist/judge/ignore.js +237 -0
  180. package/dist/judge/ignore.js.map +1 -0
  181. package/dist/judge/index.d.ts +44 -0
  182. package/dist/judge/index.js +34 -0
  183. package/dist/judge/index.js.map +1 -0
  184. package/dist/judge/inspect.d.ts +148 -0
  185. package/dist/judge/inspect.js +208 -0
  186. package/dist/judge/inspect.js.map +1 -0
  187. package/dist/judge/intent.d.ts +146 -0
  188. package/dist/judge/intent.js +150 -0
  189. package/dist/judge/intent.js.map +1 -0
  190. package/dist/judge/locale.d.ts +111 -0
  191. package/dist/judge/locale.js +247 -0
  192. package/dist/judge/locale.js.map +1 -0
  193. package/dist/judge/scope.d.ts +41 -0
  194. package/dist/judge/scope.js +47 -0
  195. package/dist/judge/scope.js.map +1 -0
  196. package/dist/judge/sensitivity.d.ts +202 -0
  197. package/dist/judge/sensitivity.js +152 -0
  198. package/dist/judge/sensitivity.js.map +1 -0
  199. package/dist/judge/trail.d.ts +122 -0
  200. package/dist/judge/trail.js +96 -0
  201. package/dist/judge/trail.js.map +1 -0
  202. package/dist/judge/verdict.d.ts +39 -0
  203. package/dist/judge/verdict.js +32 -0
  204. package/dist/judge/verdict.js.map +1 -0
  205. package/dist/plan/index.d.ts +12 -0
  206. package/dist/plan/index.js +11 -0
  207. package/dist/plan/index.js.map +1 -0
  208. package/dist/plan/tool.d.ts +85 -0
  209. package/dist/plan/tool.js +87 -0
  210. package/dist/plan/tool.js.map +1 -0
  211. package/dist/relate/graph.d.ts +190 -0
  212. package/dist/relate/graph.js +234 -0
  213. package/dist/relate/graph.js.map +1 -0
  214. package/dist/relate/index.d.ts +16 -0
  215. package/dist/relate/index.js +16 -0
  216. package/dist/relate/index.js.map +1 -0
  217. package/dist/relate/merkle.d.ts +110 -0
  218. package/dist/relate/merkle.js +246 -0
  219. package/dist/relate/merkle.js.map +1 -0
  220. package/dist/relate/reach.d.ts +65 -0
  221. package/dist/relate/reach.js +111 -0
  222. package/dist/relate/reach.js.map +1 -0
  223. package/dist/relate/records.d.ts +129 -0
  224. package/dist/relate/records.js +112 -0
  225. package/dist/relate/records.js.map +1 -0
  226. package/dist/rules/index.d.ts +19 -0
  227. package/dist/rules/index.js +17 -0
  228. package/dist/rules/index.js.map +1 -0
  229. package/dist/rules/normalize/alias.d.ts +50 -0
  230. package/dist/rules/normalize/alias.js +111 -0
  231. package/dist/rules/normalize/alias.js.map +1 -0
  232. package/dist/rules/normalize/cascade.d.ts +85 -0
  233. package/dist/rules/normalize/cascade.js +324 -0
  234. package/dist/rules/normalize/cascade.js.map +1 -0
  235. package/dist/rules/normalize/color.d.ts +30 -0
  236. package/dist/rules/normalize/color.js +185 -0
  237. package/dist/rules/normalize/color.js.map +1 -0
  238. package/dist/rules/normalize/fixture.d.ts +83 -0
  239. package/dist/rules/normalize/fixture.js +74 -0
  240. package/dist/rules/normalize/fixture.js.map +1 -0
  241. package/dist/rules/normalize/index.d.ts +39 -0
  242. package/dist/rules/normalize/index.js +268 -0
  243. package/dist/rules/normalize/index.js.map +1 -0
  244. package/dist/rules/normalize/project.d.ts +42 -0
  245. package/dist/rules/normalize/project.js +83 -0
  246. package/dist/rules/normalize/project.js.map +1 -0
  247. package/dist/rules/normalize/shorthand.d.ts +38 -0
  248. package/dist/rules/normalize/shorthand.js +388 -0
  249. package/dist/rules/normalize/shorthand.js.map +1 -0
  250. package/dist/rules/normalize/value.d.ts +23 -0
  251. package/dist/rules/normalize/value.js +162 -0
  252. package/dist/rules/normalize/value.js.map +1 -0
  253. package/dist/rules/normalize/wrapper.d.ts +16 -0
  254. package/dist/rules/normalize/wrapper.js +137 -0
  255. package/dist/rules/normalize/wrapper.js.map +1 -0
  256. package/dist/rules/ruleset.d.ts +93 -0
  257. package/dist/rules/ruleset.js +175 -0
  258. package/dist/rules/ruleset.js.map +1 -0
  259. package/mark.svg +30 -0
  260. package/package.json +69 -0
@@ -0,0 +1,333 @@
1
+ import { digestValue } from './hash.js';
2
+ import { tierReaches } from './tier.js';
3
+ /**
4
+ * Hand animations to the browser rather than emulating the hold in CSS.
5
+ *
6
+ * A browser disabling animations for a screenshot fast-forwards a finite
7
+ * animation to completion — the state a user comes to rest on — and cancels an
8
+ * infinite one to its initial frame, replaying it afterwards. That is the
9
+ * behaviour worth having, and CSS cannot express it.
10
+ */
11
+ export const holdAnimations = {
12
+ id: 'hold-animations',
13
+ trick: 'hold',
14
+ needs: 'layout',
15
+ governs: 'animations',
16
+ because: 'animations settled by the browser: finite fast-forwarded, infinite reset',
17
+ screenshot: { animations: 'disabled' },
18
+ };
19
+ /**
20
+ * The same intent without a browser that can do it, and it is not equivalent.
21
+ *
22
+ * Pins every animation at its first frame, so a fade-in is captured at the
23
+ * moment it is invisible. `animation: none` is avoided deliberately — removing
24
+ * an animation drops whatever layout its keyframes contribute, which changes the
25
+ * page rather than stopping it.
26
+ */
27
+ export const pinAnimations = {
28
+ id: 'pin-animations',
29
+ trick: 'hold',
30
+ needs: 'layout',
31
+ governs: 'animations',
32
+ because: 'animations pinned at their first frame, which is not where a user sees them',
33
+ css: '*,*::before,*::after{' +
34
+ 'animation-play-state:paused !important;' +
35
+ 'animation-delay:-0.0001s !important;' +
36
+ 'transition-duration:0s !important;' +
37
+ 'transition-delay:0s !important;' +
38
+ 'scroll-behavior:auto !important}',
39
+ };
40
+ export const hideCaret = {
41
+ id: 'hide-caret',
42
+ trick: 'support',
43
+ // A caret paints and does not lay out, so a tier that never rasterizes cannot
44
+ // see it and must not pay to hide it.
45
+ needs: 'raster',
46
+ governs: 'caret',
47
+ because: 'text caret hidden, because it blinks on its own schedule',
48
+ screenshot: { caret: 'hide' },
49
+ };
50
+ export const hideScrollbars = {
51
+ id: 'hide-scrollbars',
52
+ trick: 'support',
53
+ needs: 'layout',
54
+ governs: 'scrollbars',
55
+ because: 'scrollbars hidden, removing a platform and preference difference — and their width',
56
+ css: '*{scrollbar-width:none !important}\n*::-webkit-scrollbar{display:none !important}',
57
+ };
58
+ /**
59
+ * Drop the pixels of images the page itself called decorative, keeping their boxes.
60
+ *
61
+ * The other half of blanking, and it lives here because of what it needs to
62
+ * know. A driver rewriting responses (`@variance-authority/playwright`'s
63
+ * `blank` rules) can decide by URL and by intrinsic size, which answers "every
64
+ * illustration over 40,000 pixels" and answers it before the bytes are even
65
+ * fetched. It cannot answer `role="presentation"`, because a request carries no
66
+ * idea which element wanted it — that fact exists only in the document, so the
67
+ * trick that uses it is a stylesheet.
68
+ *
69
+ * `visibility:hidden` rather than `display:none`, and the distinction is the
70
+ * entire design: a hidden element still occupies exactly the box it would have,
71
+ * so a page whose column height comes from an image's intrinsic size is
72
+ * unchanged. `display:none` would collapse it and report a layout regression
73
+ * this tool caused.
74
+ *
75
+ * **Opt-in, and it belongs in no default recipe.** Every other trick here
76
+ * removes something that is not part of the assertion — a caret, a scrollbar, an
77
+ * animation mid-flight. This one removes page content, which is a judgement
78
+ * about what a suite is for, and a default that quietly stopped watching every
79
+ * `alt=""` image would hide real regressions under a green run.
80
+ */
81
+ export const hidePresentationalImages = {
82
+ id: 'hide-presentational-images',
83
+ trick: 'support',
84
+ // `layout` rather than `raster`, and the difference is whether it runs at all.
85
+ // A raster-tier trick is filtered out of every *collection* — `tierOfProfile`
86
+ // never returns `raster` — so it would only reach a page through a renderer
87
+ // option, which is not where an operator configures their suite. A collection
88
+ // sheet is in force when the document is serialized, so hiding it here is what
89
+ // makes the pixels absent from the render.
90
+ needs: 'layout',
91
+ governs: 'presentational-images',
92
+ because: 'images the page marked decorative hidden, keeping their boxes — real changes inside them ' +
93
+ 'are not reported',
94
+ css: 'img[role="presentation"],img[alt=""],[role="presentation"] img,[role="none"] img' +
95
+ '{visibility:hidden !important}',
96
+ };
97
+ export const waitForFonts = {
98
+ id: 'wait-for-fonts',
99
+ trick: 'wait',
100
+ needs: 'layout',
101
+ governs: 'fonts',
102
+ because: 'waited for web fonts, whose advances change every metric on the page',
103
+ // Written without a module-scope helper on purpose: a settle closure is
104
+ // shipped to a page as source text, so anything it names by identifier is a
105
+ // `ReferenceError` on the far side. Types are erased and therefore free.
106
+ settle: async (target) => {
107
+ await target.evaluate(async () => {
108
+ const view = globalThis;
109
+ await view.document.fonts?.ready;
110
+ });
111
+ },
112
+ };
113
+ export const waitForImages = {
114
+ id: 'wait-for-images',
115
+ trick: 'wait',
116
+ needs: 'layout',
117
+ governs: 'images',
118
+ because: 'waited for images to decode, since their intrinsic size participates in layout, and asked ' +
119
+ 'for the ones the browser had deferred',
120
+ settle: async (target) => {
121
+ await target.evaluate(async () => {
122
+ const view = globalThis;
123
+ const pending = Array.from(view.document.images).filter((image) => !image.complete);
124
+ const arrived = Promise.all(pending.map((image) => new Promise((resolve) => {
125
+ image.addEventListener('load', () => resolve(), { once: true });
126
+ image.addEventListener('error', () => resolve(), { once: true });
127
+ })));
128
+ // Asked for, after the listeners are attached and before anything is
129
+ // awaited. A `loading="lazy"` image outside the viewport has not been
130
+ // requested and will not be until something scrolls, so waiting on it is
131
+ // waiting for a decision the browser has already taken the other way.
132
+ //
133
+ // This is the same act as pinning an animation, not a different kind of
134
+ // thing: what the page shows stops depending on where the viewport
135
+ // happens to be. It matters most for the readings that need it most — a
136
+ // full-page capture of a long page is exactly the case where most of the
137
+ // images are deferred, and photographing it without them yields a picture
138
+ // full of empty boxes whose contents change with the browser's loading
139
+ // heuristics rather than with the product.
140
+ const asServed = pending.map((image) => image.loading);
141
+ for (const image of pending)
142
+ image.loading = 'eager';
143
+ // Bounded, and it throws when the bound is reached.
144
+ //
145
+ // A response can stall: a CDN that never answers, an image endpoint that
146
+ // deadlocks under its own concurrency, an image the browser deferred and
147
+ // will not request from where the page is scrolled. None of those fire
148
+ // `load` and none fire `error`, so an unbounded wait turns one stuck
149
+ // request into a run that never ends and never says why — not a wrong
150
+ // answer, no answer.
151
+ //
152
+ // Giving up quietly would be worse than the hang in a subtler way: it
153
+ // photographs a page with holes in it and reports the holes as a change,
154
+ // inventing a regression out of the network this trick exists to hold
155
+ // still. Refused instead, naming what it was still waiting for, because
156
+ // "these two never answered" is a finding about the application.
157
+ //
158
+ // The bound is written twice — once as the delay, once in the sentence —
159
+ // because a settle closure is shipped to the page as source text and a
160
+ // constant it named would be a `ReferenceError` on the far side.
161
+ // Held so the loser can be cancelled. A timer left to fire after the
162
+ // images arrived rejects a promise nothing is waiting on any more, which
163
+ // the page reports as an unhandled rejection — this trick's own noise,
164
+ // arriving in the console of every subject it succeeded on.
165
+ let timer;
166
+ const expired = new Promise((_, reject) => {
167
+ timer = view.setTimeout(() => {
168
+ const stuck = pending.filter((image) => !image.complete);
169
+ reject(new Error(`${stuck.length} image(s) had not loaded after 15000ms, and neither answered ` +
170
+ `nor failed: ${stuck.map((image) => image.currentSrc || image.src).join(', ')}`));
171
+ }, 15000);
172
+ });
173
+ try {
174
+ await Promise.race([arrived, expired]);
175
+ }
176
+ finally {
177
+ view.clearTimeout(timer);
178
+ // Put back, because the trick has to be invisible to the tier that
179
+ // reads the page after it. `loading` is a reflected attribute, so a
180
+ // document whose deferred images were switched to `eager` and left that
181
+ // way is a document that no longer matches the one the product served —
182
+ // and which images were still undecoded when this ran is a question
183
+ // about the network, so the edit lands in some readings and not others.
184
+ // Left in, it makes the same page at two widths disagree about its own
185
+ // markup: this trick filed as a finding against the application.
186
+ for (let index = 0; index < pending.length; index += 1) {
187
+ pending[index].loading = asServed[index];
188
+ }
189
+ }
190
+ });
191
+ },
192
+ };
193
+ export const INTERVENTIONS = [
194
+ holdAnimations,
195
+ pinAnimations,
196
+ hideCaret,
197
+ hideScrollbars,
198
+ hidePresentationalImages,
199
+ waitForFonts,
200
+ waitForImages,
201
+ ];
202
+ /**
203
+ * Nothing at all, and correct for the tier that reads structure and declared style.
204
+ *
205
+ * A font that has not loaded cannot change which rules match or what they
206
+ * declare; an image that has not decoded cannot either. Waiting for both before
207
+ * a structure-and-style hash buys nothing and costs the wait per subject, on the
208
+ * rung the tier ladder exists to make cheap.
209
+ */
210
+ export const SEMANTIC_RECIPE = [];
211
+ export const LAYOUT_RECIPE = [holdAnimations, hideScrollbars, waitForFonts, waitForImages];
212
+ export const RASTER_RECIPE = [...LAYOUT_RECIPE, hideCaret];
213
+ /**
214
+ * What is applied to a live page *before a subject is observed*, as opposed to
215
+ * before it is painted.
216
+ *
217
+ * The two are different recipes and it is not a preference. {@link
218
+ * holdAnimations} is a *screenshot option* — it asks the browser to settle
219
+ * animations for the image it is about to take — and there is no screenshot at
220
+ * collection time, so it would be a trick that silently does nothing. The CSS
221
+ * variant is the one that works where nobody is holding a camera, which is the
222
+ * whole reason both exist as separate values rather than as one switch.
223
+ *
224
+ * ## Why the cheap tier needs this at all
225
+ *
226
+ * The claim in [`ruleset.ts`](../rules/ruleset.ts) that `transition-*` and
227
+ * `animation-*` "describe a journey the snapshot does not contain" is only true
228
+ * if the snapshot is taken with the journey stopped. `transform`, `opacity`,
229
+ * `filter`, `color` and every geometric longhand *are* admitted, and an
230
+ * animation in flight moves all of them — so an unstabilized collection turns a
231
+ * 300ms fade into a component-attributed regression with a real file name on it,
232
+ * which is worse than an unexplained pixel diff because it is credible.
233
+ *
234
+ * Filtered by {@link forTier}, so jsdom applies none of it: with no layout
235
+ * engine and no animation clock there is nothing to hold still, and paying a
236
+ * `fonts.ready` wait per subject on the rung that exists to be cheap is exactly
237
+ * the trade {@link SEMANTIC_RECIPE} refuses.
238
+ */
239
+ export const COLLECT_RECIPE = [
240
+ pinAnimations,
241
+ hideScrollbars,
242
+ waitForFonts,
243
+ waitForImages,
244
+ ];
245
+ /**
246
+ * Resolve a trick by the name a caller wrote down.
247
+ *
248
+ * The boundary a collection recipe crosses is a `page.evaluate`, and an
249
+ * `Intervention` does not survive it — `settle` is a function. Ids do survive,
250
+ * and the page holds this same registry, so a recipe travels as the list of
251
+ * names it is. A name nothing answers to is a caller error worth failing on
252
+ * rather than a trick to skip quietly: under-stabilizing is how a suite gets a
253
+ * flake it has already paid to prevent.
254
+ */
255
+ export function interventionById(id) {
256
+ return INTERVENTIONS.find((intervention) => intervention.id === id);
257
+ }
258
+ /**
259
+ * A recipe from the names it travels as.
260
+ *
261
+ * Throws on a name nothing answers to, and names it. The quiet alternative —
262
+ * skip what cannot be resolved — turns a typo in a config into a suite that is
263
+ * one trick less stable than its operator believes, discovered later as a flake
264
+ * they have already paid to prevent. Failing here costs one run and one reading
265
+ * of the message.
266
+ */
267
+ export function recipeOf(ids) {
268
+ return ids.map((id) => {
269
+ const intervention = interventionById(id);
270
+ if (intervention === undefined) {
271
+ throw new Error(`no stabilization trick is called \`${id}\`; this build knows ` +
272
+ INTERVENTIONS.map((known) => `\`${known.id}\``).join(', '));
273
+ }
274
+ return intervention;
275
+ });
276
+ }
277
+ /** Only the tricks a tier can observe the effect of. */
278
+ export function forTier(recipe, tier) {
279
+ return recipe.filter((intervention) => tierReaches(tier, intervention.needs));
280
+ }
281
+ /**
282
+ * Tricks in a recipe that claim the same property.
283
+ *
284
+ * Returned rather than thrown, so a caller can decide — an override is a
285
+ * legitimate composition, and silently applying both is not. Two tricks over one
286
+ * property means one of them wins by accident of ordering, and which one is
287
+ * invisible in the result.
288
+ */
289
+ export function conflicts(recipe) {
290
+ const byProperty = new Map();
291
+ for (const intervention of recipe) {
292
+ byProperty.set(intervention.governs, [
293
+ ...(byProperty.get(intervention.governs) ?? []),
294
+ intervention.id,
295
+ ]);
296
+ }
297
+ return [...byProperty.entries()]
298
+ .filter(([, ids]) => ids.length > 1)
299
+ .map(([governs, ids]) => ({ governs, ids }));
300
+ }
301
+ export function recipeCss(recipe) {
302
+ return recipe
303
+ .map((intervention) => intervention.css)
304
+ .filter((css) => css !== undefined)
305
+ .join('\n');
306
+ }
307
+ export function recipeScreenshot(recipe) {
308
+ return recipe.reduce((options, intervention) => ({ ...options, ...intervention.screenshot }), {});
309
+ }
310
+ export async function settleRecipe(recipe, target) {
311
+ for (const intervention of recipe) {
312
+ if (intervention.settle !== undefined)
313
+ await intervention.settle(target);
314
+ }
315
+ }
316
+ /**
317
+ * The identity of a recipe.
318
+ *
319
+ * Sorted, so the order tricks were composed in does not change the identity —
320
+ * only which ones are present. Folded into `RenderIdentity`, which is what makes
321
+ * a cross-recipe comparison report `incomparable` instead of inventing a
322
+ * component to blame.
323
+ */
324
+ export function recipeDigest(recipe) {
325
+ return digestValue(recipe.map((intervention) => intervention.id).sort());
326
+ }
327
+ /** The recipe as a sentence, so the gap between image and product stays visible. */
328
+ export function describeRecipe(recipe) {
329
+ return recipe.length === 0
330
+ ? 'the subject was observed untouched'
331
+ : `the subject was altered to be observable: ${recipe.map((i) => i.because).join('; ')}`;
332
+ }
333
+ //# sourceMappingURL=stabilize.js.map
@@ -0,0 +1 @@
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;AA0DnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAiB;IAC1C,EAAE,EAAE,iBAAiB;IACrB,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,0EAA0E;IACnF,UAAU,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE;CACvC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAiB;IACzC,EAAE,EAAE,gBAAgB;IACpB,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,6EAA6E;IACtF,GAAG,EACD,uBAAuB;QACvB,yCAAyC;QACzC,sCAAsC;QACtC,oCAAoC;QACpC,iCAAiC;QACjC,kCAAkC;CACrC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAiB;IACrC,EAAE,EAAE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C,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,YAAY,CAAC,UAAU,EAAE,CAAC,EACvE,EAAE,CACH,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAc,EAAE,MAAoB;IACrE,KAAK,MAAM,YAAY,IAAI,MAAM,EAAE,CAAC;QAClC,IAAI,YAAY,CAAC,MAAM,KAAK,SAAS;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\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 screenshot: { caret: 'hide' },\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 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"]}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The cheapest representation that can answer a question.
3
+ *
4
+ * Ordered, and the order is the cost. Everything in this project that says "do
5
+ * not pay for what this rung cannot observe" says it with this type: a tool
6
+ * declares the rung it needs and a plan running lower is told which of its tools
7
+ * cannot do their job; a stabilization trick declares the rung that can observe
8
+ * what it fixes, so the structure-and-style rung waits for no fonts.
9
+ *
10
+ * It lives in `format` rather than in `plan` because two different groups need
11
+ * it and `format` is the one both may depend on. It was in `plan` until
12
+ * 2026-08-06, when the stabilization vocabulary moved into `format` and brought
13
+ * a second, separately-declared four-value union with it — two copies of a
14
+ * ladder that must not drift.
15
+ */
16
+ export type Tier = 'reachability' | 'semantic' | 'layout' | 'raster';
17
+ /** Whether a rung can observe what something declaring `needs` requires. */
18
+ export declare function tierReaches(available: Tier, needs: Tier): boolean;
19
+ //# sourceMappingURL=tier.d.ts.map
@@ -0,0 +1,11 @@
1
+ const TIER_ORDER = {
2
+ reachability: 0,
3
+ semantic: 1,
4
+ layout: 2,
5
+ raster: 3,
6
+ };
7
+ /** Whether a rung can observe what something declaring `needs` requires. */
8
+ export function tierReaches(available, needs) {
9
+ return TIER_ORDER[needs] <= TIER_ORDER[available];
10
+ }
11
+ //# sourceMappingURL=tier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tier.js","sourceRoot":"","sources":["../../src/format/tier.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,GAAyB;IACvC,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,CAAC;IACX,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;CACV,CAAC;AAEF,4EAA4E;AAC5E,MAAM,UAAU,WAAW,CAAC,SAAe,EAAE,KAAW;IACtD,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/**\n * The cheapest representation that can answer a question.\n *\n * Ordered, and the order is the cost. Everything in this project that says \"do\n * not pay for what this rung cannot observe\" says it with this type: a tool\n * declares the rung it needs and a plan running lower is told which of its tools\n * cannot do their job; a stabilization trick declares the rung that can observe\n * what it fixes, so the structure-and-style rung waits for no fonts.\n *\n * It lives in `format` rather than in `plan` because two different groups need\n * it and `format` is the one both may depend on. It was in `plan` until\n * 2026-08-06, when the stabilization vocabulary moved into `format` and brought\n * a second, separately-declared four-value union with it — two copies of a\n * ladder that must not drift.\n */\nexport type Tier = 'reachability' | 'semantic' | 'layout' | 'raster';\n\nconst TIER_ORDER: Record<Tier, number> = {\n reachability: 0,\n semantic: 1,\n layout: 2,\n raster: 3,\n};\n\n/** Whether a rung can observe what something declaring `needs` requires. */\nexport function tierReaches(available: Tier, needs: Tier): boolean {\n return TIER_ORDER[needs] <= TIER_ORDER[available];\n}\n"]}
@@ -0,0 +1,115 @@
1
+ import { type Digest } from './hash.js';
2
+ /**
3
+ * A value that was never rendered, as something a run can compare (spec 0031).
4
+ *
5
+ * The third material. It carries **text**, not a parse tree, for the reason the
6
+ * raster arm carries bytes: every reader that understands a dialect is somebody
7
+ * else's dependency, `core` carries none, and a stored parse is a parse that
8
+ * reader's next version disagrees with. The text is what the digest was taken
9
+ * over, what a baseline holds, and what a person reads in a pull request.
10
+ *
11
+ * The canonical form is `canonicalize`, unchanged and unwrapped — sorted keys,
12
+ * portable number formatting, `undefined` omitted rather than nulled, and a
13
+ * refusal on a non-finite number. What this module adds is the *shaping* that
14
+ * has to happen before it, because two of the three rules below decide whether
15
+ * the comparison downstream is readable or useless.
16
+ */
17
+ /**
18
+ * The version of the shaping rules, and part of every value digest.
19
+ *
20
+ * Bumping it invalidates stored value baselines deliberately: a text produced
21
+ * under different rules is not the same reading of the same subject, and a
22
+ * digest that could not tell the difference would report a rule change as a
23
+ * subject that did not move.
24
+ */
25
+ export declare const VALUE_RECIPE = "value/1";
26
+ /** What a dropped value becomes. Present in the text, never compared. */
27
+ export declare const DROPPED = "[dropped]";
28
+ /** What a value capture looks like once it has been shaped. */
29
+ export interface CapturedValue {
30
+ /** How to read the text: `json`, `openapi`, `graphql`, `route-table`. */
31
+ readonly dialect: string;
32
+ /** The canonical serialization — byte for byte what the digest was taken over. */
33
+ readonly text: string;
34
+ readonly digest: Digest;
35
+ /** The shaping rules this text was produced under. {@link VALUE_RECIPE}. */
36
+ readonly recipe: string;
37
+ /**
38
+ * The arrays this text was keyed by, as wildcarded pointers.
39
+ *
40
+ * A keyed array is an object whose members are named by a row's identity, so
41
+ * `/rows/checkout` is a *row* and `/rows/total` might not be. Carried because
42
+ * nothing downstream can tell those apart by looking, and a comparison that
43
+ * guessed would either group two unrelated members or fail to group the same
44
+ * edit made to two rows.
45
+ */
46
+ readonly keyed?: readonly string[];
47
+ /** What emitted it. The environment key for this material, when there is one. */
48
+ readonly generator?: {
49
+ readonly name: string;
50
+ readonly version: string;
51
+ };
52
+ }
53
+ /**
54
+ * What to do to a value before it is canonicalized.
55
+ *
56
+ * Every key is a JSON Pointer (RFC 6901) into the value. A `-` token matches any
57
+ * array index, so `/items/-/updatedAt` names that member of every item — the
58
+ * concrete pointer and the wildcarded one are both offered to the rules, so a
59
+ * literal `/items/0/updatedAt` still names exactly one.
60
+ */
61
+ export interface ValueShaping {
62
+ /**
63
+ * Paths whose values are volatile.
64
+ *
65
+ * Recorded as {@link DROPPED} rather than removed, because *this key is here
66
+ * and I chose not to look at it* and *this key is gone* are different facts and
67
+ * a comparison must not collapse them.
68
+ */
69
+ readonly drop?: readonly string[];
70
+ /** Paths whose values become a stable token of the adopter's choosing. */
71
+ readonly replace?: Readonly<Record<string, string>>;
72
+ /**
73
+ * For an array of records, the member that identifies a row.
74
+ *
75
+ * Load-bearing, and not a convenience. An array compared by index reports a row
76
+ * inserted at the top of a two-thousand-row list as two thousand rows having
77
+ * changed — the same failure as forty red screenshots for one edit, in a medium
78
+ * where nobody can see it at a glance. Keyed, the array becomes an object, so
79
+ * order stops being a fact about it and an insertion is one addition.
80
+ */
81
+ readonly arrayKey?: Readonly<Record<string, string>>;
82
+ }
83
+ export interface ShapeValueOptions extends ValueShaping {
84
+ /** Defaults to `json`. */
85
+ readonly dialect?: string;
86
+ readonly generator?: {
87
+ readonly name: string;
88
+ readonly version: string;
89
+ };
90
+ }
91
+ /**
92
+ * Shape a value, canonicalize it, and address it by content.
93
+ *
94
+ * Throws on anything that cannot be a value rather than encoding it: a function,
95
+ * a `Date`, a `bigint`, a non-finite number. Each refusal names the JSON Pointer
96
+ * where it was found, because the alternative — `JSON.stringify`'s — is to drop
97
+ * a function silently, which reads downstream as a key that was removed.
98
+ */
99
+ export declare function shapeValue(value: unknown, options?: ShapeValueOptions): CapturedValue;
100
+ /** RFC 6901: `~` becomes `~0` and `/` becomes `~1`, in that order. */
101
+ export declare function pointerToken(token: string): string;
102
+ /**
103
+ * The pointer with every row identity replaced by `-`.
104
+ *
105
+ * Two things: it is what a wildcard rule is matched against, and it is what a
106
+ * change's fingerprint is taken over — so the same kind of edit at row 4 and at
107
+ * row 900 is one shape happening twice rather than two findings.
108
+ *
109
+ * An index is a row identity by spelling. A **keyed** array's members are named
110
+ * instead, and no spelling can distinguish those from an ordinary object's keys —
111
+ * so `keyed` is passed in from the capture that declared it, and only the segment
112
+ * immediately below a keyed array is wildcarded.
113
+ */
114
+ export declare function pointerShape(pointer: string, keyed?: readonly string[]): string;
115
+ //# sourceMappingURL=value.d.ts.map