@leafer-ui/image 1.5.3 → 1.6.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 +5 -5
- package/src/check.ts +33 -28
- package/src/data.ts +2 -1
- package/src/recycle.ts +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/image",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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.
|
|
26
|
-
"@leafer-ui/draw": "1.
|
|
25
|
+
"@leafer/core": "1.6.0",
|
|
26
|
+
"@leafer-ui/draw": "1.6.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.
|
|
30
|
-
"@leafer-ui/interface": "1.
|
|
29
|
+
"@leafer/interface": "1.6.0",
|
|
30
|
+
"@leafer-ui/interface": "1.6.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/check.ts
CHANGED
|
@@ -1,47 +1,41 @@
|
|
|
1
|
-
|
|
2
1
|
import { ILeaferCanvas } from '@leafer/interface'
|
|
3
|
-
import { ImageManager, Platform } from '@leafer/core'
|
|
2
|
+
import { ImageManager, Platform, ResizeEvent } from '@leafer/core'
|
|
4
3
|
|
|
5
|
-
import { IUI, ILeafPaint } from '@leafer-ui/interface'
|
|
4
|
+
import { IUI, ILeafPaint, ILeafPaintPatternData } from '@leafer-ui/interface'
|
|
6
5
|
import { Export } from '@leafer-ui/draw'
|
|
7
6
|
|
|
8
7
|
import { createPattern } from './pattern'
|
|
9
8
|
|
|
9
|
+
|
|
10
10
|
const { abs } = Math
|
|
11
11
|
|
|
12
|
-
export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint,
|
|
12
|
+
export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, allowDraw?: boolean): boolean {
|
|
13
13
|
const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld
|
|
14
|
-
const { pixelRatio } = canvas
|
|
14
|
+
const { pixelRatio } = canvas, { data } = paint
|
|
15
15
|
|
|
16
|
-
if (!
|
|
17
|
-
return false
|
|
16
|
+
if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
|
|
17
|
+
return false // 生成图案中
|
|
18
18
|
} else {
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!data.repeat) {
|
|
24
|
-
let { width, height } = data
|
|
25
|
-
width *= abs(scaleX) * pixelRatio
|
|
26
|
-
height *= abs(scaleY) * pixelRatio
|
|
27
|
-
if (data.scaleX) {
|
|
28
|
-
width *= data.scaleX
|
|
29
|
-
height *= data.scaleY
|
|
30
|
-
}
|
|
31
|
-
allowPaint = (width * height > Platform.image.maxCacheSize) || Export.running
|
|
20
|
+
if (allowDraw) {
|
|
21
|
+
if (data.repeat) {
|
|
22
|
+
allowDraw = false
|
|
32
23
|
} else {
|
|
33
|
-
|
|
24
|
+
if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
|
|
25
|
+
let { width, height } = data
|
|
26
|
+
width *= abs(scaleX) * pixelRatio
|
|
27
|
+
height *= abs(scaleY) * pixelRatio
|
|
28
|
+
if (data.scaleX) {
|
|
29
|
+
width *= data.scaleX
|
|
30
|
+
height *= data.scaleY
|
|
31
|
+
}
|
|
32
|
+
allowDraw = (width * height > Platform.image.maxCacheSize)
|
|
33
|
+
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
if (
|
|
38
|
-
canvas
|
|
39
|
-
ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip()
|
|
40
|
-
if (paint.blendMode) canvas.blendMode = paint.blendMode
|
|
41
|
-
if (data.opacity) canvas.opacity *= data.opacity
|
|
42
|
-
if (data.transform) canvas.transform(data.transform)
|
|
43
|
-
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height)
|
|
44
|
-
canvas.restore()
|
|
37
|
+
if (allowDraw) {
|
|
38
|
+
drawImage(ui, canvas, paint, data) // 直接绘制图像,不生成图案
|
|
45
39
|
return true
|
|
46
40
|
} else {
|
|
47
41
|
if (!paint.style || paint.sync || Export.running) {
|
|
@@ -58,4 +52,15 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
|
|
|
58
52
|
return false
|
|
59
53
|
}
|
|
60
54
|
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
function drawImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, data: ILeafPaintPatternData): void { // 后续可优化
|
|
59
|
+
canvas.save()
|
|
60
|
+
ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip()
|
|
61
|
+
if (paint.blendMode) canvas.blendMode = paint.blendMode
|
|
62
|
+
if (data.opacity) canvas.opacity *= data.opacity
|
|
63
|
+
if (data.transform) canvas.transform(data.transform)
|
|
64
|
+
canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height)
|
|
65
|
+
canvas.restore()
|
|
61
66
|
}
|
package/src/data.ts
CHANGED
|
@@ -12,8 +12,9 @@ const tempPoint = {} as IPointData
|
|
|
12
12
|
const tempScaleData = {} as IScaleData
|
|
13
13
|
|
|
14
14
|
export function createData(leafPaint: ILeafPaint, image: ILeaferImage, paint: IImagePaint, box: IBoundsData): void {
|
|
15
|
-
const { blendMode, sync } = paint
|
|
15
|
+
const { blendMode, changeful, sync } = paint
|
|
16
16
|
if (blendMode) leafPaint.blendMode = blendMode
|
|
17
|
+
if (changeful) leafPaint.changeful = changeful
|
|
17
18
|
if (sync) leafPaint.sync = sync
|
|
18
19
|
leafPaint.data = getPatternData(paint, box, image)
|
|
19
20
|
}
|
package/src/recycle.ts
CHANGED
|
@@ -5,15 +5,16 @@ import { IImagePaint, ILeafPaint, IPaintAttr, IUIData } from '@leafer-ui/interfa
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export function recycleImage(attrName: IPaintAttr, data: IUIData): IBooleanMap {
|
|
8
|
-
const paints = (data as IObject)['_' + attrName]
|
|
8
|
+
const paints: ILeafPaint[] = (data as IObject)['_' + attrName]
|
|
9
9
|
|
|
10
10
|
if (paints instanceof Array) {
|
|
11
11
|
|
|
12
|
-
let image: ILeaferImage, recycleMap: IBooleanMap, input: IImagePaint[], url: string
|
|
12
|
+
let paint: ILeafPaint, image: ILeaferImage, recycleMap: IBooleanMap, input: IImagePaint[], url: string
|
|
13
13
|
|
|
14
14
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
paint = paints[i]
|
|
17
|
+
image = paint.image
|
|
17
18
|
url = image && image.url
|
|
18
19
|
|
|
19
20
|
if (url) {
|
|
@@ -28,7 +29,7 @@ export function recycleImage(attrName: IPaintAttr, data: IUIData): IBooleanMap {
|
|
|
28
29
|
if (!(input instanceof Array)) input = [input]
|
|
29
30
|
}
|
|
30
31
|
image.unload(paints[i].loadId, !input.some((item: IImagePaint) => item.url === url))
|
|
31
|
-
}
|
|
32
|
+
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
}
|