vite-plugin-storybook-nextjs 0.0.12 → 0.0.13--canary.8.c64d6ac.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 (31) hide show
  1. package/dist/index.cjs +934 -0
  2. package/dist/index.d.cts +12 -0
  3. package/dist/index.js +62 -89
  4. package/dist/mocks/storybook.global.cjs +69 -0
  5. package/dist/mocks/storybook.global.d.cts +2 -0
  6. package/dist/mocks/storybook.global.js +49 -2
  7. package/dist/plugins/next-image/alias/image-context.cjs +8 -0
  8. package/dist/plugins/next-image/alias/image-context.d.cts +13 -0
  9. package/dist/plugins/next-image/alias/image-default-loader.cjs +40 -0
  10. package/dist/plugins/next-image/alias/image-default-loader.d.cts +5 -0
  11. package/dist/plugins/next-image/alias/next-image.cjs +53 -0
  12. package/dist/plugins/next-image/alias/next-image.d.cts +30 -0
  13. package/dist/plugins/next-image/alias/next-image.d.ts +1 -1
  14. package/dist/plugins/next-image/alias/next-legacy-image.cjs +27 -0
  15. package/dist/plugins/next-image/alias/next-legacy-image.d.cts +6 -0
  16. package/dist/plugins/next-mocks/alias/cache/index.cjs +30 -0
  17. package/dist/plugins/next-mocks/alias/cache/index.d.cts +16 -0
  18. package/dist/plugins/next-mocks/alias/headers/cookies.cjs +94 -0
  19. package/dist/plugins/next-mocks/alias/headers/cookies.d.cts +14 -0
  20. package/dist/plugins/next-mocks/alias/headers/cookies.d.ts +1 -1
  21. package/dist/plugins/next-mocks/alias/headers/headers.cjs +40 -0
  22. package/dist/plugins/next-mocks/alias/headers/headers.d.cts +21 -0
  23. package/dist/plugins/next-mocks/alias/headers/index.cjs +94 -0
  24. package/dist/plugins/next-mocks/alias/headers/index.d.cts +11 -0
  25. package/dist/plugins/next-mocks/alias/navigation/index.cjs +112 -0
  26. package/dist/plugins/next-mocks/alias/navigation/index.d.cts +38 -0
  27. package/dist/plugins/next-mocks/alias/router/index.cjs +141 -0
  28. package/dist/plugins/next-mocks/alias/router/index.d.cts +45 -0
  29. package/dist/plugins/next-mocks/alias/rsc/server-only.cjs +6 -0
  30. package/dist/plugins/next-mocks/alias/rsc/server-only.d.cts +3 -0
  31. package/package.json +22 -3
@@ -0,0 +1,12 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ type VitePluginOptions = {
4
+ /**
5
+ * Provide the path to your Next.js project directory
6
+ * @default process.cwd()
7
+ */
8
+ dir?: string;
9
+ };
10
+ declare function VitePlugin({ dir }?: VitePluginOptions): Plugin[];
11
+
12
+ export { VitePlugin as default };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import path, { resolve, join } from 'node:path';
2
2
  import { createRequire } from 'node:module';
3
3
  import { getDefineEnv } from 'next/dist/build/webpack/plugins/define-env-plugin.js';
4
4
  import fs3 from 'node:fs';
5
- import nextEnv from '@next/env';
5
+ import { loadEnvConfig } from '@next/env';
6
6
  import Log from 'next/dist/build/output/log.js';
7
7
  import { transform, loadBindings, lockfilePatchPromise } from 'next/dist/build/swc/index.js';
8
8
  import { PHASE_DEVELOPMENT_SERVER, PHASE_TEST, PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants.js';
@@ -21,16 +21,9 @@ import { getParserOptions } from 'next/dist/build/swc/options.js';
21
21
  import loadConfig from 'next/dist/server/config.js';
22
22
  import { cpus } from 'node:os';
23
23
  import { decode } from 'node:querystring';
24
- import { fileURLToPath, URL as URL$1 } from 'node:url';
25
24
  import imageSizeOf from 'image-size';
26
25
 
27
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
28
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
29
- }) : x)(function(x) {
30
- if (typeof require !== "undefined") return require.apply(this, arguments);
31
- throw Error('Dynamic require of "' + x + '" is not supported');
32
- });
33
- var { loadEnvConfig } = nextEnv;
26
+ // src/index.ts
34
27
  var nextDistPath = /(next[\\/]dist[\\/]shared[\\/]lib)|(next[\\/]dist[\\/]client)|(next[\\/]dist[\\/]pages)/;
35
28
  async function loadEnvironmentConfig(dir, dev) {
36
29
  return loadEnvConfig(dir, dev, Log);
@@ -655,7 +648,7 @@ function vitePluginNextSwc(rootDir, nextConfigResolver) {
655
648
  async config(config, env) {
656
649
  const nextConfig = await nextConfigResolver.promise;
657
650
  nextDirectories = findPagesDir(resolvedDir);
658
- loadedJSConfig = await loadJsConfig.default(resolvedDir, nextConfig);
651
+ loadedJSConfig = await loadJsConfig(resolvedDir, nextConfig);
659
652
  isDev = env.mode !== "production";
660
653
  await loadClosestPackageJson(resolvedDir);
661
654
  isEsmProject = true;
@@ -666,11 +659,6 @@ function vitePluginNextSwc(rootDir, nextConfigResolver) {
666
659
  isServerEnvironment = true;
667
660
  }
668
661
  return {
669
- resolve: {
670
- alias: {
671
- "@opentelemetry/api": "next/dist/compiled/@opentelemetry/api"
672
- }
673
- },
674
662
  // esbuild: {
675
663
  // // We will use Next.js custom SWC transpiler instead of Vite's build-in esbuild
676
664
  // exclude: [/node_modules/, /.m?(t|j)sx?/],
@@ -720,16 +708,21 @@ if (typeof Promise.withResolvers === "undefined") {
720
708
  return { promise, resolve: resolve4, reject };
721
709
  };
722
710
  }
711
+
712
+ // src/utils.ts
713
+ var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
714
+ var isVitestEnv = process.env.VITEST === "true";
715
+
716
+ // src/plugins/next-image/plugin.ts
723
717
  var includePattern2 = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/;
724
718
  var excludeImporterPattern = /\.(css|scss|sass)$/;
725
719
  var virtualImage = "virtual:next-image";
726
720
  var virtualNextImage = "virtual:next/image";
727
721
  var virtualNextLegacyImage = "virtual:next/legacy/image";
728
- var virtualNextImageDefaultLoader = "virtual:next/image-default-loader";
729
- var virtualNextImageContext = "virtual:next/image-context";
730
722
  var sharp;
723
+ var require3 = createRequire(import.meta.url);
731
724
  try {
732
- sharp = __require("sharp");
725
+ sharp = require3("sharp");
733
726
  if (sharp && sharp.concurrency() > 1) {
734
727
  const divisor = process.env.NODE_ENV === "development" ? 4 : 2;
735
728
  sharp.concurrency(Math.floor(Math.max(cpus().length / divisor, 1)));
@@ -739,12 +732,25 @@ try {
739
732
  "You have to install sharp in order to use image optimization features in Next.js. AVIF support is also disabled."
740
733
  );
741
734
  }
735
+ var getEntryPoint = (subPath, env) => require3.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
736
+ var getAlias = (env) => ({
737
+ "sb-original/default-loader": getEntryPoint("image-default-loader", env),
738
+ "sb-original/image-context": getEntryPoint("image-context", env)
739
+ });
742
740
  function vitePluginNextImage(nextConfigResolver) {
741
+ let isBrowser = !isVitestEnv;
743
742
  return {
744
743
  name: "vite-plugin-storybook-nextjs-image",
745
744
  enforce: "pre",
746
745
  async config(config, env) {
747
- return config;
746
+ if (config.test?.browser?.enabled === true) {
747
+ isBrowser = true;
748
+ }
749
+ return {
750
+ resolve: {
751
+ alias: getAlias(isBrowser ? "browser" : "node")
752
+ }
753
+ };
748
754
  },
749
755
  async resolveId(id, importer) {
750
756
  const [source, queryA] = id.split("?");
@@ -762,52 +768,19 @@ function vitePluginNextImage(nextConfigResolver) {
762
768
  if (id === "next/legacy/image" && importer !== virtualNextLegacyImage) {
763
769
  return virtualNextLegacyImage;
764
770
  }
765
- if (id === "sb-original/image-context") {
766
- return virtualNextImageContext;
767
- }
768
- if (id === "sb-original/default-loader") {
769
- return virtualNextImageDefaultLoader;
770
- }
771
771
  return null;
772
772
  },
773
773
  async load(id) {
774
+ const aliasEnv = isBrowser ? "browser" : "node";
774
775
  if (virtualNextImage === id) {
775
776
  return (await fs3.promises.readFile(
776
- fileURLToPath(
777
- new URL$1(
778
- "./plugins/next-image/alias/next-image.js",
779
- import.meta.url
780
- )
781
- )
777
+ require3.resolve(`${VITEST_PLUGIN_NAME}/${aliasEnv}/mocks/image`)
782
778
  )).toString("utf-8");
783
779
  }
784
780
  if (virtualNextLegacyImage === id) {
785
781
  return (await fs3.promises.readFile(
786
- fileURLToPath(
787
- new URL$1(
788
- "./plugins/next-image/alias/next-legacy-image.js",
789
- import.meta.url
790
- )
791
- )
792
- )).toString("utf-8");
793
- }
794
- if (virtualNextImageDefaultLoader === id) {
795
- return (await fs3.promises.readFile(
796
- fileURLToPath(
797
- new URL$1(
798
- "./plugins/next-image/alias/image-default-loader.js",
799
- import.meta.url
800
- )
801
- )
802
- )).toString("utf-8");
803
- }
804
- if (virtualNextImageContext === id) {
805
- return (await fs3.promises.readFile(
806
- fileURLToPath(
807
- new URL$1(
808
- "./plugins/next-image/alias/image-context.js",
809
- import.meta.url
810
- )
782
+ require3.resolve(
783
+ `${VITEST_PLUGIN_NAME}/${aliasEnv}/mocks/legacy-image`
811
784
  )
812
785
  )).toString("utf-8");
813
786
  }
@@ -854,46 +827,46 @@ function vitePluginNextImage(nextConfigResolver) {
854
827
  }
855
828
  };
856
829
  }
857
- var dirname = path.dirname(new URL(import.meta.url).pathname);
858
- var joinDir = (...subPath) => path.join(dirname, "plugins", "next-mocks", "alias", ...subPath);
830
+ var require4 = createRequire(import.meta.url);
831
+ var getEntryPoint2 = (subPath, env) => require4.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
832
+ var getAlias2 = (env) => ({
833
+ "next/headers": getEntryPoint2("headers", env),
834
+ "@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
835
+ "next/navigation": getEntryPoint2("navigation", env),
836
+ "@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
837
+ "next/router": getEntryPoint2("router", env),
838
+ "@storybook/nextjs/router.mock": getEntryPoint2("router", env),
839
+ "next/cache": getEntryPoint2("cache", env),
840
+ "@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
841
+ "server-only": getEntryPoint2("server-only", env),
842
+ "@opentelemetry/api": require4.resolve(
843
+ "next/dist/compiled/@opentelemetry/api/index.js"
844
+ )
845
+ });
859
846
  var vitePluginNextMocks = () => ({
860
847
  name: "vite-plugin-next-mocks",
861
- config: () => ({
862
- resolve: {
863
- alias: {
864
- "next/headers": joinDir("headers", "index.js"),
865
- "@storybook/nextjs/headers.mock": joinDir("headers", "index.js"),
866
- "next/navigation": joinDir("navigation", "index.js"),
867
- "@storybook/nextjs/navigation.mock": joinDir(
868
- "navigation",
869
- "index.js"
870
- ),
871
- "next/router": joinDir("router", "index.js"),
872
- "@storybook/nextjs/router.mock": joinDir("router", "index.js"),
873
- "next/cache": joinDir("cache", "index.js"),
874
- "@storybook/nextjs/cache.mock": joinDir("cache", "index.js"),
875
- "server-only": joinDir("rsc", "server-only.js")
848
+ config: (env) => {
849
+ const aliasEnv = isVitestEnv && env.test?.browser?.enabled !== true ? "node" : "browser";
850
+ return {
851
+ resolve: {
852
+ alias: getAlias2(aliasEnv)
876
853
  }
877
- }
878
- })
854
+ };
855
+ }
879
856
  });
880
857
 
881
858
  // src/index.ts
882
- var require3 = createRequire(import.meta.url);
859
+ var require5 = createRequire(import.meta.url);
883
860
  function VitePlugin({ dir = process.cwd() } = {}) {
884
861
  const resolvedDir = resolve(dir);
885
862
  const nextConfigResolver = Promise.withResolvers();
886
- const isVitestEnv = process.env.VITEST === "true";
887
863
  return [
888
864
  {
889
865
  name: "vite-plugin-storybook-nextjs",
890
866
  enforce: "pre",
891
867
  async config(config, env) {
892
868
  const phase = env.mode === "development" ? PHASE_DEVELOPMENT_SERVER : env.mode === "test" ? PHASE_TEST : PHASE_PRODUCTION_BUILD;
893
- nextConfigResolver.resolve(
894
- // @ts-ignore TODO figure out why TypeScript is complaining about this
895
- await loadConfig.default(phase, resolvedDir)
896
- );
869
+ nextConfigResolver.resolve(await loadConfig(phase, resolvedDir));
897
870
  return {
898
871
  ...!isVitestEnv && {
899
872
  resolve: {
@@ -905,23 +878,23 @@ function VitePlugin({ dir = process.cwd() } = {}) {
905
878
  },
906
879
  test: {
907
880
  alias: {
908
- "react/jsx-dev-runtime": require3.resolve(
881
+ "react/jsx-dev-runtime": require5.resolve(
909
882
  "next/dist/compiled/react/jsx-dev-runtime.js"
910
883
  ),
911
- "react/jsx-runtime": require3.resolve(
884
+ "react/jsx-runtime": require5.resolve(
912
885
  "next/dist/compiled/react/jsx-runtime.js"
913
886
  ),
914
- react: require3.resolve("next/dist/compiled/react"),
915
- "react-dom/test-utils": require3.resolve(
887
+ react: require5.resolve("next/dist/compiled/react"),
888
+ "react-dom/test-utils": require5.resolve(
916
889
  "next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js"
917
890
  ),
918
- "react-dom/cjs/react-dom.development.js": require3.resolve(
891
+ "react-dom/cjs/react-dom.development.js": require5.resolve(
919
892
  "next/dist/compiled/react-dom/cjs/react-dom.development.js"
920
893
  ),
921
- "react-dom/client": require3.resolve(
894
+ "react-dom/client": require5.resolve(
922
895
  "next/dist/compiled/react-dom/client.js"
923
896
  ),
924
- "react-dom": require3.resolve("next/dist/compiled/react-dom")
897
+ "react-dom": require5.resolve("next/dist/compiled/react-dom")
925
898
  }
926
899
  }
927
900
  };
@@ -929,7 +902,7 @@ function VitePlugin({ dir = process.cwd() } = {}) {
929
902
  configResolved(config) {
930
903
  if (!config.test?.browser?.enabled) {
931
904
  config.test.setupFiles = [
932
- require3.resolve("./mocks/storybook.global.js"),
905
+ require5.resolve("./mocks/storybook.global.js"),
933
906
  ...config.test?.setupFiles ?? []
934
907
  ];
935
908
  }
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ var module$1 = require('module');
4
+ var moduleAlias = require('module-alias');
5
+ require('fs');
6
+ var os = require('os');
7
+ require('path');
8
+ require('querystring');
9
+ require('image-size');
10
+ require('ts-dedent');
11
+
12
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
+
15
+ var moduleAlias__default = /*#__PURE__*/_interopDefault(moduleAlias);
16
+
17
+ // src/mocks/storybook.global.ts
18
+
19
+ // src/utils.ts
20
+ var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
21
+ process.env.VITEST === "true";
22
+
23
+ // src/plugins/next-image/plugin.ts
24
+ var sharp;
25
+ var require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)));
26
+ try {
27
+ sharp = require2("sharp");
28
+ if (sharp && sharp.concurrency() > 1) {
29
+ const divisor = process.env.NODE_ENV === "development" ? 4 : 2;
30
+ sharp.concurrency(Math.floor(Math.max(os.cpus().length / divisor, 1)));
31
+ }
32
+ } catch (e) {
33
+ console.warn(
34
+ "You have to install sharp in order to use image optimization features in Next.js. AVIF support is also disabled."
35
+ );
36
+ }
37
+ var getEntryPoint = (subPath, env) => require2.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
38
+ var getAlias = (env) => ({
39
+ "sb-original/default-loader": getEntryPoint("image-default-loader", env),
40
+ "sb-original/image-context": getEntryPoint("image-context", env)
41
+ });
42
+ var require3 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)));
43
+ var getEntryPoint2 = (subPath, env) => require3.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
44
+ var getAlias2 = (env) => ({
45
+ "next/headers": getEntryPoint2("headers", env),
46
+ "@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
47
+ "next/navigation": getEntryPoint2("navigation", env),
48
+ "@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
49
+ "next/router": getEntryPoint2("router", env),
50
+ "@storybook/nextjs/router.mock": getEntryPoint2("router", env),
51
+ "next/cache": getEntryPoint2("cache", env),
52
+ "@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
53
+ "server-only": getEntryPoint2("server-only", env),
54
+ "@opentelemetry/api": require3.resolve(
55
+ "next/dist/compiled/@opentelemetry/api/index.js"
56
+ )
57
+ });
58
+
59
+ // src/mocks/storybook.global.ts
60
+ var require4 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)));
61
+ moduleAlias__default.default.addAliases({
62
+ react: "next/dist/compiled/react",
63
+ "react-dom/test-utils": require4.resolve(
64
+ "next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js"
65
+ ),
66
+ "react-dom": "next/dist/compiled/react-dom",
67
+ ...getAlias2("node"),
68
+ ...getAlias("node")
69
+ });
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -1,12 +1,59 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import moduleAlias from 'module-alias';
3
+ import { cpus } from 'node:os';
4
+ import 'image-size';
5
+ import 'ts-dedent';
3
6
 
4
7
  // src/mocks/storybook.global.ts
8
+
9
+ // src/utils.ts
10
+ var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
11
+ process.env.VITEST === "true";
12
+
13
+ // src/plugins/next-image/plugin.ts
14
+ var sharp;
5
15
  var require2 = createRequire(import.meta.url);
16
+ try {
17
+ sharp = require2("sharp");
18
+ if (sharp && sharp.concurrency() > 1) {
19
+ const divisor = process.env.NODE_ENV === "development" ? 4 : 2;
20
+ sharp.concurrency(Math.floor(Math.max(cpus().length / divisor, 1)));
21
+ }
22
+ } catch (e) {
23
+ console.warn(
24
+ "You have to install sharp in order to use image optimization features in Next.js. AVIF support is also disabled."
25
+ );
26
+ }
27
+ var getEntryPoint = (subPath, env) => require2.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
28
+ var getAlias = (env) => ({
29
+ "sb-original/default-loader": getEntryPoint("image-default-loader", env),
30
+ "sb-original/image-context": getEntryPoint("image-context", env)
31
+ });
32
+ var require3 = createRequire(import.meta.url);
33
+ var getEntryPoint2 = (subPath, env) => require3.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
34
+ var getAlias2 = (env) => ({
35
+ "next/headers": getEntryPoint2("headers", env),
36
+ "@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
37
+ "next/navigation": getEntryPoint2("navigation", env),
38
+ "@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
39
+ "next/router": getEntryPoint2("router", env),
40
+ "@storybook/nextjs/router.mock": getEntryPoint2("router", env),
41
+ "next/cache": getEntryPoint2("cache", env),
42
+ "@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
43
+ "server-only": getEntryPoint2("server-only", env),
44
+ "@opentelemetry/api": require3.resolve(
45
+ "next/dist/compiled/@opentelemetry/api/index.js"
46
+ )
47
+ });
48
+
49
+ // src/mocks/storybook.global.ts
50
+ var require4 = createRequire(import.meta.url);
6
51
  moduleAlias.addAliases({
7
52
  react: "next/dist/compiled/react",
8
- "react-dom/test-utils": require2.resolve(
53
+ "react-dom/test-utils": require4.resolve(
9
54
  "next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js"
10
55
  ),
11
- "react-dom": "next/dist/compiled/react-dom"
56
+ "react-dom": "next/dist/compiled/react-dom",
57
+ ...getAlias2("node"),
58
+ ...getAlias("node")
12
59
  });
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ var react = require('next/dist/compiled/react');
4
+
5
+ // src/plugins/next-image/alias/image-context.tsx
6
+ var ImageContext = react.createContext({});
7
+
8
+ exports.ImageContext = ImageContext;
@@ -0,0 +1,13 @@
1
+ import * as React from 'next/dist/compiled/react';
2
+ import { ImageProps, StaticImageData } from 'next/image';
3
+ import { ImageProps as ImageProps$1 } from 'next/legacy/image';
4
+
5
+ interface StaticRequire {
6
+ default: StaticImageData;
7
+ }
8
+ declare type StaticImport = StaticRequire | StaticImageData;
9
+ declare const ImageContext: React.Context<Partial<Omit<ImageProps, "src"> & {
10
+ src: string | StaticImport;
11
+ }> & Omit<ImageProps$1, "src">>;
12
+
13
+ export { ImageContext };
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ // src/plugins/next-image/alias/image-default-loader.tsx
4
+ var defaultLoader = ({
5
+ src,
6
+ width,
7
+ quality = 75
8
+ }) => {
9
+ const missingValues = [];
10
+ if (!src) {
11
+ missingValues.push("src");
12
+ }
13
+ if (!width) {
14
+ missingValues.push("width");
15
+ }
16
+ if (missingValues.length > 0) {
17
+ throw new Error(
18
+ `Next Image Optimization requires ${missingValues.join(
19
+ ", "
20
+ )} to be provided. Make sure you pass them as props to the \`next/image\` component. Received: ${JSON.stringify(
21
+ {
22
+ src,
23
+ width,
24
+ quality
25
+ }
26
+ )}`
27
+ );
28
+ }
29
+ const url = new URL(src, window.location.href);
30
+ if (!url.searchParams.has("w") && !url.searchParams.has("q")) {
31
+ url.searchParams.set("w", width.toString());
32
+ url.searchParams.set("q", quality.toString());
33
+ }
34
+ if (!src.startsWith("http://") && !src.startsWith("https://")) {
35
+ return url.toString().slice(url.origin.length);
36
+ }
37
+ return url.toString();
38
+ };
39
+
40
+ exports.defaultLoader = defaultLoader;
@@ -0,0 +1,5 @@
1
+ import * as _NextImage from 'next/image';
2
+
3
+ declare const defaultLoader: ({ src, width, quality, }: _NextImage.ImageLoaderProps) => string;
4
+
5
+ export { defaultLoader };
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var NextImageNamespace = require('next/image');
6
+ var defaultLoader = require('sb-original/default-loader');
7
+ var imageContext = require('sb-original/image-context');
8
+ var React = require('next/dist/compiled/react');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
24
+ });
25
+ }
26
+ n.default = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var NextImageNamespace__namespace = /*#__PURE__*/_interopNamespace(NextImageNamespace);
31
+ var React__default = /*#__PURE__*/_interopDefault(React);
32
+
33
+ // src/plugins/next-image/alias/next-image.tsx
34
+ var OriginalNextImage = NextImageNamespace__namespace.default;
35
+ var { getImageProps: originalGetImageProps } = NextImageNamespace__namespace;
36
+ var MockedNextImage = React__default.default.forwardRef(({ loader, ...props }, ref) => {
37
+ const imageParameters = React__default.default.useContext(imageContext.ImageContext);
38
+ return /* @__PURE__ */ React__default.default.createElement(
39
+ OriginalNextImage,
40
+ {
41
+ ref,
42
+ ...imageParameters,
43
+ ...props,
44
+ loader: loader ?? defaultLoader.defaultLoader
45
+ }
46
+ );
47
+ });
48
+ MockedNextImage.displayName = "NextImage";
49
+ var getImageProps = (props) => originalGetImageProps?.({ loader: defaultLoader.defaultLoader, ...props });
50
+ var next_image_default = MockedNextImage;
51
+
52
+ exports.default = next_image_default;
53
+ exports.getImageProps = getImageProps;
@@ -0,0 +1,30 @@
1
+ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-img-props';
2
+ import * as _NextImage from 'next/image';
3
+ import React__default from 'next/dist/compiled/react';
4
+
5
+ declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "height" | "width" | "loading" | "ref" | "alt" | "src" | "srcSet"> & {
6
+ src: string | next_dist_shared_lib_get_img_props.StaticImport;
7
+ alt: string;
8
+ width?: number | `${number}` | undefined;
9
+ height?: number | `${number}` | undefined;
10
+ fill?: boolean | undefined;
11
+ loader?: _NextImage.ImageLoader | undefined;
12
+ quality?: number | `${number}` | undefined;
13
+ priority?: boolean | undefined;
14
+ loading?: "lazy" | "eager" | undefined;
15
+ placeholder?: next_dist_shared_lib_get_img_props.PlaceholderValue | undefined;
16
+ blurDataURL?: string | undefined;
17
+ unoptimized?: boolean | undefined;
18
+ overrideSrc?: string | undefined;
19
+ onLoadingComplete?: next_dist_shared_lib_get_img_props.OnLoadingComplete | undefined;
20
+ layout?: string | undefined;
21
+ objectFit?: string | undefined;
22
+ objectPosition?: string | undefined;
23
+ lazyBoundary?: string | undefined;
24
+ lazyRoot?: string | undefined;
25
+ } & React__default.RefAttributes<HTMLImageElement>>;
26
+ declare const getImageProps: (props: _NextImage.ImageProps) => {
27
+ props: next_dist_shared_lib_get_img_props.ImgProps;
28
+ };
29
+
30
+ export { MockedNextImage as default, getImageProps };
@@ -2,7 +2,7 @@ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-im
2
2
  import * as _NextImage from 'next/image';
3
3
  import React__default from 'next/dist/compiled/react';
4
4
 
5
- declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcSet" | "ref" | "width" | "height" | "loading" | "alt"> & {
5
+ declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "height" | "width" | "loading" | "ref" | "alt" | "src" | "srcSet"> & {
6
6
  src: string | next_dist_shared_lib_get_img_props.StaticImport;
7
7
  alt: string;
8
8
  width?: number | `${number}` | undefined;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var OriginalNextLegacyImage = require('next/legacy/image');
4
+ var defaultLoader = require('sb-original/default-loader');
5
+ var imageContext = require('sb-original/image-context');
6
+ var React = require('next/dist/compiled/react');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var OriginalNextLegacyImage__default = /*#__PURE__*/_interopDefault(OriginalNextLegacyImage);
11
+ var React__default = /*#__PURE__*/_interopDefault(React);
12
+
13
+ // src/plugins/next-image/alias/next-legacy-image.tsx
14
+ function NextLegacyImage({ loader, ...props }) {
15
+ const imageParameters = React__default.default.useContext(imageContext.ImageContext);
16
+ return /* @__PURE__ */ React__default.default.createElement(
17
+ OriginalNextLegacyImage__default.default,
18
+ {
19
+ ...imageParameters,
20
+ ...props,
21
+ loader: loader ?? defaultLoader.defaultLoader
22
+ }
23
+ );
24
+ }
25
+ var next_legacy_image_default = NextLegacyImage;
26
+
27
+ module.exports = next_legacy_image_default;
@@ -0,0 +1,6 @@
1
+ import React__default from 'next/dist/compiled/react';
2
+ import * as _NextLegacyImage from 'next/legacy/image';
3
+
4
+ declare function NextLegacyImage({ loader, ...props }: _NextLegacyImage.ImageProps): React__default.JSX.Element;
5
+
6
+ export { NextLegacyImage as default };
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var test = require('@storybook/test');
6
+ var unstableCache_js = require('next/dist/server/web/spec-extension/unstable-cache.js');
7
+ var unstableNoStore_js = require('next/dist/server/web/spec-extension/unstable-no-store.js');
8
+
9
+ // src/plugins/next-mocks/alias/cache/index.ts
10
+ var revalidatePath = test.fn().mockName("next/cache::revalidatePath");
11
+ var revalidateTag = test.fn().mockName("next/cache::revalidateTag");
12
+ var cacheExports = {
13
+ unstable_cache: unstableCache_js.unstable_cache,
14
+ revalidateTag,
15
+ revalidatePath,
16
+ unstable_noStore: unstableNoStore_js.unstable_noStore
17
+ };
18
+ var cache_default = cacheExports;
19
+
20
+ Object.defineProperty(exports, "unstable_cache", {
21
+ enumerable: true,
22
+ get: function () { return unstableCache_js.unstable_cache; }
23
+ });
24
+ Object.defineProperty(exports, "unstable_noStore", {
25
+ enumerable: true,
26
+ get: function () { return unstableNoStore_js.unstable_noStore; }
27
+ });
28
+ exports.default = cache_default;
29
+ exports.revalidatePath = revalidatePath;
30
+ exports.revalidateTag = revalidateTag;