cm-chessboard 5.5.1 → 5.5.3
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.
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
<p>Works in Chrome.</p>
|
|
14
14
|
<div class="board board-small" id="board"></div>
|
|
15
15
|
<video id="videoOut" controls="controls"></video>
|
|
16
|
-
<br style="clear: both"/>
|
|
17
|
-
|
|
18
16
|
<script type="module">
|
|
19
17
|
import {RenderVideo} from "../../src/cm-chessboard/extensions/render-video/RenderVideo.js"
|
|
20
18
|
import {Chessboard} from "../../src/cm-chessboard/Chessboard.js"
|
|
@@ -33,18 +31,17 @@
|
|
|
33
31
|
chessboard.recorderStart()
|
|
34
32
|
setTimeout(() => {
|
|
35
33
|
chessboard.movePiece("e2", "e4", true).then(() => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
chessboard.movePiece("e7", "e5", true).then(() => {
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
const url = chessboard.recorderStop()
|
|
38
|
+
const video = document.getElementById("videoOut")
|
|
39
|
+
video.src = url
|
|
40
|
+
}, 100)
|
|
41
|
+
})
|
|
42
|
+
}, 400)
|
|
44
43
|
})
|
|
45
|
-
|
|
46
44
|
}, 500)
|
|
47
|
-
|
|
48
45
|
</script>
|
|
49
46
|
</body>
|
|
50
47
|
</html>
|
package/package.json
CHANGED
|
@@ -17,24 +17,26 @@ export class RenderVideo extends Extension {
|
|
|
17
17
|
this.images = []
|
|
18
18
|
this.makeSpriteInline()
|
|
19
19
|
this.registerExtensionPoint(EXTENSION_POINT.animation, () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
context.drawImage(image, 0, 0, this.canvas.width, this.canvas.height)
|
|
20
|
+
if(this.recorder && this.recorder.state === "recording") {
|
|
21
|
+
let clonedSvgElement = this.chessboard.view.svg.cloneNode(true)
|
|
22
|
+
let serialized = new XMLSerializer().serializeToString(clonedSvgElement)
|
|
23
|
+
const blob = new Blob([serialized], {type: "image/svg+xml"})
|
|
24
|
+
const blobURL = URL.createObjectURL(blob)
|
|
25
|
+
const image = new Image()
|
|
26
|
+
this.images.push(image)
|
|
27
|
+
image.onload = () => {
|
|
28
|
+
let context = this.canvas.getContext('2d')
|
|
29
|
+
context.drawImage(image, 0, 0, this.canvas.width, this.canvas.height)
|
|
30
|
+
this.recorder.requestData()
|
|
31
|
+
}
|
|
32
|
+
image.src = blobURL
|
|
34
33
|
}
|
|
35
|
-
image.src = blobURL
|
|
36
34
|
})
|
|
37
35
|
this.registerMethod("recorderStart", () => {
|
|
36
|
+
if(this.recorder && this.recorder.state === "recording") {
|
|
37
|
+
console.error("recorder is running")
|
|
38
|
+
return
|
|
39
|
+
}
|
|
38
40
|
let all = document.querySelectorAll("svg *")
|
|
39
41
|
for (let i = 0; i < all.length; i++) {
|
|
40
42
|
this.transferComputedStyle(all[i])
|
|
@@ -49,18 +51,22 @@ export class RenderVideo extends Extension {
|
|
|
49
51
|
this.recorder = new MediaRecorder(this.stream, {mimeType: this.props.mediaType})
|
|
50
52
|
this.recordedData = []
|
|
51
53
|
this.recorder.ondataavailable = (event) => {
|
|
52
|
-
// console.log(event)
|
|
53
54
|
if (event.data && event.data.size) {
|
|
54
55
|
this.recordedData.push(event.data)
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
this.recorder.start(
|
|
58
|
+
this.recorder.start()
|
|
59
|
+
this.recorder.requestData()
|
|
58
60
|
console.log("recorder", this.recorder.state)
|
|
59
61
|
})
|
|
60
62
|
/**
|
|
61
63
|
* returns the url of the recorded media
|
|
62
64
|
*/
|
|
63
65
|
this.registerMethod("recorderStop", () => {
|
|
66
|
+
if(!this.recorder || this.recorder.state !== "recording") {
|
|
67
|
+
console.error("recorder is not recording")
|
|
68
|
+
return
|
|
69
|
+
}
|
|
64
70
|
this.recorder.stop()
|
|
65
71
|
console.log("recorder", this.recorder.state)
|
|
66
72
|
return URL.createObjectURL(new Blob(this.recordedData, {type: this.props.mediaType}))
|
|
@@ -71,7 +77,7 @@ export class RenderVideo extends Extension {
|
|
|
71
77
|
const computedStyle = getComputedStyle(element, null)
|
|
72
78
|
for (let i = 0; i < computedStyle.length; i++) {
|
|
73
79
|
const style = computedStyle[i] + ""
|
|
74
|
-
if (
|
|
80
|
+
if (["fill", "stroke", "stroke-width", "font-size"].includes(style)) {
|
|
75
81
|
element.style[style] = computedStyle[style]
|
|
76
82
|
}
|
|
77
83
|
}
|