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,150 @@
1
+ /**
2
+ * The inspection pipeline (port of core.py): load, detect duration, sample, check,
3
+ * compose. `inspect()` renders a file/markup/URL in its own browser context;
4
+ * `inspectPage()` inspects a page (or one component) you already have open.
5
+ */
6
+ import type { Browser, LaunchOptions, Locator, Page } from "playwright-core";
7
+ import type { ColorScheme, Finding, ImageBuffers, ImagePaths, Report } from "./models.js";
8
+ /** A seam changing fewer than 0.2% of pixels always counts as seamless. */
9
+ export declare const SEAM_MIN_RATIO = 0.002;
10
+ /** A seam is a jump if it changes this many times more pixels than one normal step. */
11
+ export declare const SEAM_STEP_FACTOR = 3;
12
+ export declare const MIN_AUTO_SIDE = 400;
13
+ export declare const MAX_CONSOLE_ERRORS = 5;
14
+ /** Virtual clock origin (same as Python): 2025-01-01T00:00:00Z. */
15
+ export declare const EPOCH: number;
16
+ /**
17
+ * Chromium flags framesheet launches with. Pass them to your own browser
18
+ * (`launchOptions: { args: LAUNCH_ARGS }`) for byte-stable frames.
19
+ */
20
+ export declare const LAUNCH_ARGS: string[];
21
+ export declare const INSTALL_HINT: string;
22
+ export declare class BrowserNotInstalledError extends Error {
23
+ constructor(cause?: unknown);
24
+ }
25
+ /** Options shared by {@link inspect} and {@link inspectPage}. */
26
+ export interface SampleOptions {
27
+ /** Number of contact-sheet tiles (2-100), spread over one cycle. Default 12. */
28
+ frames?: number;
29
+ /** Cycle length in seconds; detected from SMIL/CSS/Web Animations if omitted. */
30
+ duration?: number;
31
+ /** Time in seconds of the full-resolution frame `full`. Default 0. */
32
+ at?: number;
33
+ /** Write `full.png`, `sheet.png`, `heatmap.png`, `report.json` here (default: nothing written). */
34
+ out?: string;
35
+ /** Longest side of a contact-sheet tile in px (default: fit 1568 px width). */
36
+ tile?: number;
37
+ /** Contact-sheet columns (default: roughly 4:3 sheet). */
38
+ columns?: number;
39
+ /** Also return (and write to `frames/`) every contact-sheet frame. */
40
+ keepFrames?: boolean;
41
+ /** Extra evenly spaced frames (pixels only) for a continuous heatmap trail. Default 48. */
42
+ heatFrames?: number;
43
+ /** Timeout for navigation and page scripts in ms. Default 30000. */
44
+ timeout?: number;
45
+ }
46
+ export interface InspectOptions extends SampleOptions {
47
+ /** Viewport `[width, height]` in CSS px (default: SVG size/viewBox, or 1280x720). */
48
+ size?: [number, number];
49
+ /** Device scale factor (default 1; tiny SVGs without `size` get more). */
50
+ scale?: number;
51
+ /** `prefers-color-scheme`. Default `light`. */
52
+ colorScheme?: ColorScheme;
53
+ /** Reuse a browser (a new context is created and closed). Default: launch Chromium. */
54
+ browser?: Browser;
55
+ /** Passed to `chromium.launch()` when no `browser` is given (args are added to LAUNCH_ARGS). */
56
+ launchOptions?: LaunchOptions;
57
+ /**
58
+ * Abort every HTTP(S) request except the input itself (`data:`/`blob:` URLs still work)
59
+ * and close every WebSocket. Recommended for untrusted markup (e.g. agent output in a
60
+ * server). Default false.
61
+ */
62
+ blockNetwork?: boolean;
63
+ }
64
+ export interface InspectPageOptions extends SampleOptions {
65
+ /** Inspect only this element (a component); default: the whole page/viewport. */
66
+ locator?: Locator;
67
+ /** Header title of the sheet/heatmap (default: locator or URL path; keep stable for snapshots). */
68
+ title?: string;
69
+ /**
70
+ * Whether Playwright's fake clock drives JS time. Default: auto (true if `prepare(page)`
71
+ * ran before navigation). Without it, SMIL/CSS/Web Animations are still frame-accurate,
72
+ * but rAF/timer-driven motion keeps running in real time.
73
+ */
74
+ clock?: boolean;
75
+ /**
76
+ * Called after time is frozen and before t=0 is captured, e.g. `() => button.click()`
77
+ * to start an "open" animation from its first frame.
78
+ */
79
+ trigger?: () => Promise<unknown>;
80
+ /** Extra space (CSS px) around the locator's box in the images. Default 0. */
81
+ padding?: number;
82
+ /** Run static source checks on the locator's/page's serialised markup. Default false. */
83
+ staticChecks?: boolean;
84
+ }
85
+ /** Everything framesheet found out about one input. */
86
+ export declare class Inspection {
87
+ /** The report (same schema as the Python package's report.json). */
88
+ readonly report: Report;
89
+ /** PNG bytes. */
90
+ readonly images: ImageBuffers;
91
+ /** Written files (only with `out`). */
92
+ readonly files: ImagePaths | null;
93
+ constructor(
94
+ /** The report (same schema as the Python package's report.json). */
95
+ report: Report,
96
+ /** PNG bytes. */
97
+ images: ImageBuffers,
98
+ /** Written files (only with `out`). */
99
+ files: ImagePaths | null);
100
+ get findings(): Finding[];
101
+ get errors(): Finding[];
102
+ get warnings(): Finding[];
103
+ /** All finding codes, handy for assertions. */
104
+ codes(): Set<string>;
105
+ /** Concise multi-line text for humans and agents (what the Python CLI prints). */
106
+ summary(): string;
107
+ /** `report.json` content. */
108
+ toJSON(): Report;
109
+ }
110
+ /** Concise multi-line text for a report (same format as the Python package). */
111
+ export declare function summarize(r: Report): string;
112
+ /**
113
+ * Render an animated SVG/HTML at evenly spaced virtual times and check it.
114
+ *
115
+ * @param source Path to an `.svg`/`.html` file, an `http(s)://` URL, or a markup string
116
+ * starting with `<`.
117
+ */
118
+ export declare function inspect(source: string, options?: InspectOptions): Promise<Inspection>;
119
+ export interface PrepareOptions {
120
+ /**
121
+ * Freeze time from navigation on, exactly like `inspect()` does: JS-driven motion that
122
+ * starts on load is captured from its first frame, byte for byte. The page's timers,
123
+ * rAF and `Date` stand still until an inspection (or `page.clock.runFor`) advances
124
+ * them, which suits component pages and stories better than whole apps.
125
+ * Default false: the fake clock follows real time and the app behaves normally.
126
+ */
127
+ paused?: boolean;
128
+ }
129
+ /**
130
+ * Install Playwright's fake clock on a page **before navigation** (`goto`), so that
131
+ * `inspectPage` can also step JavaScript-driven motion (requestAnimationFrame, timers,
132
+ * `Date`, `performance.now`: canvas, rAF/spring animation libraries) frame by frame.
133
+ *
134
+ * By default the clock keeps running in real time until an inspection pauses it, so the
135
+ * app behaves normally; after each inspection it runs on again. With `paused: true` time
136
+ * is frozen from the start (see {@link PrepareOptions.paused}). Not needed for SMIL, CSS
137
+ * animations/transitions or Web Animations, which are seeked directly on any page.
138
+ */
139
+ export declare function prepare(page: Page, options?: PrepareOptions): Promise<void>;
140
+ /**
141
+ * Inspect a page you already have open (e.g. in a Playwright test), or one component of it
142
+ * (`locator`). Same sampling, checks, images and report as {@link inspect}.
143
+ *
144
+ * Works on any page for SMIL, CSS animations/transitions and Web Animations. For JS-driven
145
+ * motion call {@link prepare} before navigating. The page is handed back afterwards
146
+ * (animations resumed, fake clock running again), but seeked animations continue from
147
+ * where the inspection left them.
148
+ */
149
+ export declare function inspectPage(page: Page, options?: InspectPageOptions): Promise<Inspection>;
150
+ //# sourceMappingURL=inspect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect.d.ts","sourceRoot":"","sources":["../src/inspect.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAiC,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAK5G,OAAO,KAAK,EACV,WAAW,EAEX,OAAO,EAEP,YAAY,EACZ,UAAU,EAGV,MAAM,EAGP,MAAM,aAAa,CAAC;AAOrB,2EAA2E;AAC3E,eAAO,MAAM,cAAc,QAAQ,CAAC;AACpC,uFAAuF;AAC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