@archastro/react-shot 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.
package/dist/stubs.js ADDED
@@ -0,0 +1,49 @@
1
+ export const nextNavigationStub = `
2
+ export function useRouter() {
3
+ return {
4
+ push() {}, replace() {}, prefetch() {}, back() {},
5
+ forward() {}, refresh() {},
6
+ };
7
+ }
8
+ export function usePathname() { return "/"; }
9
+ export function useSearchParams() { return new URLSearchParams(); }
10
+ export function useParams() { return {}; }
11
+ export function redirect() {}
12
+ export function notFound() {}
13
+ `;
14
+ export const nextLinkStub = `
15
+ import React from "react";
16
+ export default function Link({ href, children, ...rest }) {
17
+ return React.createElement("a", { href: typeof href === "string" ? href : "#", ...rest }, children);
18
+ }
19
+ `;
20
+ export const nextImageStub = `
21
+ import React from "react";
22
+ export default function Image({ src, alt, width, height, ...rest }) {
23
+ return React.createElement("img", {
24
+ src: typeof src === "string" ? src : "",
25
+ alt: alt || "",
26
+ width,
27
+ height,
28
+ ...rest,
29
+ });
30
+ }
31
+ `;
32
+ export const serverOnlyStub = `export {};`;
33
+ export const nextDynamicStub = `
34
+ import React from "react";
35
+ export default function dynamic(loader, options) {
36
+ const Lazy = React.lazy(loader);
37
+ const fallback = options && options.loading
38
+ ? React.createElement(options.loading)
39
+ : null;
40
+ return function DynamicComponent(props) {
41
+ return React.createElement(
42
+ React.Suspense,
43
+ { fallback },
44
+ React.createElement(Lazy, props),
45
+ );
46
+ };
47
+ }
48
+ `;
49
+ //# sourceMappingURL=stubs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stubs.js","sourceRoot":"","sources":["../src/stubs.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;CAYjC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;CAK3B,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;CAW5B,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAE3C,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;CAe9B,CAAC"}
@@ -0,0 +1,79 @@
1
+ import type { ReactNode } from "react";
2
+ /**
3
+ * Default export shape for a react-shot fixture module.
4
+ *
5
+ * @example
6
+ * ```tsx
7
+ * export default {
8
+ * width: 720,
9
+ * height: 900,
10
+ * background: "#faf9f6",
11
+ * component: <MyModal />,
12
+ * } satisfies ReactShotFixture;
13
+ * ```
14
+ */
15
+ export interface ReactShotFixture {
16
+ /** React tree to mount. */
17
+ component: ReactNode;
18
+ /** Viewport width in CSS pixels. Defaults to 1280. */
19
+ width?: number;
20
+ /** Viewport height in CSS pixels. Defaults to 800. */
21
+ height?: number;
22
+ /** Page or canvas background. Defaults to transparent. */
23
+ background?: string;
24
+ /** CSS selector to capture. Defaults to `[data-react-shot-root]`. */
25
+ selector?: string;
26
+ /** Optional selector or `text=...` value that must become visible. */
27
+ waitFor?: string;
28
+ /** Additional layout settling time in milliseconds. Defaults to 150. */
29
+ settleMs?: number;
30
+ /** Capture the full page instead of the selected element. */
31
+ fullPage?: boolean;
32
+ /**
33
+ * Remove a full-screen overlay around the target before capture.
34
+ * Defaults to true when `selector` targets a dialog.
35
+ */
36
+ stripOverlay?: boolean;
37
+ /**
38
+ * Preserve transparency in the PNG. Defaults to true for isolated dialogs.
39
+ */
40
+ omitBackground?: boolean;
41
+ }
42
+ /** Package-level config exported from `react-shot.config.*`. */
43
+ export interface ReactShotConfig {
44
+ /** Package root used for module resolution. Relative paths are config-relative. */
45
+ root?: string;
46
+ /** Vite aliases, such as `@` to an application's source directory. */
47
+ alias?: Record<string, string>;
48
+ /** CSS files imported into every fixture host page. */
49
+ styles?: string[];
50
+ /** Path to a PostCSS config file. */
51
+ postcssConfig?: string;
52
+ /** Additional dependencies Vite should deduplicate. */
53
+ dedupe?: string[];
54
+ /** Module names that should resolve to an empty browser-safe stub. */
55
+ stubModules?: string[];
56
+ }
57
+ export interface ShotRequest {
58
+ fixturePath: string;
59
+ outPath: string;
60
+ root?: string;
61
+ configPath?: string;
62
+ headed?: boolean;
63
+ width?: number;
64
+ height?: number;
65
+ }
66
+ export interface BatchEntry {
67
+ fixture: string;
68
+ out: string;
69
+ root?: string;
70
+ config?: string;
71
+ width?: number;
72
+ height?: number;
73
+ }
74
+ export interface BatchManifest {
75
+ root?: string;
76
+ config?: string;
77
+ shots: BatchEntry[];
78
+ }
79
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2BAA2B;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,gEAAgE;AAChE,MAAM,WAAW,eAAe;IAC9B,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,qCAAqC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>react-shot</title>
7
+ <style>
8
+ html,
9
+ body {
10
+ margin: 0;
11
+ padding: 0;
12
+ }
13
+ #root {
14
+ min-height: 100vh;
15
+ }
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <div id="root"></div>
20
+ <script type="module" src="/@react-shot/entry.tsx"></script>
21
+ </body>
22
+ </html>
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@archastro/react-shot",
3
+ "version": "0.1.0",
4
+ "description": "Capture deterministic PNG screenshots from React and TSX fixtures",
5
+ "keywords": [
6
+ "react",
7
+ "screenshot",
8
+ "playwright",
9
+ "tsx",
10
+ "visual-testing"
11
+ ],
12
+ "homepage": "https://github.com/ArchAstro/astroshots#readme",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/ArchAstro/astroshots.git",
16
+ "directory": "packages/react-shot"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/ArchAstro/astroshots/issues"
20
+ },
21
+ "license": "MIT",
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ },
30
+ "./types": {
31
+ "types": "./dist/types.d.ts",
32
+ "import": "./dist/types.js"
33
+ }
34
+ },
35
+ "bin": {
36
+ "react-shot": "bin/react-shot.mjs"
37
+ },
38
+ "files": [
39
+ "bin",
40
+ "dist",
41
+ "host",
42
+ "README.md"
43
+ ],
44
+ "engines": {
45
+ "node": ">=22.14.0"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public",
49
+ "provenance": true,
50
+ "registry": "https://registry.npmjs.org/"
51
+ },
52
+ "scripts": {
53
+ "build": "tsc -p tsconfig.build.json",
54
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
55
+ "test": "npm run build && vitest run",
56
+ "test:unit": "vitest run src/meta.test.ts",
57
+ "test:e2e": "npm run build && vitest run src/cli.e2e.test.ts",
58
+ "typecheck": "tsc -p tsconfig.json --noEmit",
59
+ "prepack": "npm run clean && npm run build"
60
+ },
61
+ "dependencies": {
62
+ "@vitejs/plugin-react": "^5.2.0",
63
+ "playwright": "1.61.1",
64
+ "tsx": "^4.19.0",
65
+ "vite": "^6.2.0",
66
+ "yaml": "^2.7.0"
67
+ },
68
+ "peerDependencies": {
69
+ "react": ">=18",
70
+ "react-dom": ">=18"
71
+ },
72
+ "devDependencies": {
73
+ "@types/node": "^22.0.0",
74
+ "@types/react": "^19.0.0",
75
+ "@types/react-dom": "^19.0.0",
76
+ "react": "^19.0.0",
77
+ "react-dom": "^19.0.0",
78
+ "typescript": "^5.0.0",
79
+ "vitest": "^4.1.9"
80
+ }
81
+ }