@tma.js/sdk 1.4.4 → 1.4.7
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 +2 -2
- package/dist/dts/bridge/env/index.d.ts +0 -1
- package/dist/dts/bridge/events/events.d.ts +16 -16
- package/dist/dts/bridge/methods/methods.d.ts +27 -27
- package/dist/dts/bridge/methods/popup.d.ts +1 -1
- package/dist/dts/index.d.ts +3 -3
- package/dist/dts/init-data/types.d.ts +3 -3
- package/dist/dts/launch-params/index.d.ts +1 -4
- package/dist/dts/launch-params/retrieveFromLocation.d.ts +2 -2
- package/dist/dts/launch-params/retrieveFromPerformance.d.ts +3 -4
- package/dist/dts/launch-params/retrieveFromUrl.d.ts +3 -2
- package/dist/dts/launch-params/retrieveLaunchData.d.ts +1 -0
- package/dist/dts/launch-params/retrieveLaunchParams.d.ts +6 -0
- package/dist/dts/launch-params/storage.d.ts +3 -5
- package/dist/dts/launch-params/types.d.ts +1 -1
- package/dist/dts/{launch-params → misc}/getFirstNavigationEntry.d.ts +1 -1
- package/dist/dts/misc/index.d.ts +3 -0
- package/dist/dts/{bridge/env → misc}/isIframe.d.ts +1 -1
- package/dist/dts/misc/isPageReload.d.ts +5 -0
- package/dist/dts/theme-params/types.d.ts +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.iife.js +1 -2
- package/dist/index.mjs +841 -866
- package/package.json +2 -3
- package/dist/dts/launch-params/computeLaunchData.d.ts +0 -6
- package/dist/dts/launch-params/computePageReload.d.ts +0 -6
- package/dist/dts/launch-params/retrieveCurrent.d.ts +0 -5
- package/dist/index.cjs.map +0 -1
- package/dist/index.iife.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/src/__tests__/globals.ts +0 -39
- package/src/back-button/BackButton.ts +0 -90
- package/src/back-button/__tests__/BackButton.ts +0 -129
- package/src/back-button/index.ts +0 -2
- package/src/back-button/types.ts +0 -14
- package/src/bridge/__tests__/parseMessage.ts +0 -23
- package/src/bridge/__tests__/request.ts +0 -236
- package/src/bridge/env/__tests__/hasExternalNotify.ts +0 -15
- package/src/bridge/env/__tests__/hasWebviewProxy.ts +0 -15
- package/src/bridge/env/__tests__/isIframe.ts +0 -30
- package/src/bridge/env/hasExternalNotify.ts +0 -19
- package/src/bridge/env/hasWebviewProxy.ts +0 -19
- package/src/bridge/env/index.ts +0 -3
- package/src/bridge/env/isIframe.ts +0 -11
- package/src/bridge/errors/MethodUnsupportedError.ts +0 -13
- package/src/bridge/errors/ParameterUnsupportedError.ts +0 -13
- package/src/bridge/errors/index.ts +0 -2
- package/src/bridge/events/__tests__/createEmitter.ts +0 -143
- package/src/bridge/events/__tests__/off.ts +0 -34
- package/src/bridge/events/__tests__/on.ts +0 -49
- package/src/bridge/events/__tests__/onTelegramEvent.ts +0 -49
- package/src/bridge/events/__tests__/once.ts +0 -64
- package/src/bridge/events/__tests__/singletonEmitter.ts +0 -22
- package/src/bridge/events/__tests__/subscribe.ts +0 -49
- package/src/bridge/events/__tests__/unsubscribe.ts +0 -34
- package/src/bridge/events/createEmitter.ts +0 -108
- package/src/bridge/events/events.ts +0 -170
- package/src/bridge/events/index.ts +0 -9
- package/src/bridge/events/off.ts +0 -14
- package/src/bridge/events/on.ts +0 -19
- package/src/bridge/events/onTelegramEvent.ts +0 -81
- package/src/bridge/events/once.ts +0 -18
- package/src/bridge/events/parsers/__tests__/clipboardTextReceived.ts +0 -21
- package/src/bridge/events/parsers/__tests__/invoiceClosed.ts +0 -12
- package/src/bridge/events/parsers/__tests__/popupClosed.ts +0 -10
- package/src/bridge/events/parsers/__tests__/qrTextReceived.ts +0 -9
- package/src/bridge/events/parsers/__tests__/theme-changed.ts +0 -42
- package/src/bridge/events/parsers/__tests__/viewportChanged.ts +0 -49
- package/src/bridge/events/parsers/clipboardTextReceived.ts +0 -26
- package/src/bridge/events/parsers/customMethodInvoked.ts +0 -25
- package/src/bridge/events/parsers/index.ts +0 -9
- package/src/bridge/events/parsers/invoiceClosed.ts +0 -26
- package/src/bridge/events/parsers/phoneRequested.ts +0 -14
- package/src/bridge/events/parsers/popupClosed.ts +0 -19
- package/src/bridge/events/parsers/qrTextReceived.ts +0 -14
- package/src/bridge/events/parsers/theme-changed.ts +0 -58
- package/src/bridge/events/parsers/viewportChanged.ts +0 -33
- package/src/bridge/events/parsers/writeAccessRequested.ts +0 -14
- package/src/bridge/events/singletonEmitter.ts +0 -19
- package/src/bridge/events/subscribe.ts +0 -15
- package/src/bridge/events/unsubscribe.ts +0 -10
- package/src/bridge/index.ts +0 -7
- package/src/bridge/invokeCustomMethod.ts +0 -56
- package/src/bridge/methods/__tests__/createPostEvent.ts +0 -37
- package/src/bridge/methods/__tests__/postEvent.ts +0 -137
- package/src/bridge/methods/createPostEvent.ts +0 -40
- package/src/bridge/methods/custom-methods.ts +0 -68
- package/src/bridge/methods/haptic.ts +0 -52
- package/src/bridge/methods/index.ts +0 -6
- package/src/bridge/methods/methods.ts +0 -370
- package/src/bridge/methods/popup.ts +0 -53
- package/src/bridge/methods/postEvent.ts +0 -101
- package/src/bridge/parseMessage.ts +0 -28
- package/src/bridge/request.ts +0 -176
- package/src/classnames/__tests__/classNames.ts +0 -20
- package/src/classnames/__tests__/mergeClassNames.ts +0 -21
- package/src/classnames/classNames.ts +0 -34
- package/src/classnames/index.ts +0 -2
- package/src/classnames/mergeClassNames.ts +0 -60
- package/src/closing-behavior/ClosingBehavior.ts +0 -64
- package/src/closing-behavior/__tests__/ClosingBehavior.ts +0 -86
- package/src/closing-behavior/index.ts +0 -2
- package/src/closing-behavior/types.ts +0 -12
- package/src/cloud-storage/CloudStorage.ts +0 -138
- package/src/cloud-storage/index.ts +0 -1
- package/src/colors/__tests__/isColorDark.ts +0 -12
- package/src/colors/__tests__/isRGB.ts +0 -13
- package/src/colors/__tests__/isRGBShort.ts +0 -13
- package/src/colors/__tests__/toRGB.ts +0 -23
- package/src/colors/index.ts +0 -5
- package/src/colors/isColorDark.ts +0 -22
- package/src/colors/isRGB.ts +0 -9
- package/src/colors/isRGBShort.ts +0 -9
- package/src/colors/toRGB.ts +0 -49
- package/src/colors/types.ts +0 -9
- package/src/css/__tests__/bindMiniAppCSSVars.ts +0 -175
- package/src/css/__tests__/bindThemeCSSVars.ts +0 -52
- package/src/css/__tests__/bindViewportCSSVars.ts +0 -55
- package/src/css/__tests__/setCSSVar.ts +0 -14
- package/src/css/bindMiniAppCSSVars.ts +0 -51
- package/src/css/bindThemeCSSVars.ts +0 -31
- package/src/css/bindViewportCSSVars.ts +0 -36
- package/src/css/index.ts +0 -4
- package/src/css/setCSSVar.ts +0 -8
- package/src/event-emitter/EventEmitter.ts +0 -146
- package/src/event-emitter/__tests__/EventEmitter.ts +0 -145
- package/src/event-emitter/index.ts +0 -2
- package/src/event-emitter/types.ts +0 -60
- package/src/globals.ts +0 -38
- package/src/haptic-feedback/HapticFeedback.ts +0 -70
- package/src/haptic-feedback/__tests__/HapticFeedback.ts +0 -68
- package/src/haptic-feedback/index.ts +0 -1
- package/src/index.ts +0 -185
- package/src/init/catchCustomStyles.ts +0 -17
- package/src/init/creators/__tests__/createViewport.ts +0 -96
- package/src/init/creators/createBackButton.ts +0 -25
- package/src/init/creators/createClosingBehavior.ts +0 -24
- package/src/init/creators/createMainButton.ts +0 -51
- package/src/init/creators/createMiniApp.ts +0 -48
- package/src/init/creators/createRequestIdGenerator.ts +0 -13
- package/src/init/creators/createSettingsButton.ts +0 -25
- package/src/init/creators/createThemeParams.ts +0 -11
- package/src/init/creators/createViewport.ts +0 -94
- package/src/init/creators/index.ts +0 -8
- package/src/init/css/index.ts +0 -1
- package/src/init/css/processCSSVarsOption.ts +0 -55
- package/src/init/index.ts +0 -2
- package/src/init/init.ts +0 -134
- package/src/init/types.ts +0 -94
- package/src/init-data/InitData.ts +0 -96
- package/src/init-data/__tests__/InitData.ts +0 -98
- package/src/init-data/__tests__/chatParser.ts +0 -102
- package/src/init-data/__tests__/initDataParser.ts +0 -136
- package/src/init-data/__tests__/parseInitData.ts +0 -136
- package/src/init-data/__tests__/userParser.ts +0 -96
- package/src/init-data/chatParser.ts +0 -19
- package/src/init-data/index.ts +0 -6
- package/src/init-data/initDataParser.ts +0 -41
- package/src/init-data/parseInitData.ts +0 -10
- package/src/init-data/types.ts +0 -164
- package/src/init-data/userParser.ts +0 -45
- package/src/invoice/Invoice.ts +0 -123
- package/src/invoice/index.ts +0 -2
- package/src/invoice/types.ts +0 -11
- package/src/launch-params/__tests__/retrieveFromUrl.ts +0 -19
- package/src/launch-params/computeLaunchData.ts +0 -81
- package/src/launch-params/computePageReload.ts +0 -13
- package/src/launch-params/getFirstNavigationEntry.ts +0 -10
- package/src/launch-params/index.ts +0 -13
- package/src/launch-params/launchParamsParser.ts +0 -45
- package/src/launch-params/parseLaunchParams.ts +0 -10
- package/src/launch-params/retrieveCurrent.ts +0 -27
- package/src/launch-params/retrieveFromLocation.ts +0 -10
- package/src/launch-params/retrieveFromPerformance.ts +0 -18
- package/src/launch-params/retrieveFromUrl.ts +0 -19
- package/src/launch-params/retrieveLaunchData.ts +0 -30
- package/src/launch-params/serializeLaunchParams.ts +0 -37
- package/src/launch-params/storage.ts +0 -33
- package/src/launch-params/types.ts +0 -62
- package/src/logger/Logger.ts +0 -72
- package/src/logger/__tests__/Logger.ts +0 -107
- package/src/logger/index.ts +0 -1
- package/src/main-button/MainButton.ts +0 -239
- package/src/main-button/__tests__/MainButton.ts +0 -346
- package/src/main-button/index.ts +0 -2
- package/src/main-button/types.ts +0 -26
- package/src/mini-app/MiniApp.ts +0 -348
- package/src/mini-app/__tests__/MiniApp.ts +0 -140
- package/src/mini-app/contactParser.ts +0 -29
- package/src/mini-app/index.ts +0 -2
- package/src/mini-app/types.ts +0 -38
- package/src/misc/__tests__/isRecord.ts +0 -21
- package/src/misc/index.ts +0 -2
- package/src/misc/isRecord.ts +0 -7
- package/src/misc/isTMA.ts +0 -13
- package/src/navigation/HashNavigator/HashNavigator.ts +0 -220
- package/src/navigation/HashNavigator/__tests__/HashNavigator.ts +0 -144
- package/src/navigation/HashNavigator/__tests__/drop.ts +0 -42
- package/src/navigation/HashNavigator/__tests__/go.ts +0 -9
- package/src/navigation/HashNavigator/drop.ts +0 -36
- package/src/navigation/HashNavigator/go.ts +0 -28
- package/src/navigation/HashNavigator/index.ts +0 -2
- package/src/navigation/HashNavigator/types.ts +0 -41
- package/src/navigation/Navigator/Navigator.ts +0 -282
- package/src/navigation/Navigator/index.ts +0 -2
- package/src/navigation/Navigator/types.ts +0 -55
- package/src/navigation/ensurePrefix.ts +0 -9
- package/src/navigation/getHash.ts +0 -17
- package/src/navigation/index.ts +0 -4
- package/src/parsing/ArrayValueParser.ts +0 -79
- package/src/parsing/ParseError.ts +0 -27
- package/src/parsing/ParseSchemaFieldError.ts +0 -21
- package/src/parsing/ValueParser.ts +0 -71
- package/src/parsing/__tests__/ArrayValueParser.ts +0 -18
- package/src/parsing/__tests__/toRecord.ts +0 -10
- package/src/parsing/createValueParserGenerator.ts +0 -16
- package/src/parsing/index.ts +0 -10
- package/src/parsing/parseBySchema.ts +0 -65
- package/src/parsing/parsers/__tests__/array.ts +0 -39
- package/src/parsing/parsers/__tests__/boolean.ts +0 -31
- package/src/parsing/parsers/__tests__/date.ts +0 -25
- package/src/parsing/parsers/__tests__/json.ts +0 -80
- package/src/parsing/parsers/__tests__/number.ts +0 -23
- package/src/parsing/parsers/__tests__/rgb.ts +0 -22
- package/src/parsing/parsers/__tests__/searchParams.ts +0 -105
- package/src/parsing/parsers/__tests__/string.ts +0 -25
- package/src/parsing/parsers/array.ts +0 -9
- package/src/parsing/parsers/boolean.ts +0 -22
- package/src/parsing/parsers/date.ts +0 -11
- package/src/parsing/parsers/index.ts +0 -8
- package/src/parsing/parsers/json.ts +0 -17
- package/src/parsing/parsers/number.ts +0 -21
- package/src/parsing/parsers/rgb.ts +0 -10
- package/src/parsing/parsers/searchParams.ts +0 -24
- package/src/parsing/parsers/string.ts +0 -12
- package/src/parsing/toRecord.ts +0 -27
- package/src/parsing/types.ts +0 -32
- package/src/parsing/unexpectedTypeError.ts +0 -6
- package/src/popup/Popup.ts +0 -91
- package/src/popup/__tests__/Popup.ts +0 -130
- package/src/popup/__tests__/preparePopupParams.ts +0 -85
- package/src/popup/index.ts +0 -2
- package/src/popup/preparePopupParams.ts +0 -59
- package/src/popup/types.ts +0 -69
- package/src/qr-scanner/QRScanner.ts +0 -95
- package/src/qr-scanner/index.ts +0 -2
- package/src/qr-scanner/types.ts +0 -11
- package/src/settings-button/SettingsButton.ts +0 -85
- package/src/settings-button/index.ts +0 -2
- package/src/settings-button/types.ts +0 -15
- package/src/state/State.ts +0 -67
- package/src/state/index.ts +0 -2
- package/src/state/types.ts +0 -31
- package/src/storage.ts +0 -69
- package/src/supports/__tests__/supports.ts +0 -123
- package/src/supports/createSupportsFunc.ts +0 -18
- package/src/supports/createSupportsParamFunc.ts +0 -27
- package/src/supports/index.ts +0 -4
- package/src/supports/supports.ts +0 -84
- package/src/supports/types.ts +0 -1
- package/src/theme-params/ThemeParams.ts +0 -131
- package/src/theme-params/__tests__/keys.ts +0 -19
- package/src/theme-params/__tests__/parseThemeParams.ts +0 -29
- package/src/theme-params/__tests__/serializeThemeParams.ts +0 -29
- package/src/theme-params/__tests__/themeParamsParser.ts +0 -29
- package/src/theme-params/index.ts +0 -6
- package/src/theme-params/keys.ts +0 -24
- package/src/theme-params/parseThemeParams.ts +0 -10
- package/src/theme-params/requestThemeParams.ts +0 -13
- package/src/theme-params/serializeThemeParams.ts +0 -20
- package/src/theme-params/themeParamsParser.ts +0 -22
- package/src/theme-params/types.ts +0 -33
- package/src/timeout/TimeoutError.ts +0 -6
- package/src/timeout/__tests__/isTimeoutError.ts +0 -9
- package/src/timeout/__tests__/withTimeout.ts +0 -28
- package/src/timeout/index.ts +0 -4
- package/src/timeout/isTimeoutError.ts +0 -9
- package/src/timeout/sleep.ts +0 -10
- package/src/timeout/withTimeout.ts +0 -24
- package/src/types/index.ts +0 -4
- package/src/types/methods.ts +0 -18
- package/src/types/platform.ts +0 -14
- package/src/types/request-id.ts +0 -10
- package/src/types/utils.ts +0 -50
- package/src/utils/Utils.ts +0 -107
- package/src/utils/index.ts +0 -1
- package/src/version/__tests__/compareVersions.ts +0 -19
- package/src/version/compareVersions.ts +0 -28
- package/src/version/index.ts +0 -2
- package/src/version/types.ts +0 -4
- package/src/viewport/Viewport.ts +0 -171
- package/src/viewport/__tests__/isStableViewportPlatform.ts +0 -15
- package/src/viewport/__tests__/utils.ts +0 -12
- package/src/viewport/index.ts +0 -4
- package/src/viewport/isStableViewportPlatform.ts +0 -10
- package/src/viewport/requestViewport.ts +0 -23
- package/src/viewport/types.ts +0 -23
- package/src/viewport/utils.ts +0 -7
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
"use strict";var ot=Object.defineProperty;var at=(r,e,t)=>e in r?ot(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var o=(r,e,t)=>(at(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function A(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function Pe(){return performance.getEntriesByType("navigation")[0]||null}function ct(){const r=Pe();return r?r.type==="reload":null}function B(){return new TypeError("Value has unexpected type")}class U extends Error{constructor(t,{cause:s,type:n}={}){super(`Unable to parse value${n?` as ${n}`:""}`,{cause:s});o(this,"type");this.value=t,Object.setPrototypeOf(this,U.prototype),this.type=n}}class J{constructor(e,t,s){this.parser=e,this.isOptional=t,this.type=s}parse(e){if(!(this.isOptional&&e===void 0))try{return this.parser(e)}catch(t){throw new U(e,{type:this.type,cause:t})}}optional(){return this.isOptional=!0,this}}function ut(r){if(Array.isArray(r))return r;if(typeof r=="string")try{const e=JSON.parse(r);if(Array.isArray(e))return e}catch{}throw B()}class ht extends J{constructor(t,s,n){super(ut,s,n);o(this,"itemParser");this.itemParser=typeof t=="function"?t:t.parse.bind(t)}parse(t){const s=super.parse(t);return s===void 0?s:s.map(this.itemParser)}of(t){return this.itemParser=typeof t=="function"?t:t.parse.bind(t),this}}function $(r,e){return()=>new J(r,!1,e)}class M extends Error{constructor(e,{cause:t,type:s}={}){super(`Unable to parse field "${e}"${s?` as ${s}`:""}`,{cause:t}),Object.setPrototypeOf(this,M.prototype)}}function ve(r,e){const t={};for(const s in r){const n=r[s];if(!n)continue;let i,a;if(typeof n=="function"||"parse"in n)i=s,a=typeof n=="function"?n:n.parse.bind(n);else{const{type:h}=n;i=n.from||s,a=typeof h=="function"?h:h.parse.bind(h)}let c;const p=e(i);try{c=a(p)}catch(h){throw h instanceof U?new M(i,{type:h.type,cause:h}):new M(i,{cause:h})}c!==void 0&&(t[s]=c)}return t}function Se(r){return new ht(e=>e,!1,r)}const E=$(r=>{if(typeof r=="boolean")return r;const e=String(r);if(e==="1"||e==="true")return!0;if(e==="0"||e==="false")return!1;throw B()},"boolean"),x=$(r=>{if(typeof r=="number")return r;if(typeof r=="string"){const e=Number(r);if(!Number.isNaN(e))return e}throw B()},"number"),ne=$(r=>r instanceof Date?r:new Date(x().parse(r)*1e3),"Date");function ie(r){let e=r;if(typeof e=="string"&&(e=JSON.parse(e)),typeof e!="object"||e===null||Array.isArray(e))throw B();return e}function f(r,e){return new J(t=>{const s=ie(t);return ve(r,n=>s[n])},!1,e)}function Q(r){return/^#[\da-f]{6}$/i.test(r)}function ke(r){return/^#[\da-f]{3}$/i.test(r)}function oe(r){const e=r.replace(/\s/g,"").toLowerCase();if(Q(e))return e;if(ke(e)){let s="#";for(let n=0;n<3;n+=1)s+=e[1+n].repeat(2);return s}const t=e.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)||e.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);if(t===null)throw new Error(`Value "${r}" does not satisfy any of known RGB formats.`);return t.slice(1).reduce((s,n)=>{const i=parseInt(n,10).toString(16);return s+(i.length===1?"0":"")+i},"#")}function ae(r){const e=oe(r);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const a=parseInt(e.slice(1+i*2,1+(i+1)*2),16);return s+a*a*n},0))<120}const u=$(r=>{if(typeof r=="string"||typeof r=="number")return r.toString();throw B()},"string"),ce=$(r=>oe(u().parse(r)),"rgb");function Z(r,e){return new J(t=>{if(typeof t!="string"&&!(t instanceof URLSearchParams))throw B();const s=typeof t=="string"?new URLSearchParams(t):t;return ve(r,n=>{const i=s.get(n);return i===null?void 0:i})},!1,e)}function xe(){return f({id:x(),type:u(),title:u(),photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"Chat")}class qe{constructor(e){this.initData=e}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:e}=this;return e===void 0?void 0:new Date(this.authDate.getTime()+e*1e3)}get chat(){return this.initData.chat}get chatType(){return this.initData.chatType}get chatInstance(){return this.initData.chatInstance}get hash(){return this.initData.hash}get queryId(){return this.initData.queryId}get receiver(){return this.initData.receiver}get startParam(){return this.initData.startParam}get user(){return this.initData.user}}function re(){return f({addedToAttachmentMenu:{type:E().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:E().optional(),from:"allows_write_to_pm"},firstName:{type:u(),from:"first_name"},id:x(),isBot:{type:E().optional(),from:"is_bot"},isPremium:{type:E().optional(),from:"is_premium"},languageCode:{type:u().optional(),from:"language_code"},lastName:{type:u().optional(),from:"last_name"},photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"User")}function ue(){return Z({authDate:{type:ne(),from:"auth_date"},canSendAfter:{type:x().optional(),from:"can_send_after"},chat:xe().optional(),chatInstance:{type:u().optional(),from:"chat_instance"},chatType:{type:u().optional(),from:"chat_type"},hash:u(),queryId:{type:u().optional(),from:"query_id"},receiver:re().optional(),startParam:{type:u().optional(),from:"start_param"},user:re().optional()},"InitData")}function pt(r){return ue().parse(r)}function lt(r){return r.replace(/(^|_)bg/,(e,t)=>`${t}background`).replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function dt(r){return r.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`).replace(/(^|_)background/,(e,t)=>`${t}bg`)}const he=$(r=>{const e=ce().optional();return Object.entries(ie(r)).reduce((t,[s,n])=>(t[lt(s)]=e.parse(n),t),{})},"ThemeParams");function pe(r){return he().parse(r)}function ft(r={}){return b("web_app_request_theme","theme_changed",r).then(pe)}function Ae(r){return JSON.stringify(Object.entries(r).reduce((e,[t,s])=>(s&&(e[dt(t)]=s),e),{}))}class w{constructor(){o(this,"listeners",new Map);o(this,"subscribeListeners",[])}addListener(e,t,s){let n=this.listeners.get(e);return n||(n=[],this.listeners.set(e,n)),n.push([t,s]),()=>this.off(e,t)}emit(e,...t){this.subscribeListeners.forEach(n=>n(e,...t));const s=this.listeners.get(e);s&&s.forEach(([n,i],a)=>{n(...t),i&&s.splice(a,1)})}on(e,t){return this.addListener(e,t,!1)}once(e,t){return this.addListener(e,t,!0)}off(e,t){const s=this.listeners.get(e);if(s){for(let n=0;n<s.length;n+=1)if(t===s[n][0]){s.splice(n,1);return}}}subscribe(e){return this.subscribeListeners.push(e),()=>this.unsubscribe(e)}unsubscribe(e){for(let t=0;t<this.subscribeListeners.length;t+=1)if(this.subscribeListeners[t]===e){this.subscribeListeners.splice(t,1);return}}}class m{constructor(e,t){this.state=e,this.ee=t}internalSet(e,t){return this.state[e]===t||t===void 0?!1:(this.state[e]=t,this.ee.emit(`change:${e}`,t),!0)}clone(){return{...this.state}}set(e,t){let s=!1;if(typeof e=="string")s=this.internalSet(e,t);else for(const n in e)this.internalSet(n,e[n])&&(s=!0);s&&this.ee.emit("change")}get(e){return this.state[e]}}class Ve{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));this.state=new m(e,this.ee)}get accentTextColor(){return this.get("accentTextColor")}get backgroundColor(){return this.get("backgroundColor")}get buttonColor(){return this.get("buttonColor")}get buttonTextColor(){return this.get("buttonTextColor")}get destructiveTextColor(){return this.get("destructiveTextColor")}get(e){return this.state.get(e)}getState(){return this.state.clone()}get headerBackgroundColor(){return this.get("headerBackgroundColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.backgroundColor||ae(this.backgroundColor)}get linkColor(){return this.get("linkColor")}get secondaryBackgroundColor(){return this.get("secondaryBackgroundColor")}get sectionBackgroundColor(){return this.get("sectionBackgroundColor")}get sectionHeaderTextColor(){return this.get("sectionHeaderTextColor")}listen(){return y("theme_changed",e=>{this.state.set(pe(e.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}function le(){return Z({botInline:{type:E().optional(),from:"tgWebAppBotInline"},initData:{type:ue().optional(),from:"tgWebAppData"},initDataRaw:{type:u().optional(),from:"tgWebAppData"},platform:{type:u(),from:"tgWebAppPlatform"},showSettings:{type:E().optional(),from:"tgWebAppShowSettings"},startParam:{type:u().optional(),from:"tgWebAppStartParam"},themeParams:{type:he(),from:"tgWebAppThemeParams"},version:{type:u(),from:"tgWebAppVersion"}},"LaunchParams")}function Re(r){return le().parse(r)}function Te(r){const e=r.includes("?")?r.replace("#","&").slice(r.indexOf("?")+1):r.slice(r.indexOf("#")+1);return Re(e)}function gt(){return Te(window.location.href)}function wt(){const r=Pe();if(!r)throw new Error("Unable to get first navigation entry.");return Te(r.name)}function _t(){try{return wt()}catch{}try{return gt()}catch{}return null}function Ie(r){const{initDataRaw:e,themeParams:t,platform:s,version:n,showSettings:i,botInline:a}=r,c=new URLSearchParams;return e&&c.set("tgWebAppData",e),c.set("tgWebAppPlatform",s),c.set("tgWebAppThemeParams",Ae(t)),c.set("tgWebAppVersion",n),typeof i=="boolean"&&c.set("tgWebAppShowSettings",i?"1":"0"),typeof a=="boolean"&&c.set("tgWebAppBotInline",a?"1":"0"),c.toString()}const Le="telegram-mini-apps-launch-params";function bt(){const r=sessionStorage.getItem(Le);return r?le().parse(r):null}function mt(r){sessionStorage.setItem(Le,Ie(r))}function yt(){try{return window.self!==window.top}catch{return!0}}function Et(){const r=bt(),e=_t(),t=ct();if(r){if(e)return{launchParams:e,isPageReload:yt()?t||r.initDataRaw===e.initDataRaw:!0};if(t)return{launchParams:r,isPageReload:t};throw new Error("Unable to retrieve current launch parameters, which must exist.")}if(e)return{launchParams:e,isPageReload:!1};throw new Error("Unable to retrieve any launch parameters.")}const be="tmajsLaunchData";function de(){const r=window[be];if(r)return r;const e=Et();return window[be]=e,mt(e.launchParams),e}function Ct(){try{return de(),!0}catch{return!1}}function Pt(r){return"external"in r&&A(r.external)&&"notify"in r.external&&typeof r.external.notify=="function"}function vt(r){return"TelegramWebviewProxy"in r&&A(r.TelegramWebviewProxy)&&"postEvent"in r.TelegramWebviewProxy&&typeof r.TelegramWebviewProxy.postEvent=="function"}function fe(){try{return window.self!==window.top}catch{return!0}}class K extends Error{constructor(e,t){super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`),Object.setPrototypeOf(this,K.prototype)}}class Y extends Error{constructor(e,t,s){super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`),Object.setPrototypeOf(this,Y.prototype)}}class Be{constructor(e,t){this.prefix=e,this.enabled=t}print(e,...t){if(!this.enabled)return;const s=new Date,n=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(s);console[e](`[${n}]`,this.prefix,...t)}disable(){this.enabled=!1}error(...e){this.print("error",...e)}enable(){this.enabled=!0}log(...e){this.print("log",...e)}warn(...e){this.print("warn",...e)}}let $e="https://web.telegram.org";const L=new Be("[SDK]",!1);function St(r){if(r){L.enable();return}L.disable()}function kt(r){$e=r}function xt(){return $e}const qt=f({eventType:u(),eventData:r=>r});function De(r){return qt.parse(r)}function At(r,e){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:r,eventData:e}),source:window.parent}))}function Vt(){const r=window;"TelegramGameProxy_receiveEvent"in r||[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=r;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=At;return}s in t||(t[s]={}),t=t[s]})})}function Rt(r){Vt(),window.addEventListener("message",e=>{if(e.source===window.parent)try{const{eventType:t,eventData:s}=De(e.data);r(t,s)}catch{}})}function Tt(){return f({req_id:u(),data:r=>r===null?r:u().optional().parse(r)})}function It(){return f({req_id:u(),result:r=>r,error:u().optional()})}function Lt(){return f({slug:u(),status:u()})}function Bt(){return f({status:u()})}function $t(){return f({button_id:r=>r==null?void 0:u().parse(r)})}function Dt(){return f({data:u().optional()})}function Nt(){return f({theme_params:r=>{const e=ce().optional();return Object.entries(ie(r)).reduce((t,[s,n])=>(t[s]=e.parse(n),t),{})}})}function Ot(){return f({height:x(),width:r=>r==null?window.innerWidth:x().parse(r),is_state_stable:E(),is_expanded:E()})}function Wt(){return f({status:u()})}function Ht(){const r=new w,e=(t,...s)=>{L.log("Emitting processed event:",t,...s),r.emit(t,...s)};return window.addEventListener("resize",()=>{e("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),Rt((t,s)=>{L.log("Received raw event:",t,s);try{switch(t){case"viewport_changed":return e(t,Ot().parse(s));case"theme_changed":return e(t,Nt().parse(s));case"popup_closed":return s==null?e(t,{}):e(t,$t().parse(s));case"set_custom_style":return e(t,u().parse(s));case"qr_text_received":return e(t,Dt().parse(s));case"clipboard_text_received":return e(t,Tt().parse(s));case"invoice_closed":return e(t,Lt().parse(s));case"phone_requested":return e("phone_requested",Bt().parse(s));case"custom_method_invoked":return e("custom_method_invoked",It().parse(s));case"write_access_requested":return e("write_access_requested",Wt().parse(s));case"main_button_pressed":case"back_button_pressed":case"settings_button_pressed":case"scan_qr_popup_closed":case"reload_iframe":return e(t);default:return e(t,s)}}catch(n){L.error("Error processing event:",n)}}),r}const X="telegram-mini-apps-cached-emitter";function G(){const r=window;return r[X]===void 0&&(r[X]=Ht()),r[X]}function R(r,e){G().off(r,e)}function y(r,e){return G().on(r,e),()=>R(r,e)}function Mt(r,e){return G().once(r,e),()=>R(r,e)}function Ne(r){G().unsubscribe(r)}function Ut(r){return G().subscribe(r),()=>Ne(r)}function Oe(r,e){const t=r.split("."),s=e.split("."),n=Math.max(t.length,s.length);for(let i=0;i<n;i+=1){const a=parseInt(t[i]||"0",10),c=parseInt(s[i]||"0",10);if(a!==c)return a>c?1:-1}return 0}function k(r,e){return Oe(r,e)<=0}function V(r,e,t){if(typeof t=="string"){if(r==="web_app_open_link"&&e==="try_instant_view")return k("6.4",t);if(r==="web_app_set_header_color"&&e==="color")return k("6.9",t)}switch(r){case"web_app_open_tg_link":case"web_app_open_invoice":case"web_app_setup_back_button":case"web_app_set_background_color":case"web_app_set_header_color":case"web_app_trigger_haptic_feedback":return k("6.1",e);case"web_app_open_popup":return k("6.2",e);case"web_app_close_scan_qr_popup":case"web_app_open_scan_qr_popup":case"web_app_read_text_from_clipboard":return k("6.4",e);case"web_app_switch_inline_query":return k("6.7",e);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return k("6.9",e);case"web_app_setup_settings_button":return k("6.10",e);default:return!0}}function P(r,e){return t=>V(e[t],r)}function We(r,e){return t=>{const[s,n]=e[t];return V(s,n,r)}}function d(r,e,t){let s={},n;e===void 0&&t===void 0?s={}:e!==void 0&&t!==void 0?(s=t,n=e):e!==void 0&&("targetOrigin"in e?s=e:n=e);const{targetOrigin:i=xt()}=s;if(L.log(`Calling method "${r}"`,n),fe()){window.parent.postMessage(JSON.stringify({eventType:r,eventData:n}),i);return}if(Pt(window)){window.external.notify(JSON.stringify({eventType:r,eventData:n}));return}if(vt(window)){window.TelegramWebviewProxy.postEvent(r,JSON.stringify(n));return}throw new Error("Unable to determine current environment and possible way to send event.")}function He(r){return(e,t)=>{if(!V(e,r))throw new K(e,r);if(A(t)){let s;if(e==="web_app_open_link"&&"try_instant_view"in t?s="try_instant_view":e==="web_app_set_header_color"&&"color"in t&&(s="color"),s&&!V(e,s,r))throw new Y(e,s,r)}return d(e,t)}}class j extends Error{constructor(e){super(`Async call timeout exceeded. Timeout: ${e}`),Object.setPrototypeOf(this,j.prototype)}}function Gt(r){return r instanceof j}function jt(r){return new Promise(e=>{setTimeout(e,r)})}function Ft(r){return new Promise((e,t)=>{setTimeout(t,r,new j(r))})}function ge(r,e){return Promise.race([r(),Ft(e)])}function b(r,e,t,s){let n,i,a,c;typeof e=="string"||Array.isArray(e)?(a=Array.isArray(e)?e:[e],n=t):(i=e,a=Array.isArray(t)?t:[t],n=s),A(i)&&typeof i.req_id=="string"&&(c=i.req_id);const{postEvent:p=d,timeout:h}=n||{},g=n&&"capture"in n?n.capture:null,_=()=>new Promise((T,l)=>{const v=a.map(S=>y(S,F=>{c&&(!A(F)||F.req_id!==c)||typeof g=="function"&&!g(F)||(q(),T(F))})),q=()=>v.forEach(S=>S());try{p(r,i)}catch(S){q(),l(S)}});return typeof h=="number"?ge(_,h):_()}async function I(r,e,t,s={}){const{result:n,error:i}=await b("web_app_invoke_custom_method",{method:r,params:e,req_id:t},"custom_method_invoked",s);if(i)throw new Error(i);return n}class Me{constructor(e,t,s=d){o(this,"ee",new w);o(this,"state");o(this,"on",(e,t)=>e==="click"?y("back_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?R("back_button_pressed",t):this.ee.off(e,t));o(this,"supports");this.postEvent=s,this.state=new m({isVisible:e},this.ee),this.supports=P(t,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_back_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function me(r,e){return r+(r.length>0&&e.length>0?` ${e}`:e)}function Ue(...r){return r.reduce((e,t)=>{let s="";return typeof t=="string"?s=t:typeof t=="object"&&t!==null&&(s=Object.entries(t).reduce((n,[i,a])=>a?me(n,i):n,"")),me(e,s)},"")}function zt(...r){return r.reduce((e,t)=>(A(t)&&Object.entries(t).forEach(([s,n])=>{const i=Ue(e[s],n);i.length>0&&(e[s]=i)}),e),{})}class Ge{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));this.postEvent=t,this.state=new m({isConfirmationNeeded:e},this.ee)}set isConfirmationNeeded(e){this.state.set("isConfirmationNeeded",e),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:e})}get isConfirmationNeeded(){return this.state.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}function ye(r,e){return r.reduce((t,s)=>(t[s]=e,t),{})}class je{constructor(e,t,s=d){o(this,"supports");this.createRequestId=t,this.postEvent=s,this.supports=P(e,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"})}async delete(e,t={}){const s=Array.isArray(e)?e:[e];s.length!==0&&await I("deleteStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent})}async getKeys(e={}){const t=await I("getStorageKeys",{},this.createRequestId(),{...e,postEvent:this.postEvent});return Se().of(u()).parse(t)}async get(e,t={}){const s=Array.isArray(e)?e:[e];if(s.length===0)return ye(s,"");const n=f(ye(s,u())),i=await I("getStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent}).then(a=>n.parse(a));return Array.isArray(e)?i:i[e]}async set(e,t,s={}){await I("saveStorageValue",{key:e,value:t},this.createRequestId(),{...s,postEvent:this.postEvent})}}function C(r,e){document.documentElement.style.setProperty(r,e)}function Fe(r,e){const t=()=>{C("--tg-background-color",r.backgroundColor)},s=()=>{const{backgroundColor:n,secondaryBackgroundColor:i}=e;if(Q(r.headerColor)){C("--tg-header-color",r.headerColor);return}if(r.headerColor==="bg_color"&&n){C("--tg-header-color",n);return}r.headerColor==="secondary_bg_color"&&i&&C("--tg-header-color",i)};e.on("change",s),r.on("change:backgroundColor",t),r.on("change:headerColor",s),t(),s()}function ze(r){const e=()=>{const t=r.getState();Object.entries(t).forEach(([s,n])=>{if(n){const i=s.replace(/[A-Z]/g,a=>`-${a.toLowerCase()}`);C(`--tg-theme-${i}`,n)}})};r.on("change",e),e()}function se(r){const e=()=>C("--tg-viewport-height",`${r.height}px`),t=()=>C("--tg-viewport-width",`${r.width}px`),s=()=>C("--tg-viewport-stable-height",`${r.stableHeight}px`);r.on("change:height",e),r.on("change:width",t),r.on("change:stableHeight",s),e(),t(),s()}class Je{constructor(e,t=d){o(this,"supports");this.postEvent=t,this.supports=P(e,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"})}impactOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:e})}notificationOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:e})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}function Jt(){const r=document.createElement("style");r.id="telegram-custom-styles",document.head.appendChild(r),y("set_custom_style",e=>{r.innerHTML=e})}function Qe(r){return`telegram-mini-apps-${r}`}function D(r,e){sessionStorage.setItem(Qe(r),JSON.stringify(e))}function N(r){const e=sessionStorage.getItem(Qe(r));return e?JSON.parse(e):null}function Qt(r,e,t){const{isVisible:s=!1}=r?N("back-button")||{}:{},n=new Me(s,e,t);return n.on("change",()=>{D("back-button",{isVisible:n.isVisible})}),n}function Zt(r,e){const{isConfirmationNeeded:t=!1}=r?N("closing-behavior")||{}:{},s=new Ge(t,e);return s.on("change",()=>D("closing-behavior",{isConfirmationNeeded:s.isConfirmationNeeded})),s}class Ze{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"postEvent");o(this,"on",(e,t)=>e==="click"?y("main_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?R("main_button_pressed",t):this.ee.off(e,t));const{postEvent:t=d,text:s,textColor:n,backgroundColor:i,isEnabled:a,isVisible:c,isLoaderVisible:p}=e;this.postEvent=t,this.state=new m({backgroundColor:i,isEnabled:a,isVisible:c,isLoaderVisible:p,text:s,textColor:n},this.ee)}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isLoaderVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}set isEnabled(e){this.setParams({isEnabled:e})}get isEnabled(){return this.state.get("isEnabled")}set isLoaderVisible(e){this.setParams({isLoaderVisible:e})}get isLoaderVisible(){return this.state.get("isLoaderVisible")}set isVisible(e){this.setParams({isVisible:e})}get isVisible(){return this.state.get("isVisible")}get backgroundColor(){return this.state.get("backgroundColor")}get text(){return this.state.get("text")}get textColor(){return this.state.get("textColor")}disable(){return this.isEnabled=!1,this}enable(){return this.isEnabled=!0,this}hide(){return this.isVisible=!1,this}hideLoader(){return this.isLoaderVisible=!1,this}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(e){return this.setParams({text:e})}setTextColor(e){return this.setParams({textColor:e})}setBackgroundColor(e){return this.setParams({backgroundColor:e})}setParams(e){return this.state.set(e),this.commit(),this}}function Kt(r,e,t,s){const{backgroundColor:n=e,isEnabled:i=!1,isVisible:a=!1,isLoaderVisible:c=!1,textColor:p=t,text:h=""}=r?N("main-button")||{}:{},g=new Ze({backgroundColor:n,isEnabled:i,isLoaderVisible:c,isVisible:a,postEvent:s,text:h,textColor:p}),_=()=>D("main-button",{backgroundColor:g.backgroundColor,isEnabled:g.isEnabled,isLoaderVisible:g.isLoaderVisible,isVisible:g.isVisible,text:g.text,textColor:g.textColor});return g.on("change",_),g}const Yt=Z({contact:f({userId:{type:x(),from:"user_id"},phoneNumber:{type:u(),from:"phone_number"},firstName:{type:u(),from:"first_name"},lastName:{type:u().optional(),from:"last_name"}}),authDate:{type:ne(),from:"auth_date"},hash:u()});class Ke{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"botInline");o(this,"postEvent");o(this,"createRequestId");o(this,"requestingPhoneAccess",!1);o(this,"requestingWriteAccess",!1);o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");o(this,"supportsParam");const{postEvent:t=d,headerColor:s,backgroundColor:n,version:i,botInline:a,createRequestId:c}=e,p=P(i,{requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access",switchInlineQuery:"web_app_switch_inline_query",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color"});this.postEvent=t,this.botInline=a,this.createRequestId=c,this.supports=h=>!(!p(h)||h==="switchInlineQuery"&&!a),this.state=new m({backgroundColor:n,headerColor:s},this.ee),this.supportsParam=We(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact(){return I("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:1e4}).then(e=>Yt.parse(e))}get backgroundColor(){return this.state.get("backgroundColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return ae(this.backgroundColor)}get isRequestingPhoneAccess(){return this.requestingPhoneAccess}get isRequestingWriteAccess(){return this.requestingWriteAccess}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:e=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const s=Date.now()+e;let n=50;return ge(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await jt(n),n+=50}throw new Error("Unable to retrieve requested contact.")},e)}requestPhoneAccess(e={}){if(this.requestingPhoneAccess)throw new Error("Phone access is already being requested.");return this.requestingPhoneAccess=!0,b("web_app_request_phone","phone_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingPhoneAccess=!1})}requestWriteAccess(e={}){if(this.requestingWriteAccess)throw new Error("Write access is already being requested.");return this.requestingWriteAccess=!0,b("web_app_request_write_access","write_access_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingWriteAccess=!1})}sendData(e){const{size:t}=new Blob([e]);if(t===0||t>4096)throw new Error(`Passed data has incorrect size: ${t}`);this.postEvent("web_app_data_send",{data:e})}setHeaderColor(e){this.postEvent("web_app_set_header_color",Q(e)?{color:e}:{color_key:e}),this.state.set("headerColor",e)}setBackgroundColor(e){this.postEvent("web_app_set_background_color",{color:e}),this.state.set("backgroundColor",e)}switchInlineQuery(e,t=[]){if(!this.supports("switchInlineQuery")&&!this.isBotInline)throw new Error("Method is unsupported because Mini App should be launched in inline mode.");this.postEvent("web_app_switch_inline_query",{query:e,chat_types:t})}}function Xt(r,e,t,s,n,i){const{backgroundColor:a=e,headerColor:c="bg_color"}=r?N("mini-app")||{}:{},p=new Ke({headerColor:c,backgroundColor:a,version:t,botInline:s,createRequestId:n,postEvent:i}),h=()=>D("mini-app",{backgroundColor:p.backgroundColor,headerColor:p.headerColor});return p.on("change",h),p}function er(){let r=0;return()=>(r+=1,r.toString())}class Ye{constructor(e,t,s=d){o(this,"ee",new w);o(this,"state");o(this,"on",(e,t)=>e==="click"?y("settings_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?R("settings_button_pressed",t):this.ee.off(e,t));o(this,"supports");this.postEvent=s,this.state=new m({isVisible:e},this.ee),this.supports=P(t,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_settings_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function tr(r,e,t){const{isVisible:s=!1}=r?N("settings-button")||{}:{},n=new Ye(s,e,t);return n.on("change",()=>{D("settings-button",{isVisible:n.isVisible})}),n}function rr(r){const e=new Ve(r);return e.listen(),e}function Xe(r){return["macos","tdesktop","unigram","web","weba"].includes(r)}async function we(r){const e=await b("web_app_request_viewport","viewport_changed",r);return{height:e.height,width:e.width,isExpanded:e.is_expanded,isStateStable:e.is_state_stable}}function O(r){return r<0?0:r}class et{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"postEvent");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));const{height:t,isExpanded:s,width:n,stableHeight:i,postEvent:a=d}=e;this.postEvent=a,this.state=new m({height:O(t),isExpanded:s,stableHeight:O(i),width:O(n)},this.ee)}sync(e){return we(e).then(({height:t,isExpanded:s,width:n,isStateStable:i})=>{this.state.set({height:t,width:n,isExpanded:s,stableHeight:i?t:this.state.get("stableHeight")})})}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}listen(){return y("viewport_changed",e=>{const{height:t,width:s,is_expanded:n,is_state_stable:i}=e,a={height:O(t),isExpanded:n,width:O(s)};i&&(a.stableHeight=a.height),this.state.set(a)})}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.postEvent("web_app_expand"),this.state.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}function z(r){const e=new et(r);return e.on("change",()=>D("viewport",{height:e.height,isExpanded:e.isExpanded,stableHeight:e.stableHeight,width:e.width})),e.listen(),e}function sr(r,e,t,s){const n=r?N("viewport"):null;if(n)return z({...n,postEvent:t});if(Xe(e))return z({height:window.innerHeight,isExpanded:!0,postEvent:t,stableHeight:window.innerHeight,width:window.innerWidth});if(s)return we({postEvent:t,timeout:5e3}).then(({height:a,isStateStable:c,...p})=>z({...p,height:a,stableHeight:c?a:0}));const i=z({width:0,height:0,isExpanded:!1,postEvent:t,stableHeight:0});return i.sync({postEvent:t,timeout:5e3}).catch(a=>{console.error("Unable to actualize viewport state",a)}),i}function nr(r){return typeof r=="object"?r:r?{themeParams:!0,viewport:!0,miniApp:!0}:{}}function Ee(r,e,t,s){const n=nr(r);n.miniApp&&Fe(e,t),n.themeParams&&ze(t),n.viewport&&(s instanceof Promise?s.then(se):se(s))}function ir(r){const{hostname:e,pathname:t}=new URL(r,window.location.href);if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const s=t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(s===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');return s[2]}class tt{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new m({isOpened:!1},this.ee),this.supports=P(e,{open:"web_app_open_invoice"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e,t){if(this.isOpened)throw new Error("Invoice is already opened");const s=t?ir(e):e;this.isOpened=!0;try{return(await b("web_app_open_invoice",{slug:s},"invoice_closed",{postEvent:this.postEvent,capture(i){return s===i.slug}})).status}finally{this.isOpened=!1}}}function or(r){const e=r.message.trim(),t=(r.title||"").trim(),s=r.buttons||[];let n;if(t.length>64)throw new Error(`Title has incorrect size: ${t.length}`);if(e.length===0||e.length>256)throw new Error(`Message has incorrect size: ${e.length}`);if(s.length>3)throw new Error(`Buttons have incorrect size: ${s.length}`);return s.length===0?n=[{type:"close",id:""}]:n=s.map(i=>{const{id:a=""}=i;if(a.length>64)throw new Error(`Button ID has incorrect size: ${a}`);if(i.type===void 0||i.type==="default"||i.type==="destructive"){const c=i.text.trim();if(c.length===0||c.length>64){const p=i.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${i.text.length}`)}return{...i,text:c,id:a}}return{...i,id:a}}),{title:t,message:e,buttons:n}}class rt{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new m({isOpened:!1},this.ee),this.supports=P(e,{open:"web_app_open_popup"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}open(e){if(this.isOpened)throw new Error("Popup is already opened.");return this.isOpened=!0,b("web_app_open_popup",or(e),"popup_closed",{postEvent:this.postEvent}).then(({button_id:t=null})=>t).finally(()=>{this.isOpened=!1})}}class st{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new m({isOpened:!1},this.ee),this.supports=P(e,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"})}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{const t=await b("web_app_open_scan_qr_popup",{text:e},["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent});return typeof t=="object"&&typeof t.data=="string"?t.data:null}finally{this.isOpened=!1}}}class nt{constructor(e,t,s=d){o(this,"supports");o(this,"supportsParam");this.version=e,this.createRequestId=t,this.postEvent=s,this.supports=P(e,{readTextFromClipboard:"web_app_read_text_from_clipboard"}),this.supportsParam=We(e,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(e,t){const s=new URL(e,window.location.href).toString();if(!V("web_app_open_link",this.version)){window.open(s,"_blank");return}this.postEvent("web_app_open_link",{url:s,...typeof t=="boolean"?{try_instant_view:t}:{}})}openTelegramLink(e){const{hostname:t,pathname:s,search:n}=new URL(e,window.location.href);if(t!=="t.me")throw new Error(`URL has not allowed hostname: ${t}. Only "t.me" is allowed`);if(!V("web_app_open_tg_link",this.version)){window.location.href=e;return}this.postEvent("web_app_open_tg_link",{path_full:s+n})}readTextFromClipboard(){return b("web_app_read_text_from_clipboard",{req_id:this.createRequestId()},"clipboard_text_received",{postEvent:this.postEvent}).then(({data:e=null})=>e)}}function ar(r={}){const{async:e=!1,complete:t=e,cssVars:s=!1,acceptCustomStyles:n=!1}=r;try{const{launchParams:{initData:i,initDataRaw:a,version:c,platform:p,themeParams:h,botInline:g=!1},isPageReload:_}=de(),T=er(),l=He(c);fe()&&(n&&Jt(),l("iframe_ready",{reload_supported:!0}),y("reload_iframe",()=>window.location.reload()));const v={backButton:Qt(_,c,l),closingBehavior:Zt(_,l),cloudStorage:new je(c,T,l),createRequestId:T,hapticFeedback:new Je(c,l),invoice:new tt(c,l),mainButton:Kt(_,h.buttonColor||"#000000",h.buttonTextColor||"#ffffff",l),miniApp:Xt(_,h.backgroundColor||"#ffffff",c,g,T,l),popup:new rt(c,l),postEvent:l,qrScanner:new st(c,l),settingsButton:tr(_,c,l),themeParams:rr(h),utils:new nt(c,T,l),...i?{initData:new qe(i),initDataRaw:a}:{}},q=sr(_,p,l,t);return q instanceof Promise||t?Promise.resolve(q).then(S=>(Ee(s,v.miniApp,v.themeParams,S),{...v,viewport:S})):(Ee(s,v.miniApp,v.themeParams,q),{...v,viewport:q})}catch(i){if(t)return Promise.reject(i);throw i}}function W(r,e){return r.startsWith(e)?r:`${e}${r}`}function cr(r){const e=r.match(/#(.+)/);return e?e[1]:null}async function H(r){return r===0?!0:Promise.race([new Promise(e=>{window.addEventListener("popstate",function t(){window.removeEventListener("popstate",t),e(!0)}),window.history.go(r)}),new Promise(e=>{setTimeout(e,50,!1)})])}async function ur(){if(window.history.length<=1||(window.history.pushState(null,""),await H(1-window.history.length)))return;let e=await H(-1);for(;e;)e=await H(-1)}class it{constructor(e,t,{debug:s=!1,loggerPrefix:n="Navigator"}){o(this,"logger");o(this,"entries");if(this.entriesCursor=t,e.length===0)throw new Error("Entries list should not be empty.");if(t>=e.length)throw new Error("Cursor should be less than entries count.");this.entries=e.map(({pathname:i="",search:a,hash:c})=>{if(!i.startsWith("/")&&i.length>0)throw new Error('Pathname should start with "/"');return{pathname:W(i,"/"),search:a?W(a,"?"):"",hash:c?W(c,"#"):""}}),this.logger=new Be(`[${n}]`,s)}formatEntry(e){let t;if(typeof e=="string")t=e;else{const{pathname:a="",search:c,hash:p}=e;t=a+(c?W(c,"?"):"")+(p?W(p,"#"):"")}const{pathname:s,search:n,hash:i}=new URL(t,`https://localhost${this.path}`);return{pathname:s,search:n,hash:i}}get entry(){return this.entries[this.entriesCursor]}back(){return this.go(-1)}get cursor(){return this.entriesCursor}get canGoBack(){return this.entriesCursor>0}get canGoForward(){return this.entriesCursor!==this.entries.length-1}forward(){return this.go(1)}go(e){this.logger.log(`called go(${e})`);const t=Math.min(this.entries.length-1,Math.max(this.entriesCursor+e,0));if(this.entriesCursor===t)return this.performGo({updated:!1,delta:e});const s=this.entry;this.entriesCursor=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performGo({updated:!0,delta:e,before:s,after:n})}getEntries(){return this.entries.map(e=>({...e}))}get hash(){return this.entry.hash}push(e){this.entriesCursor!==this.entries.length-1&&this.entries.splice(this.entriesCursor+1);const t=this.formatEntry(e),s=this.entry;this.entriesCursor+=1,this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performPush({before:s,after:n})}get path(){return`${this.pathname}${this.search}${this.hash}`}get pathname(){return this.entry.pathname}replace(e){const t=this.formatEntry(e);if(this.search===t.search&&this.pathname===t.pathname&&this.hash===t.hash)return this.performReplace({updated:!1,entry:t});const s=this.entry;this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performReplace({updated:!0,before:s,after:n})}get search(){return this.entry.search}}const Ce=0,ee=1,te=2;class _e extends it{constructor(t,s,n={}){super(t,s,{...n,loggerPrefix:"HashNavigator"});o(this,"ee",new w);o(this,"attached",!1);o(this,"onPopState",async({state:t})=>{if(this.logger.log('"popstate" event received. State:',t),t===null)return this.push(window.location.hash.slice(1));if(t===Ce){this.logger.log("Void reached. Moving history forward"),window.history.forward();return}if(t===ee)return this.back();if(t===te)return this.forward()});o(this,"back",()=>super.back());o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee))}static fromLocation(t){const{search:s,pathname:n,hash:i}=new URL(window.location.hash.slice(1),window.location.href);return new _e([{search:s,pathname:n,hash:i}],0,t)}async performGo(t){t.updated&&(this.attached&&await this.syncHistory(),this.emitChanged(t.before,t.after))}async performPush({before:t,after:s}){this.attached&&await this.syncHistory(),this.emitChanged(t,s)}async performReplace(t){t.updated&&(this.attached&&window.history.replaceState(null,"",`#${this.path}`),this.emitChanged(t.before,t.after))}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const t=`#${this.path}`;await ur(),d("web_app_setup_back_button",{is_visible:this.canGoBack}),this.canGoBack&&this.canGoForward?(this.logger.log("Setting up history: [<-, *, ->]"),window.history.replaceState(ee,""),window.history.pushState(null,"",t),window.history.pushState(te,""),await H(-1)):this.canGoBack?(this.logger.log("Setting up history: [<-, *]"),window.history.replaceState(ee,""),window.history.pushState(null,"",t)):this.canGoForward?(this.logger.log("Setting up history: [*, ->]"),window.history.replaceState(null,t),window.history.pushState(te,""),await H(-1)):(this.logger.log("Setting up history: [~, *]"),window.history.replaceState(Ce,""),window.history.pushState(null,"",t)),window.addEventListener("popstate",this.onPopState)}emitChanged(t,s){this.ee.emit("change",{navigator:this,from:t,to:s})}async attach(){if(!this.attached)return this.logger.log("Attaching",this),this.attached=!0,y("back_button_pressed",this.back),this.syncHistory()}detach(){this.attached&&(this.logger.log("Detaching",this),this.attached=!1,window.removeEventListener("popstate",this.onPopState),R("back_button_pressed",this.back))}}exports.BackButton=Me;exports.ClosingBehavior=Ge;exports.CloudStorage=je;exports.HapticFeedback=Je;exports.HashNavigator=_e;exports.InitData=qe;exports.Invoice=tt;exports.MainButton=Ze;exports.MethodUnsupportedError=K;exports.MiniApp=Ke;exports.Navigator=it;exports.ParameterUnsupportedError=Y;exports.ParseError=U;exports.ParseSchemaFieldError=M;exports.Popup=rt;exports.QRScanner=st;exports.SettingsButton=Ye;exports.ThemeParams=Ve;exports.TimeoutError=j;exports.Utils=nt;exports.Viewport=et;exports.array=Se;exports.bindMiniAppCSSVars=Fe;exports.bindThemeCSSVars=ze;exports.bindViewportCSSVars=se;exports.boolean=E;exports.chatParser=xe;exports.classNames=Ue;exports.compareVersions=Oe;exports.createPostEvent=He;exports.date=ne;exports.getHash=cr;exports.init=ar;exports.initDataParser=ue;exports.invokeCustomMethod=I;exports.isColorDark=ae;exports.isIframe=fe;exports.isRGB=Q;exports.isRGBShort=ke;exports.isRecord=A;exports.isStableViewportPlatform=Xe;exports.isTMA=Ct;exports.isTimeoutError=Gt;exports.json=f;exports.launchParamsParser=le;exports.mergeClassNames=zt;exports.number=x;exports.off=R;exports.on=y;exports.once=Mt;exports.parseInitData=pt;exports.parseLaunchParams=Re;exports.parseMessage=De;exports.parseThemeParams=pe;exports.postEvent=d;exports.request=b;exports.requestThemeParams=ft;exports.requestViewport=we;exports.retrieveLaunchData=de;exports.rgb=ce;exports.searchParams=Z;exports.serializeLaunchParams=Ie;exports.serializeThemeParams=Ae;exports.setCSSVar=C;exports.setDebug=St;exports.setTargetOrigin=kt;exports.string=u;exports.subscribe=Ut;exports.supports=V;exports.themeParamsParser=he;exports.toRGB=oe;exports.unsubscribe=Ne;exports.userParser=re;exports.withTimeout=ge;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
"use strict";var ot=Object.defineProperty;var at=(r,e,t)=>e in r?ot(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var o=(r,e,t)=>(at(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function ve(){return performance.getEntriesByType("navigation")[0]}function ie(){try{return window.self!==window.top}catch{return!0}}function oe(){var r;return((r=ve())==null?void 0:r.type)==="reload"}function V(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function B(){return new TypeError("Value has unexpected type")}class U extends Error{constructor(t,{cause:s,type:n}={}){super(`Unable to parse value${n?` as ${n}`:""}`,{cause:s});o(this,"type");this.value=t,Object.setPrototypeOf(this,U.prototype),this.type=n}}class J{constructor(e,t,s){this.parser=e,this.isOptional=t,this.type=s}parse(e){if(!(this.isOptional&&e===void 0))try{return this.parser(e)}catch(t){throw new U(e,{type:this.type,cause:t})}}optional(){return this.isOptional=!0,this}}function ct(r){if(Array.isArray(r))return r;if(typeof r=="string")try{const e=JSON.parse(r);if(Array.isArray(e))return e}catch{}throw B()}class ht extends J{constructor(t,s,n){super(ct,s,n);o(this,"itemParser");this.itemParser=typeof t=="function"?t:t.parse.bind(t)}parse(t){const s=super.parse(t);return s===void 0?s:s.map(this.itemParser)}of(t){return this.itemParser=typeof t=="function"?t:t.parse.bind(t),this}}function $(r,e){return()=>new J(r,!1,e)}class M extends Error{constructor(e,{cause:t,type:s}={}){super(`Unable to parse field "${e}"${s?` as ${s}`:""}`,{cause:t}),Object.setPrototypeOf(this,M.prototype)}}function Pe(r,e){const t={};for(const s in r){const n=r[s];if(!n)continue;let i,a;if(typeof n=="function"||"parse"in n)i=s,a=typeof n=="function"?n:n.parse.bind(n);else{const{type:p}=n;i=n.from||s,a=typeof p=="function"?p:p.parse.bind(p)}let c;const u=e(i);try{c=a(u)}catch(p){throw p instanceof U?new M(i,{type:p.type,cause:p}):new M(i,{cause:p})}c!==void 0&&(t[s]=c)}return t}function Se(r){return new ht(e=>e,!1,r)}const E=$(r=>{if(typeof r=="boolean")return r;const e=String(r);if(e==="1"||e==="true")return!0;if(e==="0"||e==="false")return!1;throw B()},"boolean"),x=$(r=>{if(typeof r=="number")return r;if(typeof r=="string"){const e=Number(r);if(!Number.isNaN(e))return e}throw B()},"number"),ae=$(r=>r instanceof Date?r:new Date(x().parse(r)*1e3),"Date");function ce(r){let e=r;if(typeof e=="string"&&(e=JSON.parse(e)),typeof e!="object"||e===null||Array.isArray(e))throw B();return e}function f(r,e){return new J(t=>{const s=ce(t);return Pe(r,n=>s[n])},!1,e)}function Q(r){return/^#[\da-f]{6}$/i.test(r)}function ke(r){return/^#[\da-f]{3}$/i.test(r)}function he(r){const e=r.replace(/\s/g,"").toLowerCase();if(Q(e))return e;if(ke(e)){let s="#";for(let n=0;n<3;n+=1)s+=e[1+n].repeat(2);return s}const t=e.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)||e.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);if(t===null)throw new Error(`Value "${r}" does not satisfy any of known RGB formats.`);return t.slice(1).reduce((s,n)=>{const i=parseInt(n,10).toString(16);return s+(i.length===1?"0":"")+i},"#")}function ue(r){const e=he(r);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const a=parseInt(e.slice(1+i*2,1+(i+1)*2),16);return s+a*a*n},0))<120}const h=$(r=>{if(typeof r=="string"||typeof r=="number")return r.toString();throw B()},"string"),pe=$(r=>he(h().parse(r)),"rgb");function Z(r,e){return new J(t=>{if(typeof t!="string"&&!(t instanceof URLSearchParams))throw B();const s=typeof t=="string"?new URLSearchParams(t):t;return Pe(r,n=>{const i=s.get(n);return i===null?void 0:i})},!1,e)}function xe(){return f({id:x(),type:h(),title:h(),photoUrl:{type:h().optional(),from:"photo_url"},username:h().optional()},"Chat")}class qe{constructor(e){this.initData=e}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:e}=this;return e===void 0?void 0:new Date(this.authDate.getTime()+e*1e3)}get chat(){return this.initData.chat}get chatType(){return this.initData.chatType}get chatInstance(){return this.initData.chatInstance}get hash(){return this.initData.hash}get queryId(){return this.initData.queryId}get receiver(){return this.initData.receiver}get startParam(){return this.initData.startParam}get user(){return this.initData.user}}function se(){return f({addedToAttachmentMenu:{type:E().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:E().optional(),from:"allows_write_to_pm"},firstName:{type:h(),from:"first_name"},id:x(),isBot:{type:E().optional(),from:"is_bot"},isPremium:{type:E().optional(),from:"is_premium"},languageCode:{type:h().optional(),from:"language_code"},lastName:{type:h().optional(),from:"last_name"},photoUrl:{type:h().optional(),from:"photo_url"},username:h().optional()},"User")}function le(){return Z({authDate:{type:ae(),from:"auth_date"},canSendAfter:{type:x().optional(),from:"can_send_after"},chat:xe().optional(),chatInstance:{type:h().optional(),from:"chat_instance"},chatType:{type:h().optional(),from:"chat_type"},hash:h(),queryId:{type:h().optional(),from:"query_id"},receiver:se().optional(),startParam:{type:h().optional(),from:"start_param"},user:se().optional()},"InitData")}function ut(r){return le().parse(r)}function pt(r){return r.replace(/(^|_)bg/,(e,t)=>`${t}background`).replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function lt(r){return r.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`).replace(/(^|_)background/,(e,t)=>`${t}bg`)}const de=$(r=>{const e=pe().optional();return Object.entries(ce(r)).reduce((t,[s,n])=>(t[pt(s)]=e.parse(n),t),{})},"ThemeParams");function fe(r){return de().parse(r)}function dt(r={}){return b("web_app_request_theme","theme_changed",r).then(fe)}function Ae(r){return JSON.stringify(Object.entries(r).reduce((e,[t,s])=>(s&&(e[lt(t)]=s),e),{}))}class w{constructor(){o(this,"listeners",new Map);o(this,"subscribeListeners",[])}addListener(e,t,s){let n=this.listeners.get(e);return n||(n=[],this.listeners.set(e,n)),n.push([t,s]),()=>this.off(e,t)}emit(e,...t){this.subscribeListeners.forEach(n=>n(e,...t));const s=this.listeners.get(e);s&&s.forEach(([n,i],a)=>{n(...t),i&&s.splice(a,1)})}on(e,t){return this.addListener(e,t,!1)}once(e,t){return this.addListener(e,t,!0)}off(e,t){const s=this.listeners.get(e);if(s){for(let n=0;n<s.length;n+=1)if(t===s[n][0]){s.splice(n,1);return}}}subscribe(e){return this.subscribeListeners.push(e),()=>this.unsubscribe(e)}unsubscribe(e){for(let t=0;t<this.subscribeListeners.length;t+=1)if(this.subscribeListeners[t]===e){this.subscribeListeners.splice(t,1);return}}}class m{constructor(e,t){this.state=e,this.ee=t}internalSet(e,t){return this.state[e]===t||t===void 0?!1:(this.state[e]=t,this.ee.emit(`change:${e}`,t),!0)}clone(){return{...this.state}}set(e,t){let s=!1;if(typeof e=="string")s=this.internalSet(e,t);else for(const n in e)this.internalSet(n,e[n])&&(s=!0);s&&this.ee.emit("change")}get(e){return this.state[e]}}class Ve{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));this.state=new m(e,this.ee)}get accentTextColor(){return this.get("accentTextColor")}get backgroundColor(){return this.get("backgroundColor")}get buttonColor(){return this.get("buttonColor")}get buttonTextColor(){return this.get("buttonTextColor")}get destructiveTextColor(){return this.get("destructiveTextColor")}get(e){return this.state.get(e)}getState(){return this.state.clone()}get headerBackgroundColor(){return this.get("headerBackgroundColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.backgroundColor||ue(this.backgroundColor)}get linkColor(){return this.get("linkColor")}get secondaryBackgroundColor(){return this.get("secondaryBackgroundColor")}get sectionBackgroundColor(){return this.get("sectionBackgroundColor")}get sectionHeaderTextColor(){return this.get("sectionHeaderTextColor")}listen(){return y("theme_changed",e=>{this.state.set(fe(e.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}function Re(){return Z({botInline:{type:E().optional(),from:"tgWebAppBotInline"},initData:{type:le().optional(),from:"tgWebAppData"},initDataRaw:{type:h().optional(),from:"tgWebAppData"},platform:{type:h(),from:"tgWebAppPlatform"},showSettings:{type:E().optional(),from:"tgWebAppShowSettings"},startParam:{type:h().optional(),from:"tgWebAppStartParam"},themeParams:{type:de(),from:"tgWebAppThemeParams"},version:{type:h(),from:"tgWebAppVersion"}},"LaunchParams")}function ge(r){return Re().parse(r)}function Te(r){const e=r.includes("?")?r.replace("#","&").slice(r.indexOf("?")+1):r.slice(r.indexOf("#")+1);return ge(e)}function ft(){return Te(window.location.href)}function gt(){const r=ve();if(!r)throw new Error("Unable to get first navigation entry.");return Te(r.name)}class Ie{constructor(e,t){this.prefix=e,this.enabled=t}print(e,...t){if(!this.enabled)return;const s=new Date,n=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(s);console[e](`[${n}]`,this.prefix,...t)}disable(){this.enabled=!1}error(...e){this.print("error",...e)}enable(){this.enabled=!0}log(...e){this.print("log",...e)}warn(...e){this.print("warn",...e)}}let Le="https://web.telegram.org";const A=new Ie("[SDK]",!1);function wt(r){if(r){A.enable();return}A.disable()}function _t(r){Le=r}function bt(){return Le}function Be(r){const{initDataRaw:e,themeParams:t,platform:s,version:n,showSettings:i,startParam:a,botInline:c}=r,u=new URLSearchParams;return e&&u.set("tgWebAppData",e),u.set("tgWebAppPlatform",s),u.set("tgWebAppThemeParams",Ae(t)),u.set("tgWebAppVersion",n),a&&u.set("tgWebAppStartParam",n),typeof i=="boolean"&&u.set("tgWebAppShowSettings",i?"1":"0"),typeof c=="boolean"&&u.set("tgWebAppBotInline",c?"1":"0"),u.toString()}const $e="telegram-mini-apps-launch-params";function mt(){return ge(sessionStorage.getItem($e)||"")}function yt(r){sessionStorage.setItem($e,Be(r))}function K(){const r=[];for(const e of[ft,gt,mt])try{const t=e();return yt(t),t}catch(t){r.push(t)}throw A.error("Unable to extract launch parameters. Received errors:",r),new Error("Unable to retrieve launch parameters from any known source.")}function Et(){return{launchParams:K(),isPageReload:oe()}}function Ct(){try{return K(),!0}catch{return!1}}function vt(r){return"external"in r&&V(r.external)&&"notify"in r.external&&typeof r.external.notify=="function"}function Pt(r){return"TelegramWebviewProxy"in r&&V(r.TelegramWebviewProxy)&&"postEvent"in r.TelegramWebviewProxy&&typeof r.TelegramWebviewProxy.postEvent=="function"}class Y extends Error{constructor(e,t){super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`),Object.setPrototypeOf(this,Y.prototype)}}class X extends Error{constructor(e,t,s){super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`),Object.setPrototypeOf(this,X.prototype)}}const St=f({eventType:h(),eventData:r=>r});function De(r){return St.parse(r)}function kt(r,e){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:r,eventData:e}),source:window.parent}))}function xt(){const r=window;"TelegramGameProxy_receiveEvent"in r||[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=r;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=kt;return}s in t||(t[s]={}),t=t[s]})})}function qt(r){xt(),window.addEventListener("message",e=>{if(e.source===window.parent)try{const{eventType:t,eventData:s}=De(e.data);r(t,s)}catch{}})}function At(){return f({req_id:h(),data:r=>r===null?r:h().optional().parse(r)})}function Vt(){return f({req_id:h(),result:r=>r,error:h().optional()})}function Rt(){return f({slug:h(),status:h()})}function Tt(){return f({status:h()})}function It(){return f({button_id:r=>r==null?void 0:h().parse(r)})}function Lt(){return f({data:h().optional()})}function Bt(){return f({theme_params:r=>{const e=pe().optional();return Object.entries(ce(r)).reduce((t,[s,n])=>(t[s]=e.parse(n),t),{})}})}function $t(){return f({height:x(),width:r=>r==null?window.innerWidth:x().parse(r),is_state_stable:E(),is_expanded:E()})}function Dt(){return f({status:h()})}function Nt(){const r=new w,e=(t,...s)=>{A.log("Emitting processed event:",t,...s),r.emit(t,...s)};return window.addEventListener("resize",()=>{e("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),qt((t,s)=>{A.log("Received raw event:",t,s);try{switch(t){case"viewport_changed":return e(t,$t().parse(s));case"theme_changed":return e(t,Bt().parse(s));case"popup_closed":return s==null?e(t,{}):e(t,It().parse(s));case"set_custom_style":return e(t,h().parse(s));case"qr_text_received":return e(t,Lt().parse(s));case"clipboard_text_received":return e(t,At().parse(s));case"invoice_closed":return e(t,Rt().parse(s));case"phone_requested":return e("phone_requested",Tt().parse(s));case"custom_method_invoked":return e("custom_method_invoked",Vt().parse(s));case"write_access_requested":return e("write_access_requested",Dt().parse(s));case"main_button_pressed":case"back_button_pressed":case"settings_button_pressed":case"scan_qr_popup_closed":case"reload_iframe":return e(t);default:return e(t,s)}}catch(n){A.error("Error processing event:",n)}}),r}const ee="telegram-mini-apps-cached-emitter";function G(){const r=window;return r[ee]===void 0&&(r[ee]=Nt()),r[ee]}function T(r,e){G().off(r,e)}function y(r,e){return G().on(r,e),()=>T(r,e)}function Ht(r,e){return G().once(r,e),()=>T(r,e)}function Ne(r){G().unsubscribe(r)}function Ot(r){return G().subscribe(r),()=>Ne(r)}function He(r,e){const t=r.split("."),s=e.split("."),n=Math.max(t.length,s.length);for(let i=0;i<n;i+=1){const a=parseInt(t[i]||"0",10),c=parseInt(s[i]||"0",10);if(a!==c)return a>c?1:-1}return 0}function k(r,e){return He(r,e)<=0}function R(r,e,t){if(typeof t=="string"){if(r==="web_app_open_link"&&e==="try_instant_view")return k("6.4",t);if(r==="web_app_set_header_color"&&e==="color")return k("6.9",t)}switch(r){case"web_app_open_tg_link":case"web_app_open_invoice":case"web_app_setup_back_button":case"web_app_set_background_color":case"web_app_set_header_color":case"web_app_trigger_haptic_feedback":return k("6.1",e);case"web_app_open_popup":return k("6.2",e);case"web_app_close_scan_qr_popup":case"web_app_open_scan_qr_popup":case"web_app_read_text_from_clipboard":return k("6.4",e);case"web_app_switch_inline_query":return k("6.7",e);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return k("6.9",e);case"web_app_setup_settings_button":return k("6.10",e);default:return!0}}function v(r,e){return t=>R(e[t],r)}function Oe(r,e){return t=>{const[s,n]=e[t];return R(s,n,r)}}function d(r,e,t){let s={},n;e===void 0&&t===void 0?s={}:e!==void 0&&t!==void 0?(s=t,n=e):e!==void 0&&("targetOrigin"in e?s=e:n=e);const{targetOrigin:i=bt()}=s;if(A.log(`Calling method "${r}"`,n),ie()){window.parent.postMessage(JSON.stringify({eventType:r,eventData:n}),i);return}if(vt(window)){window.external.notify(JSON.stringify({eventType:r,eventData:n}));return}if(Pt(window)){window.TelegramWebviewProxy.postEvent(r,JSON.stringify(n));return}throw new Error("Unable to determine current environment and possible way to send event.")}function We(r){return(e,t)=>{if(!R(e,r))throw new Y(e,r);if(V(t)){let s;if(e==="web_app_open_link"&&"try_instant_view"in t?s="try_instant_view":e==="web_app_set_header_color"&&"color"in t&&(s="color"),s&&!R(e,s,r))throw new X(e,s,r)}return d(e,t)}}class j extends Error{constructor(e){super(`Async call timeout exceeded. Timeout: ${e}`),Object.setPrototypeOf(this,j.prototype)}}function Wt(r){return r instanceof j}function Mt(r){return new Promise(e=>{setTimeout(e,r)})}function Ut(r){return new Promise((e,t)=>{setTimeout(t,r,new j(r))})}function we(r,e){return Promise.race([r(),Ut(e)])}function b(r,e,t,s){let n,i,a,c;typeof e=="string"||Array.isArray(e)?(a=Array.isArray(e)?e:[e],n=t):(i=e,a=Array.isArray(t)?t:[t],n=s),V(i)&&typeof i.req_id=="string"&&(c=i.req_id);const{postEvent:u=d,timeout:p}=n||{},g=n&&"capture"in n?n.capture:null,_=()=>new Promise((I,l)=>{const P=a.map(S=>y(S,F=>{c&&(!V(F)||F.req_id!==c)||typeof g=="function"&&!g(F)||(q(),I(F))})),q=()=>P.forEach(S=>S());try{u(r,i)}catch(S){q(),l(S)}});return typeof p=="number"?we(_,p):_()}async function L(r,e,t,s={}){const{result:n,error:i}=await b("web_app_invoke_custom_method",{method:r,params:e,req_id:t},"custom_method_invoked",s);if(i)throw new Error(i);return n}class Me{constructor(e,t,s=d){o(this,"ee",new w);o(this,"state");o(this,"on",(e,t)=>e==="click"?y("back_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?T("back_button_pressed",t):this.ee.off(e,t));o(this,"supports");this.postEvent=s,this.state=new m({isVisible:e},this.ee),this.supports=v(t,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_back_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function me(r,e){return r+(r.length>0&&e.length>0?` ${e}`:e)}function Ue(...r){return r.reduce((e,t)=>{let s="";return typeof t=="string"?s=t:typeof t=="object"&&t!==null&&(s=Object.entries(t).reduce((n,[i,a])=>a?me(n,i):n,"")),me(e,s)},"")}function Gt(...r){return r.reduce((e,t)=>(V(t)&&Object.entries(t).forEach(([s,n])=>{const i=Ue(e[s],n);i.length>0&&(e[s]=i)}),e),{})}class Ge{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));this.postEvent=t,this.state=new m({isConfirmationNeeded:e},this.ee)}set isConfirmationNeeded(e){this.state.set("isConfirmationNeeded",e),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:e})}get isConfirmationNeeded(){return this.state.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}function ye(r,e){return r.reduce((t,s)=>(t[s]=e,t),{})}class je{constructor(e,t,s=d){o(this,"supports");this.createRequestId=t,this.postEvent=s,this.supports=v(e,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"})}async delete(e,t={}){const s=Array.isArray(e)?e:[e];s.length!==0&&await L("deleteStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent})}async getKeys(e={}){const t=await L("getStorageKeys",{},this.createRequestId(),{...e,postEvent:this.postEvent});return Se().of(h()).parse(t)}async get(e,t={}){const s=Array.isArray(e)?e:[e];if(s.length===0)return ye(s,"");const n=f(ye(s,h())),i=await L("getStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent}).then(a=>n.parse(a));return Array.isArray(e)?i:i[e]}async set(e,t,s={}){await L("saveStorageValue",{key:e,value:t},this.createRequestId(),{...s,postEvent:this.postEvent})}}function C(r,e){document.documentElement.style.setProperty(r,e)}function Fe(r,e){const t=()=>{C("--tg-background-color",r.backgroundColor)},s=()=>{const{backgroundColor:n,secondaryBackgroundColor:i}=e;if(Q(r.headerColor)){C("--tg-header-color",r.headerColor);return}if(r.headerColor==="bg_color"&&n){C("--tg-header-color",n);return}r.headerColor==="secondary_bg_color"&&i&&C("--tg-header-color",i)};e.on("change",s),r.on("change:backgroundColor",t),r.on("change:headerColor",s),t(),s()}function ze(r){const e=()=>{const t=r.getState();Object.entries(t).forEach(([s,n])=>{if(n){const i=s.replace(/[A-Z]/g,a=>`-${a.toLowerCase()}`);C(`--tg-theme-${i}`,n)}})};r.on("change",e),e()}function ne(r){const e=()=>C("--tg-viewport-height",`${r.height}px`),t=()=>C("--tg-viewport-width",`${r.width}px`),s=()=>C("--tg-viewport-stable-height",`${r.stableHeight}px`);r.on("change:height",e),r.on("change:width",t),r.on("change:stableHeight",s),e(),t(),s()}class Je{constructor(e,t=d){o(this,"supports");this.postEvent=t,this.supports=v(e,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"})}impactOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:e})}notificationOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:e})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}function jt(){const r=document.createElement("style");r.id="telegram-custom-styles",document.head.appendChild(r),y("set_custom_style",e=>{r.innerHTML=e})}function Qe(r){return`telegram-mini-apps-${r}`}function D(r,e){sessionStorage.setItem(Qe(r),JSON.stringify(e))}function N(r){const e=sessionStorage.getItem(Qe(r));return e?JSON.parse(e):null}function Ft(r,e,t){const{isVisible:s=!1}=r?N("back-button")||{}:{},n=new Me(s,e,t);return n.on("change",()=>{D("back-button",{isVisible:n.isVisible})}),n}function zt(r,e){const{isConfirmationNeeded:t=!1}=r?N("closing-behavior")||{}:{},s=new Ge(t,e);return s.on("change",()=>D("closing-behavior",{isConfirmationNeeded:s.isConfirmationNeeded})),s}class Ze{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"postEvent");o(this,"on",(e,t)=>e==="click"?y("main_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?T("main_button_pressed",t):this.ee.off(e,t));const{postEvent:t=d,text:s,textColor:n,backgroundColor:i,isEnabled:a,isVisible:c,isLoaderVisible:u}=e;this.postEvent=t,this.state=new m({backgroundColor:i,isEnabled:a,isVisible:c,isLoaderVisible:u,text:s,textColor:n},this.ee)}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isLoaderVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}set isEnabled(e){this.setParams({isEnabled:e})}get isEnabled(){return this.state.get("isEnabled")}set isLoaderVisible(e){this.setParams({isLoaderVisible:e})}get isLoaderVisible(){return this.state.get("isLoaderVisible")}set isVisible(e){this.setParams({isVisible:e})}get isVisible(){return this.state.get("isVisible")}get backgroundColor(){return this.state.get("backgroundColor")}get text(){return this.state.get("text")}get textColor(){return this.state.get("textColor")}disable(){return this.isEnabled=!1,this}enable(){return this.isEnabled=!0,this}hide(){return this.isVisible=!1,this}hideLoader(){return this.isLoaderVisible=!1,this}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(e){return this.setParams({text:e})}setTextColor(e){return this.setParams({textColor:e})}setBackgroundColor(e){return this.setParams({backgroundColor:e})}setParams(e){return this.state.set(e),this.commit(),this}}function Jt(r,e,t,s){const{backgroundColor:n=e,isEnabled:i=!1,isVisible:a=!1,isLoaderVisible:c=!1,textColor:u=t,text:p=""}=r?N("main-button")||{}:{},g=new Ze({backgroundColor:n,isEnabled:i,isLoaderVisible:c,isVisible:a,postEvent:s,text:p,textColor:u}),_=()=>D("main-button",{backgroundColor:g.backgroundColor,isEnabled:g.isEnabled,isLoaderVisible:g.isLoaderVisible,isVisible:g.isVisible,text:g.text,textColor:g.textColor});return g.on("change",_),g}const Qt=Z({contact:f({userId:{type:x(),from:"user_id"},phoneNumber:{type:h(),from:"phone_number"},firstName:{type:h(),from:"first_name"},lastName:{type:h().optional(),from:"last_name"}}),authDate:{type:ae(),from:"auth_date"},hash:h()});class Ke{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"botInline");o(this,"postEvent");o(this,"createRequestId");o(this,"requestingPhoneAccess",!1);o(this,"requestingWriteAccess",!1);o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");o(this,"supportsParam");const{postEvent:t=d,headerColor:s,backgroundColor:n,version:i,botInline:a,createRequestId:c}=e,u=v(i,{requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access",switchInlineQuery:"web_app_switch_inline_query",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color"});this.postEvent=t,this.botInline=a,this.createRequestId=c,this.supports=p=>!(!u(p)||p==="switchInlineQuery"&&!a),this.state=new m({backgroundColor:n,headerColor:s},this.ee),this.supportsParam=Oe(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact(){return L("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:1e4}).then(e=>Qt.parse(e))}get backgroundColor(){return this.state.get("backgroundColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return ue(this.backgroundColor)}get isRequestingPhoneAccess(){return this.requestingPhoneAccess}get isRequestingWriteAccess(){return this.requestingWriteAccess}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:e=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const s=Date.now()+e;let n=50;return we(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await Mt(n),n+=50}throw new Error("Unable to retrieve requested contact.")},e)}requestPhoneAccess(e={}){if(this.requestingPhoneAccess)throw new Error("Phone access is already being requested.");return this.requestingPhoneAccess=!0,b("web_app_request_phone","phone_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingPhoneAccess=!1})}requestWriteAccess(e={}){if(this.requestingWriteAccess)throw new Error("Write access is already being requested.");return this.requestingWriteAccess=!0,b("web_app_request_write_access","write_access_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingWriteAccess=!1})}sendData(e){const{size:t}=new Blob([e]);if(t===0||t>4096)throw new Error(`Passed data has incorrect size: ${t}`);this.postEvent("web_app_data_send",{data:e})}setHeaderColor(e){this.postEvent("web_app_set_header_color",Q(e)?{color:e}:{color_key:e}),this.state.set("headerColor",e)}setBackgroundColor(e){this.postEvent("web_app_set_background_color",{color:e}),this.state.set("backgroundColor",e)}switchInlineQuery(e,t=[]){if(!this.supports("switchInlineQuery")&&!this.isBotInline)throw new Error("Method is unsupported because Mini App should be launched in inline mode.");this.postEvent("web_app_switch_inline_query",{query:e,chat_types:t})}}function Zt(r,e,t,s,n,i){const{backgroundColor:a=e,headerColor:c="bg_color"}=r?N("mini-app")||{}:{},u=new Ke({headerColor:c,backgroundColor:a,version:t,botInline:s,createRequestId:n,postEvent:i}),p=()=>D("mini-app",{backgroundColor:u.backgroundColor,headerColor:u.headerColor});return u.on("change",p),u}function Kt(){let r=0;return()=>(r+=1,r.toString())}class Ye{constructor(e,t,s=d){o(this,"ee",new w);o(this,"state");o(this,"on",(e,t)=>e==="click"?y("settings_button_pressed",t):this.ee.on(e,t));o(this,"off",(e,t)=>e==="click"?T("settings_button_pressed",t):this.ee.off(e,t));o(this,"supports");this.postEvent=s,this.state=new m({isVisible:e},this.ee),this.supports=v(t,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_settings_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function Yt(r,e,t){const{isVisible:s=!1}=r?N("settings-button")||{}:{},n=new Ye(s,e,t);return n.on("change",()=>{D("settings-button",{isVisible:n.isVisible})}),n}function Xt(r){const e=new Ve(r);return e.listen(),e}function Xe(r){return["macos","tdesktop","unigram","web","weba"].includes(r)}async function _e(r){const e=await b("web_app_request_viewport","viewport_changed",r);return{height:e.height,width:e.width,isExpanded:e.is_expanded,isStateStable:e.is_state_stable}}function H(r){return r<0?0:r}class et{constructor(e){o(this,"ee",new w);o(this,"state");o(this,"postEvent");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));const{height:t,isExpanded:s,width:n,stableHeight:i,postEvent:a=d}=e;this.postEvent=a,this.state=new m({height:H(t),isExpanded:s,stableHeight:H(i),width:H(n)},this.ee)}sync(e){return _e(e).then(({height:t,isExpanded:s,width:n,isStateStable:i})=>{this.state.set({height:t,width:n,isExpanded:s,stableHeight:i?t:this.state.get("stableHeight")})})}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}listen(){return y("viewport_changed",e=>{const{height:t,width:s,is_expanded:n,is_state_stable:i}=e,a={height:H(t),isExpanded:n,width:H(s)};i&&(a.stableHeight=a.height),this.state.set(a)})}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.postEvent("web_app_expand"),this.state.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}function z(r){const e=new et(r);return e.on("change",()=>D("viewport",{height:e.height,isExpanded:e.isExpanded,stableHeight:e.stableHeight,width:e.width})),e.listen(),e}function er(r,e,t,s){const n=r?N("viewport"):null;if(n)return z({...n,postEvent:t});if(Xe(e))return z({height:window.innerHeight,isExpanded:!0,postEvent:t,stableHeight:window.innerHeight,width:window.innerWidth});if(s)return _e({postEvent:t,timeout:5e3}).then(({height:a,isStateStable:c,...u})=>z({...u,height:a,stableHeight:c?a:0}));const i=z({width:0,height:0,isExpanded:!1,postEvent:t,stableHeight:0});return i.sync({postEvent:t,timeout:5e3}).catch(a=>{console.error("Unable to actualize viewport state",a)}),i}function tr(r){return typeof r=="object"?r:r?{themeParams:!0,viewport:!0,miniApp:!0}:{}}function Ee(r,e,t,s){const n=tr(r);n.miniApp&&Fe(e,t),n.themeParams&&ze(t),n.viewport&&(s instanceof Promise?s.then(ne):ne(s))}function rr(r){const{hostname:e,pathname:t}=new URL(r,window.location.href);if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const s=t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(s===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');return s[2]}class tt{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new m({isOpened:!1},this.ee),this.supports=v(e,{open:"web_app_open_invoice"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e,t){if(this.isOpened)throw new Error("Invoice is already opened");const s=t?rr(e):e;this.isOpened=!0;try{return(await b("web_app_open_invoice",{slug:s},"invoice_closed",{postEvent:this.postEvent,capture(i){return s===i.slug}})).status}finally{this.isOpened=!1}}}function sr(r){const e=r.message.trim(),t=(r.title||"").trim(),s=r.buttons||[];let n;if(t.length>64)throw new Error(`Title has incorrect size: ${t.length}`);if(e.length===0||e.length>256)throw new Error(`Message has incorrect size: ${e.length}`);if(s.length>3)throw new Error(`Buttons have incorrect size: ${s.length}`);return s.length===0?n=[{type:"close",id:""}]:n=s.map(i=>{const{id:a=""}=i;if(a.length>64)throw new Error(`Button ID has incorrect size: ${a}`);if(i.type===void 0||i.type==="default"||i.type==="destructive"){const c=i.text.trim();if(c.length===0||c.length>64){const u=i.type||"default";throw new Error(`Button text with type "${u}" has incorrect size: ${i.text.length}`)}return{...i,text:c,id:a}}return{...i,id:a}}),{title:t,message:e,buttons:n}}class rt{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new m({isOpened:!1},this.ee),this.supports=v(e,{open:"web_app_open_popup"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}open(e){if(this.isOpened)throw new Error("Popup is already opened.");return this.isOpened=!0,b("web_app_open_popup",sr(e),"popup_closed",{postEvent:this.postEvent}).then(({button_id:t=null})=>t).finally(()=>{this.isOpened=!1})}}class st{constructor(e,t=d){o(this,"ee",new w);o(this,"state");o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee));o(this,"supports");this.postEvent=t,this.state=new m({isOpened:!1},this.ee),this.supports=v(e,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"})}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{const t=await b("web_app_open_scan_qr_popup",{text:e},["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent});return typeof t=="object"&&typeof t.data=="string"?t.data:null}finally{this.isOpened=!1}}}class nt{constructor(e,t,s=d){o(this,"supports");o(this,"supportsParam");this.version=e,this.createRequestId=t,this.postEvent=s,this.supports=v(e,{readTextFromClipboard:"web_app_read_text_from_clipboard"}),this.supportsParam=Oe(e,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(e,t){const s=new URL(e,window.location.href).toString();if(!R("web_app_open_link",this.version)){window.open(s,"_blank");return}this.postEvent("web_app_open_link",{url:s,...typeof t=="boolean"?{try_instant_view:t}:{}})}openTelegramLink(e){const{hostname:t,pathname:s,search:n}=new URL(e,window.location.href);if(t!=="t.me")throw new Error(`URL has not allowed hostname: ${t}. Only "t.me" is allowed`);if(!R("web_app_open_tg_link",this.version)){window.location.href=e;return}this.postEvent("web_app_open_tg_link",{path_full:s+n})}readTextFromClipboard(){return b("web_app_read_text_from_clipboard",{req_id:this.createRequestId()},"clipboard_text_received",{postEvent:this.postEvent}).then(({data:e=null})=>e)}}function nr(r={}){const{async:e=!1,complete:t=e,cssVars:s=!1,acceptCustomStyles:n=!1}=r;try{const{initData:i,initDataRaw:a,version:c,platform:u,themeParams:p,botInline:g=!1}=K(),_=oe(),I=Kt(),l=We(c);ie()&&(n&&jt(),l("iframe_ready",{reload_supported:!0}),y("reload_iframe",()=>window.location.reload()));const P={backButton:Ft(_,c,l),closingBehavior:zt(_,l),cloudStorage:new je(c,I,l),createRequestId:I,hapticFeedback:new Je(c,l),invoice:new tt(c,l),mainButton:Jt(_,p.buttonColor||"#000000",p.buttonTextColor||"#ffffff",l),miniApp:Zt(_,p.backgroundColor||"#ffffff",c,g,I,l),popup:new rt(c,l),postEvent:l,qrScanner:new st(c,l),settingsButton:Yt(_,c,l),themeParams:Xt(p),utils:new nt(c,I,l),...i?{initData:new qe(i),initDataRaw:a}:{}},q=er(_,u,l,t);return q instanceof Promise||t?Promise.resolve(q).then(S=>(Ee(s,P.miniApp,P.themeParams,S),{...P,viewport:S})):(Ee(s,P.miniApp,P.themeParams,q),{...P,viewport:q})}catch(i){if(t)return Promise.reject(i);throw i}}function O(r,e){return r.startsWith(e)?r:`${e}${r}`}function ir(r){const e=r.match(/#(.+)/);return e?e[1]:null}async function W(r){return r===0?!0:Promise.race([new Promise(e=>{window.addEventListener("popstate",function t(){window.removeEventListener("popstate",t),e(!0)}),window.history.go(r)}),new Promise(e=>{setTimeout(e,50,!1)})])}async function or(){if(window.history.length<=1||(window.history.pushState(null,""),await W(1-window.history.length)))return;let e=await W(-1);for(;e;)e=await W(-1)}class it{constructor(e,t,{debug:s=!1,loggerPrefix:n="Navigator"}){o(this,"logger");o(this,"entries");if(this.entriesCursor=t,e.length===0)throw new Error("Entries list should not be empty.");if(t>=e.length)throw new Error("Cursor should be less than entries count.");this.entries=e.map(({pathname:i="",search:a,hash:c})=>{if(!i.startsWith("/")&&i.length>0)throw new Error('Pathname should start with "/"');return{pathname:O(i,"/"),search:a?O(a,"?"):"",hash:c?O(c,"#"):""}}),this.logger=new Ie(`[${n}]`,s)}formatEntry(e){let t;if(typeof e=="string")t=e;else{const{pathname:a="",search:c,hash:u}=e;t=a+(c?O(c,"?"):"")+(u?O(u,"#"):"")}const{pathname:s,search:n,hash:i}=new URL(t,`https://localhost${this.path}`);return{pathname:s,search:n,hash:i}}get entry(){return this.entries[this.entriesCursor]}back(){return this.go(-1)}get cursor(){return this.entriesCursor}get canGoBack(){return this.entriesCursor>0}get canGoForward(){return this.entriesCursor!==this.entries.length-1}forward(){return this.go(1)}go(e){this.logger.log(`called go(${e})`);const t=Math.min(this.entries.length-1,Math.max(this.entriesCursor+e,0));if(this.entriesCursor===t)return this.performGo({updated:!1,delta:e});const s=this.entry;this.entriesCursor=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performGo({updated:!0,delta:e,before:s,after:n})}getEntries(){return this.entries.map(e=>({...e}))}get hash(){return this.entry.hash}push(e){this.entriesCursor!==this.entries.length-1&&this.entries.splice(this.entriesCursor+1);const t=this.formatEntry(e),s=this.entry;this.entriesCursor+=1,this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performPush({before:s,after:n})}get path(){return`${this.pathname}${this.search}${this.hash}`}get pathname(){return this.entry.pathname}replace(e){const t=this.formatEntry(e);if(this.search===t.search&&this.pathname===t.pathname&&this.hash===t.hash)return this.performReplace({updated:!1,entry:t});const s=this.entry;this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performReplace({updated:!0,before:s,after:n})}get search(){return this.entry.search}}const Ce=0,te=1,re=2;class be extends it{constructor(t,s,n={}){super(t,s,{...n,loggerPrefix:"HashNavigator"});o(this,"ee",new w);o(this,"attached",!1);o(this,"onPopState",async({state:t})=>{if(this.logger.log('"popstate" event received. State:',t),t===null)return this.push(window.location.hash.slice(1));if(t===Ce){this.logger.log("Void reached. Moving history forward"),window.history.forward();return}if(t===te)return this.back();if(t===re)return this.forward()});o(this,"back",()=>super.back());o(this,"on",this.ee.on.bind(this.ee));o(this,"off",this.ee.off.bind(this.ee))}static fromLocation(t){const{search:s,pathname:n,hash:i}=new URL(window.location.hash.slice(1),window.location.href);return new be([{search:s,pathname:n,hash:i}],0,t)}async performGo(t){t.updated&&(this.attached&&await this.syncHistory(),this.emitChanged(t.before,t.after))}async performPush({before:t,after:s}){this.attached&&await this.syncHistory(),this.emitChanged(t,s)}async performReplace(t){t.updated&&(this.attached&&window.history.replaceState(null,"",`#${this.path}`),this.emitChanged(t.before,t.after))}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const t=`#${this.path}`;await or(),d("web_app_setup_back_button",{is_visible:this.canGoBack}),this.canGoBack&&this.canGoForward?(this.logger.log("Setting up history: [<-, *, ->]"),window.history.replaceState(te,""),window.history.pushState(null,"",t),window.history.pushState(re,""),await W(-1)):this.canGoBack?(this.logger.log("Setting up history: [<-, *]"),window.history.replaceState(te,""),window.history.pushState(null,"",t)):this.canGoForward?(this.logger.log("Setting up history: [*, ->]"),window.history.replaceState(null,t),window.history.pushState(re,""),await W(-1)):(this.logger.log("Setting up history: [~, *]"),window.history.replaceState(Ce,""),window.history.pushState(null,"",t)),window.addEventListener("popstate",this.onPopState)}emitChanged(t,s){this.ee.emit("change",{navigator:this,from:t,to:s})}async attach(){if(!this.attached)return this.logger.log("Attaching",this),this.attached=!0,y("back_button_pressed",this.back),this.syncHistory()}detach(){this.attached&&(this.logger.log("Detaching",this),this.attached=!1,window.removeEventListener("popstate",this.onPopState),T("back_button_pressed",this.back))}}exports.BackButton=Me;exports.ClosingBehavior=Ge;exports.CloudStorage=je;exports.HapticFeedback=Je;exports.HashNavigator=be;exports.InitData=qe;exports.Invoice=tt;exports.MainButton=Ze;exports.MethodUnsupportedError=Y;exports.MiniApp=Ke;exports.Navigator=it;exports.ParameterUnsupportedError=X;exports.ParseError=U;exports.ParseSchemaFieldError=M;exports.Popup=rt;exports.QRScanner=st;exports.SettingsButton=Ye;exports.ThemeParams=Ve;exports.TimeoutError=j;exports.Utils=nt;exports.Viewport=et;exports.array=Se;exports.bindMiniAppCSSVars=Fe;exports.bindThemeCSSVars=ze;exports.bindViewportCSSVars=ne;exports.boolean=E;exports.chatParser=xe;exports.classNames=Ue;exports.compareVersions=He;exports.createPostEvent=We;exports.date=ae;exports.getHash=ir;exports.init=nr;exports.initDataParser=le;exports.invokeCustomMethod=L;exports.isColorDark=ue;exports.isIframe=ie;exports.isPageReload=oe;exports.isRGB=Q;exports.isRGBShort=ke;exports.isRecord=V;exports.isStableViewportPlatform=Xe;exports.isTMA=Ct;exports.isTimeoutError=Wt;exports.json=f;exports.launchParamsParser=Re;exports.mergeClassNames=Gt;exports.number=x;exports.off=T;exports.on=y;exports.once=Ht;exports.parseInitData=ut;exports.parseLaunchParams=ge;exports.parseMessage=De;exports.parseThemeParams=fe;exports.postEvent=d;exports.request=b;exports.requestThemeParams=dt;exports.requestViewport=_e;exports.retrieveLaunchData=Et;exports.retrieveLaunchParams=K;exports.rgb=pe;exports.searchParams=Z;exports.serializeLaunchParams=Be;exports.serializeThemeParams=Ae;exports.setCSSVar=C;exports.setDebug=wt;exports.setTargetOrigin=_t;exports.string=h;exports.subscribe=Ot;exports.supports=R;exports.themeParamsParser=de;exports.toRGB=he;exports.unsubscribe=Ne;exports.userParser=se;exports.withTimeout=we;
|
package/dist/index.iife.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
var ur=Object.defineProperty;var hr=(o,g,k)=>g in o?ur(o,g,{enumerable:!0,configurable:!0,writable:!0,value:k}):o[g]=k;var a=(o,g,k)=>(hr(o,typeof g!="symbol"?g+"":g,k),k);this.tmajs=this.tmajs||{};this.tmajs.sdk=function(o){"use strict";function g(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function k(){return performance.getEntriesByType("navigation")[0]||null}function at(){const r=k();return r?r.type==="reload":null}function B(){return new TypeError("Value has unexpected type")}class M extends Error{constructor(t,{cause:s,type:n}={}){super(`Unable to parse value${n?` as ${n}`:""}`,{cause:s});a(this,"type");this.value=t,Object.setPrototypeOf(this,M.prototype),this.type=n}}class J{constructor(e,t,s){this.parser=e,this.isOptional=t,this.type=s}parse(e){if(!(this.isOptional&&e===void 0))try{return this.parser(e)}catch(t){throw new M(e,{type:this.type,cause:t})}}optional(){return this.isOptional=!0,this}}function ct(r){if(Array.isArray(r))return r;if(typeof r=="string")try{const e=JSON.parse(r);if(Array.isArray(e))return e}catch{}throw B()}class ut extends J{constructor(t,s,n){super(ct,s,n);a(this,"itemParser");this.itemParser=typeof t=="function"?t:t.parse.bind(t)}parse(t){const s=super.parse(t);return s===void 0?s:s.map(this.itemParser)}of(t){return this.itemParser=typeof t=="function"?t:t.parse.bind(t),this}}function $(r,e){return()=>new J(r,!1,e)}class U extends Error{constructor(e,{cause:t,type:s}={}){super(`Unable to parse field "${e}"${s?` as ${s}`:""}`,{cause:t}),Object.setPrototypeOf(this,U.prototype)}}function ye(r,e){const t={};for(const s in r){const n=r[s];if(!n)continue;let i,c;if(typeof n=="function"||"parse"in n)i=s,c=typeof n=="function"?n:n.parse.bind(n);else{const{type:p}=n;i=n.from||s,c=typeof p=="function"?p:p.parse.bind(p)}let u;const l=e(i);try{u=c(l)}catch(p){throw p instanceof M?new U(i,{type:p.type,cause:p}):new U(i,{cause:p})}u!==void 0&&(t[s]=u)}return t}function Ee(r){return new ut(e=>e,!1,r)}const P=$(r=>{if(typeof r=="boolean")return r;const e=String(r);if(e==="1"||e==="true")return!0;if(e==="0"||e==="false")return!1;throw B()},"boolean"),q=$(r=>{if(typeof r=="number")return r;if(typeof r=="string"){const e=Number(r);if(!Number.isNaN(e))return e}throw B()},"number"),te=$(r=>r instanceof Date?r:new Date(q().parse(r)*1e3),"Date");function re(r){let e=r;if(typeof e=="string"&&(e=JSON.parse(e)),typeof e!="object"||e===null||Array.isArray(e))throw B();return e}function w(r,e){return new J(t=>{const s=re(t);return ye(r,n=>s[n])},!1,e)}function Q(r){return/^#[\da-f]{6}$/i.test(r)}function Ce(r){return/^#[\da-f]{3}$/i.test(r)}function se(r){const e=r.replace(/\s/g,"").toLowerCase();if(Q(e))return e;if(Ce(e)){let s="#";for(let n=0;n<3;n+=1)s+=e[1+n].repeat(2);return s}const t=e.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)||e.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);if(t===null)throw new Error(`Value "${r}" does not satisfy any of known RGB formats.`);return t.slice(1).reduce((s,n)=>{const i=parseInt(n,10).toString(16);return s+(i.length===1?"0":"")+i},"#")}function ne(r){const e=se(r);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const c=parseInt(e.slice(1+i*2,1+(i+1)*2),16);return s+c*c*n},0))<120}const h=$(r=>{if(typeof r=="string"||typeof r=="number")return r.toString();throw B()},"string"),ie=$(r=>se(h().parse(r)),"rgb");function Z(r,e){return new J(t=>{if(typeof t!="string"&&!(t instanceof URLSearchParams))throw B();const s=typeof t=="string"?new URLSearchParams(t):t;return ye(r,n=>{const i=s.get(n);return i===null?void 0:i})},!1,e)}function Pe(){return w({id:q(),type:h(),title:h(),photoUrl:{type:h().optional(),from:"photo_url"},username:h().optional()},"Chat")}class ve{constructor(e){this.initData=e}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:e}=this;return e===void 0?void 0:new Date(this.authDate.getTime()+e*1e3)}get chat(){return this.initData.chat}get chatType(){return this.initData.chatType}get chatInstance(){return this.initData.chatInstance}get hash(){return this.initData.hash}get queryId(){return this.initData.queryId}get receiver(){return this.initData.receiver}get startParam(){return this.initData.startParam}get user(){return this.initData.user}}function oe(){return w({addedToAttachmentMenu:{type:P().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:P().optional(),from:"allows_write_to_pm"},firstName:{type:h(),from:"first_name"},id:q(),isBot:{type:P().optional(),from:"is_bot"},isPremium:{type:P().optional(),from:"is_premium"},languageCode:{type:h().optional(),from:"language_code"},lastName:{type:h().optional(),from:"last_name"},photoUrl:{type:h().optional(),from:"photo_url"},username:h().optional()},"User")}function ae(){return Z({authDate:{type:te(),from:"auth_date"},canSendAfter:{type:q().optional(),from:"can_send_after"},chat:Pe().optional(),chatInstance:{type:h().optional(),from:"chat_instance"},chatType:{type:h().optional(),from:"chat_type"},hash:h(),queryId:{type:h().optional(),from:"query_id"},receiver:oe().optional(),startParam:{type:h().optional(),from:"start_param"},user:oe().optional()},"InitData")}function ht(r){return ae().parse(r)}function pt(r){return r.replace(/(^|_)bg/,(e,t)=>`${t}background`).replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function lt(r){return r.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`).replace(/(^|_)background/,(e,t)=>`${t}bg`)}const ce=$(r=>{const e=ie().optional();return Object.entries(re(r)).reduce((t,[s,n])=>(t[pt(s)]=e.parse(n),t),{})},"ThemeParams");function ue(r){return ce().parse(r)}function dt(r={}){return C("web_app_request_theme","theme_changed",r).then(ue)}function Se(r){return JSON.stringify(Object.entries(r).reduce((e,[t,s])=>(s&&(e[lt(t)]=s),e),{}))}class b{constructor(){a(this,"listeners",new Map);a(this,"subscribeListeners",[])}addListener(e,t,s){let n=this.listeners.get(e);return n||(n=[],this.listeners.set(e,n)),n.push([t,s]),()=>this.off(e,t)}emit(e,...t){this.subscribeListeners.forEach(n=>n(e,...t));const s=this.listeners.get(e);s&&s.forEach(([n,i],c)=>{n(...t),i&&s.splice(c,1)})}on(e,t){return this.addListener(e,t,!1)}once(e,t){return this.addListener(e,t,!0)}off(e,t){const s=this.listeners.get(e);if(s){for(let n=0;n<s.length;n+=1)if(t===s[n][0]){s.splice(n,1);return}}}subscribe(e){return this.subscribeListeners.push(e),()=>this.unsubscribe(e)}unsubscribe(e){for(let t=0;t<this.subscribeListeners.length;t+=1)if(this.subscribeListeners[t]===e){this.subscribeListeners.splice(t,1);return}}}class y{constructor(e,t){this.state=e,this.ee=t}internalSet(e,t){return this.state[e]===t||t===void 0?!1:(this.state[e]=t,this.ee.emit(`change:${e}`,t),!0)}clone(){return{...this.state}}set(e,t){let s=!1;if(typeof e=="string")s=this.internalSet(e,t);else for(const n in e)this.internalSet(n,e[n])&&(s=!0);s&&this.ee.emit("change")}get(e){return this.state[e]}}class ke{constructor(e){a(this,"ee",new b);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));this.state=new y(e,this.ee)}get accentTextColor(){return this.get("accentTextColor")}get backgroundColor(){return this.get("backgroundColor")}get buttonColor(){return this.get("buttonColor")}get buttonTextColor(){return this.get("buttonTextColor")}get destructiveTextColor(){return this.get("destructiveTextColor")}get(e){return this.state.get(e)}getState(){return this.state.clone()}get headerBackgroundColor(){return this.get("headerBackgroundColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.backgroundColor||ne(this.backgroundColor)}get linkColor(){return this.get("linkColor")}get secondaryBackgroundColor(){return this.get("secondaryBackgroundColor")}get sectionBackgroundColor(){return this.get("sectionBackgroundColor")}get sectionHeaderTextColor(){return this.get("sectionHeaderTextColor")}listen(){return E("theme_changed",e=>{this.state.set(ue(e.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}function he(){return Z({botInline:{type:P().optional(),from:"tgWebAppBotInline"},initData:{type:ae().optional(),from:"tgWebAppData"},initDataRaw:{type:h().optional(),from:"tgWebAppData"},platform:{type:h(),from:"tgWebAppPlatform"},showSettings:{type:P().optional(),from:"tgWebAppShowSettings"},startParam:{type:h().optional(),from:"tgWebAppStartParam"},themeParams:{type:ce(),from:"tgWebAppThemeParams"},version:{type:h(),from:"tgWebAppVersion"}},"LaunchParams")}function qe(r){return he().parse(r)}function Ae(r){const e=r.includes("?")?r.replace("#","&").slice(r.indexOf("?")+1):r.slice(r.indexOf("#")+1);return qe(e)}function ft(){return Ae(window.location.href)}function gt(){const r=k();if(!r)throw new Error("Unable to get first navigation entry.");return Ae(r.name)}function wt(){try{return gt()}catch{}try{return ft()}catch{}return null}function Ve(r){const{initDataRaw:e,themeParams:t,platform:s,version:n,showSettings:i,botInline:c}=r,u=new URLSearchParams;return e&&u.set("tgWebAppData",e),u.set("tgWebAppPlatform",s),u.set("tgWebAppThemeParams",Se(t)),u.set("tgWebAppVersion",n),typeof i=="boolean"&&u.set("tgWebAppShowSettings",i?"1":"0"),typeof c=="boolean"&&u.set("tgWebAppBotInline",c?"1":"0"),u.toString()}const Re="telegram-mini-apps-launch-params";function _t(){const r=sessionStorage.getItem(Re);return r?he().parse(r):null}function bt(r){sessionStorage.setItem(Re,Ve(r))}function mt(){try{return window.self!==window.top}catch{return!0}}function yt(){const r=_t(),e=wt(),t=at();if(r){if(e)return{launchParams:e,isPageReload:mt()?t||r.initDataRaw===e.initDataRaw:!0};if(t)return{launchParams:r,isPageReload:t};throw new Error("Unable to retrieve current launch parameters, which must exist.")}if(e)return{launchParams:e,isPageReload:!1};throw new Error("Unable to retrieve any launch parameters.")}const Te="tmajsLaunchData";function pe(){const r=window[Te];if(r)return r;const e=yt();return window[Te]=e,bt(e.launchParams),e}function Et(){try{return pe(),!0}catch{return!1}}function Ct(r){return"external"in r&&g(r.external)&&"notify"in r.external&&typeof r.external.notify=="function"}function Pt(r){return"TelegramWebviewProxy"in r&&g(r.TelegramWebviewProxy)&&"postEvent"in r.TelegramWebviewProxy&&typeof r.TelegramWebviewProxy.postEvent=="function"}function le(){try{return window.self!==window.top}catch{return!0}}class K extends Error{constructor(e,t){super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`),Object.setPrototypeOf(this,K.prototype)}}class Y extends Error{constructor(e,t,s){super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`),Object.setPrototypeOf(this,Y.prototype)}}class Ie{constructor(e,t){this.prefix=e,this.enabled=t}print(e,...t){if(!this.enabled)return;const s=new Date,n=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(s);console[e](`[${n}]`,this.prefix,...t)}disable(){this.enabled=!1}error(...e){this.print("error",...e)}enable(){this.enabled=!0}log(...e){this.print("log",...e)}warn(...e){this.print("warn",...e)}}let Le="https://web.telegram.org";const D=new Ie("[SDK]",!1);function vt(r){if(r){D.enable();return}D.disable()}function St(r){Le=r}function kt(){return Le}const qt=w({eventType:h(),eventData:r=>r});function Be(r){return qt.parse(r)}function At(r,e){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:r,eventData:e}),source:window.parent}))}function Vt(){const r=window;"TelegramGameProxy_receiveEvent"in r||[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=r;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=At;return}s in t||(t[s]={}),t=t[s]})})}function Rt(r){Vt(),window.addEventListener("message",e=>{if(e.source===window.parent)try{const{eventType:t,eventData:s}=Be(e.data);r(t,s)}catch{}})}function Tt(){return w({req_id:h(),data:r=>r===null?r:h().optional().parse(r)})}function It(){return w({req_id:h(),result:r=>r,error:h().optional()})}function Lt(){return w({slug:h(),status:h()})}function Bt(){return w({status:h()})}function $t(){return w({button_id:r=>r==null?void 0:h().parse(r)})}function Dt(){return w({data:h().optional()})}function Nt(){return w({theme_params:r=>{const e=ie().optional();return Object.entries(re(r)).reduce((t,[s,n])=>(t[s]=e.parse(n),t),{})}})}function Ot(){return w({height:q(),width:r=>r==null?window.innerWidth:q().parse(r),is_state_stable:P(),is_expanded:P()})}function Wt(){return w({status:h()})}function Ht(){const r=new b,e=(t,...s)=>{D.log("Emitting processed event:",t,...s),r.emit(t,...s)};return window.addEventListener("resize",()=>{e("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),Rt((t,s)=>{D.log("Received raw event:",t,s);try{switch(t){case"viewport_changed":return e(t,Ot().parse(s));case"theme_changed":return e(t,Nt().parse(s));case"popup_closed":return s==null?e(t,{}):e(t,$t().parse(s));case"set_custom_style":return e(t,h().parse(s));case"qr_text_received":return e(t,Dt().parse(s));case"clipboard_text_received":return e(t,Tt().parse(s));case"invoice_closed":return e(t,Lt().parse(s));case"phone_requested":return e("phone_requested",Bt().parse(s));case"custom_method_invoked":return e("custom_method_invoked",It().parse(s));case"write_access_requested":return e("write_access_requested",Wt().parse(s));case"main_button_pressed":case"back_button_pressed":case"settings_button_pressed":case"scan_qr_popup_closed":case"reload_iframe":return e(t);default:return e(t,s)}}catch(n){D.error("Error processing event:",n)}}),r}const de="telegram-mini-apps-cached-emitter";function x(){const r=window;return r[de]===void 0&&(r[de]=Ht()),r[de]}function T(r,e){x().off(r,e)}function E(r,e){return x().on(r,e),()=>T(r,e)}function Mt(r,e){return x().once(r,e),()=>T(r,e)}function $e(r){x().unsubscribe(r)}function Ut(r){return x().subscribe(r),()=>$e(r)}function De(r,e){const t=r.split("."),s=e.split("."),n=Math.max(t.length,s.length);for(let i=0;i<n;i+=1){const c=parseInt(t[i]||"0",10),u=parseInt(s[i]||"0",10);if(c!==u)return c>u?1:-1}return 0}function A(r,e){return De(r,e)<=0}function I(r,e,t){if(typeof t=="string"){if(r==="web_app_open_link"&&e==="try_instant_view")return A("6.4",t);if(r==="web_app_set_header_color"&&e==="color")return A("6.9",t)}switch(r){case"web_app_open_tg_link":case"web_app_open_invoice":case"web_app_setup_back_button":case"web_app_set_background_color":case"web_app_set_header_color":case"web_app_trigger_haptic_feedback":return A("6.1",e);case"web_app_open_popup":return A("6.2",e);case"web_app_close_scan_qr_popup":case"web_app_open_scan_qr_popup":case"web_app_read_text_from_clipboard":return A("6.4",e);case"web_app_switch_inline_query":return A("6.7",e);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return A("6.9",e);case"web_app_setup_settings_button":return A("6.10",e);default:return!0}}function v(r,e){return t=>I(e[t],r)}function Ne(r,e){return t=>{const[s,n]=e[t];return I(s,n,r)}}function d(r,e,t){let s={},n;e===void 0&&t===void 0?s={}:e!==void 0&&t!==void 0?(s=t,n=e):e!==void 0&&("targetOrigin"in e?s=e:n=e);const{targetOrigin:i=kt()}=s;if(D.log(`Calling method "${r}"`,n),le()){window.parent.postMessage(JSON.stringify({eventType:r,eventData:n}),i);return}if(Ct(window)){window.external.notify(JSON.stringify({eventType:r,eventData:n}));return}if(Pt(window)){window.TelegramWebviewProxy.postEvent(r,JSON.stringify(n));return}throw new Error("Unable to determine current environment and possible way to send event.")}function Oe(r){return(e,t)=>{if(!I(e,r))throw new K(e,r);if(g(t)){let s;if(e==="web_app_open_link"&&"try_instant_view"in t?s="try_instant_view":e==="web_app_set_header_color"&&"color"in t&&(s="color"),s&&!I(e,s,r))throw new Y(e,s,r)}return d(e,t)}}class j extends Error{constructor(e){super(`Async call timeout exceeded. Timeout: ${e}`),Object.setPrototypeOf(this,j.prototype)}}function xt(r){return r instanceof j}function jt(r){return new Promise(e=>{setTimeout(e,r)})}function Gt(r){return new Promise((e,t)=>{setTimeout(t,r,new j(r))})}function fe(r,e){return Promise.race([r(),Gt(e)])}function C(r,e,t,s){let n,i,c,u;typeof e=="string"||Array.isArray(e)?(c=Array.isArray(e)?e:[e],n=t):(i=e,c=Array.isArray(t)?t:[t],n=s),g(i)&&typeof i.req_id=="string"&&(u=i.req_id);const{postEvent:l=d,timeout:p}=n||{},_=n&&"capture"in n?n.capture:null,m=()=>new Promise((H,f)=>{const V=c.map(R=>E(R,ee=>{u&&(!g(ee)||ee.req_id!==u)||typeof _=="function"&&!_(ee)||(L(),H(ee))})),L=()=>V.forEach(R=>R());try{l(r,i)}catch(R){L(),f(R)}});return typeof p=="number"?fe(m,p):m()}async function N(r,e,t,s={}){const{result:n,error:i}=await C("web_app_invoke_custom_method",{method:r,params:e,req_id:t},"custom_method_invoked",s);if(i)throw new Error(i);return n}class We{constructor(e,t,s=d){a(this,"ee",new b);a(this,"state");a(this,"on",(e,t)=>e==="click"?E("back_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?T("back_button_pressed",t):this.ee.off(e,t));a(this,"supports");this.postEvent=s,this.state=new y({isVisible:e},this.ee),this.supports=v(t,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_back_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function He(r,e){return r+(r.length>0&&e.length>0?` ${e}`:e)}function Me(...r){return r.reduce((e,t)=>{let s="";return typeof t=="string"?s=t:typeof t=="object"&&t!==null&&(s=Object.entries(t).reduce((n,[i,c])=>c?He(n,i):n,"")),He(e,s)},"")}function Ft(...r){return r.reduce((e,t)=>(g(t)&&Object.entries(t).forEach(([s,n])=>{const i=Me(e[s],n);i.length>0&&(e[s]=i)}),e),{})}class Ue{constructor(e,t=d){a(this,"ee",new b);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));this.postEvent=t,this.state=new y({isConfirmationNeeded:e},this.ee)}set isConfirmationNeeded(e){this.state.set("isConfirmationNeeded",e),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:e})}get isConfirmationNeeded(){return this.state.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}function xe(r,e){return r.reduce((t,s)=>(t[s]=e,t),{})}class je{constructor(e,t,s=d){a(this,"supports");this.createRequestId=t,this.postEvent=s,this.supports=v(e,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"})}async delete(e,t={}){const s=Array.isArray(e)?e:[e];s.length!==0&&await N("deleteStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent})}async getKeys(e={}){const t=await N("getStorageKeys",{},this.createRequestId(),{...e,postEvent:this.postEvent});return Ee().of(h()).parse(t)}async get(e,t={}){const s=Array.isArray(e)?e:[e];if(s.length===0)return xe(s,"");const n=w(xe(s,h())),i=await N("getStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent}).then(c=>n.parse(c));return Array.isArray(e)?i:i[e]}async set(e,t,s={}){await N("saveStorageValue",{key:e,value:t},this.createRequestId(),{...s,postEvent:this.postEvent})}}function S(r,e){document.documentElement.style.setProperty(r,e)}function Ge(r,e){const t=()=>{S("--tg-background-color",r.backgroundColor)},s=()=>{const{backgroundColor:n,secondaryBackgroundColor:i}=e;if(Q(r.headerColor)){S("--tg-header-color",r.headerColor);return}if(r.headerColor==="bg_color"&&n){S("--tg-header-color",n);return}r.headerColor==="secondary_bg_color"&&i&&S("--tg-header-color",i)};e.on("change",s),r.on("change:backgroundColor",t),r.on("change:headerColor",s),t(),s()}function Fe(r){const e=()=>{const t=r.getState();Object.entries(t).forEach(([s,n])=>{if(n){const i=s.replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`);S(`--tg-theme-${i}`,n)}})};r.on("change",e),e()}function ge(r){const e=()=>S("--tg-viewport-height",`${r.height}px`),t=()=>S("--tg-viewport-width",`${r.width}px`),s=()=>S("--tg-viewport-stable-height",`${r.stableHeight}px`);r.on("change:height",e),r.on("change:width",t),r.on("change:stableHeight",s),e(),t(),s()}class ze{constructor(e,t=d){a(this,"supports");this.postEvent=t,this.supports=v(e,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"})}impactOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:e})}notificationOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:e})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}function zt(){const r=document.createElement("style");r.id="telegram-custom-styles",document.head.appendChild(r),E("set_custom_style",e=>{r.innerHTML=e})}function Je(r){return`telegram-mini-apps-${r}`}function O(r,e){sessionStorage.setItem(Je(r),JSON.stringify(e))}function W(r){const e=sessionStorage.getItem(Je(r));return e?JSON.parse(e):null}function Jt(r,e,t){const{isVisible:s=!1}=r?W("back-button")||{}:{},n=new We(s,e,t);return n.on("change",()=>{O("back-button",{isVisible:n.isVisible})}),n}function Qt(r,e){const{isConfirmationNeeded:t=!1}=r?W("closing-behavior")||{}:{},s=new Ue(t,e);return s.on("change",()=>O("closing-behavior",{isConfirmationNeeded:s.isConfirmationNeeded})),s}class Qe{constructor(e){a(this,"ee",new b);a(this,"state");a(this,"postEvent");a(this,"on",(e,t)=>e==="click"?E("main_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?T("main_button_pressed",t):this.ee.off(e,t));const{postEvent:t=d,text:s,textColor:n,backgroundColor:i,isEnabled:c,isVisible:u,isLoaderVisible:l}=e;this.postEvent=t,this.state=new y({backgroundColor:i,isEnabled:c,isVisible:u,isLoaderVisible:l,text:s,textColor:n},this.ee)}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isLoaderVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}set isEnabled(e){this.setParams({isEnabled:e})}get isEnabled(){return this.state.get("isEnabled")}set isLoaderVisible(e){this.setParams({isLoaderVisible:e})}get isLoaderVisible(){return this.state.get("isLoaderVisible")}set isVisible(e){this.setParams({isVisible:e})}get isVisible(){return this.state.get("isVisible")}get backgroundColor(){return this.state.get("backgroundColor")}get text(){return this.state.get("text")}get textColor(){return this.state.get("textColor")}disable(){return this.isEnabled=!1,this}enable(){return this.isEnabled=!0,this}hide(){return this.isVisible=!1,this}hideLoader(){return this.isLoaderVisible=!1,this}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(e){return this.setParams({text:e})}setTextColor(e){return this.setParams({textColor:e})}setBackgroundColor(e){return this.setParams({backgroundColor:e})}setParams(e){return this.state.set(e),this.commit(),this}}function Zt(r,e,t,s){const{backgroundColor:n=e,isEnabled:i=!1,isVisible:c=!1,isLoaderVisible:u=!1,textColor:l=t,text:p=""}=r?W("main-button")||{}:{},_=new Qe({backgroundColor:n,isEnabled:i,isLoaderVisible:u,isVisible:c,postEvent:s,text:p,textColor:l}),m=()=>O("main-button",{backgroundColor:_.backgroundColor,isEnabled:_.isEnabled,isLoaderVisible:_.isLoaderVisible,isVisible:_.isVisible,text:_.text,textColor:_.textColor});return _.on("change",m),_}const Kt=Z({contact:w({userId:{type:q(),from:"user_id"},phoneNumber:{type:h(),from:"phone_number"},firstName:{type:h(),from:"first_name"},lastName:{type:h().optional(),from:"last_name"}}),authDate:{type:te(),from:"auth_date"},hash:h()});class Ze{constructor(e){a(this,"ee",new b);a(this,"state");a(this,"botInline");a(this,"postEvent");a(this,"createRequestId");a(this,"requestingPhoneAccess",!1);a(this,"requestingWriteAccess",!1);a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");a(this,"supportsParam");const{postEvent:t=d,headerColor:s,backgroundColor:n,version:i,botInline:c,createRequestId:u}=e,l=v(i,{requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access",switchInlineQuery:"web_app_switch_inline_query",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color"});this.postEvent=t,this.botInline=c,this.createRequestId=u,this.supports=p=>!(!l(p)||p==="switchInlineQuery"&&!c),this.state=new y({backgroundColor:n,headerColor:s},this.ee),this.supportsParam=Ne(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact(){return N("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:1e4}).then(e=>Kt.parse(e))}get backgroundColor(){return this.state.get("backgroundColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return ne(this.backgroundColor)}get isRequestingPhoneAccess(){return this.requestingPhoneAccess}get isRequestingWriteAccess(){return this.requestingWriteAccess}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:e=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const s=Date.now()+e;let n=50;return fe(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await jt(n),n+=50}throw new Error("Unable to retrieve requested contact.")},e)}requestPhoneAccess(e={}){if(this.requestingPhoneAccess)throw new Error("Phone access is already being requested.");return this.requestingPhoneAccess=!0,C("web_app_request_phone","phone_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingPhoneAccess=!1})}requestWriteAccess(e={}){if(this.requestingWriteAccess)throw new Error("Write access is already being requested.");return this.requestingWriteAccess=!0,C("web_app_request_write_access","write_access_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingWriteAccess=!1})}sendData(e){const{size:t}=new Blob([e]);if(t===0||t>4096)throw new Error(`Passed data has incorrect size: ${t}`);this.postEvent("web_app_data_send",{data:e})}setHeaderColor(e){this.postEvent("web_app_set_header_color",Q(e)?{color:e}:{color_key:e}),this.state.set("headerColor",e)}setBackgroundColor(e){this.postEvent("web_app_set_background_color",{color:e}),this.state.set("backgroundColor",e)}switchInlineQuery(e,t=[]){if(!this.supports("switchInlineQuery")&&!this.isBotInline)throw new Error("Method is unsupported because Mini App should be launched in inline mode.");this.postEvent("web_app_switch_inline_query",{query:e,chat_types:t})}}function Yt(r,e,t,s,n,i){const{backgroundColor:c=e,headerColor:u="bg_color"}=r?W("mini-app")||{}:{},l=new Ze({headerColor:u,backgroundColor:c,version:t,botInline:s,createRequestId:n,postEvent:i}),p=()=>O("mini-app",{backgroundColor:l.backgroundColor,headerColor:l.headerColor});return l.on("change",p),l}function Xt(){let r=0;return()=>(r+=1,r.toString())}class Ke{constructor(e,t,s=d){a(this,"ee",new b);a(this,"state");a(this,"on",(e,t)=>e==="click"?E("settings_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?T("settings_button_pressed",t):this.ee.off(e,t));a(this,"supports");this.postEvent=s,this.state=new y({isVisible:e},this.ee),this.supports=v(t,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_settings_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function er(r,e,t){const{isVisible:s=!1}=r?W("settings-button")||{}:{},n=new Ke(s,e,t);return n.on("change",()=>{O("settings-button",{isVisible:n.isVisible})}),n}function tr(r){const e=new ke(r);return e.listen(),e}function Ye(r){return["macos","tdesktop","unigram","web","weba"].includes(r)}async function we(r){const e=await C("web_app_request_viewport","viewport_changed",r);return{height:e.height,width:e.width,isExpanded:e.is_expanded,isStateStable:e.is_state_stable}}function G(r){return r<0?0:r}class Xe{constructor(e){a(this,"ee",new b);a(this,"state");a(this,"postEvent");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));const{height:t,isExpanded:s,width:n,stableHeight:i,postEvent:c=d}=e;this.postEvent=c,this.state=new y({height:G(t),isExpanded:s,stableHeight:G(i),width:G(n)},this.ee)}sync(e){return we(e).then(({height:t,isExpanded:s,width:n,isStateStable:i})=>{this.state.set({height:t,width:n,isExpanded:s,stableHeight:i?t:this.state.get("stableHeight")})})}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}listen(){return E("viewport_changed",e=>{const{height:t,width:s,is_expanded:n,is_state_stable:i}=e,c={height:G(t),isExpanded:n,width:G(s)};i&&(c.stableHeight=c.height),this.state.set(c)})}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.postEvent("web_app_expand"),this.state.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}function X(r){const e=new Xe(r);return e.on("change",()=>O("viewport",{height:e.height,isExpanded:e.isExpanded,stableHeight:e.stableHeight,width:e.width})),e.listen(),e}function rr(r,e,t,s){const n=r?W("viewport"):null;if(n)return X({...n,postEvent:t});if(Ye(e))return X({height:window.innerHeight,isExpanded:!0,postEvent:t,stableHeight:window.innerHeight,width:window.innerWidth});if(s)return we({postEvent:t,timeout:5e3}).then(({height:c,isStateStable:u,...l})=>X({...l,height:c,stableHeight:u?c:0}));const i=X({width:0,height:0,isExpanded:!1,postEvent:t,stableHeight:0});return i.sync({postEvent:t,timeout:5e3}).catch(c=>{console.error("Unable to actualize viewport state",c)}),i}function sr(r){return typeof r=="object"?r:r?{themeParams:!0,viewport:!0,miniApp:!0}:{}}function et(r,e,t,s){const n=sr(r);n.miniApp&&Ge(e,t),n.themeParams&&Fe(t),n.viewport&&(s instanceof Promise?s.then(ge):ge(s))}function nr(r){const{hostname:e,pathname:t}=new URL(r,window.location.href);if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const s=t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(s===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');return s[2]}class tt{constructor(e,t=d){a(this,"ee",new b);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");this.postEvent=t,this.state=new y({isOpened:!1},this.ee),this.supports=v(e,{open:"web_app_open_invoice"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e,t){if(this.isOpened)throw new Error("Invoice is already opened");const s=t?nr(e):e;this.isOpened=!0;try{return(await C("web_app_open_invoice",{slug:s},"invoice_closed",{postEvent:this.postEvent,capture(i){return s===i.slug}})).status}finally{this.isOpened=!1}}}function ir(r){const e=r.message.trim(),t=(r.title||"").trim(),s=r.buttons||[];let n;if(t.length>64)throw new Error(`Title has incorrect size: ${t.length}`);if(e.length===0||e.length>256)throw new Error(`Message has incorrect size: ${e.length}`);if(s.length>3)throw new Error(`Buttons have incorrect size: ${s.length}`);return s.length===0?n=[{type:"close",id:""}]:n=s.map(i=>{const{id:c=""}=i;if(c.length>64)throw new Error(`Button ID has incorrect size: ${c}`);if(i.type===void 0||i.type==="default"||i.type==="destructive"){const u=i.text.trim();if(u.length===0||u.length>64){const l=i.type||"default";throw new Error(`Button text with type "${l}" has incorrect size: ${i.text.length}`)}return{...i,text:u,id:c}}return{...i,id:c}}),{title:t,message:e,buttons:n}}class rt{constructor(e,t=d){a(this,"ee",new b);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");this.postEvent=t,this.state=new y({isOpened:!1},this.ee),this.supports=v(e,{open:"web_app_open_popup"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}open(e){if(this.isOpened)throw new Error("Popup is already opened.");return this.isOpened=!0,C("web_app_open_popup",ir(e),"popup_closed",{postEvent:this.postEvent}).then(({button_id:t=null})=>t).finally(()=>{this.isOpened=!1})}}class st{constructor(e,t=d){a(this,"ee",new b);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");this.postEvent=t,this.state=new y({isOpened:!1},this.ee),this.supports=v(e,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"})}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{const t=await C("web_app_open_scan_qr_popup",{text:e},["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent});return typeof t=="object"&&typeof t.data=="string"?t.data:null}finally{this.isOpened=!1}}}class nt{constructor(e,t,s=d){a(this,"supports");a(this,"supportsParam");this.version=e,this.createRequestId=t,this.postEvent=s,this.supports=v(e,{readTextFromClipboard:"web_app_read_text_from_clipboard"}),this.supportsParam=Ne(e,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(e,t){const s=new URL(e,window.location.href).toString();if(!I("web_app_open_link",this.version)){window.open(s,"_blank");return}this.postEvent("web_app_open_link",{url:s,...typeof t=="boolean"?{try_instant_view:t}:{}})}openTelegramLink(e){const{hostname:t,pathname:s,search:n}=new URL(e,window.location.href);if(t!=="t.me")throw new Error(`URL has not allowed hostname: ${t}. Only "t.me" is allowed`);if(!I("web_app_open_tg_link",this.version)){window.location.href=e;return}this.postEvent("web_app_open_tg_link",{path_full:s+n})}readTextFromClipboard(){return C("web_app_read_text_from_clipboard",{req_id:this.createRequestId()},"clipboard_text_received",{postEvent:this.postEvent}).then(({data:e=null})=>e)}}function or(r={}){const{async:e=!1,complete:t=e,cssVars:s=!1,acceptCustomStyles:n=!1}=r;try{const{launchParams:{initData:i,initDataRaw:c,version:u,platform:l,themeParams:p,botInline:_=!1},isPageReload:m}=pe(),H=Xt(),f=Oe(u);le()&&(n&&zt(),f("iframe_ready",{reload_supported:!0}),E("reload_iframe",()=>window.location.reload()));const V={backButton:Jt(m,u,f),closingBehavior:Qt(m,f),cloudStorage:new je(u,H,f),createRequestId:H,hapticFeedback:new ze(u,f),invoice:new tt(u,f),mainButton:Zt(m,p.buttonColor||"#000000",p.buttonTextColor||"#ffffff",f),miniApp:Yt(m,p.backgroundColor||"#ffffff",u,_,H,f),popup:new rt(u,f),postEvent:f,qrScanner:new st(u,f),settingsButton:er(m,u,f),themeParams:tr(p),utils:new nt(u,H,f),...i?{initData:new ve(i),initDataRaw:c}:{}},L=rr(m,l,f,t);return L instanceof Promise||t?Promise.resolve(L).then(R=>(et(s,V.miniApp,V.themeParams,R),{...V,viewport:R})):(et(s,V.miniApp,V.themeParams,L),{...V,viewport:L})}catch(i){if(t)return Promise.reject(i);throw i}}function F(r,e){return r.startsWith(e)?r:`${e}${r}`}function ar(r){const e=r.match(/#(.+)/);return e?e[1]:null}async function z(r){return r===0?!0:Promise.race([new Promise(e=>{window.addEventListener("popstate",function t(){window.removeEventListener("popstate",t),e(!0)}),window.history.go(r)}),new Promise(e=>{setTimeout(e,50,!1)})])}async function cr(){if(window.history.length<=1||(window.history.pushState(null,""),await z(1-window.history.length)))return;let e=await z(-1);for(;e;)e=await z(-1)}class it{constructor(e,t,{debug:s=!1,loggerPrefix:n="Navigator"}){a(this,"logger");a(this,"entries");if(this.entriesCursor=t,e.length===0)throw new Error("Entries list should not be empty.");if(t>=e.length)throw new Error("Cursor should be less than entries count.");this.entries=e.map(({pathname:i="",search:c,hash:u})=>{if(!i.startsWith("/")&&i.length>0)throw new Error('Pathname should start with "/"');return{pathname:F(i,"/"),search:c?F(c,"?"):"",hash:u?F(u,"#"):""}}),this.logger=new Ie(`[${n}]`,s)}formatEntry(e){let t;if(typeof e=="string")t=e;else{const{pathname:c="",search:u,hash:l}=e;t=c+(u?F(u,"?"):"")+(l?F(l,"#"):"")}const{pathname:s,search:n,hash:i}=new URL(t,`https://localhost${this.path}`);return{pathname:s,search:n,hash:i}}get entry(){return this.entries[this.entriesCursor]}back(){return this.go(-1)}get cursor(){return this.entriesCursor}get canGoBack(){return this.entriesCursor>0}get canGoForward(){return this.entriesCursor!==this.entries.length-1}forward(){return this.go(1)}go(e){this.logger.log(`called go(${e})`);const t=Math.min(this.entries.length-1,Math.max(this.entriesCursor+e,0));if(this.entriesCursor===t)return this.performGo({updated:!1,delta:e});const s=this.entry;this.entriesCursor=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performGo({updated:!0,delta:e,before:s,after:n})}getEntries(){return this.entries.map(e=>({...e}))}get hash(){return this.entry.hash}push(e){this.entriesCursor!==this.entries.length-1&&this.entries.splice(this.entriesCursor+1);const t=this.formatEntry(e),s=this.entry;this.entriesCursor+=1,this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performPush({before:s,after:n})}get path(){return`${this.pathname}${this.search}${this.hash}`}get pathname(){return this.entry.pathname}replace(e){const t=this.formatEntry(e);if(this.search===t.search&&this.pathname===t.pathname&&this.hash===t.hash)return this.performReplace({updated:!1,entry:t});const s=this.entry;this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performReplace({updated:!0,before:s,after:n})}get search(){return this.entry.search}}const ot=0,_e=1,be=2;class me extends it{constructor(t,s,n={}){super(t,s,{...n,loggerPrefix:"HashNavigator"});a(this,"ee",new b);a(this,"attached",!1);a(this,"onPopState",async({state:t})=>{if(this.logger.log('"popstate" event received. State:',t),t===null)return this.push(window.location.hash.slice(1));if(t===ot){this.logger.log("Void reached. Moving history forward"),window.history.forward();return}if(t===_e)return this.back();if(t===be)return this.forward()});a(this,"back",()=>super.back());a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee))}static fromLocation(t){const{search:s,pathname:n,hash:i}=new URL(window.location.hash.slice(1),window.location.href);return new me([{search:s,pathname:n,hash:i}],0,t)}async performGo(t){t.updated&&(this.attached&&await this.syncHistory(),this.emitChanged(t.before,t.after))}async performPush({before:t,after:s}){this.attached&&await this.syncHistory(),this.emitChanged(t,s)}async performReplace(t){t.updated&&(this.attached&&window.history.replaceState(null,"",`#${this.path}`),this.emitChanged(t.before,t.after))}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const t=`#${this.path}`;await cr(),d("web_app_setup_back_button",{is_visible:this.canGoBack}),this.canGoBack&&this.canGoForward?(this.logger.log("Setting up history: [<-, *, ->]"),window.history.replaceState(_e,""),window.history.pushState(null,"",t),window.history.pushState(be,""),await z(-1)):this.canGoBack?(this.logger.log("Setting up history: [<-, *]"),window.history.replaceState(_e,""),window.history.pushState(null,"",t)):this.canGoForward?(this.logger.log("Setting up history: [*, ->]"),window.history.replaceState(null,t),window.history.pushState(be,""),await z(-1)):(this.logger.log("Setting up history: [~, *]"),window.history.replaceState(ot,""),window.history.pushState(null,"",t)),window.addEventListener("popstate",this.onPopState)}emitChanged(t,s){this.ee.emit("change",{navigator:this,from:t,to:s})}async attach(){if(!this.attached)return this.logger.log("Attaching",this),this.attached=!0,E("back_button_pressed",this.back),this.syncHistory()}detach(){this.attached&&(this.logger.log("Detaching",this),this.attached=!1,window.removeEventListener("popstate",this.onPopState),T("back_button_pressed",this.back))}}return o.BackButton=We,o.ClosingBehavior=Ue,o.CloudStorage=je,o.HapticFeedback=ze,o.HashNavigator=me,o.InitData=ve,o.Invoice=tt,o.MainButton=Qe,o.MethodUnsupportedError=K,o.MiniApp=Ze,o.Navigator=it,o.ParameterUnsupportedError=Y,o.ParseError=M,o.ParseSchemaFieldError=U,o.Popup=rt,o.QRScanner=st,o.SettingsButton=Ke,o.ThemeParams=ke,o.TimeoutError=j,o.Utils=nt,o.Viewport=Xe,o.array=Ee,o.bindMiniAppCSSVars=Ge,o.bindThemeCSSVars=Fe,o.bindViewportCSSVars=ge,o.boolean=P,o.chatParser=Pe,o.classNames=Me,o.compareVersions=De,o.createPostEvent=Oe,o.date=te,o.getHash=ar,o.init=or,o.initDataParser=ae,o.invokeCustomMethod=N,o.isColorDark=ne,o.isIframe=le,o.isRGB=Q,o.isRGBShort=Ce,o.isRecord=g,o.isStableViewportPlatform=Ye,o.isTMA=Et,o.isTimeoutError=xt,o.json=w,o.launchParamsParser=he,o.mergeClassNames=Ft,o.number=q,o.off=T,o.on=E,o.once=Mt,o.parseInitData=ht,o.parseLaunchParams=qe,o.parseMessage=Be,o.parseThemeParams=ue,o.postEvent=d,o.request=C,o.requestThemeParams=dt,o.requestViewport=we,o.retrieveLaunchData=pe,o.rgb=ie,o.searchParams=Z,o.serializeLaunchParams=Ve,o.serializeThemeParams=Se,o.setCSSVar=S,o.setDebug=vt,o.setTargetOrigin=St,o.string=h,o.subscribe=Ut,o.supports=I,o.themeParamsParser=ce,o.toRGB=se,o.unsubscribe=$e,o.userParser=oe,o.withTimeout=fe,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),o}({});
|
|
2
|
-
//# sourceMappingURL=index.iife.js.map
|
|
1
|
+
var or=Object.defineProperty;var ar=(o,m,v)=>m in o?or(o,m,{enumerable:!0,configurable:!0,writable:!0,value:v}):o[m]=v;var a=(o,m,v)=>(ar(o,typeof m!="symbol"?m+"":m,v),v);this.tmajs=this.tmajs||{};this.tmajs.sdk=function(o){"use strict";function m(){return performance.getEntriesByType("navigation")[0]}function v(){try{return window.self!==window.top}catch{return!0}}function se(){var r;return((r=m())==null?void 0:r.type)==="reload"}function T(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function D(){return new TypeError("Value has unexpected type")}class U extends Error{constructor(t,{cause:s,type:n}={}){super(`Unable to parse value${n?` as ${n}`:""}`,{cause:s});a(this,"type");this.value=t,Object.setPrototypeOf(this,U.prototype),this.type=n}}class Q{constructor(e,t,s){this.parser=e,this.isOptional=t,this.type=s}parse(e){if(!(this.isOptional&&e===void 0))try{return this.parser(e)}catch(t){throw new U(e,{type:this.type,cause:t})}}optional(){return this.isOptional=!0,this}}function at(r){if(Array.isArray(r))return r;if(typeof r=="string")try{const e=JSON.parse(r);if(Array.isArray(e))return e}catch{}throw D()}class ct extends Q{constructor(t,s,n){super(at,s,n);a(this,"itemParser");this.itemParser=typeof t=="function"?t:t.parse.bind(t)}parse(t){const s=super.parse(t);return s===void 0?s:s.map(this.itemParser)}of(t){return this.itemParser=typeof t=="function"?t:t.parse.bind(t),this}}function N(r,e){return()=>new Q(r,!1,e)}class x extends Error{constructor(e,{cause:t,type:s}={}){super(`Unable to parse field "${e}"${s?` as ${s}`:""}`,{cause:t}),Object.setPrototypeOf(this,x.prototype)}}function Ee(r,e){const t={};for(const s in r){const n=r[s];if(!n)continue;let i,c;if(typeof n=="function"||"parse"in n)i=s,c=typeof n=="function"?n:n.parse.bind(n);else{const{type:l}=n;i=n.from||s,c=typeof l=="function"?l:l.parse.bind(l)}let h;const p=e(i);try{h=c(p)}catch(l){throw l instanceof U?new x(i,{type:l.type,cause:l}):new x(i,{cause:l})}h!==void 0&&(t[s]=h)}return t}function Ce(r){return new ct(e=>e,!1,r)}const P=N(r=>{if(typeof r=="boolean")return r;const e=String(r);if(e==="1"||e==="true")return!0;if(e==="0"||e==="false")return!1;throw D()},"boolean"),q=N(r=>{if(typeof r=="number")return r;if(typeof r=="string"){const e=Number(r);if(!Number.isNaN(e))return e}throw D()},"number"),ne=N(r=>r instanceof Date?r:new Date(q().parse(r)*1e3),"Date");function ie(r){let e=r;if(typeof e=="string"&&(e=JSON.parse(e)),typeof e!="object"||e===null||Array.isArray(e))throw D();return e}function g(r,e){return new Q(t=>{const s=ie(t);return Ee(r,n=>s[n])},!1,e)}function Z(r){return/^#[\da-f]{6}$/i.test(r)}function ve(r){return/^#[\da-f]{3}$/i.test(r)}function oe(r){const e=r.replace(/\s/g,"").toLowerCase();if(Z(e))return e;if(ve(e)){let s="#";for(let n=0;n<3;n+=1)s+=e[1+n].repeat(2);return s}const t=e.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/)||e.match(/^rgba\((\d{1,3}),(\d{1,3}),(\d{1,3}),\d{1,3}\)$/);if(t===null)throw new Error(`Value "${r}" does not satisfy any of known RGB formats.`);return t.slice(1).reduce((s,n)=>{const i=parseInt(n,10).toString(16);return s+(i.length===1?"0":"")+i},"#")}function ae(r){const e=oe(r);return Math.sqrt([.299,.587,.114].reduce((s,n,i)=>{const c=parseInt(e.slice(1+i*2,1+(i+1)*2),16);return s+c*c*n},0))<120}const u=N(r=>{if(typeof r=="string"||typeof r=="number")return r.toString();throw D()},"string"),ce=N(r=>oe(u().parse(r)),"rgb");function K(r,e){return new Q(t=>{if(typeof t!="string"&&!(t instanceof URLSearchParams))throw D();const s=typeof t=="string"?new URLSearchParams(t):t;return Ee(r,n=>{const i=s.get(n);return i===null?void 0:i})},!1,e)}function Pe(){return g({id:q(),type:u(),title:u(),photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"Chat")}class Se{constructor(e){this.initData=e}get authDate(){return this.initData.authDate}get canSendAfter(){return this.initData.canSendAfter}get canSendAfterDate(){const{canSendAfter:e}=this;return e===void 0?void 0:new Date(this.authDate.getTime()+e*1e3)}get chat(){return this.initData.chat}get chatType(){return this.initData.chatType}get chatInstance(){return this.initData.chatInstance}get hash(){return this.initData.hash}get queryId(){return this.initData.queryId}get receiver(){return this.initData.receiver}get startParam(){return this.initData.startParam}get user(){return this.initData.user}}function he(){return g({addedToAttachmentMenu:{type:P().optional(),from:"added_to_attachment_menu"},allowsWriteToPm:{type:P().optional(),from:"allows_write_to_pm"},firstName:{type:u(),from:"first_name"},id:q(),isBot:{type:P().optional(),from:"is_bot"},isPremium:{type:P().optional(),from:"is_premium"},languageCode:{type:u().optional(),from:"language_code"},lastName:{type:u().optional(),from:"last_name"},photoUrl:{type:u().optional(),from:"photo_url"},username:u().optional()},"User")}function ue(){return K({authDate:{type:ne(),from:"auth_date"},canSendAfter:{type:q().optional(),from:"can_send_after"},chat:Pe().optional(),chatInstance:{type:u().optional(),from:"chat_instance"},chatType:{type:u().optional(),from:"chat_type"},hash:u(),queryId:{type:u().optional(),from:"query_id"},receiver:he().optional(),startParam:{type:u().optional(),from:"start_param"},user:he().optional()},"InitData")}function ht(r){return ue().parse(r)}function ut(r){return r.replace(/(^|_)bg/,(e,t)=>`${t}background`).replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function pt(r){return r.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`).replace(/(^|_)background/,(e,t)=>`${t}bg`)}const pe=N(r=>{const e=ce().optional();return Object.entries(ie(r)).reduce((t,[s,n])=>(t[ut(s)]=e.parse(n),t),{})},"ThemeParams");function le(r){return pe().parse(r)}function lt(r={}){return C("web_app_request_theme","theme_changed",r).then(le)}function ke(r){return JSON.stringify(Object.entries(r).reduce((e,[t,s])=>(s&&(e[pt(t)]=s),e),{}))}class _{constructor(){a(this,"listeners",new Map);a(this,"subscribeListeners",[])}addListener(e,t,s){let n=this.listeners.get(e);return n||(n=[],this.listeners.set(e,n)),n.push([t,s]),()=>this.off(e,t)}emit(e,...t){this.subscribeListeners.forEach(n=>n(e,...t));const s=this.listeners.get(e);s&&s.forEach(([n,i],c)=>{n(...t),i&&s.splice(c,1)})}on(e,t){return this.addListener(e,t,!1)}once(e,t){return this.addListener(e,t,!0)}off(e,t){const s=this.listeners.get(e);if(s){for(let n=0;n<s.length;n+=1)if(t===s[n][0]){s.splice(n,1);return}}}subscribe(e){return this.subscribeListeners.push(e),()=>this.unsubscribe(e)}unsubscribe(e){for(let t=0;t<this.subscribeListeners.length;t+=1)if(this.subscribeListeners[t]===e){this.subscribeListeners.splice(t,1);return}}}class y{constructor(e,t){this.state=e,this.ee=t}internalSet(e,t){return this.state[e]===t||t===void 0?!1:(this.state[e]=t,this.ee.emit(`change:${e}`,t),!0)}clone(){return{...this.state}}set(e,t){let s=!1;if(typeof e=="string")s=this.internalSet(e,t);else for(const n in e)this.internalSet(n,e[n])&&(s=!0);s&&this.ee.emit("change")}get(e){return this.state[e]}}class qe{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));this.state=new y(e,this.ee)}get accentTextColor(){return this.get("accentTextColor")}get backgroundColor(){return this.get("backgroundColor")}get buttonColor(){return this.get("buttonColor")}get buttonTextColor(){return this.get("buttonTextColor")}get destructiveTextColor(){return this.get("destructiveTextColor")}get(e){return this.state.get(e)}getState(){return this.state.clone()}get headerBackgroundColor(){return this.get("headerBackgroundColor")}get hintColor(){return this.get("hintColor")}get isDark(){return!this.backgroundColor||ae(this.backgroundColor)}get linkColor(){return this.get("linkColor")}get secondaryBackgroundColor(){return this.get("secondaryBackgroundColor")}get sectionBackgroundColor(){return this.get("sectionBackgroundColor")}get sectionHeaderTextColor(){return this.get("sectionHeaderTextColor")}listen(){return E("theme_changed",e=>{this.state.set(le(e.theme_params))})}get subtitleTextColor(){return this.get("subtitleTextColor")}get textColor(){return this.get("textColor")}}function Ae(){return K({botInline:{type:P().optional(),from:"tgWebAppBotInline"},initData:{type:ue().optional(),from:"tgWebAppData"},initDataRaw:{type:u().optional(),from:"tgWebAppData"},platform:{type:u(),from:"tgWebAppPlatform"},showSettings:{type:P().optional(),from:"tgWebAppShowSettings"},startParam:{type:u().optional(),from:"tgWebAppStartParam"},themeParams:{type:pe(),from:"tgWebAppThemeParams"},version:{type:u(),from:"tgWebAppVersion"}},"LaunchParams")}function de(r){return Ae().parse(r)}function Ve(r){const e=r.includes("?")?r.replace("#","&").slice(r.indexOf("?")+1):r.slice(r.indexOf("#")+1);return de(e)}function dt(){return Ve(window.location.href)}function ft(){const r=m();if(!r)throw new Error("Unable to get first navigation entry.");return Ve(r.name)}class Re{constructor(e,t){this.prefix=e,this.enabled=t}print(e,...t){if(!this.enabled)return;const s=new Date,n=Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,timeZone:"UTC"}).format(s);console[e](`[${n}]`,this.prefix,...t)}disable(){this.enabled=!1}error(...e){this.print("error",...e)}enable(){this.enabled=!0}log(...e){this.print("log",...e)}warn(...e){this.print("warn",...e)}}let Te="https://web.telegram.org";const I=new Re("[SDK]",!1);function gt(r){if(r){I.enable();return}I.disable()}function wt(r){Te=r}function _t(){return Te}function Ie(r){const{initDataRaw:e,themeParams:t,platform:s,version:n,showSettings:i,startParam:c,botInline:h}=r,p=new URLSearchParams;return e&&p.set("tgWebAppData",e),p.set("tgWebAppPlatform",s),p.set("tgWebAppThemeParams",ke(t)),p.set("tgWebAppVersion",n),c&&p.set("tgWebAppStartParam",n),typeof i=="boolean"&&p.set("tgWebAppShowSettings",i?"1":"0"),typeof h=="boolean"&&p.set("tgWebAppBotInline",h?"1":"0"),p.toString()}const Le="telegram-mini-apps-launch-params";function bt(){return de(sessionStorage.getItem(Le)||"")}function mt(r){sessionStorage.setItem(Le,Ie(r))}function Y(){const r=[];for(const e of[dt,ft,bt])try{const t=e();return mt(t),t}catch(t){r.push(t)}throw I.error("Unable to extract launch parameters. Received errors:",r),new Error("Unable to retrieve launch parameters from any known source.")}function yt(){return{launchParams:Y(),isPageReload:se()}}function Et(){try{return Y(),!0}catch{return!1}}function Ct(r){return"external"in r&&T(r.external)&&"notify"in r.external&&typeof r.external.notify=="function"}function vt(r){return"TelegramWebviewProxy"in r&&T(r.TelegramWebviewProxy)&&"postEvent"in r.TelegramWebviewProxy&&typeof r.TelegramWebviewProxy.postEvent=="function"}class X extends Error{constructor(e,t){super(`Method "${e}" is unsupported in the Mini Apps version ${t}.`),Object.setPrototypeOf(this,X.prototype)}}class ee extends Error{constructor(e,t,s){super(`Parameter "${t}" in method "${e}" is unsupported in the Mini Apps version ${s}.`),Object.setPrototypeOf(this,ee.prototype)}}const Pt=g({eventType:u(),eventData:r=>r});function Be(r){return Pt.parse(r)}function St(r,e){window.dispatchEvent(new MessageEvent("message",{data:JSON.stringify({eventType:r,eventData:e}),source:window.parent}))}function kt(){const r=window;"TelegramGameProxy_receiveEvent"in r||[["TelegramGameProxy_receiveEvent"],["TelegramGameProxy","receiveEvent"],["Telegram","WebView","receiveEvent"]].forEach(e=>{let t=r;e.forEach((s,n,i)=>{if(n===i.length-1){t[s]=St;return}s in t||(t[s]={}),t=t[s]})})}function qt(r){kt(),window.addEventListener("message",e=>{if(e.source===window.parent)try{const{eventType:t,eventData:s}=Be(e.data);r(t,s)}catch{}})}function At(){return g({req_id:u(),data:r=>r===null?r:u().optional().parse(r)})}function Vt(){return g({req_id:u(),result:r=>r,error:u().optional()})}function Rt(){return g({slug:u(),status:u()})}function Tt(){return g({status:u()})}function It(){return g({button_id:r=>r==null?void 0:u().parse(r)})}function Lt(){return g({data:u().optional()})}function Bt(){return g({theme_params:r=>{const e=ce().optional();return Object.entries(ie(r)).reduce((t,[s,n])=>(t[s]=e.parse(n),t),{})}})}function $t(){return g({height:q(),width:r=>r==null?window.innerWidth:q().parse(r),is_state_stable:P(),is_expanded:P()})}function Dt(){return g({status:u()})}function Nt(){const r=new _,e=(t,...s)=>{I.log("Emitting processed event:",t,...s),r.emit(t,...s)};return window.addEventListener("resize",()=>{e("viewport_changed",{width:window.innerWidth,height:window.innerHeight,is_state_stable:!0,is_expanded:!0})}),qt((t,s)=>{I.log("Received raw event:",t,s);try{switch(t){case"viewport_changed":return e(t,$t().parse(s));case"theme_changed":return e(t,Bt().parse(s));case"popup_closed":return s==null?e(t,{}):e(t,It().parse(s));case"set_custom_style":return e(t,u().parse(s));case"qr_text_received":return e(t,Lt().parse(s));case"clipboard_text_received":return e(t,At().parse(s));case"invoice_closed":return e(t,Rt().parse(s));case"phone_requested":return e("phone_requested",Tt().parse(s));case"custom_method_invoked":return e("custom_method_invoked",Vt().parse(s));case"write_access_requested":return e("write_access_requested",Dt().parse(s));case"main_button_pressed":case"back_button_pressed":case"settings_button_pressed":case"scan_qr_popup_closed":case"reload_iframe":return e(t);default:return e(t,s)}}catch(n){I.error("Error processing event:",n)}}),r}const fe="telegram-mini-apps-cached-emitter";function j(){const r=window;return r[fe]===void 0&&(r[fe]=Nt()),r[fe]}function L(r,e){j().off(r,e)}function E(r,e){return j().on(r,e),()=>L(r,e)}function Ht(r,e){return j().once(r,e),()=>L(r,e)}function $e(r){j().unsubscribe(r)}function Ot(r){return j().subscribe(r),()=>$e(r)}function De(r,e){const t=r.split("."),s=e.split("."),n=Math.max(t.length,s.length);for(let i=0;i<n;i+=1){const c=parseInt(t[i]||"0",10),h=parseInt(s[i]||"0",10);if(c!==h)return c>h?1:-1}return 0}function A(r,e){return De(r,e)<=0}function B(r,e,t){if(typeof t=="string"){if(r==="web_app_open_link"&&e==="try_instant_view")return A("6.4",t);if(r==="web_app_set_header_color"&&e==="color")return A("6.9",t)}switch(r){case"web_app_open_tg_link":case"web_app_open_invoice":case"web_app_setup_back_button":case"web_app_set_background_color":case"web_app_set_header_color":case"web_app_trigger_haptic_feedback":return A("6.1",e);case"web_app_open_popup":return A("6.2",e);case"web_app_close_scan_qr_popup":case"web_app_open_scan_qr_popup":case"web_app_read_text_from_clipboard":return A("6.4",e);case"web_app_switch_inline_query":return A("6.7",e);case"web_app_invoke_custom_method":case"web_app_request_write_access":case"web_app_request_phone":return A("6.9",e);case"web_app_setup_settings_button":return A("6.10",e);default:return!0}}function S(r,e){return t=>B(e[t],r)}function Ne(r,e){return t=>{const[s,n]=e[t];return B(s,n,r)}}function d(r,e,t){let s={},n;e===void 0&&t===void 0?s={}:e!==void 0&&t!==void 0?(s=t,n=e):e!==void 0&&("targetOrigin"in e?s=e:n=e);const{targetOrigin:i=_t()}=s;if(I.log(`Calling method "${r}"`,n),v()){window.parent.postMessage(JSON.stringify({eventType:r,eventData:n}),i);return}if(Ct(window)){window.external.notify(JSON.stringify({eventType:r,eventData:n}));return}if(vt(window)){window.TelegramWebviewProxy.postEvent(r,JSON.stringify(n));return}throw new Error("Unable to determine current environment and possible way to send event.")}function He(r){return(e,t)=>{if(!B(e,r))throw new X(e,r);if(T(t)){let s;if(e==="web_app_open_link"&&"try_instant_view"in t?s="try_instant_view":e==="web_app_set_header_color"&&"color"in t&&(s="color"),s&&!B(e,s,r))throw new ee(e,s,r)}return d(e,t)}}class G extends Error{constructor(e){super(`Async call timeout exceeded. Timeout: ${e}`),Object.setPrototypeOf(this,G.prototype)}}function Wt(r){return r instanceof G}function Mt(r){return new Promise(e=>{setTimeout(e,r)})}function Ut(r){return new Promise((e,t)=>{setTimeout(t,r,new G(r))})}function ge(r,e){return Promise.race([r(),Ut(e)])}function C(r,e,t,s){let n,i,c,h;typeof e=="string"||Array.isArray(e)?(c=Array.isArray(e)?e:[e],n=t):(i=e,c=Array.isArray(t)?t:[t],n=s),T(i)&&typeof i.req_id=="string"&&(h=i.req_id);const{postEvent:p=d,timeout:l}=n||{},w=n&&"capture"in n?n.capture:null,b=()=>new Promise((M,f)=>{const V=c.map(R=>E(R,re=>{h&&(!T(re)||re.req_id!==h)||typeof w=="function"&&!w(re)||($(),M(re))})),$=()=>V.forEach(R=>R());try{p(r,i)}catch(R){$(),f(R)}});return typeof l=="number"?ge(b,l):b()}async function H(r,e,t,s={}){const{result:n,error:i}=await C("web_app_invoke_custom_method",{method:r,params:e,req_id:t},"custom_method_invoked",s);if(i)throw new Error(i);return n}class Oe{constructor(e,t,s=d){a(this,"ee",new _);a(this,"state");a(this,"on",(e,t)=>e==="click"?E("back_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?L("back_button_pressed",t):this.ee.off(e,t));a(this,"supports");this.postEvent=s,this.state=new y({isVisible:e},this.ee),this.supports=S(t,{show:"web_app_setup_back_button",hide:"web_app_setup_back_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_back_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function We(r,e){return r+(r.length>0&&e.length>0?` ${e}`:e)}function Me(...r){return r.reduce((e,t)=>{let s="";return typeof t=="string"?s=t:typeof t=="object"&&t!==null&&(s=Object.entries(t).reduce((n,[i,c])=>c?We(n,i):n,"")),We(e,s)},"")}function xt(...r){return r.reduce((e,t)=>(T(t)&&Object.entries(t).forEach(([s,n])=>{const i=Me(e[s],n);i.length>0&&(e[s]=i)}),e),{})}class Ue{constructor(e,t=d){a(this,"ee",new _);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));this.postEvent=t,this.state=new y({isConfirmationNeeded:e},this.ee)}set isConfirmationNeeded(e){this.state.set("isConfirmationNeeded",e),this.postEvent("web_app_setup_closing_behavior",{need_confirmation:e})}get isConfirmationNeeded(){return this.state.get("isConfirmationNeeded")}disableConfirmation(){this.isConfirmationNeeded=!1}enableConfirmation(){this.isConfirmationNeeded=!0}}function xe(r,e){return r.reduce((t,s)=>(t[s]=e,t),{})}class je{constructor(e,t,s=d){a(this,"supports");this.createRequestId=t,this.postEvent=s,this.supports=S(e,{delete:"web_app_invoke_custom_method",get:"web_app_invoke_custom_method",getKeys:"web_app_invoke_custom_method",set:"web_app_invoke_custom_method"})}async delete(e,t={}){const s=Array.isArray(e)?e:[e];s.length!==0&&await H("deleteStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent})}async getKeys(e={}){const t=await H("getStorageKeys",{},this.createRequestId(),{...e,postEvent:this.postEvent});return Ce().of(u()).parse(t)}async get(e,t={}){const s=Array.isArray(e)?e:[e];if(s.length===0)return xe(s,"");const n=g(xe(s,u())),i=await H("getStorageValues",{keys:s},this.createRequestId(),{...t,postEvent:this.postEvent}).then(c=>n.parse(c));return Array.isArray(e)?i:i[e]}async set(e,t,s={}){await H("saveStorageValue",{key:e,value:t},this.createRequestId(),{...s,postEvent:this.postEvent})}}function k(r,e){document.documentElement.style.setProperty(r,e)}function Ge(r,e){const t=()=>{k("--tg-background-color",r.backgroundColor)},s=()=>{const{backgroundColor:n,secondaryBackgroundColor:i}=e;if(Z(r.headerColor)){k("--tg-header-color",r.headerColor);return}if(r.headerColor==="bg_color"&&n){k("--tg-header-color",n);return}r.headerColor==="secondary_bg_color"&&i&&k("--tg-header-color",i)};e.on("change",s),r.on("change:backgroundColor",t),r.on("change:headerColor",s),t(),s()}function Fe(r){const e=()=>{const t=r.getState();Object.entries(t).forEach(([s,n])=>{if(n){const i=s.replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`);k(`--tg-theme-${i}`,n)}})};r.on("change",e),e()}function we(r){const e=()=>k("--tg-viewport-height",`${r.height}px`),t=()=>k("--tg-viewport-width",`${r.width}px`),s=()=>k("--tg-viewport-stable-height",`${r.stableHeight}px`);r.on("change:height",e),r.on("change:width",t),r.on("change:stableHeight",s),e(),t(),s()}class ze{constructor(e,t=d){a(this,"supports");this.postEvent=t,this.supports=S(e,{impactOccurred:"web_app_trigger_haptic_feedback",notificationOccurred:"web_app_trigger_haptic_feedback",selectionChanged:"web_app_trigger_haptic_feedback"})}impactOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"impact",impact_style:e})}notificationOccurred(e){this.postEvent("web_app_trigger_haptic_feedback",{type:"notification",notification_type:e})}selectionChanged(){this.postEvent("web_app_trigger_haptic_feedback",{type:"selection_change"})}}function jt(){const r=document.createElement("style");r.id="telegram-custom-styles",document.head.appendChild(r),E("set_custom_style",e=>{r.innerHTML=e})}function Je(r){return`telegram-mini-apps-${r}`}function O(r,e){sessionStorage.setItem(Je(r),JSON.stringify(e))}function W(r){const e=sessionStorage.getItem(Je(r));return e?JSON.parse(e):null}function Gt(r,e,t){const{isVisible:s=!1}=r?W("back-button")||{}:{},n=new Oe(s,e,t);return n.on("change",()=>{O("back-button",{isVisible:n.isVisible})}),n}function Ft(r,e){const{isConfirmationNeeded:t=!1}=r?W("closing-behavior")||{}:{},s=new Ue(t,e);return s.on("change",()=>O("closing-behavior",{isConfirmationNeeded:s.isConfirmationNeeded})),s}class Qe{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"postEvent");a(this,"on",(e,t)=>e==="click"?E("main_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?L("main_button_pressed",t):this.ee.off(e,t));const{postEvent:t=d,text:s,textColor:n,backgroundColor:i,isEnabled:c,isVisible:h,isLoaderVisible:p}=e;this.postEvent=t,this.state=new y({backgroundColor:i,isEnabled:c,isVisible:h,isLoaderVisible:p,text:s,textColor:n},this.ee)}commit(){this.text!==""&&this.postEvent("web_app_setup_main_button",{is_visible:this.isVisible,is_active:this.isEnabled,is_progress_visible:this.isLoaderVisible,text:this.text,color:this.backgroundColor,text_color:this.textColor})}set isEnabled(e){this.setParams({isEnabled:e})}get isEnabled(){return this.state.get("isEnabled")}set isLoaderVisible(e){this.setParams({isLoaderVisible:e})}get isLoaderVisible(){return this.state.get("isLoaderVisible")}set isVisible(e){this.setParams({isVisible:e})}get isVisible(){return this.state.get("isVisible")}get backgroundColor(){return this.state.get("backgroundColor")}get text(){return this.state.get("text")}get textColor(){return this.state.get("textColor")}disable(){return this.isEnabled=!1,this}enable(){return this.isEnabled=!0,this}hide(){return this.isVisible=!1,this}hideLoader(){return this.isLoaderVisible=!1,this}show(){return this.isVisible=!0,this}showLoader(){return this.isLoaderVisible=!0,this}setText(e){return this.setParams({text:e})}setTextColor(e){return this.setParams({textColor:e})}setBackgroundColor(e){return this.setParams({backgroundColor:e})}setParams(e){return this.state.set(e),this.commit(),this}}function zt(r,e,t,s){const{backgroundColor:n=e,isEnabled:i=!1,isVisible:c=!1,isLoaderVisible:h=!1,textColor:p=t,text:l=""}=r?W("main-button")||{}:{},w=new Qe({backgroundColor:n,isEnabled:i,isLoaderVisible:h,isVisible:c,postEvent:s,text:l,textColor:p}),b=()=>O("main-button",{backgroundColor:w.backgroundColor,isEnabled:w.isEnabled,isLoaderVisible:w.isLoaderVisible,isVisible:w.isVisible,text:w.text,textColor:w.textColor});return w.on("change",b),w}const Jt=K({contact:g({userId:{type:q(),from:"user_id"},phoneNumber:{type:u(),from:"phone_number"},firstName:{type:u(),from:"first_name"},lastName:{type:u().optional(),from:"last_name"}}),authDate:{type:ne(),from:"auth_date"},hash:u()});class Ze{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"botInline");a(this,"postEvent");a(this,"createRequestId");a(this,"requestingPhoneAccess",!1);a(this,"requestingWriteAccess",!1);a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");a(this,"supportsParam");const{postEvent:t=d,headerColor:s,backgroundColor:n,version:i,botInline:c,createRequestId:h}=e,p=S(i,{requestPhoneAccess:"web_app_request_phone",requestWriteAccess:"web_app_request_write_access",switchInlineQuery:"web_app_switch_inline_query",setHeaderColor:"web_app_set_header_color",setBackgroundColor:"web_app_set_background_color"});this.postEvent=t,this.botInline=c,this.createRequestId=h,this.supports=l=>!(!p(l)||l==="switchInlineQuery"&&!c),this.state=new y({backgroundColor:n,headerColor:s},this.ee),this.supportsParam=Ne(i,{"setHeaderColor.color":["web_app_set_header_color","color"]})}async getRequestedContact(){return H("getRequestedContact",{},this.createRequestId(),{postEvent:this.postEvent,timeout:1e4}).then(e=>Jt.parse(e))}get backgroundColor(){return this.state.get("backgroundColor")}close(){this.postEvent("web_app_close")}get headerColor(){return this.state.get("headerColor")}get isBotInline(){return this.botInline}get isDark(){return ae(this.backgroundColor)}get isRequestingPhoneAccess(){return this.requestingPhoneAccess}get isRequestingWriteAccess(){return this.requestingWriteAccess}ready(){this.postEvent("web_app_ready")}async requestContact({timeout:e=5e3}={}){try{return await this.getRequestedContact()}catch{}if(await this.requestPhoneAccess()!=="sent")throw new Error("Access denied.");const s=Date.now()+e;let n=50;return ge(async()=>{for(;Date.now()<s;){try{return await this.getRequestedContact()}catch{}await Mt(n),n+=50}throw new Error("Unable to retrieve requested contact.")},e)}requestPhoneAccess(e={}){if(this.requestingPhoneAccess)throw new Error("Phone access is already being requested.");return this.requestingPhoneAccess=!0,C("web_app_request_phone","phone_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingPhoneAccess=!1})}requestWriteAccess(e={}){if(this.requestingWriteAccess)throw new Error("Write access is already being requested.");return this.requestingWriteAccess=!0,C("web_app_request_write_access","write_access_requested",{...e,postEvent:this.postEvent}).then(t=>t.status).finally(()=>{this.requestingWriteAccess=!1})}sendData(e){const{size:t}=new Blob([e]);if(t===0||t>4096)throw new Error(`Passed data has incorrect size: ${t}`);this.postEvent("web_app_data_send",{data:e})}setHeaderColor(e){this.postEvent("web_app_set_header_color",Z(e)?{color:e}:{color_key:e}),this.state.set("headerColor",e)}setBackgroundColor(e){this.postEvent("web_app_set_background_color",{color:e}),this.state.set("backgroundColor",e)}switchInlineQuery(e,t=[]){if(!this.supports("switchInlineQuery")&&!this.isBotInline)throw new Error("Method is unsupported because Mini App should be launched in inline mode.");this.postEvent("web_app_switch_inline_query",{query:e,chat_types:t})}}function Qt(r,e,t,s,n,i){const{backgroundColor:c=e,headerColor:h="bg_color"}=r?W("mini-app")||{}:{},p=new Ze({headerColor:h,backgroundColor:c,version:t,botInline:s,createRequestId:n,postEvent:i}),l=()=>O("mini-app",{backgroundColor:p.backgroundColor,headerColor:p.headerColor});return p.on("change",l),p}function Zt(){let r=0;return()=>(r+=1,r.toString())}class Ke{constructor(e,t,s=d){a(this,"ee",new _);a(this,"state");a(this,"on",(e,t)=>e==="click"?E("settings_button_pressed",t):this.ee.on(e,t));a(this,"off",(e,t)=>e==="click"?L("settings_button_pressed",t):this.ee.off(e,t));a(this,"supports");this.postEvent=s,this.state=new y({isVisible:e},this.ee),this.supports=S(t,{show:"web_app_setup_settings_button",hide:"web_app_setup_settings_button"})}set isVisible(e){this.state.set("isVisible",e),this.postEvent("web_app_setup_settings_button",{is_visible:e})}get isVisible(){return this.state.get("isVisible")}hide(){this.isVisible=!1}show(){this.isVisible=!0}}function Kt(r,e,t){const{isVisible:s=!1}=r?W("settings-button")||{}:{},n=new Ke(s,e,t);return n.on("change",()=>{O("settings-button",{isVisible:n.isVisible})}),n}function Yt(r){const e=new qe(r);return e.listen(),e}function Ye(r){return["macos","tdesktop","unigram","web","weba"].includes(r)}async function _e(r){const e=await C("web_app_request_viewport","viewport_changed",r);return{height:e.height,width:e.width,isExpanded:e.is_expanded,isStateStable:e.is_state_stable}}function F(r){return r<0?0:r}class Xe{constructor(e){a(this,"ee",new _);a(this,"state");a(this,"postEvent");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));const{height:t,isExpanded:s,width:n,stableHeight:i,postEvent:c=d}=e;this.postEvent=c,this.state=new y({height:F(t),isExpanded:s,stableHeight:F(i),width:F(n)},this.ee)}sync(e){return _e(e).then(({height:t,isExpanded:s,width:n,isStateStable:i})=>{this.state.set({height:t,width:n,isExpanded:s,stableHeight:i?t:this.state.get("stableHeight")})})}get height(){return this.state.get("height")}get stableHeight(){return this.state.get("stableHeight")}listen(){return E("viewport_changed",e=>{const{height:t,width:s,is_expanded:n,is_state_stable:i}=e,c={height:F(t),isExpanded:n,width:F(s)};i&&(c.stableHeight=c.height),this.state.set(c)})}get isExpanded(){return this.state.get("isExpanded")}get width(){return this.state.get("width")}expand(){this.postEvent("web_app_expand"),this.state.set("isExpanded",!0)}get isStable(){return this.stableHeight===this.height}}function te(r){const e=new Xe(r);return e.on("change",()=>O("viewport",{height:e.height,isExpanded:e.isExpanded,stableHeight:e.stableHeight,width:e.width})),e.listen(),e}function Xt(r,e,t,s){const n=r?W("viewport"):null;if(n)return te({...n,postEvent:t});if(Ye(e))return te({height:window.innerHeight,isExpanded:!0,postEvent:t,stableHeight:window.innerHeight,width:window.innerWidth});if(s)return _e({postEvent:t,timeout:5e3}).then(({height:c,isStateStable:h,...p})=>te({...p,height:c,stableHeight:h?c:0}));const i=te({width:0,height:0,isExpanded:!1,postEvent:t,stableHeight:0});return i.sync({postEvent:t,timeout:5e3}).catch(c=>{console.error("Unable to actualize viewport state",c)}),i}function er(r){return typeof r=="object"?r:r?{themeParams:!0,viewport:!0,miniApp:!0}:{}}function et(r,e,t,s){const n=er(r);n.miniApp&&Ge(e,t),n.themeParams&&Fe(t),n.viewport&&(s instanceof Promise?s.then(we):we(s))}function tr(r){const{hostname:e,pathname:t}=new URL(r,window.location.href);if(e!=="t.me")throw new Error(`Incorrect hostname: ${e}`);const s=t.match(/^\/(\$|invoice\/)([A-Za-z0-9\-_=]+)$/);if(s===null)throw new Error('Link pathname has incorrect format. Expected to receive "/invoice/{slug}" or "/${slug}"');return s[2]}class tt{constructor(e,t=d){a(this,"ee",new _);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");this.postEvent=t,this.state=new y({isOpened:!1},this.ee),this.supports=S(e,{open:"web_app_open_invoice"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e,t){if(this.isOpened)throw new Error("Invoice is already opened");const s=t?tr(e):e;this.isOpened=!0;try{return(await C("web_app_open_invoice",{slug:s},"invoice_closed",{postEvent:this.postEvent,capture(i){return s===i.slug}})).status}finally{this.isOpened=!1}}}function rr(r){const e=r.message.trim(),t=(r.title||"").trim(),s=r.buttons||[];let n;if(t.length>64)throw new Error(`Title has incorrect size: ${t.length}`);if(e.length===0||e.length>256)throw new Error(`Message has incorrect size: ${e.length}`);if(s.length>3)throw new Error(`Buttons have incorrect size: ${s.length}`);return s.length===0?n=[{type:"close",id:""}]:n=s.map(i=>{const{id:c=""}=i;if(c.length>64)throw new Error(`Button ID has incorrect size: ${c}`);if(i.type===void 0||i.type==="default"||i.type==="destructive"){const h=i.text.trim();if(h.length===0||h.length>64){const p=i.type||"default";throw new Error(`Button text with type "${p}" has incorrect size: ${i.text.length}`)}return{...i,text:h,id:c}}return{...i,id:c}}),{title:t,message:e,buttons:n}}class rt{constructor(e,t=d){a(this,"ee",new _);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");this.postEvent=t,this.state=new y({isOpened:!1},this.ee),this.supports=S(e,{open:"web_app_open_popup"})}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}open(e){if(this.isOpened)throw new Error("Popup is already opened.");return this.isOpened=!0,C("web_app_open_popup",rr(e),"popup_closed",{postEvent:this.postEvent}).then(({button_id:t=null})=>t).finally(()=>{this.isOpened=!1})}}class st{constructor(e,t=d){a(this,"ee",new _);a(this,"state");a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee));a(this,"supports");this.postEvent=t,this.state=new y({isOpened:!1},this.ee),this.supports=S(e,{close:"web_app_close_scan_qr_popup",open:"web_app_open_scan_qr_popup"})}close(){this.postEvent("web_app_close_scan_qr_popup"),this.isOpened=!1}set isOpened(e){this.state.set("isOpened",e)}get isOpened(){return this.state.get("isOpened")}async open(e){if(this.isOpened)throw new Error("QR scanner is already opened.");this.isOpened=!0;try{const t=await C("web_app_open_scan_qr_popup",{text:e},["qr_text_received","scan_qr_popup_closed"],{postEvent:this.postEvent});return typeof t=="object"&&typeof t.data=="string"?t.data:null}finally{this.isOpened=!1}}}class nt{constructor(e,t,s=d){a(this,"supports");a(this,"supportsParam");this.version=e,this.createRequestId=t,this.postEvent=s,this.supports=S(e,{readTextFromClipboard:"web_app_read_text_from_clipboard"}),this.supportsParam=Ne(e,{"openLink.tryInstantView":["web_app_open_link","try_instant_view"]})}openLink(e,t){const s=new URL(e,window.location.href).toString();if(!B("web_app_open_link",this.version)){window.open(s,"_blank");return}this.postEvent("web_app_open_link",{url:s,...typeof t=="boolean"?{try_instant_view:t}:{}})}openTelegramLink(e){const{hostname:t,pathname:s,search:n}=new URL(e,window.location.href);if(t!=="t.me")throw new Error(`URL has not allowed hostname: ${t}. Only "t.me" is allowed`);if(!B("web_app_open_tg_link",this.version)){window.location.href=e;return}this.postEvent("web_app_open_tg_link",{path_full:s+n})}readTextFromClipboard(){return C("web_app_read_text_from_clipboard",{req_id:this.createRequestId()},"clipboard_text_received",{postEvent:this.postEvent}).then(({data:e=null})=>e)}}function sr(r={}){const{async:e=!1,complete:t=e,cssVars:s=!1,acceptCustomStyles:n=!1}=r;try{const{initData:i,initDataRaw:c,version:h,platform:p,themeParams:l,botInline:w=!1}=Y(),b=se(),M=Zt(),f=He(h);v()&&(n&&jt(),f("iframe_ready",{reload_supported:!0}),E("reload_iframe",()=>window.location.reload()));const V={backButton:Gt(b,h,f),closingBehavior:Ft(b,f),cloudStorage:new je(h,M,f),createRequestId:M,hapticFeedback:new ze(h,f),invoice:new tt(h,f),mainButton:zt(b,l.buttonColor||"#000000",l.buttonTextColor||"#ffffff",f),miniApp:Qt(b,l.backgroundColor||"#ffffff",h,w,M,f),popup:new rt(h,f),postEvent:f,qrScanner:new st(h,f),settingsButton:Kt(b,h,f),themeParams:Yt(l),utils:new nt(h,M,f),...i?{initData:new Se(i),initDataRaw:c}:{}},$=Xt(b,p,f,t);return $ instanceof Promise||t?Promise.resolve($).then(R=>(et(s,V.miniApp,V.themeParams,R),{...V,viewport:R})):(et(s,V.miniApp,V.themeParams,$),{...V,viewport:$})}catch(i){if(t)return Promise.reject(i);throw i}}function z(r,e){return r.startsWith(e)?r:`${e}${r}`}function nr(r){const e=r.match(/#(.+)/);return e?e[1]:null}async function J(r){return r===0?!0:Promise.race([new Promise(e=>{window.addEventListener("popstate",function t(){window.removeEventListener("popstate",t),e(!0)}),window.history.go(r)}),new Promise(e=>{setTimeout(e,50,!1)})])}async function ir(){if(window.history.length<=1||(window.history.pushState(null,""),await J(1-window.history.length)))return;let e=await J(-1);for(;e;)e=await J(-1)}class it{constructor(e,t,{debug:s=!1,loggerPrefix:n="Navigator"}){a(this,"logger");a(this,"entries");if(this.entriesCursor=t,e.length===0)throw new Error("Entries list should not be empty.");if(t>=e.length)throw new Error("Cursor should be less than entries count.");this.entries=e.map(({pathname:i="",search:c,hash:h})=>{if(!i.startsWith("/")&&i.length>0)throw new Error('Pathname should start with "/"');return{pathname:z(i,"/"),search:c?z(c,"?"):"",hash:h?z(h,"#"):""}}),this.logger=new Re(`[${n}]`,s)}formatEntry(e){let t;if(typeof e=="string")t=e;else{const{pathname:c="",search:h,hash:p}=e;t=c+(h?z(h,"?"):"")+(p?z(p,"#"):"")}const{pathname:s,search:n,hash:i}=new URL(t,`https://localhost${this.path}`);return{pathname:s,search:n,hash:i}}get entry(){return this.entries[this.entriesCursor]}back(){return this.go(-1)}get cursor(){return this.entriesCursor}get canGoBack(){return this.entriesCursor>0}get canGoForward(){return this.entriesCursor!==this.entries.length-1}forward(){return this.go(1)}go(e){this.logger.log(`called go(${e})`);const t=Math.min(this.entries.length-1,Math.max(this.entriesCursor+e,0));if(this.entriesCursor===t)return this.performGo({updated:!1,delta:e});const s=this.entry;this.entriesCursor=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performGo({updated:!0,delta:e,before:s,after:n})}getEntries(){return this.entries.map(e=>({...e}))}get hash(){return this.entry.hash}push(e){this.entriesCursor!==this.entries.length-1&&this.entries.splice(this.entriesCursor+1);const t=this.formatEntry(e),s=this.entry;this.entriesCursor+=1,this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performPush({before:s,after:n})}get path(){return`${this.pathname}${this.search}${this.hash}`}get pathname(){return this.entry.pathname}replace(e){const t=this.formatEntry(e);if(this.search===t.search&&this.pathname===t.pathname&&this.hash===t.hash)return this.performReplace({updated:!1,entry:t});const s=this.entry;this.entries[this.entriesCursor]=t;const n=this.entry;return this.logger.log("State changed",{before:s,after:n}),this.performReplace({updated:!0,before:s,after:n})}get search(){return this.entry.search}}const ot=0,be=1,me=2;class ye extends it{constructor(t,s,n={}){super(t,s,{...n,loggerPrefix:"HashNavigator"});a(this,"ee",new _);a(this,"attached",!1);a(this,"onPopState",async({state:t})=>{if(this.logger.log('"popstate" event received. State:',t),t===null)return this.push(window.location.hash.slice(1));if(t===ot){this.logger.log("Void reached. Moving history forward"),window.history.forward();return}if(t===be)return this.back();if(t===me)return this.forward()});a(this,"back",()=>super.back());a(this,"on",this.ee.on.bind(this.ee));a(this,"off",this.ee.off.bind(this.ee))}static fromLocation(t){const{search:s,pathname:n,hash:i}=new URL(window.location.hash.slice(1),window.location.href);return new ye([{search:s,pathname:n,hash:i}],0,t)}async performGo(t){t.updated&&(this.attached&&await this.syncHistory(),this.emitChanged(t.before,t.after))}async performPush({before:t,after:s}){this.attached&&await this.syncHistory(),this.emitChanged(t,s)}async performReplace(t){t.updated&&(this.attached&&window.history.replaceState(null,"",`#${this.path}`),this.emitChanged(t.before,t.after))}async syncHistory(){window.removeEventListener("popstate",this.onPopState);const t=`#${this.path}`;await ir(),d("web_app_setup_back_button",{is_visible:this.canGoBack}),this.canGoBack&&this.canGoForward?(this.logger.log("Setting up history: [<-, *, ->]"),window.history.replaceState(be,""),window.history.pushState(null,"",t),window.history.pushState(me,""),await J(-1)):this.canGoBack?(this.logger.log("Setting up history: [<-, *]"),window.history.replaceState(be,""),window.history.pushState(null,"",t)):this.canGoForward?(this.logger.log("Setting up history: [*, ->]"),window.history.replaceState(null,t),window.history.pushState(me,""),await J(-1)):(this.logger.log("Setting up history: [~, *]"),window.history.replaceState(ot,""),window.history.pushState(null,"",t)),window.addEventListener("popstate",this.onPopState)}emitChanged(t,s){this.ee.emit("change",{navigator:this,from:t,to:s})}async attach(){if(!this.attached)return this.logger.log("Attaching",this),this.attached=!0,E("back_button_pressed",this.back),this.syncHistory()}detach(){this.attached&&(this.logger.log("Detaching",this),this.attached=!1,window.removeEventListener("popstate",this.onPopState),L("back_button_pressed",this.back))}}return o.BackButton=Oe,o.ClosingBehavior=Ue,o.CloudStorage=je,o.HapticFeedback=ze,o.HashNavigator=ye,o.InitData=Se,o.Invoice=tt,o.MainButton=Qe,o.MethodUnsupportedError=X,o.MiniApp=Ze,o.Navigator=it,o.ParameterUnsupportedError=ee,o.ParseError=U,o.ParseSchemaFieldError=x,o.Popup=rt,o.QRScanner=st,o.SettingsButton=Ke,o.ThemeParams=qe,o.TimeoutError=G,o.Utils=nt,o.Viewport=Xe,o.array=Ce,o.bindMiniAppCSSVars=Ge,o.bindThemeCSSVars=Fe,o.bindViewportCSSVars=we,o.boolean=P,o.chatParser=Pe,o.classNames=Me,o.compareVersions=De,o.createPostEvent=He,o.date=ne,o.getHash=nr,o.init=sr,o.initDataParser=ue,o.invokeCustomMethod=H,o.isColorDark=ae,o.isIframe=v,o.isPageReload=se,o.isRGB=Z,o.isRGBShort=ve,o.isRecord=T,o.isStableViewportPlatform=Ye,o.isTMA=Et,o.isTimeoutError=Wt,o.json=g,o.launchParamsParser=Ae,o.mergeClassNames=xt,o.number=q,o.off=L,o.on=E,o.once=Ht,o.parseInitData=ht,o.parseLaunchParams=de,o.parseMessage=Be,o.parseThemeParams=le,o.postEvent=d,o.request=C,o.requestThemeParams=lt,o.requestViewport=_e,o.retrieveLaunchData=yt,o.retrieveLaunchParams=Y,o.rgb=ce,o.searchParams=K,o.serializeLaunchParams=Ie,o.serializeThemeParams=ke,o.setCSSVar=k,o.setDebug=gt,o.setTargetOrigin=wt,o.string=u,o.subscribe=Ot,o.supports=B,o.themeParamsParser=pe,o.toRGB=oe,o.unsubscribe=$e,o.userParser=he,o.withTimeout=ge,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),o}({});
|