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