diff --git a/analyzer/index.js b/analyzer/index.js index 4549127..9492552 100644 --- a/analyzer/index.js +++ b/analyzer/index.js @@ -5,4 +5,4 @@ * @license Licensed under MIT license * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE * @version v4.2.6+9869a4bc - */var r;r=function(){"use strict";function t(t){return"function"==typeof t}var r=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},o=0,i=void 0,u=void 0,c=function(t,n){h[o]=t,h[o+1]=n,2===(o+=2)&&(u?u(v):b())},a="undefined"!=typeof window?window:void 0,s=a||{},f=s.MutationObserver||s.WebKitMutationObserver,l="undefined"==typeof self&&void 0!==n&&"[object process]"==={}.toString.call(n),d="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function p(){var t=setTimeout;return function(){return t(v,1)}}var h=new Array(1e3);function v(){for(var t=0;t1)for(var e=1;e0?(0,u.startScanner)((function(t){!function(t){if(!function(t){for(var n=0;n=0&&e.splice(r,1)}},n.bridgeSync=l,n.bridgeAsync=function(t,n,e){return new Promise((function(r,o){if(f()){var u=!1,a=null;e>0&&(a=setTimeout((function(){u=!0,a=null,o("bridgeAsync timeout")}),e));var s=(0,i.createUUID)()+"_"+Date.now();d=s,(p=function(t,n){u||(a&&clearTimeout(a),0==t?r(n):o(n))})&&"function"==typeof p&&(c[d]=p),l(t,Object.assign({request_id:s},n))}else o("Can't bridgeAsync, because not in runtime");var d,p})).then((function(e){var r=[t];return n&&(r.push("params:"),r.push(n)),e&&(r.push("resp:"),r.push(e)),o.printDebug.apply(void 0,["bridge resp >>>"].concat(r)),e})).catch((function(e){throw n?(0,o.printWarn)("bridge err >>>",t,"params:",n,e):(0,o.printWarn)("bridge err >>>",t,e),e}))};var r=e(4),o=e(5),i=e(2),u={},c={},a="__bridge_client__";function s(){var t=a+"_handle_callback";window[t]||(window[t]=function(t){var n=(0,r.toAny)(t,{}),e=n.method,o=n.payload,i=n.code,a=n.request_id,s=(0,r.toAny)(o,{});a?c[a]&&c[a](i,s):u[e]&&u[e].forEach((function(t){t&&t(s)}))})}function f(){return!!window[a]}function l(t,n){s();var e=(0,r.toAny)(function(t){for(var n=t.split("."),e=window;n.length>1;)e=e[n.shift()];if(e&&1==n.length&&e.hasOwnProperty(n[0])){for(var r,o=arguments.length,i=Array(o>1?o-1:0),u=1;u>>"].concat(i)),e}},function(t,n,e){"use strict";n.__esModule=!0,n.isSupportWebScan=function(){return"undefined"!=typeof navigator&&navigator.mediaDevices&&navigator.mediaDevices.getUserMedia&&"undefined"!=typeof BarcodeDetector},n.isSupportImageScan=function(){return"undefined"!=typeof document&&"undefined"!=typeof BarcodeDetector&&"undefined"!=typeof URL&&URL.createObjectURL},n.stopScanForWeb=f,n.startScanForImage=function(){return s((0,o.getConfig)("scanType")).then((function(t){return new Promise((function(t){var n=document.createElement("input");n.type="file",n.accept="image/*",n.style.display="none";var e=!1,r=function(n){e||(e=!0,u("__webscan_image_input__"),t(n))};n.id="__webscan_image_input__",n.onchange=function(){r(n.files&&n.files[0])},n.oncancel=function(){r(null)},document.body.appendChild(n),n.click()})).then((function(n){return function(t,n){if(!n)return Promise.resolve(null);if("undefined"!=typeof createImageBitmap)return createImageBitmap(n).then((function(n){return t.detect(n).then((function(t){return n.close&&n.close(),t&&t[0]})).catch((function(t){throw n.close&&n.close(),t}))}));return new Promise((function(e,r){var o=new Image,i=URL.createObjectURL(n);o.onload=function(){t.detect(o).then((function(t){URL.revokeObjectURL(i),e(t&&t[0])})).catch((function(t){URL.revokeObjectURL(i),r(t)}))},o.onerror=function(t){URL.revokeObjectURL(i),r(t)},o.src=i}))}(t,n)}))})).then((function(t){return t&&t.rawValue?{result:t.rawValue}:{success:!1,error:"未识别到二维码或条形码"}}))},n.startScanForWeb=function(t,n){return new Promise((function(e,u){try{i.uuid=(0,r.createUUID)(),i.finish=!1;var l,d=c("video","__webscan_video__","display: none",!1),p=t||"position: fixed; width: 300px; height: 240px; top: 0; left: 0; z-index: 9999;",h=c("canvas","__webscan_canvas__",p+" display: none;",!0);h.style.display,h.style.cssText=p,l=h.style.display,h.style.display="none";var v=h.getContext("2d"),y=i.uuid;d.width=300,d.height=300,d.uuid=i.uuid,s((0,o.getConfig)("scanType")).then((function(t){return navigator.mediaDevices.getUserMedia({video:{facingMode:"environment"}}).then((function(n){return{detector:t,stream:n}}))})).then((function(t){var r=t.detector,c=t.stream;d.srcObject=c,d.setAttribute("playsinline",!0),d.play();var s=(0,o.getConfig)("closeWebScan",(function(){})),p=(0,o.getConfig)("displayWebScan",(function(t,n){}));p&&p(h,(function(){f()})),h.style.display="none";var g=!1,m=!1,_=!1,b=function(){if(!_){_=!0;try{c.getTracks()[0].stop()}catch(t){}s&&s()}},w=function t(){try{d.readyState!==d.HAVE_ENOUGH_DATA||g||(h.height=d.videoHeight,h.width=d.videoWidth,v.setTransform(-1,0,0,1,h.width,0),v.drawImage(d,0,0,h.width,h.height),v.setTransform(1,0,0,1,0,0),m||(m=!0,h.style.display=l||""),g=!0,r.detect(d).then((function(t){var r=t&&t[0];if(r&&r.rawValue&&i.uuid==y){if(n&&!n(r.rawValue))return;!function(t,n,e){var r=e.cornerPoints;if(r&&r.length){for(var o=0;o1&&(e[n[0]]=n[1])}}));if(s.status>=200&&s.status<300){var r={errMsg:"request:ok"};try{var o=JSON.parse(s.response);r.data=o}catch(t){r.data=s.response}r.header=e,r.statusCode=s.status,t.success&&t.success(r)}else t.fail&&t.fail({errMsg:"request:fail",data:s.response,header:e})}},s.send(n)}(Object.assign({},{url:n,method:e,data:f,headers:c,json:a,timeout:s},{success:t,fail:r}))})).then((function(t){if(t.statusCode&&200!=t.statusCode)throw t;return t}))};var r=e(2),o=e(17),i=e(18)},function(t,n,e){"use strict";n.__esModule=!0,n.hex_md5=function(t){return p(r(l(t),8*t.length))},n.b64_md5=function(t){return h(r(l(t),8*t.length))},n.str_md5=function(t){return d(r(l(t),8*t.length))},n.hex_hmac_md5=function(t,n){return p(s(t,n))},n.b64_hmac_md5=function(t,n){return h(s(t,n))},n.str_hmac_md5=function(t,n){return d(s(t,n))};function r(t,n){t[n>>5]|=128<>>9<<4)]=n;for(var e=1732584193,r=-271733879,o=-1732584194,s=271733878,l=0;l>>32-c,e);var u,c}function i(t,n,e,r,i,u,c){return o(n&e|~n&r,t,n,i,u,c)}function u(t,n,e,r,i,u,c){return o(n&r|e&~r,t,n,i,u,c)}function c(t,n,e,r,i,u,c){return o(n^e^r,t,n,i,u,c)}function a(t,n,e,r,i,u,c){return o(e^(n|~r),t,n,i,u,c)}function s(t,n){var e=l(t);e.length>16&&(e=r(e,8*t.length));for(var o=Array(16),i=Array(16),u=0;u<16;u++)o[u]=909522486^e[u],i[u]=1549556828^e[u];var c=r(o.concat(l(n)),512+8*n.length);return r(i.concat(c),640)}function f(t,n){var e=(65535&t)+(65535&n);return(t>>16)+(n>>16)+(e>>16)<<16|65535&e}function l(t){for(var n=Array(),e=0;e<8*t.length;e+=8)n[e>>5]|=(255&t.charCodeAt(e/8))<>5]>>>e%32&255);return n}function p(t){for(var n="0123456789abcdef",e="",r=0;r<4*t.length;r++)e+=n.charAt(t[r>>2]>>r%4*8+4&15)+n.charAt(t[r>>2]>>r%4*8&15);return e}function h(t){for(var n="",e=0;e<4*t.length;e+=3)for(var r=(t[e>>2]>>e%4*8&255)<<16|(t[e+1>>2]>>(e+1)%4*8&255)<<8|t[e+2>>2]>>(e+2)%4*8&255,o=0;o<4;o++)8*e+6*o>32*t.length?n+="":n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>6*(3-o)&63);return n}},function(t,n,e){"use strict";n.__esModule=!0,n.stringifyQuery=function(t){return Object.keys(t).map((function(n){var e=t[n];return n+"="+encodeURIComponent(e)})).join("&")},n.decodeQuery=function(t){return Object.keys(t).reduce((function(n,e){var r=t[e];return n[e]=decodeURIComponent(r),n}),{})},n.parseQueryParams=u,n.appendQueryParams=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=u(t),r=e.url,o=e.params;Object.keys(n).forEach((function(t){var e=n[t];null!=e?o[t]=e:delete o[t]}));var i=Object.keys(o).map((function(t){var n=o[t];return t+"="+encodeURIComponent(n)})).join("&");if(!r)return i;if(!i)return r;return r+"?"+i},n.getQueryString=function(t,n){var e=i.default.location.search,r=new RegExp("(^|&)"+t+"=([^&]*)(&|$)"),o=e.substr(1).match(r);if(null!=o)return decodeURIComponent(unescape(o[2]));return n};var r,o=e(1),i=(r=o)&&r.__esModule?r:{default:r};function u(t){var n="",e={};if(!t||"string"!=typeof t)return{url:n,params:e};var r="",o=t.indexOf("?"),i=t.indexOf("#"),u=t.indexOf("=");return o>=0?(n=t.substring(0,o),r=t.substring(o+1,i>0?i:t.length)):u>=0?(n="",r=t):(n=t,r=""),r.split("&").map((function(t){var n=t.indexOf("=");if(n>0){var r=t.substring(0,n),o=t.substring(n+1);e[r]=decodeURIComponent(o)}})),{url:n,params:e}}},function(t,n,e){"use strict";n.__esModule=!0,n.startScanner=function(t){if(!t||"function"!=typeof t)return;if(r=t,"scanning"===o)return;o="scanning",a(),window.addEventListener("keydown",s)},n.stopScanner=function(){if("scanning"!==o)return;o="closed",r=null,a(),window.removeEventListener("keydown",s)};var r=null,o="closed",i="",u=null,c=0;function a(){i="",c=0,u&&(clearTimeout(u),u=null)}function s(t){if("scanning"===o&&!(t.ctrlKey||t.metaKey||t.altKey)){if("Enter"===t.key){var n=i.replace(/[\uFF01-\uFF5E]/g,(function(t){return String.fromCharCode(t.charCodeAt(0)-65248)})).replace(/\u3002/g,".");return n&&function(t){t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation()}(t),console.log("onScannerKeydown",n),a(),void(n&&r&&r(n))}if(t.key&&1===t.key.length){var e=Date.now();c&&e-c>100&&a(),c=e,i+=t.key,u&&clearTimeout(u),u=setTimeout((function(){a()}),100)}}}},function(t,n,e){"use strict";n.__esModule=!0;var r="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};n.exportSDK=function(t,n){for(var e=arguments.length,o=Array(e>2?e-2:0),f=2;f1;)e=e[r.shift()];if(e&&1==r.length&&e.hasOwnProperty(r[0])){for(var o,i=arguments.length,u=Array(i>2?i-2:0),c=2;c1&&void 0!==arguments[1]?arguments[1]:"",e={};return Object.keys(t).forEach((function(o){var i=t[o];if("object"===(void 0===i?"undefined":r(i)))Object.assign(e,a(i,""+n+o+"."));else if("function"==typeof i){var u,c=""+n+o;Object.assign(e,((u={})[c]=c,u))}})),e}function s(t){Object.keys(t).forEach((function(n){var e=t[n];"object"===(void 0===e?"undefined":r(e))&&s(e)})),Object.freeze(t)}}]); \ No newline at end of file + */var r;r=function(){"use strict";function t(t){return"function"==typeof t}var r=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},o=0,i=void 0,u=void 0,c=function(t,n){h[o]=t,h[o+1]=n,2===(o+=2)&&(u?u(v):b())},a="undefined"!=typeof window?window:void 0,s=a||{},f=s.MutationObserver||s.WebKitMutationObserver,l="undefined"==typeof self&&void 0!==n&&"[object process]"==={}.toString.call(n),d="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function p(){var t=setTimeout;return function(){return t(v,1)}}var h=new Array(1e3);function v(){for(var t=0;t1)for(var e=1;e0?(0,u.startScanner)((function(t){!function(t){if(!function(t){for(var n=0;n=0&&e.splice(r,1)}},n.bridgeSync=l,n.bridgeAsync=function(t,n,e){return new Promise((function(r,o){if(f()){var u=!1,a=null;e>0&&(a=setTimeout((function(){u=!0,a=null,o("bridgeAsync timeout")}),e));var s=(0,i.createUUID)()+"_"+Date.now();d=s,(p=function(t,n){u||(a&&clearTimeout(a),0==t?r(n):o(n))})&&"function"==typeof p&&(c[d]=p),l(t,Object.assign({request_id:s},n))}else o("Can't bridgeAsync, because not in runtime");var d,p})).then((function(e){var r=[t];return n&&(r.push("params:"),r.push(n)),e&&(r.push("resp:"),r.push(e)),o.printDebug.apply(void 0,["bridge resp >>>"].concat(r)),e})).catch((function(e){throw n?(0,o.printWarn)("bridge err >>>",t,"params:",n,e):(0,o.printWarn)("bridge err >>>",t,e),e}))};var r=e(4),o=e(5),i=e(2),u={},c={},a="__bridge_client__";function s(){var t=a+"_handle_callback";window[t]||(window[t]=function(t){var n=(0,r.toAny)(t,{}),e=n.method,o=n.payload,i=n.code,a=n.request_id,s=(0,r.toAny)(o,{});a?c[a]&&c[a](i,s):u[e]&&u[e].forEach((function(t){t&&t(s)}))})}function f(){return!!window[a]}function l(t,n){s();var e=(0,r.toAny)(function(t){for(var n=t.split("."),e=window;n.length>1;)e=e[n.shift()];if(e&&1==n.length&&e.hasOwnProperty(n[0])){for(var r,o=arguments.length,i=Array(o>1?o-1:0),u=1;u>>"].concat(i)),e}},function(t,n,e){"use strict";n.__esModule=!0,n.isSupportWebScan=function(){return"undefined"!=typeof navigator&&navigator.mediaDevices&&navigator.mediaDevices.getUserMedia&&"undefined"!=typeof BarcodeDetector},n.isSupportImageScan=function(){return"undefined"!=typeof document&&"undefined"!=typeof BarcodeDetector&&"undefined"!=typeof URL&&URL.createObjectURL},n.stopScanForWeb=f,n.startScanForImage=function(){return s((0,o.getConfig)("scanType")).then((function(t){return new Promise((function(t){var n=document.createElement("input");n.type="file",n.accept="image/*",n.style.display="none";var e=!1,r=function(n){e||(e=!0,u("__webscan_image_input__"),t(n))};n.id="__webscan_image_input__",n.onchange=function(){r(n.files&&n.files[0])},n.oncancel=function(){r(null)},document.body.appendChild(n),n.click()})).then((function(n){return function(t,n){if(!n)return Promise.resolve(null);if("undefined"!=typeof createImageBitmap)return createImageBitmap(n).then((function(n){return t.detect(n).then((function(t){return n.close&&n.close(),t&&t[0]})).catch((function(t){throw n.close&&n.close(),t}))}));return new Promise((function(e,r){var o=new Image,i=URL.createObjectURL(n);o.onload=function(){t.detect(o).then((function(t){URL.revokeObjectURL(i),e(t&&t[0])})).catch((function(t){URL.revokeObjectURL(i),r(t)}))},o.onerror=function(t){URL.revokeObjectURL(i),r(t)},o.src=i}))}(t,n)}))})).then((function(t){return t&&t.rawValue?{result:t.rawValue}:{success:!1,error:"未识别到二维码或条形码"}}))},n.startScanForWeb=function(t,n){return new Promise((function(e,u){try{i.uuid=(0,r.createUUID)(),i.finish=!1;var l,d=c("video","__webscan_video__","display: none",!1),p=t||"position: fixed; width: 300px; height: 240px; top: 0; left: 0; z-index: 9999;",h=c("canvas","__webscan_canvas__",p+" display: none;",!0);h.style.display,h.style.cssText=p,l=h.style.display,h.style.display="none";var v=h.getContext("2d"),y=i.uuid;d.width=300,d.height=300,d.uuid=i.uuid,s((0,o.getConfig)("scanType")).then((function(t){return navigator.mediaDevices.getUserMedia({video:{facingMode:"environment"}}).then((function(n){return{detector:t,stream:n}}))})).then((function(t){var r=t.detector,c=t.stream;d.srcObject=c,d.setAttribute("playsinline",!0),d.play();var s=(0,o.getConfig)("closeWebScan",(function(){})),p=(0,o.getConfig)("displayWebScan",(function(t,n){}));p&&p(h,(function(){f()})),h.style.display="none";var g=!1,m=!1,_=!1,b=function(){if(!_){_=!0;try{c.getTracks()[0].stop()}catch(t){}s&&s()}},w=function t(){try{d.readyState!==d.HAVE_ENOUGH_DATA||g||(h.height=d.videoHeight,h.width=d.videoWidth,v.setTransform(-1,0,0,1,h.width,0),v.drawImage(d,0,0,h.width,h.height),v.setTransform(1,0,0,1,0,0),m||(m=!0,h.style.display=l||""),g=!0,r.detect(d).then((function(t){var r=t&&t[0];if(r&&r.rawValue&&i.uuid==y){if(n&&!n(r.rawValue))return;!function(t,n,e){var r=e.cornerPoints;if(r&&r.length){for(var o=0;o1&&(e[n[0]]=n[1])}}));if(s.status>=200&&s.status<300){var r={errMsg:"request:ok"};try{var o=JSON.parse(s.response);r.data=o}catch(t){r.data=s.response}r.header=e,r.statusCode=s.status,t.success&&t.success(r)}else t.fail&&t.fail({errMsg:"request:fail",data:s.response,header:e})}},s.send(n)}(Object.assign({},{url:n,method:e,data:f,headers:c,json:a,timeout:s},{success:t,fail:r}))})).then((function(t){if(t.statusCode&&200!=t.statusCode)throw t;return t}))};var r=e(2),o=e(17),i=e(18)},function(t,n,e){"use strict";n.__esModule=!0,n.hex_md5=function(t){return p(r(l(t),8*t.length))},n.b64_md5=function(t){return h(r(l(t),8*t.length))},n.str_md5=function(t){return d(r(l(t),8*t.length))},n.hex_hmac_md5=function(t,n){return p(s(t,n))},n.b64_hmac_md5=function(t,n){return h(s(t,n))},n.str_hmac_md5=function(t,n){return d(s(t,n))};function r(t,n){t[n>>5]|=128<>>9<<4)]=n;for(var e=1732584193,r=-271733879,o=-1732584194,s=271733878,l=0;l>>32-c,e);var u,c}function i(t,n,e,r,i,u,c){return o(n&e|~n&r,t,n,i,u,c)}function u(t,n,e,r,i,u,c){return o(n&r|e&~r,t,n,i,u,c)}function c(t,n,e,r,i,u,c){return o(n^e^r,t,n,i,u,c)}function a(t,n,e,r,i,u,c){return o(e^(n|~r),t,n,i,u,c)}function s(t,n){var e=l(t);e.length>16&&(e=r(e,8*t.length));for(var o=Array(16),i=Array(16),u=0;u<16;u++)o[u]=909522486^e[u],i[u]=1549556828^e[u];var c=r(o.concat(l(n)),512+8*n.length);return r(i.concat(c),640)}function f(t,n){var e=(65535&t)+(65535&n);return(t>>16)+(n>>16)+(e>>16)<<16|65535&e}function l(t){for(var n=Array(),e=0;e<8*t.length;e+=8)n[e>>5]|=(255&t.charCodeAt(e/8))<>5]>>>e%32&255);return n}function p(t){for(var n="0123456789abcdef",e="",r=0;r<4*t.length;r++)e+=n.charAt(t[r>>2]>>r%4*8+4&15)+n.charAt(t[r>>2]>>r%4*8&15);return e}function h(t){for(var n="",e=0;e<4*t.length;e+=3)for(var r=(t[e>>2]>>e%4*8&255)<<16|(t[e+1>>2]>>(e+1)%4*8&255)<<8|t[e+2>>2]>>(e+2)%4*8&255,o=0;o<4;o++)8*e+6*o>32*t.length?n+="":n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>6*(3-o)&63);return n}},function(t,n,e){"use strict";n.__esModule=!0,n.stringifyQuery=function(t){return Object.keys(t).map((function(n){var e=t[n];return n+"="+encodeURIComponent(e)})).join("&")},n.decodeQuery=function(t){return Object.keys(t).reduce((function(n,e){var r=t[e];return n[e]=decodeURIComponent(r),n}),{})},n.parseQueryParams=u,n.appendQueryParams=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=u(t),r=e.url,o=e.params;Object.keys(n).forEach((function(t){var e=n[t];null!=e?o[t]=e:delete o[t]}));var i=Object.keys(o).map((function(t){var n=o[t];return t+"="+encodeURIComponent(n)})).join("&");if(!r)return i;if(!i)return r;return r+"?"+i},n.getQueryString=function(t,n){var e=i.default.location.search,r=new RegExp("(^|&)"+t+"=([^&]*)(&|$)"),o=e.substr(1).match(r);if(null!=o)return decodeURIComponent(unescape(o[2]));return n};var r,o=e(1),i=(r=o)&&r.__esModule?r:{default:r};function u(t){var n="",e={};if(!t||"string"!=typeof t)return{url:n,params:e};var r="",o=t.indexOf("?"),i=t.indexOf("#"),u=t.indexOf("=");return o>=0?(n=t.substring(0,o),r=t.substring(o+1,i>0?i:t.length)):u>=0?(n="",r=t):(n=t,r=""),r.split("&").map((function(t){var n=t.indexOf("=");if(n>0){var r=t.substring(0,n),o=t.substring(n+1);e[r]=decodeURIComponent(o)}})),{url:n,params:e}}},function(t,n,e){"use strict";n.__esModule=!0,n.startScanner=function(t){if(!t||"function"!=typeof t)return;if(r=t,"scanning"===o)return;o="scanning",a(),window.addEventListener("keydown",s)},n.stopScanner=function(){if("scanning"!==o)return;o="closed",r=null,a(),window.removeEventListener("keydown",s)};var r=null,o="closed",i="",u=null,c=0;function a(){i="",c=0,u&&(clearTimeout(u),u=null)}function s(t){if("scanning"===o&&!(t.ctrlKey||t.metaKey||t.altKey)){if("Enter"===t.key){var n=i.replace(/[\uFF01-\uFF5E]/g,(function(t){return String.fromCharCode(t.charCodeAt(0)-65248)})).replace(/\u3002/g,".");return n&&function(t){t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation()}(t),console.log("onScannerKeydown",n),a(),void(n&&r&&r(n))}if(t.key&&1===t.key.length){var e=Date.now();c&&e-c>100&&a(),c=e,i+=t.key,u&&clearTimeout(u),u=setTimeout((function(){a()}),100)}}}},function(t,n,e){"use strict";n.__esModule=!0;var r="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};n.exportSDK=function(t,n){for(var e=arguments.length,o=Array(e>2?e-2:0),f=2;f1;)e=e[r.shift()];if(e&&1==r.length&&e.hasOwnProperty(r[0])){for(var o,i=arguments.length,u=Array(i>2?i-2:0),c=2;c1&&void 0!==arguments[1]?arguments[1]:"",e={};return Object.keys(t).forEach((function(o){var i=t[o];if("object"===(void 0===i?"undefined":r(i)))Object.assign(e,a(i,""+n+o+"."));else if("function"==typeof i){var u,c=""+n+o;Object.assign(e,((u={})[c]=c,u))}})),e}function s(t){Object.keys(t).forEach((function(n){var e=t[n];"object"===(void 0===e?"undefined":r(e))&&s(e)})),Object.freeze(t)}}]); \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index 4ed72c1..dc895a3 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -7,7 +7,7 @@ interface ScanConfigOptions { */ webCanvasStyle?: string, /** - * 微信JSSDK配置,配置后会自动初始化微信JSSDK + * 微信JSSDK配置,微信环境才会生效,配置后会自动初始化微信JSSDK */ initWechatJssdk: { /** @@ -33,6 +33,47 @@ interface ScanResult { key: string } +/** + * 监听key + */ +interface ScanListenerInfo { + /** + * 监听key + */ + key?: string; + /** + * 监听匹配 + */ + match?: string; + /** + * 监听级别 + */ + level?: number; + /** + * 监听回调 + */ + listener: ScanCallback; + /** + * 取消监听 + */ + cancel: () => void; +} + +/** + * 监听状态 + */ +type ScanStatus = "scanning" | "closed"; + +/** + * 监听回调 + */ +type ScanCallback = (result: ScanResult) => any; + +/** + * 监听状态 + */ +type ScanStatusCallback = (status: ScanStatus) => any; + /** IScan */ interface IScan { /** @@ -44,7 +85,7 @@ interface IScan { * 监听扫码状态 * @param callback 监听回调 */ - setStatusListener(callback: (status: "scanning" | "closed") => any): void; + setStatusListener(callback: ScanStatusCallback): void; /** * 监听扫码结果 * @param callback 监听回调 @@ -52,17 +93,17 @@ interface IScan { * @param match 监听匹配 * @param level 监听级别 */ - onScanListener(callback: (result: ScanResult) => any, key: string, match: string, level: number): void; + onScanListener(callback: ScanCallback, key: string, match?: string, level?: number): ScanListenerInfo; /** * 取消监听扫码结果 - * @param callback 监听回调 + * @param callback 监听回调,或监听key */ - offScanListener(callback: (result: ScanResult) => any): void; + offScanListener(callback: ScanCallback | string): void; /** * 获取扫码状态 - * @returns "scanning" | "closed" + * @returns ScanStatus */ - getStatus(): "scanning" | "closed"; + getStatus(): ScanStatus; /** * 关闭扫码 */ @@ -78,8 +119,15 @@ interface IScan { } +/** + * IScan 实例 + */ declare var IScan: IScan; +/** + * 将 IScan 实例挂载到 Window 对象上 + * 方便在全局使用 + */ declare interface Window { IScan: IScan; } \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 4014cae..223d05d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -!function(n){var t={};function e(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}e.m=n,e.c=t,e.d=function(n,t,r){e.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:r})},e.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},e.t=function(n,t){if(1&t&&(n=e(n)),8&t)return n;if(4&t&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&t&&"string"!=typeof n)for(var o in n)e.d(r,o,function(t){return n[t]}.bind(null,o));return r},e.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return e.d(t,"a",t),t},e.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},e.p="",e(e.s=7)}([function(n,t,e){"use strict";t.__esModule=!0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};t.getVersion=function(){return o.version},t.getConfig=function(n){var t=u[n];return t||(t=i[n]),t},t.setConfig=function(n){n&&"object"==(void 0===n?"undefined":r(n))&&Object.assign(u,n)};var o={version:"0.0.1.0430.1014"},i={},u={}},function(n,t,e){"use strict";t.__esModule=!0;var r;r="undefined"!=typeof GameGlobal?Object.assign({},GameGlobal):"undefined"==typeof window?{setTimeout:function(n){function t(){return n.apply(this,arguments)}return t.toString=function(){return n.toString()},t}((function(){return setTimeout.apply(void 0,arguments)})),setInterval:function(n){function t(){return n.apply(this,arguments)}return t.toString=function(){return n.toString()},t}((function(){return setInterval.apply(void 0,arguments)})),clearTimeout:function(n){function t(){return n.apply(this,arguments)}return t.toString=function(){return n.toString()},t}((function(){return clearTimeout.apply(void 0,arguments)})),clearInterval:function(n){function t(){return n.apply(this,arguments)}return t.toString=function(){return n.toString()},t}((function(){return clearInterval.apply(void 0,arguments)}))}:window,t.default=r},function(n,t,e){"use strict";t.__esModule=!0,t.createUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(n){var t=16*Math.random()|0;return("x"==n?t:3&t|8).toString(16)}))}},function(n,t,e){"use strict";t.__esModule=!0,t.isReadyCalled=function(){return s},e(8);var r=function(n){return n&&n.__esModule?n:{default:n}}(e(1)),o=e(0),i=e(13),u=e(6),c=e(5),a=null,s=!1;r.default.__IScanReady__&&r.default.__IScanReady__(),t.default=Object.assign({},{config:function(n){return n&&(0,o.setConfig)(n),a||(a=Promise.resolve().then((function(){return(0,c.printDebug)("-------------------------------"),(0,c.printDebug)("sdk_version:",(0,o.getVersion)()),(0,c.printDebug)("-------------------------------"),(0,u.initWxJssdk)(),Promise.resolve().then((function(){s=!0})).catch((function(n){throw a=null,n}))})))},onScanListener:i.onScanListener,offScanListener:i.offScanListener,setStatusListener:i.setStatusListener,getStatus:i.getStatus,startScan:i.startScan,stopScan:i.stopScan,clear:i.clear})},function(n,t,e){"use strict";t.__esModule=!0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};t.toAny=function(n,t){if(null==n)return t;var e=function(n){if("string"!=typeof n)return void 0===n?"undefined":r(n);try{var t=JSON.parse(n);return void 0===t?"undefined":r(t)}catch(t){var e=parseFloat(n);return isNaN(e)||""+e!==n?"string":"number"}}(n);switch(null!=t&&(e=void 0===t?"undefined":r(t)),e){case"number":return function(n){try{return JSON.parse(n)}catch(t){return parseFloat(n)}}(n);case"boolean":return function(n){return!!n&&"false"!=n&&"0"!=n}(n);case"object":return function(n,t){if("object"===(void 0===n?"undefined":r(n)))return n;try{return JSON.parse(n)}catch(n){}return t}(n,t);case"string":return function(n,t){try{var e=void 0===n?"undefined":r(n);if("string"===e)return n;if("boolean"===e)return n?"true":"false";if("number"===e)return""+n;if("object"===e)return JSON.stringify(n)}catch(n){}return t}(n,t)}return t}},function(n,t,e){"use strict";t.__esModule=!0,t.printError=function(n){for(var t,e=arguments.length,r=Array(e>1?e-1:0),o=1;o1?e-1:0),o=1;o1?e-1:0),o=1;o1)for(var e=1;e0?(0,u.startScanner)((function(n){!function(n){if(function(n){for(var t=0;t=0&&e.splice(r,1)}},t.bridgeSync=l,t.bridgeAsync=function(n,t,e){return new Promise((function(r,o){if(f()){var u=!1,a=null;e>0&&(a=setTimeout((function(){u=!0,a=null,o("bridgeAsync timeout")}),e));var s=(0,i.createUUID)()+"_"+Date.now();!function(n,t){t&&(c[n]=t)}(s,(function(n,t){u||(a&&clearTimeout(a),0==n?r(t):o(t))})),l(n,Object.assign({request_id:s},t))}else o("Can't bridgeAsync, because not in runtime")})).then((function(e){var r=[n];return t&&(r.push("params:"),r.push(t)),e&&(r.push("resp:"),r.push(e)),o.printDebug.apply(void 0,["bridge resp >>>"].concat(r)),e})).catch((function(e){throw t?(0,o.printWarn)("bridge err >>>",n,"params:",t,e):(0,o.printWarn)("bridge err >>>",n,e),e}))};var r=e(4),o=e(5),i=e(2),u={},c={},a="__bridge_client__";function s(){var n=a+"_handle_callback";window[n]||(window[n]=function(n){var t=(0,r.toAny)(n,{}),e=t.method,o=t.payload,i=t.code,a=t.request_id,s=(0,r.toAny)(o,{});a?c[a]&&c[a](i,s):u[e]&&u[e].forEach((function(n){n&&n(s)}))})}function f(){return!!window[a]}function l(n,t){s();var e=(0,r.toAny)(function(n){for(var t=n.split("."),e=window;t.length>1;)e=e[t.shift()];if(e&&1==t.length&&e.hasOwnProperty(t[0])){for(var r,o=arguments.length,i=Array(o>1?o-1:0),u=1;u>>"].concat(i)),e}},function(n,t,e){"use strict";t.__esModule=!0,t.isSupportWebScan=function(){return"undefined"!=typeof navigator&&navigator.mediaDevices&&navigator.mediaDevices.getUserMedia&&"undefined"!=typeof BarcodeDetector},t.isSupportImageScan=function(){return"undefined"!=typeof document&&"undefined"!=typeof BarcodeDetector&&"undefined"!=typeof URL&&URL.createObjectURL},t.stopScanForWeb=f,t.startScanForImage=function(){return s((0,o.getConfig)("scanType")).then((function(n){return new Promise((function(n){var t=document.createElement("input");t.type="file",t.accept="image/*",t.style.display="none";var e=!1,r=function(t){e||(e=!0,u("__webscan_image_input__"),n(t))};t.id="__webscan_image_input__",t.onchange=function(){r(t.files&&t.files[0])},t.oncancel=function(){r(null)},document.body.appendChild(t),t.click()})).then((function(t){return function(n,t){return t?"undefined"!=typeof createImageBitmap?createImageBitmap(t).then((function(t){return n.detect(t).then((function(n){return t.close&&t.close(),n&&n[0]})).catch((function(n){throw t.close&&t.close(),n}))})):new Promise((function(e,r){var o=new Image,i=URL.createObjectURL(t);o.onload=function(){n.detect(o).then((function(n){URL.revokeObjectURL(i),e(n&&n[0])})).catch((function(n){URL.revokeObjectURL(i),r(n)}))},o.onerror=function(n){URL.revokeObjectURL(i),r(n)},o.src=i})):Promise.resolve(null)}(n,t)}))})).then((function(n){return n&&n.rawValue?{result:n.rawValue}:{success:!1,error:"未识别到二维码或条形码"}}))},t.startScanForWeb=function(n,t){return new Promise((function(e,u){try{i.uuid=(0,r.createUUID)(),i.finish=!1;var l,d=c("video","__webscan_video__","display: none",!1),p=n||"position: fixed; width: 300px; height: 240px; top: 0; left: 0; z-index: 9999;",h=c("canvas","__webscan_canvas__",p+" display: none;",!0);h.style.display,h.style.cssText=p,l=h.style.display,h.style.display="none";var v=h.getContext("2d"),y=i.uuid;d.width=300,d.height=300,d.uuid=i.uuid,s((0,o.getConfig)("scanType")).then((function(n){return navigator.mediaDevices.getUserMedia({video:{facingMode:"environment"}}).then((function(t){return{detector:n,stream:t}}))})).then((function(n){var r=n.detector,c=n.stream;d.srcObject=c,d.setAttribute("playsinline",!0),d.play();var s=(0,o.getConfig)("closeWebScan",(function(){})),p=(0,o.getConfig)("displayWebScan",(function(n,t){}));p&&p(h,(function(){f()})),h.style.display="none";var g=!1,m=!1,_=!1,b=function(){if(!_){_=!0;try{c.getTracks()[0].stop()}catch(n){}s&&s()}};requestAnimationFrame((function(){!function n(){try{d.readyState!==d.HAVE_ENOUGH_DATA||g||(h.height=d.videoHeight,h.width=d.videoWidth,v.setTransform(-1,0,0,1,h.width,0),v.drawImage(d,0,0,h.width,h.height),v.setTransform(1,0,0,1,0,0),m||(m=!0,h.style.display=l||""),g=!0,r.detect(d).then((function(n){var r=n&&n[0];if(r&&r.rawValue&&i.uuid==y){if(t&&!t(r.rawValue))return;!function(n,t,e){var r=e.cornerPoints;if(r&&r.length)for(var o=0;o1&&(e[t[0]]=t[1])}})),s.status>=200&&s.status<300){var r={errMsg:"request:ok"};try{var o=JSON.parse(s.response);r.data=o}catch(n){r.data=s.response}r.header=e,r.statusCode=s.status,n.success&&n.success(r)}else n.fail&&n.fail({errMsg:"request:fail",data:s.response,header:e})}},s.send(t)}(Object.assign({},{url:t,method:e,data:f,headers:c,json:a,timeout:s},{success:n,fail:r}))})).then((function(n){if(n.statusCode&&200!=n.statusCode)throw n;return n}))};var r=e(2),o=e(17),i=e(18)},function(n,t,e){"use strict";t.__esModule=!0,t.hex_md5=function(n){return h(o(d(n),n.length*r))},t.b64_md5=function(n){return v(o(d(n),n.length*r))},t.str_md5=function(n){return p(o(d(n),n.length*r))},t.hex_hmac_md5=function(n,t){return h(f(n,t))},t.b64_hmac_md5=function(n,t){return v(f(n,t))},t.str_hmac_md5=function(n,t){return p(f(n,t))};var r=8;function o(n,t){n[t>>5]|=128<>>9<<4)]=t;for(var e=1732584193,r=-271733879,o=-1732584194,i=271733878,f=0;f>>32-t}(l(l(t,n),l(r,i)),o),e)}function u(n,t,e,r,o,u,c){return i(t&e|~t&r,n,t,o,u,c)}function c(n,t,e,r,o,u,c){return i(t&r|e&~r,n,t,o,u,c)}function a(n,t,e,r,o,u,c){return i(t^e^r,n,t,o,u,c)}function s(n,t,e,r,o,u,c){return i(e^(t|~r),n,t,o,u,c)}function f(n,t){var e=d(n);e.length>16&&(e=o(e,n.length*r));for(var i=Array(16),u=Array(16),c=0;c<16;c++)i[c]=909522486^e[c],u[c]=1549556828^e[c];var a=o(i.concat(d(t)),512+t.length*r);return o(u.concat(a),640)}function l(n,t){var e=(65535&n)+(65535&t);return(n>>16)+(t>>16)+(e>>16)<<16|65535&e}function d(n){for(var t=Array(),e=(1<>5]|=(n.charCodeAt(o/r)&e)<>5]>>>o%32&e);return t}function h(n){for(var t="0123456789abcdef",e="",r=0;r<4*n.length;r++)e+=t.charAt(n[r>>2]>>r%4*8+4&15)+t.charAt(n[r>>2]>>r%4*8&15);return e}function v(n){for(var t="",e=0;e<4*n.length;e+=3)for(var r=(n[e>>2]>>e%4*8&255)<<16|(n[e+1>>2]>>(e+1)%4*8&255)<<8|n[e+2>>2]>>(e+2)%4*8&255,o=0;o<4;o++)8*e+6*o>32*n.length?t+="":t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>6*(3-o)&63);return t}},function(n,t,e){"use strict";t.__esModule=!0,t.stringifyQuery=function(n){return Object.keys(n).map((function(t){var e=n[t];return t+"="+encodeURIComponent(e)})).join("&")},t.decodeQuery=function(n){return Object.keys(n).reduce((function(t,e){var r=n[e];return t[e]=decodeURIComponent(r),t}),{})},t.parseQueryParams=o,t.appendQueryParams=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=o(n),r=e.url,i=e.params;Object.keys(t).forEach((function(n){var e=t[n];null!=e?i[n]=e:delete i[n]}));var u=Object.keys(i).map((function(n){var t=i[n];return n+"="+encodeURIComponent(t)})).join("&");return r?u?r+"?"+u:r:u},t.getQueryString=function(n,t){var e=r.default.location.search,o=new RegExp("(^|&)"+n+"=([^&]*)(&|$)"),i=e.substr(1).match(o);return null!=i?decodeURIComponent(unescape(i[2])):t};var r=function(n){return n&&n.__esModule?n:{default:n}}(e(1));function o(n){var t="",e={};if(!n||"string"!=typeof n)return{url:t,params:e};var r="",o=n.indexOf("?"),i=n.indexOf("#"),u=n.indexOf("=");return o>=0?(t=n.substring(0,o),r=n.substring(o+1,i>0?i:n.length)):u>=0?(t="",r=n):(t=n,r=""),r.split("&").map((function(n){var t=n.indexOf("=");if(t>0){var r=n.substring(0,t),o=n.substring(t+1);e[r]=decodeURIComponent(o)}})),{url:t,params:e}}},function(n,t,e){"use strict";t.__esModule=!0,t.startScanner=function(n){n&&"function"==typeof n&&(r=n,"scanning"!==o&&(o="scanning",a(),window.addEventListener("keydown",s)))},t.stopScanner=function(){"scanning"===o&&(o="closed",r=null,a(),window.removeEventListener("keydown",s))};var r=null,o="closed",i="",u=null,c=0;function a(){i="",c=0,u&&(clearTimeout(u),u=null)}function s(n){if("scanning"===o&&!(n.ctrlKey||n.metaKey||n.altKey)){if("Enter"===n.key){var t=function(n){return n.replace(/[\uFF01-\uFF5E]/g,(function(n){return String.fromCharCode(n.charCodeAt(0)-65248)})).replace(/\u3002/g,".")}(i);return t&&function(n){n.preventDefault&&n.preventDefault(),n.stopPropagation&&n.stopPropagation()}(n),console.log("onScannerKeydown",t),a(),void(t&&r&&r(t))}if(n.key&&1===n.key.length){var e=Date.now();c&&e-c>100&&a(),c=e,i+=n.key,u&&clearTimeout(u),u=setTimeout((function(){a()}),100)}}}},function(n,t,e){"use strict";t.__esModule=!0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};t.exportSDK=function(n,t){for(var e=arguments.length,i=Array(e>2?e-2:0),u=2;u1&&void 0!==arguments[1]?arguments[1]:"",o={};return Object.keys(t).forEach((function(i){var u=t[i];if("object"===(void 0===u?"undefined":r(u)))Object.assign(o,n(u,""+e+i+"."));else if("function"==typeof u){var c,a=""+e+i;Object.assign(o,((c={})[a]=a,c))}})),o}(n);var a={};return Object.keys(c).forEach((function(t){var e=c[t],r=e&&e.method||t;!function(n,t,e){var r=t.split(".");r.forEach((function(t,o){o==r.length-1?n[t]=e:n[t]||(n[t]={}),n=n[t]}))}(a,t,(function(){for(var e=arguments.length,u=Array(e),c=0;c1;)e=e[r.shift()];if(e&&1==r.length&&e.hasOwnProperty(r[0])){for(var o,i=arguments.length,u=Array(i>2?i-2:0),c=2;c1?e-1:0),o=1;o1?e-1:0),o=1;o1?e-1:0),o=1;o1)for(var e=1;e0?(0,u.startScanner)((function(n){!function(n){if(function(n){for(var t=0;t=0&&e.splice(r,1)}},t.bridgeSync=l,t.bridgeAsync=function(n,t,e){return new Promise((function(r,o){if(f()){var u=!1,a=null;e>0&&(a=setTimeout((function(){u=!0,a=null,o("bridgeAsync timeout")}),e));var s=(0,i.createUUID)()+"_"+Date.now();!function(n,t){t&&(c[n]=t)}(s,(function(n,t){u||(a&&clearTimeout(a),0==n?r(t):o(t))})),l(n,Object.assign({request_id:s},t))}else o("Can't bridgeAsync, because not in runtime")})).then((function(e){var r=[n];return t&&(r.push("params:"),r.push(t)),e&&(r.push("resp:"),r.push(e)),o.printDebug.apply(void 0,["bridge resp >>>"].concat(r)),e})).catch((function(e){throw t?(0,o.printWarn)("bridge err >>>",n,"params:",t,e):(0,o.printWarn)("bridge err >>>",n,e),e}))};var r=e(4),o=e(5),i=e(2),u={},c={},a="__bridge_client__";function s(){var n=a+"_handle_callback";window[n]||(window[n]=function(n){var t=(0,r.toAny)(n,{}),e=t.method,o=t.payload,i=t.code,a=t.request_id,s=(0,r.toAny)(o,{});a?c[a]&&c[a](i,s):u[e]&&u[e].forEach((function(n){n&&n(s)}))})}function f(){return!!window[a]}function l(n,t){s();var e=(0,r.toAny)(function(n){for(var t=n.split("."),e=window;t.length>1;)e=e[t.shift()];if(e&&1==t.length&&e.hasOwnProperty(t[0])){for(var r,o=arguments.length,i=Array(o>1?o-1:0),u=1;u>>"].concat(i)),e}},function(n,t,e){"use strict";t.__esModule=!0,t.isSupportWebScan=function(){return"undefined"!=typeof navigator&&navigator.mediaDevices&&navigator.mediaDevices.getUserMedia&&"undefined"!=typeof BarcodeDetector},t.isSupportImageScan=function(){return"undefined"!=typeof document&&"undefined"!=typeof BarcodeDetector&&"undefined"!=typeof URL&&URL.createObjectURL},t.stopScanForWeb=f,t.startScanForImage=function(){return s((0,o.getConfig)("scanType")).then((function(n){return new Promise((function(n){var t=document.createElement("input");t.type="file",t.accept="image/*",t.style.display="none";var e=!1,r=function(t){e||(e=!0,u("__webscan_image_input__"),n(t))};t.id="__webscan_image_input__",t.onchange=function(){r(t.files&&t.files[0])},t.oncancel=function(){r(null)},document.body.appendChild(t),t.click()})).then((function(t){return function(n,t){return t?"undefined"!=typeof createImageBitmap?createImageBitmap(t).then((function(t){return n.detect(t).then((function(n){return t.close&&t.close(),n&&n[0]})).catch((function(n){throw t.close&&t.close(),n}))})):new Promise((function(e,r){var o=new Image,i=URL.createObjectURL(t);o.onload=function(){n.detect(o).then((function(n){URL.revokeObjectURL(i),e(n&&n[0])})).catch((function(n){URL.revokeObjectURL(i),r(n)}))},o.onerror=function(n){URL.revokeObjectURL(i),r(n)},o.src=i})):Promise.resolve(null)}(n,t)}))})).then((function(n){return n&&n.rawValue?{result:n.rawValue}:{success:!1,error:"未识别到二维码或条形码"}}))},t.startScanForWeb=function(n,t){return new Promise((function(e,u){try{i.uuid=(0,r.createUUID)(),i.finish=!1;var l,d=c("video","__webscan_video__","display: none",!1),p=n||"position: fixed; width: 300px; height: 240px; top: 0; left: 0; z-index: 9999;",h=c("canvas","__webscan_canvas__",p+" display: none;",!0);h.style.display,h.style.cssText=p,l=h.style.display,h.style.display="none";var v=h.getContext("2d"),y=i.uuid;d.width=300,d.height=300,d.uuid=i.uuid,s((0,o.getConfig)("scanType")).then((function(n){return navigator.mediaDevices.getUserMedia({video:{facingMode:"environment"}}).then((function(t){return{detector:n,stream:t}}))})).then((function(n){var r=n.detector,c=n.stream;d.srcObject=c,d.setAttribute("playsinline",!0),d.play();var s=(0,o.getConfig)("closeWebScan",(function(){})),p=(0,o.getConfig)("displayWebScan",(function(n,t){}));p&&p(h,(function(){f()})),h.style.display="none";var g=!1,m=!1,_=!1,b=function(){if(!_){_=!0;try{c.getTracks()[0].stop()}catch(n){}s&&s()}};requestAnimationFrame((function(){!function n(){try{d.readyState!==d.HAVE_ENOUGH_DATA||g||(h.height=d.videoHeight,h.width=d.videoWidth,v.setTransform(-1,0,0,1,h.width,0),v.drawImage(d,0,0,h.width,h.height),v.setTransform(1,0,0,1,0,0),m||(m=!0,h.style.display=l||""),g=!0,r.detect(d).then((function(n){var r=n&&n[0];if(r&&r.rawValue&&i.uuid==y){if(t&&!t(r.rawValue))return;!function(n,t,e){var r=e.cornerPoints;if(r&&r.length)for(var o=0;o1&&(e[t[0]]=t[1])}})),s.status>=200&&s.status<300){var r={errMsg:"request:ok"};try{var o=JSON.parse(s.response);r.data=o}catch(n){r.data=s.response}r.header=e,r.statusCode=s.status,n.success&&n.success(r)}else n.fail&&n.fail({errMsg:"request:fail",data:s.response,header:e})}},s.send(t)}(Object.assign({},{url:t,method:e,data:f,headers:c,json:a,timeout:s},{success:n,fail:r}))})).then((function(n){if(n.statusCode&&200!=n.statusCode)throw n;return n}))};var r=e(2),o=e(17),i=e(18)},function(n,t,e){"use strict";t.__esModule=!0,t.hex_md5=function(n){return h(o(d(n),n.length*r))},t.b64_md5=function(n){return v(o(d(n),n.length*r))},t.str_md5=function(n){return p(o(d(n),n.length*r))},t.hex_hmac_md5=function(n,t){return h(f(n,t))},t.b64_hmac_md5=function(n,t){return v(f(n,t))},t.str_hmac_md5=function(n,t){return p(f(n,t))};var r=8;function o(n,t){n[t>>5]|=128<>>9<<4)]=t;for(var e=1732584193,r=-271733879,o=-1732584194,i=271733878,f=0;f>>32-t}(l(l(t,n),l(r,i)),o),e)}function u(n,t,e,r,o,u,c){return i(t&e|~t&r,n,t,o,u,c)}function c(n,t,e,r,o,u,c){return i(t&r|e&~r,n,t,o,u,c)}function a(n,t,e,r,o,u,c){return i(t^e^r,n,t,o,u,c)}function s(n,t,e,r,o,u,c){return i(e^(t|~r),n,t,o,u,c)}function f(n,t){var e=d(n);e.length>16&&(e=o(e,n.length*r));for(var i=Array(16),u=Array(16),c=0;c<16;c++)i[c]=909522486^e[c],u[c]=1549556828^e[c];var a=o(i.concat(d(t)),512+t.length*r);return o(u.concat(a),640)}function l(n,t){var e=(65535&n)+(65535&t);return(n>>16)+(t>>16)+(e>>16)<<16|65535&e}function d(n){for(var t=Array(),e=(1<>5]|=(n.charCodeAt(o/r)&e)<>5]>>>o%32&e);return t}function h(n){for(var t="0123456789abcdef",e="",r=0;r<4*n.length;r++)e+=t.charAt(n[r>>2]>>r%4*8+4&15)+t.charAt(n[r>>2]>>r%4*8&15);return e}function v(n){for(var t="",e=0;e<4*n.length;e+=3)for(var r=(n[e>>2]>>e%4*8&255)<<16|(n[e+1>>2]>>(e+1)%4*8&255)<<8|n[e+2>>2]>>(e+2)%4*8&255,o=0;o<4;o++)8*e+6*o>32*n.length?t+="":t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>6*(3-o)&63);return t}},function(n,t,e){"use strict";t.__esModule=!0,t.stringifyQuery=function(n){return Object.keys(n).map((function(t){var e=n[t];return t+"="+encodeURIComponent(e)})).join("&")},t.decodeQuery=function(n){return Object.keys(n).reduce((function(t,e){var r=n[e];return t[e]=decodeURIComponent(r),t}),{})},t.parseQueryParams=o,t.appendQueryParams=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=o(n),r=e.url,i=e.params;Object.keys(t).forEach((function(n){var e=t[n];null!=e?i[n]=e:delete i[n]}));var u=Object.keys(i).map((function(n){var t=i[n];return n+"="+encodeURIComponent(t)})).join("&");return r?u?r+"?"+u:r:u},t.getQueryString=function(n,t){var e=r.default.location.search,o=new RegExp("(^|&)"+n+"=([^&]*)(&|$)"),i=e.substr(1).match(o);return null!=i?decodeURIComponent(unescape(i[2])):t};var r=function(n){return n&&n.__esModule?n:{default:n}}(e(1));function o(n){var t="",e={};if(!n||"string"!=typeof n)return{url:t,params:e};var r="",o=n.indexOf("?"),i=n.indexOf("#"),u=n.indexOf("=");return o>=0?(t=n.substring(0,o),r=n.substring(o+1,i>0?i:n.length)):u>=0?(t="",r=n):(t=n,r=""),r.split("&").map((function(n){var t=n.indexOf("=");if(t>0){var r=n.substring(0,t),o=n.substring(t+1);e[r]=decodeURIComponent(o)}})),{url:t,params:e}}},function(n,t,e){"use strict";t.__esModule=!0,t.startScanner=function(n){n&&"function"==typeof n&&(r=n,"scanning"!==o&&(o="scanning",a(),window.addEventListener("keydown",s)))},t.stopScanner=function(){"scanning"===o&&(o="closed",r=null,a(),window.removeEventListener("keydown",s))};var r=null,o="closed",i="",u=null,c=0;function a(){i="",c=0,u&&(clearTimeout(u),u=null)}function s(n){if("scanning"===o&&!(n.ctrlKey||n.metaKey||n.altKey)){if("Enter"===n.key){var t=function(n){return n.replace(/[\uFF01-\uFF5E]/g,(function(n){return String.fromCharCode(n.charCodeAt(0)-65248)})).replace(/\u3002/g,".")}(i);return t&&function(n){n.preventDefault&&n.preventDefault(),n.stopPropagation&&n.stopPropagation()}(n),console.log("onScannerKeydown",t),a(),void(t&&r&&r(t))}if(n.key&&1===n.key.length){var e=Date.now();c&&e-c>100&&a(),c=e,i+=n.key,u&&clearTimeout(u),u=setTimeout((function(){a()}),100)}}}},function(n,t,e){"use strict";t.__esModule=!0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};t.exportSDK=function(n,t){for(var e=arguments.length,i=Array(e>2?e-2:0),u=2;u1&&void 0!==arguments[1]?arguments[1]:"",o={};return Object.keys(t).forEach((function(i){var u=t[i];if("object"===(void 0===u?"undefined":r(u)))Object.assign(o,n(u,""+e+i+"."));else if("function"==typeof u){var c,a=""+e+i;Object.assign(o,((c={})[a]=a,c))}})),o}(n);var a={};return Object.keys(c).forEach((function(t){var e=c[t],r=e&&e.method||t;!function(n,t,e){var r=t.split(".");r.forEach((function(t,o){o==r.length-1?n[t]=e:n[t]||(n[t]={}),n=n[t]}))}(a,t,(function(){for(var e=arguments.length,u=Array(e),c=0;c1;)e=e[r.shift()];if(e&&1==r.length&&e.hasOwnProperty(r[0])){for(var o,i=arguments.length,u=Array(i>2?i-2:0),c=2;c void; +} + +/** + * 监听状态 + */ +type ScanStatus = "scanning" | "closed"; + +/** + * 监听回调 + */ +type ScanCallback = (result: ScanResult) => any; + +/** + * 监听状态 + */ +type ScanStatusCallback = (status: ScanStatus) => any; + /** IScan */ interface IScan { /** @@ -44,7 +85,7 @@ interface IScan { * 监听扫码状态 * @param callback 监听回调 */ - setStatusListener(callback: (status: "scanning" | "closed") => any): void; + setStatusListener(callback: ScanStatusCallback): void; /** * 监听扫码结果 * @param callback 监听回调 @@ -52,17 +93,17 @@ interface IScan { * @param match 监听匹配 * @param level 监听级别 */ - onScanListener(callback: (result: ScanResult) => any, key: string, match: string, level: number): void; + onScanListener(callback: ScanCallback, key: string, match?: string, level?: number): ScanListenerInfo; /** * 取消监听扫码结果 - * @param callback 监听回调 + * @param callback 监听回调,或监听key */ - offScanListener(callback: (result: ScanResult) => any): void; + offScanListener(callback: ScanCallback | string): void; /** * 获取扫码状态 - * @returns "scanning" | "closed" + * @returns ScanStatus */ - getStatus(): "scanning" | "closed"; + getStatus(): ScanStatus; /** * 关闭扫码 */ @@ -78,8 +119,15 @@ interface IScan { } +/** + * IScan 实例 + */ declare var IScan: IScan; +/** + * 将 IScan 实例挂载到 Window 对象上 + * 方便在全局使用 + */ declare interface Window { IScan: IScan; } \ No newline at end of file