y-design-ssr 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/libs/button/index.css +579 -1
  2. package/libs/button/index.mjs +111 -66
  3. package/libs/button/index.umd.js +203 -2
  4. package/libs/button/package.json +12 -0
  5. package/libs/cell/index.css +1077 -1
  6. package/libs/cell/index.mjs +167 -104
  7. package/libs/cell/index.umd.js +300 -2
  8. package/libs/cell/package.json +12 -0
  9. package/libs/checkbox/index.css +1053 -1
  10. package/libs/checkbox/index.mjs +242 -127
  11. package/libs/checkbox/index.umd.js +369 -2
  12. package/libs/checkbox/package.json +12 -0
  13. package/libs/checkboxGroup/index.css +422 -1
  14. package/libs/checkboxGroup/index.mjs +173 -87
  15. package/libs/checkboxGroup/index.umd.js +265 -2
  16. package/libs/checkboxGroup/package.json +12 -0
  17. package/libs/col/index.css +615 -1
  18. package/libs/col/index.mjs +246 -81
  19. package/libs/col/index.umd.js +305 -2
  20. package/libs/col/package.json +12 -0
  21. package/libs/countdown/index.css +417 -1
  22. package/libs/countdown/index.mjs +179 -71
  23. package/libs/countdown/index.umd.js +231 -2
  24. package/libs/countdown/package.json +12 -0
  25. package/libs/dialog/index.css +1405 -1
  26. package/libs/dialog/index.mjs +646 -476
  27. package/libs/dialog/index.umd.js +1128 -2
  28. package/libs/dialog/package.json +12 -0
  29. package/libs/empty/index.css +457 -1
  30. package/libs/empty/index.mjs +91 -44
  31. package/libs/empty/index.umd.js +139 -2
  32. package/libs/empty/package.json +12 -0
  33. package/libs/form/index.css +477 -1
  34. package/libs/form/index.mjs +226 -126
  35. package/libs/form/index.umd.js +319 -2
  36. package/libs/form/package.json +12 -0
  37. package/libs/formItem/index.css +477 -1
  38. package/libs/formItem/index.mjs +276 -126
  39. package/libs/formItem/index.umd.js +372 -2
  40. package/libs/formItem/package.json +12 -0
  41. package/libs/icon/index.css +982 -1
  42. package/libs/icon/index.mjs +107 -58
  43. package/libs/icon/index.umd.js +186 -2
  44. package/libs/icon/package.json +12 -0
  45. package/libs/index.css +2902 -1
  46. package/libs/index.mjs +3785 -2344
  47. package/libs/index.umd.js +5509 -2
  48. package/libs/input/index.css +483 -1
  49. package/libs/input/index.mjs +183 -92
  50. package/libs/input/index.umd.js +274 -2
  51. package/libs/input/package.json +12 -0
  52. package/libs/layout/index.css +684 -1
  53. package/libs/layout/index.mjs +230 -130
  54. package/libs/layout/index.umd.js +318 -2
  55. package/libs/layout/package.json +12 -0
  56. package/libs/list/index.css +440 -1
  57. package/libs/list/index.mjs +388 -207
  58. package/libs/list/index.umd.js +571 -2
  59. package/libs/list/package.json +12 -0
  60. package/libs/loading/index.css +548 -1
  61. package/libs/loading/index.mjs +196 -118
  62. package/libs/loading/index.umd.js +321 -2
  63. package/libs/loading/package.json +12 -0
  64. package/libs/mask/index.css +426 -1
  65. package/libs/mask/index.mjs +131 -70
  66. package/libs/mask/index.umd.js +201 -2
  67. package/libs/mask/package.json +12 -0
  68. package/libs/popup/index.css +465 -1
  69. package/libs/popup/index.mjs +210 -134
  70. package/libs/popup/index.umd.js +358 -2
  71. package/libs/popup/package.json +12 -0
  72. package/libs/progress/index.css +488 -1
  73. package/libs/progress/index.mjs +200 -128
  74. package/libs/progress/index.umd.js +322 -2
  75. package/libs/progress/package.json +12 -0
  76. package/libs/pullrefresh/index.css +441 -1
  77. package/libs/pullrefresh/index.mjs +241 -111
  78. package/libs/pullrefresh/index.umd.js +302 -2
  79. package/libs/pullrefresh/package.json +12 -0
  80. package/libs/row/index.css +485 -1
  81. package/libs/row/index.mjs +181 -89
  82. package/libs/row/index.umd.js +237 -2
  83. package/libs/row/package.json +12 -0
  84. package/libs/slider/index.css +558 -1
  85. package/libs/slider/index.mjs +356 -160
  86. package/libs/slider/index.umd.js +453 -2
  87. package/libs/slider/package.json +12 -0
  88. package/libs/stepper/index.css +489 -1
  89. package/libs/stepper/index.mjs +181 -101
  90. package/libs/stepper/index.umd.js +269 -2
  91. package/libs/stepper/package.json +12 -0
  92. package/libs/swipe/index.css +506 -1
  93. package/libs/swipe/index.mjs +542 -259
  94. package/libs/swipe/index.umd.js +703 -2
  95. package/libs/swipe/package.json +12 -0
  96. package/libs/swipeItem/index.css +424 -1
  97. package/libs/swipeItem/index.mjs +111 -52
  98. package/libs/swipeItem/index.umd.js +154 -2
  99. package/libs/swipeItem/package.json +12 -0
  100. package/libs/switch/index.css +472 -1
  101. package/libs/switch/index.mjs +121 -62
  102. package/libs/switch/index.umd.js +200 -2
  103. package/libs/switch/package.json +12 -0
  104. package/libs/tab/index.mjs +131 -68
  105. package/libs/tab/index.umd.js +190 -1
  106. package/libs/tab/package.json +12 -0
  107. package/libs/tabs/index.css +514 -1
  108. package/libs/tabs/index.mjs +751 -410
  109. package/libs/tabs/index.umd.js +1020 -2
  110. package/libs/tabs/package.json +12 -0
  111. package/libs/toast/index.css +1050 -1
  112. package/libs/toast/index.mjs +183 -114
  113. package/libs/toast/index.umd.js +306 -2
  114. package/libs/toast/package.json +12 -0
  115. package/libs/tooltip/index.css +514 -1
  116. package/libs/tooltip/index.mjs +293 -155
  117. package/libs/tooltip/index.umd.js +416 -2
  118. package/libs/tooltip/package.json +12 -0
  119. package/package.json +3 -3
@@ -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,293 @@ 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 as default
384
565
  };