@mizchi/vlmkit-core 0.8.0 → 0.9.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 (81) hide show
  1. package/README.md +1 -1
  2. package/dist/a11y-semantic.d.mts +34 -0
  3. package/dist/a11y-semantic.mjs +261 -0
  4. package/dist/arg-reader.d.mts +52 -0
  5. package/dist/arg-reader.mjs +129 -0
  6. package/dist/auth-state.d.mts +30 -0
  7. package/dist/auth-state.mjs +82 -0
  8. package/dist/authored-style-capture.d.mts +42 -0
  9. package/dist/authored-style-capture.mjs +117 -0
  10. package/dist/authored-style-diff.d.mts +15 -0
  11. package/dist/authored-style-diff.mjs +16 -0
  12. package/dist/cli-args.d.mts +35 -0
  13. package/dist/cli-args.mjs +63 -0
  14. package/dist/cli-error.d.mts +12 -0
  15. package/dist/cli-error.mjs +71 -0
  16. package/dist/computed-style-capture.d.mts +41 -0
  17. package/dist/computed-style-capture.mjs +589 -0
  18. package/dist/computed-style-diff.d.mts +83 -0
  19. package/dist/computed-style-diff.mjs +123 -0
  20. package/dist/diff-regions.d.mts +8 -0
  21. package/dist/diff-regions.mjs +52 -0
  22. package/dist/dom-equivalence.d.mts +51 -0
  23. package/dist/dom-equivalence.mjs +91 -0
  24. package/dist/dom-position-styles.d.mts +166 -0
  25. package/dist/dom-position-styles.mjs +296 -0
  26. package/dist/element-compare.d.mts +71 -0
  27. package/dist/element-compare.mjs +269 -0
  28. package/dist/gate-config.d.mts +116 -0
  29. package/dist/gate-config.mjs +169 -0
  30. package/dist/gate-exit.d.mts +45 -0
  31. package/dist/gate-exit.mjs +25 -0
  32. package/dist/heatmap-regions.d.mts +57 -0
  33. package/dist/heatmap-regions.mjs +158 -0
  34. package/dist/heatmap.d.mts +86 -0
  35. package/dist/heatmap.mjs +510 -0
  36. package/dist/image-resize.d.mts +34 -0
  37. package/dist/image-resize.mjs +92 -0
  38. package/dist/index.d.mts +15 -0
  39. package/dist/index.mjs +14 -0
  40. package/dist/legacy-names.d.mts +48 -0
  41. package/dist/legacy-names.mjs +134 -0
  42. package/dist/mask.d.mts +18 -0
  43. package/dist/mask.mjs +27 -0
  44. package/dist/navigation-redirect.d.mts +28 -0
  45. package/dist/navigation-redirect.mjs +47 -0
  46. package/dist/page-open.d.mts +102 -0
  47. package/dist/page-open.mjs +133 -0
  48. package/dist/png-utils.d.mts +30 -0
  49. package/dist/png-utils.mjs +80 -0
  50. package/dist/region-shift.d.mts +20 -0
  51. package/dist/region-shift.mjs +128 -0
  52. package/dist/run-ledger.d.mts +14 -0
  53. package/dist/run-ledger.mjs +31 -0
  54. package/dist/terminal-colors.d.mts +12 -0
  55. package/dist/terminal-colors.mjs +14 -0
  56. package/dist/text-rows.d.mts +121 -0
  57. package/dist/text-rows.mjs +246 -0
  58. package/{src/types.ts → dist/types.d.mts} +88 -206
  59. package/dist/types.mjs +1 -0
  60. package/package.json +17 -5
  61. package/src/a11y-semantic.ts +0 -384
  62. package/src/authored-style-capture.ts +0 -185
  63. package/src/authored-style-diff.ts +0 -32
  64. package/src/cli-args.ts +0 -29
  65. package/src/cli-error.ts +0 -85
  66. package/src/computed-style-capture.ts +0 -717
  67. package/src/computed-style-diff.ts +0 -192
  68. package/src/diff-regions.ts +0 -70
  69. package/src/dom-equivalence.ts +0 -158
  70. package/src/dom-position-styles.ts +0 -457
  71. package/src/element-compare.ts +0 -354
  72. package/src/heatmap-regions.ts +0 -245
  73. package/src/heatmap.ts +0 -670
  74. package/src/image-resize.ts +0 -112
  75. package/src/index.ts +0 -105
  76. package/src/mask.ts +0 -41
  77. package/src/png-utils.ts +0 -86
  78. package/src/region-shift.ts +0 -173
  79. package/src/run-ledger.ts +0 -39
  80. package/src/terminal-colors.ts +0 -13
  81. package/src/text-rows.ts +0 -412
@@ -1,384 +0,0 @@
1
- import type {
2
- A11yNode,
3
- A11yChange,
4
- A11yDiff,
5
- A11ySnapshot,
6
- } from "./types.ts";
7
-
8
- export const LANDMARK_ROLES = new Set([
9
- "banner",
10
- "complementary",
11
- "contentinfo",
12
- "form",
13
- "main",
14
- "navigation",
15
- "region",
16
- "search",
17
- ]);
18
-
19
- export const INTERACTIVE_ROLES = new Set([
20
- "button",
21
- "checkbox",
22
- "combobox",
23
- "link",
24
- "listbox",
25
- "menu",
26
- "menubar",
27
- "menuitem",
28
- "option",
29
- "radio",
30
- "scrollbar",
31
- "searchbox",
32
- "slider",
33
- "spinbutton",
34
- "switch",
35
- "tab",
36
- "tabpanel",
37
- "textbox",
38
- "treeitem",
39
- ]);
40
-
41
- /**
42
- * Compare two a11y tree snapshots and return the semantic diff.
43
- */
44
- export function diffA11yTrees(
45
- baseline: A11ySnapshot,
46
- current: A11ySnapshot
47
- ): A11yDiff {
48
- const changes: A11yChange[] = [];
49
- diffNodes(baseline.tree, current.tree, "", changes);
50
-
51
- const landmarkChanges = changes.filter((c) => c.type === "landmark-changed");
52
- const hasRegression = changes.some((c) => c.severity === "error");
53
-
54
- return {
55
- testId: current.testId,
56
- changes,
57
- hasRegression,
58
- landmarkChanges,
59
- stats: {
60
- added: changes.filter((c) => c.type === "node-added").length,
61
- removed: changes.filter((c) => c.type === "node-removed").length,
62
- modified: changes.filter(
63
- (c) =>
64
- c.type !== "node-added" &&
65
- c.type !== "node-removed"
66
- ).length,
67
- },
68
- };
69
- }
70
-
71
- function diffNodes(
72
- before: A11yNode | undefined,
73
- after: A11yNode | undefined,
74
- path: string,
75
- changes: A11yChange[]
76
- ): void {
77
- const nodePath = path
78
- ? `${path} > ${nodeLabel(after ?? before!)}`
79
- : nodeLabel(after ?? before!);
80
-
81
- // Node added
82
- if (!before && after) {
83
- changes.push({
84
- type: isLandmark(after) ? "landmark-changed" : "node-added",
85
- path: nodePath,
86
- after: nodeSnapshot(after),
87
- severity: "info",
88
- description: `Added ${after.role}${after.name ? ` "${after.name}"` : ""}`,
89
- });
90
- // Don't record children as added (included in parent addition)
91
- return;
92
- }
93
-
94
- // Node removed
95
- if (before && !after) {
96
- const severity = isLandmark(before)
97
- ? "error" // landmark removal is critical
98
- : isInteractive(before)
99
- ? "error" // interactive element removal is regression
100
- : "warning";
101
-
102
- changes.push({
103
- type: isLandmark(before) ? "landmark-changed" : "node-removed",
104
- path: nodePath,
105
- before: nodeSnapshot(before),
106
- severity,
107
- description: `Removed ${before.role}${before.name ? ` "${before.name}"` : ""}`,
108
- });
109
- return;
110
- }
111
-
112
- if (!before || !after) return;
113
-
114
- // role change
115
- if (before.role !== after.role) {
116
- changes.push({
117
- type: "role-changed",
118
- path: nodePath,
119
- before: { role: before.role },
120
- after: { role: after.role },
121
- severity: isInteractive(before) || isInteractive(after) ? "error" : "warning",
122
- description: `Role changed from "${before.role}" to "${after.role}"`,
123
- });
124
- }
125
-
126
- // name change
127
- if (before.name !== after.name) {
128
- const severity =
129
- isInteractive(before) && !after.name
130
- ? "error" // label loss is regression
131
- : "info";
132
-
133
- changes.push({
134
- type: "name-changed",
135
- path: nodePath,
136
- before: { name: before.name },
137
- after: { name: after.name },
138
- severity,
139
- description: after.name
140
- ? `Name changed from "${before.name}" to "${after.name}"`
141
- : `Name removed (was "${before.name}")`,
142
- });
143
- }
144
-
145
- // state change (checked, disabled, expanded, pressed, selected)
146
- const stateKeys = ["checked", "disabled", "expanded", "pressed", "selected"] as const;
147
- for (const key of stateKeys) {
148
- if (before[key] !== after[key]) {
149
- changes.push({
150
- type: "state-changed",
151
- path: nodePath,
152
- before: { [key]: before[key] },
153
- after: { [key]: after[key] },
154
- severity: "info",
155
- description: `${key} changed from ${before[key]} to ${after[key]}`,
156
- });
157
- }
158
- }
159
-
160
- // Child node diff (order-based matching + role+name key matching)
161
- const beforeChildren = before.children ?? [];
162
- const afterChildren = after.children ?? [];
163
- diffChildren(beforeChildren, afterChildren, nodePath, changes);
164
- }
165
-
166
- /**
167
- * Diff child node lists.
168
- * 1) Exact match by role+name
169
- * 2) Position-based matching for remaining -> detect role/name changes
170
- * 3) Remainder is additions/removals
171
- */
172
- function diffChildren(
173
- beforeChildren: A11yNode[],
174
- afterChildren: A11yNode[],
175
- parentPath: string,
176
- changes: A11yChange[]
177
- ): void {
178
- const matched = new Set<number>(); // matched indices in beforeChildren
179
- const afterMatched = new Set<number>();
180
-
181
- // Pass 1: exact role+name match
182
- const beforeByKey = new Map<string, { node: A11yNode; index: number }[]>();
183
- for (let i = 0; i < beforeChildren.length; i++) {
184
- const key = childKey(beforeChildren[i]);
185
- const list = beforeByKey.get(key) ?? [];
186
- list.push({ node: beforeChildren[i], index: i });
187
- beforeByKey.set(key, list);
188
- }
189
-
190
- for (let ai = 0; ai < afterChildren.length; ai++) {
191
- const key = childKey(afterChildren[ai]);
192
- const candidates = beforeByKey.get(key);
193
- if (candidates && candidates.length > 0) {
194
- const match = candidates.shift()!;
195
- matched.add(match.index);
196
- afterMatched.add(ai);
197
- diffNodes(match.node, afterChildren[ai], parentPath, changes);
198
- }
199
- }
200
-
201
- // Pass 2: position-based matching (detect role or name changes)
202
- const unmatchedBefore: { node: A11yNode; index: number }[] = [];
203
- for (let i = 0; i < beforeChildren.length; i++) {
204
- if (!matched.has(i)) unmatchedBefore.push({ node: beforeChildren[i], index: i });
205
- }
206
- const unmatchedAfter: { node: A11yNode; index: number }[] = [];
207
- for (let i = 0; i < afterChildren.length; i++) {
208
- if (!afterMatched.has(i)) unmatchedAfter.push({ node: afterChildren[i], index: i });
209
- }
210
-
211
- // role-only or name-only match for pairing
212
- const stillUnmatchedBefore: typeof unmatchedBefore = [];
213
- const stillUnmatchedAfter = new Set(unmatchedAfter.map((_, i) => i));
214
-
215
- for (const b of unmatchedBefore) {
216
- let found = false;
217
- for (let j = 0; j < unmatchedAfter.length; j++) {
218
- if (!stillUnmatchedAfter.has(j)) continue;
219
- const a = unmatchedAfter[j];
220
- // role or name match -> pair (diff as change)
221
- if (
222
- b.node.role === a.node.role ||
223
- (b.node.name && b.node.name === a.node.name)
224
- ) {
225
- stillUnmatchedAfter.delete(j);
226
- diffNodes(b.node, a.node, parentPath, changes);
227
- found = true;
228
- break;
229
- }
230
- }
231
- if (!found) {
232
- stillUnmatchedBefore.push(b);
233
- }
234
- }
235
-
236
- // Pass 3: remainder is additions/removals
237
- for (const b of stillUnmatchedBefore) {
238
- diffNodes(b.node, undefined, parentPath, changes);
239
- }
240
- for (const j of stillUnmatchedAfter) {
241
- diffNodes(undefined, unmatchedAfter[j].node, parentPath, changes);
242
- }
243
-
244
- // Detect structural changes (significant child count change)
245
- const countDiff = Math.abs(afterChildren.length - beforeChildren.length);
246
- if (countDiff > 3 && countDiff / Math.max(beforeChildren.length, 1) > 0.3) {
247
- changes.push({
248
- type: "structure-changed",
249
- path: parentPath,
250
- before: { name: `${beforeChildren.length} children` },
251
- after: { name: `${afterChildren.length} children` },
252
- severity: "warning",
253
- description: `Structure changed significantly: ${beforeChildren.length} → ${afterChildren.length} children`,
254
- });
255
- }
256
- }
257
-
258
- function childKey(node: A11yNode): string {
259
- return `${node.role}:${node.name ?? ""}`;
260
- }
261
-
262
- function nodeLabel(node: A11yNode): string {
263
- const name = node.name ? `[${node.name}]` : "";
264
- return `${node.role}${name}`;
265
- }
266
-
267
- function nodeSnapshot(node: A11yNode): Partial<A11yNode> {
268
- return {
269
- role: node.role,
270
- name: node.name,
271
- ...(node.level !== undefined && { level: node.level }),
272
- ...(node.checked !== undefined && { checked: node.checked }),
273
- ...(node.disabled !== undefined && { disabled: node.disabled }),
274
- ...(node.expanded !== undefined && { expanded: node.expanded }),
275
- };
276
- }
277
-
278
- function isLandmark(node: A11yNode): boolean {
279
- return LANDMARK_ROLES.has(node.role);
280
- }
281
-
282
- function isInteractive(node: A11yNode): boolean {
283
- return INTERACTIVE_ROLES.has(node.role);
284
- }
285
-
286
- // ---- A11y Quality Checks ----
287
-
288
- /**
289
- * A11y tree quality checks (standalone, no diff).
290
- *
291
- * Walks the tree and returns issues such as missing labels on
292
- * interactive elements and missing alt text on images.
293
- *
294
- * @since 0.5.0 — replaces `checkA11yTree`.
295
- */
296
- export function verifyA11yTree(tree: A11yNode): A11yIssue[] {
297
- const issues: A11yIssue[] = [];
298
- walkTree(tree, "", issues);
299
- return issues;
300
- }
301
-
302
- /**
303
- * @deprecated since 0.5.0 — use `verifyA11yTree` instead. Removed in 1.0.0.
304
- */
305
- export const checkA11yTree = verifyA11yTree;
306
-
307
- export interface A11yIssue {
308
- path: string;
309
- rule: string;
310
- severity: "error" | "warning";
311
- message: string;
312
- }
313
-
314
- function walkTree(node: A11yNode, path: string, issues: A11yIssue[]): void {
315
- const nodePath = path ? `${path} > ${nodeLabel(node)}` : nodeLabel(node);
316
-
317
- // Interactive elements without labels
318
- if (isInteractive(node) && !node.name) {
319
- issues.push({
320
- path: nodePath,
321
- rule: "label-missing",
322
- severity: "error",
323
- message: `Interactive element "${node.role}" has no accessible name`,
324
- });
325
- }
326
-
327
- // Images without alt (role=img with no name)
328
- if (node.role === "img" && !node.name) {
329
- issues.push({
330
- path: nodePath,
331
- rule: "img-alt-missing",
332
- severity: "error",
333
- message: "Image has no accessible name (missing alt text)",
334
- });
335
- }
336
-
337
- // Heading level skip detection needs parent context,
338
- // so only individual node checks here
339
-
340
- for (const child of node.children ?? []) {
341
- walkTree(child, nodePath, issues);
342
- }
343
- }
344
-
345
- /**
346
- * Convert Playwright page.accessibility.snapshot() output to A11ySnapshot.
347
- */
348
- export function parsePlaywrightA11ySnapshot(
349
- testId: string,
350
- testTitle: string,
351
- raw: Record<string, unknown>
352
- ): A11ySnapshot {
353
- return {
354
- testId,
355
- testTitle,
356
- tree: normalizeA11yNode(raw),
357
- };
358
- }
359
-
360
- function normalizeA11yNode(raw: Record<string, unknown>): A11yNode {
361
- return {
362
- role: (raw.role as string) ?? "none",
363
- name: (raw.name as string) ?? "",
364
- ...(raw.level !== undefined && { level: raw.level as number }),
365
- ...(raw.value !== undefined && { value: raw.value as string }),
366
- ...(raw.description !== undefined && {
367
- description: raw.description as string,
368
- }),
369
- ...(raw.checked !== undefined && {
370
- checked: raw.checked as boolean | "mixed",
371
- }),
372
- ...(raw.disabled !== undefined && { disabled: raw.disabled as boolean }),
373
- ...(raw.expanded !== undefined && { expanded: raw.expanded as boolean }),
374
- ...(raw.pressed !== undefined && {
375
- pressed: raw.pressed as boolean | "mixed",
376
- }),
377
- ...(raw.selected !== undefined && { selected: raw.selected as boolean }),
378
- ...(raw.children ? {
379
- children: (raw.children as Record<string, unknown>[]).map(
380
- normalizeA11yNode
381
- ),
382
- } : {}),
383
- };
384
- }
@@ -1,185 +0,0 @@
1
- /**
2
- * Authored CSS capture for properties whose computed form lies about the
3
- * authored shape.
4
- *
5
- * Motivating case (2026-05-23 dogfood, app-shell `.shell`):
6
- * `getComputedStyle().getPropertyValue("grid-template-columns")` resolves
7
- * `minmax(0, 1fr) 4px minmax(0, 1fr)` to a three px-tuple — but writing
8
- * those numbers back as CSS would corrupt the responsive layout. The fix is
9
- * not to track grid-template-* in computed-style at all; instead, walk
10
- * `document.styleSheets.cssRules` to emit the AUTHORED strings and diff
11
- * THEM. Same approach scales to `flex` shorthand, `transform`, and any
12
- * other property whose computed form diverges from authored.
13
- *
14
- * Surface mirrors `computed-style-capture` so consumers can reuse
15
- * `diffComputedStyles` (it's just `Record<selector, Record<prop, value>>`
16
- * → `Record<selector, Record<prop, value>>` either way).
17
- */
18
- /// <reference lib="dom" />
19
-
20
- export type AuthoredStyleSnapshot = Record<string, Record<string, string>>;
21
-
22
- /**
23
- * Properties tracked by default. These are the ones whose computed
24
- * representation differs structurally from the authored source — anything
25
- * already faithful in `getComputedStyle` does not need this channel.
26
- */
27
- export const AUTHORED_PROPERTIES = [
28
- "grid-template",
29
- "grid-template-columns",
30
- "grid-template-rows",
31
- "grid-template-areas",
32
- "grid-auto-columns",
33
- "grid-auto-rows",
34
- "grid-auto-flow",
35
- "grid-column",
36
- "grid-row",
37
- "grid",
38
- "flex",
39
- "transform",
40
- "clip-path",
41
- "mask",
42
- "mask-image",
43
- ];
44
-
45
- const MEDIA_SEPARATOR = " :: ";
46
-
47
- /**
48
- * Format a "scoped" selector key. When `mediaCondition` is empty, returns
49
- * the bare selector text. When non-empty, the key reads
50
- * `@media (min-width: 768px) :: .shell` so the diff treats the same
51
- * selector inside a different `@media` block as a distinct row.
52
- */
53
- function buildScopedSelectorKey(selector: string, mediaCondition: string): string {
54
- const trimmedMedia = mediaCondition.trim();
55
- if (!trimmedMedia) return selector;
56
- return `@media ${trimmedMedia}${MEDIA_SEPARATOR}${selector}`;
57
- }
58
-
59
- /**
60
- * Browser-context capture. Walks all same-origin stylesheets and nested
61
- * `@media` / `@supports` rules, collecting authored `value` strings for
62
- * each (scoped-selector, property) pair listed in `props`. Last
63
- * declaration wins per pair (mirrors authoring order; sufficient for
64
- * static diff use cases).
65
- *
66
- * Selectors are comma-split so `.a, .b { grid-template-columns: ... }`
67
- * fans out into both `.a` and `.b` entries.
68
- */
69
- export function captureAuthoredStyleSnapshotInDom(props: string[]): AuthoredStyleSnapshot {
70
- const trackedProps = new Set(props);
71
- const results: AuthoredStyleSnapshot = {};
72
-
73
- function visit(rule: unknown, mediaCondition: string) {
74
- if (!rule || typeof rule !== "object") return;
75
- const ruleObj = rule as {
76
- selectorText?: unknown;
77
- style?: { getPropertyValue?: (name: string) => string } | null;
78
- conditionText?: unknown;
79
- media?: { mediaText?: unknown } | null;
80
- cssRules?: ArrayLike<unknown>;
81
- };
82
-
83
- // @media / @supports / @container — descend with the media condition extended.
84
- const conditionFromMedia = typeof ruleObj.media?.mediaText === "string"
85
- ? ruleObj.media!.mediaText
86
- : "";
87
- const conditionFromAt = typeof ruleObj.conditionText === "string"
88
- ? ruleObj.conditionText
89
- : "";
90
- const additionalCondition = conditionFromMedia || conditionFromAt;
91
- const nestedMedia = additionalCondition
92
- ? mediaCondition
93
- ? `${mediaCondition} and ${additionalCondition}`
94
- : additionalCondition
95
- : mediaCondition;
96
-
97
- if (ruleObj.cssRules && typeof (ruleObj.cssRules as { length?: unknown }).length === "number") {
98
- const nested = ruleObj.cssRules as ArrayLike<unknown>;
99
- for (let i = 0; i < nested.length; i++) {
100
- visit(nested[i], nestedMedia);
101
- }
102
- // Containers like @media/@supports never carry selectorText themselves.
103
- if (!ruleObj.selectorText) return;
104
- }
105
-
106
- if (typeof ruleObj.selectorText !== "string") return;
107
- const style = ruleObj.style;
108
- if (!style || typeof style.getPropertyValue !== "function") return;
109
-
110
- for (const rawSelector of ruleObj.selectorText.split(",")) {
111
- const selector = rawSelector.trim();
112
- if (!selector) continue;
113
- const key = buildScopedSelectorKey(selector, mediaCondition);
114
- for (const prop of trackedProps) {
115
- const value = style.getPropertyValue(prop);
116
- if (!value) continue;
117
- const bucket = results[key] ?? (results[key] = {});
118
- bucket[prop] = value.trim();
119
- }
120
- }
121
- }
122
-
123
- const styleSheets = (document as Document & { styleSheets?: StyleSheetList }).styleSheets;
124
- if (!styleSheets) return results;
125
- for (const sheet of Array.from(styleSheets)) {
126
- try {
127
- const rules = (sheet as CSSStyleSheet).cssRules;
128
- for (const rule of Array.from(rules)) {
129
- visit(rule, "");
130
- }
131
- } catch { /* cross-origin stylesheet */ }
132
- }
133
-
134
- return results;
135
- }
136
-
137
- // esbuild injects __name(fn, "name") calls into Function.toString() output.
138
- const ESBUILD_NAME_POLYFILL =
139
- "var __name = typeof __name !== 'undefined' ? __name : function(fn) { return fn; };";
140
-
141
- export function buildAuthoredStyleCaptureExpression(
142
- props: string[] = AUTHORED_PROPERTIES,
143
- ): string {
144
- return `(function(){ ${ESBUILD_NAME_POLYFILL} return (${captureAuthoredStyleSnapshotInDom.toString()})(${JSON.stringify(props)}); })()`;
145
- }
146
-
147
- export function buildAuthoredStyleCaptureJsonExpression(
148
- props: string[] = AUTHORED_PROPERTIES,
149
- ): string {
150
- return `JSON.stringify(${buildAuthoredStyleCaptureExpression(props)})`;
151
- }
152
-
153
- export function parseAuthoredStyleSnapshot(value: unknown): AuthoredStyleSnapshot {
154
- const candidate = typeof value === "string" ? safeJsonParse(value) : value;
155
- if (!isRecord(candidate)) return {};
156
-
157
- const snapshot: AuthoredStyleSnapshot = {};
158
- for (const [selector, props] of Object.entries(candidate)) {
159
- if (!isRecord(props)) continue;
160
- const normalized: Record<string, string> = {};
161
- for (const [prop, propValue] of Object.entries(props)) {
162
- normalized[prop] = typeof propValue === "string" ? propValue : String(propValue ?? "");
163
- }
164
- snapshot[selector] = normalized;
165
- }
166
- return snapshot;
167
- }
168
-
169
- export function hasMeaningfulAuthoredStyleSnapshot(snapshot: AuthoredStyleSnapshot): boolean {
170
- return Object.values(snapshot).some((props) =>
171
- Object.values(props).some((value) => value.trim().length > 0)
172
- );
173
- }
174
-
175
- function safeJsonParse(value: string): unknown {
176
- try {
177
- return JSON.parse(value);
178
- } catch {
179
- return null;
180
- }
181
- }
182
-
183
- function isRecord(value: unknown): value is Record<string, unknown> {
184
- return typeof value === "object" && value !== null && !Array.isArray(value);
185
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * Authored-style diff. Same shape as `computed-style-diff` (a snapshot is
3
- * `Record<scopedSelector, Record<property, value>>` in both cases), so the
4
- * heavy lifting reuses `diffComputedStyles` — only the snapshot type
5
- * label differs.
6
- */
7
- import { diffComputedStyles, aggregateCsdByViewport } from "./computed-style-diff.ts";
8
- import type {
9
- CsdEntry,
10
- CsdResult,
11
- CsdPerViewportResult,
12
- CsdPerViewportEntry,
13
- } from "./computed-style-diff.ts";
14
- import type { AuthoredStyleSnapshot } from "./authored-style-capture.ts";
15
-
16
- export type AuthoredStyleEntry = CsdEntry;
17
- export type AuthoredStyleDiffResult = CsdResult;
18
- export type AuthoredStylePerViewportEntry = CsdPerViewportEntry;
19
- export type AuthoredStylePerViewportResult = CsdPerViewportResult;
20
-
21
- export function diffAuthoredStyles(
22
- baseline: AuthoredStyleSnapshot,
23
- variant: AuthoredStyleSnapshot,
24
- ): AuthoredStyleDiffResult {
25
- return diffComputedStyles(baseline, variant);
26
- }
27
-
28
- export function aggregateAuthoredStyleByViewport(
29
- perViewport: ReadonlyArray<{ viewport: string; result: AuthoredStyleDiffResult }>,
30
- ): AuthoredStylePerViewportResult {
31
- return aggregateCsdByViewport(perViewport);
32
- }
package/src/cli-args.ts DELETED
@@ -1,29 +0,0 @@
1
- /** Shared CLI argument parsing helpers */
2
-
3
- const args = process.argv.slice(2);
4
-
5
- export function getArg(name: string, fallback: string): string;
6
- export function getArg(name: string): string | undefined;
7
- export function getArg(name: string, fallback?: string): string | undefined {
8
- const idx = args.indexOf(`--${name}`);
9
- return idx >= 0 && args[idx + 1] ? args[idx + 1] : fallback;
10
- }
11
-
12
- export function hasFlag(name: string): boolean {
13
- return args.includes(`--${name}`);
14
- }
15
-
16
- export function getArgValues(name: string): string[] {
17
- const values: string[] = [];
18
- for (let i = 0; i < args.length; i++) {
19
- if (args[i] === `--${name}` && args[i + 1]) values.push(args[i + 1]);
20
- }
21
- return values;
22
- }
23
-
24
- /** Get positional args (not flags or flag values) */
25
- export function getPositionalArgs(): string[] {
26
- return args.filter((a, i) => !a.startsWith("--") && (i === 0 || !args[i - 1]?.startsWith("--")));
27
- }
28
-
29
- export { args };