@v-c/trigger 1.0.1 → 1.0.2

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.
@@ -69,10 +69,14 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
69
69
  onBeforeEnter: (element) => {
70
70
  onPrepare?.();
71
71
  baseTransitionProps?.onBeforeEnter?.(element);
72
- onVisibleChanged?.(true);
73
72
  },
74
73
  onAfterEnter: (element) => {
75
74
  baseTransitionProps?.onAfterEnter?.(element);
75
+ requestAnimationFrame(() => {
76
+ requestAnimationFrame(() => {
77
+ onVisibleChanged?.(true);
78
+ });
79
+ });
76
80
  },
77
81
  onAfterLeave: (element) => {
78
82
  baseTransitionProps.onAfterLeave?.(element);
@@ -137,7 +141,7 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
137
141
  default: void 0
138
142
  },
139
143
  style: {
140
- type: null,
144
+ type: Object,
141
145
  required: false,
142
146
  default: void 0
143
147
  },
@@ -148,7 +152,6 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
148
152
  default: void 0
149
153
  },
150
154
  target: {
151
- type: null,
152
155
  required: true,
153
156
  default: void 0
154
157
  },
@@ -248,7 +251,6 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
248
251
  default: void 0
249
252
  },
250
253
  portal: {
251
- type: null,
252
254
  required: true,
253
255
  default: void 0
254
256
  },
@@ -278,7 +280,6 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
278
280
  default: void 0
279
281
  },
280
282
  onAlign: {
281
- type: null,
282
283
  required: true,
283
284
  default: void 0
284
285
  },
@@ -303,7 +304,6 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
303
304
  default: void 0
304
305
  },
305
306
  onResize: {
306
- type: null,
307
307
  required: false,
308
308
  default: void 0
309
309
  },
@@ -66,10 +66,14 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
66
66
  onBeforeEnter: (element) => {
67
67
  onPrepare?.();
68
68
  baseTransitionProps?.onBeforeEnter?.(element);
69
- onVisibleChanged?.(true);
70
69
  },
71
70
  onAfterEnter: (element) => {
72
71
  baseTransitionProps?.onAfterEnter?.(element);
72
+ requestAnimationFrame(() => {
73
+ requestAnimationFrame(() => {
74
+ onVisibleChanged?.(true);
75
+ });
76
+ });
73
77
  },
74
78
  onAfterLeave: (element) => {
75
79
  baseTransitionProps.onAfterLeave?.(element);
@@ -134,7 +138,7 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
134
138
  default: void 0
135
139
  },
136
140
  style: {
137
- type: null,
141
+ type: Object,
138
142
  required: false,
139
143
  default: void 0
140
144
  },
@@ -145,7 +149,6 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
145
149
  default: void 0
146
150
  },
147
151
  target: {
148
- type: null,
149
152
  required: true,
150
153
  default: void 0
151
154
  },
@@ -245,7 +248,6 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
245
248
  default: void 0
246
249
  },
247
250
  portal: {
248
- type: null,
249
251
  required: true,
250
252
  default: void 0
251
253
  },
@@ -275,7 +277,6 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
275
277
  default: void 0
276
278
  },
277
279
  onAlign: {
278
- type: null,
279
280
  required: true,
280
281
  default: void 0
281
282
  },
@@ -300,7 +301,6 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
300
301
  default: void 0
301
302
  },
302
303
  onResize: {
303
- type: null,
304
304
  required: false,
305
305
  default: void 0
306
306
  },
@@ -12,8 +12,7 @@ var UniqueContainer = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
12
12
  (0, vue.watchEffect)(() => {
13
13
  if (ready.value) cachedOffsetStyleRef.value = offsetStyle.value;
14
14
  });
15
- (0, vue.watch)(open, async (nextVisible) => {
16
- await (0, vue.nextTick)();
15
+ (0, vue.watch)(open, (nextVisible) => {
17
16
  if (nextVisible) motionVisible.value = true;
18
17
  });
19
18
  return () => {
@@ -36,6 +35,7 @@ var UniqueContainer = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
36
35
  },
37
36
  onAfterLeave: (element) => {
38
37
  motionVisible.value = false;
38
+ cachedOffsetStyleRef.value = {};
39
39
  baseTransitionProps.onAfterLeave?.(element);
40
40
  }
41
41
  };
@@ -124,7 +124,7 @@ var UniqueContainer = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
124
124
  default: void 0
125
125
  },
126
126
  uniqueContainerStyle: {
127
- type: null,
127
+ type: Object,
128
128
  required: false,
129
129
  default: void 0
130
130
  }
@@ -1,5 +1,5 @@
1
1
  import useOffsetStyle from "../hooks/useOffsetStyle.js";
2
- import { Transition, createVNode, defineComponent, nextTick, shallowRef, vShow, watch, watchEffect, withDirectives } from "vue";
2
+ import { Transition, createVNode, defineComponent, shallowRef, vShow, watch, watchEffect, withDirectives } from "vue";
3
3
  import { toPropsRefs } from "@v-c/util/dist/props-util";
4
4
  import { getTransitionProps } from "@v-c/util/dist/utils/transition";
5
5
  var UniqueContainer_default = /* @__PURE__ */ defineComponent((props) => {
@@ -10,8 +10,7 @@ var UniqueContainer_default = /* @__PURE__ */ defineComponent((props) => {
10
10
  watchEffect(() => {
11
11
  if (ready.value) cachedOffsetStyleRef.value = offsetStyle.value;
12
12
  });
13
- watch(open, async (nextVisible) => {
14
- await nextTick();
13
+ watch(open, (nextVisible) => {
15
14
  if (nextVisible) motionVisible.value = true;
16
15
  });
17
16
  return () => {
@@ -34,6 +33,7 @@ var UniqueContainer_default = /* @__PURE__ */ defineComponent((props) => {
34
33
  },
35
34
  onAfterLeave: (element) => {
36
35
  motionVisible.value = false;
36
+ cachedOffsetStyleRef.value = {};
37
37
  baseTransitionProps.onAfterLeave?.(element);
38
38
  }
39
39
  };
@@ -122,7 +122,7 @@ var UniqueContainer_default = /* @__PURE__ */ defineComponent((props) => {
122
122
  default: void 0
123
123
  },
124
124
  uniqueContainerStyle: {
125
- type: null,
125
+ type: Object,
126
126
  required: false,
127
127
  default: void 0
128
128
  }
@@ -55,10 +55,19 @@ var UniqueProvider = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots })
55
55
  trigger(false);
56
56
  }, delay);
57
57
  };
58
+ const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, , , alignInfo, onAlign] = require_useAlign.default(open, popupEle, (0, vue.computed)(() => mergedOptions.value?.target), (0, vue.computed)(() => mergedOptions.value?.popupPlacement), (0, vue.computed)(() => mergedOptions.value?.builtinPlacements || {}), (0, vue.computed)(() => mergedOptions.value?.popupAlign), void 0, (0, vue.ref)(false));
59
+ const inMotion = (0, vue.shallowRef)(false);
60
+ (0, vue.watch)(open, () => {
61
+ if (open.value) inMotion.value = true;
62
+ });
63
+ const triggerAlign = () => {
64
+ if (!inMotion.value) onAlign();
65
+ };
58
66
  const onVisibleChanged = (visible) => {
59
67
  onTargetVisibleChanged(visible);
68
+ inMotion.value = false;
69
+ onAlign();
60
70
  };
61
- const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, , , alignInfo, onAlign] = require_useAlign.default(open, popupEle, (0, vue.computed)(() => mergedOptions.value?.target), (0, vue.computed)(() => mergedOptions.value?.popupPlacement), (0, vue.computed)(() => mergedOptions.value?.builtinPlacements || {}), (0, vue.computed)(() => mergedOptions.value?.popupAlign), void 0, (0, vue.ref)(false));
62
71
  const alignedClassName = (0, vue.computed)(() => {
63
72
  if (!mergedOptions.value) return "";
64
73
  return (0, __v_c_util.classNames)(require_util.getAlignPopupClassName(mergedOptions.value?.builtinPlacements || {}, mergedOptions.value.prefixCls || "", alignInfo.value, false), mergedOptions.value?.getPopupClassNameFromAlign?.(alignInfo.value));
@@ -69,7 +78,7 @@ var UniqueProvider = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots })
69
78
  };
70
79
  (0, vue.watch)(() => mergedOptions.value?.target, () => {
71
80
  onAlign();
72
- }, { immediate: true });
81
+ });
73
82
  const onPrepare = () => {
74
83
  onAlign();
75
84
  return Promise.resolve();
@@ -103,7 +112,7 @@ var UniqueProvider = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots })
103
112
  "offsetY": offsetY.value,
104
113
  "offsetR": offsetR.value,
105
114
  "offsetB": offsetB.value,
106
- "onAlign": onAlign,
115
+ "onAlign": triggerAlign,
107
116
  "onPrepare": onPrepare,
108
117
  "onResize": (size) => {
109
118
  popupSize.value = {
@@ -52,10 +52,19 @@ var UniqueProvider_default = /* @__PURE__ */ defineComponent((props, { slots })
52
52
  trigger(false);
53
53
  }, delay);
54
54
  };
55
+ const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, , , alignInfo, onAlign] = useAlign(open, popupEle, computed(() => mergedOptions.value?.target), computed(() => mergedOptions.value?.popupPlacement), computed(() => mergedOptions.value?.builtinPlacements || {}), computed(() => mergedOptions.value?.popupAlign), void 0, ref(false));
56
+ const inMotion = shallowRef(false);
57
+ watch(open, () => {
58
+ if (open.value) inMotion.value = true;
59
+ });
60
+ const triggerAlign = () => {
61
+ if (!inMotion.value) onAlign();
62
+ };
55
63
  const onVisibleChanged = (visible) => {
56
64
  onTargetVisibleChanged(visible);
65
+ inMotion.value = false;
66
+ onAlign();
57
67
  };
58
- const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, , , alignInfo, onAlign] = useAlign(open, popupEle, computed(() => mergedOptions.value?.target), computed(() => mergedOptions.value?.popupPlacement), computed(() => mergedOptions.value?.builtinPlacements || {}), computed(() => mergedOptions.value?.popupAlign), void 0, ref(false));
59
68
  const alignedClassName = computed(() => {
60
69
  if (!mergedOptions.value) return "";
61
70
  return classNames(getAlignPopupClassName(mergedOptions.value?.builtinPlacements || {}, mergedOptions.value.prefixCls || "", alignInfo.value, false), mergedOptions.value?.getPopupClassNameFromAlign?.(alignInfo.value));
@@ -66,7 +75,7 @@ var UniqueProvider_default = /* @__PURE__ */ defineComponent((props, { slots })
66
75
  };
67
76
  watch(() => mergedOptions.value?.target, () => {
68
77
  onAlign();
69
- }, { immediate: true });
78
+ });
70
79
  const onPrepare = () => {
71
80
  onAlign();
72
81
  return Promise.resolve();
@@ -100,7 +109,7 @@ var UniqueProvider_default = /* @__PURE__ */ defineComponent((props, { slots })
100
109
  "offsetY": offsetY.value,
101
110
  "offsetR": offsetR.value,
102
111
  "offsetB": offsetB.value,
103
- "onAlign": onAlign,
112
+ "onAlign": triggerAlign,
104
113
  "onPrepare": onPrepare,
105
114
  "onResize": (size) => {
106
115
  popupSize.value = {
@@ -11,7 +11,6 @@ function useTargetState() {
11
11
  if (nextOptions === false) {
12
12
  pendingOptionsRef.value = null;
13
13
  open.value = false;
14
- isAnimating.value = false;
15
14
  } else if (isAnimating.value && wasOpen) pendingOptionsRef.value = nextOptions;
16
15
  else {
17
16
  open.value = true;
@@ -9,7 +9,6 @@ function useTargetState() {
9
9
  if (nextOptions === false) {
10
10
  pendingOptionsRef.value = null;
11
11
  open.value = false;
12
- isAnimating.value = false;
13
12
  } else if (isAnimating.value && wasOpen) pendingOptionsRef.value = nextOptions;
14
13
  else {
15
14
  open.value = true;
@@ -5,7 +5,6 @@ let vue = require("vue");
5
5
  let __v_c_util_dist_Dom_findDOMNode = require("@v-c/util/dist/Dom/findDOMNode");
6
6
  let __v_c_util_dist_Dom_isVisible = require("@v-c/util/dist/Dom/isVisible");
7
7
  __v_c_util_dist_Dom_isVisible = require_rolldown_runtime.__toESM(__v_c_util_dist_Dom_isVisible);
8
- let __v_c_util_dist_raf = require("@v-c/util/dist/raf");
9
8
  function getUnitOffset(size, offset = 0) {
10
9
  const offsetStr = `${offset}`;
11
10
  const cells = offsetStr.match(/^(.*)\%$/);
@@ -47,46 +46,6 @@ function reversePoints(points, index) {
47
46
  return point;
48
47
  }).join("");
49
48
  }
50
- function parseOriginValue(value, size, axis) {
51
- const fallback = size / 2;
52
- if (!value) return fallback;
53
- const val = value.trim();
54
- if (!val) return fallback;
55
- if (val.endsWith("%")) return size * (parseFloat(val) / 100);
56
- if (val.endsWith("px")) return parseFloat(val);
57
- if (val === "center") return fallback;
58
- if (axis === "x") {
59
- if (val === "left") return 0;
60
- if (val === "right") return size;
61
- } else if (axis === "y") {
62
- if (val === "top") return 0;
63
- if (val === "bottom") return size;
64
- }
65
- const num = parseFloat(val);
66
- return Number.isNaN(num) ? fallback : num;
67
- }
68
- function getTransformOriginPoint(origin, width, height) {
69
- const [originX = "50%", originY = "50%"] = origin?.split(/\s+/).filter(Boolean) ?? [];
70
- return [parseOriginValue(originX, width, "x"), parseOriginValue(originY, height, "y")];
71
- }
72
- function normalizeRect(rect, scaleX, scaleY, originX, originY) {
73
- const rawX = rect.x ?? rect.left;
74
- const rawY = rect.y ?? rect.top;
75
- const width = rect.width / scaleX;
76
- const height = rect.height / scaleY;
77
- const x = rawX - (1 - scaleX) * originX;
78
- const y = rawY - (1 - scaleY) * originY;
79
- return {
80
- x,
81
- y,
82
- width,
83
- height,
84
- left: x,
85
- top: y,
86
- right: x + width,
87
- bottom: y + height
88
- };
89
- }
90
49
  function shouldSwitchPlacement(isOverflow, isVisibleFirst, newVisibleArea, originVisibleArea, newRecommendArea, originRecommendArea) {
91
50
  if (isOverflow) return newVisibleArea > originVisibleArea || newVisibleArea === originVisibleArea && (!isVisibleFirst || newRecommendArea >= originRecommendArea);
92
51
  return newVisibleArea > originVisibleArea || isVisibleFirst && newVisibleArea === originVisibleArea && newRecommendArea > originRecommendArea;
@@ -113,7 +72,9 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
113
72
  const resetFlipCache = () => {
114
73
  prevFlipRef.value = {};
115
74
  };
116
- const _onAlign = () => {
75
+ let cacheTargetRect = null;
76
+ const _onAlign = (cache = false) => {
77
+ if (cache && !cacheTargetRect) return;
117
78
  if (popupEle.value && target.value && open.value && !mobile?.value) {
118
79
  const popupElement = popupEle.value;
119
80
  const doc = popupElement.ownerDocument;
@@ -148,7 +109,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
148
109
  height: 0
149
110
  };
150
111
  else {
151
- const rect = target.value.getBoundingClientRect();
112
+ const targetRectInfo = target.value.getBoundingClientRect();
113
+ const rect = cache ? Object.assign(targetRectInfo, cacheTargetRect ?? {}) : targetRectInfo;
114
+ if (!cache) cacheTargetRect = {
115
+ width: rect.width,
116
+ height: rect.height
117
+ };
152
118
  rect.x = rect.x ?? rect.left;
153
119
  rect.y = rect.y ?? rect.top;
154
120
  targetRect = {
@@ -194,20 +160,16 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
194
160
  popupElement.style.bottom = originBottom;
195
161
  popupElement.style.overflow = originOverflow;
196
162
  popupElement.parentElement?.removeChild(placeholderElement);
197
- const widthValue = parseFloat(popupComputedStyle.width);
198
- const heightValue = parseFloat(popupComputedStyle.height);
199
- const baseWidth = !Number.isNaN(widthValue) && widthValue > 0 ? widthValue : popupElement.offsetWidth;
200
- const baseHeight = !Number.isNaN(heightValue) && heightValue > 0 ? heightValue : popupElement.offsetHeight;
201
- const safeBaseWidth = baseWidth || rawPopupRect.width || 1;
202
- const safeBaseHeight = baseHeight || rawPopupRect.height || 1;
203
- const scaleX$1 = require_util.toNum(Math.round(rawPopupRect.width / safeBaseWidth * 1e3) / 1e3);
204
- const scaleY$1 = require_util.toNum(Math.round(rawPopupRect.height / safeBaseHeight * 1e3) / 1e3);
205
- if (scaleX$1 === 0 || scaleY$1 === 0 || (0, __v_c_util_dist_Dom_findDOMNode.isDOM)(target) && !(0, __v_c_util_dist_Dom_isVisible.default)(target)) return;
206
- const [originX, originY] = getTransformOriginPoint(popupComputedStyle.transformOrigin, safeBaseWidth, safeBaseHeight);
207
- const popupRect = normalizeRect(rawPopupRect, scaleX$1, scaleY$1, originX, originY);
208
- const popupMirrorRect = normalizeRect(rawPopupMirrorRect, scaleX$1, scaleY$1, originX, originY);
163
+ const popupRect = rawPopupRect;
164
+ popupRect.x = popupRect.x ?? popupRect.left;
165
+ popupRect.y = popupRect.y ?? popupRect.top;
166
+ const { height, width } = popupComputedStyle;
209
167
  const popupHeight = popupRect.height;
210
168
  const popupWidth = popupRect.width;
169
+ const popupMirrorRect = rawPopupMirrorRect;
170
+ const scaleX$1 = require_util.toNum(Math.round(popupWidth / parseFloat(width) * 1e3) / 1e3);
171
+ const scaleY$1 = require_util.toNum(Math.round(popupHeight / parseFloat(height) * 1e3) / 1e3);
172
+ if (scaleX$1 === 0 || scaleY$1 === 0 || (0, __v_c_util_dist_Dom_findDOMNode.isDOM)(target) && !(0, __v_c_util_dist_Dom_isVisible.default)(target)) return;
211
173
  const { offset, targetOffset } = placementInfo;
212
174
  let [popupOffsetX, popupOffsetY] = getNumberOffset(popupRect, offset);
213
175
  const [targetOffsetX, targetOffsetY] = getNumberOffset(targetRect, targetOffset);
@@ -352,12 +314,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
352
314
  }
353
315
  const nextOffsetInfo = {
354
316
  ready: true,
355
- offsetX: nextOffsetX,
356
- offsetY: nextOffsetY,
357
- offsetR: offsetX4Right,
358
- offsetB: offsetY4Bottom,
359
- arrowX: nextArrowX,
360
- arrowY: nextArrowY,
317
+ offsetX: nextOffsetX / scaleX$1,
318
+ offsetY: nextOffsetY / scaleY$1,
319
+ offsetR: offsetX4Right / scaleX$1,
320
+ offsetB: offsetY4Bottom / scaleY$1,
321
+ arrowX: nextArrowX / scaleX$1,
322
+ arrowY: nextArrowY / scaleY$1,
361
323
  scaleX: scaleX$1,
362
324
  scaleY: scaleY$1,
363
325
  align: nextAlignInfo
@@ -365,12 +327,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
365
327
  Object.assign(offsetInfo, nextOffsetInfo);
366
328
  }
367
329
  };
368
- const onAlign = (0, __v_c_util_dist_raf.rafDebounce)(_onAlign);
369
- const triggerAlign = () => {
330
+ const onAlign = _onAlign;
331
+ const triggerAlign = (cache) => {
370
332
  alignCountRef.value += 1;
371
333
  const id = alignCountRef.value;
372
334
  Promise.resolve().then(() => {
373
- if (alignCountRef.value === id) onAlign();
335
+ if (alignCountRef.value === id) onAlign(cache);
374
336
  });
375
337
  };
376
338
  (0, vue.watch)(popupEle, async (ele) => {
@@ -1,4 +1,4 @@
1
1
  import { Ref } from 'vue';
2
2
  import { TriggerProps } from '../index.tsx';
3
3
  import { AlignType } from '../interface';
4
- export default function useAlign(open: Ref<boolean>, popupEle: Ref<HTMLElement>, target: Ref<HTMLElement | [x: number, y: number]>, placement: Ref<string>, builtinPlacements: Ref<any>, popupAlign?: Ref<AlignType | undefined>, onPopupAlign?: TriggerProps['onPopupAlign'], mobile?: Ref<boolean | undefined>): readonly [Ref<boolean, boolean>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<any, any>, () => void];
4
+ export default function useAlign(open: Ref<boolean>, popupEle: Ref<HTMLElement>, target: Ref<HTMLElement | [x: number, y: number]>, placement: Ref<string>, builtinPlacements: Ref<any>, popupAlign?: Ref<AlignType | undefined>, onPopupAlign?: TriggerProps['onPopupAlign'], mobile?: Ref<boolean | undefined>): readonly [Ref<boolean, boolean>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<any, any>, (cache?: boolean) => void];
@@ -2,7 +2,6 @@ import { collectScroller, getVisibleArea, getWin, toNum } from "../util.js";
2
2
  import { computed, nextTick, reactive, ref, shallowRef, toRefs, watch } from "vue";
3
3
  import { isDOM } from "@v-c/util/dist/Dom/findDOMNode";
4
4
  import isVisible from "@v-c/util/dist/Dom/isVisible";
5
- import { rafDebounce } from "@v-c/util/dist/raf";
6
5
  function getUnitOffset(size, offset = 0) {
7
6
  const offsetStr = `${offset}`;
8
7
  const cells = offsetStr.match(/^(.*)\%$/);
@@ -44,46 +43,6 @@ function reversePoints(points, index) {
44
43
  return point;
45
44
  }).join("");
46
45
  }
47
- function parseOriginValue(value, size, axis) {
48
- const fallback = size / 2;
49
- if (!value) return fallback;
50
- const val = value.trim();
51
- if (!val) return fallback;
52
- if (val.endsWith("%")) return size * (parseFloat(val) / 100);
53
- if (val.endsWith("px")) return parseFloat(val);
54
- if (val === "center") return fallback;
55
- if (axis === "x") {
56
- if (val === "left") return 0;
57
- if (val === "right") return size;
58
- } else if (axis === "y") {
59
- if (val === "top") return 0;
60
- if (val === "bottom") return size;
61
- }
62
- const num = parseFloat(val);
63
- return Number.isNaN(num) ? fallback : num;
64
- }
65
- function getTransformOriginPoint(origin, width, height) {
66
- const [originX = "50%", originY = "50%"] = origin?.split(/\s+/).filter(Boolean) ?? [];
67
- return [parseOriginValue(originX, width, "x"), parseOriginValue(originY, height, "y")];
68
- }
69
- function normalizeRect(rect, scaleX, scaleY, originX, originY) {
70
- const rawX = rect.x ?? rect.left;
71
- const rawY = rect.y ?? rect.top;
72
- const width = rect.width / scaleX;
73
- const height = rect.height / scaleY;
74
- const x = rawX - (1 - scaleX) * originX;
75
- const y = rawY - (1 - scaleY) * originY;
76
- return {
77
- x,
78
- y,
79
- width,
80
- height,
81
- left: x,
82
- top: y,
83
- right: x + width,
84
- bottom: y + height
85
- };
86
- }
87
46
  function shouldSwitchPlacement(isOverflow, isVisibleFirst, newVisibleArea, originVisibleArea, newRecommendArea, originRecommendArea) {
88
47
  if (isOverflow) return newVisibleArea > originVisibleArea || newVisibleArea === originVisibleArea && (!isVisibleFirst || newRecommendArea >= originRecommendArea);
89
48
  return newVisibleArea > originVisibleArea || isVisibleFirst && newVisibleArea === originVisibleArea && newRecommendArea > originRecommendArea;
@@ -110,7 +69,9 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
110
69
  const resetFlipCache = () => {
111
70
  prevFlipRef.value = {};
112
71
  };
113
- const _onAlign = () => {
72
+ let cacheTargetRect = null;
73
+ const _onAlign = (cache = false) => {
74
+ if (cache && !cacheTargetRect) return;
114
75
  if (popupEle.value && target.value && open.value && !mobile?.value) {
115
76
  const popupElement = popupEle.value;
116
77
  const doc = popupElement.ownerDocument;
@@ -145,7 +106,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
145
106
  height: 0
146
107
  };
147
108
  else {
148
- const rect = target.value.getBoundingClientRect();
109
+ const targetRectInfo = target.value.getBoundingClientRect();
110
+ const rect = cache ? Object.assign(targetRectInfo, cacheTargetRect ?? {}) : targetRectInfo;
111
+ if (!cache) cacheTargetRect = {
112
+ width: rect.width,
113
+ height: rect.height
114
+ };
149
115
  rect.x = rect.x ?? rect.left;
150
116
  rect.y = rect.y ?? rect.top;
151
117
  targetRect = {
@@ -191,20 +157,16 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
191
157
  popupElement.style.bottom = originBottom;
192
158
  popupElement.style.overflow = originOverflow;
193
159
  popupElement.parentElement?.removeChild(placeholderElement);
194
- const widthValue = parseFloat(popupComputedStyle.width);
195
- const heightValue = parseFloat(popupComputedStyle.height);
196
- const baseWidth = !Number.isNaN(widthValue) && widthValue > 0 ? widthValue : popupElement.offsetWidth;
197
- const baseHeight = !Number.isNaN(heightValue) && heightValue > 0 ? heightValue : popupElement.offsetHeight;
198
- const safeBaseWidth = baseWidth || rawPopupRect.width || 1;
199
- const safeBaseHeight = baseHeight || rawPopupRect.height || 1;
200
- const scaleX$1 = toNum(Math.round(rawPopupRect.width / safeBaseWidth * 1e3) / 1e3);
201
- const scaleY$1 = toNum(Math.round(rawPopupRect.height / safeBaseHeight * 1e3) / 1e3);
202
- if (scaleX$1 === 0 || scaleY$1 === 0 || isDOM(target) && !isVisible(target)) return;
203
- const [originX, originY] = getTransformOriginPoint(popupComputedStyle.transformOrigin, safeBaseWidth, safeBaseHeight);
204
- const popupRect = normalizeRect(rawPopupRect, scaleX$1, scaleY$1, originX, originY);
205
- const popupMirrorRect = normalizeRect(rawPopupMirrorRect, scaleX$1, scaleY$1, originX, originY);
160
+ const popupRect = rawPopupRect;
161
+ popupRect.x = popupRect.x ?? popupRect.left;
162
+ popupRect.y = popupRect.y ?? popupRect.top;
163
+ const { height, width } = popupComputedStyle;
206
164
  const popupHeight = popupRect.height;
207
165
  const popupWidth = popupRect.width;
166
+ const popupMirrorRect = rawPopupMirrorRect;
167
+ const scaleX$1 = toNum(Math.round(popupWidth / parseFloat(width) * 1e3) / 1e3);
168
+ const scaleY$1 = toNum(Math.round(popupHeight / parseFloat(height) * 1e3) / 1e3);
169
+ if (scaleX$1 === 0 || scaleY$1 === 0 || isDOM(target) && !isVisible(target)) return;
208
170
  const { offset, targetOffset } = placementInfo;
209
171
  let [popupOffsetX, popupOffsetY] = getNumberOffset(popupRect, offset);
210
172
  const [targetOffsetX, targetOffsetY] = getNumberOffset(targetRect, targetOffset);
@@ -349,12 +311,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
349
311
  }
350
312
  const nextOffsetInfo = {
351
313
  ready: true,
352
- offsetX: nextOffsetX,
353
- offsetY: nextOffsetY,
354
- offsetR: offsetX4Right,
355
- offsetB: offsetY4Bottom,
356
- arrowX: nextArrowX,
357
- arrowY: nextArrowY,
314
+ offsetX: nextOffsetX / scaleX$1,
315
+ offsetY: nextOffsetY / scaleY$1,
316
+ offsetR: offsetX4Right / scaleX$1,
317
+ offsetB: offsetY4Bottom / scaleY$1,
318
+ arrowX: nextArrowX / scaleX$1,
319
+ arrowY: nextArrowY / scaleY$1,
358
320
  scaleX: scaleX$1,
359
321
  scaleY: scaleY$1,
360
322
  align: nextAlignInfo
@@ -362,12 +324,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
362
324
  Object.assign(offsetInfo, nextOffsetInfo);
363
325
  }
364
326
  };
365
- const onAlign = rafDebounce(_onAlign);
366
- const triggerAlign = () => {
327
+ const onAlign = _onAlign;
328
+ const triggerAlign = (cache) => {
367
329
  alignCountRef.value += 1;
368
330
  const id = alignCountRef.value;
369
331
  Promise.resolve().then(() => {
370
- if (alignCountRef.value === id) onAlign();
332
+ if (alignCountRef.value === id) onAlign(cache);
371
333
  });
372
334
  };
373
335
  watch(popupEle, async (ele) => {
package/dist/index.cjs CHANGED
@@ -172,6 +172,7 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
172
172
  const clickToHide = (0, vue.computed)(() => hideActions.value?.has("click") || hideActions.value?.has("contextmenu"));
173
173
  const triggerAlign = () => {
174
174
  if (!inMotion.value) onAlign();
175
+ else onAlign(true);
175
176
  };
176
177
  const onScroll = () => {
177
178
  if (openRef.value && props?.alignPoint && clickToHide.value) triggerOpen(false);
@@ -214,9 +215,10 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
214
215
  props?.afterPopupVisibleChange?.(visible);
215
216
  };
216
217
  const onPrepare = () => {
218
+ syncTargetSize();
217
219
  return new Promise((resolve) => {
218
- syncTargetSize();
219
220
  motionPrepareResolve.value = resolve;
221
+ inMotion.value = true;
220
222
  });
221
223
  };
222
224
  (0, vue.watch)([motionPrepareResolve], () => {
@@ -225,7 +227,7 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
225
227
  motionPrepareResolve.value();
226
228
  motionPrepareResolve.value = void 0;
227
229
  }
228
- });
230
+ }, { flush: "post" });
229
231
  function wrapperAction(target, eventName, nextOpen, delay, callback, ignoreCheck) {
230
232
  target[eventName] = (event, ...args) => {
231
233
  if (!ignoreCheck || !ignoreCheck()) {
@@ -505,15 +507,15 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
505
507
  },
506
508
  popup: {
507
509
  type: [
510
+ Object,
511
+ Function,
508
512
  String,
509
513
  Number,
510
514
  null,
511
515
  Boolean,
512
- Array,
513
- Function
516
+ Array
514
517
  ],
515
518
  required: true,
516
- skipCheck: true,
517
519
  default: void 0
518
520
  },
519
521
  popupPlacement: {
@@ -542,12 +544,12 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
542
544
  default: void 0
543
545
  },
544
546
  uniqueContainerStyle: {
545
- type: null,
547
+ type: Object,
546
548
  required: false,
547
549
  default: void 0
548
550
  },
549
551
  popupStyle: {
550
- type: null,
552
+ type: Object,
551
553
  required: false,
552
554
  default: void 0
553
555
  },
package/dist/index.js CHANGED
@@ -168,6 +168,7 @@ function generateTrigger(PortalComponent = Portal) {
168
168
  const clickToHide = computed(() => hideActions.value?.has("click") || hideActions.value?.has("contextmenu"));
169
169
  const triggerAlign = () => {
170
170
  if (!inMotion.value) onAlign();
171
+ else onAlign(true);
171
172
  };
172
173
  const onScroll = () => {
173
174
  if (openRef.value && props?.alignPoint && clickToHide.value) triggerOpen(false);
@@ -210,9 +211,10 @@ function generateTrigger(PortalComponent = Portal) {
210
211
  props?.afterPopupVisibleChange?.(visible);
211
212
  };
212
213
  const onPrepare = () => {
214
+ syncTargetSize();
213
215
  return new Promise((resolve) => {
214
- syncTargetSize();
215
216
  motionPrepareResolve.value = resolve;
217
+ inMotion.value = true;
216
218
  });
217
219
  };
218
220
  watch([motionPrepareResolve], () => {
@@ -221,7 +223,7 @@ function generateTrigger(PortalComponent = Portal) {
221
223
  motionPrepareResolve.value();
222
224
  motionPrepareResolve.value = void 0;
223
225
  }
224
- });
226
+ }, { flush: "post" });
225
227
  function wrapperAction(target, eventName, nextOpen, delay, callback, ignoreCheck) {
226
228
  target[eventName] = (event, ...args) => {
227
229
  if (!ignoreCheck || !ignoreCheck()) {
@@ -501,15 +503,15 @@ function generateTrigger(PortalComponent = Portal) {
501
503
  },
502
504
  popup: {
503
505
  type: [
506
+ Object,
507
+ Function,
504
508
  String,
505
509
  Number,
506
510
  null,
507
511
  Boolean,
508
- Array,
509
- Function
512
+ Array
510
513
  ],
511
514
  required: true,
512
- skipCheck: true,
513
515
  default: void 0
514
516
  },
515
517
  popupPlacement: {
@@ -538,12 +540,12 @@ function generateTrigger(PortalComponent = Portal) {
538
540
  default: void 0
539
541
  },
540
542
  uniqueContainerStyle: {
541
- type: null,
543
+ type: Object,
542
544
  required: false,
543
545
  default: void 0
544
546
  },
545
547
  popupStyle: {
546
- type: null,
548
+ type: Object,
547
549
  required: false,
548
550
  default: void 0
549
551
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/trigger",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -29,9 +29,9 @@
29
29
  "vue": "^3.0.0"
30
30
  },
31
31
  "dependencies": {
32
- "@v-c/portal": "^1.0.0",
33
- "@v-c/resize-observer": "^1.0.0",
34
- "@v-c/util": "^1.0.0"
32
+ "@v-c/portal": "^1.0.1",
33
+ "@v-c/resize-observer": "^1.0.3",
34
+ "@v-c/util": "^1.0.3"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "vite build",