@leafer/canvas-web 1.0.0-beta → 1.0.0-beta.10
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 +8 -7
- package/src/LeaferCanvas.ts +16 -18
- package/src/index.ts +4 -2
- package/src/patch/index.ts +0 -5
- package/src/patch/roundRect.ts +0 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/canvas-web",
|
|
3
|
-
"version": "1.0.0-beta",
|
|
3
|
+
"version": "1.0.0-beta.10",
|
|
4
4
|
"description": "@leafer/canvas-web",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,13 +19,14 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/canvas": "1.0.0-beta",
|
|
23
|
-
"@leafer/math": "1.0.0-beta",
|
|
24
|
-
"@leafer/data": "1.0.0-beta",
|
|
25
|
-
"@leafer/event": "1.0.0-beta",
|
|
26
|
-
"@leafer/
|
|
22
|
+
"@leafer/canvas": "1.0.0-beta.10",
|
|
23
|
+
"@leafer/math": "1.0.0-beta.10",
|
|
24
|
+
"@leafer/data": "1.0.0-beta.10",
|
|
25
|
+
"@leafer/event": "1.0.0-beta.10",
|
|
26
|
+
"@leafer/platform": "1.0.0-beta.10",
|
|
27
|
+
"@leafer/debug": "1.0.0-beta.10"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.0.0-beta"
|
|
30
|
+
"@leafer/interface": "1.0.0-beta.10"
|
|
30
31
|
}
|
|
31
32
|
}
|
package/src/LeaferCanvas.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IAutoBounds, ISizeData, IScreenSizeData, IResizeEventListener } from '@leafer/interface'
|
|
2
2
|
import { LeaferCanvasBase, canvasSizeAttrs } from '@leafer/canvas'
|
|
3
3
|
import { ResizeEvent } from '@leafer/event'
|
|
4
4
|
import { DataHelper } from '@leafer/data'
|
|
5
|
+
import { Platform } from '@leafer/platform'
|
|
5
6
|
import { Debug } from '@leafer/debug'
|
|
6
7
|
|
|
7
8
|
|
|
@@ -24,7 +25,7 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
24
25
|
} else {
|
|
25
26
|
view ? this.__createViewFrom(view) : this.__createView()
|
|
26
27
|
const { style } = this.view as HTMLCanvasElement
|
|
27
|
-
|
|
28
|
+
style.display || (style.display = 'block')
|
|
28
29
|
this.parentView = (this.view as HTMLCanvasElement).parentElement
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -33,20 +34,11 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
33
34
|
if (!this.autoLayout) this.resize(this.config as IScreenSizeData)
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
public
|
|
37
|
-
|
|
38
|
-
view.style.backgroundColor = color
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public setHittable(hittable: boolean): void {
|
|
42
|
-
const view = this.view as HTMLElement
|
|
43
|
-
view.style.pointerEvents = hittable ? 'auto' : 'none'
|
|
44
|
-
}
|
|
37
|
+
public set backgroundColor(color: string) { (this.view as HTMLElement).style.backgroundColor = color }
|
|
38
|
+
public get backgroundColor(): string { return (this.view as HTMLElement).style.backgroundColor }
|
|
45
39
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.__bindContext()
|
|
49
|
-
}
|
|
40
|
+
public set hittable(hittable: boolean) { (this.view as HTMLElement).style.pointerEvents = hittable ? 'auto' : 'none' }
|
|
41
|
+
public get hittable() { return (this.view as HTMLElement).style.pointerEvents !== 'none' }
|
|
50
42
|
|
|
51
43
|
protected __createView(): void {
|
|
52
44
|
if (this.offscreen) {
|
|
@@ -97,8 +89,8 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
97
89
|
}
|
|
98
90
|
}
|
|
99
91
|
|
|
100
|
-
public
|
|
101
|
-
const { width, height, pixelRatio } =
|
|
92
|
+
public updateViewSize(): void {
|
|
93
|
+
const { width, height, pixelRatio } = this
|
|
102
94
|
|
|
103
95
|
if (!this.offscreen) {
|
|
104
96
|
const { style } = this.view as HTMLCanvasElement
|
|
@@ -108,6 +100,11 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
108
100
|
|
|
109
101
|
this.view.width = width * pixelRatio
|
|
110
102
|
this.view.height = height * pixelRatio
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public updateClientBounds(): void {
|
|
107
|
+
if (!this.offscreen) this.clientBounds = (this.view as HTMLCanvasElement).getBoundingClientRect()
|
|
111
108
|
}
|
|
112
109
|
|
|
113
110
|
public startAutoLayout(autoBounds: IAutoBounds, listener: IResizeEventListener): void {
|
|
@@ -117,6 +114,7 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
117
114
|
try {
|
|
118
115
|
|
|
119
116
|
this.resizeObserver = new ResizeObserver((entries) => {
|
|
117
|
+
this.updateClientBounds()
|
|
120
118
|
for (const entry of entries) this.checkAutoBounds(entry.contentRect)
|
|
121
119
|
})
|
|
122
120
|
|
|
@@ -137,7 +135,7 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
137
135
|
protected imitateResizeObserver(): void {
|
|
138
136
|
if (this.autoLayout) {
|
|
139
137
|
if (this.parentView) this.checkAutoBounds(this.parentView.getBoundingClientRect())
|
|
140
|
-
|
|
138
|
+
Platform.requestRender(this.imitateResizeObserver.bind(this))
|
|
141
139
|
}
|
|
142
140
|
}
|
|
143
141
|
|
package/src/index.ts
CHANGED
package/src/patch/index.ts
DELETED
package/src/patch/roundRect.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { IObject, IPathDrawer } from '@leafer/interface'
|
|
2
|
-
import { RectHelper } from '@leafer/path'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { drawRoundRect } = RectHelper
|
|
6
|
-
|
|
7
|
-
export function roundRect(): void {
|
|
8
|
-
|
|
9
|
-
const canvas = CanvasRenderingContext2D.prototype as IPathDrawer
|
|
10
|
-
|
|
11
|
-
if (!canvas.roundRect) {
|
|
12
|
-
|
|
13
|
-
canvas.roundRect = (Path2D.prototype as IObject).roundRect = function (x: number, y: number, width: number, height: number, cornerRadius: number | number[]): void {
|
|
14
|
-
|
|
15
|
-
drawRoundRect(this as IPathDrawer, x, y, width, height, cornerRadius)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|