@whitesev/pops 4.2.1 → 4.2.3
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/index.amd.js +144 -133
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +144 -133
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +144 -133
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +144 -133
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +144 -133
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +144 -133
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Pops.d.ts +8 -8
- package/dist/types/src/utils/PopsDOMUtils.d.ts +9 -9
- package/dist/types/src/utils/PopsUtils.d.ts +2 -2
- package/package.json +3 -3
- package/src/utils/PopsDOMUtils.ts +103 -101
- package/src/utils/PopsInstanceUtils.ts +3 -4
- package/src/utils/PopsUtils.ts +13 -4
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const version = "4.2.
|
|
3
|
+
const version = "4.2.3";
|
|
4
4
|
|
|
5
5
|
const GlobalConfig = {
|
|
6
6
|
config: {},
|
|
@@ -244,6 +244,24 @@ const PopsIcon = {
|
|
|
244
244
|
},
|
|
245
245
|
};
|
|
246
246
|
|
|
247
|
+
/**
|
|
248
|
+
* 通用的CSS类名
|
|
249
|
+
*/
|
|
250
|
+
const PopsCommonCSSClassName = {
|
|
251
|
+
flexCenter: "pops-flex-items-center",
|
|
252
|
+
flexYCenter: "pops-flex-y-center",
|
|
253
|
+
flexXCenter: "pops-flex-x-center",
|
|
254
|
+
hide: "pops-hide",
|
|
255
|
+
hideImportant: "pops-hide-important",
|
|
256
|
+
noBorder: "pops-no-border",
|
|
257
|
+
noBorderImportant: "pops-no-border-important",
|
|
258
|
+
userSelectNone: "pops-user-select-none",
|
|
259
|
+
lineHeightCenter: "pops-line-height-center",
|
|
260
|
+
widthFill: "pops-width-fill",
|
|
261
|
+
textIsDisabled: "pops-text-is-disabled",
|
|
262
|
+
textIsDisabledImportant: "pops-text-is-disabled-important",
|
|
263
|
+
};
|
|
264
|
+
|
|
247
265
|
const OriginPrototype = {
|
|
248
266
|
Object: {
|
|
249
267
|
defineProperty: Object.defineProperty,
|
|
@@ -293,6 +311,30 @@ const PopsCore = {
|
|
|
293
311
|
},
|
|
294
312
|
};
|
|
295
313
|
|
|
314
|
+
const PopsSafeUtils = {
|
|
315
|
+
/**
|
|
316
|
+
* 获取安全的html
|
|
317
|
+
*/
|
|
318
|
+
getSafeHTML(text) {
|
|
319
|
+
if (window.trustedTypes) {
|
|
320
|
+
const policy = window.trustedTypes.createPolicy("safe-innerHTML", {
|
|
321
|
+
createHTML: (html) => html,
|
|
322
|
+
});
|
|
323
|
+
return policy.createHTML(text);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
return text;
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
/**
|
|
330
|
+
* 设置安全的html
|
|
331
|
+
*/
|
|
332
|
+
setSafeHTML($el, text) {
|
|
333
|
+
// 创建 TrustedHTML 策略(需 CSP 允许)
|
|
334
|
+
$el.innerHTML = this.getSafeHTML(text);
|
|
335
|
+
},
|
|
336
|
+
};
|
|
337
|
+
|
|
296
338
|
const n$1="clientX",e$2="clientY",t$1=16,c$3="start",o$1="move",s$1="cancel",u$3="end",a$2="left",i$3="right",r$4="up",d$1="down",m$2={4:"start",5:"move",1:"end",3:"cancel"};function v$1(n){return m$2[n]}function b(n,e,t){const c={1:{0:{move:4},4:{move:5,end:1,cancel:3},5:{move:5,end:1,cancel:3}},0:{4:{move:2,end:1,cancel:3},5:{start:2,move:2,end:1,cancel:3}}}[Number(n)][e];return void 0!==c&&c[t]||0}function g$1(n){[1,3,2].includes(n.state)&&(n.state=0);}function h$3(n){return [5,1,3].includes(n)}function j(n){if(n.disabled)return n.state=0,true}function O(n,e){return Object.assign(Object.assign(Object.assign({},n),e),{state:0,disabled:false})}function p$3(n){return Math.round(100*n)/100}
|
|
297
339
|
|
|
298
340
|
var x=r=>Math.sqrt(r.x*r.x+r.y*r.y),y=(r,a)=>r.x*a.x+r.y*a.y,e$1=(r,a)=>{var t=x(r)*x(a);if(0===t)return 0;var h=y(r,a)/t;return h>1&&(h=1),Math.acos(h)},n=(r,a)=>r.x*a.y-a.x*r.y,o=r=>r/Math.PI*180,s=(r,a)=>{var t=e$1(r,a);return n(r,a)>0&&(t*=-1),o(t)},u$2=(x,y)=>{if(0!==x||0!==y)return Math.abs(x)>=Math.abs(y)?0<x?i$3:a$2:0<y?d$1:r$4};
|
|
@@ -633,6 +675,10 @@ class PopsUtils {
|
|
|
633
675
|
if (typeof deviation !== "number" || Number.isNaN(deviation)) {
|
|
634
676
|
deviation = 10;
|
|
635
677
|
}
|
|
678
|
+
// 最大值 2147483647
|
|
679
|
+
// const maxZIndex = Math.pow(2, 31) - 1;
|
|
680
|
+
// 比较值 2000000000
|
|
681
|
+
const maxZIndexCompare = 2 * Math.pow(10, 9);
|
|
636
682
|
/** 坐标偏移 */
|
|
637
683
|
const positionDistance = 10;
|
|
638
684
|
const defaultCalcPostion = [];
|
|
@@ -727,9 +773,14 @@ class PopsUtils {
|
|
|
727
773
|
left: maxRect.left,
|
|
728
774
|
};
|
|
729
775
|
}
|
|
776
|
+
const calcZIndex = zIndex + deviation;
|
|
777
|
+
if (calcZIndex >= maxZIndexCompare) {
|
|
778
|
+
// 不要超过最大值
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
730
781
|
return {
|
|
731
782
|
/** 计算偏移量后的z-index值 */
|
|
732
|
-
zIndex:
|
|
783
|
+
zIndex: calcZIndex,
|
|
733
784
|
/** 获取到的最大的z-index值 */
|
|
734
785
|
originZIndex: zIndex,
|
|
735
786
|
/** 拥有最大z-index的元素 */
|
|
@@ -762,48 +813,6 @@ class PopsUtils {
|
|
|
762
813
|
}
|
|
763
814
|
const popsUtils = new PopsUtils();
|
|
764
815
|
|
|
765
|
-
const PopsSafeUtils = {
|
|
766
|
-
/**
|
|
767
|
-
* 获取安全的html
|
|
768
|
-
*/
|
|
769
|
-
getSafeHTML(text) {
|
|
770
|
-
if (window.trustedTypes) {
|
|
771
|
-
const policy = window.trustedTypes.createPolicy("safe-innerHTML", {
|
|
772
|
-
createHTML: (html) => html,
|
|
773
|
-
});
|
|
774
|
-
return policy.createHTML(text);
|
|
775
|
-
}
|
|
776
|
-
else {
|
|
777
|
-
return text;
|
|
778
|
-
}
|
|
779
|
-
},
|
|
780
|
-
/**
|
|
781
|
-
* 设置安全的html
|
|
782
|
-
*/
|
|
783
|
-
setSafeHTML($el, text) {
|
|
784
|
-
// 创建 TrustedHTML 策略(需 CSP 允许)
|
|
785
|
-
$el.innerHTML = this.getSafeHTML(text);
|
|
786
|
-
},
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
/**
|
|
790
|
-
* 通用的CSS类名
|
|
791
|
-
*/
|
|
792
|
-
const PopsCommonCSSClassName = {
|
|
793
|
-
flexCenter: "pops-flex-items-center",
|
|
794
|
-
flexYCenter: "pops-flex-y-center",
|
|
795
|
-
flexXCenter: "pops-flex-x-center",
|
|
796
|
-
hide: "pops-hide",
|
|
797
|
-
hideImportant: "pops-hide-important",
|
|
798
|
-
noBorder: "pops-no-border",
|
|
799
|
-
noBorderImportant: "pops-no-border-important",
|
|
800
|
-
userSelectNone: "pops-user-select-none",
|
|
801
|
-
lineHeightCenter: "pops-line-height-center",
|
|
802
|
-
widthFill: "pops-width-fill",
|
|
803
|
-
textIsDisabled: "pops-text-is-disabled",
|
|
804
|
-
textIsDisabledImportant: "pops-text-is-disabled-important",
|
|
805
|
-
};
|
|
806
|
-
|
|
807
816
|
/**
|
|
808
817
|
* 存储在元素属性上的事件名
|
|
809
818
|
*/
|
|
@@ -893,91 +902,91 @@ class PopsDOMUtilsEvent {
|
|
|
893
902
|
// 这是存在selector的情况
|
|
894
903
|
listenerOption = getOption(args, 4, listenerOption);
|
|
895
904
|
}
|
|
896
|
-
/**
|
|
897
|
-
* 如果是once,那么删除该监听和元素上的事件和监听
|
|
898
|
-
*/
|
|
899
|
-
const checkOptionOnceToRemoveEventListener = ($el) => {
|
|
900
|
-
if (listenerOption.once) {
|
|
901
|
-
this.off($el, eventTypeList, selector, callback, option);
|
|
902
|
-
}
|
|
903
|
-
};
|
|
904
905
|
$elList.forEach(($elItem) => {
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
let execCallback = false;
|
|
914
|
-
if (selectorList.length) {
|
|
915
|
-
// 存在子元素选择器
|
|
916
|
-
// 这时候的this和target都是子元素选择器的元素
|
|
917
|
-
let $target;
|
|
918
|
-
if (listenerOption.isComposedPath) {
|
|
919
|
-
// 可能为空
|
|
920
|
-
const composedPath = event.composedPath();
|
|
921
|
-
if (!composedPath.length && event.target) {
|
|
922
|
-
composedPath.push(event.target);
|
|
923
|
-
}
|
|
924
|
-
$target = composedPath[0];
|
|
906
|
+
// 遍历事件名设置元素事件
|
|
907
|
+
eventTypeList.forEach((eventName) => {
|
|
908
|
+
/**
|
|
909
|
+
* 如果是option.once,那么删除该监听和元素上的事件和监听
|
|
910
|
+
*/
|
|
911
|
+
const checkOptionOnceToRemoveEventListener = () => {
|
|
912
|
+
if (listenerOption.once) {
|
|
913
|
+
this.off($elItem, eventName, selector, callback, option);
|
|
925
914
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
915
|
+
};
|
|
916
|
+
/**
|
|
917
|
+
* 事件回调
|
|
918
|
+
* @param event
|
|
919
|
+
*/
|
|
920
|
+
const handlerCallBack = function (event) {
|
|
921
|
+
let call_this = void 0;
|
|
922
|
+
let call_event = void 0;
|
|
923
|
+
let call_$selector = void 0;
|
|
924
|
+
let execCallback = false;
|
|
925
|
+
if (selectorList.length) {
|
|
926
|
+
// 存在子元素选择器
|
|
927
|
+
// 这时候的this和target都是子元素选择器的元素
|
|
928
|
+
let $target;
|
|
929
|
+
if (listenerOption.isComposedPath) {
|
|
930
|
+
// 可能为空
|
|
931
|
+
const composedPath = event.composedPath();
|
|
932
|
+
if (!composedPath.length && event.target) {
|
|
933
|
+
composedPath.push(event.target);
|
|
934
|
+
}
|
|
935
|
+
$target = composedPath[0];
|
|
940
936
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
if ($closestMatches && $parent?.contains?.($closestMatches)) {
|
|
944
|
-
$target = $closestMatches;
|
|
945
|
-
return true;
|
|
937
|
+
else {
|
|
938
|
+
$target = event.target;
|
|
946
939
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
940
|
+
let $parent = $elItem;
|
|
941
|
+
if (popsUtils.isWin($parent)) {
|
|
942
|
+
// window和document共用一个对象
|
|
943
|
+
// 这样就能处理子元素选择器无法匹配的问题
|
|
944
|
+
$parent = PopsCore.document.documentElement;
|
|
945
|
+
}
|
|
946
|
+
const findValue = selectorList.find((selectors) => {
|
|
947
|
+
// 判断目标元素是否匹配选择器
|
|
948
|
+
if (that.matches($target, selectors)) {
|
|
949
|
+
// 当前目标可以被selector所匹配到
|
|
950
|
+
return true;
|
|
951
|
+
}
|
|
952
|
+
// 在上层与主元素之间寻找可以被selector所匹配到的
|
|
953
|
+
const $closestMatches = that.closest($target, selectors);
|
|
954
|
+
if ($closestMatches && $parent?.contains?.($closestMatches)) {
|
|
955
|
+
$target = $closestMatches;
|
|
956
|
+
return true;
|
|
957
|
+
}
|
|
958
|
+
return false;
|
|
959
|
+
});
|
|
960
|
+
if (findValue) {
|
|
961
|
+
// 这里尝试使用defineProperty修改event的target值
|
|
962
|
+
try {
|
|
963
|
+
OriginPrototype.Object.defineProperty(event, "target", {
|
|
964
|
+
get() {
|
|
965
|
+
return $target;
|
|
966
|
+
},
|
|
967
|
+
});
|
|
968
|
+
// oxlint-disable-next-line no-empty
|
|
969
|
+
}
|
|
970
|
+
catch { }
|
|
971
|
+
execCallback = true;
|
|
972
|
+
call_this = $target;
|
|
973
|
+
call_event = event;
|
|
974
|
+
call_$selector = $target;
|
|
958
975
|
}
|
|
959
|
-
|
|
976
|
+
}
|
|
977
|
+
else {
|
|
960
978
|
execCallback = true;
|
|
961
|
-
call_this = $
|
|
979
|
+
call_this = $elItem;
|
|
962
980
|
call_event = event;
|
|
963
|
-
call_$selector = $target;
|
|
964
981
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
if (execCallback) {
|
|
972
|
-
const result = listenerCallBack.call(call_this, call_event, call_$selector);
|
|
973
|
-
checkOptionOnceToRemoveEventListener($elItem);
|
|
974
|
-
if (typeof result === "boolean" && !result) {
|
|
975
|
-
return false;
|
|
982
|
+
if (execCallback) {
|
|
983
|
+
const result = listenerCallBack.call(call_this, call_event, call_$selector);
|
|
984
|
+
checkOptionOnceToRemoveEventListener();
|
|
985
|
+
if (typeof result === "boolean" && !result) {
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
976
988
|
}
|
|
977
|
-
}
|
|
978
|
-
};
|
|
979
|
-
// 遍历事件名设置元素事件
|
|
980
|
-
eventTypeList.forEach((eventName) => {
|
|
989
|
+
};
|
|
981
990
|
// add listener
|
|
982
991
|
$elItem.addEventListener(eventName, handlerCallBack, listenerOption);
|
|
983
992
|
// 获取对象上的事件
|
|
@@ -1090,31 +1099,34 @@ class PopsDOMUtilsEvent {
|
|
|
1090
1099
|
const elementEvents = Reflect.get($elItem, SymbolEvents) || {};
|
|
1091
1100
|
eventTypeList.forEach((eventName) => {
|
|
1092
1101
|
const handlers = elementEvents[eventName] || [];
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1102
|
+
// 过滤出需要删除的事件
|
|
1103
|
+
const handlersFiltered = typeof filter === "function" ? handlers.filter(filter) : handlers;
|
|
1104
|
+
for (let index = 0; index < handlersFiltered.length; index++) {
|
|
1105
|
+
const handler = handlersFiltered[index];
|
|
1106
|
+
// 过滤出的事件再根据下面的条件进行判断处理移除
|
|
1107
|
+
// 1. callback内存地址必须相同
|
|
1108
|
+
// 2. selector必须相同
|
|
1109
|
+
// 3. option.capture必须相同
|
|
1096
1110
|
let flag = true;
|
|
1097
1111
|
if (flag && listenerCallBack && handler.callback !== listenerCallBack) {
|
|
1098
|
-
// callback不同
|
|
1099
1112
|
flag = false;
|
|
1100
1113
|
}
|
|
1101
1114
|
if (flag && selectorList.length && Array.isArray(handler.selector)) {
|
|
1102
1115
|
if (JSON.stringify(handler.selector) !== JSON.stringify(selectorList)) {
|
|
1103
|
-
// 子元素选择器不同
|
|
1104
1116
|
flag = false;
|
|
1105
1117
|
}
|
|
1106
1118
|
}
|
|
1107
1119
|
if (flag &&
|
|
1108
1120
|
typeof handler.option.capture === "boolean" &&
|
|
1109
1121
|
listenerOption.capture !== handler.option.capture) {
|
|
1110
|
-
// 事件的配置项不同
|
|
1111
1122
|
flag = false;
|
|
1112
1123
|
}
|
|
1113
1124
|
if (flag) {
|
|
1114
1125
|
$elItem.removeEventListener(eventName, handler.handlerCallBack, handler.option);
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1126
|
+
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
1127
|
+
if (handlers[i] === handler) {
|
|
1128
|
+
handlers.splice(i, 1);
|
|
1129
|
+
}
|
|
1118
1130
|
}
|
|
1119
1131
|
}
|
|
1120
1132
|
}
|
|
@@ -3178,8 +3190,8 @@ const PopsInstanceUtils = {
|
|
|
3178
3190
|
* 获取pops所有弹窗中的最大的z-index
|
|
3179
3191
|
* @param deviation
|
|
3180
3192
|
*/
|
|
3181
|
-
getPopsMaxZIndex(deviation =
|
|
3182
|
-
deviation = Number.isNaN(deviation) ?
|
|
3193
|
+
getPopsMaxZIndex(deviation = 10) {
|
|
3194
|
+
deviation = Number.isNaN(deviation) ? 10 : deviation;
|
|
3183
3195
|
// 最大值 2147483647
|
|
3184
3196
|
// const browserMaxZIndex = Math.pow(2, 31) - 1;
|
|
3185
3197
|
// 比较值 2000000000
|
|
@@ -3194,8 +3206,7 @@ const PopsInstanceUtils = {
|
|
|
3194
3206
|
const inst = instData[index];
|
|
3195
3207
|
// 不对position为static和display为none的元素进行获取它们的z-index
|
|
3196
3208
|
const $elList = [inst.$anim, inst.$pops, inst.$mask].filter((it) => it instanceof HTMLElement);
|
|
3197
|
-
const
|
|
3198
|
-
const maxNodeZIndexInfo = nodeZIndexInfoList[0];
|
|
3209
|
+
const maxNodeZIndexInfo = popsUtils.getMaxZIndexNodeInfoFromPoint($elList)[0];
|
|
3199
3210
|
if (maxNodeZIndexInfo) {
|
|
3200
3211
|
const nodeZIndex = maxNodeZIndexInfo.zIndex;
|
|
3201
3212
|
if (nodeZIndex > zIndex) {
|