!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define("jSecure",e):t.jSecure=e()}(this,function(){"use strict";function t(){}function e(){return"undefined"==typeof document?!0:"textContent"in document.createElement("div")}function r(t){return t.indexOf("<")>-1||t.indexOf("&")>-1}function n(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t}function o(t){return t.reduce(function(t,e){return t.concat(e)},[])}function i(t){t=U(t)?t:[t];var e,r,n,o=0,i="<(?!/?";return i+="(?:",L(t,function(t,a){e=t.tags||v,r=t.attrs||E,n=t.checkUrlAttrs||!1,0!==a&&(i+="|"),i+="(?:"+e.join("|")+")",i+="(?:",i+=M,i+="|"+O,i+="(?:(?:",i+="(?:"+r+")(?:=([\"'])[^'\"<>]*\\"+ ++o+")?",n&&(i+="|(?:"+S+")=([\"'])(?:(?:"+T+")(?::|&#(?:58|x3a);)|(?:"+x+")|[/.#?]|&#(?:35|4[67]|63|x(?:2[3ef]|3f));)[^'\"<>]*\\"+ ++o),i+=")"+M+")+",i+=")"}),i+=")",i+="/?>)",new RegExp(i,"i")}function a(t){return t=t||v,i({tags:t,checkUrlAttrs:!0})}function l(){var t={tag:"li-icon",attrs:"active|a11y-text|animate|color|size|type"};return i([{tags:v,checkUrlAttrs:!0},{tags:[t.tag],attrs:[h,t.attrs].join("|"),checkUrlAttrs:!1}])}function u(t,e){var r;e=e||{};var n=e.allowTags,o=e.hasCustomElementMarkup!==!1;return n?(r=a(n),!r.test(t)):o?!u.R_UNSAFE_CUSTOM_ELEMENT.test(t):!u.R_UNSAFE_HTML.test(t)}function c(t){return t.replace(/<[^>]*>|[<>'"&\\]/g,"")}function s(t,e,n){var o=e?d(t,e):t,i=t;return r(o)&&!u(o,n)&&(o=c(o),j("Content contains non-whitelisted tags or attributes:\nContent: "+i,"error")),o}function d(e,r){var n={};return e.replace(/\{([^}]+)\}/g,function(e,o){var i,a,l=e;if(n.hasOwnProperty(o))return n[o];if(r.hasOwnProperty(o)){if(l=r[o],i="string"==typeof l,a="number"==typeof l,!(i||l instanceof t||a))throw new Error("Only strings, numbers, and jSecure types are allowed as placeholder replacements.");l=i?A(l):l.toString()}return n[o]=l,l})}function f(t,e){for(var r=+e.length,n=0,o=t.length;r>n;n++)t[o++]=e[n];return t.length=o,t}function p(t,e){var r,n,o,i,a,l,u,c,s=e.createDocumentFragment(),d=[];for(l=0,c=t.length;c>l;l++)if(a=t[l],a||0===a)if("string"==typeof a){for(i=i||s.appendChild(e.createElement("div")),r=(k.exec(a)||["",""])[1].toLowerCase(),n=N[r]||N._default,o=n[1]+a+n[2],C.setElementContent(i,o),u=n[0];u--;)i.lastChild&&i.lastChild.nodeType===Node.ELEMENT_NODE&&(i=i.lastChild);f(d,i.childNodes),i=s.firstChild,i.textContent=""}else f(d,a.nodeType?[a]:a);for(s.textContent="",l=0,a=d[l];a;)s.appendChild(a),l++,a=d[l];return s}function g(t,e){e=e||document.implementation&&document.implementation.createHTMLDocument?document.implementation.createHTMLDocument(""):document;var r;if("string"==typeof t)r=p([t],e);else{if(!U(t))return t;r=p(t,e)}return f([],r.childNodes)}var h="aria-[a-z0-9_\\-]+|class|data-[a-z0-9_\\-]+|dir|id|role|tabindex",m="alt|checked|colgroup|cols|colspan|disabled|height|hidden|maxlength|method|multiple|name|placeholder|readonly|rel|required|rows|rowspan|spellcheck|target|title|width",b="border|caption|color|controls|coords|hreflang|label|lang|loop|marginheight|marginwidth|preload|reversed|type|usemap|clear|headers|ismap|start|datetime|accept|max|min|size|step",y=e()?"textContent":"innerText",w=["b","del","em","i","s","strong","sub","sup"],v=w.concat(["a","abbr","address","area","article","aside","audio","bdi","bdo","big","blockquote","br","button","center","cite","code","datalist","dd","details","dfn","div","dl","dt","fieldset","figcaption","figure","font","footer","h1","h2","h3","h4","h5","h6","header","hgroup","hr","img","ins","kbd","label","legend","li","map","mark","marquee","nav","nobr","ol","p","pre","q","rp","rt","ruby","samp","section","small","source","span","strike","table","tbody","td","tfoot","th","thead","time","tr","u","ul","var","video","wbr"]),E=[h,m,b].join("|"),S="href|src",x="data:image/(?:gif|jpg|jpeg|png);base64,",T="https?|ftp|mailto",_="&#?[a-zA-Z0-9]{1,10};",C=(new RegExp(_),{ALLOWED_TAGS:v,FORMATTING_TAGS:w}),j=C.log=function(t,e){if(e=e||"log",window&&window.jet&&"error"===e.toLowerCase())try{throw new Error(t)}catch(r){try{window.jet.error(r)}catch(n){}}"undefined"!=typeof console&&"function"==typeof console[e]&&console[e](t)},A=(C.unsafe=function(t){return t},C.htmlEncode=function(){var t,e=/[&<>"'\u0000\\=]/g;return t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","\x00":"�","\\":"&#92;","=":"&#61;"},function(r){return null===r||void 0===r?null:r.toString().replace(e,function(e){return t[e]})}}()),U=(C.htmlUnencode=function(){function t(t){var r;return o.hasOwnProperty(t)?o[t]:(e.innerHTML="&"+t+";",r=e[y],o[t]=r,r)}var e,r,n=/&(?:([a-z0-9]+)|#x([\da-f]{1,6})|#(\d{1,8}));/gi;if("undefined"==typeof document)return function(){throw new Error("document is undefined (i.e. you are probably in Node.js)")};e=document.createElement("div");var o={nbsp:" ",lt:"<",gt:">",amp:"&",quot:'"'};return r="function"==typeof String.fromCodePoint?function(t){return String.fromCodePoint(t)}:function(t){return 65535>=t?String.fromCharCode(t):"�"},function(e){return null===e||void 0===e?null:(e+"").replace(n,function(e,n,o,i){return n?t(n):o||i?r(parseInt(o||i,o?16:10)||65533):"�"})}}(),C.reEncode=function(t){return C.htmlEncode(C.htmlUnencode(t))},C.text=function(t){return C.log("jSecure.text() is deprecated. Please use jSecure.htmlEncode().","warn"),C.htmlEncode(t)},Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}),L=function(){return Array.prototype.forEach?function(t,e){Array.prototype.forEach.call(t,e)}:function(t,e){for(var r=0,n=t.length;n>r;r++)e(t[r],r)}}(),M="[ 	\r\n]*",O="[ 	\r\n]+";u.R_UNSAFE_HTML=a(),u.R_UNSAFE_CUSTOM_ELEMENT=l();var N={option:[1,'<select multiple="multiple">',"</select>"],thead:[1,"<table>","</table>"],col:[2,"<table><colgroup>","</colgroup></table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[0,"",""]};N.optgroup=N.option,N.tbody=N.tfoot=N.colgroup=N.caption=N.thead,N.th=N.td;var k=/<([\w:]+)/;C.processTemplate=s,C.sanitizeHTML=function(t){return s(t)},C.setElementContent=function(t,e,n){var o=s(e,n);return r(o)?t.innerHTML=o:t[y]=o,o};C.parseHTML=g;var R=(C.parseSelector=function(t){var e=/^(?:\s*(<[\w\W]+>)[^>]*)$/;return"string"==typeof t&&e.test(t)?[]:t},C.UnsafeString=function(t,e){return this instanceof R?(e=e||{},e.allowTags=e.allowTags?o(e.allowTags):null,this._string=t,void(this._options=e)):new R(t,e)});R.prototype=n(new t,{toString:function(){var t=this._string,e=this._stringVal,r=t;return void 0!==e?e:(u(t,this._options)||(r=t,t=c(t),C.log("UnsafeString contains non-whitelisted tags or attributes.\nString: "+r,"error")),this._stringVal=t,t)}});var z="https?|ftp|mailto|tel|sms|blob|voyager|android-app|chrome-extension",H="data:(?:(?:image/(?:gif|jpe?g|png))|(?:application/x-font-woff)|(?:font/(?:opentype|ttf)))[;,]",q="[/.#?]",P=/ /g,F=/[\s\u0000<>"]|%00/,D=/\\/,W=/;/,G=/([.]|%2e){2}/i,I=new RegExp("^(?:"+z+"|"+H+"|"+q+")"),V=new RegExp("^(?:"+H+")"),Z=(C.sanitizeUrl=function(t){var e=void 0,r="invalid://";if("string"!=typeof t)return C.log("jSecure Warning: url must be a string","error"),r;if(e=t.trim(),e.indexOf(" ")>-1&&(C.log("jSecure Warning: url should not contain spaces: "+t,"warn"),e=e.replace(P,"+")),!I.test(e))return C.log("jSecure Error: URL should be absolute with allowed schemas, relative, a hash fragment or query string. "+t,"error"),r;if(F.test(e))return C.log("jSecure Error: not valid url character found in url: "+t,"error"),r;var n=e.split("?")[0];return W.test(n)&&!V.test(e)||D.test(n)||G.test(n)||G.test(decodeURI(n))?(C.log("jSecure Error: malicious data found in url path: "+n,"error"),r):t},C._redirect=function(t){window&&(window.location.href=t)},C.redirect=function(t){var e=void 0;e=C.sanitizeUrl(t),e===t&&C._redirect(e)},C);return Z});