@leafer/canvas 1.0.0-beta.7 → 1.0.0-beta.9

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/canvas",
3
- "version": "1.0.0-beta.7",
3
+ "version": "1.0.0-beta.9",
4
4
  "description": "@leafer/canvas",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,13 +19,15 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "dependencies": {
22
- "@leafer/file": "1.0.0-beta.7",
23
- "@leafer/list": "1.0.0-beta.7",
24
- "@leafer/math": "1.0.0-beta.7",
25
- "@leafer/data": "1.0.0-beta.7",
26
- "@leafer/platform": "1.0.0-beta.7"
22
+ "@leafer/file": "1.0.0-beta.9",
23
+ "@leafer/list": "1.0.0-beta.9",
24
+ "@leafer/math": "1.0.0-beta.9",
25
+ "@leafer/data": "1.0.0-beta.9",
26
+ "@leafer/path": "1.0.0-beta.9",
27
+ "@leafer/debug": "1.0.0-beta.9",
28
+ "@leafer/platform": "1.0.0-beta.9"
27
29
  },
28
30
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-beta.7"
31
+ "@leafer/interface": "1.0.0-beta.9"
30
32
  }
31
33
  }
package/src/Canvas.ts CHANGED
@@ -136,6 +136,7 @@ export class Canvas implements ICanvasAttr {
136
136
  method = (this.context as IObject)[name]
137
137
  if (method) (this as IObject)[name] = method.bind(this.context)
138
138
  })
139
+ this.textBaseline = "alphabetic"
139
140
  }
140
141
 
141
142
  // canvas method
@@ -49,7 +49,7 @@ export class CanvasManager implements ICanvasManager {
49
49
  this.list.length = 0
50
50
  }
51
51
 
52
- public destory(): void {
52
+ public destroy(): void {
53
53
  this.clear()
54
54
  }
55
55
 
@@ -29,13 +29,14 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
29
29
  public get allowBackgroundColor(): boolean { return this.view && this.parentView && !this.offscreen }
30
30
 
31
31
  public bounds: IBounds
32
+ public clientBounds: IBoundsData
32
33
 
33
34
  public config: ILeaferCanvasConfig
34
35
 
35
36
  public autoLayout: boolean
36
37
 
37
- public view: unknown
38
- public parentView: unknown
38
+ public view: any
39
+ public parentView: any
39
40
 
40
41
  public unreal?: boolean
41
42
 
@@ -63,12 +64,14 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
63
64
  this.config = config
64
65
 
65
66
  this.init()
66
-
67
- this.textBaseline = "alphabetic"
68
67
  }
69
68
 
70
69
  public init(): void { }
71
70
 
71
+ protected __createContext(): void {
72
+ this.context = this.view.getContext('2d')
73
+ this.__bindContext()
74
+ }
72
75
 
73
76
  public toBlob(type?: IExportFileType, quality?: number): Promise<IBlob> {
74
77
  return new Promise((resolve) => {
@@ -131,6 +134,8 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
131
134
  this.smooth = this.config.smooth
132
135
  }
133
136
 
137
+ this.updateClientBounds()
138
+
134
139
  if (this.context && !this.unreal && takeCanvas) {
135
140
  this.clearWorld(takeCanvas.bounds)
136
141
  this.copyWorld(takeCanvas)
@@ -139,6 +144,8 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
139
144
  }
140
145
 
141
146
  public updateViewSize(): void { }
147
+ public updateClientBounds(): void { }
148
+
142
149
  public startAutoLayout(_autoBounds: IAutoBounds, _listener: IResizeEventListener): void { }
143
150
  public stopAutoLayout(): void { }
144
151
 
@@ -205,7 +212,7 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
205
212
  }
206
213
 
207
214
  public hitFill(point: IPointData, fillRule?: IWindingRule): boolean {
208
- return this.context.isPointInPath(point.x, point.y, fillRule)
215
+ return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y)
209
216
  }
210
217
 
211
218
  public hitStroke(point: IPointData, strokeWidth?: number): boolean {
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { CanvasManager } from './CanvasManager'
2
2
  export { HitCanvasManager } from './HitCanvasManager'
3
3
  export { LeaferCanvasBase, canvasSizeAttrs } from './LeaferCanvasBase'
4
-
4
+ export { canvasPatch } from './patch'
@@ -0,0 +1,7 @@
1
+ import { IPathDrawer } from '@leafer/interface'
2
+
3
+ import { roundRect } from './roundRect'
4
+
5
+ export function canvasPatch(drawer: IPathDrawer): void {
6
+ roundRect(drawer)
7
+ }
@@ -0,0 +1,18 @@
1
+ import { IPathDrawer } from '@leafer/interface'
2
+ import { RectHelper } from '@leafer/path'
3
+
4
+
5
+ const { drawRoundRect } = RectHelper
6
+
7
+ export function roundRect(drawer: IPathDrawer): void {
8
+
9
+ if (drawer && !drawer.roundRect) {
10
+
11
+ drawer.roundRect = function (x: number, y: number, width: number, height: number, cornerRadius: number | number[]): void {
12
+
13
+ drawRoundRect(this as IPathDrawer, x, y, width, height, cornerRadius)
14
+ }
15
+ }
16
+
17
+ }
18
+