gm-printer 10.13.8-alpha.4 → 10.13.8-alpha.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/util.js +5 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-printer",
3
- "version": "10.13.8-alpha.4",
3
+ "version": "10.13.8-alpha.5",
4
4
  "description": "diy printer",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/util.js CHANGED
@@ -15,12 +15,14 @@ function getHeight(el) {
15
15
 
16
16
  function getWidth(el) {
17
17
  const styles = window.getComputedStyle(el)
18
- const width = Math.ceil(el.offsetWidth)
18
+ // width保留小数点用 getBoundClientRect
19
+ const style = el.getBoundingClientRect()
20
+ const width = Math.round(style.width * 100) / 100 // 保留两位小数并四舍五入
19
21
  const borderLeftWidth = parseFloat(styles.borderLeftWidth)
20
- const borderRightWidth = parseFloat(styles.borderRightWidth)
22
+ // const borderRightWidth = parseFloat(styles.borderRightWidth)
21
23
  const paddingLeft = parseFloat(styles.paddingLeft)
22
24
  const paddingRight = parseFloat(styles.paddingRight)
23
- return width - borderLeftWidth - borderRightWidth - paddingLeft - paddingRight
25
+ return width - borderLeftWidth - paddingLeft - paddingRight
24
26
  }
25
27
 
26
28
  function pxAdd(origin = '0px', add) {