@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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type QrCodeOptions = {
|
|
2
|
+
text?: string;
|
|
3
|
+
size?: number;
|
|
4
|
+
correctLevel?: 'L' | 'M' | 'Q' | 'H';
|
|
5
|
+
colorDark?: string;
|
|
6
|
+
colorLight?: string;
|
|
7
|
+
margin?: number;
|
|
8
|
+
logo?: string;
|
|
9
|
+
logoWidth?: number;
|
|
10
|
+
logoHeight?: number;
|
|
11
|
+
logoBackgroundColor?: string;
|
|
12
|
+
logoRadius?: number;
|
|
13
|
+
logoBorderColor?: string;
|
|
14
|
+
logoBorderWidth?: number;
|
|
15
|
+
dotType?: 'square' | 'dots' | 'rounded' | 'liquid';
|
|
16
|
+
dotScale?: number;
|
|
17
|
+
enableGradient?: boolean;
|
|
18
|
+
gradientColor?: string;
|
|
19
|
+
gradientColors?: string[];
|
|
20
|
+
gradientDirection?: 'diagonal' | 'horizontal' | 'vertical' | number;
|
|
21
|
+
backgroundImage?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const qrEscape: (s: string) => string;
|
|
24
|
+
export declare function qrCodeMatrix(text: string, level?: QrCodeOptions['correctLevel']): boolean[][];
|
|
25
|
+
export declare function qrCodeLayout(matrix: boolean[][], options: QrCodeOptions): {
|
|
26
|
+
svg: string;
|
|
27
|
+
codeSvg: string;
|
|
28
|
+
logo: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
radius: number;
|
|
34
|
+
};
|
|
35
|
+
options: Required<QrCodeOptions>;
|
|
36
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import qrcode from 'qrcode-generator';
|
|
2
|
+
export const qrEscape = (s) => s.replace(/[<>&"']/g, c => ({ '<': '<', '>': '>', '&': '&', '"': '"', "'": ''' })[c]);
|
|
3
|
+
export function qrCodeMatrix(text, level = 'H') {
|
|
4
|
+
if (!text)
|
|
5
|
+
return [];
|
|
6
|
+
if (!['L', 'M', 'Q', 'H'].includes(level))
|
|
7
|
+
throw new Error('Invalid QR correction level');
|
|
8
|
+
if (text.length > 2953)
|
|
9
|
+
throw new Error('QR content exceeds capacity');
|
|
10
|
+
// The encoder's Byte mode consumes bytes, not UTF-16 code units. Keep its
|
|
11
|
+
// shared factory untouched so other consumers cannot change our encoding.
|
|
12
|
+
const bytes = encodeURIComponent(text).replace(/%([0-9A-F]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
13
|
+
const qr = qrcode(0, level);
|
|
14
|
+
qr.addData(bytes, 'Byte');
|
|
15
|
+
qr.make();
|
|
16
|
+
return Array.from({ length: qr.getModuleCount() }, (_, row) => Array.from({ length: qr.getModuleCount() }, (_, col) => qr.isDark(row, col)));
|
|
17
|
+
}
|
|
18
|
+
export function qrCodeLayout(matrix, options) {
|
|
19
|
+
const o = { size: 200, margin: 0, colorDark: '#000000', colorLight: '#FFFFFF', dotType: 'square', dotScale: 1, gradientColor: '#000000', gradientDirection: 'diagonal', logoWidth: 70, logoHeight: 70, logoRadius: 0, logoBorderWidth: 0, logoBackgroundColor: '#FFFFFF', ...Object.fromEntries(Object.entries(options).filter(([, v]) => v !== undefined)) };
|
|
20
|
+
for (const name of ['size', 'margin', 'dotScale', 'logoWidth', 'logoHeight', 'logoRadius', 'logoBorderWidth'])
|
|
21
|
+
if (!Number.isFinite(o[name]) || o[name] < 0)
|
|
22
|
+
throw new Error(`Invalid QR ${name}`);
|
|
23
|
+
if (o.size <= 0 || o.size > 4096 || o.margin * 2 >= o.size || o.dotScale <= 0 || o.dotScale > 1)
|
|
24
|
+
throw new Error('Invalid QR bounds');
|
|
25
|
+
if (!['square', 'dots', 'rounded', 'liquid'].includes(o.dotType))
|
|
26
|
+
throw new Error('Invalid QR dot type');
|
|
27
|
+
for (const src of [o.logo, o.backgroundImage])
|
|
28
|
+
if (src && /[\u0000-\u0020]|^(?!https?:|data:image\/(?:png|jpeg|gif|webp);base64,)[a-z][a-z0-9+.-]*:/i.test(src))
|
|
29
|
+
throw new Error('Invalid QR image URL');
|
|
30
|
+
const size = matrix.length, step = (o.size - 2 * o.margin) / size, shapes = [];
|
|
31
|
+
const dark = (r, c) => !!matrix[r]?.[c];
|
|
32
|
+
for (let r = 0; r < size; r++)
|
|
33
|
+
for (let c = 0; c < size; c++)
|
|
34
|
+
if (dark(r, c)) {
|
|
35
|
+
const left = Math.ceil(c * step) + o.margin, top = Math.ceil(r * step) + o.margin, w = Math.ceil((c + 1) * step) - Math.ceil(c * step), h = Math.ceil((r + 1) * step) - Math.ceil(r * step);
|
|
36
|
+
const sw = w * o.dotScale, sh = h * o.dotScale, x = left + (w - sw) / 2, y = top + (h - sh) / 2;
|
|
37
|
+
if (o.dotType === 'dots')
|
|
38
|
+
shapes.push(`<circle cx="${x + sw / 2}" cy="${y + sh / 2}" r="${sw / 2}"/>`);
|
|
39
|
+
else if (o.dotType === 'liquid') {
|
|
40
|
+
const radius = sw / 2, tl = dark(r - 1, c) || dark(r, c - 1) ? 0 : radius, tr = dark(r - 1, c) || dark(r, c + 1) ? 0 : radius, br = dark(r + 1, c) || dark(r, c + 1) ? 0 : radius, bl = dark(r + 1, c) || dark(r, c - 1) ? 0 : radius;
|
|
41
|
+
shapes.push(`<path d="M${x + tl} ${y}H${x + sw - tr}Q${x + sw} ${y} ${x + sw} ${y + tr}V${y + sh - br}Q${x + sw} ${y + sh} ${x + sw - br} ${y + sh}H${x + bl}Q${x} ${y + sh} ${x} ${y + sh - bl}V${y + tl}Q${x} ${y} ${x + tl} ${y}Z"/>`);
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
shapes.push(`<rect x="${x}" y="${y}" width="${sw}" height="${sh}" rx="${o.dotType === 'rounded' ? sw * .25 : 0}"/>`);
|
|
45
|
+
}
|
|
46
|
+
let defs = '', fill = qrEscape(o.colorDark);
|
|
47
|
+
if (o.enableGradient) {
|
|
48
|
+
const angle = typeof o.gradientDirection === 'number' ? o.gradientDirection : o.gradientDirection === 'horizontal' ? 0 : o.gradientDirection === 'vertical' ? 90 : 45;
|
|
49
|
+
if (!Number.isFinite(angle))
|
|
50
|
+
throw new Error('Invalid QR gradient angle');
|
|
51
|
+
const radians = angle * Math.PI / 180, extent = (Math.abs(Math.cos(radians)) + Math.abs(Math.sin(radians))) * o.size / 2, cx = o.size / 2;
|
|
52
|
+
const colors = o.gradientColors?.length ? o.gradientColors : [o.colorDark, o.gradientColor];
|
|
53
|
+
defs = `<defs><linearGradient id="qr-gradient" gradientUnits="userSpaceOnUse" x1="${cx - Math.cos(radians) * extent}" y1="${cx - Math.sin(radians) * extent}" x2="${cx + Math.cos(radians) * extent}" y2="${cx + Math.sin(radians) * extent}">${colors.map((color, i) => `<stop offset="${i / Math.max(1, colors.length - 1)}" stop-color="${qrEscape(color)}"/>`).join('')}</linearGradient></defs>`;
|
|
54
|
+
fill = 'url(#qr-gradient)';
|
|
55
|
+
}
|
|
56
|
+
const open = `<svg xmlns="http://www.w3.org/2000/svg" width="${o.size}" height="${o.size}" viewBox="0 0 ${o.size} ${o.size}">`, bg = `<rect width="100%" height="100%" fill="${qrEscape(o.colorLight)}"/>`;
|
|
57
|
+
const body = `${defs}<g fill="${fill}">${shapes.join('')}</g>`, logo = { x: (o.size - o.logoWidth) / 2, y: (o.size - o.logoHeight) / 2, width: o.logoWidth, height: o.logoHeight, radius: Math.max(0, o.logoRadius - 4) };
|
|
58
|
+
const logoSvg = o.logo && matrix.length ? `<defs><clipPath id="qr-logo-clip"><rect x="${logo.x}" y="${logo.y}" width="${logo.width}" height="${logo.height}" rx="${logo.radius}"/></clipPath></defs><rect x="${logo.x - 4}" y="${logo.y - 4}" width="${logo.width + 8}" height="${logo.height + 8}" rx="${o.logoRadius}" fill="${qrEscape(o.logoBackgroundColor)}" stroke="${qrEscape(o.logoBorderColor || 'transparent')}" stroke-width="${o.logoBorderWidth}"/><image href="${qrEscape(o.logo)}" x="${logo.x}" y="${logo.y}" width="${logo.width}" height="${logo.height}" preserveAspectRatio="none" clip-path="url(#qr-logo-clip)"/>` : '';
|
|
59
|
+
const backdrop = o.backgroundImage && matrix.length ? `<image href="${qrEscape(o.backgroundImage)}" width="${o.size}" height="${o.size}" preserveAspectRatio="none"/>` : '';
|
|
60
|
+
return { svg: open + bg + backdrop + body + logoSvg + '</svg>', codeSvg: open + body + '</svg>', logo, options: o };
|
|
61
|
+
}
|
package/dist/rate.css
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.ui-rate { display: flex; flex-direction: row; align-self: flex-start; align-items: center; }
|
|
2
|
+
.ui-rate-block { align-self: stretch; }
|
|
3
|
+
.ui-rate-item { position: relative; width: var(--ui-rate-size, 24px); height: var(--ui-rate-size, 24px); flex-shrink: 0; }
|
|
4
|
+
.ui-rate-item + .ui-rate-item { margin-left: var(--ui-rate-space, 6px); }
|
|
5
|
+
.ui-rate-glyph { width: var(--ui-rate-size, 24px); height: var(--ui-rate-size, 24px); flex-shrink: 0; }
|
|
6
|
+
.ui-rate-fill { position: absolute; left: 0; top: 0; height: 100%; overflow: hidden; }
|
|
7
|
+
.ui-rate-empty { position: absolute; right: 0; top: 0; height: 100%; overflow: hidden; }
|
|
8
|
+
.ui-rate-empty .ui-rate-glyph { position: absolute; right: 0; top: 0; }
|
|
9
|
+
.ui-rate-hit { position: absolute; left: 0; top: 0; height: 100%; width: 100%; }
|
|
10
|
+
.ui-rate-hit-half { width: 50%; }
|
|
11
|
+
.ui-rate-hit-full { width: 50%; left: 50%; }
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
.ui-rate-disabled { opacity: .4; }
|
|
18
|
+
|
|
19
|
+
.ui-rate-default-light{display:var(--cso-ui-light-display,flex);}
|
|
20
|
+
.ui-rate-default-dark{display:var(--cso-ui-dark-display,none);}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function rateCount(num: number): number;
|
|
2
|
+
export declare function rateScore(value: number | null | undefined, num: number): number;
|
|
3
|
+
export declare function nextRateValue(current: number, next: number, allowHalf: boolean, clearable: boolean): number;
|
|
4
|
+
export declare function rateSvg(path: string, color: string): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { glyphSvg } from './icons/render.js';
|
|
2
|
+
export function rateCount(num) { return Number.isFinite(num) ? Math.max(0, Math.floor(num)) : 5; }
|
|
3
|
+
export function rateScore(value, num) { return typeof value === 'number' && Number.isFinite(value) ? Math.max(0, Math.min(num, value)) : 0; }
|
|
4
|
+
export function nextRateValue(current, next, allowHalf, clearable) { return clearable && next === current && next === (allowHalf ? .5 : 1) ? 0 : next; }
|
|
5
|
+
const escapeXml = (text) => text.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
6
|
+
export function rateSvg(path, color) {
|
|
7
|
+
let paint = color;
|
|
8
|
+
let defs = '';
|
|
9
|
+
const gradient = /^linear-gradient\((.*)\)$/i.exec(color);
|
|
10
|
+
if (gradient) {
|
|
11
|
+
const parts = [];
|
|
12
|
+
let depth = 0;
|
|
13
|
+
let start = 0;
|
|
14
|
+
for (let i = 0; i < gradient[1].length; i++) {
|
|
15
|
+
const ch = gradient[1][i];
|
|
16
|
+
if (ch === '(')
|
|
17
|
+
depth++;
|
|
18
|
+
else if (ch === ')')
|
|
19
|
+
depth--;
|
|
20
|
+
else if (ch === ',' && depth === 0) {
|
|
21
|
+
parts.push(gradient[1].slice(start, i).trim());
|
|
22
|
+
start = i + 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
parts.push(gradient[1].slice(start).trim());
|
|
26
|
+
const direction = /^(-?[\d.]+)deg$/.exec(parts[0] ?? '');
|
|
27
|
+
const angle = direction ? Number(direction[1]) : 180;
|
|
28
|
+
if (direction)
|
|
29
|
+
parts.shift();
|
|
30
|
+
const radians = angle * Math.PI / 180;
|
|
31
|
+
const dx = Math.sin(radians) * 50;
|
|
32
|
+
const dy = -Math.cos(radians) * 50;
|
|
33
|
+
const stops = parts.map((part, index) => { const match = /^(.*?)(?:\s+([\d.]+)%)?$/.exec(part); return `<stop offset="${match[2] ?? index / Math.max(1, parts.length - 1) * 100}%" stop-color="${escapeXml(match[1])}"/>`; }).join('');
|
|
34
|
+
defs = `<defs><linearGradient id="rate" x1="${50 - dx}%" y1="${50 + dy}%" x2="${50 + dx}%" y2="${50 - dy}%">${stops}</linearGradient></defs>`;
|
|
35
|
+
paint = 'url(#rate)';
|
|
36
|
+
}
|
|
37
|
+
return glyphSvg(path, paint, defs);
|
|
38
|
+
}
|
package/dist/resize.css
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.ui-rich-text { width:100%; min-width:0; color:var(--cso-ui-rich-text-color,var(--cso-ui-text)); font-size:var(--cso-ui-rich-text-font-size,14px); line-height:var(--cso-ui-rich-text-line-height,1.7); }
|
|
2
|
+
.ui-rich-text-line { color:inherit; font-size:inherit; line-height:inherit; text-indent:inherit; text-align:inherit; }
|
|
3
|
+
.ui-rich-text-block { width:100%; min-width:0; }
|
|
4
|
+
.ui-rich-text-list { width:100%; padding-left:24px; }
|
|
5
|
+
.ui-rich-text-li { position:relative; display:flex; flex-direction:row; align-items:flex-start; }
|
|
6
|
+
.ui-rich-text-marker { position:absolute; left:-24px; top:0; width:24px; padding-right:4px; text-align:right; font-size:inherit; line-height:inherit; color:inherit; }
|
|
7
|
+
.ui-rich-text-li-task .ui-rich-text-marker { position:relative; left:0; width:auto; padding-right:0; flex-shrink:0; }
|
|
8
|
+
.ui-rich-text-li-content { flex:1; min-width:0; }
|
|
9
|
+
.ui-rich-text-hr { height:1px; width:100%; background:var(--cso-ui-line); }
|
|
10
|
+
.ui-rich-text-table { margin-bottom:0; }
|
|
11
|
+
.ui-rich-text-table .ui-table-content { width:100%; }
|
|
12
|
+
.ui-rich-text-cell { width:100%; min-width:0; padding:8px; }
|
|
13
|
+
.ui-rich-text-th { font-weight:bold; text-align:center; }
|
|
14
|
+
.ui-rich-text-image-alt { color:var(--cso-ui-rich-text-image-state-color,var(--cso-ui-text-muted)); font-size:inherit; line-height:inherit; }
|
|
15
|
+
.ui-rich-text-missing-image { width:100%; background:var(--cso-ui-rich-text-image-state-bg,var(--cso-ui-surface-muted)); }
|
|
16
|
+
|
|
17
|
+
.ui-rich-text-media { width:100%; min-width:0; }
|
|
18
|
+
.ui-rich-text-video { width:100%; height:var(--cso-ui-rich-text-video-height,225px); max-width:100%; }
|
|
19
|
+
.ui-rich-text-audio { width:100%; height:24px; max-width:100%; }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Shared protocol; browser DOM code is only loaded by daisu-ui/web. */
|
|
2
|
+
export type RichTextMediaType = 'audio' | 'video';
|
|
3
|
+
export type RichTextMediaConfig = {
|
|
4
|
+
id: string;
|
|
5
|
+
type: RichTextMediaType;
|
|
6
|
+
sources: string[];
|
|
7
|
+
title: string;
|
|
8
|
+
poster?: string;
|
|
9
|
+
loop: boolean;
|
|
10
|
+
muted: boolean;
|
|
11
|
+
preview?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type RichTextMediaEvent = {
|
|
14
|
+
id: string;
|
|
15
|
+
type: RichTextMediaType;
|
|
16
|
+
src: string;
|
|
17
|
+
};
|
|
18
|
+
export type RichTextMediaTimeUpdate = RichTextMediaEvent & {
|
|
19
|
+
currentTime: number;
|
|
20
|
+
duration: number;
|
|
21
|
+
};
|
|
22
|
+
export type RichTextMediaSignal = RichTextMediaTimeUpdate & {
|
|
23
|
+
kind: 'play' | 'pause' | 'ended' | 'timeupdate' | 'error' | 'close';
|
|
24
|
+
message?: string;
|
|
25
|
+
code?: string;
|
|
26
|
+
fatal?: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare function validRichTextMediaId(id: string): boolean;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
import type { RichTextMediaConfig } from './richTextMedia.js';
|
|
3
|
+
export type RichTextHeading = {
|
|
4
|
+
id: string;
|
|
5
|
+
level: number;
|
|
6
|
+
text: string;
|
|
7
|
+
};
|
|
8
|
+
export type RichTextNode = {
|
|
9
|
+
key: number;
|
|
10
|
+
tag: string;
|
|
11
|
+
text?: string;
|
|
12
|
+
attrs: Record<string, string>;
|
|
13
|
+
style: CSSProperties;
|
|
14
|
+
children: RichTextNode[];
|
|
15
|
+
anchor?: string;
|
|
16
|
+
imageIndex?: number;
|
|
17
|
+
src?: string;
|
|
18
|
+
previewSrc?: string;
|
|
19
|
+
media?: RichTextMediaConfig;
|
|
20
|
+
};
|
|
21
|
+
export type RichTextParseOptions = {
|
|
22
|
+
enableMedia?: boolean;
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
allowDataImage?: boolean;
|
|
25
|
+
enableAnchor?: boolean;
|
|
26
|
+
tagStyle?: Record<string, string>;
|
|
27
|
+
classStyles?: Record<string, string>;
|
|
28
|
+
};
|
|
29
|
+
export declare class RichTextParseError extends Error {
|
|
30
|
+
code: string;
|
|
31
|
+
constructor(code: string, message: string);
|
|
32
|
+
}
|
|
33
|
+
export declare function richTextStyle(value: string): CSSProperties;
|
|
34
|
+
export declare function richTextUrl(input: string, options?: RichTextParseOptions, link?: boolean): string;
|
|
35
|
+
export declare function richTextPlain(nodes: readonly RichTextNode[]): string;
|
|
36
|
+
export declare function parseRichText(content: string, options?: RichTextParseOptions): {
|
|
37
|
+
nodes: RichTextNode[];
|
|
38
|
+
images: RichTextNode[];
|
|
39
|
+
media: RichTextNode[];
|
|
40
|
+
headings: RichTextHeading[];
|
|
41
|
+
text: string;
|
|
42
|
+
};
|
|
43
|
+
export declare const richBlockTags: Set<string>;
|
|
44
|
+
export type RichTextTableCell = {
|
|
45
|
+
node: RichTextNode;
|
|
46
|
+
rowspan: number;
|
|
47
|
+
colspan: number;
|
|
48
|
+
};
|
|
49
|
+
export declare function richTextTableGrid(table: RichTextNode): {
|
|
50
|
+
grid: RichTextTableCell[][];
|
|
51
|
+
columns: number;
|
|
52
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Parser } from 'htmlparser2';
|
|
2
|
+
export class RichTextParseError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const blockTags = new Set('div p h1 h2 h3 h4 h5 h6 blockquote pre ul ol li table tr td th figure figcaption section article header footer dl dt dd hr'.split(' '));
|
|
10
|
+
const allowed = new Set([...blockTags, ...'span a img br strong b em i u s del mark small sub sup code thead tbody tfoot colgroup col caption audio video source'.split(' ')]);
|
|
11
|
+
const ignored = new Set('script style iframe object embed svg math template noscript'.split(' '));
|
|
12
|
+
const styleNames = new Set('color background-color font-size font-family font-weight font-style line-height letter-spacing text-align text-decoration text-indent white-space word-break vertical-align width height min-width max-width min-height max-height margin margin-top margin-bottom margin-left margin-right padding padding-top padding-bottom padding-left padding-right border border-width border-style border-color border-radius border-top border-bottom border-left border-right border-top-width border-bottom-width border-left-width border-right-width border-top-color border-bottom-color border-left-color border-right-color border-top-style border-bottom-style border-left-style border-right-style display'.split(' '));
|
|
13
|
+
export function richTextStyle(value) {
|
|
14
|
+
const result = {};
|
|
15
|
+
for (const declaration of value.split(';')) {
|
|
16
|
+
const colon = declaration.indexOf(':');
|
|
17
|
+
if (colon < 0)
|
|
18
|
+
continue;
|
|
19
|
+
const name = declaration.slice(0, colon).trim().toLowerCase(), value = declaration.slice(colon + 1).trim();
|
|
20
|
+
if (!styleNames.has(name) || !value || /url\s*\(|expression|[<>\\@]|!important/i.test(value))
|
|
21
|
+
continue;
|
|
22
|
+
if (name === 'display' && value !== 'none')
|
|
23
|
+
continue;
|
|
24
|
+
result[name.replace(/-([a-z])/g, (_, c) => c.toUpperCase())] = value;
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
export function richTextUrl(input, options = {}, link = false) {
|
|
29
|
+
const src = input.trim();
|
|
30
|
+
if (!src || /[\u0000-\u0020\u007f\\]/.test(src))
|
|
31
|
+
return '';
|
|
32
|
+
if (/^data:/i.test(src))
|
|
33
|
+
return !link && options.allowDataImage && src.length <= 65536 && /^data:image\/(png|jpeg|gif|webp);base64,[a-z0-9+/=]+$/i.test(src) ? src : '';
|
|
34
|
+
if (/^https?:\/\/[^/?#]*@/i.test(src))
|
|
35
|
+
return '';
|
|
36
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(src))
|
|
37
|
+
return /^(https?:\/\/[^/@]+|mailto:|tel:)/i.test(src) && (!/^(mailto|tel):/i.test(src) || link) ? src : '';
|
|
38
|
+
if (src.startsWith('//'))
|
|
39
|
+
return richTextUrl('https:' + src, options, link);
|
|
40
|
+
if (link || !options.baseUrl)
|
|
41
|
+
return src;
|
|
42
|
+
const match = /^(https?:\/\/[^/?#@]+)(\/[^?#]*)?(?:[?#].*)?$/i.exec(options.baseUrl);
|
|
43
|
+
if (!match)
|
|
44
|
+
return '';
|
|
45
|
+
const path = src.startsWith('/') ? src : (match[2] || '/').replace(/[^/]*$/, '') + src;
|
|
46
|
+
const segments = [];
|
|
47
|
+
for (const part of path.split('/')) {
|
|
48
|
+
if (part === '..')
|
|
49
|
+
segments.pop();
|
|
50
|
+
else if (part !== '.')
|
|
51
|
+
segments.push(part);
|
|
52
|
+
}
|
|
53
|
+
return match[1] + segments.join('/');
|
|
54
|
+
}
|
|
55
|
+
export function richTextPlain(nodes) {
|
|
56
|
+
return nodes.map(n => n.tag === '#text' ? n.text : n.tag === 'br' ? '\n' : n.tag === 'img' ? n.attrs.alt || '' : n.media ? n.media.title + '\n' : richTextPlain(n.children) + (blockTags.has(n.tag) ? '\n' : '')).join('');
|
|
57
|
+
}
|
|
58
|
+
export function parseRichText(content, options = {}) {
|
|
59
|
+
if (content.length > 200000)
|
|
60
|
+
throw new RichTextParseError('CONTENT_LIMIT', 'RichText content exceeds 200000 characters');
|
|
61
|
+
const nodes = [], stack = [], headings = [], images = [];
|
|
62
|
+
const ids = new Set();
|
|
63
|
+
let count = 0, depth = 0, skip = 0;
|
|
64
|
+
const add = (node) => { if (++count > 10000)
|
|
65
|
+
throw new RichTextParseError('NODE_LIMIT', 'RichText exceeds 10000 nodes'); (stack[stack.length - 1]?.children ?? nodes).push(node); };
|
|
66
|
+
const parser = new Parser({
|
|
67
|
+
onopentag(tag, attrs) {
|
|
68
|
+
if (++depth > 128)
|
|
69
|
+
throw new RichTextParseError('DEPTH_LIMIT', 'RichText exceeds 128 levels');
|
|
70
|
+
if (skip || ignored.has(tag) || (!options.enableMedia && ['audio', 'video', 'source'].includes(tag)) || (tag === 'source' && !['audio', 'video'].includes(stack[stack.length - 1]?.tag || ''))) {
|
|
71
|
+
skip++;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const node = { key: count, tag: allowed.has(tag) ? tag : 'div', attrs: {}, style: {}, children: [] };
|
|
75
|
+
for (const name of ['id', 'class', 'alt', 'title', 'width', 'height', 'colspan', 'rowspan', 'span', 'start', 'data-list', 'data-preview'])
|
|
76
|
+
if (attrs[name] !== undefined)
|
|
77
|
+
node.attrs[name] = attrs[name];
|
|
78
|
+
const classes = (attrs.class || '').split(/\s+/);
|
|
79
|
+
const quill = { 'ql-align-center': 'text-align:center', 'ql-align-right': 'text-align:right', 'ql-align-justify': 'text-align:justify', 'ql-size-small': 'font-size:10px', 'ql-size-large': 'font-size:21px', 'ql-size-huge': 'font-size:35px', 'ql-font-serif': 'font-family:serif', 'ql-font-monospace': 'font-family:monospace' };
|
|
80
|
+
const mapped = classes.map(c => options.classStyles?.[c] ?? quill[c] ?? (/^ql-indent-[1-8]$/.test(c) ? `padding-left:${Number(c.slice(-1)) * 3}em` : '')).join(';');
|
|
81
|
+
node.style = richTextStyle([options.tagStyle?.[tag] || '', mapped, attrs.style || ''].join(';'));
|
|
82
|
+
if (tag === 'a')
|
|
83
|
+
node.attrs.href = richTextUrl(attrs.href || '', options, true);
|
|
84
|
+
if (tag === 'img') {
|
|
85
|
+
node.src = richTextUrl(attrs.src || '', options);
|
|
86
|
+
node.previewSrc = attrs['data-preview'] === 'false' ? '' : richTextUrl(attrs['original-src'] || '', options) || node.src;
|
|
87
|
+
node.imageIndex = images.length;
|
|
88
|
+
images.push(node);
|
|
89
|
+
}
|
|
90
|
+
if (tag === 'audio' || tag === 'video')
|
|
91
|
+
node.media = { id: attrs.id || '', type: tag, sources: [], title: attrs.title || '', poster: richTextUrl(attrs.poster || '', { ...options, allowDataImage: false }), loop: attrs.loop !== undefined && attrs.loop !== 'false', muted: attrs.muted !== undefined && attrs.muted !== 'false' };
|
|
92
|
+
if (tag === 'audio' || tag === 'video' || tag === 'source')
|
|
93
|
+
node.src = richTextUrl(attrs.src || '', { ...options, allowDataImage: false });
|
|
94
|
+
if (options.enableAnchor) {
|
|
95
|
+
const wanted = attrs.id?.trim();
|
|
96
|
+
if (wanted && !ids.has(wanted)) {
|
|
97
|
+
node.anchor = wanted;
|
|
98
|
+
ids.add(wanted);
|
|
99
|
+
}
|
|
100
|
+
if (/^h[1-6]$/.test(tag) && !node.anchor) {
|
|
101
|
+
let generated = `heading-${count}`;
|
|
102
|
+
while (ids.has(generated))
|
|
103
|
+
generated += '-';
|
|
104
|
+
node.anchor = generated;
|
|
105
|
+
ids.add(generated);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
add(node);
|
|
109
|
+
stack.push(node);
|
|
110
|
+
},
|
|
111
|
+
ontext(text) { if (skip)
|
|
112
|
+
return; const pre = stack.some(n => n.tag === 'pre'); const value = pre ? text : text.replace(/[ \t\r\n\f]+/g, ' '); if (value)
|
|
113
|
+
add({ key: count, tag: '#text', text: value, attrs: {}, style: {}, children: [] }); },
|
|
114
|
+
onclosetag() {
|
|
115
|
+
depth--;
|
|
116
|
+
if (skip) {
|
|
117
|
+
skip--;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const node = stack.pop();
|
|
121
|
+
if (node?.media) {
|
|
122
|
+
const candidates = [node.src, ...node.children.filter(c => c.tag === 'source').map(c => c.src)].filter((src) => !!src);
|
|
123
|
+
node.media.sources = [...new Set(candidates)];
|
|
124
|
+
if (node.media.sources.length > 16)
|
|
125
|
+
throw new RichTextParseError('MEDIA_SOURCE_LIMIT', 'RichText media exceeds 16 sources');
|
|
126
|
+
node.children = [];
|
|
127
|
+
}
|
|
128
|
+
if (node?.anchor && /^h[1-6]$/.test(node.tag))
|
|
129
|
+
headings.push({ id: node.anchor, level: Number(node.tag[1]), text: richTextPlain(node.children).trim() });
|
|
130
|
+
},
|
|
131
|
+
}, { decodeEntities: true });
|
|
132
|
+
parser.end(content);
|
|
133
|
+
const prune = (items) => items.filter(n => { n.children = prune(n.children); return n.style.display !== 'none' && (n.tag === '#text' ? !!n.text : n.media || n.tag === 'source' || n.tag === 'img' || n.tag === 'br' || n.tag === 'hr' || n.tag === 'col' || n.tag === 'p' || n.children.length > 0); });
|
|
134
|
+
let filtered = prune(nodes);
|
|
135
|
+
const hasVisual = (n) => !!n.media || n.tag === 'img' || n.tag === 'hr' || n.children.some(hasVisual);
|
|
136
|
+
if (!richTextPlain(filtered).trim() && !filtered.some(hasVisual))
|
|
137
|
+
filtered = [];
|
|
138
|
+
const visibleAnchors = new Set();
|
|
139
|
+
const walk = (items) => { for (const n of items) {
|
|
140
|
+
if (n.anchor)
|
|
141
|
+
visibleAnchors.add(n.anchor);
|
|
142
|
+
if (n.tag === 'table')
|
|
143
|
+
richTextTableGrid(n);
|
|
144
|
+
walk(n.children);
|
|
145
|
+
} };
|
|
146
|
+
walk(filtered);
|
|
147
|
+
if (JSON.stringify(filtered).length > 2000000)
|
|
148
|
+
throw new RichTextParseError('OUTPUT_LIMIT', 'RichText rendered data exceeds limit');
|
|
149
|
+
const media = [];
|
|
150
|
+
const visibleImages = [];
|
|
151
|
+
const collectImages = (items) => { for (const node of items) {
|
|
152
|
+
if (node.media)
|
|
153
|
+
media.push(node);
|
|
154
|
+
if (node.tag === 'img') {
|
|
155
|
+
node.imageIndex = visibleImages.length;
|
|
156
|
+
visibleImages.push(node);
|
|
157
|
+
}
|
|
158
|
+
collectImages(node.children);
|
|
159
|
+
} };
|
|
160
|
+
collectImages(filtered);
|
|
161
|
+
return { nodes: filtered, images: visibleImages, media, headings: headings.filter(h => visibleAnchors.has(h.id)), text: richTextPlain(filtered).trim() };
|
|
162
|
+
}
|
|
163
|
+
export const richBlockTags = blockTags;
|
|
164
|
+
export function richTextTableGrid(table) {
|
|
165
|
+
const rows = [];
|
|
166
|
+
const collect = (node) => { if (node.tag === 'tr')
|
|
167
|
+
rows.push(node.children.filter(c => c.tag === 'td' || c.tag === 'th'));
|
|
168
|
+
else
|
|
169
|
+
for (const child of node.children)
|
|
170
|
+
if (child.tag !== 'table')
|
|
171
|
+
collect(child); };
|
|
172
|
+
collect(table);
|
|
173
|
+
const grid = [];
|
|
174
|
+
let columns = 0, slots = 0;
|
|
175
|
+
rows.forEach((cells, r) => {
|
|
176
|
+
grid[r] ??= [];
|
|
177
|
+
let column = 0;
|
|
178
|
+
for (const node of cells) {
|
|
179
|
+
const rowspan = Math.max(1, Math.min(99, rows.length - r, parseInt(node.attrs.rowspan || '1') || 1)), colspan = Math.max(1, Math.min(99, parseInt(node.attrs.colspan || '1') || 1));
|
|
180
|
+
while (Array.from({ length: colspan }, (_, i) => grid[r][column + i]).some(Boolean))
|
|
181
|
+
column++;
|
|
182
|
+
if (column + colspan > 100 || slots + rowspan * colspan > 10000)
|
|
183
|
+
throw new RichTextParseError('TABLE_LIMIT', 'RichText table exceeds 100 columns or 10000 layout cells');
|
|
184
|
+
for (let y = r; y < r + rowspan; y++) {
|
|
185
|
+
grid[y] ??= [];
|
|
186
|
+
for (let x = column; x < column + colspan; x++)
|
|
187
|
+
grid[y][x] = { node, rowspan: y === r && x === column ? rowspan : 0, colspan: y === r && x === column ? colspan : 0 };
|
|
188
|
+
}
|
|
189
|
+
slots += rowspan * colspan;
|
|
190
|
+
column += colspan;
|
|
191
|
+
columns = Math.max(columns, column);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return { grid, columns };
|
|
195
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ui-root-portal-target { position: absolute; top: 0; left: 0; width: 0; height: 0; overflow: visible; }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MutableRefObject, ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { AnyRoute } from '@tanstack/react-router';
|
|
3
|
+
import type { Router } from './core.js';
|
|
4
|
+
export type RouterViewController = {
|
|
5
|
+
back(): void;
|
|
6
|
+
isBusy(): boolean;
|
|
7
|
+
};
|
|
8
|
+
export type RouterViewProps<R, TTree extends AnyRoute = AnyRoute> = {
|
|
9
|
+
router: Router<R, TTree>;
|
|
10
|
+
renderRoute?(route: R): ReactNode;
|
|
11
|
+
controllerRef?: MutableRefObject<RouterViewController | null>;
|
|
12
|
+
onExit?(): void;
|
|
13
|
+
canSwipeBack?(route: R): boolean;
|
|
14
|
+
sceneClassName?(route: R): string;
|
|
15
|
+
viewportWidth?: number;
|
|
16
|
+
platform?: string;
|
|
17
|
+
systemGestureInsetLeft?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function shouldFinishBack(distance: number, width: number, velocity: number): boolean;
|
|
20
|
+
/** Retains covered pages and unmounts only entries actually removed from the stack. */
|
|
21
|
+
export declare function RouterView<R, TTree extends AnyRoute = AnyRoute>({ router, renderRoute, controllerRef, onExit, canSwipeBack, sceneClassName, viewportWidth, platform, systemGestureInsetLeft }: RouterViewProps<R, TTree>): import("@lynx-js/react").JSX.Element;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { RouterProvider, RouteContext, MatchContext, RouteScreen, useRouterSnapshot } from "./hooks.jsx";
|
|
3
|
+
import './router.css';
|
|
4
|
+
export function shouldFinishBack(distance, width, velocity) {
|
|
5
|
+
return distance >= width * 0.35 || (distance >= 24 && velocity >= 0.55);
|
|
6
|
+
}
|
|
7
|
+
/** Retains covered pages and unmounts only entries actually removed from the stack. */
|
|
8
|
+
export function RouterView({ router, renderRoute, controllerRef, onExit, canSwipeBack = () => true, sceneClassName = () => '', viewportWidth = 375, platform, systemGestureInsetLeft = 0 }) {
|
|
9
|
+
const snapshot = useRouterSnapshot(router);
|
|
10
|
+
const entries = snapshot.entries;
|
|
11
|
+
const currentRoute = entries[entries.length - 1].route;
|
|
12
|
+
const timer = useRef(null);
|
|
13
|
+
const drag = useRef(null);
|
|
14
|
+
const settling = useRef(false);
|
|
15
|
+
const suppressAnimation = useRef(false);
|
|
16
|
+
const [swipe, setSwipe] = useState({ x: 0, settling: false, active: false });
|
|
17
|
+
const localController = useRef(null);
|
|
18
|
+
useImperativeHandle(controllerRef || localController, () => ({
|
|
19
|
+
back() {
|
|
20
|
+
'background only';
|
|
21
|
+
if (settling.current || drag.current?.locked)
|
|
22
|
+
return;
|
|
23
|
+
if (router.routes.length <= 1)
|
|
24
|
+
onExit?.();
|
|
25
|
+
else
|
|
26
|
+
void router.back();
|
|
27
|
+
},
|
|
28
|
+
isBusy() {
|
|
29
|
+
'background only';
|
|
30
|
+
return settling.current || Boolean(drag.current?.locked);
|
|
31
|
+
},
|
|
32
|
+
}), [router, onExit]);
|
|
33
|
+
useEffect(() => () => { if (timer.current)
|
|
34
|
+
clearTimeout(timer.current); }, []);
|
|
35
|
+
const width = viewportWidth || 375;
|
|
36
|
+
const insetGesture = platform !== 'iOS' && platform !== 'ios';
|
|
37
|
+
const gestureLeft = insetGesture ? Math.max(40, systemGestureInsetLeft + 16) : 0;
|
|
38
|
+
const gestureWidth = insetGesture ? 32 : 24;
|
|
39
|
+
const finishSwipe = (complete) => {
|
|
40
|
+
'background only';
|
|
41
|
+
if (!drag.current?.locked) {
|
|
42
|
+
drag.current = null;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
drag.current = null;
|
|
46
|
+
settling.current = true;
|
|
47
|
+
setSwipe({ x: complete ? width : 0, settling: true, active: true });
|
|
48
|
+
timer.current = setTimeout(() => {
|
|
49
|
+
if (complete) {
|
|
50
|
+
suppressAnimation.current = true;
|
|
51
|
+
void router.back().finally(() => { suppressAnimation.current = false; });
|
|
52
|
+
}
|
|
53
|
+
if (!complete)
|
|
54
|
+
suppressAnimation.current = false;
|
|
55
|
+
settling.current = false;
|
|
56
|
+
setSwipe({ x: 0, settling: false, active: false });
|
|
57
|
+
timer.current = null;
|
|
58
|
+
}, 240);
|
|
59
|
+
};
|
|
60
|
+
const startSwipe = (event) => {
|
|
61
|
+
'background only';
|
|
62
|
+
if (entries.length < 2 || settling.current)
|
|
63
|
+
return;
|
|
64
|
+
const point = event.touches[0];
|
|
65
|
+
if (!point || event.touches.length !== 1 || point.clientX < gestureLeft || point.clientX > gestureLeft + gestureWidth)
|
|
66
|
+
return;
|
|
67
|
+
if (!canSwipeBack(currentRoute))
|
|
68
|
+
return;
|
|
69
|
+
drag.current = { x: point.clientX, y: point.clientY, lastX: point.clientX, lastTime: Date.now(), velocity: 0, locked: false };
|
|
70
|
+
};
|
|
71
|
+
const moveSwipe = (event) => {
|
|
72
|
+
'background only';
|
|
73
|
+
const state = drag.current;
|
|
74
|
+
if (!state)
|
|
75
|
+
return;
|
|
76
|
+
if (event.touches.length !== 1) {
|
|
77
|
+
finishSwipe(false);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const point = event.touches[0];
|
|
81
|
+
const dx = point.clientX - state.x;
|
|
82
|
+
const dy = point.clientY - state.y;
|
|
83
|
+
if (!state.locked) {
|
|
84
|
+
if (Math.abs(dy) > 8 && Math.abs(dy) >= Math.abs(dx) || dx < -8) {
|
|
85
|
+
drag.current = null;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (dx < 8 || dx <= Math.abs(dy))
|
|
89
|
+
return;
|
|
90
|
+
state.locked = true;
|
|
91
|
+
suppressAnimation.current = true;
|
|
92
|
+
}
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
state.velocity = (point.clientX - state.lastX) / Math.max(1, now - state.lastTime);
|
|
95
|
+
state.lastX = point.clientX;
|
|
96
|
+
state.lastTime = now;
|
|
97
|
+
setSwipe({ x: Math.min(width, Math.max(0, dx)), settling: false, active: true });
|
|
98
|
+
};
|
|
99
|
+
const endSwipe = () => {
|
|
100
|
+
'background only';
|
|
101
|
+
const state = drag.current;
|
|
102
|
+
if (!state)
|
|
103
|
+
return;
|
|
104
|
+
const velocity = Date.now() - state.lastTime < 100 ? state.velocity : 0;
|
|
105
|
+
finishSwipe(shouldFinishBack(Math.max(0, state.lastX - state.x), width, velocity));
|
|
106
|
+
};
|
|
107
|
+
return <RouterProvider router={router}>
|
|
108
|
+
{entries.map((entry, index) => {
|
|
109
|
+
const top = index === entries.length - 1;
|
|
110
|
+
const previous = index === entries.length - 2;
|
|
111
|
+
const x = top ? swipe.x : previous && swipe.active ? -width * 0.25 + swipe.x * 0.25 : 0;
|
|
112
|
+
return <RouteContext.Provider key={entry.key} value={entry.route}>
|
|
113
|
+
<view className={`route-scene ${sceneClassName(entry.route)} ${top && !swipe.active && !suppressAnimation.current ? `route-${snapshot.direction}` : ''}`} style={{ visibility: top || previous && swipe.active ? 'visible' : 'hidden', transform: `translateX(${x}px)`, transitionProperty: 'transform', transitionDuration: swipe.settling ? '240ms' : '0ms', transitionTimingFunction: 'cubic-bezier(.22,1,.36,1)', zIndex: index }}>
|
|
114
|
+
<MatchContext.Provider value={entry.matches}>{renderRoute ? renderRoute(entry.route) : <RouteScreen />}</MatchContext.Provider>
|
|
115
|
+
</view>
|
|
116
|
+
</RouteContext.Provider>;
|
|
117
|
+
})}
|
|
118
|
+
{entries.length > 1 && canSwipeBack(currentRoute) ? <view className={`route-back-edge ${insetGesture ? 'route-back-inset' : ''}`} flatten={false} style={{ left: `${gestureLeft}px`, width: `${gestureWidth}px` }} bindtouchstart={startSwipe} bindtouchmove={moveSwipe} bindtouchend={endSwipe} bindtouchcancel={() => finishSwipe(false)}/> : null}
|
|
119
|
+
</RouterProvider>;
|
|
120
|
+
}
|