doc-render-sdk 0.0.1 → 0.0.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/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useRef, useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
  import EventTarget from "mini-event/EventTarget";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
- import { cloneDeep, get as get$1, merge, set as set$1 } from "lodash-es";
5
+ import { cloneDeep, get, merge, set } from "lodash-es";
6
6
 
7
7
  //#region src/components/Navigation.tsx
8
8
  const Navigation = ({ config, theme, currentRoute, componentRegistry, onNavigate, compact = false }) => {
@@ -105,219 +105,10 @@ const Navigation = ({ config, theme, currentRoute, componentRegistry, onNavigate
105
105
  };
106
106
  var Navigation_default = Navigation;
107
107
 
108
- //#endregion
109
- //#region src/components/Search.tsx
110
- const Search = ({ config, componentRegistry, onClose, onNavigate }) => {
111
- const [query, setQuery] = useState("");
112
- const [results, setResults] = useState([]);
113
- const [selectedIndex, setSelectedIndex] = useState(0);
114
- const inputRef = useRef(null);
115
- const overlayRef = useRef(null);
116
- useEffect(() => {
117
- if (inputRef.current) inputRef.current.focus();
118
- const handleKeyDown = (e) => {
119
- if (e.key === "Escape") onClose();
120
- else if (e.key === "ArrowDown") {
121
- e.preventDefault();
122
- setSelectedIndex((prev) => Math.min(prev + 1, results.length - 1));
123
- } else if (e.key === "ArrowUp") {
124
- e.preventDefault();
125
- setSelectedIndex((prev) => Math.max(prev - 1, 0));
126
- } else if (e.key === "Enter") {
127
- e.preventDefault();
128
- if (results[selectedIndex]) handleResultClick(results[selectedIndex]);
129
- }
130
- };
131
- document.addEventListener("keydown", handleKeyDown);
132
- return () => document.removeEventListener("keydown", handleKeyDown);
133
- }, [
134
- results,
135
- selectedIndex,
136
- onClose
137
- ]);
138
- useEffect(() => {
139
- if (!query.trim()) {
140
- setResults([]);
141
- setSelectedIndex(0);
142
- return;
143
- }
144
- const searchResults = performSearch(query);
145
- setResults(searchResults);
146
- setSelectedIndex(0);
147
- }, [query, componentRegistry]);
148
- const performSearch = (searchQuery) => {
149
- const results$1 = [];
150
- const lowerQuery = searchQuery.toLowerCase();
151
- const componentIds = componentRegistry.getComponentIds();
152
- componentIds.forEach((componentId) => {
153
- const componentConfig = componentRegistry.getComponent(componentId);
154
- const label = componentConfig?.label || componentId;
155
- const description = componentConfig?.description || "";
156
- if (label.toLowerCase().includes(lowerQuery) || description.toLowerCase().includes(lowerQuery) || componentId.toLowerCase().includes(lowerQuery)) results$1.push({
157
- type: "component",
158
- id: componentId,
159
- title: label,
160
- description,
161
- path: `/${componentId}`,
162
- score: calculateScore(lowerQuery, label, description)
163
- });
164
- const demos = componentRegistry.getDemos(componentId);
165
- demos.forEach((demo, demoSource) => {
166
- const demoTitle = demo.title || demoSource;
167
- const demoDesc = demo.desc || "";
168
- if (demoTitle.toLowerCase().includes(lowerQuery) || demoDesc.toLowerCase().includes(lowerQuery)) results$1.push({
169
- type: "demo",
170
- id: `${componentId}-${demoSource}`,
171
- title: `${label} - ${demoTitle}`,
172
- description: demoDesc,
173
- path: `/${componentId}`,
174
- anchor: `demo-${demoSource}`,
175
- score: calculateScore(lowerQuery, demoTitle, demoDesc)
176
- });
177
- });
178
- const apis = componentRegistry.getApis(componentId);
179
- apis.forEach((api, apiKey) => {
180
- const apiTitle = api.title || apiKey;
181
- if (apiTitle.toLowerCase().includes(lowerQuery)) results$1.push({
182
- type: "api",
183
- id: `${componentId}-${apiKey}`,
184
- title: `${label} - ${apiTitle}`,
185
- description: "API文档",
186
- path: `/${componentId}`,
187
- anchor: `api-${apiKey}`,
188
- score: calculateScore(lowerQuery, apiTitle, "")
189
- });
190
- });
191
- });
192
- return results$1.sort((a, b) => b.score - a.score).slice(0, 10);
193
- };
194
- const calculateScore = (query$1, title, description) => {
195
- let score = 0;
196
- const lowerTitle = title.toLowerCase();
197
- const lowerDesc = description.toLowerCase();
198
- if (lowerTitle === query$1) score += 100;
199
- else if (lowerTitle.startsWith(query$1)) score += 50;
200
- else if (lowerTitle.includes(query$1)) score += 25;
201
- if (lowerDesc.includes(query$1)) score += 10;
202
- return score;
203
- };
204
- const handleResultClick = (result) => {
205
- if (onNavigate) {
206
- onNavigate(result.path);
207
- if (result.anchor) setTimeout(() => {
208
- const element = document.getElementById(result.anchor);
209
- if (element) element.scrollIntoView({ behavior: "smooth" });
210
- }, 100);
211
- }
212
- onClose();
213
- };
214
- const handleOverlayClick = (e) => {
215
- if (e.target === overlayRef.current) onClose();
216
- };
217
- const getResultIcon = (type) => {
218
- switch (type) {
219
- case "component": return "📦";
220
- case "demo": return "🎯";
221
- case "api": return "📋";
222
- default: return "📄";
223
- }
224
- };
225
- const highlightText = (text, query$1) => {
226
- if (!query$1) return text;
227
- const regex = new RegExp(`(${query$1})`, "gi");
228
- const parts = text.split(regex);
229
- return parts.map((part, index) => regex.test(part) ? /* @__PURE__ */ jsx("mark", {
230
- className: "doc-search-highlight",
231
- children: part
232
- }, index) : part);
233
- };
234
- return /* @__PURE__ */ jsx("div", {
235
- className: "doc-search-overlay",
236
- ref: overlayRef,
237
- onClick: handleOverlayClick,
238
- children: /* @__PURE__ */ jsxs("div", {
239
- className: "doc-search-modal",
240
- children: [
241
- /* @__PURE__ */ jsxs("div", {
242
- className: "doc-search-input-container",
243
- children: [/* @__PURE__ */ jsx("input", {
244
- ref: inputRef,
245
- type: "text",
246
- className: "doc-search-input",
247
- placeholder: config.placeholder || "搜索文档...",
248
- value: query,
249
- onChange: (e) => setQuery(e.target.value)
250
- }), /* @__PURE__ */ jsx("button", {
251
- className: "doc-search-close",
252
- onClick: onClose,
253
- title: "关闭搜索",
254
- children: "✕"
255
- })]
256
- }),
257
- results.length > 0 && /* @__PURE__ */ jsx("div", {
258
- className: "doc-search-results",
259
- children: results.map((result, index) => /* @__PURE__ */ jsxs("div", {
260
- className: `doc-search-result ${index === selectedIndex ? "selected" : ""}`,
261
- onClick: () => handleResultClick(result),
262
- children: [
263
- /* @__PURE__ */ jsx("div", {
264
- className: "doc-search-result-icon",
265
- children: getResultIcon(result.type)
266
- }),
267
- /* @__PURE__ */ jsxs("div", {
268
- className: "doc-search-result-content",
269
- children: [/* @__PURE__ */ jsx("div", {
270
- className: "doc-search-result-title",
271
- children: highlightText(result.title, query)
272
- }), result.description && /* @__PURE__ */ jsx("div", {
273
- className: "doc-search-result-description",
274
- children: highlightText(result.description, query)
275
- })]
276
- }),
277
- /* @__PURE__ */ jsx("div", {
278
- className: "doc-search-result-type",
279
- children: result.type
280
- })
281
- ]
282
- }, result.id))
283
- }),
284
- query && results.length === 0 && /* @__PURE__ */ jsx("div", {
285
- className: "doc-search-no-results",
286
- children: /* @__PURE__ */ jsx("p", { children: "未找到相关结果" })
287
- }),
288
- /* @__PURE__ */ jsx("div", {
289
- className: "doc-search-footer",
290
- children: /* @__PURE__ */ jsxs("div", {
291
- className: "doc-search-shortcuts",
292
- children: [
293
- /* @__PURE__ */ jsxs("span", { children: [
294
- /* @__PURE__ */ jsx("kbd", { children: "↑" }),
295
- /* @__PURE__ */ jsx("kbd", { children: "↓" }),
296
- " 导航"
297
- ] }),
298
- /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("kbd", { children: "Enter" }), " 选择"] }),
299
- /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("kbd", { children: "Esc" }), " 关闭"] })
300
- ]
301
- })
302
- })
303
- ]
304
- })
305
- });
306
- };
307
- var Search_default = Search;
308
-
309
108
  //#endregion
310
109
  //#region src/components/Header.tsx
311
110
  const Header = ({ config, theme, currentRoute, sidebarCollapsed, onSidebarToggle, showNavigation = false, componentRegistry, onNavigate }) => {
312
- const [searchVisible, setSearchVisible] = useState(false);
313
111
  const headerConfig = config.layout?.header || {};
314
- const searchConfig = config.search || {};
315
- const handleSearchToggle = () => {
316
- setSearchVisible(!searchVisible);
317
- };
318
- const handleSearchClose = () => {
319
- setSearchVisible(false);
320
- };
321
112
  const renderLogo = () => {
322
113
  if (!headerConfig.showLogo) return null;
323
114
  return /* @__PURE__ */ jsx("div", {
@@ -373,37 +164,28 @@ const Header = ({ config, theme, currentRoute, sidebarCollapsed, onSidebarToggle
373
164
  const renderActions = () => {
374
165
  return /* @__PURE__ */ jsxs("div", {
375
166
  className: "doc-header-actions",
376
- children: [
377
- searchConfig.enabled && headerConfig.showSearch && /* @__PURE__ */ jsx("button", {
378
- className: "doc-header-action doc-header-search-button",
379
- onClick: handleSearchToggle,
380
- title: `搜索 (${searchConfig.hotkey || "Ctrl+K"})`,
381
- children: "🔍"
382
- }),
383
- onSidebarToggle && /* @__PURE__ */ jsx("button", {
384
- className: "doc-header-action doc-header-sidebar-toggle",
385
- onClick: onSidebarToggle,
386
- title: sidebarCollapsed ? "展开侧边栏" : "收起侧边栏",
387
- children: sidebarCollapsed ? "" : "✕"
388
- }),
389
- config.github && /* @__PURE__ */ jsx("a", {
390
- className: "doc-header-action doc-header-github",
391
- href: config.github,
392
- target: "_blank",
393
- rel: "noopener noreferrer",
394
- title: "GitHub",
395
- children: /* @__PURE__ */ jsx("svg", {
396
- width: "20",
397
- height: "20",
398
- viewBox: "0 0 24 24",
399
- fill: "currentColor",
400
- children: /* @__PURE__ */ jsx("path", { d: "M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" })
401
- })
167
+ children: [onSidebarToggle && /* @__PURE__ */ jsx("button", {
168
+ className: "doc-header-action doc-header-sidebar-toggle",
169
+ onClick: onSidebarToggle,
170
+ title: sidebarCollapsed ? "展开侧边栏" : "收起侧边栏",
171
+ children: sidebarCollapsed ? "☰" : ""
172
+ }), config.github && /* @__PURE__ */ jsx("a", {
173
+ className: "doc-header-action doc-header-github",
174
+ href: config.github,
175
+ target: "_blank",
176
+ rel: "noopener noreferrer",
177
+ title: "GitHub",
178
+ children: /* @__PURE__ */ jsx("svg", {
179
+ width: "20",
180
+ height: "20",
181
+ viewBox: "0 0 24 24",
182
+ fill: "currentColor",
183
+ children: /* @__PURE__ */ jsx("path", { d: "M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" })
402
184
  })
403
- ]
185
+ })]
404
186
  });
405
187
  };
406
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("header", {
188
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("header", {
407
189
  className: "doc-header",
408
190
  children: /* @__PURE__ */ jsxs("div", {
409
191
  className: "doc-header-content",
@@ -419,12 +201,7 @@ const Header = ({ config, theme, currentRoute, sidebarCollapsed, onSidebarToggle
419
201
  })
420
202
  ]
421
203
  })
422
- }), searchVisible && searchConfig.enabled && /* @__PURE__ */ jsx(Search_default, {
423
- config: searchConfig,
424
- componentRegistry,
425
- onClose: handleSearchClose,
426
- onNavigate
427
- })] });
204
+ }) });
428
205
  };
429
206
  var Header_default = Header;
430
207
 
@@ -1030,7 +807,7 @@ const Footer = ({ config, theme }) => {
1030
807
  return /* @__PURE__ */ jsxs("div", {
1031
808
  className: "doc-footer-powered",
1032
809
  children: ["Powered by ", /* @__PURE__ */ jsx("a", {
1033
- href: "https://github.com/your-org/doc-sdk",
810
+ href: "https://github.com/Sunny-117/doc-render-sdk",
1034
811
  target: "_blank",
1035
812
  rel: "noopener noreferrer",
1036
813
  children: "Doc SDK"
@@ -1212,6 +989,11 @@ var Layout_default = Layout;
1212
989
  * 负责管理文档站点的路由系统
1213
990
  */
1214
991
  var RouterManager = class {
992
+ renderer;
993
+ currentRoute;
994
+ routes;
995
+ listeners;
996
+ isInitialized;
1215
997
  constructor(renderer) {
1216
998
  this.renderer = renderer;
1217
999
  this.currentRoute = null;
@@ -1503,7 +1285,6 @@ var ComponentRegistry = class {
1503
1285
  console.log(globalApiData, "globalApiData");
1504
1286
  if (globalApiData) return globalApiData;
1505
1287
  const apiPath = `../components/${componentId}/api`;
1506
- console.log(apiPath, "apiPath");
1507
1288
  const module = await import(apiPath);
1508
1289
  const apiData = module.default || module;
1509
1290
  return apiData[api.apiKey] || [];
@@ -1714,93 +1495,12 @@ const defaultConfig = {
1714
1495
  type: "sidebar",
1715
1496
  sidebar: {
1716
1497
  width: 280,
1717
- collapsible: true,
1718
- defaultCollapsed: false
1719
- },
1720
- header: {
1721
- height: 64,
1722
- showLogo: true,
1723
- showTitle: true,
1724
- showSearch: true
1498
+ collapsible: true
1725
1499
  },
1726
- content: {
1727
- maxWidth: 1200,
1728
- padding: 24
1729
- },
1730
- footer: {
1731
- show: true,
1732
- height: 60
1733
- }
1500
+ header: { height: 64 }
1734
1501
  },
1735
1502
  components: {},
1736
- navigation: {
1737
- mode: "auto",
1738
- groups: [],
1739
- showHome: true,
1740
- homeTitle: "首页"
1741
- },
1742
- search: {
1743
- enabled: true,
1744
- placeholder: "搜索文档...",
1745
- hotkey: "ctrl+k"
1746
- },
1747
- highlight: {
1748
- theme: "github",
1749
- languages: [
1750
- "javascript",
1751
- "jsx",
1752
- "typescript",
1753
- "tsx",
1754
- "css",
1755
- "less",
1756
- "scss",
1757
- "html",
1758
- "json"
1759
- ]
1760
- },
1761
- demo: {
1762
- showCode: true,
1763
- codeCollapsed: true,
1764
- showCopyButton: true,
1765
- showExpandButton: true
1766
- },
1767
- api: {
1768
- showRequired: true,
1769
- showType: true,
1770
- showDefault: true,
1771
- showDescription: true
1772
- },
1773
- plugins: [],
1774
- dev: {
1775
- hot: true,
1776
- port: 8080,
1777
- host: "localhost",
1778
- open: true
1779
- },
1780
- build: {
1781
- outDir: "dist",
1782
- publicPath: "/",
1783
- sourcemap: false,
1784
- minify: true
1785
- },
1786
- router: {
1787
- mode: "hash",
1788
- base: "/"
1789
- },
1790
- i18n: {
1791
- enabled: false,
1792
- defaultLocale: "zh-CN",
1793
- locales: ["zh-CN", "en-US"]
1794
- },
1795
- seo: {
1796
- keywords: [],
1797
- author: "",
1798
- favicon: ""
1799
- },
1800
- analytics: {
1801
- enabled: false,
1802
- providers: []
1803
- }
1503
+ plugins: []
1804
1504
  };
1805
1505
  var default_default$1 = defaultConfig;
1806
1506
 
@@ -1830,14 +1530,14 @@ var ConfigManager = class {
1830
1530
  */
1831
1531
  get(path, defaultValue) {
1832
1532
  if (!path) return this.getConfig();
1833
- return get$1(this.config, path, defaultValue);
1533
+ return get(this.config, path, defaultValue);
1834
1534
  }
1835
1535
  /**
1836
1536
  * 设置配置项
1837
1537
  */
1838
1538
  set(path, value) {
1839
1539
  const oldValue = this.get(path);
1840
- set$1(this.config, path, value);
1540
+ set(this.config, path, value);
1841
1541
  this.notifyChange(path, value, oldValue);
1842
1542
  }
1843
1543
  /**
@@ -2472,150 +2172,6 @@ var default_default = {
2472
2172
  background: var(--doc-color-backgroundSecondary);
2473
2173
  border-radius: var(--doc-layout-borderRadius);
2474
2174
  }
2475
- `,
2476
- search: `
2477
- .doc-search-overlay {
2478
- position: fixed;
2479
- top: 0;
2480
- left: 0;
2481
- right: 0;
2482
- bottom: 0;
2483
- background: rgba(0, 0, 0, 0.5);
2484
- z-index: 1000;
2485
- display: flex;
2486
- align-items: flex-start;
2487
- justify-content: center;
2488
- padding-top: 10vh;
2489
- }
2490
-
2491
- .doc-search-modal {
2492
- background: var(--doc-color-background);
2493
- border-radius: var(--doc-layout-borderRadius);
2494
- box-shadow: var(--doc-layout-boxShadow);
2495
- width: 90%;
2496
- max-width: 600px;
2497
- max-height: 70vh;
2498
- overflow: hidden;
2499
- display: flex;
2500
- flex-direction: column;
2501
- }
2502
-
2503
- .doc-search-input-container {
2504
- display: flex;
2505
- align-items: center;
2506
- padding: var(--doc-spacing-lg);
2507
- border-bottom: 1px solid var(--doc-color-border);
2508
- }
2509
-
2510
- .doc-search-input {
2511
- flex: 1;
2512
- border: none;
2513
- outline: none;
2514
- font-size: var(--doc-typography-fontSize-lg);
2515
- background: transparent;
2516
- color: var(--doc-color-text);
2517
- }
2518
-
2519
- .doc-search-input::placeholder {
2520
- color: var(--doc-color-textTertiary);
2521
- }
2522
-
2523
- .doc-search-close {
2524
- background: none;
2525
- border: none;
2526
- color: var(--doc-color-textSecondary);
2527
- cursor: pointer;
2528
- padding: var(--doc-spacing-sm);
2529
- border-radius: var(--doc-layout-borderRadius);
2530
- transition: all 0.2s ease;
2531
- }
2532
-
2533
- .doc-search-close:hover {
2534
- background: var(--doc-color-backgroundTertiary);
2535
- color: var(--doc-color-text);
2536
- }
2537
-
2538
- .doc-search-results {
2539
- flex: 1;
2540
- overflow-y: auto;
2541
- max-height: 400px;
2542
- }
2543
-
2544
- .doc-search-result {
2545
- display: flex;
2546
- align-items: center;
2547
- padding: var(--doc-spacing-md) var(--doc-spacing-lg);
2548
- cursor: pointer;
2549
- border-bottom: 1px solid var(--doc-color-borderSecondary);
2550
- transition: background 0.2s ease;
2551
- }
2552
-
2553
- .doc-search-result:hover,
2554
- .doc-search-result.selected {
2555
- background: var(--doc-color-backgroundSecondary);
2556
- }
2557
-
2558
- .doc-search-result-icon {
2559
- margin-right: var(--doc-spacing-md);
2560
- font-size: var(--doc-typography-fontSize-lg);
2561
- }
2562
-
2563
- .doc-search-result-content {
2564
- flex: 1;
2565
- }
2566
-
2567
- .doc-search-result-title {
2568
- font-weight: var(--doc-typography-fontWeight-medium);
2569
- color: var(--doc-color-text);
2570
- margin-bottom: 2px;
2571
- }
2572
-
2573
- .doc-search-result-description {
2574
- font-size: var(--doc-typography-fontSize-sm);
2575
- color: var(--doc-color-textSecondary);
2576
- }
2577
-
2578
- .doc-search-result-type {
2579
- font-size: var(--doc-typography-fontSize-xs);
2580
- color: var(--doc-color-textTertiary);
2581
- text-transform: uppercase;
2582
- letter-spacing: 0.5px;
2583
- }
2584
-
2585
- .doc-search-highlight {
2586
- background: var(--doc-color-warning);
2587
- color: var(--doc-color-background);
2588
- padding: 1px 2px;
2589
- border-radius: 2px;
2590
- }
2591
-
2592
- .doc-search-no-results {
2593
- padding: var(--doc-spacing-xl);
2594
- text-align: center;
2595
- color: var(--doc-color-textSecondary);
2596
- }
2597
-
2598
- .doc-search-footer {
2599
- padding: var(--doc-spacing-md) var(--doc-spacing-lg);
2600
- border-top: 1px solid var(--doc-color-border);
2601
- background: var(--doc-color-backgroundTertiary);
2602
- }
2603
-
2604
- .doc-search-shortcuts {
2605
- display: flex;
2606
- gap: var(--doc-spacing-md);
2607
- font-size: var(--doc-typography-fontSize-xs);
2608
- color: var(--doc-color-textTertiary);
2609
- }
2610
-
2611
- .doc-search-shortcuts kbd {
2612
- background: var(--doc-color-backgroundSecondary);
2613
- border: 1px solid var(--doc-color-border);
2614
- border-radius: 3px;
2615
- padding: 2px 4px;
2616
- font-family: var(--doc-typography-fontFamilyCode);
2617
- font-size: 0.9em;
2618
- }
2619
2175
  `,
2620
2176
  home: `
2621
2177
  .doc-home {
@@ -2846,7 +2402,7 @@ var ThemeManager = class {
2846
2402
  const cssVariables = this.generateCSSVariables();
2847
2403
  const themeStyles = this.generateThemeStyles();
2848
2404
  this.styleElement = document.createElement("style");
2849
- this.styleElement.setAttribute("data-doc-sdk-theme", "true");
2405
+ this.styleElement.setAttribute("data-doc-render-sdk-theme", "true");
2850
2406
  this.styleElement.textContent = `
2851
2407
  :root {
2852
2408
  ${cssVariables}
@@ -2891,7 +2447,7 @@ var ThemeManager = class {
2891
2447
  const { components } = this.currentTheme;
2892
2448
  const styles = [];
2893
2449
  styles.push(`
2894
- .doc-sdk-container {
2450
+ .doc-render-sdk-container {
2895
2451
  font-family: var(--doc-typography-fontFamily, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
2896
2452
  font-size: var(--doc-typography-fontSize, 14px);
2897
2453
  line-height: var(--doc-typography-lineHeight, 1.5);
@@ -3219,232 +2775,6 @@ var PluginManager = class {
3219
2775
  }
3220
2776
  };
3221
2777
 
3222
- //#endregion
3223
- //#region src/utils/index.ts
3224
- /**
3225
- * 工具函数
3226
- */
3227
- /**
3228
- * 转换样式化文本
3229
- * @param {string} str - 原始字符串
3230
- * @param {boolean} flag - 是否启用样式化
3231
- * @returns {string} 处理后的字符串
3232
- */
3233
- const transToStyledText = (str, flag = true) => {
3234
- if (!flag || typeof str !== "string") return str;
3235
- return str.replace(/{/g, "<span class=\"doc-highlight\">").replace(/}/g, "</span>");
3236
- };
3237
- /**
3238
- * 解析查询参数
3239
- * @param {string} query - 查询字符串
3240
- * @returns {Object} 参数对象
3241
- */
3242
- const parseQuery = (query) => {
3243
- const params = {};
3244
- if (!query) return params;
3245
- const reg = /([^=&\s]+)[=\s]*([^=&\s]*)/g;
3246
- let match;
3247
- while ((match = reg.exec(query)) !== null) params[match[1]] = match[2];
3248
- return params;
3249
- };
3250
- /**
3251
- * 序列化查询参数
3252
- * @param {Object} obj - 参数对象
3253
- * @returns {string} 查询字符串
3254
- */
3255
- const stringifyQuery = (obj) => {
3256
- if (!obj || typeof obj !== "object") return "";
3257
- const params = [];
3258
- Object.keys(obj).forEach((key) => {
3259
- if (obj.hasOwnProperty(key) && obj[key] !== void 0 && obj[key] !== null) params.push(`${key}=${obj[key]}`);
3260
- });
3261
- return params.join("&");
3262
- };
3263
- /**
3264
- * 防抖函数
3265
- * @param {Function} func - 要防抖的函数
3266
- * @param {number} wait - 等待时间
3267
- * @param {boolean} immediate - 是否立即执行
3268
- * @returns {Function} 防抖后的函数
3269
- */
3270
- const debounce = (func, wait, immediate = false) => {
3271
- let timeout;
3272
- return function executedFunction(...args) {
3273
- const later = () => {
3274
- timeout = null;
3275
- if (!immediate) func.apply(this, args);
3276
- };
3277
- const callNow = immediate && !timeout;
3278
- clearTimeout(timeout);
3279
- timeout = setTimeout(later, wait);
3280
- if (callNow) func.apply(this, args);
3281
- };
3282
- };
3283
- /**
3284
- * 节流函数
3285
- * @param {Function} func - 要节流的函数
3286
- * @param {number} limit - 时间限制
3287
- * @returns {Function} 节流后的函数
3288
- */
3289
- const throttle = (func, limit) => {
3290
- let inThrottle;
3291
- return function(...args) {
3292
- if (!inThrottle) {
3293
- func.apply(this, args);
3294
- inThrottle = true;
3295
- setTimeout(() => inThrottle = false, limit);
3296
- }
3297
- };
3298
- };
3299
- /**
3300
- * 深度合并对象
3301
- * @param {Object} target - 目标对象
3302
- * @param {...Object} sources - 源对象
3303
- * @returns {Object} 合并后的对象
3304
- */
3305
- const deepMerge = (target, ...sources) => {
3306
- if (!sources.length) return target;
3307
- const source = sources.shift();
3308
- if (isObject(target) && isObject(source)) for (const key in source) if (isObject(source[key])) {
3309
- if (!target[key]) Object.assign(target, { [key]: {} });
3310
- deepMerge(target[key], source[key]);
3311
- } else Object.assign(target, { [key]: source[key] });
3312
- return deepMerge(target, ...sources);
3313
- };
3314
- /**
3315
- * 判断是否为对象
3316
- * @param {*} item - 要判断的项
3317
- * @returns {boolean} 是否为对象
3318
- */
3319
- const isObject = (item) => {
3320
- return item && typeof item === "object" && !Array.isArray(item);
3321
- };
3322
- /**
3323
- * 获取嵌套对象的值
3324
- * @param {Object} obj - 对象
3325
- * @param {string} path - 路径,用点分隔
3326
- * @param {*} defaultValue - 默认值
3327
- * @returns {*} 值
3328
- */
3329
- const get = (obj, path, defaultValue) => {
3330
- if (!obj || !path) return defaultValue;
3331
- const keys = path.split(".");
3332
- let result = obj;
3333
- for (const key of keys) {
3334
- if (result == null || typeof result !== "object") return defaultValue;
3335
- result = result[key];
3336
- }
3337
- return result !== void 0 ? result : defaultValue;
3338
- };
3339
- /**
3340
- * 设置嵌套对象的值
3341
- * @param {Object} obj - 对象
3342
- * @param {string} path - 路径,用点分隔
3343
- * @param {*} value - 值
3344
- */
3345
- const set = (obj, path, value) => {
3346
- if (!obj || !path) return;
3347
- const keys = path.split(".");
3348
- const lastKey = keys.pop();
3349
- let current = obj;
3350
- for (const key of keys) {
3351
- if (!(key in current) || typeof current[key] !== "object") current[key] = {};
3352
- current = current[key];
3353
- }
3354
- current[lastKey] = value;
3355
- };
3356
- /**
3357
- * 生成唯一ID
3358
- * @param {string} prefix - 前缀
3359
- * @returns {string} 唯一ID
3360
- */
3361
- const generateId = (prefix = "id") => {
3362
- return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
3363
- };
3364
- /**
3365
- * 格式化文件大小
3366
- * @param {number} bytes - 字节数
3367
- * @param {number} decimals - 小数位数
3368
- * @returns {string} 格式化后的大小
3369
- */
3370
- const formatFileSize = (bytes, decimals = 2) => {
3371
- if (bytes === 0) return "0 Bytes";
3372
- const k = 1024;
3373
- const dm = decimals < 0 ? 0 : decimals;
3374
- const sizes = [
3375
- "Bytes",
3376
- "KB",
3377
- "MB",
3378
- "GB",
3379
- "TB",
3380
- "PB",
3381
- "EB",
3382
- "ZB",
3383
- "YB"
3384
- ];
3385
- const i = Math.floor(Math.log(bytes) / Math.log(k));
3386
- return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
3387
- };
3388
- /**
3389
- * 复制文本到剪贴板
3390
- * @param {string} text - 要复制的文本
3391
- * @returns {Promise<boolean>} 是否成功
3392
- */
3393
- const copyToClipboard = async (text) => {
3394
- try {
3395
- if (navigator.clipboard && window.isSecureContext) {
3396
- await navigator.clipboard.writeText(text);
3397
- return true;
3398
- } else {
3399
- const textArea = document.createElement("textarea");
3400
- textArea.value = text;
3401
- textArea.style.position = "fixed";
3402
- textArea.style.left = "-999999px";
3403
- textArea.style.top = "-999999px";
3404
- document.body.appendChild(textArea);
3405
- textArea.focus();
3406
- textArea.select();
3407
- const result = document.execCommand("copy");
3408
- document.body.removeChild(textArea);
3409
- return result;
3410
- }
3411
- } catch (error) {
3412
- console.error("Failed to copy text:", error);
3413
- return false;
3414
- }
3415
- };
3416
- /**
3417
- * 滚动到元素
3418
- * @param {string|HTMLElement} element - 元素或选择器
3419
- * @param {Object} options - 滚动选项
3420
- */
3421
- const scrollToElement = (element, options = {}) => {
3422
- const target = typeof element === "string" ? document.querySelector(element) : element;
3423
- if (!target) return;
3424
- const defaultOptions = {
3425
- behavior: "smooth",
3426
- block: "start",
3427
- inline: "nearest"
3428
- };
3429
- target.scrollIntoView({
3430
- ...defaultOptions,
3431
- ...options
3432
- });
3433
- };
3434
- /**
3435
- * 检查元素是否在视口中
3436
- * @param {HTMLElement} element - 元素
3437
- * @param {number} threshold - 阈值
3438
- * @returns {boolean} 是否在视口中
3439
- */
3440
- const isElementInViewport = (element, threshold = 0) => {
3441
- if (!element) return false;
3442
- const rect = element.getBoundingClientRect();
3443
- const windowHeight = window.innerHeight || document.documentElement.clientHeight;
3444
- const windowWidth = window.innerWidth || document.documentElement.clientWidth;
3445
- return rect.top >= -threshold && rect.left >= -threshold && rect.bottom <= windowHeight + threshold && rect.right <= windowWidth + threshold;
3446
- };
3447
-
3448
2778
  //#endregion
3449
2779
  //#region src/index.ts
3450
2780
  var DocSDK = class {
@@ -3516,4 +2846,5 @@ var DocSDK = class {
3516
2846
  };
3517
2847
 
3518
2848
  //#endregion
3519
- export { ApiDoc_default as ApiDoc, CodeBlock_default as CodeBlock, ConfigManager, Demo_default as Demo, DocRenderer, Layout_default as Layout, Navigation_default as Navigation, PluginManager, ThemeManager, copyToClipboard, debounce, deepMerge, DocSDK as default, formatFileSize, generateId, get, isElementInViewport, isObject, parseQuery, scrollToElement, set, stringifyQuery, throttle, transToStyledText };
2849
+ export { ApiDoc_default as ApiDoc, CodeBlock_default as CodeBlock, ConfigManager, Demo_default as Demo, DocRenderer, Layout_default as Layout, Navigation_default as Navigation, PluginManager, ThemeManager, DocSDK as default };
2850
+ //# sourceMappingURL=index.mjs.map