@heikeson/md-engine 0.4.0 → 0.5.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 (46) hide show
  1. package/README.md +49 -3
  2. package/dist/{chunk-V7T7I5HE.js → chunk-KC6CBSFU.js} +64 -16
  3. package/dist/chunk-KC6CBSFU.js.map +1 -0
  4. package/dist/chunk-OG47YL3H.js +68 -0
  5. package/dist/chunk-OG47YL3H.js.map +1 -0
  6. package/dist/chunk-OJQDOFGL.js +313 -0
  7. package/dist/chunk-OJQDOFGL.js.map +1 -0
  8. package/dist/{chunk-7RXVCGFM.js → chunk-USP2GQZF.js} +115 -15
  9. package/dist/chunk-USP2GQZF.js.map +1 -0
  10. package/dist/chunk-YJGGJP2V.js +68 -0
  11. package/dist/chunk-YJGGJP2V.js.map +1 -0
  12. package/dist/components/index.d.ts +3 -3
  13. package/dist/components/index.js +4 -1
  14. package/dist/editor/index.d.ts +20 -3
  15. package/dist/editor/index.js +106 -44
  16. package/dist/editor/index.js.map +1 -1
  17. package/dist/index.d.ts +128 -6
  18. package/dist/index.js +6 -3
  19. package/dist/index.js.map +1 -1
  20. package/dist/locales/en-US.d.ts +68 -0
  21. package/dist/locales/en-US.js +3 -0
  22. package/dist/locales/en-US.js.map +1 -0
  23. package/dist/locales/zh-CN.d.ts +68 -0
  24. package/dist/locales/zh-CN.js +3 -0
  25. package/dist/locales/zh-CN.js.map +1 -0
  26. package/dist/mermaid/index.d.ts +3 -1
  27. package/dist/mermaid/index.js +46 -16
  28. package/dist/mermaid/index.js.map +1 -1
  29. package/dist/{mermaid-placeholder-A1N4puyc.d.ts → mermaid-placeholder-DYfFG3_f.d.ts} +1 -0
  30. package/dist/render-DbUepYgE.d.ts +247 -0
  31. package/dist/styles.css +1 -1
  32. package/package.json +18 -4
  33. package/styles/accordion.css +1 -1
  34. package/styles/callout.css +2 -2
  35. package/styles/cards.css +9 -1
  36. package/styles/editor.css +1 -1
  37. package/styles/files.css +12 -5
  38. package/styles/image.css +5 -5
  39. package/styles/index.css +1 -0
  40. package/styles/mermaid.css +1 -1
  41. package/styles/steps.css +1 -1
  42. package/styles/type-table.css +2 -2
  43. package//345/257/271/346/216/245/345/245/221/347/272/246.md +20 -1
  44. package/dist/chunk-7RXVCGFM.js.map +0 -1
  45. package/dist/chunk-V7T7I5HE.js.map +0 -1
  46. package/dist/render-C5-vIUuK.d.ts +0 -44
package/dist/index.d.ts CHANGED
@@ -3,9 +3,12 @@ import { Parent, RootContent, Data, Root } from 'mdast';
3
3
  import { Extension } from 'mdast-util-from-markdown';
4
4
  import { Options } from 'mdast-util-to-markdown';
5
5
  import { Processor } from 'unified';
6
- export { M as MarkdownRenderer, a as MarkdownRendererProps, R as RenderConfig } from './render-C5-vIUuK.js';
6
+ import { a as UIText } from './render-DbUepYgE.js';
7
+ export { B as BUILTIN_LOCALES, D as DEFAULT_LOCALE_STORAGE_KEY, L as LocaleStorage, b as LocaleStorageOptions, M as MarkdownRenderer, c as MarkdownRendererProps, d as MdEngineProvider, e as MdEngineProviderProps, R as RenderConfig, T as TextDirection, U as UITextPatch, f as createLocaleStorage, g as defaultUIText, m as mergeUIText, u as useLocale, h as useMessage, i as useUIText } from './render-DbUepYgE.js';
7
8
  export { mdxComponents } from './components/index.js';
8
- export { M as MermaidPlaceholder, a as MermaidProps } from './mermaid-placeholder-A1N4puyc.js';
9
+ export { zhCN } from './locales/zh-CN.js';
10
+ export { enUS } from './locales/en-US.js';
11
+ export { M as MermaidPlaceholder, a as MermaidProps } from './mermaid-placeholder-DYfFG3_f.js';
9
12
  import 'react';
10
13
 
11
14
  /**
@@ -231,18 +234,26 @@ declare function remarkJsxBlocks(this: Processor): undefined;
231
234
  * @updated 2026-11-01 21:47 新增 MERMAID_EMPTY / MERMAID_TOO_LARGE 诊断与 MERMAID_MAX_BYTES
232
235
  */
233
236
 
234
- /** 诊断码 */
235
- type DiagnosticCode = "UNCLOSED_TAG" | "DEPTH_EXCEEDED" | "UNKNOWN_TAG" | "UNSAFE_HREF" | "INDENT_AS_CODE" | "MERMAID_EMPTY" | "MERMAID_TOO_LARGE";
237
+ /**
238
+ * 诊断码
239
+ * @description 一个 code 对应一条消息(展示层映射 `diag*` 文案键),因此不设「一码两用」。
240
+ */
241
+ type DiagnosticCode = "UNCLOSED_TAG" | "DEPTH_EXCEEDED" | "UNKNOWN_TAG" | "UNSAFE_HREF" | "INDENT_AS_CODE" | "MERMAID_EMPTY" | "MERMAID_TOO_LARGE" | "DUPLICATE_ID_ANCHOR" | "DUPLICATE_ID_DIV"
242
+ /** @deprecated 已细分为 DUPLICATE_ID_ANCHOR / DUPLICATE_ID_DIV,不再产出 */
243
+ | "DUPLICATE_ID";
236
244
  /** Mermaid 源码体积上限(字节):超限不渲染图表,原样显示源码 */
237
245
  declare const MERMAID_MAX_BYTES: number;
238
246
  /** 一条诊断 */
239
247
  interface Diagnostic {
248
+ /** 诊断码,同时是文案键(`diag` + 驼峰) */
240
249
  code: DiagnosticCode;
241
250
  level: "warn" | "error";
242
251
  /** 行号(1 起) */
243
252
  line: number;
244
- /** 中文提示 */
253
+ /** 中文提示(兜底:无 Provider 或日志场景直接用;展示层应优先按 code 翻译) */
245
254
  message: string;
255
+ /** 文案插值参数(展示层据此重建本地化文本) */
256
+ params?: Record<string, string | number>;
246
257
  /** 全文 offset 区间 */
247
258
  range?: [number, number];
248
259
  }
@@ -384,4 +395,115 @@ declare function roundtrip(md: string): string;
384
395
  */
385
396
  declare function normalizeMarkdown(md: string): string;
386
397
 
387
- export { type Attrs, type Block, COMPONENTS, type ComponentMode, type ComponentSpec, type ContainerBlock, type ContainerItem, type Diagnostic, type DiagnosticCode, ITEMS, type ItemSpec, type JsxBlock, MAX_CONTAINER_DEPTH, MERMAID_MAX_BYTES, type ParseOptions, type ParseResult, type SourceBlock, type SourceReason, type VisualBlock, extractBlocks, getComponent, getItemSpec, isContainerWithItems, jsxBlocks, jsxFromMarkdown, jsxToMarkdown, listComponents, normalizeMarkdown, parse, parseOpenTag, remarkJsxBlocks, roundtrip, serialize, sliceRawBody };
398
+ /**
399
+ * @file 语言标识与消息格式化(纯函数,SSR 安全)
400
+ * @description 只做四件事:BCP-47 标识规范化与回退链、书写方向判定、ICU 消息格式化、
401
+ * 客户端语言探测工具。**不含任何全局可变状态**,不在模块顶层访问 window/navigator,
402
+ * 因此可在服务端渲染与并发请求中安全复用。
403
+ * @created 2026-11-02 19:32
404
+ * @updated 2026-11-02 19:32
405
+ */
406
+ /** 包内默认语言(与内置语言包保持一致) */
407
+ declare const DEFAULT_LOCALE = "zh-CN";
408
+ /**
409
+ * 规范化 BCP-47 标识:下划线转连字符,语言小写、地区大写、文字标题大小写
410
+ * @param input 原始标识,如 `zh_CN` / `en-us` / `zh-hans-cn`
411
+ * @returns 规范化标识;空输入返回空串
412
+ */
413
+ declare function normalizeLocale(input: string): string;
414
+ /**
415
+ * 取语言主标签(小写)
416
+ * @param locale 规范化或不规范的标识
417
+ * @returns 主标签,如 `zh-CN` → `zh`
418
+ */
419
+ declare function languageOf(locale: string): string;
420
+ /**
421
+ * 生成回退候选序列(由具体到泛化)
422
+ * @param locale 目标标识
423
+ * @returns 候选数组,如 `zh-Hans-CN` → `["zh-Hans-CN","zh-Hans","zh"]`
424
+ */
425
+ declare function localeCandidates(locale: string): string[];
426
+ /**
427
+ * 在可用语言集合里按回退链匹配
428
+ * @param locale 目标标识
429
+ * @param available 可用标识列表(可为内置语言包键)
430
+ * @returns 命中的可用标识(保持 available 里的原始写法);未命中返回 null
431
+ * @description 两段匹配:先按 `zh-Hans-CN → zh-Hans → zh` 精确回退,再做语言级近似
432
+ * (`en-GB → en-US` 这类同语言不同地区)。近似时若书写系统冲突(`zh-Hant` 对简体包)则放弃,
433
+ * 避免把繁体用户按简体渲染却自以为命中。
434
+ */
435
+ declare function matchLocale(locale: string, available: readonly string[]): string | null;
436
+ /**
437
+ * 从候选列表里挑第一个可用的语言(解析 Accept-Language 等场景)
438
+ * @param candidates 候选标识(按优先级)
439
+ * @param available 可用标识;省略时取候选里第一个有效值
440
+ * @returns 命中的标识;全部无效时返回默认语言
441
+ * @description 不在库内隐式调用,由宿主显式使用
442
+ */
443
+ declare function resolveLocale(candidates: readonly string[], available?: readonly string[]): string;
444
+ /**
445
+ * 客户端一次性语言探测:`html[lang]` → `navigator.languages` → 默认
446
+ * @param fallback 探测失败时的返回值
447
+ * @returns 语言标识
448
+ * @description **只能在 effect / 事件回调里调用**。服务端调用恒返回 fallback,
449
+ * 因此不可用于首屏渲染,否则服务端与客户端结果不一致会产生 hydration mismatch。
450
+ */
451
+ declare function detectLocale(fallback?: string): string;
452
+ /**
453
+ * 判断书写方向
454
+ * @param locale 语言标识
455
+ * @returns 是否从右到左
456
+ */
457
+ declare function isRTL(locale: string): boolean;
458
+ /**
459
+ * 语言标识 → URL 段
460
+ * @param locale 语言标识,如 `zh-CN`
461
+ * @returns URL 段,如 `zh`
462
+ */
463
+ declare function toRouteSegment(locale: string): string;
464
+ /**
465
+ * URL 段 → 语言标识(在可用集合里匹配)
466
+ * @param segment URL 段,如 `en`
467
+ * @param available 可用标识列表
468
+ * @returns 命中的标识;空段或未命中返回 null
469
+ */
470
+ declare function fromRouteSegment(segment: string, available: readonly string[]): string | null;
471
+ /**
472
+ * 判断运行环境是否提供该语言的 Intl 数据
473
+ * @param locale 语言标识
474
+ * @returns 是否支持
475
+ * @description 用于 Node small-icu 构建的降级判断:缺数据时复数规则会静默退化为 en。
476
+ */
477
+ declare function supportsIntlLocale(locale: string): boolean;
478
+ /**
479
+ * 按 ICU 语法格式化消息
480
+ * @param locale 语言标识(决定复数与数字格式)
481
+ * @param template ICU 消息模板,可含 `{name}` 插值与 `{n, plural, ...}`
482
+ * @param values 插值参数;省略且模板无占位符时直接返回模板
483
+ * @returns 格式化结果;语法错误或缺参时回退为模板原文,绝不抛错
484
+ */
485
+ declare function formatMessage(locale: string, template: string, values?: Record<string, string | number>): string;
486
+
487
+ /**
488
+ * @file 诊断文案映射
489
+ * @description 诊断码 → 文案键。领域层只产出 `code + params + 中文 message`,
490
+ * 人类可读文本在这里(表现层侧)生成:有对应文案键就用当前语言,没有就回退中文原文。
491
+ * @created 2026-11-02 19:32
492
+ * @updated 2026-11-02 19:32
493
+ */
494
+
495
+ /**
496
+ * 取诊断码对应的文案键
497
+ * @param code 诊断码
498
+ * @returns 文案键;未知码返回 null
499
+ */
500
+ declare function diagnosticTextKey(code: DiagnosticCode): keyof UIText | null;
501
+ /**
502
+ * 按当前语言渲染一条诊断
503
+ * @param t 消息格式化函数(`useMessage()` 的返回值)
504
+ * @param diagnostic 诊断记录
505
+ * @returns 本地化文本;无对应文案键或缺参时回退中文 `message`
506
+ */
507
+ declare function formatDiagnostic(t: (key: keyof UIText, values?: Record<string, string | number>) => string, diagnostic: Diagnostic): string;
508
+
509
+ export { type Attrs, type Block, COMPONENTS, type ComponentMode, type ComponentSpec, type ContainerBlock, type ContainerItem, DEFAULT_LOCALE, type Diagnostic, type DiagnosticCode, ITEMS, type ItemSpec, type JsxBlock, MAX_CONTAINER_DEPTH, MERMAID_MAX_BYTES, type ParseOptions, type ParseResult, type SourceBlock, type SourceReason, UIText, type VisualBlock, detectLocale, diagnosticTextKey, extractBlocks, formatDiagnostic, formatMessage, fromRouteSegment, getComponent, getItemSpec, isContainerWithItems, isRTL, jsxBlocks, jsxFromMarkdown, jsxToMarkdown, languageOf, listComponents, localeCandidates, matchLocale, normalizeLocale, normalizeMarkdown, parse, parseOpenTag, remarkJsxBlocks, resolveLocale, roundtrip, serialize, sliceRawBody, supportsIntlLocale, toRouteSegment };
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
- import { jsxToMarkdown, parse } from './chunk-7RXVCGFM.js';
2
- export { COMPONENTS, ITEMS, MAX_CONTAINER_DEPTH, MERMAID_MAX_BYTES, MarkdownRenderer, extractBlocks, getComponent, getItemSpec, isContainerWithItems, jsxBlocks, jsxFromMarkdown, jsxToMarkdown, listComponents, normalizeMarkdown, parse, parseOpenTag, remarkJsxBlocks, sliceRawBody } from './chunk-7RXVCGFM.js';
3
- export { MermaidPlaceholder, mdxComponents } from './chunk-V7T7I5HE.js';
1
+ import { jsxToMarkdown, parse } from './chunk-USP2GQZF.js';
2
+ export { COMPONENTS, ITEMS, MAX_CONTAINER_DEPTH, MERMAID_MAX_BYTES, MarkdownRenderer, diagnosticTextKey, extractBlocks, formatDiagnostic, getComponent, getItemSpec, isContainerWithItems, jsxBlocks, jsxFromMarkdown, jsxToMarkdown, listComponents, normalizeMarkdown, parse, parseOpenTag, remarkJsxBlocks, sliceRawBody } from './chunk-USP2GQZF.js';
3
+ export { MermaidPlaceholder, mdxComponents } from './chunk-KC6CBSFU.js';
4
+ export { BUILTIN_LOCALES, DEFAULT_LOCALE, DEFAULT_LOCALE_STORAGE_KEY, MdEngineProvider, createLocaleStorage, DEFAULT_UI_TEXT as defaultUIText, detectLocale, formatMessage, fromRouteSegment, isRTL, languageOf, localeCandidates, matchLocale, mergeUIText, normalizeLocale, resolveLocale, supportsIntlLocale, toRouteSegment, useLocale, useMessage, useUIText } from './chunk-OJQDOFGL.js';
5
+ export { zhCN } from './chunk-OG47YL3H.js';
6
+ export { enUS } from './chunk-YJGGJP2V.js';
4
7
  import { toMarkdown } from 'mdast-util-to-markdown';
5
8
  import { gfmToMarkdown } from 'mdast-util-gfm';
6
9
  import { mathToMarkdown } from 'mdast-util-math';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/serialize.ts"],"names":[],"mappings":";;;;;;;AAgBA,IAAM,OAAA,GAAU;AAAA,EACd,MAAA,EAAQ,GAAA;AAAA,EACR,QAAA,EAAU,GAAA;AAAA,EACV,MAAA,EAAQ,GAAA;AAAA,EACR,IAAA,EAAM,GAAA;AAAA,EACN,MAAA,EAAQ,IAAA;AAAA,EACR,cAAA,EAAgB;AAClB,CAAA;AAOO,SAAS,UAAU,IAAA,EAAoB;AAC5C,EAAA,OAAO,WAAW,IAAA,EAAM;AAAA,IACtB,GAAG,OAAA;AAAA;AAAA,IAEH,YAAY,CAAC,aAAA,IAAiB,cAAA,EAAe,EAAG,eAAe;AAAA,GAChE,CAAA;AACH;AAOO,SAAS,UAAU,EAAA,EAAoB;AAC5C,EAAA,OAAO,SAAA,CAAU,KAAA,CAAM,EAAE,CAAA,CAAE,IAAI,CAAA;AACjC","file":"index.js","sourcesContent":["/**\n * @file 序列化:mdast → Markdown\n * @description 与解析对称:解析支持的写法,序列化必须能产出。GFM(表格/删除线/任务列表)、\n * 数学公式与尖括号块各自注册 handler,空行由 handler 统一产出。\n * @created 2026-10-24 20:30\n * @updated 2026-10-26 22:02\n */\n\nimport { toMarkdown } from \"mdast-util-to-markdown\";\nimport { gfmToMarkdown } from \"mdast-util-gfm\";\nimport { mathToMarkdown } from \"mdast-util-math\";\nimport type { Root } from \"mdast\";\nimport { jsxToMarkdown } from \"./syntax/jsx-mdast\";\nimport { parse } from \"./parse\";\n\n/** 序列化选项:保持与项目既有风格一致(`-` 列表、`*` 强调、围栏代码块) */\nconst OPTIONS = {\n bullet: \"-\",\n emphasis: \"*\",\n strong: \"*\",\n rule: \"-\",\n fences: true,\n listItemIndent: \"one\",\n} as const;\n\n/**\n * 把 mdast 序列化为 Markdown\n * @param tree mdast 根节点\n * @returns Markdown 文本\n */\nexport function serialize(tree: Root): string {\n return toMarkdown(tree, {\n ...OPTIONS,\n // mathToMarkdown 直接把公式原文写回 `$…$` / `$$…$$`,不再走文本转义\n extensions: [gfmToMarkdown(), mathToMarkdown(), jsxToMarkdown()],\n });\n}\n\n/**\n * 便捷往返:Markdown → mdast → Markdown\n * @param md 原文\n * @returns 序列化结果(用于验收 `md → AST → md` 是否一致)\n */\nexport function roundtrip(md: string): string {\n return serialize(parse(md).tree);\n}\n"]}
1
+ {"version":3,"sources":["../src/serialize.ts"],"names":[],"mappings":";;;;;;;;;;AAgBA,IAAM,OAAA,GAAU;AAAA,EACd,MAAA,EAAQ,GAAA;AAAA,EACR,QAAA,EAAU,GAAA;AAAA,EACV,MAAA,EAAQ,GAAA;AAAA,EACR,IAAA,EAAM,GAAA;AAAA,EACN,MAAA,EAAQ,IAAA;AAAA,EACR,cAAA,EAAgB;AAClB,CAAA;AAOO,SAAS,UAAU,IAAA,EAAoB;AAC5C,EAAA,OAAO,WAAW,IAAA,EAAM;AAAA,IACtB,GAAG,OAAA;AAAA;AAAA,IAEH,YAAY,CAAC,aAAA,IAAiB,cAAA,EAAe,EAAG,eAAe;AAAA,GAChE,CAAA;AACH;AAOO,SAAS,UAAU,EAAA,EAAoB;AAC5C,EAAA,OAAO,SAAA,CAAU,KAAA,CAAM,EAAE,CAAA,CAAE,IAAI,CAAA;AACjC","file":"index.js","sourcesContent":["/**\n * @file 序列化:mdast → Markdown\n * @description 与解析对称:解析支持的写法,序列化必须能产出。GFM(表格/删除线/任务列表)、\n * 数学公式与尖括号块各自注册 handler,空行由 handler 统一产出。\n * @created 2026-10-24 20:30\n * @updated 2026-10-26 22:02\n */\n\nimport { toMarkdown } from \"mdast-util-to-markdown\";\nimport { gfmToMarkdown } from \"mdast-util-gfm\";\nimport { mathToMarkdown } from \"mdast-util-math\";\nimport type { Root } from \"mdast\";\nimport { jsxToMarkdown } from \"./syntax/jsx-mdast\";\nimport { parse } from \"./parse\";\n\n/** 序列化选项:保持与项目既有风格一致(`-` 列表、`*` 强调、围栏代码块) */\nconst OPTIONS = {\n bullet: \"-\",\n emphasis: \"*\",\n strong: \"*\",\n rule: \"-\",\n fences: true,\n listItemIndent: \"one\",\n} as const;\n\n/**\n * 把 mdast 序列化为 Markdown\n * @param tree mdast 根节点\n * @returns Markdown 文本\n */\nexport function serialize(tree: Root): string {\n return toMarkdown(tree, {\n ...OPTIONS,\n // mathToMarkdown 直接把公式原文写回 `$…$` / `$$…$$`,不再走文本转义\n extensions: [gfmToMarkdown(), mathToMarkdown(), jsxToMarkdown()],\n });\n}\n\n/**\n * 便捷往返:Markdown → mdast → Markdown\n * @param md 原文\n * @returns 序列化结果(用于验收 `md → AST → md` 是否一致)\n */\nexport function roundtrip(md: string): string {\n return serialize(parse(md).tree);\n}\n"]}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @file 英语语言包
3
+ * @description 全量满足 `UIText`,编译期强制无缺键。复数分支按 CLDR 区分 one/other。
4
+ * 消息内不使用 ASCII 单引号(ICU 转义符),需要引号处用双引号或改写。
5
+ * @created 2026-11-02 19:32
6
+ * @updated 2026-11-02 19:32
7
+ */
8
+ /** 英语(美国) */
9
+ declare const enUS: {
10
+ imageZoomClose: string;
11
+ mermaidSourceView: string;
12
+ mermaidLoading: string;
13
+ mermaidErrorPrefix: string;
14
+ mermaidErrorSuffix: string;
15
+ mermaidFallbackError: string;
16
+ mermaidTimeout: string;
17
+ mermaidZoomGroup: string;
18
+ mermaidZoomIn: string;
19
+ mermaidZoomOut: string;
20
+ mermaidZoomReset: string;
21
+ mermaidResetTitle: string;
22
+ mermaidToChart: string;
23
+ mermaidToSource: string;
24
+ mermaidChartView: string;
25
+ mermaidCopied: string;
26
+ mermaidCopySource: string;
27
+ mermaidDownloadSvg: string;
28
+ mermaidDownloadPng: string;
29
+ typeTableAttr: string;
30
+ typeTableType: string;
31
+ typeTableDefault: string;
32
+ typeTableDesc: string;
33
+ typeItemRequired: string;
34
+ typeItemEmpty: string;
35
+ editorBold: string;
36
+ editorItalic: string;
37
+ editorStrike: string;
38
+ editorCode: string;
39
+ editorH2: string;
40
+ editorQuote: string;
41
+ editorList: string;
42
+ editorViewGroup: string;
43
+ editorViewSource: string;
44
+ editorViewSplit: string;
45
+ editorViewPreview: string;
46
+ editorFullscreen: string;
47
+ editorExitFullscreen: string;
48
+ editorWordCount: string;
49
+ editorDiagnostic: string;
50
+ editorWrapPlaceholder: string;
51
+ editorPlaceholder: string;
52
+ editorInsertBlock: string;
53
+ /** @deprecated 改用 editorWordCount */
54
+ editorWordCountUnit: string;
55
+ /** @deprecated 改用 editorDiagnostic */
56
+ editorDiagnosticPrefix: string;
57
+ diagDepthExceeded: string;
58
+ diagIndentAsCode: string;
59
+ diagUnclosedTag: string;
60
+ diagMermaidEmpty: string;
61
+ diagMermaidTooLarge: string;
62
+ diagUnsafeHref: string;
63
+ diagDuplicateIdAnchor: string;
64
+ diagDuplicateIdDiv: string;
65
+ diagUnknownTag: string;
66
+ };
67
+
68
+ export { enUS };
@@ -0,0 +1,3 @@
1
+ export { enUS } from '../chunk-YJGGJP2V.js';
2
+ //# sourceMappingURL=en-US.js.map
3
+ //# sourceMappingURL=en-US.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"en-US.js"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @file 简体中文语言包(包内默认)
3
+ * @description 全量满足 `UIText`,编译期强制无缺键。带 `{...}` 的是 ICU 消息模板,
4
+ * 带 `plural` 的是复数分支;纯文本消息不含花括号,格式化时走快路径。
5
+ * @created 2026-11-02 19:32
6
+ * @updated 2026-11-02 19:32
7
+ */
8
+ /** 简体中文 */
9
+ declare const zhCN: {
10
+ imageZoomClose: string;
11
+ mermaidSourceView: string;
12
+ mermaidLoading: string;
13
+ mermaidErrorPrefix: string;
14
+ mermaidErrorSuffix: string;
15
+ mermaidFallbackError: string;
16
+ mermaidTimeout: string;
17
+ mermaidZoomGroup: string;
18
+ mermaidZoomIn: string;
19
+ mermaidZoomOut: string;
20
+ mermaidZoomReset: string;
21
+ mermaidResetTitle: string;
22
+ mermaidToChart: string;
23
+ mermaidToSource: string;
24
+ mermaidChartView: string;
25
+ mermaidCopied: string;
26
+ mermaidCopySource: string;
27
+ mermaidDownloadSvg: string;
28
+ mermaidDownloadPng: string;
29
+ typeTableAttr: string;
30
+ typeTableType: string;
31
+ typeTableDefault: string;
32
+ typeTableDesc: string;
33
+ typeItemRequired: string;
34
+ typeItemEmpty: string;
35
+ editorBold: string;
36
+ editorItalic: string;
37
+ editorStrike: string;
38
+ editorCode: string;
39
+ editorH2: string;
40
+ editorQuote: string;
41
+ editorList: string;
42
+ editorViewGroup: string;
43
+ editorViewSource: string;
44
+ editorViewSplit: string;
45
+ editorViewPreview: string;
46
+ editorFullscreen: string;
47
+ editorExitFullscreen: string;
48
+ editorWordCount: string;
49
+ editorDiagnostic: string;
50
+ editorWrapPlaceholder: string;
51
+ editorPlaceholder: string;
52
+ editorInsertBlock: string;
53
+ /** @deprecated 改用 editorWordCount */
54
+ editorWordCountUnit: string;
55
+ /** @deprecated 改用 editorDiagnostic */
56
+ editorDiagnosticPrefix: string;
57
+ diagDepthExceeded: string;
58
+ diagIndentAsCode: string;
59
+ diagUnclosedTag: string;
60
+ diagMermaidEmpty: string;
61
+ diagMermaidTooLarge: string;
62
+ diagUnsafeHref: string;
63
+ diagDuplicateIdAnchor: string;
64
+ diagDuplicateIdDiv: string;
65
+ diagUnknownTag: string;
66
+ };
67
+
68
+ export { zhCN };
@@ -0,0 +1,3 @@
1
+ export { zhCN } from '../chunk-OG47YL3H.js';
2
+ //# sourceMappingURL=zh-CN.js.map
3
+ //# sourceMappingURL=zh-CN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"zh-CN.js"}
@@ -1,5 +1,5 @@
1
1
  import { ReactElement, RefObject, ComponentType } from 'react';
2
- import { a as MermaidProps } from '../mermaid-placeholder-A1N4puyc.js';
2
+ import { a as MermaidProps } from '../mermaid-placeholder-DYfFG3_f.js';
3
3
 
4
4
  /**
5
5
  * @file 交互式图表视图(客户端)
@@ -10,6 +10,7 @@ import { a as MermaidProps } from '../mermaid-placeholder-A1N4puyc.js';
10
10
  * @updated 2026-11-01 22:37 标题并入工具栏;暗色与取色按图表容器判定;手势仅在出图后启用
11
11
  * @updated 2026-11-01 22:51 导出 PNG 底色改走 resolveChartTokens
12
12
  * @updated 2026-11-01 23:18 height 未指定 / 空 / auto 一律自动高度
13
+ * @updated 2026-11-02 10:38 固定文案改走 UIText(config.text 可覆写)
13
14
  */
14
15
 
15
16
  /**
@@ -154,6 +155,7 @@ declare function downloadPng(source: string, background: string): Promise<void>;
154
155
  * @updated 2026-11-01 21:24
155
156
  * @updated 2026-11-01 22:37 令牌三级回落(引擎令牌→宿主语义变量→内置)+ oklch/hsl 归一;取色改按图表元素
156
157
  * @updated 2026-11-01 22:51 取色改为「JS 配置 → 组件自带 --lkes-chart-* → 内置」,不再读宿主变量
158
+ * @updated 2026-11-02 10:35 缓存加 LRU 上限(防编辑长文时内存只涨不落);超时改为可识别异常,文案由视图侧本地化
157
159
  */
158
160
 
159
161
  /**
@@ -1,3 +1,6 @@
1
+ import { useUIText } from '../chunk-OJQDOFGL.js';
2
+ import '../chunk-OG47YL3H.js';
3
+ import '../chunk-YJGGJP2V.js';
1
4
  import { useState, useEffect, useRef, useCallback } from 'react';
2
5
  import { jsxs, jsx } from 'react/jsx-runtime';
3
6
  import DOMPurify from 'dompurify';
@@ -132,6 +135,7 @@ function ResetIcon(props) {
132
135
  }
133
136
  function MermaidHeader(props) {
134
137
  const { showSource, canExport, source, title, onToggleView, onExportSvg, onExportPng } = props;
138
+ const text = useUIText();
135
139
  const [copied, setCopied] = useState(false);
136
140
  const timer = useRef(null);
137
141
  const onCopy = async () => {
@@ -152,10 +156,10 @@ function MermaidHeader(props) {
152
156
  className: "lkes-mermaid-mode",
153
157
  onClick: onToggleView,
154
158
  "aria-pressed": showSource,
155
- title: showSource ? "\u5207\u6362\u5230\u56FE\u8868" : "\u67E5\u770B\u6E90\u7801",
159
+ title: showSource ? text.mermaidToChart : text.mermaidToSource,
156
160
  children: [
157
161
  /* @__PURE__ */ jsx(CodeIcon, {}),
158
- /* @__PURE__ */ jsx("span", { children: showSource ? "\u56FE\u8868\u89C6\u56FE" : "\u6E90\u7801\u89C6\u56FE" })
162
+ /* @__PURE__ */ jsx("span", { children: showSource ? text.mermaidChartView : text.mermaidSourceView })
159
163
  ]
160
164
  }
161
165
  ),
@@ -164,15 +168,15 @@ function MermaidHeader(props) {
164
168
  /* @__PURE__ */ jsxs("div", { className: "lkes-mermaid-actions", children: [
165
169
  /* @__PURE__ */ jsxs("button", { type: "button", onClick: onCopy, children: [
166
170
  /* @__PURE__ */ jsx(CopyIcon, {}),
167
- /* @__PURE__ */ jsx("span", { children: copied ? "\u5DF2\u590D\u5236" : "\u590D\u5236\u6E90\u7801" })
171
+ /* @__PURE__ */ jsx("span", { children: copied ? text.mermaidCopied : text.mermaidCopySource })
168
172
  ] }),
169
173
  /* @__PURE__ */ jsxs("button", { type: "button", onClick: onExportSvg, disabled: !canExport, children: [
170
174
  /* @__PURE__ */ jsx(DownloadIcon, {}),
171
- /* @__PURE__ */ jsx("span", { children: "\u4E0B\u8F7D SVG" })
175
+ /* @__PURE__ */ jsx("span", { children: text.mermaidDownloadSvg })
172
176
  ] }),
173
177
  /* @__PURE__ */ jsxs("button", { type: "button", onClick: onExportPng, disabled: !canExport, children: [
174
178
  /* @__PURE__ */ jsx(ImageIcon, {}),
175
- /* @__PURE__ */ jsx("span", { children: "\u4E0B\u8F7D PNG" })
179
+ /* @__PURE__ */ jsx("span", { children: text.mermaidDownloadPng })
176
180
  ] })
177
181
  ] })
178
182
  ] });
@@ -375,8 +379,15 @@ function tokenFingerprint(tokens) {
375
379
  }
376
380
 
377
381
  // src/mermaid/use-render.ts
382
+ var MermaidRenderTimeoutError = class extends Error {
383
+ constructor() {
384
+ super("MERMAID_RENDER_TIMEOUT");
385
+ this.name = "MermaidRenderTimeoutError";
386
+ }
387
+ };
378
388
  var RENDER_TIMEOUT = 1e4;
379
389
  var CACHE = /* @__PURE__ */ new Map();
390
+ var CACHE_LIMIT = 32;
380
391
  var seq = 0;
381
392
  var chain = Promise.resolve();
382
393
  var loader = null;
@@ -391,7 +402,7 @@ function runExclusive(task) {
391
402
  }
392
403
  function withTimeout(task, ms) {
393
404
  return new Promise((resolve, reject) => {
394
- const timer = setTimeout(() => reject(new Error("\u56FE\u8868\u6E32\u67D3\u8D85\u65F6")), ms);
405
+ const timer = setTimeout(() => reject(new MermaidRenderTimeoutError()), ms);
395
406
  task.then(
396
407
  (value) => {
397
408
  clearTimeout(timer);
@@ -452,7 +463,11 @@ function resolveChartTokens(dark, element) {
452
463
  async function renderChart(source, tokens) {
453
464
  const key = `${tokenFingerprint(tokens)}#${source}`;
454
465
  const cached = CACHE.get(key);
455
- if (cached) return cached;
466
+ if (cached) {
467
+ CACHE.delete(key);
468
+ CACHE.set(key, cached);
469
+ return cached;
470
+ }
456
471
  const mermaid = await loadMermaid();
457
472
  const svg = await runExclusive(async () => {
458
473
  mermaid.initialize(buildMermaidConfig(tokens));
@@ -461,10 +476,15 @@ async function renderChart(source, tokens) {
461
476
  });
462
477
  const clean = sanitizeSvg(svg);
463
478
  CACHE.set(key, clean);
479
+ if (CACHE.size > CACHE_LIMIT) {
480
+ const oldest = CACHE.keys().next().value;
481
+ if (oldest !== void 0 && oldest !== key) CACHE.delete(oldest);
482
+ }
464
483
  return clean;
465
484
  }
466
485
  function useMermaidRender(source, enabled, dark, elementRef) {
467
486
  const [state, setState] = useState({ status: "idle", svg: "", error: "" });
487
+ const text = useUIText();
468
488
  useEffect(() => {
469
489
  if (!enabled) return;
470
490
  let cancelled = false;
@@ -475,7 +495,7 @@ function useMermaidRender(source, enabled, dark, elementRef) {
475
495
  if (!cancelled) setState({ status: "ready", svg, error: "" });
476
496
  } catch (error) {
477
497
  if (!cancelled) {
478
- const message = error instanceof Error ? error.message : "\u56FE\u8868\u6E32\u67D3\u5931\u8D25";
498
+ const message = error instanceof MermaidRenderTimeoutError ? text.mermaidTimeout : error instanceof Error && error.message !== "MERMAID_RENDER_TIMEOUT" ? error.message : text.mermaidFallbackError;
479
499
  console.warn("[md-engine] mermaid \u6E32\u67D3\u5931\u8D25\uFF0C\u5DF2\u964D\u7EA7\u4E3A\u6E90\u7801\uFF1A", message);
480
500
  setState({ status: "error", svg: "", error: message });
481
501
  }
@@ -484,7 +504,7 @@ function useMermaidRender(source, enabled, dark, elementRef) {
484
504
  return () => {
485
505
  cancelled = true;
486
506
  };
487
- }, [source, enabled, dark]);
507
+ }, [source, enabled, dark, text]);
488
508
  return state;
489
509
  }
490
510
  var IDENTITY = { scale: 1, x: 0, y: 0 };
@@ -596,6 +616,7 @@ function viewportHeight(height) {
596
616
  function MermaidChart({ raw, code, title, height, tooLarge }) {
597
617
  const source = String(raw ?? code ?? "");
598
618
  const disabled = Boolean(tooLarge) || source.trim() === "";
619
+ const text = useUIText();
599
620
  const frameRef = useRef(null);
600
621
  const dark = useIsDark(frameRef);
601
622
  const [visible, setVisible] = useState(false);
@@ -654,16 +675,25 @@ function MermaidChart({ raw, code, title, height, tooLarge }) {
654
675
  dangerouslySetInnerHTML: { __html: svg }
655
676
  }
656
677
  ) : /* @__PURE__ */ jsx("pre", { className: "lkes-mermaid-source", children: /* @__PURE__ */ jsx("code", { children: source }) }) }),
657
- status === "loading" ? /* @__PURE__ */ jsx("p", { className: "lkes-mermaid-hint", children: "\u6B63\u5728\u6E32\u67D3\u56FE\u8868\u2026" }) : null,
678
+ status === "loading" ? /* @__PURE__ */ jsx("p", { className: "lkes-mermaid-hint", children: text.mermaidLoading }) : null,
658
679
  error ? /* @__PURE__ */ jsxs("p", { className: "lkes-mermaid-error", children: [
659
- "\u56FE\u8868\u6E32\u67D3\u5931\u8D25\uFF1A",
680
+ text.mermaidErrorPrefix,
660
681
  error,
661
- "\uFF08\u5DF2\u663E\u793A\u6E90\u7801\uFF09"
682
+ text.mermaidErrorSuffix
662
683
  ] }) : null,
663
- ready ? /* @__PURE__ */ jsxs("div", { className: "lkes-mermaid-zoom", role: "group", "aria-label": "\u7F29\u653E\u63A7\u5236", children: [
664
- /* @__PURE__ */ jsx("button", { type: "button", onClick: zoom.zoomIn, "aria-label": "\u653E\u5927", title: "\u653E\u5927", children: /* @__PURE__ */ jsx(ZoomInIcon, {}) }),
665
- /* @__PURE__ */ jsx("button", { type: "button", onClick: zoom.zoomOut, "aria-label": "\u7F29\u5C0F", title: "\u7F29\u5C0F", children: /* @__PURE__ */ jsx(ZoomOutIcon, {}) }),
666
- /* @__PURE__ */ jsx("button", { type: "button", onClick: zoom.reset, "aria-label": "\u91CD\u7F6E\u7F29\u653E", title: "\u91CD\u7F6E", children: /* @__PURE__ */ jsx(ResetIcon, {}) })
684
+ ready ? /* @__PURE__ */ jsxs("div", { className: "lkes-mermaid-zoom", role: "group", "aria-label": text.mermaidZoomGroup, children: [
685
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: zoom.zoomIn, "aria-label": text.mermaidZoomIn, title: text.mermaidZoomIn, children: /* @__PURE__ */ jsx(ZoomInIcon, {}) }),
686
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: zoom.zoomOut, "aria-label": text.mermaidZoomOut, title: text.mermaidZoomOut, children: /* @__PURE__ */ jsx(ZoomOutIcon, {}) }),
687
+ /* @__PURE__ */ jsx(
688
+ "button",
689
+ {
690
+ type: "button",
691
+ onClick: zoom.reset,
692
+ "aria-label": text.mermaidZoomReset,
693
+ title: text.mermaidResetTitle,
694
+ children: /* @__PURE__ */ jsx(ResetIcon, {})
695
+ }
696
+ )
667
697
  ] }) : null
668
698
  ] });
669
699
  }