taro-uno-ui 0.9.0-beta
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/LICENSE +100 -0
- package/README.md +273 -0
- package/dist/js/index-6NJ3A1Dn.js +26535 -0
- package/dist/js/index-6NJ3A1Dn.js.map +1 -0
- package/dist/js/index-DFdcksbe.js +1165 -0
- package/dist/js/index-DFdcksbe.js.map +1 -0
- package/dist/js/index-DXRIkWX1.js +1148 -0
- package/dist/js/index-DXRIkWX1.js.map +1 -0
- package/dist/js/index-DffLRSro.js +26519 -0
- package/dist/js/index-DffLRSro.js.map +1 -0
- package/package.json +119 -0
- package/src/app.config.ts +55 -0
- package/src/app.scss +508 -0
- package/src/app.tsx +44 -0
- package/src/components/basic/Button/Button.styles.ts +130 -0
- package/src/components/basic/Button/Button.test.tsx +154 -0
- package/src/components/basic/Button/Button.tsx +93 -0
- package/src/components/basic/Button/Button.types.ts +45 -0
- package/src/components/basic/Button/index.tsx +6 -0
- package/src/components/basic/Divider/Divider.styles.ts +488 -0
- package/src/components/basic/Divider/Divider.test.tsx +551 -0
- package/src/components/basic/Divider/Divider.tsx +361 -0
- package/src/components/basic/Divider/Divider.types.ts +261 -0
- package/src/components/basic/Divider/index.tsx +25 -0
- package/src/components/basic/Icon/Icon.styles.ts +359 -0
- package/src/components/basic/Icon/Icon.test.tsx +357 -0
- package/src/components/basic/Icon/Icon.tsx +154 -0
- package/src/components/basic/Icon/Icon.types.ts +210 -0
- package/src/components/basic/Icon/index.tsx +22 -0
- package/src/components/basic/Text/Text.styles.ts +500 -0
- package/src/components/basic/Text/Text.test.tsx +299 -0
- package/src/components/basic/Text/Text.tsx +340 -0
- package/src/components/basic/Text/Text.types.ts +319 -0
- package/src/components/basic/Text/index.tsx +27 -0
- package/src/components/basic/Typography/Typography.styles.ts +346 -0
- package/src/components/basic/Typography/Typography.tsx +205 -0
- package/src/components/basic/Typography/Typography.types.ts +296 -0
- package/src/components/basic/Typography/index.tsx +14 -0
- package/src/components/basic/index.tsx +302 -0
- package/src/components/common/ErrorBoundary.tsx +87 -0
- package/src/components/common/LazyComponent.tsx +246 -0
- package/src/components/common/ResponsiveContainer.tsx +93 -0
- package/src/components/common/ResponsiveGrid.tsx +183 -0
- package/src/components/common/SecurityProvider.tsx +110 -0
- package/src/components/common/ThemeProvider.tsx +128 -0
- package/src/components/common/VirtualList.tsx +368 -0
- package/src/components/common/__tests__/ErrorBoundary.test.tsx +249 -0
- package/src/components/common/index.tsx +7 -0
- package/src/components/display/Avatar/Avatar.styles.ts +62 -0
- package/src/components/display/Avatar/Avatar.test.tsx +390 -0
- package/src/components/display/Avatar/Avatar.tsx +79 -0
- package/src/components/display/Avatar/Avatar.types.ts +40 -0
- package/src/components/display/Avatar/index.ts +3 -0
- package/src/components/display/Badge/Badge.tsx +42 -0
- package/src/components/display/Badge/Badge.types.ts +29 -0
- package/src/components/display/Badge/index.ts +2 -0
- package/src/components/display/Calendar/Calendar.styles.ts +255 -0
- package/src/components/display/Calendar/Calendar.test.tsx +30 -0
- package/src/components/display/Calendar/Calendar.tsx +337 -0
- package/src/components/display/Calendar/Calendar.types.ts +91 -0
- package/src/components/display/Calendar/index.ts +3 -0
- package/src/components/display/Card/Card.styles.ts +89 -0
- package/src/components/display/Card/Card.test.tsx +180 -0
- package/src/components/display/Card/Card.tsx +135 -0
- package/src/components/display/Card/Card.types.ts +55 -0
- package/src/components/display/Card/index.ts +3 -0
- package/src/components/display/Carousel/Carousel.styles.ts +206 -0
- package/src/components/display/Carousel/Carousel.tsx +295 -0
- package/src/components/display/Carousel/Carousel.types.ts +57 -0
- package/src/components/display/Carousel/index.ts +3 -0
- package/src/components/display/List/List.styles.ts +79 -0
- package/src/components/display/List/List.tsx +115 -0
- package/src/components/display/List/List.types.ts +68 -0
- package/src/components/display/List/index.ts +3 -0
- package/src/components/display/Rate/Rate.styles.ts +266 -0
- package/src/components/display/Rate/Rate.tsx +332 -0
- package/src/components/display/Rate/Rate.types.ts +111 -0
- package/src/components/display/Rate/index.ts +28 -0
- package/src/components/display/Table/Table.styles.ts +269 -0
- package/src/components/display/Table/Table.test.tsx +343 -0
- package/src/components/display/Table/Table.tsx +430 -0
- package/src/components/display/Table/Table.types.ts +255 -0
- package/src/components/display/Table/index.tsx +16 -0
- package/src/components/display/Tag/Tag.styles.ts +197 -0
- package/src/components/display/Tag/Tag.test.tsx +541 -0
- package/src/components/display/Tag/Tag.tsx +156 -0
- package/src/components/display/Tag/Tag.types.ts +49 -0
- package/src/components/display/Tag/index.ts +3 -0
- package/src/components/display/Timeline/Timeline.styles.ts +211 -0
- package/src/components/display/Timeline/Timeline.tsx +239 -0
- package/src/components/display/Timeline/Timeline.types.ts +56 -0
- package/src/components/display/Timeline/index.ts +3 -0
- package/src/components/display/index.tsx +143 -0
- package/src/components/feedback/Loading/Loading.styles.ts +117 -0
- package/src/components/feedback/Loading/Loading.test.tsx +534 -0
- package/src/components/feedback/Loading/Loading.tsx +127 -0
- package/src/components/feedback/Loading/Loading.types.ts +33 -0
- package/src/components/feedback/Loading/index.ts +9 -0
- package/src/components/feedback/Message/Message.styles.ts +41 -0
- package/src/components/feedback/Message/Message.test.tsx +234 -0
- package/src/components/feedback/Message/Message.tsx +96 -0
- package/src/components/feedback/Message/Message.types.ts +37 -0
- package/src/components/feedback/Message/index.ts +9 -0
- package/src/components/feedback/Modal/Modal.styles.ts +21 -0
- package/src/components/feedback/Modal/Modal.test.tsx +11 -0
- package/src/components/feedback/Modal/Modal.tsx +291 -0
- package/src/components/feedback/Modal/Modal.types.ts +141 -0
- package/src/components/feedback/Modal/index.tsx +11 -0
- package/src/components/feedback/Notification/Notification.styles.ts +443 -0
- package/src/components/feedback/Notification/Notification.test.tsx +401 -0
- package/src/components/feedback/Notification/Notification.tsx +370 -0
- package/src/components/feedback/Notification/Notification.types.ts +336 -0
- package/src/components/feedback/Notification/NotificationManager.tsx +376 -0
- package/src/components/feedback/Notification/index.ts +33 -0
- package/src/components/feedback/Notification/index.tsx +164 -0
- package/src/components/feedback/Progress/Progress.styles.ts +460 -0
- package/src/components/feedback/Progress/Progress.test.simple.tsx +14 -0
- package/src/components/feedback/Progress/Progress.test.tsx +312 -0
- package/src/components/feedback/Progress/Progress.tsx +508 -0
- package/src/components/feedback/Progress/Progress.types.ts +163 -0
- package/src/components/feedback/Progress/index.ts +3 -0
- package/src/components/feedback/Progress/index.tsx +38 -0
- package/src/components/feedback/Progress/utils/animation.ts +204 -0
- package/src/components/feedback/Progress/utils/index.ts +26 -0
- package/src/components/feedback/Progress/utils/progress-calculator.ts +217 -0
- package/src/components/feedback/Result/Result.styles.ts +139 -0
- package/src/components/feedback/Result/Result.tsx +233 -0
- package/src/components/feedback/Result/Result.types.ts +128 -0
- package/src/components/feedback/Result/index.tsx +3 -0
- package/src/components/feedback/Toast/Toast.styles.ts +17 -0
- package/src/components/feedback/Toast/Toast.test.tsx +10 -0
- package/src/components/feedback/Toast/Toast.tsx +372 -0
- package/src/components/feedback/Toast/Toast.types.ts +86 -0
- package/src/components/feedback/Toast/index.tsx +3 -0
- package/src/components/feedback/Tooltip/Tooltip.examples.tsx +458 -0
- package/src/components/feedback/Tooltip/Tooltip.styles.ts +346 -0
- package/src/components/feedback/Tooltip/Tooltip.test.tsx +446 -0
- package/src/components/feedback/Tooltip/Tooltip.tsx +283 -0
- package/src/components/feedback/Tooltip/Tooltip.types.ts +172 -0
- package/src/components/feedback/Tooltip/index.ts +3 -0
- package/src/components/feedback/Tooltip/index.tsx +258 -0
- package/src/components/feedback/index.tsx +164 -0
- package/src/components/form/Cascader/Cascader.styles.ts +526 -0
- package/src/components/form/Cascader/Cascader.test.tsx +77 -0
- package/src/components/form/Cascader/Cascader.tsx +585 -0
- package/src/components/form/Cascader/Cascader.types.ts +582 -0
- package/src/components/form/Cascader/hooks/index.ts +3 -0
- package/src/components/form/Cascader/hooks/useCascaderFieldNames.ts +16 -0
- package/src/components/form/Cascader/hooks/useCascaderOptions.ts +109 -0
- package/src/components/form/Cascader/hooks/useCascaderState.ts +133 -0
- package/src/components/form/Cascader/index.ts +25 -0
- package/src/components/form/Cascader/utils/formatDisplayValue.ts +19 -0
- package/src/components/form/Cascader/utils/index.ts +1 -0
- package/src/components/form/Checkbox/Checkbox.styles.ts +608 -0
- package/src/components/form/Checkbox/Checkbox.test.tsx +1140 -0
- package/src/components/form/Checkbox/Checkbox.tsx +496 -0
- package/src/components/form/Checkbox/Checkbox.types.ts +472 -0
- package/src/components/form/Checkbox/CheckboxGroup.tsx +444 -0
- package/src/components/form/Checkbox/index.tsx +27 -0
- package/src/components/form/DatePicker/DatePicker.styles.ts +393 -0
- package/src/components/form/DatePicker/DatePicker.test.tsx +407 -0
- package/src/components/form/DatePicker/DatePicker.tsx +360 -0
- package/src/components/form/DatePicker/DatePicker.types.ts +247 -0
- package/src/components/form/DatePicker/index.tsx +15 -0
- package/src/components/form/Form/Form.styles.ts +357 -0
- package/src/components/form/Form/Form.test.tsx +122 -0
- package/src/components/form/Form/Form.tsx +695 -0
- package/src/components/form/Form/Form.types.ts +407 -0
- package/src/components/form/Form/index.tsx +31 -0
- package/src/components/form/Input/Input.enhanced.tsx +732 -0
- package/src/components/form/Input/Input.styles.ts +438 -0
- package/src/components/form/Input/Input.test.tsx +494 -0
- package/src/components/form/Input/Input.tsx +541 -0
- package/src/components/form/Input/Input.types.ts +285 -0
- package/src/components/form/Input/index.tsx +26 -0
- package/src/components/form/InputNumber/InputNumber.styles.ts +665 -0
- package/src/components/form/InputNumber/InputNumber.tsx +370 -0
- package/src/components/form/InputNumber/InputNumber.types.ts +318 -0
- package/src/components/form/InputNumber/components/InputNumberClearButton.tsx +32 -0
- package/src/components/form/InputNumber/components/InputNumberControls.tsx +42 -0
- package/src/components/form/InputNumber/components/index.ts +2 -0
- package/src/components/form/InputNumber/hooks/index.ts +4 -0
- package/src/components/form/InputNumber/hooks/useInputNumberState.ts +315 -0
- package/src/components/form/InputNumber/hooks/useInputNumberValidation.ts +147 -0
- package/src/components/form/InputNumber/index.ts +25 -0
- package/src/components/form/Radio/Radio.styles.ts +458 -0
- package/src/components/form/Radio/Radio.test.tsx +547 -0
- package/src/components/form/Radio/Radio.tsx +283 -0
- package/src/components/form/Radio/Radio.types.ts +410 -0
- package/src/components/form/Radio/index.tsx +21 -0
- package/src/components/form/Select/Select.styles.ts +514 -0
- package/src/components/form/Select/Select.test.tsx +648 -0
- package/src/components/form/Select/Select.tsx +474 -0
- package/src/components/form/Select/Select.types.ts +428 -0
- package/src/components/form/Select/index.tsx +30 -0
- package/src/components/form/Slider/Slider.styles.ts +139 -0
- package/src/components/form/Slider/Slider.test.tsx +553 -0
- package/src/components/form/Slider/Slider.tsx +326 -0
- package/src/components/form/Slider/Slider.types.ts +108 -0
- package/src/components/form/Slider/index.tsx +10 -0
- package/src/components/form/Switch/Switch.styles.ts +540 -0
- package/src/components/form/Switch/Switch.test.tsx +345 -0
- package/src/components/form/Switch/Switch.tsx +464 -0
- package/src/components/form/Switch/Switch.types.ts +386 -0
- package/src/components/form/Switch/index.tsx +26 -0
- package/src/components/form/Textarea/Textarea.styles.ts +592 -0
- package/src/components/form/Textarea/Textarea.test.tsx +1075 -0
- package/src/components/form/Textarea/Textarea.tsx +602 -0
- package/src/components/form/Textarea/Textarea.types.ts +371 -0
- package/src/components/form/Textarea/index.tsx +26 -0
- package/src/components/form/TimePicker/TimePicker.styles.ts +438 -0
- package/src/components/form/TimePicker/TimePicker.test.tsx +306 -0
- package/src/components/form/TimePicker/TimePicker.tsx +228 -0
- package/src/components/form/TimePicker/TimePicker.types.ts +385 -0
- package/src/components/form/TimePicker/index.ts +21 -0
- package/src/components/form/Transfer/Transfer.styles.ts +502 -0
- package/src/components/form/Transfer/Transfer.test.tsx +316 -0
- package/src/components/form/Transfer/Transfer.tsx +402 -0
- package/src/components/form/Transfer/Transfer.types.ts +557 -0
- package/src/components/form/Transfer/components/TransferItem.tsx +101 -0
- package/src/components/form/Transfer/components/TransferList.tsx +285 -0
- package/src/components/form/Transfer/components/TransferOperations.tsx +84 -0
- package/src/components/form/Transfer/components/TransferPagination.tsx +135 -0
- package/src/components/form/Transfer/components/TransferSearch.tsx +88 -0
- package/src/components/form/Transfer/components/index.ts +6 -0
- package/src/components/form/Transfer/hooks/index.ts +3 -0
- package/src/components/form/Transfer/hooks/useTransferData.ts +192 -0
- package/src/components/form/Transfer/hooks/useTransferState.ts +114 -0
- package/src/components/form/Transfer/index.ts +33 -0
- package/src/components/form/Upload/Upload.styles.ts +145 -0
- package/src/components/form/Upload/Upload.test.tsx +10 -0
- package/src/components/form/Upload/Upload.tsx +451 -0
- package/src/components/form/Upload/Upload.types.ts +200 -0
- package/src/components/form/Upload/index.tsx +12 -0
- package/src/components/form/index.tsx +121 -0
- package/src/components/index.tsx +146 -0
- package/src/components/layout/Affix/Affix.styles.ts +37 -0
- package/src/components/layout/Affix/Affix.test.tsx +10 -0
- package/src/components/layout/Affix/Affix.tsx +91 -0
- package/src/components/layout/Affix/Affix.types.ts +29 -0
- package/src/components/layout/Affix/index.tsx +3 -0
- package/src/components/layout/Col/Col.styles.ts +185 -0
- package/src/components/layout/Col/Col.test.tsx +535 -0
- package/src/components/layout/Col/Col.tsx +115 -0
- package/src/components/layout/Col/Col.types.ts +59 -0
- package/src/components/layout/Col/index.tsx +3 -0
- package/src/components/layout/Container/Container.styles.ts +161 -0
- package/src/components/layout/Container/Container.test.tsx +380 -0
- package/src/components/layout/Container/Container.tsx +132 -0
- package/src/components/layout/Container/Container.types.ts +63 -0
- package/src/components/layout/Container/index.tsx +3 -0
- package/src/components/layout/Grid/Grid.styles.ts +183 -0
- package/src/components/layout/Grid/Grid.test.tsx +637 -0
- package/src/components/layout/Grid/Grid.tsx +173 -0
- package/src/components/layout/Grid/Grid.types.ts +78 -0
- package/src/components/layout/Grid/index.tsx +3 -0
- package/src/components/layout/Layout/Content.tsx +38 -0
- package/src/components/layout/Layout/Footer.tsx +38 -0
- package/src/components/layout/Layout/Header.tsx +38 -0
- package/src/components/layout/Layout/Layout.styles.ts +84 -0
- package/src/components/layout/Layout/Layout.test.tsx +10 -0
- package/src/components/layout/Layout/Layout.tsx +39 -0
- package/src/components/layout/Layout/Layout.types.ts +58 -0
- package/src/components/layout/Layout/Sider.tsx +56 -0
- package/src/components/layout/Layout/index.tsx +8 -0
- package/src/components/layout/Row/Row.styles.ts +159 -0
- package/src/components/layout/Row/Row.test.tsx +467 -0
- package/src/components/layout/Row/Row.tsx +139 -0
- package/src/components/layout/Row/Row.types.ts +60 -0
- package/src/components/layout/Row/index.tsx +3 -0
- package/src/components/layout/Space/Space.styles.ts +255 -0
- package/src/components/layout/Space/Space.test.tsx +682 -0
- package/src/components/layout/Space/Space.tsx +211 -0
- package/src/components/layout/Space/Space.types.ts +92 -0
- package/src/components/layout/Space/index.tsx +12 -0
- package/src/components/layout/index.tsx +68 -0
- package/src/components/navigation/Menu/Menu.styles.ts +779 -0
- package/src/components/navigation/Menu/Menu.tsx +355 -0
- package/src/components/navigation/Menu/Menu.types.ts +231 -0
- package/src/components/navigation/Menu/Menu.utils.ts +187 -0
- package/src/components/navigation/Menu/MenuItem.tsx +126 -0
- package/src/components/navigation/Menu/SubMenu.tsx +148 -0
- package/src/components/navigation/Menu/__tests__/Menu.test.tsx +687 -0
- package/src/components/navigation/Menu/index.tsx +124 -0
- package/src/components/navigation/NavBar/NavBar.styles.ts +129 -0
- package/src/components/navigation/NavBar/NavBar.test.tsx +287 -0
- package/src/components/navigation/NavBar/NavBar.tsx +231 -0
- package/src/components/navigation/NavBar/NavBar.types.ts +54 -0
- package/src/components/navigation/NavBar/index.tsx +3 -0
- package/src/components/navigation/Pagination/Pagination.styles.ts +187 -0
- package/src/components/navigation/Pagination/Pagination.test.tsx +673 -0
- package/src/components/navigation/Pagination/Pagination.tsx +395 -0
- package/src/components/navigation/Pagination/Pagination.types.ts +86 -0
- package/src/components/navigation/Pagination/index.ts +18 -0
- package/src/components/navigation/Pagination/index.tsx +9 -0
- package/src/components/navigation/Steps/Step.tsx +56 -0
- package/src/components/navigation/Steps/Steps.styles.ts +154 -0
- package/src/components/navigation/Steps/Steps.test.tsx +12 -0
- package/src/components/navigation/Steps/Steps.tsx +113 -0
- package/src/components/navigation/Steps/Steps.types.ts +47 -0
- package/src/components/navigation/Steps/index.tsx +3 -0
- package/src/components/navigation/Tabs/Tabs.styles.ts +199 -0
- package/src/components/navigation/Tabs/Tabs.test.tsx +661 -0
- package/src/components/navigation/Tabs/Tabs.tsx +253 -0
- package/src/components/navigation/Tabs/Tabs.types.ts +114 -0
- package/src/components/navigation/Tabs/index.tsx +3 -0
- package/src/components/navigation/Tree/Tree.styles.ts +553 -0
- package/src/components/navigation/Tree/Tree.test.basic.tsx +7 -0
- package/src/components/navigation/Tree/Tree.test.functional.tsx +496 -0
- package/src/components/navigation/Tree/Tree.test.import.check.tsx +6 -0
- package/src/components/navigation/Tree/Tree.test.import.tsx +6 -0
- package/src/components/navigation/Tree/Tree.test.minimal.tsx +5 -0
- package/src/components/navigation/Tree/Tree.test.simple.tsx +30 -0
- package/src/components/navigation/Tree/Tree.test.tsx +908 -0
- package/src/components/navigation/Tree/Tree.test.working.tsx +673 -0
- package/src/components/navigation/Tree/Tree.tsx +600 -0
- package/src/components/navigation/Tree/Tree.types.ts +909 -0
- package/src/components/navigation/Tree/Tree.utils.ts +452 -0
- package/src/components/navigation/Tree/index.ts +33 -0
- package/src/components/navigation/Tree/index.tsx +23 -0
- package/src/components/navigation/index.tsx +83 -0
- package/src/constants/index.ts +785 -0
- package/src/hooks/index.ts +110 -0
- package/src/hooks/types.ts +10 -0
- package/src/hooks/useAsync.ts +65 -0
- package/src/hooks/useEventHandling.ts +444 -0
- package/src/hooks/useLifecycle.ts +399 -0
- package/src/hooks/usePerformance.ts +441 -0
- package/src/hooks/usePerformanceMonitor.ts +348 -0
- package/src/hooks/usePlatform.ts +62 -0
- package/src/hooks/useRequest.test.ts +11 -0
- package/src/hooks/useRequest.ts +135 -0
- package/src/hooks/useStateManagement.ts +300 -0
- package/src/hooks/useStyle.ts +537 -0
- package/src/hooks/useTheme.ts +347 -0
- package/src/hooks/useVirtualScroll.ts +331 -0
- package/src/index.ts +298 -0
- package/src/platform/index.ts +1188 -0
- package/src/providers/AppProvider.test.tsx +63 -0
- package/src/providers/AppProvider.tsx +155 -0
- package/src/providers/index.ts +1 -0
- package/src/theme/ThemeProvider.tsx +283 -0
- package/src/theme/ThemeProvider.types.ts +26 -0
- package/src/theme/animations.tsx +660 -0
- package/src/theme/defaults.ts +188 -0
- package/src/theme/design-system.ts +562 -0
- package/src/theme/design-tokens.ts +1136 -0
- package/src/theme/generated/dark-theme.scss +120 -0
- package/src/theme/generated/tokens.css +441 -0
- package/src/theme/generated/tokens.scss +320 -0
- package/src/theme/index.ts +120 -0
- package/src/theme/responsive.tsx +193 -0
- package/src/theme/styles/mixins.scss +612 -0
- package/src/theme/styles/variables.scss +295 -0
- package/src/theme/styles.ts +403 -0
- package/src/theme/tokens/colors.ts +256 -0
- package/src/theme/tokens/effects.ts +260 -0
- package/src/theme/tokens/index.ts +217 -0
- package/src/theme/tokens/spacing.ts +137 -0
- package/src/theme/tokens/typography.ts +186 -0
- package/src/theme/types.ts +188 -0
- package/src/theme/useThemeUtils.ts +313 -0
- package/src/theme/utils.ts +501 -0
- package/src/theme/variables.ts +583 -0
- package/src/types/accessibility.ts +51 -0
- package/src/types/button.ts +562 -0
- package/src/types/component-props.ts +317 -0
- package/src/types/env.d.ts +20 -0
- package/src/types/index.ts +427 -0
- package/src/types/modules.d.ts +40 -0
- package/src/types/standardized-components.ts +544 -0
- package/src/types/taro-adapter.d.ts +174 -0
- package/src/types/taro-components.d.ts +73 -0
- package/src/types/utils.ts +410 -0
- package/src/utils/__tests__/inputValidator.test.ts +338 -0
- package/src/utils/__tests__/responsiveUtils.test.ts +310 -0
- package/src/utils/__tests__/xssProtection.test.ts +268 -0
- package/src/utils/cache.ts +83 -0
- package/src/utils/createNamespace.ts +24 -0
- package/src/utils/environment.ts +95 -0
- package/src/utils/error-handler.ts +88 -0
- package/src/utils/errorLogger.ts +197 -0
- package/src/utils/formatUtils.ts +444 -0
- package/src/utils/index.ts +115 -0
- package/src/utils/inputValidator.ts +261 -0
- package/src/utils/network/http-client.test.ts +18 -0
- package/src/utils/network/http-client.ts +151 -0
- package/src/utils/performance/performance.ts +850 -0
- package/src/utils/responsiveUtils.ts +357 -0
- package/src/utils/rtl-support.ts +344 -0
- package/src/utils/security/api-security.ts +386 -0
- package/src/utils/security/xss-protection.ts +69 -0
- package/src/utils/securityHeaders.ts +314 -0
- package/src/utils/typeHelpers.ts +16 -0
- package/src/utils/types/dataProcessing.ts +543 -0
- package/src/utils/types/typeHelpers.ts +187 -0
- package/src/utils/xssProtection.ts +420 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 响应式工具
|
|
3
|
+
* 提供屏幕尺寸检测、断点管理、响应式样式生成等功能,适配Taro.js多平台环境
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useMemo, useState, useEffect } from 'react';
|
|
7
|
+
import Taro from '@tarojs/taro';
|
|
8
|
+
|
|
9
|
+
// 断点配置
|
|
10
|
+
interface BreakpointConfig {
|
|
11
|
+
xs: number;
|
|
12
|
+
sm: number;
|
|
13
|
+
md: number;
|
|
14
|
+
lg: number;
|
|
15
|
+
xl: number;
|
|
16
|
+
'2xl': number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 默认断点配置
|
|
20
|
+
const defaultBreakpoints: BreakpointConfig = {
|
|
21
|
+
xs: 0,
|
|
22
|
+
sm: 640,
|
|
23
|
+
md: 768,
|
|
24
|
+
lg: 1024,
|
|
25
|
+
xl: 1280,
|
|
26
|
+
'2xl': 1536,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// 屏幕尺寸类型
|
|
30
|
+
type ScreenSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
|
31
|
+
|
|
32
|
+
// 响应式值类型
|
|
33
|
+
type ResponsiveValue<T> = T | Partial<Record<ScreenSize, T>>;
|
|
34
|
+
|
|
35
|
+
// 响应式样式接口
|
|
36
|
+
interface ResponsiveStyle {
|
|
37
|
+
[key: string]: ResponsiveValue<string | number>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 平台类型
|
|
41
|
+
type Platform = 'web' | 'weapp' | 'swan' | 'alipay' | 'tt' | 'qq' | 'h5' | 'rn';
|
|
42
|
+
|
|
43
|
+
class ResponsiveUtils {
|
|
44
|
+
private breakpoints: BreakpointConfig;
|
|
45
|
+
private platform: Platform;
|
|
46
|
+
|
|
47
|
+
constructor(breakpoints?: Partial<BreakpointConfig>) {
|
|
48
|
+
this.breakpoints = { ...defaultBreakpoints, ...breakpoints };
|
|
49
|
+
|
|
50
|
+
// 检测当前平台
|
|
51
|
+
if (process.env && process.env['TARO_ENV']) {
|
|
52
|
+
this.platform = process.env['TARO_ENV'] as Platform;
|
|
53
|
+
} else {
|
|
54
|
+
this.platform = 'web'; // 默认为web
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 获取当前屏幕尺寸
|
|
60
|
+
* @param width 屏幕宽度
|
|
61
|
+
* @returns 屏幕尺寸类型
|
|
62
|
+
*/
|
|
63
|
+
getScreenSize(width: number): ScreenSize {
|
|
64
|
+
const { sm, md, lg, xl, '2xl': xxl } = this.breakpoints;
|
|
65
|
+
|
|
66
|
+
if (width >= xxl) return '2xl';
|
|
67
|
+
if (width >= xl) return 'xl';
|
|
68
|
+
if (width >= lg) return 'lg';
|
|
69
|
+
if (width >= md) return 'md';
|
|
70
|
+
if (width >= sm) return 'sm';
|
|
71
|
+
return 'xs';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 检查是否匹配指定屏幕尺寸
|
|
76
|
+
* @param size 屏幕尺寸
|
|
77
|
+
* @param currentWidth 当前屏幕宽度
|
|
78
|
+
* @returns 是否匹配
|
|
79
|
+
*/
|
|
80
|
+
matchScreenSize(size: ScreenSize, currentWidth: number): boolean {
|
|
81
|
+
const currentSize = this.getScreenSize(currentWidth);
|
|
82
|
+
|
|
83
|
+
const sizeOrder: ScreenSize[] = ['xs', 'sm', 'md', 'lg', 'xl', '2xl'];
|
|
84
|
+
const currentIndex = sizeOrder.indexOf(currentSize);
|
|
85
|
+
const targetIndex = sizeOrder.indexOf(size);
|
|
86
|
+
|
|
87
|
+
return currentIndex >= targetIndex;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 获取响应式值
|
|
92
|
+
* @param value 响应式值
|
|
93
|
+
* @param currentWidth 当前屏幕宽度
|
|
94
|
+
* @returns 匹配的值
|
|
95
|
+
*/
|
|
96
|
+
getResponsiveValue<T>(value: ResponsiveValue<T>, currentWidth: number): T {
|
|
97
|
+
if (typeof value !== 'object' || value === null) {
|
|
98
|
+
return value as T;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const size = this.getScreenSize(currentWidth);
|
|
102
|
+
const responsiveValue = value as Partial<Record<ScreenSize, T>>;
|
|
103
|
+
|
|
104
|
+
// 从当前尺寸开始向上查找匹配的值
|
|
105
|
+
const sizeOrder: ScreenSize[] = ['2xl', 'xl', 'lg', 'md', 'sm', 'xs'];
|
|
106
|
+
for (const s of sizeOrder) {
|
|
107
|
+
if (responsiveValue[s] !== undefined) {
|
|
108
|
+
return responsiveValue[s] as T;
|
|
109
|
+
}
|
|
110
|
+
if (s === size) {
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 如果没有找到,返回默认值(确保不会返回undefined)
|
|
116
|
+
return (responsiveValue.xs || value as T) as T;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 生成响应式样式
|
|
121
|
+
* @param styles 响应式样式对象
|
|
122
|
+
* @param currentWidth 当前屏幕宽度
|
|
123
|
+
* @returns 样式对象
|
|
124
|
+
*/
|
|
125
|
+
generateResponsiveStyles(styles: ResponsiveStyle, currentWidth: number): Record<string, string | number> {
|
|
126
|
+
const result: Record<string, string | number> = {};
|
|
127
|
+
|
|
128
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
129
|
+
const responsiveValue = this.getResponsiveValue(value, currentWidth);
|
|
130
|
+
if (responsiveValue !== undefined) {
|
|
131
|
+
result[key] = responsiveValue;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 获取平台特定的样式
|
|
140
|
+
* @param webStyles Web平台样式
|
|
141
|
+
* @param weappStyles 小程序平台样式
|
|
142
|
+
* @param otherStyles 其他平台样式
|
|
143
|
+
* @returns 当前平台的样式
|
|
144
|
+
*/
|
|
145
|
+
getPlatformStyles<T>(
|
|
146
|
+
webStyles: T,
|
|
147
|
+
weappStyles: T,
|
|
148
|
+
otherStyles?: Partial<Record<Platform, T>>
|
|
149
|
+
): T {
|
|
150
|
+
if (this.platform === 'web' || this.platform === 'h5') {
|
|
151
|
+
return webStyles;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (this.platform === 'weapp') {
|
|
155
|
+
return weappStyles;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (otherStyles && otherStyles[this.platform]) {
|
|
159
|
+
return otherStyles[this.platform]!;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 默认返回小程序样式
|
|
163
|
+
return weappStyles;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 获取当前平台
|
|
168
|
+
* @returns 平台类型
|
|
169
|
+
*/
|
|
170
|
+
getPlatform(): Platform {
|
|
171
|
+
return this.platform;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 检查是否为移动设备
|
|
176
|
+
* @param width 屏幕宽度
|
|
177
|
+
* @returns 是否为移动设备
|
|
178
|
+
*/
|
|
179
|
+
isMobile(width: number): boolean {
|
|
180
|
+
return width < this.breakpoints.md;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 检查是否为平板设备
|
|
185
|
+
* @param width 屏幕宽度
|
|
186
|
+
* @returns 是否为平板设备
|
|
187
|
+
*/
|
|
188
|
+
isTablet(width: number): boolean {
|
|
189
|
+
return width >= this.breakpoints.md && width < this.breakpoints.lg;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* 检查是否为桌面设备
|
|
194
|
+
* @param width 屏幕宽度
|
|
195
|
+
* @returns 是否为桌面设备
|
|
196
|
+
*/
|
|
197
|
+
isDesktop(width: number): boolean {
|
|
198
|
+
return width >= this.breakpoints.lg;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 获取安全区域(适配刘海屏)
|
|
203
|
+
* @returns 安全区域配置
|
|
204
|
+
*/
|
|
205
|
+
getSafeArea(): { top: number; bottom: number; left: number; right: number } {
|
|
206
|
+
// Taro.js环境下的安全区域获取
|
|
207
|
+
if (Taro.getSystemInfoSync) {
|
|
208
|
+
const systemInfo = Taro.getSystemInfoSync();
|
|
209
|
+
return {
|
|
210
|
+
top: systemInfo.safeArea?.top || 0,
|
|
211
|
+
bottom: systemInfo.safeArea?.bottom || systemInfo.screenHeight,
|
|
212
|
+
left: systemInfo.safeArea?.left || 0,
|
|
213
|
+
right: systemInfo.safeArea?.right || systemInfo.screenWidth,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// 默认值
|
|
218
|
+
return { top: 0, bottom: 0, left: 0, right: 0 };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 获取状态栏高度
|
|
223
|
+
* @returns 状态栏高度
|
|
224
|
+
*/
|
|
225
|
+
getStatusBarHeight(): number {
|
|
226
|
+
if (Taro.getSystemInfoSync) {
|
|
227
|
+
const systemInfo = Taro.getSystemInfoSync();
|
|
228
|
+
return systemInfo.statusBarHeight || 0;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// 默认值
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 获取导航栏高度
|
|
237
|
+
* @returns 导航栏高度
|
|
238
|
+
*/
|
|
239
|
+
getNavigationBarHeight(): number {
|
|
240
|
+
if (Taro.getSystemInfoSync) {
|
|
241
|
+
const systemInfo = Taro.getSystemInfoSync();
|
|
242
|
+
// 小程序导航栏高度通常为44px
|
|
243
|
+
return systemInfo.statusBarHeight ? systemInfo.statusBarHeight + 44 : 44;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 默认值
|
|
247
|
+
return 44;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* 获取胶囊按钮信息(仅小程序)
|
|
252
|
+
* @returns 胶囊按钮信息
|
|
253
|
+
*/
|
|
254
|
+
getMenuButtonBoundingClientRect(): any {
|
|
255
|
+
if (Taro.getMenuButtonBoundingClientRect) {
|
|
256
|
+
return Taro.getMenuButtonBoundingClientRect();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// 默认值
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 创建单例实例
|
|
265
|
+
const responsiveUtils = new ResponsiveUtils();
|
|
266
|
+
|
|
267
|
+
// 响应式Hook
|
|
268
|
+
export const useResponsive = () => {
|
|
269
|
+
const [windowSize, setWindowSize] = useState({ windowWidth: 375, windowHeight: 667 });
|
|
270
|
+
|
|
271
|
+
useEffect(() => {
|
|
272
|
+
const updateWindowSize = () => {
|
|
273
|
+
try {
|
|
274
|
+
const systemInfo = Taro.getSystemInfoSync();
|
|
275
|
+
setWindowSize({
|
|
276
|
+
windowWidth: systemInfo.windowWidth || 375,
|
|
277
|
+
windowHeight: systemInfo.windowHeight || 667
|
|
278
|
+
});
|
|
279
|
+
} catch (e) {
|
|
280
|
+
// 如果获取失败,使用默认值
|
|
281
|
+
setWindowSize({ windowWidth: 375, windowHeight: 667 });
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// 初始化获取窗口尺寸
|
|
286
|
+
updateWindowSize();
|
|
287
|
+
|
|
288
|
+
// 监听窗口尺寸变化(仅Web/H5环境)
|
|
289
|
+
if (typeof window !== 'undefined') {
|
|
290
|
+
window.addEventListener('resize', updateWindowSize);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// 清理函数
|
|
294
|
+
return () => {
|
|
295
|
+
if (typeof window !== 'undefined') {
|
|
296
|
+
window.removeEventListener('resize', updateWindowSize);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}, []);
|
|
300
|
+
|
|
301
|
+
const { windowWidth, windowHeight } = windowSize;
|
|
302
|
+
|
|
303
|
+
const screenSize = useMemo(() => responsiveUtils.getScreenSize(windowWidth), [windowWidth]);
|
|
304
|
+
const isMobile = useMemo(() => responsiveUtils.isMobile(windowWidth), [windowWidth]);
|
|
305
|
+
const isTablet = useMemo(() => responsiveUtils.isTablet(windowWidth), [windowWidth]);
|
|
306
|
+
const isDesktop = useMemo(() => responsiveUtils.isDesktop(windowWidth), [windowWidth]);
|
|
307
|
+
const platform = useMemo(() => responsiveUtils.getPlatform(), []);
|
|
308
|
+
const safeArea = useMemo(() => responsiveUtils.getSafeArea(), []);
|
|
309
|
+
const statusBarHeight = useMemo(() => responsiveUtils.getStatusBarHeight(), []);
|
|
310
|
+
const navigationBarHeight = useMemo(() => responsiveUtils.getNavigationBarHeight(), []);
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
windowWidth,
|
|
314
|
+
windowHeight,
|
|
315
|
+
screenSize,
|
|
316
|
+
isMobile,
|
|
317
|
+
isTablet,
|
|
318
|
+
isDesktop,
|
|
319
|
+
platform,
|
|
320
|
+
safeArea,
|
|
321
|
+
statusBarHeight,
|
|
322
|
+
navigationBarHeight,
|
|
323
|
+
getResponsiveValue: <T>(value: ResponsiveValue<T>) =>
|
|
324
|
+
responsiveUtils.getResponsiveValue(value, windowWidth),
|
|
325
|
+
generateResponsiveStyles: (styles: ResponsiveStyle) =>
|
|
326
|
+
responsiveUtils.generateResponsiveStyles(styles, windowWidth),
|
|
327
|
+
getPlatformStyles: <T>(webStyles: T, weappStyles: T, otherStyles?: Partial<Record<Platform, T>>) =>
|
|
328
|
+
responsiveUtils.getPlatformStyles(webStyles, weappStyles, otherStyles),
|
|
329
|
+
matchScreenSize: (size: ScreenSize) =>
|
|
330
|
+
responsiveUtils.matchScreenSize(size, windowWidth),
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
// 导出便捷方法
|
|
335
|
+
export const getScreenSize = (width: number) => responsiveUtils.getScreenSize(width);
|
|
336
|
+
export const matchScreenSize = (size: ScreenSize, width: number) => responsiveUtils.matchScreenSize(size, width);
|
|
337
|
+
export const getResponsiveValue = <T>(value: ResponsiveValue<T>, width: number) =>
|
|
338
|
+
responsiveUtils.getResponsiveValue(value, width);
|
|
339
|
+
export const generateResponsiveStyles = (styles: ResponsiveStyle, width: number) =>
|
|
340
|
+
responsiveUtils.generateResponsiveStyles(styles, width);
|
|
341
|
+
export const getPlatformStyles = <T>(
|
|
342
|
+
webStyles: T,
|
|
343
|
+
weappStyles: T,
|
|
344
|
+
otherStyles?: Partial<Record<Platform, T>>
|
|
345
|
+
) => responsiveUtils.getPlatformStyles(webStyles, weappStyles, otherStyles);
|
|
346
|
+
export const getPlatform = () => responsiveUtils.getPlatform();
|
|
347
|
+
export const isMobile = (width: number) => responsiveUtils.isMobile(width);
|
|
348
|
+
export const isTablet = (width: number) => responsiveUtils.isTablet(width);
|
|
349
|
+
export const isDesktop = (width: number) => responsiveUtils.isDesktop(width);
|
|
350
|
+
export const getSafeArea = () => responsiveUtils.getSafeArea();
|
|
351
|
+
export const getStatusBarHeight = () => responsiveUtils.getStatusBarHeight();
|
|
352
|
+
export const getNavigationBarHeight = () => responsiveUtils.getNavigationBarHeight();
|
|
353
|
+
export const getMenuButtonBoundingClientRect = () => responsiveUtils.getMenuButtonBoundingClientRect();
|
|
354
|
+
|
|
355
|
+
// 导出类型
|
|
356
|
+
export type { BreakpointConfig, ScreenSize, ResponsiveValue, ResponsiveStyle, Platform };
|
|
357
|
+
export default responsiveUtils;
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RTL语言支持工具
|
|
3
|
+
* 提供RTL检测、样式切换和布局调整功能
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useEffect, useState } from 'react';
|
|
7
|
+
type SupportedLanguage = 'ar-SA' | 'he-IL' | 'fa-IR' | 'ur-PK' | string;
|
|
8
|
+
|
|
9
|
+
// RTL语言列表
|
|
10
|
+
export const RTL_LANGUAGES: SupportedLanguage[] = [
|
|
11
|
+
'ar-SA', // 阿拉伯语
|
|
12
|
+
'he-IL', // 希伯来语
|
|
13
|
+
'fa-IR', // 波斯语
|
|
14
|
+
'ur-PK', // 乌尔都语
|
|
15
|
+
'yi', // 意第绪语
|
|
16
|
+
'ps', // 普什图语
|
|
17
|
+
'sd', // 信德语
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
// 扩展RTL语言配置
|
|
21
|
+
export interface RTLConfig {
|
|
22
|
+
language: SupportedLanguage;
|
|
23
|
+
name: string;
|
|
24
|
+
rtl: boolean;
|
|
25
|
+
fontFamily: string;
|
|
26
|
+
textAlign: 'right' | 'left';
|
|
27
|
+
direction: 'rtl' | 'ltr';
|
|
28
|
+
// RTL特定的布局调整
|
|
29
|
+
flipProperties: boolean;
|
|
30
|
+
flipIcons: boolean;
|
|
31
|
+
adjustSpacing: boolean;
|
|
32
|
+
adjustAlignment: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// RTL语言配置
|
|
36
|
+
export const RTL_CONFIGS: Record<string, RTLConfig> = {
|
|
37
|
+
'ar-SA': {
|
|
38
|
+
language: 'ar-SA',
|
|
39
|
+
name: 'Arabic (Saudi Arabia)',
|
|
40
|
+
rtl: true,
|
|
41
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Tahoma", "Arial Unicode MS", "Traditional Arabic"',
|
|
42
|
+
textAlign: 'right',
|
|
43
|
+
direction: 'rtl',
|
|
44
|
+
flipProperties: true,
|
|
45
|
+
flipIcons: true,
|
|
46
|
+
adjustSpacing: true,
|
|
47
|
+
adjustAlignment: true,
|
|
48
|
+
},
|
|
49
|
+
'he-IL': {
|
|
50
|
+
language: 'he-IL',
|
|
51
|
+
name: 'Hebrew (Israel)',
|
|
52
|
+
rtl: true,
|
|
53
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "David", "Arial Hebrew", "Arial"',
|
|
54
|
+
textAlign: 'right',
|
|
55
|
+
direction: 'rtl',
|
|
56
|
+
flipProperties: true,
|
|
57
|
+
flipIcons: true,
|
|
58
|
+
adjustSpacing: true,
|
|
59
|
+
adjustAlignment: true,
|
|
60
|
+
},
|
|
61
|
+
'fa-IR': {
|
|
62
|
+
language: 'fa-IR',
|
|
63
|
+
name: 'Persian (Iran)',
|
|
64
|
+
rtl: true,
|
|
65
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Tahoma", "Arial Unicode MS", "IRANSans", "Vazir"',
|
|
66
|
+
textAlign: 'right',
|
|
67
|
+
direction: 'rtl',
|
|
68
|
+
flipProperties: true,
|
|
69
|
+
flipIcons: true,
|
|
70
|
+
adjustSpacing: true,
|
|
71
|
+
adjustAlignment: true,
|
|
72
|
+
},
|
|
73
|
+
'ur-PK': {
|
|
74
|
+
language: 'ur-PK',
|
|
75
|
+
name: 'Urdu (Pakistan)',
|
|
76
|
+
rtl: true,
|
|
77
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Noto Nastaliq Urdu", "Arial Unicode MS", "Tahoma"',
|
|
78
|
+
textAlign: 'right',
|
|
79
|
+
direction: 'rtl',
|
|
80
|
+
flipProperties: true,
|
|
81
|
+
flipIcons: true,
|
|
82
|
+
adjustSpacing: true,
|
|
83
|
+
adjustAlignment: true,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// 检查是否为RTL语言
|
|
88
|
+
export const isRTL = (language: string): boolean => {
|
|
89
|
+
return RTL_LANGUAGES.includes(language as SupportedLanguage) ||
|
|
90
|
+
language.startsWith('ar') ||
|
|
91
|
+
language.startsWith('he') ||
|
|
92
|
+
language.startsWith('fa') ||
|
|
93
|
+
language.startsWith('ur');
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// 应用RTL样式
|
|
97
|
+
export const applyRTLStyles = (language: string): void => {
|
|
98
|
+
const isRtl = isRTL(language);
|
|
99
|
+
const config = RTL_CONFIGS[language];
|
|
100
|
+
|
|
101
|
+
if (typeof document !== 'undefined') {
|
|
102
|
+
// 设置文档方向
|
|
103
|
+
document.documentElement.dir = isRtl ? 'rtl' : 'ltr';
|
|
104
|
+
document.documentElement.lang = language;
|
|
105
|
+
|
|
106
|
+
// 添加或移除RTL类
|
|
107
|
+
if (isRtl) {
|
|
108
|
+
document.body.classList.add('rtl');
|
|
109
|
+
document.body.classList.remove('ltr');
|
|
110
|
+
} else {
|
|
111
|
+
document.body.classList.add('ltr');
|
|
112
|
+
document.body.classList.remove('rtl');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 应用特定配置
|
|
116
|
+
if (config) {
|
|
117
|
+
// 设置字体
|
|
118
|
+
const style = document.createElement('style');
|
|
119
|
+
style.id = 'rtl-font-style';
|
|
120
|
+
style.textContent = `
|
|
121
|
+
html {
|
|
122
|
+
font-family: ${config.fontFamily};
|
|
123
|
+
}
|
|
124
|
+
.rtl {
|
|
125
|
+
direction: rtl;
|
|
126
|
+
text-align: ${config.textAlign};
|
|
127
|
+
}
|
|
128
|
+
.rtl .flip-icon {
|
|
129
|
+
transform: scaleX(-1);
|
|
130
|
+
}
|
|
131
|
+
.rtl .flip-property {
|
|
132
|
+
${config.flipProperties ? `
|
|
133
|
+
margin-left: initial;
|
|
134
|
+
margin-right: initial;
|
|
135
|
+
padding-left: initial;
|
|
136
|
+
padding-right: initial;
|
|
137
|
+
border-left: initial;
|
|
138
|
+
border-right: initial;
|
|
139
|
+
border-radius: initial;
|
|
140
|
+
` : ''}
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
|
|
144
|
+
// 移除旧的样式
|
|
145
|
+
const oldStyle = document.getElementById('rtl-font-style');
|
|
146
|
+
if (oldStyle) {
|
|
147
|
+
oldStyle.remove();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
document.head.appendChild(style);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// 获取RTL配置
|
|
156
|
+
export const getRTLConfig = (language: string): RTLConfig | null => {
|
|
157
|
+
return RTL_CONFIGS[language] || null;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// 生成RTL CSS变量
|
|
161
|
+
export const generateRTLVariables = (language: string): string => {
|
|
162
|
+
const config = RTL_CONFIGS[language];
|
|
163
|
+
if (!config) return '';
|
|
164
|
+
|
|
165
|
+
return `
|
|
166
|
+
:root {
|
|
167
|
+
--rtl-direction: ${config.direction};
|
|
168
|
+
--rtl-text-align: ${config.textAlign};
|
|
169
|
+
--rtl-font-family: ${config.fontFamily};
|
|
170
|
+
--rtl-flip-properties: ${config.flipProperties ? 'true' : 'false'};
|
|
171
|
+
--rtl-flip-icons: ${config.flipIcons ? 'true' : 'false'};
|
|
172
|
+
--rtl-adjust-spacing: ${config.adjustSpacing ? 'true' : 'false'};
|
|
173
|
+
--rtl-adjust-alignment: ${config.adjustAlignment ? 'true' : 'false'};
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// 生成RTL样式类
|
|
179
|
+
export const generateRTLClasses = (): string => `
|
|
180
|
+
.rtl {
|
|
181
|
+
direction: rtl;
|
|
182
|
+
text-align: right;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.rtl .text-left { text-align: right; }
|
|
186
|
+
.rtl .text-right { text-align: left; }
|
|
187
|
+
|
|
188
|
+
.rtl .mr-1 { margin-left: 0.25rem; margin-right: 0; }
|
|
189
|
+
.rtl .mr-2 { margin-left: 0.5rem; margin-right: 0; }
|
|
190
|
+
.rtl .mr-3 { margin-left: 0.75rem; margin-right: 0; }
|
|
191
|
+
.rtl .mr-4 { margin-left: 1rem; margin-right: 0; }
|
|
192
|
+
.rtl .mr-5 { margin-left: 1.25rem; margin-right: 0; }
|
|
193
|
+
|
|
194
|
+
.rtl .ml-1 { margin-right: 0.25rem; margin-left: 0; }
|
|
195
|
+
.rtl .ml-2 { margin-right: 0.5rem; margin-left: 0; }
|
|
196
|
+
.rtl .ml-3 { margin-right: 0.75rem; margin-left: 0; }
|
|
197
|
+
.rtl .ml-4 { margin-right: 1rem; margin-left: 0; }
|
|
198
|
+
.rtl .ml-5 { margin-right: 1.25rem; margin-left: 0; }
|
|
199
|
+
|
|
200
|
+
.rtl .pl-1 { padding-left: 0; padding-right: 0.25rem; }
|
|
201
|
+
.rtl .pl-2 { padding-left: 0; padding-right: 0.5rem; }
|
|
202
|
+
.rtl .pl-3 { padding-left: 0; padding-right: 0.75rem; }
|
|
203
|
+
.rtl .pl-4 { padding-left: 0; padding-right: 1rem; }
|
|
204
|
+
.rtl .pl-5 { padding-left: 0; padding-right: 1.25rem; }
|
|
205
|
+
|
|
206
|
+
.rtl .pr-1 { padding-right: 0; padding-left: 0.25rem; }
|
|
207
|
+
.rtl .pr-2 { padding-right: 0; padding-left: 0.5rem; }
|
|
208
|
+
.rtl .pr-3 { padding-right: 0; padding-left: 0.75rem; }
|
|
209
|
+
.rtl .pr-4 { padding-right: 0; padding-left: 1rem; }
|
|
210
|
+
.rtl .pr-5 { padding-right: 0; padding-left: 1.25rem; }
|
|
211
|
+
|
|
212
|
+
.rtl .border-l { border-left: none; border-right: 1px solid currentColor; }
|
|
213
|
+
.rtl .border-r { border-right: none; border-left: 1px solid currentColor; }
|
|
214
|
+
|
|
215
|
+
.rtl .rounded-l { border-top-left-radius: 0; border-bottom-left-radius: 0; border-top-right-radius: 0.25rem; border-bottom-right-radius: 0.25rem; }
|
|
216
|
+
.rtl .rounded-r { border-top-right-radius: 0; border-bottom-right-radius: 0; border-top-left-radius: 0.25rem; border-bottom-left-radius: 0.25rem; }
|
|
217
|
+
|
|
218
|
+
.rtl .flip-icon {
|
|
219
|
+
transform: scaleX(-1);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.rtl .flip-property {
|
|
223
|
+
transform: scaleX(-1);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.rtl .float-left { float: right; }
|
|
227
|
+
.rtl .float-right { float: left; }
|
|
228
|
+
|
|
229
|
+
.rtl .left-0 { left: auto; right: 0; }
|
|
230
|
+
.rtl .right-0 { right: auto; left: 0; }
|
|
231
|
+
|
|
232
|
+
.rtl .text-start { text-align: right; }
|
|
233
|
+
.rtl .text-end { text-align: left; }
|
|
234
|
+
`;
|
|
235
|
+
|
|
236
|
+
// RTL检测Hook
|
|
237
|
+
export const useRTLDetection = (language: string) => {
|
|
238
|
+
const [rtl, setRtl] = useState(false);
|
|
239
|
+
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
setRtl(isRTL(language));
|
|
242
|
+
applyRTLStyles(language);
|
|
243
|
+
}, [language]);
|
|
244
|
+
|
|
245
|
+
return { isRTL: rtl };
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// 切换RTL方向
|
|
249
|
+
export const toggleRTL = (language: string): string => {
|
|
250
|
+
const isRtl = isRTL(language);
|
|
251
|
+
const newDirection = isRtl ? 'ltr' : 'rtl';
|
|
252
|
+
|
|
253
|
+
if (typeof document !== 'undefined') {
|
|
254
|
+
document.documentElement.dir = newDirection;
|
|
255
|
+
document.body.classList.toggle('rtl', !isRtl);
|
|
256
|
+
document.body.classList.toggle('ltr', isRtl);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return newDirection;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// 获取方向相关样式
|
|
263
|
+
export const getDirectionalStyles = (language: string) => {
|
|
264
|
+
const isRtl = isRTL(language);
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
direction: isRtl ? 'rtl' : 'ltr',
|
|
268
|
+
textAlign: isRtl ? 'right' : 'left',
|
|
269
|
+
// 样式映射
|
|
270
|
+
marginStart: isRtl ? 'marginRight' : 'marginLeft',
|
|
271
|
+
marginEnd: isRtl ? 'marginLeft' : 'marginRight',
|
|
272
|
+
paddingStart: isRtl ? 'paddingRight' : 'paddingLeft',
|
|
273
|
+
paddingEnd: isRtl ? 'paddingLeft' : 'paddingRight',
|
|
274
|
+
borderStart: isRtl ? 'borderRight' : 'borderLeft',
|
|
275
|
+
borderEnd: isRtl ? 'borderLeft' : 'borderRight',
|
|
276
|
+
borderRadiusStart: isRtl ? 'borderTopRightRadius' : 'borderTopLeftRadius',
|
|
277
|
+
borderRadiusEnd: isRtl ? 'borderTopLeftRadius' : 'borderTopRightRadius',
|
|
278
|
+
floatStart: isRtl ? 'right' : 'left',
|
|
279
|
+
floatEnd: isRtl ? 'left' : 'right',
|
|
280
|
+
positionStart: isRtl ? 'right' : 'left',
|
|
281
|
+
positionEnd: isRtl ? 'left' : 'right',
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// 获取RTL特定的CSS值
|
|
286
|
+
export const getRTLValue = (_property: string, language: string, ltrValue: string, rtlValue?: string) => {
|
|
287
|
+
const isRtl = isRTL(language);
|
|
288
|
+
return isRtl && rtlValue ? rtlValue : ltrValue;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// 应用RTL特定的类名
|
|
292
|
+
export const applyRTLClasses = (element: HTMLElement, language: string): void => {
|
|
293
|
+
const isRtl = isRTL(language);
|
|
294
|
+
|
|
295
|
+
if (isRtl) {
|
|
296
|
+
element.classList.add('rtl');
|
|
297
|
+
element.classList.remove('ltr');
|
|
298
|
+
} else {
|
|
299
|
+
element.classList.add('ltr');
|
|
300
|
+
element.classList.remove('rtl');
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// 创建RTL友好的CSS
|
|
305
|
+
export const createRTLCSS = (css: string, language: string): string => {
|
|
306
|
+
if (!isRTL(language)) {
|
|
307
|
+
return css;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// 简单的RTL转换规则
|
|
311
|
+
const rtlRules = [
|
|
312
|
+
{ pattern: /margin-left:\s*([^;]+);/g, replacement: 'margin-right: $1; margin-left: 0;' },
|
|
313
|
+
{ pattern: /margin-right:\s*([^;]+);/g, replacement: 'margin-left: $1; margin-right: 0;' },
|
|
314
|
+
{ pattern: /padding-left:\s*([^;]+);/g, replacement: 'padding-right: $1; padding-left: 0;' },
|
|
315
|
+
{ pattern: /padding-right:\s*([^;]+);/g, replacement: 'padding-left: $1; padding-right: 0;' },
|
|
316
|
+
{ pattern: /border-left:\s*([^;]+);/g, replacement: 'border-right: $1; border-left: none;' },
|
|
317
|
+
{ pattern: /border-right:\s*([^;]+);/g, replacement: 'border-left: $1; border-right: none;' },
|
|
318
|
+
{ pattern: /text-align:\s*left;/g, replacement: 'text-align: right;' },
|
|
319
|
+
{ pattern: /text-align:\s*right;/g, replacement: 'text-align: left;' },
|
|
320
|
+
{ pattern: /float:\s*left;/g, replacement: 'float: right;' },
|
|
321
|
+
{ pattern: /float:\s*right;/g, replacement: 'float: left;' },
|
|
322
|
+
];
|
|
323
|
+
|
|
324
|
+
let rtlCSS = css;
|
|
325
|
+
rtlRules.forEach(rule => {
|
|
326
|
+
rtlCSS = rtlCSS.replace(rule.pattern, rule.replacement);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
return rtlCSS;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export default {
|
|
333
|
+
isRTL,
|
|
334
|
+
applyRTLStyles,
|
|
335
|
+
getRTLConfig,
|
|
336
|
+
generateRTLVariables,
|
|
337
|
+
generateRTLClasses,
|
|
338
|
+
useRTLDetection,
|
|
339
|
+
toggleRTL,
|
|
340
|
+
getDirectionalStyles,
|
|
341
|
+
getRTLValue,
|
|
342
|
+
applyRTLClasses,
|
|
343
|
+
createRTLCSS,
|
|
344
|
+
};
|