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,252 @@
1
+ /**
2
+ * A part of the script that `lint.ts` runs inside a rendered design (see `lint-page.ts`): the walk over each element: colors, fonts, sizes, contrast, tap targets, overflow, and what needs a pid. The parts are one
3
+ * function body, in this order: setup, values, literals, states, elements, checks, focus. Plain JavaScript in a string.
4
+ */
5
+ export const PAGE_ELEMENTS = String.raw`for (const el of nodes) {
6
+ const state = states.get(el);
7
+
8
+ if (!state) continue;
9
+
10
+ const style = getComputedStyle(el);
11
+ const rect = rectOf(el);
12
+ const box = rect.width > 0 && rect.height > 0 && style.display !== 'contents';
13
+
14
+ if (!box && el !== root && el !== body) continue;
15
+ if (style.visibility !== 'visible' || state.cum < 0.01) continue;
16
+ if (rect.right + win.scrollX < 0 || rect.bottom + win.scrollY < 0) continue;
17
+
18
+ elements++;
19
+ const tag = el.localName;
20
+ const text = hasText(el);
21
+ const disabled = el.matches(':disabled');
22
+ const parentStyle = el.parentElement ? getComputedStyle(el.parentElement) : null;
23
+
24
+ // Colors in use: where each is used (text, background, border, outline).
25
+ const used = new Set();
26
+ const useColor = (css, role) => {
27
+ const rgba = toRgba(css);
28
+
29
+ if (!rgba || rgba[3] <= 0) return;
30
+
31
+ const key = rgba.map((n) => round(n)).join(',');
32
+ const hard = input.literals === true && authoredColor(el, role, rgba);
33
+
34
+ if (used.has(role + key)) return;
35
+
36
+ used.add(role + key);
37
+ const found = group(groups.colors, key + '|' + role + (hard ? '|L' : ''), () => ({ rgba, roles: {}, literal: hard }), el);
38
+
39
+ if (found) found.roles[role] = (found.roles[role] || 0) + 1;
40
+ };
41
+
42
+ const fill = toRgba(style.webkitTextFillColor || style.color);
43
+ const gradientText = style.backgroundClip === 'text' || style.webkitBackgroundClip === 'text' || (fill && fill[3] === 0);
44
+
45
+ if (text && !gradientText && inheritedAuthored(el, 'color')) {
46
+ useColor(style.webkitTextFillColor || style.color, 'text');
47
+ }
48
+
49
+ if (authoredOwn(el, 'backgroundColor', style)) useColor(style.backgroundColor, 'background');
50
+
51
+ for (const [side, name] of scaleSides) {
52
+ // A border drawn in the text color (currentcolor) is the text color's to judge.
53
+ if (pxOf(style['border' + name + 'Width']) > 0 && !/^(none|hidden)$/.test(style['border' + name + 'Style']) && style['border' + name + 'Color'] !== style.color && authoredOwn(el, 'border' + name + 'Color', style)) {
54
+ useColor(style['border' + name + 'Color'], 'border');
55
+ }
56
+ }
57
+
58
+ if (pxOf(style.outlineWidth) > 0 && !/^(none|hidden)$/.test(style.outlineStyle) && authoredOwn(el, 'outlineColor', style)) useColor(style.outlineColor, 'outline');
59
+
60
+ // Fonts and font sizes, and the text's contrast with what is behind it.
61
+ // Text made invisible on purpose (a screen-reader-only label) is not judged.
62
+ const hiddenText = /^rect\(0(px)?,? ?0(px)?,? ?0(px)?,? ?0(px)?\)$/.test(style.clip) || /^inset\((50|100)%/.test(style.clipPath) || pxOf(style.textIndent) <= -500 || (/^(hidden|clip)$/.test(style.overflowX) && rect.height <= 1);
63
+
64
+ if (text && !gradientText && !hiddenText && fill && rect.width > 1 && rect.height > 1 && pxOf(style.fontSize) >= 1) {
65
+ const fontSize = pxOf(style.fontSize);
66
+ const family = familyOf(style.fontFamily);
67
+
68
+ // The font and the size that the author set; the browser's own (a heading's size, the default serif) are not judged.
69
+ if (inheritedAuthored(el, 'fontFamily')) {
70
+ const hardFamily = input.literals === true && authoredFamily(el, family);
71
+
72
+ group(groups.fonts, family + (hardFamily ? '|L' : ''), () => ({ family, list: style.fontFamily.slice(0, 300), literal: hardFamily }), el);
73
+
74
+ const info = fontInfo.get(family) || { list: style.fontFamily.slice(0, 300), count: 0 };
75
+
76
+ info.count++;
77
+ fontInfo.set(family, info);
78
+
79
+ if (!textFamilies.has(family)) textFamilies.set(family, el);
80
+ }
81
+
82
+ if (inheritedAuthored(el, 'fontSize')) {
83
+ const hardSize = input.literals === true && authoredLength(el, 'font-size', fontSize, style);
84
+
85
+ group(groups.sizes, 'font-size|' + round(fontSize) + (hardSize ? '|L' : ''), () => ({ kind: 'font-size', px: round(fontSize), props: ['font-size'], literal: hardSize }), el);
86
+ }
87
+
88
+ const near = overlapped(el, rect);
89
+
90
+ if (!state.uncertain && !near && !disabled) {
91
+ const alpha = fill[3] * state.cum;
92
+ const fg = mix(state.back, fill, alpha).map(Math.round);
93
+ const bgc = state.back.map(Math.round);
94
+ const weight = parseInt(style.fontWeight, 10) || 400;
95
+ const large = fontSize >= 24 || (fontSize >= 18.66 && weight >= 700);
96
+
97
+ group(groups.contrast, 'text|' + fg + '|' + bgc + '|' + large, () => ({ fg, bg: bgc, size: round(fontSize), large, ui: false }), el);
98
+ } else if (!disabled) {
99
+ notJudged.count++;
100
+
101
+ if (notJudged.els.length < 8) notJudged.els.push(el);
102
+ }
103
+ }
104
+
105
+ // A form control's edge against what it sits on (WCAG 1.4.11).
106
+ if (!disabled && (tag === 'select' || tag === 'textarea' || (tag === 'input' && !/^(hidden|checkbox|radio|range|color|file|button|submit|reset|image)$/.test(el.type))) && !state.uncertain) {
107
+ const around = state.before;
108
+ const own = state.back;
109
+ let best = 0;
110
+ const ratioOf = (a, b) => {
111
+ const lum = (c) => c.map((v) => { v /= 255; return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; });
112
+ const [la, lb] = [lum(a), lum(b)].map((c) => 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]);
113
+
114
+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
115
+ };
116
+ let edge = false;
117
+ const edges = [];
118
+ const fillRaw = toRgba(style.backgroundColor);
119
+
120
+ best = ratioOf(own, around);
121
+
122
+ if (best > 1.02) {
123
+ edge = true;
124
+
125
+ if (fillRaw && fillRaw[3] > 0) edges.push(fillRaw);
126
+ }
127
+
128
+ for (const [side, name] of scaleSides) {
129
+ const color = toRgba(style['border' + name + 'Color']);
130
+
131
+ if (pxOf(style['border' + name + 'Width']) > 0 && !/^(none|hidden)$/.test(style['border' + name + 'Style']) && color && color[3] > 0) {
132
+ edge = true;
133
+ edges.push(color);
134
+ best = Math.max(best, ratioOf(mix(own, color, color[3] * state.cum), around));
135
+ }
136
+ }
137
+
138
+ if (edge && best < 3) {
139
+ group(groups.contrast, 'ui|' + own.map(Math.round) + '|' + around.map(Math.round) + '|' + best.toFixed(1), () => ({ fg: own.map(Math.round), bg: around.map(Math.round), size: 0, large: false, ui: true, ratio: best, edges: edges.slice(0, 5) }), el);
140
+ }
141
+ }
142
+
143
+ // Spacing and radii.
144
+ if (box) {
145
+ const space = (value, prop, auto, uaProp) => {
146
+ const px = Math.abs(pxOf(value));
147
+
148
+ if (auto || !(px > 0.5) || Number.isNaN(px) || !authoredOwn(el, uaProp, style)) return;
149
+
150
+ const hard = input.literals === true && authoredLength(el, 'space', px, style);
151
+ const key = 'space|' + round(px) + (hard ? '|L' : '');
152
+
153
+ let seen = spaceSeen.get(key);
154
+
155
+ if (!seen || seen.el !== el) {
156
+ seen = { el, found: group(groups.sizes, key, () => ({ kind: 'space', px: round(px), props: [], literal: hard }), el) };
157
+ spaceSeen.set(key, seen);
158
+ }
159
+
160
+ const found = seen.found;
161
+
162
+ if (found && found.props.length < 3 && !found.props.includes(prop)) found.props.push(prop);
163
+ };
164
+ let map = null;
165
+
166
+ try {
167
+ map = el.computedStyleMap();
168
+ } catch {
169
+ map = null;
170
+ }
171
+
172
+ const typed = (prop) => {
173
+ const value = map ? map.get(prop) : null;
174
+
175
+ if (!value) return false;
176
+
177
+ return value.toString() === 'auto' || (value.unit === 'percent');
178
+ };
179
+
180
+ // A native checkbox or radio keeps the browser's margin unless the page changes it.
181
+ const native = tag === 'input' && /^(checkbox|radio)$/.test(el.type);
182
+
183
+ for (const [side, name] of scaleSides) {
184
+ space(style['padding' + name], 'padding', typed('padding-' + side), 'padding' + name);
185
+ space(style['margin' + name], 'margin', native || typed('margin-' + side), 'margin' + name);
186
+ }
187
+
188
+ space(style.rowGap === 'normal' ? '0px' : style.rowGap, 'gap', false, 'rowGap');
189
+ space(style.columnGap === 'normal' ? '0px' : style.columnGap, 'gap', false, 'columnGap');
190
+
191
+ for (const corner of ['TopLeft', 'TopRight', 'BottomRight', 'BottomLeft']) {
192
+ const value = style['border' + corner + 'Radius'];
193
+
194
+ if (value.includes('%')) continue;
195
+
196
+ const px = pxOf(value);
197
+
198
+ if (!(px > 0.5) || px >= Math.min(rect.width, rect.height) / 2 || !authoredOwn(el, 'border' + corner + 'Radius', style)) continue;
199
+
200
+ const hard = input.literals === true && authoredLength(el, 'radius', px, style);
201
+ const key = 'radius|' + round(px) + (hard ? '|L' : '');
202
+
203
+ if (radiusSeen.get(key) === el) continue;
204
+
205
+ radiusSeen.set(key, el);
206
+ group(groups.sizes, key, () => ({ kind: 'radius', px: round(px), props: ['border-radius'], literal: hard }), el);
207
+ }
208
+ }
209
+
210
+ // Targets that a finger or a pointer must hit.
211
+ if (!input.deck && el.matches(pointed) && !disabled && el.getAttribute('aria-hidden') !== 'true' && !el.parentElement.closest(pointed)) {
212
+ let width = rect.width;
213
+ let height = rect.height;
214
+ let left = rect.left;
215
+ let top = rect.top;
216
+ const labels = el.labels ? [...el.labels] : [];
217
+ const isCheck = tag === 'input' && /^(checkbox|radio)$/.test(el.type);
218
+
219
+ for (const label of labels) {
220
+ const lr = label.getBoundingClientRect();
221
+
222
+ if (lr.width * lr.height > width * height) {
223
+ width = lr.width;
224
+ height = lr.height;
225
+ left = lr.left;
226
+ top = lr.top;
227
+ }
228
+ }
229
+
230
+ const inline = style.display === 'inline' && tag !== 'input' && tag !== 'button' && tag !== 'select' && tag !== 'textarea' && el.parentElement && [...el.parentElement.childNodes].some((n) => n !== el && n.nodeType === 3 && n.nodeValue.trim() !== '');
231
+ const bare = (isCheck || (tag === 'input' && el.type === 'range')) && style.appearance !== 'none' && labels.length === 0;
232
+
233
+ // A control that the page has not styled at all (no padding, border, or font size of its own) is the browser's: its size is not the page's.
234
+ const unstyled = /^(button|input|select|textarea|summary)$/.test(tag) && !authoredOwn(el, 'paddingTop', style) && !authoredOwn(el, 'borderTopWidth', style) && !authoredOwn(el, 'paddingLeft', style) && !inheritedAuthored(el, 'fontSize');
235
+
236
+ if (!inline && !bare && !unstyled && width > 0 && height > 0) targets.push({ el, left, top, width, height, tag });
237
+ }
238
+
239
+ // Overflow: elements that end past the viewport and are not clipped or fixed.
240
+ if (!input.deck && el !== root && el !== body && !state.clip && !state.fixed && rect.right > viewWidth + 1) offenders.push({ el, right: rect.right, content: (el.textContent || '').trim() !== '' || el.matches(pointed + ',img,video,canvas,svg') });
241
+
242
+ // Headings in order.
243
+ const level = /^h[1-6]$/.test(tag) ? Number(tag[1]) : el.getAttribute('role') === 'heading' ? Number(el.getAttribute('aria-level')) : 0;
244
+
245
+ if (level >= 1 && level <= 6 && (el.textContent || '').trim() !== '') headings.push({ el, level });
246
+
247
+ // Elements that comments and pins need a data-pid on.
248
+ if (/^(header|nav|main|footer|section|article|aside|form|h[1-6]|button|img|a|input|select|textarea)$/.test(tag) && !el.hasAttribute('data-pid') && !(tag === 'a' && !el.hasAttribute('href'))) {
249
+ group(groups.pids, tag, () => ({ tag }), el);
250
+ }
251
+ }
252
+ `;
@@ -0,0 +1,165 @@
1
+ /**
2
+ * A part of the script that `lint.ts` runs inside a rendered design (see `lint-page.ts`): icons and focus rings, and the answer of the script. The parts are one
3
+ * function body, in this order: setup, values, literals, states, elements, checks, focus. Plain JavaScript in a string.
4
+ */
5
+ export const PAGE_FOCUS = String.raw`// Icons that are the whole of a control (a button with only an SVG): their strokes and fills need 3:1 (WCAG 1.4.11)
6
+ // against what is behind them, judged only when every color that the icon paints fails.
7
+ for (const control of [...doc.querySelectorAll(pointed)].slice(0, 300)) {
8
+ const icon = control.querySelector('svg');
9
+
10
+ if (!icon || (control.textContent || '').trim() !== '' || control.localName === 'input' || control.matches(':disabled')) continue;
11
+
12
+ const box = control.getBoundingClientRect();
13
+ let node = icon.parentElement;
14
+
15
+ while (node && !states.get(node)) node = node.parentElement;
16
+
17
+ const state = node ? states.get(node) : null;
18
+
19
+ if (!state || state.uncertain || box.width <= 0 || box.height <= 0 || getComputedStyle(control).visibility !== 'visible') continue;
20
+
21
+ const painted = [];
22
+ let unknown = false;
23
+
24
+ for (const shape of [...icon.querySelectorAll('path,circle,rect,line,polyline,polygon,ellipse')].slice(0, 60)) {
25
+ const look = getComputedStyle(shape);
26
+
27
+ if (look.display === 'none' || look.visibility !== 'visible') continue;
28
+
29
+ // The default fill of a shape is black: it counts only when the icon says so (an attribute or a style), as a line
30
+ // drawn with a stroke has no area to fill.
31
+ let said = false;
32
+
33
+ for (let each = shape; each && each !== icon.parentElement; each = each.parentElement) {
34
+ if (each.hasAttribute('fill') || (each.style && each.style.fill)) said = true;
35
+ }
36
+
37
+ for (const [paint, on] of [[look.fill, look.fill !== 'none' && (said || look.fill !== 'rgb(0, 0, 0)')], [look.stroke, look.stroke !== 'none' && pxOf(look.strokeWidth) > 0]]) {
38
+ if (!on) continue;
39
+
40
+ const rgba = toRgba(paint);
41
+
42
+ if (!rgba) unknown = true;
43
+ else if (rgba[3] * state.cum > 0.05) painted.push(rgba);
44
+ }
45
+ }
46
+
47
+ if (unknown || painted.length === 0) continue;
48
+
49
+ const ratios = painted.map((rgba) => contrastOf(mix(state.back, rgba, rgba[3]), state.back));
50
+
51
+ if (Math.max(...ratios) < 3) {
52
+ const best = painted[ratios.indexOf(Math.max(...ratios))];
53
+ const fg = mix(state.back, best, best[3]).map(Math.round);
54
+ const bg = state.back.map(Math.round);
55
+
56
+ group(groups.contrast, 'icon|' + fg + '|' + bg, () => ({ fg, bg, size: 0, large: false, ui: true, ratio: Math.max(...ratios), what: 'icon', tag: control.localName, edges: [] }), control);
57
+ }
58
+ }
59
+
60
+ // Focus: put the focus on one element of each kind and see whether anything about it, or around it, changes.
61
+ const focusProps = ['outlineStyle', 'outlineWidth', 'outlineColor', 'boxShadow', 'borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor', 'borderTopWidth', 'backgroundColor', 'color', 'textDecorationLine', 'textDecorationColor', 'filter', 'opacity', 'transform', 'backgroundImage'];
62
+ const snapshot = (list) => list.map((node) => { const s = getComputedStyle(node); return focusProps.map((p) => s[p]).join('|'); }).join('||');
63
+ const focusResults = [];
64
+ const startActive = doc.activeElement;
65
+
66
+ for (const { el, count } of [...focusCandidates.values()].slice(0, 40)) {
67
+ if (focusResults.length >= 20) break;
68
+
69
+ const scope = new Set([el, ...[...el.querySelectorAll('*')].slice(0, 12), ...(el.labels ? [...el.labels] : [])]);
70
+ let ancestor = el.parentElement;
71
+
72
+ for (let depth = 0; ancestor && depth < 3; depth++) {
73
+ scope.add(ancestor);
74
+ [...ancestor.children].slice(0, 12).forEach((child) => scope.add(child));
75
+ ancestor = ancestor.parentElement;
76
+ }
77
+
78
+ const list = [...scope];
79
+ const before = snapshot(list);
80
+ const rest = getComputedStyle(el);
81
+ const restOutline = [rest.outlineStyle, rest.outlineWidth, rest.outlineColor].join('|');
82
+ const restShadow = rest.boxShadow;
83
+ const restRing = restOutline + '|' + restShadow;
84
+
85
+ try {
86
+ el.focus({ preventScroll: true, focusVisible: true });
87
+ } catch {
88
+ continue;
89
+ }
90
+
91
+ if (doc.activeElement !== el) continue;
92
+
93
+ const after = snapshot(list);
94
+ const style = getComputedStyle(el);
95
+ const ring = !/^(none|hidden)$/.test(style.outlineStyle) && pxOf(style.outlineWidth) !== 0 && (toRgba(style.outlineColor) || [0, 0, 0, 0])[3] > 0;
96
+
97
+ // The ring that the focus draws (an outline or a spread-only shadow that was not there at rest), and how it reads
98
+ // against what is around it: 3:1 (WCAG 1.4.11). The browser's own auto ring is two-toned and is left alone.
99
+ const drawn = [style.outlineStyle, style.outlineWidth, style.outlineColor, style.boxShadow].join('|');
100
+ const state = states.get(el);
101
+
102
+ if (state && !state.uncertain && drawn !== restRing && style.outlineStyle !== 'auto') {
103
+ const rings = [];
104
+
105
+ if (ring && restOutline !== [style.outlineStyle, style.outlineWidth, style.outlineColor].join('|')) {
106
+ const color = toRgba(style.outlineColor);
107
+
108
+ rings.push({ color, back: pxOf(style.outlineOffset) < 0 ? state.back : state.before });
109
+ }
110
+
111
+ for (const layer of style.boxShadow === restShadow ? [] : style.boxShadow.split(/,(?![^(]*\))/)) {
112
+ const m = /^\s*(rgba?\([^)]*\)|color\([^)]*\)|#[0-9a-f]+)\s+(-?[\d.]+)px\s+(-?[\d.]+)px\s+([\d.]+)px\s+([\d.]+)px\s*$/i.exec(layer);
113
+
114
+ if (m && parseFloat(m[2]) === 0 && parseFloat(m[3]) === 0 && parseFloat(m[4]) === 0 && parseFloat(m[5]) >= 1) rings.push({ color: toRgba(m[1]), back: state.before });
115
+ }
116
+
117
+ const ratios = rings.filter((item) => item.color && item.color[3] > 0).map((item) => ({ ratio: contrastOf(mix(item.back, item.color, item.color[3]), item.back), item }));
118
+
119
+ // Every ring that it draws must fail: a double ring (a light gap, then a dark ring) passes by its best.
120
+ if (ratios.length > 0 && Math.max(...ratios.map((r) => r.ratio)) < 3) {
121
+ const worst = ratios.sort((a, b) => b.ratio - a.ratio)[0];
122
+ const fg = mix(worst.item.back, worst.item.color, worst.item.color[3]).map(Math.round);
123
+ const bg = worst.item.back.map(Math.round);
124
+
125
+ group(groups.contrast, 'ring|' + fg + '|' + bg, () => ({ fg, bg, size: 0, large: false, ui: true, ratio: worst.ratio, what: 'focus', tag: el.localName, edges: [] }), el);
126
+ }
127
+ }
128
+
129
+ el.blur();
130
+
131
+ if (!ring && before === after) {
132
+ focusResults.push({ count, tag: el.localName, outlineNone: style.outlineStyle === 'none' || pxOf(style.outlineWidth) === 0, el: infoOf(el) });
133
+ }
134
+ }
135
+
136
+ if (startActive && startActive !== doc.body) startActive.focus({ preventScroll: true });
137
+
138
+ calm.remove();
139
+ probeHost.remove();
140
+
141
+ return {
142
+ elements,
143
+ viewport: { width: win.innerWidth, height: win.innerHeight },
144
+ hasViewportMeta: doc.querySelector('meta[name=viewport]') !== null,
145
+ resolvedColors,
146
+ resolvedLengths,
147
+ colors: finish(groups.colors),
148
+ fonts: finish(groups.fonts),
149
+ sizes: finish(groups.sizes),
150
+ contrast: finish(groups.contrast),
151
+ targets: finish(groups.targets),
152
+ overflow,
153
+ images: finish(groups.images),
154
+ headings: headingResults,
155
+ fontFaces,
156
+ focus: focusResults,
157
+ pids: finish(groups.pids),
158
+ notJudged: { count: notJudged.count, elements: notJudged.els.map(selectorOf) },
159
+ semantics,
160
+ labels: finish(groups.labels),
161
+ names: finish(groups.names),
162
+ zoom: finish(groups.zoom),
163
+ motion: { count: motion.count, longest: motion.longest, override: motion.override, unreadable: motion.unreadable, el: motion.first ? infoOf(motion.first) : undefined },
164
+ };
165
+ })`;