fe-pilot
Version:
scanner in web, phonebook in web, autofill otp in web, share web, TextToSpeech in web, Voice Recognition in web, live location tracking in web, detect my location web, wakelock in web, color picker, WhatsappShare, SnapScanner, NetworkMonitor, View360
1 lines • 4.95 kB
JavaScript
var _excluded=["children","successCb","failureCb","loadingCb","successMsg","failureMsg","via","zIndex","color","top","bottom","left","right","position"];function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _extends(){return _extends=Object.assign?Object.assign.bind():function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)({}).hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},_extends.apply(null,arguments)}function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],-1===b.indexOf(c)&&{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(-1!==b.indexOf(d))continue;c[d]=a[d]}return c}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!=_typeof(a)||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}import React from"react";import{handleSuccess,handleError,handleLoading}from"../services/handlerService";import Wrapper from"../Wrapper/Wrapper";var failureMsgDefault={unSupported:"SnapScanner is not supporting in your device",invalidImage:"Invalid Images",error:""},isBrowserSupport=function(){return"BarcodeDetector"in globalThis},snapScanner=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},b=a.successCb,c=void 0===b?function(){}:b,d=a.failureCb,e=void 0===d?function(){}:d,f=a.loadingCb,g=void 0===f?function(){}:f,h=a.successMsg,i=void 0===h?"Successfully!!":h,j=a.failureMsg,k=void 0===j?_objectSpread({},failureMsgDefault):j,l=a.event,m=_objectSpread(_objectSpread({},failureMsgDefault),k);(function(){if(isBrowserSupport()){handleLoading({loadingCb:g});var a=l.target.files[0],b=globalThis.BarcodeDetector,d=new b;createImageBitmap(a).then(function(a){return d.detect(a)}).then(function(a){var b=a[0];if(b)handleSuccess({msgType:"SUCCESSFUL",msg:i,successCb:c,data:{barCodeValue:b.rawValue,barCodeType:b.format}});else return handleError({msgType:"INVALID_IMAGE",msg:m.invalidImage,failureCb:e});return!0})["catch"](function(a){return handleError({msgType:"ERROR",msg:m.error||a.message||"Unable to scan",failureCb:e})})}else return handleError({msgType:"UN_SUPPORTED_FEATURE",msg:m.unSupported,failureCb:e});return!0})()},processBy=function(a){var b={};return"gallery"===a&&(b.accept="image/*"),"camera"===a&&(b.accept="*",b.capture="filesystem"),"phone"===a&&(b.accept="image/png,image/jpeg",b.capture="filesystem"),b};function SnapScanner(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},b=a.children,c=a.successCb,d=a.failureCb,e=a.loadingCb,f=a.successMsg,g=a.failureMsg,h=a.via,i=void 0===h?"gallery":h,j=a.zIndex,k=void 0===j?9:j,l=a.color,m=void 0===l?"white":l,n=a.top,o=void 0===n?"auto":n,p=a.bottom,q=void 0===p?"18%":p,r=a.left,s=void 0===r?"auto":r,t=a.right,u=void 0===t?"64%":t,v=a.position,w=void 0===v?"absolute":v,x=_objectWithoutProperties(a,_excluded);return React.createElement("label",{htmlFor:"fe-pilot-scanner-imgp-".concat(i),style:{top:o,bottom:q,left:s,right:u,zIndex:k,color:m,position:w}},b||"Gallery",React.createElement("input",_extends({id:"fe-pilot-scanner-imgp-".concat(i),type:"file"},processBy(i),{onChange:function(a){return snapScanner(_objectSpread({successCb:c,failureCb:d,loadingCb:e,successMsg:f,failureMsg:g,event:a},x))},onSelect:function(a){return snapScanner(_objectSpread({successCb:c,failureCb:d,loadingCb:e,successMsg:f,failureMsg:g,event:a},x))},style:{display:"none"}})))}var WSnapScanner=Wrapper(SnapScanner,isBrowserSupport);export{snapScanner,WSnapScanner as SnapScanner};export default WSnapScanner;