@kernocal/viteshot 0.1.1

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,112 @@
1
+ import { CreatePageOptions, LaunchOptions, ScreenshotOptions } from "puppeteer-core";
2
+ import { InlineConfig as InlineConfig$1, UserConfig as UserConfig$1, ViteDevServer } from "vite";
3
+
4
+ //#region src/core/capture-extension-screenshots.d.ts
5
+ type CapturedImages = {
6
+ popup?: Buffer;
7
+ sidebar?: Buffer;
8
+ options?: Buffer;
9
+ };
10
+ /** locale language string → captured images (e.g. "es" → { sidebar: Buffer, ... }) */
11
+ type CaptureResult = Map<string, CapturedImages>;
12
+ type CaptureOptions = {
13
+ extensionPath: string;
14
+ chromePath?: string;
15
+ localesDir?: string;
16
+ waitSelector?: string;
17
+ settleDelay?: number;
18
+ };
19
+ /**
20
+ * Capture popup/sidebar/options screenshots for a single locale.
21
+ * Pass `language: "_default"` (or omit) to capture without `--lang`.
22
+ */
23
+ declare function captureLocale(options: {
24
+ extensionPath: string;
25
+ chromePath?: string;
26
+ language?: string;
27
+ waitSelector?: string;
28
+ settleDelay?: number;
29
+ }): Promise<CapturedImages>;
30
+ /**
31
+ * Capture popup/sidebar/options screenshots for all locales (batch).
32
+ * Used by the `export` command.
33
+ */
34
+ declare function captureExtensionScreenshots(options: CaptureOptions): Promise<CaptureResult>;
35
+ //#endregion
36
+ //#region src/core/config.d.ts
37
+ type PuppeteerOptions = {
38
+ launchOptions?: LaunchOptions;
39
+ newPageOptions?: CreatePageOptions;
40
+ screenshotOptions?: Omit<ScreenshotOptions, "clip" | "path">;
41
+ };
42
+ type UserConfig = UserConfig$1 & {
43
+ screenshots?: {
44
+ /** @default "locales" */localesDir?: string; /** @default "designs" */
45
+ designsDir?: string; /** @default "screenshots" */
46
+ exportsDir?: string;
47
+ /**
48
+ * How many screenshots can be exported concurrently.
49
+ *
50
+ * @default 4
51
+ */
52
+ renderConcurrency?: number; /** Override the options passed into puppeteer. */
53
+ puppeteer?: PuppeteerOptions;
54
+ /**
55
+ * List of relative paths from your viteshot.config.ts file to CSS files to
56
+ * add to your screenshot's HTML file as links.
57
+ */
58
+ css?: string[]; /** Path to the unpacked extension directory for popup screenshots. @default ".output/chrome-mv3" */
59
+ extensionPath?: string; /** Path to the Chrome/Chromium executable. Falls back to VITESHOT_CHROME_PATH env var. */
60
+ chromePath?: string;
61
+ };
62
+ };
63
+ type InlineConfig = UserConfig & {
64
+ root: string;
65
+ };
66
+ type ResolvedConfig = {
67
+ root: string;
68
+ localesDir: string;
69
+ designsDir: string;
70
+ exportsDir: string;
71
+ renderConcurrency: number;
72
+ puppeteer: PuppeteerOptions | undefined;
73
+ css: string[];
74
+ extensionPath: string;
75
+ chromePath: string;
76
+ captures?: CaptureResult;
77
+ vite: InlineConfig$1;
78
+ };
79
+ declare function defineConfig(config: UserConfig): UserConfig;
80
+ declare function resolveConfig(dir?: string): Promise<ResolvedConfig>;
81
+ //#endregion
82
+ //#region src/core/create-server.d.ts
83
+ declare function createServer(dir?: string): Promise<ViteDevServer>;
84
+ //#endregion
85
+ //#region src/core/export-screenshots.d.ts
86
+ declare function exportScreenshots(config: ResolvedConfig): Promise<void>;
87
+ //#endregion
88
+ //#region src/core/export-popup-screenshot.d.ts
89
+ type PopupScreenshotOptions = {
90
+ extensionPath: string;
91
+ chromePath?: string;
92
+ outputDir?: string;
93
+ localesDir?: string;
94
+ waitSelector?: string;
95
+ settleDelay?: number;
96
+ };
97
+ declare function exportPopupScreenshot(options: PopupScreenshotOptions): Promise<void>;
98
+ //#endregion
99
+ //#region src/core/get-screenshots.d.ts
100
+ type Screenshot = {
101
+ id: string;
102
+ path: string;
103
+ ext: string;
104
+ name: string;
105
+ size: string;
106
+ width: number;
107
+ height: number;
108
+ };
109
+ declare function getScreenshots(designsDir: string): Promise<Screenshot[]>;
110
+ declare function logInvalidDesignFiles(designsDir: string): Promise<void>;
111
+ //#endregion
112
+ export { CaptureOptions, CaptureResult, CapturedImages, InlineConfig, PopupScreenshotOptions, PuppeteerOptions, ResolvedConfig, Screenshot, UserConfig, captureExtensionScreenshots, captureLocale, createServer, defineConfig, exportPopupScreenshot, exportScreenshots, getScreenshots, logInvalidDesignFiles, resolveConfig };
package/dist/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import { n as resolveConfig, t as defineConfig } from "./config-BvHGePNd.mjs";
2
+ import { i as logInvalidDesignFiles, n as captureLocale, r as getScreenshots, t as captureExtensionScreenshots } from "./capture-extension-screenshots-DQWqq69W.mjs";
3
+ import { t as createServer } from "./create-server-CpPbF7ms.mjs";
4
+ import { t as exportScreenshots } from "./export-screenshots-B6IGCV4J.mjs";
5
+ import { t as exportPopupScreenshot } from "./export-popup-screenshot-UhxUtKCP.mjs";
6
+
7
+ export { captureExtensionScreenshots, captureLocale, createServer, defineConfig, exportPopupScreenshot, exportScreenshots, getScreenshots, logInvalidDesignFiles, resolveConfig };
@@ -0,0 +1,63 @@
1
+ import { basename, dirname, join, relative, resolve } from "node:path";
2
+ import { access, mkdir, writeFile } from "node:fs/promises";
3
+ import { styleText } from "node:util";
4
+
5
+ //#region src/core/init.ts
6
+ async function init(_dir) {
7
+ const absDir = resolve(_dir);
8
+ const relativeDir = relative(process.cwd(), absDir);
9
+ const dirBasename = basename(_dir);
10
+ for (const [file, contents] of Object.entries(FILES)) {
11
+ const path = join(absDir, file);
12
+ if (await access(path).then(() => true, () => false)) {
13
+ process.stdout.write(`File ${file} already exists. Overwrite? (y/n) `);
14
+ if ((await waitForInput()).toLowerCase() !== "y") continue;
15
+ }
16
+ await mkdir(dirname(path), { recursive: true });
17
+ await writeFile(path, contents);
18
+ }
19
+ console.log(`\n${styleText(["bold", "cyan"], "ViteShot")} project initialized:\n`);
20
+ for (const file of Object.keys(FILES)) console.log(` ${styleText("dim", `./${relativeDir}/`)}${styleText(["bold", "blue"], file)}`);
21
+ console.log("\nAdd the following scripts to your package.json:\n");
22
+ console.log(` "${dirBasename}:dev": "viteshot dev ${relativeDir}",`);
23
+ console.log(` "${dirBasename}:export": "viteshot export ${relativeDir}"\n`);
24
+ }
25
+ async function waitForInput() {
26
+ return new Promise((resolve) => {
27
+ process.stdin.once("data", (data) => {
28
+ resolve(data.toString().trim());
29
+ });
30
+ });
31
+ }
32
+ const FILES = {
33
+ "viteshot.config.ts": `import { defineConfig } from 'viteshot';
34
+
35
+ export default defineConfig({
36
+ screenshots: {
37
+ // Add CSS to the <head> of your design's HTML document
38
+ css: ["assets/style.css"],
39
+
40
+ // Other ViteShot config here
41
+ },
42
+
43
+ // Regular Vite config here
44
+ })
45
+ `,
46
+ "assets/style.css": `/* Global styles here */
47
+ body {
48
+ background: #181818;
49
+ color: white;
50
+ }`,
51
+ "designs/screenshot-1@600x480.html": `<style>
52
+ /* Inline styles per-design here */
53
+ </style>
54
+
55
+ <div>
56
+ <p>Screenshot design here</p>
57
+ <p>{{translated}}</p>
58
+ </div>
59
+ `
60
+ };
61
+
62
+ //#endregion
63
+ export { init };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@kernocal/viteshot",
3
+ "description": "fork adding weird popup sidebar options screenshots. original by @aklinker1",
4
+ "version": "0.1.1",
5
+ "type": "module",
6
+ "dependencies": {
7
+ "async-mutex": "^0.5.0",
8
+ "natural-compare-lite": "^1.4.0",
9
+ "p-map": "^7.0.4",
10
+ "p-queue": "^9.1.0",
11
+ "puppeteer-core": "^24.37.5"
12
+ },
13
+ "peerDependencies": {
14
+ "svelte": ">=5",
15
+ "vite": ">=5"
16
+ },
17
+ "peerDependenciesMeta": {
18
+ "svelte": {
19
+ "optional": true
20
+ }
21
+ },
22
+ "devDependencies": {
23
+ "@aklinker1/check": "^2.4.0",
24
+ "@sveltejs/vite-plugin-svelte": "^7.0.0",
25
+ "@tailwindcss/vite": "^4.2.2",
26
+ "@types/natural-compare-lite": "^1.4.2",
27
+ "@typescript/native-preview": "^7.0.0-dev.20260223.1",
28
+ "oxlint": "^1.50.0",
29
+ "prettier": "^3.8.1",
30
+ "prettier-plugin-jsdoc": "^1.8.0",
31
+ "publint": "^0.3.17",
32
+ "puppeteer": "^24.37.5",
33
+ "tailwindcss": "^4.2.2",
34
+ "tsdown": "^0.20.3",
35
+ "typescript": "^5"
36
+ },
37
+ "types": "dist/index.d.mts",
38
+ "module": "dist/index.mjs",
39
+ "bin": {
40
+ "viteshot": "dist/cli.mjs"
41
+ },
42
+ "exports": {
43
+ ".": {
44
+ "types": "./dist/index.d.mts",
45
+ "default": "./dist/index.mjs"
46
+ }
47
+ },
48
+ "license": "MIT",
49
+ "repository": {
50
+ "url": "https://github.com/Kernocal/viteshot"
51
+ },
52
+ "files": [
53
+ "dist",
54
+ "assets"
55
+ ],
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "scripts": {
60
+ "build": "tsdown"
61
+ }
62
+ }