@leafer-ui/paint 1.0.0-rc.6 → 1.0.0-rc.7

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.6",
3
+ "version": "1.0.0-rc.7",
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.6"
25
+ "@leafer/core": "1.0.0-rc.7"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.6",
29
- "@leafer-ui/interface": "1.0.0-rc.6"
28
+ "@leafer/interface": "1.0.0-rc.7",
29
+ "@leafer-ui/interface": "1.0.0-rc.7"
30
30
  }
31
31
  }
package/src/Compute.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap, IImagePaint } from '@leafer-ui/interface'
1
+ import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap, IImagePaint, IObject } from '@leafer-ui/interface'
2
2
  import { ColorConvert, ImageManager } from '@leafer-ui/core'
3
3
 
4
4
  import { image } from "./paint/image/image"
@@ -26,7 +26,7 @@ export function compute(attrName: 'fill' | 'stroke', ui: IUI): void {
26
26
  if (item) value.push(item)
27
27
  }
28
28
 
29
- data['_' + attrName] = value.length ? value : undefined
29
+ (data as IObject)['_' + attrName] = value.length ? value : undefined
30
30
 
31
31
  // check png / svg / webp
32
32
 
package/src/Stroke.ts CHANGED
@@ -47,7 +47,7 @@ export function stroke(stroke: string, ui: IUI, canvas: ILeaferCanvas, renderOpt
47
47
  options.windingRule ? out.clip(options.windingRule) : out.clip()
48
48
  out.clearWorld(ui.__layout.renderBounds)
49
49
 
50
- if (ui.__hasMirror || renderOptions.matrix) {
50
+ if (ui.__worldFlipped || renderOptions.matrix) {
51
51
  canvas.copyWorldByReset(out)
52
52
  } else {
53
53
  canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds)
@@ -102,7 +102,7 @@ export function strokes(strokes: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas, r
102
102
  options.windingRule ? out.clip(options.windingRule) : out.clip()
103
103
  out.clearWorld(renderBounds)
104
104
 
105
- if (ui.__hasMirror || renderOptions.matrix) {
105
+ if (ui.__worldFlipped || renderOptions.matrix) {
106
106
  canvas.copyWorldByReset(out)
107
107
  } else {
108
108
  canvas.copyWorldToInner(out, ui.__world, renderBounds)
package/src/StrokeText.ts CHANGED
@@ -36,7 +36,7 @@ function drawAlignStroke(align: IStrokeAlign, stroke: string | ILeafPaint[], isS
36
36
  fillText(ui, out)
37
37
  out.blendMode = 'normal'
38
38
 
39
- if (ui.__hasMirror || renderOptions.matrix) {
39
+ if (ui.__worldFlipped || renderOptions.matrix) {
40
40
  canvas.copyWorldByReset(out)
41
41
  } else {
42
42
  canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds)
@@ -1,11 +1,13 @@
1
1
 
2
2
  import { ILeaferCanvas } from '@leafer/interface'
3
- import { ImageManager } from '@leafer/core'
3
+ import { ImageManager, Platform } from '@leafer/core'
4
4
 
5
5
  import { IUI, ILeafPaint } from '@leafer-ui/interface'
6
+ import { Export } from '@leafer-ui/external'
6
7
 
7
8
  import { createPattern } from './pattern'
8
9
 
10
+ const { abs } = Math
9
11
 
10
12
  export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, allowPaint?: boolean): boolean {
11
13
  const { scaleX, scaleY } = ui.__world
@@ -14,12 +16,18 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
14
16
  return false
15
17
  } else {
16
18
 
19
+ const { data } = paint
20
+
17
21
  if (allowPaint) {
18
- if (paint.image.isSVG && paint.data.mode !== 'repeat') {
19
- let { width, height } = paint.data
20
- width *= scaleX * canvas.pixelRatio
21
- height *= scaleY * canvas.pixelRatio
22
- allowPaint = width > 4096 || height > 4096
22
+ if (data.mode !== 'repeat') {
23
+ let { width, height } = data
24
+ width *= abs(scaleX) * canvas.pixelRatio
25
+ height *= abs(scaleY) * canvas.pixelRatio
26
+ if (data.scaleX) {
27
+ width *= data.scaleX
28
+ height *= data.scaleY
29
+ }
30
+ allowPaint = width * height > Platform.image.maxCacheSize
23
31
  } else {
24
32
  allowPaint = false
25
33
  }
@@ -28,7 +36,6 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
28
36
  if (allowPaint) {
29
37
  canvas.save()
30
38
  canvas.clip()
31
- const { data } = paint
32
39
  if (paint.blendMode) canvas.blendMode = paint.blendMode
33
40
  if (data.opacity) canvas.opacity *= data.opacity
34
41
  if (data.transform) canvas.transform(data.transform)
@@ -36,7 +43,7 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
36
43
  canvas.restore()
37
44
  return true
38
45
  } else {
39
- if (!paint.style) {
46
+ if (!paint.style || Export.running) {
40
47
  createPattern(ui, paint, canvas.pixelRatio)
41
48
  } else {
42
49
  if (!paint.patternTask) {
@@ -64,6 +64,10 @@ function hasNaturalSize(ui: IUI, attrName: string, image: ISizeData): boolean {
64
64
  d.__naturalWidth = image.width
65
65
  d.__naturalHeight = image.height
66
66
  if (!d.__getInput('width') || !d.__getInput('height')) {
67
+ if (ui.__proxyData) {
68
+ ui.setProxyAttr('width', ui.__.width)
69
+ ui.setProxyAttr('height', ui.__.height)
70
+ }
67
71
  ui.forceUpdate('width')
68
72
  return false
69
73
  }
@@ -3,7 +3,7 @@ import { Platform, MatrixHelper } from '@leafer/core'
3
3
  import { IUI, ILeafPaint, IMatrixData } from '@leafer-ui/interface'
4
4
 
5
5
 
6
- const { get, scale: scaleHelper, copy } = MatrixHelper
6
+ const { get, scale, copy } = MatrixHelper
7
7
 
8
8
  export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): boolean {
9
9
 
@@ -13,20 +13,16 @@ export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): b
13
13
 
14
14
  if (paint.patternId !== id && !ui.destroyed) {
15
15
 
16
- paint.patternId = id
17
-
18
16
  scaleX = Math.abs(scaleX) // maybe -1
19
17
  scaleY = Math.abs(scaleY)
20
18
 
21
19
  const { image, data } = paint
22
- const maxWidth = image.isSVG ? 4096 : Math.min(image.width, 4096)
23
- const maxHeight = image.isSVG ? 4096 : Math.min(image.height, 4096)
24
- let scale: number, matrix: IMatrixData, { width, height, scaleX: sx, scaleY: sy, opacity, transform, mode } = data
20
+ let imageScale: number, imageMatrix: IMatrixData, { width, height, scaleX: sx, scaleY: sy, opacity, transform, mode } = data
25
21
 
26
22
  if (sx) {
27
- matrix = get()
28
- copy(matrix, transform)
29
- scaleHelper(matrix, 1 / sx, 1 / sy)
23
+ imageMatrix = get()
24
+ copy(imageMatrix, transform)
25
+ scale(imageMatrix, 1 / sx, 1 / sy)
30
26
  scaleX *= sx
31
27
  scaleY *= sy
32
28
  }
@@ -36,15 +32,26 @@ export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): b
36
32
  width *= scaleX
37
33
  height *= scaleY
38
34
 
39
- if (width > maxWidth || height > maxHeight) {
40
- scale = Math.max(width / maxWidth, height / maxHeight)
35
+ const size = width * height
36
+
37
+ if (paint.data.mode !== 'repeat') {
38
+ if (size > Platform.image.maxCacheSize) return false // same as check()
39
+ }
40
+
41
+ let maxSize = Platform.image.maxPatternSize
42
+
43
+ if (!image.isSVG) {
44
+ const imageSize = image.width * image.height
45
+ if (maxSize > imageSize) maxSize = imageSize
41
46
  }
42
47
 
43
- if (scale) {
44
- scaleX /= scale
45
- scaleY /= scale
46
- width /= scale
47
- height /= scale
48
+ if (size > maxSize) imageScale = Math.sqrt(size / maxSize)
49
+
50
+ if (imageScale) {
51
+ scaleX /= imageScale
52
+ scaleY /= imageScale
53
+ width /= imageScale
54
+ height /= imageScale
48
55
  }
49
56
 
50
57
  if (sx) {
@@ -53,23 +60,24 @@ export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): b
53
60
  }
54
61
 
55
62
  if (transform || scaleX !== 1 || scaleY !== 1) {
56
- if (!matrix) {
57
- matrix = get()
58
- if (transform) copy(matrix, transform)
63
+ if (!imageMatrix) {
64
+ imageMatrix = get()
65
+ if (transform) copy(imageMatrix, transform)
59
66
  }
60
- scaleHelper(matrix, 1 / scaleX, 1 / scaleY)
67
+ scale(imageMatrix, 1 / scaleX, 1 / scaleY)
61
68
  }
62
69
 
63
- const style = Platform.canvas.createPattern(image.getCanvas(width < 1 ? 1 : width, height < 1 ? 1 : height, opacity) as any, mode === 'repeat' ? 'repeat' : (Platform.origin.noRepeat || 'no-repeat'))
70
+ const pattern = Platform.canvas.createPattern(image.getCanvas(width < 1 ? 1 : width, height < 1 ? 1 : height, opacity) as any, mode === 'repeat' ? 'repeat' : (Platform.origin.noRepeat || 'no-repeat'))
64
71
 
65
72
  try {
66
73
  if (paint.transform) paint.transform = null
67
- if (matrix) style.setTransform ? style.setTransform(matrix) : paint.transform = matrix
74
+ if (imageMatrix) pattern.setTransform ? pattern.setTransform(imageMatrix) : paint.transform = imageMatrix
68
75
  } catch {
69
- paint.transform = matrix
76
+ paint.transform = imageMatrix
70
77
  }
71
78
 
72
- paint.style = style
79
+ paint.style = pattern
80
+ paint.patternId = id
73
81
 
74
82
  return true
75
83
 
@@ -1,11 +1,11 @@
1
- import { IBooleanMap, ILeaferImage } from '@leafer/interface'
1
+ import { IBooleanMap, ILeaferImage, IObject } from '@leafer/interface'
2
2
  import { ImageManager } from '@leafer/core'
3
3
 
4
4
  import { IImagePaint, ILeafPaint, IUIData } from '@leafer-ui/interface'
5
5
 
6
6
 
7
7
  export function recycleImage(attrName: 'fill' | 'stroke', data: IUIData): IBooleanMap {
8
- const paints = (attrName === 'fill' ? data._fill : data._stroke) as ILeafPaint[]
8
+ const paints = (data as IObject)['_' + attrName] as ILeafPaint[]
9
9
 
10
10
  if (paints instanceof Array) {
11
11