@leafer/canvas-web 1.3.2 → 1.4.0
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 +3 -3
- package/src/LeaferCanvas.ts +9 -7
- package/types/index.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/canvas-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "@leafer/canvas-web",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.
|
|
25
|
+
"@leafer/core": "1.4.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.
|
|
28
|
+
"@leafer/interface": "1.4.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/LeaferCanvas.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAutoBounds, ISizeData, IScreenSizeData, IResizeEventListener } from '@leafer/interface'
|
|
1
|
+
import { IAutoBounds, ISizeData, IScreenSizeData, IResizeEventListener, IFunction } from '@leafer/interface'
|
|
2
2
|
import { LeaferCanvasBase, canvasSizeAttrs, ResizeEvent, DataHelper, Platform, Debug } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
|
|
@@ -31,6 +31,7 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
31
31
|
protected resizeObserver: ResizeObserver
|
|
32
32
|
protected autoBounds: IAutoBounds
|
|
33
33
|
protected resizeListener: IResizeEventListener
|
|
34
|
+
protected windowListener: IFunction
|
|
34
35
|
|
|
35
36
|
public init(): void {
|
|
36
37
|
const { config } = this
|
|
@@ -154,7 +155,7 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
154
155
|
} else {
|
|
155
156
|
|
|
156
157
|
// check devicePixelRatio change
|
|
157
|
-
window.addEventListener('resize', () => {
|
|
158
|
+
window.addEventListener('resize', this.windowListener = () => {
|
|
158
159
|
const pixelRatio = Platform.devicePixelRatio
|
|
159
160
|
if (this.pixelRatio !== pixelRatio) {
|
|
160
161
|
const { width, height } = this
|
|
@@ -187,11 +188,8 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
187
188
|
|
|
188
189
|
public stopAutoLayout(): void {
|
|
189
190
|
this.autoLayout = false
|
|
190
|
-
this.
|
|
191
|
-
|
|
192
|
-
this.resizeObserver.disconnect()
|
|
193
|
-
this.resizeObserver = null
|
|
194
|
-
}
|
|
191
|
+
if (this.resizeObserver) this.resizeObserver.disconnect()
|
|
192
|
+
this.resizeListener = this.resizeObserver = null
|
|
195
193
|
}
|
|
196
194
|
|
|
197
195
|
protected emitResize(size: IScreenSizeData): void {
|
|
@@ -215,6 +213,10 @@ export class LeaferCanvas extends LeaferCanvasBase {
|
|
|
215
213
|
public destroy(): void {
|
|
216
214
|
if (this.view) {
|
|
217
215
|
this.stopAutoLayout()
|
|
216
|
+
if (this.windowListener) {
|
|
217
|
+
window.removeEventListener('resize', this.windowListener)
|
|
218
|
+
this.windowListener = null
|
|
219
|
+
}
|
|
218
220
|
if (!this.unreal) {
|
|
219
221
|
const view = this.view
|
|
220
222
|
if (view.parentElement) view.remove()
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAutoBounds, IResizeEventListener, ISizeData, IScreenSizeData } from '@leafer/interface';
|
|
1
|
+
import { IAutoBounds, IResizeEventListener, IFunction, ISizeData, IScreenSizeData } from '@leafer/interface';
|
|
2
2
|
import { LeaferCanvasBase } from '@leafer/core';
|
|
3
3
|
|
|
4
4
|
declare class LeaferCanvas extends LeaferCanvasBase {
|
|
@@ -9,6 +9,7 @@ declare class LeaferCanvas extends LeaferCanvasBase {
|
|
|
9
9
|
protected resizeObserver: ResizeObserver;
|
|
10
10
|
protected autoBounds: IAutoBounds;
|
|
11
11
|
protected resizeListener: IResizeEventListener;
|
|
12
|
+
protected windowListener: IFunction;
|
|
12
13
|
init(): void;
|
|
13
14
|
set backgroundColor(color: string);
|
|
14
15
|
get backgroundColor(): string;
|