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