cropduster
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -1,2 +0,2 @@ | ||
var CD=function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,r){"use strict";function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}Object.defineProperty(t,"__esModule",{value:!0});var o="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},a="callbacks are deprecated in cropduster, prefer using promises for asynchronous operations",u={CORS_PROXY_SERVER:"http://cors.movableink.com",$:function(e,t){return t||(t=document),[].concat(n(t.querySelectorAll(e)))},_initParams:function(){u._urlParams={};for(var e=/([^&=]+)=?([^&]*)/g,t=u._searchString(),r=e.exec(t);r;)u._urlParams[decodeURIComponent(r[1])]=decodeURIComponent(r[2]),r=e.exec(t)},param:function(e){return u.params()[e]},params:function(e){var t=u._urlParams;return void 0===t&&(u._initParams(),t=u._urlParams),e?t[e]:t},_searchString:function(){return window.location.search.substring(1)},autofill:function(){u.param("init");var e=u._urlParams;for(var t in e)"undefined"!==e[t]&&e[t].length>0&&document.getElementById("autofill_"+t)&&(document.getElementById("autofill_"+t).innerHTML=e[t])},throwError:function(e){u.miCaptureFallback(function(){MICapture.error(e)},function(){u.log("Capturama error: "+e)})},cancelRequest:function(e){u.miCaptureFallback(function(){MICapture.cancel(e)},function(){u.log("Request canceled: "+e)})},setImageRedirect:function(e){var t=document.getElementById("mi-redirect-image")||document.createElement("a");return t.href=e,t.id="mi-redirect-image",t.style.display="none",document.body.appendChild(t),t},setClickthrough:function(e){var t=document.getElementById("mi_dynamic_link")||document.createElement("a");return t.href=e,t.id="mi_dynamic_link",t.style.display="none",document.body.appendChild(t),t},setExtraData:function(e){var t=document.getElementById("mi-data")||document.createElement("div");t.id="mi-data",t.style.display="none";var r=void 0;try{r=JSON.parse(t.getAttribute("data-mi-data"))||{}}catch(e){r={}}for(var n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);return t.setAttribute("data-mi-data",JSON.stringify(r)),document.body.appendChild(t),t},proxyUrl:function(e){var t=document.createElement("a");t.href=e;var r="";r="0"===t.port||""===t.port?"https:"===t.protocol?":443":"":":"+t.port;var n=t.hostname,o=t.pathname,a=t.search,i=t.hash;return u.CORS_PROXY_SERVER+"/"+n+r+o+a+i},_readyToCapture:!0,_reset:function(){u._readyToCapture=!0},pause:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"manual suspension";e&&(t+=", will end in "+e+"ms",setTimeout(function(){u.resume(t)},e)),u.miCaptureFallback(function(){MICapture.pause(t)},function(){u.log("paused: "+t)})},resume:function(e){u.miCaptureFallback(function(){MICapture.resume(e)},function(){u.log("resuming paused capture: "+e)})},getCORS:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments[2];return"function"==typeof t&&(r=t,t={}),t.corsCacheTime=t.corsCacheTime||1e4,/cors.movableink.com/.test(e)||(e=u.proxyUrl(e)),t.headers=t.headers||{},t.headers["x-reverse-proxy-ttl"]=t.corsCacheTime/1e3,t.headers["x-mi-cbe"]=this._hashForRequest(e,t),u.get(e,t,r)},get:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments[2];"function"==typeof t&&(r=t,t={});var n=function(){if(r&&"function"==typeof r)return u.log(a),r.apply(void 0,arguments)},o="xhr: "+e;return new Promise(function(r,a){try{var i=new XMLHttpRequest;if(i.onerror=function(){var t="XHR error for "+e+" - "+this.status+": "+this.statusText;u.resume(o),n(null),a(new Error(t))},i.onload=function(){var e=this.getResponseHeader("content-type"),t=this.responseText,a=this.status;if(a>=400)return this.onerror();u.resume(o),n(t,a,e),r({contentType:e,data:t,status:a})},i.open(t.method||"GET",e,!0),i.withCredentials=!t.withoutCredentials,t.headers)for(var c in t.headers)i.setRequestHeader(c,t.headers[c]);i.send(t.body),u.pause(t.maxSuspension,o)}catch(e){n(null),a({message:"Cropduster failed to create Promise: "+e,error:e})}})},getImage:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments[2];"function"==typeof t&&(r=t,t={});var n=function(){if(r&&"function"==typeof r)return u.log(a),r.apply(void 0,arguments)},o="getImage: "+e;return new Promise(function(r,a){var i=new Image;i.onload=function(){u.resume(o),n(i),r(i)},i.onerror=function(e){u.resume(o),n(null),a(e)},u.pause(t.maxSuspension,o),i.src=e})},getImages:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=this,n=arguments[2],o=arguments[3],i="getImages:";u.pause(t.maxSuspension,i),"function"==typeof t&&(o=n,n=t,t={});var c=e.map(function(e){return r.getImage(e,t.maxSuspension).then(function(e){return n&&n(e),e})});return Promise.all(c).then(function(e){return o&&(u.log(a),o(e)),u.resume(i),e},function(e){throw u.resume(i),new Error("Not all images loaded successfully")})},waitForAsset:function(e){u.miCaptureFallback(function(){MICapture.waitForAsset(e)},function(){u.log("Wait for asset: "+e)})},log:function(e){console.log(e)},miCaptureFallback:function(e,t){return!window.MICapture||"object"!==o(window.MICapture)?t():e()},_hashForRequest:function(e,t){var r=""+e+JSON.stringify(t),n=0;if(0===r.length)return n;for(var o=0;o<r.length;o++)n=(n<<5)-n+r.charCodeAt(o)&4294967295;return n.toString()}};t.default=u}]); | ||
var CD=function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function r(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)}Object.defineProperty(t,"__esModule",{value:!0});var o="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},a="callbacks are deprecated in cropduster, prefer using promises for asynchronous operations",u={CORS_PROXY_SERVER:"http://cors.movableink.com",$:function(e,t){return t||(t=document),[].concat(r(t.querySelectorAll(e)))},_initParams:function(){u._urlParams={};for(var e=/([^&=]+)=?([^&]*)/g,t=u._searchString(),n=e.exec(t);n;)u._urlParams[decodeURIComponent(n[1])]=decodeURIComponent(n[2]),n=e.exec(t)},param:function(e){return u.params()[e]},params:function(e){var t=u._urlParams;return void 0===t&&(u._initParams(),t=u._urlParams),e?t[e]:t},_searchString:function(){return window.location.search.substring(1)},autofill:function(){u.param("init");var e=u._urlParams;for(var t in e)"undefined"!==e[t]&&e[t].length>0&&document.getElementById("autofill_"+t)&&(document.getElementById("autofill_"+t).innerHTML=e[t])},throwError:function(e){u.miCaptureFallback(function(){MICapture.error(e)},function(){u.log("Capturama error: "+e)})},cancelRequest:function(e){u.miCaptureFallback(function(){MICapture.cancel(e)},function(){u.log("Request canceled: "+e)})},setImageRedirect:function(e){var t=document.getElementById("mi-redirect-image")||document.createElement("a");return t.href=e,t.id="mi-redirect-image",t.style.display="none",document.body.appendChild(t),t},setClickthrough:function(e){var t=document.getElementById("mi_dynamic_link")||document.createElement("a");return t.href=e,t.id="mi_dynamic_link",t.style.display="none",document.body.appendChild(t),t},setExtraData:function(e){var t=document.getElementById("mi-data")||document.createElement("div");t.id="mi-data",t.style.display="none";var n=void 0;try{n=JSON.parse(t.getAttribute("data-mi-data"))||{}}catch(e){n={}}for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r]);return t.setAttribute("data-mi-data",JSON.stringify(n)),document.body.appendChild(t),t},proxyUrl:function(e){var t=document.createElement("a");t.href=e;var n="";n="0"===t.port||""===t.port?"https:"===t.protocol?":443":"":":"+t.port;var r=t.hostname,o=t.pathname,a=t.search,i=t.hash;return u.CORS_PROXY_SERVER+"/"+r+n+o+a+i},_readyToCapture:!0,_reset:function(){u._readyToCapture=!0},pause:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"manual suspension";e&&(t+=", will end in "+e+"ms",setTimeout(function(){u.resume(t)},e)),u.miCaptureFallback(function(){MICapture.pause(t)},function(){u.log("paused: "+t)})},resume:function(e){u.miCaptureFallback(function(){MICapture.resume(e)},function(){u.log("resuming paused capture: "+e)})},getCORS:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments[2];return"function"==typeof t&&(n=t,t={}),t.corsCacheTime=t.corsCacheTime||1e4,/cors.movableink.com/.test(e)||(e=u.proxyUrl(e)),t.headers=t.headers||{},t.headers["x-reverse-proxy-ttl"]=t.corsCacheTime/1e3,t.headers["x-mi-cbe"]=this._hashForRequest(e,t),u.get(e,t,n)},get:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments[2];"function"==typeof t&&(n=t,t={});var r="xhr: "+e,o=function(){if(n&&"function"==typeof n)return u.log(a),n.apply(void 0,arguments)};u.pause(t.maxSuspension||0,r);var i=u._optionsForFetch(t);return fetch(e,i).then(function(e){if(!e.ok)throw new Error(e.statusText);return e.text().then(function(t){var n=e.status,r=e.headers.get("Content-Type");return o(t,n,r),{data:t,status:n,contentType:r}})}).then(function(e){return u.resume(r),e},function(t){throw u.log("Error encountered in CD.get for "+e+": "+t),u.resume(r),o(null),t})},getImage:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments[2];"function"==typeof t&&(n=t,t={});var r=function(){if(n&&"function"==typeof n)return u.log(a),n.apply(void 0,arguments)},o="getImage: "+e;return new Promise(function(n,a){var i=new Image;i.onload=function(){u.resume(o),r(i),n(i)},i.onerror=function(e){u.resume(o),r(null),a(e)},u.pause(t.maxSuspension,o),i.src=e})},getImages:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this,r=arguments[2],o=arguments[3],i="getImages:";u.pause(t.maxSuspension,i),"function"==typeof t&&(o=r,r=t,t={});var c=e.map(function(e){return n.getImage(e,t.maxSuspension).then(function(e){return r&&r(e),e})});return Promise.all(c).then(function(e){return o&&(u.log(a),o(e)),u.resume(i),e},function(e){throw u.resume(i),new Error("Not all images loaded successfully")})},waitForAsset:function(e){u.miCaptureFallback(function(){MICapture.waitForAsset(e)},function(){u.log("Wait for asset: "+e)})},log:function(e){console.log(e)},miCaptureFallback:function(e,t){return!window.MICapture||"object"!==o(window.MICapture)?t():e()},_hashForRequest:function(e,t){var n=""+e+JSON.stringify(t),r=0;if(0===n.length)return r;for(var o=0;o<n.length;o++)r=(r<<5)-r+n.charCodeAt(o)&4294967295;return r.toString()},_optionsForFetch:function(e){var t={redirect:"follow",headers:new Headers(e.headers||{}),method:e.method||"GET",body:e.body,mode:"cors"};return e.withoutCredentials||(t.credentials="include"),t}};t.default=u}]); | ||
//# sourceMappingURL=cropduster.browser.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.cropduster=t():e.cropduster=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,r){"use strict";function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}Object.defineProperty(t,"__esModule",{value:!0});var o="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},a="callbacks are deprecated in cropduster, prefer using promises for asynchronous operations",u={CORS_PROXY_SERVER:"http://cors.movableink.com",$:function(e,t){return t||(t=document),[].concat(n(t.querySelectorAll(e)))},_initParams:function(){u._urlParams={};for(var e=/([^&=]+)=?([^&]*)/g,t=u._searchString(),r=e.exec(t);r;)u._urlParams[decodeURIComponent(r[1])]=decodeURIComponent(r[2]),r=e.exec(t)},param:function(e){return u.params()[e]},params:function(e){var t=u._urlParams;return void 0===t&&(u._initParams(),t=u._urlParams),e?t[e]:t},_searchString:function(){return window.location.search.substring(1)},autofill:function(){u.param("init");var e=u._urlParams;for(var t in e)"undefined"!==e[t]&&e[t].length>0&&document.getElementById("autofill_"+t)&&(document.getElementById("autofill_"+t).innerHTML=e[t])},throwError:function(e){u.miCaptureFallback(function(){MICapture.error(e)},function(){u.log("Capturama error: "+e)})},cancelRequest:function(e){u.miCaptureFallback(function(){MICapture.cancel(e)},function(){u.log("Request canceled: "+e)})},setImageRedirect:function(e){var t=document.getElementById("mi-redirect-image")||document.createElement("a");return t.href=e,t.id="mi-redirect-image",t.style.display="none",document.body.appendChild(t),t},setClickthrough:function(e){var t=document.getElementById("mi_dynamic_link")||document.createElement("a");return t.href=e,t.id="mi_dynamic_link",t.style.display="none",document.body.appendChild(t),t},setExtraData:function(e){var t=document.getElementById("mi-data")||document.createElement("div");t.id="mi-data",t.style.display="none";var r=void 0;try{r=JSON.parse(t.getAttribute("data-mi-data"))||{}}catch(e){r={}}for(var n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);return t.setAttribute("data-mi-data",JSON.stringify(r)),document.body.appendChild(t),t},proxyUrl:function(e){var t=document.createElement("a");t.href=e;var r="";r="0"===t.port||""===t.port?"https:"===t.protocol?":443":"":":"+t.port;var n=t.hostname,o=t.pathname,a=t.search,i=t.hash;return u.CORS_PROXY_SERVER+"/"+n+r+o+a+i},_readyToCapture:!0,_reset:function(){u._readyToCapture=!0},pause:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"manual suspension";e&&(t+=", will end in "+e+"ms",setTimeout(function(){u.resume(t)},e)),u.miCaptureFallback(function(){MICapture.pause(t)},function(){u.log("paused: "+t)})},resume:function(e){u.miCaptureFallback(function(){MICapture.resume(e)},function(){u.log("resuming paused capture: "+e)})},getCORS:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments[2];return"function"==typeof t&&(r=t,t={}),t.corsCacheTime=t.corsCacheTime||1e4,/cors.movableink.com/.test(e)||(e=u.proxyUrl(e)),t.headers=t.headers||{},t.headers["x-reverse-proxy-ttl"]=t.corsCacheTime/1e3,t.headers["x-mi-cbe"]=this._hashForRequest(e,t),u.get(e,t,r)},get:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments[2];"function"==typeof t&&(r=t,t={});var n=function(){if(r&&"function"==typeof r)return u.log(a),r.apply(void 0,arguments)},o="xhr: "+e;return new Promise(function(r,a){try{var i=new XMLHttpRequest;if(i.onerror=function(){var t="XHR error for "+e+" - "+this.status+": "+this.statusText;u.resume(o),n(null),a(new Error(t))},i.onload=function(){var e=this.getResponseHeader("content-type"),t=this.responseText,a=this.status;if(a>=400)return this.onerror();u.resume(o),n(t,a,e),r({contentType:e,data:t,status:a})},i.open(t.method||"GET",e,!0),i.withCredentials=!t.withoutCredentials,t.headers)for(var s in t.headers)i.setRequestHeader(s,t.headers[s]);i.send(t.body),u.pause(t.maxSuspension,o)}catch(e){n(null),a({message:"Cropduster failed to create Promise: "+e,error:e})}})},getImage:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments[2];"function"==typeof t&&(r=t,t={});var n=function(){if(r&&"function"==typeof r)return u.log(a),r.apply(void 0,arguments)},o="getImage: "+e;return new Promise(function(r,a){var i=new Image;i.onload=function(){u.resume(o),n(i),r(i)},i.onerror=function(e){u.resume(o),n(null),a(e)},u.pause(t.maxSuspension,o),i.src=e})},getImages:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=this,n=arguments[2],o=arguments[3],i="getImages:";u.pause(t.maxSuspension,i),"function"==typeof t&&(o=n,n=t,t={});var s=e.map(function(e){return r.getImage(e,t.maxSuspension).then(function(e){return n&&n(e),e})});return Promise.all(s).then(function(e){return o&&(u.log(a),o(e)),u.resume(i),e},function(e){throw u.resume(i),new Error("Not all images loaded successfully")})},waitForAsset:function(e){u.miCaptureFallback(function(){MICapture.waitForAsset(e)},function(){u.log("Wait for asset: "+e)})},log:function(e){console.log(e)},miCaptureFallback:function(e,t){return!window.MICapture||"object"!==o(window.MICapture)?t():e()},_hashForRequest:function(e,t){var r=""+e+JSON.stringify(t),n=0;if(0===r.length)return n;for(var o=0;o<r.length;o++)n=(n<<5)-n+r.charCodeAt(o)&4294967295;return n.toString()}};t.default=u}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.cropduster=t():e.cropduster=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function r(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)}Object.defineProperty(t,"__esModule",{value:!0});var o="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},a="callbacks are deprecated in cropduster, prefer using promises for asynchronous operations",u={CORS_PROXY_SERVER:"http://cors.movableink.com",$:function(e,t){return t||(t=document),[].concat(r(t.querySelectorAll(e)))},_initParams:function(){u._urlParams={};for(var e=/([^&=]+)=?([^&]*)/g,t=u._searchString(),n=e.exec(t);n;)u._urlParams[decodeURIComponent(n[1])]=decodeURIComponent(n[2]),n=e.exec(t)},param:function(e){return u.params()[e]},params:function(e){var t=u._urlParams;return void 0===t&&(u._initParams(),t=u._urlParams),e?t[e]:t},_searchString:function(){return window.location.search.substring(1)},autofill:function(){u.param("init");var e=u._urlParams;for(var t in e)"undefined"!==e[t]&&e[t].length>0&&document.getElementById("autofill_"+t)&&(document.getElementById("autofill_"+t).innerHTML=e[t])},throwError:function(e){u.miCaptureFallback(function(){MICapture.error(e)},function(){u.log("Capturama error: "+e)})},cancelRequest:function(e){u.miCaptureFallback(function(){MICapture.cancel(e)},function(){u.log("Request canceled: "+e)})},setImageRedirect:function(e){var t=document.getElementById("mi-redirect-image")||document.createElement("a");return t.href=e,t.id="mi-redirect-image",t.style.display="none",document.body.appendChild(t),t},setClickthrough:function(e){var t=document.getElementById("mi_dynamic_link")||document.createElement("a");return t.href=e,t.id="mi_dynamic_link",t.style.display="none",document.body.appendChild(t),t},setExtraData:function(e){var t=document.getElementById("mi-data")||document.createElement("div");t.id="mi-data",t.style.display="none";var n=void 0;try{n=JSON.parse(t.getAttribute("data-mi-data"))||{}}catch(e){n={}}for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r]);return t.setAttribute("data-mi-data",JSON.stringify(n)),document.body.appendChild(t),t},proxyUrl:function(e){var t=document.createElement("a");t.href=e;var n="";n="0"===t.port||""===t.port?"https:"===t.protocol?":443":"":":"+t.port;var r=t.hostname,o=t.pathname,a=t.search,i=t.hash;return u.CORS_PROXY_SERVER+"/"+r+n+o+a+i},_readyToCapture:!0,_reset:function(){u._readyToCapture=!0},pause:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"manual suspension";e&&(t+=", will end in "+e+"ms",setTimeout(function(){u.resume(t)},e)),u.miCaptureFallback(function(){MICapture.pause(t)},function(){u.log("paused: "+t)})},resume:function(e){u.miCaptureFallback(function(){MICapture.resume(e)},function(){u.log("resuming paused capture: "+e)})},getCORS:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments[2];return"function"==typeof t&&(n=t,t={}),t.corsCacheTime=t.corsCacheTime||1e4,/cors.movableink.com/.test(e)||(e=u.proxyUrl(e)),t.headers=t.headers||{},t.headers["x-reverse-proxy-ttl"]=t.corsCacheTime/1e3,t.headers["x-mi-cbe"]=this._hashForRequest(e,t),u.get(e,t,n)},get:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments[2];"function"==typeof t&&(n=t,t={});var r="xhr: "+e,o=function(){if(n&&"function"==typeof n)return u.log(a),n.apply(void 0,arguments)};u.pause(t.maxSuspension||0,r);var i=u._optionsForFetch(t);return fetch(e,i).then(function(e){if(!e.ok)throw new Error(e.statusText);return e.text().then(function(t){var n=e.status,r=e.headers.get("Content-Type");return o(t,n,r),{data:t,status:n,contentType:r}})}).then(function(e){return u.resume(r),e},function(t){throw u.log("Error encountered in CD.get for "+e+": "+t),u.resume(r),o(null),t})},getImage:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments[2];"function"==typeof t&&(n=t,t={});var r=function(){if(n&&"function"==typeof n)return u.log(a),n.apply(void 0,arguments)},o="getImage: "+e;return new Promise(function(n,a){var i=new Image;i.onload=function(){u.resume(o),r(i),n(i)},i.onerror=function(e){u.resume(o),r(null),a(e)},u.pause(t.maxSuspension,o),i.src=e})},getImages:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this,r=arguments[2],o=arguments[3],i="getImages:";u.pause(t.maxSuspension,i),"function"==typeof t&&(o=r,r=t,t={});var c=e.map(function(e){return n.getImage(e,t.maxSuspension).then(function(e){return r&&r(e),e})});return Promise.all(c).then(function(e){return o&&(u.log(a),o(e)),u.resume(i),e},function(e){throw u.resume(i),new Error("Not all images loaded successfully")})},waitForAsset:function(e){u.miCaptureFallback(function(){MICapture.waitForAsset(e)},function(){u.log("Wait for asset: "+e)})},log:function(e){console.log(e)},miCaptureFallback:function(e,t){return!window.MICapture||"object"!==o(window.MICapture)?t():e()},_hashForRequest:function(e,t){var n=""+e+JSON.stringify(t),r=0;if(0===n.length)return r;for(var o=0;o<n.length;o++)r=(r<<5)-r+n.charCodeAt(o)&4294967295;return r.toString()},_optionsForFetch:function(e){var t={redirect:"follow",headers:new Headers(e.headers||{}),method:e.method||"GET",body:e.body,mode:"cors"};return e.withoutCredentials||(t.credentials="include"),t}};t.default=u}])}); | ||
//# sourceMappingURL=cropduster.js.map |
{ | ||
"name": "cropduster", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Library for building web pages for use with Movable Ink Web Crops", | ||
@@ -14,2 +14,3 @@ "main": "src/cropduster.js", | ||
"babel-preset-es2015": "^6.24.1", | ||
"fetch-mock": "^6.0.0-beta.7", | ||
"karma": "^1.7.1", | ||
@@ -16,0 +17,0 @@ "karma-babel-preprocessor": "^6.0.1", |
@@ -67,4 +67,4 @@ # Cropduster | ||
setTimeout(() => { | ||
CD.resume(); | ||
target.innerText = 'bad customers have to wait for their images'; | ||
CD.resume(); | ||
}, 1000); | ||
@@ -74,2 +74,10 @@ } | ||
It is generally recommended to call CD.pause as the last thing before starting | ||
an asynchronous action, and CD.resume as the very first thing once that action | ||
has finished. If your asynchronous action completes successfully, but your | ||
callback runs some code before calling CD.resume again, then you run the risk of | ||
triggering a JavaScript error that stops execution of the current script. If | ||
CD.resume is not called after that first CD.pause, your image will eventually | ||
time out, as opposed to failing immediately. | ||
*NOTE:* Cropduster previously offered `CD.suspend` and `CD.capture` functions | ||
@@ -217,8 +225,21 @@ that achieved a similar goal. These functions have been replaced with `pause` | ||
brew install phantomjs | ||
npm install | ||
npm test | ||
yarn install | ||
yarn run test | ||
## Publishing | ||
1. Open a pull request with your change; add a new entry to the changelog called "Latest" and list out your changes. | ||
2. Wait for your pull request to get approved, then merge it into master. | ||
3. On master, make a commit that bumps cropduster to the next version. The commit message should be in the form "Release version X.Y.Z" We adhere to semver. (format is `Major.Minor.Patch`) Choosing a version number: | ||
* If your change introduces any breaking changes whatsoever, it needs a major version bump. These should definitely be listed in the changelog. | ||
* If your change introduces new features but does not break any existing workflows, it should bump the minor version. | ||
* If your change is fixes bugs or updates tests or something, you can just bump the patch version. | ||
4. Tag your release commit: `git tag [version]`. The version should be in the form `X.Y.Z` and _not_ have a `v` prepended. Push it to the server with `git push --tags` | ||
5. Publish to npm with `npm publish`. If you don't have permission, ask `mnutt`. | ||
## Changelog | ||
### 5.2.0 | ||
* CD.get uses the `fetch` API instead of XMLHttpRequest | ||
### 5.1.0 | ||
@@ -225,0 +246,0 @@ * Add `withoutCredentials` to `CD.get()` options to disable sending `withCredentials` in requests. |
@@ -192,2 +192,3 @@ const DEPRECATION_MSG = 'callbacks are deprecated in cropduster, prefer using promises for asynchronous operations'; | ||
const msg = `xhr: ${url}`; | ||
const deprecatedCallback = function() { | ||
@@ -200,59 +201,37 @@ if (callback && typeof callback === 'function') { | ||
const msg = `xhr: ${url}`; | ||
CD.pause(options.maxSuspension || 0, msg); | ||
return new Promise(function(resolve, reject) { | ||
try { | ||
const req = new XMLHttpRequest(); | ||
const requestOptions = CD._optionsForFetch(options); | ||
req.onerror = function() { | ||
const error = `XHR error for ${url} - ${this.status}: ${this.statusText}`; | ||
return fetch(url, requestOptions).then(response => { | ||
if (!response.ok) { | ||
throw new Error(response.statusText); // A non-200 range status was returned | ||
} | ||
CD.resume(msg); | ||
return response.text().then(data => { | ||
const status = response.status; | ||
const contentType = response.headers.get('Content-Type'); | ||
deprecatedCallback(null); | ||
deprecatedCallback(data, status, contentType); | ||
reject(new Error(error)); | ||
return { | ||
data, | ||
status, | ||
contentType | ||
}; | ||
}); | ||
}).then( | ||
(response) => { | ||
CD.resume(msg); | ||
return response; | ||
}, | ||
(error) => { | ||
CD.log(`Error encountered in CD.get for ${url}: ${error}`); | ||
CD.resume(msg); | ||
req.onload = function() { | ||
const contentType = this.getResponseHeader('content-type'); | ||
const data = this.responseText; | ||
const status = this.status; | ||
if (status >= 400) { | ||
return this.onerror(); | ||
} | ||
CD.resume(msg); | ||
deprecatedCallback(data, status, contentType); | ||
resolve({ | ||
contentType, | ||
data, | ||
status | ||
}); | ||
}; | ||
req.open(options.method || 'GET', url, true); | ||
req.withCredentials = !options.withoutCredentials; | ||
if (options.headers) { | ||
for (const header in options.headers) { | ||
req.setRequestHeader(header, options.headers[header]); | ||
} | ||
} | ||
req.send(options.body); | ||
CD.pause(options.maxSuspension, msg); | ||
} catch (error) { | ||
deprecatedCallback(null); | ||
reject({ | ||
message: `Cropduster failed to create Promise: ${error}`, | ||
error: error | ||
}); | ||
throw error; | ||
} | ||
}); | ||
); | ||
}, | ||
@@ -374,2 +353,18 @@ | ||
return hash.toString(); | ||
}, | ||
_optionsForFetch(options) { | ||
const requestOptions = { | ||
redirect: 'follow', | ||
headers: new Headers(options.headers || {}), | ||
method: options.method || 'GET', | ||
body: options.body, | ||
mode: 'cors' | ||
}; | ||
if (!options.withoutCredentials) { | ||
requestOptions.credentials = 'include'; | ||
} | ||
return requestOptions; | ||
} | ||
@@ -376,0 +371,0 @@ }; |
import CD from '../src/cropduster'; | ||
import { fakeServer, useFakeXMLHttpRequest, spy } from 'sinon'; | ||
import { spy } from 'sinon'; | ||
import fetchMock from 'fetch-mock'; | ||
const { module, test } = QUnit; | ||
const container = document.createElement('DIV'); | ||
@@ -11,2 +13,9 @@ container.style = 'position: absolute; left: -5000px;'; | ||
beforeEach() { | ||
this.fakeServer = fetchMock.mock('*', { | ||
body: 'ok', | ||
headers: { | ||
'Content-Type': 'text/html' | ||
} | ||
}); | ||
window.MICapture = { | ||
@@ -19,2 +28,6 @@ pause: spy(), | ||
}; | ||
}, | ||
afterEach() { | ||
this.fakeServer.restore(); | ||
} | ||
@@ -231,9 +244,5 @@ }); | ||
test("DEPRECATED - CD.get with callbacks and a successful response", function(assert) { | ||
const xhr = useFakeXMLHttpRequest(); | ||
const done = assert.async(); | ||
const server = fakeServer.create(); | ||
server.respondWith([200, {"Content-Type": "text/html"}, "response"]); | ||
CD.get("http://google.com", { | ||
CD.get("http://callback.com", { | ||
headers: { | ||
@@ -243,3 +252,3 @@ 'Accept': 'application/json' | ||
}, (data, status, contentType) => { | ||
assert.ok(data === 'response', 'resolves with a response'); | ||
assert.ok(data === 'ok', 'resolves with a response'); | ||
assert.ok(status === 200, 'resolves with a status'); | ||
@@ -251,15 +260,8 @@ assert.ok(contentType === 'text/html', 'resolves with a content type'); | ||
}); | ||
server.respond(); | ||
server.restore(); | ||
}); | ||
test("CD.get with promises and a successful response", function(assert) { | ||
const xhr = useFakeXMLHttpRequest(); | ||
const done = assert.async(); | ||
const server = fakeServer.create(); | ||
server.respondWith([200, {"Content-Type": "text/html"}, "response"]); | ||
CD.get("http://google.com", { | ||
CD.get("http://callback.com", { | ||
headers: { | ||
@@ -269,3 +271,3 @@ 'Accept': 'application/json' | ||
}).then(({ data, status, contentType }) => { | ||
assert.ok(data === 'response', 'resolves with a response'); | ||
assert.ok(data === 'ok', 'resolves with a response'); | ||
assert.ok(status === 200, 'resolves with a status'); | ||
@@ -277,10 +279,7 @@ assert.ok(contentType === 'text/html', 'resolves with a content type'); | ||
}); | ||
server.respond(); | ||
server.restore(); | ||
}); | ||
test("DEPRECATED - CD.get with callbacks and a failing response", function(assert) { | ||
const xhr = useFakeXMLHttpRequest(); | ||
const server = fakeServer.create(); | ||
this.fakeServer.restore(); | ||
this.fakeServer.mock('*', 500); | ||
const done = assert.async(); | ||
@@ -299,12 +298,7 @@ | ||
}); | ||
server.requests[0].abort(); | ||
server.requests[0].onerror(); | ||
server.restore(); | ||
}); | ||
test("CD.get with promises and a failing response", function(assert) { | ||
const xhr = useFakeXMLHttpRequest(); | ||
const server = fakeServer.create(); | ||
this.fakeServer.restore(); | ||
this.fakeServer.mock('*', 500); | ||
const done = assert.async(); | ||
@@ -326,7 +320,2 @@ | ||
); | ||
server.requests[0].abort(); | ||
server.requests[0].onerror(); | ||
server.restore(); | ||
}); | ||
@@ -336,8 +325,2 @@ | ||
test("CD.get - request options", function(assert) { | ||
const xhr = useFakeXMLHttpRequest(); | ||
const requests = this.requests = []; | ||
xhr.onCreate = function (xhr) { | ||
requests.push(xhr); | ||
}; | ||
CD.get("http://google.com", { | ||
@@ -350,20 +333,13 @@ corsCacheTime: 5000, | ||
assert.equal(requests.length, 1); | ||
assert.equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], null); // not automatically added | ||
assert.equal(requests[0].requestHeaders['Accept'], 'application/json'); | ||
assert.equal(requests[0].method, 'GET'); | ||
assert.equal(requests[0].async, true); | ||
assert.equal(requests[0].withCredentials, true); | ||
assert.equal(requests[0].url, "http://google.com"); | ||
const lastRequest = this.fakeServer.lastOptions(); | ||
xhr.restore(); | ||
assert.equal(this.fakeServer.calls.length, 1); | ||
assert.equal(this.fakeServer.lastUrl(), "http://google.com"); | ||
assert.equal(lastRequest.headers.get('x-reverse-proxy-ttl'), null); // not automatically added | ||
assert.equal(lastRequest.headers.get('Accept'), 'application/json'); | ||
assert.equal(lastRequest.method, 'GET'); | ||
assert.equal(lastRequest.credentials, 'include'); | ||
}); | ||
test("CD.get - withoutCredentials option", function(assert) { | ||
const xhr = useFakeXMLHttpRequest(); | ||
const requests = this.requests = []; | ||
xhr.onCreate = function (xhr) { | ||
requests.push(xhr); | ||
}; | ||
CD.get("http://google.com", { | ||
@@ -377,20 +353,14 @@ corsCacheTime: 5000, | ||
assert.equal(requests.length, 1); | ||
assert.equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], null); // not automatically added | ||
assert.equal(requests[0].requestHeaders['Accept'], 'application/json'); | ||
assert.equal(requests[0].method, 'GET'); | ||
assert.equal(requests[0].async, true); | ||
assert.equal(requests[0].withCredentials, false); | ||
assert.equal(requests[0].url, "http://google.com"); | ||
const lastRequest = this.fakeServer.lastOptions(); | ||
xhr.restore(); | ||
assert.equal(this.fakeServer.calls.length, 1); | ||
assert.equal(this.fakeServer.lastUrl(), "http://google.com"); | ||
assert.equal(lastRequest.headers.get('x-reverse-proxy-ttl'), null); // not automatically added | ||
assert.equal(lastRequest.headers.get('Accept'), 'application/json'); | ||
assert.equal(lastRequest.method, 'GET'); | ||
assert.notOk('credentials' in lastRequest, 'the request does not have a "credentials" option set'); | ||
}); | ||
test("CD.getCORS - request options", function(assert) { | ||
const xhr = useFakeXMLHttpRequest(); | ||
const requests = this.requests = []; | ||
xhr.onCreate = function (xhr) { | ||
requests.push(xhr); | ||
}; | ||
CD.getCORS("http://google.com", { | ||
@@ -403,37 +373,25 @@ corsCacheTime: 5000, | ||
assert.equal(requests.length, 1); | ||
assert.equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], 5); | ||
assert.equal(requests[0].requestHeaders['x-mi-cbe'], '-2134781906'); | ||
assert.equal(requests[0].requestHeaders['Accept'], 'application/json'); | ||
assert.equal(requests[0].method, 'GET'); | ||
assert.equal(requests[0].async, true); | ||
assert.equal(requests[0].url, "http://cors.movableink.com/google.com/"); | ||
const lastRequest = this.fakeServer.lastOptions(); | ||
xhr.restore(); | ||
assert.equal(this.fakeServer.calls.length, 1); | ||
assert.equal(this.fakeServer.lastUrl(), "http://cors.movableink.com/google.com/"); | ||
assert.equal(lastRequest.headers.get('x-reverse-proxy-ttl'), 5); // not automatically added | ||
assert.equal(lastRequest.headers.get('x-mi-cbe'), '-2134781906'); | ||
assert.equal(lastRequest.headers.get('Accept'), 'application/json'); | ||
assert.equal(lastRequest.method, 'GET'); | ||
assert.equal(lastRequest.credentials, 'include'); | ||
}); | ||
test("CD.getCORS without options", function(assert) { | ||
const xhr = useFakeXMLHttpRequest(); | ||
const requests = this.requests = []; | ||
xhr.onCreate = function (xhr) { | ||
requests.push(xhr); | ||
}; | ||
CD.getCORS("http://google.com"); | ||
assert.equal(requests.length, 1); | ||
assert.equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], 10); | ||
assert.equal(requests[0].requestHeaders['x-mi-cbe'], '2084411041'); | ||
assert.equal(requests[0].url, "http://cors.movableink.com/google.com/"); | ||
const lastRequest = this.fakeServer.lastOptions(); | ||
xhr.restore(); | ||
assert.equal(this.fakeServer.calls.length, 1); | ||
assert.equal(this.fakeServer.lastUrl(), "http://cors.movableink.com/google.com/"); | ||
assert.equal(lastRequest.headers.get('x-reverse-proxy-ttl'), 10); | ||
assert.equal(lastRequest.headers.get('x-mi-cbe'), '2084411041'); | ||
}); | ||
test("CD.getCORS with POST", function(assert) { | ||
const xhr = useFakeXMLHttpRequest(); | ||
const requests = this.requests = []; | ||
xhr.onCreate = function (xhr) { | ||
requests.push(xhr); | ||
}; | ||
CD.getCORS("http://google.com", { | ||
@@ -448,12 +406,11 @@ corsCacheTime: 5000, | ||
assert.equal(requests.length, 1); | ||
assert.equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], 5); | ||
assert.equal(requests[0].requestHeaders['Accept'], 'application/json'); | ||
assert.equal(requests[0].requestHeaders['x-mi-cbe'], '-1217831332'); | ||
assert.equal(requests[0].method, 'POST'); | ||
assert.equal(requests[0].async, true); | ||
assert.equal(requests[0].requestBody, 'foobar'); | ||
assert.equal(requests[0].url, "http://cors.movableink.com/google.com/"); | ||
const lastRequest = this.fakeServer.lastOptions(); | ||
xhr.restore(); | ||
assert.equal(this.fakeServer.calls.length, 1); | ||
assert.equal(this.fakeServer.lastUrl(), "http://cors.movableink.com/google.com/"); | ||
assert.equal(lastRequest.headers.get('x-reverse-proxy-ttl'), 5); // not automatically added | ||
assert.equal(lastRequest.headers.get('x-mi-cbe'), '-1217831332'); | ||
assert.equal(lastRequest.headers.get('Accept'), 'application/json'); | ||
assert.equal(lastRequest.method, 'POST'); | ||
assert.equal(lastRequest.body, 'foobar'); | ||
}); | ||
@@ -460,0 +417,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
285516
344
17
796
3