@leafer/canvas-web 1.0.0-beta.11 → 1.0.0-beta.12

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.
Files changed (2) hide show
  1. package/package.json +8 -8
  2. package/src/LeaferCanvas.ts +25 -41
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/canvas-web",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.12",
4
4
  "description": "@leafer/canvas-web",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,14 +19,14 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "dependencies": {
22
- "@leafer/canvas": "1.0.0-beta.11",
23
- "@leafer/math": "1.0.0-beta.11",
24
- "@leafer/data": "1.0.0-beta.11",
25
- "@leafer/event": "1.0.0-beta.11",
26
- "@leafer/platform": "1.0.0-beta.11",
27
- "@leafer/debug": "1.0.0-beta.11"
22
+ "@leafer/canvas": "1.0.0-beta.12",
23
+ "@leafer/math": "1.0.0-beta.12",
24
+ "@leafer/data": "1.0.0-beta.12",
25
+ "@leafer/event": "1.0.0-beta.12",
26
+ "@leafer/platform": "1.0.0-beta.12",
27
+ "@leafer/debug": "1.0.0-beta.12"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.0.0-beta.11"
30
+ "@leafer/interface": "1.0.0-beta.12"
31
31
  }
32
32
  }
@@ -20,14 +20,10 @@ export class LeaferCanvas extends LeaferCanvasBase {
20
20
  public init(): void {
21
21
  const { view } = this.config
22
22
 
23
- if (this.offscreen) {
24
- view ? this.view = view as OffscreenCanvas : this.__createView()
25
- } else {
26
- view ? this.__createViewFrom(view) : this.__createView()
27
- const { style } = this.view as HTMLCanvasElement
28
- style.display || (style.display = 'block')
29
- this.parentView = (this.view as HTMLCanvasElement).parentElement
30
- }
23
+ view ? this.__createViewFrom(view) : this.__createView()
24
+ const { style } = this.view as HTMLCanvasElement
25
+ style.display || (style.display = 'block')
26
+ this.parentView = (this.view as HTMLCanvasElement).parentElement
31
27
 
32
28
  this.__createContext()
33
29
 
@@ -41,14 +37,6 @@ export class LeaferCanvas extends LeaferCanvasBase {
41
37
  public get hittable() { return (this.view as HTMLElement).style.pointerEvents !== 'none' }
42
38
 
43
39
  protected __createView(): void {
44
- if (this.offscreen) {
45
- try {
46
- this.view = new OffscreenCanvas(1, 1)
47
- return
48
- } catch (e) {
49
- debug.error(e)
50
- }
51
- }
52
40
  this.view = document.createElement('canvas')
53
41
  }
54
42
 
@@ -92,11 +80,9 @@ export class LeaferCanvas extends LeaferCanvasBase {
92
80
  public updateViewSize(): void {
93
81
  const { width, height, pixelRatio } = this
94
82
 
95
- if (!this.offscreen) {
96
- const { style } = this.view as HTMLCanvasElement
97
- style.width = width + 'px'
98
- style.height = height + 'px'
99
- }
83
+ const { style } = this.view as HTMLCanvasElement
84
+ style.width = width + 'px'
85
+ style.height = height + 'px'
100
86
 
101
87
  this.view.width = width * pixelRatio
102
88
  this.view.height = height * pixelRatio
@@ -104,31 +90,29 @@ export class LeaferCanvas extends LeaferCanvasBase {
104
90
  }
105
91
 
106
92
  public updateClientBounds(): void {
107
- if (!this.offscreen) this.clientBounds = (this.view as HTMLCanvasElement).getBoundingClientRect()
93
+ this.clientBounds = (this.view as HTMLCanvasElement).getBoundingClientRect()
108
94
  }
109
95
 
110
96
  public startAutoLayout(autoBounds: IAutoBounds, listener: IResizeEventListener): void {
111
- if (!this.offscreen) {
112
- this.autoBounds = autoBounds
113
- this.resizeListener = listener
114
- try {
115
-
116
- this.resizeObserver = new ResizeObserver((entries) => {
117
- this.updateClientBounds()
118
- for (const entry of entries) this.checkAutoBounds(entry.contentRect)
119
- })
120
-
121
- const parent = this.parentView
122
- if (parent) {
123
- this.resizeObserver.observe(parent)
124
- this.checkAutoBounds(parent.getBoundingClientRect())
125
- }
97
+ this.autoBounds = autoBounds
98
+ this.resizeListener = listener
99
+ try {
100
+
101
+ this.resizeObserver = new ResizeObserver((entries) => {
102
+ this.updateClientBounds()
103
+ for (const entry of entries) this.checkAutoBounds(entry.contentRect)
104
+ })
105
+
106
+ const parent = this.parentView
107
+ if (parent) {
108
+ this.resizeObserver.observe(parent)
109
+ this.checkAutoBounds(parent.getBoundingClientRect())
110
+ }
126
111
 
127
- } catch (e) {
112
+ } catch (e) {
128
113
 
129
- this.imitateResizeObserver()
114
+ this.imitateResizeObserver()
130
115
 
131
- }
132
116
  }
133
117
  }
134
118
 
@@ -177,7 +161,7 @@ export class LeaferCanvas extends LeaferCanvasBase {
177
161
  public destroy(): void {
178
162
  if (this.view) {
179
163
  this.stopAutoLayout()
180
- if (!this.unreal && !this.offscreen) {
164
+ if (!this.unreal) {
181
165
  const view = this.view as HTMLCanvasElement
182
166
  if (view.parentElement) view.remove()
183
167
  }