pi-pocket 0.26.0 → 0.27.0-beta.2

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 (186) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/docs/design/design-system.md +165 -0
  3. package/docs/design/ds-notes-b.md +61 -0
  4. package/docs/design/ds-notes-g.md +170 -0
  5. package/docs/design/ds-notes-t.md +303 -0
  6. package/docs/design/ds-notes-u.md +220 -0
  7. package/docs/design/ds-notes-v.md +186 -0
  8. package/docs/design/ds-rounds.md +160 -0
  9. package/docs/design/ds-u-bridge.patch +732 -0
  10. package/docs/examples/design-system/README.md +15 -0
  11. package/docs/examples/design-system/pocket/.pi/design/components/badge.html +112 -0
  12. package/docs/examples/design-system/pocket/.pi/design/components/button.html +203 -0
  13. package/docs/examples/design-system/pocket/.pi/design/components/card.html +125 -0
  14. package/docs/examples/design-system/pocket/.pi/design/components/code-block.html +155 -0
  15. package/docs/examples/design-system/pocket/.pi/design/components/input.html +156 -0
  16. package/docs/examples/design-system/pocket/.pi/design/components/menu-row.html +167 -0
  17. package/docs/examples/design-system/pocket/.pi/design/components/notice.html +171 -0
  18. package/docs/examples/design-system/pocket/.pi/design/components/segmented.html +120 -0
  19. package/docs/examples/design-system/pocket/.pi/design/components/switch.html +117 -0
  20. package/docs/examples/design-system/pocket/.pi/design/components/tool-step.html +163 -0
  21. package/docs/examples/design-system/pocket/.pi/design/dist/components.css +730 -0
  22. package/docs/examples/design-system/pocket/.pi/design/dist/names.md +495 -0
  23. package/docs/examples/design-system/pocket/.pi/design/dist/tailwind.css +1132 -0
  24. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.css +1126 -0
  25. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.dark.resolved.json +2022 -0
  26. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.high-contrast.resolved.json +2022 -0
  27. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.light.resolved.json +2022 -0
  28. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.resolved.json +371 -0
  29. package/docs/examples/design-system/pocket/.pi/design/dist/tokens.studio.json +5915 -0
  30. package/docs/examples/design-system/pocket/.pi/design/guidelines.md +81 -0
  31. package/docs/examples/design-system/pocket/.pi/design/tokens.dark.json +182 -0
  32. package/docs/examples/design-system/pocket/.pi/design/tokens.high-contrast.json +185 -0
  33. package/docs/examples/design-system/pocket/.pi/design/tokens.json +2034 -0
  34. package/docs/features.md +6 -2
  35. package/docs/index.md +1 -0
  36. package/docs/map.md +34 -25
  37. package/docs/release-notes.md +1 -1
  38. package/docs/releases.md +45 -0
  39. package/package.json +2 -1
  40. package/src/server/design/check-cli.ts +283 -0
  41. package/src/server/design/color.ts +654 -0
  42. package/src/server/design/components.ts +328 -0
  43. package/src/server/design/docsite-assets.ts +29 -0
  44. package/src/server/design/docsite-color-section.ts +366 -0
  45. package/src/server/design/docsite-color.ts +303 -0
  46. package/src/server/design/docsite-components.ts +89 -0
  47. package/src/server/design/docsite-core.ts +634 -0
  48. package/src/server/design/docsite-css-base.ts +397 -0
  49. package/src/server/design/docsite-css-content.ts +477 -0
  50. package/src/server/design/docsite-css-phone.ts +251 -0
  51. package/src/server/design/docsite-css-reference.ts +374 -0
  52. package/src/server/design/docsite-css-specimens.ts +465 -0
  53. package/src/server/design/docsite-js-code.ts +96 -0
  54. package/src/server/design/docsite-js-core.ts +72 -0
  55. package/src/server/design/docsite-js-demos.ts +24 -0
  56. package/src/server/design/docsite-js-links.ts +25 -0
  57. package/src/server/design/docsite-js-nav.ts +73 -0
  58. package/src/server/design/docsite-js-stages.ts +81 -0
  59. package/src/server/design/docsite-js-table.ts +81 -0
  60. package/src/server/design/docsite-markdown.ts +221 -0
  61. package/src/server/design/docsite-motion.ts +110 -0
  62. package/src/server/design/docsite-reference.ts +269 -0
  63. package/src/server/design/docsite-sanitize.ts +193 -0
  64. package/src/server/design/docsite-shadows.ts +45 -0
  65. package/src/server/design/docsite-space.ts +289 -0
  66. package/src/server/design/docsite-type.ts +167 -0
  67. package/src/server/design/docsite.ts +508 -0
  68. package/src/server/design/export.ts +86 -9
  69. package/src/server/design/fix.ts +666 -0
  70. package/src/server/design/guide.ts +137 -22
  71. package/src/server/design/index.ts +368 -15
  72. package/src/server/design/lint-color.ts +293 -0
  73. package/src/server/design/lint-page-checks.ts +204 -0
  74. package/src/server/design/lint-page-elements.ts +252 -0
  75. package/src/server/design/lint-page-focus.ts +165 -0
  76. package/src/server/design/lint-page-literals.ts +293 -0
  77. package/src/server/design/lint-page-setup.ts +102 -0
  78. package/src/server/design/lint-page-states.ts +121 -0
  79. package/src/server/design/lint-page-values.ts +329 -0
  80. package/src/server/design/lint-page.ts +101 -0
  81. package/src/server/design/lint-suggest.ts +340 -0
  82. package/src/server/design/lint.ts +1136 -0
  83. package/src/server/design/render.ts +369 -18
  84. package/src/server/design/scan-braces.ts +115 -0
  85. package/src/server/design/scan-categorize.ts +187 -0
  86. package/src/server/design/scan-channels.ts +113 -0
  87. package/src/server/design/scan-color-base.ts +209 -0
  88. package/src/server/design/scan-color-names.ts +403 -0
  89. package/src/server/design/scan-color-palette.ts +91 -0
  90. package/src/server/design/scan-color-roles.ts +565 -0
  91. package/src/server/design/scan-colors.ts +22 -0
  92. package/src/server/design/scan-facts-antd.ts +171 -0
  93. package/src/server/design/scan-facts-files.ts +300 -0
  94. package/src/server/design/scan-facts-lists.ts +538 -0
  95. package/src/server/design/scan-facts-sass.ts +113 -0
  96. package/src/server/design/scan-facts-theme.ts +400 -0
  97. package/src/server/design/scan-facts-use.ts +674 -0
  98. package/src/server/design/scan-facts-wordpress.ts +374 -0
  99. package/src/server/design/scan-facts.ts +285 -0
  100. package/src/server/design/scan-files.ts +384 -0
  101. package/src/server/design/scan-import-convert.ts +277 -0
  102. package/src/server/design/scan-import-eval.ts +583 -0
  103. package/src/server/design/scan-import-material.ts +745 -0
  104. package/src/server/design/scan-import-sd-config.ts +370 -0
  105. package/src/server/design/scan-import-sd.ts +381 -0
  106. package/src/server/design/scan-import-studio.ts +242 -0
  107. package/src/server/design/scan-import.ts +336 -0
  108. package/src/server/design/scan-infer.ts +313 -0
  109. package/src/server/design/scan-js-eval.ts +1267 -0
  110. package/src/server/design/scan-palette.ts +485 -0
  111. package/src/server/design/scan-parse.ts +1134 -0
  112. package/src/server/design/scan-prepare.ts +402 -0
  113. package/src/server/design/scan-render-pages.ts +367 -0
  114. package/src/server/design/scan-render-probe.ts +229 -0
  115. package/src/server/design/scan-render.ts +524 -0
  116. package/src/server/design/scan-review.ts +54 -0
  117. package/src/server/design/scan-roles.ts +259 -0
  118. package/src/server/design/scan-sass-colors.ts +275 -0
  119. package/src/server/design/scan-sass-eval.ts +269 -0
  120. package/src/server/design/scan-sass-expr.ts +911 -0
  121. package/src/server/design/scan-sass-modules.ts +353 -0
  122. package/src/server/design/scan-sass-run.ts +1003 -0
  123. package/src/server/design/scan-sass-stmt.ts +256 -0
  124. package/src/server/design/scan-sass-values.ts +886 -0
  125. package/src/server/design/scan-scales.ts +983 -0
  126. package/src/server/design/scan-tailwind.ts +34 -0
  127. package/src/server/design/scan-theme-shapes.ts +579 -0
  128. package/src/server/design/scan-tree.ts +290 -0
  129. package/src/server/design/scan-util.ts +44 -0
  130. package/src/server/design/scan-variables.ts +470 -0
  131. package/src/server/design/scan.ts +703 -0
  132. package/src/server/design/system-schema.ts +68 -0
  133. package/src/server/design/system-types.ts +279 -0
  134. package/src/server/design/system.ts +510 -82
  135. package/src/server/design/tokens-base.ts +123 -0
  136. package/src/server/design/tokens-compile.ts +440 -0
  137. package/src/server/design/tokens-dtcg.ts +354 -0
  138. package/src/server/design/tokens-io.ts +417 -0
  139. package/src/server/design/tokens-model.ts +1163 -0
  140. package/src/server/design/tokens-names.ts +112 -0
  141. package/src/server/design/tokens-ramps.ts +112 -0
  142. package/src/server/design/tokens-summary.ts +317 -0
  143. package/src/server/design/tokens-tailwind.ts +324 -0
  144. package/src/server/design/tokens-values.ts +921 -0
  145. package/src/server/design/tokens.ts +533 -0
  146. package/src/server/docs.ts +8 -0
  147. package/src/server/extensions/artifacts.ts +87 -2
  148. package/src/server/extensions/design/app.js +280 -0
  149. package/src/server/extensions/design/canvas.js +142 -17
  150. package/src/server/extensions/design/check.js +656 -0
  151. package/src/server/extensions/design/color.js +383 -0
  152. package/src/server/extensions/design/data.js +102 -7
  153. package/src/server/extensions/design/devices.js +26 -0
  154. package/src/server/extensions/design/docks.js +117 -3
  155. package/src/server/extensions/design/index.js +171 -219
  156. package/src/server/extensions/design/messages.js +49 -0
  157. package/src/server/extensions/design/parts.js +15 -1
  158. package/src/server/extensions/design/paths.js +4 -0
  159. package/src/server/extensions/design/picker.js +123 -0
  160. package/src/server/extensions/design/specimen.js +55 -0
  161. package/src/server/extensions/design/state.js +72 -7
  162. package/src/server/extensions/design/style.css +546 -0
  163. package/src/server/extensions/design/system-actions.js +214 -0
  164. package/src/server/extensions/design/system-api.ts +62 -0
  165. package/src/server/extensions/design/system-data.js +315 -0
  166. package/src/server/extensions/design/system-preview.js +41 -0
  167. package/src/server/extensions/design/system-routes.ts +1122 -0
  168. package/src/server/extensions/design/system-sections.js +1344 -0
  169. package/src/server/extensions/design/system-ui.js +32 -0
  170. package/src/server/extensions/design/system-view.js +1196 -0
  171. package/src/server/extensions/design/system-widgets.js +942 -0
  172. package/src/server/extensions/design/system.css +2313 -0
  173. package/src/server/extensions/design/system.js +1479 -0
  174. package/src/server/extensions/design/unsaved.js +20 -0
  175. package/src/server/extensions/design/views.js +2 -2
  176. package/src/server/extensions/design/workspace.js +200 -105
  177. package/src/server/extensions/design.ts +89 -6
  178. package/src/server/extensions/updates/index.js +31 -9
  179. package/src/server/extensions/updates/style.css +11 -0
  180. package/src/server/extensions/updates.ts +29 -1
  181. package/src/server/host.ts +4 -1
  182. package/src/server/http/artifact-inspect.ts +338 -24
  183. package/src/server/updates.ts +235 -53
  184. package/src/server/versions.ts +71 -0
  185. package/web/artifact-bridge.js +34 -1
  186. package/npm-shrinkwrap.json +0 -3162
@@ -0,0 +1,383 @@
1
+ // Colors for the System view, as pure functions (no DOM, so a test can run them): read a DTCG color (the 2025.10 object
2
+ // form or a CSS string), write it as hex or OKLCH, and measure contrast the way WCAG 2.2 does. A color is `{ r, g, b, a }`:
3
+ // r, g, b in 0–255 (sRGB), a in 0–1.
4
+
5
+ const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
6
+ const finite = (value) => typeof value === "number" && Number.isFinite(value);
7
+ const to255 = (value) => Math.round(clamp(value, 0, 1) * 255);
8
+
9
+ /** sRGB (0–1) from linear light (0–1), and back. */
10
+ const encode = (value) => (value <= 0.0031308 ? 12.92 * value : 1.055 * value ** (1 / 2.4) - 0.055);
11
+ const decode = (value) => (value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4);
12
+
13
+ /** A color from OKLab coordinates (the CSS Color 4 matrices), clipped to sRGB. */
14
+ function fromOklab(l, a, b, alpha = 1) {
15
+ const l_ = l + 0.3963377774 * a + 0.2158037573 * b;
16
+ const m_ = l - 0.1055613458 * a - 0.0638541728 * b;
17
+ const s_ = l - 0.0894841775 * a - 1.291485548 * b;
18
+ const lc = l_ ** 3;
19
+ const mc = m_ ** 3;
20
+ const sc = s_ ** 3;
21
+ const r = 4.0767416621 * lc - 3.3077115913 * mc + 0.2309699292 * sc;
22
+ const g = -1.2684380046 * lc + 2.6097574011 * mc - 0.3413193965 * sc;
23
+ const bl = -0.0041960863 * lc - 0.7034186147 * mc + 1.707614701 * sc;
24
+
25
+ return {
26
+ r: to255(encode(clamp(r, 0, 1))),
27
+ g: to255(encode(clamp(g, 0, 1))),
28
+ b: to255(encode(clamp(bl, 0, 1))),
29
+ a: clamp(alpha, 0, 1),
30
+ };
31
+ }
32
+
33
+ /** OKLab of an sRGB color (0–255). */
34
+ function toOklab({ r, g, b }) {
35
+ const lr = decode(r / 255);
36
+ const lg = decode(g / 255);
37
+ const lb = decode(b / 255);
38
+ const l = Math.cbrt(0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb);
39
+ const m = Math.cbrt(0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb);
40
+ const s = Math.cbrt(0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb);
41
+
42
+ return {
43
+ l: 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
44
+ a: 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
45
+ b: 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
46
+ };
47
+ }
48
+
49
+ const fromOklch = (l, c, h, alpha) =>
50
+ fromOklab(l, c * Math.cos((h * Math.PI) / 180), c * Math.sin((h * Math.PI) / 180), alpha);
51
+
52
+ /** OKLCH of a color: lightness 0–1, chroma, hue in degrees (0 for a gray). */
53
+ export function toOklch(color) {
54
+ const { l, a, b } = toOklab(color);
55
+ const c = Math.hypot(a, b);
56
+ const h = c < 0.0004 ? 0 : ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360;
57
+
58
+ return { l, c, h };
59
+ }
60
+
61
+ function fromHsl(h, s, l, alpha) {
62
+ const hue = (((h % 360) + 360) % 360) / 360;
63
+ const sat = clamp(s, 0, 100) / 100;
64
+ const light = clamp(l, 0, 100) / 100;
65
+ const q = light < 0.5 ? light * (1 + sat) : light + sat - light * sat;
66
+ const p = 2 * light - q;
67
+
68
+ const channel = (t) => {
69
+ const x = (t + 1) % 1;
70
+
71
+ return x < 1 / 6
72
+ ? p + (q - p) * 6 * x
73
+ : x < 0.5
74
+ ? q
75
+ : x < 2 / 3
76
+ ? p + (q - p) * (2 / 3 - x) * 6
77
+ : p;
78
+ };
79
+
80
+ return {
81
+ r: to255(sat === 0 ? light : channel(hue + 1 / 3)),
82
+ g: to255(sat === 0 ? light : channel(hue)),
83
+ b: to255(sat === 0 ? light : channel(hue - 1 / 3)),
84
+ a: clamp(alpha, 0, 1),
85
+ };
86
+ }
87
+
88
+ /** A number or a percentage (`50%` → 0.5 × `full`), or undefined. */
89
+ function component(text, full = 1) {
90
+ const match = /^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(%|deg|rad|turn)?$/i.exec(text.trim());
91
+
92
+ if (match === null) {
93
+ return undefined;
94
+ }
95
+
96
+ const value = Number(match[1]);
97
+
98
+ return match[2] === "%" ? (value / 100) * full : value;
99
+ }
100
+
101
+ /** The hue of `text` in degrees (a bare number, `deg`, `rad`, or `turn`). */
102
+ function hueOf(text) {
103
+ const match = /^([+-]?(?:\d+\.?\d*|\.\d+))(deg|rad|turn)?$/i.exec(text.trim());
104
+
105
+ if (match === null) {
106
+ return undefined;
107
+ }
108
+
109
+ const value = Number(match[1]);
110
+ const unit = (match[2] ?? "deg").toLowerCase();
111
+
112
+ return unit === "rad" ? (value * 180) / Math.PI : unit === "turn" ? value * 360 : value;
113
+ }
114
+
115
+ const NAMED = {
116
+ transparent: { r: 0, g: 0, b: 0, a: 0 },
117
+ black: { r: 0, g: 0, b: 0, a: 1 },
118
+ white: { r: 255, g: 255, b: 255, a: 1 },
119
+ };
120
+
121
+ /** The function-style color `name(...)`: the parts, split on commas, spaces, and a slash. */
122
+ function parts(body) {
123
+ const [main, alpha] = body.split("/").map((each) => each.trim());
124
+ const list = main.split(/[\s,]+/).filter(Boolean);
125
+
126
+ if (alpha !== undefined) {
127
+ list.push(alpha);
128
+ }
129
+
130
+ return list;
131
+ }
132
+
133
+ function parseString(input) {
134
+ const text = input.trim().toLowerCase();
135
+
136
+ if (Object.hasOwn(NAMED, text)) {
137
+ return { ...NAMED[text] };
138
+ }
139
+
140
+ const hex = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.exec(text);
141
+
142
+ if (hex) {
143
+ const digits =
144
+ hex[1].length <= 4 ? [...hex[1]].map((each) => each + each).join("") : hex[1];
145
+
146
+ return {
147
+ r: parseInt(digits.slice(0, 2), 16),
148
+ g: parseInt(digits.slice(2, 4), 16),
149
+ b: parseInt(digits.slice(4, 6), 16),
150
+ a: digits.length === 8 ? parseInt(digits.slice(6, 8), 16) / 255 : 1,
151
+ };
152
+ }
153
+
154
+ const call = /^([a-z-]+)\(\s*([^()]*)\)$/.exec(text);
155
+
156
+ if (call === null) {
157
+ return null;
158
+ }
159
+
160
+ const list = parts(call[2]);
161
+ const name = call[1];
162
+ const alpha = (index) =>
163
+ list[index] === undefined ? 1 : clamp(component(list[index]) ?? NaN, 0, 1);
164
+
165
+ if (name === "rgb" || name === "rgba") {
166
+ const channels = list.slice(0, 3).map((each) => component(each, 255));
167
+
168
+ if (channels.length < 3 || channels.some((each) => !finite(each)) || !finite(alpha(3))) {
169
+ return null;
170
+ }
171
+
172
+ return {
173
+ r: Math.round(clamp(channels[0], 0, 255)),
174
+ g: Math.round(clamp(channels[1], 0, 255)),
175
+ b: Math.round(clamp(channels[2], 0, 255)),
176
+ a: alpha(3),
177
+ };
178
+ }
179
+
180
+ if (name === "hsl" || name === "hsla") {
181
+ const h = hueOf(list[0] ?? "");
182
+ const s = component(list[1] ?? "", 100);
183
+ const l = component(list[2] ?? "", 100);
184
+
185
+ return finite(h) && finite(s) && finite(l) && finite(alpha(3))
186
+ ? fromHsl(h, s, l, alpha(3))
187
+ : null;
188
+ }
189
+
190
+ if (name === "oklch") {
191
+ const l = component(list[0] ?? "", 1);
192
+ const c = component(list[1] ?? "", 0.4);
193
+ const h = hueOf(list[2] ?? "");
194
+
195
+ return finite(l) && finite(c) && finite(h) && finite(alpha(3))
196
+ ? fromOklch(l, c, h, alpha(3))
197
+ : null;
198
+ }
199
+
200
+ if (name === "oklab") {
201
+ const l = component(list[0] ?? "", 1);
202
+ const a = component(list[1] ?? "", 0.4);
203
+ const b = component(list[2] ?? "", 0.4);
204
+
205
+ return finite(l) && finite(a) && finite(b) && finite(alpha(3))
206
+ ? fromOklab(l, a, b, alpha(3))
207
+ : null;
208
+ }
209
+
210
+ if (name === "color") {
211
+ const space = list[0];
212
+ const channels = list.slice(1, 4).map((each) => component(each, 1));
213
+
214
+ if (
215
+ space === "srgb" &&
216
+ channels.length === 3 &&
217
+ channels.every(finite) &&
218
+ finite(alpha(4))
219
+ ) {
220
+ return {
221
+ r: to255(channels[0]),
222
+ g: to255(channels[1]),
223
+ b: to255(channels[2]),
224
+ a: alpha(4),
225
+ };
226
+ }
227
+ }
228
+
229
+ return null;
230
+ }
231
+
232
+ /** Display P3 (0–1) to sRGB, clipped: close enough to show and to measure. */
233
+ function fromP3(red, green, blue, alpha) {
234
+ const lr = decode(red);
235
+ const lg = decode(green);
236
+ const lb = decode(blue);
237
+ const r = 1.2249401 * lr - 0.2249402 * lg;
238
+ const g = -0.0420569 * lr + 1.0420571 * lg;
239
+ const b = -0.0196376 * lr - 0.0786507 * lg + 1.0982735 * lb;
240
+
241
+ return {
242
+ r: to255(encode(clamp(r, 0, 1))),
243
+ g: to255(encode(clamp(g, 0, 1))),
244
+ b: to255(encode(clamp(b, 0, 1))),
245
+ a: clamp(alpha, 0, 1),
246
+ };
247
+ }
248
+
249
+ function parseObject(input) {
250
+ const alpha = finite(input.alpha) ? clamp(input.alpha, 0, 1) : 1;
251
+
252
+ if (typeof input.hex === "string") {
253
+ const color = parseString(input.hex);
254
+
255
+ // The hex has no alpha of its own: the object's alpha is the color's.
256
+ return color === null ? null : { ...color, a: finite(input.alpha) ? alpha : color.a };
257
+ }
258
+
259
+ const c = Array.isArray(input.components) ? input.components : [];
260
+
261
+ if (c.length < 3 || !c.slice(0, 3).every((each) => finite(each) || each === "none")) {
262
+ return null;
263
+ }
264
+
265
+ const [x, y, z] = c.map((each) => (each === "none" ? 0 : each));
266
+
267
+ switch (input.colorSpace) {
268
+ case "srgb":
269
+ return { r: to255(x), g: to255(y), b: to255(z), a: alpha };
270
+ case "srgb-linear":
271
+ return {
272
+ r: to255(encode(clamp(x, 0, 1))),
273
+ g: to255(encode(clamp(y, 0, 1))),
274
+ b: to255(encode(clamp(z, 0, 1))),
275
+ a: alpha,
276
+ };
277
+ case "hsl":
278
+ return fromHsl(x, y, z, alpha);
279
+ case "oklch":
280
+ return fromOklch(x, y, z, alpha);
281
+ case "oklab":
282
+ return fromOklab(x, y, z, alpha);
283
+ case "display-p3":
284
+ return fromP3(x, y, z, alpha);
285
+ default:
286
+ return null;
287
+ }
288
+ }
289
+
290
+ /** A color from a DTCG value (object or string): `{ r, g, b, a }`, or null for what this cannot read. */
291
+ export function parseColor(input) {
292
+ if (typeof input === "string") {
293
+ return input.length > 200 ? null : parseString(input);
294
+ }
295
+
296
+ return typeof input === "object" && input !== null && !Array.isArray(input)
297
+ ? parseObject(input)
298
+ : null;
299
+ }
300
+
301
+ const hex2 = (value) => clamp(Math.round(value), 0, 255).toString(16).padStart(2, "0");
302
+
303
+ /** `#rrggbb`, or `#rrggbbaa` when the color is not opaque. */
304
+ export function toHex({ r, g, b, a = 1 }) {
305
+ return `#${hex2(r)}${hex2(g)}${hex2(b)}${a < 1 ? hex2(a * 255) : ""}`;
306
+ }
307
+
308
+ /** The color as `oklch(0.72 0.12 260)`, with an alpha when it is not opaque. */
309
+ export function toOklchText(color) {
310
+ const { l, c, h } = toOklch(color);
311
+ const round = (value, digits) => String(Math.round(value * 10 ** digits) / 10 ** digits);
312
+ const alpha = color.a < 1 ? ` / ${round(color.a, 2)}` : "";
313
+
314
+ return `oklch(${round(l, 3)} ${round(c, 3)} ${round(h, 1)}${alpha})`;
315
+ }
316
+
317
+ /** The color as `rgb(r g b / a)`. */
318
+ export const toRgbText = ({ r, g, b, a = 1 }) =>
319
+ `rgb(${r} ${g} ${b}${a < 1 ? ` / ${Math.round(a * 100) / 100}` : ""})`;
320
+
321
+ /** The CSS a swatch is painted with, from a DTCG value; an empty string when it cannot be read. */
322
+ export function swatchCss(value) {
323
+ const color = parseColor(value);
324
+
325
+ return color === null ? "" : toRgbText(color);
326
+ }
327
+
328
+ /** The DTCG value for `color` in the same dialect as `like`: an object (2025.10) when `like` is one, else a hex string. */
329
+ export function writeColor(color, like) {
330
+ if (typeof like === "object" && like !== null && !Array.isArray(like)) {
331
+ const next = {
332
+ colorSpace: "srgb",
333
+ components: [color.r, color.g, color.b].map(
334
+ (each) => Math.round((each / 255) * 10000) / 10000,
335
+ ),
336
+ hex: toHex({ ...color, a: 1 }),
337
+ };
338
+
339
+ return color.a < 1 ? { ...next, alpha: Math.round(color.a * 1000) / 1000 } : next;
340
+ }
341
+
342
+ return toHex(color);
343
+ }
344
+
345
+ /** Relative luminance (WCAG 2.2) of an opaque color. */
346
+ export function luminance({ r, g, b }) {
347
+ return 0.2126 * decode(r / 255) + 0.7152 * decode(g / 255) + 0.0722 * decode(b / 255);
348
+ }
349
+
350
+ /** `top` painted over `bottom` (an opaque color). */
351
+ export function over(top, bottom) {
352
+ const a = top.a ?? 1;
353
+
354
+ return {
355
+ r: Math.round(top.r * a + bottom.r * (1 - a)),
356
+ g: Math.round(top.g * a + bottom.g * (1 - a)),
357
+ b: Math.round(top.b * a + bottom.b * (1 - a)),
358
+ a: 1,
359
+ };
360
+ }
361
+
362
+ /** The contrast ratio of `foreground` on `background` (WCAG 2.2): a see-through foreground is laid over the background first. */
363
+ export function contrast(foreground, background) {
364
+ const ground =
365
+ background.a < 1 ? over(background, { r: 255, g: 255, b: 255, a: 1 }) : background;
366
+ const ink = foreground.a < 1 ? over(foreground, ground) : foreground;
367
+ const [hi, lo] = [luminance(ink), luminance(ground)].sort((a, b) => b - a);
368
+
369
+ return (hi + 0.05) / (lo + 0.05);
370
+ }
371
+
372
+ /** How a ratio fares against `min`: `pass` (≥ min), `fail`; and `level` for the usual steps. */
373
+ export function grade(ratio, min = 4.5) {
374
+ return {
375
+ ratio,
376
+ min,
377
+ pass: ratio >= min,
378
+ level: ratio >= 7 ? "AAA" : ratio >= 4.5 ? "AA" : ratio >= 3 ? "AA large" : "Fail",
379
+ };
380
+ }
381
+
382
+ /** A ratio for people: `7.1:1`, rounded down, so a 4.49 never reads as 4.5. */
383
+ export const ratioText = (ratio) => `${Math.floor(ratio * 10) / 10}:1`;
@@ -34,6 +34,54 @@ export function designsOf(appView, listed) {
34
34
  .sort((a, b) => timeOf(b) - timeOf(a));
35
35
  }
36
36
 
37
+ /**
38
+ * A check's report with the findings that people accepted put apart: `accepted` is the stored map (a finding's id to who and
39
+ * when). The open findings stay in the engine's order (`order` is the ids as it gave them), the counts are of the open ones
40
+ * only, and the accepted ones are listed apart. A report that was already split is split again, so an accept and its undo
41
+ * need no new check.
42
+ */
43
+ export function splitReport(report, accepted) {
44
+ if (!report || !Array.isArray(report.findings)) {
45
+ return report;
46
+ }
47
+
48
+ const all = [...report.findings, ...(report.accepted ?? [])];
49
+ const at = new Map((report.order ?? []).map((id, index) => [id, index]));
50
+ const place = (finding) => at.get(finding.id) ?? Number.MAX_SAFE_INTEGER;
51
+ const sorted = at.size > 0 ? all.toSorted((a, b) => place(a) - place(b)) : all;
52
+ const isAccepted = (finding) =>
53
+ finding.id !== undefined && Object.hasOwn(accepted ?? {}, finding.id);
54
+ const findings = sorted.filter((finding) => !isAccepted(finding));
55
+ const byRule = {};
56
+
57
+ for (const finding of findings) {
58
+ byRule[finding.rule] = (byRule[finding.rule] ?? 0) + 1;
59
+ }
60
+
61
+ return {
62
+ ...report,
63
+ findings,
64
+ accepted: sorted.filter(isAccepted),
65
+ summary: {
66
+ ...report.summary,
67
+ errors: findings.filter((finding) => finding.level === "error").length,
68
+ warnings: findings.filter((finding) => finding.level === "warning").length,
69
+ byRule,
70
+ },
71
+ };
72
+ }
73
+
74
+ /** The checks of one design with the accepted findings put apart again (`splitReport`): the other designs' are as they were. */
75
+ const resplit = (checks, artifact, accepted) =>
76
+ Object.fromEntries(
77
+ Object.entries(checks).map(([key, entry]) => [
78
+ key,
79
+ key.startsWith(`${artifact}@`) && entry.report
80
+ ? { ...entry, report: splitReport(entry.report, accepted) }
81
+ : entry,
82
+ ]),
83
+ );
84
+
37
85
  /** The designs in the same group as `artifact` (itself included), in the list's order; none when it has no group. */
38
86
  export function siblingsOf(designs, artifact) {
39
87
  if (!artifact?.group) {
@@ -43,6 +91,17 @@ export function siblingsOf(designs, artifact) {
43
91
  return designs.filter((each) => each.group === artifact.group);
44
92
  }
45
93
 
94
+ /** Save a file that the server wrote in the session's folder, through core's download route (an attachment). */
95
+ export function downloadFile(conversation, made) {
96
+ const link = document.createElement("a");
97
+
98
+ link.href = `/api/c/${encodeURIComponent(conversation)}/download?${new URLSearchParams({ path: made.relative })}`;
99
+ link.download = made.name;
100
+ document.body.append(link);
101
+ link.click();
102
+ link.remove();
103
+ }
104
+
46
105
  export function createData(pocket, store) {
47
106
  const conversationOf = () => store.get().conversation;
48
107
  let listing = 0;
@@ -95,6 +154,8 @@ export function createData(pocket, store) {
95
154
  if (current(conversation)) {
96
155
  store.set((state) => ({
97
156
  notes: { ...state.notes, [artifact]: { ...result, loaded: true } },
157
+ // What was accepted changed (here or somewhere else): the checks of this design are split again.
158
+ checks: resplit(state.checks, artifact, result.accepted),
98
159
  }));
99
160
  }
100
161
  } catch (error) {
@@ -104,6 +165,45 @@ export function createData(pocket, store) {
104
165
  }
105
166
  },
106
167
 
168
+ /** Accept a finding of the Check: it is fine as it is, for everyone, until somebody undoes it. */
169
+ async accept(artifact, finding) {
170
+ const conversation = conversationOf();
171
+
172
+ try {
173
+ await pocket.api(
174
+ `c/${conversation}/designs/${encodeURIComponent(artifact)}/accepted`,
175
+ { id: finding.id, rule: finding.rule, message: finding.message },
176
+ );
177
+ await data.notes(artifact);
178
+
179
+ return true;
180
+ } catch (error) {
181
+ fail(error);
182
+
183
+ return false;
184
+ }
185
+ },
186
+
187
+ /** Take an accepted finding back: it is counted again. */
188
+ async unaccept(artifact, id) {
189
+ const conversation = conversationOf();
190
+
191
+ try {
192
+ await pocket.api(
193
+ `c/${conversation}/designs/${encodeURIComponent(artifact)}/accepted/${encodeURIComponent(id)}`,
194
+ undefined,
195
+ { method: "DELETE" },
196
+ );
197
+ await data.notes(artifact);
198
+
199
+ return true;
200
+ } catch (error) {
201
+ fail(error);
202
+
203
+ return false;
204
+ }
205
+ },
206
+
107
207
  async addComment(artifact, version, target, text) {
108
208
  const conversation = conversationOf();
109
209
 
@@ -225,14 +325,9 @@ export function createData(pocket, store) {
225
325
  format,
226
326
  ...(viewport ? { viewport } : {}),
227
327
  });
228
- // The core route streams the file from the session's folder as an attachment.
229
- const link = document.createElement("a");
230
328
 
231
- link.href = `/api/c/${encodeURIComponent(conversation)}/download?${new URLSearchParams({ path: made.relative })}`;
232
- link.download = made.name;
233
- document.body.append(link);
234
- link.click();
235
- link.remove();
329
+ // The core route streams the file from the session's folder as an attachment.
330
+ downloadFile(conversation, made);
236
331
  pocket.notify("info", `Saved ${made.name}. It is also at ${made.path}`);
237
332
 
238
333
  return true;
@@ -45,6 +45,15 @@ export const ZOOMS = [0.25, 0.33, 0.5, 0.67, 0.75, 1, 1.25, 1.5, 2];
45
45
  * 100%) or a number. `gap` is the margin kept around the frame when it fits.
46
46
  */
47
47
  export function scaleOf(zoom, size, room, gap = 16) {
48
+ // The width of the room: a tall page (a phone's) is read at its width, and the room scrolls for the rest.
49
+ if (zoom === "width") {
50
+ if (!(room.w > 0)) {
51
+ return 1;
52
+ }
53
+
54
+ return Math.max(0.1, Math.floor(Math.min((room.w - gap * 2) / size.w, 1) * 100) / 100);
55
+ }
56
+
48
57
  if (zoom !== "fit") {
49
58
  return Number(zoom) > 0 ? Number(zoom) : 1;
50
59
  }
@@ -58,6 +67,23 @@ export function scaleOf(zoom, size, room, gap = 16) {
58
67
  return Math.max(0.1, Math.floor(fit * 100) / 100);
59
68
  }
60
69
 
70
+ /**
71
+ * What `auto`, the zoom that nobody chose, comes to: the width of the room on a narrow panel (a phone), where the text of a
72
+ * page is to be read and the room scrolls, and the whole page in the room elsewhere.
73
+ */
74
+ export const zoomOf = (zoom, narrow) => (zoom === "auto" ? (narrow ? "width" : "fit") : zoom);
75
+
76
+ /** The word for a zoom that follows the room, in front of its percent: `Width 95%`, `Fit 44%`. A number has none. */
77
+ export const zoomWord = (zoom) => (zoom === "width" ? "Width " : zoom === "fit" ? "Fit " : "");
78
+
79
+ /** What a tap on the zoom value goes to: on a narrow panel width, whole page, 100%; elsewhere whole page and 100%. */
80
+ export function nextZoom(zoom, narrow) {
81
+ const steps = narrow ? ["width", "fit", 1] : ["fit", 1];
82
+ const at = steps.indexOf(zoom);
83
+
84
+ return steps[(at + 1) % steps.length];
85
+ }
86
+
61
87
  /** The next zoom step up (`direction` 1) or down (-1) from `scale`, as a number: it leaves "fit". */
62
88
  export function stepZoom(scale, direction) {
63
89
  if (direction > 0) {