react-klasha
Version:
This is an reactJS library for implementing klasha payment gateway
1 lines • 16.3 kB
JavaScript
import{__awaiter,__generator,__spreadArray}from"tslib";import{r as registerInstance,e as createEvent,i as getElement,h,H as Host}from"./index-7a8b7a1c.js";import{c as componentOnReady,n as debounce}from"./helpers-dd7e4b7b.js";import{b as getIonMode}from"./ionic-global-63a97a32.js";import{o as openURL,c as createColorClasses}from"./theme-ff3fc52f.js";var Route=function(){function e(e){registerInstance(this,e);this.ionRouteDataChanged=createEvent(this,"ionRouteDataChanged",7);this.url=""}e.prototype.onUpdate=function(e){this.ionRouteDataChanged.emit(e)};e.prototype.onComponentProps=function(e,t){if(e===t){return}var r=e?Object.keys(e):[];var n=t?Object.keys(t):[];if(r.length!==n.length){this.onUpdate(e);return}for(var a=0,o=r;a<o.length;a++){var i=o[a];if(e[i]!==t[i]){this.onUpdate(e);return}}};e.prototype.connectedCallback=function(){this.ionRouteDataChanged.emit()};Object.defineProperty(e,"watchers",{get:function(){return{url:["onUpdate"],component:["onUpdate"],componentProps:["onComponentProps"]}},enumerable:false,configurable:true});return e}();var RouteRedirect=function(){function e(e){registerInstance(this,e);this.ionRouteRedirectChanged=createEvent(this,"ionRouteRedirectChanged",7)}e.prototype.propDidChange=function(){this.ionRouteRedirectChanged.emit()};e.prototype.connectedCallback=function(){this.ionRouteRedirectChanged.emit()};Object.defineProperty(e,"watchers",{get:function(){return{from:["propDidChange"],to:["propDidChange"]}},enumerable:false,configurable:true});return e}();var ROUTER_INTENT_NONE="root";var ROUTER_INTENT_FORWARD="forward";var ROUTER_INTENT_BACK="back";var generatePath=function(e){var t=e.filter((function(e){return e.length>0})).join("/");return"/"+t};var generateUrl=function(e,t,r){var n=generatePath(e);if(t){n="#"+n}if(r!==undefined){n+="?"+r}return n};var writePath=function(e,t,r,n,a,o,i){var s=generateUrl(__spreadArray(__spreadArray([],parsePath(t).segments),n),r,i);if(a===ROUTER_INTENT_FORWARD){e.pushState(o,"",s)}else{e.replaceState(o,"",s)}};var chainToPath=function(e){var t=[];for(var r=0,n=e;r<n.length;r++){var a=n[r];for(var o=0,i=a.path;o<i.length;o++){var s=i[o];if(s[0]===":"){var u=a.params&&a.params[s.slice(1)];if(!u){return null}t.push(u)}else if(s!==""){t.push(s)}}}return t};var removePrefix=function(e,t){if(e.length>t.length){return null}if(e.length<=1&&e[0]===""){return t}for(var r=0;r<e.length;r++){if(e[r]!==t[r]){return null}}if(t.length===e.length){return[""]}return t.slice(e.length)};var readPath=function(e,t,r){var n=parsePath(t).segments;var a=r?e.hash.slice(1):e.pathname;var o=parsePath(a).segments;return removePrefix(n,o)};var parsePath=function(e){var t=[""];var r;if(e!=null){var n=e.indexOf("?");if(n>-1){r=e.substr(n+1);e=e.substr(0,n)}t=e.split("/").map((function(e){return e.trim()})).filter((function(e){return e.length>0}));if(t.length===0){t=[""]}}return{segments:t,queryString:r}};var printRoutes=function(e){console.group("[ion-core] ROUTES["+e.length+"]");var t=function(e){var t=[];e.forEach((function(e){return t.push.apply(t,e.path)}));var r=e.map((function(e){return e.id}));console.debug("%c "+generatePath(t),"font-weight: bold; padding-left: 20px","=>\t","("+r.join(", ")+")")};for(var r=0,n=e;r<n.length;r++){var a=n[r];t(a)}console.groupEnd()};var printRedirects=function(e){console.group("[ion-core] REDIRECTS["+e.length+"]");for(var t=0,r=e;t<r.length;t++){var n=r[t];if(n.to){console.debug("FROM: ","$c "+generatePath(n.from),"font-weight: bold"," TO: ","$c "+generatePath(n.to.segments),"font-weight: bold")}}console.groupEnd()};var writeNavState=function(e,t,r,n,a,o){if(a===void 0){a=false}return __awaiter(void 0,void 0,void 0,(function(){var i,s,u,h;return __generator(this,(function(c){switch(c.label){case 0:c.trys.push([0,6,,7]);i=searchNavNode(e);if(n>=t.length||!i){return[2,a]}return[4,new Promise((function(e){return componentOnReady(i,e)}))];case 1:c.sent();s=t[n];return[4,i.setRouteId(s.id,s.params,r,o)];case 2:u=c.sent();if(u.changed){r=ROUTER_INTENT_NONE;a=true}return[4,writeNavState(u.element,t,r,n+1,a,o)];case 3:a=c.sent();if(!u.markVisible)return[3,5];return[4,u.markVisible()];case 4:c.sent();c.label=5;case 5:return[2,a];case 6:h=c.sent();console.error(h);return[2,false];case 7:return[2]}}))}))};var readNavState=function(e){return __awaiter(void 0,void 0,void 0,(function(){var t,r,n,a;return __generator(this,(function(o){switch(o.label){case 0:t=[];n=e;o.label=1;case 1:if(!true)return[3,5];r=searchNavNode(n);if(!r)return[3,3];return[4,r.getRouteId()];case 2:a=o.sent();if(a){n=a.element;a.element=undefined;t.push(a)}else{return[3,5]}return[3,4];case 3:return[3,5];case 4:return[3,1];case 5:return[2,{ids:t,outlet:r}]}}))}))};var waitUntilNavNode=function(){if(searchNavNode(document.body)){return Promise.resolve()}return new Promise((function(e){window.addEventListener("ionNavWillLoad",e,{once:true})}))};var QUERY=":not([no-router]) ion-nav, :not([no-router]) ion-tabs, :not([no-router]) ion-router-outlet";var searchNavNode=function(e){if(!e){return undefined}if(e.matches(QUERY)){return e}var t=e.querySelector(QUERY);return t!==null&&t!==void 0?t:undefined};var matchesRedirect=function(e,t){var r=t.from,n=t.to;if(n===undefined){return false}if(r.length>e.length){return false}for(var a=0;a<r.length;a++){var o=r[a];if(o==="*"){return true}if(o!==e[a]){return false}}return r.length===e.length};var findRouteRedirect=function(e,t){return t.find((function(t){return matchesRedirect(e,t)}))};var matchesIDs=function(e,t){var r=Math.min(e.length,t.length);var n=0;for(;n<r;n++){if(e[n].toLowerCase()!==t[n].id){break}}return n};var matchesPath=function(e,t){var r=new RouterSegments(e);var n=false;var a;for(var o=0;o<t.length;o++){var i=t[o].path;if(i[0]===""){n=true}else{for(var s=0,u=i;s<u.length;s++){var h=u[s];var c=r.next();if(h[0]===":"){if(c===""){return null}a=a||[];var f=a[o]||(a[o]={});f[h.slice(1)]=c}else if(c!==h){return null}}n=false}}var l=n?n===(r.next()===""):true;if(!l){return null}if(a){return t.map((function(e,t){return{id:e.id,path:e.path,params:mergeParams(e.params,a[t]),beforeEnter:e.beforeEnter,beforeLeave:e.beforeLeave}}))}return t};var mergeParams=function(e,t){return e||t?Object.assign(Object.assign({},e),t):undefined};var routerIDsToChain=function(e,t){var r=null;var n=0;var a=e.map((function(e){return e.id}));for(var o=0,i=t;o<i.length;o++){var s=i[o];var u=matchesIDs(a,s);if(u>n){r=s;n=u}}if(r){return r.map((function(t,r){return{id:t.id,path:t.path,params:mergeParams(t.params,e[r]&&e[r].params)}}))}return null};var routerPathToChain=function(e,t){var r=null;var n=0;for(var a=0,o=t;a<o.length;a++){var i=o[a];var s=matchesPath(e,i);if(s!==null){var u=computePriority(s);if(u>n){n=u;r=s}}}return r};var computePriority=function(e){var t=1;var r=1;for(var n=0,a=e;n<a.length;n++){var o=a[n];for(var i=0,s=o.path;i<s.length;i++){var u=s[i];if(u[0]===":"){t+=Math.pow(1,r)}else if(u!==""){t+=Math.pow(2,r)}r++}}return t};var RouterSegments=function(){function e(e){this.path=e.slice()}e.prototype.next=function(){if(this.path.length>0){return this.path.shift()}return""};return e}();var readProp=function(e,t){if(t in e){return e[t]}if(e.hasAttribute(t)){return e.getAttribute(t)}return null};var readRedirects=function(e){return Array.from(e.children).filter((function(e){return e.tagName==="ION-ROUTE-REDIRECT"})).map((function(e){var t=readProp(e,"to");return{from:parsePath(readProp(e,"from")).segments,to:t==null?undefined:parsePath(t)}}))};var readRoutes=function(e){return flattenRouterTree(readRouteNodes(e))};var readRouteNodes=function(e){return Array.from(e.children).filter((function(e){return e.tagName==="ION-ROUTE"&&e.component})).map((function(e){var t=readProp(e,"component");return{path:parsePath(readProp(e,"url")).segments,id:t.toLowerCase(),params:e.componentProps,beforeLeave:e.beforeLeave,beforeEnter:e.beforeEnter,children:readRouteNodes(e)}}))};var flattenRouterTree=function(e){var t=[];for(var r=0,n=e;r<n.length;r++){var a=n[r];flattenNode([],t,a)}return t};var flattenNode=function(e,t,r){e=e.slice();e.push({id:r.id,path:r.path,params:r.params,beforeLeave:r.beforeLeave,beforeEnter:r.beforeEnter});if(r.children.length===0){t.push(e);return}for(var n=0,a=r.children;n<a.length;n++){var o=a[n];flattenNode(e,t,o)}};var Router=function(){function e(e){registerInstance(this,e);this.ionRouteWillChange=createEvent(this,"ionRouteWillChange",7);this.ionRouteDidChange=createEvent(this,"ionRouteDidChange",7);this.previousPath=null;this.busy=false;this.state=0;this.lastState=0;this.root="/";this.useHash=true}e.prototype.componentWillLoad=function(){return __awaiter(this,void 0,void 0,(function(){var e,t,r;return __generator(this,(function(n){switch(n.label){case 0:return[4,waitUntilNavNode()];case 1:n.sent();return[4,this.runGuards(this.getPath())];case 2:e=n.sent();if(!(e!==true))return[3,5];if(!(typeof e==="object"))return[3,4];t=e.redirect;r=parsePath(t);this.setPath(r.segments,ROUTER_INTENT_NONE,r.queryString);return[4,this.writeNavStateRoot(r.segments,ROUTER_INTENT_NONE)];case 3:n.sent();n.label=4;case 4:return[3,7];case 5:return[4,this.onRoutesChanged()];case 6:n.sent();n.label=7;case 7:return[2]}}))}))};e.prototype.componentDidLoad=function(){window.addEventListener("ionRouteRedirectChanged",debounce(this.onRedirectChanged.bind(this),10));window.addEventListener("ionRouteDataChanged",debounce(this.onRoutesChanged.bind(this),100))};e.prototype.onPopState=function(){return __awaiter(this,void 0,void 0,(function(){var e,t,r;return __generator(this,(function(n){switch(n.label){case 0:e=this.historyDirection();t=this.getPath();return[4,this.runGuards(t)];case 1:r=n.sent();if(r!==true){if(typeof r==="object"){t=parsePath(r.redirect).segments}else{return[2,false]}}return[2,this.writeNavStateRoot(t,e)]}}))}))};e.prototype.onBackButton=function(e){var t=this;e.detail.register(0,(function(e){t.back();e()}))};e.prototype.canTransition=function(){return __awaiter(this,void 0,void 0,(function(){var e;return __generator(this,(function(t){switch(t.label){case 0:return[4,this.runGuards()];case 1:e=t.sent();if(e!==true){if(typeof e==="object"){return[2,e.redirect]}else{return[2,false]}}return[2,true]}}))}))};e.prototype.push=function(e,t,r){if(t===void 0){t="forward"}return __awaiter(this,void 0,void 0,(function(){var n,a;return __generator(this,(function(o){switch(o.label){case 0:if(e.startsWith(".")){e=new URL(e,window.location.href).pathname}n=parsePath(e);return[4,this.runGuards(n.segments)];case 1:a=o.sent();if(a!==true){if(typeof a==="object"){n=parsePath(a.redirect)}else{return[2,false]}}this.setPath(n.segments,t,n.queryString);return[2,this.writeNavStateRoot(n.segments,t,r)]}}))}))};e.prototype.back=function(){window.history.back();return Promise.resolve(this.waitPromise)};e.prototype.printDebug=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){printRoutes(readRoutes(this.el));printRedirects(readRedirects(this.el));return[2]}))}))};e.prototype.navChanged=function(e){return __awaiter(this,void 0,void 0,(function(){var t,r,n,a,o,i;return __generator(this,(function(s){switch(s.label){case 0:if(this.busy){console.warn("[ion-router] router is busy, navChanged was cancelled");return[2,false]}return[4,readNavState(window.document.body)];case 1:t=s.sent(),r=t.ids,n=t.outlet;a=readRoutes(this.el);o=routerIDsToChain(r,a);if(!o){console.warn("[ion-router] no matching URL for ",r.map((function(e){return e.id})));return[2,false]}i=chainToPath(o);if(!i){console.warn("[ion-router] router could not match path because some required param is missing");return[2,false]}this.setPath(i,e);return[4,this.safeWriteNavState(n,o,ROUTER_INTENT_NONE,i,null,r.length)];case 2:s.sent();return[2,true]}}))}))};e.prototype.onRedirectChanged=function(){var e=this.getPath();if(e&&findRouteRedirect(e,readRedirects(this.el))){this.writeNavStateRoot(e,ROUTER_INTENT_NONE)}};e.prototype.onRoutesChanged=function(){return this.writeNavStateRoot(this.getPath(),ROUTER_INTENT_NONE)};e.prototype.historyDirection=function(){var e;var t=window;if(t.history.state===null){this.state++;t.history.replaceState(this.state,t.document.title,(e=t.document.location)===null||e===void 0?void 0:e.href)}var r=t.history.state;var n=this.lastState;this.lastState=r;if(r>n||r>=n&&n>0){return ROUTER_INTENT_FORWARD}if(r<n){return ROUTER_INTENT_BACK}return ROUTER_INTENT_NONE};e.prototype.writeNavStateRoot=function(e,t,r){return __awaiter(this,void 0,void 0,(function(){var n,a,o,i,s,u,h,c;return __generator(this,(function(f){if(!e){console.error("[ion-router] URL is not part of the routing set");return[2,false]}n=readRedirects(this.el);a=findRouteRedirect(e,n);o=null;if(a){i=a.to,s=i.segments,u=i.queryString;this.setPath(s,t,u);o=a.from;e=s}h=readRoutes(this.el);c=routerPathToChain(e,h);if(!c){console.error("[ion-router] the path does not match any route");return[2,false]}return[2,this.safeWriteNavState(document.body,c,t,e,o,0,r)]}))}))};e.prototype.safeWriteNavState=function(e,t,r,n,a,o,i){if(o===void 0){o=0}return __awaiter(this,void 0,void 0,(function(){var s,u,h;return __generator(this,(function(c){switch(c.label){case 0:return[4,this.lock()];case 1:s=c.sent();u=false;c.label=2;case 2:c.trys.push([2,4,,5]);return[4,this.writeNavState(e,t,r,n,a,o,i)];case 3:u=c.sent();return[3,5];case 4:h=c.sent();console.error(h);return[3,5];case 5:s();return[2,u]}}))}))};e.prototype.lock=function(){return __awaiter(this,void 0,void 0,(function(){var e,t;return __generator(this,(function(r){switch(r.label){case 0:e=this.waitPromise;this.waitPromise=new Promise((function(e){return t=e}));if(!(e!==undefined))return[3,2];return[4,e];case 1:r.sent();r.label=2;case 2:return[2,t]}}))}))};e.prototype.runGuards=function(e,t){if(e===void 0){e=this.getPath()}return __awaiter(this,void 0,void 0,(function(){var r,n,a,o,i,s,u;return __generator(this,(function(h){switch(h.label){case 0:if(t===undefined){t=parsePath(this.previousPath).segments}if(!e||!t){return[2,true]}r=readRoutes(this.el);n=routerPathToChain(t,r);a=n&&n[n.length-1].beforeLeave;if(!a)return[3,2];return[4,a()];case 1:i=h.sent();return[3,3];case 2:i=true;h.label=3;case 3:o=i;if(o===false||typeof o==="object"){return[2,o]}s=routerPathToChain(e,r);u=s&&s[s.length-1].beforeEnter;return[2,u?u():true]}}))}))};e.prototype.writeNavState=function(e,t,r,n,a,o,i){if(o===void 0){o=0}return __awaiter(this,void 0,void 0,(function(){var s,u;return __generator(this,(function(h){switch(h.label){case 0:if(this.busy){console.warn("[ion-router] router is busy, transition was cancelled");return[2,false]}this.busy=true;s=this.routeChangeEvent(n,a);if(s){this.ionRouteWillChange.emit(s)}return[4,writeNavState(e,t,r,o,false,i)];case 1:u=h.sent();this.busy=false;if(s){this.ionRouteDidChange.emit(s)}return[2,u]}}))}))};e.prototype.setPath=function(e,t,r){this.state++;writePath(window.history,this.root,this.useHash,e,t,this.state,r)};e.prototype.getPath=function(){return readPath(window.location,this.root,this.useHash)};e.prototype.routeChangeEvent=function(e,t){var r=this.previousPath;var n=generatePath(e);this.previousPath=n;if(n===r){return null}var a=t?generatePath(t):null;return{from:r,redirectedFrom:a,to:n}};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});return e}();var routerLinkCss=":host{--background:transparent;--color:var(--ion-color-primary, #3880ff);background:var(--background);color:var(--color)}:host(.ion-color){color:var(--ion-color-base)}a{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;letter-spacing:inherit;text-decoration:inherit;text-indent:inherit;text-overflow:inherit;text-transform:inherit;text-align:inherit;white-space:inherit;color:inherit}";var RouterLink=function(){function e(e){var t=this;registerInstance(this,e);this.routerDirection="forward";this.onClick=function(e){openURL(t.href,e,t.routerDirection,t.routerAnimation)}}e.prototype.render=function(){var e;var t=getIonMode(this);var r={href:this.href,rel:this.rel,target:this.target};return h(Host,{onClick:this.onClick,class:createColorClasses(this.color,(e={},e[t]=true,e["ion-activatable"]=true,e))},h("a",Object.assign({},r),h("slot",null)))};return e}();RouterLink.style=routerLinkCss;export{Route as ion_route,RouteRedirect as ion_route_redirect,Router as ion_router,RouterLink as ion_router_link};