-
Notifications
You must be signed in to change notification settings - Fork 18
/
imgix-js-core.umd.js
1 lines (1 loc) · 16.3 KB
/
imgix-js-core.umd.js
1
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ImgixClient=e()}(this,function(){"use strict";function e(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function s(n){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?e(Object(o),!0).forEach(function(t){var e,r;e=n,t=o[r=t],r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach(function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(o,t))})}return n}function c(t){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function l(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i=[],a=!0,u=!1;try{for(r=r.call(t);!(a=(n=r.next()).done)&&(i.push(n.value),!e||i.length!==e);a=!0);}catch(t){u=!0,o=t}finally{try{a||null==r.return||r.return()}finally{if(u)throw o}}return i}}(t,e)||r(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||r(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Map"===(r="Object"===r&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function t(t,e){return t(e={exports:{}},e.exports),e.exports}function i(t){return null!=t&&(d(t)||"function"==typeof(e=t).readFloatLE&&"function"==typeof e.slice&&d(e.slice(0,0))||!!t._isBuffer);var e}var a=t(function(t){var i,r;i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&r.rotl(t,8)|4278255360&r.rotl(t,24);for(var e=0;e<t.length;e++)t[e]=r.endian(t[e]);return t},randomBytes:function(t){for(var e=[];0<t;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],r=0,n=0;r<t.length;r++,n+=8)e[n>>>5]|=t[r]<<24-n%32;return e},wordsToBytes:function(t){for(var e=[],r=0;r<32*t.length;r+=8)e.push(t[r>>>5]>>>24-r%32&255);return e},bytesToHex:function(t){for(var e=[],r=0;r<t.length;r++)e.push((t[r]>>>4).toString(16)),e.push((15&t[r]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],r=0;r<t.length;r+=2)e.push(parseInt(t.substr(r,2),16));return e},bytesToBase64:function(t){for(var e=[],r=0;r<t.length;r+=3)for(var n=t[r]<<16|t[r+1]<<8|t[r+2],o=0;o<4;o++)8*r+6*o<=8*t.length?e.push(i.charAt(n>>>6*(3-o)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],r=0,n=0;r<t.length;n=++r%4)0!=n&&e.push((i.indexOf(t.charAt(r-1))&Math.pow(2,-2*n+8)-1)<<2*n|i.indexOf(t.charAt(r))>>>6-2*n);return e}},t.exports=r}),u={utf8:{stringToBytes:function(t){return u.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(u.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var e=[],r=0;r<t.length;r++)e.push(255&t.charCodeAt(r));return e},bytesToString:function(t){for(var e=[],r=0;r<t.length;r++)e.push(String.fromCharCode(t[r]));return e.join("")}}},h=u;function d(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var y=t(function(t){function p(t,e){t.constructor==String?t=(e&&"binary"===e.encoding?w:m).stringToBytes(t):v(t)?t=Array.prototype.slice.call(t,0):Array.isArray(t)||(t=t.toString());for(var r=g.bytesToWords(t),t=8*t.length,n=1732584193,o=-271733879,i=-1732584194,a=271733878,u=0;u<r.length;u++)r[u]=16711935&(r[u]<<8|r[u]>>>24)|4278255360&(r[u]<<24|r[u]>>>8);r[t>>>5]|=128<<t%32,r[14+(64+t>>>9<<4)]=t;for(var s=p._ff,c=p._gg,l=p._hh,f=p._ii,u=0;u<r.length;u+=16){var h=n,d=o,y=i,b=a,n=s(n,o,i,a,r[u+0],7,-680876936),a=s(a,n,o,i,r[u+1],12,-389564586),i=s(i,a,n,o,r[u+2],17,606105819),o=s(o,i,a,n,r[u+3],22,-1044525330);n=s(n,o,i,a,r[u+4],7,-176418897),a=s(a,n,o,i,r[u+5],12,1200080426),i=s(i,a,n,o,r[u+6],17,-1473231341),o=s(o,i,a,n,r[u+7],22,-45705983),n=s(n,o,i,a,r[u+8],7,1770035416),a=s(a,n,o,i,r[u+9],12,-1958414417),i=s(i,a,n,o,r[u+10],17,-42063),o=s(o,i,a,n,r[u+11],22,-1990404162),n=s(n,o,i,a,r[u+12],7,1804603682),a=s(a,n,o,i,r[u+13],12,-40341101),i=s(i,a,n,o,r[u+14],17,-1502002290),n=c(n,o=s(o,i,a,n,r[u+15],22,1236535329),i,a,r[u+1],5,-165796510),a=c(a,n,o,i,r[u+6],9,-1069501632),i=c(i,a,n,o,r[u+11],14,643717713),o=c(o,i,a,n,r[u+0],20,-373897302),n=c(n,o,i,a,r[u+5],5,-701558691),a=c(a,n,o,i,r[u+10],9,38016083),i=c(i,a,n,o,r[u+15],14,-660478335),o=c(o,i,a,n,r[u+4],20,-405537848),n=c(n,o,i,a,r[u+9],5,568446438),a=c(a,n,o,i,r[u+14],9,-1019803690),i=c(i,a,n,o,r[u+3],14,-187363961),o=c(o,i,a,n,r[u+8],20,1163531501),n=c(n,o,i,a,r[u+13],5,-1444681467),a=c(a,n,o,i,r[u+2],9,-51403784),i=c(i,a,n,o,r[u+7],14,1735328473),n=l(n,o=c(o,i,a,n,r[u+12],20,-1926607734),i,a,r[u+5],4,-378558),a=l(a,n,o,i,r[u+8],11,-2022574463),i=l(i,a,n,o,r[u+11],16,1839030562),o=l(o,i,a,n,r[u+14],23,-35309556),n=l(n,o,i,a,r[u+1],4,-1530992060),a=l(a,n,o,i,r[u+4],11,1272893353),i=l(i,a,n,o,r[u+7],16,-155497632),o=l(o,i,a,n,r[u+10],23,-1094730640),n=l(n,o,i,a,r[u+13],4,681279174),a=l(a,n,o,i,r[u+0],11,-358537222),i=l(i,a,n,o,r[u+3],16,-722521979),o=l(o,i,a,n,r[u+6],23,76029189),n=l(n,o,i,a,r[u+9],4,-640364487),a=l(a,n,o,i,r[u+12],11,-421815835),i=l(i,a,n,o,r[u+15],16,530742520),n=f(n,o=l(o,i,a,n,r[u+2],23,-995338651),i,a,r[u+0],6,-198630844),a=f(a,n,o,i,r[u+7],10,1126891415),i=f(i,a,n,o,r[u+14],15,-1416354905),o=f(o,i,a,n,r[u+5],21,-57434055),n=f(n,o,i,a,r[u+12],6,1700485571),a=f(a,n,o,i,r[u+3],10,-1894986606),i=f(i,a,n,o,r[u+10],15,-1051523),o=f(o,i,a,n,r[u+1],21,-2054922799),n=f(n,o,i,a,r[u+8],6,1873313359),a=f(a,n,o,i,r[u+15],10,-30611744),i=f(i,a,n,o,r[u+6],15,-1560198380),o=f(o,i,a,n,r[u+13],21,1309151649),n=f(n,o,i,a,r[u+4],6,-145523070),a=f(a,n,o,i,r[u+11],10,-1120210379),i=f(i,a,n,o,r[u+2],15,718787259),o=f(o,i,a,n,r[u+9],21,-343485551),n=n+h>>>0,o=o+d>>>0,i=i+y>>>0,a=a+b>>>0}return g.endian([n,o,i,a])}var g,m,v,w;g=a,m=h.utf8,v=i,w=h.bin,p._ff=function(t,e,r,n,o,i,a){a=t+(e&r|~e&n)+(o>>>0)+a;return(a<<i|a>>>32-i)+e},p._gg=function(t,e,r,n,o,i,a){a=t+(e&n|r&~n)+(o>>>0)+a;return(a<<i|a>>>32-i)+e},p._hh=function(t,e,r,n,o,i,a){a=t+(e^r^n)+(o>>>0)+a;return(a<<i|a>>>32-i)+e},p._ii=function(t,e,r,n,o,i,a){a=t+(r^(e|~n))+(o>>>0)+a;return(a<<i|a>>>32-i)+e},p._blocksize=16,p._digestsize=16,t.exports=function(t,e){if(null==t)throw new Error("Illegal argument "+t);t=g.wordsToBytes(p(t,e));return e&&e.asBytes?t:e&&e.asString?w.bytesToString(t):g.bytesToHex(t)}}),b="3.7.2",p="function"==typeof atob,g="function"==typeof btoa,m="function"==typeof Buffer;const v="function"==typeof TextDecoder?new TextDecoder:void 0,w="function"==typeof TextEncoder?new TextEncoder:void 0;const A=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),x=(t=>{let r={};return t.forEach((t,e)=>r[t]=e),r})(A),S=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,T=String.fromCharCode.bind(String),P="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):(t,e=t=>t)=>new Uint8Array(Array.prototype.slice.call(t,0).map(e)),B=t=>t.replace(/=/g,"").replace(/[+\/]/g,t=>"+"==t?"-":"_"),C=t=>t.replace(/[^A-Za-z0-9\+\/]/g,"");var j=e=>{let r,n,o,i,a="";var t=e.length%3;for(let t=0;t<e.length;){if(255<(n=e.charCodeAt(t++))||255<(o=e.charCodeAt(t++))||255<(i=e.charCodeAt(t++)))throw new TypeError("invalid character found");r=n<<16|o<<8|i,a+=A[r>>18&63]+A[r>>12&63]+A[r>>6&63]+A[63&r]}return t?a.slice(0,t-3)+"===".substring(t):a};const U=g?t=>btoa(t):m?t=>Buffer.from(t,"binary").toString("base64"):j,R=m?t=>Buffer.from(t).toString("base64"):r=>{let n=[];for(let t=0,e=r.length;t<e;t+=4096)n.push(T.apply(null,r.subarray(t,t+4096)));return U(n.join(""))},O=(t,e=!1)=>e?B(R(t)):R(t),E=t=>{if(t.length<2)return(e=t.charCodeAt(0))<128?t:e<2048?T(192|e>>>6)+T(128|63&e):T(224|e>>>12&15)+T(128|e>>>6&63)+T(128|63&e);var e=65536+1024*(t.charCodeAt(0)-55296)+(t.charCodeAt(1)-56320);return T(240|e>>>18&7)+T(128|e>>>12&63)+T(128|e>>>6&63)+T(128|63&e)},I=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,_=t=>t.replace(I,E),F=m?t=>Buffer.from(t,"utf8").toString("base64"):w?t=>R(w.encode(t)):t=>U(_(t)),k=(t,e=!1)=>e?B(F(t)):F(t);var z=t=>k(t,!0);const D=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,L=t=>{switch(t.length){case 4:var e=((7&t.charCodeAt(0))<<18|(63&t.charCodeAt(1))<<12|(63&t.charCodeAt(2))<<6|63&t.charCodeAt(3))-65536;return T(55296+(e>>>10))+T(56320+(1023&e));case 3:return T((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return T((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}},W=t=>t.replace(D,L);g=e=>{if(e=e.replace(/\s+/g,""),!S.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let r,n="",o,i;for(let t=0;t<e.length;)r=x[e.charAt(t++)]<<18|x[e.charAt(t++)]<<12|(o=x[e.charAt(t++)])<<6|(i=x[e.charAt(t++)]),n+=64===o?T(r>>16&255):64===i?T(r>>16&255,r>>8&255):T(r>>16&255,r>>8&255,255&r);return n};const M=p?t=>atob(C(t)):m?t=>Buffer.from(t,"base64").toString("binary"):g,Z=m?t=>P(Buffer.from(t,"base64")):t=>P(M(t),t=>t.charCodeAt(0)),N=t=>Z(q(t)),Q=m?t=>Buffer.from(t,"base64").toString("utf8"):v?t=>v.decode(Z(t)):t=>W(M(t)),q=t=>C(t.replace(/[-_]/g,t=>"-"==t?"+":"/")),H=t=>Q(q(t));function V(){var t=(t,e)=>Object.defineProperty(String.prototype,t,G(e));t("fromBase64",function(){return H(this)}),t("toBase64",function(t){return k(this,t)}),t("toBase64URI",function(){return k(this,!0)}),t("toBase64URL",function(){return k(this,!0)}),t("toUint8Array",function(){return N(this)})}function $(){var t=(t,e)=>Object.defineProperty(Uint8Array.prototype,t,G(e));t("toBase64",function(t){return O(this,t)}),t("toBase64URI",function(){return O(this,!0)}),t("toBase64URL",function(){return O(this,!0)})}const G=t=>({value:t,enumerable:!1,writable:!0,configurable:!0});const J={version:b,VERSION:"3.7.2",atob:M,atobPolyfill:g,btoa:U,btoaPolyfill:j,fromBase64:H,toBase64:k,encode:k,encodeURI:z,encodeURL:z,utob:_,btou:W,decode:H,isValid:t=>{if("string"!=typeof t)return!1;t=t.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(t)||!/[^\s0-9a-zA-Z\-_]/.test(t)},fromUint8Array:O,toUint8Array:N,extendString:V,extendUint8Array:$,extendBuiltins:()=>{V(),$()}};var K=/^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/i,X={1:75,2:50,3:35,4:23,5:20},Y=[1,2,3,4,5],tt={domain:null,useHTTPS:!0,includeLibraryParam:!0,urlPrefix:"https://",secureURLToken:null};function et(t,e){if(!Number.isInteger(t)||!Number.isInteger(e)||t<=0||e<=0||e<t)throw new Error("The min and max srcset widths can only be passed positive Number values, and min must be less than max. Found min: ".concat(t," and max: ").concat(e,"."))}function rt(t){if("number"!=typeof t||t<.01)throw new Error("The srcset widthTolerance must be a number greater than or equal to 0.01")}return function(){function u(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};if(!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,u),this.settings=s(s({},tt),t),this.targetWidthsCache={},"string"!=typeof this.settings.domain)throw new Error("ImgixClient must be passed a valid string domain");if(null==K.exec(this.settings.domain))throw new Error('Domain must be passed in as fully-qualified domain name and should not include a protocol or any path element, i.e. "example.imgix.net".');this.settings.includeLibraryParam&&(this.settings.libraryParam="js-"+u.version()),this.settings.urlPrefix=this.settings.useHTTPS?"https://":"http://"}var t,e,r;return t=u,r=[{key:"version",value:function(){return"3.4.0"}},{key:"targetWidths",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:100,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:8192,r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:.08,n=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},o=Math.floor(t),i=Math.floor(e);et(t,e),rt(r);e=r+"/"+o+"/"+i;if(e in n)return n[e];if(o===i)return[o];for(var a=[],u=o;u<i;)a.push(Math.round(u)),u*=1+2*r;return a[a.length-1]<i&&a.push(i),n[e]=a}}],(e=[{key:"buildURL",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},t=this._sanitizePath(t),e=this._buildParams(e);return this.settings.secureURLToken&&(e=this._signParams(t,e)),this.settings.urlPrefix+this.settings.domain+t+e}},{key:"_buildParams",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=[].concat(f(this.settings.libraryParam?["ixlib=".concat(this.settings.libraryParam)]:[]),f(Object.entries(t).reduce(function(t,e){var r=l(e,2),n=r[0],e=r[1];if(null==e)return t;r=encodeURIComponent(n),e="64"===n.substr(-2)?J.encodeURI(e):encodeURIComponent(e);return t.push("".concat(r,"=").concat(e)),t},[])));return"".concat(0<t.length?"?":"").concat(t.join("&"))}},{key:"_signParams",value:function(t,e){t=this.settings.secureURLToken+t+e,t=y(t);return 0<e.length?e+"&s="+t:"?s="+t}},{key:"_sanitizePath",value:function(t){var t=t.replace(/^\//,"");return"/"+(t=/^https?:\/\//.test(t)?encodeURIComponent(t):encodeURI(t).replace(/[#?:+]/g,encodeURIComponent))}},{key:"buildSrcSet",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},n=e.w,o=e.h;return n||o?this._buildDPRSrcSet(t,e,r):this._buildSrcSetPairs(t,e,r)}},{key:"_buildSrcSetPairs",value:function(e,r,t){var n=this,o=l((o=void 0!==(a=t).widthTolerance?(rt(a.widthTolerance),a.widthTolerance):.08,i=void 0===a.minWidth?100:a.minWidth,a=void 0===a.maxWidth?8192:a.maxWidth,100==i&&8192==a||et(i,a),[o,i,a]),3),i=o[0],a=o[1],o=o[2],i=t.widths?(function(t){if(!Array.isArray(t)||!t.length)throw new Error("The widths argument can only be passed a valid non-empty array of integers");if(!t.every(function(t){return Number.isInteger(t)&&0<t}))throw new Error("A custom widths argument can only contain positive integer values")}(t.widths),f(t.widths)):u.targetWidths(a,o,i,this.targetWidthsCache);return i.map(function(t){return"".concat(n.buildURL(e,s(s({},r),{},{w:t}))," ").concat(t,"w")}).join(",\n")}},{key:"_buildDPRSrcSet",value:function(r,n,t){var o=this;t.devicePixelRatios&&function(t){if(!Array.isArray(t)||!t.length)throw new Error("The devicePixelRatios argument can only be passed a valid non-empty array of integers");if(!t.every(function(t){return"number"==typeof t&&1<=t&&t<=5}))throw new Error("The devicePixelRatios argument can only contain positive integer values between 1 and 5")}(t.devicePixelRatios);var e=t.devicePixelRatios||Y,i=t.disableVariableQuality||!1;i||function(t){if("boolean"!=typeof t)throw new Error("The disableVariableQuality argument can only be passed a Boolean value")}(i),t.variableQualities&&function(t){if("object"!==c(t))throw new Error("The variableQualities argument can only be an object")}(t.variableQualities);var a=s(s({},X),t.variableQualities);return(i?e.map(function(t){return"".concat(o.buildURL(r,s(s({},n),{},{dpr:t}))," ").concat(t,"x")}):e.map(function(t){return e=n,t=t,"".concat(o.buildURL(r,s(s({},e),{},{dpr:t,q:e.q||a[t]||a[Math.floor(t)]}))," ").concat(t,"x");var e})).join(",\n")}}])&&n(t.prototype,e),r&&n(t,r),u}()});