@whitesev/pops 2.0.3 → 2.0.4

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 CHANGED
@@ -1221,30 +1221,32 @@ define((function () { 'use strict';
1221
1221
  if (element == null) {
1222
1222
  return;
1223
1223
  }
1224
+ let setStyleProperty = (propertyName, propertyValue) => {
1225
+ if (typeof propertyValue === "string" &&
1226
+ propertyValue.trim().endsWith("!important")) {
1227
+ propertyValue = propertyValue
1228
+ .trim()
1229
+ .replace(/!important$/gi, "")
1230
+ .trim();
1231
+ element.style.setProperty(propertyName, propertyValue, "important");
1232
+ }
1233
+ else {
1234
+ propertyValue = handlePixe(propertyName, propertyValue);
1235
+ element.style.setProperty(propertyName, propertyValue);
1236
+ }
1237
+ };
1224
1238
  if (typeof property === "string") {
1225
1239
  if (value == null) {
1226
1240
  return getComputedStyle(element).getPropertyValue(property);
1227
1241
  }
1228
1242
  else {
1229
- if (value === "string" && value.includes("!important")) {
1230
- element.style.setProperty(property, value, "important");
1231
- }
1232
- else {
1233
- value = handlePixe(property, value);
1234
- element.style.setProperty(property, value);
1235
- }
1243
+ setStyleProperty(property, value);
1236
1244
  }
1237
1245
  }
1238
1246
  else if (typeof property === "object") {
1239
1247
  for (let prop in property) {
1240
- if (typeof property[prop] === "string" &&
1241
- property[prop].includes("!important")) {
1242
- element.style.setProperty(prop, property[prop], "important");
1243
- }
1244
- else {
1245
- property[prop] = handlePixe(prop, property[prop]);
1246
- element.style.setProperty(prop, property[prop]);
1247
- }
1248
+ let value = property[prop];
1249
+ setStyleProperty(prop, value);
1248
1250
  }
1249
1251
  }
1250
1252
  }
@@ -1903,31 +1905,37 @@ define((function () { 'use strict';
1903
1905
  * @param maskElement
1904
1906
  */
1905
1907
  hide(popsType, layerConfigList, guid, config, animElement, maskElement) {
1906
- let popsElement = animElement.querySelector(".pops[type-value]");
1907
- if (popsType === "drawer") {
1908
- let drawerConfig = config;
1909
- setTimeout(() => {
1910
- maskElement.style.setProperty("display", "none");
1911
- if (["top", "bottom"].includes(drawerConfig.direction)) {
1912
- popsElement.style.setProperty("height", "0");
1913
- }
1914
- else if (["left", "right"].includes(drawerConfig.direction)) {
1915
- popsElement.style.setProperty("width", "0");
1916
- }
1917
- else {
1918
- console.error("未知direction:", drawerConfig.direction);
1919
- }
1920
- }, drawerConfig.closeDelay);
1921
- }
1922
- else {
1923
- layerConfigList.forEach((layerConfigItem) => {
1924
- if (layerConfigItem.guid === guid) {
1908
+ return new Promise((resolve) => {
1909
+ let popsElement = animElement.querySelector(".pops[type-value]");
1910
+ if (popsType === "drawer") {
1911
+ let drawerConfig = config;
1912
+ setTimeout(() => {
1913
+ maskElement.style.setProperty("display", "none");
1914
+ if (["top", "bottom"].includes(drawerConfig.direction)) {
1915
+ popsElement.style.setProperty("height", "0");
1916
+ }
1917
+ else if (["left", "right"].includes(drawerConfig.direction)) {
1918
+ popsElement.style.setProperty("width", "0");
1919
+ }
1920
+ else {
1921
+ console.error("未知direction:", drawerConfig.direction);
1922
+ }
1923
+ resolve();
1924
+ }, drawerConfig.closeDelay);
1925
+ }
1926
+ else {
1927
+ let findLayerIns = layerConfigList.find((layerConfigItem) => layerConfigItem.guid === guid);
1928
+ if (findLayerIns) {
1925
1929
  /* 存在动画 */
1930
+ let layerConfigItem = findLayerIns;
1926
1931
  layerConfigItem.animElement.style.width = "100%";
1927
1932
  layerConfigItem.animElement.style.height = "100%";
1928
1933
  layerConfigItem.animElement.style["animation-name"] =
1929
1934
  layerConfigItem.animElement.getAttribute("anim") + "-reverse";
1930
1935
  if (pops.config.animation.hasOwnProperty(layerConfigItem.animElement.style["animation-name"])) {
1936
+ /**
1937
+ * 动画结束的回调
1938
+ */
1931
1939
  function animationendCallBack() {
1932
1940
  layerConfigItem.animElement.style.display = "none";
1933
1941
  if (layerConfigItem.maskElement) {
@@ -1936,6 +1944,7 @@ define((function () { 'use strict';
1936
1944
  popsDOMUtils.off(layerConfigItem.animElement, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
1937
1945
  capture: true,
1938
1946
  });
1947
+ resolve();
1939
1948
  }
1940
1949
  popsDOMUtils.on(layerConfigItem.animElement, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
1941
1950
  capture: true,
@@ -1946,11 +1955,11 @@ define((function () { 'use strict';
1946
1955
  if (layerConfigItem.maskElement) {
1947
1956
  layerConfigItem.maskElement.style.display = "none";
1948
1957
  }
1958
+ resolve();
1949
1959
  }
1950
- return;
1951
1960
  }
1952
- });
1953
- }
1961
+ }
1962
+ });
1954
1963
  },
1955
1964
  /**
1956
1965
  * 显示
@@ -1962,27 +1971,30 @@ define((function () { 'use strict';
1962
1971
  * @param maskElement
1963
1972
  */
1964
1973
  show(popsType, layerConfigList, guid, config, animElement, maskElement) {
1965
- let popsElement = animElement.querySelector(".pops[type-value]");
1966
- if (popsType === "drawer") {
1967
- let drawerConfig = config;
1968
- setTimeout(() => {
1969
- maskElement.style.setProperty("display", "");
1970
- let direction = drawerConfig.direction;
1971
- let size = drawerConfig.size.toString();
1972
- if (["top", "bottom"].includes(direction)) {
1973
- popsElement.style.setProperty("height", size);
1974
- }
1975
- else if (["left", "right"].includes(direction)) {
1976
- popsElement.style.setProperty("width", size);
1977
- }
1978
- else {
1979
- console.error("未知direction:", direction);
1980
- }
1981
- }, drawerConfig.openDelay);
1982
- }
1983
- else {
1984
- layerConfigList.forEach((layerConfigItem) => {
1985
- if (layerConfigItem.guid === guid) {
1974
+ return new Promise((resolve) => {
1975
+ let popsElement = animElement.querySelector(".pops[type-value]");
1976
+ if (popsType === "drawer") {
1977
+ let drawerConfig = config;
1978
+ setTimeout(() => {
1979
+ popsDOMUtils.css(maskElement, "display", "");
1980
+ let direction = drawerConfig.direction;
1981
+ let size = drawerConfig.size.toString();
1982
+ if (["top", "bottom"].includes(direction)) {
1983
+ popsElement.style.setProperty("height", size);
1984
+ }
1985
+ else if (["left", "right"].includes(direction)) {
1986
+ popsElement.style.setProperty("width", size);
1987
+ }
1988
+ else {
1989
+ console.error("未知direction:", direction);
1990
+ }
1991
+ resolve();
1992
+ }, drawerConfig.openDelay);
1993
+ }
1994
+ else {
1995
+ let findLayerIns = layerConfigList.find((layerConfigItem) => layerConfigItem.guid === guid);
1996
+ if (findLayerIns) {
1997
+ let layerConfigItem = findLayerIns;
1986
1998
  layerConfigItem.animElement.style.width = "";
1987
1999
  layerConfigItem.animElement.style.height = "";
1988
2000
  layerConfigItem.animElement.style["animation-name"] =
@@ -1990,14 +2002,18 @@ define((function () { 'use strict';
1990
2002
  .animElement.getAttribute("anim")
1991
2003
  .replace("-reverse", "");
1992
2004
  if (pops.config.animation.hasOwnProperty(layerConfigItem.animElement.style["animation-name"])) {
1993
- layerConfigItem.animElement.style.display = "";
1994
- if (layerConfigItem.maskElement) {
1995
- layerConfigItem.maskElement.style.display = "";
1996
- }
2005
+ /**
2006
+ * 动画结束的回调
2007
+ */
1997
2008
  function animationendCallBack() {
1998
2009
  popsDOMUtils.off(layerConfigItem.animElement, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
1999
2010
  capture: true,
2000
2011
  });
2012
+ resolve();
2013
+ }
2014
+ layerConfigItem.animElement.style.display = "";
2015
+ if (layerConfigItem.maskElement) {
2016
+ layerConfigItem.maskElement.style.display = "";
2001
2017
  }
2002
2018
  popsDOMUtils.on(layerConfigItem.animElement, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
2003
2019
  capture: true,
@@ -2008,11 +2024,11 @@ define((function () { 'use strict';
2008
2024
  if (layerConfigItem.maskElement) {
2009
2025
  layerConfigItem.maskElement.style.display = "";
2010
2026
  }
2027
+ resolve();
2011
2028
  }
2012
2029
  }
2013
- return;
2014
- });
2015
- }
2030
+ }
2031
+ });
2016
2032
  },
2017
2033
  /**
2018
2034
  * 关闭
@@ -2023,50 +2039,57 @@ define((function () { 'use strict';
2023
2039
  * @param animElement
2024
2040
  */
2025
2041
  close(popsType, layerConfigList, guid, config, animElement) {
2026
- let popsElement = animElement.querySelector(".pops[type-value]");
2027
- let drawerConfig = config;
2028
- /**
2029
- * 动画结束事件
2030
- */
2031
- function transitionendEvent() {
2032
- function closeCallBack(event) {
2033
- if (event.propertyName !== "transform") {
2042
+ return new Promise((resolve) => {
2043
+ let popsElement = animElement.querySelector(".pops[type-value]");
2044
+ let drawerConfig = config;
2045
+ /**
2046
+ * 动画结束事件
2047
+ */
2048
+ function transitionendEvent() {
2049
+ /**
2050
+ * 弹窗已关闭的回调
2051
+ */
2052
+ function closeCallBack(event) {
2053
+ if (event.propertyName !== "transform") {
2054
+ return;
2055
+ }
2056
+ popsDOMUtils.off(popsElement, popsDOMUtils.getTransitionEndNameList(), void 0, closeCallBack);
2057
+ PopsInstanceUtils.removeInstance([layerConfigList], guid);
2058
+ resolve();
2059
+ }
2060
+ /* 监听过渡结束 */
2061
+ popsDOMUtils.on(popsElement, popsDOMUtils.getTransitionEndNameList(), closeCallBack);
2062
+ let popsTransForm = getComputedStyle(popsElement).transform;
2063
+ if (popsTransForm !== "none") {
2064
+ popsDOMUtils.trigger(popsElement, popsDOMUtils.getTransitionEndNameList(), void 0, true);
2034
2065
  return;
2035
2066
  }
2036
- popsDOMUtils.off(popsElement, popsDOMUtils.getTransitionEndNameList(), void 0, closeCallBack);
2037
- PopsInstanceUtils.removeInstance([layerConfigList], guid);
2038
- }
2039
- /* 监听过渡结束 */
2040
- popsDOMUtils.on(popsElement, popsDOMUtils.getTransitionEndNameList(), closeCallBack);
2041
- let popsTransForm = getComputedStyle(popsElement).transform;
2042
- if (popsTransForm !== "none") {
2043
- popsDOMUtils.trigger(popsElement, popsDOMUtils.getTransitionEndNameList(), void 0, true);
2044
- return;
2045
- }
2046
- if (["top"].includes(drawerConfig.direction)) {
2047
- popsElement.style.setProperty("transform", "translateY(-100%)");
2048
- }
2049
- else if (["bottom"].includes(drawerConfig.direction)) {
2050
- popsElement.style.setProperty("transform", "translateY(100%)");
2051
- }
2052
- else if (["left"].includes(drawerConfig.direction)) {
2053
- popsElement.style.setProperty("transform", "translateX(-100%)");
2067
+ if (["top"].includes(drawerConfig.direction)) {
2068
+ popsElement.style.setProperty("transform", "translateY(-100%)");
2069
+ }
2070
+ else if (["bottom"].includes(drawerConfig.direction)) {
2071
+ popsElement.style.setProperty("transform", "translateY(100%)");
2072
+ }
2073
+ else if (["left"].includes(drawerConfig.direction)) {
2074
+ popsElement.style.setProperty("transform", "translateX(-100%)");
2075
+ }
2076
+ else if (["right"].includes(drawerConfig.direction)) {
2077
+ popsElement.style.setProperty("transform", "translateX(100%)");
2078
+ }
2079
+ else {
2080
+ console.error("未知direction:", drawerConfig.direction);
2081
+ }
2054
2082
  }
2055
- else if (["right"].includes(drawerConfig.direction)) {
2056
- popsElement.style.setProperty("transform", "translateX(100%)");
2083
+ if (popsType === "drawer") {
2084
+ setTimeout(() => {
2085
+ transitionendEvent();
2086
+ }, drawerConfig.closeDelay);
2057
2087
  }
2058
2088
  else {
2059
- console.error("未知direction:", drawerConfig.direction);
2089
+ PopsInstanceUtils.removeInstance([layerConfigList], guid);
2090
+ resolve();
2060
2091
  }
2061
- }
2062
- if (popsType === "drawer") {
2063
- setTimeout(() => {
2064
- transitionendEvent();
2065
- }, drawerConfig.closeDelay);
2066
- }
2067
- else {
2068
- PopsInstanceUtils.removeInstance([layerConfigList], guid);
2069
- }
2092
+ });
2070
2093
  },
2071
2094
  /**
2072
2095
  * 拖拽元素
@@ -2795,11 +2818,11 @@ define((function () { 'use strict';
2795
2818
  function originalRun() {
2796
2819
  if (details.config.mask.clickEvent.toClose) {
2797
2820
  /* 关闭 */
2798
- PopsInstanceUtils.close(details.type, targetLayer, details.guid, details.config, details.animElement);
2821
+ return PopsInstanceUtils.close(details.type, targetLayer, details.guid, details.config, details.animElement);
2799
2822
  }
2800
2823
  else if (details.config.mask.clickEvent.toHide) {
2801
2824
  /* 隐藏 */
2802
- PopsInstanceUtils.hide(details.type, targetLayer, details.guid, details.config, details.animElement, result.maskElement);
2825
+ return PopsInstanceUtils.hide(details.type, targetLayer, details.guid, details.config, details.animElement, result.maskElement);
2803
2826
  }
2804
2827
  }
2805
2828
  if (typeof details.config.mask.clickCallBack === "function") {
@@ -2978,13 +3001,13 @@ define((function () { 'use strict';
2978
3001
  mode: mode,
2979
3002
  guid: guid,
2980
3003
  close() {
2981
- PopsInstanceUtils.close(mode, pops.config.layer[mode], guid, config, animElement);
3004
+ return PopsInstanceUtils.close(mode, pops.config.layer[mode], guid, config, animElement);
2982
3005
  },
2983
3006
  hide() {
2984
- PopsInstanceUtils.hide(mode, pops.config.layer[mode], guid, config, animElement, maskElement);
3007
+ return PopsInstanceUtils.hide(mode, pops.config.layer[mode], guid, config, animElement, maskElement);
2985
3008
  },
2986
3009
  show() {
2987
- PopsInstanceUtils.show(mode, pops.config.layer[mode], guid, config, animElement, maskElement);
3010
+ return PopsInstanceUtils.show(mode, pops.config.layer[mode], guid, config, animElement, maskElement);
2988
3011
  },
2989
3012
  };
2990
3013
  },
@@ -3006,13 +3029,13 @@ define((function () { 'use strict';
3006
3029
  mode: mode,
3007
3030
  guid: guid,
3008
3031
  close() {
3009
- PopsInstanceUtils.close(mode, pops.config.layer[mode], guid, config, animElement);
3032
+ return PopsInstanceUtils.close(mode, pops.config.layer[mode], guid, config, animElement);
3010
3033
  },
3011
3034
  hide() {
3012
- PopsInstanceUtils.hide(mode, pops.config.layer[mode], guid, config, animElement, maskElement);
3035
+ return PopsInstanceUtils.hide(mode, pops.config.layer[mode], guid, config, animElement, maskElement);
3013
3036
  },
3014
3037
  show() {
3015
- PopsInstanceUtils.show(mode, pops.config.layer[mode], guid, config, animElement, maskElement);
3038
+ return PopsInstanceUtils.show(mode, pops.config.layer[mode], guid, config, animElement, maskElement);
3016
3039
  },
3017
3040
  };
3018
3041
  },
@@ -3780,6 +3803,9 @@ define((function () { 'use strict';
3780
3803
  maskHTML: maskHTML,
3781
3804
  });
3782
3805
  $mask = _handleMask_.maskElement;
3806
+ // 遮罩层必须是跟随主内容
3807
+ // 即设置主内容position: relative,mask:position: absolute
3808
+ popsDOMUtils.css($mask, "position", "absolute !important");
3783
3809
  elementList.push($mask);
3784
3810
  }
3785
3811
  let eventDetails = PopsHandler.handleLoadingEventDetails(guid, PopsType, $anim, $pops, $mask, config);
@@ -10054,7 +10080,7 @@ define((function () { 'use strict';
10054
10080
  /** 配置 */
10055
10081
  config = {
10056
10082
  /** 版本号 */
10057
- version: "2025.5.1",
10083
+ version: "2025.5.12",
10058
10084
  cssText: {
10059
10085
  /** 主CSS */
10060
10086
  index: indexCSS,