@leafer-ui/paint 1.9.12 → 1.10.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/paint",
3
- "version": "1.9.12",
3
+ "version": "1.10.1",
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.9.12",
26
- "@leafer-ui/draw": "1.9.12"
25
+ "@leafer/core": "1.10.1",
26
+ "@leafer-ui/draw": "1.10.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.9.12",
30
- "@leafer-ui/interface": "1.9.12"
29
+ "@leafer/interface": "1.10.1",
30
+ "@leafer-ui/interface": "1.10.1"
31
31
  }
32
32
  }
package/src/Compute.ts CHANGED
@@ -32,61 +32,66 @@ export function compute(attrName: IPaintAttr, ui: IUI): void {
32
32
  (data as IObject)['_' + attrName] = leafPaints.length ? leafPaints : undefined
33
33
 
34
34
  if (leafPaints.length) {
35
+
35
36
  if (leafPaints.every(item => item.isTransparent)) {
36
37
  if (leafPaints.some(item => item.image)) isAlphaPixel = true
37
38
  isTransparent = true
38
39
  }
39
- }
40
40
 
41
- if (attrName === 'fill') {
42
- stintSet(data, '__isAlphaPixelFill', isAlphaPixel)
43
- stintSet(data, '__isTransparentFill', isTransparent)
41
+ if (attrName === 'fill') {
42
+ stintSet(data, '__isAlphaPixelFill', isAlphaPixel)
43
+ stintSet(data, '__isTransparentFill', isTransparent)
44
+ } else {
45
+ stintSet(data, '__isAlphaPixelStroke', isAlphaPixel)
46
+ stintSet(data, '__isTransparentStroke', isTransparent)
47
+ stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth)
48
+ }
49
+
44
50
  } else {
45
- stintSet(data, '__isAlphaPixelStroke', isAlphaPixel)
46
- stintSet(data, '__isTransparentStroke', isTransparent)
47
- stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth)
51
+ data.__removePaint(attrName, false)
48
52
  }
53
+
49
54
  }
50
55
 
51
56
 
52
57
  function getLeafPaint(attrName: string, paint: IPaint, ui: IUI): ILeafPaint {
53
58
  if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined
54
59
 
55
- let data: ILeafPaint
60
+ let leafPaint: ILeafPaint
56
61
  const { boxBounds } = ui.__layout
57
62
 
58
63
  switch (paint.type) {
59
64
  case 'image':
60
- data = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url])
65
+ leafPaint = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url])
61
66
  break
62
67
  case 'linear':
63
- data = PaintGradient.linearGradient(paint, boxBounds)
68
+ leafPaint = PaintGradient.linearGradient(paint, boxBounds)
64
69
  break
65
70
  case 'radial':
66
- data = PaintGradient.radialGradient(paint, boxBounds)
71
+ leafPaint = PaintGradient.radialGradient(paint, boxBounds)
67
72
  break
68
73
  case 'angular':
69
- data = PaintGradient.conicGradient(paint, boxBounds)
74
+ leafPaint = PaintGradient.conicGradient(paint, boxBounds)
70
75
  break
71
76
  case 'solid':
72
77
  const { type, color, opacity } = paint
73
- data = { type, style: ColorConvert.string(color, opacity) }
78
+ leafPaint = { type, style: ColorConvert.string(color, opacity) }
74
79
  break
75
80
  default:
76
- if (!isUndefined((paint as IRGB).r)) data = { type: 'solid', style: ColorConvert.string(paint) }
81
+ if (!isUndefined((paint as IRGB).r)) leafPaint = { type: 'solid', style: ColorConvert.string(paint) }
77
82
  }
78
83
 
79
- if (data) {
84
+ if (leafPaint) {
85
+ // 原始paint
86
+ leafPaint.originPaint = paint
87
+
80
88
  // 描边样式
81
- if (isString(data.style) && hasTransparent(data.style)) data.isTransparent = true
89
+ if (isString(leafPaint.style) && hasTransparent(leafPaint.style)) leafPaint.isTransparent = true
82
90
  if (paint.style) {
83
91
  if (paint.style.strokeWidth === 0) return undefined
84
- data.strokeStyle = paint.style as IStrokeComputedStyle
92
+ leafPaint.strokeStyle = paint.style as IStrokeComputedStyle
85
93
  }
86
-
87
- if (paint.editing) data.editing = paint.editing
88
- if (paint.blendMode) data.blendMode = paint.blendMode
89
94
  }
90
95
 
91
- return data
96
+ return leafPaint
92
97
  }
package/src/Fill.ts CHANGED
@@ -1,28 +1,28 @@
1
- import { ILeaferCanvas } from '@leafer/interface'
1
+ import { ILeaferCanvas, IRenderOptions } from '@leafer/interface'
2
2
 
3
- import { ILeafPaint, IUI } from '@leafer-ui/interface'
4
- import { PaintImage } from "@leafer-ui/draw"
3
+ import { IImagePaint, ILeafPaint, IUI } from '@leafer-ui/interface'
4
+ import { PaintImage, Paint } from "@leafer-ui/draw"
5
5
 
6
- import { fillText } from './FillText'
7
6
 
8
-
9
- export function fill(fill: string, ui: IUI, canvas: ILeaferCanvas): void {
7
+ export function fill(fill: string, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
10
8
  canvas.fillStyle = fill
11
- fillPathOrText(ui, canvas)
9
+ fillPathOrText(ui, canvas, renderOptions)
12
10
  }
13
11
 
14
12
 
15
- export function fills(fills: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void {
16
- let item: ILeafPaint
13
+ export function fills(fills: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
14
+ let item: ILeafPaint, originPaint: IImagePaint, countImage: number
17
15
  for (let i = 0, len = fills.length; i < len; i++) {
18
- item = fills[i]
16
+ item = fills[i], originPaint = item.originPaint as IImagePaint
19
17
 
20
18
  if (item.image) {
21
19
 
22
- if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font)) continue
20
+ countImage ? countImage++ : countImage = 1
21
+
22
+ if (PaintImage.checkImage(item, !ui.__.__font, ui, canvas, renderOptions)) continue
23
23
 
24
24
  if (!item.style) {
25
- if (!i && item.image.isPlacehold) ui.drawImagePlaceholder(canvas, item.image) // 图片加载中或加载失败
25
+ if (countImage === 1 && item.image.isPlacehold) ui.drawImagePlaceholder(item, canvas, renderOptions) // 图片加载中或加载失败
26
26
  continue
27
27
  }
28
28
 
@@ -30,27 +30,27 @@ export function fills(fills: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void
30
30
 
31
31
  canvas.fillStyle = item.style
32
32
 
33
- if (item.transform || item.scaleFixed) {
33
+ if (item.transform || originPaint.scaleFixed) {
34
34
 
35
35
  canvas.save()
36
36
  if (item.transform) canvas.transform(item.transform)
37
- if (item.scaleFixed) {
37
+ if (originPaint.scaleFixed) {
38
38
  const { scaleX, scaleY } = ui.getRenderScaleData(true)
39
- if (item.scaleFixed === true || (item.scaleFixed === 'zoom-in' && scaleX > 1 && scaleY > 1)) canvas.scale(1 / scaleX, 1 / scaleY)
39
+ if (originPaint.scaleFixed === true || (originPaint.scaleFixed === 'zoom-in' && scaleX > 1 && scaleY > 1)) canvas.scale(1 / scaleX, 1 / scaleY)
40
40
  }
41
- if (item.blendMode) canvas.blendMode = item.blendMode
42
- fillPathOrText(ui, canvas)
41
+ if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode
42
+ fillPathOrText(ui, canvas, renderOptions)
43
43
  canvas.restore()
44
44
 
45
45
  } else {
46
46
 
47
- if (item.blendMode) {
47
+ if (originPaint.blendMode) {
48
48
 
49
- canvas.saveBlendMode(item.blendMode)
50
- fillPathOrText(ui, canvas)
49
+ canvas.saveBlendMode(originPaint.blendMode)
50
+ fillPathOrText(ui, canvas, renderOptions)
51
51
  canvas.restoreBlendMode()
52
52
 
53
- } else fillPathOrText(ui, canvas)
53
+ } else fillPathOrText(ui, canvas, renderOptions)
54
54
 
55
55
  }
56
56
 
@@ -58,6 +58,6 @@ export function fills(fills: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void
58
58
  }
59
59
 
60
60
 
61
- export function fillPathOrText(ui: IUI, canvas: ILeaferCanvas): void {
62
- ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill())
61
+ export function fillPathOrText(ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
62
+ ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill())
63
63
  }
package/src/FillText.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { ILeaferCanvas } from '@leafer/interface'
1
+ import { ILeaferCanvas, IRenderOptions } from '@leafer/interface'
2
2
 
3
3
  import { ITextRowData, IText } from '@leafer-ui/interface'
4
4
 
5
5
 
6
- export function fillText(ui: IText, canvas: ILeaferCanvas): void {
6
+ export function fillText(ui: IText, canvas: ILeaferCanvas, _renderOptions: IRenderOptions): void {
7
7
 
8
8
  const data = ui.__, { rows, decorationY } = data.__textDrawData
9
9
  if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor
package/src/Stroke.ts CHANGED
@@ -1,31 +1,29 @@
1
- import { ILeaferCanvas } from '@leafer/interface'
1
+ import { ILeaferCanvas, IRenderOptions } from '@leafer/interface'
2
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'
6
6
 
7
- import { strokeText, drawStrokesStyle } from './StrokeText'
8
7
 
9
-
10
- export function stroke(stroke: string, ui: IUI, canvas: ILeaferCanvas): void {
8
+ export function stroke(stroke: string, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
11
9
  const data = ui.__
12
10
  if (!data.__strokeWidth) return
13
11
 
14
12
  if (data.__font) {
15
13
 
16
- strokeText(stroke, ui, canvas)
14
+ Paint.strokeText(stroke, ui, canvas, renderOptions)
17
15
 
18
16
  } else {
19
17
 
20
18
  switch (data.strokeAlign) {
21
19
  case 'center':
22
- drawCenter(stroke, 1, ui, canvas)
20
+ drawCenter(stroke, 1, ui, canvas, renderOptions)
23
21
  break
24
22
  case 'inside':
25
- drawInside(stroke, ui, canvas)
23
+ drawInside(stroke, ui, canvas, renderOptions)
26
24
  break
27
25
  case 'outside':
28
- drawOutside(stroke, ui, canvas)
26
+ drawOutside(stroke, ui, canvas, renderOptions)
29
27
  break
30
28
  }
31
29
 
@@ -33,43 +31,43 @@ export function stroke(stroke: string, ui: IUI, canvas: ILeaferCanvas): void {
33
31
  }
34
32
 
35
33
 
36
- export function strokes(strokes: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void {
37
- stroke(strokes as any, ui, canvas)
34
+ export function strokes(strokes: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
35
+ Paint.stroke(strokes as any, ui, canvas, renderOptions)
38
36
  }
39
37
 
40
38
 
41
- function drawCenter(stroke: string | ILeafPaint[], strokeWidthScale: number, ui: IUI, canvas: ILeaferCanvas) {
39
+ function drawCenter(stroke: string | ILeafPaint[], strokeWidthScale: number, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions) {
42
40
  const data = ui.__
43
41
  if (isObject(stroke)) {
44
- drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas)
42
+ Paint.drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas, renderOptions)
45
43
  } else {
46
44
  canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data)
47
45
  canvas.stroke()
48
46
  }
49
47
 
50
- if (data.__useArrow) Paint.strokeArrow(stroke, ui, canvas)
48
+ if (data.__useArrow) Paint.strokeArrow(stroke, ui, canvas, renderOptions)
51
49
  }
52
50
 
53
- function drawInside(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanvas) {
51
+ function drawInside(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions) {
54
52
  canvas.save()
55
53
  canvas.clipUI(ui)
56
54
 
57
- drawCenter(stroke, 2, ui, canvas)
55
+ drawCenter(stroke, 2, ui, canvas, renderOptions)
58
56
  canvas.restore()
59
57
  }
60
58
 
61
- function drawOutside(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanvas) {
59
+ function drawOutside(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions) {
62
60
  const data = ui.__
63
61
  if (data.__fillAfterStroke) {
64
62
 
65
- drawCenter(stroke, 2, ui, canvas)
63
+ drawCenter(stroke, 2, ui, canvas, renderOptions)
66
64
 
67
65
  } else {
68
66
  const { renderBounds } = ui.__layout
69
67
  const out = canvas.getSameCanvas(true, true)
70
68
  ui.__drawRenderPath(out)
71
69
 
72
- drawCenter(stroke, 2, ui, out)
70
+ drawCenter(stroke, 2, ui, out, renderOptions)
73
71
 
74
72
  out.clipUI(data)
75
73
  out.clearWorld(renderBounds)
package/src/StrokeText.ts CHANGED
@@ -1,43 +1,41 @@
1
- import { ILeaferCanvas } from '@leafer/interface'
1
+ import { ILeaferCanvas, IRenderOptions } from '@leafer/interface'
2
2
  import { LeafHelper, isObject } from "@leafer/core"
3
3
 
4
4
  import { IUI, ITextRowData, ILeafPaint, IStrokeAlign, ILeafStrokePaint } from '@leafer-ui/interface'
5
- import { PaintImage } from "@leafer-ui/draw"
5
+ import { PaintImage, Paint } from "@leafer-ui/draw"
6
6
 
7
- import { fillText } from './FillText'
8
7
 
9
-
10
- export function strokeText(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void {
8
+ export function strokeText(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
11
9
  switch (ui.__.strokeAlign) {
12
10
  case 'center':
13
- drawCenter(stroke, 1, ui, canvas)
11
+ drawCenter(stroke, 1, ui, canvas, renderOptions)
14
12
  break
15
13
  case 'inside':
16
- drawAlign(stroke, 'inside', ui, canvas)
14
+ drawAlign(stroke, 'inside', ui, canvas, renderOptions)
17
15
  break
18
16
  case 'outside':
19
- ui.__.__fillAfterStroke ? drawCenter(stroke, 2, ui, canvas) : drawAlign(stroke, 'outside', ui, canvas)
17
+ ui.__.__fillAfterStroke ? drawCenter(stroke, 2, ui, canvas, renderOptions) : drawAlign(stroke, 'outside', ui, canvas, renderOptions)
20
18
  break
21
19
  }
22
20
  }
23
21
 
24
- function drawCenter(stroke: string | ILeafPaint[], strokeWidthScale: number, ui: IUI, canvas: ILeaferCanvas): void {
22
+ function drawCenter(stroke: string | ILeafPaint[], strokeWidthScale: number, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
25
23
  const data = ui.__
26
24
  if (isObject(stroke)) {
27
- drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas)
25
+ Paint.drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas, renderOptions)
28
26
  } else {
29
27
  canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data)
30
- drawTextStroke(ui, canvas)
28
+ Paint.drawTextStroke(ui, canvas, renderOptions)
31
29
  }
32
30
  }
33
31
 
34
- function drawAlign(stroke: string | ILeafPaint[], align: IStrokeAlign, ui: IUI, canvas: ILeaferCanvas): void {
32
+ function drawAlign(stroke: string | ILeafPaint[], align: IStrokeAlign, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
35
33
  const out = canvas.getSameCanvas(true, true)
36
34
  out.font = ui.__.__font
37
- drawCenter(stroke, 2, ui, out)
35
+ drawCenter(stroke, 2, ui, out, renderOptions)
38
36
 
39
37
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in'
40
- fillText(ui, out)
38
+ Paint.fillText(ui, out, renderOptions)
41
39
  out.blendMode = 'normal'
42
40
 
43
41
  LeafHelper.copyCanvasByWorld(ui, canvas, out)
@@ -46,7 +44,7 @@ function drawAlign(stroke: string | ILeafPaint[], align: IStrokeAlign, ui: IUI,
46
44
  }
47
45
 
48
46
 
49
- export function drawTextStroke(ui: IUI, canvas: ILeaferCanvas): void {
47
+ export function drawTextStroke(ui: IUI, canvas: ILeaferCanvas, _renderOptions: IRenderOptions): void {
50
48
 
51
49
  let row: ITextRowData, data = ui.__.__textDrawData
52
50
  const { rows, decorationY } = data
@@ -65,7 +63,7 @@ export function drawTextStroke(ui: IUI, canvas: ILeaferCanvas): void {
65
63
 
66
64
  }
67
65
 
68
- export function drawStrokesStyle(strokes: ILeafStrokePaint[], strokeWidthScale: number, isText: boolean, ui: IUI, canvas: ILeaferCanvas): void {
66
+ export function drawStrokesStyle(strokes: ILeafStrokePaint[], strokeWidthScale: number, isText: boolean, ui: IUI, canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
69
67
  let item: ILeafStrokePaint
70
68
  const data = ui.__, { __hasMultiStrokeStyle } = data
71
69
  __hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data)
@@ -73,7 +71,7 @@ export function drawStrokesStyle(strokes: ILeafStrokePaint[], strokeWidthScale:
73
71
  for (let i = 0, len = strokes.length; i < len; i++) {
74
72
  item = strokes[i]
75
73
 
76
- if (item.image && PaintImage.checkImage(ui, canvas, item, false)) continue
74
+ if (item.image && PaintImage.checkImage(item, false, ui, canvas, renderOptions)) continue
77
75
 
78
76
  if (item.style) {
79
77
  if (__hasMultiStrokeStyle) {
@@ -81,12 +79,12 @@ export function drawStrokesStyle(strokes: ILeafStrokePaint[], strokeWidthScale:
81
79
  strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data)
82
80
  } else canvas.strokeStyle = item.style
83
81
 
84
- if (item.blendMode) {
85
- canvas.saveBlendMode(item.blendMode)
86
- isText ? drawTextStroke(ui, canvas) : canvas.stroke()
82
+ if (item.originPaint.blendMode) {
83
+ canvas.saveBlendMode(item.originPaint.blendMode)
84
+ isText ? Paint.drawTextStroke(ui, canvas, renderOptions) : canvas.stroke()
87
85
  canvas.restoreBlendMode()
88
86
  } else {
89
- isText ? drawTextStroke(ui, canvas) : canvas.stroke()
87
+ isText ? Paint.drawTextStroke(ui, canvas, renderOptions) : canvas.stroke()
90
88
  }
91
89
  }
92
90
  }
package/src/index.ts CHANGED
@@ -3,20 +3,24 @@ import { IPaintModule } from '@leafer-ui/interface'
3
3
  import { fill, fills, fillPathOrText } from './Fill'
4
4
  import { fillText } from './FillText'
5
5
  import { stroke, strokes } from './Stroke'
6
- import { strokeText, drawTextStroke } from './StrokeText'
6
+ import { strokeText, drawTextStroke, drawStrokesStyle } from './StrokeText'
7
7
  import { shape } from './Shape'
8
8
  import { compute } from './Compute'
9
9
 
10
10
 
11
11
  export const PaintModule: IPaintModule = {
12
12
  compute,
13
+
13
14
  fill,
14
15
  fills,
15
16
  fillPathOrText,
16
17
  fillText,
18
+
17
19
  stroke,
18
20
  strokes,
19
21
  strokeText,
20
22
  drawTextStroke,
23
+ drawStrokesStyle,
24
+
21
25
  shape
22
26
  }