@leafer-ui/paint 1.0.0-rc.3 → 1.0.0-rc.5
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 +4 -4
- package/src/Compute.ts +24 -8
- package/src/Fill.ts +2 -2
- package/src/Stroke.ts +20 -10
- package/src/StrokeText.ts +14 -9
- package/src/paint/image/check.ts +6 -3
- package/src/paint/image/recycle.ts +1 -1
- package/types/index.d.ts +7 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/paint",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.5",
|
|
4
4
|
"description": "@leafer-ui/paint",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.0.0-rc.
|
|
25
|
+
"@leafer/core": "1.0.0-rc.5"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.0-rc.
|
|
29
|
-
"@leafer-ui/interface": "1.0.0-rc.
|
|
28
|
+
"@leafer/interface": "1.0.0-rc.5",
|
|
29
|
+
"@leafer-ui/interface": "1.0.0-rc.5"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/Compute.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap } from '@leafer-ui/interface'
|
|
2
|
-
import { ColorConvert } from '@leafer-ui/core'
|
|
1
|
+
import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap, IImagePaint } from '@leafer-ui/interface'
|
|
2
|
+
import { ColorConvert, ImageManager } from '@leafer-ui/core'
|
|
3
3
|
|
|
4
4
|
import { image } from "./paint/image/image"
|
|
5
5
|
import { linearGradient } from './paint/linear'
|
|
@@ -10,25 +10,41 @@ import { recycleImage } from './paint/image'
|
|
|
10
10
|
|
|
11
11
|
let recycleMap: IBooleanMap
|
|
12
12
|
|
|
13
|
-
export function compute(
|
|
13
|
+
export function compute(attrName: 'fill' | 'stroke', ui: IUI): void {
|
|
14
14
|
const value: ILeafPaint[] = []
|
|
15
|
+
const data = ui.__
|
|
16
|
+
|
|
15
17
|
let item: ILeafPaint
|
|
16
|
-
let paints =
|
|
18
|
+
let paints = data.__input[attrName] as IPaint[]
|
|
17
19
|
|
|
18
20
|
if (!(paints instanceof Array)) paints = [paints]
|
|
19
21
|
|
|
20
|
-
recycleMap = recycleImage(
|
|
22
|
+
recycleMap = recycleImage(attrName, data)
|
|
21
23
|
|
|
22
24
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
23
|
-
item = getLeafPaint(
|
|
25
|
+
item = getLeafPaint(attrName, paints[i], ui)
|
|
24
26
|
if (item) value.push(item)
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
data['_' + attrName] = value.length ? value : undefined
|
|
30
|
+
|
|
31
|
+
// check png / svg / webp
|
|
32
|
+
|
|
33
|
+
let isPixel
|
|
34
|
+
if (paints.length === 1) {
|
|
35
|
+
const paint = paints[0] as IImagePaint
|
|
36
|
+
if (paint.type === 'image') isPixel = ImageManager.isPixel(paint)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (attrName === 'fill') {
|
|
40
|
+
data.__pixelFill = isPixel
|
|
41
|
+
} else {
|
|
42
|
+
data.__pixelStroke = isPixel
|
|
43
|
+
}
|
|
28
44
|
}
|
|
29
45
|
|
|
30
46
|
|
|
31
|
-
function getLeafPaint(
|
|
47
|
+
function getLeafPaint(attrName: string, paint: IPaint, ui: IUI,): ILeafPaint {
|
|
32
48
|
if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0) return undefined
|
|
33
49
|
const { boxBounds } = ui.__layout
|
|
34
50
|
|
package/src/Fill.ts
CHANGED
|
@@ -6,13 +6,13 @@ import { checkImage } from './paint/image'
|
|
|
6
6
|
import { fillText } from './FillText'
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
export function fill(ui: IUI, canvas: ILeaferCanvas
|
|
9
|
+
export function fill(fill: string, ui: IUI, canvas: ILeaferCanvas): void {
|
|
10
10
|
canvas.fillStyle = fill
|
|
11
11
|
ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill())
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
export function fills(ui: IUI, canvas: ILeaferCanvas
|
|
15
|
+
export function fills(fills: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void {
|
|
16
16
|
let item: ILeafPaint
|
|
17
17
|
const { windingRule, __font } = ui.__
|
|
18
18
|
for (let i = 0, len = fills.length; i < len; i++) {
|
package/src/Stroke.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ILeaferCanvas } from '@leafer/interface'
|
|
1
|
+
import { ILeaferCanvas, IRenderOptions } from '@leafer/interface'
|
|
2
2
|
|
|
3
3
|
import { IUI, ILeafPaint } from '@leafer-ui/interface'
|
|
4
4
|
|
|
5
5
|
import { strokeText, drawStrokesStyle } from './StrokeText'
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
export function stroke(ui: IUI, canvas: ILeaferCanvas,
|
|
8
|
+
export function stroke(stroke: string, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
|
|
9
9
|
const options = ui.__
|
|
10
10
|
const { strokeWidth, strokeAlign, __font } = options
|
|
11
11
|
if (!strokeWidth) return
|
|
12
12
|
|
|
13
13
|
if (__font) {
|
|
14
14
|
|
|
15
|
-
strokeText(ui, canvas,
|
|
15
|
+
strokeText(stroke, ui, canvas, renderOptions)
|
|
16
16
|
|
|
17
17
|
} else {
|
|
18
18
|
|
|
@@ -47,7 +47,12 @@ export function stroke(ui: IUI, canvas: ILeaferCanvas, stroke: string): void {
|
|
|
47
47
|
options.windingRule ? out.clip(options.windingRule) : out.clip()
|
|
48
48
|
out.clearWorld(ui.__layout.renderBounds)
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
if (ui.__hasMirror || renderOptions.matrix) {
|
|
51
|
+
canvas.copyWorldByReset(out)
|
|
52
|
+
} else {
|
|
53
|
+
canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds)
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
out.recycle()
|
|
52
57
|
|
|
53
58
|
break
|
|
@@ -57,14 +62,14 @@ export function stroke(ui: IUI, canvas: ILeaferCanvas, stroke: string): void {
|
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
|
|
60
|
-
export function strokes(ui: IUI, canvas: ILeaferCanvas,
|
|
65
|
+
export function strokes(strokes: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
|
|
61
66
|
const options = ui.__
|
|
62
67
|
const { strokeWidth, strokeAlign, __font } = options
|
|
63
68
|
if (!strokeWidth) return
|
|
64
69
|
|
|
65
70
|
if (__font) {
|
|
66
71
|
|
|
67
|
-
strokeText(ui, canvas,
|
|
72
|
+
strokeText(strokes, ui, canvas, renderOptions)
|
|
68
73
|
|
|
69
74
|
} else {
|
|
70
75
|
|
|
@@ -72,7 +77,7 @@ export function strokes(ui: IUI, canvas: ILeaferCanvas, strokes: ILeafPaint[]):
|
|
|
72
77
|
|
|
73
78
|
case 'center':
|
|
74
79
|
canvas.setStroke(undefined, strokeWidth, options)
|
|
75
|
-
drawStrokesStyle(
|
|
80
|
+
drawStrokesStyle(strokes, false, ui, canvas)
|
|
76
81
|
break
|
|
77
82
|
|
|
78
83
|
case 'inside':
|
|
@@ -80,7 +85,7 @@ export function strokes(ui: IUI, canvas: ILeaferCanvas, strokes: ILeafPaint[]):
|
|
|
80
85
|
canvas.setStroke(undefined, strokeWidth * 2, options)
|
|
81
86
|
options.windingRule ? canvas.clip(options.windingRule) : canvas.clip()
|
|
82
87
|
|
|
83
|
-
drawStrokesStyle(
|
|
88
|
+
drawStrokesStyle(strokes, false, ui, canvas)
|
|
84
89
|
|
|
85
90
|
canvas.restore()
|
|
86
91
|
break
|
|
@@ -92,12 +97,17 @@ export function strokes(ui: IUI, canvas: ILeaferCanvas, strokes: ILeafPaint[]):
|
|
|
92
97
|
|
|
93
98
|
out.setStroke(undefined, strokeWidth * 2, ui.__)
|
|
94
99
|
|
|
95
|
-
drawStrokesStyle(
|
|
100
|
+
drawStrokesStyle(strokes, false, ui, out)
|
|
96
101
|
|
|
97
102
|
options.windingRule ? out.clip(options.windingRule) : out.clip()
|
|
98
103
|
out.clearWorld(renderBounds)
|
|
99
104
|
|
|
100
|
-
|
|
105
|
+
if (ui.__hasMirror || renderOptions.matrix) {
|
|
106
|
+
canvas.copyWorldByReset(out)
|
|
107
|
+
} else {
|
|
108
|
+
canvas.copyWorldToInner(out, ui.__world, renderBounds)
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
out.recycle()
|
|
102
112
|
break
|
|
103
113
|
}
|
package/src/StrokeText.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaferCanvas } from '@leafer/interface'
|
|
1
|
+
import { ILeaferCanvas, IRenderOptions } from '@leafer/interface'
|
|
2
2
|
|
|
3
3
|
import { IUI, ITextRowData, ILeafPaint, IStrokeAlign, ILeafStrokePaint } from '@leafer-ui/interface'
|
|
4
4
|
|
|
@@ -6,37 +6,42 @@ import { fillText } from './FillText'
|
|
|
6
6
|
import { checkImage } from './paint/image'
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
export function strokeText(ui: IUI, canvas: ILeaferCanvas,
|
|
9
|
+
export function strokeText(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanvas, renderOptions?: IRenderOptions): void {
|
|
10
10
|
const { strokeAlign } = ui.__
|
|
11
11
|
const isStrokes = typeof stroke !== 'string'
|
|
12
12
|
switch (strokeAlign) {
|
|
13
13
|
case 'center':
|
|
14
14
|
canvas.setStroke(isStrokes ? undefined : stroke, ui.__.strokeWidth, ui.__)
|
|
15
|
-
isStrokes ? drawStrokesStyle(
|
|
15
|
+
isStrokes ? drawStrokesStyle(stroke as ILeafPaint[], true, ui, canvas) : drawTextStroke(ui, canvas)
|
|
16
16
|
break
|
|
17
17
|
case 'inside':
|
|
18
|
-
drawAlignStroke(
|
|
18
|
+
drawAlignStroke('inside', stroke, isStrokes, ui, canvas, renderOptions)
|
|
19
19
|
break
|
|
20
20
|
case 'outside':
|
|
21
|
-
drawAlignStroke(
|
|
21
|
+
drawAlignStroke('outside', stroke, isStrokes, ui, canvas, renderOptions)
|
|
22
22
|
break
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function drawAlignStroke(
|
|
26
|
+
function drawAlignStroke(align: IStrokeAlign, stroke: string | ILeafPaint[], isStrokes: boolean, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
|
|
27
27
|
const { strokeWidth, __font } = ui.__
|
|
28
28
|
|
|
29
29
|
const out = canvas.getSameCanvas(true)
|
|
30
30
|
out.setStroke(isStrokes ? undefined : stroke, strokeWidth * 2, ui.__)
|
|
31
31
|
|
|
32
32
|
out.font = __font
|
|
33
|
-
isStrokes ? drawStrokesStyle(
|
|
33
|
+
isStrokes ? drawStrokesStyle(stroke as ILeafPaint[], true, ui, out) : drawTextStroke(ui, out)
|
|
34
34
|
|
|
35
35
|
out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in'
|
|
36
36
|
fillText(ui, out)
|
|
37
37
|
out.blendMode = 'normal'
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
if (ui.__hasMirror || renderOptions.matrix) {
|
|
40
|
+
canvas.copyWorldByReset(out)
|
|
41
|
+
} else {
|
|
42
|
+
canvas.copyWorldToInner(out, ui.__world, ui.__layout.renderBounds)
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
out.recycle()
|
|
41
46
|
}
|
|
42
47
|
|
|
@@ -61,7 +66,7 @@ export function drawTextStroke(ui: IUI, canvas: ILeaferCanvas): void {
|
|
|
61
66
|
|
|
62
67
|
}
|
|
63
68
|
|
|
64
|
-
export function drawStrokesStyle(
|
|
69
|
+
export function drawStrokesStyle(strokes: ILeafStrokePaint[], isText: boolean, ui: IUI, canvas: ILeaferCanvas): void {
|
|
65
70
|
let item: ILeafStrokePaint
|
|
66
71
|
for (let i = 0, len = strokes.length; i < len; i++) {
|
|
67
72
|
item = strokes[i]
|
package/src/paint/image/check.ts
CHANGED
|
@@ -39,9 +39,12 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
|
|
|
39
39
|
if (!paint.style) {
|
|
40
40
|
createPattern(ui, paint, canvas.pixelRatio)
|
|
41
41
|
} else {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (!paint.patternTask) {
|
|
43
|
+
paint.patternTask = ImageManager.patternTasker.add(async () => {
|
|
44
|
+
paint.patternTask = null
|
|
45
|
+
if (canvas.bounds.hit(ui.__world) && createPattern(ui, paint, canvas.pixelRatio)) ui.forceUpdate('surface')
|
|
46
|
+
}, 300)
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
49
|
return false
|
|
47
50
|
}
|
|
@@ -4,7 +4,7 @@ import { ImageManager } from '@leafer/core'
|
|
|
4
4
|
import { IImagePaint, ILeafPaint, IUIData } from '@leafer-ui/interface'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
export function recycleImage(
|
|
7
|
+
export function recycleImage(attrName: 'fill' | 'stroke', data: IUIData): IBooleanMap {
|
|
8
8
|
const paints = (attrName === 'fill' ? data._fill : data._stroke) as ILeafPaint[]
|
|
9
9
|
|
|
10
10
|
if (paints instanceof Array) {
|
package/types/index.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { ILeaferCanvas, IRenderOptions, IBooleanMap } from '@leafer/interface';
|
|
2
2
|
import { IUI, ILeafPaint, ICachedShape, IUIData } from '@leafer-ui/interface';
|
|
3
3
|
|
|
4
|
-
declare function fill(ui: IUI, canvas: ILeaferCanvas
|
|
5
|
-
declare function fills(ui: IUI, canvas: ILeaferCanvas
|
|
4
|
+
declare function fill(fill: string, ui: IUI, canvas: ILeaferCanvas): void;
|
|
5
|
+
declare function fills(fills: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void;
|
|
6
6
|
|
|
7
7
|
declare function fillText(ui: IUI, canvas: ILeaferCanvas): void;
|
|
8
8
|
|
|
9
|
-
declare function stroke(ui: IUI, canvas: ILeaferCanvas,
|
|
10
|
-
declare function strokes(ui: IUI, canvas: ILeaferCanvas,
|
|
9
|
+
declare function stroke(stroke: string, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void;
|
|
10
|
+
declare function strokes(strokes: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void;
|
|
11
11
|
|
|
12
|
-
declare function strokeText(ui: IUI, canvas: ILeaferCanvas,
|
|
12
|
+
declare function strokeText(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanvas, renderOptions?: IRenderOptions): void;
|
|
13
13
|
declare function drawTextStroke(ui: IUI, canvas: ILeaferCanvas): void;
|
|
14
14
|
|
|
15
15
|
declare function shape(ui: IUI, current: ILeaferCanvas, options: IRenderOptions): ICachedShape;
|
|
16
16
|
|
|
17
|
-
declare function compute(
|
|
17
|
+
declare function compute(attrName: 'fill' | 'stroke', ui: IUI): void;
|
|
18
18
|
|
|
19
|
-
declare function recycleImage(
|
|
19
|
+
declare function recycleImage(attrName: 'fill' | 'stroke', data: IUIData): IBooleanMap;
|
|
20
20
|
|
|
21
21
|
export { compute, drawTextStroke, fill, fillText, fills, recycleImage, shape, stroke, strokeText, strokes };
|