sugikit 0.0.1 → 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 (72) hide show
  1. package/LICENSE +29 -21
  2. package/README.md +45 -0
  3. package/dist/api/browser.d.ts +5 -0
  4. package/dist/api/browser.js +5 -0
  5. package/dist/api/rules.d.ts +12 -0
  6. package/dist/api/rules.js +14 -0
  7. package/dist/auth.d.ts +156 -0
  8. package/dist/auth.js +547 -0
  9. package/dist/browser.d.ts +25 -0
  10. package/dist/browser.js +120 -0
  11. package/dist/check.d.ts +21 -0
  12. package/dist/check.js +89 -0
  13. package/dist/convert-probe.d.ts +21 -0
  14. package/dist/convert-probe.js +647 -0
  15. package/dist/fetch.d.ts +6 -0
  16. package/dist/fetch.js +22 -0
  17. package/dist/framework.d.ts +2 -0
  18. package/dist/framework.js +17 -0
  19. package/dist/gather.d.ts +48 -0
  20. package/dist/gather.js +211 -0
  21. package/dist/html.d.ts +17 -0
  22. package/dist/html.js +43 -0
  23. package/dist/http.d.ts +36 -0
  24. package/dist/http.js +57 -0
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.js +331 -0
  27. package/dist/links.d.ts +8 -0
  28. package/dist/links.js +69 -0
  29. package/dist/polish-run.d.ts +115 -0
  30. package/dist/polish-run.js +357 -0
  31. package/dist/probe.d.ts +14 -0
  32. package/dist/probe.js +457 -0
  33. package/dist/psi-scores.d.ts +4 -0
  34. package/dist/psi-scores.js +7 -0
  35. package/dist/psi.d.ts +56 -0
  36. package/dist/psi.js +192 -0
  37. package/dist/release.d.ts +1 -0
  38. package/dist/release.js +5 -0
  39. package/dist/render.d.ts +28 -0
  40. package/dist/render.js +270 -0
  41. package/dist/report.d.ts +227 -0
  42. package/dist/report.js +69 -0
  43. package/dist/rules/convert-render.d.ts +100 -0
  44. package/dist/rules/convert-render.js +279 -0
  45. package/dist/rules/convert.d.ts +15 -0
  46. package/dist/rules/convert.js +322 -0
  47. package/dist/rules/fixes.d.ts +16 -0
  48. package/dist/rules/fixes.js +536 -0
  49. package/dist/rules/geo.d.ts +15 -0
  50. package/dist/rules/geo.js +112 -0
  51. package/dist/rules/polish.d.ts +59 -0
  52. package/dist/rules/polish.js +223 -0
  53. package/dist/rules/robots.d.ts +14 -0
  54. package/dist/rules/robots.js +69 -0
  55. package/dist/rules/seo.d.ts +31 -0
  56. package/dist/rules/seo.js +208 -0
  57. package/dist/rules/types.d.ts +55 -0
  58. package/dist/rules/types.js +78 -0
  59. package/dist/score.d.ts +6 -0
  60. package/dist/score.js +23 -0
  61. package/dist/skills.d.ts +9 -0
  62. package/dist/skills.js +22 -0
  63. package/package.json +64 -4
  64. package/skills/INSTALL_PROMPT.md +9 -0
  65. package/skills/sugikit/SKILL.md +147 -0
  66. package/skills/sugikit/references/convert.md +127 -0
  67. package/skills/sugikit/references/geo.md +97 -0
  68. package/skills/sugikit/references/next.md +254 -0
  69. package/skills/sugikit/references/pagespeed.md +94 -0
  70. package/skills/sugikit/references/polish.md +123 -0
  71. package/skills/sugikit/references/seo.md +150 -0
  72. package/skills/sugikit/references/tanstack-start.md +246 -0
@@ -0,0 +1,112 @@
1
+ import { isAllowed, parseRobots } from "./robots.js";
2
+ import { isHtmlPage, jsonLdBlocks, jsonLdTypes, notApplicable, result, textStatusMessage, validText, } from "./types.js";
3
+ export const AI_CRAWLERS = [
4
+ "GPTBot",
5
+ "OAI-SearchBot",
6
+ "ChatGPT-User",
7
+ "ClaudeBot",
8
+ "Claude-SearchBot",
9
+ "Claude-User",
10
+ "PerplexityBot",
11
+ "Google-Extended",
12
+ "Applebot-Extended",
13
+ ];
14
+ export const MIN_SSR_TEXT = 400;
15
+ export const MAX_HERO_WORDS = 30;
16
+ export const geoLlmsTxt = ({ url, llmsTxt }) => {
17
+ return result("geo/llms-txt", "error", validText(llmsTxt), textStatusMessage("/llms.txt", llmsTxt), {
18
+ url: new URL("/llms.txt", url).href,
19
+ });
20
+ };
21
+ export const geoLlmsTxtFormat = ({ url, llmsTxt }) => {
22
+ const extra = { url: new URL("/llms.txt", url).href };
23
+ if (!validText(llmsTxt))
24
+ return notApplicable("geo/llms-txt-format", "No /llms.txt to check (see geo/llms-txt)", extra);
25
+ const body = llmsTxt.body.replace(/^/, "").trimStart();
26
+ const problems = [];
27
+ if (!body.startsWith("# "))
28
+ problems.push('does not start with a "# " heading');
29
+ if (!/\[[^\][]+\]\([^)\s[]+\)/.test(body))
30
+ problems.push("has no markdown link");
31
+ return result("geo/llms-txt-format", "warn", problems.length === 0, problems.length === 0 ? "/llms.txt has a heading and links" : `/llms.txt ${problems.join(" and ")}`, { ...extra, ...(problems.length ? { evidence: body.slice(0, 120) } : {}) });
32
+ };
33
+ export const geoLlmsFullTxt = ({ url, llmsFullTxt }) => {
34
+ return result("geo/llms-full-txt", "warn", validText(llmsFullTxt), textStatusMessage("/llms-full.txt", llmsFullTxt), {
35
+ url: new URL("/llms-full.txt", url).href,
36
+ });
37
+ };
38
+ export const geoAiCrawlers = ({ url, robotsTxt }) => {
39
+ const extra = { url: new URL("/robots.txt", url).href };
40
+ // RFC 9309: an unreachable robots.txt (5xx or no response) means disallow all; 4xx means allow all.
41
+ if (!robotsTxt || robotsTxt.status >= 500) {
42
+ return result("geo/ai-crawlers", "warn", false, `robots.txt returned ${robotsTxt?.status ?? "no response"}, so crawlers treat the whole site as blocked`, extra);
43
+ }
44
+ if (robotsTxt.status !== 200) {
45
+ return result("geo/ai-crawlers", "warn", true, "No robots.txt, so AI crawlers are not blocked", extra);
46
+ }
47
+ if (isHtmlPage(robotsTxt)) {
48
+ return result("geo/ai-crawlers", "warn", true, "robots.txt is an HTML page with no rules, so AI crawlers are not blocked", extra);
49
+ }
50
+ const robots = parseRobots(robotsTxt.body);
51
+ const blocked = AI_CRAWLERS.filter((agent) => !isAllowed(robots, agent, "/"));
52
+ return result("geo/ai-crawlers", "warn", blocked.length === 0, blocked.length === 0 ? "robots.txt allows AI crawlers" : `robots.txt blocks ${blocked.length} AI crawler(s) from /`, { ...extra, ...(blocked.length ? { evidence: blocked.join(", ") } : {}) });
53
+ };
54
+ export const geoFaqSchema = ({ $ }) => {
55
+ const ok = jsonLdBlocks($).valid.flatMap(jsonLdTypes).includes("FAQPage");
56
+ return result("geo/faq-schema", "warn", ok, ok ? "Page has FAQPage JSON-LD" : "Page has no FAQPage JSON-LD", { selector: 'script[type="application/ld+json"]' });
57
+ };
58
+ export function visibleText({ $ }) {
59
+ const body = $("body").clone();
60
+ body.find("script, style, noscript, template").remove();
61
+ return body.text().replace(/\s+/g, " ").trim();
62
+ }
63
+ export const geoSsrContent = (ctx) => {
64
+ const length = visibleText(ctx).length;
65
+ const ok = length >= MIN_SSR_TEXT;
66
+ return result("geo/ssr-content", "error", ok, ok
67
+ ? `Server HTML has ${length} characters of visible text`
68
+ : `Server HTML has only ${length} characters of visible text (minimum ${MIN_SSR_TEXT}); crawlers that do not run JavaScript see almost nothing`);
69
+ };
70
+ function heroParagraph({ $ }) {
71
+ let seenH1 = false;
72
+ for (const el of $("h1, p").toArray()) {
73
+ if (el.tagName === "h1") {
74
+ seenH1 = true;
75
+ continue;
76
+ }
77
+ if (!seenH1)
78
+ continue;
79
+ const text = $(el).text().replace(/\s+/g, " ").trim();
80
+ if (text)
81
+ return text;
82
+ }
83
+ return undefined;
84
+ }
85
+ export function firstSentence(text) {
86
+ return text.split(/(?<=[.!?])\s+/)[0] ?? text;
87
+ }
88
+ export const geoHeroStatement = (ctx) => {
89
+ const text = heroParagraph(ctx);
90
+ return result("geo/hero-statement", "warn", text !== undefined, text ? "A paragraph follows the h1" : "No <p> follows the h1 to state what the product is", { selector: "h1 ~ p", ...(text ? { evidence: text.slice(0, 200) } : {}) });
91
+ };
92
+ export const geoHeroLength = (ctx) => {
93
+ const text = heroParagraph(ctx);
94
+ if (!text)
95
+ return result("geo/hero-length", "info", false, "No hero paragraph to measure");
96
+ const sentence = firstSentence(text);
97
+ const words = sentence.split(/\s+/).filter(Boolean).length;
98
+ const ok = words <= MAX_HERO_WORDS;
99
+ return result("geo/hero-length", "info", ok, ok
100
+ ? `Hero first sentence is ${words} words`
101
+ : `Hero first sentence is ${words} words, keep it at ${MAX_HERO_WORDS} or fewer so AI answers can quote it`, { evidence: sentence });
102
+ };
103
+ export const geoRules = [
104
+ geoLlmsTxt,
105
+ geoLlmsTxtFormat,
106
+ geoLlmsFullTxt,
107
+ geoAiCrawlers,
108
+ geoFaqSchema,
109
+ geoSsrContent,
110
+ geoHeroStatement,
111
+ geoHeroLength,
112
+ ];
@@ -0,0 +1,59 @@
1
+ import { type RuleResult } from "./types.js";
2
+ export declare const STATE_NAMES: readonly ["desktop-light", "desktop-dark", "phone-light", "phone-dark"];
3
+ export type StateName = (typeof STATE_NAMES)[number];
4
+ export declare const REDUCED_MOTION_STATE = "phone-light-reduced-motion";
5
+ export declare const MIN_TARGET_PX = 24;
6
+ export declare const MAX_FONT_SIZES = 12;
7
+ export declare const FONT_SIZE_GROUP_PX = 1;
8
+ export declare const MIN_BODY_PX = 15;
9
+ export declare const MAX_SMALL_BODY_SHARE = 0.5;
10
+ export declare const MAX_LINE_CHARS = 85;
11
+ export declare const MAX_OFF_GRID_SHARE = 0.25;
12
+ export declare const MAX_EVIDENCE = 5;
13
+ export interface Hit {
14
+ selector: string;
15
+ detail?: string;
16
+ }
17
+ export interface Probe {
18
+ scrolls: boolean;
19
+ scrollWidth: number;
20
+ clientWidth: number;
21
+ overflow: Hit[];
22
+ smallTargets: Hit[];
23
+ fontSizes: number[];
24
+ smallText: Hit[];
25
+ bodyText: {
26
+ total: number;
27
+ bySize: Record<string, number>;
28
+ };
29
+ longLines: Hit[];
30
+ spacing: number[];
31
+ unsizedImages: Hit[];
32
+ oversizedImages: Hit[];
33
+ theme: {
34
+ background: string;
35
+ text: string;
36
+ };
37
+ }
38
+ export interface AxeViolation {
39
+ id: string;
40
+ impact: string;
41
+ count: number;
42
+ selector?: string;
43
+ }
44
+ export declare const REQUIRED_STATES: readonly ["desktop-light", "phone-light"];
45
+ export type RequiredState = (typeof REQUIRED_STATES)[number];
46
+ export interface PolishData {
47
+ probes: Record<RequiredState, Probe> & Partial<Record<StateName, Probe>>;
48
+ contrast: Partial<Record<StateName, Hit[]>>;
49
+ axe: AxeViolation[];
50
+ motion?: Hit[];
51
+ }
52
+ export declare const POLISH_RULE_IDS: string[];
53
+ export declare function formatHits(hits: Hit[]): string;
54
+ export declare function sizeSteps(sizes: number[], groupPx?: number): number[];
55
+ export declare function offGrid(values: number[]): number[];
56
+ export declare const COLOR_TOLERANCE = 2;
57
+ export declare function sameColor(a: string, b: string): boolean;
58
+ export declare function sameColors(a: string, b: string): boolean;
59
+ export declare function polishRules(data: PolishData): RuleResult[];
@@ -0,0 +1,223 @@
1
+ import { result } from "./types.js";
2
+ export const STATE_NAMES = ["desktop-light", "desktop-dark", "phone-light", "phone-dark"];
3
+ export const REDUCED_MOTION_STATE = "phone-light-reduced-motion";
4
+ export const MIN_TARGET_PX = 24;
5
+ // Distinct content font sizes after grouping sizes within FONT_SIZE_GROUP_PX. Calibrated on a study of 100 indie
6
+ // landing pages (2026-11-21): grouped counts over all text had a median of 11 and a 75th percentile of 14, and the
7
+ // old limit of 8 failed 97% of pages, so it could not tell a tidy page from a messy one. Tailwind's default scale has
8
+ // 13 steps; a page that uses 12 or fewer content sizes reads as one system. Counting only content text (below)
9
+ // lowers every page by a few sizes, so 12 fails only the clearly scattered scales.
10
+ export const MAX_FONT_SIZES = 12;
11
+ export const FONT_SIZE_GROUP_PX = 1;
12
+ // polish/body-text-size: fails when more than MAX_SMALL_BODY_SHARE of the phone body text is under MIN_BODY_PX.
13
+ // Lighthouse's legible-font floor is 12 px and common body guidance is 16 px. 15 px keeps dense 14 px UI text
14
+ // flagged without failing 15 px designs. In the same study 76 of 90 pages had some 13 to 15 px paragraphs (card
15
+ // copy, captions, notes), so a few small paragraphs never fail: only most of the body copy does.
16
+ export const MIN_BODY_PX = 15;
17
+ export const MAX_SMALL_BODY_SHARE = 0.5;
18
+ export const MAX_LINE_CHARS = 85;
19
+ export const MAX_OFF_GRID_SHARE = 0.25;
20
+ export const MAX_EVIDENCE = 5;
21
+ // desktop-light and phone-light always run. The other states and the reduced motion run can be skipped when a
22
+ // check runs out of time; the rules that need them are left out then.
23
+ export const REQUIRED_STATES = ["desktop-light", "phone-light"];
24
+ export const POLISH_RULE_IDS = [
25
+ "polish/horizontal-scroll",
26
+ "polish/tap-targets",
27
+ "polish/contrast",
28
+ "polish/axe",
29
+ "polish/type-scale",
30
+ "polish/body-text-size",
31
+ "polish/line-length",
32
+ "polish/spacing-scale",
33
+ "polish/img-dimensions",
34
+ "polish/dark-mode",
35
+ "polish/reduced-motion",
36
+ ];
37
+ export function formatHits(hits) {
38
+ const shown = hits.slice(0, MAX_EVIDENCE).map((hit) => (hit.detail ? `${hit.selector} (${hit.detail})` : hit.selector));
39
+ const rest = hits.length - shown.length;
40
+ return rest > 0 ? `${shown.join("; ")}; and ${rest} more` : shown.join("; ");
41
+ }
42
+ function hitsResult(id, severity, hits, passMessage, failMessage) {
43
+ const first = hits[0];
44
+ if (!first)
45
+ return result(id, severity, true, passMessage);
46
+ return result(id, severity, false, failMessage, { selector: first.selector, evidence: formatHits(hits) });
47
+ }
48
+ function horizontalScroll({ probes }) {
49
+ const phone = probes["phone-light"];
50
+ if (!phone.scrolls)
51
+ return result("polish/horizontal-scroll", "error", true, `No horizontal scroll at ${phone.clientWidth} px`);
52
+ const first = phone.overflow[0];
53
+ return result("polish/horizontal-scroll", "error", false, `Page scrolls sideways on a phone: ${phone.scrollWidth} px of content in a ${phone.clientWidth} px viewport`, {
54
+ ...(first ? { selector: first.selector, evidence: formatHits(phone.overflow) } : {}),
55
+ });
56
+ }
57
+ function tapTargets({ probes }) {
58
+ const hits = probes["phone-light"].smallTargets;
59
+ return hitsResult("polish/tap-targets", "warn", hits, `Controls are at least ${MIN_TARGET_PX}x${MIN_TARGET_PX} px or spaced apart on a phone (WCAG 2.5.8)`, `${hits.length} controls are smaller than ${MIN_TARGET_PX}x${MIN_TARGET_PX} px and too close to another control on a phone (WCAG 2.5.8)`);
60
+ }
61
+ function contrast({ contrast: byState }) {
62
+ const merged = new Map();
63
+ const failing = [];
64
+ const checked = STATE_NAMES.filter((state) => byState[state] !== undefined);
65
+ for (const state of checked) {
66
+ const hits = byState[state] ?? [];
67
+ if (hits.length > 0)
68
+ failing.push(state);
69
+ for (const hit of hits) {
70
+ const entry = merged.get(hit.selector) ?? { states: [], ...(hit.detail ? { detail: hit.detail } : {}) };
71
+ entry.states.push(state);
72
+ merged.set(hit.selector, entry);
73
+ }
74
+ }
75
+ const hits = [...merged].map(([selector, entry]) => ({
76
+ selector,
77
+ detail: [entry.detail, entry.states.join(", ")].filter(Boolean).join(", "),
78
+ }));
79
+ return hitsResult("polish/contrast", "error", hits, `Text contrast passes in ${checked.join(", ")}`, `${hits.length} elements have low text contrast in ${failing.join(", ")}`);
80
+ }
81
+ function axe({ axe: violations }) {
82
+ const serious = violations.filter((v) => v.id !== "color-contrast" && (v.impact === "serious" || v.impact === "critical"));
83
+ const first = serious.find((v) => v.selector);
84
+ if (serious.length === 0)
85
+ return result("polish/axe", "warn", true, "No serious or critical axe violations in desktop-light");
86
+ return result("polish/axe", "warn", false, `${serious.length} serious or critical axe rules fail in desktop-light`, {
87
+ ...(first?.selector ? { selector: first.selector } : {}),
88
+ evidence: serious.map((v) => `${v.id} (${v.impact}, ${v.count})`).join("; "),
89
+ });
90
+ }
91
+ // Groups sorted sizes into steps: a size joins the current step when it is within groupPx of the step's first size.
92
+ // 14, 14.5 and 15 are one step; 12, 13, 14, 15 are two (12-13, 14-15), so a chain of close sizes cannot collapse.
93
+ export function sizeSteps(sizes, groupPx = FONT_SIZE_GROUP_PX) {
94
+ const steps = [];
95
+ for (const size of [...new Set(sizes)].sort((a, b) => a - b)) {
96
+ const last = steps[steps.length - 1];
97
+ if (last === undefined || size - last > groupPx)
98
+ steps.push(size);
99
+ }
100
+ return steps;
101
+ }
102
+ function typeScale({ probes }) {
103
+ const sizes = probes["desktop-light"].fontSizes;
104
+ const steps = sizeSteps(sizes);
105
+ const ok = steps.length <= MAX_FONT_SIZES;
106
+ return result("polish/type-scale", "warn", ok, ok ? `${steps.length} font sizes` : `${steps.length} font sizes, aim for ${MAX_FONT_SIZES} or fewer`, ok ? {} : { evidence: `sizes: ${sizes.map((s) => `${s}px`).join(", ")}` });
107
+ }
108
+ function bodyTextSize({ probes }) {
109
+ const id = "polish/body-text-size";
110
+ const phone = probes["phone-light"];
111
+ const { total, bySize } = phone.bodyText;
112
+ const small = Object.entries(bySize)
113
+ .map(([size, chars]) => ({ size: Number(size), chars }))
114
+ .filter((entry) => entry.size < MIN_BODY_PX)
115
+ .sort((a, b) => b.chars - a.chars);
116
+ const smallChars = small.reduce((sum, entry) => sum + entry.chars, 0);
117
+ const share = total > 0 ? smallChars / total : 0;
118
+ const percent = Math.round(share * 100);
119
+ if (share <= MAX_SMALL_BODY_SHARE) {
120
+ return result(id, "warn", true, total > 0 ? `${100 - percent}% of paragraph text is ${MIN_BODY_PX} px or larger on a phone` : "No body paragraphs to measure");
121
+ }
122
+ const common = small[0]?.size;
123
+ const first = phone.smallText[0];
124
+ return result(id, "warn", false, `${percent}% of paragraph text is under ${MIN_BODY_PX} px on a phone`, {
125
+ ...(first ? { selector: first.selector } : {}),
126
+ evidence: [`${percent}% of ${total} characters under ${MIN_BODY_PX} px`, `most common small size: ${common}px`, `paragraphs: ${formatHits(phone.smallText)}`].join(" | "),
127
+ });
128
+ }
129
+ function lineLength({ probes }) {
130
+ const hits = probes["desktop-light"].longLines;
131
+ return hitsResult("polish/line-length", "warn", hits, `Paragraph lines stay under ${MAX_LINE_CHARS} characters at 1440 px`, `${hits.length} paragraphs run longer than ${MAX_LINE_CHARS} characters per line at 1440 px`);
132
+ }
133
+ export function offGrid(values) {
134
+ return values.filter((v) => Math.abs(v / 4 - Math.round(v / 4)) > 0.01).sort((a, b) => a - b);
135
+ }
136
+ function spacingScale({ probes }) {
137
+ const values = probes["desktop-light"].spacing;
138
+ const off = offGrid(values);
139
+ const ok = values.length === 0 || off.length / values.length <= MAX_OFF_GRID_SHARE;
140
+ return result("polish/spacing-scale", "warn", ok, ok
141
+ ? `${values.length - off.length} of ${values.length} spacing values sit on a 4 px grid`
142
+ : `${off.length} of ${values.length} distinct spacing values are not multiples of 4 px`, off.length > 0 ? { evidence: off.map((v) => `${v}px`).join(", ") } : {});
143
+ }
144
+ function imgDimensions({ probes }) {
145
+ const { unsizedImages, oversizedImages } = probes["desktop-light"];
146
+ const problems = [];
147
+ if (unsizedImages.length > 0)
148
+ problems.push(`${unsizedImages.length} images have no width and height`);
149
+ if (oversizedImages.length > 0)
150
+ problems.push(`${oversizedImages.length} images are more than 2x their display size`);
151
+ if (problems.length === 0)
152
+ return result("polish/img-dimensions", "warn", true, "Images reserve their space and fit their display size");
153
+ const evidence = [];
154
+ if (unsizedImages.length > 0)
155
+ evidence.push(`no size: ${formatHits(unsizedImages)}`);
156
+ if (oversizedImages.length > 0)
157
+ evidence.push(`oversized: ${formatHits(oversizedImages)}`);
158
+ const first = unsizedImages[0] ?? oversizedImages[0];
159
+ return result("polish/img-dimensions", "warn", false, problems.join("; "), {
160
+ ...(first ? { selector: first.selector } : {}),
161
+ evidence: evidence.join(" | "),
162
+ });
163
+ }
164
+ export const COLOR_TOLERANCE = 2;
165
+ function channels(color) {
166
+ const match = /^rgba?\(([^)]+)\)$/.exec(color.trim());
167
+ if (!match?.[1])
168
+ return undefined;
169
+ const parts = match[1].split(/[\s,/]+/).filter(Boolean).map(Number);
170
+ if (parts.length < 3 || parts.some(Number.isNaN))
171
+ return undefined;
172
+ const [r = 0, g = 0, b = 0, a = 1] = parts;
173
+ return [r, g, b, a * 255];
174
+ }
175
+ export function sameColor(a, b) {
176
+ const x = channels(a);
177
+ const y = channels(b);
178
+ if (!x || !y)
179
+ return a.trim() === b.trim();
180
+ return x.every((value, i) => Math.abs(value - (y[i] ?? 0)) <= COLOR_TOLERANCE);
181
+ }
182
+ export function sameColors(a, b) {
183
+ const xs = a.split(" | ");
184
+ const ys = b.split(" | ");
185
+ return xs.length === ys.length && xs.every((x, i) => sameColor(x, ys[i] ?? ""));
186
+ }
187
+ function darkMode({ probes }) {
188
+ const light = probes["desktop-light"].theme;
189
+ const dark = probes["desktop-dark"]?.theme;
190
+ if (!dark)
191
+ return undefined;
192
+ const background = !sameColors(light.background, dark.background);
193
+ const text = !sameColors(light.text, dark.text);
194
+ const evidence = `light: ${light.background} / ${light.text}; dark: ${dark.background} / ${dark.text}`;
195
+ if (background && text) {
196
+ return result("polish/dark-mode", "info", true, "Page has a dark mode (contrast in dark is checked by polish/contrast)");
197
+ }
198
+ if (!background && !text)
199
+ return result("polish/dark-mode", "info", false, "Page has no dark mode", { evidence });
200
+ return result("polish/dark-mode", "warn", false, `Dark mode changes only the ${background ? "background" : "text color"}`, { evidence });
201
+ }
202
+ function reducedMotion({ motion }) {
203
+ if (!motion)
204
+ return undefined;
205
+ return hitsResult("polish/reduced-motion", "warn", motion, "No long or endless motion runs when reduced motion is on", `${motion.length} animations still run with prefers-reduced-motion: reduce`);
206
+ }
207
+ // Rules whose state was skipped (out of time) are left out.
208
+ export function polishRules(data) {
209
+ const rules = [
210
+ horizontalScroll,
211
+ tapTargets,
212
+ contrast,
213
+ axe,
214
+ typeScale,
215
+ bodyTextSize,
216
+ lineLength,
217
+ spacingScale,
218
+ imgDimensions,
219
+ darkMode,
220
+ reducedMotion,
221
+ ];
222
+ return rules.map((rule) => rule(data)).filter((item) => item !== undefined);
223
+ }
@@ -0,0 +1,14 @@
1
+ export interface RobotsRule {
2
+ allow: boolean;
3
+ pattern: string;
4
+ }
5
+ export interface RobotsGroup {
6
+ agents: string[];
7
+ rules: RobotsRule[];
8
+ }
9
+ export interface Robots {
10
+ groups: RobotsGroup[];
11
+ sitemaps: string[];
12
+ }
13
+ export declare function parseRobots(body: string): Robots;
14
+ export declare function isAllowed(robots: Robots, agent: string, path?: string): boolean;
@@ -0,0 +1,69 @@
1
+ export function parseRobots(body) {
2
+ const groups = [];
3
+ const sitemaps = [];
4
+ let current;
5
+ let lastWasAgent = false;
6
+ for (const rawLine of body.split(/\r\n|\r|\n/)) {
7
+ const line = rawLine.replace(/#.*$/, "").trim();
8
+ const colon = line.indexOf(":");
9
+ if (colon === -1)
10
+ continue;
11
+ const key = line.slice(0, colon).trim().toLowerCase();
12
+ const value = line.slice(colon + 1).trim();
13
+ if (key === "user-agent") {
14
+ if (!current || !lastWasAgent) {
15
+ current = { agents: [], rules: [] };
16
+ groups.push(current);
17
+ }
18
+ current.agents.push(value.toLowerCase());
19
+ lastWasAgent = true;
20
+ }
21
+ else if (key === "allow" || key === "disallow") {
22
+ lastWasAgent = false;
23
+ if (!current)
24
+ continue;
25
+ if (key === "disallow" && value === "")
26
+ continue;
27
+ current.rules.push({ allow: key === "allow", pattern: value });
28
+ }
29
+ else if (key === "sitemap") {
30
+ if (value)
31
+ sitemaps.push(value);
32
+ }
33
+ else {
34
+ lastWasAgent = false;
35
+ }
36
+ }
37
+ return { groups, sitemaps };
38
+ }
39
+ function patternMatches(pattern, path) {
40
+ const anchored = pattern.endsWith("$");
41
+ const body = anchored ? pattern.slice(0, -1) : pattern;
42
+ const source = body
43
+ .split("*")
44
+ .map((part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&"))
45
+ .join(".*");
46
+ return new RegExp(`^${source}${anchored ? "$" : ""}`).test(path);
47
+ }
48
+ function groupsFor(robots, agent) {
49
+ const name = agent.toLowerCase();
50
+ const named = robots.groups.filter((group) => group.agents.includes(name));
51
+ if (named.length > 0)
52
+ return named;
53
+ return robots.groups.filter((group) => group.agents.includes("*"));
54
+ }
55
+ export function isAllowed(robots, agent, path = "/") {
56
+ let best;
57
+ for (const group of groupsFor(robots, agent)) {
58
+ for (const rule of group.rules) {
59
+ if (!patternMatches(rule.pattern, path))
60
+ continue;
61
+ if (!best ||
62
+ rule.pattern.length > best.pattern.length ||
63
+ (rule.pattern.length === best.pattern.length && rule.allow)) {
64
+ best = rule;
65
+ }
66
+ }
67
+ }
68
+ return best?.allow ?? true;
69
+ }
@@ -0,0 +1,31 @@
1
+ import { type Rule } from "./types.js";
2
+ export declare const JSON_LD_TYPES: string[];
3
+ export declare const seoTitle: Rule;
4
+ export declare const seoTitleLength: Rule;
5
+ export declare const seoMetaDescription: Rule;
6
+ export declare const seoMetaDescriptionLength: Rule;
7
+ export declare const seoHtmlLang: Rule;
8
+ export declare const seoViewport: Rule;
9
+ export declare const seoCanonical: Rule;
10
+ export declare const seoOpenGraph: Rule;
11
+ export declare const seoTwitterCard: Rule;
12
+ export declare const seoJsonLd: Rule;
13
+ export declare const seoJsonLdType: Rule;
14
+ export declare const seoH1: Rule;
15
+ export declare const seoHeadingOrder: Rule;
16
+ export declare const seoImgAlt: Rule;
17
+ export declare const seoFavicon: Rule;
18
+ export declare function blocksIndexing(directives: string): boolean;
19
+ export declare const seoNoindex: Rule;
20
+ export declare const seoRobotsTxt: Rule;
21
+ export declare const seoRobotsSitemap: Rule;
22
+ type SitemapDoc = {
23
+ kind: "urlset" | "sitemapindex";
24
+ entries: number;
25
+ missingLastmod: string[];
26
+ };
27
+ export declare function parseSitemap(body: string): SitemapDoc | undefined;
28
+ export declare const seoSitemap: Rule;
29
+ export declare const seoSitemapLastmod: Rule;
30
+ export declare const seoRules: Rule[];
31
+ export {};