@leafer-ui/effect 1.0.0-alpha.21 → 1.0.0-alpha.30

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.21",
3
+ "version": "1.0.0-alpha.30",
4
4
  "description": "@leafer-ui/effect",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
package/src/Blur.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { ILeaferCanvas } from '@leafer/interface'
2
+
3
+ import { IUI } from '@leafer-ui/interface'
4
+
5
+ export function blur(ui: IUI, current: ILeaferCanvas, origin: ILeaferCanvas): void {
6
+ const { blur } = ui.__
7
+ origin.setWorldBlur(blur * ui.__world.a)
8
+ origin.copyWorldToInner(current, ui.__world, ui.__layout.renderBounds)
9
+ origin.filter = 'none'
10
+ }
@@ -0,0 +1,47 @@
1
+ import { IBoundsData, ILeaferCanvas, IMatrixWithBoundsData, ISizeData } from '@leafer/interface'
2
+ import { BoundsHelper } from '@leafer/core'
3
+
4
+ import { IUI, ICachedShape } from '@leafer-ui/interface'
5
+
6
+ const bigger: ISizeData = {
7
+ width: 4,
8
+ height: 4
9
+ }
10
+
11
+ export function innerShadow(ui: IUI, current: ILeaferCanvas, shape: ICachedShape): void {
12
+
13
+ let copyBounds: IBoundsData
14
+
15
+ const { __world, __layout: __layout } = ui
16
+ const { innerShadow } = ui.__
17
+ const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape
18
+
19
+ const other = current.getBiggerCanvas(bigger.width, bigger.height)
20
+ const out = BoundsHelper.getOutOfBounds(bounds, current.bounds)
21
+
22
+ innerShadow.forEach(item => {
23
+
24
+ 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)
27
+ other.restore()
28
+
29
+ if (worldCanvas) {
30
+ other.copyWorld(other, bounds, __world, 'copy')
31
+ other.copyWorld(worldCanvas, __world, __world, 'source-out')
32
+ copyBounds = __world
33
+ } else {
34
+ other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out')
35
+ copyBounds = bounds
36
+ }
37
+
38
+ other.fillWorld(copyBounds, item.color, 'source-in')
39
+
40
+ current.copyWorldToInner(other, copyBounds as IMatrixWithBoundsData, __layout.renderBounds, item.blendMode)
41
+
42
+ })
43
+
44
+ //other.debug()
45
+ other.recycle()
46
+
47
+ }
package/src/Shadow.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { IBoundsData, ILeaferCanvas, IMatrixWithBoundsData, ISizeData } from '@leafer/interface'
2
+ import { BoundsHelper } from '@leafer/core'
3
+
4
+ import { IUI, ICachedShape } from '@leafer-ui/interface'
5
+
6
+ const bigger: ISizeData = {
7
+ width: 4,
8
+ height: 4
9
+ }
10
+
11
+ export function shadow(ui: IUI, current: ILeaferCanvas, shape: ICachedShape): void {
12
+
13
+ let copyBounds: IBoundsData
14
+
15
+ const { __world, __layout: __layout } = ui
16
+ const { shadow } = ui.__
17
+ const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape
18
+
19
+ const other = current.getBiggerCanvas(bigger.width, bigger.height)
20
+ const out = BoundsHelper.getOutOfBounds(bounds, current.bounds)
21
+
22
+ shadow.forEach(item => {
23
+
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)
26
+
27
+ copyBounds = bounds
28
+
29
+ if (!item.showBehind) {
30
+
31
+ other.restore()
32
+ other.save()
33
+
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
+ if (worldCanvas) {
41
+ other.copyWorld(other, bounds, __world, 'copy')
42
+ copyBounds = __world
43
+ }
44
+
45
+ worldCanvas ? other.copyWorld(worldCanvas, __world, __world, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out')
46
+ }
47
+
48
+ current.copyWorldToInner(other, copyBounds as IMatrixWithBoundsData, __layout.renderBounds, item.blendMode)
49
+ })
50
+
51
+ //other.debug()
52
+ other.recycle()
53
+
54
+ }
package/src/index.ts CHANGED
@@ -0,0 +1,3 @@
1
+ export { shadow } from './Shadow'
2
+ export { innerShadow } from './InnerShadow'
3
+ export { blur } from './Blur'