@h-ai/ui 0.1.0-alpha9 → 1.0.0-beta.10
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 +1062 -0
- package/README.ja.md +1062 -0
- package/README.md +696 -119
- package/auto-import.d.ts +49 -0
- package/auto-import.js +51 -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 +397 -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 +300 -79
- 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 +216 -0
- package/dist/components/scenes/ai/highlight.d.ts +37 -0
- package/dist/components/scenes/ai/highlight.js +177 -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 +85 -47
- 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 +186 -0
- package/dist/components/scenes/charts/Chart.svelte.d.ts +24 -0
- 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 +52 -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 +19 -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 +164 -0
- package/dist/components/scenes/charts/chart-types.js +7 -0
- 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 +12 -0
- package/dist/components/scenes/charts/index.js +10 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte +19 -0
- package/dist/components/scenes/charts/renderers/AreaChart.svelte.d.ts +6 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte +19 -0
- package/dist/components/scenes/charts/renderers/BarChart.svelte.d.ts +6 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte +625 -0
- package/dist/components/scenes/charts/renderers/LineChart.svelte.d.ts +33 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte +19 -0
- package/dist/components/scenes/charts/renderers/PieChart.svelte.d.ts +6 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte +19 -0
- package/dist/components/scenes/charts/renderers/ScatterChart.svelte.d.ts +6 -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 +303 -16
- package/dist/messages/ja-JP.json +529 -0
- package/dist/messages/zh-CN.json +303 -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/eye-care.css +55 -0
- 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 +43 -0
- package/dist/theme-config.d.ts +263 -10
- package/dist/theme-config.js +253 -17
- package/dist/toast.svelte.d.ts +210 -2
- package/dist/toast.svelte.js +305 -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) {
|
|
@@ -107,9 +165,11 @@ function resolveDocumentBaseName(title, filename) {
|
|
|
107
165
|
const sanitizedName = stripControlCharacters(preferredName)
|
|
108
166
|
.replace(/[<>:"/\\|?*]+/g, ' ')
|
|
109
167
|
.replace(/\s+/g, ' ')
|
|
110
|
-
.replace(/[. ]+$/g, '')
|
|
111
168
|
.trim();
|
|
112
|
-
|
|
169
|
+
let end = sanitizedName.length;
|
|
170
|
+
while (end > 0 && (sanitizedName[end - 1] === '.' || sanitizedName[end - 1] === ' '))
|
|
171
|
+
end--;
|
|
172
|
+
return sanitizedName.slice(0, end) || 'ai-document';
|
|
113
173
|
}
|
|
114
174
|
function downloadBlob(blob, filename) {
|
|
115
175
|
const url = URL.createObjectURL(blob);
|
|
@@ -130,19 +190,10 @@ function escapeHtml(value) {
|
|
|
130
190
|
.replace(/"/g, '"')
|
|
131
191
|
.replace(/'/g, ''');
|
|
132
192
|
}
|
|
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 {
|
|
193
|
+
function buildDocumentExportStyles() {
|
|
194
|
+
return `
|
|
195
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} {
|
|
142
196
|
color-scheme: light;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
body {
|
|
146
197
|
margin: 0;
|
|
147
198
|
padding: 0;
|
|
148
199
|
font-family:
|
|
@@ -152,60 +203,60 @@ function buildDocumentExportHtml(title, bodyHtml) {
|
|
|
152
203
|
background: #ffffff;
|
|
153
204
|
}
|
|
154
205
|
|
|
155
|
-
main {
|
|
206
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} main {
|
|
156
207
|
max-width: 860px;
|
|
157
208
|
margin: 0 auto;
|
|
158
209
|
padding: 40px 32px 72px;
|
|
159
210
|
}
|
|
160
211
|
|
|
161
|
-
h1,
|
|
162
|
-
h2,
|
|
163
|
-
h3,
|
|
164
|
-
h4,
|
|
165
|
-
h5,
|
|
166
|
-
h6 {
|
|
212
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h1,
|
|
213
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h2,
|
|
214
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h3,
|
|
215
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h4,
|
|
216
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h5,
|
|
217
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h6 {
|
|
167
218
|
margin: 1.5em 0 0.7em;
|
|
168
219
|
line-height: 1.28;
|
|
169
220
|
color: #101827;
|
|
170
221
|
}
|
|
171
222
|
|
|
172
|
-
h1 {
|
|
223
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h1 {
|
|
173
224
|
font-size: 30px;
|
|
174
225
|
padding-bottom: 0.42em;
|
|
175
226
|
border-bottom: 1px solid #dbe4f0;
|
|
176
227
|
}
|
|
177
228
|
|
|
178
|
-
h2 {
|
|
229
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h2 {
|
|
179
230
|
font-size: 24px;
|
|
180
231
|
}
|
|
181
232
|
|
|
182
|
-
h3 {
|
|
233
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} h3 {
|
|
183
234
|
font-size: 20px;
|
|
184
235
|
}
|
|
185
236
|
|
|
186
|
-
p,
|
|
187
|
-
li,
|
|
188
|
-
blockquote,
|
|
189
|
-
td,
|
|
190
|
-
th {
|
|
237
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} p,
|
|
238
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} li,
|
|
239
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} blockquote,
|
|
240
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} td,
|
|
241
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} th {
|
|
191
242
|
font-size: 15px;
|
|
192
243
|
line-height: 1.82;
|
|
193
244
|
}
|
|
194
245
|
|
|
195
|
-
a {
|
|
246
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} a {
|
|
196
247
|
color: #2259d1;
|
|
197
248
|
text-decoration: none;
|
|
198
249
|
}
|
|
199
250
|
|
|
200
|
-
code,
|
|
201
|
-
pre,
|
|
202
|
-
kbd {
|
|
251
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} code,
|
|
252
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} pre,
|
|
253
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} kbd {
|
|
203
254
|
font-family:
|
|
204
255
|
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
|
|
205
256
|
"Liberation Mono", monospace;
|
|
206
257
|
}
|
|
207
258
|
|
|
208
|
-
pre {
|
|
259
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} pre {
|
|
209
260
|
padding: 16px;
|
|
210
261
|
border-radius: 18px;
|
|
211
262
|
overflow: auto;
|
|
@@ -213,40 +264,40 @@ function buildDocumentExportHtml(title, bodyHtml) {
|
|
|
213
264
|
color: #f8fafc;
|
|
214
265
|
}
|
|
215
266
|
|
|
216
|
-
code {
|
|
267
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} code {
|
|
217
268
|
white-space: pre-wrap;
|
|
218
269
|
}
|
|
219
270
|
|
|
220
|
-
:not(pre) > code {
|
|
271
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} :not(pre) > code {
|
|
221
272
|
padding: 0.18em 0.42em;
|
|
222
273
|
border-radius: 7px;
|
|
223
274
|
background: #eef2f8;
|
|
224
275
|
color: #132238;
|
|
225
276
|
}
|
|
226
277
|
|
|
227
|
-
blockquote {
|
|
278
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} blockquote {
|
|
228
279
|
margin: 1.1em 0;
|
|
229
280
|
padding: 0.9em 1.1em;
|
|
230
281
|
border-left: 4px solid #7fa4ff;
|
|
231
282
|
background: #f6f8fd;
|
|
232
283
|
}
|
|
233
284
|
|
|
234
|
-
table {
|
|
285
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} table {
|
|
235
286
|
width: 100%;
|
|
236
287
|
border-collapse: collapse;
|
|
237
288
|
}
|
|
238
289
|
|
|
239
|
-
th,
|
|
240
|
-
td {
|
|
290
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} th,
|
|
291
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} td {
|
|
241
292
|
padding: 12px 14px;
|
|
242
293
|
border: 1px solid #dbe4f0;
|
|
243
294
|
}
|
|
244
295
|
|
|
245
|
-
thead {
|
|
296
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} thead {
|
|
246
297
|
background: #f5f7fb;
|
|
247
298
|
}
|
|
248
299
|
|
|
249
|
-
img {
|
|
300
|
+
.${DOCUMENT_EXPORT_ROOT_CLASS} img {
|
|
250
301
|
max-width: 100%;
|
|
251
302
|
height: auto;
|
|
252
303
|
}
|
|
@@ -255,46 +306,216 @@ function buildDocumentExportHtml(title, bodyHtml) {
|
|
|
255
306
|
size: auto;
|
|
256
307
|
margin: 14mm 12mm;
|
|
257
308
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
309
|
+
`;
|
|
310
|
+
}
|
|
311
|
+
function buildDocumentExportBody(bodyHtml) {
|
|
312
|
+
return `<main>
|
|
262
313
|
${bodyHtml}
|
|
263
|
-
</main
|
|
314
|
+
</main>`;
|
|
315
|
+
}
|
|
316
|
+
function buildDocumentExportHtml(title, bodyHtml) {
|
|
317
|
+
return `<!doctype html>
|
|
318
|
+
<html lang="${escapeExportHtml(getUILocale())}">
|
|
319
|
+
<head>
|
|
320
|
+
<meta charset="utf-8" />
|
|
321
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
322
|
+
<title>${escapeHtml(title)}</title>
|
|
323
|
+
<style>${buildDocumentExportStyles()}</style>
|
|
324
|
+
</head>
|
|
325
|
+
<body class="${DOCUMENT_EXPORT_ROOT_CLASS}">
|
|
326
|
+
${buildDocumentExportBody(bodyHtml)}
|
|
264
327
|
</body>
|
|
265
328
|
</html>`;
|
|
266
329
|
}
|
|
267
|
-
function
|
|
330
|
+
function htmlToPdfFilename(title) {
|
|
268
331
|
return title.endsWith('.pdf') ? title : `${title}.pdf`;
|
|
269
332
|
}
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
333
|
+
function createBrowserPdfRenderHost(bodyHtml) {
|
|
334
|
+
const frame = document.createElement('iframe');
|
|
335
|
+
frame.setAttribute('aria-hidden', 'true');
|
|
336
|
+
frame.tabIndex = -1;
|
|
337
|
+
frame.style.position = 'fixed';
|
|
338
|
+
frame.style.left = '-10000px';
|
|
339
|
+
frame.style.top = '0';
|
|
340
|
+
frame.style.width = `${BROWSER_PDF_VIEWPORT_WIDTH_PX}px`;
|
|
341
|
+
frame.style.height = '1px';
|
|
342
|
+
frame.style.border = '0';
|
|
343
|
+
frame.style.opacity = '0';
|
|
344
|
+
frame.style.pointerEvents = 'none';
|
|
345
|
+
frame.style.background = '#ffffff';
|
|
346
|
+
document.body.append(frame);
|
|
347
|
+
const frameDocument = frame.contentDocument;
|
|
348
|
+
const frameWindow = frame.contentWindow;
|
|
349
|
+
if (!frameDocument || !frameWindow) {
|
|
350
|
+
frame.remove();
|
|
351
|
+
throw new Error('Failed to create PDF export iframe');
|
|
352
|
+
}
|
|
353
|
+
frameDocument.open();
|
|
354
|
+
frameDocument.write(buildDocumentExportHtml('PDF Export', bodyHtml));
|
|
355
|
+
frameDocument.close();
|
|
356
|
+
const renderRoot = frameDocument.querySelector(`.${DOCUMENT_EXPORT_ROOT_CLASS}`);
|
|
357
|
+
if (!renderRoot) {
|
|
358
|
+
frame.remove();
|
|
359
|
+
throw new Error('Failed to prepare PDF export document');
|
|
360
|
+
}
|
|
361
|
+
for (const image of Array.from(frameDocument.images)) {
|
|
362
|
+
image.loading = 'eager';
|
|
363
|
+
image.decoding = 'sync';
|
|
288
364
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}, 240);
|
|
365
|
+
return {
|
|
366
|
+
cleanup: () => frame.remove(),
|
|
367
|
+
frameElement: frame,
|
|
368
|
+
frameDocument,
|
|
369
|
+
frameWindow,
|
|
370
|
+
renderRoot,
|
|
296
371
|
};
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
372
|
+
}
|
|
373
|
+
function syncBrowserPdfRenderHostSize(frameElement, renderRoot) {
|
|
374
|
+
const renderHeight = Math.max(renderRoot.scrollHeight, renderRoot.offsetHeight, renderRoot.clientHeight, 1);
|
|
375
|
+
frameElement.style.height = `${Math.ceil(renderHeight)}px`;
|
|
376
|
+
}
|
|
377
|
+
function waitForNextPaint(view) {
|
|
378
|
+
return new Promise((resolve) => {
|
|
379
|
+
const requestAnimationFrame = view?.requestAnimationFrame?.bind(view) ?? window.requestAnimationFrame;
|
|
380
|
+
if (typeof requestAnimationFrame !== 'function') {
|
|
381
|
+
resolve();
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
requestAnimationFrame(() => resolve());
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
async function waitForBrowserPdfRenderReady(frameElement, frameDocument, frameWindow, renderRoot) {
|
|
388
|
+
await waitForNextPaint(frameWindow);
|
|
389
|
+
await waitForNextPaint(frameWindow);
|
|
390
|
+
const imageElements = Array.from(frameDocument.querySelectorAll('img'));
|
|
391
|
+
await Promise.all(imageElements.map((image) => {
|
|
392
|
+
if (image.complete) {
|
|
393
|
+
return Promise.resolve();
|
|
394
|
+
}
|
|
395
|
+
return new Promise((resolve) => {
|
|
396
|
+
image.addEventListener('load', () => resolve(), { once: true });
|
|
397
|
+
image.addEventListener('error', () => resolve(), { once: true });
|
|
398
|
+
});
|
|
399
|
+
}));
|
|
400
|
+
if (typeof frameDocument.fonts?.ready?.then === 'function') {
|
|
401
|
+
await frameDocument.fonts.ready;
|
|
402
|
+
}
|
|
403
|
+
syncBrowserPdfRenderHostSize(frameElement, renderRoot);
|
|
404
|
+
await waitForNextPaint(frameWindow);
|
|
405
|
+
}
|
|
406
|
+
function createPagedPdfFromCanvas(JsPdfConstructor, canvas) {
|
|
407
|
+
const pdfDocument = new JsPdfConstructor({
|
|
408
|
+
unit: 'mm',
|
|
409
|
+
format: 'a4',
|
|
410
|
+
orientation: 'portrait',
|
|
411
|
+
compress: true,
|
|
412
|
+
});
|
|
413
|
+
const pageCanvas = document.createElement('canvas');
|
|
414
|
+
const pageContext = pageCanvas.getContext('2d');
|
|
415
|
+
if (!pageContext) {
|
|
416
|
+
throw new Error('Failed to prepare PDF page canvas');
|
|
417
|
+
}
|
|
418
|
+
const pixelsPerMillimeter = canvas.width / BROWSER_PDF_CONTENT_WIDTH_MM;
|
|
419
|
+
const pageHeightPx = Math.max(1, Math.floor(BROWSER_PDF_CONTENT_HEIGHT_MM * pixelsPerMillimeter));
|
|
420
|
+
const sourceContext = canvas.getContext('2d', { willReadFrequently: true });
|
|
421
|
+
for (let pageIndex = 0, sourceY = 0; sourceY < canvas.height; pageIndex += 1) {
|
|
422
|
+
const remainingHeightPx = canvas.height - sourceY;
|
|
423
|
+
const sliceHeightPx = remainingHeightPx > pageHeightPx && sourceContext
|
|
424
|
+
? resolveCanvasPageSliceHeight(sourceContext, canvas, sourceY, pageHeightPx)
|
|
425
|
+
: Math.min(pageHeightPx, remainingHeightPx);
|
|
426
|
+
pageCanvas.width = canvas.width;
|
|
427
|
+
pageCanvas.height = sliceHeightPx;
|
|
428
|
+
pageContext.fillStyle = '#ffffff';
|
|
429
|
+
pageContext.fillRect(0, 0, pageCanvas.width, pageCanvas.height);
|
|
430
|
+
pageContext.drawImage(canvas, 0, sourceY, canvas.width, sliceHeightPx, 0, 0, canvas.width, sliceHeightPx);
|
|
431
|
+
if (pageIndex > 0) {
|
|
432
|
+
pdfDocument.addPage();
|
|
433
|
+
}
|
|
434
|
+
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');
|
|
435
|
+
sourceY += sliceHeightPx;
|
|
436
|
+
}
|
|
437
|
+
return pdfDocument.output('blob');
|
|
438
|
+
}
|
|
439
|
+
function resolveCanvasPageSliceHeight(sourceContext, canvas, sourceY, pageHeightPx) {
|
|
440
|
+
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)));
|
|
441
|
+
const scanStartY = Math.max(sourceY + 1, sourceY + pageHeightPx - searchRadiusPx);
|
|
442
|
+
const scanEndY = Math.min(sourceY + pageHeightPx, canvas.height);
|
|
443
|
+
const scanHeight = scanEndY - scanStartY;
|
|
444
|
+
if (scanHeight <= 0) {
|
|
445
|
+
return Math.min(pageHeightPx, canvas.height - sourceY);
|
|
446
|
+
}
|
|
447
|
+
const imageData = sourceContext.getImageData(0, scanStartY, canvas.width, scanHeight);
|
|
448
|
+
const bestBreakY = findCanvasPageBreakY(imageData, scanStartY);
|
|
449
|
+
return Math.max(1, Math.min(bestBreakY - sourceY, canvas.height - sourceY));
|
|
450
|
+
}
|
|
451
|
+
function findCanvasPageBreakY(imageData, scanStartY) {
|
|
452
|
+
const rowWidth = imageData.width;
|
|
453
|
+
const rowHeight = imageData.height;
|
|
454
|
+
const rowStride = rowWidth * 4;
|
|
455
|
+
let bestEmptyRowY = 0;
|
|
456
|
+
let bestInkRowY = 0;
|
|
457
|
+
let lowestInkScore = Number.POSITIVE_INFINITY;
|
|
458
|
+
for (let rowIndex = 0; rowIndex < rowHeight; rowIndex += 1) {
|
|
459
|
+
const rowInkScore = measureCanvasRowInk(imageData.data, rowIndex * rowStride, rowWidth);
|
|
460
|
+
if (rowInkScore <= BROWSER_PDF_PAGE_BREAK_EMPTY_ROW_MAX_INK) {
|
|
461
|
+
bestEmptyRowY = scanStartY + rowIndex + 1;
|
|
462
|
+
}
|
|
463
|
+
if (rowInkScore <= lowestInkScore) {
|
|
464
|
+
lowestInkScore = rowInkScore;
|
|
465
|
+
bestInkRowY = scanStartY + rowIndex + 1;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return bestEmptyRowY || bestInkRowY || (scanStartY + rowHeight);
|
|
469
|
+
}
|
|
470
|
+
function measureCanvasRowInk(pixels, rowOffset, rowWidth) {
|
|
471
|
+
let inkScore = 0;
|
|
472
|
+
for (let column = 0; column < rowWidth; column += BROWSER_PDF_PAGE_BREAK_SAMPLE_STEP_PX) {
|
|
473
|
+
const pixelOffset = rowOffset + (column * 4);
|
|
474
|
+
const alpha = pixels[pixelOffset + 3];
|
|
475
|
+
if (alpha < BROWSER_PDF_PAGE_BREAK_ALPHA_THRESHOLD) {
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
const red = pixels[pixelOffset];
|
|
479
|
+
const green = pixels[pixelOffset + 1];
|
|
480
|
+
const blue = pixels[pixelOffset + 2];
|
|
481
|
+
if (red < BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD
|
|
482
|
+
|| green < BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD
|
|
483
|
+
|| blue < BROWSER_PDF_PAGE_BREAK_WHITE_THRESHOLD) {
|
|
484
|
+
inkScore += 1;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return inkScore;
|
|
488
|
+
}
|
|
489
|
+
async function renderBrowserPdfCanvas(renderHost) {
|
|
490
|
+
syncBrowserPdfRenderHostSize(renderHost.frameElement, renderHost.renderRoot);
|
|
491
|
+
const { default: html2canvas } = await import('html2canvas');
|
|
492
|
+
return html2canvas(renderHost.renderRoot, {
|
|
493
|
+
backgroundColor: '#ffffff',
|
|
494
|
+
useCORS: true,
|
|
495
|
+
scale: 2,
|
|
496
|
+
logging: false,
|
|
497
|
+
width: Math.max(renderHost.renderRoot.scrollWidth, renderHost.renderRoot.clientWidth, BROWSER_PDF_VIEWPORT_WIDTH_PX),
|
|
498
|
+
height: Math.max(renderHost.renderRoot.scrollHeight, renderHost.renderRoot.clientHeight, 1),
|
|
499
|
+
windowWidth: Math.max(renderHost.renderRoot.scrollWidth, renderHost.renderRoot.clientWidth, BROWSER_PDF_VIEWPORT_WIDTH_PX),
|
|
500
|
+
windowHeight: Math.max(renderHost.renderRoot.scrollHeight, renderHost.renderRoot.clientHeight, 1),
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
let jsPdfModulePromise;
|
|
504
|
+
async function loadJsPdf() {
|
|
505
|
+
jsPdfModulePromise ??= import('jspdf');
|
|
506
|
+
return jsPdfModulePromise;
|
|
507
|
+
}
|
|
508
|
+
async function downloadDocumentAsPdf(filename, bodyHtml) {
|
|
509
|
+
const renderHost = createBrowserPdfRenderHost(bodyHtml);
|
|
510
|
+
try {
|
|
511
|
+
await waitForBrowserPdfRenderReady(renderHost.frameElement, renderHost.frameDocument, renderHost.frameWindow, renderHost.renderRoot);
|
|
512
|
+
const [{ jsPDF }, canvas] = await Promise.all([
|
|
513
|
+
loadJsPdf(),
|
|
514
|
+
renderBrowserPdfCanvas(renderHost),
|
|
515
|
+
]);
|
|
516
|
+
downloadBlob(createPagedPdfFromCanvas(jsPDF, canvas), filename);
|
|
517
|
+
}
|
|
518
|
+
finally {
|
|
519
|
+
renderHost.cleanup();
|
|
520
|
+
}
|
|
300
521
|
}
|
|
@@ -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;
|