@leafer-ui/paint 1.0.0-rc.4 → 1.0.0-rc.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/paint",
3
- "version": "1.0.0-rc.4",
3
+ "version": "1.0.0-rc.5",
4
4
  "description": "@leafer-ui/paint",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,10 +22,10 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.0-rc.4"
25
+ "@leafer/core": "1.0.0-rc.5"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.4",
29
- "@leafer-ui/interface": "1.0.0-rc.4"
28
+ "@leafer/interface": "1.0.0-rc.5",
29
+ "@leafer-ui/interface": "1.0.0-rc.5"
30
30
  }
31
31
  }
package/src/Compute.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap } from '@leafer-ui/interface'
2
- import { ColorConvert } from '@leafer-ui/core'
1
+ import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap, IImagePaint } from '@leafer-ui/interface'
2
+ import { ColorConvert, ImageManager } from '@leafer-ui/core'
3
3
 
4
4
  import { image } from "./paint/image/image"
5
5
  import { linearGradient } from './paint/linear'
@@ -12,19 +12,35 @@ let recycleMap: IBooleanMap
12
12
 
13
13
  export function compute(attrName: 'fill' | 'stroke', ui: IUI): void {
14
14
  const value: ILeafPaint[] = []
15
+ const data = ui.__
16
+
15
17
  let item: ILeafPaint
16
- let paints = ui.__.__input[attrName] as IPaint[]
18
+ let paints = data.__input[attrName] as IPaint[]
17
19
 
18
20
  if (!(paints instanceof Array)) paints = [paints]
19
21
 
20
- recycleMap = recycleImage(attrName, ui.__)
22
+ recycleMap = recycleImage(attrName, data)
21
23
 
22
24
  for (let i = 0, len = paints.length; i < len; i++) {
23
- item = getLeafPaint(attrName, paints[i], ui,)
25
+ item = getLeafPaint(attrName, paints[i], ui)
24
26
  if (item) value.push(item)
25
27
  }
26
28
 
27
- ui.__['_' + attrName] = value.length ? value : undefined
29
+ data['_' + attrName] = value.length ? value : undefined
30
+
31
+ // check png / svg / webp
32
+
33
+ let isPixel
34
+ if (paints.length === 1) {
35
+ const paint = paints[0] as IImagePaint
36
+ if (paint.type === 'image') isPixel = ImageManager.isPixel(paint)
37
+ }
38
+
39
+ if (attrName === 'fill') {
40
+ data.__pixelFill = isPixel
41
+ } else {
42
+ data.__pixelStroke = isPixel
43
+ }
28
44
  }
29
45
 
30
46
 
@@ -39,9 +39,12 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
39
39
  if (!paint.style) {
40
40
  createPattern(ui, paint, canvas.pixelRatio)
41
41
  } else {
42
- ImageManager.patternTasker.add(async () => {
43
- if (canvas.bounds.hit(ui.__world) && createPattern(ui, paint, canvas.pixelRatio)) ui.forceUpdate('surface')
44
- }, 300)
42
+ if (!paint.patternTask) {
43
+ paint.patternTask = ImageManager.patternTasker.add(async () => {
44
+ paint.patternTask = null
45
+ if (canvas.bounds.hit(ui.__world) && createPattern(ui, paint, canvas.pixelRatio)) ui.forceUpdate('surface')
46
+ }, 300)
47
+ }
45
48
  }
46
49
  return false
47
50
  }