@storybook/nextjs 9.2.0-alpha.2 → 10.0.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 (86) hide show
  1. package/README.md +3 -1
  2. package/dist/_browser-chunks/chunk-I5RFHXDS.js +40 -0
  3. package/dist/_browser-chunks/chunk-JOMP7DUK.js +261 -0
  4. package/dist/_browser-chunks/chunk-L5NVL7MD.js +37 -0
  5. package/dist/_browser-chunks/react-18-G7Q4PNHD.js +71 -0
  6. package/dist/_node-chunks/chunk-24UYJEDD.js +74 -0
  7. package/dist/_node-chunks/chunk-EZEBG77A.js +88 -0
  8. package/dist/_node-chunks/chunk-WCSGFZKZ.js +17 -0
  9. package/dist/_node-chunks/chunk-YMVPQWBH.js +167 -0
  10. package/dist/_node-chunks/configureNextFont-HBRWHAUG.js +36 -0
  11. package/dist/_node-chunks/loader-KXTZ5PJ5.js +51 -0
  12. package/dist/_node-chunks/loader-Z4IXWF5M.js +64 -0
  13. package/dist/_node-chunks/utils-4LRBHVQD.js +31 -0
  14. package/dist/_node-chunks/webpack-6HAXGE7X.js +38 -0
  15. package/dist/_node-chunks/webpack-AGNCA7HZ.js +77 -0
  16. package/dist/_node-chunks/webpack-CXSD35E6.js +30 -0
  17. package/dist/_node-chunks/webpack-EWT6TRQB.js +26 -0
  18. package/dist/_node-chunks/webpack-K2R3GUFU.js +29 -0
  19. package/dist/_node-chunks/webpack-PD7PIB6X.js +43 -0
  20. package/dist/_node-chunks/webpack-QFTZE3CE.js +27 -0
  21. package/dist/_node-chunks/webpack-SWQY6JJY.js +107 -0
  22. package/dist/compatibility/draft-mode.compat.js +7 -1
  23. package/dist/export-mocks/cache/index.d.ts +309 -1
  24. package/dist/export-mocks/cache/index.js +22 -1
  25. package/dist/export-mocks/headers/index.d.ts +309 -1
  26. package/dist/export-mocks/headers/index.js +77 -1
  27. package/dist/export-mocks/index.js +20 -1
  28. package/dist/export-mocks/navigation/index.d.ts +8 -1
  29. package/dist/export-mocks/navigation/index.js +88 -1
  30. package/dist/export-mocks/router/index.d.ts +2 -2
  31. package/dist/export-mocks/router/index.js +97 -1
  32. package/dist/font/webpack/loader/storybook-nextjs-font-loader.js +201 -14
  33. package/dist/image-context.js +8 -1
  34. package/dist/images/next-image.js +35 -1
  35. package/dist/images/next-legacy-image.js +21 -1
  36. package/dist/index.d.ts +53 -8
  37. package/dist/index.js +20237 -45
  38. package/dist/next-image-loader-stub.js +33 -1
  39. package/dist/node/index.d.ts +27 -6
  40. package/dist/node/index.js +23 -1
  41. package/dist/preset.js +830 -1
  42. package/dist/preview.d.ts +3 -18
  43. package/dist/preview.d.tsx +18 -0
  44. package/dist/preview.js +11 -1
  45. package/dist/rsc/server-only.js +7 -1
  46. package/dist/swc/next-swc-loader-patch.js +136 -1
  47. package/package.json +41 -122
  48. package/preset.js +1 -1
  49. package/template/cli/js/Configure.mdx +11 -11
  50. package/template/cli/ts/Configure.mdx +11 -11
  51. package/dist/chunk-2TZKD6A5.mjs +0 -20
  52. package/dist/chunk-ETFXNGLC.mjs +0 -3
  53. package/dist/chunk-L66KIASX.mjs +0 -3
  54. package/dist/chunk-NQ32RFK2.mjs +0 -6
  55. package/dist/compatibility/draft-mode.compat.d.ts +0 -1
  56. package/dist/compatibility/draft-mode.compat.mjs +0 -2
  57. package/dist/export-mocks/cache/index.mjs +0 -10
  58. package/dist/export-mocks/headers/index.mjs +0 -12
  59. package/dist/export-mocks/index.d.ts +0 -7
  60. package/dist/export-mocks/index.mjs +0 -11
  61. package/dist/export-mocks/navigation/index.mjs +0 -11
  62. package/dist/export-mocks/router/index.mjs +0 -10
  63. package/dist/font/webpack/loader/storybook-nextjs-font-loader.d.ts +0 -3
  64. package/dist/font/webpack/loader/storybook-nextjs-font-loader.mjs +0 -56
  65. package/dist/image-context.d.ts +0 -13
  66. package/dist/image-context.mjs +0 -6
  67. package/dist/images/decorator.d.ts +0 -6
  68. package/dist/images/decorator.js +0 -1
  69. package/dist/images/decorator.mjs +0 -2
  70. package/dist/images/next-image.d.ts +0 -28
  71. package/dist/images/next-image.mjs +0 -9
  72. package/dist/images/next-legacy-image.d.ts +0 -6
  73. package/dist/images/next-legacy-image.mjs +0 -9
  74. package/dist/index.d-ff220430.d.ts +0 -310
  75. package/dist/index.mjs +0 -58
  76. package/dist/next-image-loader-stub.d.ts +0 -10
  77. package/dist/next-image-loader-stub.mjs +0 -7
  78. package/dist/node/index.mjs +0 -5
  79. package/dist/preset.d.ts +0 -14
  80. package/dist/preview.mjs +0 -3
  81. package/dist/react-18-WSPZ3BUV.mjs +0 -7
  82. package/dist/rsc/server-only.d.ts +0 -3
  83. package/dist/rsc/server-only.mjs +0 -5
  84. package/dist/swc/next-swc-loader-patch.d.ts +0 -21
  85. package/dist/swc/next-swc-loader-patch.mjs +0 -8
  86. package/dist/types-f6ea2c09.d.ts +0 -54
@@ -1,23 +1,167 @@
1
- "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var storybook_nextjs_font_loader_exports={};__export(storybook_nextjs_font_loader_exports,{default:()=>storybookNextjsFontLoader});module.exports=__toCommonJS(storybook_nextjs_font_loader_exports);var import_node_path2=require("path");var import_server_errors=require("storybook/internal/server-errors"),import_fetch_css_from_google_fonts=require("next/dist/compiled/@next/font/dist/google/fetch-css-from-google-fonts"),import_get_font_axes=require("next/dist/compiled/@next/font/dist/google/get-font-axes"),import_get_google_fonts_url=require("next/dist/compiled/@next/font/dist/google/get-google-fonts-url"),import_validate_google_font_function_call=require("next/dist/compiled/@next/font/dist/google/validate-google-font-function-call"),import_loader_utils3=__toESM(require("next/dist/compiled/loader-utils3")),cssCache=new Map;async function getFontFaceDeclarations(options){let{fontFamily,weights,styles,selectedVariableAxes,display,variable}=(0,import_validate_google_font_function_call.validateGoogleFontFunctionCall)(options.fontFamily,options.props),fontAxes=(0,import_get_font_axes.getFontAxes)(fontFamily,weights,styles,selectedVariableAxes),url=(0,import_get_google_fonts_url.getGoogleFontsUrl)(fontFamily,fontAxes,display);try{let hasCachedCSS=cssCache.has(url),fontFaceCSS=hasCachedCSS?cssCache.get(url):await(0,import_fetch_css_from_google_fonts.fetchCSSFromGoogleFonts)(url,fontFamily,!0).catch(()=>null);if(hasCachedCSS?cssCache.delete(url):cssCache.set(url,fontFaceCSS),fontFaceCSS===null)throw new import_server_errors.GoogleFontsDownloadError({fontFamily,url});return{id:import_loader_utils3.default.getHashDigest(url,"md5","hex",6),fontFamily,fontFaceCSS,weights,styles,variable}}catch(error){throw new import_server_errors.GoogleFontsLoadingError({error,url})}}var import_node_path=require("path"),import_common=require("storybook/internal/common"),import_validate_local_font_function_call=require("next/dist/compiled/@next/font/dist/local/validate-local-font-function-call"),import_loader_utils32=__toESM(require("next/dist/compiled/loader-utils3"));async function getFontFaceDeclarations2(options,rootContext,swcMode){let localFontSrc=options.props.src,parentFolder=swcMode?(0,import_node_path.dirname)((0,import_node_path.join)((0,import_common.getProjectRoot)(),options.filename)).replace(rootContext,""):(0,import_node_path.dirname)(options.filename).replace(rootContext,""),{weight,style,variable,declarations=[]}=(0,import_validate_local_font_function_call.validateLocalFontFunctionCall)("",options.props),id=`font-${import_loader_utils32.default.getHashDigest(Buffer.from(JSON.stringify(localFontSrc)),"md5","hex",6)}`,fontDeclarations=declarations.map(({prop,value})=>`${prop}: ${value};`).join(`
2
- `);return{id,fontFamily:id,fontFaceCSS:(()=>{if(typeof localFontSrc=="string"){let localFontPath=(0,import_node_path.join)(parentFolder,localFontSrc).replaceAll("\\","/");return`@font-face {
1
+ import CJS_COMPAT_NODE_URL_e3twfmexlgl from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_e3twfmexlgl from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_e3twfmexlgl from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_e3twfmexlgl.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_e3twfmexlgl.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_e3twfmexlgl.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ __name
14
+ } from "../../../_node-chunks/chunk-WCSGFZKZ.js";
15
+
16
+ // src/font/webpack/loader/storybook-nextjs-font-loader.ts
17
+ import { sep } from "node:path";
18
+
19
+ // src/font/webpack/loader/google/get-font-face-declarations.ts
20
+ import {
21
+ GoogleFontsDownloadError,
22
+ GoogleFontsLoadingError
23
+ } from "storybook/internal/server-errors";
24
+ import { fetchCSSFromGoogleFonts } from "next/dist/compiled/@next/font/dist/google/fetch-css-from-google-fonts.js";
25
+ import { getFontAxes } from "next/dist/compiled/@next/font/dist/google/get-font-axes.js";
26
+ import { getGoogleFontsUrl } from "next/dist/compiled/@next/font/dist/google/get-google-fonts-url.js";
27
+ import { validateGoogleFontFunctionCall } from "next/dist/compiled/@next/font/dist/google/validate-google-font-function-call.js";
28
+ import loaderUtils from "next/dist/compiled/loader-utils3/index.js";
29
+ var cssCache = /* @__PURE__ */ new Map();
30
+ 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);
34
+ 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) {
43
+ throw new GoogleFontsDownloadError({
44
+ fontFamily,
45
+ url
46
+ });
47
+ }
48
+ return {
49
+ id: loaderUtils.getHashDigest(url, "md5", "hex", 6),
50
+ fontFamily,
51
+ fontFaceCSS,
52
+ weights,
53
+ styles,
54
+ variable
55
+ };
56
+ } catch (error) {
57
+ throw new GoogleFontsLoadingError({ error, url });
58
+ }
59
+ }
60
+ __name(getFontFaceDeclarations, "getFontFaceDeclarations");
61
+
62
+ // src/font/webpack/loader/local/get-font-face-declarations.ts
63
+ import { dirname, join } from "node:path";
64
+ import { getProjectRoot } from "storybook/internal/common";
65
+ import { validateLocalFontFunctionCall } from "next/dist/compiled/@next/font/dist/local/validate-local-font-function-call.js";
66
+ import loaderUtils2 from "next/dist/compiled/loader-utils3/index.js";
67
+ 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 {
71
+ weight,
72
+ style,
73
+ variable,
74
+ declarations = []
75
+ } = validateLocalFontFunctionCall("", options.props);
76
+ const id = `font-${loaderUtils2.getHashDigest(
77
+ Buffer.from(JSON.stringify(localFontSrc)),
78
+ "md5",
79
+ "hex",
80
+ 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 {
3
87
  font-family: ${id};
4
88
  src: url(.${localFontPath});
5
89
  ${fontDeclarations}
6
- }`}return localFontSrc.map(font=>{let localFontPath=(0,import_node_path.join)(parentFolder,font.path).replaceAll("\\","/");return`@font-face {
90
+ }`;
91
+ }
92
+ return localFontSrc.map((font) => {
93
+ const localFontPath = join(parentFolder, font.path).replaceAll("\\", "/");
94
+ return `@font-face {
7
95
  font-family: ${id};
8
96
  src: url(.${localFontPath});
9
- ${font.weight?`font-weight: ${font.weight};`:""}
10
- ${font.style?`font-style: ${font.style};`:""}
97
+ ${font.weight ? `font-weight: ${font.weight};` : ""}
98
+ ${font.style ? `font-style: ${font.style};` : ""}
11
99
  ${fontDeclarations}
12
- }`}).join("")})(),weights:weight?[weight]:[],styles:style?[style]:[],variable}}function getCSSMeta(options){let className=getClassName(options),style=getStylesObj(options),variableClassName=`__variable_${className}`,classNamesCSS=`
100
+ }`;
101
+ }).join("");
102
+ }, "getFontFaceCSS");
103
+ return {
104
+ id,
105
+ fontFamily: id,
106
+ fontFaceCSS: getFontFaceCSS(),
107
+ weights: weight ? [weight] : [],
108
+ styles: style ? [style] : [],
109
+ variable
110
+ };
111
+ }
112
+ __name(getFontFaceDeclarations2, "getFontFaceDeclarations");
113
+
114
+ // src/font/webpack/loader/utils/get-css-meta.ts
115
+ function getCSSMeta(options) {
116
+ const className = getClassName(options);
117
+ const style = getStylesObj(options);
118
+ const variableClassName = `__variable_${className}`;
119
+ const classNamesCSS = `
13
120
  .${className} {
14
121
  font-family: ${options.fontFamily};
15
- ${isNextCSSPropertyValid(options.styles)?`font-style: ${options.styles[0]};`:""}
16
- ${isNextCSSPropertyValid(options.weights)?`font-weight: ${options.weights[0]};`:""}
122
+ ${isNextCSSPropertyValid(options.styles) ? `font-style: ${options.styles[0]};` : ""}
123
+ ${isNextCSSPropertyValid(options.weights) ? `font-weight: ${options.weights[0]};` : ""}
17
124
  }
18
125
 
19
- ${options.variable?`.${variableClassName} { ${options.variable}: '${options.fontFamily}'; }`:""}
20
- `,fontFaceCSS=`${changeFontDisplayToSwap(options.fontFaceCSS)}`;return{className,fontFaceCSS,classNamesCSS,style,...options.variable?{variableClassName}:{}}}function getClassName({styles,weights,fontFamily}){let font=fontFamily.replaceAll(" ","-").toLowerCase(),style=isNextCSSPropertyValid(styles)?styles[0]:null,weight=isNextCSSPropertyValid(weights)?weights[0]:null;return`${font}${style?`-${style}`:""}${weight?`-${weight}`:""}`}function getStylesObj({styles,weights,fontFamily}){return{fontFamily,...isNextCSSPropertyValid(styles)?{fontStyle:styles[0]}:{},...isNextCSSPropertyValid(weights)?{fontWeight:weights[0]}:{}}}function isNextCSSPropertyValid(prop){return prop.length===1&&prop[0]!=="variable"}function changeFontDisplayToSwap(css){return css.replaceAll("font-display: optional;","font-display: block;")}function setFontDeclarationsInHead({id,fontFaceCSS,classNamesCSS}){return`
126
+ ${options.variable ? `.${variableClassName} { ${options.variable}: '${options.fontFamily}'; }` : ""}
127
+ `;
128
+ const fontFaceCSS = `${changeFontDisplayToSwap(options.fontFaceCSS)}`;
129
+ return {
130
+ className,
131
+ fontFaceCSS,
132
+ classNamesCSS,
133
+ style,
134
+ ...options.variable ? { variableClassName } : {}
135
+ };
136
+ }
137
+ __name(getCSSMeta, "getCSSMeta");
138
+ 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;
142
+ return `${font}${style ? `-${style}` : ""}${weight ? `-${weight}` : ""}`;
143
+ }
144
+ __name(getClassName, "getClassName");
145
+ function getStylesObj({ styles, weights, fontFamily }) {
146
+ return {
147
+ fontFamily,
148
+ ...isNextCSSPropertyValid(styles) ? { fontStyle: styles[0] } : {},
149
+ ...isNextCSSPropertyValid(weights) ? { fontWeight: weights[0] } : {}
150
+ };
151
+ }
152
+ __name(getStylesObj, "getStylesObj");
153
+ function isNextCSSPropertyValid(prop) {
154
+ return prop.length === 1 && prop[0] !== "variable";
155
+ }
156
+ __name(isNextCSSPropertyValid, "isNextCSSPropertyValid");
157
+ function changeFontDisplayToSwap(css) {
158
+ return css.replaceAll("font-display: optional;", "font-display: block;");
159
+ }
160
+ __name(changeFontDisplayToSwap, "changeFontDisplayToSwap");
161
+
162
+ // src/font/webpack/loader/utils/set-font-declarations-in-head.ts
163
+ function setFontDeclarationsInHead({ id, fontFaceCSS, classNamesCSS }) {
164
+ return `
21
165
  if (!document.getElementById('id-${id}')) {
22
166
  const fontDeclarations = \`${fontFaceCSS}\`;
23
167
  const style = document.createElement('style');
@@ -32,12 +176,55 @@
32
176
  document.head.appendChild(classNamesStyle);
33
177
 
34
178
  }
35
- `}async function storybookNextjsFontLoader(){let loaderOptions=this.getOptions(),swcMode=!1,options;if(Object.keys(loaderOptions).length>0)options=loaderOptions;else{let importQuery=JSON.parse(this.resourceQuery.slice(1));swcMode=!0,options={filename:importQuery.path,fontFamily:importQuery.import,props:importQuery.arguments[0],source:this.context.replace(this.rootContext,"")}}let rootCtx=this.rootContext,fontFaceDeclaration,pathSep=import_node_path2.sep;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"){let cssMeta=getCSSMeta(fontFaceDeclaration);return`
36
- ${setFontDeclarationsInHead({fontFaceCSS:cssMeta.fontFaceCSS,id:fontFaceDeclaration.id,classNamesCSS:cssMeta.classNamesCSS})}
179
+ `;
180
+ }
181
+ __name(setFontDeclarationsInHead, "setFontDeclarationsInHead");
182
+
183
+ // src/font/webpack/loader/storybook-nextjs-font-loader.ts
184
+ async function storybookNextjsFontLoader() {
185
+ const loaderOptions = this.getOptions();
186
+ let swcMode = false;
187
+ let options;
188
+ if (Object.keys(loaderOptions).length > 0) {
189
+ options = loaderOptions;
190
+ } else {
191
+ const importQuery = JSON.parse(this.resourceQuery.slice(1));
192
+ swcMode = true;
193
+ options = {
194
+ filename: importQuery.path,
195
+ fontFamily: importQuery.import,
196
+ props: importQuery.arguments[0],
197
+ source: this.context.replace(this.rootContext, "")
198
+ };
199
+ }
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);
211
+ return `
212
+ ${setFontDeclarationsInHead({
213
+ fontFaceCSS: cssMeta.fontFaceCSS,
214
+ id: fontFaceDeclaration.id,
215
+ classNamesCSS: cssMeta.classNamesCSS
216
+ })}
37
217
 
38
218
  module.exports = {
39
219
  className: "${cssMeta.className}",
40
220
  style: ${JSON.stringify(cssMeta.style)}
41
- ${cssMeta.variableClassName?`, variable: "${cssMeta.variableClassName}"`:""}
221
+ ${cssMeta.variableClassName ? `, variable: "${cssMeta.variableClassName}"` : ""}
42
222
  }
43
- `}return"module.exports = {}"}
223
+ `;
224
+ }
225
+ return `module.exports = {}`;
226
+ }
227
+ __name(storybookNextjsFontLoader, "storybookNextjsFontLoader");
228
+ export {
229
+ storybookNextjsFontLoader as default
230
+ };
@@ -1 +1,8 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var image_context_exports={};__export(image_context_exports,{ImageContext:()=>ImageContext});module.exports=__toCommonJS(image_context_exports);var import_react=require("react"),ImageContext=(0,import_react.createContext)({});0&&(module.exports={ImageContext});
1
+ import "./_browser-chunks/chunk-L5NVL7MD.js";
2
+
3
+ // src/image-context.ts
4
+ import { createContext } from "react";
5
+ var ImageContext = createContext({});
6
+ export {
7
+ ImageContext
8
+ };
@@ -1 +1,35 @@
1
- "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var next_image_exports={};__export(next_image_exports,{default:()=>next_image_default,getImageProps:()=>getImageProps});module.exports=__toCommonJS(next_image_exports);var import_react=__toESM(require("react")),import_image_context=require("@storybook/nextjs/dist/image-context"),NextImageNamespace=__toESM(require("sb-original/next/image"));var defaultLoader=({src,width,quality=75})=>{let missingValues=[];if(src||missingValues.push("src"),width||missingValues.push("width"),missingValues.length>0)throw new Error(`Next Image Optimization requires ${missingValues.join(", ")} to be provided. Make sure you pass them as props to the \`next/image\` component. Received: ${JSON.stringify({src,width,quality})}`);let url=new URL(src,window.location.href);return!url.searchParams.has("w")&&!url.searchParams.has("q")&&(url.searchParams.set("w",width.toString()),url.searchParams.set("q",quality.toString())),!src.startsWith("http://")&&!src.startsWith("https://")?url.toString().slice(url.origin.length):url.toString()};var OriginalNextImage=NextImageNamespace.default,{getImageProps:originalGetImageProps}=NextImageNamespace,ImageContext=import_image_context.ImageContext,MockedNextImage=import_react.default.forwardRef(({loader,...props},ref)=>{let imageParameters=import_react.default.useContext(ImageContext);return import_react.default.createElement(OriginalNextImage,{ref,...imageParameters,...props,loader:loader??defaultLoader})});MockedNextImage.displayName="NextImage";var getImageProps=props=>originalGetImageProps?.({loader:defaultLoader,...props}),next_image_default=MockedNextImage;0&&(module.exports={getImageProps});
1
+ import {
2
+ defaultLoader
3
+ } from "../_browser-chunks/chunk-I5RFHXDS.js";
4
+ import {
5
+ __name
6
+ } from "../_browser-chunks/chunk-L5NVL7MD.js";
7
+
8
+ // src/images/next-image.tsx
9
+ import React from "react";
10
+ import { ImageContext as ImageContextValue } from "@storybook/nextjs/image-context";
11
+ 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(
16
+ ({ loader, ...props }, ref) => {
17
+ const imageParameters = React.useContext(ImageContext);
18
+ return React.createElement(
19
+ OriginalNextImage,
20
+ {
21
+ ref,
22
+ ...imageParameters,
23
+ ...props,
24
+ loader: loader ?? defaultLoader
25
+ }
26
+ );
27
+ }
28
+ );
29
+ MockedNextImage.displayName = "NextImage";
30
+ var getImageProps = /* @__PURE__ */ __name((props) => originalGetImageProps?.({ loader: defaultLoader, ...props }), "getImageProps");
31
+ var next_image_default = MockedNextImage;
32
+ export {
33
+ next_image_default as default,
34
+ getImageProps
35
+ };
@@ -1 +1,21 @@
1
- "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var next_legacy_image_exports={};__export(next_legacy_image_exports,{default:()=>next_legacy_image_default});module.exports=__toCommonJS(next_legacy_image_exports);var import_react=__toESM(require("react")),import_image_context=require("@storybook/nextjs/dist/image-context"),import_image=__toESM(require("sb-original/next/legacy/image"));var defaultLoader=({src,width,quality=75})=>{let missingValues=[];if(src||missingValues.push("src"),width||missingValues.push("width"),missingValues.length>0)throw new Error(`Next Image Optimization requires ${missingValues.join(", ")} to be provided. Make sure you pass them as props to the \`next/image\` component. Received: ${JSON.stringify({src,width,quality})}`);let url=new URL(src,window.location.href);return!url.searchParams.has("w")&&!url.searchParams.has("q")&&(url.searchParams.set("w",width.toString()),url.searchParams.set("q",quality.toString())),!src.startsWith("http://")&&!src.startsWith("https://")?url.toString().slice(url.origin.length):url.toString()};var ImageContext=import_image_context.ImageContext;function NextLegacyImage({loader,...props}){let imageParameters=import_react.default.useContext(ImageContext);return import_react.default.createElement(import_image.default,{...imageParameters,...props,loader:loader??defaultLoader})}var next_legacy_image_default=NextLegacyImage;
1
+ import {
2
+ defaultLoader
3
+ } from "../_browser-chunks/chunk-I5RFHXDS.js";
4
+ import {
5
+ __name
6
+ } from "../_browser-chunks/chunk-L5NVL7MD.js";
7
+
8
+ // src/images/next-legacy-image.tsx
9
+ import React from "react";
10
+ import { ImageContext as ImageContextValue } from "@storybook/nextjs/image-context";
11
+ import OriginalNextLegacyImage from "sb-original/next/legacy/image";
12
+ var ImageContext = ImageContextValue;
13
+ function NextLegacyImage({ loader, ...props }) {
14
+ const imageParameters = React.useContext(ImageContext);
15
+ return React.createElement(OriginalNextLegacyImage, { ...imageParameters, ...props, loader: loader ?? defaultLoader });
16
+ }
17
+ __name(NextLegacyImage, "NextLegacyImage");
18
+ var next_legacy_image_default = NextLegacyImage;
19
+ export {
20
+ next_legacy_image_default as default
21
+ };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,58 @@
1
1
  import { PreviewAddon, InferTypes, AddonTypes } from 'storybook/internal/csf';
2
- import { NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, Args, StoryAnnotationsOrFn, ProjectAnnotations, ComposedStoryFn, Store_CSFExports, StoriesWithPartialProps } from 'storybook/internal/types';
2
+ import { CompatibleString, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, Args, StoryAnnotationsOrFn, ProjectAnnotations, ComposedStoryFn, Store_CSFExports, StoriesWithPartialProps } from 'storybook/internal/types';
3
3
  import { ReactRenderer, Meta, ReactTypes, ReactPreview } from '@storybook/react';
4
4
  export * from '@storybook/react';
5
- import { N as NextJsTypes } from './types-f6ea2c09.js';
6
- export { F as FrameworkOptions, a as NextJsParameters, S as StorybookConfig } from './types-f6ea2c09.js';
7
- import '@storybook/builder-webpack5';
8
- import '@storybook/preset-react-webpack';
9
- import 'next/image';
10
- import 'next/router';
5
+ import { BuilderOptions, StorybookConfigWebpack, TypescriptOptions } from '@storybook/builder-webpack5';
6
+ import { ReactOptions, StorybookConfig as StorybookConfig$1, TypescriptOptions as TypescriptOptions$1 } from '@storybook/preset-react-webpack';
7
+ import * as NextImage from 'next/image';
8
+ import { NextRouter } from 'next/router';
9
+
10
+ type FrameworkName = CompatibleString<'@storybook/nextjs'>;
11
+ type BuilderName = CompatibleString<'@storybook/builder-webpack5'>;
12
+ type FrameworkOptions = ReactOptions & {
13
+ nextConfigPath?: string;
14
+ image?: Partial<NextImage.ImageProps>;
15
+ builder?: BuilderOptions;
16
+ };
17
+ type StorybookConfigFramework = {
18
+ framework: FrameworkName | {
19
+ name: FrameworkName;
20
+ options: FrameworkOptions;
21
+ };
22
+ core?: StorybookConfig$1['core'] & {
23
+ builder?: BuilderName | {
24
+ name: BuilderName;
25
+ options: BuilderOptions;
26
+ };
27
+ };
28
+ typescript?: Partial<TypescriptOptions & TypescriptOptions$1> & StorybookConfig$1['typescript'];
29
+ };
30
+ /** The interface for Storybook configuration in `main.ts` files. */
31
+ type StorybookConfig = Omit<StorybookConfig$1, keyof StorybookConfigWebpack | keyof StorybookConfigFramework> & StorybookConfigWebpack & StorybookConfigFramework;
32
+ interface NextJsParameters {
33
+ /**
34
+ * Next.js framework configuration
35
+ *
36
+ * @see https://storybook.js.org/docs/get-started/frameworks/nextjs
37
+ */
38
+ nextjs?: {
39
+ /**
40
+ * Enable App Directory features If your story imports components that use next/navigation, you
41
+ * need to set this parameter to true
42
+ */
43
+ appDirectory?: boolean;
44
+ /**
45
+ * Next.js navigation configuration when using `next/navigation`. Please note that it can only
46
+ * be used in components/pages in the app directory.
47
+ */
48
+ navigation?: Partial<NextRouter>;
49
+ /** Next.js router configuration */
50
+ router?: Partial<NextRouter>;
51
+ };
52
+ }
53
+ interface NextJsTypes {
54
+ parameters: NextJsParameters;
55
+ }
11
56
 
12
57
  /**
13
58
  * Function that sets the globalConfig of your storybook. The global config is the preview module of
@@ -93,4 +138,4 @@ declare function definePreview<Addons extends PreviewAddon<never>[]>(preview: {
93
138
  interface NextPreview<T extends AddonTypes> extends ReactPreview<NextJsTypes & T> {
94
139
  }
95
140
 
96
- export { NextJsTypes, composeStories, composeStory, definePreview, setProjectAnnotations };
141
+ export { type FrameworkOptions, type NextJsParameters, type NextJsTypes, type StorybookConfig, composeStories, composeStory, definePreview, setProjectAnnotations };