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N,WAAKF,EAAS,QAAQ,EAAE,MAAM,EAAG,EAAE,EAAE,QAASuC,GAAO,CACzDA,EAAG,OAAO,EACX,CACH,CACD,CACH,CAEA,GAAGpB,EAAQ,CACH,MAAAqB,EAAY,KAAK,MAAQ,IACzBC,EAAOrB,EAAW,QAAUoB,EAAY,MAAMvE,EAAU,SAAS,YAAY,sBAEnF,MAAMmE,EAAMK,EAAO3C,EAAiB,IAAMA,EAAiB,IAAM2C,EAAO,CAAC,CAC3E,QACMC,EAAK,CACX,OAAQA,EAAiB,KAAM,CAC7B,IAAK,0BACFA,EAAiB,QAAU,GACrB/B,EAAA,uCAAgB,2DAAE,KAAMC,GAAMA,EAAE,QAAQ,OAAO,EAC/CC,EAAA,GACS7C,EAAA,KAChB,MACF,QACU,cAAM,6BAA8B0E,CAAG,EACxC7B,EAAA,GACP,KACJ,CAEO,QACT,CAEO,UAKT,MAAO,UAAW,CACTA,EAAA,GAEJ,EAMD,IALGA,GAIe,MAAMK,EAAQ,EAAI,EAElC,YAEI,IAEZ,EAEA,IAAIlD,EACJ,MAAMiC,EAAO,IAAI0C,EAAK,cAAe,GAAM,IAClC3E,EACN,IAAM,CAEHA,IAAeA,EAAgB+B,EAAa,GAClC/B,EAAA,KAAM4E,GAAS,CACtBA,GAAA,CACN,EAED3E,EAAU,SAAS,gBAAgB,YAAY,YAAa,CAAC,EAAG,kBAAkB,CACpF,CAAC","names":["set","getLang","cachedPromise","rootScope","config","I18n","getLanguageChangeButton","appendTo","strings","backup","string","backupString","key","btnChangeLanguage","Button","loadFonts","attachClickEvent","e","cancelEvent","putPreloader","fixBase64String","str","toUrl","bytesToBase64","bytes","mod3","result","nLen","nUint24","nIdx","uint6ToBase64","nUint6","FETCH_INTERVAL","onFirstMount","imageDiv","page","preloader","inputWrapper","btnBack","container","h4","_i18n","helpList","li","i18n","__vitePreload","m","stop","QRCodeStyling","n","options","prevToken","iterate","isLoop","loginToken","App","authorization","bytesCmp","encoded","url","style","surfaceColor","textColor","primaryColor","logoUrl","res","text","textToSvgURL","qrCode","promise","pause","resolve","c","el","timestamp","diff","err","Page","func"],"ignoreList":[],"sources":["../src/components/languageChangeButton.ts","../src/helpers/fixBase64String.ts","../src/helpers/bytes/bytesToBase64.ts","../src/pages/pageSignQR.ts"],"sourcesContent":["/*\n * https://github.com/morethanwords/tweb\n * Copyright (C) 2019-2021 Eduard Kuzmenko\n * https://github.com/morethanwords/tweb/blob/master/LICENSE\n */\n\nimport cancelEvent from '../helpers/dom/cancelEvent';\nimport {attachClickEvent} from '../helpers/dom/clickEvent';\nimport loadFonts from '../helpers/dom/loadFonts';\nimport {Config, LangPackDifference, LangPackString} from '../layer';\nimport I18n, {LangPackKey} from '../lib/langPack';\nimport rootScope from '../lib/rootScope';\nimport Button from './button';\nimport {putPreloader} from './putPreloader';\n\nlet set = false;\n\nfunction getLang(): Promise<[Config.config, LangPackString[], LangPackDifference.langPackDifference]> {\n if(cachedPromise) return cachedPromise;\n return cachedPromise = rootScope.managers.apiManager.getConfig().then((config) => {\n if(config.suggested_lang_code !== I18n.lastRequestedLangCode) {\n // I18n.loadLangPack(config.suggested_lang_code);\n\n return Promise.all([\n config,\n I18n.getStrings(config.suggested_lang_code, ['Login.ContinueOnLanguage']),\n I18n.getCacheLangPack()\n ]);\n } else {\n return [] as any;\n }\n });\n}\n\nlet cachedPromise: ReturnType;\n\nexport default function getLanguageChangeButton(appendTo: HTMLElement) {\n if(set) return;\n getLang().then(([config, strings]) => {\n if(!config) {\n return;\n }\n\n const backup: LangPackString[] = [];\n strings.forEach((string) => {\n const backupString = I18n.strings.get(string.key as LangPackKey);\n if(!backupString) {\n return;\n }\n\n backup.push(backupString);\n I18n.strings.set(string.key as LangPackKey, string);\n });\n\n const key: LangPackKey = 'Login.ContinueOnLanguage';\n const btnChangeLanguage = Button('btn-primary btn-secondary btn-primary-transparent primary', {text: key});\n btnChangeLanguage.lastElementChild.classList.remove('i18n'); // prevent changing language\n loadFonts({text: [I18n.format(key, true)]}).then(() => {\n window.requestAnimationFrame(() => {\n appendTo.append(btnChangeLanguage);\n });\n });\n\n rootScope.addEventListener('language_change', () => {\n btnChangeLanguage.remove();\n }, {once: true});\n\n backup.forEach((string) => {\n I18n.strings.set(string.key as LangPackKey, string);\n });\n\n attachClickEvent(btnChangeLanguage, (e) => {\n cancelEvent(e);\n\n set = true;\n\n btnChangeLanguage.disabled = true;\n putPreloader(btnChangeLanguage);\n\n I18n.getLangPack(config.suggested_lang_code);\n });\n });\n}\n","export default function fixBase64String(str: string, toUrl: boolean) {\n if(toUrl) {\n return str.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/\\=+$/, '');\n } else {\n return str.replace(/-/g, '+').replace(/_/g, '/');\n }\n}\n","export default function bytesToBase64(bytes: number[] | Uint8Array) {\n let mod3: number;\n let result = '';\n\n for(let nLen = bytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; ++nIdx) {\n mod3 = nIdx % 3;\n nUint24 |= bytes[nIdx] << (16 >>> mod3 & 24);\n if(mod3 === 2 || nLen - nIdx === 1) {\n result += String.fromCharCode(\n uint6ToBase64(nUint24 >>> 18 & 63),\n uint6ToBase64(nUint24 >>> 12 & 63),\n uint6ToBase64(nUint24 >>> 6 & 63),\n uint6ToBase64(nUint24 & 63)\n );\n nUint24 = 0;\n }\n }\n\n return result.replace(/A(?=A$|$)/g, '=');\n}\n\nexport function uint6ToBase64(nUint6: number) {\n return nUint6 < 26 ?\n nUint6 + 65 :\n nUint6 < 52 ?\n nUint6 + 71 :\n nUint6 < 62 ?\n nUint6 - 4 :\n nUint6 === 62 ?\n 43 :\n nUint6 === 63 ?\n 47 :\n 65;\n}\n","/*\n * https://github.com/morethanwords/tweb\n * Copyright (C) 2019-2021 Eduard Kuzmenko\n * https://github.com/morethanwords/tweb/blob/master/LICENSE\n */\n\nimport type {DcId} from '../types';\nimport Page from './page';\nimport {AuthAuthorization, AuthLoginToken} from '../layer';\nimport App from '../config/app';\nimport Button from '../components/button';\nimport {_i18n, i18n, LangPackKey} from '../lib/langPack';\nimport rootScope from '../lib/rootScope';\nimport {putPreloader} from '../components/putPreloader';\nimport getLanguageChangeButton from '../components/languageChangeButton';\nimport pause from '../helpers/schedulers/pause';\nimport fixBase64String from '../helpers/fixBase64String';\nimport bytesCmp from '../helpers/bytes/bytesCmp';\nimport bytesToBase64 from '../helpers/bytes/bytesToBase64';\nimport textToSvgURL from '../helpers/textToSvgURL';\n\nconst FETCH_INTERVAL = 3;\n\nconst onFirstMount = async() => {\n const pageElement = page.pageEl;\n const imageDiv = pageElement.querySelector('.auth-image') as HTMLDivElement;\n\n let preloader = putPreloader(imageDiv, true);\n\n const inputWrapper = document.createElement('div');\n inputWrapper.classList.add('input-wrapper');\n\n const btnBack = Button('btn-primary btn-secondary btn-primary-transparent primary', {text: 'Login.QR.Cancel'});\n inputWrapper.append(btnBack);\n\n getLanguageChangeButton(inputWrapper);\n\n const container = imageDiv.parentElement;\n\n const h4 = document.createElement('h4');\n _i18n(h4, 'Login.QR.Title');\n\n const helpList = document.createElement('ol');\n helpList.classList.add('qr-description');\n (['Login.QR.Help1', 'Login.QR.Help2', 'Login.QR.Help3'] as LangPackKey[]).forEach((key) => {\n const li = document.createElement('li');\n li.append(i18n(key));\n helpList.append(li);\n });\n\n container.append(h4, helpList, inputWrapper);\n\n btnBack.addEventListener('click', () => {\n import('./pageSignIn').then((m) => m.default.mount());\n stop = true;\n });\n\n const results = await Promise.all([\n import('qr-code-styling' as any)\n ]);\n const QRCodeStyling = results[0].default;\n\n let stop = false;\n rootScope.addEventListener('user_auth', () => {\n stop = true;\n cachedPromise = null;\n }, {once: true});\n\n const options: {dcId?: DcId, ignoreErrors: true} = {ignoreErrors: true};\n let prevToken: Uint8Array | number[];\n\n const iterate = async(isLoop: boolean) => {\n try {\n let loginToken = await rootScope.managers.apiManager.invokeApi('auth.exportLoginToken', {\n api_id: App.id,\n api_hash: App.hash,\n except_ids: []\n }, {ignoreErrors: true});\n\n if(loginToken._ === 'auth.loginTokenMigrateTo') {\n if(!options.dcId) {\n options.dcId = loginToken.dc_id as DcId;\n rootScope.managers.apiManager.setBaseDcId(loginToken.dc_id);\n // continue;\n }\n\n loginToken = await rootScope.managers.apiManager.invokeApi('auth.importLoginToken', {\n token: loginToken.token\n }, options) as AuthLoginToken.authLoginToken;\n }\n\n if(loginToken._ === 'auth.loginTokenSuccess') {\n const authorization = loginToken.authorization as any as AuthAuthorization.authAuthorization;\n await rootScope.managers.apiManager.setUser(authorization.user);\n import('./pageIm').then((m) => m.default.mount());\n return true;\n }\n\n /* // to base64\n var decoder = new TextDecoder('utf8');\n var b64encoded = btoa(String.fromCharCode.apply(null, [...loginToken.token])); */\n\n if(!prevToken || !bytesCmp(prevToken, loginToken.token)) {\n prevToken = loginToken.token;\n\n const encoded = bytesToBase64(loginToken.token);\n const url = 'tg://login?token=' + fixBase64String(encoded, true);\n\n const style = window.getComputedStyle(document.documentElement);\n const surfaceColor = style.getPropertyValue('--surface-color').trim();\n const textColor = style.getPropertyValue('--primary-text-color').trim();\n const primaryColor = style.getPropertyValue('--primary-color').trim();\n\n const logoUrl = await fetch('assets/img/logo_padded.svg')\n .then((res) => res.text())\n .then((text) => {\n text = text.replace(/(fill:).+?(;)/, `$1${primaryColor}$2`);\n return textToSvgURL(text);\n });\n\n const qrCode = new QRCodeStyling({\n width: 240 * window.devicePixelRatio,\n height: 240 * window.devicePixelRatio,\n data: url,\n image: logoUrl,\n dotsOptions: {\n color: textColor,\n type: 'rounded'\n },\n cornersSquareOptions: {\n type: 'extra-rounded'\n },\n imageOptions: {\n imageSize: 1,\n margin: 0\n },\n backgroundOptions: {\n color: surfaceColor\n },\n qrOptions: {\n errorCorrectionLevel: 'L'\n }\n });\n\n qrCode.append(imageDiv);\n (imageDiv.lastChild as HTMLCanvasElement).classList.add('qr-canvas');\n\n let promise: Promise;\n if(qrCode._drawingPromise) {\n promise = qrCode._drawingPromise;\n } else {\n promise = Promise.race([\n pause(1000),\n new Promise((resolve) => {\n qrCode._canvas._image.addEventListener('load', () => {\n window.requestAnimationFrame(() => resolve());\n }, {once: true});\n })\n ]);\n }\n\n // * это костыль, но библиотека не предоставляет никаких событий\n await promise.then(() => {\n if(preloader) {\n preloader.style.animation = 'hide-icon .4s forwards';\n\n const c = imageDiv.children[1] as HTMLElement;\n c.style.display = 'none';\n c.style.animation = 'grow-icon .4s forwards';\n setTimeout(() => {\n c.style.display = '';\n }, 150);\n\n setTimeout(() => {\n c.style.animation = '';\n }, 500);\n preloader = undefined;\n } else {\n Array.from(imageDiv.children).slice(0, -1).forEach((el) => {\n el.remove();\n });\n }\n });\n }\n\n if(isLoop) {\n const timestamp = Date.now() / 1000;\n const diff = loginToken.expires - timestamp - await rootScope.managers.timeManager.getServerTimeOffset();\n\n await pause(diff > FETCH_INTERVAL ? 1e3 * FETCH_INTERVAL : 1e3 * diff | 0);\n }\n } catch(err) {\n switch((err as ApiError).type) {\n case 'SESSION_PASSWORD_NEEDED':\n (err as ApiError).handled = true;\n import('./pagePassword').then((m) => m.default.mount());\n stop = true;\n cachedPromise = null;\n break;\n default:\n console.error('pageSignQR: default error:', err);\n stop = true;\n break;\n }\n\n return true;\n }\n\n return false;\n };\n\n // await iterate(false);\n\n return async() => {\n stop = false;\n\n do {\n if(stop) {\n break;\n }\n\n const needBreak = await iterate(true);\n if(needBreak) {\n break;\n }\n } while(true);\n };\n};\n\nlet cachedPromise: Promise<() => Promise>;\nconst page = new Page('page-signQR', true, () => {\n return cachedPromise;\n}, () => {\n // console.log('onMount');\n if(!cachedPromise) cachedPromise = onFirstMount();\n cachedPromise.then((func) => {\n func();\n });\n\n rootScope.managers.appStateManager.pushToState('authState', {_: 'authStateSignQr'});\n});\n\nexport default page;\n"],"file":"pageSignQR-CySVYV_Q.js"}