Files
typecho/admin/js/purify.js
Lu Fei 438ac35487 Implement Ctrl+S or Command+S for save draft (#1628)
* Implement Ctrl+S or Command+S for save draft

* rename

* add Typecho.savePost

* fix upload file size

* add new uploader

* replace new uploader

* fix textarea change

* fix preview

* refactor post edit

* fix issue

* fix page edit

---------

Co-authored-by: joyqi <joyqi@segmentfault.com>
Co-authored-by: joyqi <magike.net@gmail.com>
2023-10-01 16:51:09 +08:00

1 line
17 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).DOMPurify=t()}(this,function(){"use strict";var r,o=Object.hasOwnProperty,i=Object.setPrototypeOf,a=Object.isFrozen,l=Object.getPrototypeOf,c=Object.getOwnPropertyDescriptor,Re=Object.freeze,e=Object.seal,s=Object.create,t="undefined"!=typeof Reflect&&Reflect,u=(u=t.apply)||function(e,t,n){return e.apply(t,n)},Re=Re||function(e){return e},e=e||function(e){return e},m=(m=t.construct)||function(e,t){return new(Function.prototype.bind.apply(e,[null].concat(function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}(t))))},_e=p(Array.prototype.forEach),Ne=p(Array.prototype.pop),Oe=p(Array.prototype.push),Me=p(String.prototype.toLowerCase),Le=p(String.prototype.match),Fe=p(String.prototype.replace),Ie=p(String.prototype.indexOf),Je=p(String.prototype.trim),Ce=p(RegExp.prototype.test),ze=(r=TypeError,function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return m(r,t)});function p(o){return function(e){for(var t=arguments.length,n=Array(1<t?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return u(o,e,n)}}function Ue(e,t){i&&i(e,null);for(var n=t.length;n--;){var r,o=t[n];"string"==typeof o&&(r=Me(o))!==o&&(a(t)||(t[n]=r),o=r),e[o]=!0}return e}function He(e){var t=s(null),n=void 0;for(n in e)u(o,e,[n])&&(t[n]=e[n]);return t}function je(e,t){for(;null!==e;){var n=c(e,t);if(n){if(n.get)return p(n.get);if("function"==typeof n.value)return p(n.value)}e=l(e)}return function(e){return console.warn("fallback value for",e),null}}var Pe=Re(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),Be=Re(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),We=Re(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Qe=Re(["animate","color-profile","cursor","discard","fedropshadow","feimage","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),Ge=Re(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover"]),et=Re(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),qe=Re(["#text"]),Ke=Re(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","xmlns","slot"]),Ve=Re(["accent-height","accumulate","additive","alignment-baseline","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","targetx","targety","transform","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Ye=Re(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),Xe=Re(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),tt=e(/\{\{[\s\S]*|[\s\S]*\}\}/gm),nt=e(/<%[\s\S]*|[\s\S]*%>/gm),rt=e(/^data-[\-\w.\u00B7-\uFFFF]/),ot=e(/^aria-[\-\w]+$/),it=e(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),at=e(/^(?:\w+script|data):/i),lt=e(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),$e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function Ze(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}return function C(e){var l=0<arguments.length&&void 0!==e?e:"undefined"==typeof window?null:window,s=function(e){return C(e)};if(s.version="2.2.9",s.removed=[],l&&l.document&&9===l.document.nodeType){var c=l.document,o=l.document,z=l.DocumentFragment,e=l.HTMLTemplateElement,u=l.Node,U=l.Element,t=l.NodeFilter,H=void 0===(n=l.NamedNodeMap)?l.NamedNodeMap||l.MozNamedAttrMap:n,j=l.Text,P=l.Comment,B=l.DOMParser,n=l.trustedTypes,W=je(r=U.prototype,"cloneNode"),G=je(r,"nextSibling"),q=je(r,"childNodes"),m=je(r,"parentNode"),p=("function"==typeof e&&(r=o.createElement("template")).content&&r.content.ownerDocument&&(o=r.content.ownerDocument),function(e,t){if("object"!==(void 0===e?"undefined":$e(e))||"function"!=typeof e.createPolicy)return null;var n=null,r="data-tt-policy-suffix",t="dompurify"+((n=t.currentScript&&t.currentScript.hasAttribute(r)?t.currentScript.getAttribute(r):n)?"#"+n:"");try{return e.createPolicy(t,{createHTML:function(e){return e}})}catch(e){return console.warn("TrustedTypes policy "+t+" could not be created."),null}}(n,c)),K=p&&D?p.createHTML(""):"",e=o,i=e.implementation,V=e.createNodeIterator,Y=e.createDocumentFragment,X=c.importNode,r={};try{r=He(o).documentMode?o.documentMode:{}}catch(e){}var $,a={},f=(s.isSupported="function"==typeof m&&i&&void 0!==i.createHTMLDocument&&9!==r,tt),d=nt,Z=rt,J=ot,Q=at,ee=lt,g=it,h=null,te=Ue({},[].concat(Ze(Pe),Ze(Be),Ze(We),Ze(Ge),Ze(qe))),y=null,ne=Ue({},[].concat(Ze(Ke),Ze(Ve),Ze(Ye),Ze(Xe))),v=null,re=null,oe=!0,b=!0,ie=!1,A=!1,T=!1,w=!1,x=!1,S=!1,k=!1,ae=!0,D=!1,le=!0,E=!0,R=!1,_={},ce=Ue({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),se=null,ue=Ue({},["audio","video","img","source","image","track"]),me=null,pe=Ue({},["alt","class","for","id","label","name","pattern","placeholder","summary","title","value","style","xmlns"]),fe="http://www.w3.org/1998/Math/MathML",de="http://www.w3.org/2000/svg",N="http://www.w3.org/1999/xhtml",ge=N,O=null,he=o.createElement("form"),ye=function(e){O&&O===e||(e=He(e=e&&"object"===(void 0===e?"undefined":$e(e))?e:{}),h="ALLOWED_TAGS"in e?Ue({},e.ALLOWED_TAGS):te,y="ALLOWED_ATTR"in e?Ue({},e.ALLOWED_ATTR):ne,me="ADD_URI_SAFE_ATTR"in e?Ue(He(pe),e.ADD_URI_SAFE_ATTR):pe,se="ADD_DATA_URI_TAGS"in e?Ue(He(ue),e.ADD_DATA_URI_TAGS):ue,v="FORBID_TAGS"in e?Ue({},e.FORBID_TAGS):{},re="FORBID_ATTR"in e?Ue({},e.FORBID_ATTR):{},_="USE_PROFILES"in e&&e.USE_PROFILES,oe=!1!==e.ALLOW_ARIA_ATTR,b=!1!==e.ALLOW_DATA_ATTR,ie=e.ALLOW_UNKNOWN_PROTOCOLS||!1,A=e.SAFE_FOR_TEMPLATES||!1,T=e.WHOLE_DOCUMENT||!1,S=e.RETURN_DOM||!1,k=e.RETURN_DOM_FRAGMENT||!1,ae=!1!==e.RETURN_DOM_IMPORT,D=e.RETURN_TRUSTED_TYPE||!1,x=e.FORCE_BODY||!1,le=!1!==e.SANITIZE_DOM,E=!1!==e.KEEP_CONTENT,R=e.IN_PLACE||!1,g=e.ALLOWED_URI_REGEXP||g,ge=e.NAMESPACE||N,A&&(b=!1),k&&(S=!0),_&&(h=Ue({},[].concat(Ze(qe))),y=[],!0===_.html&&(Ue(h,Pe),Ue(y,Ke)),!0===_.svg&&(Ue(h,Be),Ue(y,Ve),Ue(y,Xe)),!0===_.svgFilters&&(Ue(h,We),Ue(y,Ve),Ue(y,Xe)),!0===_.mathMl)&&(Ue(h,Ge),Ue(y,Ye),Ue(y,Xe)),e.ADD_TAGS&&Ue(h=h===te?He(h):h,e.ADD_TAGS),e.ADD_ATTR&&Ue(y=y===ne?He(y):y,e.ADD_ATTR),e.ADD_URI_SAFE_ATTR&&Ue(me,e.ADD_URI_SAFE_ATTR),E&&(h["#text"]=!0),T&&Ue(h,["html","head","body"]),h.table&&(Ue(h,["tbody"]),delete v.tbody),Re&&Re(e),O=e)},ve=Ue({},["mi","mo","mn","ms","mtext"]),be=Ue({},["foreignobject","desc","title","annotation-xml"]),M=Ue({},Be),Ae=(Ue(M,We),Ue(M,Qe),Ue({},Ge)),L=(Ue(Ae,et),function(t){Oe(s.removed,{element:t});try{t.parentNode.removeChild(t)}catch(e){try{t.outerHTML=K}catch(e){t.remove()}}}),Te=function(e,t){try{Oe(s.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){Oe(s.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e&&!y[e])if(S||k)try{L(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},we=function(e){var t=void 0,n=void 0,r=(x?e="<remove></remove>"+e:n=(r=Le(e,/^[\r\n\t ]+/))&&r[0],p?p.createHTML(e):e);if(ge===N)try{t=(new B).parseFromString(r,"text/html")}catch(e){}if(!t||!t.documentElement){t=i.createDocument(ge,"template",null);try{t.documentElement.innerHTML=$?"":r}catch(e){}}return r=t.body||t.documentElement,e&&n&&r.insertBefore(o.createTextNode(n),r.childNodes[0]||null),T?t.documentElement:r},xe=function(e){return V.call(e.ownerDocument||e,e,t.SHOW_ELEMENT|t.SHOW_COMMENT|t.SHOW_TEXT,null,!1)},F=function(e){return"object"===(void 0===u?"undefined":$e(u))?e instanceof u:e&&"object"===(void 0===e?"undefined":$e(e))&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName},I=function(e,t,n){a[e]&&_e(a[e],function(e){e.call(s,t,n,O)})},Se=function(e){if(I("beforeSanitizeElements",e,null),((i=e)instanceof j||i instanceof P||"string"==typeof i.nodeName&&"string"==typeof i.textContent&&"function"==typeof i.removeChild&&i.attributes instanceof H&&"function"==typeof i.removeAttribute&&"function"==typeof i.setAttribute&&"string"==typeof i.namespaceURI&&"function"==typeof i.insertBefore)&&!Le(e.nodeName,/[\u0080-\uFFFF]/)){var t,n,r,o,i=Me(e.nodeName);if(I("uponSanitizeElement",e,{tagName:i,allowedTags:h}),F(e.firstElementChild)||F(e.content)&&F(e.content.firstElementChild)||!Ce(/<[/\w]/g,e.innerHTML)||!Ce(/<[/\w]/g,e.textContent)){if(h[i]&&!v[i])return e instanceof U&&((n=m(t=e))&&n.tagName||(n={namespaceURI:N,tagName:"template"}),r=Me(t.tagName),o=Me(n.tagName),t.namespaceURI===de?n.namespaceURI===N?"svg"!==r:n.namespaceURI===fe?"svg"!==r||"annotation-xml"!==o&&!ve[o]:!Boolean(M[r]):t.namespaceURI===fe?n.namespaceURI===N?"math"!==r:n.namespaceURI===de?"math"!==r||!be[o]:!Boolean(Ae[r]):t.namespaceURI!==N||n.namespaceURI===de&&!be[o]||n.namespaceURI===fe&&!ve[o]||(n=Ue({},["title","style","font","a","script"]),Ae[r])||!n[r]&&M[r])||("noscript"===i||"noembed"===i)&&Ce(/<\/no(script|embed)/i,e.innerHTML)?(L(e),!0):(A&&3===e.nodeType&&(t=e.textContent,t=Fe(t,f," "),t=Fe(t,d," "),e.textContent!==t)&&(Oe(s.removed,{element:e.cloneNode()}),e.textContent=t),I("afterSanitizeElements",e,null),!1);if(E&&!ce[i]){var a=m(e)||e.parentNode,l=q(e)||e.childNodes;if(l&&a)for(var c=l.length-1;0<=c;--c)a.insertBefore(W(l[c],!0),G(e))}}}return L(e),!0},ke=function(e,t,n){if(le&&("id"===t||"name"===t)&&(n in o||n in he))return!1;if(!(b&&Ce(Z,t)||oe&&Ce(J,t))){if(!y[t]||re[t])return!1;if(!me[t]&&!Ce(g,Fe(n,ee,""))&&("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==Ie(n,"data:")||!se[e])&&(!ie||Ce(Q,Fe(n,ee,"")))&&n)return!1}return!0},De=function(e){var t=void 0,n=void 0,r=(I("beforeSanitizeAttributes",e,null),e.attributes);if(r){for(var o={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:y},n=r.length;n--;){var i=(l=r[n]).name,a=l.namespaceURI,t=Je(l.value),l=Me(i);if(o.attrName=l,o.attrValue=t,o.keepAttr=!0,o.forceKeepAttr=void 0,I("uponSanitizeAttribute",e,o),t=o.attrValue,!o.forceKeepAttr&&(Te(i,e),o.keepAttr))if(Ce(/\/>/i,t))Te(i,e);else{A&&(t=Fe(t,f," "),t=Fe(t,d," "));var c=e.nodeName.toLowerCase();if(ke(c,l,t))try{a?e.setAttributeNS(a,i,t):e.setAttribute(i,t),Ne(s.removed)}catch(e){}}}I("afterSanitizeAttributes",e,null)}},Ee=function e(t){var n,r=xe(t);for(I("beforeSanitizeShadowDOM",t,null);n=r.nextNode();)I("uponSanitizeShadowNode",n,null),Se(n)||(n.content instanceof z&&e(n.content),De(n));I("afterSanitizeShadowDOM",t,null)};s.sanitize=function(e,t){var n,r=void 0,o=void 0,i=void 0;if("string"!=typeof(e=($=!e)?"\x3c!--\x3e":e)&&!F(e)){if("function"!=typeof e.toString)throw ze("toString is not a function");if("string"!=typeof(e=e.toString()))throw ze("dirty is not a string, aborting")}if(!s.isSupported){if("object"===$e(l.toStaticHTML)||"function"==typeof l.toStaticHTML){if("string"==typeof e)return l.toStaticHTML(e);if(F(e))return l.toStaticHTML(e.outerHTML)}return e}if(w||ye(t),s.removed=[],!(R="string"!=typeof e&&R))if(e instanceof u)1===(t=(r=we("\x3c!----\x3e")).ownerDocument.importNode(e,!0)).nodeType&&"BODY"===t.nodeName||"HTML"===t.nodeName?r=t:r.appendChild(t);else{if(!S&&!A&&!T&&-1===e.indexOf("<"))return p&&D?p.createHTML(e):e;if(!(r=we(e)))return S?null:K}r&&x&&L(r.firstChild);for(var a=xe(R?e:r);n=a.nextNode();)3===n.nodeType&&n===o||Se(n)||(n.content instanceof z&&Ee(n.content),De(n),o=n);if(o=null,R)return e;if(S){if(k)for(i=Y.call(r.ownerDocument);r.firstChild;)i.appendChild(r.firstChild);else i=r;return i=ae?X.call(c,i,!0):i}return t=T?r.outerHTML:r.innerHTML,A&&(t=Fe(t,f," "),t=Fe(t,d," ")),p&&D?p.createHTML(t):t},s.setConfig=function(e){ye(e),w=!0},s.clearConfig=function(){O=null,w=!1},s.isValidAttribute=function(e,t,n){return O||ye({}),e=Me(e),t=Me(t),ke(e,t,n)},s.addHook=function(e,t){"function"==typeof t&&(a[e]=a[e]||[],Oe(a[e],t))},s.removeHook=function(e){a[e]&&Ne(a[e])},s.removeHooks=function(e){a[e]&&(a[e]=[])},s.removeAllHooks=function(){a={}}}else s.isSupported=!1;return s}()});