@leafer-ui/image 1.0.1 → 1.0.3

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.0.1",
3
+ "version": "1.0.3",
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.0.1",
26
- "@leafer-ui/draw": "1.0.1"
25
+ "@leafer/core": "1.0.3",
26
+ "@leafer-ui/draw": "1.0.3"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.0.1",
30
- "@leafer-ui/interface": "1.0.1"
29
+ "@leafer/interface": "1.0.3",
30
+ "@leafer-ui/interface": "1.0.3"
31
31
  }
32
32
  }
package/src/check.ts CHANGED
@@ -11,8 +11,9 @@ const { abs } = Math
11
11
 
12
12
  export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, allowPaint?: boolean): boolean {
13
13
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld
14
+ const { pixelRatio } = canvas
14
15
 
15
- if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !Export.running)) {
16
+ if (!paint.data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
16
17
  return false
17
18
  } else {
18
19
 
@@ -21,8 +22,8 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
21
22
  if (allowPaint) {
22
23
  if (!data.repeat) {
23
24
  let { width, height } = data
24
- width *= abs(scaleX) * canvas.pixelRatio
25
- height *= abs(scaleY) * canvas.pixelRatio
25
+ width *= abs(scaleX) * pixelRatio
26
+ height *= abs(scaleY) * pixelRatio
26
27
  if (data.scaleX) {
27
28
  width *= data.scaleX
28
29
  height *= data.scaleY
@@ -43,13 +44,13 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
43
44
  canvas.restore()
44
45
  return true
45
46
  } else {
46
- if (!paint.style || Export.running) {
47
- createPattern(ui, paint, canvas.pixelRatio)
47
+ if (!paint.style || paint.sync || Export.running) {
48
+ createPattern(ui, paint, pixelRatio)
48
49
  } else {
49
50
  if (!paint.patternTask) {
50
51
  paint.patternTask = ImageManager.patternTasker.add(async () => {
51
52
  paint.patternTask = null
52
- if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, canvas.pixelRatio)
53
+ if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio)
53
54
  ui.forceUpdate('surface')
54
55
  }, 300)
55
56
  }
package/src/data.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IBoundsData, ILeaferImage, IPointData } from '@leafer/interface'
2
- import { MatrixHelper, Bounds, AlignHelper } from '@leafer/core'
1
+ import { IBoundsData, ILeaferImage, IPointData, IScaleData } from '@leafer/interface'
2
+ import { MatrixHelper, MathHelper, Bounds, AlignHelper } from '@leafer/core'
3
3
 
4
4
  import { IImagePaint, ILeafPaint, ILeafPaintPatternData } from '@leafer-ui/interface'
5
5
 
@@ -9,16 +9,19 @@ import { clipMode, fillOrFitMode, repeatMode } from './mode'
9
9
  const { get, translate } = MatrixHelper
10
10
  const tempBox = new Bounds()
11
11
  const tempPoint = {} as IPointData
12
+ const tempScaleData = {} as IScaleData
12
13
 
13
14
  export function createData(leafPaint: ILeafPaint, image: ILeaferImage, paint: IImagePaint, box: IBoundsData): void {
14
- const { blendMode } = paint
15
+ const { blendMode, sync } = paint
15
16
  if (blendMode) leafPaint.blendMode = blendMode
17
+ if (sync) leafPaint.sync = sync
16
18
  leafPaint.data = getPatternData(paint, box, image)
17
19
  }
18
20
 
19
21
  export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILeaferImage): ILeafPaintPatternData {
20
22
  let { width, height } = image
21
23
  if (paint.padding) box = tempBox.set(box).shrink(paint.padding)
24
+ if (paint.mode === 'strench' as string) paint.mode = 'stretch' // 兼容代码,后续可移除
22
25
 
23
26
  const { opacity, mode, align, offset, scale, size, rotation, repeat } = paint
24
27
  const sameBox = box.width === width && box.height === height
@@ -35,12 +38,10 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
35
38
  scaleX = scaleY = mode === 'fit' ? Math.min(sw, sh) : Math.max(sw, sh)
36
39
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2
37
40
  }
38
- } else if (size) {
39
- scaleX = (typeof size === 'number' ? size : size.width) / width
40
- scaleY = (typeof size === 'number' ? size : size.height) / height
41
- } else if (scale) {
42
- scaleX = typeof scale === 'number' ? scale : scale.x
43
- scaleY = typeof scale === 'number' ? scale : scale.y
41
+ } else if (scale || size) {
42
+ MathHelper.getScaleData(scale, size, image, tempScaleData)
43
+ scaleX = tempScaleData.scaleX
44
+ scaleY = tempScaleData.scaleY
44
45
  }
45
46
 
46
47
  if (align) {
@@ -53,7 +54,7 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
53
54
  if (offset) x += offset.x, y += offset.y
54
55
 
55
56
  switch (mode) {
56
- case 'strench':
57
+ case 'stretch':
57
58
  if (!sameBox) width = box.width, height = box.height
58
59
  break
59
60
  case 'normal':
@@ -77,7 +78,7 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
77
78
  }
78
79
  }
79
80
 
80
- if (scaleX && mode !== 'strench') {
81
+ if (scaleX && mode !== 'stretch') {
81
82
  data.scaleX = scaleX
82
83
  data.scaleY = scaleY
83
84
  }
package/src/pattern.ts CHANGED
@@ -10,7 +10,7 @@ export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): b
10
10
 
11
11
  let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld
12
12
 
13
- const id = scaleX + '-' + scaleY
13
+ const id = scaleX + '-' + scaleY + '-' + pixelRatio
14
14
 
15
15
  if (paint.patternId !== id && !ui.destroyed) {
16
16