@leafer-ui/bounds 1.9.7 → 1.9.8

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 +3 -3
  2. package/src/UIBounds.ts +29 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/bounds",
3
- "version": "1.9.7",
3
+ "version": "1.9.8",
4
4
  "description": "@leafer-ui/bounds",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,9 +22,9 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.9.7"
25
+ "@leafer/core": "1.9.8"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer-ui/interface": "1.9.7"
28
+ "@leafer-ui/interface": "1.9.8"
29
29
  }
30
30
  }
package/src/UIBounds.ts CHANGED
@@ -1,59 +1,64 @@
1
- import { IUIBoundsModule } from "@leafer-ui/interface"
1
+ import { IFourNumber } from '@leafer/interface'
2
+ import { FourNumberHelper } from '@leafer/core'
2
3
 
4
+ import { IUIBoundsModule } from "@leafer-ui/interface"
3
5
  import { Effect, Filter } from '@leafer-ui/external'
4
6
 
5
7
 
8
+ const { max, add } = FourNumberHelper
9
+
6
10
  export const UIBounds: IUIBoundsModule = {
7
11
 
8
- __updateStrokeSpread(): number {
9
- let width = 0, boxWidth = 0
12
+ __updateStrokeSpread(): IFourNumber {
13
+ let spread: IFourNumber = 0, boxSpread = 0
10
14
  const data = this.__, { strokeAlign, __maxStrokeWidth: strokeWidth } = data, box = this.__box
11
15
 
12
16
  if ((data.stroke || data.hitStroke === 'all') && strokeWidth && strokeAlign !== 'inside') {
13
- boxWidth = width = strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth
17
+ boxSpread = spread = strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth
14
18
 
15
19
  if (!data.__boxStroke) {
16
- const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * width // = Math.sin((miterLimit = 10) * OneRadian / 2) * Math.sqrt(strokeWidth) - width 后期需继续精确优化
20
+ const miterLimitAddWidth = data.__isLinePath ? 0 : 10 * spread // = Math.sin((miterLimit = 10) * OneRadian / 2) * Math.sqrt(strokeWidth) - width 后期需继续精确优化
17
21
  const storkeCapAddWidth = data.strokeCap === 'none' ? 0 : strokeWidth
18
- width += Math.max(miterLimitAddWidth, storkeCapAddWidth)
22
+ spread += Math.max(miterLimitAddWidth, storkeCapAddWidth)
19
23
  }
20
24
  }
21
25
 
22
- if (data.__useArrow) width += strokeWidth * 5 // 后期需要精细化
26
+ if (data.__useArrow) spread += strokeWidth * 5 // 后期需要精细化
23
27
 
24
28
  if (box) {
25
- width = Math.max(box.__layout.strokeSpread = box.__updateStrokeSpread(), width)
26
- boxWidth = box.__layout.strokeBoxSpread
29
+ spread = max(spread, box.__layout.strokeSpread = box.__updateStrokeSpread())
30
+ boxSpread = Math.max(boxSpread, box.__layout.strokeBoxSpread)
27
31
  }
28
32
 
29
- this.__layout.strokeBoxSpread = boxWidth
33
+ this.__layout.strokeBoxSpread = boxSpread
30
34
 
31
- return width
35
+ return spread
32
36
  },
33
37
 
34
- __updateRenderSpread(): number {
35
- let width: number = 0
36
- const { shadow, innerShadow, blur, backgroundBlur, filter, renderSpread } = this.__
38
+ __updateRenderSpread(): IFourNumber {
39
+ let spread: IFourNumber = 0
40
+ const { shadow, innerShadow, blur, backgroundBlur, filter, renderSpread } = this.__, { strokeSpread } = this.__layout, box = this.__box
41
+
42
+ if (shadow) spread = Effect.getShadowRenderSpread(this, shadow)
37
43
 
38
- if (shadow) width = Effect.getShadowSpread(this, shadow)
44
+ if (blur) spread = max(spread, blur)
39
45
 
40
- if (blur) width = Math.max(width, blur)
46
+ if (filter) spread = add(spread, Filter.getSpread(filter))
41
47
 
42
- if (filter) width += Filter.getSpread(filter)
48
+ if (renderSpread) spread = add(spread, renderSpread)
43
49
 
44
- if (renderSpread) width += renderSpread
50
+ if (strokeSpread) spread = add(spread, strokeSpread)
45
51
 
46
- let shapeWidth = width = Math.ceil(width)
47
52
 
48
- if (innerShadow) innerShadow.forEach(item => shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5))
53
+ let shapeSpread = spread
49
54
 
50
- if (backgroundBlur) shapeWidth = Math.max(shapeWidth, backgroundBlur)
55
+ if (innerShadow) shapeSpread = max(shapeSpread, Effect.getInnerShadowSpread(this, innerShadow))
51
56
 
52
- this.__layout.renderShapeSpread = shapeWidth
57
+ if (backgroundBlur) shapeSpread = max(shapeSpread, backgroundBlur)
53
58
 
54
- width += this.__layout.strokeSpread || 0
59
+ this.__layout.renderShapeSpread = shapeSpread
55
60
 
56
- return this.__box ? Math.max(this.__box.__updateRenderSpread(), width) : width
61
+ return box ? max(box.__updateRenderSpread(), spread) : spread
57
62
  }
58
63
 
59
64
  }