@percy/dom 1.30.8 → 1.30.9-alpha-1.0

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.
Files changed (2) hide show
  1. package/dist/bundle.js +56 -4
  2. package/package.json +3 -3
package/dist/bundle.js CHANGED
@@ -314,9 +314,21 @@
314
314
  /* istanbul ignore next: tested, but coverage is stripped */
315
315
  if (clone.constructor.name === 'HTMLDocument' || clone.constructor.name === 'DocumentFragment') {
316
316
  // handle document and iframe
317
- clone.body.prepend(styleLink);
317
+ // We are checking if we have multiple stylesheets present for the same clone or clone.body then we add
318
+ // them in the same order in which we receive them.
319
+ const lastLink = clone.body.querySelector('link[data-percy-adopted-stylesheets-serialized]:last-of-type');
320
+ if (lastLink) {
321
+ lastLink.after(styleLink);
322
+ } else {
323
+ clone.body.prepend(styleLink);
324
+ }
318
325
  } else if (clone.constructor.name === 'ShadowRoot') {
319
- clone.prepend(styleLink);
326
+ const lastLink = clone.querySelector('link[data-percy-adopted-stylesheets-serialized]:last-of-type');
327
+ if (lastLink) {
328
+ lastLink.after(styleLink);
329
+ } else {
330
+ clone.prepend(styleLink);
331
+ }
320
332
  }
321
333
  }
322
334
  } else {
@@ -486,12 +498,30 @@
486
498
  */
487
499
 
488
500
  const ignoreTags = ['NOSCRIPT'];
501
+ function cloneCustomElementWithoutAttributeChanged(element) {
502
+ if (!element.attributeChangedCallback || !element.tagName.includes('-')) {
503
+ return element.cloneNode(); // Standard clone for non-custom elements
504
+ }
505
+ const cloned = document.createElement('data-percy-custom-element-' + element.tagName);
506
+
507
+ // Clone attributes without triggering attributeChangedCallback
508
+ for (const attr of element.attributes) {
509
+ // handle src separately
510
+ if (attr.name.toLowerCase() === 'src') {
511
+ cloned.setAttribute('data-percy-serialized-attribute-src', attr.value);
512
+ } else {
513
+ cloned.setAttribute(attr.name, attr.value);
514
+ }
515
+ }
516
+ return cloned;
517
+ }
489
518
  function cloneNodeAndShadow(ctx) {
490
519
  let {
491
520
  dom,
492
521
  disableShadowDOM,
493
522
  resources,
494
- cache
523
+ cache,
524
+ enableJavaScript
495
525
  } = ctx;
496
526
  // clones shadow DOM and light DOM for a given node
497
527
  let cloneNode = (node, parent) => {
@@ -507,7 +537,28 @@
507
537
 
508
538
  // mark the node before cloning
509
539
  markElement(node, disableShadowDOM);
510
- let clone = node.cloneNode();
540
+ let clone = cloneCustomElementWithoutAttributeChanged(node);
541
+ // let clone = node.cloneNode();
542
+
543
+ // Handle <style> tag specifically for media queries
544
+ if (node.nodeName === 'STYLE' && !enableJavaScript) {
545
+ var _node$textContent;
546
+ let cssText = ((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : _node$textContent.trim()) || '';
547
+ if (!cssText && node.sheet) {
548
+ try {
549
+ const cssRules = node.sheet.cssRules;
550
+ if (cssRules && cssRules.length > 0) {
551
+ cssText = Array.from(cssRules).map(rule => rule.cssText).join('\n');
552
+ }
553
+ } catch (_) {
554
+ // ignore errors
555
+ }
556
+ }
557
+ if (cssText) {
558
+ clone.textContent = cssText;
559
+ clone.setAttribute('data-percy-cssom-serialized', 'true');
560
+ }
561
+ }
511
562
 
512
563
  // We apply any element transformations here to avoid another treeWalk
513
564
  applyElementTransformations(clone);
@@ -608,6 +659,7 @@
608
659
  shadowRootElements: ctx.shadowRootElements
609
660
  });
610
661
  // replace serialized data attributes with real attributes
662
+ html = html.replace(/(<\/?)data-percy-custom-element-/g, '$1');
611
663
  html = html.replace(/ data-percy-serialized-attribute-(\w+?)=/ig, ' $1=');
612
664
  // include the doctype with the html string
613
665
  return doctype(ctx.dom) + html;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/dom",
3
- "version": "1.30.8",
3
+ "version": "1.30.9-alpha-1.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "publishConfig": {
11
11
  "access": "public",
12
- "tag": "latest"
12
+ "tag": "alpha"
13
13
  },
14
14
  "main": "dist/bundle.js",
15
15
  "browser": "dist/bundle.js",
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "interactor.js": "^2.0.0-beta.10"
37
37
  },
38
- "gitHead": "daa3c96d70488a49671e48427c9b363c68876935"
38
+ "gitHead": "c9741e74fdbd7d2c152bcdcb619e9b5c1da13be6"
39
39
  }