{"name":"@percy/dom","version":"1.6.2","license":"MIT","_id":"@percy/dom@1.6.2","homepage":"https://github.com/percy/cli#readme","bugs":{"url":"https://github.com/percy/cli/issues"},"dist":{"shasum":"a2b64e5a0c18667a56d4a0431bdad136b1291031","tarball":"http://registry-npm.ywwl.com/@percy/dom/download/@percy/dom-1.6.2.tgz","fileCount":4,"integrity":"sha512-sFLULxc/zNp7lGTKPw7Qexy3RdsoT+tWFvKTEmAAr+lip3HMzbCIe26uvZUDUBr0d/hxCqf3i2uXxsIQF7S/kw==","signatures":[{"sig":"MEQCIEtdeWElyhkyp4G0IDFiDIdxAz/zwyDscydt1nOyR+9hAiBUx81n2fcZqWVMkeFcGERYLyenToDwdTYK4gI1sMujjQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14048,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi2Dq/ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrPrA//XAa1Jb5zmkKuSw8u6ggMHuY+K80Vu5qNkdKmOo0EMxw/kV5+\r\n/3UZU6SVq9lj73sS4fc44vbpBnRzfemPPpqG4znZrKuY6cxocA+33mhVZxIL\r\n/PQAp4Cp+8M66kIRByWWkFe49CncacjugRUHWaRm4OmwoxnT881Urm6PFpBl\r\nTG14RJB2dlDQGIEGc09NvcrgrCunD3vPbKeCd7jCV4M9dozNSSA21HvM3zs/\r\n9FYVq7BGEGaAp2GscUqN2CvbadfqpeiIIGSZPoL4BlLVn01/DLXe0XwN33Kk\r\nCGpZdwEzfGTDGUjfKrm8DdABdl/Myo5DwNPzoIXwsZ9/p9SCP4g3X5akCZhB\r\nm982VeY5OV2Ny+7W6fjXauw6OrkX1xtVELASD9N5IjOZUM0OwSuG4bpHD6YO\r\n/u9MTQdoSBfVLQTLO6N4NgCWmBYgWXb2v0k5Z1fOaLrt8GxIojn0LBc0PHBL\r\nyWfhPlunO96FuOHrKcayuTQLT7ISNzZ1MJiTNn7jIqL/TPukpESrYELYjceK\r\nyzAB3Ny+497kjBn+qIFDwS/cJcWD23/6PJdI7BTVxvSseRSLXRvnFuOjmhFh\r\nHvtonKULgHJ5U8Z3a1zD6YPKE8rLkLbyIKxrlfbO/as+RdkgfyjfMTZ8EHTO\r\no+iAmIeuUXTwjONN3ohLiREfKQ0DFVQ254o=\r\n=CL9W\r\n-----END PGP SIGNATURE-----\r\n","size":5126,"noattachment":false,"key":"/@percy/dom/-/@percy/dom-1.6.2.tgz"},"main":"dist/bundle.js","rollup":{"test":{"output":{"exports":"named"}},"output":{"name":"PercyDOM"}},"browser":"dist/bundle.js","gitHead":"c033d52167cdd5873027d9de2676f3fc9f55ef2d","scripts":{"lint":"eslint --ignore-path ../../.gitignore .","test":"node ../../scripts/test","build":"node ../../scripts/build","test:coverage":"yarn test --coverage"},"_npmUser":{"name":"percy-admin","email":"apps+npm@percy.io"},"repository":{"url":"git+https://github.com/percy/cli.git","type":"git","directory":"packages/dom"},"_npmVersion":"lerna/5.1.8/node@v14.20.0+x64 (linux)","description":"Serializes a document's DOM into a DOM string suitable for re-rendering.","directories":{},"_nodeVersion":"14.20.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"interactor.js":"^2.0.0-beta.10"},"_npmOperationalInternal":{"tmp":"tmp/dom_1.6.2_1658337982845_0.5770796277249264","host":"s3://npm-registry-packages"},"readme":"# @percy/dom\n\nSerializes a document's DOM into a DOM string suitable for re-rendering.\n\n- [Usage](#usage)\n  - [ES6 imports](#es6-imports)\n  - [Browser injection](#browser-injection)\n  - [Options](#options)\n- [Serialized Content](#serialize-content)\n  - [Input elements](#input-elements)\n  - [Frame elements](#frame-elements)\n  - [CSSOM rules](#cssom-rules)\n  - [Canvas elements](#canvas-elements)\n  - [Video elements](#video-elements)\n  - [Other elements](#other-elements)\n\n## Usage\n\n### ES6 imports\n\n```js\nimport serializeDOM from '@percy/dom';\n\n// optional arguments shown with defaults\nconst domSnapshot = serializeDOM(options)\n```\n\n### Browser injection\n\n```js\n// via puppeteer\nawait page.addScriptTag({ path: require.resolve('@percy/dom') })\nconst domSnapshot = await page.evaluate(() => PercyDOM.serialize(options))\n```\n\n### Options\n\n- `enableJavaScript` — When true, does not serialize some DOM elements\n- `domTransformation` — Function to transform the DOM after serialization\n- `disableShadowDOM` — disable shadow DOM capturing, usually to be used when `enableJavascript: true`\n- `reshuffleInvalidTags` — moves DOM tags which are outside `</body>` to its inside to make the DOM compliant.\n\n## Serialized Content\n\nThe following serialization happens to a cloned instance of the document in order.\n\n### Input elements\n\nInput elements (`input`, `textarea`, `select`) are serialized by setting respective DOM attributes\nto their matching JavaScript property counterparts. For example `checked`, `selected`, and `value`.\n\n### Frame elements\n\nFrame elements are serialized when they are CORS accessible and if they haven't been built by\nJavaScript when JavaScript is enabled. They are serialized by recursively serializing the iframe's\nown document element.\n\n### CSSOM rules\n\nWhen JavaScript is not enabled, CSSOM rules are serialized by iterating over and appending each rule\nto a new stylesheet inserted into the document's head.\n\n### Canvas elements\n\nCanvas elements' drawing buffers are serialized as data URIs and the canvas elements are replaced\nwith image elements. The image elements reference the serialized data URI and have the same HTML\nattributes as their respective canvas elements. The image elements also have a max-width of 100% to\naccommodate responsive layouts in situations where canvases may be expected to resize with JS.\n\n### Video elements\n\nVideos without a `poster` attribute will have the current frame of the video\nserialized into an image and set as the `poster` attribute automatically. This is\nto ensure videos have a stable image to display when screenshots are captured.\n\n### Shadow DOM\n\nShadow dom  `#shadow-root (open)` is serialized into declarative shadow DOM (`<template shadowroot=\"open\">`) form\nShadow host element is annotated with special identifier attribute named `data-percy-shadow-host`. This identifier \nattribute may be used when passing `domTransformation`.\n\n### Other elements\n\n_All other elements are not serialized._ The resulting cloned document is passed to any provided\n`domTransformation` option before the serialize function returns a DOM string.\n\n\n\n## Examples \n\n1. perform DOM transformations on serialized DOM \n\nthis example contains scenario of nested shadow DOMs\n\n```js\nimport serializeDOM from '@percy/dom';\n\nconst domSnapshot = serializeDOM({\n    domTransformation: (documentElement) => {\n      function insertHelloHeader(root) {\n        h1 = document.createElement('h1');\n        h1.innerText = 'Inserted using dom transformations';\n        root.append(h1);\n\n        root.querySelectorAll('[data-percy-shadow-host]')\n          .forEach(\n            shadowHost => {\n              if (shadowHost?.shadowRoot)\n                insertHelloHeader(shadowHost.shadowRoot)\n            });\n\n      }\n      insertHelloHeader(documentElement);\n    }\n  });\n```\n","publish_time":1658337983021,"maintainers":[{"name":"percy-admin","email":"apps+npm@percy.io"}],"_cnpm_publish_time":1658337983021,"dist-tags":{"alpha":"1.31.15-alpha.0","beta":"1.33.0-beta.0","latest":"1.33.1"}}