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