cm-chessboard 5.5.10 → 5.5.11
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.
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<h2>Example: RenderVideo extension</h2>
|
|
13
13
|
<p>Works in Chrome (webm) and Safari (mp4).</p>
|
|
14
14
|
<div class="board board-small" id="board"></div>
|
|
15
|
-
<video id="videoOut" controls="controls"
|
|
15
|
+
<video id="videoOut" controls="controls"></video>
|
|
16
16
|
<script type="module">
|
|
17
17
|
import {RenderVideo} from "../../src/cm-chessboard/extensions/render-video/RenderVideo.js"
|
|
18
18
|
import {Chessboard} from "../../src/cm-chessboard/Chessboard.js"
|
package/package.json
CHANGED
|
@@ -26,7 +26,8 @@ export class RenderVideo extends Extension {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
console.log("recorder mediaType", this.props.mediaType)
|
|
29
|
-
this.
|
|
29
|
+
this.image = new Image()
|
|
30
|
+
document.body.append(this.image)
|
|
30
31
|
this.makeSpriteInline()
|
|
31
32
|
this.registerExtensionPoint(EXTENSION_POINT.animation, (event) => {
|
|
32
33
|
if (this.recorder && this.recorder.state === "recording") {
|
|
@@ -51,6 +52,14 @@ export class RenderVideo extends Extension {
|
|
|
51
52
|
this.canvas.width = dimensions.width
|
|
52
53
|
this.canvas.height = dimensions.height
|
|
53
54
|
this.contect = this.canvas.getContext('2d')
|
|
55
|
+
|
|
56
|
+
this.image = new Image()
|
|
57
|
+
this.image.width = this.canvas.width
|
|
58
|
+
this.image.height = this.canvas.height
|
|
59
|
+
this.image.style.position = "absolute"
|
|
60
|
+
this.image.style.visibility = "hidden"
|
|
61
|
+
document.body.append(this.image)
|
|
62
|
+
|
|
54
63
|
document.body.append(this.canvas)
|
|
55
64
|
this.stream = this.canvas.captureStream()
|
|
56
65
|
this.recorder = new MediaRecorder(this.stream, {mimeType: this.props.mediaType})
|
|
@@ -79,7 +88,7 @@ export class RenderVideo extends Extension {
|
|
|
79
88
|
this.recorder.stop()
|
|
80
89
|
console.log("recorder", this.recorder.state)
|
|
81
90
|
resolve(URL.createObjectURL(new Blob(this.recordedData, {type: this.props.mediaType})))
|
|
82
|
-
},
|
|
91
|
+
}, 200)
|
|
83
92
|
})
|
|
84
93
|
})
|
|
85
94
|
}
|
|
@@ -88,19 +97,10 @@ export class RenderVideo extends Extension {
|
|
|
88
97
|
let serialized = new XMLSerializer().serializeToString(this.chessboard.view.svg)
|
|
89
98
|
const blob = new Blob([serialized], {type: "image/svg+xml"})
|
|
90
99
|
const blobURL = URL.createObjectURL(blob)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// needed for safari
|
|
94
|
-
image.width = this.canvas.width
|
|
95
|
-
image.height = this.canvas.height
|
|
96
|
-
image.style.position = "absolute"
|
|
97
|
-
image.style.visibility = "hidden"
|
|
98
|
-
//
|
|
99
|
-
document.body.append(image)
|
|
100
|
-
image.onload = () => {
|
|
101
|
-
this.contect.drawImage(image, 0, 0, this.canvas.width, this.canvas.height, 0, 0, this.canvas.width, this.canvas.height)
|
|
100
|
+
this.image.onload = () => {
|
|
101
|
+
this.contect.drawImage(this.image, 0, 0, this.canvas.width, this.canvas.height, 0, 0, this.canvas.width, this.canvas.height)
|
|
102
102
|
}
|
|
103
|
-
image.src = blobURL
|
|
103
|
+
this.image.src = blobURL
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
transferComputedStyle(element) {
|