@varlet/ui 2.10.2 → 2.10.3-alpha.1683717781836

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.
@@ -87,7 +87,7 @@ var __sfc__ = defineComponent({
87
87
  bindSwipeItems,
88
88
  length
89
89
  } = useSwipeItems();
90
- var isCalledPrevOrNext = false;
90
+ var initializedIndex = false;
91
91
  var touching = false;
92
92
  var timer = -1;
93
93
  var startX;
@@ -195,7 +195,12 @@ var __sfc__ = defineComponent({
195
195
  };
196
196
 
197
197
  var initialIndex = () => {
198
+ if (initializedIndex) {
199
+ return;
200
+ }
201
+
198
202
  index.value = boundaryIndex(toNumber(props.initialIndex));
203
+ initializedIndex = true;
199
204
  };
200
205
 
201
206
  var startAutoplay = () => {
@@ -326,7 +331,7 @@ var __sfc__ = defineComponent({
326
331
  return;
327
332
  }
328
333
 
329
- isCalledPrevOrNext = true;
334
+ initialIndex();
330
335
  var {
331
336
  loop,
332
337
  onChange
@@ -357,7 +362,7 @@ var __sfc__ = defineComponent({
357
362
  return;
358
363
  }
359
364
 
360
- isCalledPrevOrNext = true;
365
+ initialIndex();
361
366
  var {
362
367
  loop,
363
368
  onChange
@@ -407,11 +412,9 @@ var __sfc__ = defineComponent({
407
412
  };
408
413
  bindSwipeItems(swipeProvider);
409
414
  watch(() => length.value, /*#__PURE__*/_asyncToGenerator(function* () {
410
- isCalledPrevOrNext = false; // In nuxt, the size of the swipe cannot got when the route is change, need double raf
411
-
412
- yield doubleRaf(); // When double raf prev or next is called will block initialIndex
413
-
414
- !isCalledPrevOrNext && initialIndex();
415
+ // In nuxt, the size of the swipe cannot got when the route is change, need double raf
416
+ yield doubleRaf();
417
+ initialIndex();
415
418
  resize();
416
419
  }));
417
420
  onActivated(resize);
@@ -7,7 +7,7 @@ var {
7
7
  n,
8
8
  classes
9
9
  } = createNamespace('tab-item');
10
- import { renderSlot as _renderSlot, createCommentVNode as _createCommentVNode, resolveComponent as _resolveComponent, normalizeClass as _normalizeClass, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock } from "vue";
10
+ import { renderSlot as _renderSlot, resolveComponent as _resolveComponent, normalizeClass as _normalizeClass, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock } from "vue";
11
11
 
12
12
  function __render__(_ctx, _cache) {
13
13
  var _component_var_swipe_item = _resolveComponent("var-swipe-item");
@@ -16,9 +16,7 @@ function __render__(_ctx, _cache) {
16
16
  class: _normalizeClass(_ctx.classes(_ctx.n(), [!_ctx.current, _ctx.n('--inactive')])),
17
17
  "var-tab-item-cover": ""
18
18
  }, {
19
- default: _withCtx(() => [_ctx.initSlot ? _renderSlot(_ctx.$slots, "default", {
20
- key: 0
21
- }) : _createCommentVNode("v-if", true)]),
19
+ default: _withCtx(() => [_renderSlot(_ctx.$slots, "default")]),
22
20
  _: 3
23
21
  /* FORWARDED */
24
22
 
@@ -36,7 +34,6 @@ var __sfc__ = defineComponent({
36
34
 
37
35
  setup(props) {
38
36
  var current = ref(false);
39
- var initSlot = ref(false);
40
37
  var name = computed(() => props.name);
41
38
  var {
42
39
  index,
@@ -44,10 +41,6 @@ var __sfc__ = defineComponent({
44
41
  } = useTabsItems();
45
42
 
46
43
  var setCurrent = value => {
47
- if (!initSlot.value && value) {
48
- initSlot.value = true;
49
- }
50
-
51
44
  current.value = value;
52
45
  };
53
46
 
@@ -60,8 +53,7 @@ var __sfc__ = defineComponent({
60
53
  return {
61
54
  n,
62
55
  classes,
63
- current,
64
- initSlot
56
+ current
65
57
  };
66
58
  }
67
59
 
@@ -1,20 +1,43 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
-
5
- import { isNumber, isObject, isString, kebabCase, toNumber } from '@varlet/shared';
3
+ import { isNumber, isObject, isString, kebabCase, toNumber, isWindow } from '@varlet/shared';
6
4
  import { getGlobalThis } from './shared.mjs';
7
5
  import { error } from '../utils/logger.mjs';
6
+ // shorthand only
7
+ export function getStyle(element) {
8
+ return window.getComputedStyle(element);
9
+ }
10
+ export function getRect(element) {
11
+ if (isWindow(element)) {
12
+ var width = element.innerWidth;
13
+ var height = element.innerHeight;
14
+ var rect = {
15
+ x: 0,
16
+ y: 0,
17
+ top: 0,
18
+ left: 0,
19
+ right: width,
20
+ bottom: height,
21
+ width,
22
+ height
23
+ };
24
+ return _extends({}, rect, {
25
+ toJSON: () => rect
26
+ });
27
+ }
28
+
29
+ return element.getBoundingClientRect();
30
+ }
8
31
  export function getLeft(element) {
9
32
  var {
10
33
  left
11
- } = element.getBoundingClientRect();
34
+ } = getRect(element);
12
35
  return left + (document.body.scrollLeft || document.documentElement.scrollLeft);
13
36
  }
14
37
  export function getTop(element) {
15
38
  var {
16
39
  top
17
- } = element.getBoundingClientRect();
40
+ } = getRect(element);
18
41
  return top + (document.body.scrollTop || document.documentElement.scrollTop);
19
42
  }
20
43
  export function getScrollTop(element) {
@@ -26,34 +49,25 @@ export function getScrollLeft(element) {
26
49
  var left = 'scrollLeft' in element ? element.scrollLeft : element.pageXOffset;
27
50
  return Math.max(left, 0);
28
51
  }
29
- export function inViewport(_x) {
30
- return _inViewport.apply(this, arguments);
31
- }
32
-
33
- function _inViewport() {
34
- _inViewport = _asyncToGenerator(function* (element) {
35
- yield doubleRaf();
36
- var {
37
- top,
38
- bottom,
39
- left,
40
- right
41
- } = element.getBoundingClientRect();
42
- var {
43
- innerWidth,
44
- innerHeight
45
- } = window;
46
- var xInViewport = left <= innerWidth && right >= 0;
47
- var yInViewport = top <= innerHeight && bottom >= 0;
48
- return xInViewport && yInViewport;
49
- });
50
- return _inViewport.apply(this, arguments);
52
+ export function inViewport(element) {
53
+ var {
54
+ top,
55
+ bottom,
56
+ left,
57
+ right
58
+ } = getRect(element);
59
+ var {
60
+ width,
61
+ height
62
+ } = getRect(window);
63
+ var xInViewport = left <= width && right >= 0;
64
+ var yInViewport = top <= height && bottom >= 0;
65
+ return xInViewport && yInViewport;
51
66
  }
52
-
53
67
  export function getTranslate(el) {
54
68
  var {
55
69
  transform
56
- } = window.getComputedStyle(el);
70
+ } = getStyle(el);
57
71
  return +transform.slice(transform.lastIndexOf(',') + 2, transform.length - 1);
58
72
  }
59
73
  export function getParentScroller(el) {
@@ -74,7 +88,7 @@ export function getParentScroller(el) {
74
88
  var {
75
89
  overflowY,
76
90
  overflow
77
- } = window.getComputedStyle(element);
91
+ } = getStyle(element);
78
92
 
79
93
  if (scrollRE.test(overflowY) || scrollRE.test(overflow)) {
80
94
  return element;
@@ -87,7 +101,7 @@ export function getAllParentScroller(el) {
87
101
  var allParentScroller = [];
88
102
  var element = el;
89
103
 
90
- while (element !== window) {
104
+ while (!isWindow(element)) {
91
105
  element = getParentScroller(element);
92
106
  allParentScroller.push(element);
93
107
  }
@@ -110,15 +124,15 @@ export function getTarget(target, componentName) {
110
124
  }
111
125
  export function getViewportSize() {
112
126
  var {
113
- innerWidth,
114
- innerHeight
115
- } = window;
116
- return innerWidth > innerHeight ? {
117
- vMin: innerHeight,
118
- vMax: innerWidth
127
+ width,
128
+ height
129
+ } = getRect(window);
130
+ return width > height ? {
131
+ vMin: height,
132
+ vMax: width
119
133
  } : {
120
- vMin: innerWidth,
121
- vMax: innerHeight
134
+ vMin: width,
135
+ vMax: height
122
136
  };
123
137
  } // example 1rem
124
138
 
@@ -149,17 +163,22 @@ export var toPxNum = value => {
149
163
  return +value.replace('px', '');
150
164
  }
151
165
 
166
+ var {
167
+ width,
168
+ height
169
+ } = getRect(window);
170
+
152
171
  if (isVw(value)) {
153
- return +value.replace('vw', '') * window.innerWidth / 100;
172
+ return +value.replace('vw', '') * width / 100;
154
173
  }
155
174
 
156
175
  if (isVh(value)) {
157
- return +value.replace('vh', '') * window.innerHeight / 100;
176
+ return +value.replace('vh', '') * height / 100;
158
177
  }
159
178
 
160
179
  if (isRem(value)) {
161
180
  var num = +value.replace('rem', '');
162
- var rootFontSize = window.getComputedStyle(document.documentElement).fontSize;
181
+ var rootFontSize = getStyle(document.documentElement).fontSize;
163
182
  return num * parseFloat(rootFontSize);
164
183
  }
165
184