@storybook/nextjs 9.2.0-alpha.3 → 10.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/_browser-chunks/chunk-I5RFHXDS.js +40 -0
- package/dist/_browser-chunks/chunk-JOMP7DUK.js +261 -0
- package/dist/_browser-chunks/chunk-L5NVL7MD.js +37 -0
- package/dist/_browser-chunks/react-18-G7Q4PNHD.js +71 -0
- package/dist/_node-chunks/chunk-254AWWVV.js +95 -0
- package/dist/_node-chunks/chunk-4Q3WLK5D.js +167 -0
- package/dist/_node-chunks/chunk-DF7TGUJT.js +17 -0
- package/dist/_node-chunks/chunk-N47GZ6ZF.js +74 -0
- package/dist/_node-chunks/configureNextFont-YCA4Y2MY.js +36 -0
- package/dist/_node-chunks/loader-BMOR26K7.js +64 -0
- package/dist/_node-chunks/loader-W6JNOWKU.js +51 -0
- package/dist/_node-chunks/utils-TOBNY3XG.js +31 -0
- package/dist/_node-chunks/webpack-422IPQRP.js +38 -0
- package/dist/_node-chunks/webpack-7CTFG24J.js +107 -0
- package/dist/_node-chunks/webpack-AGJ2TY75.js +29 -0
- package/dist/_node-chunks/webpack-E2SJEFJM.js +27 -0
- package/dist/_node-chunks/webpack-GIA2WMBH.js +77 -0
- package/dist/_node-chunks/webpack-MCDIAAFL.js +43 -0
- package/dist/_node-chunks/webpack-UPXNFNSK.js +26 -0
- package/dist/_node-chunks/webpack-WWJ5TQDG.js +30 -0
- package/dist/compatibility/draft-mode.compat.js +7 -1
- package/dist/export-mocks/cache/index.d.ts +309 -1
- package/dist/export-mocks/cache/index.js +22 -1
- package/dist/export-mocks/headers/index.d.ts +309 -1
- package/dist/export-mocks/headers/index.js +77 -1
- package/dist/export-mocks/index.js +20 -1
- package/dist/export-mocks/navigation/index.js +88 -1
- package/dist/export-mocks/router/index.d.ts +2 -2
- package/dist/export-mocks/router/index.js +97 -1
- package/dist/font/webpack/loader/storybook-nextjs-font-loader.js +201 -14
- package/dist/image-context.js +8 -1
- package/dist/images/next-image.js +35 -1
- package/dist/images/next-legacy-image.js +21 -1
- package/dist/index.d.ts +53 -8
- package/dist/index.js +20237 -45
- package/dist/next-image-loader-stub.js +33 -1
- package/dist/node/index.d.ts +27 -6
- package/dist/node/index.js +23 -1
- package/dist/preset.js +830 -1
- package/dist/preview.d.ts +3 -18
- package/dist/preview.d.tsx +18 -0
- package/dist/preview.js +11 -1
- package/dist/rsc/server-only.js +7 -1
- package/dist/swc/next-swc-loader-patch.js +136 -1
- package/package.json +41 -122
- package/preset.js +1 -1
- package/template/cli/js/Configure.mdx +11 -11
- package/template/cli/ts/Configure.mdx +11 -11
- package/dist/chunk-2TZKD6A5.mjs +0 -20
- package/dist/chunk-ETFXNGLC.mjs +0 -3
- package/dist/chunk-L66KIASX.mjs +0 -3
- package/dist/chunk-NQ32RFK2.mjs +0 -6
- package/dist/compatibility/draft-mode.compat.d.ts +0 -1
- package/dist/compatibility/draft-mode.compat.mjs +0 -2
- package/dist/export-mocks/cache/index.mjs +0 -10
- package/dist/export-mocks/headers/index.mjs +0 -12
- package/dist/export-mocks/index.d.ts +0 -7
- package/dist/export-mocks/index.mjs +0 -11
- package/dist/export-mocks/navigation/index.mjs +0 -11
- package/dist/export-mocks/router/index.mjs +0 -10
- package/dist/font/webpack/loader/storybook-nextjs-font-loader.d.ts +0 -3
- package/dist/font/webpack/loader/storybook-nextjs-font-loader.mjs +0 -56
- package/dist/image-context.d.ts +0 -13
- package/dist/image-context.mjs +0 -6
- package/dist/images/decorator.d.ts +0 -6
- package/dist/images/decorator.js +0 -1
- package/dist/images/decorator.mjs +0 -2
- package/dist/images/next-image.d.ts +0 -28
- package/dist/images/next-image.mjs +0 -9
- package/dist/images/next-legacy-image.d.ts +0 -6
- package/dist/images/next-legacy-image.mjs +0 -9
- package/dist/index.d-ff220430.d.ts +0 -310
- package/dist/index.mjs +0 -58
- package/dist/next-image-loader-stub.d.ts +0 -10
- package/dist/next-image-loader-stub.mjs +0 -7
- package/dist/node/index.mjs +0 -5
- package/dist/preset.d.ts +0 -14
- package/dist/preview.mjs +0 -3
- package/dist/react-18-WSPZ3BUV.mjs +0 -7
- package/dist/rsc/server-only.d.ts +0 -3
- package/dist/rsc/server-only.mjs +0 -5
- package/dist/swc/next-swc-loader-patch.d.ts +0 -21
- package/dist/swc/next-swc-loader-patch.mjs +0 -8
- package/dist/types-f6ea2c09.d.ts +0 -54
|
@@ -1 +1,77 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "../../_browser-chunks/chunk-L5NVL7MD.js";
|
|
4
|
+
|
|
5
|
+
// src/export-mocks/headers/index.ts
|
|
6
|
+
import { draftMode as originalDraftMode } from "next/dist/server/request/draft-mode";
|
|
7
|
+
import * as headers3 from "next/dist/server/request/headers";
|
|
8
|
+
import { fn as fn3 } from "storybook/test";
|
|
9
|
+
export * from "next/dist/server/request/headers";
|
|
10
|
+
|
|
11
|
+
// src/export-mocks/headers/headers.ts
|
|
12
|
+
import { HeadersAdapter } from "next/dist/server/web/spec-extension/adapters/headers";
|
|
13
|
+
import { fn } from "storybook/test";
|
|
14
|
+
var _HeadersAdapterMock = class _HeadersAdapterMock extends HeadersAdapter {
|
|
15
|
+
constructor() {
|
|
16
|
+
super({});
|
|
17
|
+
this.append = fn(super.append.bind(this)).mockName("next/headers::headers().append");
|
|
18
|
+
this.delete = fn(super.delete.bind(this)).mockName("next/headers::headers().delete");
|
|
19
|
+
this.get = fn(super.get.bind(this)).mockName("next/headers::headers().get");
|
|
20
|
+
this.has = fn(super.has.bind(this)).mockName("next/headers::headers().has");
|
|
21
|
+
this.set = fn(super.set.bind(this)).mockName("next/headers::headers().set");
|
|
22
|
+
this.forEach = fn(super.forEach.bind(this)).mockName("next/headers::headers().forEach");
|
|
23
|
+
this.entries = fn(super.entries.bind(this)).mockName("next/headers::headers().entries");
|
|
24
|
+
this.keys = fn(super.keys.bind(this)).mockName("next/headers::headers().keys");
|
|
25
|
+
this.values = fn(super.values.bind(this)).mockName("next/headers::headers().values");
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
__name(_HeadersAdapterMock, "HeadersAdapterMock");
|
|
29
|
+
var HeadersAdapterMock = _HeadersAdapterMock;
|
|
30
|
+
var headersAdapterMock;
|
|
31
|
+
var headers = /* @__PURE__ */ __name(() => {
|
|
32
|
+
if (!headersAdapterMock) {
|
|
33
|
+
headersAdapterMock = new HeadersAdapterMock();
|
|
34
|
+
}
|
|
35
|
+
return headersAdapterMock;
|
|
36
|
+
}, "headers");
|
|
37
|
+
headers.mockRestore = () => {
|
|
38
|
+
headersAdapterMock = new HeadersAdapterMock();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/export-mocks/headers/cookies.ts
|
|
42
|
+
import { headers as headers2 } from "@storybook/nextjs/headers.mock";
|
|
43
|
+
import { RequestCookies } from "next/dist/compiled/@edge-runtime/cookies";
|
|
44
|
+
import { fn as fn2 } from "storybook/test";
|
|
45
|
+
var _RequestCookiesMock = class _RequestCookiesMock extends RequestCookies {
|
|
46
|
+
constructor() {
|
|
47
|
+
super(...arguments);
|
|
48
|
+
this.get = fn2(super.get.bind(this)).mockName("next/headers::cookies().get");
|
|
49
|
+
this.getAll = fn2(super.getAll.bind(this)).mockName("next/headers::cookies().getAll");
|
|
50
|
+
this.has = fn2(super.has.bind(this)).mockName("next/headers::cookies().has");
|
|
51
|
+
this.set = fn2(super.set.bind(this)).mockName("next/headers::cookies().set");
|
|
52
|
+
this.delete = fn2(super.delete.bind(this)).mockName("next/headers::cookies().delete");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
__name(_RequestCookiesMock, "RequestCookiesMock");
|
|
56
|
+
var RequestCookiesMock = _RequestCookiesMock;
|
|
57
|
+
var requestCookiesMock;
|
|
58
|
+
var cookies = fn2(() => {
|
|
59
|
+
if (!requestCookiesMock) {
|
|
60
|
+
requestCookiesMock = new RequestCookiesMock(headers2());
|
|
61
|
+
}
|
|
62
|
+
return requestCookiesMock;
|
|
63
|
+
}).mockName("next/headers::cookies()");
|
|
64
|
+
var originalRestore = cookies.mockRestore.bind(null);
|
|
65
|
+
cookies.mockRestore = () => {
|
|
66
|
+
originalRestore();
|
|
67
|
+
headers2.mockRestore();
|
|
68
|
+
requestCookiesMock = new RequestCookiesMock(headers2());
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/export-mocks/headers/index.ts
|
|
72
|
+
var draftMode2 = fn3(originalDraftMode ?? headers3.draftMode).mockName("draftMode");
|
|
73
|
+
export {
|
|
74
|
+
cookies,
|
|
75
|
+
draftMode2 as draftMode,
|
|
76
|
+
headers
|
|
77
|
+
};
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import CJS_COMPAT_NODE_URL_nafzxsaqn from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_nafzxsaqn from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_nafzxsaqn from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_nafzxsaqn.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_nafzxsaqn.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_nafzxsaqn.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import {
|
|
13
|
+
getPackageAliases
|
|
14
|
+
} from "../_node-chunks/chunk-N47GZ6ZF.js";
|
|
15
|
+
import "../_node-chunks/chunk-254AWWVV.js";
|
|
16
|
+
import "../_node-chunks/chunk-4Q3WLK5D.js";
|
|
17
|
+
import "../_node-chunks/chunk-DF7TGUJT.js";
|
|
18
|
+
export {
|
|
19
|
+
getPackageAliases
|
|
20
|
+
};
|
|
@@ -1 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "../../_browser-chunks/chunk-L5NVL7MD.js";
|
|
4
|
+
|
|
5
|
+
// src/export-mocks/navigation/index.ts
|
|
6
|
+
import { NextjsRouterMocksNotAvailable } from "storybook/internal/preview-errors";
|
|
7
|
+
import * as actual from "next/dist/client/components/navigation";
|
|
8
|
+
import { getRedirectError } from "next/dist/client/components/redirect";
|
|
9
|
+
import { RedirectStatusCode } from "next/dist/client/components/redirect-status-code";
|
|
10
|
+
import { fn } from "storybook/test";
|
|
11
|
+
export * from "next/dist/client/components/navigation";
|
|
12
|
+
var navigationAPI;
|
|
13
|
+
var createNavigation = /* @__PURE__ */ __name((overrides) => {
|
|
14
|
+
const navigationActions = {
|
|
15
|
+
push: fn().mockName("next/navigation::useRouter().push"),
|
|
16
|
+
replace: fn().mockName("next/navigation::useRouter().replace"),
|
|
17
|
+
forward: fn().mockName("next/navigation::useRouter().forward"),
|
|
18
|
+
back: fn().mockName("next/navigation::useRouter().back"),
|
|
19
|
+
prefetch: fn().mockName("next/navigation::useRouter().prefetch"),
|
|
20
|
+
refresh: fn().mockName("next/navigation::useRouter().refresh")
|
|
21
|
+
};
|
|
22
|
+
if (overrides) {
|
|
23
|
+
Object.keys(navigationActions).forEach((key) => {
|
|
24
|
+
if (key in overrides) {
|
|
25
|
+
navigationActions[key] = fn((...args) => {
|
|
26
|
+
return overrides[key](...args);
|
|
27
|
+
}).mockName(`useRouter().${key}`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
navigationAPI = navigationActions;
|
|
32
|
+
return navigationAPI;
|
|
33
|
+
}, "createNavigation");
|
|
34
|
+
var getRouter = /* @__PURE__ */ __name(() => {
|
|
35
|
+
if (!navigationAPI) {
|
|
36
|
+
throw new NextjsRouterMocksNotAvailable({
|
|
37
|
+
importType: "next/navigation"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return navigationAPI;
|
|
41
|
+
}, "getRouter");
|
|
42
|
+
var redirect = fn(
|
|
43
|
+
(url, type = actual.RedirectType.push) => {
|
|
44
|
+
throw getRedirectError(url, type, RedirectStatusCode.SeeOther);
|
|
45
|
+
}
|
|
46
|
+
).mockName("next/navigation::redirect");
|
|
47
|
+
var permanentRedirect = fn(
|
|
48
|
+
(url, type = actual.RedirectType.push) => {
|
|
49
|
+
throw getRedirectError(url, type, RedirectStatusCode.SeeOther);
|
|
50
|
+
}
|
|
51
|
+
).mockName("next/navigation::permanentRedirect");
|
|
52
|
+
var useSearchParams2 = fn(actual.useSearchParams).mockName(
|
|
53
|
+
"next/navigation::useSearchParams"
|
|
54
|
+
);
|
|
55
|
+
var usePathname2 = fn(actual.usePathname).mockName("next/navigation::usePathname");
|
|
56
|
+
var useSelectedLayoutSegment2 = fn(actual.useSelectedLayoutSegment).mockName(
|
|
57
|
+
"next/navigation::useSelectedLayoutSegment"
|
|
58
|
+
);
|
|
59
|
+
var useSelectedLayoutSegments2 = fn(actual.useSelectedLayoutSegments).mockName(
|
|
60
|
+
"next/navigation::useSelectedLayoutSegments"
|
|
61
|
+
);
|
|
62
|
+
var useRouter = fn(() => {
|
|
63
|
+
if (!navigationAPI) {
|
|
64
|
+
throw new NextjsRouterMocksNotAvailable({
|
|
65
|
+
importType: "next/navigation"
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return navigationAPI;
|
|
69
|
+
}).mockName("next/navigation::useRouter");
|
|
70
|
+
var useServerInsertedHTML2 = fn(actual.useServerInsertedHTML).mockName(
|
|
71
|
+
"next/navigation::useServerInsertedHTML"
|
|
72
|
+
);
|
|
73
|
+
var notFound2 = fn(actual.notFound).mockName("next/navigation::notFound");
|
|
74
|
+
var useParams2 = fn(actual.useParams).mockName("next/navigation::useParams");
|
|
75
|
+
export {
|
|
76
|
+
createNavigation,
|
|
77
|
+
getRouter,
|
|
78
|
+
notFound2 as notFound,
|
|
79
|
+
permanentRedirect,
|
|
80
|
+
redirect,
|
|
81
|
+
useParams2 as useParams,
|
|
82
|
+
usePathname2 as usePathname,
|
|
83
|
+
useRouter,
|
|
84
|
+
useSearchParams2 as useSearchParams,
|
|
85
|
+
useSelectedLayoutSegment2 as useSelectedLayoutSegment,
|
|
86
|
+
useSelectedLayoutSegments2 as useSelectedLayoutSegments,
|
|
87
|
+
useServerInsertedHTML2 as useServerInsertedHTML
|
|
88
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import * as next_dist_client_with_router from 'next/dist/client/with-router';
|
|
3
3
|
import * as next from 'next';
|
|
4
4
|
import * as singletonRouter from 'next/dist/client/router';
|
|
@@ -41,6 +41,6 @@ declare const getRouter: () => {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
declare const useRouter: Mock<typeof singletonRouter.useRouter>;
|
|
44
|
-
declare const withRouter: Mock<(ComposedComponent: next.NextComponentType<next.NextPageContext, any, next_dist_client_with_router.WithRouterProps>) =>
|
|
44
|
+
declare const withRouter: Mock<(ComposedComponent: next.NextComponentType<next.NextPageContext, any, next_dist_client_with_router.WithRouterProps>) => react.ComponentType<next_dist_client_with_router.ExcludeRouterProps<next_dist_client_with_router.WithRouterProps>>>;
|
|
45
45
|
|
|
46
46
|
export { createRouter, getRouter, useRouter, withRouter };
|
|
@@ -1 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "../../_browser-chunks/chunk-L5NVL7MD.js";
|
|
4
|
+
|
|
5
|
+
// src/export-mocks/router/index.ts
|
|
6
|
+
import { NextjsRouterMocksNotAvailable } from "storybook/internal/preview-errors";
|
|
7
|
+
import singletonRouter, * as originalRouter from "next/dist/client/router";
|
|
8
|
+
import { fn } from "storybook/test";
|
|
9
|
+
export * from "next/dist/client/router";
|
|
10
|
+
var defaultRouterState = {
|
|
11
|
+
route: "/",
|
|
12
|
+
asPath: "/",
|
|
13
|
+
basePath: "/",
|
|
14
|
+
pathname: "/",
|
|
15
|
+
query: {},
|
|
16
|
+
isFallback: false,
|
|
17
|
+
isLocaleDomain: false,
|
|
18
|
+
isReady: true,
|
|
19
|
+
isPreview: false
|
|
20
|
+
};
|
|
21
|
+
var routerAPI;
|
|
22
|
+
var createRouter = /* @__PURE__ */ __name((overrides) => {
|
|
23
|
+
const routerActions = {
|
|
24
|
+
push: fn((..._args) => {
|
|
25
|
+
return Promise.resolve(true);
|
|
26
|
+
}).mockName("next/router::useRouter().push"),
|
|
27
|
+
replace: fn((..._args) => {
|
|
28
|
+
return Promise.resolve(true);
|
|
29
|
+
}).mockName("next/router::useRouter().replace"),
|
|
30
|
+
reload: fn((..._args) => {
|
|
31
|
+
}).mockName("next/router::useRouter().reload"),
|
|
32
|
+
back: fn((..._args) => {
|
|
33
|
+
}).mockName("next/router::useRouter().back"),
|
|
34
|
+
forward: fn(() => {
|
|
35
|
+
}).mockName("next/router::useRouter().forward"),
|
|
36
|
+
prefetch: fn((..._args) => {
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
}).mockName("next/router::useRouter().prefetch"),
|
|
39
|
+
beforePopState: fn((..._args) => {
|
|
40
|
+
}).mockName("next/router::useRouter().beforePopState")
|
|
41
|
+
};
|
|
42
|
+
const routerEvents = {
|
|
43
|
+
on: fn((..._args) => {
|
|
44
|
+
}).mockName("next/router::useRouter().events.on"),
|
|
45
|
+
off: fn((..._args) => {
|
|
46
|
+
}).mockName("next/router::useRouter().events.off"),
|
|
47
|
+
emit: fn((..._args) => {
|
|
48
|
+
}).mockName("next/router::useRouter().events.emit")
|
|
49
|
+
};
|
|
50
|
+
if (overrides) {
|
|
51
|
+
Object.keys(routerActions).forEach((key) => {
|
|
52
|
+
if (key in overrides) {
|
|
53
|
+
routerActions[key] = fn((...args) => {
|
|
54
|
+
return overrides[key](...args);
|
|
55
|
+
}).mockName(`useRouter().${key}`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (overrides?.events) {
|
|
60
|
+
Object.keys(routerEvents).forEach((key) => {
|
|
61
|
+
if (key in routerEvents) {
|
|
62
|
+
routerEvents[key] = fn((...args) => {
|
|
63
|
+
return overrides.events[key](...args);
|
|
64
|
+
}).mockName(`useRouter().events.${key}`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
routerAPI = {
|
|
69
|
+
...defaultRouterState,
|
|
70
|
+
...overrides,
|
|
71
|
+
...routerActions,
|
|
72
|
+
// @ts-expect-error TODO improve typings
|
|
73
|
+
events: routerEvents
|
|
74
|
+
};
|
|
75
|
+
singletonRouter.router = routerAPI;
|
|
76
|
+
singletonRouter.readyCallbacks.forEach((cb) => cb());
|
|
77
|
+
singletonRouter.readyCallbacks = [];
|
|
78
|
+
return routerAPI;
|
|
79
|
+
}, "createRouter");
|
|
80
|
+
var getRouter = /* @__PURE__ */ __name(() => {
|
|
81
|
+
if (!routerAPI) {
|
|
82
|
+
throw new NextjsRouterMocksNotAvailable({
|
|
83
|
+
importType: "next/router"
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return routerAPI;
|
|
87
|
+
}, "getRouter");
|
|
88
|
+
var router_default = singletonRouter;
|
|
89
|
+
var useRouter2 = fn(originalRouter.useRouter).mockName("next/router::useRouter");
|
|
90
|
+
var withRouter2 = fn(originalRouter.withRouter).mockName("next/router::withRouter");
|
|
91
|
+
export {
|
|
92
|
+
createRouter,
|
|
93
|
+
router_default as default,
|
|
94
|
+
getRouter,
|
|
95
|
+
useRouter2 as useRouter,
|
|
96
|
+
withRouter2 as withRouter
|
|
97
|
+
};
|
|
@@ -1,23 +1,167 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import CJS_COMPAT_NODE_URL_nafzxsaqn from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_nafzxsaqn from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_nafzxsaqn from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_nafzxsaqn.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_nafzxsaqn.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_nafzxsaqn.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-DF7TGUJT.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
|
-
}
|
|
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
|
|
10
|
-
${font.style
|
|
97
|
+
${font.weight ? `font-weight: ${font.weight};` : ""}
|
|
98
|
+
${font.style ? `font-style: ${font.style};` : ""}
|
|
11
99
|
${fontDeclarations}
|
|
12
|
-
}
|
|
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)
|
|
16
|
-
${isNextCSSPropertyValid(options.weights)
|
|
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
|
|
20
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
|
221
|
+
${cssMeta.variableClassName ? `, variable: "${cssMeta.variableClassName}"` : ""}
|
|
42
222
|
}
|
|
43
|
-
|
|
223
|
+
`;
|
|
224
|
+
}
|
|
225
|
+
return `module.exports = {}`;
|
|
226
|
+
}
|
|
227
|
+
__name(storybookNextjsFontLoader, "storybookNextjsFontLoader");
|
|
228
|
+
export {
|
|
229
|
+
storybookNextjsFontLoader as default
|
|
230
|
+
};
|
package/dist/image-context.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
+
};
|