@leonidstern/census 0.0.0-stage → 0.2.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.
@@ -0,0 +1,9 @@
1
+ /** A CSS color as computed ("rgb(1, 2, 3)", "rgba(1, 2, 3, 0.5)", "color(srgb 0.1 0.2 0.3 / 0.5)") as [r, g, b, a] in 0-255 and 0-1; null when it can't be read. */
2
+ export declare function parseColor(css: string): [number, number, number, number] | null;
3
+ /** A read that asks for many colors hands over its own hidden element: the probe stays in it (one append) until the read hands back null. */
4
+ export declare function colorProbe(host: Element | null): void;
5
+ /** `top` drawn over `under` (opaque): what shows. */
6
+ export declare function over(top: [number, number, number, number], under: [number, number, number, number]): [number, number, number, number];
7
+ /** WCAG contrast ratio of two opaque colors, 1 (none) to 21. */
8
+ export declare function contrast(a: [number, number, number, number], b: [number, number, number, number]): number;
9
+ /** A color as #rrggbb, or #rrggbbaa when see-through. */
package/dist/diff.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { Census, CensusItem } from "./census";
2
+ /**
3
+ * Of two reads of one page with no change between them, the elements that differ: they change on their own (a price,
4
+ * a clock, a depth bar). Hover and pressed colors aren't compared: the capture's second read doesn't force them.
5
+ */
6
+ export declare function changesOnItsOwn(a: CensusItem[], b: CensusItem[]): CensusItem[];
7
+ /**
8
+ * What changed between two censuses taken with rules.items. Sections: elements whose look changed (each property
9
+ * before→after), elements that came or went, values the page shows now or no longer (with OFF and near), parts with
10
+ * a new or lost look, and layout problems that appeared or were fixed. Places that only moved are counted.
11
+ * What changes on its own (live data) is left out of the element lists: what differs between each capture and its
12
+ * own second read (`again`, which the capture takes by itself), and between `before` and `live` (a second capture
13
+ * taken before the change), when given. Moves are said grouped: where, how far, and which elements.
14
+ */
15
+ export declare function diffCensus(before: Census, after: Census, max?: number, live?: Census): string[];
@@ -0,0 +1,79 @@
1
+ import type { Census, CensusGroup } from "./census";
2
+ export type Level = "rule" | "accessibility" | "max";
3
+ export type Finding = {
4
+ /** check|subject: no counts or boxes, so the same finding has the same id in two captures */
5
+ id: string;
6
+ check: string;
7
+ level: Level;
8
+ /** the line, without places */
9
+ key: string;
10
+ n: number;
11
+ note?: string;
12
+ at: string[];
13
+ /** the elements it covers, so diff can say what it now also covers */
14
+ values?: string[];
15
+ /** computed styles can't decide (a gradient behind words, a ring set by a script): never fails a build */
16
+ unsure?: boolean;
17
+ };
18
+ /** A check's level and its number, from rules.checks: "off", "rule", a number, or ["rule", number]. */
19
+ export type CheckSetting = "off" | "rule" | number | ["rule", number];
20
+ /** Every check, the level it reports at, and the preset that turns it on (none: on whenever rules.json feeds it). */
21
+ export declare const CHECKS: Record<string, {
22
+ level: Level;
23
+ preset?: string;
24
+ what: string;
25
+ }>;
26
+ export declare const PRESETS: string[];
27
+ /**
28
+ * How many distinct values a group may hold before the max check says so. Flat: a design system is finite whether it
29
+ * draws a login box or a trading terminal, and a cap that grows with the page excuses the pages that need it most.
30
+ * Not every group gets one — states, used and field count occurrences of something that is already a finding, so a
31
+ * cap there would say the same thing twice.
32
+ */
33
+ export declare const MAX_DEFAULTS: Record<string, number>;
34
+ /** What rules.json can say about checks. The whole StyleRules is accepted; only these fields are read. */
35
+ type CheckRules = {
36
+ extends?: string | string[];
37
+ checks?: Record<string, CheckSetting>;
38
+ max?: Record<string, number | "off">;
39
+ } & Partial<Record<"colors" | "type" | "radii" | "shadows" | "parts", unknown>>;
40
+ /**
41
+ * The level a check reports at (null: off) and its number. The rule checks are on whenever rules.json gives what they
42
+ * compare against; the accessibility checks with `extends: "recommended@1"` or when rules.checks names them. The max
43
+ * check is on with `extends: "best-practice@1"`, with a `max` of your own, and by default when rules.json gives no
44
+ * values at all — a first run with no file still says something, which is the whole point of it.
45
+ */
46
+ export declare function checkSetting(rules: CheckRules, check: string): {
47
+ level: Level | null;
48
+ n?: number;
49
+ };
50
+ /** Whether rules ask for the accessibility or max checks (a preset, a check by name, or no values to check against). */
51
+ export declare const asksChecks: (rules: CheckRules) => boolean;
52
+ /**
53
+ * The groups holding more distinct values than their max, rarest values first — those are both the easiest to drop
54
+ * and the likeliest to be accidents. One finding per group, so a diff says a group went over or came back under
55
+ * instead of churning an id every time the tail moves. `groups` are counted whole, trimmed rows included.
56
+ */
57
+ export declare function maxFindings(groups: CensusGroup[], rules: CheckRules, name?: number): Finding[];
58
+ /**
59
+ * The accessibility findings as lines, unsure ones last, then the max findings, each with the values to drop under it.
60
+ * Rule findings are already said OFF in their own groups.
61
+ */
62
+ export declare function findingLines(c: Census, max?: number): string[];
63
+ /**
64
+ * Findings of several pages as one: the same id is one finding, counts added, a place from each page. Max findings
65
+ * are left out — adding two pages' counts says nothing, since the same color on both is one value. mergeCensus
66
+ * counts them again off the merged groups, which is the number that was meant: the system across all the pages.
67
+ */
68
+ export declare function mergeFindings(pages: Record<string, Census>): Finding[] | undefined;
69
+ /**
70
+ * What changed in the findings between two captures. The lines say accessibility findings new and fixed (a value new
71
+ * off the system is already said by diff's values); both levels' new findings are returned, for --fail-on.
72
+ */
73
+ export declare function diffFindings(before: Census, after: Census, max?: number): {
74
+ lines: string[];
75
+ newRules: Finding[];
76
+ newAccessibility: Finding[];
77
+ maxWorse: Finding[];
78
+ };
79
+ export {};
@@ -0,0 +1,6 @@
1
+ export { censusLines, layoutLines, mergeCensus, partOf, shadowLayers, specificity, stateOf, fontDiff, styleData, styleLines, nameOf, ownId, behind } from "./census";
2
+ export type { Census, CensusGroup, CensusItem, CensusLook, CensusRow, StyleRules } from "./census";
3
+ export { changesOnItsOwn, diffCensus } from "./diff";
4
+ export { contrast, over, parseColor } from "./color";
5
+ export { asksChecks, checkSetting, CHECKS, diffFindings, findingLines, maxFindings, MAX_DEFAULTS, mergeFindings, PRESETS } from "./findings";
6
+ export type { CheckSetting, Finding, Level } from "./findings";
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@leonidstern/census",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Eyes for a blind agent: a live web page's styles as text an AI can check, by your design system's own words.",
5
+ "keywords": [
6
+ "design-system",
7
+ "visual-regression",
8
+ "accessibility",
9
+ "wcag",
10
+ "css",
11
+ "agent",
12
+ "llm",
13
+ "playwright",
14
+ "ci"
15
+ ],
16
+ "homepage": "https://github.com/LeonidStern/census#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/LeonidStern/census.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/LeonidStern/census/issues"
23
+ },
24
+ "author": "Leonid Stern",
25
+ "license": "MIT",
26
+ "type": "module",
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "provenance": true
30
+ },
31
+ "bin": {
32
+ "census": "cli/census.mjs"
33
+ },
34
+ "main": "dist/census.mjs",
35
+ "types": "dist/index.d.ts",
36
+ "files": [
37
+ "dist",
38
+ "cli",
39
+ "README.md",
40
+ "LICENSE"
41
+ ],
42
+ "scripts": {
43
+ "build": "esbuild src/browser.ts --bundle --format=iife --outfile=dist/census.js --log-level=warning && esbuild src/index.ts --bundle --format=esm --outfile=dist/census.mjs --log-level=warning && tsc -p .",
44
+ "check": "tsc -p . --noEmit",
45
+ "test": "npm run build && node test/census-test.mjs",
46
+ "prepare": "npm run build"
47
+ },
48
+ "devDependencies": {
49
+ "esbuild": "0.25.12",
50
+ "svelte": "^5.57.3",
51
+ "typescript": "5.6.3",
52
+ "vue": "3.5"
53
+ },
54
+ "engines": {
55
+ "node": ">=22"
56
+ },
57
+ "exports": {
58
+ ".": {
59
+ "types": "./dist/index.d.ts",
60
+ "default": "./dist/census.mjs"
61
+ },
62
+ "./playwright": "./cli/playwright.mjs",
63
+ "./census.js": "./dist/census.js"
64
+ }
65
+ }