| 1 | // A stand-in for TelegramWidget per docs/sdk-v1.md, injected only when build.ts |
| 2 | // renders the client-SDK group (visual/sdk) natively for its reference pictures: |
| 3 | // the widgets then show their "SDK present" state. It checks arguments as the |
| 4 | // contract says and does nothing else (no dialogs, no haptics). The palette is a |
| 5 |
| 6 | // window.__conformanceNoSdk (the visual set's pictures) it sets only the palette |
| 7 | // variables, and no TelegramWidget. The bubble's colour is the page's canvas, which |
| 8 | // build.ts sets outside the document, so a widget's body background still reaches |
| 9 | // the whole picture as on every client. |
| 10 | (function () { |
| 11 | var P = { |
| 12 | light: { bg_color: '#ffffff', text_color: '#000000', hint_color: '#707579', link_color: '#3390ec', button_color: '#3390ec', button_text_color: '#ffffff', secondary_bg_color: '#f4f4f5', accent_text_color: '#3390ec', subtitle_text_color: '#707579', destructive_text_color: '#e53935', section_bg_color: '#ffffff', section_header_text_color: '#3390ec', section_separator_color: '#e7e7e7', header_bg_color: '#ffffff', bottom_bar_bg_color: '#ffffff' }, |
| 13 | dark: { bg_color: '#212121', text_color: '#ffffff', hint_color: '#aaaaaa', link_color: '#8774e1', button_color: '#8774e1', button_text_color: '#ffffff', secondary_bg_color: '#181818', accent_text_color: '#8774e1', subtitle_text_color: '#aaaaaa', destructive_text_color: '#ff595a', section_bg_color: '#212121', section_header_text_color: '#8774e1', section_separator_color: '#3d3d3d', header_bg_color: '#212121', bottom_bar_bg_color: '#212121' }, |
| 14 | }; |
| 15 | var scheme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; |
| 16 | var params = Object.freeze(P[scheme]); |
| 17 | for (var k in params) document.documentElement.style.setProperty('--tg-theme-' + k.replace(/_/g, '-'), params[k]); |
| 18 | document.documentElement.style.setProperty('--tg-color-scheme', scheme); |
| 19 | if (window.__conformanceNoSdk) return; |
| 20 | // Subdomains count too (durov.t.me), as in the framework. |
| 21 | var TG = /^([a-z0-9-]+\.)*(t\.me|telegram\.me|telegram\.dog)$/i; |
| 22 | function url(u, telegram) { |
| 23 | if (typeof u !== 'string' || u.length > 256) throw new TypeError('URL must be a string of at most 256 characters'); |
| 24 | var m = /^https:\/\/([^/?#@]+)(?:[/?#]|$)/i.exec(u); |
| 25 | if (!m || /@/.test(u.split(/[/?#]/)[2] || '')) throw new TypeError('URL must be an absolute https URL without user info'); |
| 26 | if (TG.test(m[1]) !== telegram) throw new TypeError(telegram ? 'openTelegramLink takes t.me links' : 'openLink does not take t.me links'); |
| 27 | } |
| 28 | var M = window.__conformanceMessage || {}; |
| 29 | var H = {}; |
| 30 | var check = function (v, list) { if (list.indexOf(v) < 0) throw new TypeError('unknown haptic ' + v); return H; }; |
| 31 | H.impactOccurred = function (s) { return check(s, ['light', 'medium', 'heavy', 'rigid', 'soft']); }; |
| 32 | H.notificationOccurred = function (t) { return check(t, ['error', 'success', 'warning']); }; |
| 33 | H.selectionChanged = function () { return H; }; |
| 34 | window.TelegramWidget = { |
| 35 | profile: 1, isProfileAtLeast: function (n) { return typeof n === 'number' && n <= 1; }, |
| 36 | colorScheme: scheme, theme: scheme, themeParams: params, isActive: true, |
| 37 | onEvent: function () {}, offEvent: function () {}, onTheme: function (cb) { if (typeof cb === 'function') cb(scheme); }, ready: function () {}, |
| 38 | openLink: function (u) { url(u, false); }, openTelegramLink: function (u) { url(u, true); }, |
| 39 | HapticFeedback: H, |
| 40 | setResizeAnchor: function (e) { if (e !== 'top' && e !== 'bottom') throw new TypeError("setResizeAnchor: edge must be 'top' or 'bottom'"); }, |
| 41 | // The widget's state and the message context, from the header's first message spec (build.ts sets |
| 42 | // __conformanceMessage): the original as the tester first sees it, a viewer when the message may ask. |
| 43 | chatData: M.forward ? null : M.chat_data !== undefined ? M.chat_data : null, |
| 44 | publicData: M.public_data !== undefined ? M.public_data : null, |
| 45 | isForward: !!M.forward, |
| 46 | isPreview: !!M.inline, |
| 47 | chatType: M.forward || M.inline ? null : M.chat === 'group' ? 'supergroup' : 'private', |
| 48 | viewer: M.allow_queries && !M.inline ? Object.freeze({ id: 1001, first_name: 'Ann', last_name: 'Lee', username: 'ann_lee' }) : null, |
| 49 | // Checked as the contract says; a request never settles here, so the pictures show the state before any answer. |
| 50 | request: function (d) { if (typeof d !== 'string' || !d || unescape(encodeURIComponent(d)).length > 64) throw new TypeError('request: data must be 1-64 bytes of text'); return new Promise(function () {}); }, |
| 51 | copyText: function (t) { if (typeof t !== 'string' || !t || t.length > 256) throw new TypeError('copyText: text must be 1-256 characters'); }, |
| 52 | watchPublicData: function () {}, unwatchPublicData: function () {}, |
| 53 | }; |
| 54 | })(); |
| 55 |