storybook-addon-vis 4.6.0 → 4.7.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 (49) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/exports/constants-Dyl3Z-K5.mjs +5 -0
  3. package/dist/exports/constants-Dyl3Z-K5.mjs.map +1 -0
  4. package/dist/exports/matcher.d.mts +1 -1
  5. package/dist/exports/node.d.mts +4 -11
  6. package/dist/exports/node.d.mts.map +1 -1
  7. package/dist/exports/node.mjs +2 -4
  8. package/dist/exports/node.mjs.map +1 -1
  9. package/dist/exports/preset.d.mts +2 -6
  10. package/dist/exports/preset.d.mts.map +1 -1
  11. package/dist/exports/preset.mjs +8 -10
  12. package/dist/exports/preset.mjs.map +1 -1
  13. package/dist/exports/{types-CuNXsk6J.d.mts → types-DGIY4hWl.d.mts} +1 -3
  14. package/dist/exports/types-DGIY4hWl.d.mts.map +1 -0
  15. package/dist/exports/vitest-plugin.d.mts +2 -6
  16. package/dist/exports/vitest-plugin.d.mts.map +1 -1
  17. package/dist/exports/vitest-plugin.mjs +2 -3
  18. package/dist/exports/vitest-plugin.mjs.map +1 -1
  19. package/dist/exports/vitest-setup.d.mts +4 -8
  20. package/dist/exports/vitest-setup.d.mts.map +1 -1
  21. package/dist/exports/vitest-setup.mjs +2 -3
  22. package/dist/exports/vitest-setup.mjs.map +1 -1
  23. package/dist/{global_matcher_augment-B1plNA_9.d.mts → global_matcher_augment-CGDzrdCj.d.mts} +1 -4
  24. package/dist/global_matcher_augment-CGDzrdCj.d.mts.map +1 -0
  25. package/dist/index.d.mts +12 -26
  26. package/dist/index.d.mts.map +1 -1
  27. package/dist/index.mjs +6 -10
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/manager.d.ts +1 -1
  30. package/dist/manager.js +13 -17
  31. package/dist/manager.js.map +1 -1
  32. package/dist/{vis_annotation-BHBO0X19.mjs → vis_annotation-CJD3p9Uh.mjs} +15 -21
  33. package/dist/vis_annotation-CJD3p9Uh.mjs.map +1 -0
  34. package/dist/vis_annotation-DJqDOBIl.d.mts +5 -0
  35. package/dist/vis_annotation-DJqDOBIl.d.mts.map +1 -0
  36. package/llms.txt +3 -3
  37. package/package.json +4 -4
  38. package/skills/review-image-snapshot-failures/README.md +1 -1
  39. package/skills/review-image-snapshot-failures/SKILL.md +1 -1
  40. package/src/index.ts +1 -1
  41. package/src/overview.mdx +16 -0
  42. package/src/reviewing_failures_with_agents.mdx +17 -13
  43. package/dist/exports/constants-D_WcloLE.mjs +0 -7
  44. package/dist/exports/constants-D_WcloLE.mjs.map +0 -1
  45. package/dist/exports/types-CuNXsk6J.d.mts.map +0 -1
  46. package/dist/global_matcher_augment-B1plNA_9.d.mts.map +0 -1
  47. package/dist/vis_annotation-BHBO0X19.mjs.map +0 -1
  48. package/dist/vis_annotation-N0xbuXis.d.mts +0 -9
  49. package/dist/vis_annotation-N0xbuXis.d.mts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # CHANGE LOG
2
2
 
3
+ ## 4.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1028](https://github.com/repobuddy/visual-testing/pull/1028) [`03c1da1`](https://github.com/repobuddy/visual-testing/commit/03c1da151291802d61b93391da01c391af6b84fb) Thanks [@unional](https://github.com/unional)! - Write a whole-image review image when cropping does not help, and add `reviewImage: 'full'`.
8
+
9
+ When a failed snapshot's review image cannot be cropped to its changed regions
10
+ (the image size changed, more than 5 regions, the regions cover more than half of the image, or no region is found),
11
+ `<name>.review.png` now places the whole baseline, result, and diff side by side instead of being skipped.
12
+ The smaller image is padded to the larger size when the size changed.
13
+ The `Review:` line says `(baseline, result, diff of the whole image; not cropped, <reason>)`.
14
+
15
+ `reviewImage` also accepts `'full'` to always write the whole-image review, like the composite image of `jest-image-snapshot`.
16
+ In `storybook-addon-vis`, `storybookVis({ reviewImage: 'full' })` takes the same value.
17
+
18
+ - [#1029](https://github.com/repobuddy/visual-testing/pull/1029) [`5cb6da1`](https://github.com/repobuddy/visual-testing/commit/5cb6da1ee7fc2298aa620dfced2aabc31bf231b4) Thanks [@unional](https://github.com/unional)! - Report obsolete image snapshots at the end of each run, and delete them with `-u`.
19
+
20
+ The plugin records every baseline a run uses.
21
+ At the end of the run it lists the baselines in the run's snapshot folders that the run did not use,
22
+ like Vitest's `obsolete` count for text snapshots. With `-u`, it deletes them.
23
+
24
+ It keeps snapshots of skipped, todo, and failed tests, baselines of test files with errors or outside the run,
25
+ and snapshot folders the run did not use, such as other platforms and projects.
26
+ Baselines of test files that are gone are listed only when the run covered the snapshot folder in full.
27
+
28
+ Snapshots taken in Storybook through `storybook-addon-vis` are tracked the same way.
29
+
30
+ - [#824](https://github.com/repobuddy/visual-testing/pull/824) [`51f677c`](https://github.com/repobuddy/visual-testing/commit/51f677cd04ffc463f6404037d7bfa72587ae7deb) Thanks [@kohlmannj-nyt](https://github.com/kohlmannj-nyt)! - Re-export Vitest browser's `commands` export (https://vitest.dev/api/browser/commands.html)
31
+
32
+ ### Patch Changes
33
+
34
+ - [#572](https://github.com/repobuddy/visual-testing/pull/572) [`1bb4cb9`](https://github.com/repobuddy/visual-testing/commit/1bb4cb9675b305a754ed9353472d87072a5ed31d) Thanks [@renovate](https://github.com/apps/renovate)! - Build with `tsdown` 0.22. The emitted JavaScript and type declarations are equivalent; only formatting and import style change.
35
+ - Updated dependencies [[`03c1da1`](https://github.com/repobuddy/visual-testing/commit/03c1da151291802d61b93391da01c391af6b84fb), [`5cb6da1`](https://github.com/repobuddy/visual-testing/commit/5cb6da1ee7fc2298aa620dfced2aabc31bf231b4), [`1bb4cb9`](https://github.com/repobuddy/visual-testing/commit/1bb4cb9675b305a754ed9353472d87072a5ed31d)]:
36
+ - vitest-plugin-vis@5.6.0
37
+
3
38
  ## 4.6.0
4
39
 
5
40
  ### Minor Changes
@@ -0,0 +1,5 @@
1
+ // src/shared/constants.ts
2
+ const NAME = "storybook-addon-vis";
3
+
4
+ export { NAME as t };
5
+ //# sourceMappingURL=constants-Dyl3Z-K5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants-Dyl3Z-K5.mjs","names":[],"sources":["../../src/shared/constants.ts"],"sourcesContent":["export const NAME = 'storybook-addon-vis'\nexport const VIS_PANEL_ID = `${NAME}/vis_panel`\n"],"mappings":";AAAA,MAAa,OAAO"}
@@ -1 +1 @@
1
- import "../global_matcher_augment-B1plNA_9.mjs";
1
+ import "../global_matcher_augment-CGDzrdCj.mjs";
@@ -1,7 +1,4 @@
1
- import { t as StorybookVisOptions } from "./types-CuNXsk6J.mjs";
2
-
3
- //#region src/node/define_storybook_vis.d.ts
4
-
1
+ import { t as StorybookVisOptions } from "./types-DGIY4hWl.mjs";
5
2
  /**
6
3
  * Defines the Storybook Visual Testing addon configuration.
7
4
  *
@@ -30,7 +27,7 @@ import { t as StorybookVisOptions } from "./types-CuNXsk6J.mjs";
30
27
  * // Returns: { name: string, options: StorybookVisOptions }
31
28
  * ```
32
29
  */
33
- declare function defineStorybookVis(): string;
30
+ export declare function defineStorybookVis(): string;
34
31
  /**
35
32
  * Defines the Storybook Visual Testing addon configuration with options.
36
33
  *
@@ -62,16 +59,12 @@ declare function defineStorybookVis(): string;
62
59
  * }
63
60
  * ```
64
61
  */
65
- declare function defineStorybookVis(options: StorybookVisOptions): {
62
+ export declare function defineStorybookVis(options: StorybookVisOptions): {
66
63
  name: string;
67
64
  options: StorybookVisOptions;
68
65
  };
69
- //#endregion
70
- //#region src/node/define_storybook_vis_options.d.ts
71
66
  /**
72
67
  * Define options for Storybook Visual Testing addon.
73
68
  */
74
- declare function defineStorybookVisOptions(options: StorybookVisOptions): StorybookVisOptions;
75
- //#endregion
76
- export { defineStorybookVis, defineStorybookVisOptions };
69
+ export declare function defineStorybookVisOptions(options: StorybookVisOptions): StorybookVisOptions;
77
70
  //# sourceMappingURL=node.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.mts","names":[],"sources":["../../src/node/define_storybook_vis.ts","../../src/node/define_storybook_vis_options.ts"],"sourcesContent":[],"mappings":";;;;;;AAgCA;AAgCA;;;;AC3DA;;;;;;;;;;;;;;;;;;;;;iBD2BgB,kBAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgCA,kBAAA,UAA4B;;WAA+C;;;;;;AAhC3F;AAgCgB,iBC3DA,yBAAA,CD2D4B,OAA+C,EC3DxC,mBD2D2D,CAAA,EC3DxC,mBD2DwC"}
1
+ {"version":3,"file":"node.d.mts","names":[],"sources":["../../src/node/define_storybook_vis.ts","../../src/node/define_storybook_vis_options.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAgCgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAgCA,mBAAmB,SAAS;EAAwB;EAAc,SAAS;;;;;wBC3D3E,0BAA0B,SAAS,sBAAmB"}
@@ -1,7 +1,7 @@
1
1
  import { dirname } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
3
 
4
- //#region src/node/define_storybook_vis.ts
4
+ // src/node/define_storybook_vis.ts
5
5
  function defineStorybookVis(options) {
6
6
  const name = dirname(fileURLToPath(import.meta.resolve("storybook-addon-vis/package.json")));
7
7
  return !options ? name : {
@@ -10,8 +10,7 @@ function defineStorybookVis(options) {
10
10
  };
11
11
  }
12
12
 
13
- //#endregion
14
- //#region src/node/define_storybook_vis_options.ts
13
+ // src/node/define_storybook_vis_options.ts
15
14
  /**
16
15
  * Define options for Storybook Visual Testing addon.
17
16
  */
@@ -19,6 +18,5 @@ function defineStorybookVisOptions(options) {
19
18
  return options;
20
19
  }
21
20
 
22
- //#endregion
23
21
  export { defineStorybookVis, defineStorybookVisOptions };
24
22
  //# sourceMappingURL=node.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.mjs","names":[],"sources":["../../src/node/define_storybook_vis.ts","../../src/node/define_storybook_vis_options.ts"],"sourcesContent":["import { dirname } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { StorybookVisOptions } from '../server/types.ts'\n\n/**\n * Defines the Storybook Visual Testing addon configuration.\n *\n * When called without options, returns the package directory name as a string.\n * When called with options, returns an object containing both the package name and the provided options.\n *\n * @returns When called without options, returns the package directory path as a filesystem path string (e.g., `/path/to/storybook-addon-vis`).\n *\n * @example\n * ```ts\n * // Without options - returns just the package directory path\n * const addonName = defineStorybookVis()\n * // Returns: string (absolute filesystem path to package directory)\n * ```\n *\n * @example\n * ```ts\n * // With options - returns object with name and options\n * const addonConfig = defineStorybookVis({\n * visProjects: [\n * {\n * snapshotRootDir: '__vis__/linux',\n * },\n * ],\n * })\n * // Returns: { name: string, options: StorybookVisOptions }\n * ```\n */\nexport function defineStorybookVis(): string\n/**\n * Defines the Storybook Visual Testing addon configuration with options.\n *\n * @param options - Configuration options for visual testing suites in Storybook.\n * @param options.visProjects - Array of visual testing project configurations.\n * @param options.visProjects[].snapshotRootDir - Root directory for storing snapshots. Can be a string path or a function that returns a path based on CI and platform context.\n * @param options.visProjects[].snapshotSubpath - Optional function to customize the snapshot subdirectory path.\n *\n * @returns An object containing the package name and the provided options.\n *\n * @example\n * ```ts\n * // In .storybook/main.ts\n * import { defineStorybookVis } from 'storybook-addon-vis/node'\n *\n * export default {\n * addons: [\n * defineStorybookVis({\n * visProjects: [\n * {\n * snapshotRootDir: '__vis__/linux',\n * },\n * {\n * snapshotRootDir: '__vis__/local',\n * },\n * ],\n * }),\n * ],\n * }\n * ```\n */\nexport function defineStorybookVis(options: StorybookVisOptions): { name: string; options: StorybookVisOptions }\nexport function defineStorybookVis(options?: StorybookVisOptions | undefined) {\n\tconst name = dirname(fileURLToPath(import.meta.resolve('storybook-addon-vis/package.json')))\n\treturn !options ? name : { name, options }\n}\n","import type { StorybookVisOptions } from '../server/types.ts'\n\n/**\n * Define options for Storybook Visual Testing addon.\n */\nexport function defineStorybookVisOptions(options: StorybookVisOptions) {\n\treturn options\n}\n"],"mappings":";;;;AAiEA,SAAgB,mBAAmB,SAA2C;CAC7E,MAAM,OAAO,QAAQ,cAAc,OAAO,KAAK,QAAQ,mCAAmC,CAAC,CAAC;AAC5F,QAAO,CAAC,UAAU,OAAO;EAAE;EAAM;EAAS;;;;;;;;AC9D3C,SAAgB,0BAA0B,SAA8B;AACvE,QAAO"}
1
+ {"version":3,"file":"node.mjs","names":[],"sources":["../../src/node/define_storybook_vis.ts","../../src/node/define_storybook_vis_options.ts"],"sourcesContent":["import { dirname } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { StorybookVisOptions } from '../server/types.ts'\n\n/**\n * Defines the Storybook Visual Testing addon configuration.\n *\n * When called without options, returns the package directory name as a string.\n * When called with options, returns an object containing both the package name and the provided options.\n *\n * @returns When called without options, returns the package directory path as a filesystem path string (e.g., `/path/to/storybook-addon-vis`).\n *\n * @example\n * ```ts\n * // Without options - returns just the package directory path\n * const addonName = defineStorybookVis()\n * // Returns: string (absolute filesystem path to package directory)\n * ```\n *\n * @example\n * ```ts\n * // With options - returns object with name and options\n * const addonConfig = defineStorybookVis({\n * visProjects: [\n * {\n * snapshotRootDir: '__vis__/linux',\n * },\n * ],\n * })\n * // Returns: { name: string, options: StorybookVisOptions }\n * ```\n */\nexport function defineStorybookVis(): string\n/**\n * Defines the Storybook Visual Testing addon configuration with options.\n *\n * @param options - Configuration options for visual testing suites in Storybook.\n * @param options.visProjects - Array of visual testing project configurations.\n * @param options.visProjects[].snapshotRootDir - Root directory for storing snapshots. Can be a string path or a function that returns a path based on CI and platform context.\n * @param options.visProjects[].snapshotSubpath - Optional function to customize the snapshot subdirectory path.\n *\n * @returns An object containing the package name and the provided options.\n *\n * @example\n * ```ts\n * // In .storybook/main.ts\n * import { defineStorybookVis } from 'storybook-addon-vis/node'\n *\n * export default {\n * addons: [\n * defineStorybookVis({\n * visProjects: [\n * {\n * snapshotRootDir: '__vis__/linux',\n * },\n * {\n * snapshotRootDir: '__vis__/local',\n * },\n * ],\n * }),\n * ],\n * }\n * ```\n */\nexport function defineStorybookVis(options: StorybookVisOptions): { name: string; options: StorybookVisOptions }\nexport function defineStorybookVis(options?: StorybookVisOptions | undefined) {\n\tconst name = dirname(fileURLToPath(import.meta.resolve('storybook-addon-vis/package.json')))\n\treturn !options ? name : { name, options }\n}\n","import type { StorybookVisOptions } from '../server/types.ts'\n\n/**\n * Define options for Storybook Visual Testing addon.\n */\nexport function defineStorybookVisOptions(options: StorybookVisOptions) {\n\treturn options\n}\n"],"mappings":";;;;AAiEA,SAAgB,mBAAmB,SAA2C;CAC7E,MAAM,OAAO,QAAQ,cAAc,YAAY,QAAQ,kCAAkC,CAAC,CAAC;CAC3F,OAAO,CAAC,UAAU,OAAO;EAAE;EAAM;CAAQ;AAC1C;;;;;;AC/DA,SAAgB,0BAA0B,SAA8B;CACvE,OAAO;AACR"}
@@ -1,8 +1,4 @@
1
- import { t as StorybookVisOptions } from "./types-CuNXsk6J.mjs";
1
+ import { t as StorybookVisOptions } from "./types-DGIY4hWl.mjs";
2
2
  import { Channel } from "storybook/internal/channels";
3
-
4
- //#region src/exports/preset.d.ts
5
- declare const experimental_serverChannel: (channel: Channel, options: StorybookVisOptions) => Promise<Channel>;
6
- //#endregion
7
- export { experimental_serverChannel };
3
+ export declare const experimental_serverChannel: (channel: Channel, options: StorybookVisOptions) => Promise<Channel>;
8
4
  //# sourceMappingURL=preset.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"preset.d.mts","names":[],"sources":["../../src/exports/preset.ts"],"sourcesContent":[],"mappings":";;;;cAMa,sCAA6C,kBAAkB,wBAAmB,QAAA"}
1
+ {"version":3,"file":"preset.d.mts","names":[],"sources":["../../src/exports/preset.ts"],"mappings":";;qBAMa,6BAAoC,SAAS,SAAS,SAAS,wBAAmB,QAAA"}
@@ -1,4 +1,4 @@
1
- import { t as NAME } from "./constants-D_WcloLE.mjs";
1
+ import { t as NAME } from "./constants-Dyl3Z-K5.mjs";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { platform } from "node:process";
4
4
  import { globSync } from "glob";
@@ -7,7 +7,7 @@ import memoize from "memoize";
7
7
  import { basename, resolve } from "pathe";
8
8
  import { BASELINE_DIR, DIFF_DIR, RESULT_DIR, REVIEW_IMAGE_SUFFIX, SNAPSHOT_ROOT_DIR, getSnapshotRootDir, resolveSnapshotSubpathWithinLimits, trimCommonFolder } from "vitest-plugin-vis/server-utils";
9
9
 
10
- //#region src/server/create_storybook_vis_server.ts
10
+ // src/server/create_storybook_vis_server.ts
11
11
  function createStorybookVisServer(options) {
12
12
  const visSuites = options.visProjects ?? [{}];
13
13
  return {
@@ -19,10 +19,11 @@ function createStorybookVisServer(options) {
19
19
  platform
20
20
  }) : memoize(getSnapshotRootDir)(SNAPSHOT_ROOT_DIR);
21
21
  const snapshotSubpathRaw = (typeof suite.snapshotSubpath === "function" ? memoize(suite.snapshotSubpath) : memoize(({ subpath }) => trimCommonFolder(subpath.startsWith("./") ? subpath.slice(2) : subpath)))({ subpath: importPath });
22
+ const snapshotBaselineRootAbs = resolve(snapshotRootDir, BASELINE_DIR);
22
23
  return {
23
24
  snapshotRootDir,
24
25
  snapshotSubpath: resolveSnapshotSubpathWithinLimits({
25
- snapshotBaselineRootAbs: resolve(snapshotRootDir, BASELINE_DIR),
26
+ snapshotBaselineRootAbs,
26
27
  rawSnapshotSubpath: snapshotSubpathRaw,
27
28
  shortenLongSnapshotPaths: suite.shortenLongSnapshotPaths === true
28
29
  })
@@ -33,7 +34,7 @@ function createStorybookVisServer(options) {
33
34
  const baselineGlob = resolve(snapshotRootDir, BASELINE_DIR, snapshotSubpath, taskGlob);
34
35
  const resultGlob = resolve(snapshotRootDir, RESULT_DIR, snapshotSubpath, taskGlob);
35
36
  const diffGlob = resolve(snapshotRootDir, DIFF_DIR, snapshotSubpath, taskGlob);
36
- const taskIdRegex = /* @__PURE__ */ new RegExp(`${taskId}-[^-]*.png$`);
37
+ const taskIdRegex = new RegExp(`${taskId}-[^-]*.png$`);
37
38
  const isSnapshotFile = (filePath) => taskIdRegex.test(filePath) && !filePath.endsWith(REVIEW_IMAGE_SUFFIX);
38
39
  const baselineFiles = globSync(baselineGlob).filter(isSnapshotFile);
39
40
  const resultFiles = globSync(resultGlob).filter(isSnapshotFile);
@@ -57,17 +58,15 @@ function mapFileToResult(filePath, snapshotRootDir, type) {
57
58
  };
58
59
  }
59
60
 
60
- //#endregion
61
- //#region src/shared/events.ts
61
+ // src/shared/events.ts
62
62
  const IMAGE_SNAPSHOT_RESULTS_REQUEST = "IMAGE_SNAPSHOT_RESULTS_REQUEST";
63
63
  const IMAGE_SNAPSHOT_RESULTS_RESPONSE = "IMAGE_SNAPSHOT_RESULTS_RESPONSE";
64
64
 
65
- //#endregion
66
- //#region src/exports/preset.ts
65
+ // src/exports/preset.ts
67
66
  const experimental_serverChannel = async (channel, options) => {
68
67
  const server = createStorybookVisServer(options);
69
68
  channel.on(NAME, async (event) => {
70
- if (event.type === IMAGE_SNAPSHOT_RESULTS_REQUEST) {
69
+ if (event.type === "IMAGE_SNAPSHOT_RESULTS_REQUEST") {
71
70
  const results = await server.getImageSnapshotResults(event.name, event.importPath);
72
71
  channel.emit(NAME, {
73
72
  type: IMAGE_SNAPSHOT_RESULTS_RESPONSE,
@@ -80,6 +79,5 @@ const experimental_serverChannel = async (channel, options) => {
80
79
  return channel;
81
80
  };
82
81
 
83
- //#endregion
84
82
  export { experimental_serverChannel };
85
83
  //# sourceMappingURL=preset.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"preset.mjs","names":[],"sources":["../../src/server/create_storybook_vis_server.ts","../../src/shared/events.ts","../../src/exports/preset.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\nimport { platform } from 'node:process'\nimport { globSync } from 'glob'\nimport ci from 'is-ci'\nimport memoize from 'memoize'\nimport { basename, resolve } from 'pathe'\nimport {\n\tBASELINE_DIR,\n\tDIFF_DIR,\n\tgetSnapshotRootDir,\n\tRESULT_DIR,\n\tREVIEW_IMAGE_SUFFIX,\n\tresolveSnapshotSubpathWithinLimits,\n\tSNAPSHOT_ROOT_DIR,\n\ttrimCommonFolder,\n} from 'vitest-plugin-vis/server-utils'\nimport type { ImageSnapshotResults } from '../shared/events.ts'\nimport type { StorybookVisOptions } from './types.ts'\n\nexport function createStorybookVisServer(options: StorybookVisOptions) {\n\tconst visSuites = options.visProjects ?? [{}]\n\treturn {\n\t\toptions,\n\t\tasync getImageSnapshotResults(name: string, importPath: string) {\n\t\t\treturn visSuites\n\t\t\t\t.map((suite) => {\n\t\t\t\t\tconst snapshotRootDir =\n\t\t\t\t\t\ttypeof suite.snapshotRootDir === 'string'\n\t\t\t\t\t\t\t? suite.snapshotRootDir\n\t\t\t\t\t\t\t: typeof suite.snapshotRootDir === 'function'\n\t\t\t\t\t\t\t\t? memoize(suite.snapshotRootDir)({\n\t\t\t\t\t\t\t\t\t\tci,\n\t\t\t\t\t\t\t\t\t\tplatform,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t: memoize(getSnapshotRootDir)(SNAPSHOT_ROOT_DIR)\n\n\t\t\t\t\tconst snapshotSubpathFn =\n\t\t\t\t\t\ttypeof suite.snapshotSubpath === 'function'\n\t\t\t\t\t\t\t? memoize(suite.snapshotSubpath)\n\t\t\t\t\t\t\t: memoize(({ subpath }: { subpath: string }) =>\n\t\t\t\t\t\t\t\t\ttrimCommonFolder(subpath.startsWith('./') ? subpath.slice(2) : subpath),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\tconst snapshotSubpathRaw = snapshotSubpathFn({ subpath: importPath })\n\t\t\t\t\tconst snapshotBaselineRootAbs = resolve(snapshotRootDir, BASELINE_DIR)\n\t\t\t\t\tconst snapshotSubpath = resolveSnapshotSubpathWithinLimits({\n\t\t\t\t\t\tsnapshotBaselineRootAbs,\n\t\t\t\t\t\trawSnapshotSubpath: snapshotSubpathRaw,\n\t\t\t\t\t\tshortenLongSnapshotPaths: suite.shortenLongSnapshotPaths === true,\n\t\t\t\t\t})\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsnapshotRootDir,\n\t\t\t\t\t\tsnapshotSubpath,\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.flatMap(({ snapshotRootDir, snapshotSubpath }) => {\n\t\t\t\t\tconst taskId = name.replace(/[^a-z0-9]/gi, '-').toLowerCase()\n\t\t\t\t\tconst taskGlob = `${taskId}-*.png`\n\t\t\t\t\tconst baselineGlob = resolve(snapshotRootDir, BASELINE_DIR, snapshotSubpath, taskGlob)\n\t\t\t\t\tconst resultGlob = resolve(snapshotRootDir, RESULT_DIR, snapshotSubpath, taskGlob)\n\t\t\t\t\tconst diffGlob = resolve(snapshotRootDir, DIFF_DIR, snapshotSubpath, taskGlob)\n\n\t\t\t\t\tconst taskIdRegex = new RegExp(`${taskId}-[^-]*.png$`)\n\t\t\t\t\tconst isSnapshotFile = (filePath: string) =>\n\t\t\t\t\t\ttaskIdRegex.test(filePath) && !filePath.endsWith(REVIEW_IMAGE_SUFFIX)\n\t\t\t\t\tconst baselineFiles = globSync(baselineGlob).filter(isSnapshotFile)\n\t\t\t\t\tconst resultFiles = globSync(resultGlob).filter(isSnapshotFile)\n\t\t\t\t\tconst diffFiles = globSync(diffGlob).filter(isSnapshotFile)\n\t\t\t\t\treturn [\n\t\t\t\t\t\t...baselineFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'baseline')),\n\t\t\t\t\t\t...resultFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'result')),\n\t\t\t\t\t\t...diffFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'diff')),\n\t\t\t\t\t]\n\t\t\t\t})\n\t\t},\n\t}\n}\n\nfunction mapFileToResult(\n\tfilePath: string,\n\tsnapshotRootDir: string,\n\ttype: ImageSnapshotResults['type'],\n): ImageSnapshotResults {\n\treturn {\n\t\tfilePath,\n\t\tfileName: basename(filePath),\n\t\tsnapshotRootDir,\n\t\ttype,\n\t\tbase64: readFileSync(filePath, 'base64'),\n\t}\n}\n","export type VisEvent = ImageSnapshotResultsRequest | ImageSnapshotResultsResponse\n\nexport const IMAGE_SNAPSHOT_RESULTS_REQUEST = 'IMAGE_SNAPSHOT_RESULTS_REQUEST'\nexport const IMAGE_SNAPSHOT_RESULTS_RESPONSE = 'IMAGE_SNAPSHOT_RESULTS_RESPONSE'\n\nexport function requestImageSnapshotResults({ name, importPath }: { name: string; importPath: string }) {\n\treturn {\n\t\ttype: IMAGE_SNAPSHOT_RESULTS_REQUEST,\n\t\tname,\n\t\timportPath,\n\t}\n}\n\nexport type ImageSnapshotResultsRequest = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_REQUEST\n\tname: string\n\timportPath: string\n}\n\nexport type ImageSnapshotResultsResponse = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_RESPONSE\n\tname: string\n\timportPath: string\n\tresults: ImageSnapshotResults[]\n}\n\nexport type ImageSnapshotResults = {\n\tfilePath: string\n\tfileName: string\n\tsnapshotRootDir: string\n\ttype: 'baseline' | 'diff' | 'result'\n\tbase64: string\n}\n","import type { Channel } from 'storybook/internal/channels'\nimport { createStorybookVisServer } from '../server/create_storybook_vis_server.ts'\nimport type { StorybookVisOptions } from '../server/types.ts'\nimport { NAME } from '../shared/constants.ts'\nimport { IMAGE_SNAPSHOT_RESULTS_REQUEST, IMAGE_SNAPSHOT_RESULTS_RESPONSE, type VisEvent } from '../shared/events.ts'\n\nexport const experimental_serverChannel = async (channel: Channel, options: StorybookVisOptions) => {\n\tconst server = createStorybookVisServer(options)\n\n\tchannel.on(NAME, async (event: VisEvent) => {\n\t\tif (event.type === IMAGE_SNAPSHOT_RESULTS_REQUEST) {\n\t\t\tconst results = await server.getImageSnapshotResults(event.name, event.importPath)\n\t\t\tchannel.emit(NAME, {\n\t\t\t\ttype: IMAGE_SNAPSHOT_RESULTS_RESPONSE,\n\t\t\t\tname: event.name,\n\t\t\t\timportPath: event.importPath,\n\t\t\t\tresults,\n\t\t\t})\n\t\t}\n\t})\n\n\treturn channel\n}\n"],"mappings":";;;;;;;;;;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D,WAAO;KACN,GAAG,cAAc,KAAK,aAAa,gBAAgB,UAAU,iBAAiB,WAAW,CAAC;KAC1F,GAAG,YAAY,KAAK,aAAa,gBAAgB,UAAU,iBAAiB,SAAS,CAAC;KACtF,GAAG,UAAU,KAAK,aAAa,gBAAgB,UAAU,iBAAiB,OAAO,CAAC;KAClF;KACA;;EAEJ;;AAGF,SAAS,gBACR,UACA,iBACA,MACuB;AACvB,QAAO;EACN;EACA,UAAU,SAAS,SAAS;EAC5B;EACA;EACA,QAAQ,aAAa,UAAU,SAAS;EACxC;;;;;ACtFF,MAAa,iCAAiC;AAC9C,MAAa,kCAAkC;;;;ACG/C,MAAa,6BAA6B,OAAO,SAAkB,YAAiC;CACnG,MAAM,SAAS,yBAAyB,QAAQ;AAEhD,SAAQ,GAAG,MAAM,OAAO,UAAoB;AAC3C,MAAI,MAAM,SAAS,gCAAgC;GAClD,MAAM,UAAU,MAAM,OAAO,wBAAwB,MAAM,MAAM,MAAM,WAAW;AAClF,WAAQ,KAAK,MAAM;IAClB,MAAM;IACN,MAAM,MAAM;IACZ,YAAY,MAAM;IAClB;IACA,CAAC;;GAEF;AAEF,QAAO"}
1
+ {"version":3,"file":"preset.mjs","names":[],"sources":["../../src/server/create_storybook_vis_server.ts","../../src/shared/events.ts","../../src/exports/preset.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\nimport { platform } from 'node:process'\nimport { globSync } from 'glob'\nimport ci from 'is-ci'\nimport memoize from 'memoize'\nimport { basename, resolve } from 'pathe'\nimport {\n\tBASELINE_DIR,\n\tDIFF_DIR,\n\tgetSnapshotRootDir,\n\tRESULT_DIR,\n\tREVIEW_IMAGE_SUFFIX,\n\tresolveSnapshotSubpathWithinLimits,\n\tSNAPSHOT_ROOT_DIR,\n\ttrimCommonFolder,\n} from 'vitest-plugin-vis/server-utils'\nimport type { ImageSnapshotResults } from '../shared/events.ts'\nimport type { StorybookVisOptions } from './types.ts'\n\nexport function createStorybookVisServer(options: StorybookVisOptions) {\n\tconst visSuites = options.visProjects ?? [{}]\n\treturn {\n\t\toptions,\n\t\tasync getImageSnapshotResults(name: string, importPath: string) {\n\t\t\treturn visSuites\n\t\t\t\t.map((suite) => {\n\t\t\t\t\tconst snapshotRootDir =\n\t\t\t\t\t\ttypeof suite.snapshotRootDir === 'string'\n\t\t\t\t\t\t\t? suite.snapshotRootDir\n\t\t\t\t\t\t\t: typeof suite.snapshotRootDir === 'function'\n\t\t\t\t\t\t\t\t? memoize(suite.snapshotRootDir)({\n\t\t\t\t\t\t\t\t\t\tci,\n\t\t\t\t\t\t\t\t\t\tplatform,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t: memoize(getSnapshotRootDir)(SNAPSHOT_ROOT_DIR)\n\n\t\t\t\t\tconst snapshotSubpathFn =\n\t\t\t\t\t\ttypeof suite.snapshotSubpath === 'function'\n\t\t\t\t\t\t\t? memoize(suite.snapshotSubpath)\n\t\t\t\t\t\t\t: memoize(({ subpath }: { subpath: string }) =>\n\t\t\t\t\t\t\t\t\ttrimCommonFolder(subpath.startsWith('./') ? subpath.slice(2) : subpath),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\tconst snapshotSubpathRaw = snapshotSubpathFn({ subpath: importPath })\n\t\t\t\t\tconst snapshotBaselineRootAbs = resolve(snapshotRootDir, BASELINE_DIR)\n\t\t\t\t\tconst snapshotSubpath = resolveSnapshotSubpathWithinLimits({\n\t\t\t\t\t\tsnapshotBaselineRootAbs,\n\t\t\t\t\t\trawSnapshotSubpath: snapshotSubpathRaw,\n\t\t\t\t\t\tshortenLongSnapshotPaths: suite.shortenLongSnapshotPaths === true,\n\t\t\t\t\t})\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsnapshotRootDir,\n\t\t\t\t\t\tsnapshotSubpath,\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.flatMap(({ snapshotRootDir, snapshotSubpath }) => {\n\t\t\t\t\tconst taskId = name.replace(/[^a-z0-9]/gi, '-').toLowerCase()\n\t\t\t\t\tconst taskGlob = `${taskId}-*.png`\n\t\t\t\t\tconst baselineGlob = resolve(snapshotRootDir, BASELINE_DIR, snapshotSubpath, taskGlob)\n\t\t\t\t\tconst resultGlob = resolve(snapshotRootDir, RESULT_DIR, snapshotSubpath, taskGlob)\n\t\t\t\t\tconst diffGlob = resolve(snapshotRootDir, DIFF_DIR, snapshotSubpath, taskGlob)\n\n\t\t\t\t\tconst taskIdRegex = new RegExp(`${taskId}-[^-]*.png$`)\n\t\t\t\t\tconst isSnapshotFile = (filePath: string) =>\n\t\t\t\t\t\ttaskIdRegex.test(filePath) && !filePath.endsWith(REVIEW_IMAGE_SUFFIX)\n\t\t\t\t\tconst baselineFiles = globSync(baselineGlob).filter(isSnapshotFile)\n\t\t\t\t\tconst resultFiles = globSync(resultGlob).filter(isSnapshotFile)\n\t\t\t\t\tconst diffFiles = globSync(diffGlob).filter(isSnapshotFile)\n\t\t\t\t\treturn [\n\t\t\t\t\t\t...baselineFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'baseline')),\n\t\t\t\t\t\t...resultFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'result')),\n\t\t\t\t\t\t...diffFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'diff')),\n\t\t\t\t\t]\n\t\t\t\t})\n\t\t},\n\t}\n}\n\nfunction mapFileToResult(\n\tfilePath: string,\n\tsnapshotRootDir: string,\n\ttype: ImageSnapshotResults['type'],\n): ImageSnapshotResults {\n\treturn {\n\t\tfilePath,\n\t\tfileName: basename(filePath),\n\t\tsnapshotRootDir,\n\t\ttype,\n\t\tbase64: readFileSync(filePath, 'base64'),\n\t}\n}\n","export type VisEvent = ImageSnapshotResultsRequest | ImageSnapshotResultsResponse\n\nexport const IMAGE_SNAPSHOT_RESULTS_REQUEST = 'IMAGE_SNAPSHOT_RESULTS_REQUEST'\nexport const IMAGE_SNAPSHOT_RESULTS_RESPONSE = 'IMAGE_SNAPSHOT_RESULTS_RESPONSE'\n\nexport function requestImageSnapshotResults({ name, importPath }: { name: string; importPath: string }) {\n\treturn {\n\t\ttype: IMAGE_SNAPSHOT_RESULTS_REQUEST,\n\t\tname,\n\t\timportPath,\n\t}\n}\n\nexport type ImageSnapshotResultsRequest = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_REQUEST\n\tname: string\n\timportPath: string\n}\n\nexport type ImageSnapshotResultsResponse = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_RESPONSE\n\tname: string\n\timportPath: string\n\tresults: ImageSnapshotResults[]\n}\n\nexport type ImageSnapshotResults = {\n\tfilePath: string\n\tfileName: string\n\tsnapshotRootDir: string\n\ttype: 'baseline' | 'diff' | 'result'\n\tbase64: string\n}\n","import type { Channel } from 'storybook/internal/channels'\nimport { createStorybookVisServer } from '../server/create_storybook_vis_server.ts'\nimport type { StorybookVisOptions } from '../server/types.ts'\nimport { NAME } from '../shared/constants.ts'\nimport { IMAGE_SNAPSHOT_RESULTS_REQUEST, IMAGE_SNAPSHOT_RESULTS_RESPONSE, type VisEvent } from '../shared/events.ts'\n\nexport const experimental_serverChannel = async (channel: Channel, options: StorybookVisOptions) => {\n\tconst server = createStorybookVisServer(options)\n\n\tchannel.on(NAME, async (event: VisEvent) => {\n\t\tif (event.type === IMAGE_SNAPSHOT_RESULTS_REQUEST) {\n\t\t\tconst results = await server.getImageSnapshotResults(event.name, event.importPath)\n\t\t\tchannel.emit(NAME, {\n\t\t\t\ttype: IMAGE_SNAPSHOT_RESULTS_RESPONSE,\n\t\t\t\tname: event.name,\n\t\t\t\timportPath: event.importPath,\n\t\t\t\tresults,\n\t\t\t})\n\t\t}\n\t})\n\n\treturn channel\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAgB,yBAAyB,SAA8B;CACtE,MAAM,YAAY,QAAQ,eAAe,CAAC,CAAC,CAAC;CAC5C,OAAO;EACN;EACA,MAAM,wBAAwB,MAAc,YAAoB;GAC/D,OAAO,UACL,KAAK,UAAU;I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Aa,gBAAgB,UAAU,iBAAiB,QAAQ,CAAC;KACrF,GAAG,UAAU,KAAK,aAAa,gBAAgB,UAAU,iBAAiB,MAAM,CAAC;IAClF;GACD,CAAC;EACH;CACD;AACD;AAEA,SAAS,gBACR,UACA,iBACA,MACuB;CACvB,OAAO;EACN;EACA,UAAU,SAAS,QAAQ;EAC3B;EACA;EACA,QAAQ,aAAa,UAAU,QAAQ;CACxC;AACD;;;ACvFA,MAAa,iCAAiC;AAC9C,MAAa,kCAAkC;;;ACG/C,MAAa,6BAA6B,OAAO,SAAkB,YAAiC;CACnG,MAAM,SAAS,yBAAyB,OAAO;CAE/C,QAAQ,GAAG,MAAM,OAAO,UAAoB;EAC3C,IAAI,MAAM,2CAAyC;GAClD,MAAM,UAAU,MAAM,OAAO,wBAAwB,MAAM,MAAM,MAAM,UAAU;GACjF,QAAQ,KAAK,MAAM;IAClB,MAAM;IACN,MAAM,MAAM;IACZ,YAAY,MAAM;IAClB;GACD,CAAC;EACF;CACD,CAAC;CAED,OAAO;AACR"}
@@ -1,4 +1,3 @@
1
- //#region src/server/types.d.ts
2
1
  /**
3
2
  * Configuration options for visual testing suites in Storybook.
4
3
  *
@@ -24,6 +23,5 @@ type StorybookVisOptions = {
24
23
  shortenLongSnapshotPaths?: boolean | undefined;
25
24
  }>;
26
25
  };
27
- //#endregion
28
26
  export { StorybookVisOptions as t };
29
- //# sourceMappingURL=types-CuNXsk6J.d.mts.map
27
+ //# sourceMappingURL=types-DGIY4hWl.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DGIY4hWl.d.mts","names":[],"sources":["../../src/server/types.ts"],"mappings":";;;;;;;KAOY;EACX,aAAa;IACZ,4BAA4B;MAAW;MAAa;;IACpD,oBAAoB;MAAW;;;;;;;;IAO/B"}
@@ -1,9 +1,5 @@
1
1
  import { ComparisonMethod, VisOptions, trimCommonFolder } from "vitest-plugin-vis/config";
2
2
  import { ObjectPlus } from "type-plus";
3
-
4
- //#region src/vitest-plugin/storybook_vis.d.ts
5
-
6
- declare function storybookVis<M extends ComparisonMethod>(options?: ObjectPlus.Omit<VisOptions<M>, 'preset'> | undefined): any;
7
- //#endregion
8
- export { storybookVis, trimCommonFolder };
3
+ export declare function storybookVis<M extends ComparisonMethod>(options?: ObjectPlus.Omit<VisOptions<M>, 'preset'> | undefined): any;
4
+ export { trimCommonFolder };
9
5
  //# sourceMappingURL=vitest-plugin.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vitest-plugin.d.mts","names":[],"sources":["../../src/vitest-plugin/storybook_vis.ts"],"sourcesContent":[],"mappings":";;;;;AAOuC,iBAAvB,YAAuB,CAAA,UAAA,gBAAA,CAAA,CAAA,OAAA,CAAA,EAC5B,UAAA,CAAW,IADiB,CACZ,UADY,CACD,CADC,CAAA,EAAA,QAAA,CAAA,GAAA,SAAA,CAAA,EAAA,GAAA"}
1
+ {"version":3,"file":"vitest-plugin.d.mts","names":[],"sources":["../../src/vitest-plugin/storybook_vis.ts"],"mappings":";;wBAOgB,aAAa,UAAU,kBACtC,UAAU,WAAW,KAAK,WAAW"}
@@ -1,7 +1,7 @@
1
- import { t as NAME } from "./constants-D_WcloLE.mjs";
1
+ import { t as NAME } from "./constants-Dyl3Z-K5.mjs";
2
2
  import { trimCommonFolder, vis } from "vitest-plugin-vis/config";
3
3
 
4
- //#region src/vitest-plugin/storybook_vis.ts
4
+ // src/vitest-plugin/storybook_vis.ts
5
5
  function storybookVis(options) {
6
6
  return {
7
7
  ...vis({
@@ -12,6 +12,5 @@ function storybookVis(options) {
12
12
  };
13
13
  }
14
14
 
15
- //#endregion
16
15
  export { storybookVis, trimCommonFolder };
17
16
  //# sourceMappingURL=vitest-plugin.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"vitest-plugin.mjs","names":[],"sources":["../../src/vitest-plugin/storybook_vis.ts"],"sourcesContent":["/**\n * Return type is `any` to support different Vitest and Vite versions.\n */\nimport type { ObjectPlus } from 'type-plus'\nimport { type ComparisonMethod, type VisOptions, vis } from 'vitest-plugin-vis/config'\nimport { NAME } from '../shared/constants.ts'\n\nexport function storybookVis<M extends ComparisonMethod>(\n\toptions?: ObjectPlus.Omit<VisOptions<M>, 'preset'> | undefined,\n): any {\n\treturn {\n\t\t...vis({\n\t\t\t...options,\n\t\t\tpreset: 'custom',\n\t\t}),\n\t\tname: NAME,\n\t}\n}\n"],"mappings":";;;;AAOA,SAAgB,aACf,SACM;AACN,QAAO;EACN,GAAG,IAAI;GACN,GAAG;GACH,QAAQ;GACR,CAAC;EACF,MAAM;EACN"}
1
+ {"version":3,"file":"vitest-plugin.mjs","names":[],"sources":["../../src/vitest-plugin/storybook_vis.ts"],"sourcesContent":["/**\n * Return type is `any` to support different Vitest and Vite versions.\n */\nimport type { ObjectPlus } from 'type-plus'\nimport { type ComparisonMethod, type VisOptions, vis } from 'vitest-plugin-vis/config'\nimport { NAME } from '../shared/constants.ts'\n\nexport function storybookVis<M extends ComparisonMethod>(\n\toptions?: ObjectPlus.Omit<VisOptions<M>, 'preset'> | undefined,\n): any {\n\treturn {\n\t\t...vis({\n\t\t\t...options,\n\t\t\tpreset: 'custom',\n\t\t}),\n\t\tname: NAME,\n\t}\n}\n"],"mappings":";;;;AAOA,SAAgB,aACf,SACM;CACN,OAAO;EACN,GAAG,IAAI;GACN,GAAG;GACH,QAAQ;EACT,CAAC;EACD,MAAM;CACP;AACD"}
@@ -1,12 +1,8 @@
1
- import "../global_matcher_augment-B1plNA_9.mjs";
2
- import { t as visAnnotations } from "../vis_annotation-N0xbuXis.mjs";
1
+ import "../global_matcher_augment-CGDzrdCj.mjs";
2
+ import { t as visAnnotations } from "../vis_annotation-DJqDOBIl.mjs";
3
3
  import { setAutoSnapshotOptions } from "vitest-plugin-vis";
4
- import * as vitest_plugin_vis_setup_api0 from "vitest-plugin-vis/setup-api";
5
-
6
- //#region src/exports/vitest-setup.d.ts
7
- declare const vis: vitest_plugin_vis_setup_api0.VisClientConfigurator<{
4
+ export declare const vis: import("vitest-plugin-vis/setup-api").VisClientConfigurator<{
8
5
  tags: string[];
9
6
  }>;
10
- //#endregion
11
- export { setAutoSnapshotOptions, vis, visAnnotations };
7
+ export { setAutoSnapshotOptions, visAnnotations };
12
8
  //# sourceMappingURL=vitest-setup.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vitest-setup.d.mts","names":[],"sources":["../../src/exports/vitest-setup.ts"],"sourcesContent":[],"mappings":";;;;;;cAMa,KAA6C,4BAAA,CAA1C"}
1
+ {"version":3,"file":"vitest-setup.d.mts","names":[],"sources":["../../src/exports/vitest-setup.ts"],"mappings":";;;qBAMa,2CAAG;EAAqB"}
@@ -1,10 +1,9 @@
1
- import { a as commands, t as visAnnotations } from "../vis_annotation-BHBO0X19.mjs";
1
+ import { a as commands, t as visAnnotations } from "../vis_annotation-CJD3p9Uh.mjs";
2
2
  import { setAutoSnapshotOptions } from "vitest-plugin-vis";
3
3
  import { createVis } from "vitest-plugin-vis/setup-api";
4
4
 
5
- //#region src/exports/vitest-setup.ts
5
+ // src/exports/vitest-setup.ts
6
6
  const vis = createVis(commands);
7
7
 
8
- //#endregion
9
8
  export { setAutoSnapshotOptions, vis, visAnnotations };
10
9
  //# sourceMappingURL=vitest-setup.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"vitest-setup.mjs","names":[],"sources":["../../src/exports/vitest-setup.ts"],"sourcesContent":["// `storybook-addon-vis/vitest-setup` provides code needed in `vitest.setup.ts`.\nimport '../shared/global_matcher_augment.ts'\n\nimport { createVis } from 'vitest-plugin-vis/setup-api'\nimport { commands } from '../client/vitest_proxy.ts'\n\nexport const vis = createVis<{ tags: string[] }>(commands)\nexport { setAutoSnapshotOptions } from 'vitest-plugin-vis'\nexport { visAnnotations } from '../preview/vis_annotation.ts'\n"],"mappings":";;;;;AAMA,MAAa,MAAM,UAA8B,SAAS"}
1
+ {"version":3,"file":"vitest-setup.mjs","names":[],"sources":["../../src/exports/vitest-setup.ts"],"sourcesContent":["// `storybook-addon-vis/vitest-setup` provides code needed in `vitest.setup.ts`.\nimport '../shared/global_matcher_augment.ts'\n\nimport { createVis } from 'vitest-plugin-vis/setup-api'\nimport { commands } from '../client/vitest_proxy.ts'\n\nexport const vis = createVis<{ tags: string[] }>(commands)\nexport { setAutoSnapshotOptions } from 'vitest-plugin-vis'\nexport { visAnnotations } from '../preview/vis_annotation.ts'\n"],"mappings":";;;;;AAMA,MAAa,MAAM,UAA8B,QAAQ"}
@@ -1,10 +1,7 @@
1
1
  import { ImageSnapshotMatcher } from "vitest-plugin-vis/client-api";
2
-
3
- //#region src/shared/global_matcher_augment.d.ts
4
2
  declare global {
5
3
  namespace jest {
6
4
  interface Matchers<R, T> extends ImageSnapshotMatcher {}
7
5
  }
8
6
  }
9
- //# sourceMappingURL=global_matcher_augment.d.ts.map
10
- //# sourceMappingURL=global_matcher_augment-B1plNA_9.d.mts.map
7
+ //# sourceMappingURL=global_matcher_augment-CGDzrdCj.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global_matcher_augment-CGDzrdCj.d.mts","names":[],"sources":["../src/shared/global_matcher_augment.ts"],"mappings":";QAIQ;YACG;cACC,SAAS,GAAG,WAAW"}
package/dist/index.d.mts CHANGED
@@ -1,44 +1,30 @@
1
- import "./global_matcher_augment-B1plNA_9.mjs";
2
- import { t as visAnnotations } from "./vis_annotation-N0xbuXis.mjs";
3
- import * as storybook_internal_csf0 from "storybook/internal/csf";
1
+ import "./global_matcher_augment-CGDzrdCj.mjs";
2
+ import { t as visAnnotations } from "./vis_annotation-DJqDOBIl.mjs";
4
3
  import { ComparisonMethod, FailureThresholdOptions, ImageSnapshotCompareOptions, ImageSnapshotKeyOptions, ImageSnapshotKeyOptions as ImageSnapshotKeyOptions$1, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, PageImageSnapshotOptions, PixelComparisonOptions, SsimComparisonOptions, ToMatchImageSnapshotOptions } from "vitest-plugin-vis/client-api";
5
- import * as vitest_plugin_vis0 from "vitest-plugin-vis";
6
4
  import { SetupVisOptions } from "vitest-plugin-vis";
7
- import "vitest";
8
- import { BrowserPage, CDPSession } from "vitest/browser";
5
+ import { BrowserCommands, BrowserPage, CDPSession } from "vitest/browser";
9
6
  export * from "vitest-plugin-vis";
10
-
11
- //#region src/client/vitest_proxy.d.ts
12
-
13
- declare const page: BrowserPage;
14
- declare const cdp: () => CDPSession;
15
- //#endregion
16
- //#region src/client/has_image_snapshot.d.ts
7
+ export declare const page: BrowserPage;
8
+ export declare const commands: BrowserCommands;
9
+ export declare const cdp: () => CDPSession;
17
10
  /**
18
11
  * Check if the snapshot image exists.
19
12
  */
20
- declare function hasImageSnapshot(options?: ImageSnapshotKeyOptions$1 | undefined): false | Promise<boolean>;
21
- //#endregion
22
- //#region src/client/storybook/param.d.ts
13
+ export declare function hasImageSnapshot(options?: ImageSnapshotKeyOptions$1 | undefined): false | Promise<boolean>;
23
14
  /**
24
15
  * Define snapshot parameter for auto snapshot.
25
16
  *
26
17
  * Set `fullPage: true` to snapshot the whole page instead of the subject.
27
18
  */
28
- declare function defineAutoSnapshotParam<M extends ComparisonMethod>(snapshot: ToMatchImageSnapshotOptions<M> & ImageSnapshotSubjectOptions & PageImageSnapshotOptions): {
29
- snapshot: ImageSnapshotTimeoutOptions & ImageSnapshotKeyOptions & (M extends "ssim" ? SsimComparisonOptions<M> : PixelComparisonOptions<M>) & FailureThresholdOptions & vitest_plugin_vis0.ReviewImageOptions & vitest_plugin_vis0.AnimationsOptions & vitest_plugin_vis0.MaskOptions & {
19
+ export declare function defineAutoSnapshotParam<M extends ComparisonMethod>(snapshot: ToMatchImageSnapshotOptions<M> & ImageSnapshotSubjectOptions & PageImageSnapshotOptions): {
20
+ snapshot: ImageSnapshotTimeoutOptions & ImageSnapshotKeyOptions & (M extends "ssim" ? SsimComparisonOptions<M> : PixelComparisonOptions<M>) & FailureThresholdOptions & import("vitest-plugin-vis").ReviewImageOptions & import("vitest-plugin-vis").AnimationsOptions & import("vitest-plugin-vis").MaskOptions & {
30
21
  expectToFail?: boolean | undefined;
31
22
  createMissingBaseline?: boolean | undefined;
32
23
  } & ImageSnapshotSubjectOptions & PageImageSnapshotOptions;
33
24
  };
34
- //#endregion
35
- //#region src/client/storybook/tags.d.ts
36
- declare function isSnapshotEnabled(tags: string[]): boolean;
37
- //#endregion
38
- //#region src/index.d.ts
25
+ export declare function isSnapshotEnabled(tags: string[]): boolean;
39
26
  declare const _default: (options?: SetupVisOptions<{
40
27
  tags: string[];
41
- }>) => storybook_internal_csf0.PreviewAddon<storybook_internal_csf0.AddonTypes>;
42
- //#endregion
43
- export { type ComparisonMethod, type FailureThresholdOptions, type ImageSnapshotCompareOptions, type ImageSnapshotKeyOptions, type ImageSnapshotSubjectOptions, type ImageSnapshotTimeoutOptions, type PageImageSnapshotOptions, type PixelComparisonOptions, type SsimComparisonOptions, type ToMatchImageSnapshotOptions, cdp, _default as default, defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, page, visAnnotations };
28
+ }>) => import("storybook/internal/csf").PreviewAddon<import("storybook/internal/csf").AddonTypes>;
29
+ export { type ComparisonMethod, type FailureThresholdOptions, type ImageSnapshotCompareOptions, type ImageSnapshotKeyOptions, type ImageSnapshotSubjectOptions, type ImageSnapshotTimeoutOptions, type PageImageSnapshotOptions, type PixelComparisonOptions, type SsimComparisonOptions, type ToMatchImageSnapshotOptions, _default as default, visAnnotations };
44
30
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/client/vitest_proxy.ts","../src/client/has_image_snapshot.ts","../src/client/storybook/param.ts","../src/client/storybook/tags.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;cAyGa,MAAI;cAEJ,WAhCI;;;;;;iBCpED,gBAAA,WAA2B,gDAAmC;;;;;;;;iBCyB9D,kCAAkC,4BACvC,4BAA4B,KAAK,8BAA8B;;;;;AFwE1E,CAAA;;;iBGzGgB,iBAAA;;;cCqBoB,qBAEX;;OAAqD,uBAAA,CAAA,aAAtC,uBAAA,CAAsC,UAAA"}
1
+ {"version":3,"file":"index.d.mts","names":["ImageSnapshotKeyOptions"],"sources":["../src/client/vitest_proxy.ts","../src/client/has_image_snapshot.ts","../src/client/storybook/param.ts","../src/client/storybook/tags.ts","../src/index.ts"],"mappings":";;;;;;qBAyGa,MAAI;qBACJ,UAAQ;qBACR,WAhCI;;;;wBCpED,iBAAiB,UAAUA,gDAAmC;;;;;;wBCyB9D,wBAAwB,UAAU,kBACjD,UAAU,4BAA4B,KAAK,8BAA8B;;;;;;wBCjC1D,kBAAkB;cCuBlB,WAAA,UAAS;EAAkB;wCAAmC,8CAAA"}
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
- import { a as commands, c as whenVitestProxyReady, i as cdp, l as isVitestBrowser, n as isSnapshotEnabled, o as getCurrentTest, r as toMatchImageSnapshot, s as page, t as visAnnotations } from "./vis_annotation-BHBO0X19.mjs";
1
+ import { a as commands, c as whenVitestProxyReady, i as cdp, l as isVitestBrowser, n as isSnapshotEnabled, o as getCurrentTest, r as toMatchImageSnapshot, s as page, t as visAnnotations } from "./vis_annotation-CJD3p9Uh.mjs";
2
2
  import { definePreviewAddon } from "storybook/internal/csf";
3
3
  import { expect } from "storybook/test";
4
4
  import { autoSnapshotMatcher, hasImageSnapshotAction, setAutoSnapshotOptions, toSuiteDefaults, toTaskId } from "vitest-plugin-vis/client-api";
5
5
 
6
6
  export * from "vitest-plugin-vis"
7
7
 
8
- //#region src/client/ctx.ts
8
+ // src/client/ctx.ts
9
9
  const ctx = {
10
10
  getCurrentTest,
11
11
  __test__reset() {
@@ -13,8 +13,7 @@ const ctx = {
13
13
  }
14
14
  };
15
15
 
16
- //#endregion
17
- //#region src/client/has_image_snapshot.ts
16
+ // src/client/has_image_snapshot.ts
18
17
  /**
19
18
  * Check if the snapshot image exists.
20
19
  */
@@ -24,8 +23,7 @@ function hasImageSnapshot(options) {
24
23
  return hasImageSnapshotAction(commands, toTaskId(test), options);
25
24
  }
26
25
 
27
- //#endregion
28
- //#region src/client/storybook/param.ts
26
+ // src/client/storybook/param.ts
29
27
  /**
30
28
  * Define snapshot parameter for auto snapshot.
31
29
  *
@@ -35,8 +33,7 @@ function defineAutoSnapshotParam(snapshot) {
35
33
  return { snapshot };
36
34
  }
37
35
 
38
- //#endregion
39
- //#region src/index.ts
36
+ // src/index.ts
40
37
  expect.extend({ toMatchImageSnapshot });
41
38
  var src_default = (options = { auto: false }) => {
42
39
  let matcher;
@@ -61,6 +58,5 @@ var src_default = (options = { auto: false }) => {
61
58
  });
62
59
  };
63
60
 
64
- //#endregion
65
- export { cdp, src_default as default, defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, page, visAnnotations };
61
+ export { cdp, commands, src_default as default, defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, page, visAnnotations };
66
62
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/client/ctx.ts","../src/client/has_image_snapshot.ts","../src/client/storybook/param.ts","../src/index.ts"],"sourcesContent":["import { getCurrentTest } from './vitest_proxy.ts'\n\nexport const ctx = {\n\tgetCurrentTest,\n\t__test__reset() {\n\t\tctx.getCurrentTest = getCurrentTest\n\t},\n}\n","import { hasImageSnapshotAction, type ImageSnapshotKeyOptions, toTaskId } from 'vitest-plugin-vis/client-api'\nimport { ctx } from './ctx.ts'\nimport { commands } from './vitest_proxy.ts'\n\n/**\n * Check if the snapshot image exists.\n */\nexport function hasImageSnapshot(options?: ImageSnapshotKeyOptions | undefined) {\n\tconst test = ctx.getCurrentTest()\n\tif (!test) return false\n\n\treturn hasImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type {\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotKeyOptions,\n\tImageSnapshotSubjectOptions,\n\tImageSnapshotTimeoutOptions,\n\tPageImageSnapshotOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n} from 'vitest-plugin-vis/client-api'\n\n// This fix the inferred type cannot be named error\nexport type {\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotKeyOptions,\n\tImageSnapshotSubjectOptions,\n\tImageSnapshotTimeoutOptions,\n\tPageImageSnapshotOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n}\n\n/**\n * Define snapshot parameter for auto snapshot.\n *\n * Set `fullPage: true` to snapshot the whole page instead of the subject.\n */\nexport function defineAutoSnapshotParam<M extends ComparisonMethod>(\n\tsnapshot: ToMatchImageSnapshotOptions<M> & ImageSnapshotSubjectOptions & PageImageSnapshotOptions,\n) {\n\treturn { snapshot }\n}\n","// `storybook-addon-vis` provides code that can be used in test files.\nimport './shared/global_matcher_augment.ts'\n\nimport { definePreviewAddon } from 'storybook/internal/csf'\nimport { expect } from 'storybook/test'\nimport type { SetupVisOptions } from 'vitest-plugin-vis'\nimport { autoSnapshotMatcher, setAutoSnapshotOptions, toSuiteDefaults } from 'vitest-plugin-vis/client-api'\nimport { toMatchImageSnapshot } from './client/expect/to_match_image_snapshot.ts'\nimport { isVitestBrowser } from './client/is_vitest_browser.ts'\nimport { cdp, commands, page, whenVitestProxyReady } from './client/vitest_proxy.ts'\nimport { visAnnotations } from './preview/vis_annotation.ts'\n\n// Register at module load time so it's available in Storybook dev mode.\n// (visAnnotations.beforeEach is only wired via vitest's setProjectAnnotations, not in dev mode)\nexpect.extend({ toMatchImageSnapshot })\n\nexport * from 'vitest-plugin-vis'\nexport * from './client/has_image_snapshot.ts'\nexport * from './client/storybook/param.ts'\nexport * from './client/storybook/tags.ts'\n\nexport { cdp, page, visAnnotations }\n\nexport default (options: SetupVisOptions<{ tags: string[] }> = { auto: false }) => {\n\tlet matcher: ReturnType<typeof autoSnapshotMatcher>\n\tlet matcherFn: () => Promise<void>\n\treturn definePreviewAddon({\n\t\ttags: options.auto === true ? ['snapshot'] : [],\n\t\tasync beforeAll() {\n\t\t\tif (!isVitestBrowser()) return\n\t\t\t// `page` and `getCurrentTest` come from a dynamic import; the hooks that\n\t\t\t// follow read them synchronously, so wait for it here (#835).\n\t\t\tawait whenVitestProxyReady()\n\t\t\tmatcher = autoSnapshotMatcher(commands, expect)\n\t\t\tconst suiteDefaults = toSuiteDefaults(options)\n\t\t\tif (typeof options?.auto === 'function') {\n\t\t\t\tmatcherFn = matcher.createMatcher(\n\t\t\t\t\t{\n\t\t\t\t\t\tauto: options.auto,\n\t\t\t\t\t},\n\t\t\t\t\tsuiteDefaults,\n\t\t\t\t)\n\t\t\t} else if (typeof options?.auto === 'object') {\n\t\t\t\tmatcherFn = matcher.createMatcher(options.auto, suiteDefaults)\n\t\t\t} else matcherFn = matcher.createMatcher({ async auto() {} }, suiteDefaults)\n\n\t\t\tawait matcher.setup()\n\t\t\tawait setAutoSnapshotOptions(true)\n\t\t},\n\t\tafterEach() {\n\t\t\tif (matcherFn) {\n\t\t\t\treturn matcherFn()\n\t\t\t}\n\t\t},\n\t\t...visAnnotations,\n\t})\n}\n"],"mappings":";;;;;;;;AAEA,MAAa,MAAM;CAClB;CACA,gBAAgB;AACf,MAAI,iBAAiB;;CAEtB;;;;;;;ACAD,SAAgB,iBAAiB,SAA+C;CAC/E,MAAM,OAAO,IAAI,gBAAgB;AACjC,KAAI,CAAC,KAAM,QAAO;AAElB,QAAO,uBAAuB,UAAU,SAAS,KAAK,EAAE,QAAQ;;;;;;;;;;ACqBjE,SAAgB,wBACf,UACC;AACD,QAAO,EAAE,UAAU;;;;;ACrBpB,OAAO,OAAO,EAAE,sBAAsB,CAAC;AASvC,mBAAgB,UAA+C,EAAE,MAAM,OAAO,KAAK;CAClF,IAAI;CACJ,IAAI;AACJ,QAAO,mBAAmB;EACzB,MAAM,QAAQ,SAAS,OAAO,CAAC,WAAW,GAAG,EAAE;EAC/C,MAAM,YAAY;AACjB,OAAI,CAAC,iBAAiB,CAAE;AAGxB,SAAM,sBAAsB;AAC5B,aAAU,oBAAoB,UAAU,OAAO;GAC/C,MAAM,gBAAgB,gBAAgB,QAAQ;AAC9C,OAAI,OAAO,SAAS,SAAS,WAC5B,aAAY,QAAQ,cACnB,EACC,MAAM,QAAQ,MACd,EACD,cACA;YACS,OAAO,SAAS,SAAS,SACnC,aAAY,QAAQ,cAAc,QAAQ,MAAM,cAAc;OACxD,aAAY,QAAQ,cAAc,EAAE,MAAM,OAAO,IAAI,EAAE,cAAc;AAE5E,SAAM,QAAQ,OAAO;AACrB,SAAM,uBAAuB,KAAK;;EAEnC,YAAY;AACX,OAAI,UACH,QAAO,WAAW;;EAGpB,GAAG;EACH,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/client/ctx.ts","../src/client/has_image_snapshot.ts","../src/client/storybook/param.ts","../src/index.ts"],"sourcesContent":["import { getCurrentTest } from './vitest_proxy.ts'\n\nexport const ctx = {\n\tgetCurrentTest,\n\t__test__reset() {\n\t\tctx.getCurrentTest = getCurrentTest\n\t},\n}\n","import { hasImageSnapshotAction, type ImageSnapshotKeyOptions, toTaskId } from 'vitest-plugin-vis/client-api'\nimport { ctx } from './ctx.ts'\nimport { commands } from './vitest_proxy.ts'\n\n/**\n * Check if the snapshot image exists.\n */\nexport function hasImageSnapshot(options?: ImageSnapshotKeyOptions | undefined) {\n\tconst test = ctx.getCurrentTest()\n\tif (!test) return false\n\n\treturn hasImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type {\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotKeyOptions,\n\tImageSnapshotSubjectOptions,\n\tImageSnapshotTimeoutOptions,\n\tPageImageSnapshotOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n} from 'vitest-plugin-vis/client-api'\n\n// This fix the inferred type cannot be named error\nexport type {\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotKeyOptions,\n\tImageSnapshotSubjectOptions,\n\tImageSnapshotTimeoutOptions,\n\tPageImageSnapshotOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n}\n\n/**\n * Define snapshot parameter for auto snapshot.\n *\n * Set `fullPage: true` to snapshot the whole page instead of the subject.\n */\nexport function defineAutoSnapshotParam<M extends ComparisonMethod>(\n\tsnapshot: ToMatchImageSnapshotOptions<M> & ImageSnapshotSubjectOptions & PageImageSnapshotOptions,\n) {\n\treturn { snapshot }\n}\n","// `storybook-addon-vis` provides code that can be used in test files.\nimport './shared/global_matcher_augment.ts'\n\nimport { definePreviewAddon } from 'storybook/internal/csf'\nimport { expect } from 'storybook/test'\nimport type { SetupVisOptions } from 'vitest-plugin-vis'\nimport { autoSnapshotMatcher, setAutoSnapshotOptions, toSuiteDefaults } from 'vitest-plugin-vis/client-api'\nimport { toMatchImageSnapshot } from './client/expect/to_match_image_snapshot.ts'\nimport { isVitestBrowser } from './client/is_vitest_browser.ts'\nimport { cdp, commands, page, whenVitestProxyReady } from './client/vitest_proxy.ts'\nimport { visAnnotations } from './preview/vis_annotation.ts'\n\n// Register at module load time so it's available in Storybook dev mode.\n// (visAnnotations.beforeEach is only wired via vitest's setProjectAnnotations, not in dev mode)\nexpect.extend({ toMatchImageSnapshot })\n\nexport * from 'vitest-plugin-vis'\nexport * from './client/has_image_snapshot.ts'\nexport * from './client/storybook/param.ts'\nexport * from './client/storybook/tags.ts'\n\nexport { cdp, commands, page, visAnnotations }\n\nexport default (options: SetupVisOptions<{ tags: string[] }> = { auto: false }) => {\n\tlet matcher: ReturnType<typeof autoSnapshotMatcher>\n\tlet matcherFn: () => Promise<void>\n\treturn definePreviewAddon({\n\t\ttags: options.auto === true ? ['snapshot'] : [],\n\t\tasync beforeAll() {\n\t\t\tif (!isVitestBrowser()) return\n\t\t\t// `page` and `getCurrentTest` come from a dynamic import; the hooks that\n\t\t\t// follow read them synchronously, so wait for it here (#835).\n\t\t\tawait whenVitestProxyReady()\n\t\t\tmatcher = autoSnapshotMatcher(commands, expect)\n\t\t\tconst suiteDefaults = toSuiteDefaults(options)\n\t\t\tif (typeof options?.auto === 'function') {\n\t\t\t\tmatcherFn = matcher.createMatcher(\n\t\t\t\t\t{\n\t\t\t\t\t\tauto: options.auto,\n\t\t\t\t\t},\n\t\t\t\t\tsuiteDefaults,\n\t\t\t\t)\n\t\t\t} else if (typeof options?.auto === 'object') {\n\t\t\t\tmatcherFn = matcher.createMatcher(options.auto, suiteDefaults)\n\t\t\t} else matcherFn = matcher.createMatcher({ async auto() {} }, suiteDefaults)\n\n\t\t\tawait matcher.setup()\n\t\t\tawait setAutoSnapshotOptions(true)\n\t\t},\n\t\tafterEach() {\n\t\t\tif (matcherFn) {\n\t\t\t\treturn matcherFn()\n\t\t\t}\n\t\t},\n\t\t...visAnnotations,\n\t})\n}\n"],"mappings":";;;;;;;;AAEA,MAAa,MAAM;CAClB;CACA,gBAAgB;EACf,IAAI,iBAAiB;CACtB;AACD;;;;;;ACAA,SAAgB,iBAAiB,SAA+C;CAC/E,MAAM,OAAO,IAAI,eAAe;CAChC,IAAI,CAAC,MAAM,OAAO;CAElB,OAAO,uBAAuB,UAAU,SAAS,IAAI,GAAG,OAAO;AAChE;;;;;;;;ACoBA,SAAgB,wBACf,UACC;CACD,OAAO,EAAE,SAAS;AACnB;;;ACtBA,OAAO,OAAO,EAAE,qBAAqB,CAAC;AAStC,mBAAgB,UAA+C,EAAE,MAAM,MAAM,MAAM;CAClF,IAAI;CACJ,IAAI;CACJ,OAAO,mBAAmB;EACzB,MAAM,QAAQ,SAAS,OAAO,CAAC,UAAU,IAAI,CAAC;EAC9C,MAAM,YAAY;GACjB,IAAI,CAAC,gBAAgB,GAAG;GAGxB,MAAM,qBAAqB;GAC3B,UAAU,oBAAoB,UAAU,MAAM;GAC9C,MAAM,gBAAgB,gBAAgB,OAAO;GAC7C,IAAI,OAAO,SAAS,SAAS,YAC5B,YAAY,QAAQ,cACnB,EACC,MAAM,QAAQ,KACf,GACA,aACD;QACM,IAAI,OAAO,SAAS,SAAS,UACnC,YAAY,QAAQ,cAAc,QAAQ,MAAM,aAAa;QACvD,YAAY,QAAQ,cAAc,EAAE,MAAM,OAAO,CAAC,EAAE,GAAG,aAAa;GAE3E,MAAM,QAAQ,MAAM;GACpB,MAAM,uBAAuB,IAAI;EAClC;EACA,YAAY;GACX,IAAI,WACH,OAAO,UAAU;EAEnB;EACA,GAAG;CACJ,CAAC;AACF"}
package/dist/manager.d.ts CHANGED
@@ -1 +1 @@
1
- export { };
1
+ export {}
package/dist/manager.js CHANGED
@@ -6,8 +6,8 @@ import { AddonPanel, Button, Placeholder, ScrollArea } from "storybook/internal/
6
6
  import { styled } from "storybook/theming";
7
7
  import { SNAPSHOT_ROOT_DIR } from "vitest-plugin-vis/client-api";
8
8
 
9
- //#region src/components/vis_panel.tsx
10
- const VisPanel = memo(function VisPanel$1({ active, getSnapshotResults, onRefresh }) {
9
+ // src/components/vis_panel.tsx
10
+ const VisPanel = memo(function VisPanel({ active, getSnapshotResults, onRefresh }) {
11
11
  const [snapshotResults, setSnapshotResults] = useState([]);
12
12
  useEffect(() => {
13
13
  getSnapshotResults().then(setSnapshotResults);
@@ -19,17 +19,17 @@ const VisPanel = memo(function VisPanel$1({ active, getSnapshotResults, onRefres
19
19
  }, {});
20
20
  const snapshots = Object.entries(groupedResults).filter(([, results]) => results.some((result) => result.type !== "result"));
21
21
  return /* @__PURE__ */ React.createElement(AddonPanel, { active }, snapshots.length > 0 ? /* @__PURE__ */ React.createElement(ScrollArea, { vertical: true }, snapshots.map(([key, results]) => {
22
- const baseline = results.find((result$1) => result$1.type === "baseline");
23
- const result = results.find((result$1) => result$1.type === "result");
24
- const diff = results.find((result$1) => result$1.type === "diff");
22
+ const baseline = results.find((result) => result.type === "baseline");
23
+ const result = results.find((result) => result.type === "result");
24
+ const diff = results.find((result) => result.type === "diff");
25
25
  return /* @__PURE__ */ React.createElement("div", { key }, diff ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SnapshotRow, { failed: true }, key), baseline && result ? /* @__PURE__ */ React.createElement(SnapshotCompare, {
26
26
  baseline,
27
27
  result,
28
28
  diff
29
- }) : results.map((result$1) => /* @__PURE__ */ React.createElement("img", {
30
- key: result$1.filePath,
31
- src: toDataUrl(result$1),
32
- alt: result$1.fileName
29
+ }) : results.map((result) => /* @__PURE__ */ React.createElement("img", {
30
+ key: result.filePath,
31
+ src: toDataUrl(result),
32
+ alt: result.fileName
33
33
  }))) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SnapshotRow, null, /* @__PURE__ */ React.createElement("span", null, key), /* @__PURE__ */ React.createElement(Button, {
34
34
  "aria-label": "Reload snapshot",
35
35
  onClick: () => {
@@ -117,13 +117,11 @@ const SnapshotRow = styled.div(({ theme, failed }) => ({
117
117
  color: theme.barTextColor
118
118
  }));
119
119
 
120
- //#endregion
121
- //#region src/shared/constants.ts
120
+ // src/shared/constants.ts
122
121
  const NAME = "storybook-addon-vis";
123
122
  const VIS_PANEL_ID = `${NAME}/vis_panel`;
124
123
 
125
- //#endregion
126
- //#region src/shared/events.ts
124
+ // src/shared/events.ts
127
125
  const IMAGE_SNAPSHOT_RESULTS_REQUEST = "IMAGE_SNAPSHOT_RESULTS_REQUEST";
128
126
  const IMAGE_SNAPSHOT_RESULTS_RESPONSE = "IMAGE_SNAPSHOT_RESULTS_RESPONSE";
129
127
  function requestImageSnapshotResults({ name, importPath }) {
@@ -134,8 +132,7 @@ function requestImageSnapshotResults({ name, importPath }) {
134
132
  };
135
133
  }
136
134
 
137
- //#endregion
138
- //#region src/exports/manager.tsx
135
+ // src/exports/manager.tsx
139
136
  addons.register(NAME, (api) => {
140
137
  if (globalThis.CONFIG_TYPE === "DEVELOPMENT") addons.add(VIS_PANEL_ID, {
141
138
  type: types.PANEL,
@@ -151,7 +148,7 @@ addons.register(NAME, (api) => {
151
148
  api.once(NAME, (event) => {
152
149
  if (event.name !== storyData.name) return;
153
150
  if (event.importPath !== storyData.importPath) return;
154
- if (event.type === IMAGE_SNAPSHOT_RESULTS_RESPONSE) resolve(event.results);
151
+ if (event.type === "IMAGE_SNAPSHOT_RESULTS_RESPONSE") resolve(event.results);
155
152
  });
156
153
  });
157
154
  }
@@ -166,5 +163,4 @@ addons.register(NAME, (api) => {
166
163
  });
167
164
  });
168
165
 
169
- //#endregion
170
166
  //# sourceMappingURL=manager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"manager.js","names":["VisPanel","result"],"sources":["../src/components/vis_panel.tsx","../src/shared/constants.ts","../src/shared/events.ts","../src/exports/manager.tsx"],"sourcesContent":["import { ImageCompare, type ImageCompareMode } from '@just-web/react-image-compare'\nimport { RefreshIcon } from '@storybook/icons'\nimport React, { memo, useEffect, useState } from 'react'\nimport { AddonPanel, Button, Placeholder, ScrollArea } from 'storybook/internal/components'\nimport { styled } from 'storybook/theming'\nimport { SNAPSHOT_ROOT_DIR } from 'vitest-plugin-vis/client-api'\nimport type { ImageSnapshotResults } from '../shared/events.ts'\n\ninterface PanelProps {\n\tactive: boolean\n\tgetSnapshotResults: () => Promise<ImageSnapshotResults[]>\n\tonRefresh: () => void\n}\n\nexport const VisPanel = memo(function VisPanel({ active, getSnapshotResults, onRefresh }: PanelProps) {\n\tconst [snapshotResults, setSnapshotResults] = useState<ImageSnapshotResults[]>([])\n\n\tuseEffect(() => {\n\t\tgetSnapshotResults().then(setSnapshotResults)\n\t}, [getSnapshotResults])\n\n\tconst groupedResults = snapshotResults.reduce(\n\t\t(acc, result) => {\n\t\t\tconst suiteName = result.snapshotRootDir.slice(SNAPSHOT_ROOT_DIR.length + 1)\n\t\t\tconst key = `(${suiteName}) ${result.fileName}`\n\t\t\tacc[key] = [...(acc[key] ?? []), result]\n\t\t\treturn acc\n\t\t},\n\t\t{} as Record<string, ImageSnapshotResults[]>,\n\t)\n\t// A result alone (no baseline, no diff) is a snapshot that has no baseline yet, so there is nothing to review.\n\tconst snapshots = Object.entries(groupedResults).filter(([, results]) =>\n\t\tresults.some((result) => result.type !== 'result'),\n\t)\n\treturn (\n\t\t<AddonPanel active={active}>\n\t\t\t{snapshots.length > 0 ? (\n\t\t\t\t<ScrollArea vertical>\n\t\t\t\t\t{snapshots.map(([key, results]) => {\n\t\t\t\t\t\tconst baseline = results.find((result) => result.type === 'baseline')\n\t\t\t\t\t\tconst result = results.find((result) => result.type === 'result')\n\t\t\t\t\t\tconst diff = results.find((result) => result.type === 'diff')\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<div key={key}>\n\t\t\t\t\t\t\t\t{diff ? (\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t<SnapshotRow failed>{key}</SnapshotRow>\n\t\t\t\t\t\t\t\t\t\t{baseline && result ? (\n\t\t\t\t\t\t\t\t\t\t\t<SnapshotCompare baseline={baseline} result={result} diff={diff} />\n\t\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t\t// No result to compare with (e.g. an old run): show each image as is.\n\t\t\t\t\t\t\t\t\t\t\tresults.map((result) => (\n\t\t\t\t\t\t\t\t\t\t\t\t<img key={result.filePath} src={toDataUrl(result)} alt={result.fileName} />\n\t\t\t\t\t\t\t\t\t\t\t))\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t<SnapshotRow>\n\t\t\t\t\t\t\t\t\t\t\t<span>{key}</span>\n\t\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\t\taria-label=\"Reload snapshot\"\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tonRefresh()\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetSnapshotResults().then(setSnapshotResults)\n\t\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t<RefreshIcon />\n\t\t\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t\t</SnapshotRow>\n\t\t\t\t\t\t\t\t\t\t{baseline && <SnapshotImage image={baseline} />}\n\t\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)\n\t\t\t\t\t})}\n\t\t\t\t</ScrollArea>\n\t\t\t) : (\n\t\t\t\t<Placeholder>There is no snapshots for this story</Placeholder>\n\t\t\t)}\n\t\t</AddonPanel>\n\t)\n})\n\nfunction toDataUrl(image: ImageSnapshotResults) {\n\treturn `data:image/png;base64,${image.base64}`\n}\n\nfunction SnapshotImage({ image }: { image: ImageSnapshotResults }) {\n\treturn <img src={toDataUrl(image)} alt={image.fileName} />\n}\n\ntype CompareView = ImageCompareMode | 'diff'\n\nconst compareViews: Array<{ view: CompareView; label: string }> = [\n\t{ view: 'side-by-side', label: 'Side by side' },\n\t{ view: 'swipe', label: 'Swipe' },\n\t{ view: 'onion-skin', label: 'Onion skin' },\n\t{ view: 'diff', label: 'Diff' },\n]\n\ninterface SnapshotCompareProps {\n\tbaseline: ImageSnapshotResults\n\tresult: ImageSnapshotResults\n\tdiff: ImageSnapshotResults\n}\n\n/**\n * Compares the baseline and the result of a failed snapshot like GitHub's image diff,\n * plus the diff image that marks the changed pixels.\n */\nfunction SnapshotCompare({ baseline, result, diff }: SnapshotCompareProps) {\n\tconst [view, setView] = useState<CompareView>('side-by-side')\n\t// The compare mode stays mounted while the diff shows, so the swipe position and the opacity are kept.\n\tconst [mode, setMode] = useState<ImageCompareMode>('side-by-side')\n\treturn (\n\t\t<CompareContainer>\n\t\t\t<ViewSwitcher role=\"group\" aria-label=\"Comparison view\">\n\t\t\t\t{compareViews.map(({ view: v, label }) => (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tkey={v}\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tactive={v === view}\n\t\t\t\t\t\taria-pressed={v === view}\n\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\tsetView(v)\n\t\t\t\t\t\t\tif (v !== 'diff') setMode(v)\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{label}\n\t\t\t\t\t</Button>\n\t\t\t\t))}\n\t\t\t</ViewSwitcher>\n\t\t\t<ImageCompare\n\t\t\t\tbase={toDataUrl(baseline)}\n\t\t\t\tcompare={toDataUrl(result)}\n\t\t\t\tbaseLabel=\"Baseline\"\n\t\t\t\tcompareLabel=\"Result\"\n\t\t\t\tmode={mode}\n\t\t\t\tshowModeSwitcher={false}\n\t\t\t\tstyle={view === 'diff' ? { display: 'none' } : undefined}\n\t\t\t/>\n\t\t\t{view === 'diff' && <SnapshotImage image={diff} />}\n\t\t</CompareContainer>\n\t)\n}\n\nconst CompareContainer = styled.div({\n\tdisplay: 'flex',\n\tflexDirection: 'column',\n\talignItems: 'flex-start',\n\tgap: '0.5rem',\n\tpadding: '0.5rem',\n})\n\nconst ViewSwitcher = styled.div({\n\tdisplay: 'flex',\n\tgap: '0.25rem',\n})\n\nconst SnapshotRow = styled.div<{ failed?: boolean }>(\n\t({ theme, failed }: { theme: any; failed?: boolean | undefined }) => ({\n\t\tdisplay: 'flex',\n\t\talignItems: 'center',\n\t\tgap: '0.5rem',\n\t\tpaddingBlock: '0.5rem',\n\t\tpaddingInline: '0.2rem',\n\t\tbackgroundColor: failed ? theme.background.negative : theme.background.positive,\n\t\tcolor: theme.barTextColor,\n\t}),\n)\n","export const NAME = 'storybook-addon-vis'\nexport const VIS_PANEL_ID = `${NAME}/vis_panel`\n","export type VisEvent = ImageSnapshotResultsRequest | ImageSnapshotResultsResponse\n\nexport const IMAGE_SNAPSHOT_RESULTS_REQUEST = 'IMAGE_SNAPSHOT_RESULTS_REQUEST'\nexport const IMAGE_SNAPSHOT_RESULTS_RESPONSE = 'IMAGE_SNAPSHOT_RESULTS_RESPONSE'\n\nexport function requestImageSnapshotResults({ name, importPath }: { name: string; importPath: string }) {\n\treturn {\n\t\ttype: IMAGE_SNAPSHOT_RESULTS_REQUEST,\n\t\tname,\n\t\timportPath,\n\t}\n}\n\nexport type ImageSnapshotResultsRequest = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_REQUEST\n\tname: string\n\timportPath: string\n}\n\nexport type ImageSnapshotResultsResponse = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_RESPONSE\n\tname: string\n\timportPath: string\n\tresults: ImageSnapshotResults[]\n}\n\nexport type ImageSnapshotResults = {\n\tfilePath: string\n\tfileName: string\n\tsnapshotRootDir: string\n\ttype: 'baseline' | 'diff' | 'result'\n\tbase64: string\n}\n","import React from 'react'\nimport { addons, types } from 'storybook/manager-api'\nimport { VisPanel } from '../components/vis_panel.tsx'\nimport { NAME, VIS_PANEL_ID } from '../shared/constants.ts'\nimport {\n\tIMAGE_SNAPSHOT_RESULTS_RESPONSE,\n\ttype ImageSnapshotResults,\n\trequestImageSnapshotResults,\n\ttype VisEvent,\n} from '../shared/events.ts'\n\n// Register the addon\naddons.register(NAME, (api) => {\n\t// Register the tool\n\tif ((globalThis as any).CONFIG_TYPE === 'DEVELOPMENT') {\n\t\taddons.add(VIS_PANEL_ID, {\n\t\t\ttype: types.PANEL,\n\t\t\ttitle: 'Vis',\n\t\t\tmatch: ({ tabId, viewMode }) => !tabId && viewMode === 'story',\n\t\t\trender({ active }) {\n\t\t\t\tif (!active) return null\n\t\t\t\tconst storyData = api.getCurrentStoryData()\n\t\t\t\tif (!storyData) return null\n\t\t\t\tapi.emit(NAME, requestImageSnapshotResults(storyData))\n\t\t\t\tasync function getSnapshotResults() {\n\t\t\t\t\treturn new Promise<ImageSnapshotResults[]>((resolve) => {\n\t\t\t\t\t\tapi.once(NAME, (event: VisEvent) => {\n\t\t\t\t\t\t\tif (event.name !== storyData.name) return\n\t\t\t\t\t\t\tif (event.importPath !== storyData.importPath) return\n\t\t\t\t\t\t\tif (event.type === IMAGE_SNAPSHOT_RESULTS_RESPONSE) {\n\t\t\t\t\t\t\t\tresolve(event.results)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn (\n\t\t\t\t\t<VisPanel\n\t\t\t\t\t\tactive={active}\n\t\t\t\t\t\tgetSnapshotResults={getSnapshotResults}\n\t\t\t\t\t\tonRefresh={() => {\n\t\t\t\t\t\t\tif (storyData) api.emit(NAME, requestImageSnapshotResults(storyData))\n\t\t\t\t\t\t}}\n\t\t\t\t\t/>\n\t\t\t\t)\n\t\t\t},\n\t\t})\n\t}\n})\n"],"mappings":";;;;;;;;;AAcA,MAAa,WAAW,KAAK,SAASA,WAAS,EAAE,QAAQ,oBAAoB,aAAyB;CACrG,MAAM,CAAC,iBAAiB,sBAAsB,SAAiC,EAAE,CAAC;AAElF,iBAAgB;AACf,sBAAoB,CAAC,KAAK,mBAAmB;IAC3C,CAAC,mBAAmB,CAAC;CAExB,MAAM,iBAAiB,gBAAgB,QACrC,KAAK,WAAW;EAEhB,MAAM,MAAM,IADM,OAAO,gBAAgB,MAAM,kBAAkB,SAAS,EAAE,CAClD,IAAI,OAAO;AACrC,MAAI,OAAO,CAAC,GAAI,IAAI,QAAQ,EAAE,EAAG,OAAO;AACxC,SAAO;IAER,EAAE,CACF;CAED,MAAM,YAAY,OAAO,QAAQ,eAAe,CAAC,QAAQ,GAAG,aAC3D,QAAQ,MAAM,WAAW,OAAO,SAAS,SAAS,CAClD;AACD,QACC,oCAAC,cAAmB,UAClB,UAAU,SAAS,IACnB,oCAAC,cAAW,kBACV,UAAU,KAAK,CAAC,KAAK,aAAa;EAClC,MAAM,WAAW,QAAQ,MAAM,aAAWC,SAAO,SAAS,WAAW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AiC,YAAY;AACvD,SAAI,KAAK,OAAO,UAAoB;AACnC,UAAI,MAAM,SAAS,UAAU,KAAM;AACnC,UAAI,MAAM,eAAe,UAAU,WAAY;AAC/C,UAAI,MAAM,SAAS,gCAClB,SAAQ,MAAM,QAAQ;OAEtB;MACD;;AAEH,UACC,oCAAC;IACQ;IACY;IACpB,iBAAiB;AAChB,SAAI,UAAW,KAAI,KAAK,MAAM,4BAA4B,UAAU,CAAC;;KAErE;;EAGJ,CAAC;EAEF"}
1
+ {"version":3,"file":"manager.js","names":[],"sources":["../src/components/vis_panel.tsx","../src/shared/constants.ts","../src/shared/events.ts","../src/exports/manager.tsx"],"sourcesContent":["import { ImageCompare, type ImageCompareMode } from '@just-web/react-image-compare'\nimport { RefreshIcon } from '@storybook/icons'\nimport React, { memo, useEffect, useState } from 'react'\nimport { AddonPanel, Button, Placeholder, ScrollArea } from 'storybook/internal/components'\nimport { styled } from 'storybook/theming'\nimport { SNAPSHOT_ROOT_DIR } from 'vitest-plugin-vis/client-api'\nimport type { ImageSnapshotResults } from '../shared/events.ts'\n\ninterface PanelProps {\n\tactive: boolean\n\tgetSnapshotResults: () => Promise<ImageSnapshotResults[]>\n\tonRefresh: () => void\n}\n\nexport const VisPanel = memo(function VisPanel({ active, getSnapshotResults, onRefresh }: PanelProps) {\n\tconst [snapshotResults, setSnapshotResults] = useState<ImageSnapshotResults[]>([])\n\n\tuseEffect(() => {\n\t\tgetSnapshotResults().then(setSnapshotResults)\n\t}, [getSnapshotResults])\n\n\tconst groupedResults = snapshotResults.reduce(\n\t\t(acc, result) => {\n\t\t\tconst suiteName = result.snapshotRootDir.slice(SNAPSHOT_ROOT_DIR.length + 1)\n\t\t\tconst key = `(${suiteName}) ${result.fileName}`\n\t\t\tacc[key] = [...(acc[key] ?? []), result]\n\t\t\treturn acc\n\t\t},\n\t\t{} as Record<string, ImageSnapshotResults[]>,\n\t)\n\t// A result alone (no baseline, no diff) is a snapshot that has no baseline yet, so there is nothing to review.\n\tconst snapshots = Object.entries(groupedResults).filter(([, results]) =>\n\t\tresults.some((result) => result.type !== 'result'),\n\t)\n\treturn (\n\t\t<AddonPanel active={active}>\n\t\t\t{snapshots.length > 0 ? (\n\t\t\t\t<ScrollArea vertical>\n\t\t\t\t\t{snapshots.map(([key, results]) => {\n\t\t\t\t\t\tconst baseline = results.find((result) => result.type === 'baseline')\n\t\t\t\t\t\tconst result = results.find((result) => result.type === 'result')\n\t\t\t\t\t\tconst diff = results.find((result) => result.type === 'diff')\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<div key={key}>\n\t\t\t\t\t\t\t\t{diff ? (\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t<SnapshotRow failed>{key}</SnapshotRow>\n\t\t\t\t\t\t\t\t\t\t{baseline && result ? (\n\t\t\t\t\t\t\t\t\t\t\t<SnapshotCompare baseline={baseline} result={result} diff={diff} />\n\t\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t\t// No result to compare with (e.g. an old run): show each image as is.\n\t\t\t\t\t\t\t\t\t\t\tresults.map((result) => (\n\t\t\t\t\t\t\t\t\t\t\t\t<img key={result.filePath} src={toDataUrl(result)} alt={result.fileName} />\n\t\t\t\t\t\t\t\t\t\t\t))\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t<SnapshotRow>\n\t\t\t\t\t\t\t\t\t\t\t<span>{key}</span>\n\t\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\t\taria-label=\"Reload snapshot\"\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tonRefresh()\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetSnapshotResults().then(setSnapshotResults)\n\t\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t<RefreshIcon />\n\t\t\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t\t</SnapshotRow>\n\t\t\t\t\t\t\t\t\t\t{baseline && <SnapshotImage image={baseline} />}\n\t\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)\n\t\t\t\t\t})}\n\t\t\t\t</ScrollArea>\n\t\t\t) : (\n\t\t\t\t<Placeholder>There is no snapshots for this story</Placeholder>\n\t\t\t)}\n\t\t</AddonPanel>\n\t)\n})\n\nfunction toDataUrl(image: ImageSnapshotResults) {\n\treturn `data:image/png;base64,${image.base64}`\n}\n\nfunction SnapshotImage({ image }: { image: ImageSnapshotResults }) {\n\treturn <img src={toDataUrl(image)} alt={image.fileName} />\n}\n\ntype CompareView = ImageCompareMode | 'diff'\n\nconst compareViews: Array<{ view: CompareView; label: string }> = [\n\t{ view: 'side-by-side', label: 'Side by side' },\n\t{ view: 'swipe', label: 'Swipe' },\n\t{ view: 'onion-skin', label: 'Onion skin' },\n\t{ view: 'diff', label: 'Diff' },\n]\n\ninterface SnapshotCompareProps {\n\tbaseline: ImageSnapshotResults\n\tresult: ImageSnapshotResults\n\tdiff: ImageSnapshotResults\n}\n\n/**\n * Compares the baseline and the result of a failed snapshot like GitHub's image diff,\n * plus the diff image that marks the changed pixels.\n */\nfunction SnapshotCompare({ baseline, result, diff }: SnapshotCompareProps) {\n\tconst [view, setView] = useState<CompareView>('side-by-side')\n\t// The compare mode stays mounted while the diff shows, so the swipe position and the opacity are kept.\n\tconst [mode, setMode] = useState<ImageCompareMode>('side-by-side')\n\treturn (\n\t\t<CompareContainer>\n\t\t\t<ViewSwitcher role=\"group\" aria-label=\"Comparison view\">\n\t\t\t\t{compareViews.map(({ view: v, label }) => (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tkey={v}\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tactive={v === view}\n\t\t\t\t\t\taria-pressed={v === view}\n\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\tsetView(v)\n\t\t\t\t\t\t\tif (v !== 'diff') setMode(v)\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{label}\n\t\t\t\t\t</Button>\n\t\t\t\t))}\n\t\t\t</ViewSwitcher>\n\t\t\t<ImageCompare\n\t\t\t\tbase={toDataUrl(baseline)}\n\t\t\t\tcompare={toDataUrl(result)}\n\t\t\t\tbaseLabel=\"Baseline\"\n\t\t\t\tcompareLabel=\"Result\"\n\t\t\t\tmode={mode}\n\t\t\t\tshowModeSwitcher={false}\n\t\t\t\tstyle={view === 'diff' ? { display: 'none' } : undefined}\n\t\t\t/>\n\t\t\t{view === 'diff' && <SnapshotImage image={diff} />}\n\t\t</CompareContainer>\n\t)\n}\n\nconst CompareContainer = styled.div({\n\tdisplay: 'flex',\n\tflexDirection: 'column',\n\talignItems: 'flex-start',\n\tgap: '0.5rem',\n\tpadding: '0.5rem',\n})\n\nconst ViewSwitcher = styled.div({\n\tdisplay: 'flex',\n\tgap: '0.25rem',\n})\n\nconst SnapshotRow = styled.div<{ failed?: boolean }>(\n\t({ theme, failed }: { theme: any; failed?: boolean | undefined }) => ({\n\t\tdisplay: 'flex',\n\t\talignItems: 'center',\n\t\tgap: '0.5rem',\n\t\tpaddingBlock: '0.5rem',\n\t\tpaddingInline: '0.2rem',\n\t\tbackgroundColor: failed ? theme.background.negative : theme.background.positive,\n\t\tcolor: theme.barTextColor,\n\t}),\n)\n","export const NAME = 'storybook-addon-vis'\nexport const VIS_PANEL_ID = `${NAME}/vis_panel`\n","export type VisEvent = ImageSnapshotResultsRequest | ImageSnapshotResultsResponse\n\nexport const IMAGE_SNAPSHOT_RESULTS_REQUEST = 'IMAGE_SNAPSHOT_RESULTS_REQUEST'\nexport const IMAGE_SNAPSHOT_RESULTS_RESPONSE = 'IMAGE_SNAPSHOT_RESULTS_RESPONSE'\n\nexport function requestImageSnapshotResults({ name, importPath }: { name: string; importPath: string }) {\n\treturn {\n\t\ttype: IMAGE_SNAPSHOT_RESULTS_REQUEST,\n\t\tname,\n\t\timportPath,\n\t}\n}\n\nexport type ImageSnapshotResultsRequest = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_REQUEST\n\tname: string\n\timportPath: string\n}\n\nexport type ImageSnapshotResultsResponse = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_RESPONSE\n\tname: string\n\timportPath: string\n\tresults: ImageSnapshotResults[]\n}\n\nexport type ImageSnapshotResults = {\n\tfilePath: string\n\tfileName: string\n\tsnapshotRootDir: string\n\ttype: 'baseline' | 'diff' | 'result'\n\tbase64: string\n}\n","import React from 'react'\nimport { addons, types } from 'storybook/manager-api'\nimport { VisPanel } from '../components/vis_panel.tsx'\nimport { NAME, VIS_PANEL_ID } from '../shared/constants.ts'\nimport {\n\tIMAGE_SNAPSHOT_RESULTS_RESPONSE,\n\ttype ImageSnapshotResults,\n\trequestImageSnapshotResults,\n\ttype VisEvent,\n} from '../shared/events.ts'\n\n// Register the addon\naddons.register(NAME, (api) => {\n\t// Register the tool\n\tif ((globalThis as any).CONFIG_TYPE === 'DEVELOPMENT') {\n\t\taddons.add(VIS_PANEL_ID, {\n\t\t\ttype: types.PANEL,\n\t\t\ttitle: 'Vis',\n\t\t\tmatch: ({ tabId, viewMode }) => !tabId && viewMode === 'story',\n\t\t\trender({ active }) {\n\t\t\t\tif (!active) return null\n\t\t\t\tconst storyData = api.getCurrentStoryData()\n\t\t\t\tif (!storyData) return null\n\t\t\t\tapi.emit(NAME, requestImageSnapshotResults(storyData))\n\t\t\t\tasync function getSnapshotResults() {\n\t\t\t\t\treturn new Promise<ImageSnapshotResults[]>((resolve) => {\n\t\t\t\t\t\tapi.once(NAME, (event: VisEvent) => {\n\t\t\t\t\t\t\tif (event.name !== storyData.name) return\n\t\t\t\t\t\t\tif (event.importPath !== storyData.importPath) return\n\t\t\t\t\t\t\tif (event.type === IMAGE_SNAPSHOT_RESULTS_RESPONSE) {\n\t\t\t\t\t\t\t\tresolve(event.results)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn (\n\t\t\t\t\t<VisPanel\n\t\t\t\t\t\tactive={active}\n\t\t\t\t\t\tgetSnapshotResults={getSnapshotResults}\n\t\t\t\t\t\tonRefresh={() => {\n\t\t\t\t\t\t\tif (storyData) api.emit(NAME, requestImageSnapshotResults(storyData))\n\t\t\t\t\t\t}}\n\t\t\t\t\t/>\n\t\t\t\t)\n\t\t\t},\n\t\t})\n\t}\n})\n"],"mappings":";;;;;;;;;AAcA,MAAa,WAAW,KAAK,SAAS,SAAS,EAAE,QAAQ,oBAAoB,aAAyB;CACrG,MAAM,CAAC,iBAAiB,sBAAsB,SAAiC,CAAC,CAAC;CAEjF,gBAAgB;EACf,mBAAmB,CAAC,CAAC,KAAK,kBAAkB;CAC7C,GAAG,CAAC,kBAAkB,CAAC;CAEvB,MAAM,iBAAiB,gBAAgB,QACrC,KAAK,WAAW;EAEhB,MAAM,MAAM,IADM,OAAO,gBAAgB,MAAM,kBAAkB,SAAS,CAClD,EAAE,IAAI,OAAO;EACrC,IAAI,OAAO,CAAC,GAAI,IAAI,QAAQ,CAAC,GAAI,MAAM;EACvC,OAAO;CACR,GACA,CAAC,CACF;CAEA,MAAM,YAAY,OAAO,QAAQ,cAAc,CAAC,CAAC,QAAQ,GAAG,aAC3D,QAAQ,MAAM,WAAW,OAAO,SAAS,QAAQ,CAClD;CACA,OACC,oCAAC,YAAD,EAAoB,OA6CR,GA5CV,UAAU,SAAS,IACnB,oCAAC,YAAD,EAAY,eAuCA,GAtCV,UAAU,KAAK,CAAC,KAAK,aAAa;EAClC,MAAM,WAAW,QAAQ,MAAM,WAAW,OAAO,SAAS,UAAU;EACpE,MAA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B;GAC1C,IAAI,CAAC,WAAW,OAAO;GACvB,IAAI,KAAK,MAAM,4BAA4B,SAAS,CAAC;GACrD,eAAe,qBAAqB;IACnC,OAAO,IAAI,SAAiC,YAAY;KACvD,IAAI,KAAK,OAAO,UAAoB;MACnC,IAAI,MAAM,SAAS,UAAU,MAAM;MACnC,IAAI,MAAM,eAAe,UAAU,YAAY;MAC/C,IAAI,MAAM,4CACT,QAAQ,MAAM,OAAO;KAEvB,CAAC;IACF,CAAC;GACF;GACA,OACC,oCAAC,UAAD;IACS;IACY;IACpB,iBAAiB;KAChB,IAAI,WAAW,IAAI,KAAK,MAAM,4BAA4B,SAAS,CAAC;IACrE;GACA;EAEH;CACD,CAAC;AAEH,CAAC"}
@@ -2,7 +2,7 @@ import { expect } from "storybook/test";
2
2
  import { matchImageSnapshotAction, matchPageImageSnapshotAction, success, toTaskId } from "vitest-plugin-vis/client-api";
3
3
  import { setAutoSnapshotOptions as setAutoSnapshotOptions$1 } from "vitest-plugin-vis";
4
4
 
5
- //#region src/client/is_vitest_browser.ts
5
+ // src/client/is_vitest_browser.ts
6
6
  /**
7
7
  * Whether the code is running inside a Vitest browser-mode run.
8
8
  *
@@ -16,8 +16,7 @@ function isVitestBrowser() {
16
16
  return !!globalThis.__vitest_browser__;
17
17
  }
18
18
 
19
- //#endregion
20
- //#region src/client/page/to_match_image_snapshot.ts
19
+ // src/client/page/to_match_image_snapshot.ts
21
20
  function toMatchImageSnapshot$1(options) {
22
21
  const test = getCurrentTest();
23
22
  /* v8 ignore start: stub as success when not in a test (e.g. in a story) */
@@ -26,8 +25,7 @@ function toMatchImageSnapshot$1(options) {
26
25
  return matchPageImageSnapshotAction(commands, toTaskId(test), options);
27
26
  }
28
27
 
29
- //#endregion
30
- //#region src/client/vitest_proxy.ts
28
+ // src/client/vitest_proxy.ts
31
29
  /**
32
30
  * Build the `page` / `commands` / `cdp` / `getCurrentTest` proxies over `loaders`.
33
31
  *
@@ -45,12 +43,12 @@ function createVitestProxy(loaders) {
45
43
  vitest = m;
46
44
  }) : Promise.resolve();
47
45
  const ready = Promise.all([browserReady, vitestReady]).then(() => void 0);
48
- const page$1 = new Proxy({}, { get(_target, prop) {
46
+ const page = new Proxy({}, { get(_target, prop) {
49
47
  const r = (browserContext?.page)?.[prop];
50
48
  if (prop === "toMatchImageSnapshot" && r === void 0) return () => {};
51
49
  return r;
52
50
  } });
53
- const commands$1 = new Proxy({}, { get(_target, prop) {
51
+ const commands = new Proxy({}, { get(_target, prop) {
54
52
  if (!loaders) return void 0;
55
53
  if (browserContext) return browserContext.commands[prop];
56
54
  return (...args) => browserReady.then(() => browserContext.commands[prop](...args));
@@ -63,13 +61,13 @@ function createVitestProxy(loaders) {
63
61
  * Session calls made before the import settles wait for it (#835). CDP is
64
62
  * available only with the Playwright provider on Chromium.
65
63
  */
66
- const cdp$1 = () => {
64
+ const cdp = () => {
67
65
  if (!loaders) throw new Error("cdp() is only available in a Vitest browser run.");
68
66
  return new Proxy({}, { get(_target, prop) {
69
67
  return (...args) => browserReady.then(() => browserContext.cdp()[prop](...args));
70
68
  } });
71
69
  };
72
- const getCurrentTest$1 = () => vitest?.TestRunner.getCurrentTest();
70
+ const getCurrentTest = () => vitest?.TestRunner.getCurrentTest();
73
71
  /**
74
72
  * Resolves once the vitest modules behind `page`, `commands`, and
75
73
  * `getCurrentTest` are loaded.
@@ -79,10 +77,10 @@ function createVitestProxy(loaders) {
79
77
  */
80
78
  const whenReady = () => ready;
81
79
  return {
82
- page: page$1,
83
- commands: commands$1,
84
- cdp: cdp$1,
85
- getCurrentTest: getCurrentTest$1,
80
+ page,
81
+ commands,
82
+ cdp,
83
+ getCurrentTest,
86
84
  whenReady
87
85
  };
88
86
  }
@@ -96,8 +94,7 @@ const cdp = proxy.cdp;
96
94
  const getCurrentTest = proxy.getCurrentTest;
97
95
  const whenVitestProxyReady = proxy.whenReady;
98
96
 
99
- //#endregion
100
- //#region src/client/expect/to_match_image_snapshot.ts
97
+ // src/client/expect/to_match_image_snapshot.ts
101
98
  function toMatchImageSnapshot(subject, options) {
102
99
  const test = getCurrentTest();
103
100
  /* v8 ignore start: stub as success when not in a test (e.g. in a story) */
@@ -106,8 +103,7 @@ function toMatchImageSnapshot(subject, options) {
106
103
  return matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success);
107
104
  }
108
105
 
109
- //#endregion
110
- //#region src/client/storybook/tags.ts
106
+ // src/client/storybook/tags.ts
111
107
  function isSnapshotEnabled(tags) {
112
108
  const noSnapshotIndex = tags.lastIndexOf("!snapshot");
113
109
  const snapshotIndex = tags.lastIndexOf("snapshot");
@@ -115,8 +111,7 @@ function isSnapshotEnabled(tags) {
115
111
  return noSnapshotIndex < snapshotIndex;
116
112
  }
117
113
 
118
- //#endregion
119
- //#region src/preview/vis_annotation.ts
114
+ // src/preview/vis_annotation.ts
120
115
  let extended = false;
121
116
  const visAnnotations = { beforeEach(ctx) {
122
117
  if (!isVitestBrowser()) return;
@@ -133,6 +128,5 @@ const visAnnotations = { beforeEach(ctx) {
133
128
  });
134
129
  } };
135
130
 
136
- //#endregion
137
131
  export { commands as a, whenVitestProxyReady as c, cdp as i, isVitestBrowser as l, isSnapshotEnabled as n, getCurrentTest as o, toMatchImageSnapshot as r, page as s, visAnnotations as t };
138
- //# sourceMappingURL=vis_annotation-BHBO0X19.mjs.map
132
+ //# sourceMappingURL=vis_annotation-CJD3p9Uh.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vis_annotation-CJD3p9Uh.mjs","names":["toMatchImageSnapshot"],"sources":["../src/client/is_vitest_browser.ts","../src/client/page/to_match_image_snapshot.ts","../src/client/vitest_proxy.ts","../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/tags.ts","../src/preview/vis_annotation.ts"],"sourcesContent":["/**\n * Whether the code is running inside a Vitest browser-mode run.\n *\n * This is the signal the addon actually depends on: `commands` and `page` in\n * `vitest_proxy.ts` are only populated when `__vitest_browser__` is set, so any\n * broader \"am I under test\" check (such as one matching a `HeadlessChrome` user\n * agent) lets a plain headless browser reach the snapshot setup and fail on the\n * empty proxy with `commands.setupVisSuite is not a function`.\n */\nexport function isVitestBrowser() {\n\treturn !!(globalThis as any).__vitest_browser__\n}\n","import {\n\ttype ComparisonMethod,\n\tmatchPageImageSnapshotAction,\n\ttype ToMatchPageImageSnapshotOptions,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(\n\toptions?: ToMatchPageImageSnapshotOptions<M> | undefined,\n) {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve()\n\t/* v8 ignore end */\n\n\treturn matchPageImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type { BrowserCommands, BrowserPage, CDPSession } from 'vitest/browser'\nimport type { SnapshotTestMeta } from 'vitest-plugin-vis/client-api'\nimport { isVitestBrowser } from './is_vitest_browser.ts'\nimport { toMatchImageSnapshot } from './page/to_match_image_snapshot.ts'\n\ntype BrowserModule = Awaited<typeof import('vitest/browser')>\ntype VitestModule = Awaited<typeof import('vitest')>\n\n/**\n * How the proxy gets hold of the vitest modules.\n *\n * They are loaded dynamically because this module is also reached from a plain\n * Storybook preview, where `vitest` and `vitest/browser` are not available.\n * Passing `undefined` stands for \"not a vitest browser run\": nothing is loaded\n * and the proxies stay empty.\n */\nexport type VitestProxyLoaders = {\n\tloadBrowser: () => Promise<BrowserModule>\n\tloadVitest: () => Promise<VitestModule>\n}\n\n/**\n * Build the `page` / `commands` / `cdp` / `getCurrentTest` proxies over `loaders`.\n *\n * Exported for tests: it is the only way to observe the window between module\n * load and the dynamic imports settling.\n */\nexport function createVitestProxy(loaders: VitestProxyLoaders | undefined) {\n\tlet browserContext: BrowserModule | undefined\n\tlet vitest: VitestModule | undefined\n\n\tconst browserReady = loaders\n\t\t? loaders.loadBrowser().then((m) => {\n\t\t\t\tm.page.extend({ toMatchImageSnapshot })\n\t\t\t\tbrowserContext = m\n\t\t\t})\n\t\t: Promise.resolve()\n\tconst vitestReady = loaders\n\t\t? loaders.loadVitest().then((m) => {\n\t\t\t\tvitest = m\n\t\t\t})\n\t\t: Promise.resolve()\n\tconst ready = Promise.all([browserReady, vitestReady]).then(() => undefined)\n\n\tconst page = new Proxy<BrowserPage>({} as any, {\n\t\tget(_target, prop) {\n\t\t\tconst r = (browserContext?.page as any)?.[prop]\n\t\t\tif (prop === 'toMatchImageSnapshot' && r === undefined) {\n\t\t\t\treturn () => {}\n\t\t\t}\n\t\t\treturn r\n\t\t},\n\t})\n\n\tconst commands = new Proxy<BrowserCommands>({} as any, {\n\t\tget(_target, prop) {\n\t\t\t// Outside a vitest browser run there is nothing to wait for: keep\n\t\t\t// yielding `undefined` so the addon guards stay in charge (#829).\n\t\t\tif (!loaders) return undefined\n\t\t\tif (browserContext) return (browserContext.commands as any)[prop]\n\t\t\t// The import has not settled yet (#835). Commands are async RPC calls,\n\t\t\t// so hand back a function that waits for the module instead of\n\t\t\t// `undefined`, which fails as `<command> is not a function`.\n\t\t\treturn (...args: unknown[]) => browserReady.then(() => (browserContext!.commands as any)[prop](...args))\n\t\t},\n\t})\n\n\t/**\n\t * The Chrome DevTools Protocol session of the current test, like `cdp()` from\n\t * `vitest/browser`, but safe to import from code a plain Storybook preview\n\t * also loads.\n\t *\n\t * Session calls made before the import settles wait for it (#835). CDP is\n\t * available only with the Playwright provider on Chromium.\n\t */\n\tconst cdp = (): CDPSession => {\n\t\tif (!loaders) throw new Error('cdp() is only available in a Vitest browser run.')\n\t\treturn new Proxy<CDPSession>({} as any, {\n\t\t\tget(_target, prop) {\n\t\t\t\treturn (...args: unknown[]) => browserReady.then(() => (browserContext!.cdp() as any)[prop](...args))\n\t\t\t},\n\t\t})\n\t}\n\n\tconst getCurrentTest = () =>\n\t\tvitest?.TestRunner.getCurrentTest() as\n\t\t\t| (ReturnType<VitestModule['TestRunner']['getCurrentTest']> & SnapshotTestMeta)\n\t\t\t| undefined\n\n\t/**\n\t * Resolves once the vitest modules behind `page`, `commands`, and\n\t * `getCurrentTest` are loaded.\n\t *\n\t * `page` and `getCurrentTest` are read synchronously, so hooks that depend on\n\t * them must await this first (#835).\n\t */\n\tconst whenReady = () => ready\n\n\treturn { page, commands, cdp, getCurrentTest, whenReady }\n}\n\nconst proxy = createVitestProxy(\n\tisVitestBrowser() ? { loadBrowser: () => import('vitest/browser'), loadVitest: () => import('vitest') } : undefined,\n)\n\nexport const page = proxy.page\nexport const commands = proxy.commands\nexport const cdp = proxy.cdp\nexport const getCurrentTest = proxy.getCurrentTest\nexport const whenVitestProxyReady = proxy.whenReady\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\tmatchImageSnapshotAction,\n\tsuccess,\n\ttype ToMatchImageSnapshotOptions,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod>(\n\t/**\n\t * The element or locator to take the snapshot of,\n\t * or the base64 value of the image to compare against.\n\t */\n\tsubject: any,\n\toptions?: ToMatchImageSnapshotOptions<M> | undefined,\n): AsyncExpectationResult {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve(success)\n\t/* v8 ignore end */\n\n\treturn matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success)\n}\n","export function isSnapshotEnabled(tags: string[]) {\n\tconst noSnapshotIndex = tags.lastIndexOf('!snapshot')\n\tconst snapshotIndex = tags.lastIndexOf('snapshot')\n\n\tif (noSnapshotIndex < 0 && snapshotIndex < 0) return false\n\n\treturn noSnapshotIndex < snapshotIndex\n}\n","import type { NamedOrDefaultProjectAnnotations } from 'storybook/internal/types'\nimport { expect } from 'storybook/test'\nimport { setAutoSnapshotOptions } from 'vitest-plugin-vis'\nimport { toMatchImageSnapshot } from '../client/expect/to_match_image_snapshot.ts'\nimport { isVitestBrowser } from '../client/is_vitest_browser.ts'\nimport { isSnapshotEnabled } from '../client/storybook/tags.ts'\nimport { getCurrentTest } from '../client/vitest_proxy.ts'\n\nlet extended = false\n\nexport const visAnnotations = {\n\tbeforeEach(ctx) {\n\t\tif (!isVitestBrowser()) return\n\t\tif (!extended) {\n\t\t\texpect.extend({ toMatchImageSnapshot })\n\t\t\textended = true\n\t\t}\n\t\tconst test = getCurrentTest()\n\n\t\tsetAutoSnapshotOptions({\n\t\t\tenable: isSnapshotEnabled(ctx.tags),\n\t\t\t...ctx.parameters?.snapshot,\n\t\t\ttags: ctx.tags,\n\t\t\t...test?.meta.vis,\n\t\t})\n\t},\n} satisfies NamedOrDefaultProjectAnnotations<any>\n"],"mappings":";;;;;;;;;;;;;;AASA,SAAgB,kBAAkB;CACjC,OAAO,CAAC,CAAE,WAAmB;AAC9B;;;ACHA,SAAgBA,uBACf,SACC;CACD,MAAM,OAAO,eAAe;;CAG5B,IAAI,CAAC,MAAM,OAAO,QAAQ,QAAQ;;CAGlC,OAAO,6BAA6B,UAAU,SAAS,IAAI,GAAG,OAAO;AACtE;;;;;;;;;ACSA,SAAgB,kBAAkB,SAAyC;CAC1E,IAAI;CACJ,IAAI;CAEJ,MAAM,eAAe,UAClB,QAAQ,YAAY,CAAC,CAAC,MAAM,MAAM;EAClC,EAAE,KAAK,OAAO,EAAE,6CAAqB,CAAC;EACtC,iBAAiB;CAClB,CAAC,IACA,QAAQ,QAAQ;CACnB,MAAM,cAAc,UACjB,QAAQ,WAAW,CAAC,CAAC,MAAM,MAAM;EACjC,SAAS;CACV,CAAC,IACA,QAAQ,QAAQ;CACnB,MAAM,QAAQ,QAAQ,IAAI,CAAC,cAAc,WAAW,CAAC,CAAC,CAAC,WAAW,MAAS;CAE3E,MAAM,OAAO,IAAI,MAAmB,CAAC,GAAU,EAC9C,IAAI,SAAS,MAAM;EAClB,MAAM,KAAK,gBAA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BAAgB,KAAK,YAAY,UAAU;CAEjD,IAAI,kBAAkB,KAAK,gBAAgB,GAAG,OAAO;CAErD,OAAO,kBAAkB;AAC1B;;;ACCA,IAAI,WAAW;AAEf,MAAa,iBAAiB,EAC7B,WAAW,KAAK;CACf,IAAI,CAAC,gBAAgB,GAAG;CACxB,IAAI,CAAC,UAAU;EACd,OAAO,OAAO,EAAE,qBAAqB,CAAC;EACtC,WAAW;CACZ;CACA,MAAM,OAAO,eAAe;CAE5B,yBAAuB;EACtB,QAAQ,kBAAkB,IAAI,IAAI;EAClC,GAAG,IAAI,YAAY;EACnB,MAAM,IAAI;EACV,GAAG,MAAM,KAAK;CACf,CAAC;AACF,EACD"}
@@ -0,0 +1,5 @@
1
+ declare const visAnnotations: {
2
+ beforeEach(ctx: import("storybook/internal/csf").StoryContext<any, import("storybook/internal/csf").Args>): void;
3
+ };
4
+ export { visAnnotations as t };
5
+ //# sourceMappingURL=vis_annotation-DJqDOBIl.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vis_annotation-DJqDOBIl.d.mts","names":[],"sources":["../src/preview/vis_annotation.ts"],"mappings":"A,cAUa"}
package/llms.txt CHANGED
@@ -31,7 +31,7 @@ Import from the entry points listed below, not from package internals. Documenta
31
31
  - [storybook-addon-vis: Releases/Migrating to 1.0](https://repobuddy.github.io/visual-testing/releases/migrate-to-1/): storybook-addon-vis 1.0 has made some major improvements over the previous version.
32
32
  - [storybook-addon-vis: Releases/Migrating to 3.0](https://repobuddy.github.io/visual-testing/releases/migrate-to-3/): storybook-addon-vis 3.0.0 supports Storybook 10.
33
33
  - [storybook-addon-vis: Reviewing failures (addon view)](https://repobuddy.github.io/visual-testing/addon/guides/reviewing-failures/): Find what changed when a story snapshot fails.
34
- - [storybook-addon-vis: Setup](https://repobuddy.github.io/visual-testing/addon/configuration/): Configure Storybook, Vitest, TypeScript and .gitignore for storybook-addon-vis. Documents: cdp, default, defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, page, visAnnotations, experimental_serverChannel, storybookVis, vis.
34
+ - [storybook-addon-vis: Setup](https://repobuddy.github.io/visual-testing/addon/configuration/): Configure Storybook, Vitest, TypeScript and .gitignore for storybook-addon-vis. Documents: cdp, commands, default, defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, page, visAnnotations, experimental_serverChannel, storybookVis, vis.
35
35
  - [storybook-addon-vis: The Vis panel](https://repobuddy.github.io/visual-testing/addon/guides/the-vis-panel/): Review baseline, result and diff of a story inside Storybook.
36
36
  - [storybook-addon-vis: Themes](https://repobuddy.github.io/visual-testing/addon/guides/themes/): Take every snapshot once per theme, such as light and dark.
37
37
  - [storybook-addon-vis: Thresholds and comparison for stories](https://repobuddy.github.io/visual-testing/addon/guides/thresholds-and-comparison/): Tolerate small differences and pick pixel or SSIM comparison for stories.
@@ -57,7 +57,7 @@ Import from the entry points listed below, not from package internals. Documenta
57
57
 
58
58
  ## Entry points
59
59
 
60
- - [`storybook-addon-vis`](https://github.com/repobuddy/visual-testing/blob/main/packages/storybook-addon-vis/src/index.ts): default export; functions: defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, setAutoSnapshotOptions; types: AnimationsOptions, Awaitable, ComparisonMethod, FailureThresholdOptions, ImageSnapshotCompareOptions, ImageSnapshotComparisonInfo, ImageSnapshotKeyOptions, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, MaskLocator, MaskOptions, MatchImageSnapshotOptions, MetaTask, PageImageSnapshotOptions, PixelComparisonOptions, PixelDiffOptions, ReviewImageOptions, SetupVisOptions, SnapshotTestMeta, SsimComparisonOptions, SsimDiffOptions, ToMatchImageSnapshotOptions, ToMatchPageImageSnapshotOptions; values: cdp, page, visAnnotations (31 exports, 31 with a documentation page).
60
+ - [`storybook-addon-vis`](https://github.com/repobuddy/visual-testing/blob/main/packages/storybook-addon-vis/src/index.ts): default export; functions: defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, setAutoSnapshotOptions; types: AnimationsOptions, Awaitable, ComparisonMethod, FailureThresholdOptions, ImageSnapshotCompareOptions, ImageSnapshotComparisonInfo, ImageSnapshotKeyOptions, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, MaskLocator, MaskOptions, MatchImageSnapshotOptions, MetaTask, PageImageSnapshotOptions, PixelComparisonOptions, PixelDiffOptions, ReviewImageOptions, SetupVisOptions, SnapshotTestMeta, SsimComparisonOptions, SsimDiffOptions, ToMatchImageSnapshotOptions, ToMatchPageImageSnapshotOptions; values: cdp, commands, page, visAnnotations (32 exports, 32 with a documentation page).
61
61
  - [`storybook-addon-vis/manager`](https://github.com/repobuddy/visual-testing/blob/main/packages/storybook-addon-vis/src/exports/manager.tsx): no named exports; it is imported for its side effects.
62
62
  - [`storybook-addon-vis/matcher`](https://github.com/repobuddy/visual-testing/blob/main/packages/storybook-addon-vis/src/exports/matcher.ts): no named exports; it is imported for its side effects.
63
63
  - [`storybook-addon-vis/node`](https://github.com/repobuddy/visual-testing/blob/main/packages/storybook-addon-vis/src/exports/node.ts): functions: defineStorybookVis, defineStorybookVisOptions (2 exports, 2 with a documentation page).
@@ -70,4 +70,4 @@ Import from the entry points listed below, not from package internals. Documenta
70
70
  - [storybook-addon-vis: Changelog](https://repobuddy.github.io/visual-testing/releases/changelog-addon/): Release history of storybook-addon-vis.
71
71
  - [Generator](https://github.com/repobuddy/visual-testing/blob/main/packages/storybook-addon-vis/scripts/generate-llms-txt.mjs): Source of this file. Run it with `--gaps` to list the undocumented exports.
72
72
 
73
- Documentation coverage: 37 of 37 distinct exported declarations are named on a documentation page; 7 carry a doc comment.
73
+ Documentation coverage: 38 of 38 distinct exported declarations are named on a documentation page; 7 carry a doc comment.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-vis",
3
- "version": "4.6.0",
3
+ "version": "4.7.0",
4
4
  "description": "Storybook Vitest visual testing addon",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -70,7 +70,7 @@
70
70
  "memoize": "^11.0.0",
71
71
  "pathe": "^2.0.3",
72
72
  "type-plus": "8.0.1",
73
- "vitest-plugin-vis": "^5.5.0"
73
+ "vitest-plugin-vis": "^5.6.0"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@repobuddy/storybook": "^2.33.4",
@@ -99,12 +99,12 @@
99
99
  "storybook": "^10.5.10",
100
100
  "storybook-addon-tag-badges": "^3.1.0",
101
101
  "tailwindcss": "^4.3.3",
102
- "tsdown": "^0.19.0",
102
+ "tsdown": "^0.23.0",
103
103
  "typescript": "^6.0.3",
104
104
  "vite": "^8.2.2",
105
105
  "vitest": "^4.1.11",
106
106
  "vitest-browser-react": "^2.2.0",
107
- "webdriverio": "latest",
107
+ "webdriverio": "^9.33.1",
108
108
  "zx": "^8.8.5"
109
109
  },
110
110
  "peerDependencies": {
@@ -10,7 +10,7 @@ An agent loads it when a visual test fails with a `Snapshot ... mismatched` erro
10
10
 
11
11
  1. Reads the error message: pixel count, size change, changed regions, image paths.
12
12
  2. Opens the review image, not the full Expected, Actual, or Difference images.
13
- 3. Opens a full image only when the message says the review image was skipped.
13
+ 3. Opens a full image only when the review image shows the whole images instead of crops.
14
14
  4. Updates a baseline (`-u`) only for an intended change, and reports rendering drift instead.
15
15
 
16
16
  ## Install
@@ -18,7 +18,7 @@ Snapshots live under `__vis__/`: `__baselines__` is expected, `__results__` is t
18
18
 
19
19
  1. **Read the error message first.** It gives the pixel count, any size change, the changed regions (`Changed:`), and the image paths. It is text and costs little.
20
20
  2. **Open the review image** (`Review:`), not the full images. For each region it shows Expected, Actual, and the changed pixels in red, side by side. Open the full Expected, Actual, or Difference image only if the review image leaves the question open.
21
- 3. **If the message says the review image was skipped, read why.**
21
+ 3. **If the `Review:` line says `diff of the whole image`, open one full image instead.** That review image holds the three whole images, so it costs more than any one of them. When cropping did not help, the line also says why (`not cropped, <reason>`).
22
22
  - The image size changed: open only the Actual image. A size change means the layout changed.
23
23
  - Too many regions, or they cover most of the image: open the Difference image. Red pixels changed; yellow pixels are anti-aliasing and do not count. Open Expected and Actual only if the Difference image does not show what changed.
24
24
  4. **If there is no `Review:` line**, the review image is turned off (`reviewImage: false`). The `Changed:` line still gives each region. Crop Expected and Actual to those regions with any image tool available, and open the crops.
package/src/index.ts CHANGED
@@ -19,7 +19,7 @@ export * from './client/has_image_snapshot.ts'
19
19
  export * from './client/storybook/param.ts'
20
20
  export * from './client/storybook/tags.ts'
21
21
 
22
- export { cdp, page, visAnnotations }
22
+ export { cdp, commands, page, visAnnotations }
23
23
 
24
24
  export default (options: SetupVisOptions<{ tags: string[] }> = { auto: false }) => {
25
25
  let matcher: ReturnType<typeof autoSnapshotMatcher>
package/src/overview.mdx CHANGED
@@ -585,6 +585,22 @@ Pass it to `definePreview({ addons: [addonVis({ auto: true })] })`.
585
585
  `storybook-addon-vis/preset` exports `experimental_serverChannel`, which Storybook calls so that the Vis panel can read the snapshot images.
586
586
  You do not call it yourself.
587
587
 
588
+ ## Usage - custom browser commands
589
+
590
+ `commands` is a proxy of `commands` from `vitest/browser`.
591
+ Use it to call [custom browser commands](https://vitest.dev/api/browser/commands.html) from a story.
592
+ Like `page`, it is safe to import in a plain Storybook preview, where its commands are `undefined`.
593
+
594
+ ```tsx
595
+ import { commands } from 'storybook-addon-vis'
596
+
597
+ export const WithCommand = {
598
+ async play() {
599
+ await commands.myCommand?.()
600
+ }
601
+ }
602
+ ```
603
+
588
604
  ## Usage - Chrome DevTools Protocol
589
605
 
590
606
  `cdp` is a proxy of `cdp()` from `vitest/browser`.
@@ -9,7 +9,7 @@ Images are the most expensive input an agent reads.
9
9
  This page shows what each view costs and the order in which an agent should look.
10
10
 
11
11
  In short: read the error message, then open the review image instead of the full images.
12
- Open the Actual or Difference image only when the message says the review image was skipped.
12
+ When the message says the review image is not cropped, open the Actual or Difference image instead: they cost less.
13
13
 
14
14
  ## What a failure gives you
15
15
 
@@ -44,14 +44,18 @@ The review image places, for each region, the Expected crop, the Actual crop, an
44
44
  The diff crop shows the baseline in gray at full contrast with the changed pixels in red,
45
45
  so small text in the changed area stays readable.
46
46
 
47
- The review image is skipped when cropping does not help:
48
- the image size changed, there are more than 5 regions, or the regions cover more than half of the image.
49
- The `Review:` line then says so, and why:
47
+ Cropping does not help when the image size changed, there are more than 5 regions,
48
+ the regions cover more than half of the image, or no region is found.
49
+ The review image then places the whole Expected, Actual, and diff side by side, and the `Review:` line says why:
50
50
 
51
51
  ```
52
- Review: skipped, the image size changed; open Actual or Difference instead
52
+ Review: ./__vis__/linux/__diffs__/button.stories.tsx/primary.review.png (baseline, result, diff of the whole image; not cropped, the image size changed)
53
53
  ```
54
54
 
55
+ The whole-image review is for a person browsing the `__diffs__` folder.
56
+ It holds three full images, so an agent spends fewer tokens on the Actual or Difference image alone.
57
+ `reviewImage: 'full'` writes the whole-image review for every failure.
58
+
55
59
  The regions are also written next to the diff, as `primary.regions.json`:
56
60
  `{ "width": 1280, "height": 720, "regions": [{ "x": 0, "y": 0, "width": 106, "height": 37 }] }`.
57
61
  Tools and UIs read this file to zoom to the changes; an agent gets the same data from the `Changed:` line.
@@ -103,17 +107,17 @@ Across 109 failing comparisons from this repository (see [How this was measured]
103
107
  <tbody>
104
108
  <tr><td>Expected and Actual</td><td>79,396</td><td>28,902</td><td>6,032</td></tr>
105
109
  <tr><td>Difference only</td><td>39,698 (2.0× less)</td><td>14,451 (2.0× less)</td><td>4,784 (1.3× less)</td></tr>
106
- <tr><td>Review image, or the fallback below when it is skipped</td><td>667 (119× less)</td><td>350 (83× less)</td><td>3,016 (2.0× less)</td></tr>
110
+ <tr><td>Review image, or the fallback below when it is not cropped</td><td>667 (119× less)</td><td>350 (83× less)</td><td>3,016 (2.0× less)</td></tr>
107
111
  </tbody>
108
112
  </table>
109
113
 
110
114
  Three things stand out:
111
115
 
112
- - The plugin wrote a review image for 101 of the 109 comparisons: all 66 full pages and 35 of the 39 components.
116
+ - The plugin wrote a cropped review image for 101 of the 109 comparisons: all 66 full pages and 35 of the 39 components.
113
117
  The largest one costs 20 tokens.
114
- - It skipped 4 components because the change covers 84% of an 86 × 36 image.
118
+ - It did not crop 4 components because the change covers 84% of an 86 × 36 image.
115
119
  The agent opens the Difference image instead, which costs 8 tokens each.
116
- - It skipped all 4 size changes. The Difference image is padded to the larger image and most of it shows the padding,
120
+ - It did not crop all 4 size changes. The Difference image is padded to the larger image and most of it shows the padding,
117
121
  so the agent opens only the Actual image.
118
122
 
119
123
  ## What the agent should do
@@ -125,7 +129,7 @@ It gives the pixel count, any size change, the changed regions, and the image pa
125
129
  For each region, it shows Expected, Actual, and the changed pixels in red, side by side.
126
130
  Do not open the full Expected, Actual, or Difference images unless the review image leaves the question open.
127
131
 
128
- **3. If the message says the review image was skipped, read why.**
132
+ **3. If the message says the review image is not cropped, read why, and open one full image instead.**
129
133
 
130
134
  - The image size changed: open only the Actual image.
131
135
  A size change means the layout changed, and the Actual image shows the new layout.
@@ -156,7 +160,7 @@ When a `toMatchImageSnapshot` assertion fails:
156
160
  the changed regions (`Changed:`), and the image paths.
157
161
  2. Open the review image (`Review:`), not the full images.
158
162
  For each region it shows Expected, Actual, and the changed pixels in red.
159
- 3. If the message says the review image was skipped:
163
+ 3. If the message says the review image is not cropped:
160
164
  - the image size changed: open only the Actual image.
161
165
  - otherwise: open the Difference image. Red pixels changed.
162
166
  Yellow pixels are anti-aliasing and do not count.
@@ -185,7 +189,7 @@ full pages, 1280 px wide; and components, everything else.
185
189
 
186
190
  For each pair, the script pads both images to the same size, as this plugin does,
187
191
  and runs the plugin's own code to compare them with default options,
188
- find the changed regions, decide whether to skip the review image, and build it.
192
+ find the changed regions, decide whether to crop the review image, and build the cropped one.
189
193
  It then computes the token cost of each view with the formula above.
190
194
  The 9 identical pairs are left out.
191
195
 
@@ -203,4 +207,4 @@ Limits of this measurement:
203
207
  - The token counts are computed from Anthropic's published formula, not read from API usage.
204
208
  - It measures cost, not whether the agent reaches the right decision from each view.
205
209
  - Most of the changes are small text-rendering differences, and every comparison has one changed region.
206
- A change that spreads across a page gives a larger review image, or skips it.
210
+ A change that spreads across a page gives a larger review image, or an uncropped one.
@@ -1,7 +0,0 @@
1
- //#region src/shared/constants.ts
2
- const NAME = "storybook-addon-vis";
3
- const VIS_PANEL_ID = `${NAME}/vis_panel`;
4
-
5
- //#endregion
6
- export { NAME as t };
7
- //# sourceMappingURL=constants-D_WcloLE.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants-D_WcloLE.mjs","names":[],"sources":["../../src/shared/constants.ts"],"sourcesContent":["export const NAME = 'storybook-addon-vis'\nexport const VIS_PANEL_ID = `${NAME}/vis_panel`\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,eAAe,GAAG,KAAK"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-CuNXsk6J.d.mts","names":[],"sources":["../../src/server/types.ts"],"sourcesContent":[],"mappings":";;AAOA;;;;;;KAAY,mBAAA;eACE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"global_matcher_augment-B1plNA_9.d.mts","names":[],"sources":["../src/shared/global_matcher_augment.ts"],"sourcesContent":[],"mappings":";;;;;IAEwE,UAAA,QAAA,CAAA,CAAA,EAAA,CAAA,CAAA,SAIrC,oBAJqC,CAAA,CAAA;EAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"vis_annotation-BHBO0X19.mjs","names":["toMatchImageSnapshot","page","commands","cdp","getCurrentTest"],"sources":["../src/client/is_vitest_browser.ts","../src/client/page/to_match_image_snapshot.ts","../src/client/vitest_proxy.ts","../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/tags.ts","../src/preview/vis_annotation.ts"],"sourcesContent":["/**\n * Whether the code is running inside a Vitest browser-mode run.\n *\n * This is the signal the addon actually depends on: `commands` and `page` in\n * `vitest_proxy.ts` are only populated when `__vitest_browser__` is set, so any\n * broader \"am I under test\" check (such as one matching a `HeadlessChrome` user\n * agent) lets a plain headless browser reach the snapshot setup and fail on the\n * empty proxy with `commands.setupVisSuite is not a function`.\n */\nexport function isVitestBrowser() {\n\treturn !!(globalThis as any).__vitest_browser__\n}\n","import {\n\ttype ComparisonMethod,\n\tmatchPageImageSnapshotAction,\n\ttype ToMatchPageImageSnapshotOptions,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(\n\toptions?: ToMatchPageImageSnapshotOptions<M> | undefined,\n) {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve()\n\t/* v8 ignore end */\n\n\treturn matchPageImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type { BrowserCommands, BrowserPage, CDPSession } from 'vitest/browser'\nimport type { SnapshotTestMeta } from 'vitest-plugin-vis/client-api'\nimport { isVitestBrowser } from './is_vitest_browser.ts'\nimport { toMatchImageSnapshot } from './page/to_match_image_snapshot.ts'\n\ntype BrowserModule = Awaited<typeof import('vitest/browser')>\ntype VitestModule = Awaited<typeof import('vitest')>\n\n/**\n * How the proxy gets hold of the vitest modules.\n *\n * They are loaded dynamically because this module is also reached from a plain\n * Storybook preview, where `vitest` and `vitest/browser` are not available.\n * Passing `undefined` stands for \"not a vitest browser run\": nothing is loaded\n * and the proxies stay empty.\n */\nexport type VitestProxyLoaders = {\n\tloadBrowser: () => Promise<BrowserModule>\n\tloadVitest: () => Promise<VitestModule>\n}\n\n/**\n * Build the `page` / `commands` / `cdp` / `getCurrentTest` proxies over `loaders`.\n *\n * Exported for tests: it is the only way to observe the window between module\n * load and the dynamic imports settling.\n */\nexport function createVitestProxy(loaders: VitestProxyLoaders | undefined) {\n\tlet browserContext: BrowserModule | undefined\n\tlet vitest: VitestModule | undefined\n\n\tconst browserReady = loaders\n\t\t? loaders.loadBrowser().then((m) => {\n\t\t\t\tm.page.extend({ toMatchImageSnapshot })\n\t\t\t\tbrowserContext = m\n\t\t\t})\n\t\t: Promise.resolve()\n\tconst vitestReady = loaders\n\t\t? loaders.loadVitest().then((m) => {\n\t\t\t\tvitest = m\n\t\t\t})\n\t\t: Promise.resolve()\n\tconst ready = Promise.all([browserReady, vitestReady]).then(() => undefined)\n\n\tconst page = new Proxy<BrowserPage>({} as any, {\n\t\tget(_target, prop) {\n\t\t\tconst r = (browserContext?.page as any)?.[prop]\n\t\t\tif (prop === 'toMatchImageSnapshot' && r === undefined) {\n\t\t\t\treturn () => {}\n\t\t\t}\n\t\t\treturn r\n\t\t},\n\t})\n\n\tconst commands = new Proxy<BrowserCommands>({} as any, {\n\t\tget(_target, prop) {\n\t\t\t// Outside a vitest browser run there is nothing to wait for: keep\n\t\t\t// yielding `undefined` so the addon guards stay in charge (#829).\n\t\t\tif (!loaders) return undefined\n\t\t\tif (browserContext) return (browserContext.commands as any)[prop]\n\t\t\t// The import has not settled yet (#835). Commands are async RPC calls,\n\t\t\t// so hand back a function that waits for the module instead of\n\t\t\t// `undefined`, which fails as `<command> is not a function`.\n\t\t\treturn (...args: unknown[]) => browserReady.then(() => (browserContext!.commands as any)[prop](...args))\n\t\t},\n\t})\n\n\t/**\n\t * The Chrome DevTools Protocol session of the current test, like `cdp()` from\n\t * `vitest/browser`, but safe to import from code a plain Storybook preview\n\t * also loads.\n\t *\n\t * Session calls made before the import settles wait for it (#835). CDP is\n\t * available only with the Playwright provider on Chromium.\n\t */\n\tconst cdp = (): CDPSession => {\n\t\tif (!loaders) throw new Error('cdp() is only available in a Vitest browser run.')\n\t\treturn new Proxy<CDPSession>({} as any, {\n\t\t\tget(_target, prop) {\n\t\t\t\treturn (...args: unknown[]) => browserReady.then(() => (browserContext!.cdp() as any)[prop](...args))\n\t\t\t},\n\t\t})\n\t}\n\n\tconst getCurrentTest = () =>\n\t\tvitest?.TestRunner.getCurrentTest() as\n\t\t\t| (ReturnType<VitestModule['TestRunner']['getCurrentTest']> & SnapshotTestMeta)\n\t\t\t| undefined\n\n\t/**\n\t * Resolves once the vitest modules behind `page`, `commands`, and\n\t * `getCurrentTest` are loaded.\n\t *\n\t * `page` and `getCurrentTest` are read synchronously, so hooks that depend on\n\t * them must await this first (#835).\n\t */\n\tconst whenReady = () => ready\n\n\treturn { page, commands, cdp, getCurrentTest, whenReady }\n}\n\nconst proxy = createVitestProxy(\n\tisVitestBrowser() ? { loadBrowser: () => import('vitest/browser'), loadVitest: () => import('vitest') } : undefined,\n)\n\nexport const page = proxy.page\nexport const commands = proxy.commands\nexport const cdp = proxy.cdp\nexport const getCurrentTest = proxy.getCurrentTest\nexport const whenVitestProxyReady = proxy.whenReady\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\tmatchImageSnapshotAction,\n\tsuccess,\n\ttype ToMatchImageSnapshotOptions,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod>(\n\t/**\n\t * The element or locator to take the snapshot of,\n\t * or the base64 value of the image to compare against.\n\t */\n\tsubject: any,\n\toptions?: ToMatchImageSnapshotOptions<M> | undefined,\n): AsyncExpectationResult {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve(success)\n\t/* v8 ignore end */\n\n\treturn matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success)\n}\n","export function isSnapshotEnabled(tags: string[]) {\n\tconst noSnapshotIndex = tags.lastIndexOf('!snapshot')\n\tconst snapshotIndex = tags.lastIndexOf('snapshot')\n\n\tif (noSnapshotIndex < 0 && snapshotIndex < 0) return false\n\n\treturn noSnapshotIndex < snapshotIndex\n}\n","import type { NamedOrDefaultProjectAnnotations } from 'storybook/internal/types'\nimport { expect } from 'storybook/test'\nimport { setAutoSnapshotOptions } from 'vitest-plugin-vis'\nimport { toMatchImageSnapshot } from '../client/expect/to_match_image_snapshot.ts'\nimport { isVitestBrowser } from '../client/is_vitest_browser.ts'\nimport { isSnapshotEnabled } from '../client/storybook/tags.ts'\nimport { getCurrentTest } from '../client/vitest_proxy.ts'\n\nlet extended = false\n\nexport const visAnnotations = {\n\tbeforeEach(ctx) {\n\t\tif (!isVitestBrowser()) return\n\t\tif (!extended) {\n\t\t\texpect.extend({ toMatchImageSnapshot })\n\t\t\textended = true\n\t\t}\n\t\tconst test = getCurrentTest()\n\n\t\tsetAutoSnapshotOptions({\n\t\t\tenable: isSnapshotEnabled(ctx.tags),\n\t\t\t...ctx.parameters?.snapshot,\n\t\t\ttags: ctx.tags,\n\t\t\t...test?.meta.vis,\n\t\t})\n\t},\n} satisfies NamedOrDefaultProjectAnnotations<any>\n"],"mappings":";;;;;;;;;;;;;;AASA,SAAgB,kBAAkB;AACjC,QAAO,CAAC,CAAE,WAAmB;;;;;ACF9B,SAAgBA,uBACf,SACC;CACD,MAAM,OAAO,gBAAgB;;AAG7B,KAAI,CAAC,KAAM,QAAO,QAAQ,SAAS;;AAGnC,QAAO,6BAA6B,UAAU,SAAS,KAAK,EAAE,QAAQ;;;;;;;;;;;ACUvE,SAAgB,kBAAkB,SAAyC;CAC1E,IAAI;CACJ,IAAI;CAEJ,MAAM,eAAe,UAClB,QAAQ,aAAa,CAAC,MAAM,MAAM;AAClC,IAAE,KAAK,OAAO,EAAE,8CAAsB,CAAC;AACvC,mBAAiB;GAChB,GACD,QAAQ,SAAS;CACpB,MAAM,cAAc,UACjB,QAAQ,YAAY,CAAC,MAAM,MAAM;AACjC,WAAS;GACR,GACD,QAAQ,SAAS;CACpB,MAAM,QAAQ,QAAQ,IAAI,CAAC,cAAc,YAAY,CAAC,CAAC,WAAW,OAAU;CAE5E,MAAMC,SAAO,IAAI,MAAmB,EAAE,EAAS,EAC9C,IAAI,SAAS,MAAM;EAClB,MAAM,KAAK,gBAAgB,QAAe;AAC1C,MAAI,SAAS,0BAA0B,MAAM,OAC5C,cAAa;AAEd,SAAO;IAER,CAAC;CAEF,MAAMC,aAAW,IAAI,MAAuB,EAAE,EAAS,EACtD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AAiB,CAAE;AACxB,KAAI,CAAC,UAAU;AACd,SAAO,OAAO,EAAE,sBAAsB,CAAC;AACvC,aAAW;;CAEZ,MAAM,OAAO,gBAAgB;AAE7B,0BAAuB;EACtB,QAAQ,kBAAkB,IAAI,KAAK;EACnC,GAAG,IAAI,YAAY;EACnB,MAAM,IAAI;EACV,GAAG,MAAM,KAAK;EACd,CAAC;GAEH"}
@@ -1,9 +0,0 @@
1
- import * as storybook_internal_csf1 from "storybook/internal/csf";
2
-
3
- //#region src/preview/vis_annotation.d.ts
4
- declare const visAnnotations: {
5
- beforeEach(ctx: storybook_internal_csf1.StoryContext<any, storybook_internal_csf1.Args>): void;
6
- };
7
- //#endregion
8
- export { visAnnotations as t };
9
- //# sourceMappingURL=vis_annotation-N0xbuXis.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vis_annotation-N0xbuXis.d.mts","names":[],"sources":["../src/preview/vis_annotation.ts"],"sourcesContent":[],"mappings":";;;cAUa;kBAgBoC,uBAAA,CAAA,kBAAA,uBAAA,CAAA,IAAA"}