@apiteam/twa-bridge 7.1.0 → 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/solid/index.mjs CHANGED
@@ -1 +1,502 @@
1
- import e from"debug";import{createSignal as t,onMount as s,onCleanup as a}from"solid-js";const r=()=>{const[e,r]=t({height:0,is_expanded:!1,is_state_stable:!1}),o=e=>r(e);return s((()=>{$e(Ee,o),ye(ot)})),a((()=>{Me(Ee,o)})),e},o="web",n="phone",i="desktop",_=()=>{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:o},p="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(_())},d=()=>Math.random().toString(36).substring(3,9),c=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},g=()=>b()?(ye(Fe),{status:!0}):(ve(Fe,1),{status:p}),b=()=>u(0,[o,i,n]),l=()=>w()?(ye(He),{status:!0}):(ve(He,1),{status:p}),w=()=>u(6.4,[n]),m=e=>h()?(ye(ze,e),{status:!0}):(ve(ze,1),{status:p}),h=()=>u(0,[o,i,n]),f=()=>v()?(ye(Ke),{status:!0}):(ve(Ke,1),{status:p}),v=()=>u(0,[n]),S=e=>y()?(ye(Xe,e),{status:!0}):(ve(Xe,1),{status:p}),y=()=>u(0,[o]),q=()=>x()?(ye(Xe),{status:!0}):(ve(Xe,1),{status:p}),x=()=>u(0,[o]),k="web_app_invoke_custom_method",P=async e=>O()?(void 0===e.req_id&&(e.req_id=d()),ye(k,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),Me(ke,a))};$e(ke,a)}))):(ve(k,1),{status:p}),O=()=>u(6.9,[o,i,n]),I=e=>R()?(ye(Ze,e),{status:!0}):(ve(Ze,1),{status:p}),R=()=>u(6.1,[o,i,n]),T=e=>N()?(ye(et,e),{status:!0}):(ve(et,1),{status:p}),N=()=>u(6.4,[o,i,n]),C=async e=>B()?(e.title.length>64&&ve(tt,3),e.message.length<1&&ve(tt,4),e.message.length>256&&ve(tt,5),e.buttons.length<1&&ve(tt,6),e.buttons.length>3&&ve(tt,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&ve(tt,8),ye(tt,e),new Promise(((t,s)=>{const a=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),Me(Re,a)};$e(Re,a)}))):(ve(tt,1),{status:p}),B=()=>u(6.2,[o,i,n]),L=async e=>W()?(ye(Ve,e),new Promise(((t,s)=>{Ae(Ne,(s=>{e.is_close&&l(),t({status:!0,data:s})})),Ae(Ce,(()=>{t({status:"closed"})}))}))):(ve(Ve,1),{status:p}),W=()=>u(6.4,[n]),E=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),D()?(ye(st,e),{status:!0}):(ve(st,1),{status:p})),D=()=>u(7,[o,i,n]),J=async e=>$()?(void 0===e.req_id&&(e.req_id=d()),ye(Qe,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),Me(xe,a))};$e(xe,a)}))):(ve(Qe,1),{status:p}),$=()=>u(6.4,[o,i,n]),M=()=>A()?(ye(at),{status:!0}):(ve(at,1),{status:p}),A=()=>u(6.9,[o,i,n]),U=async()=>G()?(ye(je),new Promise(((e,t)=>{Ae(Ie,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(ve(je,1),{status:p}),G=()=>u(6.9,[o,i,n]),V=()=>Q()?(ye(rt),{status:!0}):(ve(rt,1),{status:p}),Q=()=>u(0,[o,i,n]),j=()=>F()?(ye(ot),{status:!0}):(ve(ot,1),{status:p}),F=()=>u(0,[o,i,n]),H=()=>z()?(ye(nt),{status:!0}):(ve(nt,1),{status:p}),z=()=>u(6.9,[o,i,n]),K=e=>X()?(ye(it,e),{status:!0}):(ve(it,1),{status:p}),X=()=>u(6.1,[o,i,n]),Y=e=>Z()?(ye(_t,e),{status:!0}):(ve(_t,1),{status:p}),Z=()=>u(6.1,[o,i,n]),ee=e=>te()?(ye(pt,{color:e.color||e.color_key}),{status:!0}):(ve(pt,1),{status:p}),te=()=>u(710,[o,i,n]),se=e=>ae()?(ye(ut,e),{status:!0}):(ve(ut,1),{status:p}),ae=()=>u(6.1,[o,i,n]),re=e=>oe()?(ye(dt,e),{status:!0}):(ve(dt,1),{status:p}),oe=()=>u(0,[o,i,n]),ne=e=>ie()?(ye(ct,e),{status:!0}):(ve(ct,1),{status:p}),ie=()=>u(0,[o,i,n]),_e=e=>pe()?(ye(gt,e),{status:!0}):(ve(gt,1),{status:p}),pe=()=>u(6.1,[o,i,n]),ue=e=>de()?(e.query.length>256&&ve(bt,9),ye(bt,e),{status:!0}):(ve(bt,1),{status:p}),de=()=>u(6.7,[o,i,n]),ce=e=>ge()?(ye(lt,e),{status:!0}):(ve(lt,1),{status:p}),ge=()=>u(6.1,[n]),be=({key:e,value:t})=>{try{return window.sessionStorage.setItem("__telegram__"+e,JSON.stringify(t)),{status:!0}}catch(e){}return{status:!1}},le=()=>!0,we=({key:e})=>{try{return{value:JSON.parse(window.sessionStorage.getItem("__telegram__"+e)??""),status:!0}}catch(e){}return{status:!1}},me=()=>!0,he=e=>fe()?(ye(wt,e),{status:!0}):(ve(wt,1),{status:p}),fe=()=>u(7.7,[o,i,n]);var ve=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};const Se=()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppData");if(!t)return ve("getInitData",2),null;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 ye=(t,s)=>{if(window.TelegramWebviewProxy)window.TelegramWebviewProxy.postEvent(t,JSON.stringify(s));else if(window.external&&"notify"in window.external)window.external.notify(JSON.stringify({eventType:t,eventData:s}));else try{"*",window.parent.postMessage(JSON.stringify({eventType:t,eventData:s}),"*")}catch(t){e("postMessage Iframe",10)}};const qe="back_button_pressed",xe="clipboard_text_received",ke="custom_method_invoked",Pe="invoice_closed",Oe="main_button_pressed",Ie="phone_requested",Re="popup_closed",Te="reload_iframe",Ne="qr_text_received",Ce="scan_qr_popup_closed",Be="set_custom_style",Le="settings_button_pressed",We="theme_changed",Ee="viewport_changed",De="write_access_requested",Je=((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===We&&(t.theme_params=(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 in e){var o=c(e[r]);"string"==typeof o&&(a[r]=o)}return a})(t.theme_params)),Je.emit(e,t),Je.emit("*",{name:e,data:t})}window.TelegramGameProxy_receiveEvent=e,window.Telegram={WebView:{receiveEvent:e}},window.TelegramGameProxy={receiveEvent:e}})();const $e=(e,t)=>{Je.on(e,t)},Me=(e,t)=>{Je.off(e,t)},Ae=(e,t)=>{Je.once(e,t)};var Ue=Object.freeze({__proto__:null,off:Me,on:$e,once:Ae});const Ge="web_app_invoke_custom_method",Ve="web_app_open_scan_qr_popup",Qe="web_app_read_text_from_clipboard",je="web_app_request_phone",Fe="web_app_close",He="web_app_close_scan_qr_popup",ze="web_app_data_send",Ke="web_app_expand",Xe="iframe_ready",Ye="iframe_will_reload",Ze="web_app_open_invoice",et="web_app_open_link",tt="web_app_open_popup",st="web_app_open_tg_link",at="web_app_ready",rt="web_app_request_theme",ot="web_app_request_viewport",nt="web_app_request_write_access",it="web_app_set_background_color",_t="web_app_set_header_color",pt="web_app_set_bottom_bar_color",ut="web_app_setup_back_button",dt="web_app_setup_closing_behavior",ct="web_app_setup_main_button",gt="web_app_setup_settings_button",bt="web_app_switch_inline_query",lt="web_app_trigger_haptic_feedback",wt="web_app_setup_swipe_behavior";export{qe as EventBackButtonPressed,xe as EventClipboardTextReceived,ke as EventCustomMethodInvoked,Pe as EventInvoiceClosed,Oe as EventMainButtonPressed,Ie as EventPhoneRequested,Re as EventPopupClosed,Ne as EventQrTextReceived,Te as EventReloadIframe,Ce as EventScanQrPopupClosed,Be as EventSetCustomStyle,Le as EventSettingsButtonPressed,We as EventThemeChanged,Ee as EventViewportChanged,De as EventWriteAccessRequested,Fe as MethodClose,He as MethodCloseScanQrPopup,ze as MethodDataSend,Ke as MethodExpand,Xe as MethodIframeReady,Ye as MethodIframeWillReload,Ge as MethodInvokeCustomMethod,Ze as MethodOpenInvoice,et as MethodOpenLink,tt as MethodOpenPopup,Ve as MethodOpenScanQrPopup,st as MethodOpenTgLink,Qe as MethodReadTextFromClipboard,at as MethodReady,je as MethodRequestPhone,rt as MethodRequestTheme,ot as MethodRequestViewport,nt as MethodRequestWriteAccess,it as MethodSetBackgroundColor,pt as MethodSetBottomBarColor,_t as MethodSetHeaderColor,ut as MethodSetupBackButton,dt as MethodSetupClosingBehavior,ct as MethodSetupMainButton,gt as MethodSetupSettingsButton,wt as MethodSetupSwipeBehavior,bt as MethodSwitchInlineQuery,lt as MethodTriggerHapticFeedback,p as NOT_SUPPORTED,i as TG_DESKTOP,n as TG_PHONE,o as TG_WEB,g as bridgeClose,l as bridgeCloseScanQrPopup,m as bridgeDataSend,f as bridgeExpand,Se as bridgeGetInitData,S as bridgeIframeReady,q as bridgeIframeWillReload,P as bridgeInvokeCustomMethod,I as bridgeOpenInvoice,T as bridgeOpenLink,C as bridgeOpenPopup,L as bridgeOpenScanQrPopup,E as bridgeOpenTgLink,J as bridgeReadTextFromClipboard,M as bridgeReady,U as bridgeRequestPhone,V as bridgeRequestTheme,j as bridgeRequestViewport,H as bridgeRequestWriteAccess,we as bridgeSessionStorageGet,be as bridgeSessionStorageSet,K as bridgeSetBackgroundColor,ee as bridgeSetBottomBarColor,Y as bridgeSetHeaderColor,se as bridgeSetupBackButton,re as bridgeSetupClosingBehavior,ne as bridgeSetupMainButton,_e as bridgeSetupSettingsButton,he as bridgeSetupSwipeBehavior,ue as bridgeSwitchInlineQuery,ce as bridgeTriggerHapticFeedback,r as createIsViewportChanged,ve as debug,_ as getPlatform,Ue as listener,ye as sender,b as supportClose,w as supportCloseScanQrPopup,h as supportDataSend,v as supportExpand,y as supportIframeReady,x as supportIframeWillReload,O as supportInvokeCustomMethod,R as supportOpenInvoice,N as supportOpenLink,B as supportOpenPopup,W as supportOpenScanQrPopup,D as supportOpenTgLink,$ as supportReadTextFromClipboard,A as supportReady,G as supportRequestPhone,Q as supportRequestTheme,F as supportRequestViewport,z as supportRequestWriteAccess,me as supportSessionStorageGet,le as supportSessionStorageSet,X as supportSetBackgroundColor,te as supportSetBottomBarColor,Z as supportSetHeaderColor,ae as supportSetupBackButton,oe as supportSetupClosingBehavior,ie as supportSetupMainButton,pe as supportSetupSettingsButton,fe as supportSetupSwipeBehavior,de as supportSwitchInlineQuery,ge 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
+ }