@leafer-ui/paint 1.0.0-beta.5 → 1.0.0-beta.7
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/paint/image.ts +53 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/paint",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.7",
|
|
4
4
|
"description": "@leafer-ui/paint",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/core": "1.0.0-beta.
|
|
23
|
-
"@leafer-ui/color": "1.0.0-beta.
|
|
22
|
+
"@leafer/core": "1.0.0-beta.7",
|
|
23
|
+
"@leafer-ui/color": "1.0.0-beta.7"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-beta.
|
|
27
|
-
"@leafer-ui/interface": "1.0.0-beta.
|
|
26
|
+
"@leafer/interface": "1.0.0-beta.7",
|
|
27
|
+
"@leafer-ui/interface": "1.0.0-beta.7"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/paint/image.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBoundsData } from '@leafer/interface'
|
|
1
|
+
import { IBoundsData, ISizeData } from '@leafer/interface'
|
|
2
2
|
import { Platform, MatrixHelper, ImageEvent } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IUI, IImagePaint, ILeafPaint, IMatrixData, IImagePaintMode, IPointData } from '@leafer-ui/interface'
|
|
@@ -7,53 +7,54 @@ import { IUI, IImagePaint, ILeafPaint, IMatrixData, IImagePaintMode, IPointData
|
|
|
7
7
|
const { get, rotateOfOuter, translate, scaleOfOuter, scale: scaleHelper, rotate } = MatrixHelper
|
|
8
8
|
|
|
9
9
|
export function image(ui: IUI, attrName: string, paint: IImagePaint, box: IBoundsData): ILeafPaint {
|
|
10
|
-
|
|
11
|
-
let leaferPaint: ILeafPaint = {
|
|
12
|
-
|
|
13
|
-
blendMode,
|
|
14
|
-
style: 'rgba(255,255,255,0)'
|
|
15
|
-
}
|
|
10
|
+
const { type, blendMode } = paint
|
|
11
|
+
let leaferPaint: ILeafPaint = { type, style: 'rgba(255,255,255,0)' }
|
|
12
|
+
if (blendMode) leaferPaint.blendMode = blendMode
|
|
16
13
|
|
|
17
14
|
const { imageManager } = ui.leafer
|
|
18
15
|
const image = imageManager.get(paint)
|
|
19
16
|
|
|
20
17
|
if (image.ready) {
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
if (!autoSize(ui, image)) {
|
|
20
|
+
|
|
21
|
+
let transform: IMatrixData
|
|
22
|
+
let { opacity, mode, offset, scale, rotation } = paint
|
|
23
|
+
let { width, height } = image
|
|
24
|
+
const sameBox = box.width === width && box.height === height
|
|
25
|
+
|
|
26
|
+
switch (mode) {
|
|
27
|
+
case 'strench':
|
|
28
|
+
if (!sameBox) width = box.width, height = box.height
|
|
29
|
+
if (box.x || box.y) {
|
|
30
|
+
transform = get()
|
|
31
|
+
translate(transform, box.x, box.y)
|
|
32
|
+
}
|
|
33
|
+
break
|
|
34
|
+
case 'clip':
|
|
35
|
+
if (offset || scale || rotation) transform = getClipTransform(box, offset, scale, rotation)
|
|
36
|
+
break
|
|
37
|
+
case 'repeat':
|
|
38
|
+
if (!sameBox || scale || rotation) transform = getRepeatTransform(box, width, height, scale as number, rotation)
|
|
39
|
+
break
|
|
40
|
+
case 'fit':
|
|
41
|
+
case 'cover':
|
|
42
|
+
default:
|
|
43
|
+
if (!sameBox || rotation) transform = getFillOrFitTransform(mode, box, width, height, rotation)
|
|
44
|
+
}
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
leaferPaint.style = createPattern(image.getCanvas(width, height, opacity), transform, mode === 'repeat')
|
|
47
|
+
|
|
48
|
+
}
|
|
48
49
|
|
|
49
50
|
} else {
|
|
50
51
|
|
|
51
52
|
imageManager.load(image,
|
|
52
53
|
() => {
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
if (ui.leafer) {
|
|
55
|
+
if (!autoSize(ui, image)) ui.forceUpdate('width')
|
|
56
|
+
ui.emitEvent(new ImageEvent(ImageEvent.LOADED, ui, image, attrName, paint))
|
|
57
|
+
}
|
|
57
58
|
},
|
|
58
59
|
(error) => {
|
|
59
60
|
ui.emitEvent(new ImageEvent(ImageEvent.ERROR, ui, image, attrName, paint, error))
|
|
@@ -65,6 +66,22 @@ export function image(ui: IUI, attrName: string, paint: IImagePaint, box: IBound
|
|
|
65
66
|
return leaferPaint
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
function autoSize(ui: IUI, image: ISizeData): boolean {
|
|
70
|
+
let auto: boolean
|
|
71
|
+
const { __: data } = ui
|
|
72
|
+
if (data) {
|
|
73
|
+
if (!data.__getInput('width')) {
|
|
74
|
+
auto = true
|
|
75
|
+
ui.width = image.width
|
|
76
|
+
}
|
|
77
|
+
if (!data.__getInput('height')) {
|
|
78
|
+
auto = true
|
|
79
|
+
ui.height = image.height
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return auto
|
|
83
|
+
}
|
|
84
|
+
|
|
68
85
|
function getFillOrFitTransform(mode: IImagePaintMode, box: IBoundsData, width: number, height: number, rotation: number): IMatrixData {
|
|
69
86
|
const transform: IMatrixData = get()
|
|
70
87
|
const swap = rotation && rotation !== 180
|