@w-run/wdesign-ui 0.0.0-stage → 1.1.0

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.
Files changed (214) hide show
  1. package/README.md +255 -2
  2. package/dist/index.d.ts +1013 -0
  3. package/dist/parts/WdAffix.js +159 -0
  4. package/dist/parts/WdAiMessage.js +277 -0
  5. package/dist/parts/WdAlert.js +92 -0
  6. package/dist/parts/WdAnchor.js +159 -0
  7. package/dist/parts/WdAudioPlayer.js +1024 -0
  8. package/dist/parts/WdAvatar.js +6 -0
  9. package/dist/parts/WdAvatarGroup.js +46 -0
  10. package/dist/parts/WdBacktop.js +120 -0
  11. package/dist/parts/WdBadge.js +61 -0
  12. package/dist/parts/WdBento.js +40 -0
  13. package/dist/parts/WdBentoItem.js +43 -0
  14. package/dist/parts/WdBottomSheet.js +263 -0
  15. package/dist/parts/WdBreadcrumb.js +64 -0
  16. package/dist/parts/WdButton.js +94 -0
  17. package/dist/parts/WdCalendar.js +11 -0
  18. package/dist/parts/WdCard.js +113 -0
  19. package/dist/parts/WdCarousel.js +365 -0
  20. package/dist/parts/WdCascader.js +386 -0
  21. package/dist/parts/WdCheckbox.js +81 -0
  22. package/dist/parts/WdCollapse.js +135 -0
  23. package/dist/parts/WdColorPicker.js +592 -0
  24. package/dist/parts/WdCommand.js +357 -0
  25. package/dist/parts/WdContainer.js +37 -0
  26. package/dist/parts/WdCountdown.js +163 -0
  27. package/dist/parts/WdDanmaku.js +6 -0
  28. package/dist/parts/WdDatePicker.js +169 -0
  29. package/dist/parts/WdDateTimePicker.js +162 -0
  30. package/dist/parts/WdDescriptions.js +146 -0
  31. package/dist/parts/WdDivider.js +64 -0
  32. package/dist/parts/WdDrawer.js +176 -0
  33. package/dist/parts/WdDropdown.js +140 -0
  34. package/dist/parts/WdEmpty.js +79 -0
  35. package/dist/parts/WdExplorer.js +336 -0
  36. package/dist/parts/WdFileList.js +177 -0
  37. package/dist/parts/WdForm.js +111 -0
  38. package/dist/parts/WdFormItem.js +156 -0
  39. package/dist/parts/WdGrid.js +40 -0
  40. package/dist/parts/WdGroup.js +68 -0
  41. package/dist/parts/WdImagePreview.js +274 -0
  42. package/dist/parts/WdInput.js +10 -0
  43. package/dist/parts/WdInputNumber.js +253 -0
  44. package/dist/parts/WdListItem.js +60 -0
  45. package/dist/parts/WdLoading.js +128 -0
  46. package/dist/parts/WdMarkdown.js +172 -0
  47. package/dist/parts/WdMarquee.js +80 -0
  48. package/dist/parts/WdMasonry.js +40 -0
  49. package/dist/parts/WdMediaCard.js +302 -0
  50. package/dist/parts/WdMentions.js +277 -0
  51. package/dist/parts/WdModal.js +149 -0
  52. package/dist/parts/WdNav.js +311 -0
  53. package/dist/parts/WdNotification.js +112 -0
  54. package/dist/parts/WdOtp.js +107 -0
  55. package/dist/parts/WdPagination.js +252 -0
  56. package/dist/parts/WdPopconfirm.js +214 -0
  57. package/dist/parts/WdPopover.js +203 -0
  58. package/dist/parts/WdPostItem.js +84 -0
  59. package/dist/parts/WdProgress.js +48 -0
  60. package/dist/parts/WdProgressRing.js +101 -0
  61. package/dist/parts/WdPullRefresh.js +167 -0
  62. package/dist/parts/WdQRCode.js +1909 -0
  63. package/dist/parts/WdRadioGroup.js +95 -0
  64. package/dist/parts/WdRate.js +128 -0
  65. package/dist/parts/WdResult.js +86 -0
  66. package/dist/parts/WdScrollbar.js +186 -0
  67. package/dist/parts/WdSegmented.js +11 -0
  68. package/dist/parts/WdSelect.js +465 -0
  69. package/dist/parts/WdSkeleton.js +69 -0
  70. package/dist/parts/WdSlider.js +100 -0
  71. package/dist/parts/WdSortableList.js +291 -0
  72. package/dist/parts/WdSpace.js +46 -0
  73. package/dist/parts/WdSparkline.js +148 -0
  74. package/dist/parts/WdSpinner.js +6 -0
  75. package/dist/parts/WdSplitter.js +183 -0
  76. package/dist/parts/WdStatBar.js +202 -0
  77. package/dist/parts/WdStatistic.js +131 -0
  78. package/dist/parts/WdSteps.js +110 -0
  79. package/dist/parts/WdSwitch.js +63 -0
  80. package/dist/parts/WdTabBar.js +84 -0
  81. package/dist/parts/WdTable.js +589 -0
  82. package/dist/parts/WdTabs.js +219 -0
  83. package/dist/parts/WdTag.js +6 -0
  84. package/dist/parts/WdTagInput.js +181 -0
  85. package/dist/parts/WdTimePicker.js +12 -0
  86. package/dist/parts/WdTimeline.js +145 -0
  87. package/dist/parts/WdTooltip.js +108 -0
  88. package/dist/parts/WdTour.js +264 -0
  89. package/dist/parts/WdTransfer.js +446 -0
  90. package/dist/parts/WdTree.js +322 -0
  91. package/dist/parts/WdUpload.js +309 -0
  92. package/dist/parts/WdVideoPlayer.js +1006 -0
  93. package/dist/parts/WdVirtualList.js +169 -0
  94. package/dist/parts/WdWatermark.js +150 -0
  95. package/dist/parts/chunk-3LVE72ZK.js +361 -0
  96. package/dist/parts/chunk-5HYOQ52I.js +101 -0
  97. package/dist/parts/chunk-7M3MUL3B.js +275 -0
  98. package/dist/parts/chunk-AOTJ63HN.js +15 -0
  99. package/dist/parts/chunk-AXEF2U2A.js +41 -0
  100. package/dist/parts/chunk-CY3QOSFP.js +645 -0
  101. package/dist/parts/chunk-G7NN4A6J.js +40 -0
  102. package/dist/parts/chunk-HAKYCUAR.js +9 -0
  103. package/dist/parts/chunk-JDE4AHBR.js +160 -0
  104. package/dist/parts/chunk-LT3NTWIT.js +117 -0
  105. package/dist/parts/chunk-OGHYFT7B.js +387 -0
  106. package/dist/parts/chunk-Q34U2HES.js +261 -0
  107. package/dist/parts/chunk-RLSVPJHM.js +10 -0
  108. package/dist/parts/chunk-U2CDKD2T.js +30 -0
  109. package/dist/parts/chunk-UYUNYHZD.js +40 -0
  110. package/dist/parts/chunk-VUJL2HGD.js +23 -0
  111. package/dist/parts/chunk-WCFG5KNT.js +51 -0
  112. package/dist/parts/chunk-WDDAALPI.js +42 -0
  113. package/dist/parts/chunk-WFXLDBP2.js +149 -0
  114. package/dist/style/affix.css +566 -0
  115. package/dist/style/ai-msg.css +746 -0
  116. package/dist/style/alert.css +636 -0
  117. package/dist/style/anchor.css +630 -0
  118. package/dist/style/audio.css +1954 -0
  119. package/dist/style/avatar.css +651 -0
  120. package/dist/style/backtop.css +625 -0
  121. package/dist/style/badge.css +632 -0
  122. package/dist/style/bento.css +763 -0
  123. package/dist/style/bottom-sheet.css +776 -0
  124. package/dist/style/breadcrumb.css +629 -0
  125. package/dist/style/button.css +829 -0
  126. package/dist/style/calendar.css +1512 -0
  127. package/dist/style/card.css +748 -0
  128. package/dist/style/carousel.css +670 -0
  129. package/dist/style/cascader.css +862 -0
  130. package/dist/style/checkbox.css +706 -0
  131. package/dist/style/chevron.css +575 -0
  132. package/dist/style/collapse.css +648 -0
  133. package/dist/style/colorpicker.css +876 -0
  134. package/dist/style/command.css +760 -0
  135. package/dist/style/container.css +550 -0
  136. package/dist/style/countdown.css +722 -0
  137. package/dist/style/danmaku.css +644 -0
  138. package/dist/style/datepicker.css +683 -0
  139. package/dist/style/datetime-picker.css +714 -0
  140. package/dist/style/descriptions.css +712 -0
  141. package/dist/style/divider.css +604 -0
  142. package/dist/style/dot.css +585 -0
  143. package/dist/style/drawer.css +743 -0
  144. package/dist/style/dropdown.css +645 -0
  145. package/dist/style/empty.css +657 -0
  146. package/dist/style/explorer.css +944 -0
  147. package/dist/style/file-list.css +664 -0
  148. package/dist/style/flip.css +600 -0
  149. package/dist/style/form.css +638 -0
  150. package/dist/style/grid.css +618 -0
  151. package/dist/style/group.css +1022 -0
  152. package/dist/style/icon-btn.css +641 -0
  153. package/dist/style/image-preview.css +725 -0
  154. package/dist/style/input-number.css +680 -0
  155. package/dist/style/input.css +682 -0
  156. package/dist/style/list.css +630 -0
  157. package/dist/style/loading.css +667 -0
  158. package/dist/style/markdown.css +884 -0
  159. package/dist/style/marquee.css +678 -0
  160. package/dist/style/masonry.css +614 -0
  161. package/dist/style/media-card.css +1229 -0
  162. package/dist/style/mentions.css +690 -0
  163. package/dist/style/modal.css +775 -0
  164. package/dist/style/nav.css +1046 -0
  165. package/dist/style/notification.css +601 -0
  166. package/dist/style/otp.css +699 -0
  167. package/dist/style/pagination.css +680 -0
  168. package/dist/style/popconfirm.css +645 -0
  169. package/dist/style/popover.css +740 -0
  170. package/dist/style/post-item.css +676 -0
  171. package/dist/style/progress-ring.css +640 -0
  172. package/dist/style/progress.css +576 -0
  173. package/dist/style/pull-refresh.css +637 -0
  174. package/dist/style/qrcode.css +613 -0
  175. package/dist/style/radio.css +705 -0
  176. package/dist/style/rate.css +637 -0
  177. package/dist/style/result.css +597 -0
  178. package/dist/style/scroll-reveal.css +613 -0
  179. package/dist/style/scrollbar.css +644 -0
  180. package/dist/style/segmented-picker.css +679 -0
  181. package/dist/style/segmented.css +894 -0
  182. package/dist/style/select.css +937 -0
  183. package/dist/style/skeleton.css +590 -0
  184. package/dist/style/slider.css +642 -0
  185. package/dist/style/sortable.css +714 -0
  186. package/dist/style/space.css +568 -0
  187. package/dist/style/sparkline.css +606 -0
  188. package/dist/style/spinner.css +586 -0
  189. package/dist/style/splitter.css +711 -0
  190. package/dist/style/stat-bar.css +767 -0
  191. package/dist/style/statistic.css +589 -0
  192. package/dist/style/steps.css +724 -0
  193. package/dist/style/switch.css +676 -0
  194. package/dist/style/tab-bar.css +647 -0
  195. package/dist/style/table.css +1229 -0
  196. package/dist/style/tabs.css +756 -0
  197. package/dist/style/tag-input.css +710 -0
  198. package/dist/style/tag.css +682 -0
  199. package/dist/style/time-picker.css +749 -0
  200. package/dist/style/timeline.css +1082 -0
  201. package/dist/style/toast.css +598 -0
  202. package/dist/style/tooltip.css +604 -0
  203. package/dist/style/tour.css +683 -0
  204. package/dist/style/transfer.css +858 -0
  205. package/dist/style/tree.css +786 -0
  206. package/dist/style/typography.css +947 -0
  207. package/dist/style/upload.css +758 -0
  208. package/dist/style/vlist.css +591 -0
  209. package/dist/style/vplayer.css +1588 -0
  210. package/dist/style/watermark.css +570 -0
  211. package/dist/wdesign-ui.css +21093 -0
  212. package/dist/wdesign-ui.esm.js +20265 -0
  213. package/package.json +134 -4
  214. package/tokens.json +385 -0
@@ -0,0 +1,160 @@
1
+ import {
2
+ useControllable
3
+ } from "./chunk-G7NN4A6J.js";
4
+ import {
5
+ useComposition
6
+ } from "./chunk-U2CDKD2T.js";
7
+ import {
8
+ FORM_ITEM_CONTEXT
9
+ } from "./chunk-UYUNYHZD.js";
10
+ import {
11
+ WdIcon_default
12
+ } from "./chunk-Q34U2HES.js";
13
+
14
+ // .lib-build/WdInput.ts
15
+ import { defineComponent as _defineComponent } from "vue";
16
+ import { renderSlot as _renderSlot, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, unref as _unref, mergeProps as _mergeProps, createElementVNode as _createElementVNode, createVNode as _createVNode, withModifiers as _withModifiers, toDisplayString as _toDisplayString, normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle } from "vue";
17
+ import { computed, inject, ref, useAttrs } from "vue";
18
+ var _hoisted_1 = {
19
+ key: 0,
20
+ class: "wd-input__icon"
21
+ };
22
+ var _hoisted_2 = ["type", "value", "placeholder", "disabled", "readonly", "maxlength"];
23
+ var _hoisted_3 = {
24
+ key: 2,
25
+ class: "wd-input__count"
26
+ };
27
+ var WdInput_default = /* @__PURE__ */ _defineComponent({
28
+ ...{ name: "WdInput", inheritAttrs: false },
29
+ __name: "WdInput",
30
+ props: {
31
+ modelValue: { type: String, required: false },
32
+ defaultValue: { type: String, required: false },
33
+ placeholder: { type: String, required: false, default: "" },
34
+ shape: { type: String, required: false, default: "pill" },
35
+ type: { type: String, required: false, default: "text" },
36
+ disabled: { type: Boolean, required: false, default: false },
37
+ size: { type: String, required: false, default: "md" },
38
+ clearable: { type: Boolean, required: false, default: false },
39
+ maxlength: { type: Number, required: false },
40
+ showCount: { type: Boolean, required: false, default: false },
41
+ readonly: { type: Boolean, required: false, default: false },
42
+ inputmode: { type: String, required: false }
43
+ },
44
+ emits: ["update:modelValue", "change", "clear", "enter"],
45
+ setup(__props, { expose: __expose, emit: __emit }) {
46
+ const attrs = useAttrs();
47
+ const formItem = inject(FORM_ITEM_CONTEXT, null);
48
+ const inputAttrs = computed(() => {
49
+ const { class: _c, style: _s, ...rest } = attrs;
50
+ if (!formItem) return rest;
51
+ const merged = { ...rest };
52
+ if (merged["aria-invalid"] === void 0 && formItem.invalid()) {
53
+ merged["aria-invalid"] = "true";
54
+ }
55
+ const described = formItem.errorId();
56
+ if (described && merged["aria-describedby"] === void 0) {
57
+ merged["aria-describedby"] = described;
58
+ }
59
+ return merged;
60
+ });
61
+ const props = __props;
62
+ const emit = __emit;
63
+ const { value, set } = useControllable({
64
+ modelValue: computed(() => props.modelValue),
65
+ defaultValue: computed(() => props.defaultValue),
66
+ fallback: "",
67
+ onChange: (v) => {
68
+ emit("update:modelValue", v);
69
+ emit("change", v);
70
+ }
71
+ });
72
+ const el = ref(null);
73
+ const hasValue = computed(() => value.value.length > 0);
74
+ const showClear = computed(() => props.clearable && hasValue.value && !props.disabled && !props.readonly);
75
+ const count = computed(() => props.showCount && props.maxlength ? `${value.value.length}/${props.maxlength}` : "");
76
+ const { onCompositionStart, onCompositionEnd, shouldSkip } = useComposition();
77
+ function onInput(event) {
78
+ if (shouldSkip(event)) return;
79
+ let v = event.target.value;
80
+ if (props.maxlength && v.length > props.maxlength) {
81
+ v = v.slice(0, props.maxlength);
82
+ event.target.value = v;
83
+ }
84
+ set(v);
85
+ }
86
+ function clear() {
87
+ set("");
88
+ emit("clear");
89
+ el.value?.focus();
90
+ }
91
+ function onKeydown(e) {
92
+ if (e.key === "Enter" && !shouldSkip(e)) emit("enter", value.value);
93
+ }
94
+ __expose({ focus: () => el.value?.focus(), blur: () => el.value?.blur() });
95
+ return (_ctx, _cache) => {
96
+ return _openBlock(), _createElementBlock(
97
+ "label",
98
+ {
99
+ class: _normalizeClass(["wd-input", [
100
+ {
101
+ "wd-input--rounded": __props.shape === "rounded",
102
+ "wd-input--lg": __props.size === "lg",
103
+ "wd-input--sm": __props.size === "sm",
104
+ "wd-input--has-count": !!count.value
105
+ },
106
+ _ctx.$attrs.class
107
+ ]]),
108
+ style: _normalizeStyle(_ctx.$attrs.style)
109
+ },
110
+ [
111
+ _ctx.$slots.icon ? (_openBlock(), _createElementBlock("span", _hoisted_1, [
112
+ _renderSlot(_ctx.$slots, "icon")
113
+ ])) : _createCommentVNode("v-if", true),
114
+ _createElementVNode("input", _mergeProps({
115
+ ref_key: "el",
116
+ ref: el
117
+ }, inputAttrs.value, {
118
+ type: __props.type,
119
+ value: _unref(value),
120
+ placeholder: __props.placeholder,
121
+ disabled: __props.disabled,
122
+ readonly: __props.readonly,
123
+ maxlength: __props.maxlength,
124
+ onInput,
125
+ onKeydown,
126
+ onCompositionstart: _cache[0] || (_cache[0] = //@ts-ignore
127
+ (...args) => _unref(onCompositionStart) && _unref(onCompositionStart)(...args)),
128
+ onCompositionend: _cache[1] || (_cache[1] = ($event) => _unref(onCompositionEnd)($event, () => onInput($event)))
129
+ }), null, 16, _hoisted_2),
130
+ showClear.value ? (_openBlock(), _createElementBlock("button", {
131
+ key: 1,
132
+ type: "button",
133
+ class: "wd-input__clear",
134
+ "aria-label": "\u6E05\u9664",
135
+ onClick: _withModifiers(clear, ["prevent"])
136
+ }, [
137
+ _createVNode(_unref(WdIcon_default), {
138
+ name: "close",
139
+ size: 13
140
+ })
141
+ ])) : _createCommentVNode("v-if", true),
142
+ _renderSlot(_ctx.$slots, "suffix"),
143
+ count.value ? (_openBlock(), _createElementBlock(
144
+ "span",
145
+ _hoisted_3,
146
+ _toDisplayString(count.value),
147
+ 1
148
+ /* TEXT */
149
+ )) : _createCommentVNode("v-if", true)
150
+ ],
151
+ 6
152
+ /* CLASS, STYLE */
153
+ );
154
+ };
155
+ }
156
+ });
157
+
158
+ export {
159
+ WdInput_default
160
+ };
@@ -0,0 +1,117 @@
1
+ import {
2
+ installOverlayKeyboard,
3
+ topOverlay,
4
+ useOverlayLayer
5
+ } from "./chunk-5HYOQ52I.js";
6
+
7
+ // .lib-build/overlay.ts
8
+ import { onBeforeUnmount, ref, watch } from "vue";
9
+ var lockCount = 0;
10
+ var savedOverflow = "";
11
+ var savedPadding = "";
12
+ function lockScroll() {
13
+ if (lockCount === 0) {
14
+ const body = document.body;
15
+ savedOverflow = body.style.overflow;
16
+ savedPadding = body.style.paddingRight;
17
+ const scrollbar = window.innerWidth - document.documentElement.clientWidth;
18
+ body.style.overflow = "hidden";
19
+ if (scrollbar > 0) body.style.paddingRight = `${scrollbar}px`;
20
+ }
21
+ lockCount++;
22
+ }
23
+ function unlockScroll() {
24
+ lockCount = Math.max(0, lockCount - 1);
25
+ if (lockCount === 0) {
26
+ document.body.style.overflow = savedOverflow;
27
+ document.body.style.paddingRight = savedPadding;
28
+ }
29
+ }
30
+ function useScrollLock(open) {
31
+ let locked = false;
32
+ const apply = (v) => {
33
+ if (v && !locked) {
34
+ lockScroll();
35
+ locked = true;
36
+ } else if (!v && locked) {
37
+ unlockScroll();
38
+ locked = false;
39
+ }
40
+ };
41
+ watch(open, apply, { immediate: true });
42
+ onBeforeUnmount(() => {
43
+ if (locked) {
44
+ unlockScroll();
45
+ locked = false;
46
+ }
47
+ });
48
+ }
49
+ var FOCUSABLE = [
50
+ "a[href]",
51
+ "button:not([disabled])",
52
+ "input:not([disabled])",
53
+ "select:not([disabled])",
54
+ "textarea:not([disabled])",
55
+ '[tabindex]:not([tabindex="-1"])'
56
+ ].join(", ");
57
+ function useFocusTrap(open, panel, onEsc) {
58
+ installOverlayKeyboard();
59
+ const layer = useOverlayLayer(open, panel, onEsc);
60
+ let restoreTo = null;
61
+ function focusables() {
62
+ if (!panel.value) return [];
63
+ return Array.from(panel.value.querySelectorAll(FOCUSABLE)).filter((el) => el.offsetParent !== null || el === document.activeElement);
64
+ }
65
+ function onKeydown(e) {
66
+ if (!open.value || e.key !== "Tab") return;
67
+ if (!layer.isTop()) return;
68
+ const nodes = focusables();
69
+ if (!nodes.length) {
70
+ e.preventDefault();
71
+ return;
72
+ }
73
+ const first = nodes[0];
74
+ const last = nodes[nodes.length - 1];
75
+ const active = document.activeElement;
76
+ if (e.shiftKey) {
77
+ if (active === first || !panel.value?.contains(active)) {
78
+ e.preventDefault();
79
+ last.focus();
80
+ }
81
+ } else if (active === last || !panel.value?.contains(active)) {
82
+ e.preventDefault();
83
+ first.focus();
84
+ }
85
+ }
86
+ watch(open, async (v) => {
87
+ if (v) {
88
+ restoreTo = document.activeElement;
89
+ await Promise.resolve();
90
+ setTimeout(() => {
91
+ const nodes = focusables();
92
+ if (nodes.length) nodes[0].focus();
93
+ else panel.value?.focus?.();
94
+ }, 0);
95
+ } else if (restoreTo) {
96
+ if (document.contains(restoreTo)) restoreTo.focus();
97
+ else {
98
+ const top = topOverlay();
99
+ const el = top?.panel.value;
100
+ if (el) el.focus?.();
101
+ }
102
+ restoreTo = null;
103
+ }
104
+ });
105
+ if (typeof document !== "undefined") {
106
+ document.addEventListener("keydown", onKeydown, true);
107
+ }
108
+ onBeforeUnmount(() => {
109
+ document.removeEventListener("keydown", onKeydown, true);
110
+ if (restoreTo && document.contains(restoreTo)) restoreTo.focus();
111
+ });
112
+ }
113
+
114
+ export {
115
+ useScrollLock,
116
+ useFocusTrap
117
+ };
@@ -0,0 +1,387 @@
1
+ import {
2
+ useControllable
3
+ } from "./chunk-G7NN4A6J.js";
4
+ import {
5
+ useOverlayLayer
6
+ } from "./chunk-5HYOQ52I.js";
7
+ import {
8
+ useAnchoredPosition,
9
+ useDismiss
10
+ } from "./chunk-WFXLDBP2.js";
11
+ import {
12
+ useFormItemA11y
13
+ } from "./chunk-VUJL2HGD.js";
14
+ import {
15
+ WdIcon_default
16
+ } from "./chunk-Q34U2HES.js";
17
+
18
+ // .lib-build/WdTimePicker.ts
19
+ import { defineComponent as _defineComponent } from "vue";
20
+ import { unref as _unref, createCommentVNode as _createCommentVNode, toDisplayString as _toDisplayString, createElementVNode as _createElementVNode, createVNode as _createVNode, renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle, Teleport as _Teleport, createBlock as _createBlock, mergeProps as _mergeProps } from "vue";
21
+ import { computed, nextTick, ref, watch } from "vue";
22
+ var _hoisted_1 = ["aria-expanded", "aria-controls", "disabled"];
23
+ var _hoisted_2 = { class: "wd-time-picker__value" };
24
+ var _hoisted_3 = ["data-placement"];
25
+ var _hoisted_4 = ["aria-selected", "disabled", "onClick"];
26
+ var _hoisted_5 = ["aria-selected", "disabled", "onClick"];
27
+ var _hoisted_6 = ["aria-selected", "disabled", "onClick"];
28
+ var ITEM_H = 34 + 3;
29
+ var WdTimePicker_default = /* @__PURE__ */ _defineComponent({
30
+ ...{ name: "WdTimePicker" },
31
+ __name: "WdTimePicker",
32
+ props: {
33
+ modelValue: { type: String, required: false },
34
+ defaultValue: { type: String, required: false, default: "" },
35
+ second: { type: Boolean, required: false, default: false },
36
+ hour12: { type: Boolean, required: false, default: false },
37
+ minuteStep: { type: Number, required: false, default: 1 },
38
+ hourRange: { type: Array, required: false, default: () => [0, 23] },
39
+ min: { type: String, required: false, default: "" },
40
+ max: { type: String, required: false, default: "" },
41
+ disabled: { type: Boolean, required: false, default: false },
42
+ size: { type: String, required: false, default: "md" },
43
+ inline: { type: Boolean, required: false, default: false }
44
+ },
45
+ emits: ["update:modelValue", "change"],
46
+ setup(__props, { emit: __emit }) {
47
+ const formA11y = useFormItemA11y();
48
+ const props = __props;
49
+ const emit = __emit;
50
+ const { value, set } = useControllable({
51
+ modelValue: computed(() => props.modelValue),
52
+ defaultValue: computed(() => props.defaultValue),
53
+ fallback: "",
54
+ onChange: (v) => {
55
+ emit("update:modelValue", v);
56
+ emit("change", v);
57
+ }
58
+ });
59
+ function pad(n) {
60
+ return n < 10 ? "0" + n : String(n);
61
+ }
62
+ function parseTime(s) {
63
+ const m = /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(s.trim());
64
+ if (!m) return null;
65
+ const h = Number(m[1]);
66
+ const mi = Number(m[2]);
67
+ const se = m[3] ? Number(m[3]) : 0;
68
+ if (h > 23 || mi > 59 || se > 59) return null;
69
+ return [h, mi, se];
70
+ }
71
+ function format(h, m, s) {
72
+ return props.second ? `${pad(h)}:${pad(m)}:${pad(s)}` : `${pad(h)}:${pad(m)}`;
73
+ }
74
+ const parts = computed(() => parseTime(value.value) ?? [0, 0, 0]);
75
+ const hours = computed(() => {
76
+ const [start, end] = props.hourRange;
77
+ const out = [];
78
+ if (start <= end) {
79
+ for (let h = start; h <= end; h++) out.push(h);
80
+ } else {
81
+ for (let h = start; h <= 23; h++) out.push(h);
82
+ for (let h = 0; h <= end; h++) out.push(h);
83
+ }
84
+ return out;
85
+ });
86
+ const minutes = computed(() => {
87
+ const step = Math.max(1, Math.min(30, props.minuteStep));
88
+ const out = [];
89
+ for (let m = 0; m < 60; m += step) out.push(m);
90
+ return out;
91
+ });
92
+ const seconds = computed(() => Array.from({ length: 60 }, (_, i) => i));
93
+ function hourDisabled(h) {
94
+ const [minH, minM] = props.min ? parseTime(props.min) ?? [-1, -1] : [-1, -1];
95
+ const [maxH, maxM] = props.max ? parseTime(props.max) ?? [99, 99] : [99, 99];
96
+ const [curH, curM] = parts.value;
97
+ if (minH >= 0 && h < minH) return true;
98
+ if (maxH < 99 && h > maxH) return true;
99
+ return false;
100
+ }
101
+ function minuteDisabled(h, m) {
102
+ const [minH, minM] = props.min ? parseTime(props.min) ?? [-1, -1] : [-1, -1];
103
+ const [maxH, maxM] = props.max ? parseTime(props.max) ?? [99, 99] : [99, 99];
104
+ if (minH >= 0 && (h < minH || h === minH && m < minM)) return true;
105
+ if (maxH < 99 && (h > maxH || h === maxH && m > maxM)) return true;
106
+ return false;
107
+ }
108
+ function secondDisabled(_h, _m, s) {
109
+ return s < 0;
110
+ }
111
+ function pickHour(h) {
112
+ const [, m, s] = parts.value;
113
+ let nm = m;
114
+ const [minH, minM] = props.min ? parseTime(props.min) ?? [-1, -1] : [-1, -1];
115
+ if (minH >= 0 && h === minH && nm < minM) nm = minM;
116
+ set(format(h, nm, s));
117
+ syncOpenPart("hour");
118
+ }
119
+ function pickMinute(m) {
120
+ const [h, , s] = parts.value;
121
+ if (minuteDisabled(h, m)) return;
122
+ set(format(h, m, s));
123
+ syncOpenPart("minute");
124
+ }
125
+ function pickSecond(s) {
126
+ const [h, m] = parts.value;
127
+ set(format(h, m, s));
128
+ }
129
+ const activePart = ref("hour");
130
+ function syncOpenPart(p) {
131
+ activePart.value = p;
132
+ }
133
+ let scrollTimers = {};
134
+ const programmatic = {};
135
+ function onColScroll(part, e) {
136
+ const el = e.currentTarget;
137
+ if (programmatic[part]) return;
138
+ if (scrollTimers[part]) window.clearTimeout(scrollTimers[part]);
139
+ scrollTimers[part] = window.setTimeout(() => {
140
+ const PAD = parseFloat(getComputedStyle(el).paddingTop) || 0;
141
+ const scrollToCenter = (i) => PAD + i * ITEM_H + ITEM_H / 2 - el.clientHeight / 2;
142
+ const idx = Math.round(
143
+ (el.scrollTop + el.clientHeight / 2 - ITEM_H / 2 - PAD) / ITEM_H
144
+ );
145
+ const opts = [...el.querySelectorAll(".wd-time-picker__opt")];
146
+ const target = opts[idx];
147
+ if (!target) return;
148
+ const val = Number(target.textContent);
149
+ if (part === "hour") pickHour(val);
150
+ else if (part === "minute") pickMinute(val);
151
+ else pickSecond(val);
152
+ programmatic[part] = true;
153
+ el.scrollTo({ top: scrollToCenter(idx), behavior: "smooth" });
154
+ window.setTimeout(() => {
155
+ programmatic[part] = false;
156
+ }, 400);
157
+ }, 150);
158
+ }
159
+ const open = ref(false);
160
+ const panelId = `wd-time-picker-panel-${Math.random().toString(36).slice(2, 9)}`;
161
+ const rootEl = ref(null);
162
+ const panelEl = ref(null);
163
+ const { pos, actual } = useAnchoredPosition(open, rootEl, panelEl, {
164
+ /*
165
+ * 用 bottom-start 而不是 bottom-center:面板宽度 > 触发器宽度,
166
+ * 居中要靠面板实测宽度来算,而 v-if 首帧宽度是 0 —— 会算偏(实测偏右 220px)。
167
+ * 左对齐与触发器左边线对齐,不依赖宽度测量。
168
+ */
169
+ placement: "bottom-start",
170
+ gap: 8
171
+ });
172
+ useDismiss([rootEl, panelEl], () => {
173
+ open.value = false;
174
+ }, open);
175
+ useOverlayLayer(open, rootEl, () => {
176
+ open.value = false;
177
+ return true;
178
+ });
179
+ const hourCol = ref(null);
180
+ const minuteCol = ref(null);
181
+ const secondCol = ref(null);
182
+ watch(open, async (v) => {
183
+ if (!v) return;
184
+ await nextTick();
185
+ const [h, m, sec] = parts.value;
186
+ const scrollToVal = (col, val, list) => {
187
+ if (!col) return;
188
+ const idx = list.indexOf(val);
189
+ if (idx < 0) return;
190
+ const PAD = parseFloat(getComputedStyle(col).paddingTop) || 0;
191
+ col.scrollTop = PAD + idx * ITEM_H + ITEM_H / 2 - col.clientHeight / 2;
192
+ };
193
+ scrollToVal(hourCol.value, h, hours.value);
194
+ scrollToVal(minuteCol.value, m, minutes.value);
195
+ scrollToVal(secondCol.value, sec, seconds.value);
196
+ });
197
+ function toggle() {
198
+ if (props.disabled) return;
199
+ open.value = !open.value;
200
+ }
201
+ function onBlur(e) {
202
+ const root = e.currentTarget;
203
+ const t = e.relatedTarget;
204
+ if (root.contains(t) || panelEl.value?.contains(t)) return;
205
+ open.value = false;
206
+ }
207
+ const display = computed(() => value.value || "--:--");
208
+ return (_ctx, _cache) => {
209
+ return _openBlock(), _createElementBlock(
210
+ "div",
211
+ _mergeProps({
212
+ ref_key: "rootEl",
213
+ ref: rootEl,
214
+ class: ["wd-time-picker", [`wd-time-picker--${__props.size}`, { "is-open": open.value, "is-disabled": __props.disabled }]],
215
+ tabindex: "-1",
216
+ onBlur
217
+ }, _unref(formA11y).attrs.value),
218
+ [
219
+ _createCommentVNode(" aria-haspopup \u4E0E DatePicker(dialog) / Select(listbox) \u5BF9\u9F50\uFF1A\n \u8BFB\u5C4F\u8F6F\u4EF6\u9760\u5B83\u77E5\u9053\u300C\u6309\u4E0B\u53BB\u4F1A\u5F39\u51FA\u4E00\u4E2A\u6D6E\u5C42\u300D\uFF0C\u7F3A\u4E86\u53EA\u4F1A\u88AB\u5FF5\u6210\u666E\u901A\u6309\u94AE\u3002 "),
220
+ _createElementVNode("button", {
221
+ type: "button",
222
+ class: "wd-time-picker__trigger",
223
+ "aria-haspopup": "listbox",
224
+ "aria-expanded": open.value,
225
+ "aria-controls": open.value ? panelId : void 0,
226
+ disabled: __props.disabled,
227
+ onClick: toggle
228
+ }, [
229
+ _createElementVNode(
230
+ "span",
231
+ _hoisted_2,
232
+ _toDisplayString(display.value),
233
+ 1
234
+ /* TEXT */
235
+ ),
236
+ _createVNode(_unref(WdIcon_default), {
237
+ name: "clock",
238
+ size: 15,
239
+ class: "wd-time-picker__icon"
240
+ })
241
+ ], 8, _hoisted_1),
242
+ (_openBlock(), _createBlock(_Teleport, {
243
+ to: "body",
244
+ disabled: __props.inline
245
+ }, [
246
+ open.value ? (_openBlock(), _createElementBlock("div", {
247
+ key: 0,
248
+ id: panelId,
249
+ ref_key: "panelEl",
250
+ ref: panelEl,
251
+ class: "wd-time-picker__panel",
252
+ "data-placement": __props.inline ? void 0 : _unref(actual),
253
+ style: _normalizeStyle(__props.inline ? void 0 : { top: _unref(pos).top + "px", left: _unref(pos).left + "px" })
254
+ }, [
255
+ _createCommentVNode(" \u65F6 "),
256
+ _createElementVNode(
257
+ "div",
258
+ {
259
+ ref_key: "hourCol",
260
+ ref: hourCol,
261
+ class: "wd-time-picker__col",
262
+ role: "listbox",
263
+ "aria-label": "\u5C0F\u65F6",
264
+ onScrollPassive: _cache[0] || (_cache[0] = ($event) => onColScroll("hour", $event))
265
+ },
266
+ [
267
+ (_openBlock(true), _createElementBlock(
268
+ _Fragment,
269
+ null,
270
+ _renderList(hours.value, (h) => {
271
+ return _openBlock(), _createElementBlock("button", {
272
+ key: h,
273
+ type: "button",
274
+ role: "option",
275
+ class: _normalizeClass(["wd-time-picker__opt", { "is-on": h === parts.value[0], "is-off": hourDisabled(h) }]),
276
+ "aria-selected": h === parts.value[0],
277
+ disabled: hourDisabled(h),
278
+ onClick: ($event) => pickHour(h)
279
+ }, _toDisplayString(pad(h)), 11, _hoisted_4);
280
+ }),
281
+ 128
282
+ /* KEYED_FRAGMENT */
283
+ ))
284
+ ],
285
+ 544
286
+ /* NEED_HYDRATION, NEED_PATCH */
287
+ ),
288
+ _cache[4] || (_cache[4] = _createElementVNode(
289
+ "span",
290
+ { class: "wd-time-picker__sep" },
291
+ ":",
292
+ -1
293
+ /* CACHED */
294
+ )),
295
+ _createCommentVNode(" \u5206 "),
296
+ _createElementVNode(
297
+ "div",
298
+ {
299
+ ref_key: "minuteCol",
300
+ ref: minuteCol,
301
+ class: "wd-time-picker__col",
302
+ role: "listbox",
303
+ "aria-label": "\u5206\u949F",
304
+ onScrollPassive: _cache[1] || (_cache[1] = ($event) => onColScroll("minute", $event))
305
+ },
306
+ [
307
+ (_openBlock(true), _createElementBlock(
308
+ _Fragment,
309
+ null,
310
+ _renderList(minutes.value, (m) => {
311
+ return _openBlock(), _createElementBlock("button", {
312
+ key: m,
313
+ type: "button",
314
+ role: "option",
315
+ class: _normalizeClass(["wd-time-picker__opt", { "is-on": m === parts.value[1], "is-off": minuteDisabled(parts.value[0], m) }]),
316
+ "aria-selected": m === parts.value[1],
317
+ disabled: minuteDisabled(parts.value[0], m),
318
+ onClick: ($event) => pickMinute(m)
319
+ }, _toDisplayString(pad(m)), 11, _hoisted_5);
320
+ }),
321
+ 128
322
+ /* KEYED_FRAGMENT */
323
+ ))
324
+ ],
325
+ 544
326
+ /* NEED_HYDRATION, NEED_PATCH */
327
+ ),
328
+ __props.second ? (_openBlock(), _createElementBlock(
329
+ _Fragment,
330
+ { key: 0 },
331
+ [
332
+ _cache[3] || (_cache[3] = _createElementVNode(
333
+ "span",
334
+ { class: "wd-time-picker__sep" },
335
+ ":",
336
+ -1
337
+ /* CACHED */
338
+ )),
339
+ _createElementVNode(
340
+ "div",
341
+ {
342
+ ref_key: "secondCol",
343
+ ref: secondCol,
344
+ class: "wd-time-picker__col",
345
+ role: "listbox",
346
+ "aria-label": "\u79D2",
347
+ onScrollPassive: _cache[2] || (_cache[2] = ($event) => onColScroll("second", $event))
348
+ },
349
+ [
350
+ (_openBlock(true), _createElementBlock(
351
+ _Fragment,
352
+ null,
353
+ _renderList(seconds.value, (s) => {
354
+ return _openBlock(), _createElementBlock("button", {
355
+ key: s,
356
+ type: "button",
357
+ role: "option",
358
+ class: _normalizeClass(["wd-time-picker__opt", { "is-on": s === parts.value[2], "is-off": secondDisabled(parts.value[0], parts.value[1], s) }]),
359
+ "aria-selected": s === parts.value[2],
360
+ disabled: secondDisabled(parts.value[0], parts.value[1], s),
361
+ onClick: ($event) => pickSecond(s)
362
+ }, _toDisplayString(pad(s)), 11, _hoisted_6);
363
+ }),
364
+ 128
365
+ /* KEYED_FRAGMENT */
366
+ ))
367
+ ],
368
+ 544
369
+ /* NEED_HYDRATION, NEED_PATCH */
370
+ )
371
+ ],
372
+ 64
373
+ /* STABLE_FRAGMENT */
374
+ )) : _createCommentVNode("v-if", true)
375
+ ], 12, _hoisted_3)) : _createCommentVNode("v-if", true)
376
+ ], 8, ["disabled"]))
377
+ ],
378
+ 16
379
+ /* FULL_PROPS */
380
+ );
381
+ };
382
+ }
383
+ });
384
+
385
+ export {
386
+ WdTimePicker_default
387
+ };