@daisu-ui/ui 0.0.0-stage → 0.1.0-beta.3
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/CHANGELOG.md +58 -0
- package/LICENSE +21 -0
- package/README.md +93 -2
- package/THIRD_PARTY_NOTICES.md +19 -0
- package/dist/ActionSheet.d.ts +45 -0
- package/dist/ActionSheet.jsx +37 -0
- package/dist/AnchoredBubble.d.ts +36 -0
- package/dist/AnchoredBubble.jsx +120 -0
- package/dist/Avatar.d.ts +35 -0
- package/dist/Avatar.jsx +29 -0
- package/dist/Backtop.d.ts +22 -0
- package/dist/Backtop.jsx +18 -0
- package/dist/Badge.d.ts +19 -0
- package/dist/Badge.jsx +11 -0
- package/dist/BarCode.d.ts +20 -0
- package/dist/BarCode.jsx +38 -0
- package/dist/Button.d.ts +21 -0
- package/dist/Button.jsx +19 -0
- package/dist/Calendar.d.ts +90 -0
- package/dist/Calendar.jsx +164 -0
- package/dist/CalendarView.d.ts +51 -0
- package/dist/CalendarView.jsx +136 -0
- package/dist/Card.d.ts +21 -0
- package/dist/Card.jsx +21 -0
- package/dist/Cascader.d.ts +75 -0
- package/dist/Cascader.jsx +212 -0
- package/dist/Cell.d.ts +34 -0
- package/dist/Cell.jsx +37 -0
- package/dist/Checkbox.d.ts +50 -0
- package/dist/Checkbox.jsx +74 -0
- package/dist/Circle.d.ts +19 -0
- package/dist/Circle.jsx +35 -0
- package/dist/Collapse.d.ts +31 -0
- package/dist/Collapse.jsx +61 -0
- package/dist/ConfigProvider.d.ts +15 -0
- package/dist/ConfigProvider.jsx +20 -0
- package/dist/CountDown.d.ts +20 -0
- package/dist/CountDown.jsx +15 -0
- package/dist/CountTo.d.ts +28 -0
- package/dist/CountTo.jsx +27 -0
- package/dist/Curtain.d.ts +29 -0
- package/dist/Curtain.jsx +51 -0
- package/dist/DatetimePicker.d.ts +46 -0
- package/dist/DatetimePicker.jsx +138 -0
- package/dist/DatetimePickerView.d.ts +38 -0
- package/dist/DatetimePickerView.jsx +36 -0
- package/dist/Dialog.d.ts +64 -0
- package/dist/Dialog.jsx +105 -0
- package/dist/Divider.d.ts +16 -0
- package/dist/Divider.jsx +9 -0
- package/dist/DropMenu.d.ts +55 -0
- package/dist/DropMenu.jsx +210 -0
- package/dist/Empty.d.ts +14 -0
- package/dist/Empty.jsx +14 -0
- package/dist/EmptyState.d.ts +6 -0
- package/dist/EmptyState.jsx +9 -0
- package/dist/Fab.d.ts +30 -0
- package/dist/Fab.jsx +127 -0
- package/dist/FloatingPanel.d.ts +21 -0
- package/dist/FloatingPanel.jsx +102 -0
- package/dist/Form.d.ts +63 -0
- package/dist/Form.jsx +108 -0
- package/dist/FormFieldRow.d.ts +56 -0
- package/dist/FormFieldRow.jsx +63 -0
- package/dist/Gap.d.ts +10 -0
- package/dist/Gap.jsx +14 -0
- package/dist/Grid.d.ts +47 -0
- package/dist/Grid.jsx +31 -0
- package/dist/Icon.d.ts +11 -0
- package/dist/Icon.jsx +12 -0
- package/dist/ImagePreview.d.ts +62 -0
- package/dist/ImagePreview.jsx +78 -0
- package/dist/Img.d.ts +28 -0
- package/dist/Img.jsx +59 -0
- package/dist/ImgCropper.d.ts +74 -0
- package/dist/ImgCropper.jsx +114 -0
- package/dist/IndexBar.d.ts +36 -0
- package/dist/IndexBar.jsx +149 -0
- package/dist/Input.d.ts +11 -0
- package/dist/Input.jsx +3 -0
- package/dist/InputNumber.d.ts +32 -0
- package/dist/InputNumber.jsx +165 -0
- package/dist/Keyboard.d.ts +37 -0
- package/dist/Keyboard.jsx +130 -0
- package/dist/Layout.d.ts +31 -0
- package/dist/Layout.jsx +14 -0
- package/dist/Loading.d.ts +18 -0
- package/dist/Loading.jsx +15 -0
- package/dist/Loadmore.d.ts +18 -0
- package/dist/Loadmore.jsx +16 -0
- package/dist/Navbar.d.ts +35 -0
- package/dist/Navbar.jsx +50 -0
- package/dist/NoticeBar.d.ts +30 -0
- package/dist/NoticeBar.jsx +86 -0
- package/dist/Notify.d.ts +34 -0
- package/dist/Notify.jsx +52 -0
- package/dist/NumberStepper.d.ts +11 -0
- package/dist/NumberStepper.jsx +41 -0
- package/dist/Overlay.d.ts +16 -0
- package/dist/Overlay.jsx +12 -0
- package/dist/PagedList.d.ts +13 -0
- package/dist/PagedList.jsx +36 -0
- package/dist/Pagination.d.ts +29 -0
- package/dist/Pagination.jsx +33 -0
- package/dist/PasswordInput.d.ts +16 -0
- package/dist/PasswordInput.jsx +20 -0
- package/dist/Picker.d.ts +61 -0
- package/dist/Picker.jsx +80 -0
- package/dist/PickerView.d.ts +43 -0
- package/dist/PickerView.jsx +142 -0
- package/dist/Popover.d.ts +23 -0
- package/dist/Popover.jsx +35 -0
- package/dist/Popup.d.ts +30 -0
- package/dist/Popup.jsx +32 -0
- package/dist/Progress.d.ts +17 -0
- package/dist/Progress.jsx +45 -0
- package/dist/QrCode.d.ts +46 -0
- package/dist/QrCode.jsx +67 -0
- package/dist/Radio.d.ts +21 -0
- package/dist/Radio.jsx +34 -0
- package/dist/Rate.d.ts +25 -0
- package/dist/Rate.jsx +39 -0
- package/dist/Resize.d.ts +17 -0
- package/dist/Resize.jsx +17 -0
- package/dist/RichText.d.ts +133 -0
- package/dist/RichText.jsx +288 -0
- package/dist/RootPortal.d.ts +11 -0
- package/dist/RootPortal.jsx +19 -0
- package/dist/Search.d.ts +39 -0
- package/dist/Search.jsx +94 -0
- package/dist/Segmented.d.ts +18 -0
- package/dist/Segmented.jsx +35 -0
- package/dist/SelectPicker.d.ts +54 -0
- package/dist/SelectPicker.jsx +136 -0
- package/dist/Sidebar.d.ts +34 -0
- package/dist/Sidebar.jsx +43 -0
- package/dist/Signature.d.ts +46 -0
- package/dist/Signature.jsx +203 -0
- package/dist/Skeleton.d.ts +27 -0
- package/dist/Skeleton.jsx +29 -0
- package/dist/SlideVerify.d.ts +27 -0
- package/dist/SlideVerify.jsx +138 -0
- package/dist/Slider.d.ts +21 -0
- package/dist/Slider.jsx +131 -0
- package/dist/SortButton.d.ts +16 -0
- package/dist/SortButton.jsx +19 -0
- package/dist/Steps.d.ts +23 -0
- package/dist/Steps.jsx +25 -0
- package/dist/Sticky.d.ts +17 -0
- package/dist/Sticky.jsx +69 -0
- package/dist/SwipeAction.d.ts +27 -0
- package/dist/SwipeAction.jsx +187 -0
- package/dist/Swiper.d.ts +54 -0
- package/dist/Swiper.jsx +94 -0
- package/dist/SwiperNav.d.ts +18 -0
- package/dist/SwiperNav.jsx +10 -0
- package/dist/Switch.d.ts +31 -0
- package/dist/Switch.jsx +46 -0
- package/dist/SyncedInput.d.ts +12 -0
- package/dist/SyncedInput.jsx +18 -0
- package/dist/SyncedTextarea.d.ts +11 -0
- package/dist/SyncedTextarea.jsx +18 -0
- package/dist/Tabbar.d.ts +37 -0
- package/dist/Tabbar.jsx +46 -0
- package/dist/Table.d.ts +51 -0
- package/dist/Table.jsx +125 -0
- package/dist/Tabs.d.ts +65 -0
- package/dist/Tabs.jsx +132 -0
- package/dist/Tag.d.ts +33 -0
- package/dist/Tag.jsx +63 -0
- package/dist/Text.d.ts +19 -0
- package/dist/Text.jsx +7 -0
- package/dist/TextField.d.ts +89 -0
- package/dist/TextField.jsx +149 -0
- package/dist/Textarea.d.ts +22 -0
- package/dist/Textarea.jsx +3 -0
- package/dist/Toast.d.ts +36 -0
- package/dist/Toast.jsx +30 -0
- package/dist/Tooltip.d.ts +8 -0
- package/dist/Tooltip.jsx +5 -0
- package/dist/Tour.d.ts +85 -0
- package/dist/Tour.jsx +150 -0
- package/dist/Transition.d.ts +32 -0
- package/dist/Transition.jsx +43 -0
- package/dist/Upload.d.ts +64 -0
- package/dist/Upload.jsx +163 -0
- package/dist/VideoPreview.d.ts +47 -0
- package/dist/VideoPreview.jsx +59 -0
- package/dist/Watermark.d.ts +36 -0
- package/dist/Watermark.jsx +18 -0
- package/dist/action-sheet.css +19 -0
- package/dist/avatar.css +23 -0
- package/dist/avatarModel.d.ts +8 -0
- package/dist/avatarModel.js +17 -0
- package/dist/backtop.css +6 -0
- package/dist/badge.css +15 -0
- package/dist/badgeModel.d.ts +2 -0
- package/dist/badgeModel.js +18 -0
- package/dist/bar-code.css +5 -0
- package/dist/barCodeModel.d.ts +80 -0
- package/dist/barCodeModel.js +99 -0
- package/dist/bubble.css +14 -0
- package/dist/bubblePosition.d.ts +19 -0
- package/dist/bubblePosition.js +41 -0
- package/dist/button.css +56 -0
- package/dist/calendar.css +56 -0
- package/dist/calendarModel.d.ts +62 -0
- package/dist/calendarModel.js +141 -0
- package/dist/card.css +8 -0
- package/dist/cascader.css +16 -0
- package/dist/cascaderModel.d.ts +21 -0
- package/dist/cascaderModel.js +32 -0
- package/dist/cell.css +41 -0
- package/dist/choice.css +27 -0
- package/dist/choice.d.ts +28 -0
- package/dist/choice.jsx +16 -0
- package/dist/circle.css +4 -0
- package/dist/circleModel.d.ts +15 -0
- package/dist/circleModel.js +31 -0
- package/dist/config-provider.css +2 -0
- package/dist/configContext.d.ts +23 -0
- package/dist/configContext.js +24 -0
- package/dist/configTheme.d.ts +3 -0
- package/dist/configTheme.js +22 -0
- package/dist/count-down.css +2 -0
- package/dist/count-to.css +8 -0
- package/dist/countDownModel.d.ts +11 -0
- package/dist/countDownModel.js +7 -0
- package/dist/countToModel.d.ts +3 -0
- package/dist/countToModel.js +3 -0
- package/dist/curtain.css +10 -0
- package/dist/datetime-picker.css +11 -0
- package/dist/datetimePickerModel.d.ts +47 -0
- package/dist/datetimePickerModel.js +128 -0
- package/dist/dialog.css +23 -0
- package/dist/divider.css +14 -0
- package/dist/drop-menu.css +28 -0
- package/dist/empty.css +7 -0
- package/dist/fab.css +23 -0
- package/dist/fabModel.d.ts +26 -0
- package/dist/fabModel.js +16 -0
- package/dist/floating-panel.css +6 -0
- package/dist/floatingPanelModel.d.ts +3 -0
- package/dist/floatingPanelModel.js +10 -0
- package/dist/form.css +10 -0
- package/dist/formContext.d.ts +7 -0
- package/dist/formContext.js +2 -0
- package/dist/formModel.d.ts +38 -0
- package/dist/formModel.js +16 -0
- package/dist/gap.css +1 -0
- package/dist/grid.css +17 -0
- package/dist/icon.css +8 -0
- package/dist/icons/LICENSE.tabler +21 -0
- package/dist/icons/paths.d.ts +309 -0
- package/dist/icons/paths.js +310 -0
- package/dist/icons/render.d.ts +2 -0
- package/dist/icons/render.js +5 -0
- package/dist/image-preview.css +8 -0
- package/dist/img-cropper.css +1 -0
- package/dist/img.css +5 -0
- package/dist/imgCropperModel.d.ts +55 -0
- package/dist/imgCropperModel.js +41 -0
- package/dist/imgModel.d.ts +13 -0
- package/dist/imgModel.js +22 -0
- package/dist/index-bar.css +12 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +99 -0
- package/dist/indexBarModel.d.ts +19 -0
- package/dist/indexBarModel.js +37 -0
- package/dist/input-number.css +24 -0
- package/dist/inputNumberModel.d.ts +23 -0
- package/dist/inputNumberModel.js +40 -0
- package/dist/keyboard.css +26 -0
- package/dist/keyboardModel.d.ts +11 -0
- package/dist/keyboardModel.js +34 -0
- package/dist/layout.css +2 -0
- package/dist/legacy/RadioGroup.d.ts +13 -0
- package/dist/legacy/RadioGroup.jsx +13 -0
- package/dist/legacy-controls.css +87 -0
- package/dist/loading.css +31 -0
- package/dist/loadingModel.d.ts +2 -0
- package/dist/loadingModel.js +21 -0
- package/dist/loadmore.css +5 -0
- package/dist/navbar.css +16 -0
- package/dist/notice-bar.css +19 -0
- package/dist/notify.css +14 -0
- package/dist/overlay.css +2 -0
- package/dist/pagination.css +12 -0
- package/dist/paginationModel.d.ts +6 -0
- package/dist/paginationModel.js +7 -0
- package/dist/password-input.css +14 -0
- package/dist/passwordInputModel.d.ts +6 -0
- package/dist/passwordInputModel.js +11 -0
- package/dist/picker.css +42 -0
- package/dist/pickerModel.d.ts +32 -0
- package/dist/pickerModel.js +49 -0
- package/dist/popover.css +5 -0
- package/dist/popup.css +17 -0
- package/dist/progress.css +16 -0
- package/dist/progressModel.d.ts +12 -0
- package/dist/progressModel.js +19 -0
- package/dist/qr-code.css +4 -0
- package/dist/qrCodeModel.d.ts +36 -0
- package/dist/qrCodeModel.js +61 -0
- package/dist/rate.css +20 -0
- package/dist/rateModel.d.ts +4 -0
- package/dist/rateModel.js +38 -0
- package/dist/resize.css +2 -0
- package/dist/rich-text.css +19 -0
- package/dist/richTextMedia.d.ts +28 -0
- package/dist/richTextMedia.js +3 -0
- package/dist/richTextModel.d.ts +52 -0
- package/dist/richTextModel.js +195 -0
- package/dist/root-portal.css +1 -0
- package/dist/router/RouterView.d.ts +21 -0
- package/dist/router/RouterView.jsx +120 -0
- package/dist/router/core.d.ts +85 -0
- package/dist/router/core.js +255 -0
- package/dist/router/hooks.d.ts +17 -0
- package/dist/router/hooks.jsx +71 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/index.js +3 -0
- package/dist/router/location.d.ts +8 -0
- package/dist/router/location.js +46 -0
- package/dist/router/router.css +7 -0
- package/dist/router/runtime.d.ts +1 -0
- package/dist/router/runtime.js +25 -0
- package/dist/search.css +23 -0
- package/dist/segmented.css +19 -0
- package/dist/segmentedModel.d.ts +10 -0
- package/dist/segmentedModel.js +8 -0
- package/dist/sidebar.css +18 -0
- package/dist/sidebarModel.d.ts +8 -0
- package/dist/sidebarModel.js +27 -0
- package/dist/signature.css +5 -0
- package/dist/signatureModel.d.ts +23 -0
- package/dist/signatureModel.js +80 -0
- package/dist/skeleton.css +16 -0
- package/dist/slide-verify.css +7 -0
- package/dist/slider.css +49 -0
- package/dist/sliderModel.d.ts +10 -0
- package/dist/sliderModel.js +27 -0
- package/dist/sort-button.css +12 -0
- package/dist/steps.css +35 -0
- package/dist/sticky.css +7 -0
- package/dist/styles.css +136 -0
- package/dist/styles.d.ts +1 -0
- package/dist/swipe-action.css +6 -0
- package/dist/swiper.css +27 -0
- package/dist/swiperAnimation.d.ts +3 -0
- package/dist/swiperAnimation.js +6 -0
- package/dist/swiperModel.d.ts +2 -0
- package/dist/swiperModel.js +3 -0
- package/dist/switch.css +12 -0
- package/dist/tabbar.css +17 -0
- package/dist/tabbarModel.d.ts +8 -0
- package/dist/tabbarModel.js +27 -0
- package/dist/table.css +21 -0
- package/dist/tableModel.d.ts +10 -0
- package/dist/tableModel.js +17 -0
- package/dist/tabs.css +31 -0
- package/dist/tabsModel.d.ts +7 -0
- package/dist/tabsModel.js +14 -0
- package/dist/tag.css +66 -0
- package/dist/text-field.css +15 -0
- package/dist/text.css +7 -0
- package/dist/textModel.d.ts +3 -0
- package/dist/textModel.js +24 -0
- package/dist/toast.css +13 -0
- package/dist/tokens.d.ts +34 -0
- package/dist/tokens.js +10 -0
- package/dist/tour.css +8 -0
- package/dist/transition.css +12 -0
- package/dist/upload.css +11 -0
- package/dist/useCountDown.d.ts +14 -0
- package/dist/useCountDown.js +73 -0
- package/dist/useDialog.d.ts +9 -0
- package/dist/useDialog.js +33 -0
- package/dist/useImagePreview.d.ts +7 -0
- package/dist/useImagePreview.js +17 -0
- package/dist/useNotify.d.ts +9 -0
- package/dist/useNotify.js +26 -0
- package/dist/usePressState.d.ts +6 -0
- package/dist/usePressState.js +17 -0
- package/dist/useToast.d.ts +11 -0
- package/dist/useToast.js +23 -0
- package/dist/useVideoPreview.d.ts +7 -0
- package/dist/useVideoPreview.js +17 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +4 -0
- package/dist/video-preview.css +7 -0
- package/dist/watermark.css +6 -0
- package/dist/web/imgCropperElement.d.ts +2 -0
- package/dist/web/imgCropperElement.js +309 -0
- package/dist/web/index.d.ts +6 -0
- package/dist/web/index.js +6 -0
- package/dist/web/qrCodeExportElement.d.ts +4 -0
- package/dist/web/qrCodeExportElement.js +70 -0
- package/dist/web/richTextMediaElement.d.ts +2 -0
- package/dist/web/richTextMediaElement.js +276 -0
- package/package.json +98 -4
package/dist/Upload.jsx
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { useContext, useEffect, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Icon } from "./Icon.jsx";
|
|
3
|
+
import { Loading } from "./Loading.jsx";
|
|
4
|
+
import { FormFieldContext } from './formContext.js';
|
|
5
|
+
const emptyFiles = [];
|
|
6
|
+
const errorOf = (reason, fallback) => reason instanceof Error ? reason : new Error(fallback);
|
|
7
|
+
export function Upload({ fileList = emptyFiles, onChange, adapter, disabled: disabledProp, readonly = false, limit = 0, size = 88, deletable = true, showLimitNum = true, reupload = false, previewFullImage = true, imageMode = 'aspectFill', uploadIcon = 'camera-fill', uploadText, loadingType = 'circular', loadingSize = 24, loadingColor = '#fff', beforeChoose, beforePreview, beforeRemove, onSuccess, onFail, onProgress, onPreview, onRemove, renderPreviewCover, className = '', evokeClassName = '', previewClassName = '', style, children }) {
|
|
8
|
+
const field = useContext(FormFieldContext), disabled = disabledProp ?? field?.disabled ?? false;
|
|
9
|
+
const [uploading, setUploading] = useState(false), [progress, setProgress] = useState(0);
|
|
10
|
+
const generation = useRef(0), choosing = useRef(false), removing = useRef(false), previewing = useRef(false);
|
|
11
|
+
const latest = useRef({ fileList, disabled, readonly, limit, adapter, onChange, onSuccess, onFail, onProgress, onPreview, onRemove });
|
|
12
|
+
latest.current = { fileList, disabled, readonly, limit, adapter, onChange, onSuccess, onFail, onProgress, onPreview, onRemove };
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
generation.current++;
|
|
15
|
+
choosing.current = false;
|
|
16
|
+
removing.current = false;
|
|
17
|
+
previewing.current = false;
|
|
18
|
+
setUploading(false);
|
|
19
|
+
return () => { generation.current++; };
|
|
20
|
+
}, [fileList, disabled, readonly, adapter, limit, reupload, deletable, previewFullImage]);
|
|
21
|
+
const withinLimit = limit <= 0 || fileList.length < limit;
|
|
22
|
+
const choose = async (target) => {
|
|
23
|
+
'background only';
|
|
24
|
+
if (disabled || readonly || choosing.current || (!target && !withinLimit))
|
|
25
|
+
return;
|
|
26
|
+
choosing.current = true;
|
|
27
|
+
const ticket = generation.current;
|
|
28
|
+
let acceptingProgress = false;
|
|
29
|
+
try {
|
|
30
|
+
const index = target ? fileList.indexOf(target) : -1;
|
|
31
|
+
if (beforeChoose && !await beforeChoose({ fileList, ...(index < 0 ? {} : { reuploadIndex: index }) }))
|
|
32
|
+
return;
|
|
33
|
+
if (ticket !== generation.current)
|
|
34
|
+
return;
|
|
35
|
+
if (!adapter)
|
|
36
|
+
throw new Error('未接入图片上传能力');
|
|
37
|
+
acceptingProgress = true;
|
|
38
|
+
setUploading(true);
|
|
39
|
+
setProgress(0);
|
|
40
|
+
const file = await adapter.chooseAndUpload(value => {
|
|
41
|
+
'background only';
|
|
42
|
+
if (ticket !== generation.current || !acceptingProgress || !Number.isFinite(value))
|
|
43
|
+
return;
|
|
44
|
+
const next = Math.max(0, Math.min(100, value));
|
|
45
|
+
setProgress(next);
|
|
46
|
+
latest.current.onProgress?.(next);
|
|
47
|
+
});
|
|
48
|
+
acceptingProgress = false;
|
|
49
|
+
if (ticket !== generation.current || !file)
|
|
50
|
+
return;
|
|
51
|
+
if (!file.url)
|
|
52
|
+
throw new Error('上传结果缺少图片地址');
|
|
53
|
+
const current = latest.current, next = [...current.fileList], uploaded = { ...file, status: 'success' };
|
|
54
|
+
if (target) {
|
|
55
|
+
const location = next.indexOf(target);
|
|
56
|
+
if (location < 0)
|
|
57
|
+
return;
|
|
58
|
+
next[location] = uploaded;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (current.limit > 0 && next.length >= current.limit)
|
|
62
|
+
return;
|
|
63
|
+
next.push(uploaded);
|
|
64
|
+
}
|
|
65
|
+
current.onChange?.({ fileList: next });
|
|
66
|
+
current.onSuccess?.(uploaded);
|
|
67
|
+
}
|
|
68
|
+
catch (reason) {
|
|
69
|
+
if (ticket === generation.current)
|
|
70
|
+
latest.current.onFail?.(errorOf(reason, '上传失败'));
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
acceptingProgress = false;
|
|
74
|
+
if (ticket === generation.current) {
|
|
75
|
+
choosing.current = false;
|
|
76
|
+
setUploading(false);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const remove = async (file, index) => {
|
|
81
|
+
'background only';
|
|
82
|
+
if (disabled || readonly || !deletable || file.status === 'loading' || removing.current)
|
|
83
|
+
return;
|
|
84
|
+
removing.current = true;
|
|
85
|
+
const ticket = generation.current;
|
|
86
|
+
try {
|
|
87
|
+
if (!await (beforeRemove?.(file, index) ?? true) || ticket !== generation.current)
|
|
88
|
+
return;
|
|
89
|
+
const current = latest.current, location = current.fileList.indexOf(file);
|
|
90
|
+
if (location >= 0) {
|
|
91
|
+
current.onChange?.({ fileList: current.fileList.filter((_, i) => i !== location) });
|
|
92
|
+
current.onRemove?.({ file, index: location });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (reason) {
|
|
96
|
+
if (ticket === generation.current)
|
|
97
|
+
latest.current.onFail?.(errorOf(reason, '删除失败'));
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
if (ticket === generation.current)
|
|
101
|
+
removing.current = false;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const preview = async (file, index) => {
|
|
105
|
+
'background only';
|
|
106
|
+
if (file.status === 'loading')
|
|
107
|
+
return;
|
|
108
|
+
if (reupload && !readonly) {
|
|
109
|
+
await choose(file);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (previewing.current)
|
|
113
|
+
return;
|
|
114
|
+
previewing.current = true;
|
|
115
|
+
const ticket = generation.current;
|
|
116
|
+
try {
|
|
117
|
+
if (!await (beforePreview?.(file, index) ?? true) || ticket !== generation.current)
|
|
118
|
+
return;
|
|
119
|
+
const current = latest.current, location = current.fileList.indexOf(file);
|
|
120
|
+
if (location < 0)
|
|
121
|
+
return;
|
|
122
|
+
current.onPreview?.({ file, index: location });
|
|
123
|
+
if (previewFullImage) {
|
|
124
|
+
if (current.adapter?.preview)
|
|
125
|
+
await current.adapter.preview(current.fileList, location);
|
|
126
|
+
else if (!current.onPreview)
|
|
127
|
+
throw new Error('未接入图片预览能力');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (reason) {
|
|
131
|
+
if (ticket === generation.current)
|
|
132
|
+
latest.current.onFail?.(errorOf(reason, '预览失败'));
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
if (ticket === generation.current)
|
|
136
|
+
previewing.current = false;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const dimension = Number.isFinite(size) ? Math.max(0, size) : 88;
|
|
140
|
+
return <view className={`ui-upload ${disabled ? 'ui-upload-disabled' : ''} ${className}`} style={{ '--ui-upload-size': `${dimension}px`, ...style }}>
|
|
141
|
+
{fileList.map((file, index) => <view className={`ui-upload-preview ${previewClassName}`} key={`${file.path ?? file.url}-${index}`}>
|
|
142
|
+
<view className="ui-upload-picture" bindtap={() => {
|
|
143
|
+
'background only';
|
|
144
|
+
void preview(file, index);
|
|
145
|
+
}} accessibility-element accessibility-traits="button" accessibility-label={`${reupload && !readonly ? '重新上传' : '预览'}${file.name ?? `图片${index + 1}`}`}>
|
|
146
|
+
<image src={file.url} mode={imageMode} className="ui-upload-image"/>
|
|
147
|
+
</view>
|
|
148
|
+
<view className="ui-upload-border"/>
|
|
149
|
+
{file.status === 'loading' || file.status === 'fail' ? <view className="ui-upload-status">{file.status === 'loading' ? <Loading type={loadingType} size={loadingSize} color={loadingColor}/> : <Icon name="close-circle" color="#fff" size={24}/>}<text>{file.message ?? (file.status === 'fail' ? '上传失败' : file.percent === undefined ? '上传中' : `${Math.round(file.percent)}%`)}</text></view> : null}
|
|
150
|
+
{deletable && !readonly && !disabled && file.status !== 'loading' ? <view className="ui-upload-remove" catchtap={() => {
|
|
151
|
+
'background only';
|
|
152
|
+
void remove(file, index);
|
|
153
|
+
}} accessibility-element accessibility-traits="button" accessibility-label={`删除${file.name ?? `图片${index + 1}`}`}><Icon name="close" size={16} color="#fff"/></view> : null}
|
|
154
|
+
{renderPreviewCover?.({ file, index })}
|
|
155
|
+
</view>)}
|
|
156
|
+
{!readonly && withinLimit ? <view className={`${children ? 'ui-upload-evoke-slot' : 'ui-upload-add'} ${evokeClassName}`} bindtap={() => {
|
|
157
|
+
'background only';
|
|
158
|
+
void choose();
|
|
159
|
+
}} accessibility-element accessibility-traits="button" accessibility-label={disabled ? '上传已禁用' : uploading ? `上传中${Math.round(progress)}%` : uploadText ?? '上传图片'}>
|
|
160
|
+
{uploading ? <><Loading type={loadingType} size={loadingSize}/><text>{Math.round(progress)}%</text></> : children ?? <><Icon name={uploadIcon} size={32} color={disabled ? '#c9cbd4' : '#868a9c'}/>{uploadText ? <text>{uploadText}</text> : null}{limit > 0 && showLimitNum ? <text className="ui-upload-count">({fileList.length}/{limit})</text> : null}</>}
|
|
161
|
+
</view> : null}
|
|
162
|
+
</view>;
|
|
163
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
export type PreviewVideo = {
|
|
3
|
+
url: string;
|
|
4
|
+
poster?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
};
|
|
7
|
+
export type VideoPreviewOptions = PreviewVideo & {
|
|
8
|
+
zIndex?: number;
|
|
9
|
+
fullScreen?: boolean;
|
|
10
|
+
closePosition?: 'left-top' | 'right-top';
|
|
11
|
+
onOpen?: () => void;
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
};
|
|
14
|
+
export type VideoPreviewProps = Partial<VideoPreviewOptions> & {
|
|
15
|
+
show?: boolean;
|
|
16
|
+
onShowChange?: (show: boolean) => void;
|
|
17
|
+
options?: VideoPreviewOptions;
|
|
18
|
+
requestKey?: number;
|
|
19
|
+
mediaMode?: 'browser' | 'none';
|
|
20
|
+
rootPortal?: boolean;
|
|
21
|
+
duration?: number;
|
|
22
|
+
onError?: (error: {
|
|
23
|
+
src: string;
|
|
24
|
+
message: string;
|
|
25
|
+
}) => void;
|
|
26
|
+
className?: string;
|
|
27
|
+
style?: CSSProperties;
|
|
28
|
+
};
|
|
29
|
+
export type VideoPreviewRef = {
|
|
30
|
+
open: (video: VideoPreviewOptions) => boolean;
|
|
31
|
+
close: () => void;
|
|
32
|
+
};
|
|
33
|
+
export declare const VideoPreview: (props: Partial<VideoPreviewOptions> & {
|
|
34
|
+
show?: boolean;
|
|
35
|
+
onShowChange?: (show: boolean) => void;
|
|
36
|
+
options?: VideoPreviewOptions;
|
|
37
|
+
requestKey?: number;
|
|
38
|
+
mediaMode?: "browser" | "none";
|
|
39
|
+
rootPortal?: boolean;
|
|
40
|
+
duration?: number;
|
|
41
|
+
onError?: (error: {
|
|
42
|
+
src: string;
|
|
43
|
+
message: string;
|
|
44
|
+
}) => void;
|
|
45
|
+
className?: string;
|
|
46
|
+
style?: CSSProperties;
|
|
47
|
+
} & import("react").RefAttributes<VideoPreviewRef>) => React.ReactElement | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { richTextUrl } from './richTextModel.js';
|
|
3
|
+
import { Overlay } from "./Overlay.jsx";
|
|
4
|
+
import { Icon } from "./Icon.jsx";
|
|
5
|
+
export const VideoPreview = forwardRef(function VideoPreview({ show, onShowChange, options, requestKey = 0, mediaMode = 'none', rootPortal = false, duration = 300, onError, className = '', style, ...defaults }, ref) {
|
|
6
|
+
const [innerShow, setInnerShow] = useState(false), [imperative, setImperative] = useState({}), [revision, setRevision] = useState(0);
|
|
7
|
+
const imperativeRequest = useRef(requestKey);
|
|
8
|
+
const settings = { ...defaults, ...(imperativeRequest.current === requestKey && Object.keys(imperative).length ? imperative : options) }, visible = show ?? innerShow;
|
|
9
|
+
const active = visible && mediaMode === 'browser' && !!richTextUrl(settings.url || '');
|
|
10
|
+
const state = useRef({ visible, settings, onShowChange, onError, mediaMode, requestKey }), wasVisible = useRef(false), closing = useRef(false), player = useRef(null);
|
|
11
|
+
state.current = { visible, settings, onShowChange, onError, mediaMode, requestKey };
|
|
12
|
+
const close = () => {
|
|
13
|
+
'background only';
|
|
14
|
+
if (!state.current.visible || closing.current)
|
|
15
|
+
return;
|
|
16
|
+
closing.current = true;
|
|
17
|
+
player.current?.invoke({ method: 'pauseMedia' }).exec();
|
|
18
|
+
setInnerShow(false);
|
|
19
|
+
state.current.onShowChange?.(false);
|
|
20
|
+
};
|
|
21
|
+
useImperativeHandle(ref, () => ({ open(video) {
|
|
22
|
+
'background only';
|
|
23
|
+
if (state.current.mediaMode !== 'browser' || !richTextUrl(video.url)) {
|
|
24
|
+
state.current.onError?.({ src: video.url, message: '当前环境不支持此视频地址的预览' });
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
imperativeRequest.current = state.current.requestKey;
|
|
28
|
+
setImperative(video);
|
|
29
|
+
setRevision(v => v + 1);
|
|
30
|
+
closing.current = false;
|
|
31
|
+
setInnerShow(true);
|
|
32
|
+
state.current.onShowChange?.(true);
|
|
33
|
+
return true;
|
|
34
|
+
}, close }), []);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (active && !wasVisible.current) {
|
|
37
|
+
closing.current = false;
|
|
38
|
+
state.current.settings.onOpen?.();
|
|
39
|
+
}
|
|
40
|
+
else if (!active && wasVisible.current)
|
|
41
|
+
state.current.settings.onClose?.();
|
|
42
|
+
wasVisible.current = active;
|
|
43
|
+
}, [active]);
|
|
44
|
+
useEffect(() => { if (visible && !active)
|
|
45
|
+
state.current.onError?.({ src: settings.url || '', message: mediaMode !== 'browser' ? '当前环境不支持视频预览' : '视频地址不可用' }); }, [visible, active, mediaMode, settings.url]);
|
|
46
|
+
const config = { id: 'preview', type: 'video', sources: [richTextUrl(settings.url || '')].filter(Boolean), title: settings.title || '', poster: richTextUrl(settings.poster || ''), loop: false, muted: false, preview: true };
|
|
47
|
+
return <Overlay show={active} rootPortal={rootPortal} duration={duration} lockScroll onTap={close} zIndex={settings.zIndex ?? 1000} className={`ui-video-preview ${className}`} style={style}>
|
|
48
|
+
{active ? <view className="ui-video-preview-stage"><daisu-rich-media key={`${requestKey}:${revision}`} ref={player} className={`ui-video-preview-video ${settings.fullScreen ? 'ui-video-preview-fullscreen' : ''}`} media-config={JSON.stringify(config)} catchtap={() => { }} bindmediaevent={({ detail: event }) => {
|
|
49
|
+
'background only';
|
|
50
|
+
if (!state.current.visible)
|
|
51
|
+
return;
|
|
52
|
+
if (event.kind === 'close')
|
|
53
|
+
close();
|
|
54
|
+
else if (event.kind === 'error')
|
|
55
|
+
state.current.onError?.({ src: event.src, message: event.message || '视频加载失败' });
|
|
56
|
+
}}/></view> : null}
|
|
57
|
+
<view className={`ui-video-preview-close ui-video-preview-close-${settings.closePosition ?? 'left-top'}`} catchtap={close} accessibility-element accessibility-label="关闭视频预览" accessibility-traits="button"><Icon name="close" size={24} color="#fff"/></view>
|
|
58
|
+
</Overlay>;
|
|
59
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
export type WatermarkProps = {
|
|
3
|
+
content?: string;
|
|
4
|
+
image?: string;
|
|
5
|
+
imageWidth?: number;
|
|
6
|
+
imageHeight?: number;
|
|
7
|
+
gutterX?: number;
|
|
8
|
+
gutterY?: number;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
fullScreen?: boolean;
|
|
12
|
+
color?: string;
|
|
13
|
+
size?: number;
|
|
14
|
+
fontStyle?: 'normal' | 'italic' | 'oblique';
|
|
15
|
+
fontWeight?: CSSProperties['fontWeight'] | 'bolder' | number;
|
|
16
|
+
fontFamily?: string;
|
|
17
|
+
rotate?: number;
|
|
18
|
+
zIndex?: number;
|
|
19
|
+
opacity?: number;
|
|
20
|
+
layout?: 'grid' | 'staggered';
|
|
21
|
+
rootPortal?: boolean;
|
|
22
|
+
className?: string;
|
|
23
|
+
style?: CSSProperties;
|
|
24
|
+
};
|
|
25
|
+
export declare function watermarkGrid(viewport: {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}, width: number, height: number, gutterX: number, gutterY: number): {
|
|
29
|
+
cellWidth: number;
|
|
30
|
+
cellHeight: number;
|
|
31
|
+
columns: number;
|
|
32
|
+
rows: number;
|
|
33
|
+
count: number;
|
|
34
|
+
};
|
|
35
|
+
/** Repeated native content. No Canvas, DOM, downloaded executable code or touch interception. */
|
|
36
|
+
export declare function Watermark({ content, image, imageWidth, imageHeight, gutterX, gutterY, width, height, fullScreen, color, size, fontStyle, fontWeight, fontFamily, rotate, zIndex, opacity, layout, rootPortal, className, style }: WatermarkProps): import("@lynx-js/react").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useState } from '@lynx-js/react';
|
|
2
|
+
import { RootPortal } from "./RootPortal.jsx";
|
|
3
|
+
const number = (value, fallback, min = -Infinity, max = Infinity) => Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : fallback;
|
|
4
|
+
export function watermarkGrid(viewport, width, height, gutterX, gutterY) {
|
|
5
|
+
const cellWidth = number(width, 100, 1) + number(gutterX, 0, 0), cellHeight = number(height, 100, 1) + number(gutterY, 0, 0);
|
|
6
|
+
const columns = Math.min(2048, Math.ceil(Math.max(0, viewport.width) / cellWidth)), rows = Math.min(2048, Math.ceil(Math.max(0, viewport.height) / cellHeight));
|
|
7
|
+
return { cellWidth, cellHeight, columns, rows, count: Math.min(2048, columns * rows) };
|
|
8
|
+
}
|
|
9
|
+
/** Repeated native content. No Canvas, DOM, downloaded executable code or touch interception. */
|
|
10
|
+
export function Watermark({ content = '', image = '', imageWidth = 100, imageHeight = 100, gutterX = 0, gutterY = 0, width = 100, height = 100, fullScreen = true, color = '#c9cbd4', size = 14, fontStyle = 'normal', fontWeight = 'normal', fontFamily = 'PingFang SC', rotate = -25, zIndex = 1100, opacity = .6, layout = 'grid', rootPortal = false, className = '', style }) {
|
|
11
|
+
const [viewport, setViewport] = useState({ width: 0, height: 0 }), grid = watermarkGrid(viewport, width, height, gutterX, gutterY), tileWidth = number(width, 100, 1), tileHeight = number(height, 100, 1), fontSize = number(size, 14, 1), svg = /\.svg(?:[?#]|$)|^data:image\/svg\+xml/i.test(image);
|
|
12
|
+
const weight = typeof fontWeight === 'number' ? String(Math.round(number(fontWeight, 400, 100, 900) / 100) * 100) : fontWeight === 'bolder' ? 'bold' : fontWeight;
|
|
13
|
+
const layer = <view className={`ui-watermark ${fullScreen ? 'ui-watermark-fullscreen' : ''} ${className}`} style={{ zIndex: number(zIndex, 1100), opacity: number(opacity, .6, 0, 1), ...style }} event-through user-interaction-enabled={false} accessibility-element={false} bindlayoutchange={event => { const { width: w, height: h } = event.detail; if (w >= 0 && h >= 0 && Number.isFinite(w) && Number.isFinite(h))
|
|
14
|
+
setViewport(previous => previous.width === w && previous.height === h ? previous : { width: w, height: h }); }}>
|
|
15
|
+
{Array.from({ length: grid.count }, (_, index) => { const row = Math.floor(index / (grid.columns || 1)), column = index % (grid.columns || 1); return layout === 'staggered' && (row + column) % 2 !== 0 ? null : <view className="ui-watermark-tile" key={index} style={{ left: `${column * grid.cellWidth}px`, top: `${row * grid.cellHeight}px`, width: `${tileWidth}px`, height: `${tileHeight}px` }}><view className="ui-watermark-mark" style={{ width: `${tileWidth}px`, height: `${tileHeight}px`, transform: `rotate(${number(rotate, -25)}deg)` }}>{image ? (svg ? <svg className="ui-watermark-image" src={image} style={{ width: `${number(imageWidth, 100, 1)}px`, height: `${number(imageHeight, 100, 1)}px` }}/> : <image className="ui-watermark-image" src={image} mode="scaleToFill" style={{ width: `${number(imageWidth, 100, 1)}px`, height: `${number(imageHeight, 100, 1)}px` }}/>) : <text className="ui-watermark-text" style={{ color, fontSize: `${fontSize}px`, lineHeight: `${fontSize * 1.2}px`, fontStyle, fontWeight: weight, fontFamily }}>{content}</text>}</view></view>; })}
|
|
16
|
+
</view>;
|
|
17
|
+
return fullScreen && rootPortal ? <RootPortal>{layer}</RootPortal> : layer;
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.ui-action-sheet.ui-popup-round { border-radius: 8px 8px 0 0; background-color: var(--cso-ui-surface); }
|
|
2
|
+
.ui-action-sheet-header { height: 56px; padding: 0 40px; display: flex; align-items: center; justify-content: center; position: relative; }
|
|
3
|
+
.ui-action-sheet-title { font-size: 16px; line-height: 24px; font-weight: 500; text-align: center; color: var(--cso-ui-text); }
|
|
4
|
+
.ui-action-sheet-close { position: absolute; top: 16px; right: 16px; width: 24px; height: 24px; }
|
|
5
|
+
.ui-action-sheet-action { flex-direction: column; position: relative; min-height: 58px; padding: 16px 12px; display: flex; align-items: center; justify-content: center; background-color: var(--cso-ui-surface); }
|
|
6
|
+
.ui-action-sheet-line { position: absolute; top: 0; left: 0; right: 0; height: 0; border-top: .5px solid var(--cso-ui-line); }
|
|
7
|
+
.ui-action-sheet-name { font-size: 18px; line-height: 26px; text-align: center; color: var(--cso-ui-text); }
|
|
8
|
+
.ui-action-sheet-description { margin-top: 8px; font-size: 14px; line-height: 20px; text-align: center; color: var(--cso-ui-text-auxiliary, var(--cso-ui-text-muted)); }
|
|
9
|
+
.ui-action-sheet-disabled { opacity: .4; }
|
|
10
|
+
.ui-action-sheet-cancel-wrap { padding-top: 8px; background-color: var(--cso-ui-surface-muted); }
|
|
11
|
+
.ui-action-sheet-cancel { height: 58px; display: flex; align-items: center; justify-content: center; background-color: var(--cso-ui-surface); }
|
|
12
|
+
.ui-action-sheet-cancel text { font-size: 18px; line-height: 26px; color: var(--cso-ui-text); }
|
|
13
|
+
.ui-action-sheet-panels { padding: 10px 0; }
|
|
14
|
+
.ui-action-sheet-panel-scroll { width: 100%; }
|
|
15
|
+
.ui-action-sheet-panel-row { display: flex; flex-direction: row; padding: 0 10px; }
|
|
16
|
+
.ui-action-sheet-panel { width: 88px; padding: 10px 0; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; }
|
|
17
|
+
.ui-action-sheet-panel-icon { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; background-color: transparent; }
|
|
18
|
+
.ui-action-sheet-panel-image { width: 24px; height: 24px; }
|
|
19
|
+
.ui-action-sheet-panel-title { margin-top: 8px; font-size: 12px; line-height: 18px; color: var(--cso-ui-text-muted); }
|
package/dist/avatar.css
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.ui-avatar { display: flex; align-items: center; justify-content: center; flex-shrink: 0; align-self: flex-start; overflow: hidden; background-color: var(--cso-ui-avatar-bg,var(--cso-ui-line)); }
|
|
2
|
+
.ui-avatar-round { border-radius: 9999px; }
|
|
3
|
+
.ui-avatar-square { border-radius: 4px; }
|
|
4
|
+
.ui-avatar-text { max-width: 100%; font-weight: 500; color: var(--cso-ui-avatar-text,var(--cso-ui-text-auxiliary, var(--cso-ui-text-muted))); text-align: center; white-space: nowrap; }
|
|
5
|
+
.ui-avatar-image { width: 100%; height: 100%; }
|
|
6
|
+
.ui-avatar-icon { display: flex; align-items: center; justify-content: center; }
|
|
7
|
+
.ui-avatar-icon .ui-icon { width: 100% !important; height: 100% !important; }
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
.ui-avatar-group { display: flex; flex-direction: row; }
|
|
13
|
+
.ui-avatar-group-vertical { flex-direction: column; align-items: flex-start; }
|
|
14
|
+
.ui-avatar-group-item { position: relative; }
|
|
15
|
+
.ui-avatar-collapse { background-color: var(--cso-ui-avatar-collapse-bg, #ebedf0); }
|
|
16
|
+
.ui-avatar-collapse .ui-avatar-text { color: var(--cso-ui-avatar-collapse-color, #969799); }
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
.ui-avatar-icon-light{display:var(--cso-ui-light-display,flex);}
|
|
23
|
+
.ui-avatar-icon-dark{display:var(--cso-ui-dark-display,none);}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type AvatarSize = 'large' | 'medium' | 'normal' | 'small' | (string & {}) | number;
|
|
2
|
+
export declare function avatarMetrics(size?: AvatarSize): {
|
|
3
|
+
dimension: string;
|
|
4
|
+
font: string;
|
|
5
|
+
line: string;
|
|
6
|
+
overlap: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function avatarVisibleCount(length: number, maxCount?: number): number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const sizes = { large: [56, 24, 34], medium: [48, 20, 28], normal: [36, 20, 28], small: [24, 18, 26] };
|
|
2
|
+
export function avatarMetrics(size = 'normal') {
|
|
3
|
+
if (typeof size === 'string' && size in sizes) {
|
|
4
|
+
const [dimension, font, line] = sizes[size];
|
|
5
|
+
return { dimension: `${dimension}px`, font: `${font}px`, line: `${line}px`, overlap: `${-dimension / 4}px` };
|
|
6
|
+
}
|
|
7
|
+
const raw = typeof size === 'number' ? `${size}` : size.trim();
|
|
8
|
+
const match = /^(\d+(?:\.\d+)?)(px|rpx|rem|vw|vh)?$/.exec(raw);
|
|
9
|
+
if (!match || !Number.isFinite(Number(match[1])))
|
|
10
|
+
return avatarMetrics('normal');
|
|
11
|
+
const value = Number(match[1]) / (match[2] === 'rpx' ? 7.5 : 1);
|
|
12
|
+
const unit = match[2] === 'rpx' ? 'vw' : match[2] || 'px';
|
|
13
|
+
return { dimension: `${value}${unit}`, font: `${value * .45}${unit}`, line: '28px', overlap: `${value * -.25}${unit}` };
|
|
14
|
+
}
|
|
15
|
+
export function avatarVisibleCount(length, maxCount) {
|
|
16
|
+
return typeof maxCount === 'number' && Number.isFinite(maxCount) && maxCount >= 1 ? Math.min(length, Math.floor(maxCount)) : length;
|
|
17
|
+
}
|
package/dist/backtop.css
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
.ui-backtop-position { position: fixed; }
|
|
2
|
+
.ui-backtop { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; background-color: var(--cso-ui-surface); box-shadow: 0 2px 8px rgba(0,0,0,.12); }
|
|
3
|
+
.ui-backtop-circle { border-radius: 50%; }
|
|
4
|
+
.ui-backtop-square { border-radius: 4px; }
|
|
5
|
+
.ui-backtop-content { display: flex; flex-direction: column; align-items: center; justify-content: center; }
|
|
6
|
+
.ui-backtop-text { margin-top: 2px; font-size: 10px; line-height: 14px; color: var(--cso-ui-text); }
|
package/dist/badge.css
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.ui-badge { position: relative; display: flex; flex-direction: row; align-items: center; align-self: flex-start; }
|
|
2
|
+
.ui-badge-content { min-width: 16px; height: 16px; padding: 0 4px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; box-sizing: border-box; }
|
|
3
|
+
.ui-badge-label { font-size: 10px; line-height: 16px; font-weight: 400; color: #fff; white-space: nowrap; }
|
|
4
|
+
.ui-badge-fixed { position: absolute; top: 0; right: 0; transform: translate(50%, -50%); }
|
|
5
|
+
.ui-badge-circle { border-radius: 9999px; }
|
|
6
|
+
.ui-badge-square { border-radius: 4px; }
|
|
7
|
+
.ui-badge-bubble { border-radius: 8px 8px 8px 0; }
|
|
8
|
+
.ui-badge-dot { width: 6px; min-width: 6px; height: 6px; padding: 0; }
|
|
9
|
+
.ui-badge-bordered { box-shadow: 0 0 0 1px var(--cso-ui-surface); }
|
|
10
|
+
.ui-badge-primary { background-color: var(--cso-ui-primary); }
|
|
11
|
+
.ui-badge-success { background-color: var(--cso-ui-success); }
|
|
12
|
+
.ui-badge-warning { background-color: var(--cso-ui-warning); }
|
|
13
|
+
.ui-badge-danger { background-color: var(--cso-ui-danger); }
|
|
14
|
+
.ui-badge-info { background-color: var(--cso-ui-surface-muted); }
|
|
15
|
+
.ui-badge-info .ui-badge-label { color: var(--cso-ui-text-muted); }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function badgeLabel(value, max, showZero = false) {
|
|
2
|
+
if (value === undefined || value === '' || (!showZero && (value === 0 || value === '0')))
|
|
3
|
+
return null;
|
|
4
|
+
if (typeof value === 'number' && !Number.isFinite(value))
|
|
5
|
+
return null;
|
|
6
|
+
return typeof value === 'number' && typeof max === 'number' && Number.isFinite(max) && value > max ? `${max}+` : String(value);
|
|
7
|
+
}
|
|
8
|
+
export function badgeOffset(value) {
|
|
9
|
+
if (value === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
if (typeof value === 'number')
|
|
12
|
+
return Number.isFinite(value) ? `${value}px` : undefined;
|
|
13
|
+
const input = value.trim();
|
|
14
|
+
if (/^-?\d+(?:\.\d+)?$/.test(input))
|
|
15
|
+
return `${input}px`;
|
|
16
|
+
const rpx = /^(-?\d+(?:\.\d+)?)rpx$/.exec(input);
|
|
17
|
+
return rpx ? `${Number(rpx[1]) / 7.5}vw` : input || undefined;
|
|
18
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
type Encoding = {
|
|
2
|
+
data: string;
|
|
3
|
+
text?: string;
|
|
4
|
+
options?: {
|
|
5
|
+
height?: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare const barCodeFormats: readonly ["auto", "CODE128", "CODE128A", "CODE128B", "CODE128C", "EAN13", "EAN8", "UPC", "UPCE", "CODE39", "ITF14", "MSI", "MSI10", "MSI11", "MSI1010", "MSI1110", "pharmacode", "codabar"];
|
|
9
|
+
export type BarCodeFormat = typeof barCodeFormats[number];
|
|
10
|
+
export type BarCodeOptions = {
|
|
11
|
+
value?: string | number;
|
|
12
|
+
format?: BarCodeFormat;
|
|
13
|
+
width?: number;
|
|
14
|
+
height?: number;
|
|
15
|
+
text?: string;
|
|
16
|
+
font?: string;
|
|
17
|
+
fontSize?: number;
|
|
18
|
+
fontOptions?: '' | 'bold' | 'italic' | 'bold italic';
|
|
19
|
+
textMargin?: number;
|
|
20
|
+
background?: string;
|
|
21
|
+
lineColor?: string;
|
|
22
|
+
margin?: number;
|
|
23
|
+
marginTop?: number;
|
|
24
|
+
marginBottom?: number;
|
|
25
|
+
marginLeft?: number;
|
|
26
|
+
marginRight?: number;
|
|
27
|
+
displayValue?: boolean;
|
|
28
|
+
textAlign?: 'left' | 'center' | 'right';
|
|
29
|
+
textPosition?: 'top' | 'bottom';
|
|
30
|
+
};
|
|
31
|
+
export declare function encodeBarCode(props: BarCodeOptions): {
|
|
32
|
+
options: Required<Omit<BarCodeOptions, "value">> & {
|
|
33
|
+
value?: string | number;
|
|
34
|
+
};
|
|
35
|
+
encodings: never[];
|
|
36
|
+
empty: boolean;
|
|
37
|
+
valid?: undefined;
|
|
38
|
+
error?: undefined;
|
|
39
|
+
} | {
|
|
40
|
+
options: Required<Omit<BarCodeOptions, "value">> & {
|
|
41
|
+
value?: string | number;
|
|
42
|
+
};
|
|
43
|
+
encodings: Encoding[];
|
|
44
|
+
valid: true;
|
|
45
|
+
empty: boolean;
|
|
46
|
+
error?: undefined;
|
|
47
|
+
} | {
|
|
48
|
+
options: Required<Omit<BarCodeOptions, "value">> & {
|
|
49
|
+
value?: string | number;
|
|
50
|
+
};
|
|
51
|
+
encodings: never[];
|
|
52
|
+
valid: boolean | undefined;
|
|
53
|
+
empty: boolean;
|
|
54
|
+
error: Error;
|
|
55
|
+
};
|
|
56
|
+
export type BarCodeEncoding = ReturnType<typeof encodeBarCode>;
|
|
57
|
+
export declare function barCodeLayout(encoded: BarCodeEncoding, measured?: Readonly<Record<string, number>>): {
|
|
58
|
+
svg: string;
|
|
59
|
+
texts: never[];
|
|
60
|
+
error: Error | undefined;
|
|
61
|
+
barSvg?: undefined;
|
|
62
|
+
fontSize?: undefined;
|
|
63
|
+
barHeight?: undefined;
|
|
64
|
+
textY?: undefined;
|
|
65
|
+
segmented?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
svg: string;
|
|
68
|
+
barSvg: string;
|
|
69
|
+
texts: {
|
|
70
|
+
text: string;
|
|
71
|
+
x: number;
|
|
72
|
+
width: number;
|
|
73
|
+
}[];
|
|
74
|
+
fontSize: number;
|
|
75
|
+
barHeight: number;
|
|
76
|
+
textY: number;
|
|
77
|
+
segmented: boolean;
|
|
78
|
+
error?: undefined;
|
|
79
|
+
};
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Import only encoders. JsBarcode's root entry also imports DOM/Canvas renderers.
|
|
2
|
+
import barcodeModule from 'jsbarcode/bin/barcodes/index.js';
|
|
3
|
+
export const barCodeFormats = ['auto', 'CODE128', 'CODE128A', 'CODE128B', 'CODE128C', 'EAN13', 'EAN8', 'UPC', 'UPCE', 'CODE39', 'ITF14', 'MSI', 'MSI10', 'MSI11', 'MSI1010', 'MSI1110', 'pharmacode', 'codabar'];
|
|
4
|
+
const defaults = { format: 'auto', width: 200, height: 100, text: '', font: 'monospace', fontSize: 20, fontOptions: '', textMargin: 2, background: '#ffffff', lineColor: '#000000', margin: 10, displayValue: true, textAlign: 'center', textPosition: 'bottom' };
|
|
5
|
+
const escape = (value) => value.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g, '').replace(/[<>&"']/g, character => ({ '<': '<', '>': '>', '&': '&', '"': '"', "'": ''' })[character]);
|
|
6
|
+
export function encodeBarCode(props) {
|
|
7
|
+
const options = { ...defaults, ...Object.fromEntries(Object.entries(props).filter(([, value]) => value !== undefined)) };
|
|
8
|
+
options.marginTop ??= options.margin;
|
|
9
|
+
options.marginBottom ??= options.margin;
|
|
10
|
+
options.marginLeft ??= options.margin;
|
|
11
|
+
options.marginRight ??= options.margin;
|
|
12
|
+
let valid;
|
|
13
|
+
try {
|
|
14
|
+
if (options.value === undefined || String(options.value) === '')
|
|
15
|
+
return { options, encodings: [], empty: true };
|
|
16
|
+
const value = String(options.value);
|
|
17
|
+
if (value.length > 128)
|
|
18
|
+
throw new Error('Barcode value exceeds max length 128');
|
|
19
|
+
if (!barCodeFormats.includes(options.format))
|
|
20
|
+
throw new Error(`Unsupported barcode format: ${options.format}`);
|
|
21
|
+
for (const name of ['margin', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight', 'textMargin']) {
|
|
22
|
+
if (!Number.isFinite(options[name]) || options[name] < 0)
|
|
23
|
+
throw new Error(`Barcode ${name} must be a non-negative finite number`);
|
|
24
|
+
}
|
|
25
|
+
const encoders = barcodeModule.default ?? barcodeModule;
|
|
26
|
+
const encoder = new encoders[options.format === 'auto' ? 'CODE128' : options.format](value, { ...options, width: 2, text: options.text || undefined });
|
|
27
|
+
valid = encoder.valid();
|
|
28
|
+
if (!valid)
|
|
29
|
+
throw new Error('Invalid barcode value');
|
|
30
|
+
const encoded = encoder.encode();
|
|
31
|
+
const encodings = Array.isArray(encoded) ? encoded : [encoded];
|
|
32
|
+
if (!encodings.some(item => item.data.length))
|
|
33
|
+
throw new Error('Invalid barcode value');
|
|
34
|
+
for (const name of ['width', 'height', 'fontSize']) {
|
|
35
|
+
if (!Number.isFinite(options[name]) || options[name] <= 0)
|
|
36
|
+
throw new Error(`Barcode ${name} must be a positive finite number`);
|
|
37
|
+
}
|
|
38
|
+
return { options, encodings, valid, empty: false };
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return { options, encodings: [], valid, empty: false, error: error instanceof Error ? error : new Error(String(error)) };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function barCodeLayout(encoded, measured = {}) {
|
|
45
|
+
const { options: o, encodings } = encoded;
|
|
46
|
+
if (encoded.error || encoded.empty)
|
|
47
|
+
return { svg: '', texts: [], error: encoded.error };
|
|
48
|
+
try {
|
|
49
|
+
const units = encodings.reduce((total, item) => total + item.data.length, 0), available = o.width - o.marginLeft - o.marginRight;
|
|
50
|
+
if (available <= 0)
|
|
51
|
+
throw new Error('Barcode width is too small for the margins');
|
|
52
|
+
const unitWidth = available / units;
|
|
53
|
+
const segmented = !o.text && ['EAN13', 'EAN8', 'UPC', 'UPCE'].includes(o.format);
|
|
54
|
+
let offset = o.marginLeft;
|
|
55
|
+
const segments = encodings.map(item => { const segment = { ...item, x: offset, width: item.data.length * unitWidth }; offset += segment.width; return segment; });
|
|
56
|
+
const texts = !o.displayValue ? [] : (segmented ? segments.map(item => ({ text: item.text ?? '', x: item.x, width: item.width })) : [{ text: o.text || encodings.map(item => item.text ?? '').join(''), x: o.marginLeft, width: available }]).filter(item => item.text);
|
|
57
|
+
const approximate = (text) => Array.from(text).reduce((sum, c) => sum + (c.charCodeAt(0) > 255 ? 1 : o.font === 'monospace' ? .60205 : .65), 0) * o.fontSize;
|
|
58
|
+
const italic = o.fontOptions.includes('italic');
|
|
59
|
+
const fit = texts.reduce((ratio, item) => {
|
|
60
|
+
const width = measured[item.text], textWidth = Number.isFinite(width) && width > 0 ? width : approximate(item.text);
|
|
61
|
+
return Math.min(ratio, item.width / (textWidth + (italic ? o.fontSize / 4 : 0)));
|
|
62
|
+
}, 1);
|
|
63
|
+
const fontSize = fit < 1 ? Math.floor(o.fontSize * fit) : o.fontSize;
|
|
64
|
+
if (texts.length && fontSize < 1)
|
|
65
|
+
throw new Error('Barcode width is too small for the display text');
|
|
66
|
+
const textHeight = texts.length ? fontSize * 1.25 + o.textMargin : 0;
|
|
67
|
+
const barHeight = o.height - o.marginTop - o.marginBottom - textHeight;
|
|
68
|
+
if (barHeight < 1)
|
|
69
|
+
throw new Error('Barcode height is too small for the margins, text and bars');
|
|
70
|
+
const barY = o.marginTop + (o.textPosition === 'top' ? textHeight : 0);
|
|
71
|
+
const guardHeight = barHeight + (o.displayValue && segmented && o.textPosition === 'bottom' ? o.textMargin + fontSize / 2 : 0);
|
|
72
|
+
const rects = [];
|
|
73
|
+
for (const segment of segments) {
|
|
74
|
+
const h = Number(segment.options?.height) > o.height ? guardHeight : barHeight;
|
|
75
|
+
let run = -1;
|
|
76
|
+
for (let i = 0; i <= segment.data.length; i++) {
|
|
77
|
+
if (segment.data[i] === '1') {
|
|
78
|
+
if (run < 0)
|
|
79
|
+
run = i;
|
|
80
|
+
}
|
|
81
|
+
else if (run >= 0) {
|
|
82
|
+
rects.push(`<rect x="${segment.x + run * unitWidth}" y="${barY}" width="${(i - run) * unitWidth}" height="${h}"/>`);
|
|
83
|
+
run = -1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const textY = o.textPosition === 'top' ? o.marginTop + fontSize : barY + barHeight + o.textMargin + fontSize;
|
|
88
|
+
const labels = texts.map(item => {
|
|
89
|
+
const align = segmented ? 'center' : o.textAlign, anchor = align === 'left' ? 'start' : align === 'right' ? 'end' : 'middle';
|
|
90
|
+
const x = item.x + (align === 'left' ? 0 : align === 'right' ? item.width : item.width / 2);
|
|
91
|
+
return `<text x="${x}" y="${textY}" text-anchor="${anchor}" font-family="${escape(o.font)}" font-size="${fontSize}" font-weight="${o.fontOptions.includes('bold') ? 'bold' : 'normal'}" font-style="${italic ? 'italic' : 'normal'}">${escape(item.text)}</text>`;
|
|
92
|
+
});
|
|
93
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${o.width}" height="${o.height}" viewBox="0 0 ${o.width} ${o.height}"><rect width="${o.width}" height="${o.height}" fill="${escape(o.background || 'transparent')}"/><g fill="${escape(o.lineColor)}">${rects.join('')}${labels.join('')}</g></svg>`;
|
|
94
|
+
return { svg, barSvg: svg.replace(labels.join(''), ''), texts, fontSize, barHeight, textY, segmented };
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return { svg: '', texts: [], error: error instanceof Error ? error : new Error(String(error)) };
|
|
98
|
+
}
|
|
99
|
+
}
|