@leafer-ui/effect 1.0.0-alpha.23 → 1.0.0-alpha.31

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/effect",
3
- "version": "1.0.0-alpha.23",
3
+ "version": "1.0.0-alpha.31",
4
4
  "description": "@leafer-ui/effect",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -1,29 +1,35 @@
1
- import { IBoundsData, ILeaferCanvas, IMatrixWithBoundsData, ISizeData } from '@leafer/interface'
1
+ import { IBoundsData, ILeaferCanvas, IMatrixWithBoundsData, IOffsetBoundsData } from '@leafer/interface'
2
2
  import { BoundsHelper } from '@leafer/core'
3
3
 
4
4
  import { IUI, ICachedShape } from '@leafer-ui/interface'
5
+ import { drawWorldShadow } from './Shadow'
5
6
 
6
- const bigger: ISizeData = {
7
- width: 4,
8
- height: 4
9
- }
7
+ const { toOffsetOutBounds } = BoundsHelper
8
+ const offsetOutBounds = {} as IOffsetBoundsData
10
9
 
11
10
  export function innerShadow(ui: IUI, current: ILeaferCanvas, shape: ICachedShape): void {
12
11
 
13
- let copyBounds: IBoundsData
12
+ let copyBounds: IBoundsData, spreadScale: number
14
13
 
15
- const { __world, __layout } = ui
14
+ const { __world, __layout: __layout } = ui
16
15
  const { innerShadow } = ui.__
17
16
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape
18
17
 
19
- const other = current.getBiggerCanvas(bigger.width, bigger.height)
20
- const out = BoundsHelper.getOutOfBounds(bounds, current.bounds)
18
+ const other = current.getSameCanvas()
19
+ const end = innerShadow.length - 1
20
+
21
+ toOffsetOutBounds(bounds, offsetOutBounds)
21
22
 
22
- innerShadow.forEach(item => {
23
+ innerShadow.forEach((item, index) => {
23
24
 
24
25
  other.save()
25
- other.setWorldShadow((out.offsetX + item.x * scaleX), (out.offsetY + item.y * scaleY), item.blur * scaleX)
26
- other.copyWorld(shape.canvas, shapeBounds, item.spread ? BoundsHelper.getSpread(out, -item.spread * scaleX * (__layout.renderBounds.width / __layout.strokeBounds.width)) : out)
26
+
27
+ other.setWorldShadow((offsetOutBounds.offsetX + item.x * scaleX), (offsetOutBounds.offsetY + item.y * scaleY), item.blur * scaleX)
28
+
29
+ spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.shapeStrokeSpreadWidth || 0) * 2) : 0
30
+
31
+ drawWorldShadow(other, offsetOutBounds, spreadScale, shape)
32
+
27
33
  other.restore()
28
34
 
29
35
  if (worldCanvas) {
@@ -39,9 +45,12 @@ export function innerShadow(ui: IUI, current: ILeaferCanvas, shape: ICachedShape
39
45
 
40
46
  current.copyWorldToInner(other, copyBounds as IMatrixWithBoundsData, __layout.renderBounds, item.blendMode)
41
47
 
48
+ if (end && index < end) other.clear()
49
+
42
50
  })
43
51
 
44
- //other.debug()
45
52
  other.recycle()
46
53
 
47
- }
54
+ }
55
+
56
+
package/src/Shadow.ts CHANGED
@@ -1,42 +1,42 @@
1
- import { IBoundsData, ILeaferCanvas, IMatrixWithBoundsData, ISizeData } from '@leafer/interface'
2
- import { BoundsHelper } from '@leafer/core'
1
+ import { IBoundsData, ILeaferCanvas, IMatrixWithBoundsData, IOffsetBoundsData } from '@leafer/interface'
2
+ import { BoundsHelper, Platform } from '@leafer/core'
3
3
 
4
4
  import { IUI, ICachedShape } from '@leafer-ui/interface'
5
5
 
6
- const bigger: ISizeData = {
7
- width: 4,
8
- height: 4
9
- }
6
+
7
+ const { copy, toOffsetOutBounds } = BoundsHelper
8
+ const tempBounds = {} as IBoundsData
9
+ const offsetOutBounds = {} as IOffsetBoundsData
10
10
 
11
11
  export function shadow(ui: IUI, current: ILeaferCanvas, shape: ICachedShape): void {
12
12
 
13
- let copyBounds: IBoundsData
13
+ let copyBounds: IBoundsData, spreadScale: number
14
14
 
15
15
  const { __world, __layout } = ui
16
16
  const { shadow } = ui.__
17
17
  const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape
18
18
 
19
- const other = current.getBiggerCanvas(bigger.width, bigger.height)
20
- const out = BoundsHelper.getOutOfBounds(bounds, current.bounds)
19
+ const other = current.getSameCanvas()
20
+ const end = shadow.length - 1
21
+
22
+ toOffsetOutBounds(bounds, offsetOutBounds)
23
+ console.log(offsetOutBounds)
21
24
 
22
- shadow.forEach(item => {
25
+ shadow.forEach((item, index) => {
23
26
 
24
- other.setWorldShadow((out.offsetX + item.x * scaleX), (out.offsetY + item.y * scaleY), item.blur * scaleX, item.color)
25
- other.copyWorld(shape.canvas, shapeBounds, item.spread ? BoundsHelper.getSpread(out, item.spread * scaleX * (__layout.renderBounds.width / __layout.strokeBounds.width)) : out)
27
+ other.setWorldShadow((offsetOutBounds.offsetX + item.x * scaleX), (offsetOutBounds.offsetY + item.y * scaleY), item.blur * scaleX, item.color)
28
+
29
+ spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.shapeStrokeSpreadWidth || 0) * 2) : 0
30
+
31
+ drawWorldShadow(other, offsetOutBounds, spreadScale, shape)
26
32
 
27
33
  copyBounds = bounds
28
34
 
29
- if (!item.showBehind) {
35
+ if (item.boxShadow) {
30
36
 
31
37
  other.restore()
32
38
  other.save()
33
39
 
34
- // other.replaceBy(other, renderBounds, ui.__world)
35
- // other.setTransform(ui.__world)
36
- // ui.__drawPath(other.context, ui.__.__path)
37
- // other.context.clip()
38
- // other.clearRect(ui.__layout.renderBounds)
39
-
40
40
  if (worldCanvas) {
41
41
  other.copyWorld(other, bounds, __world, 'copy')
42
42
  copyBounds = __world
@@ -46,9 +46,46 @@ export function shadow(ui: IUI, current: ILeaferCanvas, shape: ICachedShape): vo
46
46
  }
47
47
 
48
48
  current.copyWorldToInner(other, copyBounds as IMatrixWithBoundsData, __layout.renderBounds, item.blendMode)
49
+
50
+ if (end && index < end) other.clear()
49
51
  })
50
52
 
51
- //other.debug()
52
53
  other.recycle()
53
54
 
55
+ }
56
+
57
+
58
+ export function drawWorldShadow(canvas: ILeaferCanvas, outBounds: IBoundsData, spreadScale: number, shape: ICachedShape,): void {
59
+
60
+ const { bounds, shapeBounds } = shape
61
+
62
+ if (Platform.fullImageShadow) { // Safari
63
+
64
+ copy(tempBounds, canvas.bounds)
65
+ tempBounds.x += (outBounds.x - shapeBounds.x)
66
+ tempBounds.y += (outBounds.y - shapeBounds.y)
67
+
68
+ if (spreadScale) {
69
+ const { matrix } = shape
70
+ tempBounds.x -= (bounds.x + (matrix ? matrix.e : 0) + bounds.width / 2) * (spreadScale - 1)
71
+ tempBounds.y -= (bounds.y + (matrix ? matrix.f : 0) + bounds.height / 2) * (spreadScale - 1)
72
+ tempBounds.width *= spreadScale
73
+ tempBounds.height *= spreadScale
74
+ }
75
+
76
+ canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds)
77
+
78
+ } else {
79
+
80
+ if (spreadScale) {
81
+ copy(tempBounds, outBounds)
82
+ tempBounds.x -= (outBounds.width / 2) * (spreadScale - 1)
83
+ tempBounds.y -= (outBounds.height / 2) * (spreadScale - 1)
84
+ tempBounds.width *= spreadScale
85
+ tempBounds.height *= spreadScale
86
+ }
87
+
88
+ canvas.copyWorld(shape.canvas, shapeBounds, spreadScale ? tempBounds : outBounds)
89
+ }
90
+
54
91
  }