@v-c/trigger 0.0.9 → 0.0.11
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.
- package/dist/Popup/Arrow.cjs +91 -1
- package/dist/Popup/Arrow.js +60 -38
- package/dist/Popup/Mask.cjs +66 -1
- package/dist/Popup/Mask.js +35 -32
- package/dist/Popup/PopupContent.cjs +29 -1
- package/dist/Popup/PopupContent.js +15 -8
- package/dist/Popup/index.cjs +365 -1
- package/dist/Popup/index.js +194 -160
- package/dist/UniqueProvider/UniqueContainer.cjs +159 -1
- package/dist/UniqueProvider/UniqueContainer.js +87 -67
- package/dist/UniqueProvider/index.cjs +213 -1
- package/dist/UniqueProvider/index.js +177 -131
- package/dist/UniqueProvider/useTargetState.cjs +42 -1
- package/dist/UniqueProvider/useTargetState.js +39 -10
- package/dist/context.cjs +38 -1
- package/dist/context.js +27 -16
- package/dist/hooks/useAction.cjs +32 -1
- package/dist/hooks/useAction.js +27 -12
- package/dist/hooks/useAlign.cjs +499 -1
- package/dist/hooks/useAlign.d.ts +1 -1
- package/dist/hooks/useAlign.js +445 -204
- package/dist/hooks/useDelay.cjs +27 -1
- package/dist/hooks/useDelay.js +23 -12
- package/dist/hooks/useOffsetStyle.cjs +36 -1
- package/dist/hooks/useOffsetStyle.js +28 -12
- package/dist/hooks/useWatch.cjs +37 -1
- package/dist/hooks/useWatch.js +28 -17
- package/dist/hooks/useWinClick.cjs +67 -1
- package/dist/hooks/useWinClick.js +56 -39
- package/dist/index.cjs +700 -1
- package/dist/index.js +501 -312
- package/dist/util.cjs +101 -1
- package/dist/util.js +86 -54
- package/package.json +3 -3
package/dist/hooks/useAlign.js
CHANGED
|
@@ -1,39 +1,64 @@
|
|
|
1
|
-
import { isDOM
|
|
2
|
-
import
|
|
3
|
-
import { rafDebounce
|
|
4
|
-
import {
|
|
5
|
-
import { collectScroller
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
|
|
1
|
+
import { isDOM } from "@v-c/util/dist/Dom/findDOMNode";
|
|
2
|
+
import isVisible from "@v-c/util/dist/Dom/isVisible";
|
|
3
|
+
import { rafDebounce } from "@v-c/util/dist/raf";
|
|
4
|
+
import { reactive, shallowRef, computed, ref, watch, nextTick, watchEffect, toRefs } from "vue";
|
|
5
|
+
import { collectScroller, getWin, getVisibleArea, toNum } from "../util.js";
|
|
6
|
+
function getUnitOffset(size, offset = 0) {
|
|
7
|
+
const offsetStr = `${offset}`;
|
|
8
|
+
const cells = offsetStr.match(/^(.*)\%$/);
|
|
9
|
+
if (cells) {
|
|
10
|
+
return size * (parseFloat(cells[1]) / 100);
|
|
11
|
+
}
|
|
12
|
+
return parseFloat(offsetStr);
|
|
9
13
|
}
|
|
10
|
-
function
|
|
11
|
-
const [
|
|
14
|
+
function getNumberOffset(rect, offset) {
|
|
15
|
+
const [offsetX, offsetY] = offset || [];
|
|
12
16
|
return [
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
getUnitOffset(rect.width, offsetX),
|
|
18
|
+
getUnitOffset(rect.height, offsetY)
|
|
15
19
|
];
|
|
16
20
|
}
|
|
17
|
-
function
|
|
18
|
-
return [
|
|
21
|
+
function splitPoints(points = "") {
|
|
22
|
+
return [points[0], points[1]];
|
|
19
23
|
}
|
|
20
|
-
function
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
function getAlignPoint(rect, points) {
|
|
25
|
+
const topBottom = points[0];
|
|
26
|
+
const leftRight = points[1];
|
|
27
|
+
let x;
|
|
28
|
+
let y;
|
|
29
|
+
if (topBottom === "t") {
|
|
30
|
+
y = rect.y;
|
|
31
|
+
} else if (topBottom === "b") {
|
|
32
|
+
y = rect.y + rect.height;
|
|
33
|
+
} else {
|
|
34
|
+
y = rect.y + rect.height / 2;
|
|
35
|
+
}
|
|
36
|
+
if (leftRight === "l") {
|
|
37
|
+
x = rect.x;
|
|
38
|
+
} else if (leftRight === "r") {
|
|
39
|
+
x = rect.x + rect.width;
|
|
40
|
+
} else {
|
|
41
|
+
x = rect.x + rect.width / 2;
|
|
42
|
+
}
|
|
43
|
+
return { x, y };
|
|
24
44
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
45
|
+
function reversePoints(points, index) {
|
|
46
|
+
const reverseMap = {
|
|
27
47
|
t: "b",
|
|
28
48
|
b: "t",
|
|
29
49
|
l: "r",
|
|
30
50
|
r: "l"
|
|
31
51
|
};
|
|
32
|
-
return
|
|
52
|
+
return points.map((point, i) => {
|
|
53
|
+
if (i === index) {
|
|
54
|
+
return reverseMap[point] || "c";
|
|
55
|
+
}
|
|
56
|
+
return point;
|
|
57
|
+
}).join("");
|
|
33
58
|
}
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
ready:
|
|
59
|
+
function useAlign(open, popupEle, target, placement, builtinPlacements, popupAlign, onPopupAlign, mobile) {
|
|
60
|
+
const offsetInfo = reactive({
|
|
61
|
+
ready: false,
|
|
37
62
|
offsetX: 0,
|
|
38
63
|
offsetY: 0,
|
|
39
64
|
offsetR: 0,
|
|
@@ -42,217 +67,433 @@ function $e(o, a, f, c, d, X, Tt, D) {
|
|
|
42
67
|
arrowY: 0,
|
|
43
68
|
scaleX: 1,
|
|
44
69
|
scaleY: 1,
|
|
45
|
-
align:
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
align: builtinPlacements.value[placement.value] || {}
|
|
71
|
+
});
|
|
72
|
+
const alignCountRef = shallowRef(0);
|
|
73
|
+
const scrollerList = computed(() => {
|
|
74
|
+
if (!popupEle.value || mobile?.value) {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
return collectScroller(popupEle.value);
|
|
78
|
+
});
|
|
79
|
+
const prevFlipRef = ref({});
|
|
80
|
+
const resetFlipCache = () => {
|
|
81
|
+
prevFlipRef.value = {};
|
|
82
|
+
};
|
|
83
|
+
const _onAlign = () => {
|
|
84
|
+
if (popupEle.value && target.value && open.value && !mobile?.value) {
|
|
85
|
+
let getIntersectionVisibleArea = function(offsetX2, offsetY2, area = visibleArea) {
|
|
86
|
+
const l = popupRect.x + offsetX2;
|
|
87
|
+
const t = popupRect.y + offsetY2;
|
|
88
|
+
const r = l + popupWidth;
|
|
89
|
+
const b = t + popupHeight;
|
|
90
|
+
const visibleL = Math.max(l, area.left);
|
|
91
|
+
const visibleT = Math.max(t, area.top);
|
|
92
|
+
const visibleR = Math.min(r, area.right);
|
|
93
|
+
const visibleB = Math.min(b, area.bottom);
|
|
94
|
+
return Math.max(0, (visibleR - visibleL) * (visibleB - visibleT));
|
|
95
|
+
}, syncNextPopupPosition = function() {
|
|
96
|
+
nextPopupY = popupRect.y + nextOffsetY;
|
|
97
|
+
nextPopupBottom = nextPopupY + popupHeight;
|
|
98
|
+
nextPopupX = popupRect.x + nextOffsetX;
|
|
99
|
+
nextPopupRight = nextPopupX + popupWidth;
|
|
55
100
|
};
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
101
|
+
const popupElement = popupEle.value;
|
|
102
|
+
const doc = popupElement.ownerDocument;
|
|
103
|
+
const win = getWin(popupElement);
|
|
104
|
+
const { position: popupPosition } = win.getComputedStyle(popupElement);
|
|
105
|
+
const originLeft = popupElement.style.left;
|
|
106
|
+
const originTop = popupElement.style.top;
|
|
107
|
+
const originRight = popupElement.style.right;
|
|
108
|
+
const originBottom = popupElement.style.bottom;
|
|
109
|
+
const originOverflow = popupElement.style.overflow;
|
|
110
|
+
const placementInfo = {
|
|
111
|
+
...builtinPlacements.value[placement.value],
|
|
112
|
+
...popupAlign?.value
|
|
113
|
+
};
|
|
114
|
+
const placeholderElement = doc.createElement("div");
|
|
115
|
+
popupElement.parentElement?.appendChild(placeholderElement);
|
|
116
|
+
placeholderElement.style.left = `${popupElement.offsetLeft}px`;
|
|
117
|
+
placeholderElement.style.top = `${popupElement.offsetTop}px`;
|
|
118
|
+
placeholderElement.style.position = popupPosition;
|
|
119
|
+
placeholderElement.style.height = `${popupElement.offsetHeight}px`;
|
|
120
|
+
placeholderElement.style.width = `${popupElement.offsetWidth}px`;
|
|
121
|
+
popupElement.style.left = "0";
|
|
122
|
+
popupElement.style.top = "0";
|
|
123
|
+
popupElement.style.right = "auto";
|
|
124
|
+
popupElement.style.bottom = "auto";
|
|
125
|
+
popupElement.style.overflow = "hidden";
|
|
126
|
+
let targetRect;
|
|
127
|
+
if (Array.isArray(target.value)) {
|
|
128
|
+
targetRect = {
|
|
129
|
+
x: target.value[0],
|
|
130
|
+
y: target.value[1],
|
|
66
131
|
width: 0,
|
|
67
132
|
height: 0
|
|
68
133
|
};
|
|
69
|
-
else {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
134
|
+
} else {
|
|
135
|
+
const rect = target.value.getBoundingClientRect();
|
|
136
|
+
rect.x = rect.x ?? rect.left;
|
|
137
|
+
rect.y = rect.y ?? rect.top;
|
|
138
|
+
targetRect = {
|
|
139
|
+
x: rect.x,
|
|
140
|
+
y: rect.y,
|
|
141
|
+
width: rect.width,
|
|
142
|
+
height: rect.height
|
|
76
143
|
};
|
|
77
144
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
145
|
+
const popupRect = popupElement.getBoundingClientRect();
|
|
146
|
+
const { height, width } = win.getComputedStyle(popupElement);
|
|
147
|
+
popupRect.x = popupRect.x ?? popupRect.left;
|
|
148
|
+
popupRect.y = popupRect.y ?? popupRect.top;
|
|
80
149
|
const {
|
|
81
|
-
clientWidth
|
|
82
|
-
clientHeight
|
|
83
|
-
scrollWidth
|
|
84
|
-
scrollHeight
|
|
85
|
-
scrollTop
|
|
86
|
-
scrollLeft
|
|
87
|
-
} =
|
|
150
|
+
clientWidth,
|
|
151
|
+
clientHeight,
|
|
152
|
+
scrollWidth,
|
|
153
|
+
scrollHeight,
|
|
154
|
+
scrollTop,
|
|
155
|
+
scrollLeft
|
|
156
|
+
} = doc.documentElement;
|
|
157
|
+
const popupHeight = popupRect.height;
|
|
158
|
+
const popupWidth = popupRect.width;
|
|
159
|
+
const targetHeight = targetRect.height;
|
|
160
|
+
const targetWidth = targetRect.width;
|
|
161
|
+
const visibleRegion = {
|
|
88
162
|
left: 0,
|
|
89
163
|
top: 0,
|
|
90
|
-
right:
|
|
91
|
-
bottom:
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
164
|
+
right: clientWidth,
|
|
165
|
+
bottom: clientHeight
|
|
166
|
+
};
|
|
167
|
+
const scrollRegion = {
|
|
168
|
+
left: -scrollLeft,
|
|
169
|
+
top: -scrollTop,
|
|
170
|
+
right: scrollWidth - scrollLeft,
|
|
171
|
+
bottom: scrollHeight - scrollTop
|
|
97
172
|
};
|
|
98
|
-
let { htmlRegion
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
173
|
+
let { htmlRegion } = placementInfo;
|
|
174
|
+
const VISIBLE = "visible";
|
|
175
|
+
const VISIBLE_FIRST = "visibleFirst";
|
|
176
|
+
if (htmlRegion !== "scroll" && htmlRegion !== VISIBLE_FIRST) {
|
|
177
|
+
htmlRegion = VISIBLE;
|
|
178
|
+
}
|
|
179
|
+
const isVisibleFirst = htmlRegion === VISIBLE_FIRST;
|
|
180
|
+
const scrollRegionArea = getVisibleArea(scrollRegion, scrollerList.value);
|
|
181
|
+
const visibleRegionArea = getVisibleArea(visibleRegion, scrollerList.value);
|
|
182
|
+
const visibleArea = htmlRegion === VISIBLE ? visibleRegionArea : scrollRegionArea;
|
|
183
|
+
const adjustCheckVisibleArea = isVisibleFirst ? visibleRegionArea : visibleArea;
|
|
184
|
+
popupElement.style.left = "auto";
|
|
185
|
+
popupElement.style.top = "auto";
|
|
186
|
+
popupElement.style.right = "0";
|
|
187
|
+
popupElement.style.bottom = "0";
|
|
188
|
+
const popupMirrorRect = popupElement.getBoundingClientRect();
|
|
189
|
+
popupElement.style.left = originLeft;
|
|
190
|
+
popupElement.style.top = originTop;
|
|
191
|
+
popupElement.style.right = originRight;
|
|
192
|
+
popupElement.style.bottom = originBottom;
|
|
193
|
+
popupElement.style.overflow = originOverflow;
|
|
194
|
+
popupElement.parentElement?.removeChild(placeholderElement);
|
|
195
|
+
const scaleX2 = toNum(
|
|
196
|
+
Math.round(popupWidth / parseFloat(width) * 1e3) / 1e3
|
|
109
197
|
);
|
|
110
|
-
|
|
198
|
+
const scaleY2 = toNum(
|
|
199
|
+
Math.round(popupHeight / parseFloat(height) * 1e3) / 1e3
|
|
200
|
+
);
|
|
201
|
+
if (scaleX2 === 0 || scaleY2 === 0 || isDOM(target) && !isVisible(target)) {
|
|
111
202
|
return;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
203
|
+
}
|
|
204
|
+
const { offset, targetOffset } = placementInfo;
|
|
205
|
+
let [popupOffsetX, popupOffsetY] = getNumberOffset(popupRect, offset);
|
|
206
|
+
const [targetOffsetX, targetOffsetY] = getNumberOffset(
|
|
207
|
+
targetRect,
|
|
208
|
+
targetOffset
|
|
209
|
+
);
|
|
210
|
+
targetRect.x -= targetOffsetX;
|
|
211
|
+
targetRect.y -= targetOffsetY;
|
|
212
|
+
const [popupPoint, targetPoint] = placementInfo.points || [];
|
|
213
|
+
const targetPoints = splitPoints(targetPoint);
|
|
214
|
+
const popupPoints = splitPoints(popupPoint);
|
|
215
|
+
const targetAlignPoint = getAlignPoint(targetRect, targetPoints);
|
|
216
|
+
const popupAlignPoint = getAlignPoint(popupRect, popupPoints);
|
|
217
|
+
const nextAlignInfo = {
|
|
218
|
+
...placementInfo
|
|
219
|
+
};
|
|
220
|
+
let nextOffsetX = targetAlignPoint.x - popupAlignPoint.x + popupOffsetX;
|
|
221
|
+
let nextOffsetY = targetAlignPoint.y - popupAlignPoint.y + popupOffsetY;
|
|
222
|
+
const originIntersectionVisibleArea = getIntersectionVisibleArea(
|
|
223
|
+
nextOffsetX,
|
|
224
|
+
nextOffsetY
|
|
225
|
+
);
|
|
226
|
+
const originIntersectionRecommendArea = getIntersectionVisibleArea(
|
|
227
|
+
nextOffsetX,
|
|
228
|
+
nextOffsetY,
|
|
229
|
+
visibleRegionArea
|
|
117
230
|
);
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
231
|
+
const targetAlignPointTL = getAlignPoint(targetRect, ["t", "l"]);
|
|
232
|
+
const popupAlignPointTL = getAlignPoint(popupRect, ["t", "l"]);
|
|
233
|
+
const targetAlignPointBR = getAlignPoint(targetRect, ["b", "r"]);
|
|
234
|
+
const popupAlignPointBR = getAlignPoint(popupRect, ["b", "r"]);
|
|
235
|
+
const overflow = placementInfo.overflow || {};
|
|
236
|
+
const { adjustX, adjustY, shiftX, shiftY } = overflow;
|
|
237
|
+
const supportAdjust = (val) => {
|
|
238
|
+
if (typeof val === "boolean") {
|
|
239
|
+
return val;
|
|
240
|
+
}
|
|
241
|
+
return val >= 0;
|
|
121
242
|
};
|
|
122
|
-
let
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
243
|
+
let nextPopupY;
|
|
244
|
+
let nextPopupBottom;
|
|
245
|
+
let nextPopupX;
|
|
246
|
+
let nextPopupRight;
|
|
247
|
+
syncNextPopupPosition();
|
|
248
|
+
const needAdjustY = supportAdjust(adjustY);
|
|
249
|
+
const sameTB = popupPoints[0] === targetPoints[0];
|
|
250
|
+
if (needAdjustY && popupPoints[0] === "t" && (nextPopupBottom > adjustCheckVisibleArea.bottom || prevFlipRef.value.bt)) {
|
|
251
|
+
let tmpNextOffsetY = nextOffsetY;
|
|
252
|
+
if (sameTB) {
|
|
253
|
+
tmpNextOffsetY -= popupHeight - targetHeight;
|
|
254
|
+
} else {
|
|
255
|
+
tmpNextOffsetY = targetAlignPointTL.y - popupAlignPointBR.y - popupOffsetY;
|
|
256
|
+
}
|
|
257
|
+
const newVisibleArea = getIntersectionVisibleArea(
|
|
258
|
+
nextOffsetX,
|
|
259
|
+
tmpNextOffsetY
|
|
260
|
+
);
|
|
261
|
+
const newVisibleRecommendArea = getIntersectionVisibleArea(
|
|
262
|
+
nextOffsetX,
|
|
263
|
+
tmpNextOffsetY,
|
|
264
|
+
visibleRegionArea
|
|
144
265
|
);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
266
|
+
if (
|
|
267
|
+
// Of course use larger one
|
|
268
|
+
newVisibleArea > originIntersectionVisibleArea || newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst || newVisibleRecommendArea >= originIntersectionRecommendArea)
|
|
269
|
+
) {
|
|
270
|
+
prevFlipRef.value.bt = true;
|
|
271
|
+
nextOffsetY = tmpNextOffsetY;
|
|
272
|
+
popupOffsetY = -popupOffsetY;
|
|
273
|
+
nextAlignInfo.points = [
|
|
274
|
+
reversePoints(popupPoints, 0),
|
|
275
|
+
reversePoints(targetPoints, 0)
|
|
276
|
+
];
|
|
277
|
+
} else {
|
|
278
|
+
prevFlipRef.value.bt = false;
|
|
279
|
+
}
|
|
149
280
|
}
|
|
150
|
-
if (
|
|
151
|
-
let
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
281
|
+
if (needAdjustY && popupPoints[0] === "b" && (nextPopupY < adjustCheckVisibleArea.top || prevFlipRef.value.tb)) {
|
|
282
|
+
let tmpNextOffsetY = nextOffsetY;
|
|
283
|
+
if (sameTB) {
|
|
284
|
+
tmpNextOffsetY += popupHeight - targetHeight;
|
|
285
|
+
} else {
|
|
286
|
+
tmpNextOffsetY = targetAlignPointBR.y - popupAlignPointTL.y - popupOffsetY;
|
|
287
|
+
}
|
|
288
|
+
const newVisibleArea = getIntersectionVisibleArea(
|
|
289
|
+
nextOffsetX,
|
|
290
|
+
tmpNextOffsetY
|
|
160
291
|
);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
292
|
+
const newVisibleRecommendArea = getIntersectionVisibleArea(
|
|
293
|
+
nextOffsetX,
|
|
294
|
+
tmpNextOffsetY,
|
|
295
|
+
visibleRegionArea
|
|
296
|
+
);
|
|
297
|
+
if (
|
|
298
|
+
// Of course use larger one
|
|
299
|
+
newVisibleArea > originIntersectionVisibleArea || newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst || newVisibleRecommendArea >= originIntersectionRecommendArea)
|
|
300
|
+
) {
|
|
301
|
+
prevFlipRef.value.tb = true;
|
|
302
|
+
nextOffsetY = tmpNextOffsetY;
|
|
303
|
+
popupOffsetY = -popupOffsetY;
|
|
304
|
+
nextAlignInfo.points = [
|
|
305
|
+
reversePoints(popupPoints, 0),
|
|
306
|
+
reversePoints(targetPoints, 0)
|
|
307
|
+
];
|
|
308
|
+
} else {
|
|
309
|
+
prevFlipRef.value.tb = false;
|
|
310
|
+
}
|
|
165
311
|
}
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
312
|
+
const needAdjustX = supportAdjust(adjustX);
|
|
313
|
+
const sameLR = popupPoints[1] === targetPoints[1];
|
|
314
|
+
if (needAdjustX && popupPoints[1] === "l" && (nextPopupRight > adjustCheckVisibleArea.right || prevFlipRef.value.rl)) {
|
|
315
|
+
let tmpNextOffsetX = nextOffsetX;
|
|
316
|
+
if (sameLR) {
|
|
317
|
+
tmpNextOffsetX -= popupWidth - targetWidth;
|
|
318
|
+
} else {
|
|
319
|
+
tmpNextOffsetX = targetAlignPointTL.x - popupAlignPointBR.x - popupOffsetX;
|
|
320
|
+
}
|
|
321
|
+
const newVisibleArea = getIntersectionVisibleArea(
|
|
322
|
+
tmpNextOffsetX,
|
|
323
|
+
nextOffsetY
|
|
324
|
+
);
|
|
325
|
+
const newVisibleRecommendArea = getIntersectionVisibleArea(
|
|
326
|
+
tmpNextOffsetX,
|
|
327
|
+
nextOffsetY,
|
|
328
|
+
visibleRegionArea
|
|
177
329
|
);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
330
|
+
if (
|
|
331
|
+
// Of course use larger one
|
|
332
|
+
newVisibleArea > originIntersectionVisibleArea || newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst || newVisibleRecommendArea >= originIntersectionRecommendArea)
|
|
333
|
+
) {
|
|
334
|
+
prevFlipRef.value.rl = true;
|
|
335
|
+
nextOffsetX = tmpNextOffsetX;
|
|
336
|
+
popupOffsetX = -popupOffsetX;
|
|
337
|
+
nextAlignInfo.points = [
|
|
338
|
+
reversePoints(popupPoints, 1),
|
|
339
|
+
reversePoints(targetPoints, 1)
|
|
340
|
+
];
|
|
341
|
+
} else {
|
|
342
|
+
prevFlipRef.value.rl = false;
|
|
343
|
+
}
|
|
182
344
|
}
|
|
183
|
-
if (
|
|
184
|
-
let
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
345
|
+
if (needAdjustX && popupPoints[1] === "r" && (nextPopupX < adjustCheckVisibleArea.left || prevFlipRef.value.lr)) {
|
|
346
|
+
let tmpNextOffsetX = nextOffsetX;
|
|
347
|
+
if (sameLR) {
|
|
348
|
+
tmpNextOffsetX += popupWidth - targetWidth;
|
|
349
|
+
} else {
|
|
350
|
+
tmpNextOffsetX = targetAlignPointBR.x - popupAlignPointTL.x - popupOffsetX;
|
|
351
|
+
}
|
|
352
|
+
const newVisibleArea = getIntersectionVisibleArea(
|
|
353
|
+
tmpNextOffsetX,
|
|
354
|
+
nextOffsetY
|
|
355
|
+
);
|
|
356
|
+
const newVisibleRecommendArea = getIntersectionVisibleArea(
|
|
357
|
+
tmpNextOffsetX,
|
|
358
|
+
nextOffsetY,
|
|
359
|
+
visibleRegionArea
|
|
193
360
|
);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
361
|
+
if (
|
|
362
|
+
// Of course use larger one
|
|
363
|
+
newVisibleArea > originIntersectionVisibleArea || newVisibleArea === originIntersectionVisibleArea && (!isVisibleFirst || newVisibleRecommendArea >= originIntersectionRecommendArea)
|
|
364
|
+
) {
|
|
365
|
+
prevFlipRef.value.lr = true;
|
|
366
|
+
nextOffsetX = tmpNextOffsetX;
|
|
367
|
+
popupOffsetX = -popupOffsetX;
|
|
368
|
+
nextAlignInfo.points = [
|
|
369
|
+
reversePoints(popupPoints, 1),
|
|
370
|
+
reversePoints(targetPoints, 1)
|
|
371
|
+
];
|
|
372
|
+
} else {
|
|
373
|
+
prevFlipRef.value.lr = false;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
syncNextPopupPosition();
|
|
377
|
+
const numShiftX = shiftX === true ? 0 : shiftX;
|
|
378
|
+
if (typeof numShiftX === "number") {
|
|
379
|
+
if (nextPopupX < visibleRegionArea.left) {
|
|
380
|
+
nextOffsetX -= nextPopupX - visibleRegionArea.left - popupOffsetX;
|
|
381
|
+
if (targetRect.x + targetWidth < visibleRegionArea.left + numShiftX) {
|
|
382
|
+
nextOffsetX += targetRect.x - visibleRegionArea.left + targetWidth - numShiftX;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (nextPopupRight > visibleRegionArea.right) {
|
|
386
|
+
nextOffsetX -= nextPopupRight - visibleRegionArea.right - popupOffsetX;
|
|
387
|
+
if (targetRect.x > visibleRegionArea.right - numShiftX) {
|
|
388
|
+
nextOffsetX += targetRect.x - visibleRegionArea.right + numShiftX;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
const numShiftY = shiftY === true ? 0 : shiftY;
|
|
393
|
+
if (typeof numShiftY === "number") {
|
|
394
|
+
if (nextPopupY < visibleRegionArea.top) {
|
|
395
|
+
nextOffsetY -= nextPopupY - visibleRegionArea.top - popupOffsetY;
|
|
396
|
+
if (targetRect.y + targetHeight < visibleRegionArea.top + numShiftY) {
|
|
397
|
+
nextOffsetY += targetRect.y - visibleRegionArea.top + targetHeight - numShiftY;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (nextPopupBottom > visibleRegionArea.bottom) {
|
|
401
|
+
nextOffsetY -= nextPopupBottom - visibleRegionArea.bottom - popupOffsetY;
|
|
402
|
+
if (targetRect.y > visibleRegionArea.bottom - numShiftY) {
|
|
403
|
+
nextOffsetY += targetRect.y - visibleRegionArea.bottom + numShiftY;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
const popupLeft = popupRect.x + nextOffsetX;
|
|
408
|
+
const popupRight = popupLeft + popupWidth;
|
|
409
|
+
const popupTop = popupRect.y + nextOffsetY;
|
|
410
|
+
const popupBottom = popupTop + popupHeight;
|
|
411
|
+
const targetLeft = targetRect.x;
|
|
412
|
+
const targetRight = targetLeft + targetWidth;
|
|
413
|
+
const targetTop = targetRect.y;
|
|
414
|
+
const targetBottom = targetTop + targetHeight;
|
|
415
|
+
const maxLeft = Math.max(popupLeft, targetLeft);
|
|
416
|
+
const minRight = Math.min(popupRight, targetRight);
|
|
417
|
+
const xCenter = (maxLeft + minRight) / 2;
|
|
418
|
+
const nextArrowX = xCenter - popupLeft;
|
|
419
|
+
const maxTop = Math.max(popupTop, targetTop);
|
|
420
|
+
const minBottom = Math.min(popupBottom, targetBottom);
|
|
421
|
+
const yCenter = (maxTop + minBottom) / 2;
|
|
422
|
+
const nextArrowY = yCenter - popupTop;
|
|
423
|
+
onPopupAlign?.(popupEle.value, nextAlignInfo);
|
|
424
|
+
let offsetX4Right = popupMirrorRect.right - popupRect.x - (nextOffsetX + popupRect.width);
|
|
425
|
+
let offsetY4Bottom = popupMirrorRect.bottom - popupRect.y - (nextOffsetY + popupRect.height);
|
|
426
|
+
if (scaleX2 === 1) {
|
|
427
|
+
nextOffsetX = Math.round(nextOffsetX);
|
|
428
|
+
offsetX4Right = Math.round(offsetX4Right);
|
|
198
429
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
arrowX: ge / B,
|
|
215
|
-
arrowY: ye / M,
|
|
216
|
-
scaleX: B,
|
|
217
|
-
scaleY: M,
|
|
218
|
-
align: O
|
|
430
|
+
if (scaleY2 === 1) {
|
|
431
|
+
nextOffsetY = Math.round(nextOffsetY);
|
|
432
|
+
offsetY4Bottom = Math.round(offsetY4Bottom);
|
|
433
|
+
}
|
|
434
|
+
const nextOffsetInfo = {
|
|
435
|
+
ready: true,
|
|
436
|
+
offsetX: nextOffsetX / scaleX2,
|
|
437
|
+
offsetY: nextOffsetY / scaleY2,
|
|
438
|
+
offsetR: offsetX4Right / scaleX2,
|
|
439
|
+
offsetB: offsetY4Bottom / scaleY2,
|
|
440
|
+
arrowX: nextArrowX / scaleX2,
|
|
441
|
+
arrowY: nextArrowY / scaleY2,
|
|
442
|
+
scaleX: scaleX2,
|
|
443
|
+
scaleY: scaleY2,
|
|
444
|
+
align: nextAlignInfo
|
|
219
445
|
};
|
|
220
|
-
|
|
446
|
+
Object.assign(offsetInfo, nextOffsetInfo);
|
|
221
447
|
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
448
|
+
};
|
|
449
|
+
const onAlign = rafDebounce(_onAlign);
|
|
450
|
+
const triggerAlign = () => {
|
|
451
|
+
alignCountRef.value += 1;
|
|
452
|
+
const id = alignCountRef.value;
|
|
225
453
|
Promise.resolve().then(() => {
|
|
226
|
-
|
|
454
|
+
if (alignCountRef.value === id) {
|
|
455
|
+
onAlign();
|
|
456
|
+
}
|
|
227
457
|
});
|
|
228
458
|
};
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
async (
|
|
232
|
-
|
|
459
|
+
watch(
|
|
460
|
+
popupEle,
|
|
461
|
+
async (ele) => {
|
|
462
|
+
if (ele && open.value && !mobile?.value) {
|
|
463
|
+
await nextTick();
|
|
464
|
+
triggerAlign();
|
|
465
|
+
}
|
|
233
466
|
}
|
|
234
467
|
);
|
|
235
|
-
const
|
|
236
|
-
|
|
468
|
+
const resetReady = () => {
|
|
469
|
+
offsetInfo.ready = false;
|
|
237
470
|
};
|
|
238
|
-
|
|
239
|
-
await
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
471
|
+
watch(placement, async () => {
|
|
472
|
+
await nextTick();
|
|
473
|
+
resetReady();
|
|
474
|
+
});
|
|
475
|
+
watchEffect(async () => {
|
|
476
|
+
if (!open.value) {
|
|
477
|
+
resetFlipCache();
|
|
478
|
+
await nextTick();
|
|
479
|
+
resetReady();
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
const { ready, offsetX, offsetR, offsetY, offsetB, align, arrowY, arrowX, scaleY, scaleX } = toRefs(offsetInfo);
|
|
483
|
+
return [
|
|
484
|
+
ready,
|
|
485
|
+
offsetX,
|
|
486
|
+
offsetY,
|
|
487
|
+
offsetR,
|
|
488
|
+
offsetB,
|
|
489
|
+
arrowX,
|
|
490
|
+
arrowY,
|
|
491
|
+
scaleX,
|
|
492
|
+
scaleY,
|
|
493
|
+
align,
|
|
494
|
+
triggerAlign
|
|
254
495
|
];
|
|
255
496
|
}
|
|
256
497
|
export {
|
|
257
|
-
|
|
498
|
+
useAlign as default
|
|
258
499
|
};
|