@tma.js/sdk 1.4.3 → 1.4.6

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.
Files changed (283) hide show
  1. package/README.md +2 -2
  2. package/dist/dts/bridge/events/events.d.ts +16 -16
  3. package/dist/dts/bridge/methods/methods.d.ts +27 -27
  4. package/dist/dts/bridge/methods/popup.d.ts +1 -1
  5. package/dist/dts/{init/css → css}/bindMiniAppCSSVars.d.ts +2 -2
  6. package/dist/dts/{init/css → css}/bindThemeCSSVars.d.ts +1 -1
  7. package/dist/dts/{init/css → css}/bindViewportCSSVars.d.ts +1 -1
  8. package/dist/dts/css/index.d.ts +4 -0
  9. package/dist/dts/index.d.ts +1 -0
  10. package/dist/dts/init-data/types.d.ts +3 -3
  11. package/dist/dts/launch-params/types.d.ts +1 -1
  12. package/dist/dts/theme-params/types.d.ts +1 -1
  13. package/dist/index.cjs +1 -2
  14. package/dist/index.iife.js +1 -2
  15. package/dist/index.mjs +126 -115
  16. package/package.json +2 -3
  17. package/dist/index.cjs.map +0 -1
  18. package/dist/index.iife.js.map +0 -1
  19. package/dist/index.mjs.map +0 -1
  20. package/src/__tests__/globals.ts +0 -39
  21. package/src/back-button/BackButton.ts +0 -90
  22. package/src/back-button/__tests__/BackButton.ts +0 -129
  23. package/src/back-button/index.ts +0 -2
  24. package/src/back-button/types.ts +0 -14
  25. package/src/bridge/__tests__/parseMessage.ts +0 -23
  26. package/src/bridge/__tests__/request.ts +0 -236
  27. package/src/bridge/env/__tests__/hasExternalNotify.ts +0 -15
  28. package/src/bridge/env/__tests__/hasWebviewProxy.ts +0 -15
  29. package/src/bridge/env/__tests__/isIframe.ts +0 -30
  30. package/src/bridge/env/hasExternalNotify.ts +0 -19
  31. package/src/bridge/env/hasWebviewProxy.ts +0 -19
  32. package/src/bridge/env/index.ts +0 -3
  33. package/src/bridge/env/isIframe.ts +0 -11
  34. package/src/bridge/errors/MethodUnsupportedError.ts +0 -13
  35. package/src/bridge/errors/ParameterUnsupportedError.ts +0 -13
  36. package/src/bridge/errors/index.ts +0 -2
  37. package/src/bridge/events/__tests__/createEmitter.ts +0 -143
  38. package/src/bridge/events/__tests__/off.ts +0 -34
  39. package/src/bridge/events/__tests__/on.ts +0 -49
  40. package/src/bridge/events/__tests__/onTelegramEvent.ts +0 -49
  41. package/src/bridge/events/__tests__/once.ts +0 -64
  42. package/src/bridge/events/__tests__/singletonEmitter.ts +0 -22
  43. package/src/bridge/events/__tests__/subscribe.ts +0 -49
  44. package/src/bridge/events/__tests__/unsubscribe.ts +0 -34
  45. package/src/bridge/events/createEmitter.ts +0 -108
  46. package/src/bridge/events/events.ts +0 -170
  47. package/src/bridge/events/index.ts +0 -9
  48. package/src/bridge/events/off.ts +0 -14
  49. package/src/bridge/events/on.ts +0 -19
  50. package/src/bridge/events/onTelegramEvent.ts +0 -81
  51. package/src/bridge/events/once.ts +0 -18
  52. package/src/bridge/events/parsers/__tests__/clipboardTextReceived.ts +0 -21
  53. package/src/bridge/events/parsers/__tests__/invoiceClosed.ts +0 -12
  54. package/src/bridge/events/parsers/__tests__/popupClosed.ts +0 -10
  55. package/src/bridge/events/parsers/__tests__/qrTextReceived.ts +0 -9
  56. package/src/bridge/events/parsers/__tests__/theme-changed.ts +0 -42
  57. package/src/bridge/events/parsers/__tests__/viewportChanged.ts +0 -49
  58. package/src/bridge/events/parsers/clipboardTextReceived.ts +0 -26
  59. package/src/bridge/events/parsers/customMethodInvoked.ts +0 -25
  60. package/src/bridge/events/parsers/index.ts +0 -9
  61. package/src/bridge/events/parsers/invoiceClosed.ts +0 -26
  62. package/src/bridge/events/parsers/phoneRequested.ts +0 -14
  63. package/src/bridge/events/parsers/popupClosed.ts +0 -19
  64. package/src/bridge/events/parsers/qrTextReceived.ts +0 -14
  65. package/src/bridge/events/parsers/theme-changed.ts +0 -58
  66. package/src/bridge/events/parsers/viewportChanged.ts +0 -33
  67. package/src/bridge/events/parsers/writeAccessRequested.ts +0 -14
  68. package/src/bridge/events/singletonEmitter.ts +0 -19
  69. package/src/bridge/events/subscribe.ts +0 -15
  70. package/src/bridge/events/unsubscribe.ts +0 -10
  71. package/src/bridge/index.ts +0 -7
  72. package/src/bridge/invokeCustomMethod.ts +0 -56
  73. package/src/bridge/methods/__tests__/createPostEvent.ts +0 -37
  74. package/src/bridge/methods/__tests__/postEvent.ts +0 -137
  75. package/src/bridge/methods/createPostEvent.ts +0 -40
  76. package/src/bridge/methods/custom-methods.ts +0 -68
  77. package/src/bridge/methods/haptic.ts +0 -52
  78. package/src/bridge/methods/index.ts +0 -6
  79. package/src/bridge/methods/methods.ts +0 -370
  80. package/src/bridge/methods/popup.ts +0 -53
  81. package/src/bridge/methods/postEvent.ts +0 -101
  82. package/src/bridge/parseMessage.ts +0 -28
  83. package/src/bridge/request.ts +0 -176
  84. package/src/classnames/__tests__/classNames.ts +0 -20
  85. package/src/classnames/__tests__/mergeClassNames.ts +0 -21
  86. package/src/classnames/classNames.ts +0 -34
  87. package/src/classnames/index.ts +0 -2
  88. package/src/classnames/mergeClassNames.ts +0 -60
  89. package/src/closing-behavior/ClosingBehavior.ts +0 -64
  90. package/src/closing-behavior/__tests__/ClosingBehavior.ts +0 -86
  91. package/src/closing-behavior/index.ts +0 -2
  92. package/src/closing-behavior/types.ts +0 -12
  93. package/src/cloud-storage/CloudStorage.ts +0 -138
  94. package/src/cloud-storage/index.ts +0 -1
  95. package/src/colors/__tests__/isColorDark.ts +0 -12
  96. package/src/colors/__tests__/isRGB.ts +0 -13
  97. package/src/colors/__tests__/isRGBShort.ts +0 -13
  98. package/src/colors/__tests__/toRGB.ts +0 -23
  99. package/src/colors/index.ts +0 -5
  100. package/src/colors/isColorDark.ts +0 -22
  101. package/src/colors/isRGB.ts +0 -9
  102. package/src/colors/isRGBShort.ts +0 -9
  103. package/src/colors/toRGB.ts +0 -49
  104. package/src/colors/types.ts +0 -9
  105. package/src/event-emitter/EventEmitter.ts +0 -146
  106. package/src/event-emitter/__tests__/EventEmitter.ts +0 -145
  107. package/src/event-emitter/index.ts +0 -2
  108. package/src/event-emitter/types.ts +0 -60
  109. package/src/globals.ts +0 -38
  110. package/src/haptic-feedback/HapticFeedback.ts +0 -70
  111. package/src/haptic-feedback/__tests__/HapticFeedback.ts +0 -68
  112. package/src/haptic-feedback/index.ts +0 -1
  113. package/src/index.ts +0 -179
  114. package/src/init/catchCustomStyles.ts +0 -17
  115. package/src/init/creators/__tests__/createViewport.ts +0 -96
  116. package/src/init/creators/createBackButton.ts +0 -25
  117. package/src/init/creators/createClosingBehavior.ts +0 -24
  118. package/src/init/creators/createMainButton.ts +0 -51
  119. package/src/init/creators/createMiniApp.ts +0 -48
  120. package/src/init/creators/createRequestIdGenerator.ts +0 -13
  121. package/src/init/creators/createSettingsButton.ts +0 -25
  122. package/src/init/creators/createThemeParams.ts +0 -11
  123. package/src/init/creators/createViewport.ts +0 -94
  124. package/src/init/creators/index.ts +0 -8
  125. package/src/init/css/bindMiniAppCSSVars.ts +0 -48
  126. package/src/init/css/bindThemeCSSVars.ts +0 -31
  127. package/src/init/css/bindViewportCSSVars.ts +0 -36
  128. package/src/init/css/index.ts +0 -1
  129. package/src/init/css/processCSSVarsOption.ts +0 -57
  130. package/src/init/css/setCSSVar.ts +0 -8
  131. package/src/init/index.ts +0 -2
  132. package/src/init/init.ts +0 -134
  133. package/src/init/types.ts +0 -94
  134. package/src/init-data/InitData.ts +0 -96
  135. package/src/init-data/__tests__/InitData.ts +0 -98
  136. package/src/init-data/__tests__/chatParser.ts +0 -102
  137. package/src/init-data/__tests__/initDataParser.ts +0 -136
  138. package/src/init-data/__tests__/parseInitData.ts +0 -136
  139. package/src/init-data/__tests__/userParser.ts +0 -96
  140. package/src/init-data/chatParser.ts +0 -19
  141. package/src/init-data/index.ts +0 -6
  142. package/src/init-data/initDataParser.ts +0 -41
  143. package/src/init-data/parseInitData.ts +0 -10
  144. package/src/init-data/types.ts +0 -164
  145. package/src/init-data/userParser.ts +0 -45
  146. package/src/invoice/Invoice.ts +0 -123
  147. package/src/invoice/index.ts +0 -2
  148. package/src/invoice/types.ts +0 -11
  149. package/src/launch-params/__tests__/retrieveFromUrl.ts +0 -19
  150. package/src/launch-params/computeLaunchData.ts +0 -81
  151. package/src/launch-params/computePageReload.ts +0 -13
  152. package/src/launch-params/getFirstNavigationEntry.ts +0 -10
  153. package/src/launch-params/index.ts +0 -13
  154. package/src/launch-params/launchParamsParser.ts +0 -45
  155. package/src/launch-params/parseLaunchParams.ts +0 -10
  156. package/src/launch-params/retrieveCurrent.ts +0 -27
  157. package/src/launch-params/retrieveFromLocation.ts +0 -10
  158. package/src/launch-params/retrieveFromPerformance.ts +0 -18
  159. package/src/launch-params/retrieveFromUrl.ts +0 -19
  160. package/src/launch-params/retrieveLaunchData.ts +0 -30
  161. package/src/launch-params/serializeLaunchParams.ts +0 -37
  162. package/src/launch-params/storage.ts +0 -33
  163. package/src/launch-params/types.ts +0 -62
  164. package/src/logger/Logger.ts +0 -72
  165. package/src/logger/__tests__/Logger.ts +0 -107
  166. package/src/logger/index.ts +0 -1
  167. package/src/main-button/MainButton.ts +0 -239
  168. package/src/main-button/__tests__/MainButton.ts +0 -346
  169. package/src/main-button/index.ts +0 -2
  170. package/src/main-button/types.ts +0 -26
  171. package/src/mini-app/MiniApp.ts +0 -348
  172. package/src/mini-app/__tests__/MiniApp.ts +0 -140
  173. package/src/mini-app/contactParser.ts +0 -29
  174. package/src/mini-app/index.ts +0 -2
  175. package/src/mini-app/types.ts +0 -38
  176. package/src/misc/__tests__/isRecord.ts +0 -21
  177. package/src/misc/index.ts +0 -2
  178. package/src/misc/isRecord.ts +0 -7
  179. package/src/misc/isTMA.ts +0 -13
  180. package/src/navigation/HashNavigator/HashNavigator.ts +0 -220
  181. package/src/navigation/HashNavigator/__tests__/HashNavigator.ts +0 -144
  182. package/src/navigation/HashNavigator/__tests__/drop.ts +0 -42
  183. package/src/navigation/HashNavigator/__tests__/go.ts +0 -9
  184. package/src/navigation/HashNavigator/drop.ts +0 -36
  185. package/src/navigation/HashNavigator/go.ts +0 -28
  186. package/src/navigation/HashNavigator/index.ts +0 -2
  187. package/src/navigation/HashNavigator/types.ts +0 -41
  188. package/src/navigation/Navigator/Navigator.ts +0 -282
  189. package/src/navigation/Navigator/index.ts +0 -2
  190. package/src/navigation/Navigator/types.ts +0 -55
  191. package/src/navigation/ensurePrefix.ts +0 -9
  192. package/src/navigation/getHash.ts +0 -17
  193. package/src/navigation/index.ts +0 -4
  194. package/src/parsing/ArrayValueParser.ts +0 -79
  195. package/src/parsing/ParseError.ts +0 -27
  196. package/src/parsing/ParseSchemaFieldError.ts +0 -21
  197. package/src/parsing/ValueParser.ts +0 -71
  198. package/src/parsing/__tests__/ArrayValueParser.ts +0 -18
  199. package/src/parsing/__tests__/toRecord.ts +0 -10
  200. package/src/parsing/createValueParserGenerator.ts +0 -16
  201. package/src/parsing/index.ts +0 -10
  202. package/src/parsing/parseBySchema.ts +0 -65
  203. package/src/parsing/parsers/__tests__/array.ts +0 -39
  204. package/src/parsing/parsers/__tests__/boolean.ts +0 -31
  205. package/src/parsing/parsers/__tests__/date.ts +0 -25
  206. package/src/parsing/parsers/__tests__/json.ts +0 -80
  207. package/src/parsing/parsers/__tests__/number.ts +0 -23
  208. package/src/parsing/parsers/__tests__/rgb.ts +0 -22
  209. package/src/parsing/parsers/__tests__/searchParams.ts +0 -105
  210. package/src/parsing/parsers/__tests__/string.ts +0 -25
  211. package/src/parsing/parsers/array.ts +0 -9
  212. package/src/parsing/parsers/boolean.ts +0 -22
  213. package/src/parsing/parsers/date.ts +0 -11
  214. package/src/parsing/parsers/index.ts +0 -8
  215. package/src/parsing/parsers/json.ts +0 -17
  216. package/src/parsing/parsers/number.ts +0 -21
  217. package/src/parsing/parsers/rgb.ts +0 -10
  218. package/src/parsing/parsers/searchParams.ts +0 -24
  219. package/src/parsing/parsers/string.ts +0 -12
  220. package/src/parsing/toRecord.ts +0 -27
  221. package/src/parsing/types.ts +0 -32
  222. package/src/parsing/unexpectedTypeError.ts +0 -6
  223. package/src/popup/Popup.ts +0 -91
  224. package/src/popup/__tests__/Popup.ts +0 -130
  225. package/src/popup/__tests__/preparePopupParams.ts +0 -85
  226. package/src/popup/index.ts +0 -2
  227. package/src/popup/preparePopupParams.ts +0 -59
  228. package/src/popup/types.ts +0 -69
  229. package/src/qr-scanner/QRScanner.ts +0 -95
  230. package/src/qr-scanner/index.ts +0 -2
  231. package/src/qr-scanner/types.ts +0 -11
  232. package/src/settings-button/SettingsButton.ts +0 -85
  233. package/src/settings-button/index.ts +0 -2
  234. package/src/settings-button/types.ts +0 -15
  235. package/src/state/State.ts +0 -67
  236. package/src/state/index.ts +0 -2
  237. package/src/state/types.ts +0 -31
  238. package/src/storage.ts +0 -69
  239. package/src/supports/__tests__/supports.ts +0 -123
  240. package/src/supports/createSupportsFunc.ts +0 -18
  241. package/src/supports/createSupportsParamFunc.ts +0 -27
  242. package/src/supports/index.ts +0 -4
  243. package/src/supports/supports.ts +0 -84
  244. package/src/supports/types.ts +0 -1
  245. package/src/theme-params/ThemeParams.ts +0 -131
  246. package/src/theme-params/__tests__/keys.ts +0 -19
  247. package/src/theme-params/__tests__/parseThemeParams.ts +0 -29
  248. package/src/theme-params/__tests__/serializeThemeParams.ts +0 -29
  249. package/src/theme-params/__tests__/themeParamsParser.ts +0 -29
  250. package/src/theme-params/index.ts +0 -6
  251. package/src/theme-params/keys.ts +0 -24
  252. package/src/theme-params/parseThemeParams.ts +0 -10
  253. package/src/theme-params/requestThemeParams.ts +0 -13
  254. package/src/theme-params/serializeThemeParams.ts +0 -20
  255. package/src/theme-params/themeParamsParser.ts +0 -22
  256. package/src/theme-params/types.ts +0 -33
  257. package/src/timeout/TimeoutError.ts +0 -6
  258. package/src/timeout/__tests__/isTimeoutError.ts +0 -9
  259. package/src/timeout/__tests__/withTimeout.ts +0 -28
  260. package/src/timeout/index.ts +0 -4
  261. package/src/timeout/isTimeoutError.ts +0 -9
  262. package/src/timeout/sleep.ts +0 -10
  263. package/src/timeout/withTimeout.ts +0 -24
  264. package/src/types/index.ts +0 -4
  265. package/src/types/methods.ts +0 -18
  266. package/src/types/platform.ts +0 -14
  267. package/src/types/request-id.ts +0 -10
  268. package/src/types/utils.ts +0 -50
  269. package/src/utils/Utils.ts +0 -107
  270. package/src/utils/index.ts +0 -1
  271. package/src/version/__tests__/compareVersions.ts +0 -19
  272. package/src/version/compareVersions.ts +0 -28
  273. package/src/version/index.ts +0 -2
  274. package/src/version/types.ts +0 -4
  275. package/src/viewport/Viewport.ts +0 -171
  276. package/src/viewport/__tests__/isStableViewportPlatform.ts +0 -15
  277. package/src/viewport/__tests__/utils.ts +0 -12
  278. package/src/viewport/index.ts +0 -4
  279. package/src/viewport/isStableViewportPlatform.ts +0 -10
  280. package/src/viewport/requestViewport.ts +0 -23
  281. package/src/viewport/types.ts +0 -23
  282. package/src/viewport/utils.ts +0 -7
  283. /package/dist/dts/{init/css → css}/setCSSVar.d.ts +0 -0
package/dist/index.mjs CHANGED
@@ -4,11 +4,11 @@ var o = (r, t, e) => (It(r, typeof t != "symbol" ? t + "" : t, e), e);
4
4
  function R(r) {
5
5
  return typeof r == "object" && r !== null && !Array.isArray(r);
6
6
  }
7
- function ut() {
7
+ function ht() {
8
8
  return performance.getEntriesByType("navigation")[0] || null;
9
9
  }
10
10
  function Lt() {
11
- const r = ut();
11
+ const r = ht();
12
12
  return r ? r.type === "reload" : null;
13
13
  }
14
14
  function L() {
@@ -74,7 +74,7 @@ class j extends Error {
74
74
  super(`Unable to parse field "${t}"${s ? ` as ${s}` : ""}`, { cause: e }), Object.setPrototypeOf(this, j.prototype);
75
75
  }
76
76
  }
77
- function ht(r, t) {
77
+ function pt(r, t) {
78
78
  const e = {};
79
79
  for (const s in r) {
80
80
  const n = r[s];
@@ -122,7 +122,7 @@ const k = $((r) => {
122
122
  return t;
123
123
  }
124
124
  throw L();
125
- }, "number"), pt = $((r) => r instanceof Date ? r : new Date(q().parse(r) * 1e3), "Date");
125
+ }, "number"), lt = $((r) => r instanceof Date ? r : new Date(q().parse(r) * 1e3), "Date");
126
126
  function Y(r) {
127
127
  let t = r;
128
128
  if (typeof t == "string" && (t = JSON.parse(t)), typeof t != "object" || t === null || Array.isArray(t))
@@ -132,10 +132,10 @@ function Y(r) {
132
132
  function f(r, t) {
133
133
  return new z((e) => {
134
134
  const s = Y(e);
135
- return ht(r, (n) => s[n]);
135
+ return pt(r, (n) => s[n]);
136
136
  }, !1, t);
137
137
  }
138
- function lt(r) {
138
+ function X(r) {
139
139
  return /^#[\da-f]{6}$/i.test(r);
140
140
  }
141
141
  function Dt(r) {
@@ -143,7 +143,7 @@ function Dt(r) {
143
143
  }
144
144
  function dt(r) {
145
145
  const t = r.replace(/\s/g, "").toLowerCase();
146
- if (lt(t))
146
+ if (X(t))
147
147
  return t;
148
148
  if (Dt(t)) {
149
149
  let s = "#";
@@ -173,12 +173,12 @@ const u = $((r) => {
173
173
  return r.toString();
174
174
  throw L();
175
175
  }, "string"), gt = $((r) => dt(u().parse(r)), "rgb");
176
- function X(r, t) {
176
+ function tt(r, t) {
177
177
  return new z((e) => {
178
178
  if (typeof e != "string" && !(e instanceof URLSearchParams))
179
179
  throw L();
180
180
  const s = typeof e == "string" ? new URLSearchParams(e) : e;
181
- return ht(r, (n) => {
181
+ return pt(r, (n) => {
182
182
  const i = s.get(n);
183
183
  return i === null ? void 0 : i;
184
184
  });
@@ -269,7 +269,7 @@ class Nt {
269
269
  return this.initData.user;
270
270
  }
271
271
  }
272
- function rt() {
272
+ function st() {
273
273
  return f({
274
274
  addedToAttachmentMenu: {
275
275
  type: k().optional(),
@@ -308,9 +308,9 @@ function rt() {
308
308
  }, "User");
309
309
  }
310
310
  function wt() {
311
- return X({
311
+ return tt({
312
312
  authDate: {
313
- type: pt(),
313
+ type: lt(),
314
314
  from: "auth_date"
315
315
  },
316
316
  canSendAfter: {
@@ -331,12 +331,12 @@ function wt() {
331
331
  type: u().optional(),
332
332
  from: "query_id"
333
333
  },
334
- receiver: rt().optional(),
334
+ receiver: st().optional(),
335
335
  startParam: {
336
336
  type: u().optional(),
337
337
  from: "start_param"
338
338
  },
339
- user: rt().optional()
339
+ user: st().optional()
340
340
  }, "InitData");
341
341
  }
342
342
  function tr(r) {
@@ -577,7 +577,7 @@ class Mt {
577
577
  }
578
578
  }
579
579
  function mt() {
580
- return X({
580
+ return tt({
581
581
  botInline: {
582
582
  type: k().optional(),
583
583
  from: "tgWebAppBotInline"
@@ -623,7 +623,7 @@ function jt() {
623
623
  return yt(window.location.href);
624
624
  }
625
625
  function Ft() {
626
- const r = ut();
626
+ const r = ht();
627
627
  if (!r)
628
628
  throw new Error("Unable to get first navigation entry.");
629
629
  return yt(r.name);
@@ -687,13 +687,13 @@ function Yt() {
687
687
  };
688
688
  throw new Error("Unable to retrieve any launch parameters.");
689
689
  }
690
- const st = "tmajsLaunchData";
690
+ const nt = "tmajsLaunchData";
691
691
  function Ct() {
692
- const r = window[st];
692
+ const r = window[nt];
693
693
  if (r)
694
694
  return r;
695
695
  const t = Yt();
696
- return window[st] = t, Zt(t.launchParams), t;
696
+ return window[nt] = t, Zt(t.launchParams), t;
697
697
  }
698
698
  function rr() {
699
699
  try {
@@ -715,14 +715,14 @@ function vt() {
715
715
  return !0;
716
716
  }
717
717
  }
718
- class tt extends Error {
718
+ class et extends Error {
719
719
  constructor(t, e) {
720
- super(`Method "${t}" is unsupported in the Mini Apps version ${e}.`), Object.setPrototypeOf(this, tt.prototype);
720
+ super(`Method "${t}" is unsupported in the Mini Apps version ${e}.`), Object.setPrototypeOf(this, et.prototype);
721
721
  }
722
722
  }
723
- class et extends Error {
723
+ class rt extends Error {
724
724
  constructor(t, e, s) {
725
- super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this, et.prototype);
725
+ super(`Parameter "${e}" in method "${t}" is unsupported in the Mini Apps version ${s}.`), Object.setPrototypeOf(this, rt.prototype);
726
726
  }
727
727
  }
728
728
  class Pt {
@@ -1042,11 +1042,11 @@ function d(r, t, e) {
1042
1042
  function me(r) {
1043
1043
  return (t, e) => {
1044
1044
  if (!I(t, r))
1045
- throw new tt(t, r);
1045
+ throw new et(t, r);
1046
1046
  if (R(e)) {
1047
1047
  let s;
1048
1048
  if (t === "web_app_open_link" && "try_instant_view" in e ? s = "try_instant_view" : t === "web_app_set_header_color" && "color" in e && (s = "color"), s && !I(t, s, r))
1049
- throw new et(t, s, r);
1049
+ throw new rt(t, s, r);
1050
1050
  }
1051
1051
  return d(t, e);
1052
1052
  };
@@ -1152,13 +1152,13 @@ class Ce {
1152
1152
  this.isVisible = !0;
1153
1153
  }
1154
1154
  }
1155
- function nt(r, t) {
1155
+ function it(r, t) {
1156
1156
  return r + (r.length > 0 && t.length > 0 ? ` ${t}` : t);
1157
1157
  }
1158
1158
  function ve(...r) {
1159
1159
  return r.reduce((t, e) => {
1160
1160
  let s = "";
1161
- return typeof e == "string" ? s = e : typeof e == "object" && e !== null && (s = Object.entries(e).reduce((n, [i, a]) => a ? nt(n, i) : n, "")), nt(t, s);
1161
+ return typeof e == "string" ? s = e : typeof e == "object" && e !== null && (s = Object.entries(e).reduce((n, [i, a]) => a ? it(n, i) : n, "")), it(t, s);
1162
1162
  }, "");
1163
1163
  }
1164
1164
  function cr(...r) {
@@ -1206,7 +1206,7 @@ class Pe {
1206
1206
  this.isConfirmationNeeded = !0;
1207
1207
  }
1208
1208
  }
1209
- function it(r, t) {
1209
+ function ot(r, t) {
1210
1210
  return r.reduce((e, s) => (e[s] = t, e), {});
1211
1211
  }
1212
1212
  class ke {
@@ -1252,9 +1252,9 @@ class ke {
1252
1252
  async get(t, e = {}) {
1253
1253
  const s = Array.isArray(t) ? t : [t];
1254
1254
  if (s.length === 0)
1255
- return it(s, "");
1255
+ return ot(s, "");
1256
1256
  const n = f(
1257
- it(s, u())
1257
+ ot(s, u())
1258
1258
  ), i = await O(
1259
1259
  "getStorageValues",
1260
1260
  { keys: s },
@@ -1278,7 +1278,46 @@ class ke {
1278
1278
  );
1279
1279
  }
1280
1280
  }
1281
- class Se {
1281
+ function S(r, t) {
1282
+ document.documentElement.style.setProperty(r, t);
1283
+ }
1284
+ function Se(r, t) {
1285
+ const e = () => {
1286
+ S("--tg-background-color", r.backgroundColor);
1287
+ }, s = () => {
1288
+ const {
1289
+ backgroundColor: n,
1290
+ secondaryBackgroundColor: i
1291
+ } = t;
1292
+ if (X(r.headerColor)) {
1293
+ S("--tg-header-color", r.headerColor);
1294
+ return;
1295
+ }
1296
+ if (r.headerColor === "bg_color" && n) {
1297
+ S("--tg-header-color", n);
1298
+ return;
1299
+ }
1300
+ r.headerColor === "secondary_bg_color" && i && S("--tg-header-color", i);
1301
+ };
1302
+ t.on("change", s), r.on("change:backgroundColor", e), r.on("change:headerColor", s), e(), s();
1303
+ }
1304
+ function xe(r) {
1305
+ const t = () => {
1306
+ const e = r.getState();
1307
+ Object.entries(e).forEach(([s, n]) => {
1308
+ if (n) {
1309
+ const i = s.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
1310
+ S(`--tg-theme-${i}`, n);
1311
+ }
1312
+ });
1313
+ };
1314
+ r.on("change", t), t();
1315
+ }
1316
+ function at(r) {
1317
+ const t = () => S("--tg-viewport-height", `${r.height}px`), e = () => S("--tg-viewport-width", `${r.width}px`), s = () => S("--tg-viewport-stable-height", `${r.stableHeight}px`);
1318
+ r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", s), t(), e(), s();
1319
+ }
1320
+ class qe {
1282
1321
  constructor(t, e = d) {
1283
1322
  /**
1284
1323
  * Checks if specified method is supported by current component.
@@ -1324,7 +1363,7 @@ class Se {
1324
1363
  this.postEvent("web_app_trigger_haptic_feedback", { type: "selection_change" });
1325
1364
  }
1326
1365
  }
1327
- function xe() {
1366
+ function Ae() {
1328
1367
  const r = document.createElement("style");
1329
1368
  r.id = "telegram-custom-styles", document.head.appendChild(r), y("set_custom_style", (t) => {
1330
1369
  r.innerHTML = t;
@@ -1340,19 +1379,19 @@ function D(r) {
1340
1379
  const t = sessionStorage.getItem(qt(r));
1341
1380
  return t ? JSON.parse(t) : null;
1342
1381
  }
1343
- function qe(r, t, e) {
1382
+ function Ve(r, t, e) {
1344
1383
  const { isVisible: s = !1 } = r ? D("back-button") || {} : {}, n = new Ce(s, t, e);
1345
1384
  return n.on("change", () => {
1346
1385
  B("back-button", { isVisible: n.isVisible });
1347
1386
  }), n;
1348
1387
  }
1349
- function Ae(r, t) {
1388
+ function Re(r, t) {
1350
1389
  const { isConfirmationNeeded: e = !1 } = r ? D("closing-behavior") || {} : {}, s = new Pe(e, t);
1351
1390
  return s.on("change", () => B("closing-behavior", {
1352
1391
  isConfirmationNeeded: s.isConfirmationNeeded
1353
1392
  })), s;
1354
1393
  }
1355
- class Ve {
1394
+ class Ie {
1356
1395
  constructor(t) {
1357
1396
  o(this, "ee", new w());
1358
1397
  o(this, "state");
@@ -1517,7 +1556,7 @@ class Ve {
1517
1556
  return this.state.set(t), this.commit(), this;
1518
1557
  }
1519
1558
  }
1520
- function Re(r, t, e, s) {
1559
+ function Le(r, t, e, s) {
1521
1560
  const {
1522
1561
  backgroundColor: n = t,
1523
1562
  isEnabled: i = !1,
@@ -1525,7 +1564,7 @@ function Re(r, t, e, s) {
1525
1564
  isLoaderVisible: c = !1,
1526
1565
  textColor: p = e,
1527
1566
  text: h = ""
1528
- } = r ? D("main-button") || {} : {}, g = new Ve({
1567
+ } = r ? D("main-button") || {} : {}, g = new Ie({
1529
1568
  backgroundColor: n,
1530
1569
  isEnabled: i,
1531
1570
  isLoaderVisible: c,
@@ -1543,7 +1582,7 @@ function Re(r, t, e, s) {
1543
1582
  });
1544
1583
  return g.on("change", _), g;
1545
1584
  }
1546
- const Ie = X({
1585
+ const $e = tt({
1547
1586
  contact: f({
1548
1587
  userId: {
1549
1588
  type: q(),
@@ -1563,12 +1602,12 @@ const Ie = X({
1563
1602
  }
1564
1603
  }),
1565
1604
  authDate: {
1566
- type: pt(),
1605
+ type: lt(),
1567
1606
  from: "auth_date"
1568
1607
  },
1569
1608
  hash: u()
1570
1609
  });
1571
- class Le {
1610
+ class Te {
1572
1611
  constructor(t) {
1573
1612
  o(this, "ee", new w());
1574
1613
  o(this, "state");
@@ -1623,7 +1662,7 @@ class Le {
1623
1662
  postEvent: this.postEvent,
1624
1663
  timeout: 1e4
1625
1664
  }
1626
- ).then((t) => Ie.parse(t));
1665
+ ).then((t) => $e.parse(t));
1627
1666
  }
1628
1667
  /**
1629
1668
  * The Mini App background color.
@@ -1758,7 +1797,7 @@ class Le {
1758
1797
  * @param color - color key or RGB color.
1759
1798
  */
1760
1799
  setHeaderColor(t) {
1761
- this.postEvent("web_app_set_header_color", lt(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
1800
+ this.postEvent("web_app_set_header_color", X(t) ? { color: t } : { color_key: t }), this.state.set("headerColor", t);
1762
1801
  }
1763
1802
  /**
1764
1803
  * Updates current Mini App background color.
@@ -1786,11 +1825,11 @@ class Le {
1786
1825
  });
1787
1826
  }
1788
1827
  }
1789
- function $e(r, t, e, s, n, i) {
1828
+ function Be(r, t, e, s, n, i) {
1790
1829
  const {
1791
1830
  backgroundColor: a = t,
1792
1831
  headerColor: c = "bg_color"
1793
- } = r ? D("mini-app") || {} : {}, p = new Le({
1832
+ } = r ? D("mini-app") || {} : {}, p = new Te({
1794
1833
  headerColor: c,
1795
1834
  backgroundColor: a,
1796
1835
  version: e,
@@ -1803,11 +1842,11 @@ function $e(r, t, e, s, n, i) {
1803
1842
  });
1804
1843
  return p.on("change", h), p;
1805
1844
  }
1806
- function Te() {
1845
+ function De() {
1807
1846
  let r = 0;
1808
1847
  return () => (r += 1, r.toString());
1809
1848
  }
1810
- class Be {
1849
+ class We {
1811
1850
  constructor(t, e, s = d) {
1812
1851
  o(this, "ee", new w());
1813
1852
  o(this, "state");
@@ -1854,17 +1893,17 @@ class Be {
1854
1893
  this.isVisible = !0;
1855
1894
  }
1856
1895
  }
1857
- function De(r, t, e) {
1858
- const { isVisible: s = !1 } = r ? D("settings-button") || {} : {}, n = new Be(s, t, e);
1896
+ function Ne(r, t, e) {
1897
+ const { isVisible: s = !1 } = r ? D("settings-button") || {} : {}, n = new We(s, t, e);
1859
1898
  return n.on("change", () => {
1860
1899
  B("settings-button", { isVisible: n.isVisible });
1861
1900
  }), n;
1862
1901
  }
1863
- function We(r) {
1902
+ function Oe(r) {
1864
1903
  const t = new Mt(r);
1865
1904
  return t.listen(), t;
1866
1905
  }
1867
- function Ne(r) {
1906
+ function He(r) {
1868
1907
  return ["macos", "tdesktop", "unigram", "web", "weba"].includes(r);
1869
1908
  }
1870
1909
  async function At(r) {
@@ -1879,7 +1918,7 @@ async function At(r) {
1879
1918
  function W(r) {
1880
1919
  return r < 0 ? 0 : r;
1881
1920
  }
1882
- class Oe {
1921
+ class Ue {
1883
1922
  constructor(t) {
1884
1923
  o(this, "ee", new w());
1885
1924
  o(this, "state");
@@ -2009,7 +2048,7 @@ class Oe {
2009
2048
  }
2010
2049
  }
2011
2050
  function G(r) {
2012
- const t = new Oe(r);
2051
+ const t = new Ue(r);
2013
2052
  return t.on("change", () => B("viewport", {
2014
2053
  height: t.height,
2015
2054
  isExpanded: t.isExpanded,
@@ -2017,11 +2056,11 @@ function G(r) {
2017
2056
  width: t.width
2018
2057
  })), t.listen(), t;
2019
2058
  }
2020
- function He(r, t, e, s) {
2059
+ function Me(r, t, e, s) {
2021
2060
  const n = r ? D("viewport") : null;
2022
2061
  if (n)
2023
2062
  return G({ ...n, postEvent: e });
2024
- if (Ne(t))
2063
+ if (He(t))
2025
2064
  return G({
2026
2065
  height: window.innerHeight,
2027
2066
  isExpanded: !0,
@@ -2049,37 +2088,6 @@ function He(r, t, e, s) {
2049
2088
  console.error("Unable to actualize viewport state", a);
2050
2089
  }), i;
2051
2090
  }
2052
- function S(r, t) {
2053
- document.documentElement.style.setProperty(r, t);
2054
- }
2055
- function Ue(r, t) {
2056
- const e = () => {
2057
- S("--tg-background-color", r.backgroundColor);
2058
- }, s = () => {
2059
- const {
2060
- backgroundColor: n,
2061
- secondaryBackgroundColor: i
2062
- } = t;
2063
- r.headerColor === "bg_color" ? n && S("--tg-header-color", n) : r.headerColor === "secondary_bg_color" ? i && S("--tg-header-color", i) : S("--tg-header-color", r.headerColor);
2064
- };
2065
- t.on("change", s), r.on("change:backgroundColor", e), r.on("change:headerColor", s), e(), s();
2066
- }
2067
- function Me(r) {
2068
- const t = () => {
2069
- const e = r.getState();
2070
- Object.entries(e).forEach(([s, n]) => {
2071
- if (n) {
2072
- const i = s.replace(/[A-Z]/g, (a) => `-${a.toLowerCase()}`);
2073
- S(`--tg-theme-${i}`, n);
2074
- }
2075
- });
2076
- };
2077
- r.on("change", t), t();
2078
- }
2079
- function ot(r) {
2080
- const t = () => S("--tg-viewport-height", `${r.height}px`), e = () => S("--tg-viewport-width", `${r.width}px`), s = () => S("--tg-viewport-height", `${r.stableHeight}px`);
2081
- r.on("change:height", t), r.on("change:width", e), r.on("change:stableHeight", s), t(), e(), s();
2082
- }
2083
2091
  function Ge(r) {
2084
2092
  return typeof r == "object" ? r : r ? {
2085
2093
  themeParams: !0,
@@ -2087,9 +2095,9 @@ function Ge(r) {
2087
2095
  miniApp: !0
2088
2096
  } : {};
2089
2097
  }
2090
- function at(r, t, e, s) {
2098
+ function ct(r, t, e, s) {
2091
2099
  const n = Ge(r);
2092
- n.miniApp && Ue(t, e), n.themeParams && Me(e), n.viewport && (s instanceof Promise ? s.then(ot) : ot(s));
2100
+ n.miniApp && Se(t, e), n.themeParams && xe(e), n.viewport && (s instanceof Promise ? s.then(at) : at(s));
2093
2101
  }
2094
2102
  function je(r) {
2095
2103
  const { hostname: t, pathname: e } = new URL(r, window.location.href);
@@ -2374,22 +2382,22 @@ function ur(r = {}) {
2374
2382
  botInline: g = !1
2375
2383
  },
2376
2384
  isPageReload: _
2377
- } = Ct(), A = Te(), l = me(c);
2378
- vt() && (n && xe(), l("iframe_ready", { reload_supported: !0 }), y("reload_iframe", () => window.location.reload()));
2385
+ } = Ct(), A = De(), l = me(c);
2386
+ vt() && (n && Ae(), l("iframe_ready", { reload_supported: !0 }), y("reload_iframe", () => window.location.reload()));
2379
2387
  const C = {
2380
- backButton: qe(_, c, l),
2381
- closingBehavior: Ae(_, l),
2388
+ backButton: Ve(_, c, l),
2389
+ closingBehavior: Re(_, l),
2382
2390
  cloudStorage: new ke(c, A, l),
2383
2391
  createRequestId: A,
2384
- hapticFeedback: new Se(c, l),
2392
+ hapticFeedback: new qe(c, l),
2385
2393
  invoice: new Fe(c, l),
2386
- mainButton: Re(
2394
+ mainButton: Le(
2387
2395
  _,
2388
2396
  h.buttonColor || "#000000",
2389
2397
  h.buttonTextColor || "#ffffff",
2390
2398
  l
2391
2399
  ),
2392
- miniApp: $e(
2400
+ miniApp: Be(
2393
2401
  _,
2394
2402
  h.backgroundColor || "#ffffff",
2395
2403
  c,
@@ -2400,20 +2408,20 @@ function ur(r = {}) {
2400
2408
  popup: new Je(c, l),
2401
2409
  postEvent: l,
2402
2410
  qrScanner: new Qe(c, l),
2403
- settingsButton: De(_, c, l),
2404
- themeParams: We(h),
2411
+ settingsButton: Ne(_, c, l),
2412
+ themeParams: Oe(h),
2405
2413
  utils: new Ze(c, A, l),
2406
2414
  ...i ? {
2407
2415
  initData: new Nt(i),
2408
2416
  initDataRaw: a
2409
2417
  } : {}
2410
- }, x = He(_, p, l, e);
2411
- return x instanceof Promise || e ? Promise.resolve(x).then((v) => (at(
2418
+ }, x = Me(_, p, l, e);
2419
+ return x instanceof Promise || e ? Promise.resolve(x).then((v) => (ct(
2412
2420
  s,
2413
2421
  C.miniApp,
2414
2422
  C.themeParams,
2415
2423
  v
2416
- ), { ...C, viewport: v })) : (at(
2424
+ ), { ...C, viewport: v })) : (ct(
2417
2425
  s,
2418
2426
  C.miniApp,
2419
2427
  C.themeParams,
@@ -2651,7 +2659,7 @@ class Ye {
2651
2659
  return this.entry.search;
2652
2660
  }
2653
2661
  }
2654
- const ct = 0, Z = 1, K = 2;
2662
+ const ut = 0, Z = 1, K = 2;
2655
2663
  class Vt extends Ye {
2656
2664
  constructor(e, s, n = {}) {
2657
2665
  super(e, s, {
@@ -2667,7 +2675,7 @@ class Vt extends Ye {
2667
2675
  o(this, "onPopState", async ({ state: e }) => {
2668
2676
  if (this.logger.log('"popstate" event received. State:', e), e === null)
2669
2677
  return this.push(window.location.hash.slice(1));
2670
- if (e === ct) {
2678
+ if (e === ut) {
2671
2679
  this.logger.log("Void reached. Moving history forward"), window.history.forward();
2672
2680
  return;
2673
2681
  }
@@ -2716,7 +2724,7 @@ class Vt extends Ye {
2716
2724
  async syncHistory() {
2717
2725
  window.removeEventListener("popstate", this.onPopState);
2718
2726
  const e = `#${this.path}`;
2719
- await Ke(), d("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(Z, ""), window.history.pushState(null, "", e), window.history.pushState(K, ""), await H(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(Z, ""), window.history.pushState(null, "", e)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, e), window.history.pushState(K, ""), await H(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(ct, ""), window.history.pushState(null, "", e)), window.addEventListener("popstate", this.onPopState);
2727
+ await Ke(), d("web_app_setup_back_button", { is_visible: this.canGoBack }), this.canGoBack && this.canGoForward ? (this.logger.log("Setting up history: [<-, *, ->]"), window.history.replaceState(Z, ""), window.history.pushState(null, "", e), window.history.pushState(K, ""), await H(-1)) : this.canGoBack ? (this.logger.log("Setting up history: [<-, *]"), window.history.replaceState(Z, ""), window.history.pushState(null, "", e)) : this.canGoForward ? (this.logger.log("Setting up history: [*, ->]"), window.history.replaceState(null, e), window.history.pushState(K, ""), await H(-1)) : (this.logger.log("Setting up history: [~, *]"), window.history.replaceState(ut, ""), window.history.pushState(null, "", e)), window.addEventListener("popstate", this.onPopState);
2720
2728
  }
2721
2729
  emitChanged(e, s) {
2722
2730
  this.ee.emit("change", {
@@ -2743,41 +2751,44 @@ export {
2743
2751
  Ce as BackButton,
2744
2752
  Pe as ClosingBehavior,
2745
2753
  ke as CloudStorage,
2746
- Se as HapticFeedback,
2754
+ qe as HapticFeedback,
2747
2755
  Vt as HashNavigator,
2748
2756
  Nt as InitData,
2749
2757
  Fe as Invoice,
2750
- Ve as MainButton,
2751
- tt as MethodUnsupportedError,
2752
- Le as MiniApp,
2758
+ Ie as MainButton,
2759
+ et as MethodUnsupportedError,
2760
+ Te as MiniApp,
2753
2761
  Ye as Navigator,
2754
- et as ParameterUnsupportedError,
2762
+ rt as ParameterUnsupportedError,
2755
2763
  F as ParseError,
2756
2764
  j as ParseSchemaFieldError,
2757
2765
  Je as Popup,
2758
2766
  Qe as QRScanner,
2759
- Be as SettingsButton,
2767
+ We as SettingsButton,
2760
2768
  Mt as ThemeParams,
2761
2769
  J as TimeoutError,
2762
2770
  Ze as Utils,
2763
- Oe as Viewport,
2771
+ Ue as Viewport,
2764
2772
  Bt as array,
2773
+ Se as bindMiniAppCSSVars,
2774
+ xe as bindThemeCSSVars,
2775
+ at as bindViewportCSSVars,
2765
2776
  k as boolean,
2766
2777
  Wt as chatParser,
2767
2778
  ve as classNames,
2768
2779
  be as compareVersions,
2769
2780
  me as createPostEvent,
2770
- pt as date,
2781
+ lt as date,
2771
2782
  hr as getHash,
2772
2783
  ur as init,
2773
2784
  wt as initDataParser,
2774
2785
  O as invokeCustomMethod,
2775
2786
  ft as isColorDark,
2776
2787
  vt as isIframe,
2777
- lt as isRGB,
2788
+ X as isRGB,
2778
2789
  Dt as isRGBShort,
2779
2790
  R as isRecord,
2780
- Ne as isStableViewportPlatform,
2791
+ He as isStableViewportPlatform,
2781
2792
  rr as isTMA,
2782
2793
  ar as isTimeoutError,
2783
2794
  f as json,
@@ -2797,9 +2808,10 @@ export {
2797
2808
  At as requestViewport,
2798
2809
  Ct as retrieveLaunchData,
2799
2810
  gt as rgb,
2800
- X as searchParams,
2811
+ tt as searchParams,
2801
2812
  Jt as serializeLaunchParams,
2802
2813
  Ut as serializeThemeParams,
2814
+ S as setCSSVar,
2803
2815
  sr as setDebug,
2804
2816
  nr as setTargetOrigin,
2805
2817
  u as string,
@@ -2808,7 +2820,6 @@ export {
2808
2820
  _t as themeParamsParser,
2809
2821
  dt as toRGB,
2810
2822
  _e as unsubscribe,
2811
- rt as userParser,
2823
+ st as userParser,
2812
2824
  xt as withTimeout
2813
2825
  };
2814
- //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tma.js/sdk",
3
- "version": "1.4.3",
3
+ "version": "1.4.6",
4
4
  "description": "TypeScript Source Development Kit for Telegram Mini Apps client application.",
5
5
  "author": "Vladislav Kibenko <wolfram.deus@gmail.com>",
6
6
  "homepage": "https://github.com/Telegram-Mini-Apps/tma.js#readme",
@@ -21,8 +21,7 @@
21
21
  "type": "module",
22
22
  "sideEffects": false,
23
23
  "files": [
24
- "dist",
25
- "src"
24
+ "dist"
26
25
  ],
27
26
  "main": "./dist/index.cjs",
28
27
  "browser": "./dist/index.iife.js",