@leafer-ui/render 1.0.0-rc.9 → 1.0.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/render",
3
- "version": "1.0.0-rc.9",
3
+ "version": "1.0.1",
4
4
  "description": "@leafer-ui/render",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -15,17 +15,17 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/leaferjs/ui.git"
17
17
  },
18
- "homepage": "https://github.com/leaferjs/ui/tree/main/packages/render",
18
+ "homepage": "https://github.com/leaferjs/ui/tree/main/packages/display-module/render",
19
19
  "bugs": "https://github.com/leaferjs/ui/issues",
20
20
  "keywords": [
21
21
  "leafer-ui",
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer-ui/external": "1.0.0-rc.9"
25
+ "@leafer-ui/external": "1.0.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.9",
29
- "@leafer-ui/interface": "1.0.0-rc.9"
28
+ "@leafer/interface": "1.0.1",
29
+ "@leafer-ui/interface": "1.0.1"
30
30
  }
31
31
  }
package/src/RectRender.ts CHANGED
@@ -7,7 +7,7 @@ export const RectRender: IRectRenderModule = {
7
7
 
8
8
  __drawFast(canvas: ILeaferCanvas, options: IRenderOptions): void {
9
9
 
10
- const { width, height, fill, stroke, __drawAfterFill } = this.__
10
+ let { width, height, fill, stroke, __drawAfterFill } = this.__
11
11
 
12
12
  if (fill) {
13
13
  canvas.fillStyle = fill
@@ -18,21 +18,32 @@ export const RectRender: IRectRenderModule = {
18
18
 
19
19
  if (stroke) {
20
20
 
21
- const { strokeAlign, strokeWidth } = this.__
22
- canvas.setStroke(stroke, strokeWidth, this.__)
23
- const half = strokeWidth / 2
21
+ const { strokeAlign, __strokeWidth } = this.__
22
+ if (!__strokeWidth) return
23
+
24
+ canvas.setStroke(stroke, __strokeWidth, this.__)
25
+ const half = __strokeWidth / 2
24
26
 
25
27
  switch (strokeAlign) {
26
28
  case 'center':
27
29
  canvas.strokeRect(0, 0, width, height)
28
30
  break
29
31
  case 'inside':
30
- canvas.strokeRect(half, half, width - strokeWidth, height - strokeWidth)
32
+ width -= __strokeWidth, height -= __strokeWidth
33
+ if (width < 0 || height < 0) {
34
+ canvas.save()
35
+ this.__clip(canvas, options)
36
+ canvas.strokeRect(half, half, width, height)
37
+ canvas.restore()
38
+ } else {
39
+ canvas.strokeRect(half, half, width, height)
40
+ }
31
41
  break
32
42
  case 'outside':
33
- canvas.strokeRect(-half, -half, width + strokeWidth, height + strokeWidth)
43
+ canvas.strokeRect(-half, -half, width + __strokeWidth, height + __strokeWidth)
34
44
  break
35
45
  }
46
+
36
47
  }
37
48
 
38
49
  }
package/src/UIRender.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ILeaferCanvas, IRenderOptions } from '@leafer/interface'
2
2
 
3
- import { IUIRenderModule, ILeafPaint, ILeafStrokePaint } from '@leafer-ui/interface'
3
+ import { IUIRenderModule, ILeafPaint, ILeafStrokePaint, IUI } from '@leafer-ui/interface'
4
4
  import { Paint, Effect } from '@leafer-ui/external'
5
5
 
6
6
 
@@ -26,69 +26,82 @@ export const UIRender: IUIRenderModule = {
26
26
  },
27
27
 
28
28
  __drawFast(canvas: ILeaferCanvas, options: IRenderOptions): void {
29
- const { fill, stroke, __drawAfterFill } = this.__
30
-
31
- this.__drawRenderPath(canvas)
32
-
33
- if (fill) Paint.fill(fill as string, this, canvas)
34
- if (__drawAfterFill) this.__drawAfterFill(canvas, options)
35
- if (stroke) Paint.stroke(stroke as string, this, canvas, options)
29
+ drawFast(this, canvas, options)
36
30
  },
37
31
 
38
32
  __draw(canvas: ILeaferCanvas, options: IRenderOptions): void {
33
+ const data = this.__
34
+
35
+ if (data.__complex) {
39
36
 
40
- if (this.__.__complex) {
37
+ if (data.__needComputePaint) data.__computePaint()
41
38
 
42
- const { fill, stroke, __drawAfterFill } = this.__
39
+ const { fill, stroke, __drawAfterFill } = data
43
40
 
44
41
  this.__drawRenderPath(canvas)
45
42
 
46
- if (this.__.__useEffect) {
43
+ if (data.__useEffect) {
47
44
 
48
45
  const shape = Paint.shape(this, canvas, options)
46
+ this.__nowWorld = this.__getNowWorld(options) // restore
49
47
 
50
- const { shadow, innerShadow } = this.__
48
+ const { shadow, innerShadow } = data
51
49
 
52
- if (shadow) Effect.shadow(this, canvas, shape, options)
50
+ if (shadow) Effect.shadow(this, canvas, shape)
53
51
 
54
- if (fill) this.__.__isFills ? Paint.fills(fill as ILeafPaint[], this, canvas) : Paint.fill(fill as string, this, canvas)
52
+ if (fill) data.__isFills ? Paint.fills(fill as ILeafPaint[], this, canvas) : Paint.fill(fill as string, this, canvas)
55
53
 
56
54
  if (__drawAfterFill) this.__drawAfterFill(canvas, options)
57
55
 
58
- if (innerShadow) Effect.innerShadow(this, canvas, shape, options)
56
+ if (innerShadow) Effect.innerShadow(this, canvas, shape)
59
57
 
60
- if (stroke) this.__.__isStrokes ? Paint.strokes(stroke as ILeafStrokePaint[], this, canvas, options) : Paint.stroke(stroke as string, this, canvas, options)
58
+ if (stroke) data.__isStrokes ? Paint.strokes(stroke as ILeafStrokePaint[], this, canvas) : Paint.stroke(stroke as string, this, canvas)
61
59
 
62
60
  if (shape.worldCanvas) shape.worldCanvas.recycle()
63
61
  shape.canvas.recycle()
64
62
 
65
63
  } else {
66
64
 
67
- if (fill) this.__.__isFills ? Paint.fills(fill as ILeafPaint[], this, canvas) : Paint.fill(fill as string, this, canvas)
65
+ if (fill) data.__isFills ? Paint.fills(fill as ILeafPaint[], this, canvas) : Paint.fill(fill as string, this, canvas)
68
66
  if (__drawAfterFill) this.__drawAfterFill(canvas, options)
69
- if (stroke) this.__.__isStrokes ? Paint.strokes(stroke as ILeafStrokePaint[], this, canvas, options) : Paint.stroke(stroke as string, this, canvas, options)
67
+ if (stroke) data.__isStrokes ? Paint.strokes(stroke as ILeafStrokePaint[], this, canvas) : Paint.stroke(stroke as string, this, canvas)
70
68
 
71
69
  }
72
70
 
73
-
74
71
  } else {
75
72
 
76
- this.__drawFast(canvas, options)
73
+ if (data.__pathInputed) {
74
+ drawFast(this, canvas, options)
75
+ } else {
76
+ this.__drawFast(canvas, options)
77
+ }
77
78
 
78
79
  }
79
80
  },
80
81
 
81
- __renderShape(canvas: ILeaferCanvas, renderOptions: IRenderOptions): void {
82
- if (!this.__worldOpacity) return
82
+ __renderShape(canvas: ILeaferCanvas, options: IRenderOptions, ignoreFill?: boolean, ignoreStroke?: boolean): void {
83
+ if (this.__worldOpacity) {
84
+ canvas.setWorld(this.__nowWorld = this.__getNowWorld(options))
83
85
 
84
- canvas.setWorld(this.__world, renderOptions.matrix)
86
+ const { fill, stroke } = this.__
85
87
 
86
- const { fill, stroke } = this.__
87
-
88
- this.__drawRenderPath(canvas)
88
+ this.__drawRenderPath(canvas)
89
89
 
90
- if (fill) this.__.__pixelFill ? Paint.fills(fill as ILeafPaint[], this, canvas) : Paint.fill('#000000', this, canvas)
91
- if (stroke) this.__.__pixelStroke ? Paint.strokes(stroke as ILeafStrokePaint[], this, canvas, renderOptions) : Paint.stroke('#000000', this, canvas, renderOptions)
90
+ if (fill && !ignoreFill) this.__.__pixelFill ? Paint.fills(fill as ILeafPaint[], this, canvas) : Paint.fill('#000000', this, canvas)
91
+ if (this.__.__isCanvas) this.__drawAfterFill(canvas, options)
92
+ if (stroke && !ignoreStroke) this.__.__pixelStroke ? Paint.strokes(stroke as ILeafStrokePaint[], this, canvas) : Paint.stroke('#000000', this, canvas)
93
+ }
92
94
  }
93
95
 
96
+ }
97
+
98
+
99
+ function drawFast(ui: IUI, canvas: ILeaferCanvas, options: IRenderOptions): void {
100
+ const { fill, stroke, __drawAfterFill } = ui.__
101
+
102
+ ui.__drawRenderPath(canvas)
103
+
104
+ if (fill) Paint.fill(fill as string, ui, canvas)
105
+ if (__drawAfterFill) ui.__drawAfterFill(canvas, options)
106
+ if (stroke) Paint.stroke(stroke as string, ui, canvas)
94
107
  }