@nutui/nutui 4.0.12-beta.1 → 4.0.12

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 (158) hide show
  1. package/dist/nutui.es.js +1 -1
  2. package/dist/nutui.js +1 -1
  3. package/dist/nutui.umd.js +1 -1
  4. package/dist/packages/_es/ActionSheet.js +111 -78
  5. package/dist/packages/_es/Address.js +375 -250
  6. package/dist/packages/_es/AddressList.js +354 -269
  7. package/dist/packages/_es/Animate.js +58 -41
  8. package/dist/packages/_es/Audio.js +197 -128
  9. package/dist/packages/_es/AudioOperate.js +71 -60
  10. package/dist/packages/_es/Avatar.js +89 -66
  11. package/dist/packages/_es/AvatarGroup.js +31 -23
  12. package/dist/packages/_es/Backtop.js +99 -59
  13. package/dist/packages/_es/Badge.js +47 -36
  14. package/dist/packages/_es/Barrage.js +147 -68
  15. package/dist/packages/_es/Button.js +66 -47
  16. package/dist/packages/_es/Calendar.js +157 -135
  17. package/dist/packages/_es/CalendarItem.js +6 -6
  18. package/dist/packages/_es/Card.js +56 -42
  19. package/dist/packages/_es/Cascader.js +474 -315
  20. package/dist/packages/_es/Category.js +39 -29
  21. package/dist/packages/_es/CategoryPane.js +83 -57
  22. package/dist/packages/_es/Cell.js +71 -56
  23. package/dist/packages/_es/CellGroup.js +27 -19
  24. package/dist/packages/_es/Checkbox.js +156 -109
  25. package/dist/packages/_es/CheckboxGroup.js +59 -38
  26. package/dist/packages/_es/CircleProgress.js +96 -67
  27. package/dist/packages/_es/Col.js +31 -23
  28. package/dist/packages/_es/Collapse.js +58 -33
  29. package/dist/packages/_es/CollapseItem.js +108 -78
  30. package/dist/packages/_es/Comment.js +279 -207
  31. package/dist/packages/_es/ConfigProvider.js +55 -37
  32. package/dist/packages/_es/Countdown.js +212 -100
  33. package/dist/packages/_es/Countup.js +445 -232
  34. package/dist/packages/_es/DatePicker.js +265 -162
  35. package/dist/packages/_es/Dialog.js +213 -161
  36. package/dist/packages/_es/Divider.js +57 -42
  37. package/dist/packages/_es/Drag.js +153 -70
  38. package/dist/packages/_es/Ecard.js +104 -64
  39. package/dist/packages/_es/Elevator.js +219 -143
  40. package/dist/packages/_es/Ellipsis.js +178 -95
  41. package/dist/packages/_es/Empty.js +39 -23
  42. package/dist/packages/_es/FixedNav.js +116 -93
  43. package/dist/packages/_es/Form.js +178 -107
  44. package/dist/packages/_es/FormItem.js +61 -48
  45. package/dist/packages/_es/Grid.js +6 -5
  46. package/dist/packages/_es/GridItem.js +84 -58
  47. package/dist/packages/_es/Image.js +130 -90
  48. package/dist/packages/_es/ImagePreview.js +412 -256
  49. package/dist/packages/_es/Indicator.js +34 -30
  50. package/dist/packages/_es/InfiniteLoading.js +136 -83
  51. package/dist/packages/_es/Input.js +264 -160
  52. package/dist/packages/_es/InputNumber.js +117 -81
  53. package/dist/packages/_es/Interceptor-956b24fc.js +29 -0
  54. package/dist/packages/_es/Invoice.js +130 -104
  55. package/dist/packages/_es/Layout.js +4 -3
  56. package/dist/packages/_es/List.js +215 -117
  57. package/dist/packages/_es/Menu.js +150 -95
  58. package/dist/packages/_es/MenuItem.js +154 -109
  59. package/dist/packages/_es/Navbar.js +119 -103
  60. package/dist/packages/_es/Noticebar.js +312 -197
  61. package/dist/packages/_es/Notify.js +166 -110
  62. package/dist/packages/_es/NumberKeyboard.js +202 -127
  63. package/dist/packages/_es/Overlay.js +80 -52
  64. package/dist/packages/_es/Pagination.js +100 -70
  65. package/dist/packages/_es/Picker.js +437 -275
  66. package/dist/packages/_es/Popover.js +225 -122
  67. package/dist/packages/_es/Popup.js +4 -4
  68. package/dist/packages/_es/Price.js +82 -44
  69. package/dist/packages/_es/Progress.js +79 -63
  70. package/dist/packages/_es/PullRefresh.js +173 -95
  71. package/dist/packages/_es/Radio.js +4 -4
  72. package/dist/packages/_es/RadioGroup.js +3 -3
  73. package/dist/packages/_es/Range.js +347 -204
  74. package/dist/packages/_es/Rate.js +141 -92
  75. package/dist/packages/_es/Row.js +27 -21
  76. package/dist/packages/_es/Searchbar.js +174 -123
  77. package/dist/packages/_es/ShortPassword.js +93 -69
  78. package/dist/packages/_es/SideNavbar.js +80 -49
  79. package/dist/packages/_es/SideNavbarItem.js +32 -22
  80. package/dist/packages/_es/Signature.js +146 -83
  81. package/dist/packages/_es/Skeleton.js +130 -110
  82. package/dist/packages/_es/Sku.js +343 -250
  83. package/dist/packages/_es/Step.js +86 -59
  84. package/dist/packages/_es/Steps.js +31 -26
  85. package/dist/packages/_es/Sticky.js +4 -4
  86. package/dist/packages/_es/SubSideNavbar.js +74 -52
  87. package/dist/packages/_es/Swipe.js +155 -83
  88. package/dist/packages/_es/Swiper.js +311 -174
  89. package/dist/packages/_es/SwiperItem.js +44 -28
  90. package/dist/packages/_es/Switch.js +68 -55
  91. package/dist/packages/_es/TabPane.js +41 -30
  92. package/dist/packages/_es/Tabbar.js +52 -41
  93. package/dist/packages/_es/TabbarItem.js +82 -61
  94. package/dist/packages/_es/Table.js +165 -109
  95. package/dist/packages/_es/Tabs.js +388 -240
  96. package/dist/packages/_es/Tag.js +61 -44
  97. package/dist/packages/_es/Textarea.js +124 -80
  98. package/dist/packages/_es/TimeDetail.js +76 -49
  99. package/dist/packages/_es/TimePannel.js +48 -34
  100. package/dist/packages/_es/TimeSelect.js +68 -47
  101. package/dist/packages/_es/Toast.js +218 -144
  102. package/dist/packages/_es/Tour.js +192 -138
  103. package/dist/packages/_es/TrendArrow.js +77 -57
  104. package/dist/packages/_es/Uploader.js +359 -234
  105. package/dist/packages/_es/Video.js +316 -191
  106. package/dist/packages/_es/Watermark.js +117 -84
  107. package/dist/packages/_es/_plugin-vue_export-helper-cc2b3d55.js +10 -0
  108. package/dist/packages/_es/common-b9a5e726.js +145 -0
  109. package/dist/packages/_es/component-81a4c1d0.js +145 -0
  110. package/dist/packages/_es/index-29892cda.js +33 -0
  111. package/dist/packages/_es/index-43c34ac6.js +30 -0
  112. package/dist/packages/_es/index-54d03fc1.js +8 -0
  113. package/dist/packages/_es/index-79c5dc33.js +10 -0
  114. package/dist/packages/_es/index-7a7385e4.js +67 -0
  115. package/dist/packages/_es/index-87422be8.js +942 -0
  116. package/dist/packages/_es/index-da0a7662.js +259 -0
  117. package/dist/packages/_es/index.vue_vue_type_script_lang-22dfc112.js +46 -0
  118. package/dist/packages/_es/index.vue_vue_type_script_lang-a8856969.js +97 -0
  119. package/dist/packages/_es/index.vue_vue_type_script_lang-cc5c4086.js +151 -0
  120. package/dist/packages/_es/mountComponent-8b24c346.js +39 -0
  121. package/dist/packages/_es/pxCheck-c6b9f6b7.js +6 -0
  122. package/dist/packages/_es/raf-729dad54.js +25 -0
  123. package/dist/packages/_es/renderIcon-3d0fd47c.js +9 -0
  124. package/dist/packages/locale/lang/baseLang-3a8457ac.js +5 -0
  125. package/dist/packages/locale/lang/en-US.js +39 -36
  126. package/dist/packages/locale/lang/id-ID.js +39 -36
  127. package/dist/packages/locale/lang/index.js +44 -22
  128. package/dist/packages/locale/lang/zh-CN.js +38 -35
  129. package/dist/packages/locale/lang/zh-TW.js +38 -35
  130. package/dist/resolver/index.js +26 -1
  131. package/dist/resolver/index.mjs +17 -14
  132. package/dist/smartips/web-types.json +1 -1
  133. package/dist/style.css +1 -1
  134. package/dist/styles/themes/default.scss +50 -50
  135. package/dist/styles/themes/jdb.scss +50 -50
  136. package/dist/styles/themes/jddkh.scss +50 -50
  137. package/dist/styles/themes/jdt.scss +50 -50
  138. package/dist/types/index.d.ts +1 -1
  139. package/package.json +2 -2
  140. package/dist/packages/_es/Interceptor-6e26b757.js +0 -18
  141. package/dist/packages/_es/_plugin-vue_export-helper-dad06003.js +0 -9
  142. package/dist/packages/_es/common-d218746f.js +0 -116
  143. package/dist/packages/_es/component-234624bc.js +0 -89
  144. package/dist/packages/_es/index-14dfadc4.js +0 -561
  145. package/dist/packages/_es/index-192a3ef6.js +0 -29
  146. package/dist/packages/_es/index-360c5092.js +0 -210
  147. package/dist/packages/_es/index-496e6e05.js +0 -24
  148. package/dist/packages/_es/index-50eed3d9.js +0 -7
  149. package/dist/packages/_es/index-53ec2d4d.js +0 -34
  150. package/dist/packages/_es/index-fadb0974.js +0 -8
  151. package/dist/packages/_es/index.vue_vue_type_script_lang-1139b29a.js +0 -43
  152. package/dist/packages/_es/index.vue_vue_type_script_lang-43b774dd.js +0 -77
  153. package/dist/packages/_es/index.vue_vue_type_script_lang-f44c159d.js +0 -110
  154. package/dist/packages/_es/mountComponent-6d4ff200.js +0 -23
  155. package/dist/packages/_es/pxCheck-38173291.js +0 -4
  156. package/dist/packages/_es/raf-a74f1a06.js +0 -16
  157. package/dist/packages/_es/renderIcon-47498b32.js +0 -5
  158. package/dist/packages/locale/lang/baseLang-0bdc6353.js +0 -5
@@ -1,120 +1,178 @@
1
- var le = Object.defineProperty, oe = Object.defineProperties;
2
- var ae = Object.getOwnPropertyDescriptors;
3
- var Q = Object.getOwnPropertySymbols;
4
- var re = Object.prototype.hasOwnProperty, se = Object.prototype.propertyIsEnumerable;
5
- var W = (e, n, a) => n in e ? le(e, n, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[n] = a, B = (e, n) => {
6
- for (var a in n || (n = {}))
7
- re.call(n, a) && W(e, a, n[a]);
8
- if (Q)
9
- for (var a of Q(n))
10
- se.call(n, a) && W(e, a, n[a]);
11
- return e;
12
- }, L = (e, n) => oe(e, ae(n));
13
- import { reactive as x, ref as $, computed as b, watch as E, toRefs as J, onMounted as ue, openBlock as S, createElementBlock as D, createElementVNode as N, normalizeStyle as I, Fragment as U, renderList as _, normalizeClass as ee, toDisplayString as R, createCommentVNode as j, resolveComponent as ie, renderSlot as X, createVNode as ce } from "vue";
14
- import { c as q, d as Z, e as me } from "./component-234624bc.js";
15
- import { p as de } from "./pxCheck-38173291.js";
16
- import { u as he } from "./index-53ec2d4d.js";
17
- import { _ as te } from "./_plugin-vue_export-helper-dad06003.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import { reactive, ref, computed, watch, toRefs, onMounted, openBlock, createElementBlock, createElementVNode, normalizeStyle, Fragment, renderList, normalizeClass, toDisplayString, createCommentVNode, resolveComponent, renderSlot, createVNode } from "vue";
21
+ import { c as createComponent, d as preventDefault, e as clamp } from "./component-81a4c1d0.js";
22
+ import { p as pxCheck } from "./pxCheck-c6b9f6b7.js";
23
+ import { u as useTouch } from "./index-7a7385e4.js";
24
+ import { _ as _export_sfc } from "./_plugin-vue_export-helper-cc2b3d55.js";
18
25
  import "../locale/lang";
19
- const { componentName: fe } = q("picker"), ve = (e, n) => {
20
- const a = x({
21
- formattedColumns: e.columns
22
- }), t = $([]), y = $([]), p = (l) => {
23
- l && y.value.length < d.value.length && y.value.push(l);
24
- }, r = b(() => ({
25
- [fe]: !0
26
- })), s = b(() => d.value.map((l, c) => l.find((T) => T.value === t.value[c]))), g = b(() => {
27
- const l = a.formattedColumns[0];
28
- if (l) {
29
- if (Array.isArray(l))
26
+ const { componentName: componentName$1 } = createComponent("picker");
27
+ const usePicker = (props, emit) => {
28
+ const state = reactive({
29
+ formattedColumns: props.columns
30
+ });
31
+ const defaultValues = ref([]);
32
+ const pickerColumn = ref([]);
33
+ const swipeRef = (el) => {
34
+ if (el && pickerColumn.value.length < columnsList.value.length) {
35
+ pickerColumn.value.push(el);
36
+ }
37
+ };
38
+ const classes = computed(() => {
39
+ const prefixCls = componentName$1;
40
+ return {
41
+ [prefixCls]: true
42
+ };
43
+ });
44
+ const selectedOptions = computed(() => {
45
+ return columnsList.value.map((column2, index) => {
46
+ return column2.find((item) => item.value === defaultValues.value[index]);
47
+ });
48
+ });
49
+ const columnsType = computed(() => {
50
+ const firstColumn = state.formattedColumns[0];
51
+ if (firstColumn) {
52
+ if (Array.isArray(firstColumn)) {
30
53
  return "multiple";
31
- if ("children" in l)
54
+ }
55
+ if ("children" in firstColumn) {
32
56
  return "cascade";
57
+ }
33
58
  }
34
59
  return "single";
35
- }), d = b(() => {
36
- switch (g.value) {
60
+ });
61
+ const columnsList = computed(() => {
62
+ switch (columnsType.value) {
37
63
  case "multiple":
38
- return a.formattedColumns;
64
+ return state.formattedColumns;
39
65
  case "cascade":
40
- return H(a.formattedColumns, t.value ? t.value : []);
66
+ return formatCascade(state.formattedColumns, defaultValues.value ? defaultValues.value : []);
41
67
  default:
42
- return [a.formattedColumns];
68
+ return [state.formattedColumns];
43
69
  }
44
- }), H = (l, c) => {
45
- const T = [];
46
- let u = {
70
+ });
71
+ const formatCascade = (columns, defaultValues2) => {
72
+ const formatted = [];
73
+ let cursor = {
47
74
  text: "",
48
75
  value: "",
49
- children: l
50
- }, z = 0;
51
- for (; u && u.children; ) {
52
- const P = u.children, w = c[z];
53
- let C = P.findIndex((O) => O.value === w);
54
- C === -1 && (C = 0), u = u.children[C], z++, T.push(P);
76
+ children: columns
77
+ };
78
+ let columnIndex = 0;
79
+ while (cursor && cursor.children) {
80
+ const options = cursor.children;
81
+ const value = defaultValues2[columnIndex];
82
+ let index = options.findIndex((columnItem) => columnItem.value === value);
83
+ if (index === -1)
84
+ index = 0;
85
+ cursor = cursor.children[index];
86
+ columnIndex++;
87
+ formatted.push(options);
55
88
  }
56
- return T;
57
- }, M = () => {
58
- n("cancel", {
59
- selectedValue: t.value,
60
- selectedOptions: s.value
89
+ return formatted;
90
+ };
91
+ const cancel = () => {
92
+ emit("cancel", {
93
+ selectedValue: defaultValues.value,
94
+ selectedOptions: selectedOptions.value
61
95
  });
62
- }, A = (l, c) => {
63
- if (c && Object.keys(c).length) {
64
- if (t.value = t.value ? t.value : [], g.value === "cascade") {
65
- t.value[l] = c.value ? c.value : "";
66
- let T = l, u = c;
67
- for (; u && u.children && u.children[0]; )
68
- t.value[T + 1] = u.children[0].value, T++, u = u.children[0];
69
- u && u.children && u.children.length === 0 && (t.value = t.value.slice(0, T + 1));
70
- } else
71
- t.value[l] = c.hasOwnProperty("value") ? c.value : "";
72
- n("change", {
73
- columnIndex: l,
74
- selectedValue: t.value,
75
- selectedOptions: s.value
96
+ };
97
+ const changeHandler = (columnIndex, option) => {
98
+ if (option && Object.keys(option).length) {
99
+ defaultValues.value = defaultValues.value ? defaultValues.value : [];
100
+ if (columnsType.value === "cascade") {
101
+ defaultValues.value[columnIndex] = option.value ? option.value : "";
102
+ let index = columnIndex;
103
+ let cursor = option;
104
+ while (cursor && cursor.children && cursor.children[0]) {
105
+ defaultValues.value[index + 1] = cursor.children[0].value;
106
+ index++;
107
+ cursor = cursor.children[0];
108
+ }
109
+ if (cursor && cursor.children && cursor.children.length === 0) {
110
+ defaultValues.value = defaultValues.value.slice(0, index + 1);
111
+ }
112
+ } else {
113
+ defaultValues.value[columnIndex] = option.hasOwnProperty("value") ? option.value : "";
114
+ }
115
+ emit("change", {
116
+ columnIndex,
117
+ selectedValue: defaultValues.value,
118
+ selectedOptions: selectedOptions.value
119
+ });
120
+ }
121
+ };
122
+ const confirm = () => {
123
+ if (defaultValues.value && !defaultValues.value.length) {
124
+ columnsList.value.forEach((columns) => {
125
+ defaultValues.value.push(columns[0].value);
76
126
  });
77
127
  }
78
- }, f = () => {
79
- t.value && !t.value.length && d.value.forEach((l) => {
80
- t.value.push(l[0].value);
81
- }), n("confirm", {
82
- selectedValue: t.value,
83
- selectedOptions: s.value
128
+ emit("confirm", {
129
+ selectedValue: defaultValues.value,
130
+ selectedOptions: selectedOptions.value
84
131
  });
85
- }, Y = (l, c) => JSON.stringify(l) === JSON.stringify(c);
86
- return E(
87
- () => e.modelValue,
88
- (l) => {
89
- Y(l, t.value) || (t.value = l);
132
+ };
133
+ const isSameValue = (valA, valB) => JSON.stringify(valA) === JSON.stringify(valB);
134
+ watch(
135
+ () => props.modelValue,
136
+ (newValues) => {
137
+ if (!isSameValue(newValues, defaultValues.value)) {
138
+ defaultValues.value = newValues;
139
+ }
90
140
  },
91
- { deep: !0, immediate: !0 }
92
- ), E(
93
- t,
94
- (l) => {
95
- Y(l, e.modelValue) || n("update:modelValue", l);
141
+ { deep: true, immediate: true }
142
+ );
143
+ watch(
144
+ defaultValues,
145
+ (newValues) => {
146
+ if (!isSameValue(newValues, props.modelValue)) {
147
+ emit("update:modelValue", newValues);
148
+ }
96
149
  },
97
- { deep: !0 }
98
- ), E(
99
- () => e.columns,
100
- (l) => {
101
- l.length && (a.formattedColumns = l);
150
+ { deep: true }
151
+ );
152
+ watch(
153
+ () => props.columns,
154
+ (val) => {
155
+ if (val.length)
156
+ state.formattedColumns = val;
102
157
  }
103
- ), L(B({
104
- classes: r
105
- }, J(a)), {
106
- columnsType: g,
107
- columnsList: d,
108
- cancel: M,
109
- changeHandler: A,
110
- confirm: f,
111
- defaultValues: t,
112
- pickerColumn: y,
113
- swipeRef: p,
114
- selectedOptions: s,
115
- isSameValue: Y
158
+ );
159
+ return __spreadProps(__spreadValues({
160
+ classes
161
+ }, toRefs(state)), {
162
+ columnsType,
163
+ columnsList,
164
+ cancel,
165
+ changeHandler,
166
+ confirm,
167
+ defaultValues,
168
+ pickerColumn,
169
+ swipeRef,
170
+ selectedOptions,
171
+ isSameValue
116
172
  });
117
- }, { create: pe } = q("picker-column"), ge = pe({
173
+ };
174
+ const { create: create$1 } = createComponent("picker-column");
175
+ const _sfc_main$1 = create$1({
118
176
  props: {
119
177
  // 当前选中项
120
178
  value: [String, Number],
@@ -126,7 +184,7 @@ const { componentName: fe } = q("picker"), ve = (e, n) => {
126
184
  // 是否开启3D效果
127
185
  threeDimensional: {
128
186
  type: Boolean,
129
- default: !0
187
+ default: true
130
188
  },
131
189
  swipeDuration: {
132
190
  type: [Number, String],
@@ -142,8 +200,9 @@ const { componentName: fe } = q("picker"), ve = (e, n) => {
142
200
  }
143
201
  },
144
202
  emits: ["click", "change"],
145
- setup(e, { emit: n }) {
146
- const a = he(), t = x({
203
+ setup(props, { emit }) {
204
+ const touch = useTouch();
205
+ const state = reactive({
147
206
  touchParams: {
148
207
  startY: 0,
149
208
  endY: 0,
@@ -156,141 +215,227 @@ const { componentName: fe } = q("picker"), ve = (e, n) => {
156
215
  transformY: 0,
157
216
  scrollDistance: 0,
158
217
  rotation: 20
159
- }), y = $(null), p = $(!1), r = $(0), s = $(0), g = 200, d = 300, H = 15, M = b(() => ({
160
- transition: `transform ${s.value}ms cubic-bezier(0.17, 0.89, 0.45, 1)`,
161
- transform: `rotate3d(1, 0, 0, ${r.value})`,
162
- top: `calc(50% - ${+e.optionHeight / 2}px)`
163
- })), A = b(() => {
164
- const { optionHeight: o } = e;
218
+ });
219
+ const roller = ref(null);
220
+ const moving = ref(false);
221
+ const touchDeg = ref(0);
222
+ const touchTime = ref(0);
223
+ const DEFAULT_DURATION = 200;
224
+ const INERTIA_TIME = 300;
225
+ const INERTIA_DISTANCE = 15;
226
+ const touchRollerStyle = computed(() => {
227
+ return {
228
+ transition: `transform ${touchTime.value}ms cubic-bezier(0.17, 0.89, 0.45, 1)`,
229
+ transform: `rotate3d(1, 0, 0, ${touchDeg.value})`,
230
+ top: `calc(50% - ${+props.optionHeight / 2}px)`
231
+ };
232
+ });
233
+ const touchTileStyle = computed(() => {
234
+ const { optionHeight } = props;
235
+ return {
236
+ transition: `transform ${touchTime.value}ms cubic-bezier(0.17, 0.89, 0.45, 1)`,
237
+ transform: `translate3d(0, ${state.scrollDistance}px, 0)`,
238
+ top: `calc(50% - ${+optionHeight / 2}px)`,
239
+ height: `${optionHeight}px`
240
+ };
241
+ });
242
+ const setRollerStyle = (index) => {
243
+ return `transform: rotate3d(1, 0, 0, ${-state.rotation * index}deg) translate3d(0px, 0px, 104px)`;
244
+ };
245
+ const maskStyles = computed(() => {
165
246
  return {
166
- transition: `transform ${s.value}ms cubic-bezier(0.17, 0.89, 0.45, 1)`,
167
- transform: `translate3d(0, ${t.scrollDistance}px, 0)`,
168
- top: `calc(50% - ${+o / 2}px)`,
169
- height: `${o}px`
247
+ backgroundSize: `100% ${(+props.visibleOptionNum - 1) * +props.optionHeight / 2}px`
170
248
  };
171
- }), f = (o) => `transform: rotate3d(1, 0, 0, ${-t.rotation * o}deg) translate3d(0px, 0px, 104px)`, Y = b(() => ({
172
- backgroundSize: `100% ${(+e.visibleOptionNum - 1) * +e.optionHeight / 2}px`
173
- })), l = (o) => {
174
- if (a.start(o), p.value) {
175
- let m = y.value;
176
- const { transform: i } = window.getComputedStyle(m);
177
- if (e.threeDimensional) {
178
- const h = Math.floor(parseInt(r.value) / 360), v = +i.split(", ")[5], k = +i.split(", ")[6] < 0 ? 180 : 0, V = h * 360 + Math.acos(v) / Math.PI * 180 + k;
179
- t.scrollDistance = -Math.abs((V / t.rotation - 1) * +e.optionHeight);
180
- } else
181
- t.scrollDistance = +i.slice(7, i.length - 1).split(", ")[5];
249
+ });
250
+ const onTouchStart = (event) => {
251
+ touch.start(event);
252
+ if (moving.value) {
253
+ let dom = roller.value;
254
+ const { transform } = window.getComputedStyle(dom);
255
+ if (props.threeDimensional) {
256
+ const circle = Math.floor(parseInt(touchDeg.value) / 360);
257
+ const cos = +transform.split(", ")[5];
258
+ const sin = +transform.split(", ")[6] < 0 ? 180 : 0;
259
+ const endDeg = circle * 360 + Math.acos(cos) / Math.PI * 180 + sin;
260
+ state.scrollDistance = -Math.abs((endDeg / state.rotation - 1) * +props.optionHeight);
261
+ } else {
262
+ state.scrollDistance = +transform.slice(7, transform.length - 1).split(", ")[5];
263
+ }
264
+ }
265
+ preventDefault(event, true);
266
+ state.touchParams.startY = touch.deltaY.value;
267
+ state.touchParams.startTime = Date.now();
268
+ state.transformY = state.scrollDistance;
269
+ };
270
+ const onTouchMove = (event) => {
271
+ touch.move(event);
272
+ if (touch.isVertical()) {
273
+ moving.value = true;
274
+ preventDefault(event, true);
182
275
  }
183
- Z(o, !0), t.touchParams.startY = a.deltaY.value, t.touchParams.startTime = Date.now(), t.transformY = t.scrollDistance;
184
- }, c = (o) => {
185
- a.move(o), a.isVertical() && (p.value = !0, Z(o, !0)), t.touchParams.lastY = a.deltaY.value;
186
- let m = t.touchParams.lastY - t.touchParams.startY;
187
- w(m);
188
- }, T = () => {
189
- t.touchParams.lastY = a.deltaY.value, t.touchParams.lastTime = Date.now();
190
- let o = t.touchParams.lastY - t.touchParams.startY, m = t.touchParams.lastTime - t.touchParams.startTime;
191
- if (m <= d && Math.abs(o) > H) {
192
- const i = u(o, m);
193
- w(i, "end", +e.swipeDuration);
276
+ state.touchParams.lastY = touch.deltaY.value;
277
+ let move = state.touchParams.lastY - state.touchParams.startY;
278
+ setMove(move);
279
+ };
280
+ const onTouchEnd = () => {
281
+ state.touchParams.lastY = touch.deltaY.value;
282
+ state.touchParams.lastTime = Date.now();
283
+ let move = state.touchParams.lastY - state.touchParams.startY;
284
+ let moveTime = state.touchParams.lastTime - state.touchParams.startTime;
285
+ if (moveTime <= INERTIA_TIME && Math.abs(move) > INERTIA_DISTANCE) {
286
+ const distance = momentum(move, moveTime);
287
+ setMove(distance, "end", +props.swipeDuration);
194
288
  return;
195
- } else
196
- w(o, "end");
289
+ } else {
290
+ setMove(move, "end");
291
+ }
197
292
  setTimeout(() => {
198
- a.reset(), p.value = !1;
293
+ touch.reset();
294
+ moving.value = false;
199
295
  }, 0);
200
- }, u = (o, m) => (o = Math.abs(o / m) / 3e-3 * (o < 0 ? -1 : 1), o), z = (o) => o >= t.currIndex + 8 || o <= t.currIndex - 8, P = (o = 0, m, i = g, h) => {
201
- m === "end" ? s.value = i : s.value = 0, r.value = h, t.scrollDistance = o;
202
- }, w = (o, m, i) => {
203
- const { optionHeight: h } = e;
204
- let v = o + t.transformY;
205
- if (m === "end") {
206
- v > 0 && (v = 0), v < -(e.column.length - 1) * +h && (v = -(e.column.length - 1) * +h);
207
- let k = Math.round(v / +h) * +h, V = `${(Math.abs(Math.round(k / +h)) + 1) * t.rotation}deg`;
208
- P(k, m, i, V), t.currIndex = Math.abs(Math.round(k / +h)) + 1;
296
+ };
297
+ const momentum = (distance, duration) => {
298
+ const speed = Math.abs(distance / duration);
299
+ distance = speed / 3e-3 * (distance < 0 ? -1 : 1);
300
+ return distance;
301
+ };
302
+ const isHidden = (index) => {
303
+ if (index >= state.currIndex + 8 || index <= state.currIndex - 8) {
304
+ return true;
305
+ } else {
306
+ return false;
307
+ }
308
+ };
309
+ const setTransform = (translateY = 0, type, time = DEFAULT_DURATION, deg) => {
310
+ if (type === "end") {
311
+ touchTime.value = time;
312
+ } else {
313
+ touchTime.value = 0;
314
+ }
315
+ touchDeg.value = deg;
316
+ state.scrollDistance = translateY;
317
+ };
318
+ const setMove = (move, type, time) => {
319
+ const { optionHeight } = props;
320
+ let updateMove = move + state.transformY;
321
+ if (type === "end") {
322
+ if (updateMove > 0) {
323
+ updateMove = 0;
324
+ }
325
+ if (updateMove < -(props.column.length - 1) * +optionHeight) {
326
+ updateMove = -(props.column.length - 1) * +optionHeight;
327
+ }
328
+ let endMove = Math.round(updateMove / +optionHeight) * +optionHeight;
329
+ let deg = `${(Math.abs(Math.round(endMove / +optionHeight)) + 1) * state.rotation}deg`;
330
+ setTransform(endMove, type, time, deg);
331
+ state.currIndex = Math.abs(Math.round(endMove / +optionHeight)) + 1;
209
332
  } else {
210
- let k = 0, V = (-v / +h + 1) * t.rotation;
211
- const G = (e.column.length + 1) * t.rotation, K = 0;
212
- k = me(V, K, G), K < k && k < G && (P(v, null, void 0, k + "deg"), t.currIndex = Math.abs(Math.round(v / +h)) + 1);
333
+ let deg = 0;
334
+ let currentDeg = (-updateMove / +optionHeight + 1) * state.rotation;
335
+ const maxDeg = (props.column.length + 1) * state.rotation;
336
+ const minDeg = 0;
337
+ deg = clamp(currentDeg, minDeg, maxDeg);
338
+ if (minDeg < deg && deg < maxDeg) {
339
+ setTransform(updateMove, null, void 0, deg + "deg");
340
+ state.currIndex = Math.abs(Math.round(updateMove / +optionHeight)) + 1;
341
+ }
213
342
  }
214
- }, C = () => {
215
- n("change", e.column[t.currIndex - 1]);
216
- }, O = (o) => {
217
- const { column: m } = e;
218
- let i = m.findIndex((v) => v.value === e.value);
219
- t.currIndex = i === -1 ? 1 : i + 1;
220
- let h = i === -1 ? 0 : i * +e.optionHeight;
221
- o && C(), w(-h);
222
- }, ne = () => {
223
- p.value = !1, s.value = 0, C();
224
343
  };
225
- return E(
226
- () => e.column,
227
- (o) => {
228
- e.column && e.column.length > 0 && (t.transformY = 0, O(!1));
344
+ const setChooseValue = () => {
345
+ emit("change", props.column[state.currIndex - 1]);
346
+ };
347
+ const modifyStatus = (type) => {
348
+ const { column: column2 } = props;
349
+ let index = column2.findIndex((columnItem) => columnItem.value === props.value);
350
+ state.currIndex = index === -1 ? 1 : index + 1;
351
+ let move = index === -1 ? 0 : index * +props.optionHeight;
352
+ type && setChooseValue();
353
+ setMove(-move);
354
+ };
355
+ const stopMomentum = () => {
356
+ moving.value = false;
357
+ touchTime.value = 0;
358
+ setChooseValue();
359
+ };
360
+ watch(
361
+ () => props.column,
362
+ (val) => {
363
+ if (props.column && props.column.length > 0) {
364
+ state.transformY = 0;
365
+ modifyStatus(false);
366
+ }
229
367
  },
230
368
  {
231
- deep: !0
369
+ deep: true
232
370
  }
233
- ), E(
234
- () => e.value,
235
- (o) => {
236
- t.transformY = 0, O(!1);
371
+ );
372
+ watch(
373
+ () => props.value,
374
+ (val) => {
375
+ state.transformY = 0;
376
+ modifyStatus(false);
237
377
  },
238
378
  {
239
- deep: !0
379
+ deep: true
240
380
  }
241
- ), ue(() => {
242
- O(!0);
243
- }), L(B(B({}, J(t)), J(e)), {
244
- setRollerStyle: f,
245
- isHidden: z,
246
- roller: y,
247
- onTouchStart: l,
248
- onTouchMove: c,
249
- onTouchEnd: T,
250
- touchRollerStyle: M,
251
- touchTileStyle: A,
252
- setMove: w,
253
- stopMomentum: ne,
254
- pxCheck: de,
255
- maskStyles: Y
381
+ );
382
+ onMounted(() => {
383
+ modifyStatus(true);
384
+ });
385
+ return __spreadProps(__spreadValues(__spreadValues({}, toRefs(state)), toRefs(props)), {
386
+ setRollerStyle,
387
+ isHidden,
388
+ roller,
389
+ onTouchStart,
390
+ onTouchMove,
391
+ onTouchEnd,
392
+ touchRollerStyle,
393
+ touchTileStyle,
394
+ setMove,
395
+ stopMomentum,
396
+ pxCheck,
397
+ maskStyles
256
398
  });
257
399
  }
258
400
  });
259
- function ye(e, n, a, t, y, p) {
260
- return S(), D("view", {
401
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
402
+ return openBlock(), createElementBlock("view", {
261
403
  class: "nut-picker__list",
262
- onTouchstart: n[1] || (n[1] = (...r) => e.onTouchStart && e.onTouchStart(...r)),
263
- onTouchmove: n[2] || (n[2] = (...r) => e.onTouchMove && e.onTouchMove(...r)),
264
- onTouchend: n[3] || (n[3] = (...r) => e.onTouchEnd && e.onTouchEnd(...r))
404
+ onTouchstart: _cache[1] || (_cache[1] = (...args) => _ctx.onTouchStart && _ctx.onTouchStart(...args)),
405
+ onTouchmove: _cache[2] || (_cache[2] = (...args) => _ctx.onTouchMove && _ctx.onTouchMove(...args)),
406
+ onTouchend: _cache[3] || (_cache[3] = (...args) => _ctx.onTouchEnd && _ctx.onTouchEnd(...args))
265
407
  }, [
266
- N("view", {
408
+ createElementVNode("view", {
267
409
  class: "nut-picker-roller",
268
410
  ref: "roller",
269
- style: I(e.threeDimensional ? e.touchRollerStyle : e.touchTileStyle),
270
- onTransitionend: n[0] || (n[0] = (...r) => e.stopMomentum && e.stopMomentum(...r))
411
+ style: normalizeStyle(_ctx.threeDimensional ? _ctx.touchRollerStyle : _ctx.touchTileStyle),
412
+ onTransitionend: _cache[0] || (_cache[0] = (...args) => _ctx.stopMomentum && _ctx.stopMomentum(...args))
271
413
  }, [
272
- (S(!0), D(U, null, _(e.column, (r, s) => (S(), D(U, {
273
- key: r.value ? r.value : s
274
- }, [
275
- r && r.text && e.threeDimensional ? (S(), D("view", {
276
- key: 0,
277
- class: ee(["nut-picker-roller-item", { "nut-picker-roller-item-hidden": e.isHidden(s + 1) }]),
278
- style: I(e.setRollerStyle(s + 1))
279
- }, R(r.text), 7)) : j("", !0),
280
- r && r.text && !e.threeDimensional ? (S(), D("view", {
281
- key: 1,
282
- class: "nut-picker-roller-item-tile",
283
- style: I({ height: e.pxCheck(e.optionHeight), lineHeight: e.pxCheck(e.optionHeight) })
284
- }, R(r.text), 5)) : j("", !0)
285
- ], 64))), 128))
414
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.column, (item, index) => {
415
+ return openBlock(), createElementBlock(Fragment, {
416
+ key: item.value ? item.value : index
417
+ }, [
418
+ item && item.text && _ctx.threeDimensional ? (openBlock(), createElementBlock("view", {
419
+ key: 0,
420
+ class: normalizeClass(["nut-picker-roller-item", { "nut-picker-roller-item-hidden": _ctx.isHidden(index + 1) }]),
421
+ style: normalizeStyle(_ctx.setRollerStyle(index + 1))
422
+ }, toDisplayString(item.text), 7)) : createCommentVNode("", true),
423
+ item && item.text && !_ctx.threeDimensional ? (openBlock(), createElementBlock("view", {
424
+ key: 1,
425
+ class: "nut-picker-roller-item-tile",
426
+ style: normalizeStyle({ height: _ctx.pxCheck(_ctx.optionHeight), lineHeight: _ctx.pxCheck(_ctx.optionHeight) })
427
+ }, toDisplayString(item.text), 5)) : createCommentVNode("", true)
428
+ ], 64);
429
+ }), 128))
286
430
  ], 36),
287
- N("view", {
431
+ createElementVNode("view", {
288
432
  class: "nut-picker-roller-mask",
289
- style: I(e.maskStyles)
433
+ style: normalizeStyle(_ctx.maskStyles)
290
434
  }, null, 4)
291
435
  ], 32);
292
436
  }
293
- const F = /* @__PURE__ */ te(ge, [["render", ye]]), Te = {
437
+ const column = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
438
+ const baseProps = {
294
439
  modelValue: {
295
440
  type: Array,
296
441
  default: () => []
@@ -309,11 +454,13 @@ const F = /* @__PURE__ */ te(ge, [["render", ye]]), Te = {
309
454
  },
310
455
  columns: {
311
456
  type: Array,
312
- default: () => []
457
+ default: () => {
458
+ return [];
459
+ }
313
460
  },
314
461
  threeDimensional: {
315
462
  type: Boolean,
316
- default: !0
463
+ default: true
317
464
  },
318
465
  swipeDuration: {
319
466
  type: [Number, String],
@@ -321,7 +468,7 @@ const F = /* @__PURE__ */ te(ge, [["render", ye]]), Te = {
321
468
  },
322
469
  showToolbar: {
323
470
  type: Boolean,
324
- default: !0
471
+ default: true
325
472
  },
326
473
  visibleOptionNum: {
327
474
  type: [Number, String],
@@ -331,87 +478,102 @@ const F = /* @__PURE__ */ te(ge, [["render", ye]]), Te = {
331
478
  type: [Number, String],
332
479
  default: 36
333
480
  }
334
- }, { componentName: Ve, create: ke, translate: Se } = q("picker"), De = ke({
481
+ };
482
+ const { componentName, create, translate } = createComponent("picker");
483
+ const _sfc_main = create({
335
484
  components: {
336
- [F.name]: F
485
+ [column.name]: column
337
486
  },
338
- props: Te,
487
+ props: baseProps,
339
488
  emits: ["cancel", "change", "confirm", "update:modelValue"],
340
- setup(e, { emit: n }) {
341
- const { changeHandler: a, confirm: t, defaultValues: y, columnsList: p, columnsType: r, classes: s, cancel: g } = ve(e, n), d = $([]), H = (f) => {
342
- f && d.value.length < p.value.length && d.value.push(f);
343
- }, M = b(() => {
344
- const f = {};
345
- return f.height = `${+e.visibleOptionNum * +e.optionHeight}px`, f["--lineHeight"] = `${+e.optionHeight}px`, f;
489
+ setup(props, { emit }) {
490
+ const { changeHandler, confirm, defaultValues, columnsList, columnsType, classes, cancel } = usePicker(props, emit);
491
+ const pickerColumn = ref([]);
492
+ const swipeRef = (el) => {
493
+ if (el && pickerColumn.value.length < columnsList.value.length) {
494
+ pickerColumn.value.push(el);
495
+ }
496
+ };
497
+ const columnStyle = computed(() => {
498
+ const styles = {};
499
+ styles.height = `${+props.visibleOptionNum * +props.optionHeight}px`;
500
+ styles["--lineHeight"] = `${+props.optionHeight}px`;
501
+ return styles;
346
502
  });
503
+ const confirmHandler = () => {
504
+ pickerColumn.value.length > 0 && pickerColumn.value.forEach((column2) => {
505
+ column2.stopMomentum();
506
+ });
507
+ confirm();
508
+ };
347
509
  return {
348
- classes: s,
349
- column: F,
350
- columnsType: r,
351
- columnsList: p,
352
- cancel: g,
353
- changeHandler: a,
354
- confirmHandler: () => {
355
- d.value.length > 0 && d.value.forEach((f) => {
356
- f.stopMomentum();
357
- }), t();
358
- },
359
- defaultValues: y,
360
- translate: Se,
361
- pickerColumn: d,
362
- swipeRef: H,
363
- columnStyle: M
510
+ classes,
511
+ column,
512
+ columnsType,
513
+ columnsList,
514
+ cancel,
515
+ changeHandler,
516
+ confirmHandler,
517
+ defaultValues,
518
+ translate,
519
+ pickerColumn,
520
+ swipeRef,
521
+ columnStyle
364
522
  };
365
523
  }
366
- }), be = {
524
+ });
525
+ const _hoisted_1 = {
367
526
  key: 0,
368
527
  class: "nut-picker__bar"
369
- }, we = { class: "nut-picker__title" };
370
- function $e(e, n, a, t, y, p) {
371
- const r = ie("nut-picker-column");
372
- return S(), D("div", {
373
- class: ee(e.classes)
528
+ };
529
+ const _hoisted_2 = { class: "nut-picker__title" };
530
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
531
+ const _component_nut_picker_column = resolveComponent("nut-picker-column");
532
+ return openBlock(), createElementBlock("div", {
533
+ class: normalizeClass(_ctx.classes)
374
534
  }, [
375
- e.showToolbar ? (S(), D("view", be, [
376
- N("view", {
535
+ _ctx.showToolbar ? (openBlock(), createElementBlock("view", _hoisted_1, [
536
+ createElementVNode("view", {
377
537
  class: "nut-picker__left",
378
- onClick: n[0] || (n[0] = (...s) => e.cancel && e.cancel(...s))
379
- }, R(e.cancelText || e.translate("cancel")), 1),
380
- N("view", we, R(e.title), 1),
381
- N("view", {
538
+ onClick: _cache[0] || (_cache[0] = (...args) => _ctx.cancel && _ctx.cancel(...args))
539
+ }, toDisplayString(_ctx.cancelText || _ctx.translate("cancel")), 1),
540
+ createElementVNode("view", _hoisted_2, toDisplayString(_ctx.title), 1),
541
+ createElementVNode("view", {
382
542
  class: "nut-picker__right",
383
- onClick: n[1] || (n[1] = (s) => e.confirmHandler())
384
- }, R(e.okText || e.translate("confirm")), 1)
385
- ])) : j("", !0),
386
- X(e.$slots, "top"),
387
- N("view", {
543
+ onClick: _cache[1] || (_cache[1] = ($event) => _ctx.confirmHandler())
544
+ }, toDisplayString(_ctx.okText || _ctx.translate("confirm")), 1)
545
+ ])) : createCommentVNode("", true),
546
+ renderSlot(_ctx.$slots, "top"),
547
+ createElementVNode("view", {
388
548
  class: "nut-picker__column",
389
- style: I(e.columnStyle)
549
+ style: normalizeStyle(_ctx.columnStyle)
390
550
  }, [
391
- (S(!0), D(U, null, _(e.columnsList, (s, g) => (S(), D("view", {
392
- class: "nut-picker__columnitem",
393
- key: g
394
- }, [
395
- ce(r, {
396
- ref_for: !0,
397
- ref: e.swipeRef,
398
- column: s,
399
- columnsType: e.columnsType,
400
- value: e.defaultValues && e.defaultValues[g],
401
- threeDimensional: e.threeDimensional,
402
- swipeDuration: e.swipeDuration,
403
- visibleOptionNum: e.visibleOptionNum,
404
- optionHeight: e.optionHeight,
405
- onChange: (d) => {
406
- e.changeHandler(g, d);
407
- }
408
- }, null, 8, ["column", "columnsType", "value", "threeDimensional", "swipeDuration", "visibleOptionNum", "optionHeight", "onChange"])
409
- ]))), 128))
551
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.columnsList, (column2, columnIndex) => {
552
+ return openBlock(), createElementBlock("view", {
553
+ class: "nut-picker__columnitem",
554
+ key: columnIndex
555
+ }, [
556
+ createVNode(_component_nut_picker_column, {
557
+ ref_for: true,
558
+ ref: _ctx.swipeRef,
559
+ column: column2,
560
+ columnsType: _ctx.columnsType,
561
+ value: _ctx.defaultValues && _ctx.defaultValues[columnIndex],
562
+ threeDimensional: _ctx.threeDimensional,
563
+ swipeDuration: _ctx.swipeDuration,
564
+ visibleOptionNum: _ctx.visibleOptionNum,
565
+ optionHeight: _ctx.optionHeight,
566
+ onChange: (option) => {
567
+ _ctx.changeHandler(columnIndex, option);
568
+ }
569
+ }, null, 8, ["column", "columnsType", "value", "threeDimensional", "swipeDuration", "visibleOptionNum", "optionHeight", "onChange"])
570
+ ]);
571
+ }), 128))
410
572
  ], 4),
411
- X(e.$slots, "default")
573
+ renderSlot(_ctx.$slots, "default")
412
574
  ], 2);
413
575
  }
414
- const Ie = /* @__PURE__ */ te(De, [["render", $e]]);
576
+ const Picker = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
415
577
  export {
416
- Ie as default
578
+ Picker as default
417
579
  };