@leafer/canvas-web 1.0.0-beta.6 → 1.0.0-beta.8

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-web",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.8",
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.6",
23
- "@leafer/math": "1.0.0-beta.6",
24
- "@leafer/data": "1.0.0-beta.6",
25
- "@leafer/event": "1.0.0-beta.6",
26
- "@leafer/debug": "1.0.0-beta.6"
22
+ "@leafer/canvas": "1.0.0-beta.8",
23
+ "@leafer/math": "1.0.0-beta.8",
24
+ "@leafer/data": "1.0.0-beta.8",
25
+ "@leafer/event": "1.0.0-beta.8",
26
+ "@leafer/platform": "1.0.0-beta.8",
27
+ "@leafer/debug": "1.0.0-beta.8"
27
28
  },
28
29
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-beta.6"
30
+ "@leafer/interface": "1.0.0-beta.8"
30
31
  }
31
32
  }
@@ -1,7 +1,8 @@
1
- import { ICanvasContext2D, IAutoBounds, ISizeData, IScreenSizeData, IResizeEventListener } from '@leafer/interface'
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
- if (this.autoLayout) style.display || (style.display = 'block')
28
+ style.display || (style.display = 'block')
28
29
  this.parentView = (this.view as HTMLCanvasElement).parentElement
29
30
  }
30
31
 
@@ -39,11 +40,6 @@ export class LeaferCanvas extends LeaferCanvasBase {
39
40
  public set hittable(hittable: boolean) { (this.view as HTMLElement).style.pointerEvents = hittable ? 'auto' : 'none' }
40
41
  public get hittable() { return (this.view as HTMLElement).style.pointerEvents !== 'none' }
41
42
 
42
- protected __createContext(): void {
43
- this.context = this.view.getContext('2d') as ICanvasContext2D
44
- this.__bindContext()
45
- }
46
-
47
43
  protected __createView(): void {
48
44
  if (this.offscreen) {
49
45
  try {
@@ -104,6 +100,11 @@ export class LeaferCanvas extends LeaferCanvasBase {
104
100
 
105
101
  this.view.width = width * pixelRatio
106
102
  this.view.height = height * pixelRatio
103
+
104
+ }
105
+
106
+ public updateClientBounds(): void {
107
+ if (!this.offscreen) this.clientBounds = (this.view as HTMLCanvasElement).getBoundingClientRect()
107
108
  }
108
109
 
109
110
  public startAutoLayout(autoBounds: IAutoBounds, listener: IResizeEventListener): void {
@@ -113,6 +114,7 @@ export class LeaferCanvas extends LeaferCanvasBase {
113
114
  try {
114
115
 
115
116
  this.resizeObserver = new ResizeObserver((entries) => {
117
+ this.updateClientBounds()
116
118
  for (const entry of entries) this.checkAutoBounds(entry.contentRect)
117
119
  })
118
120
 
@@ -133,7 +135,7 @@ export class LeaferCanvas extends LeaferCanvasBase {
133
135
  protected imitateResizeObserver(): void {
134
136
  if (this.autoLayout) {
135
137
  if (this.parentView) this.checkAutoBounds(this.parentView.getBoundingClientRect())
136
- window.requestAnimationFrame(this.imitateResizeObserver.bind(this))
138
+ Platform.requestRender(this.imitateResizeObserver.bind(this))
137
139
  }
138
140
  }
139
141