@leafer-ui/image 2.1.0 → 2.1.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 +5 -5
- package/src/check.ts +15 -9
- package/src/data.ts +1 -0
- package/src/image.ts +5 -3
- package/src/pattern.ts +6 -2
- package/src/recycle.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/image",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.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.1.
|
|
26
|
-
"@leafer-ui/draw": "2.1.
|
|
25
|
+
"@leafer/core": "2.1.2",
|
|
26
|
+
"@leafer-ui/draw": "2.1.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "2.1.
|
|
30
|
-
"@leafer-ui/interface": "2.1.
|
|
29
|
+
"@leafer/interface": "2.1.2",
|
|
30
|
+
"@leafer-ui/interface": "2.1.2"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/check.ts
CHANGED
|
@@ -7,10 +7,12 @@ import { PaintImage } from "@leafer-ui/draw"
|
|
|
7
7
|
|
|
8
8
|
export function checkImage(paint: ILeafPaint, drawImage: boolean, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): boolean {
|
|
9
9
|
const { scaleX, scaleY } = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = paint.film ? paint.nowIndex : scaleX + '-' + scaleY
|
|
10
|
-
const { image, data, originPaint } = paint, { exporting, snapshot } = renderOptions
|
|
10
|
+
const { image, brush, data, originPaint } = paint, { exporting, snapshot } = renderOptions
|
|
11
11
|
|
|
12
12
|
if (!data || (paint.patternId === id && !exporting) || snapshot) {
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
if (!(brush && paint.style)) return false // 生成图案中
|
|
15
|
+
|
|
14
16
|
} else {
|
|
15
17
|
|
|
16
18
|
if (drawImage) {
|
|
@@ -26,19 +28,22 @@ export function checkImage(paint: ILeafPaint, drawImage: boolean, ui: IUI, canva
|
|
|
26
28
|
canvas.fillStyle = paint.style || '#000'
|
|
27
29
|
canvas.fill()
|
|
28
30
|
}
|
|
29
|
-
PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions) // 直接绘制图像,不生成图案
|
|
30
|
-
return true
|
|
31
31
|
} else {
|
|
32
32
|
if (!paint.style || (originPaint as IImagePaint).sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions)
|
|
33
33
|
else PaintImage.createPatternTask(paint, ui, canvas, renderOptions)
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
if (!(brush && paint.style)) return false
|
|
36
|
+
|
|
35
37
|
}
|
|
36
38
|
}
|
|
39
|
+
|
|
40
|
+
PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions) // 直接绘制图像,不生成图案
|
|
41
|
+
return true
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
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
|
|
45
|
+
const { data, image, brush, complex } = paint
|
|
46
|
+
let { width, height } = image, view = brush || image
|
|
42
47
|
|
|
43
48
|
if (complex) {
|
|
44
49
|
|
|
@@ -48,20 +53,21 @@ export function drawImage(paint: ILeafPaint, imageScaleX: number, imageScaleY: n
|
|
|
48
53
|
blendMode && (canvas.blendMode = blendMode)
|
|
49
54
|
opacity && (canvas.opacity *= opacity)
|
|
50
55
|
transform && canvas.transform(transform)
|
|
51
|
-
|
|
56
|
+
view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY) // svg need size
|
|
52
57
|
canvas.restore()
|
|
53
58
|
|
|
54
59
|
} else {
|
|
55
60
|
|
|
56
61
|
// 简单矩形
|
|
57
62
|
if (data.scaleX) width *= data.scaleX, height *= data.scaleY
|
|
58
|
-
|
|
63
|
+
view.render(canvas, 0, 0, width, height, ui, paint, imageScaleX, imageScaleY)
|
|
59
64
|
|
|
60
65
|
}
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
export function getImageRenderScaleData(paint: ILeafPaint, ui: IUI, canvas?: ILeaferCanvas, _renderOptions?: IRenderOptions): IScaleData {
|
|
64
69
|
const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), { data } = paint
|
|
70
|
+
if (paint.brush) PaintImage.addBrushScale(scaleData, paint, ui)
|
|
65
71
|
if (canvas) {
|
|
66
72
|
const { pixelRatio } = canvas
|
|
67
73
|
scaleData.scaleX *= pixelRatio
|
package/src/data.ts
CHANGED
|
@@ -66,6 +66,7 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
|
|
|
66
66
|
}
|
|
67
67
|
break
|
|
68
68
|
case 'repeat':
|
|
69
|
+
case 'brush':
|
|
69
70
|
if (!sameBox || scaleX || rotation || skew) PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform)
|
|
70
71
|
if (!repeat) data.repeat = 'repeat'
|
|
71
72
|
const count = isObject(repeat)
|
package/src/image.ts
CHANGED
|
@@ -103,12 +103,14 @@ function checkSizeAndCreateData(ui: IUI, attrName: string, paint: IImagePaint, i
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
if (paint.mode === 'brush') PaintImage.brush(leafPaint)
|
|
107
|
+
|
|
106
108
|
if (!leafPaint.data) {
|
|
107
109
|
PaintImage.createData(leafPaint, image, paint, boxBounds)
|
|
108
110
|
|
|
109
|
-
const { transform } = leafPaint.data, { opacity
|
|
110
|
-
const clip = (transform && !transform.onlyScale) || data.path || data.cornerRadius
|
|
111
|
-
if (clip || (opacity && opacity < 1) || blendMode) leafPaint.complex = clip ? 2 : true
|
|
111
|
+
const { transform } = leafPaint.data, { opacity } = paint
|
|
112
|
+
const clip = ((transform && !transform.onlyScale) || data.path || data.cornerRadius) && !leafPaint.brush
|
|
113
|
+
if (clip || (opacity && opacity < 1) || paint.blendMode) leafPaint.complex = clip ? 2 : true
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
if (paint.filter) PaintImage.applyFilter(leafPaint, image, paint.filter, ui)
|
package/src/pattern.ts
CHANGED
|
@@ -26,7 +26,7 @@ export function createPattern(paint: ILeafPaint, ui: IUI, canvas: ILeaferCanvas,
|
|
|
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, { opacity } = paint.originPaint as IImagePaint, { transform, gap } = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY)
|
|
29
|
+
const { image, brush, data } = paint, { opacity } = 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
|
|
@@ -38,6 +38,10 @@ export function createPattern(paint: ILeafPaint, ui: IUI, canvas: ILeaferCanvas,
|
|
|
38
38
|
if (gap) {
|
|
39
39
|
xGap = gap.x * scaleX / abs(data.scaleX || 1)
|
|
40
40
|
yGap = gap.y * scaleY / abs(data.scaleY || 1)
|
|
41
|
+
if (brush) {
|
|
42
|
+
const brushScale = PaintImage.getBrushScale(paint, ui)
|
|
43
|
+
xGap /= brushScale, yGap /= brushScale
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
if (transform || scaleX !== 1 || scaleY !== 1) {
|
|
@@ -50,7 +54,7 @@ export function createPattern(paint: ILeafPaint, ui: IUI, canvas: ILeaferCanvas,
|
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
const imageCanvas = image.getCanvas(width, height, opacity, undefined, xGap, yGap, ui.leafer && ui.leafer.config.smooth, data.interlace)
|
|
53
|
-
const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint)
|
|
57
|
+
const pattern = brush ? imageCanvas : image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint)
|
|
54
58
|
|
|
55
59
|
paint.style = pattern
|
|
56
60
|
paint.patternId = id
|
package/src/recycle.ts
CHANGED
|
@@ -11,6 +11,7 @@ export function recycleImage(attrName: IPaintAttr, data: IUIData): IBooleanMap {
|
|
|
11
11
|
if (isArray(paints)) {
|
|
12
12
|
|
|
13
13
|
let paint: ILeafPaint, image: ILeaferImage, recycleMap: IBooleanMap, input: IImagePaint[], url: string
|
|
14
|
+
const ui = data.__leaf as IUI
|
|
14
15
|
|
|
15
16
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
16
17
|
|
|
@@ -22,7 +23,8 @@ export function recycleImage(attrName: IPaintAttr, data: IUIData): IBooleanMap {
|
|
|
22
23
|
if (!recycleMap) recycleMap = {}
|
|
23
24
|
recycleMap[url] = true
|
|
24
25
|
ImageManager.recyclePaint(paint)
|
|
25
|
-
if (
|
|
26
|
+
if (paint.brush) PaintImage.recycleBrush(paint, ui)
|
|
27
|
+
if (data.__willDestroy && image.parent) PaintImage.recycleFilter(image, ui)
|
|
26
28
|
|
|
27
29
|
// stop load
|
|
28
30
|
if (image.loading) {
|