y-design-ssr 0.2.4 → 0.2.6

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 (213) hide show
  1. package/README.md +21 -16
  2. package/libs/button/index.css +579 -1
  3. package/libs/button/index.mjs +111 -66
  4. package/libs/button/index.umd.js +203 -2
  5. package/libs/button/package.json +2 -1
  6. package/libs/{types/components/button → button}/src/button.d.ts +1 -1
  7. package/libs/cell/index.css +1077 -1
  8. package/libs/{types/components/cell → cell}/index.d.ts +1 -0
  9. package/libs/cell/index.mjs +168 -104
  10. package/libs/cell/index.umd.js +301 -2
  11. package/libs/cell/package.json +2 -1
  12. package/libs/{types/components/cell → cell}/src/cell.d.ts +1 -1
  13. package/libs/checkbox/index.css +1053 -1
  14. package/libs/{types/components/checkbox → checkbox}/index.d.ts +1 -0
  15. package/libs/checkbox/index.mjs +243 -127
  16. package/libs/checkbox/index.umd.js +370 -2
  17. package/libs/checkbox/package.json +2 -1
  18. package/libs/checkboxGroup/index.css +422 -1
  19. package/libs/{types/components/checkboxGroup → checkboxGroup}/index.d.ts +1 -0
  20. package/libs/checkboxGroup/index.mjs +174 -87
  21. package/libs/checkboxGroup/index.umd.js +266 -2
  22. package/libs/checkboxGroup/package.json +2 -1
  23. package/libs/col/index.css +615 -1
  24. package/libs/{types/components/col → col}/index.d.ts +1 -0
  25. package/libs/col/index.mjs +247 -81
  26. package/libs/col/index.umd.js +306 -2
  27. package/libs/col/package.json +2 -1
  28. package/libs/countdown/index.css +417 -1
  29. package/libs/{types/components/countdown → countdown}/index.d.ts +1 -0
  30. package/libs/countdown/index.mjs +180 -71
  31. package/libs/countdown/index.umd.js +232 -2
  32. package/libs/countdown/package.json +2 -1
  33. package/libs/dialog/index.css +1405 -1
  34. package/libs/{types/components/dialog → dialog}/index.d.ts +1 -0
  35. package/libs/dialog/index.mjs +647 -476
  36. package/libs/dialog/index.umd.js +1129 -2
  37. package/libs/dialog/package.json +2 -1
  38. package/libs/{types/components/dialog → dialog}/src/dialog.d.ts +1 -1
  39. package/libs/empty/index.css +457 -1
  40. package/libs/{types/components/empty → empty}/index.d.ts +1 -0
  41. package/libs/empty/index.mjs +92 -44
  42. package/libs/empty/index.umd.js +140 -2
  43. package/libs/empty/package.json +2 -1
  44. package/libs/form/index.css +477 -1
  45. package/libs/{types/components/form → form}/index.d.ts +1 -0
  46. package/libs/form/index.mjs +227 -126
  47. package/libs/form/index.umd.js +320 -2
  48. package/libs/form/package.json +2 -1
  49. package/libs/formItem/index.css +477 -1
  50. package/libs/{types/components/formItem → formItem}/index.d.ts +1 -0
  51. package/libs/formItem/index.mjs +277 -126
  52. package/libs/formItem/index.umd.js +373 -2
  53. package/libs/formItem/package.json +2 -1
  54. package/libs/icon/index.css +982 -1
  55. package/libs/{types/components/icon → icon}/index.d.ts +1 -0
  56. package/libs/icon/index.mjs +108 -58
  57. package/libs/icon/index.umd.js +187 -2
  58. package/libs/icon/package.json +2 -1
  59. package/libs/index.css +2902 -1
  60. package/libs/index.d.ts +86 -3
  61. package/libs/index.mjs +3785 -2344
  62. package/libs/index.umd.js +5509 -2
  63. package/libs/input/index.css +483 -1
  64. package/libs/{types/components/input → input}/index.d.ts +1 -0
  65. package/libs/input/index.mjs +184 -92
  66. package/libs/input/index.umd.js +275 -2
  67. package/libs/input/package.json +2 -1
  68. package/libs/layout/index.css +684 -1
  69. package/libs/layout/index.mjs +230 -130
  70. package/libs/layout/index.umd.js +318 -2
  71. package/libs/layout/package.json +2 -1
  72. package/libs/list/index.css +440 -1
  73. package/libs/{types/components/list → list}/index.d.ts +1 -0
  74. package/libs/list/index.mjs +389 -207
  75. package/libs/list/index.umd.js +572 -2
  76. package/libs/list/package.json +2 -1
  77. package/libs/loading/index.css +548 -1
  78. package/libs/{types/components/loading → loading}/index.d.ts +1 -0
  79. package/libs/loading/index.mjs +197 -118
  80. package/libs/loading/index.umd.js +322 -2
  81. package/libs/loading/package.json +2 -1
  82. package/libs/{types/components/loading → loading}/src/loading.d.ts +1 -1
  83. package/libs/mask/index.css +426 -1
  84. package/libs/{types/components/mask → mask}/index.d.ts +1 -0
  85. package/libs/mask/index.mjs +132 -70
  86. package/libs/mask/index.umd.js +202 -2
  87. package/libs/mask/package.json +2 -1
  88. package/libs/popup/index.css +465 -1
  89. package/libs/{types/components/popup → popup}/index.d.ts +1 -0
  90. package/libs/popup/index.mjs +211 -134
  91. package/libs/popup/index.umd.js +359 -2
  92. package/libs/popup/package.json +2 -1
  93. package/libs/{types/components/popup → popup}/src/popup.d.ts +1 -1
  94. package/libs/progress/index.css +488 -1
  95. package/libs/{types/components/progress → progress}/index.d.ts +1 -0
  96. package/libs/progress/index.mjs +201 -128
  97. package/libs/progress/index.umd.js +323 -2
  98. package/libs/progress/package.json +2 -1
  99. package/libs/pullrefresh/index.css +441 -1
  100. package/libs/{types/components/pullrefresh → pullrefresh}/index.d.ts +1 -0
  101. package/libs/pullrefresh/index.mjs +242 -111
  102. package/libs/pullrefresh/index.umd.js +303 -2
  103. package/libs/pullrefresh/package.json +2 -1
  104. package/libs/row/index.css +485 -1
  105. package/libs/{types/components/row → row}/index.d.ts +1 -0
  106. package/libs/row/index.mjs +182 -89
  107. package/libs/row/index.umd.js +238 -2
  108. package/libs/row/package.json +2 -1
  109. package/libs/{types/components/row → row}/src/row.d.ts +1 -1
  110. package/libs/slider/index.css +558 -1
  111. package/libs/{types/components/slider → slider}/index.d.ts +1 -0
  112. package/libs/slider/index.mjs +357 -160
  113. package/libs/slider/index.umd.js +454 -2
  114. package/libs/slider/package.json +2 -1
  115. package/libs/stepper/index.css +489 -1
  116. package/libs/{types/components/stepper → stepper}/index.d.ts +1 -0
  117. package/libs/stepper/index.mjs +182 -101
  118. package/libs/stepper/index.umd.js +270 -2
  119. package/libs/stepper/package.json +2 -1
  120. package/libs/swipe/index.css +506 -1
  121. package/libs/{types/components/swipe → swipe}/index.d.ts +1 -0
  122. package/libs/swipe/index.mjs +543 -259
  123. package/libs/swipe/index.umd.js +704 -2
  124. package/libs/swipe/package.json +2 -1
  125. package/libs/swipeItem/index.css +424 -1
  126. package/libs/{types/components/swipeItem → swipeItem}/index.d.ts +1 -0
  127. package/libs/swipeItem/index.mjs +112 -52
  128. package/libs/swipeItem/index.umd.js +155 -2
  129. package/libs/swipeItem/package.json +2 -1
  130. package/libs/switch/index.css +472 -1
  131. package/libs/{types/components/switch → switch}/index.d.ts +1 -0
  132. package/libs/switch/index.mjs +122 -62
  133. package/libs/switch/index.umd.js +201 -2
  134. package/libs/switch/package.json +2 -1
  135. package/libs/{types/components/switch → switch}/src/switch.d.ts +1 -1
  136. package/libs/{types/components/tab → tab}/index.d.ts +1 -0
  137. package/libs/tab/index.mjs +132 -68
  138. package/libs/tab/index.umd.js +191 -1
  139. package/libs/tab/package.json +2 -1
  140. package/libs/tabs/index.css +514 -1
  141. package/libs/{types/components/tabs → tabs}/index.d.ts +1 -0
  142. package/libs/tabs/index.mjs +752 -410
  143. package/libs/tabs/index.umd.js +1021 -2
  144. package/libs/tabs/package.json +2 -1
  145. package/libs/toast/index.css +1050 -1
  146. package/libs/{types/components/toast → toast}/index.d.ts +1 -0
  147. package/libs/toast/index.mjs +184 -114
  148. package/libs/toast/index.umd.js +307 -2
  149. package/libs/toast/package.json +2 -1
  150. package/libs/{types/components/toast → toast}/src/toast.d.ts +1 -1
  151. package/libs/tooltip/index.css +514 -1
  152. package/libs/{types/components/tooltip → tooltip}/index.d.ts +1 -0
  153. package/libs/tooltip/index.mjs +294 -155
  154. package/libs/tooltip/index.umd.js +417 -2
  155. package/libs/tooltip/package.json +2 -1
  156. package/libs/vue-sfc.d.ts +12 -0
  157. package/libs/vue-tsx.d.ts +42 -0
  158. package/package.json +5 -2
  159. package/libs/types/index.d.ts +0 -86
  160. /package/libs/{types/components/button → button}/index.d.ts +0 -0
  161. /package/libs/{types/components/checkbox → checkbox}/src/checkbox.d.ts +0 -0
  162. /package/libs/{types/components/checkboxGroup → checkboxGroup}/src/checkboxGroup.d.ts +0 -0
  163. /package/libs/{types/components/checkboxGroup → checkboxGroup}/src/constants.d.ts +0 -0
  164. /package/libs/{types/components/col → col}/src/col.d.ts +0 -0
  165. /package/libs/{types/context → context}/filed/constants.d.ts +0 -0
  166. /package/libs/{types/context → context}/filed/index.d.ts +0 -0
  167. /package/libs/{types/context → context}/filed/inject.d.ts +0 -0
  168. /package/libs/{types/context → context}/filed/provide.d.ts +0 -0
  169. /package/libs/{types/context → context}/relation/index.d.ts +0 -0
  170. /package/libs/{types/context → context}/relation/inject.d.ts +0 -0
  171. /package/libs/{types/context → context}/relation/provide.d.ts +0 -0
  172. /package/libs/{types/components/countdown → countdown}/src/count-down.d.ts +0 -0
  173. /package/libs/{types/components/dialog → dialog}/src/create.d.ts +0 -0
  174. /package/libs/{types/components/empty → empty}/src/empty.d.ts +0 -0
  175. /package/libs/{types/components/empty → empty}/src/utils.d.ts +0 -0
  176. /package/libs/{types/components/form → form}/src/constants.d.ts +0 -0
  177. /package/libs/{types/components/form → form}/src/form.d.ts +0 -0
  178. /package/libs/{types/components/formItem → formItem}/src/formItem.d.ts +0 -0
  179. /package/libs/{types/hooks → hooks}/touch/index.d.ts +0 -0
  180. /package/libs/{types/components/icon → icon}/src/icon.d.ts +0 -0
  181. /package/libs/{types/components/input → input}/src/input.d.ts +0 -0
  182. /package/libs/{types/components/list → list}/src/list.d.ts +0 -0
  183. /package/libs/{types/components/loading → loading}/src/create.d.ts +0 -0
  184. /package/libs/{types/components/loading → loading}/src/directive.d.ts +0 -0
  185. /package/libs/{types/locale → locale}/index.d.ts +0 -0
  186. /package/libs/{types/locale → locale}/lang/zh-CN.d.ts +0 -0
  187. /package/libs/{types/components/mask → mask}/src/mask.d.ts +0 -0
  188. /package/libs/{types/components/progress → progress}/src/progress.d.ts +0 -0
  189. /package/libs/{types/components/pullrefresh → pullrefresh}/src/pullrefresh.d.ts +0 -0
  190. /package/libs/{types/components/pullrefresh → pullrefresh}/src/utils.d.ts +0 -0
  191. /package/libs/{types/components/row → row}/src/constants.d.ts +0 -0
  192. /package/libs/{types/components/slider → slider}/src/slider.d.ts +0 -0
  193. /package/libs/{types/components/stepper → stepper}/src/stepper.d.ts +0 -0
  194. /package/libs/{types/style → style}/index.d.ts +0 -0
  195. /package/libs/{types/components/swipe → swipe}/src/constants.d.ts +0 -0
  196. /package/libs/{types/components/swipe → swipe}/src/swipe.d.ts +0 -0
  197. /package/libs/{types/components/swipeItem → swipeItem}/src/swipeItem.d.ts +0 -0
  198. /package/libs/{types/components/tab → tab}/src/tab.d.ts +0 -0
  199. /package/libs/{types/components/tabs → tabs}/src/constants.d.ts +0 -0
  200. /package/libs/{types/components/tabs → tabs}/src/tabs.d.ts +0 -0
  201. /package/libs/{types/components/tabs → tabs}/src/title.d.ts +0 -0
  202. /package/libs/{types/components/toast → toast}/src/create.d.ts +0 -0
  203. /package/libs/{types/components/tooltip → tooltip}/src/constants.d.ts +0 -0
  204. /package/libs/{types/components/tooltip → tooltip}/src/direactive.d.ts +0 -0
  205. /package/libs/{types/components/tooltip → tooltip}/src/popper.d.ts +0 -0
  206. /package/libs/{types/components/tooltip → tooltip}/src/tooltip.d.ts +0 -0
  207. /package/libs/{types/utils → utils}/create/bem.d.ts +0 -0
  208. /package/libs/{types/utils → utils}/create/index.d.ts +0 -0
  209. /package/libs/{types/utils → utils}/index.d.ts +0 -0
  210. /package/libs/{types/utils → utils}/is.d.ts +0 -0
  211. /package/libs/{types/utils → utils}/parseFlexDirection.d.ts +0 -0
  212. /package/libs/{types/utils → utils}/parseUnit.d.ts +0 -0
  213. /package/libs/{types/utils → utils}/types.d.ts +0 -0
@@ -1,11 +1,46 @@
1
- import { ref as d, reactive as K, defineComponent as P, createVNode as i, computed as S, onMounted as Q, onUpdated as X, nextTick as Z, onUnmounted as ee, createTextVNode as te } from "vue";
2
- const ne = (e) => (n) => Object.prototype.toString.call(n) === `[object ${e}]`, ae = ne("Number"), L = (e, n) => n ? typeof n == "string" ? ` ${e}--${n}` : Array.isArray(n) ? n.reduce((c, r) => c + L(e, r), "") : Object.keys(n).reduce(
3
- (c, r) => c + (n[r] ? L(e, r) : ""),
4
- ""
5
- ) : "", le = (e) => (n, c) => {
6
- let r = n, f = c;
7
- return r && typeof r != "string" && (f = r, r = ""), r = r ? `${e}__${r}` : e, `${r}${L(r, f)}`;
8
- }, re = () => (e, n) => n ? `${L(`y-${e}`, n)}` : `y-${e}`, ie = {
1
+ import { ref, reactive, defineComponent, createVNode, computed, onMounted, onUpdated, nextTick, onUnmounted, createTextVNode } from "vue";
2
+ const tagTester = (name2) => {
3
+ return (obj) => {
4
+ return Object.prototype.toString.call(obj) === `[object ${name2}]`;
5
+ };
6
+ };
7
+ const isNumber = tagTester("Number");
8
+ const getMods = (el, mods) => {
9
+ if (!mods) {
10
+ return "";
11
+ }
12
+ if (typeof mods === "string") {
13
+ return ` ${el}--${mods}`;
14
+ }
15
+ if (Array.isArray(mods)) {
16
+ return mods.reduce((acc, cur) => acc + getMods(el, cur), "");
17
+ }
18
+ return Object.keys(mods).reduce(
19
+ (acc, cur) => acc + (mods[cur] ? getMods(el, cur) : ""),
20
+ ""
21
+ );
22
+ };
23
+ const createBEM = (block) => {
24
+ return (el, mods) => {
25
+ let _el = el;
26
+ let _mods = mods;
27
+ if (_el && typeof _el !== "string") {
28
+ _mods = _el;
29
+ _el = "";
30
+ }
31
+ _el = _el ? `${block}__${_el}` : block;
32
+ return `${_el}${getMods(_el, _mods)}`;
33
+ };
34
+ };
35
+ const createGlobalBem = () => {
36
+ return (el, mods) => {
37
+ if (!mods) {
38
+ return `y-${el}`;
39
+ }
40
+ return `${getMods(`y-${el}`, mods)}`;
41
+ };
42
+ };
43
+ const defaultLang = {
9
44
  "pull-refresh": {
10
45
  pulling: "下拉刷新...",
11
46
  loosing: "释放刷新...",
@@ -17,15 +52,22 @@ const ne = (e) => (n) => Object.prototype.toString.call(n) === `[object ${e}]`,
17
52
  validateMessage: "请输入正确内容"
18
53
  }
19
54
  };
20
- d("zh-CN");
21
- K({
22
- "zh-CN": ie
55
+ ref("zh-CN");
56
+ reactive({
57
+ "zh-CN": defaultLang
23
58
  });
24
- const G = (e) => {
25
- const n = `y-${e}`;
26
- return [n, le(n), re()];
27
- }, H = (e) => isNaN(Number(e)) && typeof e == "string" ? e : `${e}px`, oe = (e) => {
28
- switch (e) {
59
+ const createNamespace = (name2) => {
60
+ const prefixedName = `y-${name2}`;
61
+ return [prefixedName, createBEM(prefixedName), createGlobalBem()];
62
+ };
63
+ const parseUnit = (val) => {
64
+ if (isNaN(Number(val)) && typeof val === "string") {
65
+ return val;
66
+ }
67
+ return `${val}px`;
68
+ };
69
+ const parseFlexDirection = (location) => {
70
+ switch (location) {
29
71
  case "top":
30
72
  return "column-reverse";
31
73
  case "bottom":
@@ -37,7 +79,9 @@ const G = (e) => {
37
79
  default:
38
80
  return "column";
39
81
  }
40
- }, [ue, R] = G("loading"), ce = {
82
+ };
83
+ const [name, bem$1] = createNamespace("loading");
84
+ const _props = {
41
85
  // Loading icon 的颜色
42
86
  color: {
43
87
  type: String,
@@ -96,76 +140,80 @@ const G = (e) => {
96
140
  type: String,
97
141
  default: "relative"
98
142
  }
99
- }, se = /* @__PURE__ */ P({
100
- name: ue,
101
- props: ce,
102
- setup(e, {
103
- slots: n
143
+ };
144
+ const YLoading = /* @__PURE__ */ defineComponent({
145
+ name,
146
+ props: _props,
147
+ setup(props, {
148
+ slots
104
149
  }) {
105
150
  return () => {
106
- var w, B;
151
+ var _a, _b;
107
152
  const {
108
- position: c,
109
- textLocation: r,
110
- bgColor: f,
111
- bgBorderRadius: m,
112
- size: o,
113
- padding: x,
114
- color: v,
115
- thick: C,
116
- direction: I,
117
- text: s,
118
- textColor: p,
119
- textSize: l
120
- } = e, k = ((w = n.default) == null ? void 0 : w.call(n)) || s;
121
- return i("div", {
122
- class: R({
123
- [c]: c !== "relative"
153
+ position,
154
+ textLocation,
155
+ bgColor,
156
+ bgBorderRadius,
157
+ size,
158
+ padding,
159
+ color,
160
+ thick,
161
+ direction,
162
+ text,
163
+ textColor,
164
+ textSize
165
+ } = props;
166
+ const showText = ((_a = slots.default) == null ? void 0 : _a.call(slots)) || text;
167
+ return createVNode("div", {
168
+ "class": bem$1({
169
+ [position]: position !== "relative"
124
170
  })
125
- }, [i("div", {
126
- class: R("bg", {
127
- [c]: c !== "relative"
171
+ }, [createVNode("div", {
172
+ "class": bem$1("bg", {
173
+ [position]: position !== "relative"
128
174
  }),
129
- style: {
130
- flexDirection: oe(r),
131
- backgroundColor: f,
132
- borderRadius: H(m),
133
- padding: H(x)
175
+ "style": {
176
+ flexDirection: parseFlexDirection(textLocation),
177
+ backgroundColor: bgColor,
178
+ borderRadius: parseUnit(bgBorderRadius),
179
+ padding: parseUnit(padding)
134
180
  }
135
- }, [i("span", {
136
- class: R("icon-wrapper"),
137
- style: {
138
- width: H(o),
139
- height: H(o)
181
+ }, [createVNode("span", {
182
+ "class": bem$1("icon-wrapper"),
183
+ "style": {
184
+ width: parseUnit(size),
185
+ height: parseUnit(size)
140
186
  }
141
- }, [((B = n.icon) == null ? void 0 : B.call(n)) || i("svg", {
142
- class: R("icon", {
143
- [I]: I
187
+ }, [((_b = slots.icon) == null ? void 0 : _b.call(slots)) || createVNode("svg", {
188
+ "class": bem$1("icon", {
189
+ [direction]: direction
144
190
  }),
145
- viewBox: "25 25 50 50"
146
- }, [i("circle", {
147
- class: R("icon-circle"),
148
- style: {
149
- stroke: v,
150
- strokeWidth: H(C)
191
+ "viewBox": "25 25 50 50"
192
+ }, [createVNode("circle", {
193
+ "class": bem$1("icon-circle"),
194
+ "style": {
195
+ stroke: color,
196
+ strokeWidth: parseUnit(thick)
151
197
  },
152
- cx: "50",
153
- cy: "50",
154
- r: "20",
155
- fill: "none"
156
- }, null)])]), k && i("span", {
157
- class: R("text", {
158
- [r]: r
198
+ "cx": "50",
199
+ "cy": "50",
200
+ "r": "20",
201
+ "fill": "none"
202
+ }, null)])]), showText && createVNode("span", {
203
+ "class": bem$1("text", {
204
+ [textLocation]: textLocation
159
205
  }),
160
- style: {
161
- color: p,
162
- fontSize: H(l)
206
+ "style": {
207
+ color: textColor,
208
+ fontSize: parseUnit(textSize)
163
209
  }
164
- }, [k])])]);
210
+ }, [showText])])]);
165
211
  };
166
212
  }
167
- }), [de, h] = G("list"), V = /* @__PURE__ */ P({
168
- name: de,
213
+ });
214
+ const [cname, bem] = createNamespace("list");
215
+ const List = /* @__PURE__ */ defineComponent({
216
+ name: cname,
169
217
  props: {
170
218
  // 加载中 文案
171
219
  loadingText: {
@@ -200,7 +248,7 @@ const G = (e) => {
200
248
  // 是否在初始化时立即执行滚动位置检查
201
249
  immediateCheck: {
202
250
  type: Boolean,
203
- default: !0
251
+ default: true
204
252
  },
205
253
  // 滚动条与底部距离小于多少时触发加载
206
254
  loadOffset: {
@@ -210,7 +258,7 @@ const G = (e) => {
210
258
  // 是否使用虚拟列表
211
259
  virtual: {
212
260
  type: Boolean,
213
- default: !1
261
+ default: false
214
262
  },
215
263
  // 缓冲区比例
216
264
  bufferScale: {
@@ -225,160 +273,294 @@ const G = (e) => {
225
273
  // 是否是不定高度子项
226
274
  dynamicItemHeight: {
227
275
  type: Boolean,
228
- default: !1
276
+ default: false
229
277
  }
230
278
  },
231
279
  emits: ["load"],
232
- setup(e, {
233
- slots: n,
234
- emit: c,
235
- expose: r
280
+ setup(props, {
281
+ slots,
282
+ emit,
283
+ expose
236
284
  }) {
237
- const f = d(0), m = d(!1), o = d("normal"), x = d(), v = d(), C = d(), I = d([]), s = d(0), p = d(0), l = d([]), k = S(() => ae(e.height) ? `${e.height}px` : e.height), w = S(() => l.value.length ? l.value[l.value.length - 1].bottom : 0), B = S(() => {
238
- if (e.virtual) {
239
- const t = s.value - M.value, a = p.value + A.value;
240
- return _.value.slice(t, a);
285
+ const visibleHeightRef = ref(0);
286
+ const pageModeRef = ref(false);
287
+ const stateRef = ref("normal");
288
+ const listRef = ref();
289
+ const contentRef = ref();
290
+ const scrollBarRef = ref();
291
+ const itemsRef = ref([]);
292
+ const startIndexRef = ref(0);
293
+ const endIndexRef = ref(0);
294
+ const positionsRef = ref([]);
295
+ const listContainerRef = computed(() => {
296
+ return isNumber(props.height) ? `${props.height}px` : props.height;
297
+ });
298
+ const listHeightRef = computed(() => {
299
+ const listHeight = positionsRef.value.length ? positionsRef.value[positionsRef.value.length - 1].bottom : 0;
300
+ return listHeight;
301
+ });
302
+ const realRenderListRef = computed(() => {
303
+ if (props.virtual) {
304
+ const start = startIndexRef.value - aboveCountRef.value;
305
+ const end = endIndexRef.value + belowCountRef.value;
306
+ return _dataSourceRef.value.slice(start, end);
241
307
  }
242
- return _.value;
243
- }), M = S(() => Math.min(s.value, e.bufferScale * $.value)), A = S(() => Math.min(e.dataSource.length - p.value, e.bufferScale * $.value)), $ = S(() => Math.ceil(f.value / parseInt(String(e.itemHeight)))), _ = S(() => e.dataSource.map((t, a) => (t[e.keyName] = a, t))), j = () => m.value ? document.documentElement.scrollTop || document.body.scrollTop : x.value.scrollTop, W = () => m.value ? document.documentElement.scrollHeight : x.value.scrollHeight, E = () => {
244
- o.value !== "loading" && (o.value = "loading", c("load", (t) => {
245
- if (o.value === "loading")
246
- switch (t) {
247
- case "error":
248
- o.value = "error";
249
- break;
250
- case "finished":
251
- o.value = "finished", e.virtual && D(), e.virtual && e.dynamicItemHeight && U();
252
- break;
253
- default:
254
- o.value = "normal", e.virtual && (U(), e.dataSource.length < $.value + A.value && E());
255
- }
256
- }));
257
- }, z = () => {
258
- o.value === "normal" && W() - j() - f.value <= e.loadOffset && E();
259
- }, D = () => {
260
- l.value = _.value.map((t, a) => {
261
- const u = parseInt(String(e.itemHeight));
308
+ return _dataSourceRef.value;
309
+ });
310
+ const aboveCountRef = computed(() => {
311
+ const above = Math.min(startIndexRef.value, props.bufferScale * visibleCountRef.value);
312
+ return above;
313
+ });
314
+ const belowCountRef = computed(() => {
315
+ const below = Math.min(props.dataSource.length - endIndexRef.value, props.bufferScale * visibleCountRef.value);
316
+ return below;
317
+ });
318
+ const visibleCountRef = computed(() => {
319
+ const count = Math.ceil(visibleHeightRef.value / parseInt(String(props.itemHeight)));
320
+ return count;
321
+ });
322
+ const _dataSourceRef = computed(() => {
323
+ return props.dataSource.map((item, index) => {
324
+ item[props.keyName] = index;
325
+ return item;
326
+ });
327
+ });
328
+ const getScrollTop = () => {
329
+ if (pageModeRef.value) {
330
+ return document.documentElement.scrollTop || document.body.scrollTop;
331
+ }
332
+ return listRef.value.scrollTop;
333
+ };
334
+ const getScrollHeight = () => {
335
+ if (pageModeRef.value) {
336
+ return document.documentElement.scrollHeight;
337
+ }
338
+ return listRef.value.scrollHeight;
339
+ };
340
+ const loadData = () => {
341
+ if (stateRef.value === "loading")
342
+ return;
343
+ stateRef.value = "loading";
344
+ emit("load", (state) => {
345
+ if (stateRef.value !== "loading")
346
+ return;
347
+ switch (state) {
348
+ case "error":
349
+ stateRef.value = "error";
350
+ break;
351
+ case "finished":
352
+ stateRef.value = "finished";
353
+ if (props.virtual) {
354
+ initPositions();
355
+ }
356
+ if (props.virtual && props.dynamicItemHeight) {
357
+ updatePositions();
358
+ }
359
+ break;
360
+ default:
361
+ stateRef.value = "normal";
362
+ if (props.virtual) {
363
+ updatePositions();
364
+ if (props.dataSource.length < visibleCountRef.value + belowCountRef.value) {
365
+ loadData();
366
+ }
367
+ }
368
+ }
369
+ });
370
+ };
371
+ const checkIsScrollToBottom = () => {
372
+ if (stateRef.value !== "normal")
373
+ return;
374
+ if (getScrollHeight() - getScrollTop() - visibleHeightRef.value <= props.loadOffset) {
375
+ loadData();
376
+ }
377
+ };
378
+ const initPositions = () => {
379
+ positionsRef.value = _dataSourceRef.value.map((_, index) => {
380
+ const height = parseInt(String(props.itemHeight));
262
381
  return {
263
- index: a,
264
- height: u,
265
- top: a * u,
266
- bottom: (a + 1) * u
382
+ index,
383
+ height,
384
+ top: index * height,
385
+ bottom: (index + 1) * height
267
386
  };
268
387
  });
269
- }, U = () => {
270
- D();
271
- for (let t = 1; t < l.value.length; t++)
272
- l.value[t].top = l.value[t - 1].bottom, l.value[t].bottom = l.value[t].top + l.value[t].height;
273
- }, Y = (t, a) => {
274
- let u = 0, N = t.length - 1, g = -1;
275
- for (; u <= N; ) {
276
- const y = Math.floor((u + N) / 2), b = t[y].bottom;
277
- if (b === a)
278
- return y + 1;
279
- b < a ? u = y + 1 : b > a && ((g === -1 || g > y) && (g = y), N = y - 1);
388
+ };
389
+ const updatePositions = () => {
390
+ initPositions();
391
+ for (let i = 1; i < positionsRef.value.length; i++) {
392
+ positionsRef.value[i].top = positionsRef.value[i - 1].bottom;
393
+ positionsRef.value[i].bottom = positionsRef.value[i].top + positionsRef.value[i].height;
394
+ }
395
+ };
396
+ const binarySearch = (list, value) => {
397
+ let start = 0;
398
+ let end = list.length - 1;
399
+ let tempIndex = -1;
400
+ while (start <= end) {
401
+ const midIndex = Math.floor((start + end) / 2);
402
+ const midValue = list[midIndex].bottom;
403
+ if (midValue === value) {
404
+ return midIndex + 1;
405
+ } else if (midValue < value) {
406
+ start = midIndex + 1;
407
+ } else if (midValue > value) {
408
+ if (tempIndex === -1 || tempIndex > midIndex) {
409
+ tempIndex = midIndex;
410
+ }
411
+ end = midIndex - 1;
412
+ }
280
413
  }
281
- return g;
282
- }, q = (t) => Y(l.value, t), O = () => {
283
- if (z(), e.virtual) {
284
- const t = j();
285
- F(t);
414
+ return tempIndex;
415
+ };
416
+ const getStartIndex = (scrollTop) => {
417
+ return binarySearch(positionsRef.value, scrollTop);
418
+ };
419
+ const handleScroll = () => {
420
+ checkIsScrollToBottom();
421
+ if (props.virtual) {
422
+ const scrollTop = getScrollTop();
423
+ updateVisibleData(scrollTop);
286
424
  }
287
- }, F = (t) => {
288
- if (!v.value)
425
+ };
426
+ const updateVisibleData = (scrollTopParam) => {
427
+ if (!contentRef.value)
289
428
  return;
290
- const a = t || 0;
291
- if (e.dynamicItemHeight) {
292
- s.value = q(a), p.value = s.value + $.value;
293
- const u = l.value[s.value - M.value].top ? l.value[s.value - M.value].top : 0;
294
- v.value.style.transform = `translate3d(0, ${u}px, 0)`;
429
+ const scrollTop = scrollTopParam || 0;
430
+ if (props.dynamicItemHeight) {
431
+ startIndexRef.value = getStartIndex(scrollTop);
432
+ endIndexRef.value = startIndexRef.value + visibleCountRef.value;
433
+ const startOffset = positionsRef.value[startIndexRef.value - aboveCountRef.value].top ? positionsRef.value[startIndexRef.value - aboveCountRef.value].top : 0;
434
+ contentRef.value.style.transform = `translate3d(0, ${startOffset}px, 0)`;
295
435
  } else {
296
- s.value = Math.floor(a / parseInt(String(e.itemHeight))), p.value = s.value + $.value;
297
- const u = s.value * parseInt(String(e.itemHeight)) - M.value * parseInt(String(e.itemHeight));
298
- v.value.style.transform = `translate3d(0, ${u}px, 0)`;
436
+ startIndexRef.value = Math.floor(scrollTop / parseInt(String(props.itemHeight)));
437
+ endIndexRef.value = startIndexRef.value + visibleCountRef.value;
438
+ const startOffset = startIndexRef.value * parseInt(String(props.itemHeight)) - aboveCountRef.value * parseInt(String(props.itemHeight));
439
+ contentRef.value.style.transform = `translate3d(0, ${startOffset}px, 0)`;
299
440
  }
300
- }, J = () => {
301
- if (!v.value || !C.value)
441
+ };
442
+ const updateItemSize = () => {
443
+ if (!contentRef.value || !scrollBarRef.value)
444
+ return;
445
+ const nodes = contentRef.value.children;
446
+ if (!(nodes && nodes.length > 0))
302
447
  return;
303
- const t = v.value.children;
304
- t && t.length > 0 && [...t].forEach((a) => {
305
- if (a instanceof HTMLDivElement) {
306
- const u = a.getBoundingClientRect(), {
307
- height: N
308
- } = u, g = Number(a.dataset.index), b = l.value[g].height - N;
309
- if (b) {
310
- l.value[g].bottom -= b, l.value[g].height = N;
311
- for (let T = g + 1; T < l.value.length; T++)
312
- l.value[T].top = l.value[T - 1].bottom, l.value[T].bottom -= b;
448
+ [...nodes].forEach((node) => {
449
+ if (node instanceof HTMLDivElement) {
450
+ const rect = node.getBoundingClientRect();
451
+ const {
452
+ height
453
+ } = rect;
454
+ const index = Number(node.dataset.index);
455
+ const oldHeight = positionsRef.value[index].height;
456
+ const dValue = oldHeight - height;
457
+ if (dValue) {
458
+ positionsRef.value[index].bottom -= dValue;
459
+ positionsRef.value[index].height = height;
460
+ for (let k = index + 1; k < positionsRef.value.length; k++) {
461
+ positionsRef.value[k].top = positionsRef.value[k - 1].bottom;
462
+ positionsRef.value[k].bottom -= dValue;
463
+ }
313
464
  }
314
465
  }
315
466
  });
316
467
  };
317
- return r({
318
- ...e,
319
- checkIsScrollToBottom: z,
320
- loadData: E
321
- }), Q(() => {
322
- e.height !== "auto" ? (m.value = !1, f.value = x.value.clientHeight) : e.height === "auto" && (m.value = !0, f.value = document.documentElement.clientHeight, document.addEventListener("scroll", O)), e.virtual && (D(), F()), e.immediateCheck && z();
323
- }), X(async () => {
324
- var t, a;
325
- if (e.virtual && e.dynamicItemHeight) {
326
- if (await Z(), !((a = (t = v.value) == null ? void 0 : t.children) != null && a.length))
468
+ expose({
469
+ ...props,
470
+ checkIsScrollToBottom,
471
+ loadData
472
+ });
473
+ onMounted(() => {
474
+ if (props.height !== "auto") {
475
+ pageModeRef.value = false;
476
+ visibleHeightRef.value = listRef.value.clientHeight;
477
+ } else if (props.height === "auto") {
478
+ pageModeRef.value = true;
479
+ visibleHeightRef.value = document.documentElement.clientHeight;
480
+ document.addEventListener("scroll", handleScroll);
481
+ }
482
+ if (props.virtual) {
483
+ initPositions();
484
+ updateVisibleData();
485
+ }
486
+ if (props.immediateCheck) {
487
+ checkIsScrollToBottom();
488
+ }
489
+ });
490
+ onUpdated(async () => {
491
+ var _a, _b;
492
+ if (props.virtual && props.dynamicItemHeight) {
493
+ await nextTick();
494
+ if (!((_b = (_a = contentRef.value) == null ? void 0 : _a.children) == null ? void 0 : _b.length)) {
327
495
  return;
328
- J();
496
+ }
497
+ updateItemSize();
329
498
  }
330
- }), ee(() => {
331
- m.value && document.removeEventListener("scroll", O);
332
- }), () => i("div", {
333
- ref: x,
334
- class: `${h()} ${e.virtual ? h({
335
- virtual: !0
336
- }) : ""}`,
337
- style: {
338
- height: k.value
339
- },
340
- onScroll: O
341
- }, [e.virtual && i("div", {
342
- ref: C,
343
- class: h("phantom"),
344
- style: {
345
- height: `${w.value}px`
499
+ });
500
+ onUnmounted(() => {
501
+ if (pageModeRef.value) {
502
+ document.removeEventListener("scroll", handleScroll);
346
503
  }
347
- }, null), i("div", {
348
- ref: v,
349
- class: h("content")
350
- }, [B.value.map((t) => {
351
- var a;
352
- return i("div", {
353
- ref: I,
354
- class: h("item"),
355
- "data-index": t._index
356
- }, [(a = n.default) == null ? void 0 : a.call(n, {
357
- item: t
358
- })]);
359
- })]), o.value === "loading" && i("div", {
360
- class: h({
361
- loading: !0
362
- })
363
- }, [n.loading ? n.loading() : i(se, {
364
- "text-location": "right"
365
- }, {
366
- default: () => [te("加载中...")]
367
- })]), o.value === "finished" && i("div", {
368
- class: h({
369
- finished: !0
370
- })
371
- }, [e.finishedText]), o.value === "error" && i("div", {
372
- class: h("error"),
373
- role: "presentation",
374
- onClick: E
375
- }, [e.errorText])]);
504
+ });
505
+ return () => {
506
+ return createVNode("div", {
507
+ "ref": listRef,
508
+ "class": `${bem()} ${props.virtual ? bem({
509
+ virtual: true
510
+ }) : ""}`,
511
+ "style": {
512
+ height: listContainerRef.value
513
+ },
514
+ "onScroll": handleScroll
515
+ }, [props.virtual && createVNode("div", {
516
+ "ref": scrollBarRef,
517
+ "class": bem("phantom"),
518
+ "style": {
519
+ height: `${listHeightRef.value}px`
520
+ }
521
+ }, null), createVNode("div", {
522
+ "ref": contentRef,
523
+ "class": bem("content")
524
+ }, [realRenderListRef.value.map((item) => {
525
+ var _a;
526
+ return createVNode("div", {
527
+ "ref": itemsRef,
528
+ "class": bem("item"),
529
+ "data-index": item._index
530
+ }, [(_a = slots.default) == null ? void 0 : _a.call(slots, {
531
+ item
532
+ })]);
533
+ })]), stateRef.value === "loading" && createVNode("div", {
534
+ "class": bem({
535
+ loading: true
536
+ })
537
+ }, [slots.loading ? slots.loading() : createVNode(YLoading, {
538
+ "text-location": "right"
539
+ }, {
540
+ default: () => [createTextVNode("加载中...")]
541
+ })]), stateRef.value === "finished" && createVNode("div", {
542
+ "class": bem({
543
+ finished: true
544
+ })
545
+ }, [props.finishedText]), stateRef.value === "error" && createVNode("div", {
546
+ "class": bem("error"),
547
+ "role": "presentation",
548
+ "onClick": loadData
549
+ }, [props.errorText])]);
550
+ };
376
551
  }
377
552
  });
378
- V.install = (e) => {
379
- const { name: n } = V;
380
- e.component(n, V);
553
+ const reset = "";
554
+ const libs = "";
555
+ const font = "";
556
+ const animation = "";
557
+ const theme = "";
558
+ const style = "";
559
+ List.install = (Vue) => {
560
+ const { name: name2 } = List;
561
+ Vue.component(name2, List);
381
562
  };
382
563
  export {
383
- V as default
564
+ List,
565
+ List as default
384
566
  };