framesheet 0.0.0-stage → 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 (69) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +212 -2
  3. package/dist/analysis.d.ts +84 -0
  4. package/dist/analysis.d.ts.map +1 -0
  5. package/dist/analysis.js +335 -0
  6. package/dist/analysis.js.map +1 -0
  7. package/dist/checks.d.ts +44 -0
  8. package/dist/checks.d.ts.map +1 -0
  9. package/dist/checks.js +200 -0
  10. package/dist/checks.js.map +1 -0
  11. package/dist/compose.d.ts +117 -0
  12. package/dist/compose.d.ts.map +1 -0
  13. package/dist/compose.js +236 -0
  14. package/dist/compose.js.map +1 -0
  15. package/dist/driver.d.ts +56 -0
  16. package/dist/driver.d.ts.map +1 -0
  17. package/dist/driver.js +94 -0
  18. package/dist/driver.js.map +1 -0
  19. package/dist/generated/assets.d.ts +9 -0
  20. package/dist/generated/assets.d.ts.map +1 -0
  21. package/dist/generated/assets.js +11 -0
  22. package/dist/generated/assets.js.map +1 -0
  23. package/dist/index.d.ts +15 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +14 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/inspect.d.ts +150 -0
  28. package/dist/inspect.d.ts.map +1 -0
  29. package/dist/inspect.js +570 -0
  30. package/dist/inspect.js.map +1 -0
  31. package/dist/models.d.ts +117 -0
  32. package/dist/models.d.ts.map +1 -0
  33. package/dist/models.js +9 -0
  34. package/dist/models.js.map +1 -0
  35. package/dist/pixels.d.ts +46 -0
  36. package/dist/pixels.d.ts.map +1 -0
  37. package/dist/pixels.js +237 -0
  38. package/dist/pixels.js.map +1 -0
  39. package/dist/pyfmt.d.ts +16 -0
  40. package/dist/pyfmt.d.ts.map +1 -0
  41. package/dist/pyfmt.js +54 -0
  42. package/dist/pyfmt.js.map +1 -0
  43. package/dist/report.schema.json +754 -0
  44. package/dist/sources.d.ts +32 -0
  45. package/dist/sources.d.ts.map +1 -0
  46. package/dist/sources.js +123 -0
  47. package/dist/sources.js.map +1 -0
  48. package/dist/test.d.ts +46 -0
  49. package/dist/test.d.ts.map +1 -0
  50. package/dist/test.js +58 -0
  51. package/dist/test.js.map +1 -0
  52. package/dist/timing.d.ts +30 -0
  53. package/dist/timing.d.ts.map +1 -0
  54. package/dist/timing.js +128 -0
  55. package/dist/timing.js.map +1 -0
  56. package/package.json +78 -4
  57. package/src/analysis.ts +416 -0
  58. package/src/checks.ts +261 -0
  59. package/src/compose.ts +303 -0
  60. package/src/driver.ts +115 -0
  61. package/src/generated/assets.ts +14 -0
  62. package/src/index.ts +44 -0
  63. package/src/inspect.ts +690 -0
  64. package/src/models.ts +130 -0
  65. package/src/pixels.ts +248 -0
  66. package/src/pyfmt.ts +55 -0
  67. package/src/sources.ts +131 -0
  68. package/src/test.ts +100 -0
  69. package/src/timing.ts +133 -0
@@ -0,0 +1,32 @@
1
+ /** Input handling: files, markup strings and URLs (port of sources.py). */
2
+ import type { ParsedDocument } from "./checks.js";
3
+ import type { SourceKind } from "./models.js";
4
+ export declare const DEFAULT_HTML_SIZE: [number, number];
5
+ export declare const DEFAULT_SVG_SIZE: [number, number];
6
+ /** Markup strings are served from this virtual origin (page.route), never from disk. */
7
+ export declare const VIRTUAL_ORIGIN = "http://framesheet.invalid";
8
+ /** A resolved input. */
9
+ export interface Source {
10
+ /** What the caller passed (path, URL, or `<snippet>`). */
11
+ label: string;
12
+ kind: SourceKind;
13
+ /** What the browser navigates to. */
14
+ url: string;
15
+ /** Source text if available (static checks, size detection). */
16
+ text: string | null;
17
+ /** Markup served via page.route at `url` (markup-string inputs only). */
18
+ body?: string;
19
+ }
20
+ export declare function looksLikeSvg(text: string): boolean;
21
+ /** Wrap an in-memory SVG/HTML snippet as a source (served from a virtual URL). */
22
+ export declare function snippet(markup: string, label?: string): Source;
23
+ /** Best-effort download of a URL's body (for static checks and SVG size detection). */
24
+ export declare function fetchText(url: string, timeoutMs?: number): Promise<string | null>;
25
+ /** Turn a path, URL or markup string (starting with `<`) into a {@link Source}. */
26
+ export declare function resolveSource(source: string): Promise<Source>;
27
+ /** Intrinsic size of a parsed SVG: absolute width/height attributes, else the viewBox. */
28
+ export declare function svgSize(doc: ParsedDocument): [number, number] | null;
29
+ export declare function defaultSize(kind: SourceKind, parsed: ParsedDocument | null): [number, number];
30
+ /** Parse `WxH` (e.g. `1280x720`). */
31
+ export declare function parseSize(value: string): [number, number];
32
+ //# sourceMappingURL=sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAK3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,eAAO,MAAM,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAe,CAAC;AAC/D,eAAO,MAAM,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAc,CAAC;AAE7D,wFAAwF;AACxF,eAAO,MAAM,cAAc,8BAA8B,CAAC;AAE1D,wBAAwB;AACxB,MAAM,WAAW,MAAM;IACrB,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,UAAU,CAAC;IACjB,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,gEAAgE;IAChE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQlD;AAED,kFAAkF;AAClF,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAAc,GAAG,MAAM,CAOnE;AAED,uFAAuF;AACvF,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWvF;AAED,mFAAmF;AACnF,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBnE;AAQD,0FAA0F;AAC1F,wBAAgB,OAAO,CAAC,GAAG,EAAE,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAoBpE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAM7F;AAED,qCAAqC;AACrC,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAIzD"}
@@ -0,0 +1,123 @@
1
+ /** Input handling: files, markup strings and URLs (port of sources.py). */
2
+ import { readFileSync, statSync } from "node:fs";
3
+ import { extname, resolve as resolvePath } from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ import { pyRound } from "./pyfmt.js";
6
+ export const DEFAULT_HTML_SIZE = [1280, 720];
7
+ export const DEFAULT_SVG_SIZE = [960, 540];
8
+ const LENGTH = /^\s*([0-9]*\.?[0-9]+)\s*(px)?\s*$/;
9
+ /** Markup strings are served from this virtual origin (page.route), never from disk. */
10
+ export const VIRTUAL_ORIGIN = "http://framesheet.invalid";
11
+ export function looksLikeSvg(text) {
12
+ let head = text.slice(0, 4096).replace(/<!--[\s\S]*?-->/g, "").trimStart().toLowerCase();
13
+ if (head.startsWith("<?xml")) {
14
+ const i = head.indexOf("?>");
15
+ head = (i >= 0 ? head.slice(i + 2) : "").trimStart();
16
+ }
17
+ if (head.startsWith("<!doctype svg"))
18
+ return true;
19
+ return head.startsWith("<svg");
20
+ }
21
+ /** Wrap an in-memory SVG/HTML snippet as a source (served from a virtual URL). */
22
+ export function snippet(markup, label = "<snippet>") {
23
+ const kind = looksLikeSvg(markup) ? "svg" : "html";
24
+ let text = markup;
25
+ if (kind === "html" && !text.toLowerCase().includes("<html")) {
26
+ text = `<!DOCTYPE html>\n<html><head><meta charset='utf-8'></head><body>${text}</body></html>`;
27
+ }
28
+ return { label, kind, url: `${VIRTUAL_ORIGIN}/input.${kind}`, text, body: text };
29
+ }
30
+ /** Best-effort download of a URL's body (for static checks and SVG size detection). */
31
+ export async function fetchText(url, timeoutMs = 15_000) {
32
+ try {
33
+ const response = await fetch(url, {
34
+ headers: { "User-Agent": "framesheet" },
35
+ signal: AbortSignal.timeout(timeoutMs),
36
+ });
37
+ if (!response.ok)
38
+ return null;
39
+ return await response.text();
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ }
45
+ /** Turn a path, URL or markup string (starting with `<`) into a {@link Source}. */
46
+ export async function resolveSource(source) {
47
+ if (source.trimStart().startsWith("<"))
48
+ return snippet(source);
49
+ if (/^https?:\/\//.test(source)) {
50
+ const text = await fetchText(source);
51
+ const byName = source.split("?")[0].toLowerCase().endsWith(".svg");
52
+ const kind = byName || (text !== null && looksLikeSvg(text)) ? "svg" : "html";
53
+ return { label: source, kind, url: source, text };
54
+ }
55
+ const path = resolvePath(source.startsWith("file://") ? new URL(source).pathname : source);
56
+ let isFile = false;
57
+ try {
58
+ isFile = statSync(path).isFile();
59
+ }
60
+ catch {
61
+ isFile = false;
62
+ }
63
+ if (!isFile)
64
+ throw new Error(`Input not found: ${source}`);
65
+ const text = readFileSync(path, "utf8");
66
+ const ext = extname(path).toLowerCase();
67
+ let kind;
68
+ if (ext === ".svg")
69
+ kind = "svg";
70
+ else if ([".html", ".htm", ".xhtml"].includes(ext))
71
+ kind = "html";
72
+ else
73
+ kind = looksLikeSvg(text) ? "svg" : "html";
74
+ return { label: source, kind, url: pathToFileURL(path).href, text };
75
+ }
76
+ function length(value) {
77
+ if (value == null)
78
+ return null;
79
+ const m = LENGTH.exec(value);
80
+ return m ? parseFloat(m[1]) : null;
81
+ }
82
+ /** Intrinsic size of a parsed SVG: absolute width/height attributes, else the viewBox. */
83
+ export function svgSize(doc) {
84
+ if (doc.error !== null || !doc.elements.length)
85
+ return null;
86
+ const root = doc.elements[0];
87
+ const get = (name) => root.attrs.find(([local]) => local === name)?.[2];
88
+ let width = length(get("width"));
89
+ let height = length(get("height"));
90
+ const box = (get("viewBox") ?? "")
91
+ .trim()
92
+ .split(/[\s,]+/)
93
+ .filter(Boolean)
94
+ .map(Number);
95
+ if (box.length === 4 && box[2] > 0 && box[3] > 0) {
96
+ const [, , vbW, vbH] = box;
97
+ if (width && !height)
98
+ height = (width * vbH) / vbW;
99
+ else if (height && !width)
100
+ width = (height * vbW) / vbH;
101
+ width = width || vbW;
102
+ height = height || vbH;
103
+ }
104
+ if (width && height)
105
+ return [Math.max(1, pyRound(width)), Math.max(1, pyRound(height))];
106
+ return null;
107
+ }
108
+ export function defaultSize(kind, parsed) {
109
+ if (kind === "svg" && parsed) {
110
+ const size = svgSize(parsed);
111
+ if (size)
112
+ return size;
113
+ }
114
+ return kind === "svg" ? DEFAULT_SVG_SIZE : DEFAULT_HTML_SIZE;
115
+ }
116
+ /** Parse `WxH` (e.g. `1280x720`). */
117
+ export function parseSize(value) {
118
+ const m = /^\s*(\d+)\s*[xX*]\s*(\d+)\s*$/.exec(value);
119
+ if (!m)
120
+ throw new Error(`Invalid size '${value}'; expected WIDTHxHEIGHT, e.g. 1280x720`);
121
+ return [Number(m[1]), Number(m[2])];
122
+ }
123
+ //# sourceMappingURL=sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.js","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAE3E,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,M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;aAC9C,IAAI,MAAM,IAAI,CAAC,KAAK;YAAE,KAAK,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;QACxD,KAAK,GAAG,KAAK,IAAI,GAAG,CAAC;QACrB,MAAM,GAAG,MAAM,IAAI,GAAG,CAAC;IACzB,CAAC;IACD,IAAI,KAAK,IAAI,MAAM;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACxF,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAgB,EAAE,MAA6B;IACzE,IAAI,IAAI,KAAK,KAAK,IAAI,MAAM,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7B,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBAAiB,CAAC;AAC/D,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,MAAM,CAAC,GAAG,+BAA+B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtD,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,KAAK,yCAAyC,CAAC,CAAC;IACzF,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC"}
package/dist/test.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * `framesheet/test`: visual regression of animations in a `@playwright/test` suite.
3
+ *
4
+ * ```ts
5
+ * import { test } from "@playwright/test";
6
+ * import { expectAnimation } from "framesheet/test";
7
+ *
8
+ * test("mind map opens smoothly", async ({ page }) => {
9
+ * await page.goto("/mindmap");
10
+ * await expectAnimation(page.locator("#mindmap"), "mindmap-open", { frames: 8 });
11
+ * });
12
+ * ```
13
+ */
14
+ import { type Locator, type Page } from "@playwright/test";
15
+ import { type Inspection, type InspectPageOptions } from "./inspect.js";
16
+ import type { Severity } from "./models.js";
17
+ export { LAUNCH_ARGS, prepare } from "./inspect.js";
18
+ export interface ExpectAnimationOptions extends Omit<InspectPageOptions, "locator" | "out"> {
19
+ /** Allowed share of differing pixels in the sheet (Playwright `maxDiffPixelRatio`). */
20
+ maxDiffPixelRatio?: number;
21
+ /** Allowed number of differing pixels (Playwright `maxDiffPixels`). */
22
+ maxDiffPixels?: number;
23
+ /** Per-pixel colour distance threshold 0-1 (Playwright `threshold`, default 0.2). */
24
+ threshold?: number;
25
+ /** Also compare the motion heatmap against `<name>-heatmap.png`. Default false. */
26
+ heatmap?: boolean;
27
+ /**
28
+ * Fail on findings of this severity or worse: `"error"` (default), `"warning"`, or
29
+ * `false` to only compare images.
30
+ */
31
+ failOn?: Exclude<Severity, "info"> | false;
32
+ /** Finding codes to ignore for `failOn` (e.g. `["console-error"]`). */
33
+ ignore?: string[];
34
+ /** Attach sheet/heatmap/full/report to the test report. Default true. */
35
+ attach?: boolean;
36
+ /** Compare against the stored baseline. Default true; `false` only checks findings. */
37
+ snapshot?: boolean;
38
+ }
39
+ /**
40
+ * Build the contact sheet of an animation (whole page or one component) and compare it
41
+ * with the stored baseline `<name>.png` via Playwright's `toMatchSnapshot` (so
42
+ * `--update-snapshots`, per-platform snapshot names and diff images work as usual).
43
+ * Also fails on error findings unless `failOn: false`. Returns the inspection.
44
+ */
45
+ export declare function expectAnimation(target: Page | Locator, name: string, options?: ExpectAnimationOptions): Promise<Inspection>;
46
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAU,KAAK,OAAO,EAAE,KAAK,IAAI,EAAQ,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAe,MAAM,cAAc,CAAC;AACrF,OAAO,KAAK,EAAW,QAAQ,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,kBAAkB,EAAE,SAAS,GAAG,KAAK,CAAC;IACzF,uFAAuF;IACvF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uEAAuE;IACvE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mFAAmF;IACnF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;IAC3C,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,uFAAuF;IACvF,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAUD;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,IAAI,GAAG,OAAO,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,UAAU,CAAC,CAuCrB"}
package/dist/test.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * `framesheet/test`: visual regression of animations in a `@playwright/test` suite.
3
+ *
4
+ * ```ts
5
+ * import { test } from "@playwright/test";
6
+ * import { expectAnimation } from "framesheet/test";
7
+ *
8
+ * test("mind map opens smoothly", async ({ page }) => {
9
+ * await page.goto("/mindmap");
10
+ * await expectAnimation(page.locator("#mindmap"), "mindmap-open", { frames: 8 });
11
+ * });
12
+ * ```
13
+ */
14
+ import { expect, test } from "@playwright/test";
15
+ import { inspectPage } from "./inspect.js";
16
+ export { LAUNCH_ARGS, prepare } from "./inspect.js";
17
+ function isPage(target) {
18
+ return typeof target.goto === "function";
19
+ }
20
+ function describe(findings) {
21
+ return findings.map((f) => `${f.severity} ${f.code}: ${f.message}`).join("\n");
22
+ }
23
+ /**
24
+ * Build the contact sheet of an animation (whole page or one component) and compare it
25
+ * with the stored baseline `<name>.png` via Playwright's `toMatchSnapshot` (so
26
+ * `--update-snapshots`, per-platform snapshot names and diff images work as usual).
27
+ * Also fails on error findings unless `failOn: false`. Returns the inspection.
28
+ */
29
+ export async function expectAnimation(target, name, options = {}) {
30
+ const page = isPage(target) ? target : target.page();
31
+ const locator = isPage(target) ? undefined : target;
32
+ const { maxDiffPixelRatio, maxDiffPixels, threshold, heatmap, failOn = "error", ignore = [], attach = true, snapshot = true, ...rest } = options;
33
+ const result = await inspectPage(page, { ...rest, locator, title: rest.title ?? name });
34
+ const base = name.replace(/\.png$/i, "");
35
+ if (attach) {
36
+ const info = test.info();
37
+ await info.attach(`${base}-sheet.png`, { body: result.images.sheet, contentType: "image/png" });
38
+ await info.attach(`${base}-heatmap.png`, { body: result.images.heatmap, contentType: "image/png" });
39
+ await info.attach(`${base}-full.png`, { body: result.images.full, contentType: "image/png" });
40
+ await info.attach(`${base}-report.json`, {
41
+ body: JSON.stringify(result.report, null, 2),
42
+ contentType: "application/json",
43
+ });
44
+ }
45
+ const compare = Object.fromEntries(Object.entries({ maxDiffPixelRatio, maxDiffPixels, threshold }).filter(([, v]) => v !== undefined));
46
+ if (snapshot) {
47
+ expect(result.images.sheet).toMatchSnapshot(`${base}.png`, compare);
48
+ if (heatmap)
49
+ expect(result.images.heatmap).toMatchSnapshot(`${base}-heatmap.png`, compare);
50
+ }
51
+ if (failOn) {
52
+ const worst = failOn === "warning" ? ["error", "warning"] : ["error"];
53
+ const bad = result.findings.filter((f) => worst.includes(f.severity) && !ignore.includes(f.code));
54
+ expect(bad, `framesheet findings for '${base}':\n${describe(bad)}\n\n${result.summary()}`).toEqual([]);
55
+ }
56
+ return result;
57
+ }
58
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,MAAM,EAA2B,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAA4C,WAAW,EAAE,MAAM,cAAc,CAAC;AAGrF,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAwBpD,SAAS,MAAM,CAAC,MAAsB;IACpC,OAAO,OAAQ,MAAe,CAAC,IAAI,KAAK,UAAU,CAAC;AACrD,CAAC;AAED,SAAS,QAAQ,CAAC,QAAmB;IACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjF,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAsB,EACtB,IAAY,EACZ,OAAO,GAA2B,EAAE;IAEpC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACrD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;IACpD,MAAM,EACJ,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,OAAO,EACP,MAAM,GAAG,OAAO,EAChB,MAAM,GAAG,EAAE,EACX,MAAM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AC,CAAC,KAAK,SAAS,CAAC,CACnG,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,GAAG,IAAI,MAAM,EAAE,OAAO,CAAC,CAAC;QACpE,IAAI,OAAO;YAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,eAAe,CAAC,GAAG,IAAI,cAAc,EAAE,OAAO,CAAC,CAAC;IAC7F,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,KAAK,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACtE,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAClG,MAAM,CAAC,GAAG,EAAE,4BAA4B,IAAI,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /** Duration detection and sample-time planning (port of timing.py). */
2
+ import type { AnimationTiming, DurationInfo } from "./models.js";
3
+ export declare const FALLBACK_SECONDS = 3;
4
+ export declare const MAX_SECONDS = 60;
5
+ /** Use the LCM of loop periods only if it is at most this many times the longest period. */
6
+ export declare const LCM_FACTOR = 4;
7
+ /** One 60 fps frame: the last tile and the loop probe sit this far before the cycle end. */
8
+ export declare const EPSILON: number;
9
+ /** Normalise raw runtime output (`window.__framesheet.timings()`) to full records. */
10
+ export declare function parseTimings(raw: unknown[]): AnimationTiming[];
11
+ /**
12
+ * Pick the time span to sample.
13
+ *
14
+ * - Infinite animations contribute their loop period (`duration`, doubled for
15
+ * `alternate`). Several periods are combined with their least common multiple if that
16
+ * stays reasonable, otherwise the longest period wins.
17
+ * - A positive start (`begin`/`delay`) of a looping animation is added, so the warm-up
18
+ * before the first iteration is visible.
19
+ * - Finite animations contribute their end time (delay + duration x iterations).
20
+ */
21
+ export declare function detectDuration(animations: AnimationTiming[], override?: number | null): DurationInfo;
22
+ /** The probe offset for loop checks: one 60 fps frame, or 1% of very short cycles. */
23
+ export declare function epsilon(duration: number): number;
24
+ /**
25
+ * Evenly spaced times over `[0, duration]`. The last sample is one 60 fps frame *before*
26
+ * the end: at exactly `t=end` an infinite animation has already wrapped to its first
27
+ * frame, which would make every loop look seamless.
28
+ */
29
+ export declare function sampleTimes(duration: number, frames: number): number[];
30
+ //# sourceMappingURL=timing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../src/timing.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGjE,eAAO,MAAM,gBAAgB,IAAM,CAAC;AACpC,eAAO,MAAM,WAAW,KAAO,CAAC;AAChC,4FAA4F;AAC5F,eAAO,MAAM,UAAU,IAAI,CAAC;AAC5B,4FAA4F;AAC5F,eAAO,MAAM,OAAO,QAAS,CAAC;AAE9B,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,eAAe,EAAE,CAgB9D;AAYD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,eAAe,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,YAAY,CAgEpG;AAED,sFAAsF;AACtF,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAKtE"}
package/dist/timing.js ADDED
@@ -0,0 +1,128 @@
1
+ /** Duration detection and sample-time planning (port of timing.py). */
2
+ import { g, pyRound } from "./pyfmt.js";
3
+ export const FALLBACK_SECONDS = 3.0;
4
+ export const MAX_SECONDS = 60.0;
5
+ /** Use the LCM of loop periods only if it is at most this many times the longest period. */
6
+ export const LCM_FACTOR = 4;
7
+ /** One 60 fps frame: the last tile and the loop probe sit this far before the cycle end. */
8
+ export const EPSILON = 1 / 60;
9
+ /** Normalise raw runtime output (`window.__framesheet.timings()`) to full records. */
10
+ export function parseTimings(raw) {
11
+ return raw.map((item) => {
12
+ const r = item;
13
+ return {
14
+ kind: r.kind,
15
+ target: r.target ?? null,
16
+ name: r.name ?? null,
17
+ start: Number(r.start),
18
+ duration: Number(r.duration),
19
+ iterations: r.iterations == null ? null : Number(r.iterations),
20
+ direction: r.direction ?? "normal",
21
+ period: Number(r.period),
22
+ end: r.end == null ? null : Number(r.end),
23
+ transform_box: r.transform_box ?? null,
24
+ };
25
+ });
26
+ }
27
+ function gcd(a, b) {
28
+ while (b)
29
+ [a, b] = [b, a % b];
30
+ return a;
31
+ }
32
+ function lcm(periods) {
33
+ const ticks = periods.map((p) => Math.max(1, pyRound(p * 100))); // 10 ms resolution
34
+ return ticks.reduce((a, b) => (a / gcd(a, b)) * b) / 100;
35
+ }
36
+ /**
37
+ * Pick the time span to sample.
38
+ *
39
+ * - Infinite animations contribute their loop period (`duration`, doubled for
40
+ * `alternate`). Several periods are combined with their least common multiple if that
41
+ * stays reasonable, otherwise the longest period wins.
42
+ * - A positive start (`begin`/`delay`) of a looping animation is added, so the warm-up
43
+ * before the first iteration is visible.
44
+ * - Finite animations contribute their end time (delay + duration x iterations).
45
+ */
46
+ export function detectDuration(animations, override) {
47
+ const infinite = animations.filter((a) => a.iterations === null);
48
+ const finite = animations.filter((a) => a.iterations !== null && a.end !== null);
49
+ const looping = infinite.length > 0;
50
+ if (override != null) {
51
+ return {
52
+ seconds: override,
53
+ method: "override",
54
+ looping,
55
+ detail: `--duration ${g(override)}s`,
56
+ animations,
57
+ };
58
+ }
59
+ if (animations.length === 0) {
60
+ return {
61
+ seconds: FALLBACK_SECONDS,
62
+ method: "fallback",
63
+ looping: false,
64
+ detail: `no SMIL/CSS/Web Animations found; sampled the ${g(FALLBACK_SECONDS)}s ` +
65
+ "fallback (pass --duration for JS-driven animation)",
66
+ animations: [],
67
+ };
68
+ }
69
+ const parts = [];
70
+ let seconds = 0;
71
+ if (infinite.length) {
72
+ const periods = [...new Set(infinite.map((a) => pyRound(a.period, 3)))].sort((a, b) => a - b);
73
+ let cycle = lcm(periods);
74
+ const longest = periods[periods.length - 1];
75
+ const list = periods.map((p) => `${g(p)}s`).join(", ");
76
+ if (periods.length === 1) {
77
+ parts.push(`loop period ${g(periods[0])}s`);
78
+ }
79
+ else if (cycle <= LCM_FACTOR * longest && cycle <= MAX_SECONDS) {
80
+ parts.push(`LCM of loop periods ${list}`);
81
+ }
82
+ else {
83
+ cycle = longest;
84
+ parts.push(`longest of loop periods ${list} (no short common multiple)`);
85
+ }
86
+ seconds = cycle;
87
+ const warmup = Math.max(Math.max(...infinite.map((a) => a.start)), 0);
88
+ if (warmup > 0) {
89
+ seconds = Math.max(seconds, warmup + cycle);
90
+ parts.push(`+ ${g(warmup)}s positive begin/delay before the first loop`);
91
+ }
92
+ }
93
+ if (finite.length) {
94
+ const lastEnd = Math.max(...finite.map((a) => a.end ?? 0));
95
+ if (lastEnd > seconds) {
96
+ seconds = lastEnd;
97
+ parts.push(`finite animations end at ${g(lastEnd)}s`);
98
+ }
99
+ }
100
+ const kinds = [...new Set(animations.map((a) => a.kind))].sort();
101
+ let detail = `${parts.join("; ")} (${animations.length} animation(s): ${kinds.join(", ")})`;
102
+ if (seconds > MAX_SECONDS) {
103
+ detail += `; capped at ${g(MAX_SECONDS)}s`;
104
+ seconds = MAX_SECONDS;
105
+ }
106
+ if (seconds <= 0) {
107
+ seconds = FALLBACK_SECONDS;
108
+ detail += `; zero-length, using ${g(FALLBACK_SECONDS)}s`;
109
+ }
110
+ return { seconds: pyRound(seconds, 3), method: "detected", looping, detail, animations };
111
+ }
112
+ /** The probe offset for loop checks: one 60 fps frame, or 1% of very short cycles. */
113
+ export function epsilon(duration) {
114
+ return Math.min(EPSILON, duration / 100);
115
+ }
116
+ /**
117
+ * Evenly spaced times over `[0, duration]`. The last sample is one 60 fps frame *before*
118
+ * the end: at exactly `t=end` an infinite animation has already wrapped to its first
119
+ * frame, which would make every loop look seamless.
120
+ */
121
+ export function sampleTimes(duration, frames) {
122
+ if (frames < 2)
123
+ return [0];
124
+ const times = Array.from({ length: frames }, (_, i) => pyRound((duration * i) / (frames - 1), 4));
125
+ times[times.length - 1] = pyRound(duration - epsilon(duration), 4);
126
+ return times;
127
+ }
128
+ //# sourceMappingURL=timing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing.js","sourceRoot":"","sources":["../src/timing.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAGvE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AACpC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC;AAChC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAC5B,4FAA4F;AAC5F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,CAAC;AAE9B,sFAAsF;AACtF,MAAM,UAAU,YAAY,CAAC,GAAc;IACzC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACtB,MAAM,CAAC,GAAG,IAA+B,CAAC;QAC1C,OAAO;YACL,IAAI,EAAE,CAAC,CAAC,IAA+B;YACvC,MAAM,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,CAAC,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,MAAc;IAC1D,IAAI,MAAM,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAClG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IACnE,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,80 @@
1
1
  {
2
2
  "name": "framesheet",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Frame-accurate contact sheets, motion heatmaps and checks for animated SVG/HTML and running web apps, for humans and AI agents (Playwright)",
5
+ "keywords": [
6
+ "animation",
7
+ "svg",
8
+ "playwright",
9
+ "visual-regression",
10
+ "contact-sheet",
11
+ "smil",
12
+ "web-animations",
13
+ "ai-agent"
14
+ ],
15
+ "homepage": "https://github.com/phil65/framesheet/tree/main/js#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/phil65/framesheet.git",
19
+ "directory": "js"
20
+ },
21
+ "bugs": "https://github.com/phil65/framesheet/issues",
22
+ "license": "MIT",
23
+ "author": "Philipp Temminghoff",
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./test": {
32
+ "types": "./dist/test.d.ts",
33
+ "default": "./dist/test.js"
34
+ },
35
+ "./schema/report.schema.json": "./dist/report.schema.json",
36
+ "./package.json": "./package.json"
37
+ },
38
+ "main": "./dist/index.js",
39
+ "types": "./dist/index.d.ts",
40
+ "files": [
41
+ "dist",
42
+ "src",
43
+ "README.md",
44
+ "LICENSE"
45
+ ],
46
+ "engines": {
47
+ "node": ">=20"
48
+ },
49
+ "scripts": {
50
+ "generate": "node scripts/embed-assets.mjs",
51
+ "build": "node scripts/embed-assets.mjs && rm -rf dist && tsc -p tsconfig.build.json && node scripts/copy-schema.mjs",
52
+ "typecheck": "node scripts/embed-assets.mjs && tsc -p tsconfig.json --noEmit",
53
+ "check:runtime": "node scripts/check-runtime.mjs",
54
+ "test": "node scripts/embed-assets.mjs && vitest run",
55
+ "test:e2e": "playwright test -c e2e/playwright.config.ts",
56
+ "golden": "cd .. && uv run --no-sync python scripts/golden_reports.py",
57
+ "prepack": "npm run build && node scripts/check-runtime.mjs"
58
+ },
59
+ "dependencies": {
60
+ "pngjs": "^7.0.0"
61
+ },
62
+ "peerDependencies": {
63
+ "@playwright/test": ">=1.45.0",
64
+ "playwright-core": ">=1.45.0"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "@playwright/test": {
68
+ "optional": true
69
+ }
70
+ },
71
+ "devDependencies": {
72
+ "@playwright/test": "1.65.1",
73
+ "@types/node": "^22.19.0",
74
+ "@types/pngjs": "^6.0.5",
75
+ "ajv": "^8.17.1",
76
+ "playwright-core": "1.65.1",
77
+ "typescript": "^7.0.2",
78
+ "vitest": "^5.1.1"
79
+ }
80
+ }