pxd 0.1.2 → 0.1.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/dist/components/_internal/calendar-day.vue +19 -19
- package/dist/components/_internal/dismiss-container.d.vue.ts +1 -1
- package/dist/components/_internal/dismiss-container.vue +19 -19
- package/dist/components/_internal/loading-mask.vue +9 -1
- package/dist/components/_internal/mention-editor.d.vue.ts +1 -1
- package/dist/components/_internal/mention-editor.vue +1 -1
- package/dist/components/_internal/popover-arrow.d.vue.ts +1 -1
- package/dist/components/_internal/popover-arrow.vue +1 -1
- package/dist/components/{steps → _internal}/step-item.d.vue.ts +1 -1
- package/dist/components/{steps → _internal}/step-item.vue +1 -1
- package/dist/components/_internal/tree-node.d.vue.ts +20 -20
- package/dist/components/_internal/tree-node.vue +53 -45
- package/dist/components/active-graph/index.d.vue.ts +2 -2
- package/dist/components/approval-card/index.d.vue.ts +1 -1
- package/dist/components/approval-card/index.vue +34 -17
- package/dist/components/approval-card/types.d.ts +1 -1
- package/dist/components/avatar/index.d.vue.ts +2 -2
- package/dist/components/avatar/index.vue +1 -1
- package/dist/components/backtop/index.d.vue.ts +3 -3
- package/dist/components/backtop/index.vue +17 -17
- package/dist/components/backtop/types.d.ts +1 -1
- package/dist/components/badge/index.d.vue.ts +3 -3
- package/dist/components/badge/index.vue +43 -43
- package/dist/components/badge/types.d.ts +1 -1
- package/dist/components/book/types.d.ts +1 -1
- package/dist/components/border-beam/index.vue +1 -1
- package/dist/components/border-beam/types.d.ts +1 -1
- package/dist/components/bubble/index.vue +1 -1
- package/dist/components/bubble-group/index.d.vue.ts +4 -4
- package/dist/components/button/index.d.vue.ts +5 -5
- package/dist/components/button/index.vue +13 -13
- package/dist/components/button/types.d.ts +1 -1
- package/dist/components/button-group/types.d.ts +1 -1
- package/dist/components/calendar/index.d.vue.ts +2 -2
- package/dist/components/calendar/index.vue +5 -5
- package/dist/components/calendar/types.d.ts +1 -1
- package/dist/components/card/types.d.ts +1 -1
- package/dist/components/carousel/index.d.vue.ts +7 -7
- package/dist/components/carousel/index.vue +1 -1
- package/dist/components/carousel/types.d.ts +1 -1
- package/dist/components/checkbox/index.vue +1 -1
- package/dist/components/checkbox/types.d.ts +1 -1
- package/dist/components/checkbox-group/index.d.vue.ts +2 -2
- package/dist/components/checkbox-group/types.d.ts +1 -1
- package/dist/components/chip/index.d.vue.ts +1 -1
- package/dist/components/chip/types.d.ts +1 -1
- package/dist/components/choicebox/index.d.vue.ts +3 -3
- package/dist/components/choicebox/types.d.ts +1 -1
- package/dist/components/choicebox-item/index.vue +8 -8
- package/dist/components/choicebox-item/types.d.ts +1 -1
- package/dist/components/collapse/index.vue +2 -2
- package/dist/components/collapse-group/index.vue +1 -1
- package/dist/components/collapse-group/types.d.ts +1 -1
- package/dist/components/command-menu/index.d.vue.ts +5 -5
- package/dist/components/command-menu/index.vue +10 -3
- package/dist/components/config-provider/index.d.vue.ts +40 -5
- package/dist/components/config-provider/types.d.ts +2 -1
- package/dist/components/confirm-popover/index.d.vue.ts +39 -0
- package/dist/components/confirm-popover/index.vue +177 -0
- package/dist/components/confirm-popover/types.d.ts +23 -0
- package/dist/components/copy-button/index.d.vue.ts +2 -6
- package/dist/components/copy-button/index.vue +4 -6
- package/dist/components/dash-line/index.d.vue.ts +1 -1
- package/dist/components/dash-line/index.vue +8 -8
- package/dist/components/dash-line/types.d.ts +1 -1
- package/dist/components/date-picker/index.d.vue.ts +1 -1
- package/dist/components/date-picker/index.vue +3 -3
- package/dist/components/date-picker/types.d.ts +1 -1
- package/dist/components/drawer/index.d.vue.ts +7 -7
- package/dist/components/drawer/index.vue +30 -15
- package/dist/components/drawer/types.d.ts +2 -2
- package/dist/components/effort-slider/index.vue +12 -18
- package/dist/components/effort-slider/types.d.ts +1 -1
- package/dist/components/ellipsis-text/index.d.vue.ts +2 -2
- package/dist/components/ellipsis-text/index.vue +75 -75
- package/dist/components/error/types.d.ts +1 -1
- package/dist/components/fader/index.vue +2 -2
- package/dist/components/fader/types.d.ts +1 -1
- package/dist/components/gauge/index.vue +2 -2
- package/dist/components/gauge/types.d.ts +1 -1
- package/dist/components/grid/types.d.ts +1 -1
- package/dist/components/grid-item/types.d.ts +1 -1
- package/dist/components/hint/index.d.vue.ts +32 -0
- package/dist/components/hint/index.vue +239 -0
- package/dist/components/hint/types.d.ts +17 -0
- package/dist/components/hold-button/index.d.vue.ts +4 -4
- package/dist/components/hold-button/index.vue +10 -10
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +4 -0
- package/dist/components/input/index.d.vue.ts +1 -1
- package/dist/components/input/index.vue +14 -7
- package/dist/components/input/types.d.ts +1 -1
- package/dist/components/intersection-observer/index.vue +3 -3
- package/dist/components/kbd/index.vue +2 -2
- package/dist/components/kbd/types.d.ts +1 -1
- package/dist/components/link-button/index.d.vue.ts +5 -5
- package/dist/components/list/index.d.vue.ts +4 -4
- package/dist/components/list/index.vue +126 -47
- package/dist/components/list/types.d.ts +1 -1
- package/dist/components/list-group/types.d.ts +1 -1
- package/dist/components/list-item/index.d.vue.ts +2 -2
- package/dist/components/list-item/index.vue +26 -8
- package/dist/components/loading-bar/index.vue +5 -5
- package/dist/components/marching-ants/index.d.vue.ts +2 -2
- package/dist/components/marching-ants/index.vue +56 -56
- package/dist/components/marching-ants/types.d.ts +1 -1
- package/dist/components/marquee/index.d.vue.ts +6 -6
- package/dist/components/marquee/index.vue +16 -16
- package/dist/components/marquee/types.d.ts +1 -1
- package/dist/components/material/index.d.vue.ts +3 -3
- package/dist/components/mention/index.d.vue.ts +5 -5
- package/dist/components/mention/index.vue +68 -68
- package/dist/components/menu/index.d.vue.ts +4 -4
- package/dist/components/menu/index.vue +10 -10
- package/dist/components/menu/types.d.ts +1 -1
- package/dist/components/message/index.d.vue.ts +1 -1
- package/dist/components/message/index.vue +19 -25
- package/dist/components/message/types.d.ts +1 -1
- package/dist/components/message-item/index.vue +2 -6
- package/dist/components/modal/index.d.vue.ts +7 -7
- package/dist/components/modal/index.vue +26 -11
- package/dist/components/modal/types.d.ts +2 -2
- package/dist/components/noise-background/types.d.ts +1 -1
- package/dist/components/note/index.vue +6 -2
- package/dist/components/note/types.d.ts +2 -1
- package/dist/components/number-input/index.d.vue.ts +11 -6
- package/dist/components/number-input/index.vue +57 -16
- package/dist/components/number-input/types.d.ts +2 -1
- package/dist/components/overlay/index.d.vue.ts +2 -3
- package/dist/components/overlay/index.vue +10 -62
- package/dist/components/overlay/types.d.ts +0 -2
- package/dist/components/page-number/index.vue +30 -29
- package/dist/components/page-number/types.d.ts +1 -1
- package/dist/components/pin-input/index.d.vue.ts +1 -1
- package/dist/components/pin-input/index.vue +6 -6
- package/dist/components/pin-input/types.d.ts +1 -1
- package/dist/components/popover/index.vue +49 -21
- package/dist/components/popover/types.d.ts +3 -1
- package/dist/components/progress/index.d.vue.ts +2 -2
- package/dist/components/progress/index.vue +12 -12
- package/dist/components/progress/types.d.ts +1 -1
- package/dist/components/project-banner/types.d.ts +1 -1
- package/dist/components/questionnaire/index.vue +14 -14
- package/dist/components/radio/index.vue +1 -1
- package/dist/components/radio/types.d.ts +1 -1
- package/dist/components/radio-group/index.d.vue.ts +2 -2
- package/dist/components/radio-group/types.d.ts +1 -1
- package/dist/components/rating/index.vue +28 -28
- package/dist/components/rating/types.d.ts +1 -1
- package/dist/components/resizable/index.d.vue.ts +1 -0
- package/dist/components/resizable/index.vue +130 -195
- package/dist/components/resizable/types.d.ts +2 -10
- package/dist/components/reveal/index.d.vue.ts +3 -3
- package/dist/components/reveal/index.vue +4 -4
- package/dist/components/reveal/types.d.ts +1 -1
- package/dist/components/rolling-number/index.d.vue.ts +2 -2
- package/dist/components/rolling-number/index.vue +15 -15
- package/dist/components/scalable-text/index.vue +9 -9
- package/dist/components/scroll-text/index.d.vue.ts +3 -3
- package/dist/components/scroll-text/index.vue +6 -6
- package/dist/components/scroll-text/types.d.ts +1 -1
- package/dist/components/scrollable/types.d.ts +2 -1
- package/dist/components/search-input/index.d.vue.ts +5 -5
- package/dist/components/search-input/index.vue +2 -1
- package/dist/components/select/index.d.vue.ts +12 -9
- package/dist/components/select/index.vue +165 -42
- package/dist/components/select/types.d.ts +3 -1
- package/dist/components/separator/index.d.vue.ts +1 -1
- package/dist/components/separator/types.d.ts +1 -1
- package/dist/components/skeleton/index.d.vue.ts +1 -1
- package/dist/components/skeleton/index.vue +11 -11
- package/dist/components/skeleton/types.d.ts +1 -1
- package/dist/components/slider/index.d.vue.ts +1 -1
- package/dist/components/slider/index.vue +1 -1
- package/dist/components/slider/types.d.ts +1 -1
- package/dist/components/snippet/index.d.vue.ts +3 -3
- package/dist/components/snippet/index.vue +7 -5
- package/dist/components/snippet/types.d.ts +1 -1
- package/dist/components/spinner/index.vue +5 -1
- package/dist/components/spinner-dots/index.d.vue.ts +1 -1
- package/dist/components/split-button/index.d.vue.ts +5 -5
- package/dist/components/split-button/types.d.ts +1 -1
- package/dist/components/stack/index.d.vue.ts +3 -3
- package/dist/components/stack/index.vue +28 -29
- package/dist/components/stack/types.d.ts +1 -1
- package/dist/components/status-dot/types.d.ts +1 -1
- package/dist/components/steps/index.d.vue.ts +2 -2
- package/dist/components/steps/index.vue +6 -6
- package/dist/components/steps/types.d.ts +1 -1
- package/dist/components/stick-to-bottom/types.d.ts +1 -1
- package/dist/components/swipe-cell/index.d.vue.ts +6 -6
- package/dist/components/swipe-cell/index.vue +64 -64
- package/dist/components/swipe-cell/types.d.ts +2 -1
- package/dist/components/switch/index.vue +1 -1
- package/dist/components/switch/types.d.ts +1 -1
- package/dist/components/switch-item/index.vue +1 -1
- package/dist/components/switch-item/types.d.ts +1 -1
- package/dist/components/tabs/index.d.vue.ts +1 -1
- package/dist/components/tabs/index.vue +48 -51
- package/dist/components/tabs/types.d.ts +1 -1
- package/dist/components/teleport/index.vue +2 -2
- package/dist/components/text/index.d.vue.ts +3 -3
- package/dist/components/text/index.vue +11 -11
- package/dist/components/text/types.d.ts +1 -1
- package/dist/components/textarea/index.vue +1 -1
- package/dist/components/textarea/types.d.ts +1 -1
- package/dist/components/theme-switcher/index.d.vue.ts +3 -2
- package/dist/components/theme-switcher/index.vue +15 -7
- package/dist/components/theme-switcher/types.d.ts +2 -2
- package/dist/components/time-ago/index.d.vue.ts +6 -0
- package/dist/components/time-ago/index.vue +143 -0
- package/dist/components/time-ago/types.d.ts +4 -0
- package/dist/components/time-picker/index.d.vue.ts +1 -1
- package/dist/components/time-picker/index.vue +7 -7
- package/dist/components/time-picker/types.d.ts +1 -1
- package/dist/components/toc/index.d.vue.ts +2 -2
- package/dist/components/toc/index.vue +1 -1
- package/dist/components/todo-list/index.d.vue.ts +4 -4
- package/dist/components/todo-list/index.vue +15 -15
- package/dist/components/todo-list/types.d.ts +1 -1
- package/dist/components/toggle/index.vue +3 -3
- package/dist/components/toggle/types.d.ts +1 -1
- package/dist/components/toggle-button/index.vue +14 -11
- package/dist/components/toggle-button/types.d.ts +2 -2
- package/dist/components/toggle-button-group/index.d.vue.ts +3 -3
- package/dist/components/toggle-button-group/index.vue +2 -2
- package/dist/components/toggle-button-group/types.d.ts +2 -2
- package/dist/components/tool-call/index.vue +5 -5
- package/dist/components/tooltip/index.d.vue.ts +4 -5
- package/dist/components/tooltip/index.vue +4 -49
- package/dist/components/tooltip/types.d.ts +3 -7
- package/dist/components/tour/index.d.vue.ts +33 -0
- package/dist/components/tour/index.vue +302 -0
- package/dist/components/tour/types.d.ts +29 -0
- package/dist/components/tree/index.d.vue.ts +24 -28
- package/dist/components/tree/index.vue +290 -223
- package/dist/components/tree/types.d.ts +38 -13
- package/dist/components/virtual-list/index.d.vue.ts +4 -4
- package/dist/composables/_internal/use-list-keyboard-controller.js +9 -10
- package/dist/composables/_internal/use-list-rows.d.ts +4 -0
- package/dist/composables/_internal/use-list-rows.js +12 -4
- package/dist/composables/_internal/use-list-selection.d.ts +1 -1
- package/dist/composables/_internal/use-lock-scroll.d.ts +8 -1
- package/dist/composables/_internal/use-lock-scroll.js +57 -36
- package/dist/composables/_internal/use-mention-editor.js +1 -1
- package/dist/composables/_internal/use-message-group.d.ts +22 -0
- package/dist/composables/_internal/use-message-group.js +143 -0
- package/dist/composables/_internal/use-overlay-dialog.js +1 -3
- package/dist/composables/_internal/use-overlay-manager.d.ts +4 -1
- package/dist/composables/_internal/use-overlay-manager.js +67 -8
- package/dist/composables/_internal/use-swipe-gesture.d.ts +1 -1
- package/dist/composables/_internal/use-tour-target.d.ts +29 -0
- package/dist/composables/_internal/use-tour-target.js +201 -0
- package/dist/composables/_internal/use-tree.d.ts +103 -0
- package/dist/composables/_internal/use-tree.js +676 -0
- package/dist/composables/_internal/use-word-limit.d.ts +1 -1
- package/dist/composables/index.d.ts +1 -0
- package/dist/composables/index.js +1 -0
- package/dist/composables/use-color-scheme.d.ts +1 -1
- package/dist/composables/use-color-scheme.js +7 -6
- package/dist/composables/use-delay-destroy.d.ts +1 -1
- package/dist/composables/use-document-hidden.d.ts +1 -1
- package/dist/composables/use-intersection-observer.d.ts +1 -1
- package/dist/composables/use-intersection-observer.js +1 -1
- package/dist/composables/{_internal/use-motion-reduce.js → use-motion-reduce.js} +2 -2
- package/dist/composables/use-mutation-observer.d.ts +1 -1
- package/dist/composables/use-mutation-observer.js +1 -1
- package/dist/composables/use-resize-observer.d.ts +1 -1
- package/dist/composables/use-resize-observer.js +1 -1
- package/dist/composables/use-view-transition.js +1 -0
- package/dist/composables/use-virtual-list.d.ts +1 -1
- package/dist/constants/tooltip-variants.d.ts +28 -0
- package/dist/constants/tooltip-variants.js +27 -0
- package/dist/contexts/avatar.js +1 -1
- package/dist/contexts/breadcrumb.js +1 -1
- package/dist/contexts/button.js +1 -1
- package/dist/contexts/checkbox.js +1 -1
- package/dist/contexts/choicebox.js +1 -1
- package/dist/contexts/collapse.js +1 -1
- package/dist/contexts/config-provider.js +1 -1
- package/dist/contexts/list.js +1 -1
- package/dist/contexts/radio.js +1 -1
- package/dist/contexts/switch.js +1 -1
- package/dist/contexts/toggle-button.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/locales/en-us.d.ts +35 -0
- package/dist/locales/en-us.js +20 -0
- package/dist/locales/zh-cn.d.ts +35 -0
- package/dist/locales/zh-cn.js +20 -0
- package/dist/styles/styles.css +1 -1
- package/dist/styles/tw.css +43 -30
- package/dist/utils/{context.js → _internal/context.js} +1 -1
- package/dist/utils/{observer.d.ts → _internal/observer.d.ts} +1 -1
- package/dist/utils/{observer.js → _internal/observer.js} +4 -4
- package/dist/{components/swipe-cell/instances.d.ts → utils/_internal/swipe-cell-instances.d.ts} +1 -1
- package/dist/utils/event.d.ts +2 -1
- package/dist/utils/event.js +3 -0
- package/package.json +26 -50
- package/volar.d.ts +4 -0
- package/dist/components/message/composables/use-group-expand.d.ts +0 -13
- package/dist/components/message/composables/use-group-expand.js +0 -50
- package/dist/components/message/composables/use-message-timer.d.ts +0 -9
- package/dist/components/message/composables/use-message-timer.js +0 -62
- package/dist/components/message/composables/use-promise-message.d.ts +0 -4
- package/dist/components/message/composables/use-promise-message.js +0 -49
- package/dist/components/resizable/utils.d.ts +0 -4
- package/dist/components/resizable/utils.js +0 -10
- package/dist/composables/_internal/use-tree-drag.d.ts +0 -23
- package/dist/composables/_internal/use-tree-drag.js +0 -196
- package/dist/composables/_internal/use-tree-move.d.ts +0 -20
- package/dist/composables/_internal/use-tree-move.js +0 -96
- package/dist/composables/_internal/use-tree-rows.d.ts +0 -46
- package/dist/composables/_internal/use-tree-rows.js +0 -101
- package/dist/composables/_internal/use-tree-selection.d.ts +0 -22
- package/dist/composables/_internal/use-tree-selection.js +0 -87
- package/dist/styles/source.css +0 -675
- package/dist/types/shared/index.d.ts +0 -2
- /package/dist/composables/{_internal/use-motion-reduce.d.ts → use-motion-reduce.d.ts} +0 -0
- /package/dist/utils/{context.d.ts → _internal/context.d.ts} +0 -0
- /package/dist/utils/{mention-html.d.ts → _internal/mention-html.d.ts} +0 -0
- /package/dist/utils/{mention-html.js → _internal/mention-html.js} +0 -0
- /package/dist/{components/swipe-cell/instances.js → utils/_internal/swipe-cell-instances.js} +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { computed, shallowRef, watch } from "vue";
|
|
2
|
+
import { computed, onMounted, shallowRef, watch } from "vue";
|
|
3
3
|
import { useModelValue } from "../../composables/_internal/use-model-value.js";
|
|
4
|
+
import { useResizeObserver } from "../../composables/use-resize-observer.js";
|
|
4
5
|
import { throttleByRaf } from "../../utils/event.js";
|
|
6
|
+
import { clampValue } from "../../utils/format.js";
|
|
5
7
|
import { getUniqueId } from "../../utils/helper.js";
|
|
6
8
|
import { isNil } from "../../utils/is.js";
|
|
7
|
-
import { clamp, PERCENT_TOTAL, roundSize, toPair } from "./utils";
|
|
8
9
|
defineOptions({
|
|
9
10
|
name: "PResizable",
|
|
10
11
|
inheritAttrs: false,
|
|
@@ -19,6 +20,11 @@ const props = defineProps({
|
|
|
19
20
|
required: false,
|
|
20
21
|
default: "horizontal"
|
|
21
22
|
},
|
|
23
|
+
unit: {
|
|
24
|
+
type: String,
|
|
25
|
+
required: false,
|
|
26
|
+
default: "percent"
|
|
27
|
+
},
|
|
22
28
|
minSize: {
|
|
23
29
|
type: Array,
|
|
24
30
|
required: false,
|
|
@@ -50,93 +56,115 @@ const emits = defineEmits([
|
|
|
50
56
|
"reset",
|
|
51
57
|
"update:modelValue"
|
|
52
58
|
]);
|
|
59
|
+
const PERCENT_TOTAL = 100;
|
|
60
|
+
const KEYBOARD_STEP = 1;
|
|
61
|
+
const KEYBOARD_STEP_LARGE = 10;
|
|
53
62
|
const uid = getUniqueId("pxd-resizable");
|
|
63
|
+
const leadingId = `${uid}-leading`;
|
|
64
|
+
const trailingId = `${uid}-trailing`;
|
|
65
|
+
const initialSizes = toPair(isNil(props.modelValue) ? props.defaultValue : props.modelValue);
|
|
66
|
+
let drag = null;
|
|
67
|
+
const flushResize = throttleByRaf(applyPendingDelta);
|
|
54
68
|
const containerRef = shallowRef();
|
|
55
69
|
const handleRef = shallowRef();
|
|
56
|
-
const
|
|
70
|
+
const containerSize = shallowRef(0);
|
|
57
71
|
const isControlled = computed(() => !isNil(props.modelValue));
|
|
72
|
+
const isPixel = computed(() => props.unit === "px");
|
|
58
73
|
const innerSizes = shallowRef(toPair(props.defaultValue));
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
/** Percent sizes are measured against 100; pixel sizes fill the measured container. */
|
|
75
|
+
const totalSize = computed(() => isPixel.value ? containerSize.value : PERCENT_TOTAL);
|
|
76
|
+
/** Only the leading size of a pixel group comes from the caller. */
|
|
77
|
+
const sizes = computed(() => {
|
|
78
|
+
const source = toPair(isControlled.value ? props.modelValue : innerSizes.value);
|
|
79
|
+
const leading = source[0];
|
|
80
|
+
return isPixel.value ? [leading, Math.max(totalSize.value - leading, 0)] : source;
|
|
81
|
+
});
|
|
82
|
+
/** The pair the panel slots are handed, updated only when a change settles. */
|
|
83
|
+
const settledSizes = shallowRef(sizes.value);
|
|
84
|
+
const restoreSizes = shallowRef(null);
|
|
85
|
+
const collapsed = computed(() => restoreSizes.value !== null);
|
|
86
|
+
const unitSuffix = computed(() => isPixel.value ? "px" : "%");
|
|
65
87
|
const bounds = computed(() => {
|
|
66
88
|
const [leading, trailing] = toPair(props.minSize);
|
|
67
|
-
|
|
89
|
+
const total = totalSize.value;
|
|
90
|
+
if (total <= 0) {
|
|
91
|
+
return {
|
|
92
|
+
min: sizes.value[0],
|
|
93
|
+
max: sizes.value[0]
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (leading + trailing > total) {
|
|
68
97
|
return {
|
|
69
98
|
min: 0,
|
|
70
|
-
max:
|
|
99
|
+
max: total
|
|
71
100
|
};
|
|
72
101
|
}
|
|
73
102
|
return {
|
|
74
103
|
min: leading,
|
|
75
|
-
max:
|
|
104
|
+
max: total - trailing
|
|
76
105
|
};
|
|
77
106
|
});
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const rounded = [roundSize(next[0]), roundSize(next[1])];
|
|
94
|
-
if (rounded[0] === current[0] && rounded[1] === current[1]) {
|
|
107
|
+
const ariaValueNow = computed(() => roundSize(sizes.value[0]));
|
|
108
|
+
const ariaValueText = computed(() => `${ariaValueNow.value}${unitSuffix.value}${collapsed.value ? ", folded" : ""}`);
|
|
109
|
+
const modelValue = useModelValue(props, emits, { withChange: false });
|
|
110
|
+
useResizeObserver(containerRef, syncContainerSize);
|
|
111
|
+
function roundSize(value) {
|
|
112
|
+
return Math.round(value * 100) / 100;
|
|
113
|
+
}
|
|
114
|
+
function toPair(value) {
|
|
115
|
+
return [value?.[0] ?? 0, value?.[1] ?? 0];
|
|
116
|
+
}
|
|
117
|
+
function setSizes([leading, trailing]) {
|
|
118
|
+
const [currentLeading, currentTrailing] = sizes.value;
|
|
119
|
+
const nextLeading = roundSize(leading);
|
|
120
|
+
const next = isPixel.value ? [nextLeading, roundSize(Math.max(totalSize.value - nextLeading, 0))] : [nextLeading, roundSize(trailing)];
|
|
121
|
+
if (next[0] === currentLeading && next[1] === currentTrailing) {
|
|
95
122
|
return false;
|
|
96
123
|
}
|
|
97
124
|
if (!isControlled.value) {
|
|
98
|
-
innerSizes.value =
|
|
125
|
+
innerSizes.value = next;
|
|
99
126
|
}
|
|
100
|
-
modelValue.value =
|
|
127
|
+
modelValue.value = next;
|
|
101
128
|
return true;
|
|
102
129
|
}
|
|
103
|
-
function
|
|
130
|
+
function applyDelta(delta) {
|
|
104
131
|
const [leading, trailing] = sizes.value;
|
|
105
132
|
const { min, max } = bounds.value;
|
|
106
|
-
|
|
107
|
-
// hand the trailing panel the same delta so the pair keeps summing to 100%.
|
|
108
|
-
const applied = clamp(deltaPercent, min - leading, max - leading);
|
|
133
|
+
const applied = clampValue(delta, min - leading, max - leading);
|
|
109
134
|
if (applied === 0) {
|
|
110
135
|
return false;
|
|
111
136
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Moving the divider brings a folded pair back, so a collapsed panel is never a
|
|
119
|
-
* dead end. The remembered sizes go with it: they described a pair that no
|
|
120
|
-
* longer exists once it has been moved somewhere else.
|
|
121
|
-
*/
|
|
122
|
-
function applyDelta(deltaPercent) {
|
|
123
|
-
const changed = resize(deltaPercent);
|
|
124
|
-
if (changed && collapsed.value) {
|
|
125
|
-
collapsed.value = false;
|
|
126
|
-
expandedPair = null;
|
|
137
|
+
const nextLeading = roundSize(leading + applied);
|
|
138
|
+
const changed = setSizes([nextLeading, roundSize(leading + trailing - nextLeading)]);
|
|
139
|
+
if (changed) {
|
|
140
|
+
restoreSizes.value = null;
|
|
127
141
|
}
|
|
128
142
|
return changed;
|
|
129
143
|
}
|
|
130
|
-
function
|
|
144
|
+
function syncContainerSize() {
|
|
131
145
|
const container = containerRef.value;
|
|
132
146
|
if (!container) {
|
|
133
|
-
|
|
147
|
+
containerSize.value = 0;
|
|
148
|
+
return;
|
|
134
149
|
}
|
|
135
|
-
|
|
136
|
-
|
|
150
|
+
containerSize.value = props.direction === "horizontal" ? container.offsetWidth : container.offsetHeight;
|
|
151
|
+
}
|
|
152
|
+
function applyPendingDelta() {
|
|
153
|
+
if (!drag || drag.delta === 0) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const delta = drag.delta;
|
|
157
|
+
drag.delta = 0;
|
|
158
|
+
drag.resized = applyPointerDelta(delta) || drag.resized;
|
|
159
|
+
}
|
|
160
|
+
function applyPointerDelta(delta) {
|
|
161
|
+
if (isPixel.value) {
|
|
162
|
+
return applyDelta(delta);
|
|
163
|
+
}
|
|
164
|
+
if (containerSize.value <= 0) {
|
|
137
165
|
return false;
|
|
138
166
|
}
|
|
139
|
-
return applyDelta(delta / containerSize * PERCENT_TOTAL);
|
|
167
|
+
return applyDelta(delta / containerSize.value * PERCENT_TOTAL);
|
|
140
168
|
}
|
|
141
169
|
function commitChange() {
|
|
142
170
|
emits("change", sizes.value.slice());
|
|
@@ -145,121 +173,91 @@ function toggleCollapse() {
|
|
|
145
173
|
if (props.disabled) {
|
|
146
174
|
return;
|
|
147
175
|
}
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
collapsed.value = false;
|
|
153
|
-
if (setSizes([restore[0], restore[1]])) {
|
|
176
|
+
const restore = restoreSizes.value;
|
|
177
|
+
if (restore) {
|
|
178
|
+
restoreSizes.value = null;
|
|
179
|
+
if (setSizes(restore)) {
|
|
154
180
|
commitChange();
|
|
155
181
|
}
|
|
156
182
|
return;
|
|
157
183
|
}
|
|
158
|
-
|
|
159
|
-
collapsed.value = true;
|
|
184
|
+
restoreSizes.value = [sizes.value[0], sizes.value[1]];
|
|
160
185
|
const { min } = bounds.value;
|
|
161
|
-
|
|
162
|
-
// summing to 100% while folded.
|
|
163
|
-
if (setSizes([min, PERCENT_TOTAL - min])) {
|
|
186
|
+
if (setSizes([min, totalSize.value - min])) {
|
|
164
187
|
commitChange();
|
|
165
188
|
}
|
|
166
189
|
}
|
|
167
190
|
function reset() {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
collapsed.value = false;
|
|
171
|
-
if (setSizes([restore[0], restore[1]])) {
|
|
191
|
+
restoreSizes.value = null;
|
|
192
|
+
if (setSizes(initialSizes)) {
|
|
172
193
|
emits("reset", sizes.value.slice());
|
|
173
194
|
}
|
|
174
195
|
}
|
|
175
|
-
let activePointerId = null;
|
|
176
|
-
let startPosition = 0;
|
|
177
|
-
let accumulated = 0;
|
|
178
|
-
let resized = false;
|
|
179
196
|
function axisOf(event) {
|
|
180
197
|
return props.direction === "horizontal" ? event.clientX : event.clientY;
|
|
181
198
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
190
|
-
// The capture target is the handle itself, never `event.target`: a child element
|
|
191
|
-
// can be swapped mid-drag, which would both throw on release and strand the drag.
|
|
192
|
-
// Holding the capture also keeps the drag alive when the pointer leaves the window.
|
|
193
|
-
function releaseCapture() {
|
|
194
|
-
const id = activePointerId;
|
|
195
|
-
const el = handleRef.value;
|
|
196
|
-
activePointerId = null;
|
|
197
|
-
if (!el || id === null) {
|
|
199
|
+
function resetDragging() {
|
|
200
|
+
const pointerId = drag?.pointerId;
|
|
201
|
+
const handle = handleRef.value;
|
|
202
|
+
flushResize.cancel();
|
|
203
|
+
drag = null;
|
|
204
|
+
settledSizes.value = sizes.value;
|
|
205
|
+
if (pointerId === undefined || !handle) {
|
|
198
206
|
return;
|
|
199
207
|
}
|
|
200
208
|
try {
|
|
201
|
-
|
|
209
|
+
handle.releasePointerCapture(pointerId);
|
|
202
210
|
} catch {}
|
|
203
211
|
}
|
|
204
|
-
function resetDragging() {
|
|
205
|
-
startPosition = 0;
|
|
206
|
-
accumulated = 0;
|
|
207
|
-
resized = false;
|
|
208
|
-
flushResize.cancel();
|
|
209
|
-
releaseCapture();
|
|
210
|
-
}
|
|
211
212
|
function handlePointerDown(event) {
|
|
212
213
|
if (props.disabled) {
|
|
213
214
|
return;
|
|
214
215
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
drag = {
|
|
217
|
+
pointerId: event.pointerId,
|
|
218
|
+
position: axisOf(event),
|
|
219
|
+
delta: 0,
|
|
220
|
+
resized: false
|
|
221
|
+
};
|
|
222
|
+
syncContainerSize();
|
|
219
223
|
try {
|
|
220
224
|
handleRef.value?.setPointerCapture(event.pointerId);
|
|
221
225
|
} catch {}
|
|
222
226
|
}
|
|
223
227
|
function handlePointerMove(event) {
|
|
224
|
-
if (event.pointerId !==
|
|
228
|
+
if (!drag || event.pointerId !== drag.pointerId) {
|
|
225
229
|
return;
|
|
226
230
|
}
|
|
227
231
|
event.preventDefault();
|
|
228
232
|
const position = axisOf(event);
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
drag.delta += position - drag.position;
|
|
234
|
+
drag.position = position;
|
|
231
235
|
flushResize();
|
|
232
236
|
}
|
|
233
237
|
function handlePointerUp(event) {
|
|
234
|
-
if (event.pointerId !==
|
|
238
|
+
if (!drag || event.pointerId !== drag.pointerId) {
|
|
235
239
|
return;
|
|
236
240
|
}
|
|
237
241
|
flushResize.cancel();
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
accumulated = 0;
|
|
241
|
-
resized = resizeByPixels(delta) || resized;
|
|
242
|
-
}
|
|
243
|
-
const didResize = resized;
|
|
242
|
+
applyPendingDelta();
|
|
243
|
+
const didResize = drag.resized;
|
|
244
244
|
resetDragging();
|
|
245
245
|
if (didResize) {
|
|
246
246
|
commitChange();
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
function handlePointerCancel(event) {
|
|
250
|
-
if (event.pointerId !==
|
|
250
|
+
if (!drag || event.pointerId !== drag.pointerId) {
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
253
253
|
resetDragging();
|
|
254
254
|
}
|
|
255
255
|
function handleLostCapture() {
|
|
256
|
-
if (
|
|
256
|
+
if (!drag) {
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
259
259
|
resetDragging();
|
|
260
260
|
}
|
|
261
|
-
const KEYBOARD_STEP = 1;
|
|
262
|
-
const KEYBOARD_STEP_LARGE = 10;
|
|
263
261
|
function handleKeydown(event) {
|
|
264
262
|
if (props.disabled) {
|
|
265
263
|
return;
|
|
@@ -272,9 +270,9 @@ function handleKeydown(event) {
|
|
|
272
270
|
} else if (event.key === (horizontal ? "ArrowRight" : "ArrowDown")) {
|
|
273
271
|
delta = step;
|
|
274
272
|
} else if (event.key === "Home") {
|
|
275
|
-
delta = bounds.value.min -
|
|
273
|
+
delta = bounds.value.min - sizes.value[0];
|
|
276
274
|
} else if (event.key === "End") {
|
|
277
|
-
delta = bounds.value.max -
|
|
275
|
+
delta = bounds.value.max - sizes.value[0];
|
|
278
276
|
}
|
|
279
277
|
if (delta === null) {
|
|
280
278
|
return;
|
|
@@ -284,75 +282,19 @@ function handleKeydown(event) {
|
|
|
284
282
|
commitChange();
|
|
285
283
|
}
|
|
286
284
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
warn(`${name} holds ${value.length} value${value.length === 1 ? "" : "s"} but the group has 2 panels; only the first two are used.`);
|
|
292
|
-
}
|
|
293
|
-
function warn(message) {
|
|
294
|
-
if (import.meta.env?.DEV) {
|
|
295
|
-
console.warn(`[pxd] PResizable: ${message}`);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
function warnSum(name, value) {
|
|
299
|
-
const total = roundSize(value[0] + value[1]);
|
|
300
|
-
if (Math.abs(total - PERCENT_TOTAL) > .01) {
|
|
301
|
-
warn(`${name} adds up to ${total}% instead of ${PERCENT_TOTAL}%; the panels keep the sizes they were given.`);
|
|
285
|
+
/** Only the leading panel of a pixel group gets a basis; the trailing one fills. */
|
|
286
|
+
function panelStyle(index) {
|
|
287
|
+
if (isPixel.value && index === 1) {
|
|
288
|
+
return {};
|
|
302
289
|
}
|
|
290
|
+
return { flexBasis: `${sizes.value[index]}${unitSuffix.value}` };
|
|
303
291
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
watch(() => [
|
|
308
|
-
props.modelValue,
|
|
309
|
-
props.minSize,
|
|
310
|
-
props.defaultValue
|
|
311
|
-
], () => {
|
|
312
|
-
if (!import.meta.env?.DEV) {
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
const mins = toPair(props.minSize);
|
|
316
|
-
if (props.minSize.length !== 2) {
|
|
317
|
-
warnLength("min-size", props.minSize);
|
|
318
|
-
}
|
|
319
|
-
if (!isPercent(mins[0]) || !isPercent(mins[1])) {
|
|
320
|
-
warn(`min-size values must be between 0 and ${PERCENT_TOTAL}, got [${mins.join(", ")}].`);
|
|
321
|
-
} else if (mins[0] + mins[1] > PERCENT_TOTAL) {
|
|
322
|
-
warn(`min-size [${mins.join(", ")}] adds up to more than ${PERCENT_TOTAL}%, so no split fits and the constraint is ignored.`);
|
|
323
|
-
}
|
|
324
|
-
for (const [name, value] of [["model-value", props.modelValue], ["default-value", props.defaultValue]]) {
|
|
325
|
-
if (isNil(value)) {
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
if (value.length !== 2) {
|
|
329
|
-
warnLength(name, value);
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
warnSum(name, [value[0], value[1]]);
|
|
333
|
-
}
|
|
334
|
-
const { min, max } = bounds.value;
|
|
335
|
-
const leading = sizes.value[0];
|
|
336
|
-
if (leading < min || leading > max) {
|
|
337
|
-
warn(`the leading panel sits at ${leading}%, outside its ${min}-${max}% range; it keeps that size until it is dragged.`);
|
|
292
|
+
watch(sizes, (value) => {
|
|
293
|
+
if (!drag) {
|
|
294
|
+
settledSizes.value = value;
|
|
338
295
|
}
|
|
339
|
-
}, {
|
|
340
|
-
immediate: true,
|
|
341
|
-
flush: "post"
|
|
342
296
|
});
|
|
343
|
-
|
|
344
|
-
const ariaValueNow = computed(() => roundSize(position.value));
|
|
345
|
-
// A bare number is announced as "30" - no unit, and nothing about the fold.
|
|
346
|
-
// valuetext is the only place a separator can put either, since it has no
|
|
347
|
-
// aria-expanded to lean on.
|
|
348
|
-
const ariaValueText = computed(() => collapsed.value ? `${ariaValueNow.value}%, folded` : `${ariaValueNow.value}%`);
|
|
349
|
-
function panelStyle(index) {
|
|
350
|
-
return {
|
|
351
|
-
flexBasis: `${sizes.value[index]}%`,
|
|
352
|
-
flexGrow: 0,
|
|
353
|
-
flexShrink: 1
|
|
354
|
-
};
|
|
355
|
-
}
|
|
297
|
+
onMounted(syncContainerSize);
|
|
356
298
|
defineExpose({
|
|
357
299
|
getPanelSizes: () => sizes.value.slice(),
|
|
358
300
|
reset
|
|
@@ -364,6 +306,7 @@ defineExpose({
|
|
|
364
306
|
data-resizable
|
|
365
307
|
ref="containerRef"
|
|
366
308
|
:data-orientation="direction"
|
|
309
|
+
:data-unit="unit"
|
|
367
310
|
class="pxd-resizable flex size-full max-w-full flex-row overflow-hidden data-[orientation=vertical]:flex-col"
|
|
368
311
|
v-bind="$attrs"
|
|
369
312
|
>
|
|
@@ -372,17 +315,9 @@ defineExpose({
|
|
|
372
315
|
class="pxd-resizable-panel min-w-0 min-h-0 overflow-hidden"
|
|
373
316
|
:style="panelStyle(0)"
|
|
374
317
|
>
|
|
375
|
-
<slot name="leading" :size="
|
|
318
|
+
<slot name="leading" :size="settledSizes[0]" />
|
|
376
319
|
</div>
|
|
377
320
|
|
|
378
|
-
<!--
|
|
379
|
-
A *focusable* separator is a widget, and only that flavour may carry
|
|
380
|
-
aria-valuenow / aria-valuemin / aria-valuemax - which is why it takes a
|
|
381
|
-
tabindex and the key handler below, not just a pointer drag. aria-expanded
|
|
382
|
-
is not a separator state at any focusability: it marks control over
|
|
383
|
-
visibility, and folding a panel never hides it. The fold therefore rides
|
|
384
|
-
on aria-valuetext.
|
|
385
|
-
-->
|
|
386
321
|
<div
|
|
387
322
|
ref="handleRef"
|
|
388
323
|
role="separator"
|
|
@@ -398,7 +333,7 @@ defineExpose({
|
|
|
398
333
|
:data-collapsed="collapsed || void 0"
|
|
399
334
|
:data-handler="handle"
|
|
400
335
|
:data-orientation="direction"
|
|
401
|
-
class="pxd-resizable-handle relative shrink-0 touch-none
|
|
336
|
+
class="pxd-resizable-handle relative shrink-0 touch-none self-focus-ring select-none aria-disabled:cursor-default after:motion-safe:transition-colors"
|
|
402
337
|
@pointerdown.prevent="handlePointerDown"
|
|
403
338
|
@pointermove="handlePointerMove"
|
|
404
339
|
@pointerup="handlePointerUp"
|
|
@@ -413,11 +348,11 @@ defineExpose({
|
|
|
413
348
|
class="pxd-resizable-panel min-w-0 min-h-0 overflow-hidden"
|
|
414
349
|
:style="panelStyle(1)"
|
|
415
350
|
>
|
|
416
|
-
<slot name="trailing" :size="
|
|
351
|
+
<slot name="trailing" :size="settledSizes[1]" />
|
|
417
352
|
</div>
|
|
418
353
|
</div>
|
|
419
354
|
</template>
|
|
420
355
|
|
|
421
356
|
<style>
|
|
422
|
-
.pxd-resizable-handle[data-handler=true]:before{background-color:var(--color-gray-300);border-radius:.5rem;content:"";left:50%;pointer-events:none;position:absolute;top:50%;transform:translate(-50%,-50%);z-index:1}.pxd-resizable-handle[data-collapsed=true]:before{opacity:.4}.pxd-resizable-handle:after{content:"";left:50%;padding:
|
|
357
|
+
.pxd-resizable-panel{flex-grow:0;flex-shrink:1}.pxd-resizable[data-unit=px] .pxd-resizable-panel:first-child{flex-shrink:0}.pxd-resizable[data-unit=px] .pxd-resizable-panel:last-child{flex-basis:0;flex-grow:1}.pxd-resizable-handle[data-handler=true]:before{background-color:var(--color-gray-300);border-radius:.5rem;content:"";left:50%;pointer-events:none;position:absolute;top:50%;transform:translate(-50%,-50%);z-index:1}.pxd-resizable-handle[data-collapsed=true]:before{opacity:.4}.pxd-resizable-handle:after{content:"";left:50%;padding:2px;position:absolute;top:50%;transform:translate(-50%,-50%)}.pxd-resizable-handle:hover:after{background-color:var(--color-primary)}.pxd-resizable-handle[data-orientation=horizontal]{border-left-width:1px;cursor:ew-resize;height:100%}.pxd-resizable-handle[data-orientation=horizontal]:before{height:1.5rem;width:.375rem}.pxd-resizable-handle[data-orientation=horizontal]:after{height:100%}.pxd-resizable-handle[data-orientation=vertical]{border-bottom-width:1px;cursor:ns-resize;width:100%}.pxd-resizable-handle[data-orientation=vertical]:before{height:.375rem;width:1.5rem}.pxd-resizable-handle[data-orientation=vertical]:after{width:100%}
|
|
423
358
|
</style>
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import type { ComponentDirection } from '../../types/shared'
|
|
1
|
+
import type { ComponentDirection } from '../../types/shared/props'
|
|
2
2
|
|
|
3
3
|
export interface ResizableProps {
|
|
4
4
|
direction?: ComponentDirection
|
|
5
|
-
|
|
6
|
-
* Per-panel floors as percentages. The group always sums to 100, so one panel's
|
|
7
|
-
* floor is the other panel's ceiling: `[20, 40]` means leading 20-60 and
|
|
8
|
-
* trailing 40-80. Adding up to more than 100 leaves no split that fits, so the
|
|
9
|
-
* constraint is ignored.
|
|
10
|
-
*/
|
|
5
|
+
unit?: 'percent' | 'px'
|
|
11
6
|
minSize?: number[]
|
|
12
|
-
/** Draw the grip in the middle of the handle. */
|
|
13
7
|
handle?: boolean
|
|
14
|
-
/** Stop the handle from dragging or folding. */
|
|
15
8
|
disabled?: boolean
|
|
16
|
-
/** Starting sizes when uncontrolled. Read once, on setup. */
|
|
17
9
|
defaultValue?: number[]
|
|
18
10
|
modelValue?: number[] | null
|
|
19
11
|
}
|
|
@@ -4,13 +4,13 @@ type __VLS_Slots = {} & {
|
|
|
4
4
|
default?: (props: typeof __VLS_1) => any;
|
|
5
5
|
};
|
|
6
6
|
declare const __VLS_base: import("vue").DefineComponent<RevealProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<RevealProps> & Readonly<{}>, {
|
|
7
|
-
delay:
|
|
8
|
-
duration:
|
|
7
|
+
delay: string | number;
|
|
8
|
+
duration: string | number;
|
|
9
9
|
threshold: number | number[];
|
|
10
10
|
direction: import("../../types/shared/props.js").BasePosition;
|
|
11
11
|
trigger: import("./types").RevealTrigger;
|
|
12
12
|
rootMargin: string;
|
|
13
|
-
distance:
|
|
13
|
+
distance: string | number;
|
|
14
14
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
15
15
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
16
16
|
declare const _default: typeof __VLS_export;
|
|
@@ -49,10 +49,6 @@ const props = defineProps({
|
|
|
49
49
|
});
|
|
50
50
|
const containerRef = shallowRef();
|
|
51
51
|
const revealed = shallowRef(props.trigger === "mount");
|
|
52
|
-
/** Bare numbers are seconds, matching the CSS `animation-*` time grammar. */
|
|
53
|
-
function getTimeUnitValue(value) {
|
|
54
|
-
return typeof value === "number" ? `${value}s` : value;
|
|
55
|
-
}
|
|
56
52
|
const computedStyle = computed(() => ({
|
|
57
53
|
"--reveal-duration": getTimeUnitValue(props.duration),
|
|
58
54
|
"--reveal-delay": getTimeUnitValue(props.delay),
|
|
@@ -79,6 +75,10 @@ const { observer, stop } = useIntersectionObserver(target, ([{ entry }]) => {
|
|
|
79
75
|
* leaving that content permanently invisible.
|
|
80
76
|
*/
|
|
81
77
|
const gated = computed(() => props.trigger === "viewport" && !!observer.value);
|
|
78
|
+
/** Bare numbers are seconds, matching the CSS `animation-*` time grammar. */
|
|
79
|
+
function getTimeUnitValue(value) {
|
|
80
|
+
return typeof value === "number" ? `${value}s` : value;
|
|
81
|
+
}
|
|
82
82
|
</script>
|
|
83
83
|
|
|
84
84
|
<template>
|
|
@@ -7,8 +7,8 @@ declare const __VLS_export: import("vue").DefineComponent<RollingNumberProps, {
|
|
|
7
7
|
}, string, import("vue").PublicProps, Readonly<RollingNumberProps> & Readonly<{
|
|
8
8
|
onFinish?: (() => any) | undefined;
|
|
9
9
|
}>, {
|
|
10
|
-
value:
|
|
11
|
-
mode: "
|
|
10
|
+
value: string | number;
|
|
11
|
+
mode: "scroll" | "tween";
|
|
12
12
|
durations: number;
|
|
13
13
|
thousands: boolean;
|
|
14
14
|
animateOnMount: boolean;
|
|
@@ -65,21 +65,6 @@ const decimalPlaces = computed(() => {
|
|
|
65
65
|
}
|
|
66
66
|
return Math.min(str.length - dotIndex - 1, 10);
|
|
67
67
|
});
|
|
68
|
-
function formatNumber(rawValue) {
|
|
69
|
-
// avoid -0
|
|
70
|
-
const d = decimalPlaces.value;
|
|
71
|
-
const raw = Math.abs(rawValue) < 5 * 10 ** -(d + 1) ? 0 : rawValue;
|
|
72
|
-
const val = raw.toFixed(d);
|
|
73
|
-
if (!props.thousands) {
|
|
74
|
-
return val;
|
|
75
|
-
}
|
|
76
|
-
const [intPart, decPart] = val.split(".");
|
|
77
|
-
const formatted = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
78
|
-
return isUndefined(decPart) ? formatted : `${formatted}.${decPart}`;
|
|
79
|
-
}
|
|
80
|
-
function maskDigitsAsZero(formatted) {
|
|
81
|
-
return formatted.replace(/\d/g, "0");
|
|
82
|
-
}
|
|
83
68
|
const formattedValue = computed(() => formatNumber(displayValue.value));
|
|
84
69
|
const scrollChars = computed(() => {
|
|
85
70
|
const chars = (scrollText.value ?? formattedValue.value).split("");
|
|
@@ -96,6 +81,21 @@ const scrollChars = computed(() => {
|
|
|
96
81
|
});
|
|
97
82
|
});
|
|
98
83
|
const scrollStyle = computed(() => ({ "--pxd-rolling-duration": `${Math.max(props.durations, 0)}ms` }));
|
|
84
|
+
function formatNumber(rawValue) {
|
|
85
|
+
// avoid -0
|
|
86
|
+
const d = decimalPlaces.value;
|
|
87
|
+
const raw = Math.abs(rawValue) < 5 * 10 ** -(d + 1) ? 0 : rawValue;
|
|
88
|
+
const val = raw.toFixed(d);
|
|
89
|
+
if (!props.thousands) {
|
|
90
|
+
return val;
|
|
91
|
+
}
|
|
92
|
+
const [intPart, decPart] = val.split(".");
|
|
93
|
+
const formatted = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
94
|
+
return isUndefined(decPart) ? formatted : `${formatted}.${decPart}`;
|
|
95
|
+
}
|
|
96
|
+
function maskDigitsAsZero(formatted) {
|
|
97
|
+
return formatted.replace(/\d/g, "0");
|
|
98
|
+
}
|
|
99
99
|
function easeOutCubic(t) {
|
|
100
100
|
return t === 1 ? 1 : 1 - 2 ** (-10 * t);
|
|
101
101
|
}
|
|
@@ -21,9 +21,18 @@ const props = defineProps({
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
const PRECISION = .5;
|
|
24
|
+
const scheduleAdjust = scheduleByRaf(adjust, { defer: true });
|
|
24
25
|
const needsWrap = shallowRef(false);
|
|
25
26
|
const containerRef = shallowRef();
|
|
26
27
|
const fittedFontSize = shallowRef(null);
|
|
28
|
+
const computedStyle = computed(() => {
|
|
29
|
+
const size = fittedFontSize.value;
|
|
30
|
+
if (size === null) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return { fontSize: `${size}px` };
|
|
34
|
+
});
|
|
35
|
+
useResizeObserver(containerRef, scheduleAdjust);
|
|
27
36
|
function parseSize(value) {
|
|
28
37
|
return Number.parseFloat(value) || 0;
|
|
29
38
|
}
|
|
@@ -117,17 +126,8 @@ function adjust() {
|
|
|
117
126
|
fittedFontSize.value = best;
|
|
118
127
|
needsWrap.value = false;
|
|
119
128
|
}
|
|
120
|
-
const scheduleAdjust = scheduleByRaf(adjust, { defer: true });
|
|
121
|
-
const computedStyle = computed(() => {
|
|
122
|
-
const size = fittedFontSize.value;
|
|
123
|
-
if (size === null) {
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
return { fontSize: `${size}px` };
|
|
127
|
-
});
|
|
128
129
|
// Watch only the specific props that matter, no deep traversal
|
|
129
130
|
watch(() => [props.text, props.minFontSize], scheduleAdjust, { flush: "post" });
|
|
130
|
-
useResizeObserver(containerRef, scheduleAdjust);
|
|
131
131
|
onBeforeUnmount(() => {
|
|
132
132
|
scheduleAdjust.cancel();
|
|
133
133
|
});
|