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