@leafer-ui/image 2.0.0 → 2.0.2

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/image",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "@leafer-ui/image",
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": "2.0.0",
26
- "@leafer-ui/draw": "2.0.0"
25
+ "@leafer/core": "2.0.2",
26
+ "@leafer-ui/draw": "2.0.2"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "2.0.0",
30
- "@leafer-ui/interface": "2.0.0"
29
+ "@leafer/interface": "2.0.2",
30
+ "@leafer-ui/interface": "2.0.2"
31
31
  }
32
32
  }
package/src/check.ts CHANGED
@@ -6,18 +6,18 @@ import { PaintImage } from "@leafer-ui/draw"
6
6
 
7
7
 
8
8
  export function checkImage(paint: ILeafPaint, drawImage: boolean, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): boolean {
9
- const { scaleX, scaleY } = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions)
9
+ const { scaleX, scaleY } = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + '-' + scaleY
10
10
  const { image, data, originPaint } = paint, { exporting, snapshot } = renderOptions
11
11
 
12
- if (!data || (paint.patternId === scaleX + '-' + scaleY && !exporting) || snapshot) {
12
+ if (!data || (paint.patternId === id && !exporting) || snapshot) {
13
13
  return false // 生成图案中
14
14
  } else {
15
15
 
16
16
  if (drawImage) {
17
17
  if (data.repeat) {
18
18
  drawImage = false
19
- } else if (!((originPaint as IImagePaint).changeful || (Platform.name === 'miniapp' && ResizeEvent.isResizing(ui)) || exporting)) { // 小程序resize过程中直接绘制原图(绕过垃圾回收bug)
20
- drawImage = Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096 // 大长图单边超过8096生成pattern会有问题
19
+ } else if (!((originPaint as IImagePaint).changeful || paint.film || (Platform.name === 'miniapp' && ResizeEvent.isResizing(ui)) || exporting)) { // 小程序resize过程中直接绘制原图(绕过垃圾回收bug)
20
+ drawImage = Platform.image.isLarge(image, scaleX, scaleY) || image.width * scaleX > 8096 || image.height * scaleY > 8096 // 非image类型的尽量绘制原图,大长图单边超过8096生成pattern会有问题
21
21
  }
22
22
  }
23
23
 
@@ -36,23 +36,28 @@ export function checkImage(paint: ILeafPaint, drawImage: boolean, ui: IUI, canva
36
36
  }
37
37
  }
38
38
 
39
- export function drawImage(paint: ILeafPaint, _imageScaleX: number, _imageScaleY: number, ui: IUI, canvas: ILeaferCanvas, _renderOptions: IRenderOptions): void {
40
- const { data, image } = paint, { blendMode } = paint.originPaint as IImagePaint, { opacity, transform } = data, view = image.getFull(data.filters), u = ui.__
41
- let { width, height } = image, clipUI: any
39
+ export function drawImage(paint: ILeafPaint, imageScaleX: number, imageScaleY: number, ui: IUI, canvas: ILeaferCanvas, _renderOptions: IRenderOptions): void {
40
+ const { data, image, complex } = paint
41
+ let { width, height } = image
42
42
 
43
- if ((clipUI = (transform && !transform.onlyScale) || u.path || u.cornerRadius) || opacity || blendMode) {
44
- canvas.save()
45
- clipUI && canvas.clipUI(ui)
43
+ if (complex) {
44
+
45
+ const { blendMode, opacity } = paint.originPaint as IImagePaint, { transform } = data
46
+ canvas.save();
47
+ (complex === 2) && canvas.clipUI(ui)
46
48
  blendMode && (canvas.blendMode = blendMode)
47
49
  opacity && (canvas.opacity *= opacity)
48
50
  transform && canvas.transform(transform)
49
- canvas.drawImage(view, 0, 0, width, height) // svg need size
51
+ image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY) // svg need size
50
52
  canvas.restore()
51
- } else { // 简单矩形
53
+
54
+ } else {
55
+
56
+ // 简单矩形
52
57
  if (data.scaleX) width *= data.scaleX, height *= data.scaleY
53
- canvas.drawImage(view, 0, 0, width, height)
54
- }
58
+ image.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY)
55
59
 
60
+ }
56
61
  }
57
62
 
58
63
  export function getImageRenderScaleData(paint: ILeafPaint, ui: IUI, canvas?: ILeaferCanvas, _renderOptions?: IRenderOptions): IScaleData {
package/src/data.ts CHANGED
@@ -19,7 +19,7 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
19
19
  if (paint.mode === 'strench' as string) paint.mode = 'stretch' // 兼容代码,后续可移除
20
20
 
21
21
  const { width, height } = image
22
- const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, gap, filters, interlace } = paint
22
+ const { mode, align, offset, scale, size, rotation, skew, clipSize, repeat, gap, interlace } = paint
23
23
  const sameBox = box.width === width && box.height === height
24
24
 
25
25
  const data: ILeafPaintPatternData = { mode }
@@ -86,8 +86,6 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
86
86
  data.scaleY = scaleY
87
87
  }
88
88
 
89
- if (opacity && opacity < 1) data.opacity = opacity
90
- if (filters) data.filters = filters
91
89
  if (repeat) data.repeat = isString(repeat) ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat'
92
90
  if (interlace) data.interlace = (isNumber(interlace) || interlace.type === 'percent') ? { type: 'x', offset: interlace } : interlace
93
91
  return data
package/src/image.ts CHANGED
@@ -16,7 +16,7 @@ const { isSame } = BoundsHelper
16
16
 
17
17
  export function image(ui: IUI, attrName: string, paint: IImagePaint, boxBounds: IBoundsData, firstUse: boolean): ILeafPaint {
18
18
  let leafPaint: ILeafPaint, event: IImageEvent
19
- const image = ImageManager.get(paint)
19
+ const image = ImageManager.get(paint, paint.type)
20
20
 
21
21
  if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
22
22
  leafPaint = cache.leafPaint
@@ -86,8 +86,9 @@ export function image(ui: IUI, attrName: string, paint: IImagePaint, boxBounds:
86
86
 
87
87
 
88
88
  function checkSizeAndCreateData(ui: IUI, attrName: string, paint: IImagePaint, image: ILeaferImage, leafPaint: ILeafPaint, boxBounds: IBoundsData): boolean {
89
- if (attrName === 'fill' && !ui.__.__naturalWidth) {
90
- const data = ui.__
89
+ const data = ui.__
90
+
91
+ if (attrName === 'fill' && !data.__naturalWidth) {
91
92
  data.__naturalWidth = image.width / data.pixelRatio
92
93
  data.__naturalHeight = image.height / data.pixelRatio
93
94
  if (data.__autoSide) {
@@ -100,7 +101,13 @@ function checkSizeAndCreateData(ui: IUI, attrName: string, paint: IImagePaint, i
100
101
  }
101
102
  }
102
103
 
103
- if (!leafPaint.data) PaintImage.createData(leafPaint, image, paint, boxBounds)
104
+ if (!leafPaint.data) {
105
+ PaintImage.createData(leafPaint, image, paint, boxBounds)
106
+
107
+ const { transform } = leafPaint.data, { opacity, blendMode } = paint
108
+ const clip = (transform && !transform.onlyScale) || data.path || data.cornerRadius
109
+ if (clip || (opacity && opacity < 1) || blendMode) leafPaint.complex = clip ? 2 : true
110
+ }
104
111
  return true
105
112
  }
106
113
 
package/src/mode.ts CHANGED
@@ -10,7 +10,7 @@ const { get, set, rotateOfOuter, translate, scaleOfOuter, multiplyParent, scale:
10
10
  export function stretchMode(data: ILeafPaintPatternData, box: IBoundsData, scaleX: number, scaleY: number): void {
11
11
  const transform: IMatrixData = get(), { x, y } = box
12
12
  if (x || y) translate(transform, x, y)
13
- else transform.onlyScale = true
13
+ else if (scaleX > 0 && scaleY > 0) transform.onlyScale = true
14
14
  scaleHelper(transform, scaleX, scaleY)
15
15
  data.transform = transform
16
16
  }
package/src/pattern.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ILeaferCanvas, IRenderOptions } from '@leafer/interface'
2
2
  import { Platform, MatrixHelper, MathHelper, ImageManager } from '@leafer/core'
3
3
 
4
- import { IUI, ILeafPaint, IMatrixData } from '@leafer-ui/interface'
4
+ import { IUI, ILeafPaint, IMatrixData, IImagePaint } from '@leafer-ui/interface'
5
5
  import { PaintImage } from "@leafer-ui/draw"
6
6
 
7
7
 
@@ -21,12 +21,12 @@ export function createPatternTask(paint: ILeafPaint, ui: IUI, canvas: ILeaferCan
21
21
  }
22
22
 
23
23
  export function createPattern(paint: ILeafPaint, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
24
- let { scaleX, scaleY } = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + '-' + scaleY
24
+ let { scaleX, scaleY } = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + '-' + scaleY
25
25
 
26
26
  if (paint.patternId !== id && !ui.destroyed) {
27
27
  if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
28
28
 
29
- const { image, data } = paint, { transform, gap } = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY)
29
+ const { image, data } = paint, { opacity, filters } = paint.originPaint as IImagePaint, { transform, gap } = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY)
30
30
  let imageMatrix: IMatrixData, xGap: number, yGap: number, { width, height } = image
31
31
 
32
32
  if (fixScale) scaleX *= fixScale, scaleY *= fixScale
@@ -49,7 +49,7 @@ export function createPattern(paint: ILeafPaint, ui: IUI, canvas: ILeaferCanvas,
49
49
  scale(imageMatrix, 1 / scaleX, 1 / scaleY)
50
50
  }
51
51
 
52
- const imageCanvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace)
52
+ const imageCanvas = image.getCanvas(width, height, opacity, filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace)
53
53
  const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint)
54
54
 
55
55
  paint.style = pattern