@percy/dom 1.0.0-beta.75 → 1.0.0-beta.76
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/README.md +7 -0
- package/dist/bundle.js +20 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ Serializes a document's DOM into a DOM string suitable for re-rendering.
|
|
|
11
11
|
- [Frame elements](#frame-elements)
|
|
12
12
|
- [CSSOM rules](#cssom-rules)
|
|
13
13
|
- [Canvas elements](#canvas-elements)
|
|
14
|
+
- [Video elements](#video-elements)
|
|
14
15
|
- [Other elements](#other-elements)
|
|
15
16
|
|
|
16
17
|
## Usage
|
|
@@ -64,6 +65,12 @@ with image elements. The image elements reference the serialized data URI and ha
|
|
|
64
65
|
attributes as their respective canvas elements. The image elements also have a max-width of 100% to
|
|
65
66
|
accomidate responsive layouts in situations where canvases may be expected to resize with JS.
|
|
66
67
|
|
|
68
|
+
### Video elements
|
|
69
|
+
|
|
70
|
+
Videos without a `poster` attribute will have the current frame of the video
|
|
71
|
+
serialized into an image and set as the `poster` attribute automatically. This is
|
|
72
|
+
to ensure videos have a stable image to display when screenshots are captured.
|
|
73
|
+
|
|
67
74
|
### Other elements
|
|
68
75
|
|
|
69
76
|
_All other elements are not serialized._ The resulting cloned document is passed to any provided
|
package/dist/bundle.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
function prepareDOM(dom) {
|
|
16
|
-
for (let elem of dom.querySelectorAll('input, textarea, select, iframe, canvas')) {
|
|
16
|
+
for (let elem of dom.querySelectorAll('input, textarea, select, iframe, canvas, video')) {
|
|
17
17
|
if (!elem.getAttribute('data-percy-element-id')) {
|
|
18
18
|
elem.setAttribute('data-percy-element-id', uid());
|
|
19
19
|
}
|
|
@@ -157,6 +157,24 @@
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
// Captures the current frame of videos and sets the poster image
|
|
161
|
+
function serializeVideos(dom, clone) {
|
|
162
|
+
for (let video of dom.querySelectorAll('video')) {
|
|
163
|
+
// If the video already has a poster image, no work for us to do
|
|
164
|
+
if (video.getAttribute('poster')) continue;
|
|
165
|
+
let videoId = video.getAttribute('data-percy-element-id');
|
|
166
|
+
let cloneEl = clone.querySelector(`[data-percy-element-id="${videoId}"]`);
|
|
167
|
+
let canvas = document.createElement('canvas');
|
|
168
|
+
let width = canvas.width = video.videoWidth;
|
|
169
|
+
let height = canvas.height = video.videoHeight;
|
|
170
|
+
canvas.getContext('2d').drawImage(video, 0, 0, width, height);
|
|
171
|
+
let dataUrl = canvas.toDataURL(); // If the canvas produces a blank image, skip
|
|
172
|
+
|
|
173
|
+
if (!dataUrl || dataUrl === 'data:,') continue;
|
|
174
|
+
cloneEl.setAttribute('poster', dataUrl);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
160
178
|
function doctype(dom) {
|
|
161
179
|
var _dom$doctype;
|
|
162
180
|
|
|
@@ -192,6 +210,7 @@
|
|
|
192
210
|
serializeFrames(dom, clone, {
|
|
193
211
|
enableJavaScript
|
|
194
212
|
});
|
|
213
|
+
serializeVideos(dom, clone);
|
|
195
214
|
|
|
196
215
|
if (!enableJavaScript) {
|
|
197
216
|
serializeCSSOM(dom, clone);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/dom",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.76",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"interactor.js": "^2.0.0-beta.10"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "445af68d8e270e2a35fc74e26422ed5d3c91d2ae"
|
|
38
38
|
}
|