@leafer-ui/image 1.6.7 → 1.8.0

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": "1.6.7",
3
+ "version": "1.8.0",
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": "1.6.7",
26
- "@leafer-ui/draw": "1.6.7"
25
+ "@leafer/core": "1.8.0",
26
+ "@leafer-ui/draw": "1.8.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.6.7",
30
- "@leafer-ui/interface": "1.6.7"
29
+ "@leafer/interface": "1.8.0",
30
+ "@leafer-ui/interface": "1.8.0"
31
31
  }
32
32
  }
package/src/check.ts CHANGED
@@ -7,10 +7,8 @@ import { Export } from '@leafer-ui/draw'
7
7
  import { createPattern } from './pattern'
8
8
 
9
9
 
10
- const { abs } = Math
11
-
12
10
  export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, allowDraw?: boolean): boolean {
13
- const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld
11
+ const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed)
14
12
  const { pixelRatio } = canvas, { data } = paint
15
13
 
16
14
  if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
@@ -23,8 +21,8 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
23
21
  } else {
24
22
  if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
25
23
  let { width, height } = data
26
- width *= abs(scaleX) * pixelRatio
27
- height *= abs(scaleY) * pixelRatio
24
+ width *= scaleX * pixelRatio
25
+ height *= scaleY * pixelRatio
28
26
  if (data.scaleX) {
29
27
  width *= data.scaleX
30
28
  height *= data.scaleY
@@ -35,6 +33,10 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
35
33
  }
36
34
 
37
35
  if (allowDraw) {
36
+ if (ui.__.__isFastShadow) { // fix: 快速阴影时,直接 drawImage 会无阴影,需fill一下
37
+ canvas.fillStyle = paint.style || '#000'
38
+ canvas.fill()
39
+ }
38
40
  drawImage(ui, canvas, paint, data) // 直接绘制图像,不生成图案
39
41
  return true
40
42
  } else {
package/src/data.ts CHANGED
@@ -12,9 +12,11 @@ const tempScaleData = {} as IScaleData
12
12
  const tempImage = {} as IBoundsData
13
13
 
14
14
  export function createData(leafPaint: ILeafPaint, image: ILeaferImage, paint: IImagePaint, box: IBoundsData): void {
15
- const { changeful, sync } = paint
15
+ const { changeful, sync, editing, scaleFixed } = paint
16
16
  if (changeful) leafPaint.changeful = changeful
17
17
  if (sync) leafPaint.sync = sync
18
+ if (editing) leafPaint.editing = editing
19
+ if (scaleFixed) leafPaint.scaleFixed = scaleFixed
18
20
  leafPaint.data = getPatternData(paint, box, image)
19
21
  }
20
22
 
@@ -23,7 +25,7 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
23
25
  if (paint.mode === 'strench' as string) paint.mode = 'stretch' // 兼容代码,后续可移除
24
26
 
25
27
  let { width, height } = image
26
- const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint
28
+ const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, filters } = paint
27
29
  const sameBox = box.width === width && box.height === height
28
30
 
29
31
  const data: ILeafPaintPatternData = { mode }
@@ -59,7 +61,7 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
59
61
  break
60
62
  case 'normal':
61
63
  case 'clip':
62
- if (tempImage.x || tempImage.y || scaleX || rotation) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation)
64
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize)
63
65
  break
64
66
  case 'repeat':
65
67
  if (!sameBox || scaleX || rotation) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, align)
package/src/image.ts CHANGED
@@ -60,12 +60,12 @@ export function image(ui: IUI, attrName: string, paint: IImagePaint, boxBounds:
60
60
  }
61
61
  onLoadSuccess(ui, event)
62
62
  }
63
- leafPaint.loadId = null
63
+ leafPaint.loadId = undefined
64
64
  },
65
65
  (error) => {
66
66
  ignoreRender(ui, false)
67
67
  onLoadError(ui, event, error)
68
- leafPaint.loadId = null
68
+ leafPaint.loadId = undefined
69
69
  }
70
70
  )
71
71
 
package/src/mode.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { IBoundsData, IPointData, IMatrixData, IAlign } from '@leafer/interface'
2
- import { MatrixHelper } from '@leafer/core'
1
+ import { IBoundsData, IPointData, IMatrixData, IAlign, ISizeData } from '@leafer/interface'
2
+ import { getMatrixData, MatrixHelper } from '@leafer/core'
3
3
 
4
4
  import { ILeafPaintPatternData } from '@leafer-ui/interface'
5
5
 
6
6
 
7
- let origin = {} as IPointData
8
- const { get, rotateOfOuter, translate, scaleOfOuter, scale: scaleHelper, rotate } = MatrixHelper
7
+ let origin = {} as IPointData, tempMatrix = getMatrixData()
8
+ const { get, rotateOfOuter, translate, scaleOfOuter, multiplyParent, scale: scaleHelper, rotate, skew: skewHelper } = MatrixHelper
9
9
 
10
10
  export function fillOrFitMode(data: ILeafPaintPatternData, box: IBoundsData, x: number, y: number, scaleX: number, scaleY: number, rotation: number): void {
11
11
  const transform: IMatrixData = get()
@@ -16,11 +16,17 @@ export function fillOrFitMode(data: ILeafPaintPatternData, box: IBoundsData, x:
16
16
  }
17
17
 
18
18
 
19
- export function clipMode(data: ILeafPaintPatternData, box: IBoundsData, x: number, y: number, scaleX: number, scaleY: number, rotation: number): void {
19
+ export function clipMode(data: ILeafPaintPatternData, box: IBoundsData, x: number, y: number, scaleX: number, scaleY: number, rotation: number, skew: IPointData, clipSize?: ISizeData): void {
20
+ // rotate -> skew -> scale -> translate
20
21
  const transform: IMatrixData = get()
21
- translate(transform, box.x + x, box.y + y)
22
- if (scaleX) scaleHelper(transform, scaleX, scaleY)
23
22
  if (rotation) rotate(transform, rotation)
23
+ if (skew) skewHelper(transform, skew.x, skew.y)
24
+ if (scaleX) scaleHelper(transform, scaleX, scaleY)
25
+ translate(transform, box.x + x, box.y + y)
26
+ if (clipSize) {
27
+ tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height
28
+ multiplyParent(transform, tempMatrix)
29
+ }
24
30
  data.transform = transform
25
31
  }
26
32
 
package/src/pattern.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Platform, MatrixHelper, ImageManager } from '@leafer/core'
1
+ import { Platform, MatrixHelper } from '@leafer/core'
2
2
 
3
3
  import { IUI, ILeafPaint, IMatrixData } from '@leafer-ui/interface'
4
4
 
@@ -7,20 +7,17 @@ const { get, scale, copy } = MatrixHelper
7
7
  const { ceil, abs } = Math
8
8
 
9
9
  export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): boolean {
10
-
11
- let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld
12
-
10
+ let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed)
13
11
  const id = scaleX + '-' + scaleY + '-' + pixelRatio
14
12
 
15
13
  if (paint.patternId !== id && !ui.destroyed) {
16
14
 
17
- scaleX = abs(scaleX) // maybe -1
18
- scaleY = abs(scaleY)
19
-
20
15
  const { image, data } = paint
21
16
  let imageScale: number, imageMatrix: IMatrixData, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data
22
17
 
23
18
  if (sx) {
19
+ sx = abs(sx) // maybe -1
20
+ sy = abs(sy)
24
21
  imageMatrix = get()
25
22
  copy(imageMatrix, transform)
26
23
  scale(imageMatrix, 1 / sx, 1 / sy)