@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.
package/dist/util.cjs CHANGED
@@ -1 +1,101 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function j(e=[],o=[],t){return t?e[0]===o[0]:e[0]===o[0]&&e[1]===o[1]}function I(e,o,t,n){const{points:s}=t,i=Object.keys(e);for(let r=0;r<i.length;r+=1){const l=i[r];if(j(e[l]?.points,s,n))return`${o}-placement-${l}`}return""}function m(e){return e.ownerDocument.defaultView}function X(e){const o=[];let t=e?.parentElement;const n=["hidden","scroll","clip","auto"];for(;t;){const{overflowX:s,overflowY:i,overflow:r}=m(t).getComputedStyle(t);[s,i,r].some(l=>n.includes(l))&&o.push(t),t=t.parentElement}return o}function a(e,o=1){return Number.isNaN(e)?o:e}function d(e){return a(parseFloat(e),0)}function Y(e,o){const t={...e};return(o||[]).forEach(n=>{if(n instanceof HTMLBodyElement||n instanceof HTMLHtmlElement)return;const{overflow:s,overflowClipMargin:i,borderTopWidth:r,borderBottomWidth:l,borderLeftWidth:L,borderRightWidth:T}=m(n).getComputedStyle(n),c=n.getBoundingClientRect(),{offsetHeight:p,clientHeight:C,offsetWidth:b,clientWidth:E}=n,W=d(r),M=d(l),N=d(L),w=d(T),h=a(Math.round(c.width/b*1e3)/1e3),u=a(Math.round(c.height/p*1e3)/1e3),R=(b-E-N-w)*h,A=(p-C-W-M)*u,B=W*u,x=M*u,H=N*h,O=w*h;let f=0,g=0;if(s==="clip"){const v=d(i);f=v*h,g=v*u}const S=c.x+H-f,y=c.y+B-g,P=S+c.width+2*f-H-O-R,V=y+c.height+2*g-B-x-A;t.left=Math.max(t.left,S),t.top=Math.max(t.top,y),t.right=Math.min(t.right,P),t.bottom=Math.min(t.bottom,V)}),t}exports.collectScroller=X;exports.getAlignPopupClassName=I;exports.getVisibleArea=Y;exports.getWin=m;exports.toNum=a;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function isPointsEq(a1 = [], a2 = [], isAlignPoint) {
4
+ if (isAlignPoint) {
5
+ return a1[0] === a2[0];
6
+ }
7
+ return a1[0] === a2[0] && a1[1] === a2[1];
8
+ }
9
+ function getAlignPopupClassName(builtinPlacements, prefixCls, align, isAlignPoint) {
10
+ const { points } = align;
11
+ const placements = Object.keys(builtinPlacements);
12
+ for (let i = 0; i < placements.length; i += 1) {
13
+ const placement = placements[i];
14
+ if (isPointsEq(builtinPlacements[placement]?.points, points, isAlignPoint)) {
15
+ return `${prefixCls}-placement-${placement}`;
16
+ }
17
+ }
18
+ return "";
19
+ }
20
+ function getWin(ele) {
21
+ return ele.ownerDocument.defaultView;
22
+ }
23
+ function collectScroller(ele) {
24
+ const scrollerList = [];
25
+ let current = ele?.parentElement;
26
+ const scrollStyle = ["hidden", "scroll", "clip", "auto"];
27
+ while (current) {
28
+ const { overflowX, overflowY, overflow } = getWin(current).getComputedStyle(current);
29
+ if ([overflowX, overflowY, overflow].some((o) => scrollStyle.includes(o))) {
30
+ scrollerList.push(current);
31
+ }
32
+ current = current.parentElement;
33
+ }
34
+ return scrollerList;
35
+ }
36
+ function toNum(num, defaultValue = 1) {
37
+ return Number.isNaN(num) ? defaultValue : num;
38
+ }
39
+ function getPxValue(val) {
40
+ return toNum(parseFloat(val), 0);
41
+ }
42
+ function getVisibleArea(initArea, scrollerList) {
43
+ const visibleArea = { ...initArea };
44
+ (scrollerList || []).forEach((ele) => {
45
+ if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) {
46
+ return;
47
+ }
48
+ const {
49
+ overflow,
50
+ overflowClipMargin,
51
+ borderTopWidth,
52
+ borderBottomWidth,
53
+ borderLeftWidth,
54
+ borderRightWidth
55
+ } = getWin(ele).getComputedStyle(ele);
56
+ const eleRect = ele.getBoundingClientRect();
57
+ const {
58
+ offsetHeight: eleOutHeight,
59
+ clientHeight: eleInnerHeight,
60
+ offsetWidth: eleOutWidth,
61
+ clientWidth: eleInnerWidth
62
+ } = ele;
63
+ const borderTopNum = getPxValue(borderTopWidth);
64
+ const borderBottomNum = getPxValue(borderBottomWidth);
65
+ const borderLeftNum = getPxValue(borderLeftWidth);
66
+ const borderRightNum = getPxValue(borderRightWidth);
67
+ const scaleX = toNum(
68
+ Math.round(eleRect.width / eleOutWidth * 1e3) / 1e3
69
+ );
70
+ const scaleY = toNum(
71
+ Math.round(eleRect.height / eleOutHeight * 1e3) / 1e3
72
+ );
73
+ const eleScrollWidth = (eleOutWidth - eleInnerWidth - borderLeftNum - borderRightNum) * scaleX;
74
+ const eleScrollHeight = (eleOutHeight - eleInnerHeight - borderTopNum - borderBottomNum) * scaleY;
75
+ const scaledBorderTopWidth = borderTopNum * scaleY;
76
+ const scaledBorderBottomWidth = borderBottomNum * scaleY;
77
+ const scaledBorderLeftWidth = borderLeftNum * scaleX;
78
+ const scaledBorderRightWidth = borderRightNum * scaleX;
79
+ let clipMarginWidth = 0;
80
+ let clipMarginHeight = 0;
81
+ if (overflow === "clip") {
82
+ const clipNum = getPxValue(overflowClipMargin);
83
+ clipMarginWidth = clipNum * scaleX;
84
+ clipMarginHeight = clipNum * scaleY;
85
+ }
86
+ const eleLeft = eleRect.x + scaledBorderLeftWidth - clipMarginWidth;
87
+ const eleTop = eleRect.y + scaledBorderTopWidth - clipMarginHeight;
88
+ const eleRight = eleLeft + eleRect.width + 2 * clipMarginWidth - scaledBorderLeftWidth - scaledBorderRightWidth - eleScrollWidth;
89
+ const eleBottom = eleTop + eleRect.height + 2 * clipMarginHeight - scaledBorderTopWidth - scaledBorderBottomWidth - eleScrollHeight;
90
+ visibleArea.left = Math.max(visibleArea.left, eleLeft);
91
+ visibleArea.top = Math.max(visibleArea.top, eleTop);
92
+ visibleArea.right = Math.min(visibleArea.right, eleRight);
93
+ visibleArea.bottom = Math.min(visibleArea.bottom, eleBottom);
94
+ });
95
+ return visibleArea;
96
+ }
97
+ exports.collectScroller = collectScroller;
98
+ exports.getAlignPopupClassName = getAlignPopupClassName;
99
+ exports.getVisibleArea = getVisibleArea;
100
+ exports.getWin = getWin;
101
+ exports.toNum = toNum;
package/dist/util.js CHANGED
@@ -1,69 +1,101 @@
1
- function P(e = [], o = [], t) {
2
- return t ? e[0] === o[0] : e[0] === o[0] && e[1] === o[1];
1
+ function isPointsEq(a1 = [], a2 = [], isAlignPoint) {
2
+ if (isAlignPoint) {
3
+ return a1[0] === a2[0];
4
+ }
5
+ return a1[0] === a2[0] && a1[1] === a2[1];
3
6
  }
4
- function X(e, o, t, n) {
5
- const { points: s } = t, i = Object.keys(e);
6
- for (let r = 0; r < i.length; r += 1) {
7
- const c = i[r];
8
- if (P(e[c]?.points, s, n))
9
- return `${o}-placement-${c}`;
7
+ function getAlignPopupClassName(builtinPlacements, prefixCls, align, isAlignPoint) {
8
+ const { points } = align;
9
+ const placements = Object.keys(builtinPlacements);
10
+ for (let i = 0; i < placements.length; i += 1) {
11
+ const placement = placements[i];
12
+ if (isPointsEq(builtinPlacements[placement]?.points, points, isAlignPoint)) {
13
+ return `${prefixCls}-placement-${placement}`;
14
+ }
10
15
  }
11
16
  return "";
12
17
  }
13
- function y(e) {
14
- return e.ownerDocument.defaultView;
18
+ function getWin(ele) {
19
+ return ele.ownerDocument.defaultView;
15
20
  }
16
- function Y(e) {
17
- const o = [];
18
- let t = e?.parentElement;
19
- const n = ["hidden", "scroll", "clip", "auto"];
20
- for (; t; ) {
21
- const { overflowX: s, overflowY: i, overflow: r } = y(t).getComputedStyle(t);
22
- [s, i, r].some((c) => n.includes(c)) && o.push(t), t = t.parentElement;
21
+ function collectScroller(ele) {
22
+ const scrollerList = [];
23
+ let current = ele?.parentElement;
24
+ const scrollStyle = ["hidden", "scroll", "clip", "auto"];
25
+ while (current) {
26
+ const { overflowX, overflowY, overflow } = getWin(current).getComputedStyle(current);
27
+ if ([overflowX, overflowY, overflow].some((o) => scrollStyle.includes(o))) {
28
+ scrollerList.push(current);
29
+ }
30
+ current = current.parentElement;
23
31
  }
24
- return o;
32
+ return scrollerList;
25
33
  }
26
- function m(e, o = 1) {
27
- return Number.isNaN(e) ? o : e;
34
+ function toNum(num, defaultValue = 1) {
35
+ return Number.isNaN(num) ? defaultValue : num;
28
36
  }
29
- function h(e) {
30
- return m(parseFloat(e), 0);
37
+ function getPxValue(val) {
38
+ return toNum(parseFloat(val), 0);
31
39
  }
32
- function $(e, o) {
33
- const t = { ...e };
34
- return (o || []).forEach((n) => {
35
- if (n instanceof HTMLBodyElement || n instanceof HTMLHtmlElement)
40
+ function getVisibleArea(initArea, scrollerList) {
41
+ const visibleArea = { ...initArea };
42
+ (scrollerList || []).forEach((ele) => {
43
+ if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) {
36
44
  return;
45
+ }
46
+ const {
47
+ overflow,
48
+ overflowClipMargin,
49
+ borderTopWidth,
50
+ borderBottomWidth,
51
+ borderLeftWidth,
52
+ borderRightWidth
53
+ } = getWin(ele).getComputedStyle(ele);
54
+ const eleRect = ele.getBoundingClientRect();
37
55
  const {
38
- overflow: s,
39
- overflowClipMargin: i,
40
- borderTopWidth: r,
41
- borderBottomWidth: c,
42
- borderLeftWidth: E,
43
- borderRightWidth: R
44
- } = y(n).getComputedStyle(n), l = n.getBoundingClientRect(), {
45
- offsetHeight: g,
46
- clientHeight: S,
47
- offsetWidth: p,
48
- clientWidth: T
49
- } = n, W = h(r), b = h(c), M = h(E), w = h(R), d = m(
50
- Math.round(l.width / p * 1e3) / 1e3
51
- ), u = m(
52
- Math.round(l.height / g * 1e3) / 1e3
53
- ), x = (p - T - M - w) * d, C = (g - S - W - b) * u, B = W * u, A = b * u, N = M * d, O = w * d;
54
- let f = 0, a = 0;
55
- if (s === "clip") {
56
- const v = h(i);
57
- f = v * d, a = v * u;
56
+ offsetHeight: eleOutHeight,
57
+ clientHeight: eleInnerHeight,
58
+ offsetWidth: eleOutWidth,
59
+ clientWidth: eleInnerWidth
60
+ } = ele;
61
+ const borderTopNum = getPxValue(borderTopWidth);
62
+ const borderBottomNum = getPxValue(borderBottomWidth);
63
+ const borderLeftNum = getPxValue(borderLeftWidth);
64
+ const borderRightNum = getPxValue(borderRightWidth);
65
+ const scaleX = toNum(
66
+ Math.round(eleRect.width / eleOutWidth * 1e3) / 1e3
67
+ );
68
+ const scaleY = toNum(
69
+ Math.round(eleRect.height / eleOutHeight * 1e3) / 1e3
70
+ );
71
+ const eleScrollWidth = (eleOutWidth - eleInnerWidth - borderLeftNum - borderRightNum) * scaleX;
72
+ const eleScrollHeight = (eleOutHeight - eleInnerHeight - borderTopNum - borderBottomNum) * scaleY;
73
+ const scaledBorderTopWidth = borderTopNum * scaleY;
74
+ const scaledBorderBottomWidth = borderBottomNum * scaleY;
75
+ const scaledBorderLeftWidth = borderLeftNum * scaleX;
76
+ const scaledBorderRightWidth = borderRightNum * scaleX;
77
+ let clipMarginWidth = 0;
78
+ let clipMarginHeight = 0;
79
+ if (overflow === "clip") {
80
+ const clipNum = getPxValue(overflowClipMargin);
81
+ clipMarginWidth = clipNum * scaleX;
82
+ clipMarginHeight = clipNum * scaleY;
58
83
  }
59
- const H = l.x + N - f, L = l.y + B - a, V = H + l.width + 2 * f - N - O - x, I = L + l.height + 2 * a - B - A - C;
60
- t.left = Math.max(t.left, H), t.top = Math.max(t.top, L), t.right = Math.min(t.right, V), t.bottom = Math.min(t.bottom, I);
61
- }), t;
84
+ const eleLeft = eleRect.x + scaledBorderLeftWidth - clipMarginWidth;
85
+ const eleTop = eleRect.y + scaledBorderTopWidth - clipMarginHeight;
86
+ const eleRight = eleLeft + eleRect.width + 2 * clipMarginWidth - scaledBorderLeftWidth - scaledBorderRightWidth - eleScrollWidth;
87
+ const eleBottom = eleTop + eleRect.height + 2 * clipMarginHeight - scaledBorderTopWidth - scaledBorderBottomWidth - eleScrollHeight;
88
+ visibleArea.left = Math.max(visibleArea.left, eleLeft);
89
+ visibleArea.top = Math.max(visibleArea.top, eleTop);
90
+ visibleArea.right = Math.min(visibleArea.right, eleRight);
91
+ visibleArea.bottom = Math.min(visibleArea.bottom, eleBottom);
92
+ });
93
+ return visibleArea;
62
94
  }
63
95
  export {
64
- Y as collectScroller,
65
- X as getAlignPopupClassName,
66
- $ as getVisibleArea,
67
- y as getWin,
68
- m as toNum
96
+ collectScroller,
97
+ getAlignPopupClassName,
98
+ getVisibleArea,
99
+ getWin,
100
+ toNum
69
101
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/trigger",
3
3
  "type": "module",
4
- "version": "0.0.10",
4
+ "version": "0.0.11",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@v-c/portal": "0.0.3",
33
33
  "@v-c/resize-observer": "0.0.2",
34
- "@v-c/util": "0.0.12"
34
+ "@v-c/util": "0.0.13"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "vite build",