@leafer-ui/image 1.7.0 → 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.7.0",
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.7.0",
26
- "@leafer-ui/draw": "1.7.0"
25
+ "@leafer/core": "1.8.0",
26
+ "@leafer-ui/draw": "1.8.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.7.0",
30
- "@leafer-ui/interface": "1.7.0"
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,10 +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, editing } = paint
15
+ const { changeful, sync, editing, scaleFixed } = paint
16
16
  if (changeful) leafPaint.changeful = changeful
17
17
  if (sync) leafPaint.sync = sync
18
18
  if (editing) leafPaint.editing = editing
19
+ if (scaleFixed) leafPaint.scaleFixed = scaleFixed
19
20
  leafPaint.data = getPatternData(paint, box, image)
20
21
  }
21
22
 
@@ -24,7 +25,7 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
24
25
  if (paint.mode === 'strench' as string) paint.mode = 'stretch' // 兼容代码,后续可移除
25
26
 
26
27
  let { width, height } = image
27
- const { opacity, mode, align, offset, scale, size, rotation, skew, repeat, filters } = paint
28
+ const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, filters } = paint
28
29
  const sameBox = box.width === width && box.height === height
29
30
 
30
31
  const data: ILeafPaintPatternData = { mode }
@@ -60,7 +61,7 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
60
61
  break
61
62
  case 'normal':
62
63
  case 'clip':
63
- if (tempImage.x || tempImage.y || scaleX || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew)
64
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize)
64
65
  break
65
66
  case 'repeat':
66
67
  if (!sameBox || scaleX || rotation) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, align)
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, skew: skewHelper } = 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,13 +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, skew: IPointData): 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
20
  // rotate -> skew -> scale -> translate
21
21
  const transform: IMatrixData = get()
22
22
  if (rotation) rotate(transform, rotation)
23
23
  if (skew) skewHelper(transform, skew.x, skew.y)
24
24
  if (scaleX) scaleHelper(transform, scaleX, scaleY)
25
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
+ }
26
30
  data.transform = transform
27
31
  }
28
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,16 +7,11 @@ 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