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 • 15.1 kB
JavaScript
var _excluded=["children","successCb","failureCb","loadingCb","successMsg","failureMsg"];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 _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)}function _regeneratorRuntime(){"use strict";function b(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function f(b,d,e,f){var g=d&&d.prototype instanceof k?d:k,h=Object.create(g.prototype),a=new B(f||[]);return E(h,"_invoke",{value:w(b,e,a)}),h}function j(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function k(){}function l(){}function m(){}function q(a){["next","throw","return"].forEach(function(c){b(a,c,function(a){return this._invoke(c,a)})})}function s(b,d){function c(e,f,g,i){var a=j(b[e],b,f);if("throw"!==a.type){var k=a.arg,l=k.value;return l&&"object"==_typeof(l)&&t.call(l,"__await")?d.resolve(l.__await).then(function(a){c("next",a,g,i)},function(a){c("throw",a,g,i)}):d.resolve(l).then(function(a){k.value=a,g(k)},function(a){return c("throw",a,g,i)})}i(a.arg)}var e;E(this,"_invoke",{value:function(a,b){function f(){return new d(function(d,e){c(a,b,d,e)})}return e=e?e.then(f,f):f()}})}function w(a,b,d){var e="suspendedStart";return function(f,g){if(e==="executing")throw Error("Generator is already running");if("completed"===e){if("throw"===f)throw g;return{value:D,done:!0}}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var i=x(h,d);if(i){if(i===G)continue;return i}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"===e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=j(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===G)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}function x(b,c){var d=c.method,e=b.iterator[d];if(e===D)return c.delegate=null,"throw"===d&&b.iterator["return"]&&(c.method="return",c.arg=D,x(b,c),"throw"===c.method)||"return"!==d&&(c.method="throw",c.arg=new TypeError("The iterator does not provide a '"+d+"' method")),G;var f=j(e,b.iterator,c.arg);if("throw"===f.type)return c.method="throw",c.arg=f.arg,c.delegate=null,G;var g=f.arg;return g?g.done?(c[b.resultName]=g.value,c.next=b.nextLoc,"return"!==c.method&&(c.method="next",c.arg=D),c.delegate=null,G):g:(c.method="throw",c.arg=new TypeError("iterator result is not an object"),c.delegate=null,G)}function z(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function A(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function B(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(z,this),this.reset(!0)}function C(a){if(a||""===a){var b=a[F];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(t.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=D,b.done=!0,b};return d.next=d}}throw new TypeError(_typeof(a)+" is not iterable")}_regeneratorRuntime=function(){return h};var D,h={},e=Object.prototype,t=e.hasOwnProperty,E=Object.defineProperty||function(a,b,c){a[b]=c.value},n="function"==typeof Symbol?Symbol:{},F=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",c=n.toStringTag||"@@toStringTag";try{b({},"")}catch(a){b=function(a,b,c){return a[b]=c}}h.wrap=f;var G={},i={};b(i,F,function(){return this});var o=Object.getPrototypeOf,d=o&&o(o(C([])));d&&d!==e&&t.call(d,F)&&(i=d);var r=m.prototype=k.prototype=Object.create(i);return l.prototype=m,E(r,"constructor",{value:m,configurable:!0}),E(m,"constructor",{value:l,configurable:!0}),l.displayName=b(m,c,"GeneratorFunction"),h.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===l||"GeneratorFunction"===(b.displayName||b.name))},h.mark=function(a){return Object.setPrototypeOf?Object.setPrototypeOf(a,m):(a.__proto__=m,b(a,c,"GeneratorFunction")),a.prototype=Object.create(r),a},h.awrap=function(a){return{__await:a}},q(s.prototype),b(s.prototype,a,function(){return this}),h.AsyncIterator=s,h.async=function(b,c,d,e,g){void 0===g&&(g=Promise);var j=new s(f(b,c,d,e),g);return h.isGeneratorFunction(c)?j:j.next().then(function(a){return a.done?a.value:j.next()})},q(r),b(r,c,"Generator"),b(r,F,function(){return this}),b(r,"toString",function(){return"[object Generator]"}),h.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function a(){for(;c.length;){var d=c.pop();if(d in b)return a.value=d,a.done=!1,a}return a.done=!0,a}},h.values=C,B.prototype={constructor:B,reset:function(a){if(this.prev=0,this.next=0,this.sent=this._sent=D,this.done=!1,this.delegate=null,this.method="next",this.arg=D,this.tryEntries.forEach(A),!a)for(var b in this)"t"===b.charAt(0)&&t.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=D)},stop:function(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function(b){function d(a,c){return h.type="throw",h.arg=b,e.next=a,c&&(e.method="next",e.arg=D),!!c}if(this.done)throw b;for(var e=this,f=this.tryEntries.length-1;0<=f;--f){var g=this.tryEntries[f],h=g.completion;if("root"===g.tryLoc)return d("end");if(g.tryLoc<=this.prev){var j=t.call(g,"catchLoc"),k=t.call(g,"finallyLoc");if(j&&k){if(this.prev<g.catchLoc)return d(g.catchLoc,!0);if(this.prev<g.finallyLoc)return d(g.finallyLoc)}else if(!j){if(!k)throw Error("try statement without catch or finally");if(this.prev<g.finallyLoc)return d(g.finallyLoc)}else if(this.prev<g.catchLoc)return d(g.catchLoc,!0)}}},abrupt:function(b,c){for(var d,e=this.tryEntries.length-1;0<=e;--e)if(d=this.tryEntries[e],d.tryLoc<=this.prev&&t.call(d,"finallyLoc")&&this.prev<d.finallyLoc){var f=d;break}f&&("break"===b||"continue"===b)&&f.tryLoc<=c&&c<=f.finallyLoc&&(f=null);var g=f?f.completion:{};return g.type=b,g.arg=c,f?(this.method="next",this.next=f.finallyLoc,G):this.complete(g)},complete:function(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),G},finish:function(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),A(b),G},catch:function(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var f=d.arg;A(b)}return f}throw Error("illegal catch attempt")},delegateYield:function(a,b,c){return this.delegate={iterator:C(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=D),G}},h}function asyncGeneratorStep(b,d,f,e,g,h,a){try{var c=b[h](a),i=c.value}catch(a){return void f(a)}c.done?d(i):Promise.resolve(i).then(e,g)}function _asyncToGenerator(b){return function(){var c=this,d=arguments;return new Promise(function(e,f){function g(a){asyncGeneratorStep(i,e,f,g,h,"next",a)}function h(a){asyncGeneratorStep(i,e,f,g,h,"throw",a)}var i=b.apply(c,d);g(void 0)})}}import React,{useEffect}from"react";import{handleSuccess,handleError,handleLoading}from"../services/handlerService";import Wrapper from"../Wrapper/Wrapper";import dependentJsService from"../services/dependentJsService";var failureMsgDefault={unSupported:"LocationMe is not supporting in your device",permissionDenied:"Permission Denied",googleAPIKeyMissing:"Google Key is missing",unableToLoadGoogleAPI:"Unable to load google api script",browserPermissionAPIFailed:"Unable to check browser permission",invalidLatLng:"Invalid Lat lng",error:""},isBrowserSupport=function(){var a,b,c;return(null===(a=globalThis.navigator)||void 0===a?void 0:a.geolocation)&&(null===(b=globalThis.navigator)||void 0===b||null===(b=b.permissions)||void 0===b?void 0:b.query)&&(null===(c=globalThis.navigator)||void 0===c||null===(c=c.geolocation)||void 0===c?void 0:c.getCurrentPosition)},checkPermitByBrowser=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function c(a,b){var d;return _regeneratorRuntime().wrap(function e(c){for(;1;)switch(c.prev=c.next){case 0:return c.prev=0,c.next=3,navigator.permissions.query({name:"geolocation"});case 3:if(d=c.sent,"denied"!==d.state){c.next=6;break}return c.abrupt("return",handleError({msgType:"PERMISSION_DENIED",msg:a.permissionDenied,failureCb:b}));case 6:c.next=11;break;case 8:return c.prev=8,c.t0=c["catch"](0),c.abrupt("return",handleError({msgType:"BROWSER_PERMISION_API_FAILED",msg:a.browserPermissionAPIFailed,failureCb:b}));case 11:return c.abrupt("return",!0);case 12:case"end":return c.stop()}},c,null,[[0,8]])}));return function d(b,c){return a.apply(this,arguments)}}(),checkScriptInBrowser=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function e(a,b,c,d){var f;return _regeneratorRuntime().wrap(function g(e){for(;1;)switch(e.prev=e.next){case 0:if(d){e.next=2;break}return e.abrupt("return",handleError({msgType:"GOOGLE_API_KEY_MISSING",msg:a.googleAPIKeyMissing,failureCb:b}));case 2:return f="https://maps.googleapis.com/maps/api/js?".concat(c?"client":"key","=").concat(d,"&libraries=places&loading=async"),e.prev=3,e.next=6,dependentJsService(f,"googleMapLocationAPI",!0);case 6:return e.abrupt("return",!0);case 9:return e.prev=9,e.t0=e["catch"](3),e.abrupt("return",handleError({msgType:"UNABLE_TO_LOAD_GOOGLE_APIS",msg:a.unableToLoadGoogleAPI,failureCb:b}));case 12:case"end":return e.stop()}},e,null,[[3,9]])}));return function f(b,c,d,e){return a.apply(this,arguments)}}(),getPincode=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function e(a,b,c,d){var f,g,h,j,k,l,m;return _regeneratorRuntime().wrap(function i(e){for(;1;)switch(e.prev=e.next){case 0:return e.prev=0,f=new google.maps.Geocoder,g=new google.maps.LatLng(a,b),e.next=5,f.geocode({latLng:g});case 5:if(h=e.sent,j=h.results,!j[0]){e.next=12;break}for(k=j[0].address_components,l="",m=0;m<k.length;m++)k[m].types.includes("postal_code")&&(l=k[m].short_name);return e.abrupt("return",l);case 12:e.next=17;break;case 14:return e.prev=14,e.t0=e["catch"](0),e.abrupt("return",handleError({msgType:"INVALID_LAT_LNG",msg:d.invalidLatLng,failureCb:c}));case 17:return e.abrupt("return","");case 18:case"end":return e.stop()}},e,null,[[0,14]])}));return function f(b,c,d,e){return a.apply(this,arguments)}}(),onSuccss=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function f(a,b,c,d,e){var g;return _regeneratorRuntime().wrap(function h(f){for(;1;)switch(f.prev=f.next){case 0:return f.next=2,getPincode(e.coords.latitude,e.coords.longitude,b,d);case 2:g=f.sent,handleSuccess({msgType:"SUCCESSFUL",msg:c,successCb:a,data:g});case 4:case"end":return f.stop()}},f)}));return function g(b,c,d,e,f){return a.apply(this,arguments)}}(),onFailure=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function d(a,b,c){return _regeneratorRuntime().wrap(function e(d){for(;1;)switch(d.prev=d.next){case 0:return d.abrupt("return",handleError({msgType:"ERROR",msg:c.error||b||"Error occured",failureCb:a}));case 1:case"end":return d.stop()}},d)}));return function e(b,c,d){return a.apply(this,arguments)}}(),locateMe=function a(){var b=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},c=b.successCb,d=void 0===c?function(){}:c,e=b.failureCb,f=void 0===e?function(){}:e,g=b.loadingCb,h=void 0===g?function(){}:g,i=b.successMsg,j=void 0===i?"Located Successfully!!":i,k=b.failureMsg,l=void 0===k?_objectSpread({},failureMsgDefault):k,m=b.isProdKey,n=!(void 0!==m)||m,o=b.googleKey,p=void 0===o?"":o,q=_objectSpread(_objectSpread({},failureMsgDefault),l),r=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark(function a(){var b,c;return _regeneratorRuntime().wrap(function e(a){for(;1;)switch(a.prev=a.next){case 0:if(!isBrowserSupport()){a.next=11;break}return handleLoading({loadingCb:h}),a.next=4,checkPermitByBrowser(q,f);case 4:return b=a.sent,a.next=7,checkScriptInBrowser(q,f,n,p);case 7:c=a.sent,b&&c&&navigator.geolocation.getCurrentPosition(function(a){onSuccss(d,f,j,q,a)},function(a){onFailure(f,a,q)}),a.next=12;break;case 11:return a.abrupt("return",handleError({msgType:"UN_SUPPORTED_FEATURE",msg:q.unSupported,failureCb:f}));case 12:return a.abrupt("return",!0);case 13:case"end":return a.stop()}},a)}));return function b(){return a.apply(this,arguments)}}();r()};function LocateMe(a){var b=a.children,c=a.successCb,d=a.failureCb,e=a.loadingCb,f=a.successMsg,g=a.failureMsg,h=_objectWithoutProperties(a,_excluded);return useEffect(function(){globalThis.console.error=function(){for(var a,b=arguments.length,c=Array(b),e=0;e<b;e++)c[e]=arguments[e];if(c[0]&&-1!==(null===(a=c[0])||void 0===a?void 0:a.indexOf("https://developers.google.com/maps/documentation/javascript/error-messages"))){var f=c[0].split("\nhttps://developers.google.com/maps/documentation/javascript/error-messages")[0];return handleError({msgType:"ERROR",msg:f,failureCb:d})}return!0}},[]),React.Children.map(b||"LocateMe",function(a){return React.cloneElement("string"==typeof a?React.createElement("span",null,a):a,{onClick:function a(){return locateMe(_objectSpread({successCb:c,failureCb:d,loadingCb:e,successMsg:f,failureMsg:g},h))}})})}var WLocateMe=Wrapper(LocateMe,isBrowserSupport);export{locateMe,WLocateMe as LocateMe};export default WLocateMe;