@whitesev/pops 2.0.3 → 2.0.5

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