@h-ai/ui 0.1.0-alpha8 → 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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mermaid host 同步状态工具。
|
|
3
|
+
*
|
|
4
|
+
* Mermaid 图表通过 {@html} 插入占位节点后异步渲染。流式输出时,HTML 占位可能不变,
|
|
5
|
+
* 但源码正文会持续变化,因此必须用源码签名判断是否需要重渲染。
|
|
6
|
+
*
|
|
7
|
+
* @example 模块内部上下文
|
|
8
|
+
* ```ts
|
|
9
|
+
* const example: MermaidHostRenderActionInput = { status: 'ready', renderedSignature: 'old-source', nextSignature: 'new-source' }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export interface MermaidHostRenderActionInput {
|
|
13
|
+
/** 当前 host 上记录的渲染状态。 */
|
|
14
|
+
status?: string;
|
|
15
|
+
/** 当前 host 上一次渲染使用的源码签名。 */
|
|
16
|
+
renderedSignature?: string;
|
|
17
|
+
/** 本次 Markdown 解析得到的最新源码签名。 */
|
|
18
|
+
nextSignature: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 异步 Mermaid 渲染决策;仅 shouldRender=true 时携带提交 token。
|
|
22
|
+
*
|
|
23
|
+
* @example 模块内部上下文
|
|
24
|
+
* ```ts
|
|
25
|
+
* const example: MermaidHostRenderAction = { shouldRender: true, token: 'diagram-1-source' }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type MermaidHostRenderAction = {
|
|
29
|
+
shouldRender: false;
|
|
30
|
+
} | {
|
|
31
|
+
shouldRender: true;
|
|
32
|
+
token: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* 为 Mermaid block 生成稳定签名。
|
|
36
|
+
*
|
|
37
|
+
* 签名同时包含 block id 与源码正文,避免流式阶段占位 HTML 未变化时漏掉源码更新。
|
|
38
|
+
* @param blockId - 当前代码块的稳定 ID。
|
|
39
|
+
* @param code - Mermaid 或待渲染的代码源码。
|
|
40
|
+
* @returns 绑定块 id 和完整源码的稳定签名。
|
|
41
|
+
*
|
|
42
|
+
* @example 模块内部上下文
|
|
43
|
+
* ```ts
|
|
44
|
+
* const signature = createMermaidSourceSignature('diagram-1', 'graph TD; A-->B')
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function createMermaidSourceSignature(blockId: string, code: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* 判断 Mermaid host 是否需要发起一次新的异步渲染。
|
|
50
|
+
* @param input - 当前状态及目标源码签名。
|
|
51
|
+
* @returns 是否重渲染的决策,需要时携带提交 token。
|
|
52
|
+
*
|
|
53
|
+
* @example 模块内部上下文
|
|
54
|
+
* ```ts
|
|
55
|
+
* const action = getMermaidHostRenderAction({ status: 'ready', renderedSignature: 'old', nextSignature: 'new' })
|
|
56
|
+
* if (action.shouldRender) { const token = action.token }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function getMermaidHostRenderAction(input: MermaidHostRenderActionInput): MermaidHostRenderAction;
|
|
60
|
+
/**
|
|
61
|
+
* 判断异步 Mermaid 渲染结果是否仍对应当前 host 源码。
|
|
62
|
+
* @param renderToken - 异步渲染启动时捕获的 token。
|
|
63
|
+
* @param currentSignature - 宿主当前源码签名。
|
|
64
|
+
* @returns 渲染 token 是否仍匹配当前源码签名。
|
|
65
|
+
*
|
|
66
|
+
* @example 模块内部上下文
|
|
67
|
+
* ```ts
|
|
68
|
+
* const accepted = isCurrentMermaidRenderToken('current-source', 'current-source')
|
|
69
|
+
* const stale = isCurrentMermaidRenderToken('old-source', 'current-source')
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function isCurrentMermaidRenderToken(renderToken: string, currentSignature: string | undefined): boolean;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mermaid host 同步状态工具。
|
|
3
|
+
*
|
|
4
|
+
* Mermaid 图表通过 {@html} 插入占位节点后异步渲染。流式输出时,HTML 占位可能不变,
|
|
5
|
+
* 但源码正文会持续变化,因此必须用源码签名判断是否需要重渲染。
|
|
6
|
+
*
|
|
7
|
+
* @example 模块内部上下文
|
|
8
|
+
* ```ts
|
|
9
|
+
* const example: MermaidHostRenderActionInput = { status: 'ready', renderedSignature: 'old-source', nextSignature: 'new-source' }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* 为 Mermaid block 生成稳定签名。
|
|
14
|
+
*
|
|
15
|
+
* 签名同时包含 block id 与源码正文,避免流式阶段占位 HTML 未变化时漏掉源码更新。
|
|
16
|
+
* @param blockId - 当前代码块的稳定 ID。
|
|
17
|
+
* @param code - Mermaid 或待渲染的代码源码。
|
|
18
|
+
* @returns 绑定块 id 和完整源码的稳定签名。
|
|
19
|
+
*
|
|
20
|
+
* @example 模块内部上下文
|
|
21
|
+
* ```ts
|
|
22
|
+
* const signature = createMermaidSourceSignature('diagram-1', 'graph TD; A-->B')
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function createMermaidSourceSignature(blockId, code) {
|
|
26
|
+
return JSON.stringify([blockId, code]);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 判断 Mermaid host 是否需要发起一次新的异步渲染。
|
|
30
|
+
* @param input - 当前状态及目标源码签名。
|
|
31
|
+
* @returns 是否重渲染的决策,需要时携带提交 token。
|
|
32
|
+
*
|
|
33
|
+
* @example 模块内部上下文
|
|
34
|
+
* ```ts
|
|
35
|
+
* const action = getMermaidHostRenderAction({ status: 'ready', renderedSignature: 'old', nextSignature: 'new' })
|
|
36
|
+
* if (action.shouldRender) { const token = action.token }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function getMermaidHostRenderAction(input) {
|
|
40
|
+
const status = input.status?.trim();
|
|
41
|
+
const renderedSignature = input.renderedSignature?.trim();
|
|
42
|
+
if ((status === 'ready' || status === 'rendering' || status === 'error')
|
|
43
|
+
&& renderedSignature === input.nextSignature) {
|
|
44
|
+
return { shouldRender: false };
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
shouldRender: true,
|
|
48
|
+
token: input.nextSignature,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 判断异步 Mermaid 渲染结果是否仍对应当前 host 源码。
|
|
53
|
+
* @param renderToken - 异步渲染启动时捕获的 token。
|
|
54
|
+
* @param currentSignature - 宿主当前源码签名。
|
|
55
|
+
* @returns 渲染 token 是否仍匹配当前源码签名。
|
|
56
|
+
*
|
|
57
|
+
* @example 模块内部上下文
|
|
58
|
+
* ```ts
|
|
59
|
+
* const accepted = isCurrentMermaidRenderToken('current-source', 'current-source')
|
|
60
|
+
* const stale = isCurrentMermaidRenderToken('old-source', 'current-source')
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export function isCurrentMermaidRenderToken(renderToken, currentSignature) {
|
|
64
|
+
return renderToken === currentSignature;
|
|
65
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @h-ai/ui — Mermaid 图表渲染助手
|
|
3
|
+
*
|
|
4
|
+
* 以懒加载方式引入 mermaid,把图表源码渲染为安全的 SVG。
|
|
5
|
+
* 使用 `securityLevel: 'strict'`,由 mermaid 自身完成消毒,避免 {@html} 注入风险。
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 判断 fence 语言是否为 mermaid。
|
|
9
|
+
* @param language - 待识别的语言标记。
|
|
10
|
+
* @returns 语言标记是否属于 Mermaid。
|
|
11
|
+
*
|
|
12
|
+
* @example 模块内部上下文
|
|
13
|
+
* ```ts
|
|
14
|
+
* const supported = isMermaidLanguage('mermaid')
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function isMermaidLanguage(language: string | undefined | null): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 把 mermaid 源码渲染为 SVG 字符串;语法错误时抛出由调用方兜底展示。
|
|
20
|
+
* @param code - Mermaid 或待渲染的代码源码。
|
|
21
|
+
* @returns 严格模式渲染的 SVG;保留节点、连线和文字所需的样式。
|
|
22
|
+
* @throws 浏览器渲染、第三方解析或下载失败时抛出异常,由交互边界显示错误。
|
|
23
|
+
*
|
|
24
|
+
* @example 模块内部上下文
|
|
25
|
+
* ```ts
|
|
26
|
+
* const svg = await renderMermaidDiagram('graph TD; A-->B')
|
|
27
|
+
* // 在浏览器异步渲染,失败由调用交互边界处理。
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function renderMermaidDiagram(code: string): Promise<string>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @h-ai/ui — Mermaid 图表渲染助手
|
|
3
|
+
*
|
|
4
|
+
* 以懒加载方式引入 mermaid,把图表源码渲染为安全的 SVG。
|
|
5
|
+
* 使用 `securityLevel: 'strict'`,由 mermaid 自身完成消毒,避免 {@html} 注入风险。
|
|
6
|
+
*/
|
|
7
|
+
/** mermaid 模块只在首次渲染时动态加载,并缓存初始化后的实例。 */
|
|
8
|
+
let mermaidLoader = null;
|
|
9
|
+
/** render id 需要在页面内唯一,递增计数器即可保证不冲突。 */
|
|
10
|
+
let renderSeq = 0;
|
|
11
|
+
/**
|
|
12
|
+
* 判断 fence 语言是否为 mermaid。
|
|
13
|
+
* @param language - 待识别的语言标记。
|
|
14
|
+
* @returns 语言标记是否属于 Mermaid。
|
|
15
|
+
*
|
|
16
|
+
* @example 模块内部上下文
|
|
17
|
+
* ```ts
|
|
18
|
+
* const supported = isMermaidLanguage('mermaid')
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function isMermaidLanguage(language) {
|
|
22
|
+
return (language ?? '').trim().toLowerCase() === 'mermaid';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 懒加载并初始化 mermaid,多次调用复用同一实例。
|
|
26
|
+
*/
|
|
27
|
+
async function loadMermaid() {
|
|
28
|
+
if (!mermaidLoader) {
|
|
29
|
+
mermaidLoader = import('mermaid').then((module) => {
|
|
30
|
+
const mermaid = module.default;
|
|
31
|
+
mermaid.initialize({
|
|
32
|
+
startOnLoad: false,
|
|
33
|
+
securityLevel: 'strict',
|
|
34
|
+
theme: 'default',
|
|
35
|
+
// 不允许文档指令修改安全策略、消毒规则或注入页面级 CSS。
|
|
36
|
+
secure: ['secure', 'securityLevel', 'startOnLoad', 'maxTextSize', 'suppressErrorRendering', 'maxEdges', 'themeCSS', 'themeVariables', 'fontFamily', 'altFontFamily', 'dompurifyConfig'],
|
|
37
|
+
});
|
|
38
|
+
return mermaid;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return mermaidLoader;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 把 mermaid 源码渲染为 SVG 字符串;语法错误时抛出由调用方兜底展示。
|
|
45
|
+
* @param code - Mermaid 或待渲染的代码源码。
|
|
46
|
+
* @returns 严格模式渲染的 SVG;保留节点、连线和文字所需的样式。
|
|
47
|
+
* @throws 浏览器渲染、第三方解析或下载失败时抛出异常,由交互边界显示错误。
|
|
48
|
+
*
|
|
49
|
+
* @example 模块内部上下文
|
|
50
|
+
* ```ts
|
|
51
|
+
* const svg = await renderMermaidDiagram('graph TD; A-->B')
|
|
52
|
+
* // 在浏览器异步渲染,失败由调用交互边界处理。
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export async function renderMermaidDiagram(code) {
|
|
56
|
+
const mermaid = await loadMermaid();
|
|
57
|
+
const renderId = `hai-mermaid-${Date.now()}-${renderSeq++}`;
|
|
58
|
+
const { svg } = await mermaid.render(renderId, code);
|
|
59
|
+
// 编辑预览中隐藏样式节点自身,但保留其 CSS 规则;删除规则会使节点成为黑色实心块。
|
|
60
|
+
return svg.replace(/<style>/gi, '<style style="display:none">');
|
|
61
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @h-ai/ui — Markdown 渲染的安全 HTML 工具。
|
|
3
|
+
*
|
|
4
|
+
* Markdown 默认将原始 HTML 当作纯文本转义。
|
|
5
|
+
* 显式允许 HTML 后,也只重建白名单中的安全标签与
|
|
6
|
+
* 属性;不支持或危险的标记仍按文字转义。
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 将候选文本中的 HTML 特殊字符转义为可安全展示的纯文本。
|
|
10
|
+
* @param text - 待处理文本。
|
|
11
|
+
* @returns HTML 特殊字符被转义的字符串。
|
|
12
|
+
*
|
|
13
|
+
* @example 模块内部上下文
|
|
14
|
+
* ```ts
|
|
15
|
+
* const escaped = escapeHtml('<b>文本</b>')
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function escapeHtml(text: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* 拒绝脚本等危险协议,只输出允许的链接地址。
|
|
21
|
+
* @param href - 待验证的链接候选地址。
|
|
22
|
+
* @returns 允许的链接地址,不安全或空输入返回空字符串。
|
|
23
|
+
*
|
|
24
|
+
* @example 模块内部上下文
|
|
25
|
+
* ```ts
|
|
26
|
+
* const safe = sanitizeLinkHref('javascript:alert(1)')
|
|
27
|
+
* // 不安全协议变为空字符串,不能直接渲染原始 href。
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function sanitizeLinkHref(href: string | null | undefined): string;
|
|
31
|
+
/**
|
|
32
|
+
* 识别外部链接,供渲染器添加相应的 rel/target 安全属性。
|
|
33
|
+
* @param href - 待验证的链接候选地址。
|
|
34
|
+
* @returns 地址是否为需要外链安全属性的外部链接。
|
|
35
|
+
*
|
|
36
|
+
* @example 模块内部上下文
|
|
37
|
+
* ```ts
|
|
38
|
+
* const external = isExternalLinkHref('https://example.com/help')
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function isExternalLinkHref(href: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* 拒绝危险图片来源,保留允许的远程、相对或受控数据地址。
|
|
44
|
+
* @param src - 待验证的图片候选地址。
|
|
45
|
+
* @returns 允许的图片地址,不安全或空输入返回空字符串。
|
|
46
|
+
*
|
|
47
|
+
* @example 模块内部上下文
|
|
48
|
+
* ```ts
|
|
49
|
+
* const safe = sanitizeImageSrc('https://example.com/image.png')
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function sanitizeImageSrc(src: string | null | undefined): string;
|
|
53
|
+
/**
|
|
54
|
+
* 消毒 Markdown 中嵌入的原始 HTML 片段。
|
|
55
|
+
* 只重建白名单标签,其余内容保持转义。
|
|
56
|
+
* @param fragment - 待消毒的 HTML 片段。
|
|
57
|
+
* @returns 仅保留白名单标签和安全属性的 HTML。
|
|
58
|
+
*
|
|
59
|
+
* @example 模块内部上下文
|
|
60
|
+
* ```ts
|
|
61
|
+
* const safe = sanitizeMarkdownHtml('<p onclick="alert(1)">正文</p>')
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function sanitizeMarkdownHtml(fragment: string): string;
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @h-ai/ui — Markdown 渲染的安全 HTML 工具。
|
|
3
|
+
*
|
|
4
|
+
* Markdown 默认将原始 HTML 当作纯文本转义。
|
|
5
|
+
* 显式允许 HTML 后,也只重建白名单中的安全标签与
|
|
6
|
+
* 属性;不支持或危险的标记仍按文字转义。
|
|
7
|
+
*/
|
|
8
|
+
const SAFE_LINK_HREF_REGEX = /^(?:https?:\/\/|\/|#|mailto:)/i;
|
|
9
|
+
const SAFE_IMAGE_SRC_REGEX = /^(?:https?:\/\/|\/|data:image\/)/i;
|
|
10
|
+
const SAFE_ALIGN_VALUE_REGEX = /^(?:left|center|right|justify)$/i;
|
|
11
|
+
const SAFE_TABLE_SPAN_REGEX = /^[1-9]\d{0,2}$/;
|
|
12
|
+
const SAFE_IMAGE_DIMENSION_REGEX = /^[1-9]\d{0,4}$/;
|
|
13
|
+
const HTML_ATTR_REGEX = /([^\s"'=<>`/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
14
|
+
const ALLOWED_HTML_TAGS = new Set([
|
|
15
|
+
'a',
|
|
16
|
+
'b',
|
|
17
|
+
'blockquote',
|
|
18
|
+
'br',
|
|
19
|
+
'code',
|
|
20
|
+
'del',
|
|
21
|
+
'div',
|
|
22
|
+
'em',
|
|
23
|
+
'h1',
|
|
24
|
+
'h2',
|
|
25
|
+
'h3',
|
|
26
|
+
'h4',
|
|
27
|
+
'h5',
|
|
28
|
+
'h6',
|
|
29
|
+
'hr',
|
|
30
|
+
'i',
|
|
31
|
+
'img',
|
|
32
|
+
'kbd',
|
|
33
|
+
'li',
|
|
34
|
+
'mark',
|
|
35
|
+
'ol',
|
|
36
|
+
'p',
|
|
37
|
+
'pre',
|
|
38
|
+
's',
|
|
39
|
+
'span',
|
|
40
|
+
'strong',
|
|
41
|
+
'sub',
|
|
42
|
+
'sup',
|
|
43
|
+
'table',
|
|
44
|
+
'tbody',
|
|
45
|
+
'td',
|
|
46
|
+
'th',
|
|
47
|
+
'thead',
|
|
48
|
+
'tr',
|
|
49
|
+
'u',
|
|
50
|
+
'ul',
|
|
51
|
+
]);
|
|
52
|
+
const VOID_HTML_TAGS = new Set(['br', 'hr', 'img']);
|
|
53
|
+
const ALIGNABLE_HTML_TAGS = new Set([
|
|
54
|
+
'blockquote',
|
|
55
|
+
'div',
|
|
56
|
+
'h1',
|
|
57
|
+
'h2',
|
|
58
|
+
'h3',
|
|
59
|
+
'h4',
|
|
60
|
+
'h5',
|
|
61
|
+
'h6',
|
|
62
|
+
'li',
|
|
63
|
+
'p',
|
|
64
|
+
'td',
|
|
65
|
+
'th',
|
|
66
|
+
]);
|
|
67
|
+
/**
|
|
68
|
+
* 将候选文本中的 HTML 特殊字符转义为可安全展示的纯文本。
|
|
69
|
+
* @param text - 待处理文本。
|
|
70
|
+
* @returns HTML 特殊字符被转义的字符串。
|
|
71
|
+
*
|
|
72
|
+
* @example 模块内部上下文
|
|
73
|
+
* ```ts
|
|
74
|
+
* const escaped = escapeHtml('<b>文本</b>')
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function escapeHtml(text) {
|
|
78
|
+
return text
|
|
79
|
+
.replace(/&/g, '&')
|
|
80
|
+
.replace(/</g, '<')
|
|
81
|
+
.replace(/>/g, '>')
|
|
82
|
+
.replace(/"/g, '"')
|
|
83
|
+
.replace(/'/g, ''');
|
|
84
|
+
}
|
|
85
|
+
/** 仅用于已分离的 HTML 文本:保留实体的一层含义,不把编码标签重新交给标签解析器。 */
|
|
86
|
+
function escapeHtmlText(text) {
|
|
87
|
+
return escapeHtml(text).replace(/&((?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z][a-zA-Z\d]+);)/g, '&$1');
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 拒绝脚本等危险协议,只输出允许的链接地址。
|
|
91
|
+
* @param href - 待验证的链接候选地址。
|
|
92
|
+
* @returns 允许的链接地址,不安全或空输入返回空字符串。
|
|
93
|
+
*
|
|
94
|
+
* @example 模块内部上下文
|
|
95
|
+
* ```ts
|
|
96
|
+
* const safe = sanitizeLinkHref('javascript:alert(1)')
|
|
97
|
+
* // 不安全协议变为空字符串,不能直接渲染原始 href。
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export function sanitizeLinkHref(href) {
|
|
101
|
+
const normalized = href?.trim() ?? '';
|
|
102
|
+
return SAFE_LINK_HREF_REGEX.test(normalized) ? normalized : '';
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 识别外部链接,供渲染器添加相应的 rel/target 安全属性。
|
|
106
|
+
* @param href - 待验证的链接候选地址。
|
|
107
|
+
* @returns 地址是否为需要外链安全属性的外部链接。
|
|
108
|
+
*
|
|
109
|
+
* @example 模块内部上下文
|
|
110
|
+
* ```ts
|
|
111
|
+
* const external = isExternalLinkHref('https://example.com/help')
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export function isExternalLinkHref(href) {
|
|
115
|
+
return /^https?:\/\//i.test(href);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 拒绝危险图片来源,保留允许的远程、相对或受控数据地址。
|
|
119
|
+
* @param src - 待验证的图片候选地址。
|
|
120
|
+
* @returns 允许的图片地址,不安全或空输入返回空字符串。
|
|
121
|
+
*
|
|
122
|
+
* @example 模块内部上下文
|
|
123
|
+
* ```ts
|
|
124
|
+
* const safe = sanitizeImageSrc('https://example.com/image.png')
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export function sanitizeImageSrc(src) {
|
|
128
|
+
const normalized = src?.trim() ?? '';
|
|
129
|
+
return SAFE_IMAGE_SRC_REGEX.test(normalized) ? normalized : '';
|
|
130
|
+
}
|
|
131
|
+
function sanitizeAlignValue(value) {
|
|
132
|
+
const normalized = value?.trim().toLowerCase();
|
|
133
|
+
return normalized && SAFE_ALIGN_VALUE_REGEX.test(normalized)
|
|
134
|
+
? normalized
|
|
135
|
+
: undefined;
|
|
136
|
+
}
|
|
137
|
+
function parseHtmlAttributes(rawAttributes) {
|
|
138
|
+
const attributes = [];
|
|
139
|
+
for (const match of rawAttributes.matchAll(HTML_ATTR_REGEX)) {
|
|
140
|
+
const [, rawName, quotedDouble, quotedSingle, unquoted] = match;
|
|
141
|
+
const attrName = rawName?.trim().toLowerCase();
|
|
142
|
+
if (!attrName) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const attrValue = quotedDouble ?? quotedSingle ?? unquoted ?? '';
|
|
146
|
+
attributes.push([attrName, attrValue]);
|
|
147
|
+
}
|
|
148
|
+
return attributes;
|
|
149
|
+
}
|
|
150
|
+
function isHtmlTagNameChar(char) {
|
|
151
|
+
return typeof char === 'string' && /^[\w:-]$/.test(char);
|
|
152
|
+
}
|
|
153
|
+
function skipWhitespace(source, startIndex) {
|
|
154
|
+
let cursor = startIndex;
|
|
155
|
+
while (cursor < source.length && /\s/.test(source[cursor] ?? '')) {
|
|
156
|
+
cursor += 1;
|
|
157
|
+
}
|
|
158
|
+
return cursor;
|
|
159
|
+
}
|
|
160
|
+
function findHtmlTagEnd(source, startIndex) {
|
|
161
|
+
let quote = null;
|
|
162
|
+
for (let cursor = startIndex; cursor < source.length; cursor += 1) {
|
|
163
|
+
const char = source[cursor];
|
|
164
|
+
if (quote) {
|
|
165
|
+
if (char === quote) {
|
|
166
|
+
quote = null;
|
|
167
|
+
}
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (char === '"' || char === '\'') {
|
|
171
|
+
quote = char;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (char === '>') {
|
|
175
|
+
return cursor;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return -1;
|
|
179
|
+
}
|
|
180
|
+
function readNextHtmlTag(source, startIndex) {
|
|
181
|
+
let cursor = source.indexOf('<', startIndex);
|
|
182
|
+
while (cursor >= 0) {
|
|
183
|
+
const nextChar = source[cursor + 1];
|
|
184
|
+
if (!nextChar || (nextChar !== '/' && !/[a-z]/i.test(nextChar))) {
|
|
185
|
+
cursor = source.indexOf('<', cursor + 1);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const tagEnd = findHtmlTagEnd(source, cursor + 1);
|
|
189
|
+
if (tagEnd < 0) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
rawTag: source.slice(cursor, tagEnd + 1),
|
|
194
|
+
start: cursor,
|
|
195
|
+
end: tagEnd + 1,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
function readSanitizedAttributes(tagName, rawAttributes) {
|
|
201
|
+
const sanitized = {};
|
|
202
|
+
for (const [attrName, attrValue] of parseHtmlAttributes(rawAttributes)) {
|
|
203
|
+
if (tagName === 'a') {
|
|
204
|
+
if (attrName === 'href') {
|
|
205
|
+
sanitized.href = sanitizeLinkHref(attrValue);
|
|
206
|
+
}
|
|
207
|
+
if (attrName === 'title' && attrValue.trim()) {
|
|
208
|
+
sanitized.title = attrValue.trim();
|
|
209
|
+
}
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (tagName === 'img') {
|
|
213
|
+
if (attrName === 'src') {
|
|
214
|
+
sanitized.src = sanitizeImageSrc(attrValue);
|
|
215
|
+
}
|
|
216
|
+
if (attrName === 'alt') {
|
|
217
|
+
sanitized.alt = attrValue;
|
|
218
|
+
}
|
|
219
|
+
// 保留有限的正整数像素尺寸,让延迟加载图片提前占位,仍拒绝style和事件属性。
|
|
220
|
+
if ((attrName === 'width' || attrName === 'height') && SAFE_IMAGE_DIMENSION_REGEX.test(attrValue.trim())) {
|
|
221
|
+
sanitized[attrName] = attrValue.trim();
|
|
222
|
+
}
|
|
223
|
+
if (attrName === 'title' && attrValue.trim()) {
|
|
224
|
+
sanitized.title = attrValue.trim();
|
|
225
|
+
}
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (ALIGNABLE_HTML_TAGS.has(tagName) && attrName === 'align') {
|
|
229
|
+
sanitized.align = sanitizeAlignValue(attrValue);
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if ((tagName === 'td' || tagName === 'th') && attrName === 'colspan') {
|
|
233
|
+
const normalized = attrValue.trim();
|
|
234
|
+
if (SAFE_TABLE_SPAN_REGEX.test(normalized)) {
|
|
235
|
+
sanitized.colspan = normalized;
|
|
236
|
+
}
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if ((tagName === 'td' || tagName === 'th') && attrName === 'rowspan') {
|
|
240
|
+
const normalized = attrValue.trim();
|
|
241
|
+
if (SAFE_TABLE_SPAN_REGEX.test(normalized)) {
|
|
242
|
+
sanitized.rowspan = normalized;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return sanitized;
|
|
247
|
+
}
|
|
248
|
+
function sanitizeHtmlTag(rawTag) {
|
|
249
|
+
if (!rawTag.startsWith('<') || !rawTag.endsWith('>')) {
|
|
250
|
+
return escapeHtml(rawTag);
|
|
251
|
+
}
|
|
252
|
+
let cursor = 1;
|
|
253
|
+
cursor = skipWhitespace(rawTag, cursor);
|
|
254
|
+
let isClosingTag = false;
|
|
255
|
+
if (rawTag[cursor] === '/') {
|
|
256
|
+
isClosingTag = true;
|
|
257
|
+
cursor += 1;
|
|
258
|
+
cursor = skipWhitespace(rawTag, cursor);
|
|
259
|
+
}
|
|
260
|
+
const tagNameStart = cursor;
|
|
261
|
+
while (isHtmlTagNameChar(rawTag[cursor])) {
|
|
262
|
+
cursor += 1;
|
|
263
|
+
}
|
|
264
|
+
const tagName = rawTag.slice(tagNameStart, cursor).toLowerCase();
|
|
265
|
+
if (!tagName) {
|
|
266
|
+
return escapeHtml(rawTag);
|
|
267
|
+
}
|
|
268
|
+
let rawAttributes = rawTag.slice(cursor, -1);
|
|
269
|
+
let selfClosing = false;
|
|
270
|
+
const trimmedAttributes = rawAttributes.trimEnd();
|
|
271
|
+
if (trimmedAttributes.endsWith('/')) {
|
|
272
|
+
selfClosing = true;
|
|
273
|
+
rawAttributes = trimmedAttributes.slice(0, -1);
|
|
274
|
+
}
|
|
275
|
+
if (!ALLOWED_HTML_TAGS.has(tagName)) {
|
|
276
|
+
return escapeHtml(rawTag);
|
|
277
|
+
}
|
|
278
|
+
if (isClosingTag) {
|
|
279
|
+
return VOID_HTML_TAGS.has(tagName) ? '' : `</${tagName}>`;
|
|
280
|
+
}
|
|
281
|
+
const attributes = readSanitizedAttributes(tagName, rawAttributes);
|
|
282
|
+
const renderedAttributes = [];
|
|
283
|
+
if (attributes.href !== undefined) {
|
|
284
|
+
renderedAttributes.push(`href="${escapeHtml(attributes.href)}"`);
|
|
285
|
+
if (attributes.href && isExternalLinkHref(attributes.href)) {
|
|
286
|
+
renderedAttributes.push('target="_blank"');
|
|
287
|
+
renderedAttributes.push('rel="noopener noreferrer"');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (attributes.title) {
|
|
291
|
+
renderedAttributes.push(`title="${escapeHtml(attributes.title)}"`);
|
|
292
|
+
}
|
|
293
|
+
if (attributes.src !== undefined) {
|
|
294
|
+
renderedAttributes.push(`src="${escapeHtml(attributes.src)}"`);
|
|
295
|
+
renderedAttributes.push('loading="lazy"');
|
|
296
|
+
renderedAttributes.push('class="hai-md-img"');
|
|
297
|
+
}
|
|
298
|
+
if (attributes.alt !== undefined) {
|
|
299
|
+
renderedAttributes.push(`alt="${escapeHtml(attributes.alt)}"`);
|
|
300
|
+
}
|
|
301
|
+
for (const dimension of ['width', 'height']) {
|
|
302
|
+
if (attributes[dimension])
|
|
303
|
+
renderedAttributes.push(`${dimension}="${attributes[dimension]}"`);
|
|
304
|
+
}
|
|
305
|
+
if (attributes.align) {
|
|
306
|
+
renderedAttributes.push(`style="text-align:${escapeHtml(attributes.align)}"`);
|
|
307
|
+
}
|
|
308
|
+
if (attributes.colspan) {
|
|
309
|
+
renderedAttributes.push(`colspan="${escapeHtml(attributes.colspan)}"`);
|
|
310
|
+
}
|
|
311
|
+
if (attributes.rowspan) {
|
|
312
|
+
renderedAttributes.push(`rowspan="${escapeHtml(attributes.rowspan)}"`);
|
|
313
|
+
}
|
|
314
|
+
const attributeText = renderedAttributes.length > 0
|
|
315
|
+
? ` ${renderedAttributes.join(' ')}`
|
|
316
|
+
: '';
|
|
317
|
+
return VOID_HTML_TAGS.has(tagName) || selfClosing
|
|
318
|
+
? `<${tagName}${attributeText} />`
|
|
319
|
+
: `<${tagName}${attributeText}>`;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* 消毒 Markdown 中嵌入的原始 HTML 片段。
|
|
323
|
+
* 只重建白名单标签,其余内容保持转义。
|
|
324
|
+
* @param fragment - 待消毒的 HTML 片段。
|
|
325
|
+
* @returns 仅保留白名单标签和安全属性的 HTML。
|
|
326
|
+
*
|
|
327
|
+
* @example 模块内部上下文
|
|
328
|
+
* ```ts
|
|
329
|
+
* const safe = sanitizeMarkdownHtml('<p onclick="alert(1)">正文</p>')
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
export function sanitizeMarkdownHtml(fragment) {
|
|
333
|
+
if (!fragment) {
|
|
334
|
+
return '';
|
|
335
|
+
}
|
|
336
|
+
let sanitized = '';
|
|
337
|
+
let lastIndex = 0;
|
|
338
|
+
for (let match = readNextHtmlTag(fragment, lastIndex); match; match = readNextHtmlTag(fragment, lastIndex)) {
|
|
339
|
+
sanitized += escapeHtmlText(fragment.slice(lastIndex, match.start));
|
|
340
|
+
sanitized += sanitizeHtmlTag(match.rawTag);
|
|
341
|
+
lastIndex = match.end;
|
|
342
|
+
}
|
|
343
|
+
sanitized += escapeHtmlText(fragment.slice(lastIndex));
|
|
344
|
+
return sanitized;
|
|
345
|
+
}
|