@leafer-ui/image 1.6.2 → 1.6.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 +5 -5
- package/src/data.ts +25 -26
- package/src/image.ts +13 -7
- package/src/mode.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/image",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.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.6.
|
|
26
|
-
"@leafer-ui/draw": "1.6.
|
|
25
|
+
"@leafer/core": "1.6.3",
|
|
26
|
+
"@leafer-ui/draw": "1.6.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.6.
|
|
30
|
-
"@leafer-ui/interface": "1.6.
|
|
29
|
+
"@leafer/interface": "1.6.3",
|
|
30
|
+
"@leafer-ui/interface": "1.6.3"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/data.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IBoundsData, ILeaferImage,
|
|
2
|
-
import { MatrixHelper, MathHelper, Bounds, AlignHelper } from '@leafer/core'
|
|
1
|
+
import { IBoundsData, ILeaferImage, IScaleData } from '@leafer/interface'
|
|
2
|
+
import { MatrixHelper, MathHelper, Bounds, AlignHelper, BoundsHelper, PointHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IImagePaint, ILeafPaint, ILeafPaintPatternData } from '@leafer-ui/interface'
|
|
5
5
|
|
|
@@ -8,51 +8,50 @@ import { clipMode, fillOrFitMode, repeatMode } from './mode'
|
|
|
8
8
|
|
|
9
9
|
const { get, translate } = MatrixHelper
|
|
10
10
|
const tempBox = new Bounds()
|
|
11
|
-
const tempPoint = {} as IPointData
|
|
12
11
|
const tempScaleData = {} as IScaleData
|
|
12
|
+
const tempImage = {} as IBoundsData
|
|
13
13
|
|
|
14
14
|
export function createData(leafPaint: ILeafPaint, image: ILeaferImage, paint: IImagePaint, box: IBoundsData): void {
|
|
15
|
-
const {
|
|
16
|
-
if (blendMode) leafPaint.blendMode = blendMode
|
|
15
|
+
const { changeful, sync } = paint
|
|
17
16
|
if (changeful) leafPaint.changeful = changeful
|
|
18
17
|
if (sync) leafPaint.sync = sync
|
|
19
18
|
leafPaint.data = getPatternData(paint, box, image)
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILeaferImage): ILeafPaintPatternData {
|
|
23
|
-
let { width, height } = image
|
|
24
22
|
if (paint.padding) box = tempBox.set(box).shrink(paint.padding)
|
|
25
23
|
if (paint.mode === 'strench' as string) paint.mode = 'stretch' // 兼容代码,后续可移除
|
|
26
24
|
|
|
25
|
+
let { width, height } = image
|
|
27
26
|
const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint
|
|
28
27
|
const sameBox = box.width === width && box.height === height
|
|
29
28
|
|
|
30
29
|
const data: ILeafPaintPatternData = { mode }
|
|
31
30
|
const swapSize = align !== 'center' && (rotation || 0) % 180 === 90
|
|
32
|
-
|
|
31
|
+
BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height)
|
|
33
32
|
|
|
34
|
-
let
|
|
33
|
+
let scaleX: number, scaleY: number
|
|
35
34
|
|
|
36
|
-
if (!mode || mode === 'cover' || mode === 'fit') {
|
|
35
|
+
if (!mode || mode === 'cover' || mode === 'fit') { // mode 默认值为 cover
|
|
37
36
|
if (!sameBox || rotation) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !== 'fit')
|
|
38
|
+
BoundsHelper.put(box, image, align, scaleX, false, tempImage)
|
|
39
|
+
BoundsHelper.scale(tempImage, scaleX, scaleY, true)
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
if (scale || size) {
|
|
43
|
+
MathHelper.getScaleData(scale, size, image, tempScaleData)
|
|
44
|
+
scaleX = tempScaleData.scaleX
|
|
45
|
+
scaleY = tempScaleData.scaleY
|
|
41
46
|
}
|
|
42
|
-
} else if (scale || size) {
|
|
43
|
-
MathHelper.getScaleData(scale, size, image, tempScaleData)
|
|
44
|
-
scaleX = tempScaleData.scaleX
|
|
45
|
-
scaleY = tempScaleData.scaleY
|
|
46
|
-
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
x += tempPoint.x, y += tempPoint.y
|
|
48
|
+
if (align) {
|
|
49
|
+
if (scaleX) BoundsHelper.scale(tempImage, scaleX, scaleY, true)
|
|
50
|
+
AlignHelper.toPoint(align, tempImage, box, tempImage, true, true)
|
|
51
|
+
}
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
if (offset)
|
|
54
|
+
if (offset) PointHelper.move(tempImage, offset)
|
|
56
55
|
|
|
57
56
|
switch (mode) {
|
|
58
57
|
case 'stretch':
|
|
@@ -60,16 +59,16 @@ export function getPatternData(paint: IImagePaint, box: IBoundsData, image: ILea
|
|
|
60
59
|
break
|
|
61
60
|
case 'normal':
|
|
62
61
|
case 'clip':
|
|
63
|
-
if (x || y || scaleX || rotation) clipMode(data, box, x, y, scaleX, scaleY, rotation)
|
|
62
|
+
if (tempImage.x || tempImage.y || scaleX || rotation) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation)
|
|
64
63
|
break
|
|
65
64
|
case 'repeat':
|
|
66
|
-
if (!sameBox || scaleX || rotation) repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align)
|
|
65
|
+
if (!sameBox || scaleX || rotation) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, align)
|
|
67
66
|
if (!repeat) data.repeat = 'repeat'
|
|
68
67
|
break
|
|
69
68
|
case 'fit':
|
|
70
69
|
case 'cover':
|
|
71
70
|
default:
|
|
72
|
-
if (scaleX) fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation)
|
|
71
|
+
if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation)
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
if (!data.transform) {
|
package/src/image.ts
CHANGED
|
@@ -23,6 +23,7 @@ export function image(ui: IUI, attrName: string, paint: IImagePaint, boxBounds:
|
|
|
23
23
|
leafPaint = cache.leafPaint
|
|
24
24
|
} else {
|
|
25
25
|
leafPaint = { type: paint.type, image }
|
|
26
|
+
if (image.hasAlphaPixel) leafPaint.isTransparent = true
|
|
26
27
|
|
|
27
28
|
cache = image.use > 1 ? { leafPaint, paint, boxBounds: box.set(boxBounds) } : null // 只保留最后一个cache
|
|
28
29
|
}
|
|
@@ -54,7 +55,7 @@ export function image(ui: IUI, attrName: string, paint: IImagePaint, boxBounds:
|
|
|
54
55
|
ignoreRender(ui, false)
|
|
55
56
|
if (!ui.destroyed) {
|
|
56
57
|
if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
|
|
57
|
-
if (image.
|
|
58
|
+
if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true
|
|
58
59
|
ui.forceUpdate('surface')
|
|
59
60
|
}
|
|
60
61
|
onLoadSuccess(ui, event)
|
|
@@ -68,12 +69,17 @@ export function image(ui: IUI, attrName: string, paint: IImagePaint, boxBounds:
|
|
|
68
69
|
}
|
|
69
70
|
)
|
|
70
71
|
|
|
71
|
-
if (ui.placeholderColor)
|
|
72
|
-
if (!
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
if (ui.placeholderColor) {
|
|
73
|
+
if (!ui.placeholderDelay) image.isPlacehold = true
|
|
74
|
+
else setTimeout(() => {
|
|
75
|
+
if (!image.ready) {
|
|
76
|
+
image.isPlacehold = true
|
|
77
|
+
ui.forceUpdate('surface')
|
|
78
|
+
}
|
|
79
|
+
}, ui.placeholderDelay)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
77
83
|
|
|
78
84
|
}
|
|
79
85
|
|
package/src/mode.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBoundsData, IPointData, IMatrixData, IAlign
|
|
1
|
+
import { IBoundsData, IPointData, IMatrixData, IAlign } from '@leafer/interface'
|
|
2
2
|
import { MatrixHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { ILeafPaintPatternData } from '@leafer-ui/interface'
|