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