@clarify-labs/renderer 0.1.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 (50) hide show
  1. package/LICENSE +661 -0
  2. package/output/AppShell-C_bj6ZhV.js +1928 -0
  3. package/output/AppShell-C_bj6ZhV.js.map +1 -0
  4. package/output/AppShell-DBgUlirU.cjs +2127 -0
  5. package/output/AppShell-DBgUlirU.cjs.map +1 -0
  6. package/output/app/AppShell.d.ts +7 -0
  7. package/output/client.cjs +3 -0
  8. package/output/client.d.ts +1 -0
  9. package/output/client.js +2 -0
  10. package/output/components/BuiltWithClarify.d.ts +1 -0
  11. package/output/components/Code.d.ts +18 -0
  12. package/output/components/Feedback.d.ts +1 -0
  13. package/output/components/PageFooter.d.ts +1 -0
  14. package/output/components/SectionProvider.d.ts +25 -0
  15. package/output/components/SiteLogo.d.ts +6 -0
  16. package/output/components/ThemeProvider.d.ts +13 -0
  17. package/output/components/ThemeToggle.d.ts +1 -0
  18. package/output/components/index.d.ts +82 -0
  19. package/output/components/patterns.d.ts +9 -0
  20. package/output/context.d.ts +6 -0
  21. package/output/index.cjs +870 -0
  22. package/output/index.cjs.map +1 -0
  23. package/output/index.d.ts +11 -0
  24. package/output/index.js +850 -0
  25. package/output/index.js.map +1 -0
  26. package/output/mdx/components.d.ts +50 -0
  27. package/output/mdx/primitives.d.ts +42 -0
  28. package/output/openapi/index.d.ts +20 -0
  29. package/output/openapi/utils.d.ts +12 -0
  30. package/output/render-CLI-MnH_.cjs +60 -0
  31. package/output/render-CLI-MnH_.cjs.map +1 -0
  32. package/output/render-Ca4Is683.js +55 -0
  33. package/output/render-Ca4Is683.js.map +1 -0
  34. package/output/renderer.css +3986 -0
  35. package/output/runtime/render.d.ts +2 -0
  36. package/output/runtime/server.d.ts +7 -0
  37. package/output/server.cjs +34 -0
  38. package/output/server.cjs.map +1 -0
  39. package/output/server.d.ts +1 -0
  40. package/output/server.js +33 -0
  41. package/output/server.js.map +1 -0
  42. package/output/shell/ContentActions.d.ts +7 -0
  43. package/output/shell/Header.d.ts +8 -0
  44. package/output/shell/Navigation.d.ts +5 -0
  45. package/output/shell/Search.d.ts +10 -0
  46. package/output/shell/index.d.ts +5 -0
  47. package/output/shell/mobile.d.ts +15 -0
  48. package/output/types.d.ts +121 -0
  49. package/output/utils/remToPx.d.ts +1 -0
  50. package/package.json +71 -0
@@ -0,0 +1,2 @@
1
+ import { RenderOptions } from '../types';
2
+ export declare function render(options: RenderOptions): void;
@@ -0,0 +1,7 @@
1
+ import { ServerRenderOptions } from '../types';
2
+ /**
3
+ * Clarify 服务端渲染入口。
4
+ * 由 @clarify-labs/cli 在构建时调用,为每条路由生成 React HTML 片段。
5
+ * 返回 `div#root` 内部的 HTML,由 Clarify CLI 组装为完整的 HTML 文档。
6
+ */
7
+ export declare function renderToHTML(options: ServerRenderOptions): string;
@@ -0,0 +1,34 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_AppShell = require("./AppShell-DBgUlirU.cjs");
3
+ let react = require("react");
4
+ let react_router_dom = require("react-router-dom");
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+ let react_dom_server = require("react-dom/server");
7
+ //#region source/runtime/server.tsx
8
+ /**
9
+ * Clarify 服务端渲染入口。
10
+ * 由 @clarify-labs/cli 在构建时调用,为每条路由生成 React HTML 片段。
11
+ * 返回 `div#root` 内部的 HTML,由 Clarify CLI 组装为完整的 HTML 文档。
12
+ */
13
+ function renderToHTML(options) {
14
+ const { config, routes, navigation, openApis = {}, url } = options;
15
+ return (0, react_dom_server.renderToString)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.StrictMode, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_router_dom.StaticRouter, {
16
+ basename: config.routePrefix,
17
+ location: url,
18
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AppShell.ClarifyConfigContext.Provider, {
19
+ value: config,
20
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AppShell.OpenApisContext.Provider, {
21
+ value: openApis,
22
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AppShell.ThemeProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AppShell.AppShell, {
23
+ config,
24
+ routes,
25
+ navigation: navigation ?? []
26
+ }) })
27
+ })
28
+ })
29
+ }) }));
30
+ }
31
+ //#endregion
32
+ exports.renderToHTML = renderToHTML;
33
+
34
+ //# sourceMappingURL=server.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.cjs","names":[],"sources":["../source/runtime/server.tsx"],"sourcesContent":["import { StrictMode } from 'react'\nimport { renderToString } from 'react-dom/server'\nimport { StaticRouter } from 'react-router-dom'\n\nimport { AppShell } from '../app/AppShell'\nimport { ThemeProvider } from '../components/ThemeProvider'\nimport { ClarifyConfigContext, OpenApisContext } from '../context'\nimport type { ServerRenderOptions } from '../types'\n\n/**\n * Clarify 服务端渲染入口。\n * 由 @clarify-labs/cli 在构建时调用,为每条路由生成 React HTML 片段。\n * 返回 `div#root` 内部的 HTML,由 Clarify CLI 组装为完整的 HTML 文档。\n */\nexport function renderToHTML(options: ServerRenderOptions): string {\n const { config, routes, navigation, openApis = {}, url } = options\n\n return renderToString(\n <StrictMode>\n <StaticRouter basename={config.routePrefix} location={url}>\n <ClarifyConfigContext.Provider value={config}>\n <OpenApisContext.Provider value={openApis}>\n <ThemeProvider>\n <AppShell config={config} routes={routes} navigation={navigation ?? []} />\n </ThemeProvider>\n </OpenApisContext.Provider>\n </ClarifyConfigContext.Provider>\n </StaticRouter>\n </StrictMode>\n )\n}\n"],"mappings":";;;;;;;;;;;;AAcA,SAAgB,aAAa,SAAsC;CACjE,MAAM,EAAE,QAAQ,QAAQ,YAAY,WAAW,CAAC,GAAG,QAAQ;CAE3D,QAAA,GAAA,iBAAA,gBACE,iBAAA,GAAA,kBAAA,KAAC,MAAA,YAAD,EAAA,UACE,iBAAA,GAAA,kBAAA,KAAC,iBAAA,cAAD;EAAc,UAAU,OAAO;EAAa,UAAU;YACpD,iBAAA,GAAA,kBAAA,KAAC,iBAAA,qBAAqB,UAAtB;GAA+B,OAAO;aACpC,iBAAA,GAAA,kBAAA,KAAC,iBAAA,gBAAgB,UAAjB;IAA0B,OAAO;cAC/B,iBAAA,GAAA,kBAAA,KAAC,iBAAA,eAAD,EAAA,UACE,iBAAA,GAAA,kBAAA,KAAC,iBAAA,UAAD;KAAkB;KAAgB;KAAQ,YAAY,cAAc,CAAC;IAAI,CAAA,EAC5D,CAAA;GACS,CAAA;EACG,CAAA;CACnB,CAAA,EACJ,CAAA,CACd;AACF"}
@@ -0,0 +1 @@
1
+ export { renderToHTML } from './runtime/server';
@@ -0,0 +1,33 @@
1
+ import { m as OpenApisContext, p as ClarifyConfigContext, t as AppShell, u as ThemeProvider } from "./AppShell-C_bj6ZhV.js";
2
+ import { StrictMode } from "react";
3
+ import { StaticRouter } from "react-router-dom";
4
+ import { jsx } from "react/jsx-runtime";
5
+ import { renderToString } from "react-dom/server";
6
+ //#region source/runtime/server.tsx
7
+ /**
8
+ * Clarify 服务端渲染入口。
9
+ * 由 @clarify-labs/cli 在构建时调用,为每条路由生成 React HTML 片段。
10
+ * 返回 `div#root` 内部的 HTML,由 Clarify CLI 组装为完整的 HTML 文档。
11
+ */
12
+ function renderToHTML(options) {
13
+ const { config, routes, navigation, openApis = {}, url } = options;
14
+ return renderToString(/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(StaticRouter, {
15
+ basename: config.routePrefix,
16
+ location: url,
17
+ children: /* @__PURE__ */ jsx(ClarifyConfigContext.Provider, {
18
+ value: config,
19
+ children: /* @__PURE__ */ jsx(OpenApisContext.Provider, {
20
+ value: openApis,
21
+ children: /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(AppShell, {
22
+ config,
23
+ routes,
24
+ navigation: navigation ?? []
25
+ }) })
26
+ })
27
+ })
28
+ }) }));
29
+ }
30
+ //#endregion
31
+ export { renderToHTML };
32
+
33
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","names":[],"sources":["../source/runtime/server.tsx"],"sourcesContent":["import { StrictMode } from 'react'\nimport { renderToString } from 'react-dom/server'\nimport { StaticRouter } from 'react-router-dom'\n\nimport { AppShell } from '../app/AppShell'\nimport { ThemeProvider } from '../components/ThemeProvider'\nimport { ClarifyConfigContext, OpenApisContext } from '../context'\nimport type { ServerRenderOptions } from '../types'\n\n/**\n * Clarify 服务端渲染入口。\n * 由 @clarify-labs/cli 在构建时调用,为每条路由生成 React HTML 片段。\n * 返回 `div#root` 内部的 HTML,由 Clarify CLI 组装为完整的 HTML 文档。\n */\nexport function renderToHTML(options: ServerRenderOptions): string {\n const { config, routes, navigation, openApis = {}, url } = options\n\n return renderToString(\n <StrictMode>\n <StaticRouter basename={config.routePrefix} location={url}>\n <ClarifyConfigContext.Provider value={config}>\n <OpenApisContext.Provider value={openApis}>\n <ThemeProvider>\n <AppShell config={config} routes={routes} navigation={navigation ?? []} />\n </ThemeProvider>\n </OpenApisContext.Provider>\n </ClarifyConfigContext.Provider>\n </StaticRouter>\n </StrictMode>\n )\n}\n"],"mappings":";;;;;;;;;;;AAcA,SAAgB,aAAa,SAAsC;CACjE,MAAM,EAAE,QAAQ,QAAQ,YAAY,WAAW,CAAC,GAAG,QAAQ;CAE3D,OAAO,eACL,oBAAC,YAAD,EAAA,UACE,oBAAC,cAAD;EAAc,UAAU,OAAO;EAAa,UAAU;YACpD,oBAAC,qBAAqB,UAAtB;GAA+B,OAAO;aACpC,oBAAC,gBAAgB,UAAjB;IAA0B,OAAO;cAC/B,oBAAC,eAAD,EAAA,UACE,oBAAC,UAAD;KAAkB;KAAgB;KAAQ,YAAY,cAAc,CAAC;IAAI,CAAA,EAC5D,CAAA;GACS,CAAA;EACG,CAAA;CACnB,CAAA,EACJ,CAAA,CACd;AACF"}
@@ -0,0 +1,7 @@
1
+ import { RouteItem } from '../types';
2
+ type ContentActionsProps = {
3
+ route?: RouteItem;
4
+ routePrefix?: string;
5
+ };
6
+ export declare function ContentActions(arg0: ContentActionsProps): import("react").JSX.Element | null;
7
+ export {};
@@ -0,0 +1,8 @@
1
+ import { ClarifyConfig, NavigationNode, RouteItem } from '../types';
2
+ export declare const Header: import('react').ForwardRefExoticComponent<Omit<Omit<import('framer-motion').HTMLMotionProps<"div">, "ref"> & import('react').RefAttributes<HTMLDivElement>, "ref"> & {
3
+ config: ClarifyConfig;
4
+ navigation: NavigationNode[];
5
+ routes: RouteItem[];
6
+ currentLocale?: string;
7
+ currentRoute?: RouteItem;
8
+ } & import('react').RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,5 @@
1
+ import { NavigationNode } from '../types';
2
+ export declare function Navigation(arg0: {
3
+ navigation: NavigationNode[];
4
+ className?: string;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { NavigationNode, RouteItem } from '../types';
2
+ export declare function Search(arg0: {
3
+ routes: RouteItem[];
4
+ navigation: NavigationNode[];
5
+ }): import("react").JSX.Element;
6
+ export declare function MobileSearch(arg0: {
7
+ routes: RouteItem[];
8
+ navigation: NavigationNode[];
9
+ onNavigate?: () => void;
10
+ }): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ export { ContentActions } from './ContentActions';
2
+ export { Header } from './Header';
3
+ export { MobileNavigation, useIsInsideMobileNavigation, useMobileNavigationStore } from './mobile';
4
+ export { Navigation } from './Navigation';
5
+ export { MobileSearch, Search } from './Search';
@@ -0,0 +1,15 @@
1
+ import { ClarifyConfig, NavigationNode, RouteItem } from '../types';
2
+ export declare function useIsInsideMobileNavigation(): boolean;
3
+ export declare const useMobileNavigationStore: import('zustand').UseBoundStore<import('zustand').StoreApi<{
4
+ isOpen: boolean;
5
+ open: () => void;
6
+ close: () => void;
7
+ toggle: () => void;
8
+ }>>;
9
+ export declare function MobileNavigation(arg0: {
10
+ config: ClarifyConfig;
11
+ navigation: NavigationNode[];
12
+ routes: RouteItem[];
13
+ currentLocale?: string;
14
+ currentRoute?: RouteItem;
15
+ }): import("react").JSX.Element;
@@ -0,0 +1,121 @@
1
+ import { ComponentType } from 'react';
2
+ import { OpenAPISpec } from './openapi/utils';
3
+ export type RouteSection = {
4
+ id: string;
5
+ title: string;
6
+ badge?: string;
7
+ tags?: string[];
8
+ };
9
+ export type NavigationNode = {
10
+ path: string;
11
+ title: string;
12
+ icon?: string;
13
+ children?: NavigationNode[];
14
+ sections?: RouteSection[];
15
+ };
16
+ export type RouteItem = {
17
+ path: string;
18
+ basePath?: string;
19
+ locale?: string;
20
+ isFallback?: boolean;
21
+ alternates?: Record<string, string>;
22
+ title: string;
23
+ component: ComponentType;
24
+ kind?: 'mdx' | 'openapi';
25
+ sections?: RouteSection[];
26
+ rawContentUrl?: string;
27
+ };
28
+ export type ClarifyLogoConfig = string | {
29
+ light?: string;
30
+ dark?: string;
31
+ };
32
+ export type ClarifyFaviconConfig = string | {
33
+ light?: string;
34
+ dark?: string;
35
+ };
36
+ export type ClarifyLocalizedText = string | Record<string, string>;
37
+ export type ClarifyLocaleConfig = {
38
+ code: string;
39
+ label: string;
40
+ dir?: 'ltr' | 'rtl';
41
+ };
42
+ export type ClarifyI18nConfig = {
43
+ defaultLocale: string;
44
+ missing: 'fallback' | '404' | 'hide';
45
+ locales: ClarifyLocaleConfig[];
46
+ };
47
+ export type ClarifyNavbarLink = {
48
+ label: ClarifyLocalizedText;
49
+ href: string;
50
+ external?: boolean;
51
+ };
52
+ export type ClarifyBannerConfig = {
53
+ content: ClarifyLocalizedText;
54
+ dismissible?: boolean;
55
+ };
56
+ export type ClarifyFooterConfig = {
57
+ links?: ClarifyNavbarLink[];
58
+ socials?: Record<string, string>;
59
+ copyright?: ClarifyLocalizedText;
60
+ };
61
+ export type ClarifyPagesItem = string | {
62
+ page: string;
63
+ title?: ClarifyLocalizedText;
64
+ icon?: string;
65
+ redirect?: string;
66
+ } | {
67
+ openapi: string;
68
+ icon?: string;
69
+ title?: ClarifyLocalizedText;
70
+ };
71
+ export type ClarifyPagesGroup = {
72
+ group: ClarifyLocalizedText;
73
+ icon?: string;
74
+ pages: ClarifyPagesItem[];
75
+ };
76
+ export type ClarifyPagesConfig = ClarifyPagesGroup[] | 'FileTree';
77
+ export type ClarifyConfig = {
78
+ title: string;
79
+ logo?: ClarifyLogoConfig;
80
+ favicon?: ClarifyFaviconConfig;
81
+ theme: {
82
+ primary?: string;
83
+ };
84
+ description: string;
85
+ rootDirectory: string;
86
+ routePrefix: string;
87
+ outputDirectory: string;
88
+ navbar?: {
89
+ links?: ClarifyNavbarLink[];
90
+ };
91
+ banner?: ClarifyBannerConfig;
92
+ footer?: ClarifyFooterConfig;
93
+ i18n?: ClarifyI18nConfig;
94
+ pages?: ClarifyPagesConfig;
95
+ };
96
+ export type LocalizedNavigation = Record<string, NavigationNode[]>;
97
+ export type NavigationTree = NavigationNode[] | LocalizedNavigation;
98
+ export type RenderOptions = {
99
+ /** 从 virtual:clarify-config 导入的 config */
100
+ config: ClarifyConfig;
101
+ /** 从 virtual:clarify-routes 导入的路由数组 */
102
+ routes: RouteItem[];
103
+ /** 从 virtual:clarify-routes 导入的导航树;启用 i18n 时为按 locale 分组的导航树 */
104
+ navigation?: NavigationTree;
105
+ /** 从 virtual:clarify-openapi-registry 导入的 OpenAPI 规范表 */
106
+ openApis?: Record<string, OpenAPISpec>;
107
+ /** 挂载节点,默认 document.getElementById('root') */
108
+ container?: Element | null;
109
+ };
110
+ export type ServerRenderOptions = {
111
+ /** 从 virtual:clarify-config 导入的 config */
112
+ config: ClarifyConfig;
113
+ /** 从 virtual:clarify-routes 导入的路由数组 */
114
+ routes: RouteItem[];
115
+ /** 从 virtual:clarify-routes 导入的导航树;启用 i18n 时为按 locale 分组的导航树 */
116
+ navigation?: NavigationTree;
117
+ /** 从 virtual:clarify-openapi-registry 导入的 OpenAPI 规范表 */
118
+ openApis?: Record<string, OpenAPISpec>;
119
+ /** 当前请求的 URL */
120
+ url: string;
121
+ };
@@ -0,0 +1 @@
1
+ export declare function remToPx(remValue: number): number;
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@clarify-labs/renderer",
3
+ "version": "0.1.0",
4
+ "license": "AGPL-3.0-only",
5
+ "type": "module",
6
+ "main": "output/index.cjs",
7
+ "module": "output/index.js",
8
+ "types": "output/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./output/index.d.ts",
12
+ "import": "./output/index.js",
13
+ "require": "./output/index.cjs",
14
+ "default": "./output/index.js"
15
+ },
16
+ "./client": {
17
+ "types": "./output/client.d.ts",
18
+ "import": "./output/client.js",
19
+ "require": "./output/client.cjs",
20
+ "default": "./output/client.js"
21
+ },
22
+ "./server": {
23
+ "types": "./output/server.d.ts",
24
+ "import": "./output/server.js",
25
+ "require": "./output/server.cjs",
26
+ "default": "./output/server.js"
27
+ },
28
+ "./style.css": "./output/renderer.css",
29
+ "./package.json": "./package.json"
30
+ },
31
+ "files": [
32
+ "LICENSE",
33
+ "output"
34
+ ],
35
+ "scripts": {
36
+ "dev": "vite build --watch",
37
+ "build": "vite build",
38
+ "lint": "eslint source/",
39
+ "lint:fix": "eslint source/ --fix",
40
+ "typecheck": "tsc -p tsconfig.json --noEmit"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^19.0.0",
44
+ "react-dom": "^19.0.0",
45
+ "react-router-dom": "^7.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@tailwindcss/vite": "^4.1.11",
49
+ "@types/github-slugger": "^2.0.0",
50
+ "@types/react": "^19.1.8",
51
+ "@types/react-dom": "^19.1.6",
52
+ "@vitejs/plugin-react": "^5.0.5",
53
+ "react": "^19.0.0",
54
+ "react-dom": "^19.0.0",
55
+ "react-router-dom": "^7.0.0",
56
+ "tailwindcss": "^4.1.11",
57
+ "typescript": "^5.8.3",
58
+ "vite": "^8.0.15",
59
+ "vite-plugin-dts": "^4.5.4"
60
+ },
61
+ "dependencies": {
62
+ "@headlessui/react": "^2.2.10",
63
+ "@tailwindcss/typography": "^0.5.20",
64
+ "clsx": "^2.1.1",
65
+ "framer-motion": "^12.40.0",
66
+ "github-slugger": "^2.0.0",
67
+ "lucide-react": "^1.20.0",
68
+ "openapi-types": "^12.1.3",
69
+ "zustand": "^5.0.14"
70
+ }
71
+ }