@clarify-labs/renderer 0.7.0 → 0.7.2
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/output/{OpenApiOperation-ZXToVSFC.cjs → OpenApiOperation-BcyW_ULy.cjs} +186 -140
- package/output/OpenApiOperation-BcyW_ULy.cjs.map +1 -0
- package/output/{OpenApiOperation-CWSOhUVa.js → OpenApiOperation-tUKf7lZ4.js} +166 -120
- package/output/OpenApiOperation-tUKf7lZ4.js.map +1 -0
- package/output/{shell-xxhV0p7k.cjs → PageActions-1RDCHcUY.cjs} +280 -308
- package/output/PageActions-1RDCHcUY.cjs.map +1 -0
- package/output/{shell-CumiARRe.js → PageActions-yoDRjkq8.js} +235 -263
- package/output/PageActions-yoDRjkq8.js.map +1 -0
- package/output/{ThemeRoot-C_ZdzSMu.js → ThemeRoot-QULrwQf6.js} +407 -53
- package/output/ThemeRoot-QULrwQf6.js.map +1 -0
- package/output/{ThemeRoot-CEvwrGp5.cjs → ThemeRoot-UWj0iK1X.cjs} +458 -80
- package/output/ThemeRoot-UWj0iK1X.cjs.map +1 -0
- package/output/app/AppShell.d.ts +3 -2
- package/output/app/PageActions.d.ts +12 -0
- package/output/app/PageBanner.d.ts +7 -0
- package/output/app/SectionProvider.d.ts +1 -0
- package/output/client.cjs +14 -7
- package/output/client.d.ts +4 -2
- package/output/client.js +4 -4
- package/output/context.d.ts +1 -1
- package/output/core/context.d.ts +5 -5
- package/output/core/index.d.ts +1 -1
- package/output/core/types.d.ts +70 -61
- package/output/index.cjs +56 -28
- package/output/index.cjs.map +1 -1
- package/output/index.d.ts +7 -5
- package/output/index.js +37 -12
- package/output/index.js.map +1 -1
- package/output/mdx/components.d.ts +2 -0
- package/output/mdx/primitives.d.ts +2 -0
- package/output/openapi/components/EndpointSections.d.ts +30 -0
- package/output/preview.cjs +7 -7
- package/output/preview.cjs.map +1 -1
- package/output/preview.js +4 -4
- package/output/preview.js.map +1 -1
- package/output/{render-zHU25Nm9.cjs → render-ByWbJbrA.cjs} +8 -7
- package/output/render-ByWbJbrA.cjs.map +1 -0
- package/output/{render-CnUd0XwZ.js → render-psutGbsg.js} +6 -5
- package/output/render-psutGbsg.js.map +1 -0
- package/output/renderer.css +371 -269
- package/output/server.cjs +8 -7
- package/output/server.cjs.map +1 -1
- package/output/server.js +5 -4
- package/output/server.js.map +1 -1
- package/output/shell/ContentActions.d.ts +0 -1
- package/output/shell/Header.d.ts +3 -2
- package/output/shell/SiteLogo.d.ts +2 -2
- package/output/shell/mobile.d.ts +2 -2
- package/output/theme/ThemeEditor.d.ts +53 -17
- package/output/theme/ThemeProvider.d.ts +2 -1
- package/output/theme/ThemeRoot.d.ts +2 -2
- package/output/theme/cookies.d.ts +11 -0
- package/output/theme/randomTheme.d.ts +2 -2
- package/output/theme/variables.d.ts +58 -20
- package/output/utils/href.d.ts +3 -3
- package/package.json +1 -1
- package/output/OpenApiOperation-CWSOhUVa.js.map +0 -1
- package/output/OpenApiOperation-ZXToVSFC.cjs.map +0 -1
- package/output/ThemeRoot-CEvwrGp5.cjs.map +0 -1
- package/output/ThemeRoot-C_ZdzSMu.js.map +0 -1
- package/output/render-CnUd0XwZ.js.map +0 -1
- package/output/render-zHU25Nm9.cjs.map +0 -1
- package/output/shell-CumiARRe.js.map +0 -1
- package/output/shell-xxhV0p7k.cjs.map +0 -1
package/output/core/types.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
import { OpenAPISpec } from '../openapi/lib/utils';
|
|
3
|
-
export type
|
|
3
|
+
export type FooterComponentPath = string;
|
|
4
4
|
export type RouteComponent = ComponentType | (() => Promise<{
|
|
5
5
|
default: ComponentType;
|
|
6
6
|
}>);
|
|
7
7
|
export type RouteSection = {
|
|
8
8
|
id: string;
|
|
9
9
|
title: string;
|
|
10
|
+
level?: number;
|
|
10
11
|
badge?: string;
|
|
11
12
|
tags?: string[];
|
|
12
13
|
};
|
|
@@ -33,123 +34,127 @@ export type RouteItem = {
|
|
|
33
34
|
contentArtifactUrl?: string;
|
|
34
35
|
sourceUrl?: string;
|
|
35
36
|
};
|
|
36
|
-
export type
|
|
37
|
+
export type LogoConfig = string | {
|
|
37
38
|
light?: string;
|
|
38
39
|
dark?: string;
|
|
39
40
|
};
|
|
40
|
-
export type
|
|
41
|
+
export type FaviconConfig = string | {
|
|
41
42
|
light?: string;
|
|
42
43
|
dark?: string;
|
|
43
44
|
};
|
|
44
|
-
export type
|
|
45
|
-
export type
|
|
45
|
+
export type LocalizedText = string | Record<string, string>;
|
|
46
|
+
export type LocaleConfig = {
|
|
46
47
|
code: string;
|
|
47
48
|
label: string;
|
|
48
49
|
dir?: 'ltr' | 'rtl';
|
|
49
50
|
};
|
|
50
|
-
export type
|
|
51
|
+
export type I18nConfig = {
|
|
51
52
|
defaultLocale: string;
|
|
52
53
|
missing: 'fallback' | '404' | 'hide';
|
|
53
|
-
locales:
|
|
54
|
+
locales: LocaleConfig[];
|
|
54
55
|
};
|
|
55
|
-
export type
|
|
56
|
-
label:
|
|
56
|
+
export type NavbarLink = {
|
|
57
|
+
label: LocalizedText;
|
|
57
58
|
href: string;
|
|
58
59
|
external?: boolean;
|
|
59
60
|
};
|
|
60
|
-
export type
|
|
61
|
-
|
|
61
|
+
export type BannerComponentPath = string;
|
|
62
|
+
export type BannerConfigOptions = {
|
|
63
|
+
content: LocalizedText;
|
|
62
64
|
dismissible?: boolean;
|
|
65
|
+
link?: NavbarLink;
|
|
63
66
|
};
|
|
64
|
-
export type
|
|
65
|
-
|
|
67
|
+
export type BannerConfig = BannerConfigOptions | BannerComponentPath;
|
|
68
|
+
export type FooterLinksConfig = {
|
|
69
|
+
links?: NavbarLink[];
|
|
66
70
|
socials?: Record<string, string>;
|
|
67
|
-
copyright?:
|
|
71
|
+
copyright?: LocalizedText;
|
|
68
72
|
};
|
|
69
|
-
export type
|
|
70
|
-
export type
|
|
73
|
+
export type FooterConfig = FooterLinksConfig | FooterComponentPath;
|
|
74
|
+
export type SourceConfig = {
|
|
71
75
|
repository: string;
|
|
72
76
|
branch?: string;
|
|
73
77
|
directory?: string;
|
|
74
78
|
};
|
|
75
|
-
export type
|
|
76
|
-
export type
|
|
79
|
+
export type ThemePreset = 'default' | 'base';
|
|
80
|
+
export type ThemeModeColorValue = {
|
|
77
81
|
light?: string;
|
|
78
82
|
dark?: string;
|
|
79
83
|
};
|
|
80
|
-
export type
|
|
81
|
-
export type
|
|
82
|
-
primary:
|
|
83
|
-
accent:
|
|
84
|
-
background:
|
|
85
|
-
foreground:
|
|
86
|
-
surface:
|
|
87
|
-
muted:
|
|
88
|
-
border:
|
|
89
|
-
codeBackground:
|
|
90
|
-
};
|
|
91
|
-
export type
|
|
84
|
+
export type ThemeColorValue = string | ThemeModeColorValue;
|
|
85
|
+
export type ThemeColorTokensConfig = {
|
|
86
|
+
primary: ThemeColorValue;
|
|
87
|
+
accent: ThemeColorValue;
|
|
88
|
+
background: ThemeColorValue;
|
|
89
|
+
foreground: ThemeColorValue;
|
|
90
|
+
surface: ThemeColorValue;
|
|
91
|
+
muted: ThemeColorValue;
|
|
92
|
+
border: ThemeColorValue;
|
|
93
|
+
codeBackground: ThemeColorValue;
|
|
94
|
+
};
|
|
95
|
+
export type ThemeRadiusTokensConfig = {
|
|
92
96
|
sm: string;
|
|
93
97
|
md: string;
|
|
94
98
|
lg: string;
|
|
95
99
|
xl: string;
|
|
96
100
|
};
|
|
97
|
-
export type
|
|
98
|
-
colors:
|
|
99
|
-
radius:
|
|
101
|
+
export type ThemeTokensConfig = {
|
|
102
|
+
colors: ThemeColorTokensConfig;
|
|
103
|
+
radius: ThemeRadiusTokensConfig;
|
|
100
104
|
};
|
|
101
|
-
export type
|
|
105
|
+
export type ThemeLayoutConfig = {
|
|
102
106
|
maxWidth: string;
|
|
103
107
|
};
|
|
104
|
-
export type
|
|
105
|
-
preset:
|
|
106
|
-
tokens:
|
|
107
|
-
layout:
|
|
108
|
+
export type ThemeConfig = {
|
|
109
|
+
preset: ThemePreset;
|
|
110
|
+
tokens: ThemeTokensConfig;
|
|
111
|
+
layout: ThemeLayoutConfig;
|
|
108
112
|
editor: boolean;
|
|
109
113
|
};
|
|
110
|
-
export type
|
|
114
|
+
export type PagesItem = string | {
|
|
111
115
|
page: string;
|
|
112
|
-
title?:
|
|
116
|
+
title?: LocalizedText;
|
|
113
117
|
icon?: string;
|
|
114
118
|
redirect?: string;
|
|
115
119
|
} | {
|
|
116
120
|
openapi: string;
|
|
117
121
|
icon?: string;
|
|
118
|
-
title?:
|
|
122
|
+
title?: LocalizedText;
|
|
119
123
|
filter?: {
|
|
120
124
|
tags?: string[];
|
|
121
125
|
};
|
|
122
126
|
};
|
|
123
|
-
export type
|
|
124
|
-
group:
|
|
127
|
+
export type PagesGroup = {
|
|
128
|
+
group: LocalizedText;
|
|
125
129
|
icon?: string;
|
|
126
|
-
pages:
|
|
130
|
+
pages: PagesItem[];
|
|
127
131
|
};
|
|
128
|
-
export type
|
|
129
|
-
export type
|
|
130
|
-
tab:
|
|
132
|
+
export type PagesConfig = PagesGroup[] | 'FileTree';
|
|
133
|
+
export type TabItem = {
|
|
134
|
+
tab: LocalizedText;
|
|
131
135
|
icon?: string;
|
|
132
|
-
pages?:
|
|
136
|
+
pages?: PagesConfig;
|
|
133
137
|
};
|
|
134
|
-
export type
|
|
135
|
-
export type
|
|
138
|
+
export type TabsConfig = TabItem[];
|
|
139
|
+
export type Config = {
|
|
136
140
|
title: string;
|
|
137
|
-
logo?:
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
logo?: LogoConfig;
|
|
142
|
+
homeUrl?: string;
|
|
143
|
+
favicon?: FaviconConfig;
|
|
144
|
+
theme: ThemeConfig;
|
|
140
145
|
description: string;
|
|
141
146
|
siteUrl?: string;
|
|
142
|
-
source?:
|
|
147
|
+
source?: SourceConfig;
|
|
143
148
|
rootDirectory: string;
|
|
144
149
|
routePrefix: string;
|
|
145
150
|
outputDirectory: string;
|
|
146
151
|
navbar?: {
|
|
147
|
-
links?:
|
|
152
|
+
links?: NavbarLink[];
|
|
148
153
|
};
|
|
149
|
-
banner?:
|
|
150
|
-
footer?:
|
|
151
|
-
i18n?:
|
|
152
|
-
tabs?:
|
|
154
|
+
banner?: BannerConfig;
|
|
155
|
+
footer?: FooterConfig;
|
|
156
|
+
i18n?: I18nConfig;
|
|
157
|
+
tabs?: TabsConfig;
|
|
153
158
|
};
|
|
154
159
|
export type NavigationTab = {
|
|
155
160
|
type: 'tab';
|
|
@@ -166,13 +171,15 @@ export type LocalizedTabbedNavigation = Record<string, TabbedNavigation>;
|
|
|
166
171
|
export type NavigationTree = NavigationNode[] | LocalizedNavigation | TabbedNavigation | LocalizedTabbedNavigation;
|
|
167
172
|
export type RenderOptions = {
|
|
168
173
|
/** 从 virtual:clarify-config 导入的 config */
|
|
169
|
-
config:
|
|
174
|
+
config: Config;
|
|
170
175
|
/** 从 virtual:clarify-routes 导入的路由数组 */
|
|
171
176
|
routes: RouteItem[];
|
|
172
177
|
/** 从 virtual:clarify-routes 导入的导航树;启用 i18n 时为按 locale 分组的导航树 */
|
|
173
178
|
navigation?: NavigationTree;
|
|
174
179
|
/** 从 virtual:clarify-openapi-registry 导入的 OpenAPI 规范表 */
|
|
175
180
|
openApis?: Record<string, OpenAPISpec>;
|
|
181
|
+
/** Custom banner component imported from a configured banner path. */
|
|
182
|
+
bannerComponent?: ComponentType;
|
|
176
183
|
/** Custom footer component imported from a configured footer path. */
|
|
177
184
|
footerComponent?: ComponentType;
|
|
178
185
|
/** Whether to render the live theme editor inside the app tree. */
|
|
@@ -185,13 +192,15 @@ export type ServerRouteItem = Omit<RouteItem, 'component'> & {
|
|
|
185
192
|
};
|
|
186
193
|
export type ServerRenderOptions = {
|
|
187
194
|
/** 从 virtual:clarify-config 导入的 config */
|
|
188
|
-
config:
|
|
195
|
+
config: Config;
|
|
189
196
|
/** 从 virtual:clarify-routes 导入的服务端路由数组 */
|
|
190
197
|
routes: ServerRouteItem[];
|
|
191
198
|
/** 从 virtual:clarify-routes 导入的导航树;启用 i18n 时为按 locale 分组的导航树 */
|
|
192
199
|
navigation?: NavigationTree;
|
|
193
200
|
/** 从 virtual:clarify-openapi-registry 导入的 OpenAPI 规范表 */
|
|
194
201
|
openApis?: Record<string, OpenAPISpec>;
|
|
202
|
+
/** Custom banner component imported from a configured banner path. */
|
|
203
|
+
bannerComponent?: ComponentType;
|
|
195
204
|
/** Custom footer component imported from a configured footer path. */
|
|
196
205
|
footerComponent?: ComponentType;
|
|
197
206
|
/** Whether to render the live theme editor inside the app tree. */
|
package/output/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const require_ThemeRoot = require("./ThemeRoot-
|
|
4
|
-
const require_OpenApiOperation = require("./OpenApiOperation-
|
|
2
|
+
const require_PageActions = require("./PageActions-1RDCHcUY.cjs");
|
|
3
|
+
const require_ThemeRoot = require("./ThemeRoot-UWj0iK1X.cjs");
|
|
4
|
+
const require_OpenApiOperation = require("./OpenApiOperation-BcyW_ULy.cjs");
|
|
5
5
|
const require_remark = require("./remark-Dv3owbSH.cjs");
|
|
6
|
-
const require_render = require("./render-
|
|
6
|
+
const require_render = require("./render-ByWbJbrA.cjs");
|
|
7
7
|
let react_router_dom = require("react-router-dom");
|
|
8
8
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
9
|
//#region source/openapi/lib/spec-path.ts
|
|
@@ -23,13 +23,32 @@ function normalizeSpecPath(specPath, currentRoutePath, routePrefix = "") {
|
|
|
23
23
|
const fromDir = currentRoutePath === "/" ? "" : currentRoutePath?.replace(/^\//, "").replace(/\/[^/]*$/, "") ?? "";
|
|
24
24
|
return VIRTUAL_PREFIX + resolveRelativePath(normalizedRoutePrefix && fromDir.startsWith(`${normalizedRoutePrefix}/`) ? fromDir.slice(normalizedRoutePrefix.length + 1) : fromDir, normalizedSpecPath);
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* 为绝对 specPath 生成带 locale 前缀的候选模块 ID。
|
|
28
|
+
*
|
|
29
|
+
* 局部嵌入(OpenApiOperation / OpenApiDocument)通常使用 `/api` 这样的绝对路径。
|
|
30
|
+
* 默认 locale 的 spec 注册在 `virtual:clarify-page/api`,而其他 locale 的 spec
|
|
31
|
+
* 注册在 `virtual:clarify-page/<locale>/api`。相对路径会因为当前路由已含 locale 前缀
|
|
32
|
+
* 而自动解析到正确的 spec,但绝对路径不会,因此这里显式注入 locale 前缀。
|
|
33
|
+
*/
|
|
34
|
+
function localizeSpecModuleId(moduleId, specPath, locale, defaultLocale) {
|
|
35
|
+
if (!locale || locale === defaultLocale) return void 0;
|
|
36
|
+
if (!specPath.startsWith("/") || specPath.startsWith(VIRTUAL_PREFIX)) return void 0;
|
|
37
|
+
const rest = moduleId.slice(21);
|
|
38
|
+
if (rest.startsWith(`${locale}/`) || rest === locale) return void 0;
|
|
39
|
+
return `${VIRTUAL_PREFIX}${locale}/${rest}`;
|
|
40
|
+
}
|
|
26
41
|
function useOpenApiSpec(spec, specPath) {
|
|
27
|
-
const specs =
|
|
42
|
+
const specs = require_PageActions.useOpenApis();
|
|
28
43
|
const location = (0, react_router_dom.useLocation)();
|
|
29
|
-
const config =
|
|
44
|
+
const config = require_PageActions.useConfig();
|
|
45
|
+
const locale = require_PageActions.useLocale();
|
|
30
46
|
if (spec) return spec;
|
|
31
47
|
if (!specPath) return null;
|
|
32
|
-
|
|
48
|
+
const normalized = normalizeSpecPath(specPath, location.pathname, config.routePrefix);
|
|
49
|
+
const localized = localizeSpecModuleId(normalized, specPath, locale, config.i18n?.defaultLocale);
|
|
50
|
+
if (localized && specs[localized]) return specs[localized];
|
|
51
|
+
return specs[normalized] ?? null;
|
|
33
52
|
}
|
|
34
53
|
//#endregion
|
|
35
54
|
//#region source/openapi/lib/utils.ts
|
|
@@ -83,21 +102,27 @@ function listOpenApiOperations(spec) {
|
|
|
83
102
|
//#region source/openapi/entry.tsx
|
|
84
103
|
function OpenApiHeader(arg0) {
|
|
85
104
|
const { spec } = arg0;
|
|
86
|
-
const t =
|
|
105
|
+
const t = require_PageActions.useBuiltInText();
|
|
87
106
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
|
|
88
|
-
className: "mb-16",
|
|
107
|
+
className: "clarify-openapi-header mb-16 border-b border-(--clarify-theme-tokens-colors-border) pb-8",
|
|
89
108
|
children: [
|
|
90
109
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
91
|
-
className: "mb-3 text-xs/6 font-medium tracking-widest text-
|
|
110
|
+
className: "mb-3 text-xs/6 font-medium tracking-widest text-(--clarify-ui-accent-text) uppercase",
|
|
92
111
|
children: t("openapi.openApiReference")
|
|
93
112
|
}),
|
|
94
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
113
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
114
|
+
className: "clarify-page-title-row flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",
|
|
115
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", {
|
|
116
|
+
className: "clarify-page-title min-w-0 flex-1",
|
|
117
|
+
children: spec.info?.title ?? t("openapi.apiDocumentation")
|
|
118
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PageActions.PageTitleActions, {})]
|
|
119
|
+
}),
|
|
95
120
|
spec.info?.description ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_OpenApiOperation.Markdown, {
|
|
96
|
-
className: "lead *:first:mt-0 *:last:mb-0",
|
|
121
|
+
className: "lead mt-4 *:first:mt-0 *:last:mb-0",
|
|
97
122
|
children: spec.info.description
|
|
98
123
|
}) : null,
|
|
99
124
|
spec.info?.version ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
100
|
-
className: "text-sm text-
|
|
125
|
+
className: "mt-4 text-sm text-(--clarify-ui-text-faint)",
|
|
101
126
|
children: t("openapi.version", { version: spec.info.version })
|
|
102
127
|
}) : null
|
|
103
128
|
]
|
|
@@ -132,7 +157,7 @@ function WarningBox(arg0) {
|
|
|
132
157
|
}
|
|
133
158
|
function OpenApiDocument(arg0) {
|
|
134
159
|
const { spec, specPath, tagFilter } = arg0;
|
|
135
|
-
const t =
|
|
160
|
+
const t = require_PageActions.useBuiltInText();
|
|
136
161
|
const resolved = useOpenApiSpec(spec, specPath);
|
|
137
162
|
if (!resolved) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WarningBox, { children: t("openapi.specNotFound", { specPath: specPath ?? t("openapi.specPathMissing") }) });
|
|
138
163
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("article", {
|
|
@@ -148,7 +173,7 @@ function OpenApiDocument(arg0) {
|
|
|
148
173
|
}
|
|
149
174
|
function OpenApiOperationWithSpec(arg0) {
|
|
150
175
|
const { spec, path, method } = arg0;
|
|
151
|
-
const t =
|
|
176
|
+
const t = require_PageActions.useBuiltInText();
|
|
152
177
|
const op = getOpenApiOperation(spec, path, method);
|
|
153
178
|
if (!op) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WarningBox, {
|
|
154
179
|
tone: "red",
|
|
@@ -164,7 +189,7 @@ function OpenApiOperationWithSpec(arg0) {
|
|
|
164
189
|
}
|
|
165
190
|
function OpenApiOperation(arg0) {
|
|
166
191
|
const { specPath, path, method } = arg0;
|
|
167
|
-
const t =
|
|
192
|
+
const t = require_PageActions.useBuiltInText();
|
|
168
193
|
const spec = useOpenApiSpec(void 0, specPath);
|
|
169
194
|
if (!spec) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WarningBox, { children: t("openapi.specNotFound", { specPath }) });
|
|
170
195
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OpenApiOperationWithSpec, {
|
|
@@ -219,10 +244,10 @@ exports.Button = require_OpenApiOperation.Button;
|
|
|
219
244
|
exports.Callout = require_OpenApiOperation.Callout;
|
|
220
245
|
exports.Card = require_OpenApiOperation.Card;
|
|
221
246
|
exports.CardGroup = require_OpenApiOperation.CardGroup;
|
|
222
|
-
exports.ClarifyConfigContext = require_shell.ClarifyConfigContext;
|
|
223
247
|
exports.Code = require_OpenApiOperation.Code;
|
|
224
248
|
exports.CodeGroup = require_OpenApiOperation.CodeGroup;
|
|
225
249
|
exports.Collapse = require_OpenApiOperation.Collapse;
|
|
250
|
+
exports.ConfigContext = require_PageActions.ConfigContext;
|
|
226
251
|
exports.DocShell = DocShell;
|
|
227
252
|
exports.Feedback = require_OpenApiOperation.Feedback;
|
|
228
253
|
exports.GridPattern = require_OpenApiOperation.GridPattern;
|
|
@@ -232,25 +257,28 @@ exports.Logo = require_OpenApiOperation.Logo;
|
|
|
232
257
|
exports.Markdown = require_OpenApiOperation.Markdown;
|
|
233
258
|
exports.OpenApiDocument = OpenApiDocument;
|
|
234
259
|
exports.OpenApiOperation = OpenApiOperation;
|
|
235
|
-
exports.OpenApisContext =
|
|
260
|
+
exports.OpenApisContext = require_PageActions.OpenApisContext;
|
|
261
|
+
exports.PageBanner = require_ThemeRoot.PageBanner;
|
|
236
262
|
exports.PageFooter = require_ThemeRoot.PageFooter;
|
|
237
263
|
exports.Pre = require_OpenApiOperation.Pre;
|
|
238
264
|
exports.Prose = require_OpenApiOperation.Prose;
|
|
239
|
-
exports.SectionProvider =
|
|
265
|
+
exports.SectionProvider = require_PageActions.SectionProvider;
|
|
240
266
|
exports.Tag = require_OpenApiOperation.Tag;
|
|
241
267
|
exports.ThemeEditor = require_ThemeRoot.ThemeEditor;
|
|
242
|
-
exports.ThemeProvider =
|
|
243
|
-
exports.ThemeToggle =
|
|
268
|
+
exports.ThemeProvider = require_PageActions.ThemeProvider;
|
|
269
|
+
exports.ThemeToggle = require_PageActions.ThemeToggle;
|
|
244
270
|
exports.WebFrame = require_OpenApiOperation.WebFrame;
|
|
245
|
-
exports.
|
|
246
|
-
exports.clarifyThemeEditorPresets = require_ThemeRoot.clarifyThemeEditorPresets;
|
|
271
|
+
exports.applyThemeVariables = require_ThemeRoot.applyThemeVariables;
|
|
247
272
|
exports.markdownRemarkPlugins = require_remark.markdownRemarkPlugins;
|
|
248
|
-
exports.remToPx =
|
|
273
|
+
exports.remToPx = require_PageActions.remToPx;
|
|
249
274
|
exports.render = require_render.render;
|
|
250
|
-
exports.
|
|
275
|
+
exports.themeBootstrapScript = require_ThemeRoot.themeBootstrapScript;
|
|
276
|
+
exports.themeEditorPresets = require_ThemeRoot.themeEditorPresets;
|
|
277
|
+
exports.themePresets = require_ThemeRoot.themePresets;
|
|
278
|
+
exports.useConfig = require_PageActions.useConfig;
|
|
251
279
|
exports.useMDXComponents = useMDXComponents;
|
|
252
|
-
exports.useOpenApis =
|
|
253
|
-
exports.useSectionStore =
|
|
254
|
-
exports.useTheme =
|
|
280
|
+
exports.useOpenApis = require_PageActions.useOpenApis;
|
|
281
|
+
exports.useSectionStore = require_PageActions.useSectionStore;
|
|
282
|
+
exports.useTheme = require_PageActions.useTheme;
|
|
255
283
|
|
|
256
284
|
//# sourceMappingURL=index.cjs.map
|
package/output/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../source/openapi/lib/spec-path.ts","../source/openapi/lib/utils.ts","../source/openapi/entry.tsx","../source/mdx/components.ts","../source/mdx/DocShell.tsx"],"sourcesContent":["import { useLocation } from 'react-router-dom'\n\nimport { useClarifyConfig, useOpenApis } from '../../core/context'\n\nimport type { OpenAPISpec } from './utils'\n\nconst VIRTUAL_PREFIX = 'virtual:clarify-page/'\n\nfunction resolveRelativePath(fromDir: string, to: string): string {\n const parts = (fromDir + '/' + to).split('/').filter(Boolean)\n const stack: string[] = []\n for (const part of parts) {\n if (part === '..') {\n stack.pop()\n } else if (part !== '.') {\n stack.push(part)\n }\n }\n return stack.join('/')\n}\n\nfunction normalizeSpecPath(specPath: string, currentRoutePath?: string, routePrefix = ''): string {\n if (specPath.startsWith(VIRTUAL_PREFIX)) return specPath\n\n const normalizedRoutePrefix = routePrefix.replace(/^\\/+|\\/+$/g, '')\n const normalizedSpecPath = specPath.startsWith('/') && normalizedRoutePrefix && specPath.slice(1).startsWith(`${normalizedRoutePrefix}/`)\n ? '/' + specPath.slice(normalizedRoutePrefix.length + 2)\n : specPath\n\n if (normalizedSpecPath.startsWith('/')) {\n return VIRTUAL_PREFIX + normalizedSpecPath.replace(/^\\//, '')\n }\n const fromDir = currentRoutePath === '/' ? '' : currentRoutePath?.replace(/^\\//, '').replace(/\\/[^/]*$/, '') ?? ''\n const normalizedFromDir = normalizedRoutePrefix && fromDir.startsWith(`${normalizedRoutePrefix}/`)\n ? fromDir.slice(normalizedRoutePrefix.length + 1)\n : fromDir\n return VIRTUAL_PREFIX + resolveRelativePath(normalizedFromDir, normalizedSpecPath)\n}\n\nexport function useOpenApiSpec(spec?: OpenAPISpec, specPath?: string): OpenAPISpec | null {\n const specs = useOpenApis()\n const location = useLocation()\n const config = useClarifyConfig()\n\n if (spec) return spec\n if (!specPath) return null\n\n const normalized = normalizeSpecPath(specPath, location.pathname, config.routePrefix)\n return specs[normalized] ?? null\n}\n","import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nimport type { OpenApiRecord } from '../types'\n\nexport type OpenAPISpec = OpenAPIV3.Document | OpenAPIV3_1.Document\nexport type OpenAPIOperation = OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject\n\nexport const OPENAPI_HTTP_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const\n\nexport type OpenAPIHttpMethod = typeof OPENAPI_HTTP_METHODS[number]\n\nexport function isOpenAPIHttpMethod(method: string): method is OpenAPIHttpMethod {\n return (OPENAPI_HTTP_METHODS as readonly string[]).includes(method.toLowerCase())\n}\n\nfunction isRecord(value: unknown): value is OpenApiRecord {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction resolveOpenApiRef(spec: OpenAPISpec, ref: string): unknown {\n if (!ref.startsWith('#/')) return undefined\n\n return ref\n .slice(2)\n .split('/')\n .map((part) => part.replace(/~1/g, '/').replace(/~0/g, '~'))\n .reduce<unknown>((current, part) => (isRecord(current) ? current[part] : undefined), spec)\n}\n\nfunction getPathItem(spec: OpenAPISpec, path: string): OpenApiRecord | undefined {\n const pathItem = spec.paths?.[path]\n const resolved = isRecord(pathItem) && typeof pathItem.$ref === 'string' ? resolveOpenApiRef(spec, pathItem.$ref) : pathItem\n return isRecord(resolved) ? resolved : undefined\n}\n\nexport function getOpenApiOperation(spec: OpenAPISpec, path: string, method: string): OpenAPIOperation | undefined {\n if (!isOpenAPIHttpMethod(method)) return undefined\n return getPathItem(spec, path)?.[method.toLowerCase() as OpenAPIHttpMethod] as OpenAPIOperation | undefined\n}\n\nexport function listOpenApiOperations(spec: OpenAPISpec): Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> {\n const paths = spec.paths ?? {}\n const operations: Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> = []\n\n for (const path of Object.keys(paths)) {\n const pathItem = getPathItem(spec, path)\n if (!pathItem) continue\n for (const method of OPENAPI_HTTP_METHODS) {\n const operation = pathItem[method]\n if (operation) operations.push({ path, method, operation: operation as OpenAPIOperation })\n }\n }\n\n return operations\n}\n","import type { ReactNode } from 'react'\n\nimport { Prose } from '../components/Prose'\nimport { useBuiltInText } from '../core/i18n'\nimport { Markdown } from '../mdx/Markdown'\n\nimport { OpenApiOperation as OpenApiOperationComponent } from './components/OpenApiOperation'\nimport { useOpenApiSpec } from './lib/spec-path'\nimport { getOpenApiOperation, listOpenApiOperations } from './lib/utils'\nimport type { OpenAPISpec } from './lib/utils'\n\ntype OpenApiPathsProps = { spec: OpenAPISpec; tagFilter?: string[] }\n\ntype OpenApiHeaderProps = { spec: OpenAPISpec }\n\ntype WarningBoxProps = {\n children: ReactNode\n tone?: 'amber' | 'red'\n}\n\nexport type OpenApiDocumentProps = {\n spec?: OpenAPISpec\n specPath?: string\n tagFilter?: string[]\n}\n\ntype OpenApiOperationWithSpecProps = {\n spec: OpenAPISpec\n path: string\n method: string\n}\n\nexport type OpenApiOperationProps = {\n specPath: string\n path: string\n method: string\n}\n\nfunction OpenApiHeader(arg0: OpenApiHeaderProps): ReactNode {\n const { spec } = arg0\n\n const t = useBuiltInText()\n return (\n <header className=\"mb-16\">\n <p className=\"mb-3 text-xs/6 font-medium tracking-widest text-emerald-500 uppercase dark:text-emerald-400\">\n {t('openapi.openApiReference')}\n </p>\n <h1>{spec.info?.title ?? t('openapi.apiDocumentation')}</h1>\n {spec.info?.description ? <Markdown className=\"lead *:first:mt-0 *:last:mb-0\">{spec.info.description}</Markdown> : null}\n {spec.info?.version ? <p className=\"text-sm text-zinc-500 dark:text-zinc-400\">{t('openapi.version', { version: spec.info.version })}</p> : null}\n </header>\n )\n}\n\nfunction operationMatchesTags(operationTags: string[] | undefined, filterTags: string[] | undefined): boolean {\n if (!filterTags?.length) return true\n return operationTags?.some(tag => filterTags.includes(tag)) ?? false\n}\n\nfunction OpenApiPaths(arg0: OpenApiPathsProps): ReactNode {\n const { spec, tagFilter } = arg0\n\n const entries = listOpenApiOperations(spec)\n .filter(({ operation }) => operationMatchesTags(operation.tags, tagFilter))\n .map(({ path, method, operation }) => ({\n path,\n method: method.toUpperCase(),\n operation,\n }))\n\n return (\n <div className=\"clarify-api-endpoints divide-y divide-zinc-200/70 dark:divide-white/10\">\n {entries.map(({ path, method, operation }) => (\n <OpenApiOperationComponent key={`${method}-${path}`} spec={spec} path={path} method={method} operation={operation} />\n ))}\n </div>\n )\n}\n\nfunction WarningBox(arg0: WarningBoxProps): ReactNode {\n const { children, tone = 'amber' } = arg0\n\n const classes = tone === 'red'\n ? 'rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-200'\n : 'rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200'\n\n return <div className={`clarify-warning ${classes}`}>{children}</div>\n}\n\nexport function OpenApiDocument(arg0: OpenApiDocumentProps): ReactNode {\n const { spec, specPath, tagFilter } = arg0\n const t = useBuiltInText()\n const resolved = useOpenApiSpec(spec, specPath)\n\n if (!resolved) {\n return <WarningBox>{t('openapi.specNotFound', { specPath: specPath ?? t('openapi.specPathMissing') })}</WarningBox>\n }\n\n return (\n <article className=\"clarify-openapi-page flex h-full flex-col pt-16 pb-10\">\n <Prose className=\"flex-auto\">\n <OpenApiHeader spec={resolved} />\n <OpenApiPaths spec={resolved} tagFilter={tagFilter} />\n </Prose>\n </article>\n )\n}\n\nfunction OpenApiOperationWithSpec(arg0: OpenApiOperationWithSpecProps): ReactNode {\n const { spec, path, method } = arg0\n const t = useBuiltInText()\n const op = getOpenApiOperation(spec, path, method)\n\n if (!op) {\n return <WarningBox tone=\"red\">{t('openapi.endpointNotFound', { endpoint: `${method.toUpperCase()} ${path}` })}</WarningBox>\n }\n\n const normalizedMethod = method.toUpperCase()\n return <OpenApiOperationComponent key={`${normalizedMethod}-${path}`} spec={spec} path={path} method={normalizedMethod} operation={op} />\n}\n\nexport function OpenApiOperation(arg0: OpenApiOperationProps): ReactNode {\n const { specPath, path, method } = arg0\n const t = useBuiltInText()\n const spec = useOpenApiSpec(undefined, specPath)\n\n if (!spec) {\n return <WarningBox>{t('openapi.specNotFound', { specPath })}</WarningBox>\n }\n\n return <OpenApiOperationWithSpec spec={spec} path={path} method={method} />\n}\n","import { Collapse } from '../components/Collapse'\nimport { OpenApiDocument, OpenApiOperation } from '../openapi'\n\nimport { Markdown } from './Markdown'\nimport * as mdxPrimitives from './primitives'\n\nconst builtInMDXComponents = {\n ...mdxPrimitives,\n Markdown,\n Collapse,\n}\n\nconst builtInOpenAPIComponents = {\n OpenApiDocument,\n OpenApiOperation,\n}\n\nexport function useMDXComponents(components: Record<string, unknown> = {}) {\n return {\n ...components,\n ...builtInMDXComponents,\n ...builtInOpenAPIComponents,\n }\n}\n","import type { ReactNode } from 'react'\n\nimport { Prose } from '../components/Prose'\n\nexport type DocShellProps = {\n title: string\n subtitle?: string\n children: ReactNode\n}\n\nexport function DocShell(arg0: DocShellProps) {\n const { title, subtitle, children } = arg0\n\n return (\n <main className=\"clarify-doc-shell min-h-screen bg-(--clarify-theme-tokens-colors-background) px-6 py-10 text-(--clarify-theme-tokens-colors-foreground) md:px-10\">\n <div className=\"mx-auto max-w-6xl\">\n <header className=\"mb-10\">\n <h1 className=\"text-3xl font-bold tracking-tight md:text-5xl\">{title}</h1>\n {subtitle ? <p className=\"mt-3 max-w-2xl text-(--clarify-ui-text-soft)\">{subtitle}</p> : null}\n </header>\n <Prose>{children}</Prose>\n </div>\n </main>\n )\n}\n"],"mappings":";;;;;;;;;AAMA,IAAM,iBAAiB;AAEvB,SAAS,oBAAoB,SAAiB,IAAoB;CAChE,MAAM,SAAS,UAAU,MAAM,IAAI,MAAM,GAAG,EAAE,OAAO,OAAO;CAC5D,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,QAAQ,OACjB,IAAI,SAAS,MACX,MAAM,IAAI;MACL,IAAI,SAAS,KAClB,MAAM,KAAK,IAAI;CAGnB,OAAO,MAAM,KAAK,GAAG;AACvB;AAEA,SAAS,kBAAkB,UAAkB,kBAA2B,cAAc,IAAY;CAChG,IAAI,SAAS,WAAW,cAAc,GAAG,OAAO;CAEhD,MAAM,wBAAwB,YAAY,QAAQ,cAAc,EAAE;CAClE,MAAM,qBAAqB,SAAS,WAAW,GAAG,KAAK,yBAAyB,SAAS,MAAM,CAAC,EAAE,WAAW,GAAG,sBAAsB,EAAE,IACpI,MAAM,SAAS,MAAM,sBAAsB,SAAS,CAAC,IACrD;CAEJ,IAAI,mBAAmB,WAAW,GAAG,GACnC,OAAO,iBAAiB,mBAAmB,QAAQ,OAAO,EAAE;CAE9D,MAAM,UAAU,qBAAqB,MAAM,KAAK,kBAAkB,QAAQ,OAAO,EAAE,EAAE,QAAQ,YA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U,CAAA,GACxE,WAAW,iBAAA,GAAA,kBAAA,KAAC,KAAD;KAAG,WAAU;eAAgD;IAAY,CAAA,IAAI,IACnF;OACR,iBAAA,GAAA,kBAAA,KAAC,yBAAA,OAAD,EAAQ,SAAgB,CAAA,CACrB;;CACD,CAAA;AAEV"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../source/openapi/lib/spec-path.ts","../source/openapi/lib/utils.ts","../source/openapi/entry.tsx","../source/mdx/components.ts","../source/mdx/DocShell.tsx"],"sourcesContent":["import { useLocation } from 'react-router-dom'\n\nimport { useConfig, useLocale, useOpenApis } from '../../core/context'\n\nimport type { OpenAPISpec } from './utils'\n\nconst VIRTUAL_PREFIX = 'virtual:clarify-page/'\n\nfunction resolveRelativePath(fromDir: string, to: string): string {\n const parts = (fromDir + '/' + to).split('/').filter(Boolean)\n const stack: string[] = []\n for (const part of parts) {\n if (part === '..') {\n stack.pop()\n } else if (part !== '.') {\n stack.push(part)\n }\n }\n return stack.join('/')\n}\n\nfunction normalizeSpecPath(specPath: string, currentRoutePath?: string, routePrefix = ''): string {\n if (specPath.startsWith(VIRTUAL_PREFIX)) return specPath\n\n const normalizedRoutePrefix = routePrefix.replace(/^\\/+|\\/+$/g, '')\n const normalizedSpecPath = specPath.startsWith('/') && normalizedRoutePrefix && specPath.slice(1).startsWith(`${normalizedRoutePrefix}/`)\n ? '/' + specPath.slice(normalizedRoutePrefix.length + 2)\n : specPath\n\n if (normalizedSpecPath.startsWith('/')) {\n return VIRTUAL_PREFIX + normalizedSpecPath.replace(/^\\//, '')\n }\n const fromDir = currentRoutePath === '/' ? '' : currentRoutePath?.replace(/^\\//, '').replace(/\\/[^/]*$/, '') ?? ''\n const normalizedFromDir = normalizedRoutePrefix && fromDir.startsWith(`${normalizedRoutePrefix}/`)\n ? fromDir.slice(normalizedRoutePrefix.length + 1)\n : fromDir\n return VIRTUAL_PREFIX + resolveRelativePath(normalizedFromDir, normalizedSpecPath)\n}\n\n/**\n * 为绝对 specPath 生成带 locale 前缀的候选模块 ID。\n *\n * 局部嵌入(OpenApiOperation / OpenApiDocument)通常使用 `/api` 这样的绝对路径。\n * 默认 locale 的 spec 注册在 `virtual:clarify-page/api`,而其他 locale 的 spec\n * 注册在 `virtual:clarify-page/<locale>/api`。相对路径会因为当前路由已含 locale 前缀\n * 而自动解析到正确的 spec,但绝对路径不会,因此这里显式注入 locale 前缀。\n */\nfunction localizeSpecModuleId(moduleId: string, specPath: string, locale: string | undefined, defaultLocale: string | undefined): string | undefined {\n if (!locale || locale === defaultLocale) return undefined\n // 仅处理绝对路径;相对路径已经基于含 locale 前缀的当前路由解析。\n if (!specPath.startsWith('/') || specPath.startsWith(VIRTUAL_PREFIX)) return undefined\n const rest = moduleId.slice(VIRTUAL_PREFIX.length)\n if (rest.startsWith(`${locale}/`) || rest === locale) return undefined\n return `${VIRTUAL_PREFIX}${locale}/${rest}`\n}\n\nexport function useOpenApiSpec(spec?: OpenAPISpec, specPath?: string): OpenAPISpec | null {\n const specs = useOpenApis()\n const location = useLocation()\n const config = useConfig()\n const locale = useLocale()\n\n if (spec) return spec\n if (!specPath) return null\n\n const normalized = normalizeSpecPath(specPath, location.pathname, config.routePrefix)\n const localized = localizeSpecModuleId(normalized, specPath, locale, config.i18n?.defaultLocale)\n\n if (localized && specs[localized]) return specs[localized]\n return specs[normalized] ?? null\n}\n","import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nimport type { OpenApiRecord } from '../types'\n\nexport type OpenAPISpec = OpenAPIV3.Document | OpenAPIV3_1.Document\nexport type OpenAPIOperation = OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject\n\nexport const OPENAPI_HTTP_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const\n\nexport type OpenAPIHttpMethod = typeof OPENAPI_HTTP_METHODS[number]\n\nexport function isOpenAPIHttpMethod(method: string): method is OpenAPIHttpMethod {\n return (OPENAPI_HTTP_METHODS as readonly string[]).includes(method.toLowerCase())\n}\n\nfunction isRecord(value: unknown): value is OpenApiRecord {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction resolveOpenApiRef(spec: OpenAPISpec, ref: string): unknown {\n if (!ref.startsWith('#/')) return undefined\n\n return ref\n .slice(2)\n .split('/')\n .map((part) => part.replace(/~1/g, '/').replace(/~0/g, '~'))\n .reduce<unknown>((current, part) => (isRecord(current) ? current[part] : undefined), spec)\n}\n\nfunction getPathItem(spec: OpenAPISpec, path: string): OpenApiRecord | undefined {\n const pathItem = spec.paths?.[path]\n const resolved = isRecord(pathItem) && typeof pathItem.$ref === 'string' ? resolveOpenApiRef(spec, pathItem.$ref) : pathItem\n return isRecord(resolved) ? resolved : undefined\n}\n\nexport function getOpenApiOperation(spec: OpenAPISpec, path: string, method: string): OpenAPIOperation | undefined {\n if (!isOpenAPIHttpMethod(method)) return undefined\n return getPathItem(spec, path)?.[method.toLowerCase() as OpenAPIHttpMethod] as OpenAPIOperation | undefined\n}\n\nexport function listOpenApiOperations(spec: OpenAPISpec): Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> {\n const paths = spec.paths ?? {}\n const operations: Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> = []\n\n for (const path of Object.keys(paths)) {\n const pathItem = getPathItem(spec, path)\n if (!pathItem) continue\n for (const method of OPENAPI_HTTP_METHODS) {\n const operation = pathItem[method]\n if (operation) operations.push({ path, method, operation: operation as OpenAPIOperation })\n }\n }\n\n return operations\n}\n","import type { ReactNode } from 'react'\n\nimport { PageTitleActions } from '../app/PageActions'\nimport { Prose } from '../components/Prose'\nimport { useBuiltInText } from '../core/i18n'\nimport { Markdown } from '../mdx/Markdown'\n\nimport { OpenApiOperation as OpenApiOperationComponent } from './components/OpenApiOperation'\nimport { useOpenApiSpec } from './lib/spec-path'\nimport { getOpenApiOperation, listOpenApiOperations } from './lib/utils'\nimport type { OpenAPISpec } from './lib/utils'\n\ntype OpenApiPathsProps = { spec: OpenAPISpec; tagFilter?: string[] }\n\ntype OpenApiHeaderProps = { spec: OpenAPISpec }\n\ntype WarningBoxProps = {\n children: ReactNode\n tone?: 'amber' | 'red'\n}\n\nexport type OpenApiDocumentProps = {\n spec?: OpenAPISpec\n specPath?: string\n tagFilter?: string[]\n}\n\ntype OpenApiOperationWithSpecProps = {\n spec: OpenAPISpec\n path: string\n method: string\n}\n\nexport type OpenApiOperationProps = {\n specPath: string\n path: string\n method: string\n}\n\nfunction OpenApiHeader(arg0: OpenApiHeaderProps): ReactNode {\n const { spec } = arg0\n\n const t = useBuiltInText()\n return (\n <header className=\"clarify-openapi-header mb-16 border-b border-(--clarify-theme-tokens-colors-border) pb-8\">\n <p className=\"mb-3 text-xs/6 font-medium tracking-widest text-(--clarify-ui-accent-text) uppercase\">\n {t('openapi.openApiReference')}\n </p>\n <div className=\"clarify-page-title-row flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between\">\n <h1 className=\"clarify-page-title min-w-0 flex-1\">{spec.info?.title ?? t('openapi.apiDocumentation')}</h1>\n <PageTitleActions />\n </div>\n {spec.info?.description ? <Markdown className=\"lead mt-4 *:first:mt-0 *:last:mb-0\">{spec.info.description}</Markdown> : null}\n {spec.info?.version ? <p className=\"mt-4 text-sm text-(--clarify-ui-text-faint)\">{t('openapi.version', { version: spec.info.version })}</p> : null}\n </header>\n )\n}\n\nfunction operationMatchesTags(operationTags: string[] | undefined, filterTags: string[] | undefined): boolean {\n if (!filterTags?.length) return true\n return operationTags?.some(tag => filterTags.includes(tag)) ?? false\n}\n\nfunction OpenApiPaths(arg0: OpenApiPathsProps): ReactNode {\n const { spec, tagFilter } = arg0\n\n const entries = listOpenApiOperations(spec)\n .filter(({ operation }) => operationMatchesTags(operation.tags, tagFilter))\n .map(({ path, method, operation }) => ({\n path,\n method: method.toUpperCase(),\n operation,\n }))\n\n return (\n <div className=\"clarify-api-endpoints divide-y divide-zinc-200/70 dark:divide-white/10\">\n {entries.map(({ path, method, operation }) => (\n <OpenApiOperationComponent key={`${method}-${path}`} spec={spec} path={path} method={method} operation={operation} />\n ))}\n </div>\n )\n}\n\nfunction WarningBox(arg0: WarningBoxProps): ReactNode {\n const { children, tone = 'amber' } = arg0\n\n const classes = tone === 'red'\n ? 'rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-200'\n : 'rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200'\n\n return <div className={`clarify-warning ${classes}`}>{children}</div>\n}\n\nexport function OpenApiDocument(arg0: OpenApiDocumentProps): ReactNode {\n const { spec, specPath, tagFilter } = arg0\n const t = useBuiltInText()\n const resolved = useOpenApiSpec(spec, specPath)\n\n if (!resolved) {\n return <WarningBox>{t('openapi.specNotFound', { specPath: specPath ?? t('openapi.specPathMissing') })}</WarningBox>\n }\n\n return (\n <article className=\"clarify-openapi-page flex h-full flex-col pt-16 pb-10\">\n <Prose className=\"flex-auto\">\n <OpenApiHeader spec={resolved} />\n <OpenApiPaths spec={resolved} tagFilter={tagFilter} />\n </Prose>\n </article>\n )\n}\n\nfunction OpenApiOperationWithSpec(arg0: OpenApiOperationWithSpecProps): ReactNode {\n const { spec, path, method } = arg0\n const t = useBuiltInText()\n const op = getOpenApiOperation(spec, path, method)\n\n if (!op) {\n return <WarningBox tone=\"red\">{t('openapi.endpointNotFound', { endpoint: `${method.toUpperCase()} ${path}` })}</WarningBox>\n }\n\n const normalizedMethod = method.toUpperCase()\n return <OpenApiOperationComponent key={`${normalizedMethod}-${path}`} spec={spec} path={path} method={normalizedMethod} operation={op} />\n}\n\nexport function OpenApiOperation(arg0: OpenApiOperationProps): ReactNode {\n const { specPath, path, method } = arg0\n const t = useBuiltInText()\n const spec = useOpenApiSpec(undefined, specPath)\n\n if (!spec) {\n return <WarningBox>{t('openapi.specNotFound', { specPath })}</WarningBox>\n }\n\n return <OpenApiOperationWithSpec spec={spec} path={path} method={method} />\n}\n","import { Collapse } from '../components/Collapse'\nimport { OpenApiDocument, OpenApiOperation } from '../openapi'\n\nimport { Markdown } from './Markdown'\nimport * as mdxPrimitives from './primitives'\n\nconst builtInMDXComponents = {\n ...mdxPrimitives,\n Markdown,\n Collapse,\n}\n\nconst builtInOpenAPIComponents = {\n OpenApiDocument,\n OpenApiOperation,\n}\n\nexport function useMDXComponents(components: Record<string, unknown> = {}) {\n return {\n ...components,\n ...builtInMDXComponents,\n ...builtInOpenAPIComponents,\n }\n}\n","import type { ReactNode } from 'react'\n\nimport { Prose } from '../components/Prose'\n\nexport type DocShellProps = {\n title: string\n subtitle?: string\n children: ReactNode\n}\n\nexport function DocShell(arg0: DocShellProps) {\n const { title, subtitle, children } = arg0\n\n return (\n <main className=\"clarify-doc-shell min-h-screen bg-(--clarify-theme-tokens-colors-background) px-6 py-10 text-(--clarify-theme-tokens-colors-foreground) md:px-10\">\n <div className=\"mx-auto max-w-6xl\">\n <header className=\"mb-10\">\n <h1 className=\"text-3xl font-bold tracking-tight md:text-5xl\">{title}</h1>\n {subtitle ? <p className=\"mt-3 max-w-2xl text-(--clarify-ui-text-soft)\">{subtitle}</p> : null}\n </header>\n <Prose>{children}</Prose>\n </div>\n </main>\n )\n}\n"],"mappings":";;;;;;;;;AAMA,IAAM,iBAAiB;AAEvB,SAAS,oBAAoB,SAAiB,IAAoB;CAChE,MAAM,SAAS,UAAU,MAAM,IAAI,MAAM,GAAG,EAAE,OAAO,OAAO;CAC5D,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,QAAQ,OACjB,IAAI,SAAS,MACX,MAAM,IAAI;MACL,IAAI,SAAS,KAClB,MAAM,KAAK,IAAI;CAGnB,OAAO,MAAM,KAAK,GAAG;AACvB;AAEA,SAAS,kBAAkB,UAAkB,kBAA2B,cAAc,IAAY;CAChG,IAAI,SAAS,WAAW,cAAc,GAAG,OAAO;CAEhD,MAAM,wBAAwB,YAAY,QAAQ,cAAc,EAAE;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
import { BuiltWithClarify } from './app/BuiltWithClarify';
|
|
3
|
+
import { PageBanner } from './app/PageBanner';
|
|
3
4
|
import { PageFooter } from './app/PageFooter';
|
|
4
5
|
import { SectionProvider, useSectionStore, Section } from './app/SectionProvider';
|
|
5
6
|
import { Button, Callout, Card, CardGroup, Code, CodeGroup, Collapse, Feedback, GridPattern, Heading, HeroPattern, Logo, Pre, Prose, Tag, WebFrame } from './components';
|
|
6
|
-
import {
|
|
7
|
+
import { ConfigContext, OpenApisContext, useConfig, useOpenApis } from './context';
|
|
7
8
|
import { useMDXComponents } from './mdx/components';
|
|
8
9
|
import { DocShell } from './mdx/DocShell';
|
|
9
10
|
import { Markdown } from './mdx/Markdown';
|
|
10
11
|
import { markdownRemarkPlugins } from './mdx/remark';
|
|
11
12
|
import { OpenApiDocument, OpenApiOperation } from './openapi';
|
|
12
13
|
import { render } from './runtime/render';
|
|
13
|
-
import {
|
|
14
|
+
import { applyThemeVariables, themeEditorPresets, ThemeEditor } from './theme/ThemeEditor';
|
|
14
15
|
import { ThemeProvider, useTheme } from './theme/ThemeProvider';
|
|
15
16
|
import { ThemeToggle } from './theme/ThemeToggle';
|
|
16
|
-
import {
|
|
17
|
+
import { themePresets, themeBootstrapScript } from './theme/variables';
|
|
18
|
+
import { Config, RouteItem, RenderOptions, ServerRenderOptions } from './types';
|
|
17
19
|
import { remToPx } from './utils/remToPx';
|
|
18
20
|
export type { OpenApiOperationProps, OpenApiDocumentProps, OpenAPIOperation, OpenAPISpec } from './openapi';
|
|
19
21
|
export type { ThemeEditorProps } from './theme/ThemeEditor';
|
|
20
|
-
export type {
|
|
21
|
-
export { AppShell, render,
|
|
22
|
+
export type { Config, RouteItem, RenderOptions, ServerRenderOptions, Section };
|
|
23
|
+
export { AppShell, render, ConfigContext, OpenApisContext, useConfig, useOpenApis, BuiltWithClarify, PageBanner, PageFooter, ThemeProvider, ThemeToggle, ThemeEditor, useTheme, SectionProvider, useSectionStore, remToPx, applyThemeVariables, themeEditorPresets, themePresets, themeBootstrapScript };
|
|
22
24
|
export { Button, Callout, Card, CardGroup, Code, CodeGroup, Collapse, Pre, Prose, Heading, Logo, GridPattern, HeroPattern, Feedback, Tag, WebFrame };
|
|
23
25
|
export { DocShell, Markdown, useMDXComponents, markdownRemarkPlugins };
|
|
24
26
|
export { OpenApiDocument, OpenApiOperation };
|
package/output/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as Code, D as CardGroup, E as Card, O as Callout, S as Collapse, T as Pre, _ as HeroPattern, b as Tag, f as Markdown, g as GridPattern, h as Prose, k as Button, m as WebFrame, n as OpenApiOperation$1, p as primitives_exports, v as Logo, w as CodeGroup, x as Feedback, y as Heading } from "./OpenApiOperation-
|
|
2
|
-
import { A as OpenApisContext, D as useBuiltInText, N as useOpenApis, O as
|
|
3
|
-
import { a as AppShell, i as
|
|
1
|
+
import { C as Code, D as CardGroup, E as Card, O as Callout, S as Collapse, T as Pre, _ as HeroPattern, b as Tag, f as Markdown, g as GridPattern, h as Prose, k as Button, m as WebFrame, n as OpenApiOperation$1, p as primitives_exports, v as Logo, w as CodeGroup, x as Feedback, y as Heading } from "./OpenApiOperation-tUKf7lZ4.js";
|
|
2
|
+
import { A as OpenApisContext, D as useBuiltInText, M as useLocale, N as useOpenApis, O as ConfigContext, c as remToPx, h as useTheme, j as useConfig, m as ThemeProvider, n as PageTitleActions, o as SectionProvider, p as ThemeToggle, s as useSectionStore } from "./PageActions-yoDRjkq8.js";
|
|
3
|
+
import { a as themeBootstrapScript, c as AppShell, d as PageBanner, i as themeEditorPresets, l as PageFooter, n as ThemeEditor, o as themePresets, r as applyThemeVariables, u as BuiltWithClarify } from "./ThemeRoot-QULrwQf6.js";
|
|
4
4
|
import { t as markdownRemarkPlugins } from "./remark-Dd2WU50s.js";
|
|
5
|
-
import { t as render } from "./render-
|
|
5
|
+
import { t as render } from "./render-psutGbsg.js";
|
|
6
6
|
import { useLocation } from "react-router-dom";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
//#region source/openapi/lib/spec-path.ts
|
|
@@ -22,13 +22,32 @@ function normalizeSpecPath(specPath, currentRoutePath, routePrefix = "") {
|
|
|
22
22
|
const fromDir = currentRoutePath === "/" ? "" : currentRoutePath?.replace(/^\//, "").replace(/\/[^/]*$/, "") ?? "";
|
|
23
23
|
return VIRTUAL_PREFIX + resolveRelativePath(normalizedRoutePrefix && fromDir.startsWith(`${normalizedRoutePrefix}/`) ? fromDir.slice(normalizedRoutePrefix.length + 1) : fromDir, normalizedSpecPath);
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* 为绝对 specPath 生成带 locale 前缀的候选模块 ID。
|
|
27
|
+
*
|
|
28
|
+
* 局部嵌入(OpenApiOperation / OpenApiDocument)通常使用 `/api` 这样的绝对路径。
|
|
29
|
+
* 默认 locale 的 spec 注册在 `virtual:clarify-page/api`,而其他 locale 的 spec
|
|
30
|
+
* 注册在 `virtual:clarify-page/<locale>/api`。相对路径会因为当前路由已含 locale 前缀
|
|
31
|
+
* 而自动解析到正确的 spec,但绝对路径不会,因此这里显式注入 locale 前缀。
|
|
32
|
+
*/
|
|
33
|
+
function localizeSpecModuleId(moduleId, specPath, locale, defaultLocale) {
|
|
34
|
+
if (!locale || locale === defaultLocale) return void 0;
|
|
35
|
+
if (!specPath.startsWith("/") || specPath.startsWith(VIRTUAL_PREFIX)) return void 0;
|
|
36
|
+
const rest = moduleId.slice(21);
|
|
37
|
+
if (rest.startsWith(`${locale}/`) || rest === locale) return void 0;
|
|
38
|
+
return `${VIRTUAL_PREFIX}${locale}/${rest}`;
|
|
39
|
+
}
|
|
25
40
|
function useOpenApiSpec(spec, specPath) {
|
|
26
41
|
const specs = useOpenApis();
|
|
27
42
|
const location = useLocation();
|
|
28
|
-
const config =
|
|
43
|
+
const config = useConfig();
|
|
44
|
+
const locale = useLocale();
|
|
29
45
|
if (spec) return spec;
|
|
30
46
|
if (!specPath) return null;
|
|
31
|
-
|
|
47
|
+
const normalized = normalizeSpecPath(specPath, location.pathname, config.routePrefix);
|
|
48
|
+
const localized = localizeSpecModuleId(normalized, specPath, locale, config.i18n?.defaultLocale);
|
|
49
|
+
if (localized && specs[localized]) return specs[localized];
|
|
50
|
+
return specs[normalized] ?? null;
|
|
32
51
|
}
|
|
33
52
|
//#endregion
|
|
34
53
|
//#region source/openapi/lib/utils.ts
|
|
@@ -84,19 +103,25 @@ function OpenApiHeader(arg0) {
|
|
|
84
103
|
const { spec } = arg0;
|
|
85
104
|
const t = useBuiltInText();
|
|
86
105
|
return /* @__PURE__ */ jsxs("header", {
|
|
87
|
-
className: "mb-16",
|
|
106
|
+
className: "clarify-openapi-header mb-16 border-b border-(--clarify-theme-tokens-colors-border) pb-8",
|
|
88
107
|
children: [
|
|
89
108
|
/* @__PURE__ */ jsx("p", {
|
|
90
|
-
className: "mb-3 text-xs/6 font-medium tracking-widest text-
|
|
109
|
+
className: "mb-3 text-xs/6 font-medium tracking-widest text-(--clarify-ui-accent-text) uppercase",
|
|
91
110
|
children: t("openapi.openApiReference")
|
|
92
111
|
}),
|
|
93
|
-
/* @__PURE__ */
|
|
112
|
+
/* @__PURE__ */ jsxs("div", {
|
|
113
|
+
className: "clarify-page-title-row flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",
|
|
114
|
+
children: [/* @__PURE__ */ jsx("h1", {
|
|
115
|
+
className: "clarify-page-title min-w-0 flex-1",
|
|
116
|
+
children: spec.info?.title ?? t("openapi.apiDocumentation")
|
|
117
|
+
}), /* @__PURE__ */ jsx(PageTitleActions, {})]
|
|
118
|
+
}),
|
|
94
119
|
spec.info?.description ? /* @__PURE__ */ jsx(Markdown, {
|
|
95
|
-
className: "lead *:first:mt-0 *:last:mb-0",
|
|
120
|
+
className: "lead mt-4 *:first:mt-0 *:last:mb-0",
|
|
96
121
|
children: spec.info.description
|
|
97
122
|
}) : null,
|
|
98
123
|
spec.info?.version ? /* @__PURE__ */ jsx("p", {
|
|
99
|
-
className: "text-sm text-
|
|
124
|
+
className: "mt-4 text-sm text-(--clarify-ui-text-faint)",
|
|
100
125
|
children: t("openapi.version", { version: spec.info.version })
|
|
101
126
|
}) : null
|
|
102
127
|
]
|
|
@@ -212,6 +237,6 @@ function DocShell(arg0) {
|
|
|
212
237
|
});
|
|
213
238
|
}
|
|
214
239
|
//#endregion
|
|
215
|
-
export { AppShell, BuiltWithClarify, Button, Callout, Card, CardGroup,
|
|
240
|
+
export { AppShell, BuiltWithClarify, Button, Callout, Card, CardGroup, Code, CodeGroup, Collapse, ConfigContext, DocShell, Feedback, GridPattern, Heading, HeroPattern, Logo, Markdown, OpenApiDocument, OpenApiOperation, OpenApisContext, PageBanner, PageFooter, Pre, Prose, SectionProvider, Tag, ThemeEditor, ThemeProvider, ThemeToggle, WebFrame, applyThemeVariables, markdownRemarkPlugins, remToPx, render, themeBootstrapScript, themeEditorPresets, themePresets, useConfig, useMDXComponents, useOpenApis, useSectionStore, useTheme };
|
|
216
241
|
|
|
217
242
|
//# sourceMappingURL=index.js.map
|