ztxkutils 2.10.66-38 → 2.10.66-39

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.
Files changed (2) hide show
  1. package/dist/print.js +27 -20
  2. package/package.json +1 -1
package/dist/print.js CHANGED
@@ -59,26 +59,33 @@ function printCurrentDom(_a) {
59
59
  window.print();
60
60
  }
61
61
  function getTextDimensions(text, fontSize) {
62
- // 创建一个临时元素
63
- var tempElement = document.createElement('div');
64
- // 设置元素内容为传入的文本
65
- tempElement.textContent = text;
66
- // 设置样式使其不可见且不影响页面布局
67
- tempElement.style.position = 'absolute';
68
- tempElement.style.visibility = 'hidden'; // 元素不可见但仍占据空间
69
- tempElement.style.opacity = '0'; // 完全透明
70
- tempElement.style.pointerEvents = 'none'; // 不响应鼠标事件
71
- tempElement.style.whiteSpace = 'nowrap'; // 防止文本换行影响宽度测量
72
- tempElement.style.fontSize = fontSize;
73
- tempElement.style.fontFamily = '微软雅黑';
74
- tempElement.style.padding = '50px 10px';
75
- // 插入到body中
76
- document.body.appendChild(tempElement);
77
- // 获取元素的宽高
78
- var width = tempElement.offsetWidth;
79
- var height = tempElement.offsetHeight;
80
- // 从DOM中移除元素
81
- document.body.removeChild(tempElement);
62
+ var width, height;
63
+ try {
64
+ // 创建一个临时元素
65
+ var tempElement = document.createElement('div');
66
+ // 设置元素内容为传入的文本
67
+ tempElement.textContent = text;
68
+ // 设置样式使其不可见且不影响页面布局
69
+ tempElement.style.position = 'absolute';
70
+ tempElement.style.visibility = 'hidden'; // 元素不可见但仍占据空间
71
+ tempElement.style.opacity = '0'; // 完全透明
72
+ tempElement.style.pointerEvents = 'none'; // 不响应鼠标事件
73
+ tempElement.style.whiteSpace = 'nowrap'; // 防止文本换行影响宽度测量
74
+ tempElement.style.fontSize = fontSize;
75
+ tempElement.style.fontFamily = '微软雅黑';
76
+ tempElement.style.padding = '50px 10px';
77
+ // 插入到body中
78
+ document.body.appendChild(tempElement);
79
+ // 获取元素的宽高
80
+ width = tempElement.offsetWidth;
81
+ height = tempElement.offsetHeight;
82
+ // 从DOM中移除元素
83
+ document.body.removeChild(tempElement);
84
+ }
85
+ catch (err) {
86
+ width = text.length * 22;
87
+ height = text.length * 9;
88
+ }
82
89
  // 返回测量结果
83
90
  return {
84
91
  width: width > 520 ? 520 : width < 240 ? 240 : width,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.10.66-38",
3
+ "version": "2.10.66-39",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",