@leafer-ui/paint 1.8.0 → 1.9.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/Compute.ts +8 -5
- package/src/Fill.ts +1 -1
- package/src/Shape.ts +12 -11
- package/src/Stroke.ts +2 -2
- package/src/StrokeText.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/paint",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "@leafer-ui/paint",
|
|
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.9.0",
|
|
26
|
+
"@leafer-ui/draw": "1.9.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.
|
|
30
|
-
"@leafer-ui/interface": "1.
|
|
29
|
+
"@leafer/interface": "1.9.0",
|
|
30
|
+
"@leafer-ui/interface": "1.9.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/Compute.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataHelper } from '@leafer/core'
|
|
1
|
+
import { DataHelper, isArray, isObject, isString, isUndefined } from '@leafer/core'
|
|
2
2
|
|
|
3
3
|
import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap, IObject, IPaintAttr, IStrokeComputedStyle } from '@leafer-ui/interface'
|
|
4
4
|
import { ColorConvert, PaintImage, PaintGradient } from '@leafer-ui/draw'
|
|
@@ -11,7 +11,7 @@ export function compute(attrName: IPaintAttr, ui: IUI): void {
|
|
|
11
11
|
const data = ui.__, leafPaints: ILeafPaint[] = []
|
|
12
12
|
|
|
13
13
|
let paints: IPaint[] = data.__input[attrName], isAlphaPixel: boolean, isTransparent: boolean
|
|
14
|
-
if (!(paints
|
|
14
|
+
if (!isArray(paints)) paints = [paints]
|
|
15
15
|
|
|
16
16
|
recycleMap = PaintImage.recycleImage(attrName, data)
|
|
17
17
|
|
|
@@ -50,7 +50,7 @@ export function compute(attrName: IPaintAttr, ui: IUI): void {
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
function getLeafPaint(attrName: string, paint: IPaint, ui: IUI): ILeafPaint {
|
|
53
|
-
if (
|
|
53
|
+
if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined
|
|
54
54
|
|
|
55
55
|
let data: ILeafPaint
|
|
56
56
|
const { boxBounds } = ui.__layout
|
|
@@ -73,15 +73,18 @@ function getLeafPaint(attrName: string, paint: IPaint, ui: IUI): ILeafPaint {
|
|
|
73
73
|
data = { type, style: ColorConvert.string(color, opacity) }
|
|
74
74
|
break
|
|
75
75
|
default:
|
|
76
|
-
if ((paint as IRGB).r
|
|
76
|
+
if (!isUndefined((paint as IRGB).r)) data = { type: 'solid', style: ColorConvert.string(paint) }
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
if (data) {
|
|
80
|
-
|
|
80
|
+
// 描边样式
|
|
81
|
+
if (isString(data.style) && hasTransparent(data.style)) data.isTransparent = true
|
|
81
82
|
if (paint.style) {
|
|
82
83
|
if (paint.style.strokeWidth === 0) return undefined
|
|
83
84
|
data.strokeStyle = paint.style as IStrokeComputedStyle
|
|
84
85
|
}
|
|
86
|
+
|
|
87
|
+
if (paint.editing) data.editing = paint.editing
|
|
85
88
|
if (paint.blendMode) data.blendMode = paint.blendMode
|
|
86
89
|
}
|
|
87
90
|
|
package/src/Fill.ts
CHANGED
|
@@ -36,7 +36,7 @@ export function fills(fills: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void
|
|
|
36
36
|
if (item.transform) canvas.transform(item.transform)
|
|
37
37
|
if (item.scaleFixed) {
|
|
38
38
|
const { scaleX, scaleY } = ui.getRenderScaleData(true)
|
|
39
|
-
canvas.scale(1 / scaleX, 1 / scaleY)
|
|
39
|
+
if (item.scaleFixed === true || (item.scaleFixed === 'zoom-in' && scaleX > 1 && scaleY > 1)) canvas.scale(1 / scaleX, 1 / scaleY)
|
|
40
40
|
}
|
|
41
41
|
if (item.blendMode) canvas.blendMode = item.blendMode
|
|
42
42
|
fillPathOrText(ui, canvas)
|
package/src/Shape.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBoundsData, ILeaferCanvas, IRenderOptions, IMatrix } from '@leafer/interface'
|
|
2
|
-
import { BoundsHelper } from '@leafer/core'
|
|
2
|
+
import { BoundsHelper, Matrix } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IUI, ICachedShape } from '@leafer-ui/interface'
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ export function shape(ui: IUI, current: ILeaferCanvas, options: IRenderOptions):
|
|
|
10
10
|
const canvas = current.getSameCanvas()
|
|
11
11
|
const nowWorld = ui.__nowWorld
|
|
12
12
|
|
|
13
|
-
let bounds: IBoundsData, fitMatrix: IMatrix, shapeBounds: IBoundsData, worldCanvas: ILeaferCanvas
|
|
13
|
+
let bounds: IBoundsData, matrix: IMatrix, fitMatrix: IMatrix, shapeBounds: IBoundsData, worldCanvas: ILeaferCanvas
|
|
14
14
|
|
|
15
15
|
let { scaleX, scaleY } = nowWorld
|
|
16
16
|
if (scaleX < 0) scaleX = -scaleX
|
|
@@ -39,21 +39,22 @@ export function shape(ui: IUI, current: ILeaferCanvas, options: IRenderOptions):
|
|
|
39
39
|
shapeBounds = getOuterOf(nowWorld, fitMatrix)
|
|
40
40
|
bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f)
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
fitMatrix
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
options = { ...options, matrix: fitMatrix.withScale(fitScaleX, fitScaleY) }
|
|
42
|
+
const userMatrix = options.matrix
|
|
43
|
+
if (userMatrix) {
|
|
44
|
+
matrix = new Matrix(fitMatrix) // 仅用于渲染
|
|
45
|
+
matrix.multiply(userMatrix)
|
|
46
|
+
fitScaleX *= userMatrix.scaleX
|
|
47
|
+
fitScaleY *= userMatrix.scaleY
|
|
48
|
+
} else matrix = fitMatrix
|
|
50
49
|
|
|
50
|
+
matrix.withScale(fitScaleX, fitScaleY)
|
|
51
|
+
options = { ...options, matrix }
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
ui.__renderShape(canvas, options)
|
|
54
55
|
|
|
55
56
|
return {
|
|
56
|
-
canvas, matrix
|
|
57
|
+
canvas, matrix, fitMatrix, bounds,
|
|
57
58
|
worldCanvas, shapeBounds, scaleX, scaleY
|
|
58
59
|
}
|
|
59
60
|
}
|
package/src/Stroke.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ILeaferCanvas } from '@leafer/interface'
|
|
2
|
-
import { LeafHelper } from "@leafer/core"
|
|
2
|
+
import { LeafHelper, isObject } from "@leafer/core"
|
|
3
3
|
|
|
4
4
|
import { IUI, ILeafPaint } from '@leafer-ui/interface'
|
|
5
5
|
import { Paint } from '@leafer-ui/draw'
|
|
@@ -40,7 +40,7 @@ export function strokes(strokes: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas):
|
|
|
40
40
|
|
|
41
41
|
function drawCenter(stroke: string | ILeafPaint[], strokeWidthScale: number, ui: IUI, canvas: ILeaferCanvas) {
|
|
42
42
|
const data = ui.__
|
|
43
|
-
if (
|
|
43
|
+
if (isObject(stroke)) {
|
|
44
44
|
drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas)
|
|
45
45
|
} else {
|
|
46
46
|
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data)
|
package/src/StrokeText.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ILeaferCanvas } from '@leafer/interface'
|
|
2
|
-
import { LeafHelper } from "@leafer/core"
|
|
2
|
+
import { LeafHelper, isObject } from "@leafer/core"
|
|
3
3
|
|
|
4
4
|
import { IUI, ITextRowData, ILeafPaint, IStrokeAlign, ILeafStrokePaint } from '@leafer-ui/interface'
|
|
5
5
|
import { PaintImage } from "@leafer-ui/draw"
|
|
@@ -23,7 +23,7 @@ export function strokeText(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaf
|
|
|
23
23
|
|
|
24
24
|
function drawCenter(stroke: string | ILeafPaint[], strokeWidthScale: number, ui: IUI, canvas: ILeaferCanvas): void {
|
|
25
25
|
const data = ui.__
|
|
26
|
-
if (
|
|
26
|
+
if (isObject(stroke)) {
|
|
27
27
|
drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas)
|
|
28
28
|
} else {
|
|
29
29
|
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data)
|