@uzum-tech/ui 1.10.1 → 1.11.1

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 (91) hide show
  1. package/dist/index.js +1248 -263
  2. package/dist/index.prod.js +3 -3
  3. package/es/_internal/index.d.ts +2 -0
  4. package/es/_internal/index.js +1 -0
  5. package/es/_internal/safe-top-scrollbar/index.d.ts +2 -0
  6. package/es/_internal/safe-top-scrollbar/index.js +1 -0
  7. package/es/_internal/safe-top-scrollbar/src/SafeTopScrollbar.d.ts +356 -0
  8. package/es/_internal/safe-top-scrollbar/src/SafeTopScrollbar.js +708 -0
  9. package/es/_internal/safe-top-scrollbar/src/styles/index.cssr.d.ts +2 -0
  10. package/es/_internal/safe-top-scrollbar/src/styles/index.cssr.js +80 -0
  11. package/es/_internal/safe-top-scrollbar/src/styles/rtl.cssr.d.ts +2 -0
  12. package/es/_internal/safe-top-scrollbar/src/styles/rtl.cssr.js +10 -0
  13. package/es/_internal/safe-top-scrollbar/styles/common.d.ts +7 -0
  14. package/es/_internal/safe-top-scrollbar/styles/common.js +7 -0
  15. package/es/_internal/safe-top-scrollbar/styles/dark.d.ts +3 -0
  16. package/es/_internal/safe-top-scrollbar/styles/dark.js +8 -0
  17. package/es/_internal/safe-top-scrollbar/styles/index.d.ts +4 -0
  18. package/es/_internal/safe-top-scrollbar/styles/index.js +3 -0
  19. package/es/_internal/safe-top-scrollbar/styles/light.d.ts +18 -0
  20. package/es/_internal/safe-top-scrollbar/styles/light.js +12 -0
  21. package/es/_internal/safe-top-scrollbar/styles/rtl.d.ts +3 -0
  22. package/es/_internal/safe-top-scrollbar/styles/rtl.js +6 -0
  23. package/es/chat/src/Chat.d.ts +14 -1
  24. package/es/chat/src/Chat.js +5 -0
  25. package/es/chat/src/ChatParts/ChatAttachment.js +31 -3
  26. package/es/chat/src/ChatParts/MainArea.js +37 -41
  27. package/es/chat/src/interface.d.ts +6 -2
  28. package/es/components.d.ts +1 -0
  29. package/es/components.js +1 -0
  30. package/es/config-provider/src/internal-interface.d.ts +2 -0
  31. package/es/drawer/src/Drawer.d.ts +18 -0
  32. package/es/drawer/src/Drawer.js +28 -26
  33. package/es/drawer/src/DrawerBodyWrapper.d.ts +8 -0
  34. package/es/drawer/src/DrawerBodyWrapper.js +36 -8
  35. package/es/modal-fullscreen/src/ModalFull.d.ts +2 -2
  36. package/es/modal-fullscreen/src/ModalFull.js +31 -24
  37. package/es/modal-fullscreen/src/styles/index.cssr.js +11 -11
  38. package/es/safe-top-scrollbar/index.d.ts +2 -0
  39. package/es/safe-top-scrollbar/index.js +1 -0
  40. package/es/safe-top-scrollbar/src/SafeTopScrollbar.d.ts +177 -0
  41. package/es/safe-top-scrollbar/src/SafeTopScrollbar.js +38 -0
  42. package/es/themes/dark.js +2 -0
  43. package/es/themes/light.js +2 -0
  44. package/es/version.d.ts +1 -1
  45. package/es/version.js +1 -1
  46. package/lib/_internal/index.d.ts +2 -0
  47. package/lib/_internal/index.js +4 -1
  48. package/lib/_internal/safe-top-scrollbar/index.d.ts +2 -0
  49. package/lib/_internal/safe-top-scrollbar/index.js +9 -0
  50. package/lib/_internal/safe-top-scrollbar/src/SafeTopScrollbar.d.ts +356 -0
  51. package/lib/_internal/safe-top-scrollbar/src/SafeTopScrollbar.js +714 -0
  52. package/lib/_internal/safe-top-scrollbar/src/styles/index.cssr.d.ts +2 -0
  53. package/lib/_internal/safe-top-scrollbar/src/styles/index.cssr.js +85 -0
  54. package/lib/_internal/safe-top-scrollbar/src/styles/rtl.cssr.d.ts +2 -0
  55. package/lib/_internal/safe-top-scrollbar/src/styles/rtl.cssr.js +15 -0
  56. package/lib/_internal/safe-top-scrollbar/styles/common.d.ts +7 -0
  57. package/lib/_internal/safe-top-scrollbar/styles/common.js +10 -0
  58. package/lib/_internal/safe-top-scrollbar/styles/dark.d.ts +3 -0
  59. package/lib/_internal/safe-top-scrollbar/styles/dark.js +10 -0
  60. package/lib/_internal/safe-top-scrollbar/styles/index.d.ts +4 -0
  61. package/lib/_internal/safe-top-scrollbar/styles/index.js +12 -0
  62. package/lib/_internal/safe-top-scrollbar/styles/light.d.ts +18 -0
  63. package/lib/_internal/safe-top-scrollbar/styles/light.js +16 -0
  64. package/lib/_internal/safe-top-scrollbar/styles/rtl.d.ts +3 -0
  65. package/lib/_internal/safe-top-scrollbar/styles/rtl.js +12 -0
  66. package/lib/chat/src/Chat.d.ts +14 -1
  67. package/lib/chat/src/Chat.js +5 -0
  68. package/lib/chat/src/ChatParts/ChatAttachment.js +30 -2
  69. package/lib/chat/src/ChatParts/MainArea.js +37 -41
  70. package/lib/chat/src/interface.d.ts +6 -2
  71. package/lib/components.d.ts +1 -0
  72. package/lib/components.js +1 -0
  73. package/lib/config-provider/src/internal-interface.d.ts +2 -0
  74. package/lib/drawer/src/Drawer.d.ts +18 -0
  75. package/lib/drawer/src/Drawer.js +28 -26
  76. package/lib/drawer/src/DrawerBodyWrapper.d.ts +8 -0
  77. package/lib/drawer/src/DrawerBodyWrapper.js +36 -8
  78. package/lib/modal-fullscreen/src/ModalFull.d.ts +2 -2
  79. package/lib/modal-fullscreen/src/ModalFull.js +30 -23
  80. package/lib/modal-fullscreen/src/styles/index.cssr.js +11 -11
  81. package/lib/safe-top-scrollbar/index.d.ts +2 -0
  82. package/lib/safe-top-scrollbar/index.js +9 -0
  83. package/lib/safe-top-scrollbar/src/SafeTopScrollbar.d.ts +177 -0
  84. package/lib/safe-top-scrollbar/src/SafeTopScrollbar.js +41 -0
  85. package/lib/themes/dark.js +5 -0
  86. package/lib/themes/light.js +5 -0
  87. package/lib/version.d.ts +1 -1
  88. package/lib/version.js +1 -1
  89. package/package.json +1 -1
  90. package/volar.d.ts +1 -0
  91. package/web-types.json +58 -2
@@ -0,0 +1,708 @@
1
+ import { off, on } from 'evtd';
2
+ import { depx, getPadding, getPreciseEventTarget } from 'seemly';
3
+ import { useIsIos } from 'vooks';
4
+ import { computed, defineComponent, Fragment, h, mergeProps, onBeforeUnmount, onMounted, ref, Transition, watchEffect } from 'vue';
5
+ import { VResizeObserver } from 'vueuc';
6
+ import { useConfig, useRtl, useTheme, useThemeClass } from '../../../_mixins';
7
+ import { rtlInset, useReactivated, Wrapper } from '../../../_utils';
8
+ import { scrollbarLight } from '../styles';
9
+ import style from './styles/index.cssr';
10
+ const safeTopscrollbarProps = Object.assign(Object.assign({}, useTheme.props), { duration: {
11
+ type: Number,
12
+ default: 0
13
+ }, scrollable: {
14
+ type: Boolean,
15
+ default: true
16
+ }, xScrollable: Boolean, trigger: {
17
+ type: String,
18
+ default: 'hover'
19
+ }, useUnifiedContainer: Boolean, triggerDisplayManually: Boolean,
20
+ // If container is set, resize observer won't not attached
21
+ container: Function, content: Function, containerClass: String, containerStyle: [String, Object], contentClass: [String, Array], contentStyle: [String, Object], horizontalRailStyle: [String, Object], verticalRailStyle: [String, Object], onScroll: Function, onWheel: Function, onResize: Function, internalOnUpdateScrollLeft: Function, internalHoistYRail: Boolean, yPlacement: {
22
+ type: String,
23
+ default: 'right'
24
+ }, xPlacement: {
25
+ type: String,
26
+ default: 'bottom'
27
+ } });
28
+ const SafeTopScrollbar = defineComponent({
29
+ name: 'SafeTopScrollbar',
30
+ props: safeTopscrollbarProps,
31
+ inheritAttrs: false,
32
+ setup(props) {
33
+ const { mergedClsPrefixRef, inlineThemeDisabled, mergedRtlRef } = useConfig(props);
34
+ const rtlEnabledRef = useRtl('SafeTopScrollbar', mergedRtlRef, mergedClsPrefixRef);
35
+ // dom ref
36
+ const wrapperRef = ref(null);
37
+ const containerRef = ref(null);
38
+ const contentRef = ref(null);
39
+ const yRailRef = ref(null);
40
+ const xRailRef = ref(null);
41
+ // data ref
42
+ const contentHeightRef = ref(null);
43
+ const contentWidthRef = ref(null);
44
+ const containerHeightRef = ref(null);
45
+ const containerWidthRef = ref(null);
46
+ const yRailSizeRef = ref(null);
47
+ const xRailSizeRef = ref(null);
48
+ const containerScrollTopRef = ref(0);
49
+ const containerScrollLeftRef = ref(0);
50
+ const isShowXBarRef = ref(false);
51
+ const isShowYBarRef = ref(false);
52
+ let yBarPressed = false;
53
+ let xBarPressed = false;
54
+ let xBarVanishTimerId;
55
+ let yBarVanishTimerId;
56
+ let memoYTop = 0;
57
+ let memoXLeft = 0;
58
+ let memoMouseX = 0;
59
+ let memoMouseY = 0;
60
+ let previousScrollHeight = 0;
61
+ let previousScrollTop = 0;
62
+ const isIos = useIsIos();
63
+ const themeRef = useTheme('SafeTopScrollbar', '-safe-top-scrollbar', style, scrollbarLight, props, mergedClsPrefixRef);
64
+ const yBarSizeRef = computed(() => {
65
+ const { value: containerHeight } = containerHeightRef;
66
+ const { value: contentHeight } = contentHeightRef;
67
+ const { value: yRailSize } = yRailSizeRef;
68
+ if (containerHeight === null ||
69
+ contentHeight === null ||
70
+ yRailSize === null) {
71
+ return 0;
72
+ }
73
+ else {
74
+ return Math.min(containerHeight, (yRailSize * containerHeight) / contentHeight +
75
+ depx(themeRef.value.self.width) * 1.5);
76
+ }
77
+ });
78
+ const yBarSizePxRef = computed(() => {
79
+ return `${yBarSizeRef.value}px`;
80
+ });
81
+ const xBarSizeRef = computed(() => {
82
+ const { value: containerWidth } = containerWidthRef;
83
+ const { value: contentWidth } = contentWidthRef;
84
+ const { value: xRailSize } = xRailSizeRef;
85
+ if (containerWidth === null ||
86
+ contentWidth === null ||
87
+ xRailSize === null) {
88
+ return 0;
89
+ }
90
+ else {
91
+ return ((xRailSize * containerWidth) / contentWidth +
92
+ depx(themeRef.value.self.height) * 1.5);
93
+ }
94
+ });
95
+ const xBarSizePxRef = computed(() => {
96
+ return `${xBarSizeRef.value}px`;
97
+ });
98
+ const yBarTopRef = computed(() => {
99
+ const { value: containerHeight } = containerHeightRef;
100
+ const { value: containerScrollTop } = containerScrollTopRef;
101
+ const { value: contentHeight } = contentHeightRef;
102
+ const { value: yRailSize } = yRailSizeRef;
103
+ if (containerHeight === null ||
104
+ contentHeight === null ||
105
+ yRailSize === null) {
106
+ return 0;
107
+ }
108
+ else {
109
+ const heightDiff = contentHeight - containerHeight;
110
+ if (!heightDiff)
111
+ return 0;
112
+ return ((containerScrollTop / heightDiff) * (yRailSize - yBarSizeRef.value));
113
+ }
114
+ });
115
+ const yBarTopPxRef = computed(() => {
116
+ return `${yBarTopRef.value}px`;
117
+ });
118
+ const xBarLeftRef = computed(() => {
119
+ const { value: containerWidth } = containerWidthRef;
120
+ const { value: containerScrollLeft } = containerScrollLeftRef;
121
+ const { value: contentWidth } = contentWidthRef;
122
+ const { value: xRailSize } = xRailSizeRef;
123
+ if (containerWidth === null ||
124
+ contentWidth === null ||
125
+ xRailSize === null) {
126
+ return 0;
127
+ }
128
+ else {
129
+ const widthDiff = contentWidth - containerWidth;
130
+ if (!widthDiff)
131
+ return 0;
132
+ return ((containerScrollLeft / widthDiff) * (xRailSize - xBarSizeRef.value));
133
+ }
134
+ });
135
+ const xBarLeftPxRef = computed(() => {
136
+ return `${xBarLeftRef.value}px`;
137
+ });
138
+ const needYBarRef = computed(() => {
139
+ const { value: containerHeight } = containerHeightRef;
140
+ const { value: contentHeight } = contentHeightRef;
141
+ return (containerHeight !== null &&
142
+ contentHeight !== null &&
143
+ contentHeight > containerHeight);
144
+ });
145
+ const needXBarRef = computed(() => {
146
+ const { value: containerWidth } = containerWidthRef;
147
+ const { value: contentWidth } = contentWidthRef;
148
+ return (containerWidth !== null &&
149
+ contentWidth !== null &&
150
+ contentWidth > containerWidth);
151
+ });
152
+ const mergedShowXBarRef = computed(() => {
153
+ const { trigger } = props;
154
+ return trigger === 'none' || isShowXBarRef.value;
155
+ });
156
+ const mergedShowYBarRef = computed(() => {
157
+ const { trigger } = props;
158
+ return trigger === 'none' || isShowYBarRef.value;
159
+ });
160
+ const mergedContainerRef = computed(() => {
161
+ const { container } = props;
162
+ if (container)
163
+ return container();
164
+ return containerRef.value;
165
+ });
166
+ const mergedContentRef = computed(() => {
167
+ const { content } = props;
168
+ if (content)
169
+ return content();
170
+ return contentRef.value;
171
+ });
172
+ const scrollTo = (options, y) => {
173
+ if (!props.scrollable)
174
+ return;
175
+ if (typeof options === 'number') {
176
+ scrollToPosition(options, y !== null && y !== void 0 ? y : 0, 0, false, 'auto');
177
+ return;
178
+ }
179
+ const { left, top, index, elSize, position, behavior, el, debounce = true } = options;
180
+ if (left !== undefined || top !== undefined) {
181
+ scrollToPosition(left !== null && left !== void 0 ? left : 0, top !== null && top !== void 0 ? top : 0, 0, false, behavior);
182
+ }
183
+ if (el !== undefined) {
184
+ scrollToPosition(0, el.offsetTop, el.offsetHeight, debounce, behavior);
185
+ }
186
+ else if (index !== undefined && elSize !== undefined) {
187
+ scrollToPosition(0, index * elSize, elSize, debounce, behavior);
188
+ }
189
+ else if (position === 'bottom') {
190
+ scrollToPosition(0, Number.MAX_SAFE_INTEGER, 0, false, behavior);
191
+ }
192
+ else if (position === 'top') {
193
+ scrollToPosition(0, 0, 0, false, behavior);
194
+ }
195
+ };
196
+ const activateState = useReactivated(() => {
197
+ // Only restore for builtin container & content
198
+ if (!props.container) {
199
+ // remount
200
+ scrollTo({
201
+ top: containerScrollTopRef.value,
202
+ left: containerScrollLeftRef.value
203
+ });
204
+ }
205
+ });
206
+ const handleContentResize = () => {
207
+ if (activateState.isDeactivated)
208
+ return;
209
+ const { value: container } = mergedContainerRef;
210
+ if (container && previousScrollHeight > 0) {
211
+ const currentScrollHeight = container.scrollHeight;
212
+ const currentScrollTop = container.scrollTop;
213
+ const savedScrollHeight = previousScrollHeight;
214
+ const savedScrollTop = previousScrollTop;
215
+ const heightDiff = currentScrollHeight - savedScrollHeight;
216
+ if (heightDiff > 0 && currentScrollTop === savedScrollTop) {
217
+ container.scrollTop = savedScrollTop + heightDiff;
218
+ }
219
+ sync();
220
+ }
221
+ else {
222
+ sync();
223
+ }
224
+ };
225
+ const handleContainerResize = (e) => {
226
+ if (activateState.isDeactivated)
227
+ return;
228
+ const { onResize } = props;
229
+ if (onResize) {
230
+ onResize(e);
231
+ }
232
+ sync();
233
+ };
234
+ const scrollBy = (options, y) => {
235
+ if (!props.scrollable)
236
+ return;
237
+ const { value: container } = mergedContainerRef;
238
+ if (!container)
239
+ return;
240
+ if (typeof options === 'object') {
241
+ container.scrollBy(options);
242
+ }
243
+ else {
244
+ container.scrollBy(options, y || 0);
245
+ }
246
+ };
247
+ function scrollToPosition(left, top, elSize, debounce, behavior) {
248
+ const { value: container } = mergedContainerRef;
249
+ if (!container)
250
+ return;
251
+ if (debounce) {
252
+ const { scrollTop, offsetHeight } = container;
253
+ if (top > scrollTop) {
254
+ if (top + elSize <= scrollTop + offsetHeight) {
255
+ // do nothing
256
+ }
257
+ else {
258
+ container.scrollTo({
259
+ left,
260
+ top: top + elSize - offsetHeight,
261
+ behavior
262
+ });
263
+ }
264
+ return;
265
+ }
266
+ }
267
+ container.scrollTo({
268
+ left,
269
+ top,
270
+ behavior
271
+ });
272
+ }
273
+ function handleMouseEnterWrapper() {
274
+ showXBar();
275
+ showYBar();
276
+ sync();
277
+ }
278
+ function handleMouseLeaveWrapper() {
279
+ hideBar();
280
+ }
281
+ function hideBar() {
282
+ hideYBar();
283
+ hideXBar();
284
+ }
285
+ function hideYBar() {
286
+ if (yBarVanishTimerId !== undefined) {
287
+ window.clearTimeout(yBarVanishTimerId);
288
+ }
289
+ yBarVanishTimerId = window.setTimeout(() => {
290
+ isShowYBarRef.value = false;
291
+ }, props.duration);
292
+ }
293
+ function hideXBar() {
294
+ if (xBarVanishTimerId !== undefined) {
295
+ window.clearTimeout(xBarVanishTimerId);
296
+ }
297
+ xBarVanishTimerId = window.setTimeout(() => {
298
+ isShowXBarRef.value = false;
299
+ }, props.duration);
300
+ }
301
+ function showXBar() {
302
+ if (xBarVanishTimerId !== undefined) {
303
+ window.clearTimeout(xBarVanishTimerId);
304
+ }
305
+ isShowXBarRef.value = true;
306
+ }
307
+ function showYBar() {
308
+ if (yBarVanishTimerId !== undefined) {
309
+ window.clearTimeout(yBarVanishTimerId);
310
+ }
311
+ isShowYBarRef.value = true;
312
+ }
313
+ function handleScroll(e) {
314
+ const { onScroll } = props;
315
+ if (onScroll)
316
+ onScroll(e);
317
+ // Save scroll state before syncing
318
+ const { value: container } = mergedContainerRef;
319
+ if (container) {
320
+ previousScrollHeight = container.scrollHeight;
321
+ previousScrollTop = container.scrollTop;
322
+ }
323
+ syncScrollState();
324
+ }
325
+ function syncScrollState() {
326
+ // only collect scroll state, do not trigger any dom event
327
+ const { value: container } = mergedContainerRef;
328
+ if (container) {
329
+ containerScrollTopRef.value = container.scrollTop;
330
+ containerScrollLeftRef.value =
331
+ container.scrollLeft * ((rtlEnabledRef === null || rtlEnabledRef === void 0 ? void 0 : rtlEnabledRef.value) ? -1 : 1);
332
+ }
333
+ }
334
+ function syncPositionState() {
335
+ // only collect position state, do not trigger any dom event
336
+ // Don't use getClientBoundingRect because element may be scale transformed
337
+ const { value: content } = mergedContentRef;
338
+ if (content) {
339
+ contentHeightRef.value = content.offsetHeight;
340
+ contentWidthRef.value = content.offsetWidth;
341
+ }
342
+ const { value: container } = mergedContainerRef;
343
+ if (container) {
344
+ containerHeightRef.value = container.offsetHeight;
345
+ containerWidthRef.value = container.offsetWidth;
346
+ }
347
+ const { value: xRailEl } = xRailRef;
348
+ const { value: yRailEl } = yRailRef;
349
+ if (xRailEl) {
350
+ xRailSizeRef.value = xRailEl.offsetWidth;
351
+ }
352
+ if (yRailEl) {
353
+ yRailSizeRef.value = yRailEl.offsetHeight;
354
+ }
355
+ }
356
+ /**
357
+ * Sometimes there's only one element that we can scroll,
358
+ * For example for textarea, there won't be a content element.
359
+ */
360
+ function syncUnifiedContainer() {
361
+ const { value: container } = mergedContainerRef;
362
+ if (container) {
363
+ containerScrollTopRef.value = container.scrollTop;
364
+ containerScrollLeftRef.value =
365
+ container.scrollLeft * ((rtlEnabledRef === null || rtlEnabledRef === void 0 ? void 0 : rtlEnabledRef.value) ? -1 : 1);
366
+ containerHeightRef.value = container.offsetHeight;
367
+ containerWidthRef.value = container.offsetWidth;
368
+ contentHeightRef.value = container.scrollHeight;
369
+ contentWidthRef.value = container.scrollWidth;
370
+ }
371
+ const { value: xRailEl } = xRailRef;
372
+ const { value: yRailEl } = yRailRef;
373
+ if (xRailEl) {
374
+ xRailSizeRef.value = xRailEl.offsetWidth;
375
+ }
376
+ if (yRailEl) {
377
+ yRailSizeRef.value = yRailEl.offsetHeight;
378
+ }
379
+ }
380
+ function sync() {
381
+ if (!props.scrollable)
382
+ return;
383
+ if (props.useUnifiedContainer) {
384
+ syncUnifiedContainer();
385
+ }
386
+ else {
387
+ syncPositionState();
388
+ syncScrollState();
389
+ }
390
+ // Save current scroll state after sync for next comparison
391
+ const { value: container } = mergedContainerRef;
392
+ if (container) {
393
+ previousScrollHeight = container.scrollHeight;
394
+ previousScrollTop = container.scrollTop;
395
+ }
396
+ }
397
+ function isMouseUpAway(e) {
398
+ var _a;
399
+ return !((_a = wrapperRef.value) === null || _a === void 0 ? void 0 : _a.contains(getPreciseEventTarget(e)));
400
+ }
401
+ function handleXScrollMouseDown(e) {
402
+ e.preventDefault();
403
+ e.stopPropagation();
404
+ xBarPressed = true;
405
+ on('mousemove', window, handleXScrollMouseMove, true);
406
+ on('mouseup', window, handleXScrollMouseUp, true);
407
+ memoXLeft = containerScrollLeftRef.value;
408
+ memoMouseX = (rtlEnabledRef === null || rtlEnabledRef === void 0 ? void 0 : rtlEnabledRef.value)
409
+ ? window.innerWidth - e.clientX
410
+ : e.clientX;
411
+ }
412
+ function handleXScrollMouseMove(e) {
413
+ if (!xBarPressed)
414
+ return;
415
+ if (xBarVanishTimerId !== undefined) {
416
+ window.clearTimeout(xBarVanishTimerId);
417
+ }
418
+ if (yBarVanishTimerId !== undefined) {
419
+ window.clearTimeout(yBarVanishTimerId);
420
+ }
421
+ const { value: containerWidth } = containerWidthRef;
422
+ const { value: contentWidth } = contentWidthRef;
423
+ const { value: xBarSize } = xBarSizeRef;
424
+ if (containerWidth === null || contentWidth === null)
425
+ return;
426
+ const dX = (rtlEnabledRef === null || rtlEnabledRef === void 0 ? void 0 : rtlEnabledRef.value)
427
+ ? window.innerWidth - e.clientX - memoMouseX
428
+ : e.clientX - memoMouseX;
429
+ const dScrollLeft = (dX * (contentWidth - containerWidth)) / (containerWidth - xBarSize);
430
+ const toScrollLeftUpperBound = contentWidth - containerWidth;
431
+ let toScrollLeft = memoXLeft + dScrollLeft;
432
+ toScrollLeft = Math.min(toScrollLeftUpperBound, toScrollLeft);
433
+ toScrollLeft = Math.max(toScrollLeft, 0);
434
+ const { value: container } = mergedContainerRef;
435
+ if (container) {
436
+ container.scrollLeft = toScrollLeft * ((rtlEnabledRef === null || rtlEnabledRef === void 0 ? void 0 : rtlEnabledRef.value) ? -1 : 1);
437
+ const { internalOnUpdateScrollLeft } = props;
438
+ if (internalOnUpdateScrollLeft)
439
+ internalOnUpdateScrollLeft(toScrollLeft);
440
+ }
441
+ }
442
+ function handleXScrollMouseUp(e) {
443
+ e.preventDefault();
444
+ e.stopPropagation();
445
+ off('mousemove', window, handleXScrollMouseMove, true);
446
+ off('mouseup', window, handleXScrollMouseUp, true);
447
+ xBarPressed = false;
448
+ sync();
449
+ if (isMouseUpAway(e)) {
450
+ hideBar();
451
+ }
452
+ }
453
+ function handleYScrollMouseDown(e) {
454
+ e.preventDefault();
455
+ e.stopPropagation();
456
+ yBarPressed = true;
457
+ on('mousemove', window, handleYScrollMouseMove, true);
458
+ on('mouseup', window, handleYScrollMouseUp, true);
459
+ memoYTop = containerScrollTopRef.value;
460
+ memoMouseY = e.clientY;
461
+ }
462
+ function handleYScrollMouseMove(e) {
463
+ if (!yBarPressed)
464
+ return;
465
+ if (xBarVanishTimerId !== undefined) {
466
+ window.clearTimeout(xBarVanishTimerId);
467
+ }
468
+ if (yBarVanishTimerId !== undefined) {
469
+ window.clearTimeout(yBarVanishTimerId);
470
+ }
471
+ const { value: containerHeight } = containerHeightRef;
472
+ const { value: contentHeight } = contentHeightRef;
473
+ const { value: yBarSize } = yBarSizeRef;
474
+ if (containerHeight === null || contentHeight === null)
475
+ return;
476
+ const dY = e.clientY - memoMouseY;
477
+ const dScrollTop = (dY * (contentHeight - containerHeight)) / (containerHeight - yBarSize);
478
+ const toScrollTopUpperBound = contentHeight - containerHeight;
479
+ let toScrollTop = memoYTop + dScrollTop;
480
+ toScrollTop = Math.min(toScrollTopUpperBound, toScrollTop);
481
+ toScrollTop = Math.max(toScrollTop, 0);
482
+ const { value: container } = mergedContainerRef;
483
+ if (container) {
484
+ container.scrollTop = toScrollTop;
485
+ }
486
+ }
487
+ function handleYScrollMouseUp(e) {
488
+ e.preventDefault();
489
+ e.stopPropagation();
490
+ off('mousemove', window, handleYScrollMouseMove, true);
491
+ off('mouseup', window, handleYScrollMouseUp, true);
492
+ yBarPressed = false;
493
+ sync();
494
+ if (isMouseUpAway(e)) {
495
+ hideBar();
496
+ }
497
+ }
498
+ watchEffect(() => {
499
+ const { value: needXBar } = needXBarRef;
500
+ const { value: needYBar } = needYBarRef;
501
+ const { value: mergedClsPrefix } = mergedClsPrefixRef;
502
+ const { value: xRailEl } = xRailRef;
503
+ const { value: yRailEl } = yRailRef;
504
+ if (xRailEl) {
505
+ if (!needXBar) {
506
+ xRailEl.classList.add(`${mergedClsPrefix}-scrollbar-rail--disabled`);
507
+ }
508
+ else {
509
+ xRailEl.classList.remove(`${mergedClsPrefix}-scrollbar-rail--disabled`);
510
+ }
511
+ }
512
+ if (yRailEl) {
513
+ if (!needYBar) {
514
+ yRailEl.classList.add(`${mergedClsPrefix}-scrollbar-rail--disabled`);
515
+ }
516
+ else {
517
+ yRailEl.classList.remove(`${mergedClsPrefix}-scrollbar-rail--disabled`);
518
+ }
519
+ }
520
+ });
521
+ onMounted(() => {
522
+ // if container exist, it always can't be resolved when scrollbar is mounted
523
+ // for example:
524
+ // - component
525
+ // - scrollbar
526
+ // - inner
527
+ // if you pass inner to scrollbar, you may use a ref inside component
528
+ // however, when scrollbar is mounted, ref is not ready at component
529
+ // you need to init by yourself
530
+ if (props.container)
531
+ return;
532
+ sync();
533
+ // Initialize previous values
534
+ const { value: container } = mergedContainerRef;
535
+ if (container) {
536
+ previousScrollHeight = container.scrollHeight;
537
+ previousScrollTop = container.scrollTop;
538
+ }
539
+ });
540
+ onBeforeUnmount(() => {
541
+ if (xBarVanishTimerId !== undefined) {
542
+ window.clearTimeout(xBarVanishTimerId);
543
+ }
544
+ if (yBarVanishTimerId !== undefined) {
545
+ window.clearTimeout(yBarVanishTimerId);
546
+ }
547
+ off('mousemove', window, handleYScrollMouseMove, true);
548
+ off('mouseup', window, handleYScrollMouseUp, true);
549
+ });
550
+ const cssVarsRef = computed(() => {
551
+ const { common: { cubicBezierEaseInOut }, self: { color, colorHover, height, width, borderRadius, railInsetHorizontalTop, railInsetHorizontalBottom, railInsetVerticalRight, railInsetVerticalLeft, railColor } } = themeRef.value;
552
+ const { top: railTopHorizontalTop, right: railRightHorizontalTop, bottom: railBottomHorizontalTop, left: railLeftHorizontalTop } = getPadding(railInsetHorizontalTop);
553
+ const { top: railTopHorizontalBottom, right: railRightHorizontalBottom, bottom: railBottomHorizontalBottom, left: railLeftHorizontalBottom } = getPadding(railInsetHorizontalBottom);
554
+ const { top: railTopVerticalRight, right: railRightVerticalRight, bottom: railBottomVerticalRight, left: railLeftVerticalRight } = getPadding((rtlEnabledRef === null || rtlEnabledRef === void 0 ? void 0 : rtlEnabledRef.value)
555
+ ? rtlInset(railInsetVerticalRight)
556
+ : railInsetVerticalRight);
557
+ const { top: railTopVerticalLeft, right: railRightVerticalLeft, bottom: railBottomVerticalLeft, left: railLeftVerticalLeft } = getPadding((rtlEnabledRef === null || rtlEnabledRef === void 0 ? void 0 : rtlEnabledRef.value)
558
+ ? rtlInset(railInsetVerticalLeft)
559
+ : railInsetVerticalLeft);
560
+ return {
561
+ '--u-scrollbar-bezier': cubicBezierEaseInOut,
562
+ '--u-scrollbar-color': color,
563
+ '--u-scrollbar-color-hover': colorHover,
564
+ '--u-scrollbar-border-radius': borderRadius,
565
+ '--u-scrollbar-width': width,
566
+ '--u-scrollbar-height': height,
567
+ '--u-scrollbar-rail-top-horizontal-top': railTopHorizontalTop,
568
+ '--u-scrollbar-rail-right-horizontal-top': railRightHorizontalTop,
569
+ '--u-scrollbar-rail-bottom-horizontal-top': railBottomHorizontalTop,
570
+ '--u-scrollbar-rail-left-horizontal-top': railLeftHorizontalTop,
571
+ '--u-scrollbar-rail-top-horizontal-bottom': railTopHorizontalBottom,
572
+ '--u-scrollbar-rail-right-horizontal-bottom': railRightHorizontalBottom,
573
+ '--u-scrollbar-rail-bottom-horizontal-bottom': railBottomHorizontalBottom,
574
+ '--u-scrollbar-rail-left-horizontal-bottom': railLeftHorizontalBottom,
575
+ '--u-scrollbar-rail-top-vertical-right': railTopVerticalRight,
576
+ '--u-scrollbar-rail-right-vertical-right': railRightVerticalRight,
577
+ '--u-scrollbar-rail-bottom-vertical-right': railBottomVerticalRight,
578
+ '--u-scrollbar-rail-left-vertical-right': railLeftVerticalRight,
579
+ '--u-scrollbar-rail-top-vertical-left': railTopVerticalLeft,
580
+ '--u-scrollbar-rail-right-vertical-left': railRightVerticalLeft,
581
+ '--u-scrollbar-rail-bottom-vertical-left': railBottomVerticalLeft,
582
+ '--u-scrollbar-rail-left-vertical-left': railLeftVerticalLeft,
583
+ '--u-scrollbar-rail-color': railColor
584
+ };
585
+ });
586
+ const themeClassHandle = inlineThemeDisabled
587
+ ? useThemeClass('scrollbar', undefined, cssVarsRef, props)
588
+ : undefined;
589
+ function getScrollState() {
590
+ const { value: container } = mergedContainerRef;
591
+ if (!container) {
592
+ return { scrollHeight: 0, scrollTop: 0, clientHeight: 0 };
593
+ }
594
+ return {
595
+ scrollHeight: container.scrollHeight,
596
+ scrollTop: container.scrollTop,
597
+ clientHeight: container.clientHeight
598
+ };
599
+ }
600
+ function adjustScrollTop(heightDiff) {
601
+ const { value: container } = mergedContainerRef;
602
+ if (!container)
603
+ return;
604
+ container.scrollTop = container.scrollTop + heightDiff;
605
+ }
606
+ const exposedMethods = {
607
+ scrollTo,
608
+ scrollBy,
609
+ sync,
610
+ syncUnifiedContainer,
611
+ handleMouseEnterWrapper,
612
+ handleMouseLeaveWrapper,
613
+ getScrollState,
614
+ adjustScrollTop
615
+ };
616
+ return Object.assign(Object.assign({}, exposedMethods), { mergedClsPrefix: mergedClsPrefixRef, rtlEnabled: rtlEnabledRef, containerScrollTop: containerScrollTopRef, wrapperRef,
617
+ containerRef,
618
+ contentRef,
619
+ yRailRef,
620
+ xRailRef, needYBar: needYBarRef, needXBar: needXBarRef, yBarSizePx: yBarSizePxRef, xBarSizePx: xBarSizePxRef, yBarTopPx: yBarTopPxRef, xBarLeftPx: xBarLeftPxRef, isShowXBar: mergedShowXBarRef, isShowYBar: mergedShowYBarRef, isIos,
621
+ handleScroll,
622
+ handleContentResize,
623
+ handleContainerResize,
624
+ handleYScrollMouseDown,
625
+ handleXScrollMouseDown, cssVars: inlineThemeDisabled ? undefined : cssVarsRef, themeClass: themeClassHandle === null || themeClassHandle === void 0 ? void 0 : themeClassHandle.themeClass, onRender: themeClassHandle === null || themeClassHandle === void 0 ? void 0 : themeClassHandle.onRender });
626
+ },
627
+ render() {
628
+ var _a;
629
+ const { $slots, mergedClsPrefix, triggerDisplayManually, rtlEnabled, internalHoistYRail, yPlacement, xPlacement, xScrollable } = this;
630
+ if (!this.scrollable)
631
+ return (_a = $slots.default) === null || _a === void 0 ? void 0 : _a.call($slots);
632
+ const triggerIsNone = this.trigger === 'none';
633
+ const createYRail = (className, style) => {
634
+ return (h("div", { ref: "yRailRef", class: [
635
+ `${mergedClsPrefix}-scrollbar-rail`,
636
+ `${mergedClsPrefix}-scrollbar-rail--vertical`,
637
+ `${mergedClsPrefix}-scrollbar-rail--vertical--${yPlacement}`,
638
+ className
639
+ ], "data-scrollbar-rail": true, style: [style || '', this.verticalRailStyle], "aria-hidden": true }, h((triggerIsNone ? Wrapper : Transition), triggerIsNone ? null : { name: 'fade-in-transition' }, {
640
+ default: () => this.needYBar && this.isShowYBar && !this.isIos ? (h("div", { class: `${mergedClsPrefix}-scrollbar-rail__scrollbar`, style: {
641
+ height: this.yBarSizePx,
642
+ top: this.yBarTopPx
643
+ }, onMousedown: this.handleYScrollMouseDown })) : null
644
+ })));
645
+ };
646
+ const createChildren = () => {
647
+ var _a, _b;
648
+ (_a = this.onRender) === null || _a === void 0 ? void 0 : _a.call(this);
649
+ return h('div', mergeProps(this.$attrs, {
650
+ role: 'none',
651
+ ref: 'wrapperRef',
652
+ class: [
653
+ `${mergedClsPrefix}-safe-top-scrollbar`,
654
+ this.themeClass,
655
+ rtlEnabled && `${mergedClsPrefix}-scrollbar--rtl`
656
+ ],
657
+ style: this.cssVars,
658
+ onMouseenter: triggerDisplayManually
659
+ ? undefined
660
+ : this.handleMouseEnterWrapper,
661
+ onMouseleave: triggerDisplayManually
662
+ ? undefined
663
+ : this.handleMouseLeaveWrapper
664
+ }), [
665
+ this.container ? ((_b = $slots.default) === null || _b === void 0 ? void 0 : _b.call($slots)) : (h("div", { role: "none", ref: "containerRef", class: [
666
+ `${mergedClsPrefix}-scrollbar-container`,
667
+ this.containerClass
668
+ ], style: this.containerStyle, onScroll: this.handleScroll, onWheel: this.onWheel },
669
+ h(VResizeObserver, { onResize: this.handleContentResize }, {
670
+ default: () => (h("div", { ref: "contentRef", role: "none", style: [
671
+ {
672
+ width: this.xScrollable ? 'fit-content' : null
673
+ },
674
+ this.contentStyle
675
+ ], class: [
676
+ `${mergedClsPrefix}-scrollbar-content`,
677
+ this.contentClass
678
+ ] }, $slots))
679
+ }))),
680
+ internalHoistYRail ? null : createYRail(undefined, undefined),
681
+ xScrollable && (h("div", { ref: "xRailRef", class: [
682
+ `${mergedClsPrefix}-scrollbar-rail`,
683
+ `${mergedClsPrefix}-scrollbar-rail--horizontal`,
684
+ `${mergedClsPrefix}-scrollbar-rail--horizontal--${xPlacement}`
685
+ ], style: this.horizontalRailStyle, "data-scrollbar-rail": true, "aria-hidden": true }, h((triggerIsNone ? Wrapper : Transition), triggerIsNone ? null : { name: 'fade-in-transition' }, {
686
+ default: () => this.needXBar && this.isShowXBar && !this.isIos ? (h("div", { class: `${mergedClsPrefix}-scrollbar-rail__scrollbar`, style: {
687
+ width: this.xBarSizePx,
688
+ right: rtlEnabled ? this.xBarLeftPx : undefined,
689
+ left: rtlEnabled ? undefined : this.xBarLeftPx
690
+ }, onMousedown: this.handleXScrollMouseDown })) : null
691
+ })))
692
+ ]);
693
+ };
694
+ const scrollbarNode = this.container ? (createChildren()) : (h(VResizeObserver, { onResize: this.handleContainerResize }, {
695
+ default: createChildren
696
+ }));
697
+ if (internalHoistYRail) {
698
+ return (h(Fragment, null,
699
+ scrollbarNode,
700
+ createYRail(this.themeClass, this.cssVars)));
701
+ }
702
+ else {
703
+ return scrollbarNode;
704
+ }
705
+ }
706
+ });
707
+ export default SafeTopScrollbar;
708
+ export const XSafeTopScrollbar = SafeTopScrollbar;