@apiteam/twa-bridge 7.1.1 → 7.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/solid/index.d.ts +2 -657
- package/solid/index.js +491 -1
- package/solid/index.mjs +502 -1
- package/react/index.d.ts +0 -1048
- package/react/index.js +0 -1
- package/react/index.mjs +0 -1
- package/react/package.json +0 -17
package/solid/index.mjs
CHANGED
|
@@ -1 +1,502 @@
|
|
|
1
|
-
import{createSignal as e,onMount as t,onCleanup as s,createContext as a}from"solid-js";import{createStore as r}from"solid-js/store";const o=()=>{const[a,r]=e({height:0,is_expanded:!1,is_state_stable:!1}),o=e=>r(e);return t((()=>{bt(ut,o),qe(je)})),s((()=>{lt(ut,o)})),a},i="web",n="phone",_="desktop",p=()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(t)?n:["tdesktop","macos"].includes(t)?_:i},d="not_supported",u=(e,t)=>{const s=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(s?.replace(".",""))>=Number(String(e)?.replace(".",""))&&-1!==t.indexOf(p())},c=()=>Math.random().toString(36).substring(3,9),g=e=>{var t;if(t=/^\s*#([0-9a-f]{6})\s*$/i.exec(e+=""))return"#"+t[1].toLowerCase();if(t=/^\s*#([0-9a-f])([0-9a-f])([0-9a-f])\s*$/i.exec(e))return("#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]).toLowerCase();if(t=/^\s*rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)\s*$/.exec(e)){var s=parseInt(t[1]),a=parseInt(t[2]),r=parseInt(t[3]);return"#"+((s<16?"0":"")+s.toString(16))+((a<16?"0":"")+a.toString(16))+((r<16?"0":"")+r.toString(16))}return!1},b=e=>{"#1c1c1d"==e.bg_color&&e.bg_color==e.secondary_bg_color&&(e.secondary_bg_color="#2c2c2e");const t=window.location.hash.slice(1),s=new URLSearchParams(t);var a=JSON.parse(s.get("tgWebAppThemeParams")??"");for(var r of Object.keys(e)){var o=g(e[r]);"string"==typeof o&&(a[r]=o)}return a},l=e=>w()?(qe(Ie,e),{status:!0}):(Se(Ie,1),{status:d}),w=()=>u(0,[i,_,n]),m=e=>h()?(qe(Re,e),{status:!0}):(Se(Re,1),{status:d}),h=()=>u(6.4,[n]),v=e=>f()?(qe(Te,e),{status:!0}):(Se(Te,1),{status:d}),f=()=>u(0,[i,_,n]),S=e=>y()?(qe(Ne,e),{status:!0}):(Se(Ne,1),{status:d}),y=()=>u(0,[n]),q=e=>x()?(qe(Ce,e),{status:!0}):(Se(Ce,1),{status:d}),x=()=>u(0,[i]),P=()=>k()?(qe(Ce),{status:!0}):(Se(Ce,1),{status:d}),k=()=>u(0,[i]),O=async e=>I()?(void 0===e.req_id&&(e.req_id=c()),qe(xe,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),lt(et,a))};bt(et,a)}))):(Se(xe,1),{status:d}),I=()=>u(6.9,[i,_,n]),R=e=>T()?(qe(Ee,e),{status:!0}):(Se(Ee,1),{status:d}),T=()=>u(6.1,[i,_,n]),N=e=>C()?(qe(Le,e),{status:!0}):(Se(Le,1),{status:d}),C=()=>u(6.4,[i,_,n]),B=async e=>E()?(e.title.length>64&&Se(We,3),e.message.length<1&&Se(We,4),e.message.length>256&&Se(We,5),e.buttons.length<1&&Se(We,6),e.buttons.length>3&&Se(We,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&Se(We,8),qe(We,e),new Promise(((t,s)=>{const a=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),lt(rt,a)};bt(rt,a)}))):(Se(We,1),{status:d}),E=()=>u(6.2,[i,_,n]),L=async e=>W()?(qe(Pe,e),new Promise(((t,s)=>{wt(it,(s=>{e.is_close&&m(),t({status:!0,data:s})})),wt(nt,(()=>{t({status:"closed"})}))}))):(Se(Pe,1),{status:d}),W=()=>u(6.4,[n]),D=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),J()?(qe(De,e),{status:!0}):(Se(De,1),{status:d})),J=()=>u(7,[i,_,n]),$=async e=>j()?(e||(e={req_id:void 0}),void 0===e.req_id&&(e.req_id=c()),qe(ke,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e?.req_id&&(t({status:!0,data:s}),lt(Ze,a))};bt(Ze,a)}))):(Se(ke,1),{status:d}),j=()=>u(6.4,[i,_,n]),M=e=>A()?(qe(Je,e),{status:!0}):(Se(Je,1),{status:d}),A=()=>u(6.9,[i,_,n]),G=async()=>U()?(qe(Oe),new Promise(((e,t)=>{wt(at,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(Se(Oe,1),{status:d}),U=()=>u(6.9,[i,_,n]),V=e=>H()?(qe($e,e),{status:!0}):(Se($e,1),{status:d}),H=()=>u(0,[i,_,n]),Q=e=>F()?(qe(je,e),{status:!0}):(Se(je,1),{status:d}),F=()=>u(0,[i,_,n]),z=()=>K()?(qe(Me),{status:!0}):(Se(Me,1),{status:d}),K=()=>u(6.9,[i,_,n]),X=e=>Y()?(qe(Ae,e),{status:!0}):(Se(Ae,1),{status:d}),Y=()=>u(6.1,[i,_,n]),Z=e=>ee()?(qe(Ge,e),{status:!0}):(Se(Ge,1),{status:d}),ee=()=>u(6.1,[i,_,n]),te=e=>se()?(qe(Ue,{color:e?.color||e?.color_key}),{status:!0}):(Se(Ue,1),{status:d}),se=()=>u(710,[i,_,n]),ae=e=>re()?(qe(Ve,e),{status:!0}):(Se(Ve,1),{status:d}),re=()=>u(6.1,[i,_,n]),oe=e=>ie()?(qe(He,e),{status:!0}):(Se(He,1),{status:d}),ie=()=>u(0,[i,_,n]),ne=e=>_e()?(qe(Qe,e),{status:!0}):(Se(Qe,1),{status:d}),_e=()=>u(0,[i,_,n]),pe=e=>de()?(qe(Fe,e),{status:!0}):(Se(Fe,1),{status:d}),de=()=>u(6.1,[i,_,n]),ue=e=>ce()?(e.query.length>256&&Se(ze,9),qe(ze,e),{status:!0}):(Se(ze,1),{status:d}),ce=()=>u(6.7,[i,_,n]),ge=e=>be()?(qe(Ke,e),{status:!0}):(Se(Ke,1),{status:d}),be=()=>u(6.1,[n]),le=({key:e,value:t})=>{try{return window.sessionStorage.setItem("__telegram__"+e,JSON.stringify(t)),{status:!0}}catch(s){return window.sessionStorage.setItem("__telegram__"+e,t),{status:!0}}},we=()=>!0,me=({key:e})=>{try{return{is_json:!0,value:JSON.parse(window.sessionStorage.getItem("__telegram__"+e)??""),status:!0}}catch(t){return{is_json:!1,value:window.sessionStorage.getItem("__telegram__"+e)??"",status:!0}}},he=()=>!0,ve=e=>fe()?(qe(Xe,e),{status:!0}):(Se(Xe,1),{status:d}),fe=()=>u(7.7,[i,_,n]);var Se=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};const ye=()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppData");if(!t)return void Se("getInitData",2);const s=new URLSearchParams(t);let a={};return s.forEach(((e,t)=>{if(a[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{a[t]=JSON.parse(e)}catch{}})),a};var qe=(e,t)=>{if(window.TelegramWebviewProxy)window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t));else if(window.external&&"notify"in window.external)window.external.notify(JSON.stringify({eventType:e,eventData:t}));else try{"*",window.parent.postMessage(JSON.stringify({eventType:e,eventData:t}),"*")}catch(e){Se("postMessage Iframe",10)}};const xe="web_app_invoke_custom_method",Pe="web_app_open_scan_qr_popup",ke="web_app_read_text_from_clipboard",Oe="web_app_request_phone",Ie="web_app_close",Re="web_app_close_scan_qr_popup",Te="web_app_data_send",Ne="web_app_expand",Ce="iframe_ready",Be="iframe_will_reload",Ee="web_app_open_invoice",Le="web_app_open_link",We="web_app_open_popup",De="web_app_open_tg_link",Je="web_app_ready",$e="web_app_request_theme",je="web_app_request_viewport",Me="web_app_request_write_access",Ae="web_app_set_background_color",Ge="web_app_set_header_color",Ue="web_app_set_bottom_bar_color",Ve="web_app_setup_back_button",He="web_app_setup_closing_behavior",Qe="web_app_setup_main_button",Fe="web_app_setup_settings_button",ze="web_app_switch_inline_query",Ke="web_app_trigger_haptic_feedback",Xe="web_app_setup_swipe_behavior";const Ye="back_button_pressed",Ze="clipboard_text_received",et="custom_method_invoked",tt="invoice_closed",st="main_button_pressed",at="phone_requested",rt="popup_closed",ot="reload_iframe",it="qr_text_received",nt="scan_qr_popup_closed",_t="set_custom_style",pt="settings_button_pressed",dt="theme_changed",ut="viewport_changed",ct="write_access_requested",gt=((e=new Map)=>({once:(t,s,a=e.get(t),r=(e=>{s(e),a&&a.splice(a.indexOf(s)>>>0,1)}))=>a?a.push(r):e.set(t,[r]),on:(t,s,a=e.get(t))=>a?a.push(s):e.set(t,[s]),off:(t,s,a=e.get(t))=>a&&s?a.splice(a.indexOf(s)>>>0,1):e.set(t,[]),emit:(t,s,a=e.get(t)||[])=>{for(const e of a)e(s)}}))();(()=>{function e(e,t){e===dt&&(t.theme_params=b(t.theme_params)),gt.emit(e,t),gt.emit("*",{name:e,data:t})}window.TelegramGameProxy_receiveEvent=e,window.Telegram={WebView:{receiveEvent:e}},window.TelegramGameProxy={receiveEvent:e}})();const bt=(e,t)=>{gt.on(e,t)},lt=(e,t)=>{gt.off(e,t)},wt=(e,t)=>{gt.once(e,t)};var mt=Object.freeze({__proto__:null,off:lt,on:bt,once:wt});const ht=a({viewport:void 0,theme:void 0,init:void 0}),vt=e=>{const[a,o]=r({viewport:void 0,theme:void 0,init:void 0});return t((()=>{const e=()=>{o("init",ye())};e();const t=t=>{e(),o("viewport",{...t,safe_area_bottom:t.is_expanded&&t.is_state_stable?window.outerHeight-t.height:0})};bt(ut,t),Q();const a=t=>{e(),o("theme",t)};bt(dt,a),Q(),s((()=>{lt(ut,t),lt(dt,a)}))})),React.createElement(ht.Provider,{value:a},e.children)};export{ht as ContextTwa,Ye as EventBackButtonPressed,Ze as EventClipboardTextReceived,et as EventCustomMethodInvoked,tt as EventInvoiceClosed,st as EventMainButtonPressed,at as EventPhoneRequested,rt as EventPopupClosed,it as EventQrTextReceived,ot as EventReloadIframe,nt as EventScanQrPopupClosed,_t as EventSetCustomStyle,pt as EventSettingsButtonPressed,dt as EventThemeChanged,ut as EventViewportChanged,ct as EventWriteAccessRequested,Ie as MethodClose,Re as MethodCloseScanQrPopup,Te as MethodDataSend,Ne as MethodExpand,Ce as MethodIframeReady,Be as MethodIframeWillReload,xe as MethodInvokeCustomMethod,Ee as MethodOpenInvoice,Le as MethodOpenLink,We as MethodOpenPopup,Pe as MethodOpenScanQrPopup,De as MethodOpenTgLink,ke as MethodReadTextFromClipboard,Je as MethodReady,Oe as MethodRequestPhone,$e as MethodRequestTheme,je as MethodRequestViewport,Me as MethodRequestWriteAccess,Ae as MethodSetBackgroundColor,Ue as MethodSetBottomBarColor,Ge as MethodSetHeaderColor,Ve as MethodSetupBackButton,He as MethodSetupClosingBehavior,Qe as MethodSetupMainButton,Fe as MethodSetupSettingsButton,Xe as MethodSetupSwipeBehavior,ze as MethodSwitchInlineQuery,Ke as MethodTriggerHapticFeedback,d as NOT_SUPPORTED,vt as ProviderTWA,_ as TG_DESKTOP,n as TG_PHONE,i as TG_WEB,l as bridgeClose,m as bridgeCloseScanQrPopup,v as bridgeDataSend,S as bridgeExpand,ye as bridgeGetInitData,b as bridgeGetThemeParams,q as bridgeIframeReady,P as bridgeIframeWillReload,O as bridgeInvokeCustomMethod,R as bridgeOpenInvoice,N as bridgeOpenLink,B as bridgeOpenPopup,L as bridgeOpenScanQrPopup,D as bridgeOpenTgLink,$ as bridgeReadTextFromClipboard,M as bridgeReady,G as bridgeRequestPhone,V as bridgeRequestTheme,Q as bridgeRequestViewport,z as bridgeRequestWriteAccess,qe as bridgeSend,me as bridgeSessionStorageGet,le as bridgeSessionStorageSet,X as bridgeSetBackgroundColor,te as bridgeSetBottomBarColor,Z as bridgeSetHeaderColor,ae as bridgeSetupBackButton,oe as bridgeSetupClosingBehavior,ne as bridgeSetupMainButton,pe as bridgeSetupSettingsButton,ve as bridgeSetupSwipeBehavior,ue as bridgeSwitchInlineQuery,ge as bridgeTriggerHapticFeedback,o as createIsViewportChanged,Se as debug,p as getPlatform,mt as listener,qe as sender,w as supportClose,h as supportCloseScanQrPopup,f as supportDataSend,y as supportExpand,x as supportIframeReady,k as supportIframeWillReload,I as supportInvokeCustomMethod,T as supportOpenInvoice,C as supportOpenLink,E as supportOpenPopup,W as supportOpenScanQrPopup,J as supportOpenTgLink,j as supportReadTextFromClipboard,A as supportReady,U as supportRequestPhone,H as supportRequestTheme,F as supportRequestViewport,K as supportRequestWriteAccess,he as supportSessionStorageGet,we as supportSessionStorageSet,Y as supportSetBackgroundColor,se as supportSetBottomBarColor,ee as supportSetHeaderColor,re as supportSetupBackButton,ie as supportSetupClosingBehavior,_e as supportSetupMainButton,de as supportSetupSettingsButton,fe as supportSetupSwipeBehavior,ce as supportSwitchInlineQuery,be as supportTriggerHapticFeedback};
|
|
1
|
+
import {
|
|
2
|
+
createSignal as e,
|
|
3
|
+
onMount as t,
|
|
4
|
+
onCleanup as s,
|
|
5
|
+
createContext as a,
|
|
6
|
+
} from 'solid-js'
|
|
7
|
+
import { createStore as r } from 'solid-js/store'
|
|
8
|
+
const o = () => {
|
|
9
|
+
const [a, r] = e({ height: 0, is_expanded: !1, is_state_stable: !1 }),
|
|
10
|
+
o = e => r(e)
|
|
11
|
+
return (
|
|
12
|
+
t(() => {
|
|
13
|
+
bt(ut, o), qe(je)
|
|
14
|
+
}),
|
|
15
|
+
s(() => {
|
|
16
|
+
lt(ut, o)
|
|
17
|
+
}),
|
|
18
|
+
a
|
|
19
|
+
)
|
|
20
|
+
},
|
|
21
|
+
i = 'web',
|
|
22
|
+
n = 'phone',
|
|
23
|
+
_ = 'desktop',
|
|
24
|
+
p = () => {
|
|
25
|
+
const e = window.location.hash.slice(1),
|
|
26
|
+
t = new URLSearchParams(e).get('tgWebAppPlatform') ?? 'ios'
|
|
27
|
+
return ['android', 'ios'].includes(t)
|
|
28
|
+
? n
|
|
29
|
+
: ['tdesktop', 'macos'].includes(t)
|
|
30
|
+
? _
|
|
31
|
+
: i
|
|
32
|
+
},
|
|
33
|
+
d = 'not_supported',
|
|
34
|
+
u = (e, t) => {
|
|
35
|
+
const s = new URLSearchParams(window.location.hash.slice(1)).get(
|
|
36
|
+
'tgWebAppVersion'
|
|
37
|
+
)
|
|
38
|
+
return (
|
|
39
|
+
Number(s?.replace('.', '')) >= Number(String(e)?.replace('.', '')) &&
|
|
40
|
+
-1 !== t.indexOf(p())
|
|
41
|
+
)
|
|
42
|
+
},
|
|
43
|
+
c = () => Math.random().toString(36).substring(3, 9),
|
|
44
|
+
g = e => {
|
|
45
|
+
var t
|
|
46
|
+
if ((t = /^\s*#([0-9a-f]{6})\s*$/i.exec((e += ''))))
|
|
47
|
+
return '#' + t[1].toLowerCase()
|
|
48
|
+
if ((t = /^\s*#([0-9a-f])([0-9a-f])([0-9a-f])\s*$/i.exec(e)))
|
|
49
|
+
return ('#' + t[1] + t[1] + t[2] + t[2] + t[3] + t[3]).toLowerCase()
|
|
50
|
+
if (
|
|
51
|
+
(t =
|
|
52
|
+
/^\s*rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)\s*$/.exec(
|
|
53
|
+
e
|
|
54
|
+
))
|
|
55
|
+
) {
|
|
56
|
+
var s = parseInt(t[1]),
|
|
57
|
+
a = parseInt(t[2]),
|
|
58
|
+
r = parseInt(t[3])
|
|
59
|
+
return (
|
|
60
|
+
'#' +
|
|
61
|
+
((s < 16 ? '0' : '') + s.toString(16)) +
|
|
62
|
+
((a < 16 ? '0' : '') + a.toString(16)) +
|
|
63
|
+
((r < 16 ? '0' : '') + r.toString(16))
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
return !1
|
|
67
|
+
},
|
|
68
|
+
b = e => {
|
|
69
|
+
'#1c1c1d' == e.bg_color &&
|
|
70
|
+
e.bg_color == e.secondary_bg_color &&
|
|
71
|
+
(e.secondary_bg_color = '#2c2c2e')
|
|
72
|
+
const t = window.location.hash.slice(1),
|
|
73
|
+
s = new URLSearchParams(t)
|
|
74
|
+
var a = JSON.parse(s.get('tgWebAppThemeParams') ?? '')
|
|
75
|
+
for (var r of Object.keys(e)) {
|
|
76
|
+
var o = g(e[r])
|
|
77
|
+
'string' == typeof o && (a[r] = o)
|
|
78
|
+
}
|
|
79
|
+
return a
|
|
80
|
+
},
|
|
81
|
+
l = e => (w() ? (qe(Ie, e), { status: !0 }) : (Se(Ie, 1), { status: d })),
|
|
82
|
+
w = () => u(0, [i, _, n]),
|
|
83
|
+
m = e => (h() ? (qe(Re, e), { status: !0 }) : (Se(Re, 1), { status: d })),
|
|
84
|
+
h = () => u(6.4, [n]),
|
|
85
|
+
v = e => (f() ? (qe(Te, e), { status: !0 }) : (Se(Te, 1), { status: d })),
|
|
86
|
+
f = () => u(0, [i, _, n]),
|
|
87
|
+
S = e => (y() ? (qe(Ne, e), { status: !0 }) : (Se(Ne, 1), { status: d })),
|
|
88
|
+
y = () => u(0, [n]),
|
|
89
|
+
q = e => (x() ? (qe(Ce, e), { status: !0 }) : (Se(Ce, 1), { status: d })),
|
|
90
|
+
x = () => u(0, [i]),
|
|
91
|
+
P = () => (k() ? (qe(Ce), { status: !0 }) : (Se(Ce, 1), { status: d })),
|
|
92
|
+
k = () => u(0, [i]),
|
|
93
|
+
O = async e =>
|
|
94
|
+
I()
|
|
95
|
+
? (void 0 === e.req_id && (e.req_id = c()),
|
|
96
|
+
qe(xe, e),
|
|
97
|
+
new Promise((t, s) => {
|
|
98
|
+
const a = s => {
|
|
99
|
+
s.req_id === e.req_id && (t({ status: !0, data: s }), lt(et, a))
|
|
100
|
+
}
|
|
101
|
+
bt(et, a)
|
|
102
|
+
}))
|
|
103
|
+
: (Se(xe, 1), { status: d }),
|
|
104
|
+
I = () => u(6.9, [i, _, n]),
|
|
105
|
+
R = e => (T() ? (qe(Ee, e), { status: !0 }) : (Se(Ee, 1), { status: d })),
|
|
106
|
+
T = () => u(6.1, [i, _, n]),
|
|
107
|
+
N = e => (C() ? (qe(Le, e), { status: !0 }) : (Se(Le, 1), { status: d })),
|
|
108
|
+
C = () => u(6.4, [i, _, n]),
|
|
109
|
+
B = async e =>
|
|
110
|
+
E()
|
|
111
|
+
? (e.title.length > 64 && Se(We, 3),
|
|
112
|
+
e.message.length < 1 && Se(We, 4),
|
|
113
|
+
e.message.length > 256 && Se(We, 5),
|
|
114
|
+
e.buttons.length < 1 && Se(We, 6),
|
|
115
|
+
e.buttons.length > 3 && Se(We, 7),
|
|
116
|
+
void 0 !== e.buttons.find(e => e.text?.match(/^(ok|close|cancel)$/g)) &&
|
|
117
|
+
Se(We, 8),
|
|
118
|
+
qe(We, e),
|
|
119
|
+
new Promise((t, s) => {
|
|
120
|
+
const a = s => {
|
|
121
|
+
t({
|
|
122
|
+
status: !!e.buttons.find(e => e.id === s?.button_id),
|
|
123
|
+
data: s,
|
|
124
|
+
}),
|
|
125
|
+
lt(rt, a)
|
|
126
|
+
}
|
|
127
|
+
bt(rt, a)
|
|
128
|
+
}))
|
|
129
|
+
: (Se(We, 1), { status: d }),
|
|
130
|
+
E = () => u(6.2, [i, _, n]),
|
|
131
|
+
L = async e =>
|
|
132
|
+
W()
|
|
133
|
+
? (qe(Pe, e),
|
|
134
|
+
new Promise((t, s) => {
|
|
135
|
+
wt(it, s => {
|
|
136
|
+
e.is_close && m(), t({ status: !0, data: s })
|
|
137
|
+
}),
|
|
138
|
+
wt(nt, () => {
|
|
139
|
+
t({ status: 'closed' })
|
|
140
|
+
})
|
|
141
|
+
}))
|
|
142
|
+
: (Se(Pe, 1), { status: d }),
|
|
143
|
+
W = () => u(6.4, [n]),
|
|
144
|
+
D = e => (
|
|
145
|
+
'/' !== e.path_full[0] && (e.path_full = '/' + e.path_full),
|
|
146
|
+
J() ? (qe(De, e), { status: !0 }) : (Se(De, 1), { status: d })
|
|
147
|
+
),
|
|
148
|
+
J = () => u(7, [i, _, n]),
|
|
149
|
+
$ = async e =>
|
|
150
|
+
j()
|
|
151
|
+
? (e || (e = { req_id: void 0 }),
|
|
152
|
+
void 0 === e.req_id && (e.req_id = c()),
|
|
153
|
+
qe(ke, e),
|
|
154
|
+
new Promise((t, s) => {
|
|
155
|
+
const a = s => {
|
|
156
|
+
s.req_id === e?.req_id && (t({ status: !0, data: s }), lt(Ze, a))
|
|
157
|
+
}
|
|
158
|
+
bt(Ze, a)
|
|
159
|
+
}))
|
|
160
|
+
: (Se(ke, 1), { status: d }),
|
|
161
|
+
j = () => u(6.4, [i, _, n]),
|
|
162
|
+
M = e => (A() ? (qe(Je, e), { status: !0 }) : (Se(Je, 1), { status: d })),
|
|
163
|
+
A = () => u(6.9, [i, _, n]),
|
|
164
|
+
G = async () =>
|
|
165
|
+
U()
|
|
166
|
+
? (qe(Oe),
|
|
167
|
+
new Promise((e, t) => {
|
|
168
|
+
wt(at, t => {
|
|
169
|
+
'sent' === t.status && e({ status: !0 }), e({ status: !1 })
|
|
170
|
+
})
|
|
171
|
+
}))
|
|
172
|
+
: (Se(Oe, 1), { status: d }),
|
|
173
|
+
U = () => u(6.9, [i, _, n]),
|
|
174
|
+
V = e => (H() ? (qe($e, e), { status: !0 }) : (Se($e, 1), { status: d })),
|
|
175
|
+
H = () => u(0, [i, _, n]),
|
|
176
|
+
Q = e => (F() ? (qe(je, e), { status: !0 }) : (Se(je, 1), { status: d })),
|
|
177
|
+
F = () => u(0, [i, _, n]),
|
|
178
|
+
z = () => (K() ? (qe(Me), { status: !0 }) : (Se(Me, 1), { status: d })),
|
|
179
|
+
K = () => u(6.9, [i, _, n]),
|
|
180
|
+
X = e => (Y() ? (qe(Ae, e), { status: !0 }) : (Se(Ae, 1), { status: d })),
|
|
181
|
+
Y = () => u(6.1, [i, _, n]),
|
|
182
|
+
Z = e => (ee() ? (qe(Ge, e), { status: !0 }) : (Se(Ge, 1), { status: d })),
|
|
183
|
+
ee = () => u(6.1, [i, _, n]),
|
|
184
|
+
te = e =>
|
|
185
|
+
se()
|
|
186
|
+
? (qe(Ue, { color: e?.color || e?.color_key }), { status: !0 })
|
|
187
|
+
: (Se(Ue, 1), { status: d }),
|
|
188
|
+
se = () => u(710, [i, _, n]),
|
|
189
|
+
ae = e => (re() ? (qe(Ve, e), { status: !0 }) : (Se(Ve, 1), { status: d })),
|
|
190
|
+
re = () => u(6.1, [i, _, n]),
|
|
191
|
+
oe = e => (ie() ? (qe(He, e), { status: !0 }) : (Se(He, 1), { status: d })),
|
|
192
|
+
ie = () => u(0, [i, _, n]),
|
|
193
|
+
ne = e => (_e() ? (qe(Qe, e), { status: !0 }) : (Se(Qe, 1), { status: d })),
|
|
194
|
+
_e = () => u(0, [i, _, n]),
|
|
195
|
+
pe = e => (de() ? (qe(Fe, e), { status: !0 }) : (Se(Fe, 1), { status: d })),
|
|
196
|
+
de = () => u(6.1, [i, _, n]),
|
|
197
|
+
ue = e =>
|
|
198
|
+
ce()
|
|
199
|
+
? (e.query.length > 256 && Se(ze, 9), qe(ze, e), { status: !0 })
|
|
200
|
+
: (Se(ze, 1), { status: d }),
|
|
201
|
+
ce = () => u(6.7, [i, _, n]),
|
|
202
|
+
ge = e => (be() ? (qe(Ke, e), { status: !0 }) : (Se(Ke, 1), { status: d })),
|
|
203
|
+
be = () => u(6.1, [n]),
|
|
204
|
+
le = ({ key: e, value: t }) => {
|
|
205
|
+
try {
|
|
206
|
+
return (
|
|
207
|
+
window.sessionStorage.setItem('__telegram__' + e, JSON.stringify(t)),
|
|
208
|
+
{ status: !0 }
|
|
209
|
+
)
|
|
210
|
+
} catch (s) {
|
|
211
|
+
return (
|
|
212
|
+
window.sessionStorage.setItem('__telegram__' + e, t), { status: !0 }
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
we = () => !0,
|
|
217
|
+
me = ({ key: e }) => {
|
|
218
|
+
try {
|
|
219
|
+
return {
|
|
220
|
+
is_json: !0,
|
|
221
|
+
value: JSON.parse(
|
|
222
|
+
window.sessionStorage.getItem('__telegram__' + e) ?? ''
|
|
223
|
+
),
|
|
224
|
+
status: !0,
|
|
225
|
+
}
|
|
226
|
+
} catch (t) {
|
|
227
|
+
return {
|
|
228
|
+
is_json: !1,
|
|
229
|
+
value: window.sessionStorage.getItem('__telegram__' + e) ?? '',
|
|
230
|
+
status: !0,
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
he = () => !0,
|
|
235
|
+
ve = e => (fe() ? (qe(Xe, e), { status: !0 }) : (Se(Xe, 1), { status: d })),
|
|
236
|
+
fe = () => u(7.7, [i, _, n])
|
|
237
|
+
var Se = (e, t) => {
|
|
238
|
+
'development' === process.env.NODE_ENV &&
|
|
239
|
+
console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)
|
|
240
|
+
}
|
|
241
|
+
const ye = () => {
|
|
242
|
+
const e = window.location.hash.slice(1),
|
|
243
|
+
t = new URLSearchParams(e).get('tgWebAppData')
|
|
244
|
+
if (!t) return void Se('getInitData', 2)
|
|
245
|
+
const s = new URLSearchParams(t)
|
|
246
|
+
let a = {}
|
|
247
|
+
return (
|
|
248
|
+
s.forEach((e, t) => {
|
|
249
|
+
if (((a[t] = e), void 0 !== t.match(/^(chat|receiver|user)$/g)))
|
|
250
|
+
try {
|
|
251
|
+
a[t] = JSON.parse(e)
|
|
252
|
+
} catch {}
|
|
253
|
+
}),
|
|
254
|
+
a
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
var qe = (e, t) => {
|
|
258
|
+
if (window.TelegramWebviewProxy)
|
|
259
|
+
window.TelegramWebviewProxy.postEvent(e, JSON.stringify(t))
|
|
260
|
+
else if (window.external && 'notify' in window.external)
|
|
261
|
+
window.external.notify(JSON.stringify({ eventType: e, eventData: t }))
|
|
262
|
+
else
|
|
263
|
+
try {
|
|
264
|
+
'*',
|
|
265
|
+
window.parent.postMessage(
|
|
266
|
+
JSON.stringify({ eventType: e, eventData: t }),
|
|
267
|
+
'*'
|
|
268
|
+
)
|
|
269
|
+
} catch (e) {
|
|
270
|
+
Se('postMessage Iframe', 10)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const xe = 'web_app_invoke_custom_method',
|
|
274
|
+
Pe = 'web_app_open_scan_qr_popup',
|
|
275
|
+
ke = 'web_app_read_text_from_clipboard',
|
|
276
|
+
Oe = 'web_app_request_phone',
|
|
277
|
+
Ie = 'web_app_close',
|
|
278
|
+
Re = 'web_app_close_scan_qr_popup',
|
|
279
|
+
Te = 'web_app_data_send',
|
|
280
|
+
Ne = 'web_app_expand',
|
|
281
|
+
Ce = 'iframe_ready',
|
|
282
|
+
Be = 'iframe_will_reload',
|
|
283
|
+
Ee = 'web_app_open_invoice',
|
|
284
|
+
Le = 'web_app_open_link',
|
|
285
|
+
We = 'web_app_open_popup',
|
|
286
|
+
De = 'web_app_open_tg_link',
|
|
287
|
+
Je = 'web_app_ready',
|
|
288
|
+
$e = 'web_app_request_theme',
|
|
289
|
+
je = 'web_app_request_viewport',
|
|
290
|
+
Me = 'web_app_request_write_access',
|
|
291
|
+
Ae = 'web_app_set_background_color',
|
|
292
|
+
Ge = 'web_app_set_header_color',
|
|
293
|
+
Ue = 'web_app_set_bottom_bar_color',
|
|
294
|
+
Ve = 'web_app_setup_back_button',
|
|
295
|
+
He = 'web_app_setup_closing_behavior',
|
|
296
|
+
Qe = 'web_app_setup_main_button',
|
|
297
|
+
Fe = 'web_app_setup_settings_button',
|
|
298
|
+
ze = 'web_app_switch_inline_query',
|
|
299
|
+
Ke = 'web_app_trigger_haptic_feedback',
|
|
300
|
+
Xe = 'web_app_setup_swipe_behavior'
|
|
301
|
+
const Ye = 'back_button_pressed',
|
|
302
|
+
Ze = 'clipboard_text_received',
|
|
303
|
+
et = 'custom_method_invoked',
|
|
304
|
+
tt = 'invoice_closed',
|
|
305
|
+
st = 'main_button_pressed',
|
|
306
|
+
at = 'phone_requested',
|
|
307
|
+
rt = 'popup_closed',
|
|
308
|
+
ot = 'reload_iframe',
|
|
309
|
+
it = 'qr_text_received',
|
|
310
|
+
nt = 'scan_qr_popup_closed',
|
|
311
|
+
_t = 'set_custom_style',
|
|
312
|
+
pt = 'settings_button_pressed',
|
|
313
|
+
dt = 'theme_changed',
|
|
314
|
+
ut = 'viewport_changed',
|
|
315
|
+
ct = 'write_access_requested',
|
|
316
|
+
gt = ((e = new Map()) => ({
|
|
317
|
+
once: (
|
|
318
|
+
t,
|
|
319
|
+
s,
|
|
320
|
+
a = e.get(t),
|
|
321
|
+
r = e => {
|
|
322
|
+
s(e), a && a.splice(a.indexOf(s) >>> 0, 1)
|
|
323
|
+
}
|
|
324
|
+
) => (a ? a.push(r) : e.set(t, [r])),
|
|
325
|
+
on: (t, s, a = e.get(t)) => (a ? a.push(s) : e.set(t, [s])),
|
|
326
|
+
off: (t, s, a = e.get(t)) =>
|
|
327
|
+
a && s ? a.splice(a.indexOf(s) >>> 0, 1) : e.set(t, []),
|
|
328
|
+
emit: (t, s, a = e.get(t) || []) => {
|
|
329
|
+
for (const e of a) e(s)
|
|
330
|
+
},
|
|
331
|
+
}))()
|
|
332
|
+
;(() => {
|
|
333
|
+
function e(e, t) {
|
|
334
|
+
e === dt && (t.theme_params = b(t.theme_params)),
|
|
335
|
+
gt.emit(e, t),
|
|
336
|
+
gt.emit('*', { name: e, data: t })
|
|
337
|
+
}
|
|
338
|
+
;(window.TelegramGameProxy_receiveEvent = e),
|
|
339
|
+
(window.Telegram = { WebView: { receiveEvent: e } }),
|
|
340
|
+
(window.TelegramGameProxy = { receiveEvent: e })
|
|
341
|
+
})()
|
|
342
|
+
const bt = (e, t) => {
|
|
343
|
+
gt.on(e, t)
|
|
344
|
+
},
|
|
345
|
+
lt = (e, t) => {
|
|
346
|
+
gt.off(e, t)
|
|
347
|
+
},
|
|
348
|
+
wt = (e, t) => {
|
|
349
|
+
gt.once(e, t)
|
|
350
|
+
}
|
|
351
|
+
var mt = Object.freeze({ __proto__: null, off: lt, on: bt, once: wt })
|
|
352
|
+
const ht = a({ viewport: void 0, theme: void 0, init: void 0 }),
|
|
353
|
+
vt = e => {
|
|
354
|
+
const [a, o] = r({ viewport: void 0, theme: void 0, init: void 0 })
|
|
355
|
+
return (
|
|
356
|
+
t(() => {
|
|
357
|
+
const e = () => {
|
|
358
|
+
o('init', ye())
|
|
359
|
+
}
|
|
360
|
+
e()
|
|
361
|
+
const t = t => {
|
|
362
|
+
e(),
|
|
363
|
+
o('viewport', {
|
|
364
|
+
...t,
|
|
365
|
+
safe_area_bottom:
|
|
366
|
+
t.is_expanded && t.is_state_stable
|
|
367
|
+
? window.outerHeight - t.height
|
|
368
|
+
: 0,
|
|
369
|
+
})
|
|
370
|
+
}
|
|
371
|
+
bt(ut, t), Q()
|
|
372
|
+
const a = t => {
|
|
373
|
+
e(), o('theme', t)
|
|
374
|
+
}
|
|
375
|
+
bt(dt, a),
|
|
376
|
+
Q(),
|
|
377
|
+
s(() => {
|
|
378
|
+
lt(ut, t), lt(dt, a)
|
|
379
|
+
})
|
|
380
|
+
}),
|
|
381
|
+
e.children
|
|
382
|
+
)
|
|
383
|
+
}
|
|
384
|
+
export {
|
|
385
|
+
ht as ContextTwa,
|
|
386
|
+
Ye as EventBackButtonPressed,
|
|
387
|
+
Ze as EventClipboardTextReceived,
|
|
388
|
+
et as EventCustomMethodInvoked,
|
|
389
|
+
tt as EventInvoiceClosed,
|
|
390
|
+
st as EventMainButtonPressed,
|
|
391
|
+
at as EventPhoneRequested,
|
|
392
|
+
rt as EventPopupClosed,
|
|
393
|
+
it as EventQrTextReceived,
|
|
394
|
+
ot as EventReloadIframe,
|
|
395
|
+
nt as EventScanQrPopupClosed,
|
|
396
|
+
_t as EventSetCustomStyle,
|
|
397
|
+
pt as EventSettingsButtonPressed,
|
|
398
|
+
dt as EventThemeChanged,
|
|
399
|
+
ut as EventViewportChanged,
|
|
400
|
+
ct as EventWriteAccessRequested,
|
|
401
|
+
Ie as MethodClose,
|
|
402
|
+
Re as MethodCloseScanQrPopup,
|
|
403
|
+
Te as MethodDataSend,
|
|
404
|
+
Ne as MethodExpand,
|
|
405
|
+
Ce as MethodIframeReady,
|
|
406
|
+
Be as MethodIframeWillReload,
|
|
407
|
+
xe as MethodInvokeCustomMethod,
|
|
408
|
+
Ee as MethodOpenInvoice,
|
|
409
|
+
Le as MethodOpenLink,
|
|
410
|
+
We as MethodOpenPopup,
|
|
411
|
+
Pe as MethodOpenScanQrPopup,
|
|
412
|
+
De as MethodOpenTgLink,
|
|
413
|
+
ke as MethodReadTextFromClipboard,
|
|
414
|
+
Je as MethodReady,
|
|
415
|
+
Oe as MethodRequestPhone,
|
|
416
|
+
$e as MethodRequestTheme,
|
|
417
|
+
je as MethodRequestViewport,
|
|
418
|
+
Me as MethodRequestWriteAccess,
|
|
419
|
+
Ae as MethodSetBackgroundColor,
|
|
420
|
+
Ue as MethodSetBottomBarColor,
|
|
421
|
+
Ge as MethodSetHeaderColor,
|
|
422
|
+
Ve as MethodSetupBackButton,
|
|
423
|
+
He as MethodSetupClosingBehavior,
|
|
424
|
+
Qe as MethodSetupMainButton,
|
|
425
|
+
Fe as MethodSetupSettingsButton,
|
|
426
|
+
Xe as MethodSetupSwipeBehavior,
|
|
427
|
+
ze as MethodSwitchInlineQuery,
|
|
428
|
+
Ke as MethodTriggerHapticFeedback,
|
|
429
|
+
d as NOT_SUPPORTED,
|
|
430
|
+
vt as ProviderTWA,
|
|
431
|
+
_ as TG_DESKTOP,
|
|
432
|
+
n as TG_PHONE,
|
|
433
|
+
i as TG_WEB,
|
|
434
|
+
l as bridgeClose,
|
|
435
|
+
m as bridgeCloseScanQrPopup,
|
|
436
|
+
v as bridgeDataSend,
|
|
437
|
+
S as bridgeExpand,
|
|
438
|
+
ye as bridgeGetInitData,
|
|
439
|
+
b as bridgeGetThemeParams,
|
|
440
|
+
q as bridgeIframeReady,
|
|
441
|
+
P as bridgeIframeWillReload,
|
|
442
|
+
O as bridgeInvokeCustomMethod,
|
|
443
|
+
R as bridgeOpenInvoice,
|
|
444
|
+
N as bridgeOpenLink,
|
|
445
|
+
B as bridgeOpenPopup,
|
|
446
|
+
L as bridgeOpenScanQrPopup,
|
|
447
|
+
D as bridgeOpenTgLink,
|
|
448
|
+
$ as bridgeReadTextFromClipboard,
|
|
449
|
+
M as bridgeReady,
|
|
450
|
+
G as bridgeRequestPhone,
|
|
451
|
+
V as bridgeRequestTheme,
|
|
452
|
+
Q as bridgeRequestViewport,
|
|
453
|
+
z as bridgeRequestWriteAccess,
|
|
454
|
+
qe as bridgeSend,
|
|
455
|
+
me as bridgeSessionStorageGet,
|
|
456
|
+
le as bridgeSessionStorageSet,
|
|
457
|
+
X as bridgeSetBackgroundColor,
|
|
458
|
+
te as bridgeSetBottomBarColor,
|
|
459
|
+
Z as bridgeSetHeaderColor,
|
|
460
|
+
ae as bridgeSetupBackButton,
|
|
461
|
+
oe as bridgeSetupClosingBehavior,
|
|
462
|
+
ne as bridgeSetupMainButton,
|
|
463
|
+
pe as bridgeSetupSettingsButton,
|
|
464
|
+
ve as bridgeSetupSwipeBehavior,
|
|
465
|
+
ue as bridgeSwitchInlineQuery,
|
|
466
|
+
ge as bridgeTriggerHapticFeedback,
|
|
467
|
+
o as createIsViewportChanged,
|
|
468
|
+
Se as debug,
|
|
469
|
+
p as getPlatform,
|
|
470
|
+
mt as listener,
|
|
471
|
+
qe as sender,
|
|
472
|
+
w as supportClose,
|
|
473
|
+
h as supportCloseScanQrPopup,
|
|
474
|
+
f as supportDataSend,
|
|
475
|
+
y as supportExpand,
|
|
476
|
+
x as supportIframeReady,
|
|
477
|
+
k as supportIframeWillReload,
|
|
478
|
+
I as supportInvokeCustomMethod,
|
|
479
|
+
T as supportOpenInvoice,
|
|
480
|
+
C as supportOpenLink,
|
|
481
|
+
E as supportOpenPopup,
|
|
482
|
+
W as supportOpenScanQrPopup,
|
|
483
|
+
J as supportOpenTgLink,
|
|
484
|
+
j as supportReadTextFromClipboard,
|
|
485
|
+
A as supportReady,
|
|
486
|
+
U as supportRequestPhone,
|
|
487
|
+
H as supportRequestTheme,
|
|
488
|
+
F as supportRequestViewport,
|
|
489
|
+
K as supportRequestWriteAccess,
|
|
490
|
+
he as supportSessionStorageGet,
|
|
491
|
+
we as supportSessionStorageSet,
|
|
492
|
+
Y as supportSetBackgroundColor,
|
|
493
|
+
se as supportSetBottomBarColor,
|
|
494
|
+
ee as supportSetHeaderColor,
|
|
495
|
+
re as supportSetupBackButton,
|
|
496
|
+
ie as supportSetupClosingBehavior,
|
|
497
|
+
_e as supportSetupMainButton,
|
|
498
|
+
de as supportSetupSettingsButton,
|
|
499
|
+
fe as supportSetupSwipeBehavior,
|
|
500
|
+
ce as supportSwitchInlineQuery,
|
|
501
|
+
be as supportTriggerHapticFeedback,
|
|
502
|
+
}
|