UNPKG

open-in-app-akshita

Version:

open-in-app-akshita is a lightweight React component that enables seamless deep linking to your mobile app. If the app is not installed, the component smartly redirects users to the Play Store (Android) or App Store (iOS).

31 lines (28 loc) 14.1 kB
(function(_,R){typeof exports=="object"&&typeof module<"u"?module.exports=R(require("react")):typeof define=="function"&&define.amd?define(["react"],R):(_=typeof globalThis<"u"?globalThis:_||self,_.OpenInApp=R(_.React))})(this,function(_){"use strict";var R={exports:{}},D={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Z;function Se(){if(Z)return D;Z=1;var I=_,T=Symbol.for("react.element"),W=Symbol.for("react.fragment"),b=Object.prototype.hasOwnProperty,O=I.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,j={key:!0,ref:!0,__self:!0,__source:!0};function w(g,l,E){var p,y={},P=null,L=null;E!==void 0&&(P=""+E),l.key!==void 0&&(P=""+l.key),l.ref!==void 0&&(L=l.ref);for(p in l)b.call(l,p)&&!j.hasOwnProperty(p)&&(y[p]=l[p]);if(g&&g.defaultProps)for(p in l=g.defaultProps,l)y[p]===void 0&&(y[p]=l[p]);return{$$typeof:T,type:g,key:P,ref:L,props:y,_owner:O.current}}return D.Fragment=W,D.jsx=w,D.jsxs=w,D}var F={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Q;function Ce(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&function(){var I=_,T=Symbol.for("react.element"),W=Symbol.for("react.portal"),b=Symbol.for("react.fragment"),O=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),w=Symbol.for("react.provider"),g=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),E=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),L=Symbol.for("react.offscreen"),re=Symbol.iterator,ke="@@iterator";function Ae(e){if(e===null||typeof e!="object")return null;var r=re&&e[re]||e[ke];return typeof r=="function"?r:null}var x=I.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function c(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];De("error",e,t)}}function De(e,r,t){{var n=x.ReactDebugCurrentFrame,o=n.getStackAddendum();o!==""&&(r+="%s",t=t.concat([o]));var u=t.map(function(i){return String(i)});u.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,u)}}var Fe=!1,Ie=!1,We=!1,Ye=!1,$e=!1,te;te=Symbol.for("react.module.reference");function Le(e){return!!(typeof e=="string"||typeof e=="function"||e===b||e===j||$e||e===O||e===E||e===p||Ye||e===L||Fe||Ie||We||typeof e=="object"&&e!==null&&(e.$$typeof===P||e.$$typeof===y||e.$$typeof===w||e.$$typeof===g||e.$$typeof===l||e.$$typeof===te||e.getModuleId!==void 0))}function Ue(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return o!==""?t+"("+o+")":t}function ne(e){return e.displayName||"Context"}function m(e){if(e==null)return null;if(typeof e.tag=="number"&&c("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case b:return"Fragment";case W:return"Portal";case j:return"Profiler";case O:return"StrictMode";case E:return"Suspense";case p:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case g:var r=e;return ne(r)+".Consumer";case w:var t=e;return ne(t._context)+".Provider";case l:return Ue(e,e.render,"ForwardRef");case y:var n=e.displayName||null;return n!==null?n:m(e.type)||"Memo";case P:{var o=e,u=o._payload,i=o._init;try{return m(i(u))}catch{return null}}}return null}var S=Object.assign,Y=0,ae,ie,oe,ue,se,fe,le;function ce(){}ce.__reactDisabledLog=!0;function Ve(){{if(Y===0){ae=console.log,ie=console.info,oe=console.warn,ue=console.error,se=console.group,fe=console.groupCollapsed,le=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ce,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}Y++}}function Me(){{if(Y--,Y===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:S({},e,{value:ae}),info:S({},e,{value:ie}),warn:S({},e,{value:oe}),error:S({},e,{value:ue}),group:S({},e,{value:se}),groupCollapsed:S({},e,{value:fe}),groupEnd:S({},e,{value:le})})}Y<0&&c("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var J=x.ReactCurrentDispatcher,B;function U(e,r,t){{if(B===void 0)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);B=n&&n[1]||""}return` `+B+e}}var q=!1,V;{var Ne=typeof WeakMap=="function"?WeakMap:Map;V=new Ne}function de(e,r){if(!e||q)return"";{var t=V.get(e);if(t!==void 0)return t}var n;q=!0;var o=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var u;u=J.current,J.current=null,Ve();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(v){n=v}Reflect.construct(e,[],i)}else{try{i.call()}catch(v){n=v}e.call(i.prototype)}}else{try{throw Error()}catch(v){n=v}e()}}catch(v){if(v&&n&&typeof v.stack=="string"){for(var a=v.stack.split(` `),d=n.stack.split(` `),s=a.length-1,f=d.length-1;s>=1&&f>=0&&a[s]!==d[f];)f--;for(;s>=1&&f>=0;s--,f--)if(a[s]!==d[f]){if(s!==1||f!==1)do if(s--,f--,f<0||a[s]!==d[f]){var h=` `+a[s].replace(" at new "," at ");return e.displayName&&h.includes("<anonymous>")&&(h=h.replace("<anonymous>",e.displayName)),typeof e=="function"&&V.set(e,h),h}while(s>=1&&f>=0);break}}}finally{q=!1,J.current=u,Me(),Error.prepareStackTrace=o}var A=e?e.displayName||e.name:"",C=A?U(A):"";return typeof e=="function"&&V.set(e,C),C}function Je(e,r,t){return de(e,!1)}function Be(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function M(e,r,t){if(e==null)return"";if(typeof e=="function")return de(e,Be(e));if(typeof e=="string")return U(e);switch(e){case E:return U("Suspense");case p:return U("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case l:return Je(e.render);case y:return M(e.type,r,t);case P:{var n=e,o=n._payload,u=n._init;try{return M(u(o),r,t)}catch{}}}return""}var $=Object.prototype.hasOwnProperty,ve={},pe=x.ReactDebugCurrentFrame;function N(e){if(e){var r=e._owner,t=M(e.type,e._source,r?r.type:null);pe.setExtraStackFrame(t)}else pe.setExtraStackFrame(null)}function qe(e,r,t,n,o){{var u=Function.call.bind($);for(var i in e)if(u(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var d=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw d.name="Invariant Violation",d}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(s){a=s}a&&!(a instanceof Error)&&(N(o),c("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof a),N(null)),a instanceof Error&&!(a.message in ve)&&(ve[a.message]=!0,N(o),c("Failed %s type: %s",t,a.message),N(null))}}}var Ke=Array.isArray;function K(e){return Ke(e)}function Ge(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function ze(e){try{return he(e),!1}catch{return!0}}function he(e){return""+e}function ge(e){if(ze(e))return c("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ge(e)),he(e)}var be=x.ReactCurrentOwner,Xe={key:!0,ref:!0,__self:!0,__source:!0},Ee,ye;function He(e){if($.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function Ze(e){if($.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function Qe(e,r){typeof e.ref=="string"&&be.current}function er(e,r){{var t=function(){Ee||(Ee=!0,c("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function rr(e,r){{var t=function(){ye||(ye=!0,c("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var tr=function(e,r,t,n,o,u,i){var a={$$typeof:T,type:e,key:r,ref:t,props:i,_owner:u};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function nr(e,r,t,n,o){{var u,i={},a=null,d=null;t!==void 0&&(ge(t),a=""+t),Ze(r)&&(ge(r.key),a=""+r.key),He(r)&&(d=r.ref,Qe(r,o));for(u in r)$.call(r,u)&&!Xe.hasOwnProperty(u)&&(i[u]=r[u]);if(e&&e.defaultProps){var s=e.defaultProps;for(u in s)i[u]===void 0&&(i[u]=s[u])}if(a||d){var f=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&er(i,f),d&&rr(i,f)}return tr(e,a,d,o,n,be.current,i)}}var G=x.ReactCurrentOwner,_e=x.ReactDebugCurrentFrame;function k(e){if(e){var r=e._owner,t=M(e.type,e._source,r?r.type:null);_e.setExtraStackFrame(t)}else _e.setExtraStackFrame(null)}var z;z=!1;function X(e){return typeof e=="object"&&e!==null&&e.$$typeof===T}function Re(){{if(G.current){var e=m(G.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function ar(e){return""}var me={};function ir(e){{var r=Re();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=` Check the top-level render call using <`+t+">.")}return r}}function Te(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=ir(r);if(me[t])return;me[t]=!0;var n="";e&&e._owner&&e._owner!==G.current&&(n=" It was passed a child from "+m(e._owner.type)+"."),k(e),c('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),k(null)}}function Oe(e,r){{if(typeof e!="object")return;if(K(e))for(var t=0;t<e.length;t++){var n=e[t];X(n)&&Te(n,r)}else if(X(e))e._store&&(e._store.validated=!0);else if(e){var o=Ae(e);if(typeof o=="function"&&o!==e.entries)for(var u=o.call(e),i;!(i=u.next()).done;)X(i.value)&&Te(i.value,r)}}}function or(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===l||r.$$typeof===y))t=r.propTypes;else return;if(t){var n=m(r);qe(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!z){z=!0;var o=m(r);c("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",o||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&c("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ur(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){k(e),c("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),k(null);break}}e.ref!==null&&(k(e),c("Invalid attribute `ref` supplied to `React.Fragment`."),k(null))}}var we={};function Pe(e,r,t,n,o,u){{var i=Le(e);if(!i){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var d=ar();d?a+=d:a+=Re();var s;e===null?s="null":K(e)?s="array":e!==void 0&&e.$$typeof===T?(s="<"+(m(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):s=typeof e,c("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",s,a)}var f=nr(e,r,t,o,u);if(f==null)return f;if(i){var h=r.children;if(h!==void 0)if(n)if(K(h)){for(var A=0;A<h.length;A++)Oe(h[A],e);Object.freeze&&Object.freeze(h)}else c("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Oe(h,e)}if($.call(r,"key")){var C=m(e),v=Object.keys(r).filter(function(vr){return vr!=="key"}),H=v.length>0?"{key: someKey, "+v.join(": ..., ")+": ...}":"{key: someKey}";if(!we[C+H]){var dr=v.length>0?"{"+v.join(": ..., ")+": ...}":"{}";c(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,H,C,dr,C),we[C+H]=!0}}return e===b?ur(f):or(f),f}}function sr(e,r,t){return Pe(e,r,t,!0)}function fr(e,r,t){return Pe(e,r,t,!1)}var lr=fr,cr=sr;F.Fragment=b,F.jsx=lr,F.jsxs=cr}()),F}var ee;function je(){return ee||(ee=1,process.env.NODE_ENV==="production"?R.exports=Se():R.exports=Ce()),R.exports}var xe=je();return({deepLink:I,fallbackPlayStore:T,fallbackAppStore:W,delay:b=2e3,autoRedirect:O=!1,buttonText:j="Open in App"})=>{const w=/iPhone|iPad|iPod/i.test(navigator.userAgent),g=()=>{const l=Date.now();window.location.href=I,setTimeout(()=>{const E=w?W:T;Date.now()-l>=b&&E&&window.open(E,"_blank","noopener,noreferrer")},b)};return _.useEffect(()=>{O&&g()},[]),O?null:xe.jsx("button",{onClick:g,children:j})}});