{"version":3,"file":"index.cjs","sources":["../src/env.ts","../src/posting/postEvent.ts","../src/parsing.ts","../src/events-observer.ts","../src/events-receiver.ts","../src/Bridge.ts","../src/supports.ts"],"sourcesContent":["import {isRecord} from '@twa-dev/utils';\n\ntype AnyFunc = (...args: unknown[]) => unknown;\n\n/**\n * Returns true in case, passed value contains function property `notify`.\n * @param value - value to check.\n */\nexport function hasNotify<T extends {}>(value: T): value is T & { notify: AnyFunc } {\n  return 'notify' in value && typeof value.notify === 'function';\n}\n\n/**\n * Returns true in case, passed value contains object property `external`.\n * @param value - value to check.\n */\nexport function hasExternal<T extends {}>(value: T): value is T & { external: Record<string, unknown> } {\n  return 'external' in value && isRecord(value.external);\n}\n\n/**\n * Returns true in case, passed value contains function property `notify`.\n * @param value - value to check.\n */\nexport function hasInvoke<T extends {}>(value: T): value is T & { invoke: AnyFunc } {\n  return 'invoke' in value && typeof value.invoke === 'function';\n}\n\n/**\n * Returns true in case, current environment is iframe.\n * @see https://stackoverflow.com/a/326076\n */\nexport function isIframe(): boolean {\n  try {\n    return window.self !== window.top;\n  } catch (e) {\n    return true;\n  }\n}\n","import {\n  PostEmptyEventName, PostEventName,\n  PostEventParams,\n  PostNonEmptyEventName,\n} from './events';\nimport {hasInvoke, hasNotify, hasExternal, isIframe} from '../env';\nimport {isRecord} from '@twa-dev/utils';\n\ninterface PostEventOptions {\n  /**\n   * Origin used while posting message. This option is only used in case,\n   * current environment is browser (Web version of Telegram) and could\n   * be used for test purposes.\n   * @default 'https://web.telegram.org'\n   */\n  targetOrigin?: string;\n}\n\n/**\n * Sends event to native application which launched Web App. This function\n * accepts only events, which require arguments.\n * @param eventType - event name.\n * @param params - event parameters.\n * @param options - posting options.\n * @throws {Error} Bridge could not determine current\n * environment and possible way to send event.\n */\nexport function postEvent<E extends PostNonEmptyEventName>(\n  eventType: E,\n  params: PostEventParams<E>,\n  options?: PostEventOptions,\n): void;\n\n/**\n * Sends event to native application which launched Web App. This function\n * accepts only events, which require arguments.\n * @param eventType - event name.\n * @param options - posting options.\n * @throws {Error} Bridge could not determine current\n * environment and possible way to send event.\n */\nexport function postEvent(\n  eventType: PostEmptyEventName,\n  options?: PostEventOptions,\n): void;\n\nexport function postEvent(\n  eventType: PostEventName,\n  paramsOrOptions?: PostEventParams<PostEventName> | PostEventOptions,\n  options?: PostEventOptions,\n): void {\n  let _options: PostEventOptions = {};\n  let eventData: any;\n\n  // Parameters and options were not passed.\n  if (paramsOrOptions === undefined && options === undefined) {\n    _options = {};\n  }\n  // Both parameters and options passed.\n  else if (paramsOrOptions !== undefined && options !== undefined) {\n    _options = options;\n    eventData = paramsOrOptions;\n  }\n  // Only parameters were passed.\n  else if (paramsOrOptions !== undefined) {\n    if ('targetOrigin' in paramsOrOptions) {\n      _options = paramsOrOptions;\n    } else {\n      eventData = paramsOrOptions;\n    }\n  }\n  const {targetOrigin = 'https://web.telegram.org'} = _options;\n\n  // Telegram Web.\n  if (isIframe()) {\n    window.parent.postMessage(JSON.stringify({\n      eventType,\n      eventData,\n    }), targetOrigin);\n    return;\n  }\n\n  // Telegram for Windows Phone, iOS or Android.\n  if (hasExternal(window)) {\n    if (hasNotify(window.external)) {\n      window.external.notify(JSON.stringify({eventType, eventData}));\n      return;\n    }\n\n    if (hasInvoke(window.external)) {\n      window.external.invoke(JSON.stringify([eventType, eventData]));\n      return;\n    }\n  }\n\n  // Otherwise current environment is unknown, and we are not able to send\n  // event.\n  throw new Error(\n    'Unable to determine current environment and possible ' +\n    'way to send event.',\n  );\n}\n","import {\n  createJsonParser,\n  parseJsonValueAsNumber,\n  parseJsonValueAsString,\n} from '@twa-dev/utils';\nimport {ViewportChangedPayload} from './listening';\n\n/**\n * Parses incoming value as ThemeChangedPayload.\n */\nexport const parseThemeChangedPayload = createJsonParser({\n  theme_params: createJsonParser({\n    bg_color: 'rgb',\n    text_color: 'rgb',\n    hint_color: 'rgb',\n    link_color: 'rgb',\n    button_color: 'rgb',\n    button_text_color: 'rgb',\n    secondary_bg_color: {type: 'rgb', optional: true},\n  }),\n});\n\n/**\n * Parses incoming value as ViewportChangedPayload with optional width.\n */\nconst parseRawViewportChangedPayload = createJsonParser({\n  height: 'number',\n  width: {\n    type: value => value === null ? undefined : parseJsonValueAsNumber(value),\n    optional: true,\n  },\n  is_state_stable: 'boolean',\n  is_expanded: 'boolean',\n});\n\n/**\n * Parses incoming value as ViewportChangedPayload.\n * @param value - value to parse.\n */\nexport function parseViewportChangedPayload(value: unknown): ViewportChangedPayload {\n  const {\n    width = window.innerWidth,\n    ...rest\n  } = parseRawViewportChangedPayload(value);\n  return {width, ...rest};\n}\n\n/**\n * Parses incoming value as PopupClosedPayload.\n */\nexport const parsePopupClosedPayload = createJsonParser({\n  button_id: {\n    type: value => value === null ? undefined : parseJsonValueAsString(value),\n    optional: true,\n  },\n});\n\n/**\n * Parses incoming value as QrTextReceivedPayload.\n */\nexport const parseQrTextReceivedPayload = createJsonParser({\n  data: {type: 'string', optional: true},\n});\n\n/**\n * Parses incoming value as InvoiceClosedPayload.\n */\nexport const parseInvoiceClosedPayload = createJsonParser({\n  slug: 'string',\n  status: 'string',\n});\n\n/**\n * Parses incoming value as clipboard text received payload.\n */\nexport const parseClipboardTextReceivedPayload = createJsonParser({\n  req_id: 'string',\n  data: {\n    type: value => value === null ? value : parseJsonValueAsString(value),\n    optional: true,\n  },\n});\n","import {EventEmitter, createJsonParser} from '@twa-dev/utils';\nimport {ViewportChangedPayload} from './listening';\n\nexport interface EventsObserverEventsMap {\n  /**\n   * Event, emitted by Telegram native application.\n   * @param eventType - event name.\n   * @param eventData - event payload.\n   */\n  message(eventType: string, eventData: unknown): void;\n}\n\n/**\n * Represents global event emitter which handles window \"message\" event and\n * emits new event with prepared data.\n */\nexport type EventsObserver = EventEmitter<EventsObserverEventsMap>;\n\n\n/**\n * Extracts event data from native application event.\n */\nconst parseMessageEventData = createJsonParser({\n  eventType: 'string',\n  eventData: {type: value => value, optional: true},\n});\n\n/**\n * Returns event emitter which is listening to window \"message\" events, extracts\n * their data assuming they are Telegram native application events and emits\n * them by itself.\n */\nexport function createEventsObserver(): EventsObserver {\n  const emitter: EventsObserver = new EventEmitter();\n\n  // We could receive \"message\" events in case they were sent from Telegram\n  // native application.\n  window.addEventListener('message', event => {\n    try {\n      const {eventType, eventData} = parseMessageEventData(event.data);\n      emitter.emit('message', eventType, eventData);\n    } catch {\n      // We ignore incorrect messages as long as they could be generated\n      // by anyone and there is no warranty, it was sent from Telegram.\n    }\n  });\n\n  // Desktop version of Telegram is sometimes not sending the viewport_changed\n  // event. For example, when main button is shown. That's why we should\n  // add our own listener to make sure, viewport information is always fresh.\n  // Issue: https://github.com/Telegram-Web-Apps/twa/issues/10\n  window.addEventListener('resize', () => {\n    const payload: ViewportChangedPayload = {\n      width: window.innerWidth,\n      height: window.innerHeight,\n      is_state_stable: true,\n      is_expanded: true,\n    };\n    emitter.emit('message', 'viewport_changed', payload);\n  });\n\n  return emitter;\n}","/**\n * Emits event sent from Telegram native application like it was sent in\n * default web environment between 2 iframes. It dispatches new MessageEvent\n * and expects it to be handled via `window.addEventListener('message', ...)`\n * as developer would do it to handle messages sent from parent iframe.\n * @param eventType - event name.\n * @param eventData - event payload.\n */\nfunction emitTelegramEvent(eventType: string, eventData: unknown): void {\n  window.dispatchEvent(new MessageEvent('message', {\n    data: JSON.stringify({eventType, eventData}),\n  }));\n}\n\n/**\n * Defines global event receiver, which handles events sent from native\n * Telegram application. As a result, this handler emits \"message\" event.\n */\nexport function defineEventsReceiver(): void {\n  const wnd = window as any;\n\n  // Iterate over each path, where \"receiveEvent\" function should be\n  // defined. This function is called by external environment in case,\n  // it wants to emit some event.\n  [\n    ['TelegramGameProxy_receiveEvent'], // Windows Phone.\n    ['TelegramGameProxy', 'receiveEvent'], // Desktop.\n    ['Telegram', 'WebView', 'receiveEvent'], // Android and iOS.\n  ].forEach(path => {\n    // Path starts from \"window\" object.\n    let pointer = wnd;\n\n    path.forEach((item, idx, arr) => {\n      // We are on the last iteration, where function property name is passed.\n      if (idx === arr.length - 1) {\n        pointer[item] = emitTelegramEvent;\n        return;\n      }\n\n      if (!(item in pointer)) {\n        pointer[item] = {};\n      }\n      pointer = pointer[item];\n    });\n  });\n}\n","import {EventEmitter, log, parseJsonValueAsString} from '@twa-dev/utils';\n\nimport {\n  parseClipboardTextReceivedPayload,\n  parseInvoiceClosedPayload,\n  parsePopupClosedPayload,\n  parseQrTextReceivedPayload,\n  parseThemeChangedPayload,\n  parseViewportChangedPayload,\n} from './parsing';\nimport {\n  PostEmptyEventName,\n  postEvent, PostEventName,\n  PostEventParams,\n  PostNonEmptyEventName,\n} from './posting';\nimport {createEventsObserver} from './events-observer';\nimport {BridgeEventName, BridgeEventsMap} from './listening';\nimport {defineEventsReceiver} from './events-receiver';\n\nexport interface BridgeProps {\n  /**\n   * Is debug mode currently enabled. Enable of this feature outputs additional\n   * log messages into console.\n   * @default false\n   */\n  debug?: boolean;\n\n  /**\n   * Origin used while posting message. This option is only used in case,\n   * current environment is browser (Web version of Telegram) and could\n   * be used for test purposes.\n   * @default 'https://web.telegram.org'\n   */\n  targetOrigin?: string;\n}\n\n/**\n * Provides special layer between parent device and current application.\n * @see How events work: https://telegram-web-apps.github.io/twa/docs/category/apps-communication\n */\nexport class Bridge {\n  /**\n   * Initializes default version of Bridge instance applying additional\n   * Bridge-required lifecycle logic. It is recommended to use this function\n   * instead of usual Bridge constructor to make sure, created instance will\n   * work appropriately.\n   * @param props - bridge properties.\n   */\n  static init(props: BridgeProps = {}): Bridge {\n    // Define event receiver to make sure, emitter will receive events.\n    defineEventsReceiver();\n\n    // Create Bridge instance.\n    const bridge = new Bridge(props);\n\n    // Create global events observer.\n    const observer = createEventsObserver();\n\n    // Start listening to incoming events from observer.\n    observer.on('message', bridge.processEvent);\n\n    return bridge;\n  }\n\n  private readonly targetOrigin: string;\n  private readonly ee = new EventEmitter<BridgeEventsMap>();\n\n  constructor(props: BridgeProps) {\n    const {debug = false, targetOrigin = 'https://web.telegram.org'} = props;\n    this.debug = debug;\n    this.targetOrigin = targetOrigin;\n  }\n\n  private emit: typeof this.ee.emit = (event: any, ...args: any[]) => {\n    this.log('log', 'Emitting event:', event, ...args);\n    this.ee.emit(event, ...args);\n  };\n\n  private log: typeof log = (level, ...args) => {\n    if (this.debug) {\n      log(level, '[Bridge]', ...args);\n    }\n  };\n\n  /**\n   * Prepares event data before passing it to listeners. Then, calls them.\n   * @param type - event name.\n   * @param data - event data.\n   * @throws {TypeError} Data has unexpected format for event.\n   */\n  private processEvent = (type: BridgeEventName | string, data: unknown): void => {\n    this.log('log', 'Received event from Telegram:', type, data);\n\n    try {\n      switch (type) {\n        case 'viewport_changed':\n          return this.emit(type, parseViewportChangedPayload(data));\n\n        case 'theme_changed':\n          return this.emit(type, parseThemeChangedPayload(data));\n\n        case 'popup_closed':\n          // FIXME: Payloads are different on different platforms.\n          //  Issue: https://github.com/Telegram-Web-Apps/twa/issues/2\n          if (\n            // Sent on desktop.\n            data === undefined ||\n            // Sent on iOS.\n            data === null\n          ) {\n            return this.emit(type, {});\n          }\n          return this.emit(type, parsePopupClosedPayload(data));\n\n        case 'set_custom_style':\n          return this.emit(type, parseJsonValueAsString(data));\n\n        case 'qr_text_received':\n          return this.emit(type, parseQrTextReceivedPayload(data));\n\n        // Events which do not require any arguments.\n        case 'main_button_pressed':\n        case 'back_button_pressed':\n        case 'settings_button_pressed':\n        case 'scan_qr_popup_closed':\n          return this.emit(type);\n\n        case 'clipboard_text_received':\n          return this.emit(type, parseClipboardTextReceivedPayload(data));\n\n        case 'invoice_closed':\n          return this.emit(type, parseInvoiceClosedPayload(data));\n\n        // All other event listeners will receive unknown type of data.\n        default:\n          return this.emit(type as any, data);\n      }\n    } catch (cause) {\n      this.log('error', `Error processing Telegram event:`, cause);\n    }\n  };\n\n  /**\n   * Is debug mode currently enabled. This value must be set by developer\n   * himself. In case, it is enabled, additional logs will appear in console.\n   */\n  debug: boolean;\n\n  /**\n   * Adds new event listener.\n   */\n  on = this.ee.on.bind(this.ee);\n\n  /**\n   * Removes event listener.\n   */\n  off = this.ee.off.bind(this.ee);\n\n  /**\n   * Sends event to native application which launched Web App. This function\n   * accepts only events, which require arguments.\n   * @param event - event name.\n   * @throws {Error} Bridge could not determine current\n   * environment and possible way to send event.\n   */\n  postEvent(event: PostEmptyEventName): void;\n\n  /**\n   * Sends event to native application which launched Web App. This function\n   * accepts only events, which require arguments.\n   * @param event - event name.\n   * @param params - event parameters.\n   * @throws {Error} Bridge could not determine current\n   * environment and possible way to send event.\n   */\n  postEvent<E extends PostNonEmptyEventName>(\n    event: E,\n    params: PostEventParams<E>,\n  ): void;\n\n  postEvent(event: PostEventName, params?: any) {\n    const options = {targetOrigin: this.targetOrigin};\n\n    if (params === undefined) {\n      postEvent(event as PostEmptyEventName, options);\n    } else {\n      postEvent(event as PostNonEmptyEventName, params, options);\n    }\n    this.log('log', 'Sending event to Telegram:', event, params);\n  }\n\n  /**\n   * Add listener for all events. It is triggered always, when `emit`\n   * function called.\n   */\n  subscribe: typeof this.ee.subscribe = this.ee.subscribe.bind(this.ee);\n\n  /**\n   * Removes listener added with `subscribe`.\n   */\n  unsubscribe: typeof this.ee.unsubscribe = this.ee.unsubscribe.bind(this.ee);\n}\n","import {PostEventName} from './posting';\nimport {compareVersions, Version} from '@twa-dev/utils';\n\n/**\n * Returns true in case, specified method is supported in passed version.\n * @param method - checked method.\n * @param inVersion - Web App version to check method support in.\n */\nexport function supports(method: PostEventName, inVersion: Version): boolean {\n  switch (method) {\n    case 'web_app_open_tg_link':\n    case 'web_app_open_invoice':\n    case 'web_app_setup_back_button':\n    case 'web_app_set_background_color':\n    case 'web_app_set_header_color':\n    case 'web_app_trigger_haptic_feedback':\n      return compareVersions('6.1', inVersion) <= 0;\n    case 'web_app_open_popup':\n      return compareVersions('6.2', inVersion) <= 0;\n    case 'web_app_close_scan_qr_popup':\n    case 'web_app_open_scan_qr_popup':\n    case 'web_app_read_text_from_clipboard':\n      return compareVersions('6.4', inVersion) <= 0;\n    default:\n      return true;\n  }\n}\n"],"names":["hasNotify","value","notify","hasExternal","isRecord","external","hasInvoke","invoke","isIframe","window","self","top","e","postEvent","eventType","paramsOrOptions","options","eventData","_options","undefined","targetOrigin","JSON","stringify","Error","parent","postMessage","parseThemeChangedPayload","createJsonParser","theme_params","bg_color","text_color","hint_color","link_color","button_color","button_text_color","secondary_bg_color","type","optional","parseRawViewportChangedPayload","height","width","parseJsonValueAsNumber","is_state_stable","is_expanded","parsePopupClosedPayload","button_id","parseJsonValueAsString","parseQrTextReceivedPayload","data","parseInvoiceClosedPayload","slug","status","parseClipboardTextReceivedPayload","req_id","parseMessageEventData","emitTelegramEvent","dispatchEvent","MessageEvent","Bridge","static","props","wnd","forEach","path","pointer","item","idx","arr","length","defineEventsReceiver","bridge","emitter","EventEmitter","addEventListener","event","emit","payload","innerWidth","innerHeight","createEventsObserver","on","processEvent","ee","constructor","debug","this","args","log","level","rest","parseViewportChangedPayload","cause","bind","off","params","subscribe","unsubscribe","method","inVersion","compareVersions"],"mappings":"6CAQM,SAAUA,EAAwBC,GACtC,MAAO,WAAYA,GAAiC,mBAAjBA,EAAMC,MAC3C,CAMM,SAAUC,EAA0BF,GACxC,MAAO,aAAcA,GAASG,EAAQA,SAACH,EAAMI,SAC/C,CAMM,SAAUC,EAAwBL,GACtC,MAAO,WAAYA,GAAiC,mBAAjBA,EAAMM,MAC3C,UAMgBC,IACd,IACE,OAAOC,OAAOC,OAASD,OAAOE,GAC/B,CAAC,MAAOC,GACP,OAAO,CACR,CACH,UCQgBC,EACdC,EACAC,EACAC,GAEA,IACIC,EADAC,EAA6B,CAAA,OAITC,IAApBJ,QAA6CI,IAAZH,EACnCE,EAAW,CAAA,OAGgBC,IAApBJ,QAA6CI,IAAZH,GACxCE,EAAWF,EACXC,EAAYF,QAGeI,IAApBJ,IACH,iBAAkBA,EACpBG,EAAWH,EAEXE,EAAYF,GAGhB,MAAMK,aAACA,EAAe,4BAA8BF,EAGpD,IAAIV,IAAJ,CASA,GAAIL,EAAYM,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