@h-ai/ui 1.0.0-beta.3 → 1.0.0-beta.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +14 -1007
- package/README.ja.md +13 -1006
- package/README.md +15 -1007
- package/auto-import.d.ts +9 -0
- package/auto-import.js +246 -65
- package/dist/components/compounds/Accordion.svelte +6 -2
- package/dist/components/compounds/BottomNav.svelte +14 -2
- package/dist/components/compounds/Card.svelte +3 -1
- package/dist/components/compounds/Combobox.svelte +41 -5
- package/dist/components/compounds/DataTable.svelte +28 -8
- package/dist/components/compounds/DatePicker.svelte +6 -1
- package/dist/components/compounds/Drawer.svelte +12 -4
- package/dist/components/compounds/Dropdown.svelte +135 -59
- package/dist/components/compounds/Empty.svelte +10 -2
- package/dist/components/compounds/FormField.svelte +10 -2
- package/dist/components/compounds/JsonViewer.svelte +18 -6
- package/dist/components/compounds/Modal.svelte +8 -2
- package/dist/components/compounds/Pagination.svelte +22 -7
- package/dist/components/compounds/Popover.svelte +94 -12
- package/dist/components/compounds/Steps.svelte +24 -8
- package/dist/components/compounds/SwipeCell.svelte +3 -1
- package/dist/components/compounds/TableToolbar.svelte +32 -9
- package/dist/components/compounds/Tabs.svelte +25 -5
- package/dist/components/compounds/TagInput.svelte +2 -0
- package/dist/components/compounds/Timeline.svelte +6 -2
- package/dist/components/compounds/ToastContainer.svelte +41 -10
- package/dist/components/compounds/Tooltip.svelte +1 -1
- package/dist/components/compounds/Tooltip.svelte.d.ts +1 -1
- package/dist/components/control-size.js +48 -8
- package/dist/components/primitives/Avatar.svelte +9 -3
- package/dist/components/primitives/BareInput.svelte +3 -1
- package/dist/components/primitives/Button.svelte +6 -2
- package/dist/components/primitives/Checkbox.svelte +5 -0
- package/dist/components/primitives/IconButton.svelte +3 -1
- package/dist/components/primitives/Input.svelte +19 -3
- package/dist/components/primitives/Radio.svelte +4 -1
- package/dist/components/primitives/Range.svelte +3 -1
- package/dist/components/primitives/Rating.svelte +9 -3
- package/dist/components/primitives/Select.svelte +21 -5
- package/dist/components/primitives/Tag.svelte +6 -10
- package/dist/components/primitives/Textarea.svelte +14 -2
- package/dist/components/scenes/ai/AiDocumentEditor.svelte +118 -76
- package/dist/components/scenes/ai/document-download.js +55 -88
- package/dist/components/scenes/ai/document-parse.js +27 -33
- package/dist/components/scenes/ai/document-pdf-pages.d.ts +26 -0
- package/dist/components/scenes/ai/document-pdf-pages.js +111 -0
- package/dist/components/scenes/ai/document-pdf-worker.d.ts +11 -0
- package/dist/components/scenes/ai/document-pdf-worker.js +29 -0
- package/dist/components/scenes/ai/document-render-pool.d.ts +19 -0
- package/dist/components/scenes/ai/document-render-pool.js +20 -0
- package/dist/components/scenes/ai/document-render-worker.d.ts +13 -0
- package/dist/components/scenes/ai/document-render-worker.js +7 -0
- package/dist/components/scenes/ai/document-types.d.ts +2 -12
- package/dist/components/scenes/ai/editor-markdown-extensions.js +9 -3
- package/dist/components/scenes/ai/highlight.js +3 -1
- package/dist/components/scenes/ai/index.d.ts +4 -1
- package/dist/components/scenes/ai/index.js +2 -0
- package/dist/components/scenes/ai/markdown-parse.js +36 -10
- package/dist/components/scenes/ai/mermaid-render.js +13 -1
- package/dist/components/scenes/ai/mind/AiMindMapEditor.svelte +519 -0
- package/dist/components/scenes/ai/mind/AiMindMapEditor.svelte.d.ts +8 -0
- package/dist/components/scenes/ai/mind/mind-adapter.d.ts +38 -0
- package/dist/components/scenes/ai/mind/mind-adapter.js +59 -0
- package/dist/components/scenes/ai/mind/mind-types.d.ts +116 -0
- package/dist/components/scenes/ai/mind/mind-types.js +1 -0
- package/dist/components/scenes/ai/safe-html.js +9 -3
- package/dist/components/scenes/ai/table/AiTableEditor.svelte +28 -16
- package/dist/components/scenes/app/FeedbackDetail.svelte +102 -24
- package/dist/components/scenes/app/FeedbackForm.svelte +70 -16
- package/dist/components/scenes/app/FeedbackList.svelte +138 -21
- package/dist/components/scenes/app/FeedbackRecorder.svelte +18 -5
- package/dist/components/scenes/app/FeedbackReplay.svelte +15 -3
- package/dist/components/scenes/app/FeedbackScreenshot.svelte +64 -13
- package/dist/components/scenes/app/LanguageSwitch.svelte +6 -2
- package/dist/components/scenes/app/SettingsLayout.svelte +3 -1
- package/dist/components/scenes/app/ThemeSelector.svelte +29 -5
- package/dist/components/scenes/app/ThemeToggle.svelte +6 -2
- package/dist/components/scenes/app/WorkspaceLayout.svelte +1 -1
- package/dist/components/scenes/app/feedback-functions.js +6 -2
- package/dist/components/scenes/charts/Chart.svelte +55 -21
- package/dist/components/scenes/charts/Chart.svelte.d.ts +0 -1
- package/dist/components/scenes/charts/ChartLoadError.svelte +13 -0
- package/dist/components/scenes/charts/ChartLoadError.svelte.d.ts +6 -0
- package/dist/components/scenes/charts/DashboardGrid.svelte +34 -0
- package/dist/components/scenes/charts/DashboardGrid.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/MetricCard.svelte +69 -0
- package/dist/components/scenes/charts/MetricCard.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/ReportCard.svelte +48 -0
- package/dist/components/scenes/charts/ReportCard.svelte.d.ts +15 -0
- package/dist/components/scenes/charts/chart-presets.d.ts +15 -0
- package/dist/components/scenes/charts/chart-presets.js +56 -0
- package/dist/components/scenes/charts/chart-types.d.ts +13 -2
- package/dist/components/scenes/charts/dashboard-types.d.ts +79 -0
- package/dist/components/scenes/charts/dashboard-types.js +1 -0
- package/dist/components/scenes/charts/index.d.ts +6 -2
- package/dist/components/scenes/charts/index.js +4 -1
- package/dist/components/scenes/charts/renderers/AreaChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte +39 -12
- package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte.d.ts +1 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte +1 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte.d.ts +1 -0
- package/dist/components/scenes/code/CodeWorkspace.svelte +946 -0
- package/dist/components/scenes/code/CodeWorkspace.svelte.d.ts +21 -0
- package/dist/components/scenes/code/CodeWorkspaceEditor.svelte +737 -0
- package/dist/components/scenes/code/CodeWorkspaceEditor.svelte.d.ts +37 -0
- package/dist/components/scenes/code/CodeWorkspaceGutter.svelte +246 -0
- package/dist/components/scenes/code/CodeWorkspaceGutter.svelte.d.ts +23 -0
- package/dist/components/scenes/code/CodeWorkspaceSearch.svelte +234 -0
- package/dist/components/scenes/code/CodeWorkspaceSearch.svelte.d.ts +23 -0
- package/dist/components/scenes/code/CodeWorkspaceTree.svelte +519 -0
- package/dist/components/scenes/code/CodeWorkspaceTree.svelte.d.ts +26 -0
- package/dist/components/scenes/code/code-editor.d.ts +12 -0
- package/dist/components/scenes/code/code-editor.js +93 -0
- package/dist/components/scenes/code/code-types.d.ts +346 -0
- package/dist/components/scenes/code/code-types.js +1 -0
- package/dist/components/scenes/code/index.d.ts +2 -0
- package/dist/components/scenes/code/index.js +1 -0
- package/dist/components/scenes/code/workers/css.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/css.worker.js +1 -0
- package/dist/components/scenes/code/workers/editor.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/editor.worker.js +1 -0
- package/dist/components/scenes/code/workers/html.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/html.worker.js +1 -0
- package/dist/components/scenes/code/workers/json.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/json.worker.js +1 -0
- package/dist/components/scenes/code/workers/ts.worker.d.ts +1 -0
- package/dist/components/scenes/code/workers/ts.worker.js +1 -0
- package/dist/components/scenes/crud/CrudDetailDrawer.svelte +6 -2
- package/dist/components/scenes/crud/CrudDetailPanel.svelte +6 -2
- package/dist/components/scenes/crud/CrudEditPanel.svelte +41 -12
- package/dist/components/scenes/crud/CrudPage.svelte +34 -9
- package/dist/components/scenes/crud/crud-controller.svelte.js +23 -8
- package/dist/components/scenes/crud/crud-form-validation.js +27 -9
- package/dist/components/scenes/crypto/EncryptedInput.svelte +9 -3
- package/dist/components/scenes/error/error-presets.js +30 -5
- package/dist/components/scenes/guide/GuideHostContent.svelte +7 -1
- package/dist/components/scenes/guide/HelpCenter.svelte +23 -4
- package/dist/components/scenes/iam/AgreementNotice.svelte +9 -3
- package/dist/components/scenes/iam/AuthPanel.svelte +74 -16
- package/dist/components/scenes/iam/ChangePasswordForm.svelte +6 -2
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte +9 -3
- package/dist/components/scenes/iam/LoginForm.svelte +32 -8
- package/dist/components/scenes/iam/PasswordInput.svelte +50 -12
- package/dist/components/scenes/iam/RegisterForm.svelte +11 -3
- package/dist/components/scenes/iam/ResetPasswordForm.svelte +6 -2
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +3 -1
- package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +4 -1
- package/dist/components/scenes/iam/UserProfile.svelte +41 -14
- package/dist/components/scenes/iam/auth-captcha.js +9 -2
- package/dist/components/scenes/iam/auth-error-message.d.ts +2 -2
- package/dist/components/scenes/iam/auth-error-message.js +16 -3
- package/dist/components/scenes/iam/password-utils.js +9 -2
- package/dist/components/scenes/iam/sensitive-actions.svelte.js +4 -1
- package/dist/components/scenes/index.d.ts +2 -0
- package/dist/components/scenes/index.js +4 -0
- package/dist/components/scenes/storage/FileList.svelte +3 -1
- package/dist/components/scenes/storage/FileUpload.svelte +7 -2
- package/dist/components/scenes/tools/ArtifactWorkspace.svelte +561 -0
- package/dist/components/scenes/tools/ArtifactWorkspace.svelte.d.ts +17 -0
- package/dist/components/scenes/tools/ToolWorkspace.svelte +435 -0
- package/dist/components/scenes/tools/ToolWorkspace.svelte.d.ts +17 -0
- package/dist/components/scenes/tools/artifact-data.d.ts +35 -0
- package/dist/components/scenes/tools/artifact-data.js +127 -0
- package/dist/components/scenes/tools/artifact-markdown.d.ts +58 -0
- package/dist/components/scenes/tools/artifact-markdown.js +308 -0
- package/dist/components/scenes/tools/artifact-preview.d.ts +9 -0
- package/dist/components/scenes/tools/artifact-preview.js +31 -0
- package/dist/components/scenes/tools/index.d.ts +4 -0
- package/dist/components/scenes/tools/index.js +3 -0
- package/dist/components/scenes/tools/tool-form.d.ts +74 -0
- package/dist/components/scenes/tools/tool-form.js +179 -0
- package/dist/components/scenes/tools/workspace-types.d.ts +221 -0
- package/dist/components/scenes/tools/workspace-types.js +1 -0
- package/dist/components/scenes/types.d.ts +2 -2
- package/dist/guide-storage.js +12 -4
- package/dist/guide.svelte.js +59 -16
- package/dist/i18n.svelte.js +9 -3
- package/dist/internal/dialog-focus.d.ts +19 -0
- package/dist/internal/dialog-focus.js +104 -4
- package/dist/internal/form-validation.svelte.js +46 -15
- package/dist/internal/icon-safety.js +6 -2
- package/dist/message.svelte.js +6 -2
- package/dist/messagebox.svelte.js +6 -2
- package/dist/messages/en-US.json +158 -2
- package/dist/messages/ja-JP.json +158 -2
- package/dist/messages/zh-CN.json +158 -2
- package/dist/styles/eye-care.css +55 -0
- package/dist/styles/global.css +16 -0
- package/dist/styles/theme.css +1 -0
- package/dist/theme-config.d.ts +1 -3
- package/dist/theme-config.js +137 -22
- package/dist/toast.svelte.js +27 -7
- package/dist/types.d.ts +3 -3
- package/dist/utils.js +6 -2
- package/package.json +31 -19
|
@@ -87,7 +87,9 @@ function createHeadingId(state, text) {
|
|
|
87
87
|
// next count per slug ensures stable suffixing.
|
|
88
88
|
const nextCount = (state.headingIds.get(base) ?? 0) + 1;
|
|
89
89
|
state.headingIds.set(base, nextCount);
|
|
90
|
-
return nextCount === 1
|
|
90
|
+
return nextCount === 1
|
|
91
|
+
? base
|
|
92
|
+
: `${base}-${nextCount}`;
|
|
91
93
|
}
|
|
92
94
|
/**
|
|
93
95
|
* 为目录条目添加 1、1.1 等层级编号。
|
|
@@ -109,7 +111,9 @@ function createNumberedOutline(outline) {
|
|
|
109
111
|
.join('.');
|
|
110
112
|
return {
|
|
111
113
|
...item,
|
|
112
|
-
numberedTitle: prefix
|
|
114
|
+
numberedTitle: prefix
|
|
115
|
+
? `${prefix} ${item.text}`
|
|
116
|
+
: item.text,
|
|
113
117
|
};
|
|
114
118
|
});
|
|
115
119
|
}
|
|
@@ -197,7 +201,9 @@ function createRendererObject(options, state) {
|
|
|
197
201
|
+ `<div class="hai-md-code-header-main">${codePreviewToggle}${langLabel}${previewHint}</div>`
|
|
198
202
|
+ `<div class="hai-md-code-actions">${runBtn}${copyBtn}</div>`
|
|
199
203
|
+ `</div>`
|
|
200
|
-
+ `<pre><code class="hai-hl${highlightLanguage
|
|
204
|
+
+ `<pre><code class="hai-hl${highlightLanguage
|
|
205
|
+
? ` language-${escapeHtml(highlightLanguage)}`
|
|
206
|
+
: ''}">${highlighted}</code></pre>`
|
|
201
207
|
+ `${previewHost}`
|
|
202
208
|
+ `</div>`;
|
|
203
209
|
},
|
|
@@ -217,7 +223,9 @@ function createRendererObject(options, state) {
|
|
|
217
223
|
// attrs is the flattened HTML attribute string.
|
|
218
224
|
const attrs = [
|
|
219
225
|
`href="${escapeHtml(safeHref)}"`,
|
|
220
|
-
title
|
|
226
|
+
title
|
|
227
|
+
? `title="${escapeHtml(title)}"`
|
|
228
|
+
: '',
|
|
221
229
|
isExternal ? 'target="_blank" rel="noopener noreferrer"' : '',
|
|
222
230
|
].filter(Boolean).join(' ');
|
|
223
231
|
return `<a ${attrs}>${text}</a>`;
|
|
@@ -229,7 +237,9 @@ function createRendererObject(options, state) {
|
|
|
229
237
|
const attrs = [
|
|
230
238
|
`src="${escapeHtml(safeSrc)}"`,
|
|
231
239
|
`alt="${escapeHtml(text || '')}"`,
|
|
232
|
-
title
|
|
240
|
+
title
|
|
241
|
+
? `title="${escapeHtml(title)}"`
|
|
242
|
+
: '',
|
|
233
243
|
'loading="lazy"',
|
|
234
244
|
'class="hai-md-img"',
|
|
235
245
|
].filter(Boolean).join(' ');
|
|
@@ -240,7 +250,9 @@ function createRendererObject(options, state) {
|
|
|
240
250
|
let headerHtml = '';
|
|
241
251
|
for (const cell of token.header) {
|
|
242
252
|
// align adds text alignment for each header cell.
|
|
243
|
-
const align = cell.align
|
|
253
|
+
const align = cell.align
|
|
254
|
+
? ` style="text-align:${cell.align}"`
|
|
255
|
+
: '';
|
|
244
256
|
headerHtml += `<th${align}>${this.parser.parseInline(cell.tokens)}</th>`;
|
|
245
257
|
}
|
|
246
258
|
// bodyHtml accumulates all body rows.
|
|
@@ -250,7 +262,9 @@ function createRendererObject(options, state) {
|
|
|
250
262
|
let rowHtml = '';
|
|
251
263
|
for (const cell of row) {
|
|
252
264
|
// align adds text alignment for each body cell.
|
|
253
|
-
const align = cell.align
|
|
265
|
+
const align = cell.align
|
|
266
|
+
? ` style="text-align:${cell.align}"`
|
|
267
|
+
: '';
|
|
254
268
|
rowHtml += `<td${align}>${this.parser.parseInline(cell.tokens)}</td>`;
|
|
255
269
|
}
|
|
256
270
|
bodyHtml += `<tr>${rowHtml}</tr>`;
|
|
@@ -294,14 +308,6 @@ function createHtmlBlock(id, html) {
|
|
|
294
308
|
}
|
|
295
309
|
: null;
|
|
296
310
|
}
|
|
297
|
-
function renderMarkdownDocumentHtmlChunk(content, options, state) {
|
|
298
|
-
const marked = createMarkedInstance(options, state);
|
|
299
|
-
const result = marked.parse(content);
|
|
300
|
-
return {
|
|
301
|
-
html: typeof result === 'string' ? result : '',
|
|
302
|
-
codeBlocks: state.codeBlocks,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
311
|
function isClosedMermaidToken(token, options) {
|
|
306
312
|
if (token.type !== 'code'
|
|
307
313
|
|| !('text' in token)
|
|
@@ -314,28 +320,18 @@ function isClosedMermaidToken(token, options) {
|
|
|
314
320
|
&& !options.showCodePreviewToggle
|
|
315
321
|
&& isClosedFencedCodeBlock(codeToken);
|
|
316
322
|
}
|
|
317
|
-
function renderMarkdownDocumentBlocks(content, options) {
|
|
318
|
-
const marked =
|
|
319
|
-
extensions: createEditorMarkdownExtensions(),
|
|
320
|
-
gfm: true,
|
|
321
|
-
breaks: options.breaks,
|
|
322
|
-
});
|
|
323
|
+
function renderMarkdownDocumentBlocks(content, options, state) {
|
|
324
|
+
const marked = createMarkedInstance(options, state);
|
|
323
325
|
const tokens = marked.lexer(content);
|
|
324
326
|
const blocks = [];
|
|
325
327
|
let htmlTokens = [];
|
|
326
|
-
const state = {
|
|
327
|
-
outline: [],
|
|
328
|
-
codeBlocks: [],
|
|
329
|
-
headingIds: new Map(),
|
|
330
|
-
};
|
|
331
328
|
let nextBlockIndex = 1;
|
|
332
329
|
function flushHtmlTokens() {
|
|
333
330
|
if (htmlTokens.length === 0) {
|
|
334
331
|
return;
|
|
335
332
|
}
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
const block = createHtmlBlock(`hai-md-block-${nextBlockIndex}`, result.html);
|
|
333
|
+
const html = marked.parser(htmlTokens);
|
|
334
|
+
const block = createHtmlBlock(`hai-md-block-${nextBlockIndex}`, html);
|
|
339
335
|
if (block) {
|
|
340
336
|
blocks.push(block);
|
|
341
337
|
nextBlockIndex += 1;
|
|
@@ -396,12 +392,10 @@ export function renderMarkdownDocument(content, options) {
|
|
|
396
392
|
codeBlocks: [],
|
|
397
393
|
headingIds: new Map(),
|
|
398
394
|
};
|
|
399
|
-
|
|
400
|
-
const marked = createMarkedInstance(mergedOptions, state);
|
|
401
|
-
marked.parse(content);
|
|
395
|
+
const blocks = renderMarkdownDocumentBlocks(content, mergedOptions, state);
|
|
402
396
|
return {
|
|
403
397
|
outline: createNumberedOutline(state.outline),
|
|
404
398
|
codeBlocks: state.codeBlocks,
|
|
405
|
-
blocks
|
|
399
|
+
blocks,
|
|
406
400
|
};
|
|
407
401
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF 页边距按上、右、下、左排列,单位为毫米。
|
|
3
|
+
* @example 模块内部上下文
|
|
4
|
+
* ```ts
|
|
5
|
+
* const topMargin = BROWSER_PDF_MARGIN_MM[0]
|
|
6
|
+
* ```
|
|
7
|
+
*/
|
|
8
|
+
export declare const BROWSER_PDF_MARGIN_MM: readonly [14, 12, 14, 12];
|
|
9
|
+
/**
|
|
10
|
+
* PDF 正文宽度,单位为毫米。
|
|
11
|
+
* @example 模块内部上下文
|
|
12
|
+
* ```ts
|
|
13
|
+
* const pdfWidth = BROWSER_PDF_CONTENT_WIDTH_MM
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const BROWSER_PDF_CONTENT_WIDTH_MM: number;
|
|
17
|
+
/**
|
|
18
|
+
* 按每页可用高度及接近页底的空白行选择断点。页面画布由调用者按顺序复用。
|
|
19
|
+
* @example 模块内部上下文
|
|
20
|
+
* ```ts
|
|
21
|
+
* const source = new OffscreenCanvas(794, 1123)
|
|
22
|
+
* const page = new OffscreenCanvas(1, 1)
|
|
23
|
+
* const pages = sliceCanvasPages(source, page)
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function sliceCanvasPages(canvas: HTMLCanvasElement | OffscreenCanvas, pageCanvas: HTMLCanvasElement | OffscreenCanvas): Generator<number>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const BROWSER_PDF_PAGE_HEIGHT_MM = 297;
|
|
2
|
+
/**
|
|
3
|
+
* PDF 页边距按上、右、下、左排列,单位为毫米。
|
|
4
|
+
* @example 模块内部上下文
|
|
5
|
+
* ```ts
|
|
6
|
+
* const topMargin = BROWSER_PDF_MARGIN_MM[0]
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export const BROWSER_PDF_MARGIN_MM = [14, 12, 14, 12];
|
|
10
|
+
/**
|
|
11
|
+
* PDF 正文宽度,单位为毫米。
|
|
12
|
+
* @example 模块内部上下文
|
|
13
|
+
* ```ts
|
|
14
|
+
* const pdfWidth = BROWSER_PDF_CONTENT_WIDTH_MM
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const BROWSER_PDF_CONTENT_WIDTH_MM = 210 - BROWSER_PDF_MARGIN_MM[1] - BROWSER_PDF_MARGIN_MM[3];
|
|
18
|
+
const BROWSER_PDF_CONTENT_HEIGHT_MM = BROWSER_PDF_PAGE_HEIGHT_MM - BROWSER_PDF_MARGIN_MM[0] - BROWSER_PDF_MARGIN_MM[2];
|
|
19
|
+
const BROWSER_PDF_PAGE_BREAK_SEARCH_RATIO = 0.12;
|
|
20
|
+
const BROWSER_PDF_PAGE_BREAK_SEARCH_MAX_PX = 160;
|
|
21
|
+
const BROWSER_PDF_PAGE_BREAK_SEARCH_MIN_PX = 24;
|
|
22
|
+
const BROWSER_PDF_PAGE_BREAK_SAMPLE_STEP_PX = 4;
|
|
23
|
+
const BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD = 246;
|
|
24
|
+
const BROWSER_PDF_PAGE_BREAK_ALPHA_THRESHOLD = 12;
|
|
25
|
+
const BROWSER_PDF_PAGE_BREAK_EMPTY_ROW_MAX_INK = 1;
|
|
26
|
+
function canvas2d(canvas, options) {
|
|
27
|
+
// 两种画布都提供 2D 重载,公共签名避免联合重载回退到其他渲染上下文。
|
|
28
|
+
const surface = canvas;
|
|
29
|
+
return surface.getContext('2d', options);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 按每页可用高度及接近页底的空白行选择断点。页面画布由调用者按顺序复用。
|
|
33
|
+
* @example 模块内部上下文
|
|
34
|
+
* ```ts
|
|
35
|
+
* const source = new OffscreenCanvas(794, 1123)
|
|
36
|
+
* const page = new OffscreenCanvas(1, 1)
|
|
37
|
+
* const pages = sliceCanvasPages(source, page)
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function* sliceCanvasPages(canvas, pageCanvas) {
|
|
41
|
+
const pageContext = canvas2d(pageCanvas);
|
|
42
|
+
if (!pageContext) {
|
|
43
|
+
throw new Error('Failed to prepare PDF page canvas');
|
|
44
|
+
}
|
|
45
|
+
const pixelsPerMillimeter = canvas.width / BROWSER_PDF_CONTENT_WIDTH_MM;
|
|
46
|
+
const pageHeightPx = Math.max(1, Math.floor(BROWSER_PDF_CONTENT_HEIGHT_MM * pixelsPerMillimeter));
|
|
47
|
+
const sourceContext = canvas2d(canvas, { willReadFrequently: true });
|
|
48
|
+
for (let sourceY = 0; sourceY < canvas.height;) {
|
|
49
|
+
const remainingHeightPx = canvas.height - sourceY;
|
|
50
|
+
const sliceHeightPx = remainingHeightPx > pageHeightPx && sourceContext
|
|
51
|
+
? resolveCanvasPageSliceHeight(sourceContext, canvas, sourceY, pageHeightPx)
|
|
52
|
+
: Math.min(pageHeightPx, remainingHeightPx);
|
|
53
|
+
pageCanvas.width = canvas.width;
|
|
54
|
+
pageCanvas.height = sliceHeightPx;
|
|
55
|
+
pageContext.fillStyle = '#ffffff';
|
|
56
|
+
pageContext.fillRect(0, 0, pageCanvas.width, pageCanvas.height);
|
|
57
|
+
pageContext.drawImage(canvas, 0, sourceY, canvas.width, sliceHeightPx, 0, 0, canvas.width, sliceHeightPx);
|
|
58
|
+
yield sliceHeightPx / pixelsPerMillimeter;
|
|
59
|
+
sourceY += sliceHeightPx;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function resolveCanvasPageSliceHeight(sourceContext, canvas, sourceY, pageHeightPx) {
|
|
63
|
+
const searchRadiusPx = Math.max(BROWSER_PDF_PAGE_BREAK_SEARCH_MIN_PX, Math.min(BROWSER_PDF_PAGE_BREAK_SEARCH_MAX_PX, Math.floor(pageHeightPx * BROWSER_PDF_PAGE_BREAK_SEARCH_RATIO)));
|
|
64
|
+
const scanStartY = Math.max(sourceY + 1, sourceY + pageHeightPx - searchRadiusPx);
|
|
65
|
+
const scanEndY = Math.min(sourceY + pageHeightPx, canvas.height);
|
|
66
|
+
const scanHeight = scanEndY - scanStartY;
|
|
67
|
+
if (scanHeight <= 0) {
|
|
68
|
+
return Math.min(pageHeightPx, canvas.height - sourceY);
|
|
69
|
+
}
|
|
70
|
+
const imageData = sourceContext.getImageData(0, scanStartY, canvas.width, scanHeight);
|
|
71
|
+
const bestBreakY = findCanvasPageBreakY(imageData, scanStartY);
|
|
72
|
+
return Math.max(1, Math.min(bestBreakY - sourceY, canvas.height - sourceY));
|
|
73
|
+
}
|
|
74
|
+
function findCanvasPageBreakY(imageData, scanStartY) {
|
|
75
|
+
const rowWidth = imageData.width;
|
|
76
|
+
const rowHeight = imageData.height;
|
|
77
|
+
const rowStride = rowWidth * 4;
|
|
78
|
+
let bestEmptyRowY = 0;
|
|
79
|
+
let bestInkRowY = 0;
|
|
80
|
+
let lowestInkScore = Number.POSITIVE_INFINITY;
|
|
81
|
+
for (let rowIndex = 0; rowIndex < rowHeight; rowIndex += 1) {
|
|
82
|
+
const rowInkScore = measureCanvasRowInk(imageData.data, rowIndex * rowStride, rowWidth);
|
|
83
|
+
if (rowInkScore <= BROWSER_PDF_PAGE_BREAK_EMPTY_ROW_MAX_INK) {
|
|
84
|
+
bestEmptyRowY = scanStartY + rowIndex + 1;
|
|
85
|
+
}
|
|
86
|
+
if (rowInkScore <= lowestInkScore) {
|
|
87
|
+
lowestInkScore = rowInkScore;
|
|
88
|
+
bestInkRowY = scanStartY + rowIndex + 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return bestEmptyRowY || bestInkRowY || (scanStartY + rowHeight);
|
|
92
|
+
}
|
|
93
|
+
function measureCanvasRowInk(pixels, rowOffset, rowWidth) {
|
|
94
|
+
let inkScore = 0;
|
|
95
|
+
for (let column = 0; column < rowWidth; column += BROWSER_PDF_PAGE_BREAK_SAMPLE_STEP_PX) {
|
|
96
|
+
const pixelOffset = rowOffset + (column * 4);
|
|
97
|
+
const alpha = pixels[pixelOffset + 3];
|
|
98
|
+
if (alpha < BROWSER_PDF_PAGE_BREAK_ALPHA_THRESHOLD) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const red = pixels[pixelOffset];
|
|
102
|
+
const green = pixels[pixelOffset + 1];
|
|
103
|
+
const blue = pixels[pixelOffset + 2];
|
|
104
|
+
if (red < BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD
|
|
105
|
+
|| green < BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD
|
|
106
|
+
|| blue < BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD) {
|
|
107
|
+
inkScore += 1;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return inkScore;
|
|
111
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sliceCanvasPages } from './document-pdf-pages.js';
|
|
2
|
+
globalThis.addEventListener('message', async ({ data: bitmap }) => {
|
|
3
|
+
try {
|
|
4
|
+
const source = new OffscreenCanvas(bitmap.width, bitmap.height);
|
|
5
|
+
const context = source.getContext('2d', { willReadFrequently: true });
|
|
6
|
+
if (!context)
|
|
7
|
+
throw new Error('Failed to prepare PDF source canvas');
|
|
8
|
+
context.drawImage(bitmap, 0, 0);
|
|
9
|
+
bitmap.close();
|
|
10
|
+
const page = new OffscreenCanvas(1, 1);
|
|
11
|
+
const pages = [];
|
|
12
|
+
for (const height of sliceCanvasPages(source, page)) {
|
|
13
|
+
const image = await page.convertToBlob({ type: 'image/png' });
|
|
14
|
+
pages.push({
|
|
15
|
+
bytes: new Uint8Array(await image.arrayBuffer()),
|
|
16
|
+
height,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
globalThis.postMessage(pages, {
|
|
20
|
+
transfer: pages.map(item => item.bytes.buffer),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
globalThis.postMessage(undefined);
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
bitmap.close();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MarkdownRenderResult } from './document-parse.js';
|
|
2
|
+
import type { DocumentRenderJob } from './document-render-worker.js';
|
|
3
|
+
/**
|
|
4
|
+
* 浏览器长文档共用解析池。SSR 和短文档直接使用已有渲染器。
|
|
5
|
+
* @example 模块内部上下文
|
|
6
|
+
* ```ts
|
|
7
|
+
* const result = await documentRenderPool.run({ content: '# Report', locale: 'en-US' })
|
|
8
|
+
* if (result.success) void result.data.outline
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const documentRenderPool: import("@h-ai/core").WorkerPool<DocumentRenderJob, MarkdownRenderResult>;
|
|
12
|
+
/**
|
|
13
|
+
* 小文档同步渲染,以便在一次更新内保留 DOM 和选区行为。
|
|
14
|
+
* @example 模块内部上下文
|
|
15
|
+
* ```ts
|
|
16
|
+
* const eligible = useDocumentRenderWorker('# Article')
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function useDocumentRenderWorker(content: string): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { core } from '@h-ai/core';
|
|
2
|
+
/**
|
|
3
|
+
* 浏览器长文档共用解析池。SSR 和短文档直接使用已有渲染器。
|
|
4
|
+
* @example 模块内部上下文
|
|
5
|
+
* ```ts
|
|
6
|
+
* const result = await documentRenderPool.run({ content: '# Report', locale: 'en-US' })
|
|
7
|
+
* if (result.success) void result.data.outline
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export const documentRenderPool = core.worker.createPool(() => new Worker(new URL('./document-render-worker.js', import.meta.url), { type: 'module' }), { maxWorkers: 2, maxQueuedJobs: 4, idleTimeoutMs: 15_000 });
|
|
11
|
+
/**
|
|
12
|
+
* 小文档同步渲染,以便在一次更新内保留 DOM 和选区行为。
|
|
13
|
+
* @example 模块内部上下文
|
|
14
|
+
* ```ts
|
|
15
|
+
* const eligible = useDocumentRenderWorker('# Article')
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function useDocumentRenderWorker(content) {
|
|
19
|
+
return typeof Worker !== 'undefined' && content.length >= 32 * 1024;
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MarkdownDocumentParseOptions } from './document-parse.js';
|
|
2
|
+
/**
|
|
3
|
+
* 文档 Worker 只接收 Markdown、宿主语言及渲染选项。
|
|
4
|
+
* @example 模块内部上下文
|
|
5
|
+
* ```ts
|
|
6
|
+
* const job: DocumentRenderJob = { content: '# Report', locale: 'en-US', options: { enableHighlight: true } }
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export interface DocumentRenderJob {
|
|
10
|
+
content: string;
|
|
11
|
+
locale: string;
|
|
12
|
+
options?: MarkdownDocumentParseOptions;
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { core } from '@h-ai/core';
|
|
2
|
+
import { renderMarkdownDocument } from './document-parse.js';
|
|
3
|
+
globalThis.addEventListener('message', ({ data }) => {
|
|
4
|
+
core.i18n.setGlobalLocale(data.locale);
|
|
5
|
+
const result = renderMarkdownDocument(data.content, data.options);
|
|
6
|
+
globalThis.postMessage(result);
|
|
7
|
+
});
|
|
@@ -120,21 +120,13 @@ export interface MarkdownRewriteRequest {
|
|
|
120
120
|
actionId: string;
|
|
121
121
|
/** 当前选中的原文。 */
|
|
122
122
|
selectedText: string;
|
|
123
|
+
/** 可视正文中的精确纯文本偏移;宿主可据此映射原始 Markdown,不以纯文本猜测源码位置。 */
|
|
124
|
+
selectionSnapshot?: MarkdownSelectionSnapshot;
|
|
123
125
|
/** 触发请求时的完整文档内容。 */
|
|
124
126
|
content: string;
|
|
125
127
|
/** 当前文档标题。 */
|
|
126
128
|
title?: string;
|
|
127
129
|
}
|
|
128
|
-
/**
|
|
129
|
-
* 块级快捷操作种类:标题或列表。
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```ts
|
|
133
|
-
* import type { MarkdownBlockFormatKind } from '@h-ai/ui'
|
|
134
|
-
* const example: MarkdownBlockFormatKind = 'heading'
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
export type MarkdownBlockFormatKind = 'heading' | 'bullet';
|
|
138
130
|
/**
|
|
139
131
|
* 当前工具栏支持的具体段落和标题样式。
|
|
140
132
|
*
|
|
@@ -357,8 +349,6 @@ export interface AiDocumentEditorProps extends DataAttributes {
|
|
|
357
349
|
onhistory?: () => void;
|
|
358
350
|
/** 宿主自定义的整篇复制操作。 */
|
|
359
351
|
oncopydocument?: () => void | Promise<void>;
|
|
360
|
-
/** 标题/列表快捷格式操作回调。 */
|
|
361
|
-
onapplyblockformat?: BivariantCallback<[kind: MarkdownBlockFormatKind], void>;
|
|
362
352
|
/** 切换段落或具体标题级别的回调。 */
|
|
363
353
|
onapplyblockstyle?: BivariantCallback<[kind: MarkdownBlockStyleKind], void>;
|
|
364
354
|
/** 选区工具栏的行内格式回调。 */
|
|
@@ -53,7 +53,9 @@ function sanitizeColor(value) {
|
|
|
53
53
|
return undefined;
|
|
54
54
|
}
|
|
55
55
|
const normalized = value.trim().toLowerCase();
|
|
56
|
-
return HEX_COLOR_REGEX.test(normalized)
|
|
56
|
+
return HEX_COLOR_REGEX.test(normalized)
|
|
57
|
+
? normalized
|
|
58
|
+
: undefined;
|
|
57
59
|
}
|
|
58
60
|
function sanitizeAlign(value) {
|
|
59
61
|
if (!value) {
|
|
@@ -146,8 +148,12 @@ export function createEditorMarkdownExtensions() {
|
|
|
146
148
|
renderer(token) {
|
|
147
149
|
const spanToken = token;
|
|
148
150
|
const style = [
|
|
149
|
-
spanToken.color
|
|
150
|
-
|
|
151
|
+
spanToken.color
|
|
152
|
+
? `color:${spanToken.color}`
|
|
153
|
+
: '',
|
|
154
|
+
spanToken.background
|
|
155
|
+
? `background-color:${spanToken.background}`
|
|
156
|
+
: '',
|
|
151
157
|
].filter(Boolean).join(';');
|
|
152
158
|
if (!style) {
|
|
153
159
|
return this.parser.parseInline(spanToken.tokens);
|
|
@@ -124,7 +124,9 @@ function resolveLang(lang) {
|
|
|
124
124
|
return null;
|
|
125
125
|
const resolved = LANG_ALIASES[normalized] ?? normalized;
|
|
126
126
|
const loaded = highlighter.getLoadedLanguages();
|
|
127
|
-
return loaded.includes(resolved)
|
|
127
|
+
return loaded.includes(resolved)
|
|
128
|
+
? resolved
|
|
129
|
+
: null;
|
|
128
130
|
}
|
|
129
131
|
/**
|
|
130
132
|
* 从 codeToHtml 输出中提取 <code> 标签内的 innerHTML
|
|
@@ -11,10 +11,13 @@ export { downloadAiDocument, resolveDocumentDownloadActions, resolveDocumentMark
|
|
|
11
11
|
export type { AiDocumentDownloadFormat, AiDocumentDownloadRequest, AiDocumentResolvedDownloadAction, } from './document-download.js';
|
|
12
12
|
export { renderMarkdownDocument } from './document-parse.js';
|
|
13
13
|
export type { MarkdownDocumentBlock, MarkdownDocumentHtmlBlock, MarkdownDocumentMermaidBlock, MarkdownDocumentParseOptions, MarkdownRenderResult, } from './document-parse.js';
|
|
14
|
-
export type { AiDocumentEditorProps,
|
|
14
|
+
export type { AiDocumentEditorProps, MarkdownBlockStyleKind, MarkdownCodeBlockItem, MarkdownCodeRunRequest, MarkdownCodeRunResult, MarkdownColorFormatRequest, MarkdownInlineFormatKind, MarkdownOutlineItem, MarkdownRewriteAction, MarkdownRewriteRequest, MarkdownTextAlignKind, MarkdownToolbarDownloadAction, } from './document-types.js';
|
|
15
15
|
export { highlightCode, isLanguageSupported } from './highlight.js';
|
|
16
16
|
export { parseMarkdown } from './markdown-parse.js';
|
|
17
17
|
export type { MarkdownParseOptions } from './markdown-parse.js';
|
|
18
18
|
export { default as MarkdownRenderer } from './MarkdownRenderer.svelte';
|
|
19
|
+
export { default as AiMindMapEditor } from './mind/AiMindMapEditor.svelte';
|
|
20
|
+
export { fromMindElixirData, toMindElixirData } from './mind/mind-adapter.js';
|
|
21
|
+
export type { AiMindMapChangePayload, AiMindMapData, AiMindMapEditorProps, AiMindMapExportFormat, AiMindMapNode, AiMindMapSelection } from './mind/mind-types.js';
|
|
19
22
|
export { default as AiTableEditor } from './table/AiTableEditor.svelte';
|
|
20
23
|
export type { AiTableColumn, AiTableColumnType, AiTableCopyPayload, AiTableData, AiTableDownloadPayload, AiTableEditorChangeAction, AiTableEditorChangePayload, AiTableEditorProps, AiTableRow, } from './table/table-types.js';
|
|
@@ -13,4 +13,6 @@ export { renderMarkdownDocument } from './document-parse.js';
|
|
|
13
13
|
export { highlightCode, isLanguageSupported } from './highlight.js';
|
|
14
14
|
export { parseMarkdown } from './markdown-parse.js';
|
|
15
15
|
export { default as MarkdownRenderer } from './MarkdownRenderer.svelte';
|
|
16
|
+
export { default as AiMindMapEditor } from './mind/AiMindMapEditor.svelte';
|
|
17
|
+
export { fromMindElixirData, toMindElixirData } from './mind/mind-adapter.js';
|
|
16
18
|
export { default as AiTableEditor } from './table/AiTableEditor.svelte';
|
|
@@ -26,11 +26,15 @@ function createTableCellAttrs(cell) {
|
|
|
26
26
|
if (cell.text.trim()) {
|
|
27
27
|
attrs.push(`title="${escapeHtml(cell.text)}"`);
|
|
28
28
|
}
|
|
29
|
-
return attrs.length > 0
|
|
29
|
+
return attrs.length > 0
|
|
30
|
+
? ` ${attrs.join(' ')}`
|
|
31
|
+
: '';
|
|
30
32
|
}
|
|
31
33
|
/** 围栏代码和 HTML 代码共用渲染,颜色与复制控件始终由框架生成。 */
|
|
32
34
|
function renderCodeBlock(text, lang, options) {
|
|
33
|
-
const language = lang && isLanguageSupported(lang)
|
|
35
|
+
const language = lang && isLanguageSupported(lang)
|
|
36
|
+
? lang
|
|
37
|
+
: '';
|
|
34
38
|
let highlighted;
|
|
35
39
|
if (options.enableHighlight && language) {
|
|
36
40
|
highlighted = highlightCode(text, language);
|
|
@@ -50,17 +54,30 @@ function renderCodeBlock(text, lang, options) {
|
|
|
50
54
|
: '';
|
|
51
55
|
return `<div class="hai-md-code-block">`
|
|
52
56
|
+ `<div class="hai-md-code-header">${langLabel}${copyBtn}</div>`
|
|
53
|
-
+ `<pre><code class="hai-hl${language
|
|
57
|
+
+ `<pre><code class="hai-hl${language
|
|
58
|
+
? ` language-${escapeHtml(language)}`
|
|
59
|
+
: ''}">${highlighted}</code></pre>`
|
|
54
60
|
+ `</div>`;
|
|
55
61
|
}
|
|
56
62
|
/** 仅还原代码文本的实体;随后仍按普通代码转义,绝不把代码中的标签作为 HTML 执行。 */
|
|
57
63
|
function decodeCodeText(text) {
|
|
58
|
-
const named = {
|
|
64
|
+
const named = {
|
|
65
|
+
amp: '&',
|
|
66
|
+
lt: '<',
|
|
67
|
+
gt: '>',
|
|
68
|
+
quot: '"',
|
|
69
|
+
apos: '\'',
|
|
70
|
+
nbsp: '\u00A0',
|
|
71
|
+
};
|
|
59
72
|
return text.replace(/&(#(?:[xX][\da-fA-F]+|\d+)|amp|lt|gt|quot|apos|nbsp);/g, (entity, key) => {
|
|
60
73
|
if (!key.startsWith('#'))
|
|
61
74
|
return named[key] ?? entity;
|
|
62
|
-
const code = key[1]?.toLowerCase() === 'x'
|
|
63
|
-
|
|
75
|
+
const code = key[1]?.toLowerCase() === 'x'
|
|
76
|
+
? Number.parseInt(key.slice(2), 16)
|
|
77
|
+
: Number(key.slice(1));
|
|
78
|
+
return code > 0 && code <= 0x10FFFF && !(code >= 0xD800 && code <= 0xDFFF)
|
|
79
|
+
? String.fromCodePoint(code)
|
|
80
|
+
: entity;
|
|
64
81
|
});
|
|
65
82
|
}
|
|
66
83
|
/** 重建 pre/code,不保留输入的 style、事件或任意 class;其余 HTML 继续通过原有白名单。 */
|
|
@@ -103,7 +120,9 @@ function createRendererObject(options) {
|
|
|
103
120
|
const isExternal = safeHref && isExternalLinkHref(safeHref);
|
|
104
121
|
const attrs = [
|
|
105
122
|
`href="${escapeHtml(safeHref)}"`,
|
|
106
|
-
title
|
|
123
|
+
title
|
|
124
|
+
? `title="${escapeHtml(title)}"`
|
|
125
|
+
: '',
|
|
107
126
|
isExternal ? 'target="_blank" rel="noopener noreferrer"' : '',
|
|
108
127
|
].filter(Boolean).join(' ');
|
|
109
128
|
return `<a ${attrs}>${text}</a>`;
|
|
@@ -115,7 +134,9 @@ function createRendererObject(options) {
|
|
|
115
134
|
const attrs = [
|
|
116
135
|
`src="${escapeHtml(safeSrc)}"`,
|
|
117
136
|
`alt="${escapeHtml(text || '')}"`,
|
|
118
|
-
title
|
|
137
|
+
title
|
|
138
|
+
? `title="${escapeHtml(title)}"`
|
|
139
|
+
: '',
|
|
119
140
|
'loading="lazy"',
|
|
120
141
|
'class="hai-md-img"',
|
|
121
142
|
].filter(Boolean).join(' ');
|
|
@@ -187,7 +208,10 @@ function getOptionsKey(options) {
|
|
|
187
208
|
export function parseMarkdown(content, options) {
|
|
188
209
|
if (!content)
|
|
189
210
|
return '';
|
|
190
|
-
const mergedOptions = {
|
|
211
|
+
const mergedOptions = {
|
|
212
|
+
...DEFAULT_OPTIONS,
|
|
213
|
+
...options,
|
|
214
|
+
};
|
|
191
215
|
const key = getOptionsKey(mergedOptions);
|
|
192
216
|
if (!cachedInstance || cachedOptionsKey !== key) {
|
|
193
217
|
cachedInstance = createMarkedInstance(mergedOptions);
|
|
@@ -195,5 +219,7 @@ export function parseMarkdown(content, options) {
|
|
|
195
219
|
}
|
|
196
220
|
const result = cachedInstance.parse(content);
|
|
197
221
|
// marked.parse 可能返回 string | Promise<string>,此处同步调用
|
|
198
|
-
return typeof result === 'string'
|
|
222
|
+
return typeof result === 'string'
|
|
223
|
+
? result
|
|
224
|
+
: '';
|
|
199
225
|
}
|
|
@@ -33,7 +33,19 @@ async function loadMermaid() {
|
|
|
33
33
|
securityLevel: 'strict',
|
|
34
34
|
theme: 'default',
|
|
35
35
|
// 不允许文档指令修改安全策略、消毒规则或注入页面级 CSS。
|
|
36
|
-
secure: [
|
|
36
|
+
secure: [
|
|
37
|
+
'secure',
|
|
38
|
+
'securityLevel',
|
|
39
|
+
'startOnLoad',
|
|
40
|
+
'maxTextSize',
|
|
41
|
+
'suppressErrorRendering',
|
|
42
|
+
'maxEdges',
|
|
43
|
+
'themeCSS',
|
|
44
|
+
'themeVariables',
|
|
45
|
+
'fontFamily',
|
|
46
|
+
'altFontFamily',
|
|
47
|
+
'dompurifyConfig',
|
|
48
|
+
],
|
|
37
49
|
});
|
|
38
50
|
return mermaid;
|
|
39
51
|
});
|