-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyfill-svg-uri.min.js
1 lines (1 loc) · 3.17 KB
/
polyfill-svg-uri.min.js
1
!function(e){"use strict";function t(){var t,r,o,n,c,l,u,i=!!document.uniqueID,s=Function.prototype.call.bind(Array.prototype.slice),a=new RegExp("^data:(.+?),(.*)$"),y=new RegExp("\\burl\\((?:('|\")(.*?)\\1|(.*?))\\)","g");function f(e){return(e+"").replace(a,function(e,t,r){return(t=t.split(";")).indexOf("image/svg+xml")>-1&&-1===t.indexOf("base64")&&/^<svg\b/i.test(r)&&(t=t.filter(function(e){return"utf8"!==e&&"charset=utf-8"!==e}),i?(r=encodeURIComponent(decodeURIComponent(r)),t.push("charset=utf-8")):(r=r.replace(/#/g,"%23"),t.push("utf8"))),"data:"+t.join(";")+","+r})}function p(e){return(e+"").replace(y,function(e,t,r,o){return"url("+(t=t||"")+f(r||o)+t+")"})}function d(t){var r,o,n,c;for(c=t.length-1;c>=0;c--)if(r=t[c],(o=t.getPropertyValue(r))&&(n=p(o))!==o)try{t.setProperty(r,n,t.getPropertyPriority(r))}catch(t){e.console.warn("Couldn't set property.",t,r)}}s(document.styleSheets).forEach(function e(t){try{t.style&&d(t.style)}catch(e){}try{t.cssRules&&s(t.cssRules).forEach(e)}catch(e){}try{t.styleSheet&&e(t.styleSheet)}catch(e){}}),["src","data"].forEach(function(e){s(document.querySelectorAll("["+e+'^="data:"]')).forEach(function(t){t[e]=f(t[e])})}),s(document.querySelectorAll("[style]")).forEach(function(e){d(e.style)}),(t=e.CSSStyleDeclaration&&e.CSSStyleDeclaration.prototype)&&((l=t.setProperty)&&(t.setProperty=function(e,t,r){l.call(this,e,p(t),r||"")}),(r=(Object.prototype.toString.call(document.body.style)||"").replace(/^\[object (.+?)\]$/,"$1"))&&("CSS2Properties"===r||"CSS3Properties"===r||"CSSProperties"===r?(o=e[r].prototype,n=Object.keys(o)):"MSStyleCSSProperties"===r?(o=t,n=Object.keys(o)):(o=t,-1===(n=Object.keys(o)).indexOf("color")&&(n=Object.keys(document.body.style),c=document.body.style,-1===n.indexOf("color")&&(n=Object.keys(e.getComputedStyle(document.body,""))))),n.forEach(function(e){var t,r=Object.getOwnPropertyDescriptor(c||o,e);r&&r.enumerable&&(c||r.set)&&(c?Object.defineProperty(o,e,{configurable:!0,enumerable:!0,get:function(){return o.getPropertyValue.call(this,e)},set:function(t){o.setProperty.call(this,e,t,"")}}):(t=r.set,Object.defineProperty(o,e,{configurable:r.configurable,enumerable:r.enumerable,get:r.get,set:function(e){t.call(this,p(e))}})))})),n&&-1!==n.indexOf("cssText")||function(e){var r;e&&e.set&&(r=e.set,Object.defineProperty(t,"cssText",{configurable:e.configurable,enumerable:e.enumerable,get:e.get,set:function(e){r.call(this,p(e))}}))}(Object.getOwnPropertyDescriptor(t,"cssText"))),function(e){var t;e&&((t=e.insertRule)&&(e.insertRule=function(e,r){t.call(this,p(e),r)}),function(t){t&&(e.addRule=function(e,r,o){t.call(this,e,p(r),o)})}(e.addRule))}(e.CSSStyleSheet&&e.CSSStyleSheet.prototype),(u=e.HTMLElement)&&Object.getOwnPropertyNames(e).forEach(function(t){var r;try{r=e[t]&&e[t].prototype}catch(r){return void e.console.warn("Couldn't get prototype.",r,t)}r&&u.prototype.isPrototypeOf(r)&&["src","data"].forEach(function(e){var t,o;(t=Object.getOwnPropertyDescriptor(r,e))&&t.set&&(o=t.set,Object.defineProperty(r,e,{configurable:t.configurable,enumerable:t.enumerable,get:t.get,set:function(e){o.call(this,f(e))}}))})})}"complete"===document.readyState?t():document.addEventListener("DOMContentLoaded",t,!1)}(Function("return this")());