@h-ai/ui 0.1.0-alpha9 → 1.0.0-beta.1
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 +1036 -0
- package/README.ja.md +1036 -0
- package/README.md +670 -119
- package/auto-import.d.ts +45 -0
- package/auto-import.js +46 -69
- package/dist/components/compounds/Accordion.svelte +30 -3
- package/dist/components/compounds/Accordion.svelte.d.ts +37 -1
- package/dist/components/compounds/ActionSheet.svelte +35 -8
- package/dist/components/compounds/ActionSheet.svelte.d.ts +41 -1
- package/dist/components/compounds/Alert.svelte +24 -15
- package/dist/components/compounds/Alert.svelte.d.ts +14 -3
- package/dist/components/compounds/AppBar.svelte +37 -9
- package/dist/components/compounds/AppBar.svelte.d.ts +36 -1
- package/dist/components/compounds/BottomNav.svelte +68 -8
- package/dist/components/compounds/BottomNav.svelte.d.ts +51 -1
- package/dist/components/compounds/Breadcrumb.svelte +18 -5
- package/dist/components/compounds/Breadcrumb.svelte.d.ts +23 -2
- package/dist/components/compounds/Calendar.svelte +31 -12
- package/dist/components/compounds/Calendar.svelte.d.ts +23 -7
- package/dist/components/compounds/Card.svelte +17 -5
- package/dist/components/compounds/Card.svelte.d.ts +13 -2
- package/dist/components/compounds/Combobox.svelte +124 -42
- package/dist/components/compounds/Combobox.svelte.d.ts +42 -20
- package/dist/components/compounds/Confirm.svelte +32 -9
- package/dist/components/compounds/Confirm.svelte.d.ts +24 -2
- package/dist/components/compounds/DataTable.svelte +317 -33
- package/dist/components/compounds/DataTable.svelte.d.ts +28 -14
- package/dist/components/compounds/DatePicker.svelte +62 -18
- package/dist/components/compounds/DatePicker.svelte.d.ts +27 -8
- package/dist/components/compounds/Drawer.svelte +179 -22
- package/dist/components/compounds/Drawer.svelte.d.ts +24 -2
- package/dist/components/compounds/Dropdown.svelte +19 -5
- package/dist/components/compounds/Dropdown.svelte.d.ts +13 -2
- package/dist/components/compounds/Empty.svelte +22 -9
- package/dist/components/compounds/Empty.svelte.d.ts +23 -2
- package/dist/components/compounds/FilterBar.svelte +82 -0
- package/dist/components/compounds/FilterBar.svelte.d.ts +39 -0
- package/dist/components/compounds/Form.svelte +59 -16
- package/dist/components/compounds/Form.svelte.d.ts +23 -2
- package/dist/components/compounds/FormField.svelte +99 -16
- package/dist/components/compounds/FormField.svelte.d.ts +23 -2
- package/dist/components/compounds/FormLayout.svelte +71 -0
- package/dist/components/compounds/FormLayout.svelte.d.ts +17 -0
- package/dist/components/compounds/InfiniteScroll.svelte +34 -7
- package/dist/components/compounds/InfiniteScroll.svelte.d.ts +37 -1
- package/dist/components/compounds/JsonViewer.svelte +214 -0
- package/dist/components/compounds/JsonViewer.svelte.d.ts +26 -0
- package/dist/components/compounds/MessageBoxContainer.svelte +34 -0
- package/dist/components/compounds/MessageBoxContainer.svelte.d.ts +25 -0
- package/dist/components/compounds/MessageBoxDialog.svelte +209 -0
- package/dist/components/compounds/MessageBoxDialog.svelte.d.ts +29 -0
- package/dist/components/compounds/MessageContainer.svelte +24 -0
- package/dist/components/compounds/MessageContainer.svelte.d.ts +18 -0
- package/dist/components/compounds/Modal.svelte +348 -73
- package/dist/components/compounds/Modal.svelte.d.ts +13 -2
- package/dist/components/compounds/PageHeader.svelte +44 -20
- package/dist/components/compounds/PageHeader.svelte.d.ts +24 -9
- package/dist/components/compounds/Pagination.svelte +139 -105
- package/dist/components/compounds/Pagination.svelte.d.ts +23 -2
- package/dist/components/compounds/Popover.svelte +124 -25
- package/dist/components/compounds/Popover.svelte.d.ts +23 -2
- package/dist/components/compounds/PullRefresh.svelte +35 -8
- package/dist/components/compounds/PullRefresh.svelte.d.ts +35 -1
- package/dist/components/compounds/Result.svelte +17 -4
- package/dist/components/compounds/Result.svelte.d.ts +23 -2
- package/dist/components/compounds/SafeArea.svelte +30 -3
- package/dist/components/compounds/SafeArea.svelte.d.ts +35 -1
- package/dist/components/compounds/Skeleton.svelte +19 -7
- package/dist/components/compounds/Skeleton.svelte.d.ts +13 -2
- package/dist/components/compounds/Steps.svelte +17 -4
- package/dist/components/compounds/Steps.svelte.d.ts +23 -2
- package/dist/components/compounds/SwipeCell.svelte +30 -3
- package/dist/components/compounds/SwipeCell.svelte.d.ts +40 -1
- package/dist/components/compounds/TableToolbar.svelte +289 -0
- package/dist/components/compounds/TableToolbar.svelte.d.ts +69 -0
- package/dist/components/compounds/Tabs.svelte +84 -14
- package/dist/components/compounds/Tabs.svelte.d.ts +13 -2
- package/dist/components/compounds/TagInput.svelte +51 -33
- package/dist/components/compounds/TagInput.svelte.d.ts +23 -2
- package/dist/components/compounds/Timeline.svelte +30 -3
- package/dist/components/compounds/Timeline.svelte.d.ts +37 -1
- package/dist/components/compounds/ToastContainer.svelte +386 -28
- package/dist/components/compounds/ToastContainer.svelte.d.ts +27 -1
- package/dist/components/compounds/Tooltip.svelte +143 -9
- package/dist/components/compounds/Tooltip.svelte.d.ts +25 -2
- package/dist/components/compounds/accordion-types.d.ts +10 -1
- package/dist/components/compounds/action-sheet-types.d.ts +9 -0
- package/dist/components/compounds/bottom-nav-types.d.ts +9 -0
- package/dist/components/compounds/index.d.ts +7 -0
- package/dist/components/compounds/index.js +11 -0
- package/dist/components/compounds/swipe-cell-types.d.ts +9 -0
- package/dist/components/compounds/timeline-types.d.ts +9 -0
- package/dist/components/control-size.d.ts +35 -0
- package/dist/components/control-size.js +26 -0
- package/dist/components/primitives/Avatar.svelte +19 -5
- package/dist/components/primitives/Avatar.svelte.d.ts +13 -2
- package/dist/components/primitives/Badge.svelte +16 -4
- package/dist/components/primitives/Badge.svelte.d.ts +13 -2
- package/dist/components/primitives/BareButton.svelte +26 -12
- package/dist/components/primitives/BareButton.svelte.d.ts +23 -2
- package/dist/components/primitives/BareInput.svelte +57 -35
- package/dist/components/primitives/BareInput.svelte.d.ts +23 -2
- package/dist/components/primitives/Button.svelte +30 -9
- package/dist/components/primitives/Button.svelte.d.ts +13 -2
- package/dist/components/primitives/Checkbox.svelte +24 -5
- package/dist/components/primitives/Checkbox.svelte.d.ts +23 -2
- package/dist/components/primitives/IconButton.svelte +35 -10
- package/dist/components/primitives/IconButton.svelte.d.ts +23 -2
- package/dist/components/primitives/Input.svelte +56 -26
- package/dist/components/primitives/Input.svelte.d.ts +13 -2
- package/dist/components/primitives/Progress.svelte +17 -4
- package/dist/components/primitives/Progress.svelte.d.ts +23 -2
- package/dist/components/primitives/Radio.svelte +17 -4
- package/dist/components/primitives/Radio.svelte.d.ts +22 -2
- package/dist/components/primitives/Range.svelte +31 -4
- package/dist/components/primitives/Range.svelte.d.ts +37 -1
- package/dist/components/primitives/Rating.svelte +32 -5
- package/dist/components/primitives/Rating.svelte.d.ts +37 -1
- package/dist/components/primitives/Select.svelte +404 -47
- package/dist/components/primitives/Select.svelte.d.ts +23 -2
- package/dist/components/primitives/Spinner.svelte +17 -4
- package/dist/components/primitives/Spinner.svelte.d.ts +23 -2
- package/dist/components/primitives/Switch.svelte +22 -4
- package/dist/components/primitives/Switch.svelte.d.ts +23 -2
- package/dist/components/primitives/Tag.svelte +17 -4
- package/dist/components/primitives/Tag.svelte.d.ts +23 -2
- package/dist/components/primitives/Textarea.svelte +75 -30
- package/dist/components/primitives/Textarea.svelte.d.ts +24 -2
- package/dist/components/primitives/ToggleCheckbox.svelte +24 -10
- package/dist/components/primitives/ToggleCheckbox.svelte.d.ts +23 -2
- package/dist/components/primitives/ToggleInput.svelte +24 -10
- package/dist/components/primitives/ToggleInput.svelte.d.ts +23 -2
- package/dist/components/primitives/ToggleRadio.svelte +24 -10
- package/dist/components/primitives/ToggleRadio.svelte.d.ts +23 -2
- package/dist/components/scenes/ai/AiDocumentDownloadMenu.svelte +54 -23
- package/dist/components/scenes/ai/AiDocumentDownloadMenu.svelte.d.ts +30 -1
- package/dist/components/scenes/ai/AiDocumentEditor.svelte +3428 -693
- package/dist/components/scenes/ai/AiDocumentEditor.svelte.d.ts +26 -1
- package/dist/components/scenes/ai/MarkdownRenderer.svelte +119 -116
- package/dist/components/scenes/ai/MarkdownRenderer.svelte.d.ts +31 -1
- package/dist/components/scenes/ai/code-preview.d.ts +46 -0
- package/dist/components/scenes/ai/code-preview.js +141 -0
- package/dist/components/scenes/ai/document-download.d.ts +52 -0
- package/dist/components/scenes/ai/document-download.js +296 -77
- package/dist/components/scenes/ai/document-parse.d.ts +101 -11
- package/dist/components/scenes/ai/document-parse.js +212 -48
- package/dist/components/scenes/ai/document-types.d.ts +292 -75
- package/dist/components/scenes/ai/editor-markdown-extensions.d.ts +27 -0
- package/dist/components/scenes/ai/editor-markdown-extensions.js +215 -0
- package/dist/components/scenes/ai/highlight.d.ts +37 -0
- package/dist/components/scenes/ai/highlight.js +162 -0
- package/dist/components/scenes/ai/index.d.ts +5 -2
- package/dist/components/scenes/ai/index.js +3 -0
- package/dist/components/scenes/ai/markdown-parse.d.ts +11 -3
- package/dist/components/scenes/ai/markdown-parse.js +42 -31
- package/dist/components/scenes/ai/mermaid-host-sync.d.ts +72 -0
- package/dist/components/scenes/ai/mermaid-host-sync.js +65 -0
- package/dist/components/scenes/ai/mermaid-render.d.ts +30 -0
- package/dist/components/scenes/ai/mermaid-render.js +61 -0
- package/dist/components/scenes/ai/safe-html.d.ts +64 -0
- package/dist/components/scenes/ai/safe-html.js +345 -0
- package/dist/components/scenes/ai/table/AiTableEditor.svelte +1692 -0
- package/dist/components/scenes/ai/table/AiTableEditor.svelte.d.ts +32 -0
- package/dist/components/scenes/ai/table/table-types.d.ts +181 -0
- package/dist/components/scenes/ai/table/table-types.js +1 -0
- package/dist/components/scenes/app/FeedbackDetail.svelte +236 -0
- package/dist/components/scenes/app/FeedbackDetail.svelte.d.ts +40 -0
- package/dist/components/scenes/app/FeedbackForm.svelte +337 -0
- package/dist/components/scenes/app/FeedbackForm.svelte.d.ts +72 -0
- package/dist/components/scenes/app/FeedbackList.svelte +150 -0
- package/dist/components/scenes/app/FeedbackList.svelte.d.ts +28 -0
- package/dist/components/scenes/app/FeedbackModal.svelte +65 -139
- package/dist/components/scenes/app/FeedbackModal.svelte.d.ts +14 -39
- package/dist/components/scenes/app/FeedbackRecorder.svelte +154 -0
- package/dist/components/scenes/app/FeedbackRecorder.svelte.d.ts +9 -0
- package/dist/components/scenes/app/FeedbackReplay.svelte +142 -0
- package/dist/components/scenes/app/FeedbackReplay.svelte.d.ts +7 -0
- package/dist/components/scenes/app/FeedbackScreenshot.svelte +120 -0
- package/dist/components/scenes/app/FeedbackScreenshot.svelte.d.ts +8 -0
- package/dist/components/scenes/app/LanguageSwitch.svelte +38 -21
- package/dist/components/scenes/app/LanguageSwitch.svelte.d.ts +33 -20
- package/dist/components/scenes/app/SettingsLayout.svelte +115 -0
- package/dist/components/scenes/app/SettingsLayout.svelte.d.ts +54 -0
- package/dist/components/scenes/app/SettingsModal.svelte +33 -7
- package/dist/components/scenes/app/SettingsModal.svelte.d.ts +27 -1
- package/dist/components/scenes/app/ThemeColorPicker.svelte +240 -0
- package/dist/components/scenes/app/ThemeColorPicker.svelte.d.ts +57 -0
- package/dist/components/scenes/app/ThemeSelector.svelte +87 -26
- package/dist/components/scenes/app/ThemeSelector.svelte.d.ts +26 -7
- package/dist/components/scenes/app/ThemeToggle.svelte +27 -6
- package/dist/components/scenes/app/ThemeToggle.svelte.d.ts +24 -5
- package/dist/components/scenes/app/WorkspaceLayout.svelte +64 -0
- package/dist/components/scenes/app/WorkspaceLayout.svelte.d.ts +36 -0
- package/dist/components/scenes/app/feedback-functions.d.ts +57 -0
- package/dist/components/scenes/app/feedback-functions.js +107 -0
- package/dist/components/scenes/app/feedback-types.d.ts +224 -0
- package/dist/components/scenes/app/feedback-types.js +1 -0
- package/dist/components/scenes/app/index.d.ts +8 -1
- package/dist/components/scenes/app/index.js +7 -1
- package/dist/components/scenes/charts/Chart.svelte +163 -0
- package/dist/components/scenes/charts/Chart.svelte.d.ts +25 -0
- package/dist/components/scenes/charts/chart-theme.d.ts +47 -0
- package/dist/components/scenes/charts/chart-theme.js +68 -0
- package/dist/components/scenes/charts/chart-types.d.ts +153 -0
- package/dist/components/scenes/charts/chart-types.js +7 -0
- package/dist/components/scenes/charts/index.d.ts +8 -0
- package/dist/components/scenes/charts/index.js +7 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte +18 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte.d.ts +5 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte +18 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte.d.ts +5 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte +624 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +32 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte +18 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte.d.ts +5 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte +18 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte.d.ts +5 -0
- package/dist/components/scenes/crud/CrudDeleteConfirm.svelte +29 -11
- package/dist/components/scenes/crud/CrudDeleteConfirm.svelte.d.ts +13 -1
- package/dist/components/scenes/crud/CrudDetailDrawer.svelte +77 -22
- package/dist/components/scenes/crud/CrudDetailDrawer.svelte.d.ts +19 -4
- package/dist/components/scenes/crud/CrudDetailPanel.svelte +242 -0
- package/dist/components/scenes/crud/CrudDetailPanel.svelte.d.ts +66 -0
- package/dist/components/scenes/crud/CrudEditPanel.svelte +365 -0
- package/dist/components/scenes/crud/CrudEditPanel.svelte.d.ts +48 -0
- package/dist/components/scenes/crud/CrudFilterBar.svelte +17 -85
- package/dist/components/scenes/crud/CrudFilterBar.svelte.d.ts +13 -25
- package/dist/components/scenes/crud/CrudPage.svelte +564 -185
- package/dist/components/scenes/crud/CrudPage.svelte.d.ts +137 -51
- package/dist/components/scenes/crud/crud-controller.svelte.d.ts +335 -0
- package/dist/components/scenes/crud/crud-controller.svelte.js +276 -0
- package/dist/components/scenes/crud/crud-form-validation.d.ts +16 -0
- package/dist/components/scenes/crud/crud-form-validation.js +51 -0
- package/dist/components/scenes/crud/crud-types.d.ts +136 -43
- package/dist/components/scenes/crud/index.d.ts +9 -3
- package/dist/components/scenes/crud/index.js +8 -3
- package/dist/components/scenes/crud/nav-adapter.d.ts +50 -0
- package/dist/components/scenes/crud/nav-adapter.js +39 -0
- package/dist/components/scenes/crypto/EncryptedInput.svelte +63 -28
- package/dist/components/scenes/crypto/EncryptedInput.svelte.d.ts +38 -3
- package/dist/components/scenes/crypto/HashDisplay.svelte +30 -22
- package/dist/components/scenes/crypto/HashDisplay.svelte.d.ts +24 -1
- package/dist/components/scenes/crypto/SignatureDisplay.svelte +41 -40
- package/dist/components/scenes/crypto/SignatureDisplay.svelte.d.ts +24 -1
- package/dist/components/scenes/error/ErrorPage.svelte +135 -0
- package/dist/components/scenes/error/ErrorPage.svelte.d.ts +50 -0
- package/dist/components/scenes/error/error-presets.d.ts +60 -0
- package/dist/components/scenes/error/error-presets.js +51 -0
- package/dist/components/scenes/error/index.d.ts +8 -0
- package/dist/components/scenes/error/index.js +8 -0
- package/dist/components/scenes/guide/GuideHost.svelte +56 -0
- package/dist/components/scenes/guide/GuideHost.svelte.d.ts +35 -0
- package/dist/components/scenes/guide/GuideHostContent.svelte +136 -0
- package/dist/components/scenes/guide/GuideHostContent.svelte.d.ts +43 -0
- package/dist/components/scenes/guide/HelpCenter.svelte +135 -0
- package/dist/components/scenes/guide/HelpCenter.svelte.d.ts +40 -0
- package/dist/components/scenes/guide/index.d.ts +2 -0
- package/dist/components/scenes/guide/index.js +2 -0
- package/dist/components/scenes/iam/AgreementNotice.svelte +48 -0
- package/dist/components/scenes/iam/AgreementNotice.svelte.d.ts +7 -0
- package/dist/components/scenes/iam/AuthPanel.svelte +226 -0
- package/dist/components/scenes/iam/AuthPanel.svelte.d.ts +29 -0
- package/dist/components/scenes/iam/AuthShell.svelte +160 -0
- package/dist/components/scenes/iam/AuthShell.svelte.d.ts +56 -0
- package/dist/components/scenes/iam/ChangePasswordForm.svelte +84 -63
- package/dist/components/scenes/iam/ChangePasswordForm.svelte.d.ts +13 -1
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte +113 -89
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte.d.ts +24 -1
- package/dist/components/scenes/iam/LoginForm.svelte +215 -117
- package/dist/components/scenes/iam/LoginForm.svelte.d.ts +13 -1
- package/dist/components/scenes/iam/PasswordInput.svelte +79 -32
- package/dist/components/scenes/iam/PasswordInput.svelte.d.ts +30 -4
- package/dist/components/scenes/iam/PermGuard.svelte +21 -11
- package/dist/components/scenes/iam/PermGuard.svelte.d.ts +30 -0
- package/dist/components/scenes/iam/ReauthenticationDialog.svelte +68 -0
- package/dist/components/scenes/iam/ReauthenticationDialog.svelte.d.ts +17 -0
- package/dist/components/scenes/iam/RegisterForm.svelte +129 -116
- package/dist/components/scenes/iam/RegisterForm.svelte.d.ts +13 -1
- package/dist/components/scenes/iam/ResetPasswordForm.svelte +101 -88
- package/dist/components/scenes/iam/ResetPasswordForm.svelte.d.ts +13 -1
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +76 -0
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte.d.ts +21 -0
- package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +64 -0
- package/dist/components/scenes/iam/SessionRecoveryDialog.svelte.d.ts +22 -0
- package/dist/components/scenes/iam/UserProfile.svelte +47 -21
- package/dist/components/scenes/iam/UserProfile.svelte.d.ts +24 -1
- package/dist/components/scenes/iam/auth-captcha.d.ts +21 -0
- package/dist/components/scenes/iam/auth-captcha.js +23 -0
- package/dist/components/scenes/iam/auth-error-message.d.ts +13 -0
- package/dist/components/scenes/iam/auth-error-message.js +65 -0
- package/dist/components/scenes/iam/index.d.ts +10 -0
- package/dist/components/scenes/iam/index.js +9 -1
- package/dist/components/scenes/iam/password-utils.d.ts +33 -6
- package/dist/components/scenes/iam/password-utils.js +61 -8
- package/dist/components/scenes/iam/permission-context.svelte.d.ts +33 -23
- package/dist/components/scenes/iam/permission-context.svelte.js +20 -22
- package/dist/components/scenes/iam/sensitive-actions.svelte.d.ts +68 -0
- package/dist/components/scenes/iam/sensitive-actions.svelte.js +101 -0
- package/dist/components/scenes/iam/session-recovery.svelte.d.ts +44 -0
- package/dist/components/scenes/iam/session-recovery.svelte.js +57 -0
- package/dist/components/scenes/index.d.ts +3 -0
- package/dist/components/scenes/index.js +5 -0
- package/dist/components/scenes/storage/AvatarUpload.svelte +82 -68
- package/dist/components/scenes/storage/AvatarUpload.svelte.d.ts +23 -1
- package/dist/components/scenes/storage/FileList.svelte +19 -5
- package/dist/components/scenes/storage/FileList.svelte.d.ts +23 -1
- package/dist/components/scenes/storage/FileUpload.svelte +151 -96
- package/dist/components/scenes/storage/FileUpload.svelte.d.ts +24 -1
- package/dist/components/scenes/storage/ImageUpload.svelte +93 -94
- package/dist/components/scenes/storage/ImageUpload.svelte.d.ts +24 -1
- package/dist/components/scenes/types.d.ts +574 -42
- package/dist/guide-storage.d.ts +18 -0
- package/dist/guide-storage.js +79 -0
- package/dist/guide-types.d.ts +143 -0
- package/dist/guide-types.js +1 -0
- package/dist/guide.d.ts +3 -0
- package/dist/guide.js +3 -0
- package/dist/guide.svelte.d.ts +29 -0
- package/dist/guide.svelte.js +506 -0
- package/dist/i18n.svelte.d.ts +67 -4
- package/dist/i18n.svelte.js +106 -21
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/internal/browser-safety.d.ts +88 -0
- package/dist/internal/browser-safety.js +140 -0
- package/dist/internal/dialog-focus.d.ts +21 -0
- package/dist/internal/dialog-focus.js +77 -0
- package/dist/internal/form-context.d.ts +92 -0
- package/dist/internal/form-context.js +70 -0
- package/dist/internal/form-validation.svelte.d.ts +70 -0
- package/dist/internal/form-validation.svelte.js +142 -0
- package/dist/internal/icon-safety.d.ts +14 -0
- package/dist/internal/icon-safety.js +40 -0
- package/dist/internal/locale.d.ts +21 -0
- package/dist/internal/locale.js +43 -0
- package/dist/message.svelte.d.ts +138 -0
- package/dist/message.svelte.js +149 -0
- package/dist/messagebox.svelte.d.ts +130 -0
- package/dist/messagebox.svelte.js +171 -0
- package/dist/messages/en-US.json +297 -16
- package/dist/messages/ja-JP.json +523 -0
- package/dist/messages/zh-CN.json +297 -16
- package/dist/messages.d.ts +25 -3
- package/dist/messages.js +23 -6
- package/dist/styles/design-tokens.css +4 -2
- package/dist/styles/formal.css +55 -0
- package/dist/styles/global.css +86 -18
- package/dist/styles/guide.css +88 -0
- package/dist/styles/high-contrast.css +64 -0
- package/dist/styles/mobile.css +28 -0
- package/dist/styles/theme.css +42 -0
- package/dist/theme-config.d.ts +263 -10
- package/dist/theme-config.js +252 -17
- package/dist/toast.svelte.d.ts +210 -2
- package/dist/toast.svelte.js +296 -19
- package/dist/types.d.ts +787 -63
- package/dist/utils/platform.svelte.d.ts +28 -15
- package/dist/utils/platform.svelte.js +23 -16
- package/dist/utils.d.ts +121 -1
- package/dist/utils.js +208 -13
- package/dist/workspace-context.d.ts +20 -0
- package/dist/workspace-context.js +9 -0
- package/package.json +120 -24
- package/vite.d.ts +13 -0
- package/vite.js +96 -0
- package/dist/components/scenes/crud/CrudEditDrawer.svelte +0 -225
- package/dist/components/scenes/crud/CrudEditDrawer.svelte.d.ts +0 -48
|
@@ -1,8 +1,48 @@
|
|
|
1
|
-
import { uiM } from '../../../messages.js';
|
|
1
|
+
import { getUILocale, uiM } from '../../../messages.js';
|
|
2
2
|
import { renderMarkdownDocument } from './document-parse.js';
|
|
3
|
+
const DOCUMENT_EXPORT_ROOT_CLASS = 'hai-ai-document-export';
|
|
4
|
+
const BROWSER_PDF_PAGE_HEIGHT_MM = 297;
|
|
5
|
+
const BROWSER_PDF_VIEWPORT_WIDTH_PX = 794;
|
|
6
|
+
const BROWSER_PDF_MARGIN_MM = [14, 12, 14, 12];
|
|
7
|
+
const BROWSER_PDF_CONTENT_WIDTH_MM = 210 - BROWSER_PDF_MARGIN_MM[1] - BROWSER_PDF_MARGIN_MM[3];
|
|
8
|
+
const BROWSER_PDF_CONTENT_HEIGHT_MM = BROWSER_PDF_PAGE_HEIGHT_MM - BROWSER_PDF_MARGIN_MM[0] - BROWSER_PDF_MARGIN_MM[2];
|
|
9
|
+
const BROWSER_PDF_PAGE_BREAK_SEARCH_RATIO = 0.12;
|
|
10
|
+
const BROWSER_PDF_PAGE_BREAK_SEARCH_MAX_PX = 160;
|
|
11
|
+
const BROWSER_PDF_PAGE_BREAK_SEARCH_MIN_PX = 24;
|
|
12
|
+
const BROWSER_PDF_PAGE_BREAK_SAMPLE_STEP_PX = 4;
|
|
13
|
+
const BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD = 246;
|
|
14
|
+
const BROWSER_PDF_PAGE_BREAK_ALPHA_THRESHOLD = 12;
|
|
15
|
+
const BROWSER_PDF_PAGE_BREAK_EMPTY_ROW_MAX_INK = 1;
|
|
16
|
+
function escapeExportHtml(value) {
|
|
17
|
+
return value
|
|
18
|
+
.replace(/&/g, '&')
|
|
19
|
+
.replace(/</g, '<')
|
|
20
|
+
.replace(/>/g, '>')
|
|
21
|
+
.replace(/"/g, '"')
|
|
22
|
+
.replace(/'/g, ''');
|
|
23
|
+
}
|
|
24
|
+
function renderDocumentBlocksForExport(blocks) {
|
|
25
|
+
return blocks.map((block) => {
|
|
26
|
+
if (block.kind === 'html') {
|
|
27
|
+
return block.html;
|
|
28
|
+
}
|
|
29
|
+
return `<pre><code class="language-${escapeExportHtml(block.language)}">${escapeExportHtml(block.code)}</code></pre>`;
|
|
30
|
+
}).join('\n');
|
|
31
|
+
}
|
|
3
32
|
/**
|
|
4
33
|
* code 类型产物通常只有裸代码正文。
|
|
5
34
|
* 下载和预览都通过同一份规范化逻辑包装成 fenced markdown,避免两边导出的结构不一致。
|
|
35
|
+
* @param value - 待处理或校验的值。
|
|
36
|
+
* @param kind - 本次操作输入,具体字段见参数类型。
|
|
37
|
+
* @param language - 待识别的语言标记。
|
|
38
|
+
* @returns 保留原文或按代码来源包装后的 Markdown。
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { resolveDocumentMarkdownContent } from '@h-ai/ui'
|
|
43
|
+
* const markdown = resolveDocumentMarkdownContent('const count = 42', 'code', 'typescript')
|
|
44
|
+
* // 裸代码会包装成足够长的 Markdown fence,保留源码中的反引号。
|
|
45
|
+
* ```
|
|
6
46
|
*/
|
|
7
47
|
export function resolveDocumentMarkdownContent(value, kind = 'markdown', language) {
|
|
8
48
|
if (kind !== 'code') {
|
|
@@ -16,6 +56,14 @@ export function resolveDocumentMarkdownContent(value, kind = 'markdown', languag
|
|
|
16
56
|
}
|
|
17
57
|
/**
|
|
18
58
|
* 把自定义动作和内置动作统一归一成统一的菜单项,保证左右两侧下载菜单展示一致。
|
|
59
|
+
* @param actions - 宿主提供的动作列表。
|
|
60
|
+
* @returns 具备显示标签的标准下载动作列表。
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { resolveDocumentDownloadActions } from '@h-ai/ui'
|
|
65
|
+
* const actions = resolveDocumentDownloadActions([{ id: 'markdown', label: 'Markdown', badgeLabel: 'MD' }])
|
|
66
|
+
* ```
|
|
19
67
|
*/
|
|
20
68
|
export function resolveDocumentDownloadActions(actions = []) {
|
|
21
69
|
if (actions.length === 0) {
|
|
@@ -38,6 +86,15 @@ export function resolveDocumentDownloadActions(actions = []) {
|
|
|
38
86
|
}
|
|
39
87
|
/**
|
|
40
88
|
* 执行内置下载动作;未知动作直接跳过,方便外层保留自定义回调扩展口。
|
|
89
|
+
* @param request - 包含来源、内容和动作标识的请求。
|
|
90
|
+
* @returns 下载流程的 Promise;SSR 或未知动作无操作。
|
|
91
|
+
* @throws 浏览器渲染、第三方解析或下载失败时抛出异常,由交互边界显示错误。
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { downloadAiDocument } from '@h-ai/ui'
|
|
96
|
+
* await downloadAiDocument({ actionId: 'markdown', content: '# 报告\n正文', title: '报告', filename: 'report.md', sourceKind: 'document' })
|
|
97
|
+
* ```
|
|
41
98
|
*/
|
|
42
99
|
export async function downloadAiDocument(request) {
|
|
43
100
|
if (typeof document === 'undefined') {
|
|
@@ -62,14 +119,15 @@ export async function downloadAiDocument(request) {
|
|
|
62
119
|
showRunButton: false,
|
|
63
120
|
breaks: true,
|
|
64
121
|
});
|
|
65
|
-
const
|
|
122
|
+
const renderedHtml = renderDocumentBlocksForExport(rendered.blocks);
|
|
123
|
+
const exportHtml = buildDocumentExportHtml(exportTitle, renderedHtml);
|
|
66
124
|
if (builtIn.id === 'word') {
|
|
67
125
|
downloadBlob(new Blob([`\uFEFF${exportHtml}`], {
|
|
68
126
|
type: 'application/msword;charset=utf-8',
|
|
69
127
|
}), `${baseName}.doc`);
|
|
70
128
|
return;
|
|
71
129
|
}
|
|
72
|
-
await
|
|
130
|
+
await downloadDocumentAsPdf(htmlToPdfFilename(exportTitle), renderedHtml);
|
|
73
131
|
}
|
|
74
132
|
function createBuiltInDownloadAction(format) {
|
|
75
133
|
switch (format) {
|
|
@@ -130,19 +188,10 @@ function escapeHtml(value) {
|
|
|
130
188
|
.replace(/"/g, '"')
|
|
131
189
|
.replace(/'/g, ''');
|
|
132
190
|
}
|
|
133
|
-
function
|
|
134
|
-
return
|
|
135
|
-
|
|
136
|
-
<head>
|
|
137
|
-
<meta charset="utf-8" />
|
|
138
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
139
|
-
<title>${escapeHtml(title)}</title>
|
|
140
|
-
<style>
|
|
141
|
-
:root {
|
|
191
|
+
function buildDocumentExportStyles() {
|
|
192
|
+
return `
|
|
193
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} {
|
|
142
194
|
color-scheme: light;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
body {
|
|
146
195
|
margin: 0;
|
|
147
196
|
padding: 0;
|
|
148
197
|
font-family:
|
|
@@ -152,60 +201,60 @@ function buildDocumentExportHtml(title, bodyHtml) {
|
|
|
152
201
|
background: #ffffff;
|
|
153
202
|
}
|
|
154
203
|
|
|
155
|
-
main {
|
|
204
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} main {
|
|
156
205
|
max-width: 860px;
|
|
157
206
|
margin: 0 auto;
|
|
158
207
|
padding: 40px 32px 72px;
|
|
159
208
|
}
|
|
160
209
|
|
|
161
|
-
h1,
|
|
162
|
-
h2,
|
|
163
|
-
h3,
|
|
164
|
-
h4,
|
|
165
|
-
h5,
|
|
166
|
-
h6 {
|
|
210
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h1,
|
|
211
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h2,
|
|
212
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h3,
|
|
213
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h4,
|
|
214
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h5,
|
|
215
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h6 {
|
|
167
216
|
margin: 1.5em 0 0.7em;
|
|
168
217
|
line-height: 1.28;
|
|
169
218
|
color: #101827;
|
|
170
219
|
}
|
|
171
220
|
|
|
172
|
-
h1 {
|
|
221
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h1 {
|
|
173
222
|
font-size: 30px;
|
|
174
223
|
padding-bottom: 0.42em;
|
|
175
224
|
border-bottom: 1px solid #dbe4f0;
|
|
176
225
|
}
|
|
177
226
|
|
|
178
|
-
h2 {
|
|
227
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h2 {
|
|
179
228
|
font-size: 24px;
|
|
180
229
|
}
|
|
181
230
|
|
|
182
|
-
h3 {
|
|
231
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h3 {
|
|
183
232
|
font-size: 20px;
|
|
184
233
|
}
|
|
185
234
|
|
|
186
|
-
p,
|
|
187
|
-
li,
|
|
188
|
-
blockquote,
|
|
189
|
-
td,
|
|
190
|
-
th {
|
|
235
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} p,
|
|
236
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} li,
|
|
237
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} blockquote,
|
|
238
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} td,
|
|
239
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} th {
|
|
191
240
|
font-size: 15px;
|
|
192
241
|
line-height: 1.82;
|
|
193
242
|
}
|
|
194
243
|
|
|
195
|
-
a {
|
|
244
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} a {
|
|
196
245
|
color: #2259d1;
|
|
197
246
|
text-decoration: none;
|
|
198
247
|
}
|
|
199
248
|
|
|
200
|
-
code,
|
|
201
|
-
pre,
|
|
202
|
-
kbd {
|
|
249
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} code,
|
|
250
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} pre,
|
|
251
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} kbd {
|
|
203
252
|
font-family:
|
|
204
253
|
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
|
|
205
254
|
"Liberation Mono", monospace;
|
|
206
255
|
}
|
|
207
256
|
|
|
208
|
-
pre {
|
|
257
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} pre {
|
|
209
258
|
padding: 16px;
|
|
210
259
|
border-radius: 18px;
|
|
211
260
|
overflow: auto;
|
|
@@ -213,40 +262,40 @@ function buildDocumentExportHtml(title, bodyHtml) {
|
|
|
213
262
|
color: #f8fafc;
|
|
214
263
|
}
|
|
215
264
|
|
|
216
|
-
code {
|
|
265
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} code {
|
|
217
266
|
white-space: pre-wrap;
|
|
218
267
|
}
|
|
219
268
|
|
|
220
|
-
:not(pre) > code {
|
|
269
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} :not(pre) > code {
|
|
221
270
|
padding: 0.18em 0.42em;
|
|
222
271
|
border-radius: 7px;
|
|
223
272
|
background: #eef2f8;
|
|
224
273
|
color: #132238;
|
|
225
274
|
}
|
|
226
275
|
|
|
227
|
-
blockquote {
|
|
276
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} blockquote {
|
|
228
277
|
margin: 1.1em 0;
|
|
229
278
|
padding: 0.9em 1.1em;
|
|
230
279
|
border-left: 4px solid #7fa4ff;
|
|
231
280
|
background: #f6f8fd;
|
|
232
281
|
}
|
|
233
282
|
|
|
234
|
-
table {
|
|
283
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} table {
|
|
235
284
|
width: 100%;
|
|
236
285
|
border-collapse: collapse;
|
|
237
286
|
}
|
|
238
287
|
|
|
239
|
-
th,
|
|
240
|
-
td {
|
|
288
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} th,
|
|
289
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} td {
|
|
241
290
|
padding: 12px 14px;
|
|
242
291
|
border: 1px solid #dbe4f0;
|
|
243
292
|
}
|
|
244
293
|
|
|
245
|
-
thead {
|
|
294
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} thead {
|
|
246
295
|
background: #f5f7fb;
|
|
247
296
|
}
|
|
248
297
|
|
|
249
|
-
img {
|
|
298
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} img {
|
|
250
299
|
max-width: 100%;
|
|
251
300
|
height: auto;
|
|
252
301
|
}
|
|
@@ -255,46 +304,216 @@ function buildDocumentExportHtml(title, bodyHtml) {
|
|
|
255
304
|
size: auto;
|
|
256
305
|
margin: 14mm 12mm;
|
|
257
306
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
307
|
+
`;
|
|
308
|
+
}
|
|
309
|
+
function buildDocumentExportBody(bodyHtml) {
|
|
310
|
+
return `<main>
|
|
262
311
|
${bodyHtml}
|
|
263
|
-
</main
|
|
312
|
+
</main>`;
|
|
313
|
+
}
|
|
314
|
+
function buildDocumentExportHtml(title, bodyHtml) {
|
|
315
|
+
return `<!doctype html>
|
|
316
|
+
<html lang="${escapeExportHtml(getUILocale())}">
|
|
317
|
+
<head>
|
|
318
|
+
<meta charset="utf-8" />
|
|
319
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
320
|
+
<title>${escapeHtml(title)}</title>
|
|
321
|
+
<style>${buildDocumentExportStyles()}</style>
|
|
322
|
+
</head>
|
|
323
|
+
<body class="${DOCUMENT_EXPORT_ROOT_CLASS}">
|
|
324
|
+
${buildDocumentExportBody(bodyHtml)}
|
|
264
325
|
</body>
|
|
265
326
|
</html>`;
|
|
266
327
|
}
|
|
267
|
-
function
|
|
328
|
+
function htmlToPdfFilename(title) {
|
|
268
329
|
return title.endsWith('.pdf') ? title : `${title}.pdf`;
|
|
269
330
|
}
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
331
|
+
function createBrowserPdfRenderHost(bodyHtml) {
|
|
332
|
+
const frame = document.createElement('iframe');
|
|
333
|
+
frame.setAttribute('aria-hidden', 'true');
|
|
334
|
+
frame.tabIndex = -1;
|
|
335
|
+
frame.style.position = 'fixed';
|
|
336
|
+
frame.style.left = '-10000px';
|
|
337
|
+
frame.style.top = '0';
|
|
338
|
+
frame.style.width = `${BROWSER_PDF_VIEWPORT_WIDTH_PX}px`;
|
|
339
|
+
frame.style.height = '1px';
|
|
340
|
+
frame.style.border = '0';
|
|
341
|
+
frame.style.opacity = '0';
|
|
342
|
+
frame.style.pointerEvents = 'none';
|
|
343
|
+
frame.style.background = '#ffffff';
|
|
344
|
+
document.body.append(frame);
|
|
345
|
+
const frameDocument = frame.contentDocument;
|
|
346
|
+
const frameWindow = frame.contentWindow;
|
|
347
|
+
if (!frameDocument || !frameWindow) {
|
|
348
|
+
frame.remove();
|
|
349
|
+
throw new Error('Failed to create PDF export iframe');
|
|
350
|
+
}
|
|
351
|
+
frameDocument.open();
|
|
352
|
+
frameDocument.write(buildDocumentExportHtml('PDF Export', bodyHtml));
|
|
353
|
+
frameDocument.close();
|
|
354
|
+
const renderRoot = frameDocument.querySelector(`.${DOCUMENT_EXPORT_ROOT_CLASS}`);
|
|
355
|
+
if (!renderRoot) {
|
|
356
|
+
frame.remove();
|
|
357
|
+
throw new Error('Failed to prepare PDF export document');
|
|
358
|
+
}
|
|
359
|
+
for (const image of Array.from(frameDocument.images)) {
|
|
360
|
+
image.loading = 'eager';
|
|
361
|
+
image.decoding = 'sync';
|
|
288
362
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}, 240);
|
|
363
|
+
return {
|
|
364
|
+
cleanup: () => frame.remove(),
|
|
365
|
+
frameElement: frame,
|
|
366
|
+
frameDocument,
|
|
367
|
+
frameWindow,
|
|
368
|
+
renderRoot,
|
|
296
369
|
};
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
370
|
+
}
|
|
371
|
+
function syncBrowserPdfRenderHostSize(frameElement, renderRoot) {
|
|
372
|
+
const renderHeight = Math.max(renderRoot.scrollHeight, renderRoot.offsetHeight, renderRoot.clientHeight, 1);
|
|
373
|
+
frameElement.style.height = `${Math.ceil(renderHeight)}px`;
|
|
374
|
+
}
|
|
375
|
+
function waitForNextPaint(view) {
|
|
376
|
+
return new Promise((resolve) => {
|
|
377
|
+
const requestAnimationFrame = view?.requestAnimationFrame?.bind(view) ?? window.requestAnimationFrame;
|
|
378
|
+
if (typeof requestAnimationFrame !== 'function') {
|
|
379
|
+
resolve();
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
requestAnimationFrame(() => resolve());
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
async function waitForBrowserPdfRenderReady(frameElement, frameDocument, frameWindow, renderRoot) {
|
|
386
|
+
await waitForNextPaint(frameWindow);
|
|
387
|
+
await waitForNextPaint(frameWindow);
|
|
388
|
+
const imageElements = Array.from(frameDocument.querySelectorAll('img'));
|
|
389
|
+
await Promise.all(imageElements.map((image) => {
|
|
390
|
+
if (image.complete) {
|
|
391
|
+
return Promise.resolve();
|
|
392
|
+
}
|
|
393
|
+
return new Promise((resolve) => {
|
|
394
|
+
image.addEventListener('load', () => resolve(), { once: true });
|
|
395
|
+
image.addEventListener('error', () => resolve(), { once: true });
|
|
396
|
+
});
|
|
397
|
+
}));
|
|
398
|
+
if (typeof frameDocument.fonts?.ready?.then === 'function') {
|
|
399
|
+
await frameDocument.fonts.ready;
|
|
400
|
+
}
|
|
401
|
+
syncBrowserPdfRenderHostSize(frameElement, renderRoot);
|
|
402
|
+
await waitForNextPaint(frameWindow);
|
|
403
|
+
}
|
|
404
|
+
function createPagedPdfFromCanvas(JsPdfConstructor, canvas) {
|
|
405
|
+
const pdfDocument = new JsPdfConstructor({
|
|
406
|
+
unit: 'mm',
|
|
407
|
+
format: 'a4',
|
|
408
|
+
orientation: 'portrait',
|
|
409
|
+
compress: true,
|
|
410
|
+
});
|
|
411
|
+
const pageCanvas = document.createElement('canvas');
|
|
412
|
+
const pageContext = pageCanvas.getContext('2d');
|
|
413
|
+
if (!pageContext) {
|
|
414
|
+
throw new Error('Failed to prepare PDF page canvas');
|
|
415
|
+
}
|
|
416
|
+
const pixelsPerMillimeter = canvas.width / BROWSER_PDF_CONTENT_WIDTH_MM;
|
|
417
|
+
const pageHeightPx = Math.max(1, Math.floor(BROWSER_PDF_CONTENT_HEIGHT_MM * pixelsPerMillimeter));
|
|
418
|
+
const sourceContext = canvas.getContext('2d', { willReadFrequently: true });
|
|
419
|
+
for (let pageIndex = 0, sourceY = 0; sourceY < canvas.height; pageIndex += 1) {
|
|
420
|
+
const remainingHeightPx = canvas.height - sourceY;
|
|
421
|
+
const sliceHeightPx = remainingHeightPx > pageHeightPx && sourceContext
|
|
422
|
+
? resolveCanvasPageSliceHeight(sourceContext, canvas, sourceY, pageHeightPx)
|
|
423
|
+
: Math.min(pageHeightPx, remainingHeightPx);
|
|
424
|
+
pageCanvas.width = canvas.width;
|
|
425
|
+
pageCanvas.height = sliceHeightPx;
|
|
426
|
+
pageContext.fillStyle = '#ffffff';
|
|
427
|
+
pageContext.fillRect(0, 0, pageCanvas.width, pageCanvas.height);
|
|
428
|
+
pageContext.drawImage(canvas, 0, sourceY, canvas.width, sliceHeightPx, 0, 0, canvas.width, sliceHeightPx);
|
|
429
|
+
if (pageIndex > 0) {
|
|
430
|
+
pdfDocument.addPage();
|
|
431
|
+
}
|
|
432
|
+
pdfDocument.addImage(pageCanvas.toDataURL('image/png'), 'PNG', BROWSER_PDF_MARGIN_MM[3], BROWSER_PDF_MARGIN_MM[0], BROWSER_PDF_CONTENT_WIDTH_MM, sliceHeightPx / pixelsPerMillimeter, undefined, 'FAST');
|
|
433
|
+
sourceY += sliceHeightPx;
|
|
434
|
+
}
|
|
435
|
+
return pdfDocument.output('blob');
|
|
436
|
+
}
|
|
437
|
+
function resolveCanvasPageSliceHeight(sourceContext, canvas, sourceY, pageHeightPx) {
|
|
438
|
+
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)));
|
|
439
|
+
const scanStartY = Math.max(sourceY + 1, sourceY + pageHeightPx - searchRadiusPx);
|
|
440
|
+
const scanEndY = Math.min(sourceY + pageHeightPx, canvas.height);
|
|
441
|
+
const scanHeight = scanEndY - scanStartY;
|
|
442
|
+
if (scanHeight <= 0) {
|
|
443
|
+
return Math.min(pageHeightPx, canvas.height - sourceY);
|
|
444
|
+
}
|
|
445
|
+
const imageData = sourceContext.getImageData(0, scanStartY, canvas.width, scanHeight);
|
|
446
|
+
const bestBreakY = findCanvasPageBreakY(imageData, scanStartY);
|
|
447
|
+
return Math.max(1, Math.min(bestBreakY - sourceY, canvas.height - sourceY));
|
|
448
|
+
}
|
|
449
|
+
function findCanvasPageBreakY(imageData, scanStartY) {
|
|
450
|
+
const rowWidth = imageData.width;
|
|
451
|
+
const rowHeight = imageData.height;
|
|
452
|
+
const rowStride = rowWidth * 4;
|
|
453
|
+
let bestEmptyRowY = 0;
|
|
454
|
+
let bestInkRowY = 0;
|
|
455
|
+
let lowestInkScore = Number.POSITIVE_INFINITY;
|
|
456
|
+
for (let rowIndex = 0; rowIndex < rowHeight; rowIndex += 1) {
|
|
457
|
+
const rowInkScore = measureCanvasRowInk(imageData.data, rowIndex * rowStride, rowWidth);
|
|
458
|
+
if (rowInkScore <= BROWSER_PDF_PAGE_BREAK_EMPTY_ROW_MAX_INK) {
|
|
459
|
+
bestEmptyRowY = scanStartY + rowIndex + 1;
|
|
460
|
+
}
|
|
461
|
+
if (rowInkScore <= lowestInkScore) {
|
|
462
|
+
lowestInkScore = rowInkScore;
|
|
463
|
+
bestInkRowY = scanStartY + rowIndex + 1;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return bestEmptyRowY || bestInkRowY || (scanStartY + rowHeight);
|
|
467
|
+
}
|
|
468
|
+
function measureCanvasRowInk(pixels, rowOffset, rowWidth) {
|
|
469
|
+
let inkScore = 0;
|
|
470
|
+
for (let column = 0; column < rowWidth; column += BROWSER_PDF_PAGE_BREAK_SAMPLE_STEP_PX) {
|
|
471
|
+
const pixelOffset = rowOffset + (column * 4);
|
|
472
|
+
const alpha = pixels[pixelOffset + 3];
|
|
473
|
+
if (alpha < BROWSER_PDF_PAGE_BREAK_ALPHA_THRESHOLD) {
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
const red = pixels[pixelOffset];
|
|
477
|
+
const green = pixels[pixelOffset + 1];
|
|
478
|
+
const blue = pixels[pixelOffset + 2];
|
|
479
|
+
if (red < BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD
|
|
480
|
+
|| green < BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD
|
|
481
|
+
|| blue < BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD) {
|
|
482
|
+
inkScore += 1;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return inkScore;
|
|
486
|
+
}
|
|
487
|
+
async function renderBrowserPdfCanvas(renderHost) {
|
|
488
|
+
syncBrowserPdfRenderHostSize(renderHost.frameElement, renderHost.renderRoot);
|
|
489
|
+
const { default: html2canvas } = await import('html2canvas');
|
|
490
|
+
return html2canvas(renderHost.renderRoot, {
|
|
491
|
+
backgroundColor: '#ffffff',
|
|
492
|
+
useCORS: true,
|
|
493
|
+
scale: 2,
|
|
494
|
+
logging: false,
|
|
495
|
+
width: Math.max(renderHost.renderRoot.scrollWidth, renderHost.renderRoot.clientWidth, BROWSER_PDF_VIEWPORT_WIDTH_PX),
|
|
496
|
+
height: Math.max(renderHost.renderRoot.scrollHeight, renderHost.renderRoot.clientHeight, 1),
|
|
497
|
+
windowWidth: Math.max(renderHost.renderRoot.scrollWidth, renderHost.renderRoot.clientWidth, BROWSER_PDF_VIEWPORT_WIDTH_PX),
|
|
498
|
+
windowHeight: Math.max(renderHost.renderRoot.scrollHeight, renderHost.renderRoot.clientHeight, 1),
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
let jsPdfModulePromise;
|
|
502
|
+
async function loadJsPdf() {
|
|
503
|
+
jsPdfModulePromise ??= import('jspdf');
|
|
504
|
+
return jsPdfModulePromise;
|
|
505
|
+
}
|
|
506
|
+
async function downloadDocumentAsPdf(filename, bodyHtml) {
|
|
507
|
+
const renderHost = createBrowserPdfRenderHost(bodyHtml);
|
|
508
|
+
try {
|
|
509
|
+
await waitForBrowserPdfRenderReady(renderHost.frameElement, renderHost.frameDocument, renderHost.frameWindow, renderHost.renderRoot);
|
|
510
|
+
const [{ jsPDF }, canvas] = await Promise.all([
|
|
511
|
+
loadJsPdf(),
|
|
512
|
+
renderBrowserPdfCanvas(renderHost),
|
|
513
|
+
]);
|
|
514
|
+
downloadBlob(createPagedPdfFromCanvas(jsPDF, canvas), filename);
|
|
515
|
+
}
|
|
516
|
+
finally {
|
|
517
|
+
renderHost.cleanup();
|
|
518
|
+
}
|
|
300
519
|
}
|
|
@@ -1,28 +1,118 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @h-ai/ui — Markdown
|
|
2
|
+
* @h-ai/ui — Markdown 文档解析工具
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 为文档模式提取安全 HTML、目录和代码块元信息。
|
|
5
5
|
*/
|
|
6
6
|
import type { MarkdownCodeBlockItem, MarkdownOutlineItem } from './document-types.js';
|
|
7
|
+
/**
|
|
8
|
+
* 安全 Markdown 文档解析选项;运行按钮不等于允许执行代码。
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import type { MarkdownDocumentParseOptions } from '@h-ai/ui'
|
|
13
|
+
* const example: MarkdownDocumentParseOptions = { enableHighlight: true, allowHtmlTags: false, showRunButton: false, breaks: true }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
7
16
|
export interface MarkdownDocumentParseOptions {
|
|
8
|
-
/**
|
|
17
|
+
/** 是否启用代码块语法高亮。 */
|
|
9
18
|
enableHighlight?: boolean;
|
|
10
|
-
/**
|
|
19
|
+
/** 是否渲染代码块复制按钮。 */
|
|
11
20
|
showCopyButton?: boolean;
|
|
12
|
-
/**
|
|
21
|
+
/** 是否渲染运行按钮和预览槽;实际运行由宿主授权。 */
|
|
13
22
|
showRunButton?: boolean;
|
|
14
|
-
/**
|
|
23
|
+
/** 是否渲染代码块头部的代码/预览切换。 */
|
|
24
|
+
showCodePreviewToggle?: boolean;
|
|
25
|
+
/** 启用预览切换时的代码页签文案。 */
|
|
26
|
+
codeViewCodeLabel?: string;
|
|
27
|
+
/** 启用预览切换时的预览页签文案。 */
|
|
28
|
+
codeViewPreviewLabel?: string;
|
|
29
|
+
/** 代码块头部语言标签旁的提示文案。 */
|
|
30
|
+
codePreviewHint?: string;
|
|
31
|
+
/** 是否将普通换行转换成 br。 */
|
|
15
32
|
breaks?: boolean;
|
|
33
|
+
/** 是否按安全白名单解析原始 HTML 标签。 */
|
|
34
|
+
allowHtmlTags?: boolean;
|
|
16
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* 一次文档解析生成的安全渲染块、目录和原始代码块信息。
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { renderMarkdownDocument } from '@h-ai/ui'
|
|
42
|
+
* import type { MarkdownRenderResult } from '@h-ai/ui'
|
|
43
|
+
* const result: MarkdownRenderResult = renderMarkdownDocument('# 简介\n正文')
|
|
44
|
+
* const headings = result.outline
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
17
47
|
export interface MarkdownRenderResult {
|
|
18
|
-
/**
|
|
19
|
-
html: string;
|
|
20
|
-
/** Extracted outline items for navigation. */
|
|
48
|
+
/** 供目录导航使用的标题条目。 */
|
|
21
49
|
outline: MarkdownOutlineItem[];
|
|
22
|
-
/**
|
|
50
|
+
/** 供运行/复制功能使用的代码块元信息。 */
|
|
23
51
|
codeBlocks: MarkdownCodeBlockItem[];
|
|
52
|
+
/** 阅读态使用的稳定块列表,避免流式更新销毁重型块 DOM。 */
|
|
53
|
+
blocks: MarkdownDocumentBlock[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 文档渲染块的可辨识联合;HTML 块和 Mermaid 源码块分开更新。
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import type { MarkdownDocumentBlock } from '@h-ai/ui'
|
|
61
|
+
* const example: MarkdownDocumentBlock = { kind: 'html', id: 'paragraph-1', html: '<p>正文</p>' }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export type MarkdownDocumentBlock = MarkdownDocumentHtmlBlock | MarkdownDocumentMermaidBlock;
|
|
65
|
+
/**
|
|
66
|
+
* 已经过安全策略处理的 Markdown HTML 块;不要填入未消毒输入。
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import type { MarkdownDocumentHtmlBlock } from '@h-ai/ui'
|
|
71
|
+
* const example: MarkdownDocumentHtmlBlock = { kind: 'html', id: 'paragraph-1', html: '<p>正文</p>' }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export interface MarkdownDocumentHtmlBlock {
|
|
75
|
+
/** 普通 Markdown HTML 块。 */
|
|
76
|
+
kind: 'html';
|
|
77
|
+
/** 稳定块 id,用于 Svelte keyed each。 */
|
|
78
|
+
id: string;
|
|
79
|
+
/** 已按现有安全策略渲染后的 HTML。 */
|
|
80
|
+
html: string;
|
|
24
81
|
}
|
|
25
82
|
/**
|
|
26
|
-
*
|
|
83
|
+
* 完整 Mermaid 块的源码与签名,等待异步严格模式渲染。
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* import type { MarkdownDocumentMermaidBlock } from '@h-ai/ui'
|
|
88
|
+
* const example: MarkdownDocumentMermaidBlock = { kind: 'mermaid', id: 'diagram-1', codeBlockId: 'code-1', code: 'graph TD; A-->B', language: 'mermaid', signature: JSON.stringify(['diagram-1', 'graph TD; A-->B']) }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export interface MarkdownDocumentMermaidBlock {
|
|
92
|
+
/** 已闭合 Mermaid fence 块。 */
|
|
93
|
+
kind: 'mermaid';
|
|
94
|
+
/** 稳定块 id,用于 Svelte keyed each。 */
|
|
95
|
+
id: string;
|
|
96
|
+
/** 对应 codeBlocks 中的代码块 id。 */
|
|
97
|
+
codeBlockId: string;
|
|
98
|
+
/** Mermaid 源码。 */
|
|
99
|
+
code: string;
|
|
100
|
+
/** 原始 fence info string。 */
|
|
101
|
+
language: string;
|
|
102
|
+
/** Mermaid 源码签名,源码变化时才需要重渲染。 */
|
|
103
|
+
signature: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 安全渲染 Markdown,同时提取目录和代码块元信息。
|
|
107
|
+
* @param content - Markdown 或文档正文。
|
|
108
|
+
* @param options - 本次操作的行为与显示选项。
|
|
109
|
+
* @returns 已消毒渲染块、目录和代码元信息。
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { renderMarkdownDocument } from '@h-ai/ui'
|
|
114
|
+
* const result = renderMarkdownDocument('# 简介\n正文', { allowHtmlTags: false, enableHighlight: true })
|
|
115
|
+
* const firstHeading = result.outline[0]?.text
|
|
116
|
+
* ```
|
|
27
117
|
*/
|
|
28
118
|
export declare function renderMarkdownDocument(content: string, options?: MarkdownDocumentParseOptions): MarkdownRenderResult;
|