@apiteam/twa-bridge 0.0.2-beta.4 → 7.0.0-beta.2

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/README.md CHANGED
@@ -27,7 +27,7 @@ Telegram distributes SDK via [link](https://core.telegram.org/bots/webapps#initi
27
27
  This package allows to work with SDK as with a npm package:
28
28
 
29
29
  ```js
30
- import { bridgeOpenPopup } from '@apiteam/twa-bridge'
30
+ import { bridgeOpenPopup } from '@apiteam/twa-bridge/solid'
31
31
 
32
32
  bridgeOpenPopup({ message: 'message' })
33
33
  ```
@@ -39,4 +39,18 @@ And yes, it supports TS.
39
39
  import { createIsViewportChanged } from '@apiteam/twa-bridge/solid'
40
40
 
41
41
  const viewport = createIsViewportChanged()
42
- ```
42
+ ```
43
+
44
+ ### Errors
45
+
46
+ | ID | Description |
47
+ | --- | ----------------------------------------------------------------- |
48
+ | 1 | Method not supported |
49
+ | 2 | Ooof! Something is wrong. Init data is missing |
50
+ | 3 | Title too long, maximum length 64 characters |
51
+ | 4 | Your message is too short, at least 1 character |
52
+ | 5 | Your message is too long, maximum 256 characters |
53
+ | 6 | You are passing too few buttons, at least 1 button |
54
+ | 7 | You are passing too many buttons, maximum 3 buttons |
55
+ | 8 | The button text ignores the following values: "ok, close, cancel" |
56
+ | 9 | EDIT_MESSAGE
package/package.json CHANGED
@@ -1,18 +1,9 @@
1
1
  {
2
2
  "name": "@apiteam/twa-bridge",
3
- "version": "0.0.2-beta.4",
3
+ "version": "7.0.0-beta.2",
4
4
  "description": "Telegram bridge",
5
5
  "license": "MIT",
6
- "main": "index.js",
7
- "module": "index.mjs",
8
- "typings": "index.d.ts",
9
- "browser": {
10
- "./index.cjs": "index.cjs",
11
- "./index.js": "index.js"
12
- },
13
- "unpkg": "index.cjs",
14
- "types": "index.d.ts",
15
- "type": "module",
6
+ "types": "index.ts",
16
7
  "author": {
17
8
  "name": "Egor Kytyukov",
18
9
  "url": "https://vk.com/xuserz"
@@ -194,9 +194,10 @@ type OpenPopup = (eventData: {
194
194
  * List of buttons to be displayed in the popup, 1-3 buttons
195
195
  */
196
196
  buttons: PopupButton[];
197
- }) => {
197
+ }) => Promise<{
198
198
  status: boolean | typeof NOT_SUPPORTED;
199
- };
199
+ data?: EventsData['popup_closed'];
200
+ }>;
200
201
  /**
201
202
  * Opens a new popup. When user closes the popup, Telegram creates the popup_closed event.
202
203
  *
@@ -890,19 +891,17 @@ declare global {
890
891
  };
891
892
  }
892
893
  }
893
- declare const listenerStart: () => void;
894
894
  type Listened = <T extends EventsData, E extends keyof T, D extends T[E]>(eventName: E, callback: (eventData: D) => void) => void;
895
895
  declare const on: Listened;
896
896
  declare const off: Listened;
897
897
  declare const once: Listened;
898
898
 
899
899
  type listener_EventsData = EventsData;
900
- declare const listener_listenerStart: typeof listenerStart;
901
900
  declare const listener_off: typeof off;
902
901
  declare const listener_on: typeof on;
903
902
  declare const listener_once: typeof once;
904
903
  declare namespace listener {
905
- export { type listener_EventsData as EventsData, listener_listenerStart as listenerStart, listener_off as off, listener_on as on, listener_once as once };
904
+ export { type listener_EventsData as EventsData, listener_off as off, listener_on as on, listener_once as once };
906
905
  }
907
906
 
908
907
  declare const TG_WEB = "web";
package/react/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e=require("solid"),t=require("utils");const s="web",o="phone",r="desktop",p="not_supported",a=(e,t)=>{const p=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(p)>=e&&-1!==t.indexOf((()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(t)?o:["tdesktop","macos"].includes(t)?r:s})())},n=()=>Math.random().toString(36).substring(3,9),u=()=>a(0,[s,r,o]),i=()=>d()?(D(J),{status:!0}):(Q(J,1),{status:p}),d=()=>a(6.4,[o]),_=()=>a(0,[s,r,o]),c=()=>a(0,[o]),x=()=>a(0,[s]),l=()=>a(0,[s]),h="web_app_invoke_custom_method",g=()=>a(6.9,[s,r,o]),b=()=>a(6.1,[s,r,o]),w=()=>a(6.4,[s,r,o]),m=()=>a(6.2,[s,r,o]),v=()=>a(6.4,[o]),S=()=>a(7,[s,r,o]),f=()=>a(6.4,[s,r,o]),P=()=>a(6.9,[s,r,o]),q=()=>a(6.9,[s,r,o]),M=()=>a(0,[s,r,o]),R=()=>a(0,[s,r,o]),k=()=>a(6.9,[s,r,o]),y=()=>a(6.1,[s,r,o]),C=()=>a(6.1,[s,r,o]),E=()=>a(6.1,[s,r,o]),T=()=>a(0,[s,r,o]),O=()=>a(0,[s,r,o]),B=()=>a(6.1,[s,r,o]),I=()=>a(6.7,[s,r,o]),W=()=>a(6.1,[o]);var Q=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};var D=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const L=((e=new Map)=>({once:(t,s,o=e.get(t),r=(e=>{s(e),o&&o.splice(o.indexOf(s)>>>0,1)}))=>o?o.push(r):e.set(t,[r]),on:(t,s,o=e.get(t))=>o?o.push(s):e.set(t,[s]),off:(t,s,o=e.get(t))=>o&&s?o.splice(o.indexOf(s)>>>0,1):e.set(t,[]),emit:(t,s,o=e.get(t)||[])=>{for(const e of o)e(s)}}))();(()=>{function s(s,o){s===e.EventThemeChanged&&(o.theme_params=t.getThemeParams(o.theme_params)),L.emit(s,o),L.emit("*",{name:s,data:o})}window.TelegramGameProxy_receiveEvent=s,window.Telegram={WebView:{receiveEvent:s}},window.TelegramGameProxy={receiveEvent:s}})();const N=(e,t)=>{L.on(e,t)},A=(e,t)=>{L.off(e,t)},H=(e,t)=>{L.once(e,t)};var V=Object.freeze({__proto__:null,off:A,on:N,once:H});const F="web_app_open_scan_qr_popup",G="web_app_read_text_from_clipboard",U="web_app_request_phone",$="web_app_close",J="web_app_close_scan_qr_popup",j="web_app_data_send",z="web_app_expand",K="iframe_ready",X="web_app_open_invoice",Y="web_app_open_link",Z="web_app_open_popup",ee="web_app_open_tg_link",te="web_app_ready",se="web_app_request_theme",oe="web_app_request_viewport",re="web_app_request_write_access",pe="web_app_set_background_color",ae="web_app_set_header_color",ne="web_app_setup_back_button",ue="web_app_setup_closing_behavior",ie="web_app_setup_main_button",de="web_app_setup_settings_button",_e="web_app_switch_inline_query",ce="web_app_trigger_haptic_feedback",xe="clipboard_text_received",le="custom_method_invoked",he="phone_requested",ge="popup_closed",be="qr_text_received",we="scan_qr_popup_closed";exports.EventBackButtonPressed="back_button_pressed",exports.EventClipboardTextReceived=xe,exports.EventCustomMethodInvoked=le,exports.EventInvoiceClosed="invoice_closed",exports.EventMainButtonPressed="main_button_pressed",exports.EventPhoneRequested=he,exports.EventPopupClosed=ge,exports.EventQrTextReceived=be,exports.EventReloadIframe="reload_iframe",exports.EventScanQrPopupClosed=we,exports.EventSetCustomStyle="set_custom_style",exports.EventSettingsButtonPressed="settings_button_pressed",exports.EventThemeChanged="theme_changed",exports.EventViewportChanged="viewport_changed",exports.EventWriteAccessRequested="write_access_requested",exports.MethodClose=$,exports.MethodCloseScanQrPopup=J,exports.MethodDataSend=j,exports.MethodExpand=z,exports.MethodIframeReady=K,exports.MethodIframeWillReload="iframe_will_reload",exports.MethodInvokeCustomMethod="web_app_invoke_custom_method",exports.MethodOpenInvoice=X,exports.MethodOpenLink=Y,exports.MethodOpenPopup=Z,exports.MethodOpenScanQrPopup=F,exports.MethodOpenTgLink=ee,exports.MethodReadTextFromClipboard=G,exports.MethodReady=te,exports.MethodRequestPhone=U,exports.MethodRequestTheme=se,exports.MethodRequestViewport=oe,exports.MethodRequestWriteAccess=re,exports.MethodSetBackgroundColor=pe,exports.MethodSetHeaderColor=ae,exports.MethodSetupBackButton=ne,exports.MethodSetupClosingBehavior=ue,exports.MethodSetupMainButton=ie,exports.MethodSetupSettingsButton=de,exports.MethodSwitchInlineQuery=_e,exports.MethodTriggerHapticFeedback=ce,exports.NOT_SUPPORTED=p,exports.TG_DESKTOP=r,exports.TG_PHONE=o,exports.TG_WEB=s,exports.bridgeClose=()=>u()?(D($),{status:!0}):(Q($,1),{status:p}),exports.bridgeCloseScanQrPopup=i,exports.bridgeDataSend=e=>_()?(D(j,e),{status:!0}):(Q(j,1),{status:p}),exports.bridgeExpand=()=>c()?(D(z),{status:!0}):(Q(z,1),{status:p}),exports.bridgeGetInitData=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return Q("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s},exports.bridgeIframeReady=e=>x()?(D(K,e),{status:!0}):(Q(K,1),{status:p}),exports.bridgeIframeWillReload=()=>l()?(D(K),{status:!0}):(Q(K,1),{status:p}),exports.bridgeInvokeCustomMethod=async e=>g()?(void 0===e.req_id&&(e.req_id=n()),D(h,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),A(le,o))};N(le,o)}))):(Q(h,1),{status:p}),exports.bridgeOpenInvoice=e=>b()?(D(X,e),{status:!0}):(Q(X,1),{status:p}),exports.bridgeOpenLink=e=>w()?(D(Y,e),{status:!0}):(Q(Y,1),{status:p}),exports.bridgeOpenPopup=async e=>m()?(e.title.length>64&&Q(Z,3),e.message.length<1&&Q(Z,4),e.message.length>256&&Q(Z,5),e.buttons.length<1&&Q(Z,6),e.buttons.length>3&&Q(Z,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&Q(Z,8),D(Z,e),new Promise(((t,s)=>{const o=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),A(ge,o)};N(ge,o)}))):(Q(Z,1),{status:p}),exports.bridgeOpenScanQrPopup=async e=>v()?(D(F,e),new Promise(((t,s)=>{H(be,(s=>{e.is_close&&i(),t({status:!0,data:s})})),H(we,(()=>{t({status:"closed"})}))}))):(Q(F,1),{status:p}),exports.bridgeOpenTgLink=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),S()?(D(ee,e),{status:!0}):(Q(ee,1),{status:p})),exports.bridgeReadTextFromClipboard=async e=>f()?(void 0===e.req_id&&(e.req_id=n()),D(G,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),A(xe,o))};N(xe,o)}))):(Q(G,1),{status:p}),exports.bridgeReady=()=>P()?(D(te),{status:!0}):(Q(te,1),{status:p}),exports.bridgeRequestPhone=async()=>q()?(D(U),new Promise(((e,t)=>{H(he,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(Q(U,1),{status:p}),exports.bridgeRequestTheme=()=>M()?(D(se),{status:!0}):(Q(se,1),{status:p}),exports.bridgeRequestViewport=()=>R()?(D(oe),{status:!0}):(Q(oe,1),{status:p}),exports.bridgeRequestWriteAccess=()=>k()?(D(re),{status:!0}):(Q(re,1),{status:p}),exports.bridgeSetBackgroundColor=e=>y()?(D(pe,e),{status:!0}):(Q(pe,1),{status:p}),exports.bridgeSetHeaderColor=e=>C()?(D(ae,e),{status:!0}):(Q(ae,1),{status:p}),exports.bridgeSetupBackButton=e=>E()?(D(ne,e),{status:!0}):(Q(ne,1),{status:p}),exports.bridgeSetupClosingBehavior=e=>T()?(D(ue,e),{status:!0}):(Q(ue,1),{status:p}),exports.bridgeSetupMainButton=e=>O()?(D(ie,e),{status:!0}):(Q(ie,1),{status:p}),exports.bridgeSetupSettingsButton=e=>B()?(D(de,e),{status:!0}):(Q(de,1),{status:p}),exports.bridgeSwitchInlineQuery=e=>I()?(e.query.length>256&&Q(_e,9),D(_e,e),{status:!0}):(Q(_e,1),{status:p}),exports.bridgeTriggerHapticFeedback=e=>W()?(D(ce,e),{status:!0}):(Q(ce,1),{status:p}),exports.debug=Q,exports.listener=V,exports.sender=D,exports.supportClose=u,exports.supportCloseScanQrPopup=d,exports.supportDataSend=_,exports.supportExpand=c,exports.supportIframeReady=x,exports.supportIframeWillReload=l,exports.supportInvokeCustomMethod=g,exports.supportOpenInvoice=b,exports.supportOpenLink=w,exports.supportOpenPopup=m,exports.supportOpenScanQrPopup=v,exports.supportOpenTgLink=S,exports.supportReadTextFromClipboard=f,exports.supportReady=P,exports.supportRequestPhone=q,exports.supportRequestTheme=M,exports.supportRequestViewport=R,exports.supportRequestWriteAccess=k,exports.supportSetBackgroundColor=y,exports.supportSetHeaderColor=C,exports.supportSetupBackButton=E,exports.supportSetupClosingBehavior=T,exports.supportSetupMainButton=O,exports.supportSetupSettingsButton=B,exports.supportSwitchInlineQuery=I,exports.supportTriggerHapticFeedback=W;
@@ -0,0 +1 @@
1
+ import{EventThemeChanged as e}from"solid";import{getThemeParams as t}from"utils";const s="web",a="phone",o="desktop",n="not_supported",r=(e,t)=>{const n=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(n)>=e&&-1!==t.indexOf((()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(t)?a:["tdesktop","macos"].includes(t)?o:s})())},i=()=>Math.random().toString(36).substring(3,9),_=()=>p()?(pe(fe),{status:!0}):(ie(fe,1),{status:n}),p=()=>r(0,[s,o,a]),u=()=>d()?(pe(ve),{status:!0}):(ie(ve,1),{status:n}),d=()=>r(6.4,[a]),c=e=>b()?(pe(qe,e),{status:!0}):(ie(qe,1),{status:n}),b=()=>r(0,[s,o,a]),g=()=>l()?(pe(ye),{status:!0}):(ie(ye,1),{status:n}),l=()=>r(0,[a]),w=e=>m()?(pe(Pe,e),{status:!0}):(ie(Pe,1),{status:n}),m=()=>r(0,[s]),h=()=>f()?(pe(Pe),{status:!0}):(ie(Pe,1),{status:n}),f=()=>r(0,[s]),v="web_app_invoke_custom_method",q=async e=>y()?(void 0===e.req_id&&(e.req_id=i()),pe(v,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),ce(Ge,a))};de(Ge,a)}))):(ie(v,1),{status:n}),y=()=>r(6.9,[s,o,a]),P=e=>S()?(pe(ke,e),{status:!0}):(ie(ke,1),{status:n}),S=()=>r(6.1,[s,o,a]),k=e=>x()?(pe(xe,e),{status:!0}):(ie(xe,1),{status:n}),x=()=>r(6.4,[s,o,a]),O=async e=>R()?(e.title.length>64&&ie(Oe,3),e.message.length<1&&ie(Oe,4),e.message.length>256&&ie(Oe,5),e.buttons.length<1&&ie(Oe,6),e.buttons.length>3&&ie(Oe,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&ie(Oe,8),pe(Oe,e),new Promise(((t,s)=>{const a=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),ce(He,a)};de(He,a)}))):(ie(Oe,1),{status:n}),R=()=>r(6.2,[s,o,a]),T=async e=>E()?(pe(we,e),new Promise(((t,s)=>{be(ze,(s=>{e.is_close&&u(),t({status:!0,data:s})})),be(Ke,(()=>{t({status:"closed"})}))}))):(ie(we,1),{status:n}),E=()=>r(6.4,[a]),C=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),W()?(pe(Re,e),{status:!0}):(ie(Re,1),{status:n})),W=()=>r(7,[s,o,a]),I=async e=>B()?(void 0===e.req_id&&(e.req_id=i()),pe(me,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),ce($e,a))};de($e,a)}))):(ie(me,1),{status:n}),B=()=>r(6.4,[s,o,a]),D=()=>L()?(pe(Te),{status:!0}):(ie(Te,1),{status:n}),L=()=>r(6.9,[s,o,a]),N=async()=>A()?(pe(he),new Promise(((e,t)=>{be(Fe,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(ie(he,1),{status:n}),A=()=>r(6.9,[s,o,a]),M=()=>U()?(pe(Ee),{status:!0}):(ie(Ee,1),{status:n}),U=()=>r(0,[s,o,a]),V=()=>$()?(pe(Ce),{status:!0}):(ie(Ce,1),{status:n}),$=()=>r(0,[s,o,a]),G=()=>J()?(pe(We),{status:!0}):(ie(We,1),{status:n}),J=()=>r(6.9,[s,o,a]),Q=e=>F()?(pe(Ie,e),{status:!0}):(ie(Ie,1),{status:n}),F=()=>r(6.1,[s,o,a]),H=e=>j()?(pe(Be,e),{status:!0}):(ie(Be,1),{status:n}),j=()=>r(6.1,[s,o,a]),z=e=>K()?(pe(De,e),{status:!0}):(ie(De,1),{status:n}),K=()=>r(6.1,[s,o,a]),X=e=>Y()?(pe(Le,e),{status:!0}):(ie(Le,1),{status:n}),Y=()=>r(0,[s,o,a]),Z=e=>ee()?(pe(Ne,e),{status:!0}):(ie(Ne,1),{status:n}),ee=()=>r(0,[s,o,a]),te=e=>se()?(pe(Ae,e),{status:!0}):(ie(Ae,1),{status:n}),se=()=>r(6.1,[s,o,a]),ae=e=>oe()?(e.query.length>256&&ie(Me,9),pe(Me,e),{status:!0}):(ie(Me,1),{status:n}),oe=()=>r(6.7,[s,o,a]),ne=e=>re()?(pe(Ue,e),{status:!0}):(ie(Ue,1),{status:n}),re=()=>r(6.1,[a]);var ie=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};const _e=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return ie("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s};var pe=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const ue=((e=new Map)=>({once:(t,s,a=e.get(t),o=(e=>{s(e),a&&a.splice(a.indexOf(s)>>>0,1)}))=>a?a.push(o):e.set(t,[o]),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 s(s,a){s===e&&(a.theme_params=t(a.theme_params)),ue.emit(s,a),ue.emit("*",{name:s,data:a})}window.TelegramGameProxy_receiveEvent=s,window.Telegram={WebView:{receiveEvent:s}},window.TelegramGameProxy={receiveEvent:s}})();const de=(e,t)=>{ue.on(e,t)},ce=(e,t)=>{ue.off(e,t)},be=(e,t)=>{ue.once(e,t)};var ge=Object.freeze({__proto__:null,off:ce,on:de,once:be});const le="web_app_invoke_custom_method",we="web_app_open_scan_qr_popup",me="web_app_read_text_from_clipboard",he="web_app_request_phone",fe="web_app_close",ve="web_app_close_scan_qr_popup",qe="web_app_data_send",ye="web_app_expand",Pe="iframe_ready",Se="iframe_will_reload",ke="web_app_open_invoice",xe="web_app_open_link",Oe="web_app_open_popup",Re="web_app_open_tg_link",Te="web_app_ready",Ee="web_app_request_theme",Ce="web_app_request_viewport",We="web_app_request_write_access",Ie="web_app_set_background_color",Be="web_app_set_header_color",De="web_app_setup_back_button",Le="web_app_setup_closing_behavior",Ne="web_app_setup_main_button",Ae="web_app_setup_settings_button",Me="web_app_switch_inline_query",Ue="web_app_trigger_haptic_feedback",Ve="back_button_pressed",$e="clipboard_text_received",Ge="custom_method_invoked",Je="invoice_closed",Qe="main_button_pressed",Fe="phone_requested",He="popup_closed",je="reload_iframe",ze="qr_text_received",Ke="scan_qr_popup_closed",Xe="set_custom_style",Ye="settings_button_pressed",Ze="theme_changed",et="viewport_changed",tt="write_access_requested";export{Ve as EventBackButtonPressed,$e as EventClipboardTextReceived,Ge as EventCustomMethodInvoked,Je as EventInvoiceClosed,Qe as EventMainButtonPressed,Fe as EventPhoneRequested,He as EventPopupClosed,ze as EventQrTextReceived,je as EventReloadIframe,Ke as EventScanQrPopupClosed,Xe as EventSetCustomStyle,Ye as EventSettingsButtonPressed,Ze as EventThemeChanged,et as EventViewportChanged,tt as EventWriteAccessRequested,fe as MethodClose,ve as MethodCloseScanQrPopup,qe as MethodDataSend,ye as MethodExpand,Pe as MethodIframeReady,Se as MethodIframeWillReload,le as MethodInvokeCustomMethod,ke as MethodOpenInvoice,xe as MethodOpenLink,Oe as MethodOpenPopup,we as MethodOpenScanQrPopup,Re as MethodOpenTgLink,me as MethodReadTextFromClipboard,Te as MethodReady,he as MethodRequestPhone,Ee as MethodRequestTheme,Ce as MethodRequestViewport,We as MethodRequestWriteAccess,Ie as MethodSetBackgroundColor,Be as MethodSetHeaderColor,De as MethodSetupBackButton,Le as MethodSetupClosingBehavior,Ne as MethodSetupMainButton,Ae as MethodSetupSettingsButton,Me as MethodSwitchInlineQuery,Ue as MethodTriggerHapticFeedback,n as NOT_SUPPORTED,o as TG_DESKTOP,a as TG_PHONE,s as TG_WEB,_ as bridgeClose,u as bridgeCloseScanQrPopup,c as bridgeDataSend,g as bridgeExpand,_e as bridgeGetInitData,w as bridgeIframeReady,h as bridgeIframeWillReload,q as bridgeInvokeCustomMethod,P as bridgeOpenInvoice,k as bridgeOpenLink,O as bridgeOpenPopup,T as bridgeOpenScanQrPopup,C as bridgeOpenTgLink,I as bridgeReadTextFromClipboard,D as bridgeReady,N as bridgeRequestPhone,M as bridgeRequestTheme,V as bridgeRequestViewport,G as bridgeRequestWriteAccess,Q as bridgeSetBackgroundColor,H as bridgeSetHeaderColor,z as bridgeSetupBackButton,X as bridgeSetupClosingBehavior,Z as bridgeSetupMainButton,te as bridgeSetupSettingsButton,ae as bridgeSwitchInlineQuery,ne as bridgeTriggerHapticFeedback,ie as debug,ge as listener,pe as sender,p as supportClose,d as supportCloseScanQrPopup,b as supportDataSend,l as supportExpand,m as supportIframeReady,f as supportIframeWillReload,y as supportInvokeCustomMethod,S as supportOpenInvoice,x as supportOpenLink,R as supportOpenPopup,E as supportOpenScanQrPopup,W as supportOpenTgLink,B as supportReadTextFromClipboard,L as supportReady,A as supportRequestPhone,U as supportRequestTheme,$ as supportRequestViewport,J as supportRequestWriteAccess,F as supportSetBackgroundColor,j as supportSetHeaderColor,K as supportSetupBackButton,Y as supportSetupClosingBehavior,ee as supportSetupMainButton,se as supportSetupSettingsButton,oe as supportSwitchInlineQuery,re as supportTriggerHapticFeedback};
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@apiteam/twa-bridge/react",
3
+ "main": "index.js",
4
+ "module": "index.mjs",
5
+ "typings": "index.d.ts",
6
+ "browser": {
7
+ "./index.cjs": "index.cjs",
8
+ "./index.js": "index.js"
9
+ },
10
+ "unpkg": "index.cjs",
11
+ "types": "index.d.ts",
12
+ "type": "module",
13
+ "peerDependencies": {
14
+ "react": "^18.0.0",
15
+ "react-dom": "^18.0.0"
16
+ }
17
+ }
package/solid/index.d.ts CHANGED
@@ -7,4 +7,959 @@ declare const createIsViewportChanged: () => solid_js.Accessor<{
7
7
  is_state_stable: boolean;
8
8
  }>;
9
9
 
10
- export { createIsViewportChanged };
10
+ type Close = () => {
11
+ status: boolean | typeof NOT_SUPPORTED;
12
+ };
13
+ /**
14
+ * Closes Mini App.
15
+ *
16
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-close
17
+ */
18
+ declare const close: Close;
19
+ /**
20
+ * Method support check
21
+ */
22
+ declare const supportClose: () => boolean;
23
+
24
+ type CloseScanQrPopup = () => {
25
+ status: boolean | typeof NOT_SUPPORTED;
26
+ };
27
+ /**
28
+ * Closes a QR scanner. The Telegram application creates the scan_qr_popup_closed event.
29
+ *
30
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-close-scan-qr-popup
31
+ */
32
+ declare const closeScanQrPopup: CloseScanQrPopup;
33
+ /**
34
+ * Method support check
35
+ */
36
+ declare const supportCloseScanQrPopup: () => boolean;
37
+
38
+ type DataSend = (eventData: {
39
+ /**
40
+ * Data to send to a bot. Should not have size of more than 4096 bytes.
41
+ */
42
+ data: string;
43
+ }) => {
44
+ status: boolean | typeof NOT_SUPPORTED;
45
+ };
46
+ /**
47
+ * Sends data to the bot. When this method is called, a service message is sent to the bot containing the data of the length up to 4096 bytes.
48
+ *
49
+ * Then, Mini App will be closed.
50
+ *
51
+ * To get more information, take a look at web_app_data field in the class Message.
52
+ *
53
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-data-send
54
+ */
55
+ declare const dataSend: DataSend;
56
+ /**
57
+ * Method support check
58
+ */
59
+ declare const supportDataSend: () => boolean;
60
+
61
+ type Expand = () => {
62
+ status: boolean | typeof NOT_SUPPORTED;
63
+ };
64
+ /**
65
+ * Closes Mini App.
66
+ */
67
+ declare const expand: Expand;
68
+ /**
69
+ * Method support check
70
+ */
71
+ declare const supportExpand: () => boolean;
72
+
73
+ type IframeReady = (eventData: {
74
+ /**
75
+ * Optional. True, if current Mini App supports native reloading.
76
+ */
77
+ reload_supported?: boolean;
78
+ }) => {
79
+ status: boolean | typeof NOT_SUPPORTED;
80
+ };
81
+ /**
82
+ * Notifies parent iframe about the current frame is ready.
83
+ * This method is only used in the Web version of Telegram.
84
+ * As a result, Mini App will receive set_custom_style event.
85
+ *
86
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#iframe-ready
87
+ */
88
+ declare const iframeReady: IframeReady;
89
+ /**
90
+ * Method support check
91
+ */
92
+ declare const supportIframeReady: () => boolean;
93
+
94
+ type IframeWillReload = () => {
95
+ status: boolean | typeof NOT_SUPPORTED;
96
+ };
97
+ /**
98
+ * Notifies parent iframe about the current iframe is going to reload.
99
+ *
100
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#iframe-will-reload
101
+ */
102
+ declare const iframeWillReload: IframeWillReload;
103
+ /**
104
+ * Method support check
105
+ */
106
+ declare const supportIframeWillReload: () => boolean;
107
+
108
+ type InvokeCustomMethod = (eventData: {
109
+ /**
110
+ * Current invocation unique identifier.
111
+ *
112
+ * Default: () => randomReqId
113
+ */
114
+ req_id?: string;
115
+ /**
116
+ * Method name.
117
+ */
118
+ method: string;
119
+ /**
120
+ * Parameters according to method.
121
+ */
122
+ params: unknown;
123
+ }) => Promise<{
124
+ status: boolean | typeof NOT_SUPPORTED;
125
+ data?: EventsData[typeof EventCustomMethodInvoked];
126
+ }>;
127
+ /**
128
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-invoke-custom-method
129
+ */
130
+ declare const invokeCustomMethod: InvokeCustomMethod;
131
+ /**
132
+ * Method support check
133
+ */
134
+ declare const supportInvokeCustomMethod: () => boolean;
135
+
136
+ type OpenInvoice = (eventData: {
137
+ /**
138
+ * Invoice unique identifier.
139
+ */
140
+ slug: string;
141
+ }) => {
142
+ status: boolean | typeof NOT_SUPPORTED;
143
+ };
144
+ /**
145
+ * Opens an invoice by its specified slug.
146
+ *
147
+ * More information about invoices in this documentation.
148
+ *
149
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-invoice
150
+ */
151
+ declare const openInvoice: OpenInvoice;
152
+ /**
153
+ * Method support check
154
+ */
155
+ declare const supportOpenInvoice: () => boolean;
156
+
157
+ type OpenLink = (eventData: {
158
+ /**
159
+ * URL to be opened by Telegram application. Should be a full path with https protocol.
160
+ */
161
+ url: string;
162
+ /**
163
+ * Optional. Link will be opened in Instant View mode if possible.
164
+ */
165
+ try_instant_view?: boolean;
166
+ }) => {
167
+ status: boolean | typeof NOT_SUPPORTED;
168
+ };
169
+ /**
170
+ * Opens link in the default browser.
171
+ *
172
+ * Mini App will not be closed.
173
+ *
174
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-link
175
+ */
176
+ declare const openLink: OpenLink;
177
+ /**
178
+ * Method support check
179
+ */
180
+ declare const supportOpenLink: () => boolean;
181
+
182
+ type PopupButton = {
183
+ /**
184
+ * Identifier of the button, 0-64 characters.
185
+ */
186
+ id: string;
187
+ type: 'default' | 'destructive' | 'ok' | 'close' | 'cancel';
188
+ /**
189
+ * The text to be displayed on the button, 0-64 characters. Ignored when type is ok, close or cancel.
190
+ */
191
+ text: string;
192
+ };
193
+ type OpenPopup = (eventData: {
194
+ /**
195
+ * The text to be displayed in the popup title, 0-64 characters
196
+ */
197
+ title: string;
198
+ /**
199
+ * The message to be displayed in the body of the popup, 1-256 characters
200
+ */
201
+ message: string;
202
+ /**
203
+ * List of buttons to be displayed in the popup, 1-3 buttons
204
+ */
205
+ buttons: PopupButton[];
206
+ }) => Promise<{
207
+ status: boolean | typeof NOT_SUPPORTED;
208
+ data?: EventsData['popup_closed'];
209
+ }>;
210
+ /**
211
+ * Opens a new popup. When user closes the popup, Telegram creates the popup_closed event.
212
+ *
213
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-popup
214
+ */
215
+ declare const openPopup: OpenPopup;
216
+ /**
217
+ * Method support check
218
+ */
219
+ declare const supportOpenPopup: () => boolean;
220
+
221
+ type OpenScanQrPopup = (eventData: {
222
+ /**
223
+ * Optional. Text to be displayed in the QR scanner.
224
+ */
225
+ text?: string;
226
+ /**
227
+ * [Custom] Optional. Сlose QR scanner after receiving data
228
+ */
229
+ is_close?: boolean;
230
+ }) => Promise<{
231
+ status: boolean | typeof NOT_SUPPORTED | 'closed';
232
+ data?: EventsData[typeof EventQrTextReceived];
233
+ }>;
234
+ /**
235
+ * Opens a QR scanner.
236
+ *
237
+ * When the scanner was closed, the Telegram application creates the scan_qr_popup_closed event.
238
+ *
239
+ * When the scanner reads QR, Telegram creates the qr_text_received event.
240
+ *
241
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-close-scan-qr-popup
242
+ */
243
+ declare const openScanQrPopup: OpenScanQrPopup;
244
+ /**
245
+ * Method support check
246
+ */
247
+ declare const supportOpenScanQrPopup: () => boolean;
248
+
249
+ type OpenTgLink = (eventData: {
250
+ /**
251
+ * Should be a value taken from the link of this format: https://t.me/{path_full}.
252
+ *
253
+ * Can additionally contain query parameters.
254
+ */
255
+ path_full: string;
256
+ }) => {
257
+ status: boolean | typeof NOT_SUPPORTED;
258
+ };
259
+ /**
260
+ * Opens the Telegram link by its pathname and query parameters.
261
+ *
262
+ * The link will be opened in the Telegram app, Mini App will be closed.
263
+ *
264
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-open-tg-link
265
+ */
266
+ declare const openTgLink: OpenTgLink;
267
+ /**
268
+ * Method support check
269
+ */
270
+ declare const supportOpenTgLink: () => boolean;
271
+
272
+ type ReadTextFromClipboard = (eventData: {
273
+ /**
274
+ * Unique request identifier. Should be any unique string to handle the generated event appropriately.
275
+ *
276
+ * Default: () => randomReqId
277
+ */
278
+ req_id?: string;
279
+ }) => Promise<{
280
+ status: boolean | typeof NOT_SUPPORTED;
281
+ data?: EventsData[typeof EventClipboardTextReceived];
282
+ }>;
283
+ /**
284
+ * Reads text from the clipboard.
285
+ *
286
+ * The method accepts a request identifier which is used to appropriately retrieve the method execution result from the clipboard_text_received event.
287
+ *
288
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-read-text-from-clipboard
289
+ */
290
+ declare const readTextFromClipboard: ReadTextFromClipboard;
291
+ /**
292
+ * Method support check
293
+ */
294
+ declare const supportReadTextFromClipboard: () => boolean;
295
+
296
+ type Ready = () => {
297
+ status: boolean | typeof NOT_SUPPORTED;
298
+ };
299
+ /**
300
+ * Notifies Telegram about current application is ready to be shown.
301
+ *
302
+ * This method will make Telegram to remove application loader and display Mini App.
303
+ *
304
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-ready
305
+ */
306
+ declare const ready: Ready;
307
+ /**
308
+ * Method support check
309
+ */
310
+ declare const supportReady: () => boolean;
311
+
312
+ type RequestPhone = () => Promise<{
313
+ status: boolean | typeof NOT_SUPPORTED;
314
+ }>;
315
+ /**
316
+ * Requests access to current user's phone.
317
+ *
318
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-phone
319
+ */
320
+ declare const requestPhone: RequestPhone;
321
+ /**
322
+ * Method support check
323
+ */
324
+ declare const supportRequestPhone: () => boolean;
325
+
326
+ type RequestTheme = () => {
327
+ status: boolean | typeof NOT_SUPPORTED;
328
+ };
329
+ /**
330
+ * Requests current theme from Telegram.
331
+ *
332
+ * As a result, Telegram will create theme_changed event.
333
+ *
334
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-theme
335
+ */
336
+ declare const requestTheme: RequestTheme;
337
+ /**
338
+ * Method support check
339
+ */
340
+ declare const supportRequestTheme: () => boolean;
341
+
342
+ type RequestViewport = () => {
343
+ status: boolean | typeof NOT_SUPPORTED;
344
+ };
345
+ /**
346
+ * Requests current viewport information from Telegram.
347
+ *
348
+ * As a result, Telegram will create viewport_changed event.
349
+ *
350
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-viewport
351
+ */
352
+ declare const requestViewport: RequestViewport;
353
+ /**
354
+ * Method support check
355
+ */
356
+ declare const supportRequestViewport: () => boolean;
357
+
358
+ type RequestWriteAccess = () => {
359
+ status: boolean | typeof NOT_SUPPORTED;
360
+ };
361
+ /**
362
+ * Requests write message access to current user.
363
+ *
364
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-request-viewport
365
+ */
366
+ declare const requestWriteAccess: RequestWriteAccess;
367
+ /**
368
+ * Method support check
369
+ */
370
+ declare const supportRequestWriteAccess: () => boolean;
371
+
372
+ type SetBackgroundColor = (eventData: {
373
+ /**
374
+ * The Mini App background color in #RRGGBB format.
375
+ */
376
+ color: string;
377
+ }) => {
378
+ status: boolean | typeof NOT_SUPPORTED;
379
+ };
380
+ /**
381
+ * Updates the Mini App background color.
382
+ *
383
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-set-background-color
384
+ */
385
+ declare const setBackgroundColor: SetBackgroundColor;
386
+ /**
387
+ * Method support check
388
+ */
389
+ declare const supportSetBackgroundColor: () => boolean;
390
+
391
+ type SetHeaderColor = (eventData: {
392
+ /**
393
+ * The Mini App header color key. Could be either bg_color or secondary_bg_color.
394
+ */
395
+ color_key: 'bg_color' | 'secondary_bg_color';
396
+ /**
397
+ * Color in RGB format.
398
+ */
399
+ color: string;
400
+ }) => {
401
+ status: boolean | typeof NOT_SUPPORTED;
402
+ };
403
+ /**
404
+ * Updates the Mini App header color. This method should accept color_key or color property.
405
+ *
406
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-set-header-color
407
+ */
408
+ declare const setHeaderColor: SetHeaderColor;
409
+ /**
410
+ * Method support check
411
+ */
412
+ declare const supportSetHeaderColor: () => boolean;
413
+
414
+ type SetupBackButton = (eventData: {
415
+ /**
416
+ * Should the Back Button be visible.
417
+ */
418
+ is_visible: boolean;
419
+ }) => {
420
+ status: boolean | typeof NOT_SUPPORTED;
421
+ };
422
+ /**
423
+ * Updates the Back Button settings.
424
+ *
425
+ * https://docs.telegram-mini-apps.com/platform/ui/back-button
426
+ */
427
+ declare const setupBackButton: SetupBackButton;
428
+ /**
429
+ * Method support check
430
+ */
431
+ declare const supportSetupBackButton: () => boolean;
432
+
433
+ type SetupClosingBehavior = (eventData: {
434
+ /**
435
+ * Will user be prompted in case, an application is going to be closed.
436
+ */
437
+ need_confirmation: boolean;
438
+ }) => {
439
+ status: boolean | typeof NOT_SUPPORTED;
440
+ };
441
+ /**
442
+ * Updates current closing behavior.
443
+ *
444
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-setup-closing-behavior
445
+ */
446
+ declare const setupClosingBehavior: SetupClosingBehavior;
447
+ /**
448
+ * Method support check
449
+ */
450
+ declare const supportSetupClosingBehavior: () => boolean;
451
+
452
+ type SetupMainButton = (eventData: {
453
+ /**
454
+ * Optional. Should the Main Button be displayed.
455
+ */
456
+ is_visible?: boolean;
457
+ /**
458
+ * Optional. Should the Main Button be enabled.
459
+ */
460
+ is_active?: boolean;
461
+ /**
462
+ * Optional. Should loader inside the Main Button be displayed. Use this property in case, some operation takes time. This loader will make user notified about it.
463
+ */
464
+ is_progress_visible?: boolean;
465
+ /**
466
+ * Optional. Text inside the Main Button.
467
+ */
468
+ text?: string;
469
+ /**
470
+ * Optional. The Main Button background color in #RRGGBB format.
471
+ */
472
+ color?: string;
473
+ /**
474
+ * Optional. The Main Button text color in #RRGGBB format.
475
+ */
476
+ text_color?: string;
477
+ }) => {
478
+ status: boolean | typeof NOT_SUPPORTED;
479
+ };
480
+ /**
481
+ * Updates the Main Button settings.
482
+ *
483
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-setup-main-button
484
+ */
485
+ declare const setupMainButton: SetupMainButton;
486
+ /**
487
+ * Method support check
488
+ */
489
+ declare const supportSetupMainButton: () => boolean;
490
+
491
+ type SetupSettingsButton = (eventData: {
492
+ /**
493
+ * Should the Settings Button be displayed.
494
+ */
495
+ is_visible: boolean;
496
+ }) => {
497
+ status: boolean | typeof NOT_SUPPORTED;
498
+ };
499
+ /**
500
+ * Updates current state of Settings Button.
501
+ *
502
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-setup-settings-button
503
+ */
504
+ declare const setupSettingsButton: SetupSettingsButton;
505
+ /**
506
+ * Method support check
507
+ */
508
+ declare const supportSetupSettingsButton: () => boolean;
509
+
510
+ type SwitchInlineQuery = (eventData: {
511
+ /**
512
+ * Text which should be inserted in the input after the current bot name. Max length is 256 symbols.
513
+ */
514
+ query: string;
515
+ /**
516
+ * List of chat types which could be chosen to send the message. Could be empty list. Values:
517
+ *
518
+ * users, bots, groups, channels
519
+ */
520
+ chat_types: ['users', 'bots', 'groups', 'channels'];
521
+ }) => {
522
+ status: boolean | typeof NOT_SUPPORTED;
523
+ };
524
+ /**
525
+ * Inserts the bot's username and the specified inline query in the current chat's input field.
526
+ *
527
+ * Query may be empty, in which case only the bot's username will be inserted.
528
+ *
529
+ * The client prompts the user to choose a specific chat, then opens that chat and inserts the bot's username and the specified inline query in the input field.
530
+ *
531
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-switch-inline-query
532
+ */
533
+ declare const switchInlineQuery: SwitchInlineQuery;
534
+ /**
535
+ * Method support check
536
+ */
537
+ declare const supportSwitchInlineQuery: () => boolean;
538
+
539
+ type TriggerHapticFeedback = (eventData: {
540
+ /**
541
+ * Type of haptic event. Values:
542
+ *
543
+ * impact - when there's a collision involving UI components.
544
+ *
545
+ * notification - when some action execution has been completed.
546
+ *
547
+ * selection_change - when the user changes their selection.
548
+ */
549
+ type: 'impact' | 'notification' | 'selection_change';
550
+ /**
551
+ * Required when type is impact. Values:
552
+ *
553
+ * light - indicates a collision between small or lightweight UI objects
554
+ *
555
+ * medium - indicates a collision between medium-sized or medium-weight UI objects
556
+ *
557
+ * heavy - indicates a collision between large or heavyweight UI objects
558
+ *
559
+ * rigid - indicates a collision between hard or inflexible UI objects
560
+ *
561
+ * soft - indicates a collision between soft or flexible UI objects
562
+ */
563
+ impact_style: 'light' | 'medium' | 'heavy' | 'rigid' | 'soft';
564
+ /**
565
+ * Required when type is notification. Values:
566
+ *
567
+ * error - indicates that a task or action has failed
568
+ *
569
+ * success - indicates that a task or action has completed successfully
570
+ *
571
+ * warning - indicates that a task or action produced a warning
572
+ */
573
+ notification_type: 'error' | 'success' | 'warning';
574
+ }) => {
575
+ status: boolean | typeof NOT_SUPPORTED;
576
+ };
577
+ /**
578
+ * Generates the haptic feedback event.
579
+ *
580
+ * Original: https://docs.telegram-mini-apps.com/platform/apps-communication/methods#web-app-trigger-haptic-feedback
581
+ */
582
+ declare const triggerHapticFeedback: TriggerHapticFeedback;
583
+ /**
584
+ * Method support check
585
+ */
586
+ declare const supportTriggerHapticFeedback: () => boolean;
587
+
588
+ type User = {
589
+ /**
590
+ * Optional. True, if this user added the bot to the attachment menu.
591
+ */
592
+ added_to_attachment_menu?: boolean;
593
+ /**
594
+ * Optional. True, if this user allowed the bot to message them.
595
+ */
596
+ allows_write_to_pm?: boolean;
597
+ /**
598
+ * Optional. Has the user purchased Telegram Premium.
599
+ */
600
+ is_premium?: boolean;
601
+ /**
602
+ * Bot or user name.
603
+ */
604
+ first_name: string;
605
+ /**
606
+ * Bot or user ID.
607
+ */
608
+ id: number;
609
+ /**
610
+ * Optional. Is the user a bot.
611
+ */
612
+ is_bot?: boolean;
613
+ /**
614
+ * Optional. User's last name.
615
+ */
616
+ last_name?: string;
617
+ /**
618
+ * Optional. IETF user's language.
619
+ */
620
+ language_code: string;
621
+ /**
622
+ * Optional. Link to the user's or bot's photo.
623
+ *
624
+ * Photos can have formats .jpeg and .svg.
625
+ *
626
+ * It is returned only for Mini Apps opened through the attachment menu.
627
+ */
628
+ photo_url?: string;
629
+ /**
630
+ * Optional. Login of the bot or user.
631
+ */
632
+ username?: string;
633
+ };
634
+ type Chat = {
635
+ /**
636
+ * Unique chat ID.
637
+ */
638
+ id: number;
639
+ /**
640
+ * Chat type. Values:
641
+ *
642
+ * group, supergroup, channel
643
+ */
644
+ type: 'group' | 'supergroup' | 'channel';
645
+ /**
646
+ * Chat title.
647
+ */
648
+ title: string;
649
+ /**
650
+ * Optional. Chat photo link. The photo can have .jpeg and .svg formats.
651
+ *
652
+ * It is returned only for Mini Apps opened through the attachments menu.
653
+ */
654
+ photo_url?: string;
655
+ /**
656
+ * Optional. Chat user login.
657
+ */
658
+ username?: string;
659
+ };
660
+ type GetInitData = () => null | {
661
+ /**
662
+ * The date the initialization data was created.
663
+ *
664
+ * Is a number representing a Unix timestamp.
665
+ */
666
+ auth_date: number;
667
+ /**
668
+ * Optional. The number of seconds after which a message can be sent via the method answerWebAppQuery.
669
+ */
670
+ can_send_after?: number;
671
+ /**
672
+ * Optional. An object containing information about the chat with the bot in which the Mini Apps was launched.
673
+ *
674
+ * It is returned only for Mini Apps opened through the attachments menu.
675
+ */
676
+ chat?: Chat;
677
+ /**
678
+ * Optional. The type of chat from which the Mini Apps was opened. Values:
679
+ *
680
+ * sender, private, group, supergroup, channel
681
+ *
682
+ * Returned only for applications opened by direct link.
683
+ */
684
+ chat_type?: 'sender' | 'private' | 'group' | 'supergroup' | 'channel';
685
+ /**
686
+ * Optional. A global identifier indicating the chat from which the Mini Apps was opened.
687
+ *
688
+ * Returned only for applications opened by direct link.
689
+ */
690
+ chat_instance?: string;
691
+ /**
692
+ * Initialization data signature.
693
+ */
694
+ hash: string;
695
+ /**
696
+ * Optional. The unique session ID of the Mini App. Used in the process of sending a message via the method answerWebAppQuery.
697
+ */
698
+ query_id?: string;
699
+ /**
700
+ * Optional. An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu.
701
+ *
702
+ * Returned only for private chats and only for Mini Apps launched via the attachment menu.
703
+ */
704
+ receiver?: User;
705
+ /**
706
+ * Optional. The value of the startattach or startapp query parameter specified in the link. It is returned only for Mini Apps opened through the attachment menu.
707
+ */
708
+ start_param?: string;
709
+ /**
710
+ * Optional. An object containing information about the current user.
711
+ */
712
+ user?: User;
713
+ };
714
+ /**
715
+ * In the list of launch parameters, initialization data is located in the tgWebAppData parameter.
716
+ *
717
+ * It is a set of data mostly related to a specific user who launched the Mini App.
718
+ *
719
+ * Original: https://docs.telegram-mini-apps.com/platform/launch-parameters/init-data#init-data
720
+ */
721
+ declare const getInitData: GetInitData;
722
+
723
+ type Sender = (eventType: string, eventData?: any) => void;
724
+ /**
725
+ * EDIT
726
+ *
727
+ * window.parent.postMessage(JSON.stringify({ eventType, eventData }), 'https://web.telegram.org');
728
+ * window['TelegramWebviewProxy'].postEvent(eventType, JSON.stringify(eventData));
729
+ */
730
+ declare const sender: Sender;
731
+
732
+ type Debug = (methondName: string, errorId: number) => void;
733
+ declare const debug: Debug;
734
+
735
+ type EventsData = {
736
+ /**
737
+ * User clicked the Back Button.
738
+ */
739
+ "back_button_pressed": undefined;
740
+ /**
741
+ * Telegram application attempted to extract text from clipboard.
742
+ */
743
+ "clipboard_text_received": {
744
+ /**
745
+ * Passed during the web_app_read_text_from_clipboard method invocation req_id value.
746
+ */
747
+ req_id: string;
748
+ /**
749
+ * Optional. Data extracted from the clipboard. The returned value will have the type string only in the case, application has access to the clipboard.
750
+ */
751
+ data?: string | null;
752
+ };
753
+ /**
754
+ * Custom method invocation completed.
755
+ */
756
+ "custom_method_invoked": {
757
+ /**
758
+ * Unique identifier of this invocation.
759
+ */
760
+ req_id: string;
761
+ /**
762
+ * Optional. Method invocation successful result.
763
+ */
764
+ result?: unknown;
765
+ /**
766
+ * Optional. Method invocation error code.
767
+ */
768
+ error?: string;
769
+ };
770
+ /**
771
+ * An invoice was closed.
772
+ */
773
+ "invoice_closed": {
774
+ /**
775
+ * Passed during the web_app_open_invoice method invocation slug value.
776
+ */
777
+ slug: string;
778
+ /**
779
+ * Invoice status. Values:
780
+ *
781
+ * paid - invoice was paid
782
+ *
783
+ * failed - invoice failed
784
+ *
785
+ * pending - invoice is currently pending
786
+ *
787
+ * cancelled - invoice was cancelled
788
+ */
789
+ status: 'paid' | 'failed' | 'pending' | 'cancelled';
790
+ };
791
+ /**
792
+ * User clicked the Main Button.
793
+ */
794
+ "main_button_pressed": undefined;
795
+ /**
796
+ * Application received phone access request status.
797
+ */
798
+ "phone_requested": {
799
+ /**
800
+ * Request status. Can only be sent
801
+ */
802
+ status: 'sent';
803
+ };
804
+ /**
805
+ * Popup was closed.
806
+ */
807
+ "popup_closed": {
808
+ /**
809
+ * Optional. Identifier of the clicked button.
810
+ *
811
+ * In case, the popup was closed without clicking any button, this property will be omitted.
812
+ */
813
+ button_id?: string;
814
+ };
815
+ /**
816
+ * Parent iframe requested current iframe reload.
817
+ */
818
+ "reload_iframe": undefined;
819
+ /**
820
+ * The QR scanner scanned some QR and extracted its content.
821
+ */
822
+ "qr_text_received": {
823
+ /**
824
+ * Optional. Data extracted from the QR.
825
+ */
826
+ data?: string;
827
+ };
828
+ /**
829
+ * QR scanner was closed.
830
+ */
831
+ "scan_qr_popup_closed": undefined;
832
+ /**
833
+ * The event which is usually sent by the Telegram web application.
834
+ *
835
+ * Its payload represents <style/> tag html content, a developer could use. The stylesheet described in the payload will help the developer to stylize the app scrollbar (but he is still able to do it himself).
836
+ */
837
+ "set_custom_style": undefined;
838
+ /**
839
+ * Occurs when the Settings Button was pressed.
840
+ */
841
+ "settings_button_pressed": undefined;
842
+ /**
843
+ * Occurs whenever the theme was changed in the user's Telegram app ( including switching to night mode).
844
+ */
845
+ "theme_changed": {
846
+ /**
847
+ * Map where the key is a theme stylesheet key and value is the corresponding color in #RRGGBB format.
848
+ */
849
+ theme_params: Record<string, string>;
850
+ };
851
+ /**
852
+ * Occurs whenever the viewport has been changed.
853
+ *
854
+ * For example, when the user started dragging the application or called the expansion method.
855
+ */
856
+ "viewport_changed": {
857
+ /**
858
+ * The viewport height.
859
+ */
860
+ height: number;
861
+ /**
862
+ * Optional. The viewport width.
863
+ */
864
+ width?: number;
865
+ /**
866
+ * Is the viewport currently expanded.
867
+ */
868
+ is_expanded: boolean;
869
+ /**
870
+ * Is the viewport current state stable and not going to change in the next moment.
871
+ */
872
+ is_state_stable: boolean;
873
+ };
874
+ /**
875
+ * Application received write access request status.
876
+ */
877
+ "write_access_requested": {
878
+ /**
879
+ * Request status. Can only be allowed.
880
+ */
881
+ status: 'allowed';
882
+ };
883
+ };
884
+ interface TelegramGameProxy {
885
+ receiveEvent: (event: string, data: string) => void;
886
+ }
887
+ interface TelegramWebviewProxy {
888
+ postEvent: (event: string, data: string) => void;
889
+ }
890
+ declare global {
891
+ interface External {
892
+ notify: (event: string) => void;
893
+ }
894
+ interface Window {
895
+ TelegramWebviewProxy: TelegramWebviewProxy;
896
+ TelegramGameProxy: TelegramGameProxy;
897
+ TelegramGameProxy_receiveEvent: TelegramGameProxy["receiveEvent"];
898
+ Telegram: {
899
+ WebView: TelegramGameProxy;
900
+ };
901
+ }
902
+ }
903
+ type Listened = <T extends EventsData, E extends keyof T, D extends T[E]>(eventName: E, callback: (eventData: D) => void) => void;
904
+ declare const on: Listened;
905
+ declare const off: Listened;
906
+ declare const once: Listened;
907
+
908
+ type listener_EventsData = EventsData;
909
+ declare const listener_off: typeof off;
910
+ declare const listener_on: typeof on;
911
+ declare const listener_once: typeof once;
912
+ declare namespace listener {
913
+ export { type listener_EventsData as EventsData, listener_off as off, listener_on as on, listener_once as once };
914
+ }
915
+
916
+ declare const TG_WEB = "web";
917
+ declare const TG_PHONE = "phone";
918
+ declare const TG_DESKTOP = "desktop";
919
+
920
+ declare const NOT_SUPPORTED = "not_supported";
921
+
922
+ declare const MethodInvokeCustomMethod = "web_app_invoke_custom_method";
923
+ declare const MethodOpenScanQrPopup = "web_app_open_scan_qr_popup";
924
+ declare const MethodReadTextFromClipboard = "web_app_read_text_from_clipboard";
925
+ declare const MethodRequestPhone = "web_app_request_phone";
926
+ declare const MethodClose = "web_app_close";
927
+ declare const MethodCloseScanQrPopup = "web_app_close_scan_qr_popup";
928
+ declare const MethodDataSend = "web_app_data_send";
929
+ declare const MethodExpand = "web_app_expand";
930
+ declare const MethodIframeReady = "iframe_ready";
931
+ declare const MethodIframeWillReload = "iframe_will_reload";
932
+ declare const MethodOpenInvoice = "web_app_open_invoice";
933
+ declare const MethodOpenLink = "web_app_open_link";
934
+ declare const MethodOpenPopup = "web_app_open_popup";
935
+ declare const MethodOpenTgLink = "web_app_open_tg_link";
936
+ declare const MethodReady = "web_app_ready";
937
+ declare const MethodRequestTheme = "web_app_request_theme";
938
+ declare const MethodRequestViewport = "web_app_request_viewport";
939
+ declare const MethodRequestWriteAccess = "web_app_request_write_access";
940
+ declare const MethodSetBackgroundColor = "web_app_set_background_color";
941
+ declare const MethodSetHeaderColor = "web_app_set_header_color";
942
+ declare const MethodSetupBackButton = "web_app_setup_back_button";
943
+ declare const MethodSetupClosingBehavior = "web_app_setup_closing_behavior";
944
+ declare const MethodSetupMainButton = "web_app_setup_main_button";
945
+ declare const MethodSetupSettingsButton = "web_app_setup_settings_button";
946
+ declare const MethodSwitchInlineQuery = "web_app_switch_inline_query";
947
+ declare const MethodTriggerHapticFeedback = "web_app_trigger_haptic_feedback";
948
+
949
+ declare const EventBackButtonPressed = "back_button_pressed";
950
+ declare const EventClipboardTextReceived = "clipboard_text_received";
951
+ declare const EventCustomMethodInvoked = "custom_method_invoked";
952
+ declare const EventInvoiceClosed = "invoice_closed";
953
+ declare const EventMainButtonPressed = "main_button_pressed";
954
+ declare const EventPhoneRequested = "phone_requested";
955
+ declare const EventPopupClosed = "popup_closed";
956
+ declare const EventReloadIframe = "reload_iframe";
957
+ declare const EventQrTextReceived = "qr_text_received";
958
+ declare const EventScanQrPopupClosed = "scan_qr_popup_closed";
959
+ declare const EventSetCustomStyle = "set_custom_style";
960
+ declare const EventSettingsButtonPressed = "settings_button_pressed";
961
+ declare const EventThemeChanged = "theme_changed";
962
+ declare const EventViewportChanged = "viewport_changed";
963
+ declare const EventWriteAccessRequested = "write_access_requested";
964
+
965
+ export { EventBackButtonPressed, EventClipboardTextReceived, EventCustomMethodInvoked, EventInvoiceClosed, EventMainButtonPressed, EventPhoneRequested, EventPopupClosed, EventQrTextReceived, EventReloadIframe, EventScanQrPopupClosed, EventSetCustomStyle, EventSettingsButtonPressed, EventThemeChanged, EventViewportChanged, EventWriteAccessRequested, type EventsData, MethodClose, MethodCloseScanQrPopup, MethodDataSend, MethodExpand, MethodIframeReady, MethodIframeWillReload, MethodInvokeCustomMethod, MethodOpenInvoice, MethodOpenLink, MethodOpenPopup, MethodOpenScanQrPopup, MethodOpenTgLink, MethodReadTextFromClipboard, MethodReady, MethodRequestPhone, MethodRequestTheme, MethodRequestViewport, MethodRequestWriteAccess, MethodSetBackgroundColor, MethodSetHeaderColor, MethodSetupBackButton, MethodSetupClosingBehavior, MethodSetupMainButton, MethodSetupSettingsButton, MethodSwitchInlineQuery, MethodTriggerHapticFeedback, NOT_SUPPORTED, TG_DESKTOP, TG_PHONE, TG_WEB, close as bridgeClose, closeScanQrPopup as bridgeCloseScanQrPopup, dataSend as bridgeDataSend, expand as bridgeExpand, getInitData as bridgeGetInitData, iframeReady as bridgeIframeReady, iframeWillReload as bridgeIframeWillReload, invokeCustomMethod as bridgeInvokeCustomMethod, openInvoice as bridgeOpenInvoice, openLink as bridgeOpenLink, openPopup as bridgeOpenPopup, openScanQrPopup as bridgeOpenScanQrPopup, openTgLink as bridgeOpenTgLink, readTextFromClipboard as bridgeReadTextFromClipboard, ready as bridgeReady, requestPhone as bridgeRequestPhone, requestTheme as bridgeRequestTheme, requestViewport as bridgeRequestViewport, requestWriteAccess as bridgeRequestWriteAccess, setBackgroundColor as bridgeSetBackgroundColor, setHeaderColor as bridgeSetHeaderColor, setupBackButton as bridgeSetupBackButton, setupClosingBehavior as bridgeSetupClosingBehavior, setupMainButton as bridgeSetupMainButton, setupSettingsButton as bridgeSetupSettingsButton, switchInlineQuery as bridgeSwitchInlineQuery, triggerHapticFeedback as bridgeTriggerHapticFeedback, createIsViewportChanged, debug, listener, sender, supportClose, supportCloseScanQrPopup, supportDataSend, supportExpand, supportIframeReady, supportIframeWillReload, supportInvokeCustomMethod, supportOpenInvoice, supportOpenLink, supportOpenPopup, supportOpenScanQrPopup, supportOpenTgLink, supportReadTextFromClipboard, supportReady, supportRequestPhone, supportRequestTheme, supportRequestViewport, supportRequestWriteAccess, supportSetBackgroundColor, supportSetHeaderColor, supportSetupBackButton, supportSetupClosingBehavior, supportSetupMainButton, supportSetupSettingsButton, supportSwitchInlineQuery, supportTriggerHapticFeedback };
package/solid/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("solid-js");var t=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const n=((e=new Map)=>({once:(t,n,i=e.get(t),o=(e=>{n(e),i&&i.splice(i.indexOf(n)>>>0,1)}))=>i?i.push(o):e.set(t,[o]),on:(t,n,i=e.get(t))=>i?i.push(n):e.set(t,[n]),off:(t,n,i=e.get(t))=>i&&n?i.splice(i.indexOf(n)>>>0,1):e.set(t,[]),emit:(t,n,i=e.get(t)||[])=>{for(const e of i)e(n)}}))(),i=()=>{function e(e,t){n.emit(e,t),n.emit("*",{name:e,data:t})}window.TelegramGameProxy_receiveEvent=e,window.Telegram={WebView:{receiveEvent:e}},window.TelegramGameProxy={receiveEvent:e}};i();const o=(e,t)=>{n.on(e,t)},r=(e,t)=>{n.off(e,t)};const a="web_app_request_viewport",s="viewport_changed";exports.createIsViewportChanged=()=>{const[n,i]=e.createSignal({height:0,is_expanded:!1,is_state_stable:!1}),w=e=>i(e);return e.onMount((()=>{o(s,w),t(a)})),e.onCleanup((()=>{r(s,w)})),n};
1
+ "use strict";var e=require("solid"),t=require("utils"),s=require("solid-js");const o="web",r="phone",p="desktop",a="not_supported",n=(e,t)=>{const s=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(s)>=e&&-1!==t.indexOf((()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(t)?r:["tdesktop","macos"].includes(t)?p:o})())},i=()=>Math.random().toString(36).substring(3,9),u=()=>n(0,[o,p,r]),d=()=>_()?(L(j),{status:!0}):(D(j,1),{status:a}),_=()=>n(6.4,[r]),c=()=>n(0,[o,p,r]),x=()=>n(0,[r]),l=()=>n(0,[o]),h=()=>n(0,[o]),g="web_app_invoke_custom_method",b=()=>n(6.9,[o,p,r]),w=()=>n(6.1,[o,p,r]),m=()=>n(6.4,[o,p,r]),v=()=>n(6.2,[o,p,r]),S=()=>n(6.4,[r]),f=()=>n(7,[o,p,r]),q=()=>n(6.4,[o,p,r]),M=()=>n(6.9,[o,p,r]),P=()=>n(6.9,[o,p,r]),R=()=>n(0,[o,p,r]),k=()=>n(0,[o,p,r]),C=()=>n(6.9,[o,p,r]),y=()=>n(6.1,[o,p,r]),E=()=>n(6.1,[o,p,r]),T=()=>n(6.1,[o,p,r]),O=()=>n(0,[o,p,r]),B=()=>n(0,[o,p,r]),I=()=>n(6.1,[o,p,r]),W=()=>n(6.7,[o,p,r]),Q=()=>n(6.1,[r]);var D=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};var L=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const N=((e=new Map)=>({once:(t,s,o=e.get(t),r=(e=>{s(e),o&&o.splice(o.indexOf(s)>>>0,1)}))=>o?o.push(r):e.set(t,[r]),on:(t,s,o=e.get(t))=>o?o.push(s):e.set(t,[s]),off:(t,s,o=e.get(t))=>o&&s?o.splice(o.indexOf(s)>>>0,1):e.set(t,[]),emit:(t,s,o=e.get(t)||[])=>{for(const e of o)e(s)}}))();(()=>{function s(s,o){s===e.EventThemeChanged&&(o.theme_params=t.getThemeParams(o.theme_params)),N.emit(s,o),N.emit("*",{name:s,data:o})}window.TelegramGameProxy_receiveEvent=s,window.Telegram={WebView:{receiveEvent:s}},window.TelegramGameProxy={receiveEvent:s}})();const V=(e,t)=>{N.on(e,t)},A=(e,t)=>{N.off(e,t)},H=(e,t)=>{N.once(e,t)};var F=Object.freeze({__proto__:null,off:A,on:V,once:H});const G="web_app_open_scan_qr_popup",U="web_app_read_text_from_clipboard",$="web_app_request_phone",J="web_app_close",j="web_app_close_scan_qr_popup",z="web_app_data_send",K="web_app_expand",X="iframe_ready",Y="web_app_open_invoice",Z="web_app_open_link",ee="web_app_open_popup",te="web_app_open_tg_link",se="web_app_ready",oe="web_app_request_theme",re="web_app_request_viewport",pe="web_app_request_write_access",ae="web_app_set_background_color",ne="web_app_set_header_color",ie="web_app_setup_back_button",ue="web_app_setup_closing_behavior",de="web_app_setup_main_button",_e="web_app_setup_settings_button",ce="web_app_switch_inline_query",xe="web_app_trigger_haptic_feedback",le="clipboard_text_received",he="custom_method_invoked",ge="phone_requested",be="popup_closed",we="qr_text_received",me="scan_qr_popup_closed",ve="viewport_changed";exports.EventBackButtonPressed="back_button_pressed",exports.EventClipboardTextReceived=le,exports.EventCustomMethodInvoked=he,exports.EventInvoiceClosed="invoice_closed",exports.EventMainButtonPressed="main_button_pressed",exports.EventPhoneRequested=ge,exports.EventPopupClosed=be,exports.EventQrTextReceived=we,exports.EventReloadIframe="reload_iframe",exports.EventScanQrPopupClosed=me,exports.EventSetCustomStyle="set_custom_style",exports.EventSettingsButtonPressed="settings_button_pressed",exports.EventThemeChanged="theme_changed",exports.EventViewportChanged=ve,exports.EventWriteAccessRequested="write_access_requested",exports.MethodClose=J,exports.MethodCloseScanQrPopup=j,exports.MethodDataSend=z,exports.MethodExpand=K,exports.MethodIframeReady=X,exports.MethodIframeWillReload="iframe_will_reload",exports.MethodInvokeCustomMethod="web_app_invoke_custom_method",exports.MethodOpenInvoice=Y,exports.MethodOpenLink=Z,exports.MethodOpenPopup=ee,exports.MethodOpenScanQrPopup=G,exports.MethodOpenTgLink=te,exports.MethodReadTextFromClipboard=U,exports.MethodReady=se,exports.MethodRequestPhone=$,exports.MethodRequestTheme=oe,exports.MethodRequestViewport=re,exports.MethodRequestWriteAccess=pe,exports.MethodSetBackgroundColor=ae,exports.MethodSetHeaderColor=ne,exports.MethodSetupBackButton=ie,exports.MethodSetupClosingBehavior=ue,exports.MethodSetupMainButton=de,exports.MethodSetupSettingsButton=_e,exports.MethodSwitchInlineQuery=ce,exports.MethodTriggerHapticFeedback=xe,exports.NOT_SUPPORTED=a,exports.TG_DESKTOP=p,exports.TG_PHONE=r,exports.TG_WEB=o,exports.bridgeClose=()=>u()?(L(J),{status:!0}):(D(J,1),{status:a}),exports.bridgeCloseScanQrPopup=d,exports.bridgeDataSend=e=>c()?(L(z,e),{status:!0}):(D(z,1),{status:a}),exports.bridgeExpand=()=>x()?(L(K),{status:!0}):(D(K,1),{status:a}),exports.bridgeGetInitData=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return D("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s},exports.bridgeIframeReady=e=>l()?(L(X,e),{status:!0}):(D(X,1),{status:a}),exports.bridgeIframeWillReload=()=>h()?(L(X),{status:!0}):(D(X,1),{status:a}),exports.bridgeInvokeCustomMethod=async e=>b()?(void 0===e.req_id&&(e.req_id=i()),L(g,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),A(he,o))};V(he,o)}))):(D(g,1),{status:a}),exports.bridgeOpenInvoice=e=>w()?(L(Y,e),{status:!0}):(D(Y,1),{status:a}),exports.bridgeOpenLink=e=>m()?(L(Z,e),{status:!0}):(D(Z,1),{status:a}),exports.bridgeOpenPopup=async e=>v()?(e.title.length>64&&D(ee,3),e.message.length<1&&D(ee,4),e.message.length>256&&D(ee,5),e.buttons.length<1&&D(ee,6),e.buttons.length>3&&D(ee,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&D(ee,8),L(ee,e),new Promise(((t,s)=>{const o=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),A(be,o)};V(be,o)}))):(D(ee,1),{status:a}),exports.bridgeOpenScanQrPopup=async e=>S()?(L(G,e),new Promise(((t,s)=>{H(we,(s=>{e.is_close&&d(),t({status:!0,data:s})})),H(me,(()=>{t({status:"closed"})}))}))):(D(G,1),{status:a}),exports.bridgeOpenTgLink=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),f()?(L(te,e),{status:!0}):(D(te,1),{status:a})),exports.bridgeReadTextFromClipboard=async e=>q()?(void 0===e.req_id&&(e.req_id=i()),L(U,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),A(le,o))};V(le,o)}))):(D(U,1),{status:a}),exports.bridgeReady=()=>M()?(L(se),{status:!0}):(D(se,1),{status:a}),exports.bridgeRequestPhone=async()=>P()?(L($),new Promise(((e,t)=>{H(ge,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(D($,1),{status:a}),exports.bridgeRequestTheme=()=>R()?(L(oe),{status:!0}):(D(oe,1),{status:a}),exports.bridgeRequestViewport=()=>k()?(L(re),{status:!0}):(D(re,1),{status:a}),exports.bridgeRequestWriteAccess=()=>C()?(L(pe),{status:!0}):(D(pe,1),{status:a}),exports.bridgeSetBackgroundColor=e=>y()?(L(ae,e),{status:!0}):(D(ae,1),{status:a}),exports.bridgeSetHeaderColor=e=>E()?(L(ne,e),{status:!0}):(D(ne,1),{status:a}),exports.bridgeSetupBackButton=e=>T()?(L(ie,e),{status:!0}):(D(ie,1),{status:a}),exports.bridgeSetupClosingBehavior=e=>O()?(L(ue,e),{status:!0}):(D(ue,1),{status:a}),exports.bridgeSetupMainButton=e=>B()?(L(de,e),{status:!0}):(D(de,1),{status:a}),exports.bridgeSetupSettingsButton=e=>I()?(L(_e,e),{status:!0}):(D(_e,1),{status:a}),exports.bridgeSwitchInlineQuery=e=>W()?(e.query.length>256&&D(ce,9),L(ce,e),{status:!0}):(D(ce,1),{status:a}),exports.bridgeTriggerHapticFeedback=e=>Q()?(L(xe,e),{status:!0}):(D(xe,1),{status:a}),exports.createIsViewportChanged=()=>{const[e,t]=s.createSignal({height:0,is_expanded:!1,is_state_stable:!1}),o=e=>t(e);return s.onMount((()=>{V(ve,o),L(re)})),s.onCleanup((()=>{A(ve,o)})),e},exports.debug=D,exports.listener=F,exports.sender=L,exports.supportClose=u,exports.supportCloseScanQrPopup=_,exports.supportDataSend=c,exports.supportExpand=x,exports.supportIframeReady=l,exports.supportIframeWillReload=h,exports.supportInvokeCustomMethod=b,exports.supportOpenInvoice=w,exports.supportOpenLink=m,exports.supportOpenPopup=v,exports.supportOpenScanQrPopup=S,exports.supportOpenTgLink=f,exports.supportReadTextFromClipboard=q,exports.supportReady=M,exports.supportRequestPhone=P,exports.supportRequestTheme=R,exports.supportRequestViewport=k,exports.supportRequestWriteAccess=C,exports.supportSetBackgroundColor=y,exports.supportSetHeaderColor=E,exports.supportSetupBackButton=T,exports.supportSetupClosingBehavior=O,exports.supportSetupMainButton=B,exports.supportSetupSettingsButton=I,exports.supportSwitchInlineQuery=W,exports.supportTriggerHapticFeedback=Q;
package/solid/index.mjs CHANGED
@@ -1 +1 @@
1
- import{createSignal as e,onMount as t,onCleanup as n}from"solid-js";var i=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const o=((e=new Map)=>({once:(t,n,i=e.get(t),o=(e=>{n(e),i&&i.splice(i.indexOf(n)>>>0,1)}))=>i?i.push(o):e.set(t,[o]),on:(t,n,i=e.get(t))=>i?i.push(n):e.set(t,[n]),off:(t,n,i=e.get(t))=>i&&n?i.splice(i.indexOf(n)>>>0,1):e.set(t,[]),emit:(t,n,i=e.get(t)||[])=>{for(const e of i)e(n)}}))(),r=()=>{function e(e,t){o.emit(e,t),o.emit("*",{name:e,data:t})}window.TelegramGameProxy_receiveEvent=e,window.Telegram={WebView:{receiveEvent:e}},window.TelegramGameProxy={receiveEvent:e}};r();const w=(e,t)=>{o.on(e,t)},a=(e,t)=>{o.off(e,t)};const s="web_app_request_viewport",d="viewport_changed",f=()=>{const[o,r]=e({height:0,is_expanded:!1,is_state_stable:!1}),f=e=>r(e);return t((()=>{w(d,f),i(s)})),n((()=>{a(d,f)})),o};export{f as createIsViewportChanged};
1
+ import{EventThemeChanged as e}from"solid";import{getThemeParams as t}from"utils";import{createSignal as s,onMount as a,onCleanup as o}from"solid-js";const n=()=>{const[e,t]=s({height:0,is_expanded:!1,is_state_stable:!1}),n=e=>t(e);return a((()=>{ge(ot,n),be(De)})),o((()=>{we(ot,n)})),e},r="web",i="phone",_="desktop",p="not_supported",u=(e,t)=>{const s=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(s)>=e&&-1!==t.indexOf((()=>{const e=window.location.hash.slice(1),t=new URLSearchParams(e).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(t)?i:["tdesktop","macos"].includes(t)?_:r})())},d=()=>Math.random().toString(36).substring(3,9),c=()=>b()?(be(xe),{status:!0}):(de(xe,1),{status:p}),b=()=>u(0,[r,_,i]),l=()=>g()?(be(Pe),{status:!0}):(de(Pe,1),{status:p}),g=()=>u(6.4,[i]),w=e=>m()?(be(Se,e),{status:!0}):(de(Se,1),{status:p}),m=()=>u(0,[r,_,i]),h=()=>f()?(be(ke),{status:!0}):(de(ke,1),{status:p}),f=()=>u(0,[i]),v=e=>q()?(be(Oe,e),{status:!0}):(de(Oe,1),{status:p}),q=()=>u(0,[r]),y=()=>x()?(be(Oe),{status:!0}):(de(Oe,1),{status:p}),x=()=>u(0,[r]),P="web_app_invoke_custom_method",S=async e=>k()?(void 0===e.req_id&&(e.req_id=d()),be(P,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),we(Fe,a))};ge(Fe,a)}))):(de(P,1),{status:p}),k=()=>u(6.9,[r,_,i]),O=e=>R()?(be(Te,e),{status:!0}):(de(Te,1),{status:p}),R=()=>u(6.1,[r,_,i]),T=e=>E()?(be(Ee,e),{status:!0}):(de(Ee,1),{status:p}),E=()=>u(6.4,[r,_,i]),C=async e=>W()?(e.title.length>64&&de(Ce,3),e.message.length<1&&de(Ce,4),e.message.length>256&&de(Ce,5),e.buttons.length<1&&de(Ce,6),e.buttons.length>3&&de(Ce,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&de(Ce,8),be(Ce,e),new Promise(((t,s)=>{const a=s=>{t({status:!!e.buttons.find((e=>e.id===s?.button_id)),data:s}),we(Xe,a)};ge(Xe,a)}))):(de(Ce,1),{status:p}),W=()=>u(6.2,[r,_,i]),I=async e=>B()?(be(ve,e),new Promise(((t,s)=>{me(Ze,(s=>{e.is_close&&l(),t({status:!0,data:s})})),me(et,(()=>{t({status:"closed"})}))}))):(de(ve,1),{status:p}),B=()=>u(6.4,[i]),D=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),L()?(be(We,e),{status:!0}):(de(We,1),{status:p})),L=()=>u(7,[r,_,i]),N=async e=>A()?(void 0===e.req_id&&(e.req_id=d()),be(qe,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),we(je,a))};ge(je,a)}))):(de(qe,1),{status:p}),A=()=>u(6.4,[r,_,i]),M=()=>U()?(be(Ie),{status:!0}):(de(Ie,1),{status:p}),U=()=>u(6.9,[r,_,i]),V=async()=>$()?(be(ye),new Promise(((e,t)=>{me(Ke,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(de(ye,1),{status:p}),$=()=>u(6.9,[r,_,i]),G=()=>J()?(be(Be),{status:!0}):(de(Be,1),{status:p}),J=()=>u(0,[r,_,i]),Q=()=>j()?(be(De),{status:!0}):(de(De,1),{status:p}),j=()=>u(0,[r,_,i]),F=()=>H()?(be(Le),{status:!0}):(de(Le,1),{status:p}),H=()=>u(6.9,[r,_,i]),z=e=>K()?(be(Ne,e),{status:!0}):(de(Ne,1),{status:p}),K=()=>u(6.1,[r,_,i]),X=e=>Y()?(be(Ae,e),{status:!0}):(de(Ae,1),{status:p}),Y=()=>u(6.1,[r,_,i]),Z=e=>ee()?(be(Me,e),{status:!0}):(de(Me,1),{status:p}),ee=()=>u(6.1,[r,_,i]),te=e=>se()?(be(Ue,e),{status:!0}):(de(Ue,1),{status:p}),se=()=>u(0,[r,_,i]),ae=e=>oe()?(be(Ve,e),{status:!0}):(de(Ve,1),{status:p}),oe=()=>u(0,[r,_,i]),ne=e=>re()?(be($e,e),{status:!0}):(de($e,1),{status:p}),re=()=>u(6.1,[r,_,i]),ie=e=>_e()?(e.query.length>256&&de(Ge,9),be(Ge,e),{status:!0}):(de(Ge,1),{status:p}),_e=()=>u(6.7,[r,_,i]),pe=e=>ue()?(be(Je,e),{status:!0}):(de(Je,1),{status:p}),ue=()=>u(6.1,[i]);var de=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};const ce=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return de("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s};var be=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const le=((e=new Map)=>({once:(t,s,a=e.get(t),o=(e=>{s(e),a&&a.splice(a.indexOf(s)>>>0,1)}))=>a?a.push(o):e.set(t,[o]),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 s(s,a){s===e&&(a.theme_params=t(a.theme_params)),le.emit(s,a),le.emit("*",{name:s,data:a})}window.TelegramGameProxy_receiveEvent=s,window.Telegram={WebView:{receiveEvent:s}},window.TelegramGameProxy={receiveEvent:s}})();const ge=(e,t)=>{le.on(e,t)},we=(e,t)=>{le.off(e,t)},me=(e,t)=>{le.once(e,t)};var he=Object.freeze({__proto__:null,off:we,on:ge,once:me});const fe="web_app_invoke_custom_method",ve="web_app_open_scan_qr_popup",qe="web_app_read_text_from_clipboard",ye="web_app_request_phone",xe="web_app_close",Pe="web_app_close_scan_qr_popup",Se="web_app_data_send",ke="web_app_expand",Oe="iframe_ready",Re="iframe_will_reload",Te="web_app_open_invoice",Ee="web_app_open_link",Ce="web_app_open_popup",We="web_app_open_tg_link",Ie="web_app_ready",Be="web_app_request_theme",De="web_app_request_viewport",Le="web_app_request_write_access",Ne="web_app_set_background_color",Ae="web_app_set_header_color",Me="web_app_setup_back_button",Ue="web_app_setup_closing_behavior",Ve="web_app_setup_main_button",$e="web_app_setup_settings_button",Ge="web_app_switch_inline_query",Je="web_app_trigger_haptic_feedback",Qe="back_button_pressed",je="clipboard_text_received",Fe="custom_method_invoked",He="invoice_closed",ze="main_button_pressed",Ke="phone_requested",Xe="popup_closed",Ye="reload_iframe",Ze="qr_text_received",et="scan_qr_popup_closed",tt="set_custom_style",st="settings_button_pressed",at="theme_changed",ot="viewport_changed",nt="write_access_requested";export{Qe as EventBackButtonPressed,je as EventClipboardTextReceived,Fe as EventCustomMethodInvoked,He as EventInvoiceClosed,ze as EventMainButtonPressed,Ke as EventPhoneRequested,Xe as EventPopupClosed,Ze as EventQrTextReceived,Ye as EventReloadIframe,et as EventScanQrPopupClosed,tt as EventSetCustomStyle,st as EventSettingsButtonPressed,at as EventThemeChanged,ot as EventViewportChanged,nt as EventWriteAccessRequested,xe as MethodClose,Pe as MethodCloseScanQrPopup,Se as MethodDataSend,ke as MethodExpand,Oe as MethodIframeReady,Re as MethodIframeWillReload,fe as MethodInvokeCustomMethod,Te as MethodOpenInvoice,Ee as MethodOpenLink,Ce as MethodOpenPopup,ve as MethodOpenScanQrPopup,We as MethodOpenTgLink,qe as MethodReadTextFromClipboard,Ie as MethodReady,ye as MethodRequestPhone,Be as MethodRequestTheme,De as MethodRequestViewport,Le as MethodRequestWriteAccess,Ne as MethodSetBackgroundColor,Ae as MethodSetHeaderColor,Me as MethodSetupBackButton,Ue as MethodSetupClosingBehavior,Ve as MethodSetupMainButton,$e as MethodSetupSettingsButton,Ge as MethodSwitchInlineQuery,Je as MethodTriggerHapticFeedback,p as NOT_SUPPORTED,_ as TG_DESKTOP,i as TG_PHONE,r as TG_WEB,c as bridgeClose,l as bridgeCloseScanQrPopup,w as bridgeDataSend,h as bridgeExpand,ce as bridgeGetInitData,v as bridgeIframeReady,y as bridgeIframeWillReload,S as bridgeInvokeCustomMethod,O as bridgeOpenInvoice,T as bridgeOpenLink,C as bridgeOpenPopup,I as bridgeOpenScanQrPopup,D as bridgeOpenTgLink,N as bridgeReadTextFromClipboard,M as bridgeReady,V as bridgeRequestPhone,G as bridgeRequestTheme,Q as bridgeRequestViewport,F as bridgeRequestWriteAccess,z as bridgeSetBackgroundColor,X as bridgeSetHeaderColor,Z as bridgeSetupBackButton,te as bridgeSetupClosingBehavior,ae as bridgeSetupMainButton,ne as bridgeSetupSettingsButton,ie as bridgeSwitchInlineQuery,pe as bridgeTriggerHapticFeedback,n as createIsViewportChanged,de as debug,he as listener,be as sender,b as supportClose,g as supportCloseScanQrPopup,m as supportDataSend,f as supportExpand,q as supportIframeReady,x as supportIframeWillReload,k as supportInvokeCustomMethod,R as supportOpenInvoice,E as supportOpenLink,W as supportOpenPopup,B as supportOpenScanQrPopup,L as supportOpenTgLink,A as supportReadTextFromClipboard,U as supportReady,$ as supportRequestPhone,J as supportRequestTheme,j as supportRequestViewport,H as supportRequestWriteAccess,K as supportSetBackgroundColor,Y as supportSetHeaderColor,ee as supportSetupBackButton,se as supportSetupClosingBehavior,oe as supportSetupMainButton,re as supportSetupSettingsButton,_e as supportSwitchInlineQuery,ue as supportTriggerHapticFeedback};
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "twa_sdk",
2
+ "name": "@apiteam/twa-bridge/solid",
3
3
  "main": "index.js",
4
4
  "module": "index.mjs",
5
5
  "typings": "index.d.ts",
package/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";const e="web",t="phone",s="desktop",o="not_supported",p=(o,p)=>{const r=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(r)>=o&&-1!==p.indexOf((()=>{const o=window.location.hash.slice(1),p=new URLSearchParams(o).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(p)?t:["tdesktop","macos"].includes(p)?s:e})())},r=()=>Math.random().toString(36).substring(3,9),a=()=>p(0,[e,s,t]),n=()=>u()?(W($),{status:!0}):(I($,1),{status:o}),u=()=>p(6.4,[t]),i=()=>p(0,[e,s,t]),d=()=>p(0,[t]),_=()=>p(0,[e]),x=()=>p(0,[e]),c="web_app_invoke_custom_method",l=()=>p(6.9,[e,s,t]),g=()=>p(6.1,[e,s,t]),b=()=>p(6.4,[e,s,t]),h=()=>p(6.2,[e,s,t]),w=()=>p(6.4,[t]),m=()=>p(7,[e,s,t]),v=()=>p(6.4,[e,s,t]),S=()=>p(6.9,[e,s,t]),f=()=>p(6.9,[e,s,t]),M=()=>p(0,[e,s,t]),P=()=>p(0,[e,s,t]),q=()=>p(6.9,[e,s,t]),R=()=>p(6.1,[e,s,t]),k=()=>p(6.1,[e,s,t]),y=()=>p(6.1,[e,s,t]),C=()=>p(0,[e,s,t]),E=()=>p(0,[e,s,t]),O=()=>p(6.1,[e,s,t]),T=()=>p(6.7,[e,s,t]),B=()=>p(6.1,[t]);var I=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};var W=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const Q=((e=new Map)=>({once:(t,s,o=e.get(t),p=(e=>{s(e),o&&o.splice(o.indexOf(s)>>>0,1)}))=>o?o.push(p):e.set(t,[p]),on:(t,s,o=e.get(t))=>o?o.push(s):e.set(t,[s]),off:(t,s,o=e.get(t))=>o&&s?o.splice(o.indexOf(s)>>>0,1):e.set(t,[]),emit:(t,s,o=e.get(t)||[])=>{for(const e of o)e(s)}}))(),D=()=>{function e(e,t){Q.emit(e,t),Q.emit("*",{name:e,data:t})}window.TelegramGameProxy_receiveEvent=e,window.Telegram={WebView:{receiveEvent:e}},window.TelegramGameProxy={receiveEvent:e}};D();const L=(e,t)=>{Q.on(e,t)},N=(e,t)=>{Q.off(e,t)},A=(e,t)=>{Q.once(e,t)};var H=Object.freeze({__proto__:null,listenerStart:D,off:N,on:L,once:A});const V="web_app_open_scan_qr_popup",F="web_app_read_text_from_clipboard",G="web_app_request_phone",U="web_app_close",$="web_app_close_scan_qr_popup",J="web_app_data_send",j="web_app_expand",z="iframe_ready",K="web_app_open_invoice",X="web_app_open_link",Y="web_app_open_popup",Z="web_app_open_tg_link",ee="web_app_ready",te="web_app_request_theme",se="web_app_request_viewport",oe="web_app_request_write_access",pe="web_app_set_background_color",re="web_app_set_header_color",ae="web_app_setup_back_button",ne="web_app_setup_closing_behavior",ue="web_app_setup_main_button",ie="web_app_setup_settings_button",de="web_app_switch_inline_query",_e="web_app_trigger_haptic_feedback",xe="clipboard_text_received",ce="custom_method_invoked",le="phone_requested",ge="qr_text_received",be="scan_qr_popup_closed";exports.EventBackButtonPressed="back_button_pressed",exports.EventClipboardTextReceived=xe,exports.EventCustomMethodInvoked=ce,exports.EventInvoiceClosed="invoice_closed",exports.EventMainButtonPressed="main_button_pressed",exports.EventPhoneRequested=le,exports.EventPopupClosed="popup_closed",exports.EventQrTextReceived=ge,exports.EventReloadIframe="reload_iframe",exports.EventScanQrPopupClosed=be,exports.EventSetCustomStyle="set_custom_style",exports.EventSettingsButtonPressed="settings_button_pressed",exports.EventThemeChanged="theme_changed",exports.EventViewportChanged="viewport_changed",exports.EventWriteAccessRequested="write_access_requested",exports.MethodClose=U,exports.MethodCloseScanQrPopup=$,exports.MethodDataSend=J,exports.MethodExpand=j,exports.MethodIframeReady=z,exports.MethodIframeWillReload="iframe_will_reload",exports.MethodInvokeCustomMethod="web_app_invoke_custom_method",exports.MethodOpenInvoice=K,exports.MethodOpenLink=X,exports.MethodOpenPopup=Y,exports.MethodOpenScanQrPopup=V,exports.MethodOpenTgLink=Z,exports.MethodReadTextFromClipboard=F,exports.MethodReady=ee,exports.MethodRequestPhone=G,exports.MethodRequestTheme=te,exports.MethodRequestViewport=se,exports.MethodRequestWriteAccess=oe,exports.MethodSetBackgroundColor=pe,exports.MethodSetHeaderColor=re,exports.MethodSetupBackButton=ae,exports.MethodSetupClosingBehavior=ne,exports.MethodSetupMainButton=ue,exports.MethodSetupSettingsButton=ie,exports.MethodSwitchInlineQuery=de,exports.MethodTriggerHapticFeedback=_e,exports.NOT_SUPPORTED=o,exports.TG_DESKTOP=s,exports.TG_PHONE=t,exports.TG_WEB=e,exports.bridgeClose=()=>a()?(W(U),{status:!0}):(I(U,1),{status:o}),exports.bridgeCloseScanQrPopup=n,exports.bridgeDataSend=e=>i()?(W(J,e),{status:!0}):(I(J,1),{status:o}),exports.bridgeExpand=()=>d()?(W(j),{status:!0}):(I(j,1),{status:o}),exports.bridgeGetInitData=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return I("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s},exports.bridgeIframeReady=e=>_()?(W(z,e),{status:!0}):(I(z,1),{status:o}),exports.bridgeIframeWillReload=()=>x()?(W(z),{status:!0}):(I(z,1),{status:o}),exports.bridgeInvokeCustomMethod=async e=>l()?(void 0===e.req_id&&(e.req_id=r()),W(c,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),N(ce,o))};L(ce,o)}))):(I(c,1),{status:o}),exports.bridgeOpenInvoice=e=>g()?(W(K,e),{status:!0}):(I(K,1),{status:o}),exports.bridgeOpenLink=e=>b()?(W(X,e),{status:!0}):(I(X,1),{status:o}),exports.bridgeOpenPopup=e=>h()?(e.title.length>64&&I(Y,3),e.message.length<1&&I(Y,4),e.message.length>256&&I(Y,5),e.buttons.length<1&&I(Y,6),e.buttons.length>3&&I(Y,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&I(Y,8),W(Y,e),{status:!0}):(I(Y,1),{status:o}),exports.bridgeOpenScanQrPopup=async e=>w()?(W(V,e),new Promise(((t,s)=>{A(ge,(s=>{e.is_close&&n(),t({status:!0,data:s})})),A(be,(()=>{t({status:"closed"})}))}))):(I(V,1),{status:o}),exports.bridgeOpenTgLink=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),m()?(W(Z,e),{status:!0}):(I(Z,1),{status:o})),exports.bridgeReadTextFromClipboard=async e=>v()?(void 0===e.req_id&&(e.req_id=r()),W(F,e),new Promise(((t,s)=>{const o=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),N(xe,o))};L(xe,o)}))):(I(F,1),{status:o}),exports.bridgeReady=()=>S()?(W(ee),{status:!0}):(I(ee,1),{status:o}),exports.bridgeRequestPhone=async()=>f()?(W(G),new Promise(((e,t)=>{A(le,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(I(G,1),{status:o}),exports.bridgeRequestTheme=()=>M()?(W(te),{status:!0}):(I(te,1),{status:o}),exports.bridgeRequestViewport=()=>P()?(W(se),{status:!0}):(I(se,1),{status:o}),exports.bridgeRequestWriteAccess=()=>q()?(W(oe),{status:!0}):(I(oe,1),{status:o}),exports.bridgeSetBackgroundColor=e=>R()?(W(pe,e),{status:!0}):(I(pe,1),{status:o}),exports.bridgeSetHeaderColor=e=>k()?(W(re,e),{status:!0}):(I(re,1),{status:o}),exports.bridgeSetupBackButton=e=>y()?(W(ae,e),{status:!0}):(I(ae,1),{status:o}),exports.bridgeSetupClosingBehavior=e=>C()?(W(ne,e),{status:!0}):(I(ne,1),{status:o}),exports.bridgeSetupMainButton=e=>E()?(W(ue,e),{status:!0}):(I(ue,1),{status:o}),exports.bridgeSetupSettingsButton=e=>O()?(W(ie,e),{status:!0}):(I(ie,1),{status:o}),exports.bridgeSwitchInlineQuery=e=>T()?(e.query.length>256&&I(de,9),W(de,e),{status:!0}):(I(de,1),{status:o}),exports.bridgeTriggerHapticFeedback=e=>B()?(W(_e,e),{status:!0}):(I(_e,1),{status:o}),exports.debug=I,exports.listener=H,exports.sender=W,exports.supportClose=a,exports.supportCloseScanQrPopup=u,exports.supportDataSend=i,exports.supportExpand=d,exports.supportIframeReady=_,exports.supportIframeWillReload=x,exports.supportInvokeCustomMethod=l,exports.supportOpenInvoice=g,exports.supportOpenLink=b,exports.supportOpenPopup=h,exports.supportOpenScanQrPopup=w,exports.supportOpenTgLink=m,exports.supportReadTextFromClipboard=v,exports.supportReady=S,exports.supportRequestPhone=f,exports.supportRequestTheme=M,exports.supportRequestViewport=P,exports.supportRequestWriteAccess=q,exports.supportSetBackgroundColor=R,exports.supportSetHeaderColor=k,exports.supportSetupBackButton=y,exports.supportSetupClosingBehavior=C,exports.supportSetupMainButton=E,exports.supportSetupSettingsButton=O,exports.supportSwitchInlineQuery=T,exports.supportTriggerHapticFeedback=B;
package/index.mjs DELETED
@@ -1 +0,0 @@
1
- const e="web",t="phone",s="desktop",a="not_supported",n=(a,n)=>{const o=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppVersion");return Number(o)>=a&&-1!==n.indexOf((()=>{const a=window.location.hash.slice(1),n=new URLSearchParams(a).get("tgWebAppPlatform")??"ios";return["android","ios"].includes(n)?t:["tdesktop","macos"].includes(n)?s:e})())},o=()=>Math.random().toString(36).substring(3,9),r=()=>i()?(ie(he),{status:!0}):(oe(he,1),{status:a}),i=()=>n(0,[e,s,t]),_=()=>p()?(ie(ve),{status:!0}):(oe(ve,1),{status:a}),p=()=>n(6.4,[t]),u=e=>d()?(ie(fe,e),{status:!0}):(oe(fe,1),{status:a}),d=()=>n(0,[e,s,t]),c=()=>b()?(ie(qe),{status:!0}):(oe(qe,1),{status:a}),b=()=>n(0,[t]),l=e=>g()?(ie(ye,e),{status:!0}):(oe(ye,1),{status:a}),g=()=>n(0,[e]),w=()=>m()?(ie(ye),{status:!0}):(oe(ye,1),{status:a}),m=()=>n(0,[e]),h="web_app_invoke_custom_method",v=async e=>f()?(void 0===e.req_id&&(e.req_id=o()),ie(h,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),de($e,a))};ue($e,a)}))):(oe(h,1),{status:a}),f=()=>n(6.9,[e,s,t]),q=e=>y()?(ie(ke,e),{status:!0}):(oe(ke,1),{status:a}),y=()=>n(6.1,[e,s,t]),S=e=>k()?(ie(xe,e),{status:!0}):(oe(xe,1),{status:a}),k=()=>n(6.4,[e,s,t]),x=e=>P()?(e.title.length>64&&oe(Pe,3),e.message.length<1&&oe(Pe,4),e.message.length>256&&oe(Pe,5),e.buttons.length<1&&oe(Pe,6),e.buttons.length>3&&oe(Pe,7),void 0!==e.buttons.find((e=>e.text?.match(/^(ok|close|cancel)$/g)))&&oe(Pe,8),ie(Pe,e),{status:!0}):(oe(Pe,1),{status:a}),P=()=>n(6.2,[e,s,t]),O=async e=>R()?(ie(ge,e),new Promise(((t,s)=>{ce(je,(s=>{e.is_close&&_(),t({status:!0,data:s})})),ce(ze,(()=>{t({status:"closed"})}))}))):(oe(ge,1),{status:a}),R=()=>n(6.4,[t]),T=e=>("/"!==e.path_full[0]&&(e.path_full="/"+e.path_full),E()?(ie(Oe,e),{status:!0}):(oe(Oe,1),{status:a})),E=()=>n(7,[e,s,t]),W=async e=>C()?(void 0===e.req_id&&(e.req_id=o()),ie(we,e),new Promise(((t,s)=>{const a=s=>{s.req_id===e.req_id&&(t({status:!0,data:s}),de(Ve,a))};ue(Ve,a)}))):(oe(we,1),{status:a}),C=()=>n(6.4,[e,s,t]),I=()=>B()?(ie(Re),{status:!0}):(oe(Re,1),{status:a}),B=()=>n(6.9,[e,s,t]),D=async()=>L()?(ie(me),new Promise(((e,t)=>{ce(Qe,(t=>{"sent"===t.status&&e({status:!0}),e({status:!1})}))}))):(oe(me,1),{status:a}),L=()=>n(6.9,[e,s,t]),N=()=>A()?(ie(Te),{status:!0}):(oe(Te,1),{status:a}),A=()=>n(0,[e,s,t]),M=()=>U()?(ie(Ee),{status:!0}):(oe(Ee,1),{status:a}),U=()=>n(0,[e,s,t]),V=()=>$()?(ie(We),{status:!0}):(oe(We,1),{status:a}),$=()=>n(6.9,[e,s,t]),G=e=>J()?(ie(Ce,e),{status:!0}):(oe(Ce,1),{status:a}),J=()=>n(6.1,[e,s,t]),Q=e=>F()?(ie(Ie,e),{status:!0}):(oe(Ie,1),{status:a}),F=()=>n(6.1,[e,s,t]),H=e=>j()?(ie(Be,e),{status:!0}):(oe(Be,1),{status:a}),j=()=>n(6.1,[e,s,t]),z=e=>K()?(ie(De,e),{status:!0}):(oe(De,1),{status:a}),K=()=>n(0,[e,s,t]),X=e=>Y()?(ie(Le,e),{status:!0}):(oe(Le,1),{status:a}),Y=()=>n(0,[e,s,t]),Z=e=>ee()?(ie(Ne,e),{status:!0}):(oe(Ne,1),{status:a}),ee=()=>n(6.1,[e,s,t]),te=e=>se()?(e.query.length>256&&oe(Ae,9),ie(Ae,e),{status:!0}):(oe(Ae,1),{status:a}),se=()=>n(6.7,[e,s,t]),ae=e=>ne()?(ie(Me,e),{status:!0}):(oe(Me,1),{status:a}),ne=()=>n(6.1,[t]);var oe=(e,t)=>{"development"===process.env.NODE_ENV&&console.error(`[@apiteam/twa-bridge](${e}) = ${t}`)};const re=()=>{const e=new URLSearchParams(window.location.hash.slice(1)).get("tgWebAppData");if(null===e)return oe("getInitData",2),null;const t=new URLSearchParams(e);let s={};return t.forEach(((e,t)=>{if(s[t]=e,void 0!==t.match(/^(chat|receiver|user)$/g))try{s[t]=JSON.parse(e)}catch{}})),s};var ie=(e,t)=>{window.TelegramWebviewProxy?window.TelegramWebviewProxy.postEvent(e,JSON.stringify(t)):window.external&&"notify"in window.external&&window.external.notify(JSON.stringify({eventType:e,eventData:t}))};const _e=((e=new Map)=>({once:(t,s,a=e.get(t),n=(e=>{s(e),a&&a.splice(a.indexOf(s)>>>0,1)}))=>a?a.push(n):e.set(t,[n]),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)}}))(),pe=()=>{function e(e,t){_e.emit(e,t),_e.emit("*",{name:e,data:t})}window.TelegramGameProxy_receiveEvent=e,window.Telegram={WebView:{receiveEvent:e}},window.TelegramGameProxy={receiveEvent:e}};pe();const ue=(e,t)=>{_e.on(e,t)},de=(e,t)=>{_e.off(e,t)},ce=(e,t)=>{_e.once(e,t)};var be=Object.freeze({__proto__:null,listenerStart:pe,off:de,on:ue,once:ce});const le="web_app_invoke_custom_method",ge="web_app_open_scan_qr_popup",we="web_app_read_text_from_clipboard",me="web_app_request_phone",he="web_app_close",ve="web_app_close_scan_qr_popup",fe="web_app_data_send",qe="web_app_expand",ye="iframe_ready",Se="iframe_will_reload",ke="web_app_open_invoice",xe="web_app_open_link",Pe="web_app_open_popup",Oe="web_app_open_tg_link",Re="web_app_ready",Te="web_app_request_theme",Ee="web_app_request_viewport",We="web_app_request_write_access",Ce="web_app_set_background_color",Ie="web_app_set_header_color",Be="web_app_setup_back_button",De="web_app_setup_closing_behavior",Le="web_app_setup_main_button",Ne="web_app_setup_settings_button",Ae="web_app_switch_inline_query",Me="web_app_trigger_haptic_feedback",Ue="back_button_pressed",Ve="clipboard_text_received",$e="custom_method_invoked",Ge="invoice_closed",Je="main_button_pressed",Qe="phone_requested",Fe="popup_closed",He="reload_iframe",je="qr_text_received",ze="scan_qr_popup_closed",Ke="set_custom_style",Xe="settings_button_pressed",Ye="theme_changed",Ze="viewport_changed",et="write_access_requested";export{Ue as EventBackButtonPressed,Ve as EventClipboardTextReceived,$e as EventCustomMethodInvoked,Ge as EventInvoiceClosed,Je as EventMainButtonPressed,Qe as EventPhoneRequested,Fe as EventPopupClosed,je as EventQrTextReceived,He as EventReloadIframe,ze as EventScanQrPopupClosed,Ke as EventSetCustomStyle,Xe as EventSettingsButtonPressed,Ye as EventThemeChanged,Ze as EventViewportChanged,et as EventWriteAccessRequested,he as MethodClose,ve as MethodCloseScanQrPopup,fe as MethodDataSend,qe as MethodExpand,ye as MethodIframeReady,Se as MethodIframeWillReload,le as MethodInvokeCustomMethod,ke as MethodOpenInvoice,xe as MethodOpenLink,Pe as MethodOpenPopup,ge as MethodOpenScanQrPopup,Oe as MethodOpenTgLink,we as MethodReadTextFromClipboard,Re as MethodReady,me as MethodRequestPhone,Te as MethodRequestTheme,Ee as MethodRequestViewport,We as MethodRequestWriteAccess,Ce as MethodSetBackgroundColor,Ie as MethodSetHeaderColor,Be as MethodSetupBackButton,De as MethodSetupClosingBehavior,Le as MethodSetupMainButton,Ne as MethodSetupSettingsButton,Ae as MethodSwitchInlineQuery,Me as MethodTriggerHapticFeedback,a as NOT_SUPPORTED,s as TG_DESKTOP,t as TG_PHONE,e as TG_WEB,r as bridgeClose,_ as bridgeCloseScanQrPopup,u as bridgeDataSend,c as bridgeExpand,re as bridgeGetInitData,l as bridgeIframeReady,w as bridgeIframeWillReload,v as bridgeInvokeCustomMethod,q as bridgeOpenInvoice,S as bridgeOpenLink,x as bridgeOpenPopup,O as bridgeOpenScanQrPopup,T as bridgeOpenTgLink,W as bridgeReadTextFromClipboard,I as bridgeReady,D as bridgeRequestPhone,N as bridgeRequestTheme,M as bridgeRequestViewport,V as bridgeRequestWriteAccess,G as bridgeSetBackgroundColor,Q as bridgeSetHeaderColor,H as bridgeSetupBackButton,z as bridgeSetupClosingBehavior,X as bridgeSetupMainButton,Z as bridgeSetupSettingsButton,te as bridgeSwitchInlineQuery,ae as bridgeTriggerHapticFeedback,oe as debug,be as listener,ie as sender,i as supportClose,p as supportCloseScanQrPopup,d as supportDataSend,b as supportExpand,g as supportIframeReady,m as supportIframeWillReload,f as supportInvokeCustomMethod,y as supportOpenInvoice,k as supportOpenLink,P as supportOpenPopup,R as supportOpenScanQrPopup,E as supportOpenTgLink,C as supportReadTextFromClipboard,B as supportReady,L as supportRequestPhone,A as supportRequestTheme,U as supportRequestViewport,$ as supportRequestWriteAccess,J as supportSetBackgroundColor,F as supportSetHeaderColor,j as supportSetupBackButton,K as supportSetupClosingBehavior,Y as supportSetupMainButton,ee as supportSetupSettingsButton,se as supportSwitchInlineQuery,ne as supportTriggerHapticFeedback};