cm-chessboard 5.5.13 → 5.5.14

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": "cm-chessboard",
3
- "version": "5.5.13",
3
+ "version": "5.5.14",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -29,11 +29,11 @@ export class RenderVideo extends Extension {
29
29
  this.image = new Image()
30
30
  document.body.append(this.image)
31
31
  this.makeSpriteInline()
32
- this.registerExtensionPoint(EXTENSION_POINT.animation, () => {
33
- if (this.recorder && this.recorder.state === "recording") {
34
- setTimeout(() => {
35
- this.cloneImageAndRender()
36
- })
32
+ this.registerExtensionPoint(EXTENSION_POINT.animation, async (event) => {
33
+ if(event.event = "frame") {
34
+ if (this.recorder && this.recorder.state === "recording") {
35
+ await this.cloneImageAndRender()
36
+ }
37
37
  }
38
38
  })
39
39
  this.registerMethod("recorderInit", () => {
@@ -86,11 +86,11 @@ export class RenderVideo extends Extension {
86
86
  * returns the url of the recorded media
87
87
  */
88
88
  this.registerMethod("recorderStop", () => {
89
- return new Promise((resolve, reject) => {
89
+ return new Promise(async (resolve, reject) => {
90
90
  if (!this.recorder || this.recorder.state !== "recording") {
91
91
  reject("recorder is not recording")
92
92
  }
93
- this.cloneImageAndRender()
93
+ await this.cloneImageAndRender()
94
94
  setTimeout(() => {
95
95
  this.recorder.stop()
96
96
  console.log("recorder", this.recorder.state)
@@ -99,34 +99,37 @@ export class RenderVideo extends Extension {
99
99
  })
100
100
  })
101
101
  this.registerMethod("recorderPause", (ms) => {
102
- return new Promise((resolve) => {
103
- this.cloneImageAndRender()
104
- const interval = setInterval(() => {
105
- this.cloneImageAndRender()
106
- }, 20)
107
- setTimeout(() => {
102
+ return new Promise(async (resolve) => {
103
+ await this.cloneImageAndRender()
104
+ const interval = setInterval(async () => {
105
+ await this.cloneImageAndRender()
106
+ }, 50)
107
+ setTimeout(async () => {
108
108
  clearInterval(interval)
109
- this.cloneImageAndRender()
109
+ await this.cloneImageAndRender()
110
110
  resolve()
111
111
  }, ms)
112
112
  })
113
113
  })
114
114
  }
115
115
 
116
- cloneImageAndRender() {
117
- if(this.rendering) {
118
- return
119
- }
120
- this.rendering = true
121
- let serialized = new XMLSerializer().serializeToString(this.chessboard.view.svg)
122
- const blob = new Blob([serialized], {type: "image/svg+xml"})
123
- const blobURL = URL.createObjectURL(blob)
124
- this.image.onload = () => {
125
- this.context.drawImage(this.image, 0, 0, this.canvas.width, this.canvas.height, 0, 0, this.canvas.width, this.canvas.height)
126
- this.recorder.requestData()
127
- this.rendering = false
128
- }
129
- this.image.src = blobURL
116
+ async cloneImageAndRender() {
117
+ return new Promise((resolve, reject) => {
118
+ if(this.rendering) {
119
+ resolve()
120
+ }
121
+ this.rendering = true
122
+ let serialized = new XMLSerializer().serializeToString(this.chessboard.view.svg)
123
+ const blob = new Blob([serialized], {type: "image/svg+xml"})
124
+ const blobURL = URL.createObjectURL(blob)
125
+ this.image.onload = () => {
126
+ this.context.drawImage(this.image, 0, 0, this.canvas.width, this.canvas.height, 0, 0, this.canvas.width, this.canvas.height)
127
+ this.recorder.requestData()
128
+ this.rendering = false
129
+ resolve()
130
+ }
131
+ this.image.src = blobURL
132
+ })
130
133
  }
131
134
 
132
135
  transferComputedStyle(element) {