single-file-extension-editor-helper.js 3.9 KB

1
  1. !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).singlefile={})}(this,(function(e){"use strict";const t=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],a=[{tagName:"head",accept:e=>!e.childNodes.length||1==e.childNodes[0].nodeType},{tagName:"body",accept:e=>!e.childNodes.length}],n=[{tagName:"html",accept:e=>!e||8!=e.nodeType},{tagName:"head",accept:e=>!e||8!=e.nodeType&&(3!=e.nodeType||!p(e.textContent))},{tagName:"body",accept:e=>!e||8!=e.nodeType},{tagName:"li",accept:(e,t)=>!e&&t.parentElement&&("UL"==t.parentElement.tagName||"OL"==t.parentElement.tagName)||e&&["LI"].includes(e.tagName)},{tagName:"dt",accept:e=>!e||["DT","DD"].includes(e.tagName)},{tagName:"p",accept:e=>e&&["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DETAILS","DIV","DL","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","H1","H2","H3","H4","H5","H6","HEADER","HR","MAIN","NAV","OL","P","PRE","SECTION","TABLE","UL"].includes(e.tagName)},{tagName:"dd",accept:e=>!e||["DT","DD"].includes(e.tagName)},{tagName:"rt",accept:e=>!e||["RT","RP"].includes(e.tagName)},{tagName:"rp",accept:e=>!e||["RT","RP"].includes(e.tagName)},{tagName:"optgroup",accept:e=>!e||["OPTGROUP"].includes(e.tagName)},{tagName:"option",accept:e=>!e||["OPTION","OPTGROUP"].includes(e.tagName)},{tagName:"colgroup",accept:e=>!e||8!=e.nodeType&&(3!=e.nodeType||!p(e.textContent))},{tagName:"caption",accept:e=>!e||8!=e.nodeType&&(3!=e.nodeType||!p(e.textContent))},{tagName:"thead",accept:e=>!e||["TBODY","TFOOT"].includes(e.tagName)},{tagName:"tbody",accept:e=>!e||["TBODY","TFOOT"].includes(e.tagName)},{tagName:"tfoot",accept:e=>!e},{tagName:"tr",accept:e=>!e||["TR"].includes(e.tagName)},{tagName:"td",accept:e=>!e||["TD","TH"].includes(e.tagName)},{tagName:"th",accept:e=>!e||["TD","TH"].includes(e.tagName)}],c=["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"];function o(e,p,m){return 3==e.nodeType?function(e){const t=e.parentNode;let a;t&&1==t.nodeType&&(a=t.tagName.toLowerCase());return!a||c.includes(a)?"script"==a?e.textContent.replace(/<\//gi,"<\\/").replace(/\/>/gi,"\\/>"):e.textContent:e.textContent.replace(/&/g,"&amp;").replace(/\u00a0/g,"&nbsp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}(e):8==e.nodeType?"\x3c!--"+e.textContent+"--\x3e":1==e.nodeType?function(e,c,p){const m=e.tagName.toLowerCase(),l=c&&a.find((t=>m==t.tagName&&t.accept(e)));let s="";l&&!e.attributes.length||(s="<"+m,Array.from(e.attributes).forEach((t=>s+=function(e,t,a){const n=e.name;let c="";if(!n.match(/["'>/=]/)){let o,p=e.value;a&&"class"==n&&(p=Array.from(t.classList).map((e=>e.trim())).join(" ")),p=p.replace(/&/g,"&amp;").replace(/\u00a0/g,"&nbsp;"),p.includes('"')&&(p.includes("'")||!a?p=p.replace(/"/g,"&quot;"):o=!0);const m=!a||!p.match(/^[^ \t\n\f\r'"`=<>]+$/);c+=" ",e.namespace?"http://www.w3.org/XML/1998/namespace"==e.namespaceURI?c+="xml:"+n:"http://www.w3.org/2000/xmlns/"==e.namespaceURI?("xmlns"!==n&&(c+="xmlns:"),c+=n):"http://www.w3.org/1999/xlink"==e.namespaceURI?c+="xlink:"+n:c+=n:c+=n,""!=p&&(c+="=",m&&(c+=o?"'":'"'),c+=p,m&&(c+=o?"'":'"'))}return c}(t,e,c))),s+=">");"TEMPLATE"!=e.tagName||e.childNodes.length?Array.from(e.childNodes).forEach((e=>s+=o(e,c,p||"svg"==m))):s+=e.innerHTML;const d=c&&n.find((t=>m==t.tagName&&t.accept(e.nextSibling,e)));(p||!d&&!t.includes(m))&&(s+="</"+m+">");return s}(e,p,m):void 0}function p(e){return Boolean(e.match(/^[ \t\n\f\r]/))}const m={serialize:(e,t)=>function(e,t){const a=e.doctype;let n="";return a&&(n="<!DOCTYPE "+a.nodeName,a.publicId?(n+=' PUBLIC "'+a.publicId+'"',a.systemId&&(n+=' "'+a.systemId+'"')):a.systemId&&(n+=' SYSTEM "'+a.systemId+'"'),a.internalSubset&&(n+=" ["+a.internalSubset+"]"),n+="> "),n+o(e.documentElement,t)}(e,t)};e.helper=m,Object.defineProperty(e,"__esModule",{value:!0})}));