@leafer-ui/mask 1.0.8 → 1.0.10

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 +5 -5
  2. package/src/index.ts +10 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/mask",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "@leafer-ui/mask",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.8",
26
- "@leafer-ui/draw": "1.0.8"
25
+ "@leafer/core": "1.0.10",
26
+ "@leafer-ui/draw": "1.0.10"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.0.8",
30
- "@leafer-ui/interface": "1.0.8"
29
+ "@leafer/interface": "1.0.10",
30
+ "@leafer-ui/interface": "1.0.10"
31
31
  }
32
32
  }
package/src/index.ts CHANGED
@@ -1,21 +1,21 @@
1
- import { ILeaf, ILeaferCanvas, IRenderOptions } from '@leafer/interface'
1
+ import { ILeaf, ILeaferCanvas, IMaskType, IRenderOptions } from '@leafer/interface'
2
2
  import { LeafBoundsHelper } from '@leafer/core'
3
3
 
4
4
  import { Group } from '@leafer-ui/draw'
5
5
 
6
6
 
7
- type IMaskMode = 'path' | 'alpha' | 'opacity-path'
7
+ type IMaskMode = 'path' | 'alpha' | 'grayscale' | 'opacity-path'
8
8
  const { excludeRenderBounds } = LeafBoundsHelper
9
9
 
10
10
  Group.prototype.__renderMask = function (canvas: ILeaferCanvas, options: IRenderOptions): void {
11
11
 
12
- let child: ILeaf, maskCanvas: ILeaferCanvas, contentCanvas: ILeaferCanvas, maskOpacity: number, currentMask: IMaskMode
12
+ let child: ILeaf, maskCanvas: ILeaferCanvas, contentCanvas: ILeaferCanvas, maskOpacity: number, currentMask: IMaskMode, mask: boolean | IMaskType
13
13
  const { children } = this
14
14
 
15
15
  for (let i = 0, len = children.length; i < len; i++) {
16
- child = children[i]
16
+ child = children[i], mask = child.__.mask
17
17
 
18
- if (child.__.mask) {
18
+ if (mask) {
19
19
 
20
20
  if (currentMask) {
21
21
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity)
@@ -24,7 +24,7 @@ Group.prototype.__renderMask = function (canvas: ILeaferCanvas, options: IRender
24
24
 
25
25
  // mask start
26
26
 
27
- if (child.__.mask === 'path') {
27
+ if (mask === 'path' || mask === 'clipping-path') {
28
28
 
29
29
  if (child.opacity < 1) {
30
30
 
@@ -42,14 +42,14 @@ Group.prototype.__renderMask = function (canvas: ILeaferCanvas, options: IRender
42
42
 
43
43
  } else { // pixel
44
44
 
45
- currentMask = 'alpha'
45
+ currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha'
46
46
  if (!maskCanvas) maskCanvas = getCanvas(canvas)
47
47
  if (!contentCanvas) contentCanvas = getCanvas(canvas)
48
48
  child.__render(maskCanvas, options)
49
49
 
50
50
  }
51
51
 
52
- if (child.__.mask !== 'clipping') continue
52
+ if (!(mask === 'clipping' || mask === 'clipping-path')) continue
53
53
  }
54
54
 
55
55
  if (excludeRenderBounds(child, options)) continue
@@ -63,6 +63,8 @@ Group.prototype.__renderMask = function (canvas: ILeaferCanvas, options: IRender
63
63
 
64
64
  function maskEnd(leaf: ILeaf, maskMode: IMaskMode, canvas: ILeaferCanvas, contentCanvas: ILeaferCanvas, maskCanvas: ILeaferCanvas, maskOpacity: number): void {
65
65
  switch (maskMode) {
66
+ case 'grayscale':
67
+ maskCanvas.useGrayscaleAlpha(leaf.__nowWorld)
66
68
  case 'alpha':
67
69
  usePixelMask(leaf, canvas, contentCanvas, maskCanvas); break
68
70
  case 'opacity-path':