@whitesev/pops 4.2.1 → 4.2.2
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 +131 -128
- 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 +131 -128
- 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 +131 -128
- 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 +131 -128
- 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 +131 -128
- 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 +131 -128
- 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/package.json +1 -1
- package/src/utils/PopsDOMUtils.ts +103 -101
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.2";
|
|
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};
|
|
@@ -765,48 +807,6 @@ System.register('pops', [], (function (exports) {
|
|
|
765
807
|
}
|
|
766
808
|
const popsUtils = new PopsUtils();
|
|
767
809
|
|
|
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
810
|
/**
|
|
811
811
|
* 存储在元素属性上的事件名
|
|
812
812
|
*/
|
|
@@ -896,91 +896,91 @@ System.register('pops', [], (function (exports) {
|
|
|
896
896
|
// 这是存在selector的情况
|
|
897
897
|
listenerOption = getOption(args, 4, listenerOption);
|
|
898
898
|
}
|
|
899
|
-
/**
|
|
900
|
-
* 如果是once,那么删除该监听和元素上的事件和监听
|
|
901
|
-
*/
|
|
902
|
-
const checkOptionOnceToRemoveEventListener = ($el) => {
|
|
903
|
-
if (listenerOption.once) {
|
|
904
|
-
this.off($el, eventTypeList, selector, callback, option);
|
|
905
|
-
}
|
|
906
|
-
};
|
|
907
899
|
$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];
|
|
900
|
+
// 遍历事件名设置元素事件
|
|
901
|
+
eventTypeList.forEach((eventName) => {
|
|
902
|
+
/**
|
|
903
|
+
* 如果是option.once,那么删除该监听和元素上的事件和监听
|
|
904
|
+
*/
|
|
905
|
+
const checkOptionOnceToRemoveEventListener = () => {
|
|
906
|
+
if (listenerOption.once) {
|
|
907
|
+
this.off($elItem, eventName, selector, callback, option);
|
|
928
908
|
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
909
|
+
};
|
|
910
|
+
/**
|
|
911
|
+
* 事件回调
|
|
912
|
+
* @param event
|
|
913
|
+
*/
|
|
914
|
+
const handlerCallBack = function (event) {
|
|
915
|
+
let call_this = void 0;
|
|
916
|
+
let call_event = void 0;
|
|
917
|
+
let call_$selector = void 0;
|
|
918
|
+
let execCallback = false;
|
|
919
|
+
if (selectorList.length) {
|
|
920
|
+
// 存在子元素选择器
|
|
921
|
+
// 这时候的this和target都是子元素选择器的元素
|
|
922
|
+
let $target;
|
|
923
|
+
if (listenerOption.isComposedPath) {
|
|
924
|
+
// 可能为空
|
|
925
|
+
const composedPath = event.composedPath();
|
|
926
|
+
if (!composedPath.length && event.target) {
|
|
927
|
+
composedPath.push(event.target);
|
|
928
|
+
}
|
|
929
|
+
$target = composedPath[0];
|
|
943
930
|
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
if ($closestMatches && $parent?.contains?.($closestMatches)) {
|
|
947
|
-
$target = $closestMatches;
|
|
948
|
-
return true;
|
|
931
|
+
else {
|
|
932
|
+
$target = event.target;
|
|
949
933
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
OriginPrototype.Object.defineProperty(event, "target", {
|
|
956
|
-
get() {
|
|
957
|
-
return $target;
|
|
958
|
-
},
|
|
959
|
-
});
|
|
960
|
-
// oxlint-disable-next-line no-empty
|
|
934
|
+
let $parent = $elItem;
|
|
935
|
+
if (popsUtils.isWin($parent)) {
|
|
936
|
+
// window和document共用一个对象
|
|
937
|
+
// 这样就能处理子元素选择器无法匹配的问题
|
|
938
|
+
$parent = PopsCore.document.documentElement;
|
|
961
939
|
}
|
|
962
|
-
|
|
940
|
+
const findValue = selectorList.find((selectors) => {
|
|
941
|
+
// 判断目标元素是否匹配选择器
|
|
942
|
+
if (that.matches($target, selectors)) {
|
|
943
|
+
// 当前目标可以被selector所匹配到
|
|
944
|
+
return true;
|
|
945
|
+
}
|
|
946
|
+
// 在上层与主元素之间寻找可以被selector所匹配到的
|
|
947
|
+
const $closestMatches = that.closest($target, selectors);
|
|
948
|
+
if ($closestMatches && $parent?.contains?.($closestMatches)) {
|
|
949
|
+
$target = $closestMatches;
|
|
950
|
+
return true;
|
|
951
|
+
}
|
|
952
|
+
return false;
|
|
953
|
+
});
|
|
954
|
+
if (findValue) {
|
|
955
|
+
// 这里尝试使用defineProperty修改event的target值
|
|
956
|
+
try {
|
|
957
|
+
OriginPrototype.Object.defineProperty(event, "target", {
|
|
958
|
+
get() {
|
|
959
|
+
return $target;
|
|
960
|
+
},
|
|
961
|
+
});
|
|
962
|
+
// oxlint-disable-next-line no-empty
|
|
963
|
+
}
|
|
964
|
+
catch { }
|
|
965
|
+
execCallback = true;
|
|
966
|
+
call_this = $target;
|
|
967
|
+
call_event = event;
|
|
968
|
+
call_$selector = $target;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
else {
|
|
963
972
|
execCallback = true;
|
|
964
|
-
call_this = $
|
|
973
|
+
call_this = $elItem;
|
|
965
974
|
call_event = event;
|
|
966
|
-
call_$selector = $target;
|
|
967
975
|
}
|
|
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;
|
|
976
|
+
if (execCallback) {
|
|
977
|
+
const result = listenerCallBack.call(call_this, call_event, call_$selector);
|
|
978
|
+
checkOptionOnceToRemoveEventListener();
|
|
979
|
+
if (typeof result === "boolean" && !result) {
|
|
980
|
+
return false;
|
|
981
|
+
}
|
|
979
982
|
}
|
|
980
|
-
}
|
|
981
|
-
};
|
|
982
|
-
// 遍历事件名设置元素事件
|
|
983
|
-
eventTypeList.forEach((eventName) => {
|
|
983
|
+
};
|
|
984
984
|
// add listener
|
|
985
985
|
$elItem.addEventListener(eventName, handlerCallBack, listenerOption);
|
|
986
986
|
// 获取对象上的事件
|
|
@@ -1093,31 +1093,34 @@ System.register('pops', [], (function (exports) {
|
|
|
1093
1093
|
const elementEvents = Reflect.get($elItem, SymbolEvents) || {};
|
|
1094
1094
|
eventTypeList.forEach((eventName) => {
|
|
1095
1095
|
const handlers = elementEvents[eventName] || [];
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1096
|
+
// 过滤出需要删除的事件
|
|
1097
|
+
const handlersFiltered = typeof filter === "function" ? handlers.filter(filter) : handlers;
|
|
1098
|
+
for (let index = 0; index < handlersFiltered.length; index++) {
|
|
1099
|
+
const handler = handlersFiltered[index];
|
|
1100
|
+
// 过滤出的事件再根据下面的条件进行判断处理移除
|
|
1101
|
+
// 1. callback内存地址必须相同
|
|
1102
|
+
// 2. selector必须相同
|
|
1103
|
+
// 3. option.capture必须相同
|
|
1099
1104
|
let flag = true;
|
|
1100
1105
|
if (flag && listenerCallBack && handler.callback !== listenerCallBack) {
|
|
1101
|
-
// callback不同
|
|
1102
1106
|
flag = false;
|
|
1103
1107
|
}
|
|
1104
1108
|
if (flag && selectorList.length && Array.isArray(handler.selector)) {
|
|
1105
1109
|
if (JSON.stringify(handler.selector) !== JSON.stringify(selectorList)) {
|
|
1106
|
-
// 子元素选择器不同
|
|
1107
1110
|
flag = false;
|
|
1108
1111
|
}
|
|
1109
1112
|
}
|
|
1110
1113
|
if (flag &&
|
|
1111
1114
|
typeof handler.option.capture === "boolean" &&
|
|
1112
1115
|
listenerOption.capture !== handler.option.capture) {
|
|
1113
|
-
// 事件的配置项不同
|
|
1114
1116
|
flag = false;
|
|
1115
1117
|
}
|
|
1116
1118
|
if (flag) {
|
|
1117
1119
|
$elItem.removeEventListener(eventName, handler.handlerCallBack, handler.option);
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1120
|
+
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
1121
|
+
if (handlers[i] === handler) {
|
|
1122
|
+
handlers.splice(i, 1);
|
|
1123
|
+
}
|
|
1121
1124
|
}
|
|
1122
1125
|
}
|
|
1123
1126
|
}
|