@storybook/nextjs 10.1.0-alpha.9 → 10.1.0-beta.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 (51) hide show
  1. package/dist/_browser-chunks/{chunk-KX5HHFXV.js → chunk-2SBZPHE7.js} +50 -100
  2. package/dist/_browser-chunks/chunk-RDMFII4N.js +22 -0
  3. package/dist/_browser-chunks/{chunk-L5NVL7MD.js → chunk-SL3VIQZ3.js} +7 -13
  4. package/dist/_browser-chunks/react-18-PYSEDAWB.js +43 -0
  5. package/dist/_node-chunks/chunk-AU547LNK.js +76 -0
  6. package/dist/_node-chunks/chunk-EONFLREF.js +57 -0
  7. package/dist/_node-chunks/chunk-NVHRUSN5.js +211 -0
  8. package/dist/_node-chunks/configureNextFont-3RPVM2N7.js +28 -0
  9. package/dist/_node-chunks/{loader-7OJQICYP.js → loader-PBLFQE7I.js} +15 -25
  10. package/dist/_node-chunks/{loader-OFLGZQCU.js → loader-UX42M74F.js} +11 -16
  11. package/dist/_node-chunks/{utils-NVB3HGRH.js → utils-MPWEOWV4.js} +8 -9
  12. package/dist/_node-chunks/webpack-5IZRQF33.js +23 -0
  13. package/dist/_node-chunks/{webpack-E2OB2ZPW.js → webpack-C4DEBGCG.js} +13 -19
  14. package/dist/_node-chunks/webpack-EFCFZKO7.js +97 -0
  15. package/dist/_node-chunks/{webpack-VD3FKUZZ.js → webpack-KW7MEY7C.js} +9 -12
  16. package/dist/_node-chunks/webpack-TVYIGXMK.js +24 -0
  17. package/dist/_node-chunks/webpack-UAKFJEYJ.js +30 -0
  18. package/dist/_node-chunks/webpack-WL4FYVO5.js +23 -0
  19. package/dist/_node-chunks/webpack-WZC6ZANM.js +60 -0
  20. package/dist/compatibility/draft-mode.compat.js +1 -1
  21. package/dist/export-mocks/cache/index.js +3 -6
  22. package/dist/export-mocks/headers/index.js +6 -29
  23. package/dist/export-mocks/index.js +9 -10
  24. package/dist/export-mocks/navigation/index.js +17 -41
  25. package/dist/export-mocks/router/index.d.ts +4 -7
  26. package/dist/export-mocks/router/index.js +20 -54
  27. package/dist/font/webpack/loader/storybook-nextjs-font-loader.js +38 -80
  28. package/dist/image-context.js +1 -1
  29. package/dist/images/next-image.js +5 -11
  30. package/dist/images/next-legacy-image.js +3 -6
  31. package/dist/index.js +2865 -8413
  32. package/dist/next-image-loader-stub.js +9 -16
  33. package/dist/node/index.js +6 -10
  34. package/dist/preset.js +183 -462
  35. package/dist/preview.js +2 -2
  36. package/dist/rsc/server-only.js +1 -1
  37. package/dist/swc/next-swc-loader-patch.js +46 -84
  38. package/package.json +6 -6
  39. package/dist/_browser-chunks/chunk-I5RFHXDS.js +0 -40
  40. package/dist/_browser-chunks/react-18-G7Q4PNHD.js +0 -71
  41. package/dist/_node-chunks/chunk-PWZWGY6W.js +0 -17
  42. package/dist/_node-chunks/chunk-UHO3ELD2.js +0 -475
  43. package/dist/_node-chunks/chunk-WR63XCFA.js +0 -74
  44. package/dist/_node-chunks/chunk-X47EC6DB.js +0 -102
  45. package/dist/_node-chunks/configureNextFont-ZL3UHKQ4.js +0 -36
  46. package/dist/_node-chunks/webpack-3J2WBZ2E.js +0 -30
  47. package/dist/_node-chunks/webpack-7PUWUCNJ.js +0 -27
  48. package/dist/_node-chunks/webpack-JVSODHFI.js +0 -38
  49. package/dist/_node-chunks/webpack-O36IRAFL.js +0 -77
  50. package/dist/_node-chunks/webpack-SNP77BVT.js +0 -107
  51. package/dist/_node-chunks/webpack-THQBX5DA.js +0 -26
@@ -1,17 +1,14 @@
1
- import CJS_COMPAT_NODE_URL_mt98813ktw from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_mt98813ktw from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_mt98813ktw from "node:module";
1
+ import CJS_COMPAT_NODE_URL_kl8x2s4rzz from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_kl8x2s4rzz from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_kl8x2s4rzz from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_mt98813ktw.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_mt98813ktw.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_mt98813ktw.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_kl8x2s4rzz.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_kl8x2s4rzz.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_kl8x2s4rzz.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- import {
13
- __name
14
- } from "../../../_node-chunks/chunk-PWZWGY6W.js";
15
12
 
16
13
  // src/font/webpack/loader/storybook-nextjs-font-loader.ts
17
14
  import { sep } from "node:path";
@@ -28,23 +25,14 @@ import { validateGoogleFontFunctionCall } from "next/dist/compiled/@next/font/di
28
25
  import loaderUtils from "next/dist/compiled/loader-utils3/index.js";
29
26
  var cssCache = /* @__PURE__ */ new Map();
30
27
  async function getFontFaceDeclarations(options) {
31
- const { fontFamily, weights, styles, selectedVariableAxes, display, variable } = validateGoogleFontFunctionCall(options.fontFamily, options.props);
32
- const fontAxes = getFontAxes(fontFamily, weights, styles, selectedVariableAxes);
33
- const url = getGoogleFontsUrl(fontFamily, fontAxes, display);
28
+ let { fontFamily, weights, styles, selectedVariableAxes, display, variable } = validateGoogleFontFunctionCall(options.fontFamily, options.props), fontAxes = getFontAxes(fontFamily, weights, styles, selectedVariableAxes), url = getGoogleFontsUrl(fontFamily, fontAxes, display);
34
29
  try {
35
- const hasCachedCSS = cssCache.has(url);
36
- const fontFaceCSS = hasCachedCSS ? cssCache.get(url) : await fetchCSSFromGoogleFonts(url, fontFamily, true).catch(() => null);
37
- if (!hasCachedCSS) {
38
- cssCache.set(url, fontFaceCSS);
39
- } else {
40
- cssCache.delete(url);
41
- }
42
- if (fontFaceCSS === null) {
30
+ let hasCachedCSS = cssCache.has(url), fontFaceCSS = hasCachedCSS ? cssCache.get(url) : await fetchCSSFromGoogleFonts(url, fontFamily, !0).catch(() => null);
31
+ if (hasCachedCSS ? cssCache.delete(url) : cssCache.set(url, fontFaceCSS), fontFaceCSS === null)
43
32
  throw new GoogleFontsDownloadError({
44
33
  fontFamily,
45
34
  url
46
35
  });
47
- }
48
36
  return {
49
37
  id: loaderUtils.getHashDigest(url, "md5", "hex", 6),
50
38
  fontFamily,
@@ -57,7 +45,6 @@ async function getFontFaceDeclarations(options) {
57
45
  throw new GoogleFontsLoadingError({ error, url });
58
46
  }
59
47
  }
60
- __name(getFontFaceDeclarations, "getFontFaceDeclarations");
61
48
 
62
49
  // src/font/webpack/loader/local/get-font-face-declarations.ts
63
50
  import { dirname, join } from "node:path";
@@ -65,58 +52,50 @@ import { getProjectRoot } from "storybook/internal/common";
65
52
  import { validateLocalFontFunctionCall } from "next/dist/compiled/@next/font/dist/local/validate-local-font-function-call.js";
66
53
  import loaderUtils2 from "next/dist/compiled/loader-utils3/index.js";
67
54
  async function getFontFaceDeclarations2(options, rootContext, swcMode) {
68
- const localFontSrc = options.props.src;
69
- const parentFolder = swcMode ? dirname(join(getProjectRoot(), options.filename)).replace(rootContext, "") : dirname(options.filename).replace(rootContext, "");
70
- const {
55
+ let localFontSrc = options.props.src, parentFolder = swcMode ? dirname(join(getProjectRoot(), options.filename)).replace(rootContext, "") : dirname(options.filename).replace(rootContext, ""), {
71
56
  weight,
72
57
  style,
73
58
  variable,
74
59
  declarations = []
75
- } = validateLocalFontFunctionCall("", options.props);
76
- const id = `font-${loaderUtils2.getHashDigest(
60
+ } = validateLocalFontFunctionCall("", options.props), id = `font-${loaderUtils2.getHashDigest(
77
61
  Buffer.from(JSON.stringify(localFontSrc)),
78
62
  "md5",
79
63
  "hex",
80
64
  6
81
- )}`;
82
- const fontDeclarations = declarations.map(({ prop, value }) => `${prop}: ${value};`).join("\n");
83
- const getFontFaceCSS = /* @__PURE__ */ __name(() => {
84
- if (typeof localFontSrc === "string") {
85
- const localFontPath = join(parentFolder, localFontSrc).replaceAll("\\", "/");
86
- return `@font-face {
65
+ )}`, fontDeclarations = declarations.map(({ prop, value }) => `${prop}: ${value};`).join(`
66
+ `);
67
+ return {
68
+ id,
69
+ fontFamily: id,
70
+ fontFaceCSS: (() => {
71
+ if (typeof localFontSrc == "string") {
72
+ let localFontPath = join(parentFolder, localFontSrc).replaceAll("\\", "/");
73
+ return `@font-face {
87
74
  font-family: ${id};
88
75
  src: url(.${localFontPath});
89
76
  ${fontDeclarations}
90
77
  }`;
91
- }
92
- return localFontSrc.map((font) => {
93
- const localFontPath = join(parentFolder, font.path).replaceAll("\\", "/");
94
- return `@font-face {
78
+ }
79
+ return localFontSrc.map((font) => {
80
+ let localFontPath = join(parentFolder, font.path).replaceAll("\\", "/");
81
+ return `@font-face {
95
82
  font-family: ${id};
96
83
  src: url(.${localFontPath});
97
84
  ${font.weight ? `font-weight: ${font.weight};` : ""}
98
85
  ${font.style ? `font-style: ${font.style};` : ""}
99
86
  ${fontDeclarations}
100
87
  }`;
101
- }).join("");
102
- }, "getFontFaceCSS");
103
- return {
104
- id,
105
- fontFamily: id,
106
- fontFaceCSS: getFontFaceCSS(),
88
+ }).join("");
89
+ })(),
107
90
  weights: weight ? [weight] : [],
108
91
  styles: style ? [style] : [],
109
92
  variable
110
93
  };
111
94
  }
112
- __name(getFontFaceDeclarations2, "getFontFaceDeclarations");
113
95
 
114
96
  // src/font/webpack/loader/utils/get-css-meta.ts
115
97
  function getCSSMeta(options) {
116
- const className = getClassName(options);
117
- const style = getStylesObj(options);
118
- const variableClassName = `__variable_${className}`;
119
- const classNamesCSS = `
98
+ let className = getClassName(options), style = getStylesObj(options), variableClassName = `__variable_${className}`, classNamesCSS = `
120
99
  .${className} {
121
100
  font-family: ${options.fontFamily};
122
101
  ${isNextCSSPropertyValid(options.styles) ? `font-style: ${options.styles[0]};` : ""}
@@ -124,8 +103,7 @@ function getCSSMeta(options) {
124
103
  }
125
104
 
126
105
  ${options.variable ? `.${variableClassName} { ${options.variable}: '${options.fontFamily}'; }` : ""}
127
- `;
128
- const fontFaceCSS = `${changeFontDisplayToSwap(options.fontFaceCSS)}`;
106
+ `, fontFaceCSS = `${changeFontDisplayToSwap(options.fontFaceCSS)}`;
129
107
  return {
130
108
  className,
131
109
  fontFaceCSS,
@@ -134,14 +112,10 @@ function getCSSMeta(options) {
134
112
  ...options.variable ? { variableClassName } : {}
135
113
  };
136
114
  }
137
- __name(getCSSMeta, "getCSSMeta");
138
115
  function getClassName({ styles, weights, fontFamily }) {
139
- const font = fontFamily.replaceAll(" ", "-").toLowerCase();
140
- const style = isNextCSSPropertyValid(styles) ? styles[0] : null;
141
- const weight = isNextCSSPropertyValid(weights) ? weights[0] : null;
116
+ let font = fontFamily.replaceAll(" ", "-").toLowerCase(), style = isNextCSSPropertyValid(styles) ? styles[0] : null, weight = isNextCSSPropertyValid(weights) ? weights[0] : null;
142
117
  return `${font}${style ? `-${style}` : ""}${weight ? `-${weight}` : ""}`;
143
118
  }
144
- __name(getClassName, "getClassName");
145
119
  function getStylesObj({ styles, weights, fontFamily }) {
146
120
  return {
147
121
  fontFamily,
@@ -149,15 +123,12 @@ function getStylesObj({ styles, weights, fontFamily }) {
149
123
  ...isNextCSSPropertyValid(weights) ? { fontWeight: weights[0] } : {}
150
124
  };
151
125
  }
152
- __name(getStylesObj, "getStylesObj");
153
126
  function isNextCSSPropertyValid(prop) {
154
127
  return prop.length === 1 && prop[0] !== "variable";
155
128
  }
156
- __name(isNextCSSPropertyValid, "isNextCSSPropertyValid");
157
129
  function changeFontDisplayToSwap(css) {
158
130
  return css.replaceAll("font-display: optional;", "font-display: block;");
159
131
  }
160
- __name(changeFontDisplayToSwap, "changeFontDisplayToSwap");
161
132
 
162
133
  // src/font/webpack/loader/utils/set-font-declarations-in-head.ts
163
134
  function setFontDeclarationsInHead({ id, fontFaceCSS, classNamesCSS }) {
@@ -178,36 +149,24 @@ function setFontDeclarationsInHead({ id, fontFaceCSS, classNamesCSS }) {
178
149
  }
179
150
  `;
180
151
  }
181
- __name(setFontDeclarationsInHead, "setFontDeclarationsInHead");
182
152
 
183
153
  // src/font/webpack/loader/storybook-nextjs-font-loader.ts
184
154
  async function storybookNextjsFontLoader() {
185
- const loaderOptions = this.getOptions();
186
- let swcMode = false;
187
- let options;
188
- if (Object.keys(loaderOptions).length > 0) {
155
+ let loaderOptions = this.getOptions(), swcMode = !1, options;
156
+ if (Object.keys(loaderOptions).length > 0)
189
157
  options = loaderOptions;
190
- } else {
191
- const importQuery = JSON.parse(this.resourceQuery.slice(1));
192
- swcMode = true;
193
- options = {
158
+ else {
159
+ let importQuery = JSON.parse(this.resourceQuery.slice(1));
160
+ swcMode = !0, options = {
194
161
  filename: importQuery.path,
195
162
  fontFamily: importQuery.import,
196
163
  props: importQuery.arguments[0],
197
164
  source: this.context.replace(this.rootContext, "")
198
165
  };
199
166
  }
200
- const rootCtx = this.rootContext;
201
- let fontFaceDeclaration;
202
- const pathSep = sep;
203
- if (options.source.endsWith(`next${pathSep}font${pathSep}google`) || options.source.endsWith(`@next${pathSep}font${pathSep}google`)) {
204
- fontFaceDeclaration = await getFontFaceDeclarations(options);
205
- }
206
- if (options.source.endsWith(`next${pathSep}font${pathSep}local`) || options.source.endsWith(`@next${pathSep}font${pathSep}local`)) {
207
- fontFaceDeclaration = await getFontFaceDeclarations2(options, rootCtx, swcMode);
208
- }
209
- if (typeof fontFaceDeclaration !== "undefined") {
210
- const cssMeta = getCSSMeta(fontFaceDeclaration);
167
+ let rootCtx = this.rootContext, fontFaceDeclaration, pathSep = sep;
168
+ if ((options.source.endsWith(`next${pathSep}font${pathSep}google`) || options.source.endsWith(`@next${pathSep}font${pathSep}google`)) && (fontFaceDeclaration = await getFontFaceDeclarations(options)), (options.source.endsWith(`next${pathSep}font${pathSep}local`) || options.source.endsWith(`@next${pathSep}font${pathSep}local`)) && (fontFaceDeclaration = await getFontFaceDeclarations2(options, rootCtx, swcMode)), typeof fontFaceDeclaration < "u") {
169
+ let cssMeta = getCSSMeta(fontFaceDeclaration);
211
170
  return `
212
171
  ${setFontDeclarationsInHead({
213
172
  fontFaceCSS: cssMeta.fontFaceCSS,
@@ -222,9 +181,8 @@ async function storybookNextjsFontLoader() {
222
181
  }
223
182
  `;
224
183
  }
225
- return `module.exports = {}`;
184
+ return "module.exports = {}";
226
185
  }
227
- __name(storybookNextjsFontLoader, "storybookNextjsFontLoader");
228
186
  export {
229
187
  storybookNextjsFontLoader as default
230
188
  };
@@ -1,4 +1,4 @@
1
- import "./_browser-chunks/chunk-L5NVL7MD.js";
1
+ import "./_browser-chunks/chunk-SL3VIQZ3.js";
2
2
 
3
3
  // src/image-context.ts
4
4
  import { createContext } from "react";
@@ -1,20 +1,15 @@
1
1
  import {
2
2
  defaultLoader
3
- } from "../_browser-chunks/chunk-I5RFHXDS.js";
4
- import {
5
- __name
6
- } from "../_browser-chunks/chunk-L5NVL7MD.js";
3
+ } from "../_browser-chunks/chunk-RDMFII4N.js";
4
+ import "../_browser-chunks/chunk-SL3VIQZ3.js";
7
5
 
8
6
  // src/images/next-image.tsx
9
7
  import React from "react";
10
8
  import { ImageContext as ImageContextValue } from "@storybook/nextjs/image-context";
11
9
  import * as NextImageNamespace from "sb-original/next/image";
12
- var OriginalNextImage = NextImageNamespace.default;
13
- var { getImageProps: originalGetImageProps } = NextImageNamespace;
14
- var ImageContext = ImageContextValue;
15
- var MockedNextImage = React.forwardRef(
10
+ var OriginalNextImage = NextImageNamespace.default, { getImageProps: originalGetImageProps } = NextImageNamespace, ImageContext = ImageContextValue, MockedNextImage = React.forwardRef(
16
11
  ({ loader, ...props }, ref) => {
17
- const imageParameters = React.useContext(ImageContext);
12
+ let imageParameters = React.useContext(ImageContext);
18
13
  return React.createElement(
19
14
  OriginalNextImage,
20
15
  {
@@ -27,8 +22,7 @@ var MockedNextImage = React.forwardRef(
27
22
  }
28
23
  );
29
24
  MockedNextImage.displayName = "NextImage";
30
- var getImageProps = /* @__PURE__ */ __name((props) => originalGetImageProps?.({ loader: defaultLoader, ...props }), "getImageProps");
31
- var next_image_default = MockedNextImage;
25
+ var getImageProps = (props) => originalGetImageProps?.({ loader: defaultLoader, ...props }), next_image_default = MockedNextImage;
32
26
  export {
33
27
  next_image_default as default,
34
28
  getImageProps
@@ -1,9 +1,7 @@
1
1
  import {
2
2
  defaultLoader
3
- } from "../_browser-chunks/chunk-I5RFHXDS.js";
4
- import {
5
- __name
6
- } from "../_browser-chunks/chunk-L5NVL7MD.js";
3
+ } from "../_browser-chunks/chunk-RDMFII4N.js";
4
+ import "../_browser-chunks/chunk-SL3VIQZ3.js";
7
5
 
8
6
  // src/images/next-legacy-image.tsx
9
7
  import React from "react";
@@ -11,10 +9,9 @@ import { ImageContext as ImageContextValue } from "@storybook/nextjs/image-conte
11
9
  import OriginalNextLegacyImage from "sb-original/next/legacy/image";
12
10
  var ImageContext = ImageContextValue;
13
11
  function NextLegacyImage({ loader, ...props }) {
14
- const imageParameters = React.useContext(ImageContext);
12
+ let imageParameters = React.useContext(ImageContext);
15
13
  return React.createElement(OriginalNextLegacyImage, { ...imageParameters, ...props, loader: loader ?? defaultLoader });
16
14
  }
17
- __name(NextLegacyImage, "NextLegacyImage");
18
15
  var next_legacy_image_default = NextLegacyImage;
19
16
  export {
20
17
  next_legacy_image_default as default