rrweb-snapshot
Advanced tools
Comparing version 0.7.10 to 0.7.11
@@ -17,5 +17,2 @@ var rrwebSnapshot = (function (exports) { | ||
} | ||
function resetId() { | ||
_id = 1; | ||
} | ||
function getCssRulesString(s) { | ||
@@ -227,7 +224,12 @@ try { | ||
} | ||
var serializedNode = Object.assign(_serializedNode, { | ||
id: genId() | ||
}); | ||
var id; | ||
if ('__sn' in n) { | ||
id = n.__sn.id; | ||
} | ||
else { | ||
id = genId(); | ||
} | ||
var serializedNode = Object.assign(_serializedNode, { id: id }); | ||
n.__sn = serializedNode; | ||
map[serializedNode.id] = n; | ||
map[id] = n; | ||
var recordChild = !skipChild; | ||
@@ -254,3 +256,2 @@ if (serializedNode.type === exports.NodeType.Element) { | ||
if (inlineStylesheet === void 0) { inlineStylesheet = true; } | ||
resetId(); | ||
var idNodeMap = {}; | ||
@@ -355,3 +356,8 @@ return [ | ||
try { | ||
node.setAttribute(name, value); | ||
if (n.isSVG && name === 'xlink:href') { | ||
node.setAttributeNS('http://www.w3.org/1999/xlink', name, value); | ||
} | ||
else { | ||
node.setAttribute(name, value); | ||
} | ||
} | ||
@@ -417,3 +423,2 @@ catch (error) { | ||
exports.serializeNodeWithId = serializeNodeWithId; | ||
exports.resetId = resetId; | ||
exports.rebuild = rebuild; | ||
@@ -420,0 +425,0 @@ exports.buildNodeWithSN = buildNodeWithSN; |
@@ -1,2 +0,2 @@ | ||
var rrwebSnapshot=function(e){"use strict";var t;(t=e.NodeType||(e.NodeType={}))[t.Document=0]="Document",t[t.DocumentType=1]="DocumentType",t[t.Element=2]="Element",t[t.Text=3]="Text",t[t.CDATA=4]="CDATA",t[t.Comment=5]="Comment";var r=1;function n(){r=1}function a(e){try{var t=e.rules||e.cssRules;return t?Array.from(t).reduce(function(e,t){return e+(function(e){return"styleSheet"in e}(r=t)?a(r.styleSheet)||"":r.cssText);var r},""):null}catch(e){return null}}var o=/url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm,i=/^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/,l=/^(data:)([\w\/\+]+);(charset=[\w-]+|base64).*,(.*)/gi;function s(e,t){return e.replace(o,function(e,r,n,a){var o,s=r||n||a;if(!s)return e;if(!i.test(s))return"url('"+s+"')";if(l.test(s))return"url("+s+")";if("/"===s[0])return"url('"+(((o=t).indexOf("//")>-1?o.split("/").slice(0,3).join("/"):o.split("/")[0]).split("?")[0]+s)+"')";var c=t.split("/"),f=s.split("/");c.pop();for(var u=0,p=f;u<p.length;u++){var d=p[u];"."!==d&&(".."===d?c.pop():c.push(d))}return"url('"+c.join("/")+"')"})}function c(e,t){var r=e.createElement("a");return r.href=t,r.href}function f(t,r,n,o){switch(t.nodeType){case t.DOCUMENT_NODE:return{type:e.NodeType.Document,childNodes:[]};case t.DOCUMENT_TYPE_NODE:return{type:e.NodeType.DocumentType,name:t.name,publicId:t.publicId,systemId:t.systemId};case t.ELEMENT_NODE:var i=!1;"string"==typeof n?i=t.classList.contains(n):t.classList.forEach(function(e){n.test(e)&&(i=!0)});for(var l=t.tagName.toLowerCase(),f={},u=0,p=Array.from(t.attributes);u<p.length;u++){var d=p[u],h=d.name,m=d.value;f[h]="src"===h||"href"===h?c(r,m):"style"===h?s(m,location.href):m}if("link"===l&&o){var y,g=Array.from(r.styleSheets).find(function(e){return e.href===t.href});(y=a(g))&&(delete f.rel,delete f.href,f._cssText=s(y,g.href))}if("style"===l&&t.sheet&&!t.innerText.trim().length)(y=a(t.sheet))&&(f._cssText=s(y,location.href));if("input"===l||"textarea"===l||"select"===l){m=t.value;"radio"!==f.type&&"checkbox"!==f.type&&m?f.value=m:t.checked&&(f.checked=t.checked)}if("option"===l){var v=t.parentElement;f.value===v.value&&(f.selected=t.selected)}if(i){var T=t.getBoundingClientRect(),N=T.width,C=T.height;f.rr_width=N+"px",f.rr_height=C+"px"}return{type:e.NodeType.Element,tagName:l,attributes:f,childNodes:[],isSVG:(b=t,"svg"===b.tagName||b instanceof SVGElement||void 0),needBlock:i};case t.TEXT_NODE:var D=t.parentNode&&t.parentNode.tagName,x=t.textContent,E="STYLE"===D||void 0;return E&&x&&(x=s(x,location.href)),"SCRIPT"===D&&(x="SCRIPT_PLACEHOLDER"),{type:e.NodeType.Text,textContent:x||"",isStyle:E};case t.CDATA_SECTION_NODE:return{type:e.NodeType.CDATA,textContent:""};case t.COMMENT_NODE:return{type:e.NodeType.Comment,textContent:t.textContent||""};default:return!1}var b}function u(t,n,a,o,i,l){void 0===i&&(i=!1),void 0===l&&(l=!0);var s=f(t,n,o,l);if(!s)return console.warn(t,"not serialized"),null;var c=Object.assign(s,{id:r++});t.__sn=c,a[c.id]=t;var p=!i;if(c.type===e.NodeType.Element&&(p=p&&!c.needBlock,delete c.needBlock),(c.type===e.NodeType.Document||c.type===e.NodeType.Element)&&p)for(var d=0,h=Array.from(t.childNodes);d<h.length;d++){var m=u(h[d],n,a,o,i,l);m&&c.childNodes.push(m)}return c}var p={script:"noscript",altglyph:"altGlyph",altglyphdef:"altGlyphDef",altglyphitem:"altGlyphItem",animatecolor:"animateColor",animatemotion:"animateMotion",animatetransform:"animateTransform",clippath:"clipPath",feblend:"feBlend",fecolormatrix:"feColorMatrix",fecomponenttransfer:"feComponentTransfer",fecomposite:"feComposite",feconvolvematrix:"feConvolveMatrix",fediffuselighting:"feDiffuseLighting",fedisplacementmap:"feDisplacementMap",fedistantlight:"feDistantLight",fedropshadow:"feDropShadow",feflood:"feFlood",fefunca:"feFuncA",fefuncb:"feFuncB",fefuncg:"feFuncG",fefuncr:"feFuncR",fegaussianblur:"feGaussianBlur",feimage:"feImage",femerge:"feMerge",femergenode:"feMergeNode",femorphology:"feMorphology",feoffset:"feOffset",fepointlight:"fePointLight",fespecularlighting:"feSpecularLighting",fespotlight:"feSpotLight",fetile:"feTile",feturbulence:"feTurbulence",foreignobject:"foreignObject",glyphref:"glyphRef",lineargradient:"linearGradient",radialgradient:"radialGradient"};var d=/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/g,h=/([^\\]):hover/g;function m(e){return e.replace(d,function(e,t,r){if(h.test(t)){var n=t.replace(h,"$1.\\:hover");return t.replace(/\s*$/,"")+", "+n.replace(/^\s*/,"")+r}return e})}function y(t,r){switch(t.type){case e.NodeType.Document:return r.implementation.createDocument(null,"",null);case e.NodeType.DocumentType:return r.implementation.createDocumentType(t.name,t.publicId,t.systemId);case e.NodeType.Element:var n=function(e){var t=p[e.tagName]?p[e.tagName]:e.tagName;return"link"===t&&e.attributes._cssText&&(t="style"),t}(t),a=void 0;for(var o in a=t.isSVG?r.createElementNS("http://www.w3.org/2000/svg",n):r.createElement(n),t.attributes)if(t.attributes.hasOwnProperty(o)&&!o.startsWith("rr_")){var i=t.attributes[o];i="boolean"==typeof i?"":i;var l="textarea"===n&&"value"===o,s="style"===n&&"_cssText"===o;if(s&&(i=m(i)),l||s){var c=r.createTextNode(i);a.appendChild(c);continue}if("iframe"===n&&"src"===o)continue;try{a.setAttribute(o,i)}catch(e){}}else t.attributes.rr_width&&(a.style.width=t.attributes.rr_width),t.attributes.rr_height&&(a.style.height=t.attributes.rr_height);return a;case e.NodeType.Text:return r.createTextNode(t.isStyle?m(t.textContent):t.textContent);case e.NodeType.CDATA:return r.createCDATASection(t.textContent);case e.NodeType.Comment:return r.createComment(t.textContent);default:return null}}function g(t,r,n,a){void 0===a&&(a=!1);var o=y(t,r);if(!o)return null;if(t.type===e.NodeType.Document&&(r.close(),r.open(),o=r),o.__sn=t,n[t.id]=o,(t.type===e.NodeType.Document||t.type===e.NodeType.Element)&&!a)for(var i=0,l=t.childNodes;i<l.length;i++){var s=l[i],c=g(s,r,n);c?o.appendChild(c):console.warn("Failed to rebuild",s)}return o}return e.snapshot=function(e,t,r){void 0===t&&(t="rr-block"),void 0===r&&(r=!0),n();var a={};return[u(e,e,a,t,!1,r),a]},e.serializeNodeWithId=u,e.resetId=n,e.rebuild=function(e,t){var r={};return[g(e,t,r),r]},e.buildNodeWithSN=g,e}({}); | ||
var rrwebSnapshot=function(e){"use strict";var t;(t=e.NodeType||(e.NodeType={}))[t.Document=0]="Document",t[t.DocumentType=1]="DocumentType",t[t.Element=2]="Element",t[t.Text=3]="Text",t[t.CDATA=4]="CDATA",t[t.Comment=5]="Comment";var r=1;function n(e){try{var t=e.rules||e.cssRules;return t?Array.from(t).reduce(function(e,t){return e+(function(e){return"styleSheet"in e}(r=t)?n(r.styleSheet)||"":r.cssText);var r},""):null}catch(e){return null}}var a=/url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm,i=/^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/,o=/^(data:)([\w\/\+]+);(charset=[\w-]+|base64).*,(.*)/gi;function l(e,t){return e.replace(a,function(e,r,n,a){var l,s=r||n||a;if(!s)return e;if(!i.test(s))return"url('"+s+"')";if(o.test(s))return"url("+s+")";if("/"===s[0])return"url('"+(((l=t).indexOf("//")>-1?l.split("/").slice(0,3).join("/"):l.split("/")[0]).split("?")[0]+s)+"')";var c=t.split("/"),f=s.split("/");c.pop();for(var u=0,p=f;u<p.length;u++){var d=p[u];"."!==d&&(".."===d?c.pop():c.push(d))}return"url('"+c.join("/")+"')"})}function s(e,t){var r=e.createElement("a");return r.href=t,r.href}function c(t,r,a,i){switch(t.nodeType){case t.DOCUMENT_NODE:return{type:e.NodeType.Document,childNodes:[]};case t.DOCUMENT_TYPE_NODE:return{type:e.NodeType.DocumentType,name:t.name,publicId:t.publicId,systemId:t.systemId};case t.ELEMENT_NODE:var o=!1;"string"==typeof a?o=t.classList.contains(a):t.classList.forEach(function(e){a.test(e)&&(o=!0)});for(var c=t.tagName.toLowerCase(),f={},u=0,p=Array.from(t.attributes);u<p.length;u++){var d=p[u],h=d.name,m=d.value;f[h]="src"===h||"href"===h?s(r,m):"style"===h?l(m,location.href):m}if("link"===c&&i){var y,g=Array.from(r.styleSheets).find(function(e){return e.href===t.href});(y=n(g))&&(delete f.rel,delete f.href,f._cssText=l(y,g.href))}if("style"===c&&t.sheet&&!t.innerText.trim().length)(y=n(t.sheet))&&(f._cssText=l(y,location.href));if("input"===c||"textarea"===c||"select"===c){m=t.value;"radio"!==f.type&&"checkbox"!==f.type&&m?f.value=m:t.checked&&(f.checked=t.checked)}if("option"===c){var v=t.parentElement;f.value===v.value&&(f.selected=t.selected)}if(o){var T=t.getBoundingClientRect(),N=T.width,C=T.height;f.rr_width=N+"px",f.rr_height=C+"px"}return{type:e.NodeType.Element,tagName:c,attributes:f,childNodes:[],isSVG:(E=t,"svg"===E.tagName||E instanceof SVGElement||void 0),needBlock:o};case t.TEXT_NODE:var x=t.parentNode&&t.parentNode.tagName,D=t.textContent,b="STYLE"===x||void 0;return b&&D&&(D=l(D,location.href)),"SCRIPT"===x&&(D="SCRIPT_PLACEHOLDER"),{type:e.NodeType.Text,textContent:D||"",isStyle:b};case t.CDATA_SECTION_NODE:return{type:e.NodeType.CDATA,textContent:""};case t.COMMENT_NODE:return{type:e.NodeType.Comment,textContent:t.textContent||""};default:return!1}var E}function f(t,n,a,i,o,l){void 0===o&&(o=!1),void 0===l&&(l=!0);var s,u=c(t,n,i,l);if(!u)return console.warn(t,"not serialized"),null;s="__sn"in t?t.__sn.id:r++;var p=Object.assign(u,{id:s});t.__sn=p,a[s]=t;var d=!o;if(p.type===e.NodeType.Element&&(d=d&&!p.needBlock,delete p.needBlock),(p.type===e.NodeType.Document||p.type===e.NodeType.Element)&&d)for(var h=0,m=Array.from(t.childNodes);h<m.length;h++){var y=f(m[h],n,a,i,o,l);y&&p.childNodes.push(y)}return p}var u={script:"noscript",altglyph:"altGlyph",altglyphdef:"altGlyphDef",altglyphitem:"altGlyphItem",animatecolor:"animateColor",animatemotion:"animateMotion",animatetransform:"animateTransform",clippath:"clipPath",feblend:"feBlend",fecolormatrix:"feColorMatrix",fecomponenttransfer:"feComponentTransfer",fecomposite:"feComposite",feconvolvematrix:"feConvolveMatrix",fediffuselighting:"feDiffuseLighting",fedisplacementmap:"feDisplacementMap",fedistantlight:"feDistantLight",fedropshadow:"feDropShadow",feflood:"feFlood",fefunca:"feFuncA",fefuncb:"feFuncB",fefuncg:"feFuncG",fefuncr:"feFuncR",fegaussianblur:"feGaussianBlur",feimage:"feImage",femerge:"feMerge",femergenode:"feMergeNode",femorphology:"feMorphology",feoffset:"feOffset",fepointlight:"fePointLight",fespecularlighting:"feSpecularLighting",fespotlight:"feSpotLight",fetile:"feTile",feturbulence:"feTurbulence",foreignobject:"foreignObject",glyphref:"glyphRef",lineargradient:"linearGradient",radialgradient:"radialGradient"};var p=/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/g,d=/([^\\]):hover/g;function h(e){return e.replace(p,function(e,t,r){if(d.test(t)){var n=t.replace(d,"$1.\\:hover");return t.replace(/\s*$/,"")+", "+n.replace(/^\s*/,"")+r}return e})}function m(t,r){switch(t.type){case e.NodeType.Document:return r.implementation.createDocument(null,"",null);case e.NodeType.DocumentType:return r.implementation.createDocumentType(t.name,t.publicId,t.systemId);case e.NodeType.Element:var n=function(e){var t=u[e.tagName]?u[e.tagName]:e.tagName;return"link"===t&&e.attributes._cssText&&(t="style"),t}(t),a=void 0;for(var i in a=t.isSVG?r.createElementNS("http://www.w3.org/2000/svg",n):r.createElement(n),t.attributes)if(t.attributes.hasOwnProperty(i)&&!i.startsWith("rr_")){var o=t.attributes[i];o="boolean"==typeof o?"":o;var l="textarea"===n&&"value"===i,s="style"===n&&"_cssText"===i;if(s&&(o=h(o)),l||s){var c=r.createTextNode(o);a.appendChild(c);continue}if("iframe"===n&&"src"===i)continue;try{t.isSVG&&"xlink:href"===i?a.setAttributeNS("http://www.w3.org/1999/xlink",i,o):a.setAttribute(i,o)}catch(e){}}else t.attributes.rr_width&&(a.style.width=t.attributes.rr_width),t.attributes.rr_height&&(a.style.height=t.attributes.rr_height);return a;case e.NodeType.Text:return r.createTextNode(t.isStyle?h(t.textContent):t.textContent);case e.NodeType.CDATA:return r.createCDATASection(t.textContent);case e.NodeType.Comment:return r.createComment(t.textContent);default:return null}}function y(t,r,n,a){void 0===a&&(a=!1);var i=m(t,r);if(!i)return null;if(t.type===e.NodeType.Document&&(r.close(),r.open(),i=r),i.__sn=t,n[t.id]=i,(t.type===e.NodeType.Document||t.type===e.NodeType.Element)&&!a)for(var o=0,l=t.childNodes;o<l.length;o++){var s=l[o],c=y(s,r,n);c?i.appendChild(c):console.warn("Failed to rebuild",s)}return i}return e.snapshot=function(e,t,r){void 0===t&&(t="rr-block"),void 0===r&&(r=!0);var n={};return[f(e,e,n,t,!1,r),n]},e.serializeNodeWithId=f,e.rebuild=function(e,t){var r={};return[y(e,t,r),r]},e.buildNodeWithSN=y,e}({}); | ||
//# sourceMappingURL=rrweb-snapshot.min.js.map |
@@ -15,5 +15,2 @@ var NodeType; | ||
} | ||
function resetId() { | ||
_id = 1; | ||
} | ||
function getCssRulesString(s) { | ||
@@ -225,7 +222,12 @@ try { | ||
} | ||
var serializedNode = Object.assign(_serializedNode, { | ||
id: genId() | ||
}); | ||
var id; | ||
if ('__sn' in n) { | ||
id = n.__sn.id; | ||
} | ||
else { | ||
id = genId(); | ||
} | ||
var serializedNode = Object.assign(_serializedNode, { id: id }); | ||
n.__sn = serializedNode; | ||
map[serializedNode.id] = n; | ||
map[id] = n; | ||
var recordChild = !skipChild; | ||
@@ -252,3 +254,2 @@ if (serializedNode.type === NodeType.Element) { | ||
if (inlineStylesheet === void 0) { inlineStylesheet = true; } | ||
resetId(); | ||
var idNodeMap = {}; | ||
@@ -353,3 +354,8 @@ return [ | ||
try { | ||
node.setAttribute(name, value); | ||
if (n.isSVG && name === 'xlink:href') { | ||
node.setAttributeNS('http://www.w3.org/1999/xlink', name, value); | ||
} | ||
else { | ||
node.setAttribute(name, value); | ||
} | ||
} | ||
@@ -413,2 +419,2 @@ catch (error) { | ||
export { snapshot, serializeNodeWithId, resetId, rebuild, buildNodeWithSN, NodeType }; | ||
export { snapshot, serializeNodeWithId, rebuild, buildNodeWithSN, NodeType }; |
@@ -1,2 +0,2 @@ | ||
var NodeType;!function(e){e[e.Document=0]="Document",e[e.DocumentType=1]="DocumentType",e[e.Element=2]="Element",e[e.Text=3]="Text",e[e.CDATA=4]="CDATA",e[e.Comment=5]="Comment"}(NodeType||(NodeType={}));var _id=1;function genId(){return _id++}function resetId(){_id=1}function getCssRulesString(e){try{var t=e.rules||e.cssRules;return t?Array.from(t).reduce(function(e,t){return e+getCssRuleString(t)},""):null}catch(e){return null}}function getCssRuleString(e){return isCSSImportRule(e)?getCssRulesString(e.styleSheet)||"":e.cssText}function isCSSImportRule(e){return"styleSheet"in e}function extractOrigin(e){return(e.indexOf("//")>-1?e.split("/").slice(0,3).join("/"):e.split("/")[0]).split("?")[0]}var URL_IN_CSS_REF=/url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm,RELATIVE_PATH=/^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/,DATA_URI=/^(data:)([\w\/\+]+);(charset=[\w-]+|base64).*,(.*)/gi;function absoluteToStylesheet(e,t){return e.replace(URL_IN_CSS_REF,function(e,r,n,i){var o=r||n||i;if(!o)return e;if(!RELATIVE_PATH.test(o))return"url('"+o+"')";if(DATA_URI.test(o))return"url("+o+")";if("/"===o[0])return"url('"+(extractOrigin(t)+o)+"')";var a=t.split("/"),l=o.split("/");a.pop();for(var s=0,u=l;s<u.length;s++){var c=u[s];"."!==c&&(".."===c?a.pop():a.push(c))}return"url('"+a.join("/")+"')"})}function absoluteToDoc(e,t){var r=e.createElement("a");return r.href=t,r.href}function isSVGElement(e){return"svg"===e.tagName||e instanceof SVGElement}function serializeNode(e,t,r,n){switch(e.nodeType){case e.DOCUMENT_NODE:return{type:NodeType.Document,childNodes:[]};case e.DOCUMENT_TYPE_NODE:return{type:NodeType.DocumentType,name:e.name,publicId:e.publicId,systemId:e.systemId};case e.ELEMENT_NODE:var i=!1;"string"==typeof r?i=e.classList.contains(r):e.classList.forEach(function(e){r.test(e)&&(i=!0)});for(var o=e.tagName.toLowerCase(),a={},l=0,s=Array.from(e.attributes);l<s.length;l++){var u=s[l],c=u.name,d=u.value;a[c]="src"===c||"href"===c?absoluteToDoc(t,d):"style"===c?absoluteToStylesheet(d,location.href):d}if("link"===o&&n){var f,p=Array.from(t.styleSheets).find(function(t){return t.href===e.href});(f=getCssRulesString(p))&&(delete a.rel,delete a.href,a._cssText=absoluteToStylesheet(f,p.href))}if("style"===o&&e.sheet&&!e.innerText.trim().length)(f=getCssRulesString(e.sheet))&&(a._cssText=absoluteToStylesheet(f,location.href));if("input"===o||"textarea"===o||"select"===o){d=e.value;"radio"!==a.type&&"checkbox"!==a.type&&d?a.value=d:e.checked&&(a.checked=e.checked)}if("option"===o){var h=e.parentElement;a.value===h.value&&(a.selected=e.selected)}if(i){var m=e.getBoundingClientRect(),g=m.width,y=m.height;a.rr_width=g+"px",a.rr_height=y+"px"}return{type:NodeType.Element,tagName:o,attributes:a,childNodes:[],isSVG:isSVGElement(e)||void 0,needBlock:i};case e.TEXT_NODE:var T=e.parentNode&&e.parentNode.tagName,N=e.textContent,v="STYLE"===T||void 0;return v&&N&&(N=absoluteToStylesheet(N,location.href)),"SCRIPT"===T&&(N="SCRIPT_PLACEHOLDER"),{type:NodeType.Text,textContent:N||"",isStyle:v};case e.CDATA_SECTION_NODE:return{type:NodeType.CDATA,textContent:""};case e.COMMENT_NODE:return{type:NodeType.Comment,textContent:e.textContent||""};default:return!1}}function serializeNodeWithId(e,t,r,n,i,o){void 0===i&&(i=!1),void 0===o&&(o=!0);var a=serializeNode(e,t,n,o);if(!a)return console.warn(e,"not serialized"),null;var l=Object.assign(a,{id:genId()});e.__sn=l,r[l.id]=e;var s=!i;if(l.type===NodeType.Element&&(s=s&&!l.needBlock,delete l.needBlock),(l.type===NodeType.Document||l.type===NodeType.Element)&&s)for(var u=0,c=Array.from(e.childNodes);u<c.length;u++){var d=serializeNodeWithId(c[u],t,r,n,i,o);d&&l.childNodes.push(d)}return l}function snapshot(e,t,r){void 0===t&&(t="rr-block"),void 0===r&&(r=!0),resetId();var n={};return[serializeNodeWithId(e,e,n,t,!1,r),n]}var tagMap={script:"noscript",altglyph:"altGlyph",altglyphdef:"altGlyphDef",altglyphitem:"altGlyphItem",animatecolor:"animateColor",animatemotion:"animateMotion",animatetransform:"animateTransform",clippath:"clipPath",feblend:"feBlend",fecolormatrix:"feColorMatrix",fecomponenttransfer:"feComponentTransfer",fecomposite:"feComposite",feconvolvematrix:"feConvolveMatrix",fediffuselighting:"feDiffuseLighting",fedisplacementmap:"feDisplacementMap",fedistantlight:"feDistantLight",fedropshadow:"feDropShadow",feflood:"feFlood",fefunca:"feFuncA",fefuncb:"feFuncB",fefuncg:"feFuncG",fefuncr:"feFuncR",fegaussianblur:"feGaussianBlur",feimage:"feImage",femerge:"feMerge",femergenode:"feMergeNode",femorphology:"feMorphology",feoffset:"feOffset",fepointlight:"fePointLight",fespecularlighting:"feSpecularLighting",fespotlight:"feSpotLight",fetile:"feTile",feturbulence:"feTurbulence",foreignobject:"foreignObject",glyphref:"glyphRef",lineargradient:"linearGradient",radialgradient:"radialGradient"};function getTagName(e){var t=tagMap[e.tagName]?tagMap[e.tagName]:e.tagName;return"link"===t&&e.attributes._cssText&&(t="style"),t}var CSS_SELECTOR=/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/g,HOVER_SELECTOR=/([^\\]):hover/g;function addHoverClass(e){return e.replace(CSS_SELECTOR,function(e,t,r){if(HOVER_SELECTOR.test(t)){var n=t.replace(HOVER_SELECTOR,"$1.\\:hover");return t.replace(/\s*$/,"")+", "+n.replace(/^\s*/,"")+r}return e})}function buildNode(e,t){switch(e.type){case NodeType.Document:return t.implementation.createDocument(null,"",null);case NodeType.DocumentType:return t.implementation.createDocumentType(e.name,e.publicId,e.systemId);case NodeType.Element:var r=getTagName(e),n=void 0;for(var i in n=e.isSVG?t.createElementNS("http://www.w3.org/2000/svg",r):t.createElement(r),e.attributes)if(e.attributes.hasOwnProperty(i)&&!i.startsWith("rr_")){var o=e.attributes[i];o="boolean"==typeof o?"":o;var a="textarea"===r&&"value"===i,l="style"===r&&"_cssText"===i;if(l&&(o=addHoverClass(o)),a||l){var s=t.createTextNode(o);n.appendChild(s);continue}if("iframe"===r&&"src"===i)continue;try{n.setAttribute(i,o)}catch(e){}}else e.attributes.rr_width&&(n.style.width=e.attributes.rr_width),e.attributes.rr_height&&(n.style.height=e.attributes.rr_height);return n;case NodeType.Text:return t.createTextNode(e.isStyle?addHoverClass(e.textContent):e.textContent);case NodeType.CDATA:return t.createCDATASection(e.textContent);case NodeType.Comment:return t.createComment(e.textContent);default:return null}}function buildNodeWithSN(e,t,r,n){void 0===n&&(n=!1);var i=buildNode(e,t);if(!i)return null;if(e.type===NodeType.Document&&(t.close(),t.open(),i=t),i.__sn=e,r[e.id]=i,(e.type===NodeType.Document||e.type===NodeType.Element)&&!n)for(var o=0,a=e.childNodes;o<a.length;o++){var l=a[o],s=buildNodeWithSN(l,t,r);s?i.appendChild(s):console.warn("Failed to rebuild",l)}return i}function rebuild(e,t){var r={};return[buildNodeWithSN(e,t,r),r]}export{snapshot,serializeNodeWithId,resetId,rebuild,buildNodeWithSN,NodeType}; | ||
var NodeType;!function(e){e[e.Document=0]="Document",e[e.DocumentType=1]="DocumentType",e[e.Element=2]="Element",e[e.Text=3]="Text",e[e.CDATA=4]="CDATA",e[e.Comment=5]="Comment"}(NodeType||(NodeType={}));var _id=1;function genId(){return _id++}function getCssRulesString(e){try{var t=e.rules||e.cssRules;return t?Array.from(t).reduce(function(e,t){return e+getCssRuleString(t)},""):null}catch(e){return null}}function getCssRuleString(e){return isCSSImportRule(e)?getCssRulesString(e.styleSheet)||"":e.cssText}function isCSSImportRule(e){return"styleSheet"in e}function extractOrigin(e){return(e.indexOf("//")>-1?e.split("/").slice(0,3).join("/"):e.split("/")[0]).split("?")[0]}var URL_IN_CSS_REF=/url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm,RELATIVE_PATH=/^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/,DATA_URI=/^(data:)([\w\/\+]+);(charset=[\w-]+|base64).*,(.*)/gi;function absoluteToStylesheet(e,t){return e.replace(URL_IN_CSS_REF,function(e,r,n,i){var o=r||n||i;if(!o)return e;if(!RELATIVE_PATH.test(o))return"url('"+o+"')";if(DATA_URI.test(o))return"url("+o+")";if("/"===o[0])return"url('"+(extractOrigin(t)+o)+"')";var a=t.split("/"),l=o.split("/");a.pop();for(var s=0,u=l;s<u.length;s++){var c=u[s];"."!==c&&(".."===c?a.pop():a.push(c))}return"url('"+a.join("/")+"')"})}function absoluteToDoc(e,t){var r=e.createElement("a");return r.href=t,r.href}function isSVGElement(e){return"svg"===e.tagName||e instanceof SVGElement}function serializeNode(e,t,r,n){switch(e.nodeType){case e.DOCUMENT_NODE:return{type:NodeType.Document,childNodes:[]};case e.DOCUMENT_TYPE_NODE:return{type:NodeType.DocumentType,name:e.name,publicId:e.publicId,systemId:e.systemId};case e.ELEMENT_NODE:var i=!1;"string"==typeof r?i=e.classList.contains(r):e.classList.forEach(function(e){r.test(e)&&(i=!0)});for(var o=e.tagName.toLowerCase(),a={},l=0,s=Array.from(e.attributes);l<s.length;l++){var u=s[l],c=u.name,f=u.value;a[c]="src"===c||"href"===c?absoluteToDoc(t,f):"style"===c?absoluteToStylesheet(f,location.href):f}if("link"===o&&n){var d,p=Array.from(t.styleSheets).find(function(t){return t.href===e.href});(d=getCssRulesString(p))&&(delete a.rel,delete a.href,a._cssText=absoluteToStylesheet(d,p.href))}if("style"===o&&e.sheet&&!e.innerText.trim().length)(d=getCssRulesString(e.sheet))&&(a._cssText=absoluteToStylesheet(d,location.href));if("input"===o||"textarea"===o||"select"===o){f=e.value;"radio"!==a.type&&"checkbox"!==a.type&&f?a.value=f:e.checked&&(a.checked=e.checked)}if("option"===o){var h=e.parentElement;a.value===h.value&&(a.selected=e.selected)}if(i){var m=e.getBoundingClientRect(),g=m.width,y=m.height;a.rr_width=g+"px",a.rr_height=y+"px"}return{type:NodeType.Element,tagName:o,attributes:a,childNodes:[],isSVG:isSVGElement(e)||void 0,needBlock:i};case e.TEXT_NODE:var T=e.parentNode&&e.parentNode.tagName,N=e.textContent,v="STYLE"===T||void 0;return v&&N&&(N=absoluteToStylesheet(N,location.href)),"SCRIPT"===T&&(N="SCRIPT_PLACEHOLDER"),{type:NodeType.Text,textContent:N||"",isStyle:v};case e.CDATA_SECTION_NODE:return{type:NodeType.CDATA,textContent:""};case e.COMMENT_NODE:return{type:NodeType.Comment,textContent:e.textContent||""};default:return!1}}function serializeNodeWithId(e,t,r,n,i,o){void 0===i&&(i=!1),void 0===o&&(o=!0);var a,l=serializeNode(e,t,n,o);if(!l)return console.warn(e,"not serialized"),null;a="__sn"in e?e.__sn.id:genId();var s=Object.assign(l,{id:a});e.__sn=s,r[a]=e;var u=!i;if(s.type===NodeType.Element&&(u=u&&!s.needBlock,delete s.needBlock),(s.type===NodeType.Document||s.type===NodeType.Element)&&u)for(var c=0,f=Array.from(e.childNodes);c<f.length;c++){var d=serializeNodeWithId(f[c],t,r,n,i,o);d&&s.childNodes.push(d)}return s}function snapshot(e,t,r){void 0===t&&(t="rr-block"),void 0===r&&(r=!0);var n={};return[serializeNodeWithId(e,e,n,t,!1,r),n]}var tagMap={script:"noscript",altglyph:"altGlyph",altglyphdef:"altGlyphDef",altglyphitem:"altGlyphItem",animatecolor:"animateColor",animatemotion:"animateMotion",animatetransform:"animateTransform",clippath:"clipPath",feblend:"feBlend",fecolormatrix:"feColorMatrix",fecomponenttransfer:"feComponentTransfer",fecomposite:"feComposite",feconvolvematrix:"feConvolveMatrix",fediffuselighting:"feDiffuseLighting",fedisplacementmap:"feDisplacementMap",fedistantlight:"feDistantLight",fedropshadow:"feDropShadow",feflood:"feFlood",fefunca:"feFuncA",fefuncb:"feFuncB",fefuncg:"feFuncG",fefuncr:"feFuncR",fegaussianblur:"feGaussianBlur",feimage:"feImage",femerge:"feMerge",femergenode:"feMergeNode",femorphology:"feMorphology",feoffset:"feOffset",fepointlight:"fePointLight",fespecularlighting:"feSpecularLighting",fespotlight:"feSpotLight",fetile:"feTile",feturbulence:"feTurbulence",foreignobject:"foreignObject",glyphref:"glyphRef",lineargradient:"linearGradient",radialgradient:"radialGradient"};function getTagName(e){var t=tagMap[e.tagName]?tagMap[e.tagName]:e.tagName;return"link"===t&&e.attributes._cssText&&(t="style"),t}var CSS_SELECTOR=/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/g,HOVER_SELECTOR=/([^\\]):hover/g;function addHoverClass(e){return e.replace(CSS_SELECTOR,function(e,t,r){if(HOVER_SELECTOR.test(t)){var n=t.replace(HOVER_SELECTOR,"$1.\\:hover");return t.replace(/\s*$/,"")+", "+n.replace(/^\s*/,"")+r}return e})}function buildNode(e,t){switch(e.type){case NodeType.Document:return t.implementation.createDocument(null,"",null);case NodeType.DocumentType:return t.implementation.createDocumentType(e.name,e.publicId,e.systemId);case NodeType.Element:var r=getTagName(e),n=void 0;for(var i in n=e.isSVG?t.createElementNS("http://www.w3.org/2000/svg",r):t.createElement(r),e.attributes)if(e.attributes.hasOwnProperty(i)&&!i.startsWith("rr_")){var o=e.attributes[i];o="boolean"==typeof o?"":o;var a="textarea"===r&&"value"===i,l="style"===r&&"_cssText"===i;if(l&&(o=addHoverClass(o)),a||l){var s=t.createTextNode(o);n.appendChild(s);continue}if("iframe"===r&&"src"===i)continue;try{e.isSVG&&"xlink:href"===i?n.setAttributeNS("http://www.w3.org/1999/xlink",i,o):n.setAttribute(i,o)}catch(e){}}else e.attributes.rr_width&&(n.style.width=e.attributes.rr_width),e.attributes.rr_height&&(n.style.height=e.attributes.rr_height);return n;case NodeType.Text:return t.createTextNode(e.isStyle?addHoverClass(e.textContent):e.textContent);case NodeType.CDATA:return t.createCDATASection(e.textContent);case NodeType.Comment:return t.createComment(e.textContent);default:return null}}function buildNodeWithSN(e,t,r,n){void 0===n&&(n=!1);var i=buildNode(e,t);if(!i)return null;if(e.type===NodeType.Document&&(t.close(),t.open(),i=t),i.__sn=e,r[e.id]=i,(e.type===NodeType.Document||e.type===NodeType.Element)&&!n)for(var o=0,a=e.childNodes;o<a.length;o++){var l=a[o],s=buildNodeWithSN(l,t,r);s?i.appendChild(s):console.warn("Failed to rebuild",l)}return i}function rebuild(e,t){var r={};return[buildNodeWithSN(e,t,r),r]}export{snapshot,serializeNodeWithId,rebuild,buildNodeWithSN,NodeType}; | ||
//# sourceMappingURL=rrweb-snapshot.min.js.map |
@@ -18,5 +18,2 @@ 'use strict'; | ||
} | ||
function resetId() { | ||
_id = 1; | ||
} | ||
function getCssRulesString(s) { | ||
@@ -228,7 +225,12 @@ try { | ||
} | ||
var serializedNode = Object.assign(_serializedNode, { | ||
id: genId() | ||
}); | ||
var id; | ||
if ('__sn' in n) { | ||
id = n.__sn.id; | ||
} | ||
else { | ||
id = genId(); | ||
} | ||
var serializedNode = Object.assign(_serializedNode, { id: id }); | ||
n.__sn = serializedNode; | ||
map[serializedNode.id] = n; | ||
map[id] = n; | ||
var recordChild = !skipChild; | ||
@@ -255,3 +257,2 @@ if (serializedNode.type === exports.NodeType.Element) { | ||
if (inlineStylesheet === void 0) { inlineStylesheet = true; } | ||
resetId(); | ||
var idNodeMap = {}; | ||
@@ -356,3 +357,8 @@ return [ | ||
try { | ||
node.setAttribute(name, value); | ||
if (n.isSVG && name === 'xlink:href') { | ||
node.setAttributeNS('http://www.w3.org/1999/xlink', name, value); | ||
} | ||
else { | ||
node.setAttribute(name, value); | ||
} | ||
} | ||
@@ -418,4 +424,3 @@ catch (error) { | ||
exports.serializeNodeWithId = serializeNodeWithId; | ||
exports.resetId = resetId; | ||
exports.rebuild = rebuild; | ||
exports.buildNodeWithSN = buildNodeWithSN; |
{ | ||
"name": "rrweb-snapshot", | ||
"version": "0.7.10", | ||
"version": "0.7.11", | ||
"description": "rrweb's component to take a snapshot of DOM, aka DOM serializer", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -1,4 +0,4 @@ | ||
import snapshot, { serializeNodeWithId, resetId } from './snapshot'; | ||
import snapshot, { serializeNodeWithId } from './snapshot'; | ||
import rebuild, { buildNodeWithSN } from './rebuild'; | ||
export * from './types'; | ||
export { snapshot, serializeNodeWithId, resetId, rebuild, buildNodeWithSN }; | ||
export { snapshot, serializeNodeWithId, rebuild, buildNodeWithSN }; |
@@ -1,6 +0,5 @@ | ||
import { serializedNodeWithId, idNodeMap } from './types'; | ||
export declare function resetId(): void; | ||
import { serializedNodeWithId, INode, idNodeMap } from './types'; | ||
export declare function absoluteToStylesheet(cssText: string, href: string): string; | ||
export declare function serializeNodeWithId(n: Node, doc: Document, map: idNodeMap, blockClass: string | RegExp, skipChild?: boolean, inlineStylesheet?: boolean): serializedNodeWithId | null; | ||
export declare function serializeNodeWithId(n: Node | INode, doc: Document, map: idNodeMap, blockClass: string | RegExp, skipChild?: boolean, inlineStylesheet?: boolean): serializedNodeWithId | null; | ||
declare function snapshot(n: Document, blockClass?: string | RegExp, inlineStylesheet?: boolean): [serializedNodeWithId | null, idNodeMap]; | ||
export default snapshot; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112272
1368