@core-ease/telegram-kit 3.0.1

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 (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +299 -0
  3. package/dist/animation/index.d.mts +4 -0
  4. package/dist/animation/index.d.ts +4 -0
  5. package/dist/animation/index.js +2413 -0
  6. package/dist/animation/index.mjs +5 -0
  7. package/dist/animation/lottie/index.d.mts +10 -0
  8. package/dist/animation/lottie/index.d.ts +10 -0
  9. package/dist/animation/lottie/index.js +2313 -0
  10. package/dist/animation/lottie/index.mjs +4 -0
  11. package/dist/animation/tgs/index.d.mts +18 -0
  12. package/dist/animation/tgs/index.d.ts +18 -0
  13. package/dist/animation/tgs/index.js +2402 -0
  14. package/dist/animation/tgs/index.mjs +4 -0
  15. package/dist/bot/index.d.mts +477 -0
  16. package/dist/bot/index.d.ts +477 -0
  17. package/dist/bot/index.js +870 -0
  18. package/dist/bot/index.mjs +847 -0
  19. package/dist/bot-D8BnLWIi.d.mts +2041 -0
  20. package/dist/bot-D8BnLWIi.d.ts +2041 -0
  21. package/dist/browser.global.js +23 -0
  22. package/dist/chunk-7AARTHNW.mjs +40 -0
  23. package/dist/chunk-7CVYPKAL.mjs +15 -0
  24. package/dist/chunk-B3PWALX5.mjs +4418 -0
  25. package/dist/chunk-BQEUEAVK.mjs +2262 -0
  26. package/dist/chunk-FPWYSKK2.mjs +3089 -0
  27. package/dist/chunk-JXK5HCDV.mjs +254 -0
  28. package/dist/chunk-OMH2JGOH.mjs +88 -0
  29. package/dist/chunk-PXO36YTU.mjs +38 -0
  30. package/dist/core/index.d.mts +151 -0
  31. package/dist/core/index.d.ts +151 -0
  32. package/dist/core/index.js +3837 -0
  33. package/dist/core/index.mjs +495 -0
  34. package/dist/dev/index.d.mts +77 -0
  35. package/dist/dev/index.d.ts +77 -0
  36. package/dist/dev/index.js +3214 -0
  37. package/dist/dev/index.mjs +151 -0
  38. package/dist/engine-BDm1_hzn.d.mts +382 -0
  39. package/dist/engine-BDm1_hzn.d.ts +382 -0
  40. package/dist/format/index.d.mts +61 -0
  41. package/dist/format/index.d.ts +61 -0
  42. package/dist/format/index.js +121 -0
  43. package/dist/format/index.mjs +112 -0
  44. package/dist/hooks/index.d.mts +1 -0
  45. package/dist/hooks/index.d.ts +1 -0
  46. package/dist/hooks/index.js +4234 -0
  47. package/dist/hooks/index.mjs +3 -0
  48. package/dist/hooks-C5Per70R.d.mts +1066 -0
  49. package/dist/hooks-C5Per70R.d.ts +1066 -0
  50. package/dist/index.d.mts +849 -0
  51. package/dist/index.d.ts +849 -0
  52. package/dist/index.js +5026 -0
  53. package/dist/index.mjs +478 -0
  54. package/dist/keyboards/index.d.mts +50 -0
  55. package/dist/keyboards/index.d.ts +50 -0
  56. package/dist/keyboards/index.js +127 -0
  57. package/dist/keyboards/index.mjs +124 -0
  58. package/dist/links/index.d.mts +53 -0
  59. package/dist/links/index.d.ts +53 -0
  60. package/dist/links/index.js +139 -0
  61. package/dist/links/index.mjs +133 -0
  62. package/dist/lottie/index.d.mts +3 -0
  63. package/dist/lottie/index.d.ts +3 -0
  64. package/dist/lottie/index.js +2313 -0
  65. package/dist/lottie/index.mjs +4 -0
  66. package/dist/qr/index.d.mts +75 -0
  67. package/dist/qr/index.d.ts +75 -0
  68. package/dist/qr/index.js +983 -0
  69. package/dist/qr/index.mjs +946 -0
  70. package/dist/sdk/index.d.mts +322 -0
  71. package/dist/sdk/index.d.ts +322 -0
  72. package/dist/sdk/index.js +3138 -0
  73. package/dist/sdk/index.mjs +2 -0
  74. package/dist/server/index.d.mts +28 -0
  75. package/dist/server/index.d.ts +28 -0
  76. package/dist/server/index.js +254 -0
  77. package/dist/server/index.mjs +246 -0
  78. package/dist/tgs/index.d.mts +3 -0
  79. package/dist/tgs/index.d.ts +3 -0
  80. package/dist/tgs/index.js +2402 -0
  81. package/dist/tgs/index.mjs +4 -0
  82. package/dist/webapp-B-3_74nK.d.mts +842 -0
  83. package/dist/webapp-B-3_74nK.d.ts +842 -0
  84. package/dist/webapp-BDi9q3-a.d.mts +42 -0
  85. package/dist/webapp-YvmwFYUQ.d.ts +42 -0
  86. package/package.json +165 -0
@@ -0,0 +1,983 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var React__default = /*#__PURE__*/_interopDefault(React);
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
14
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
+ var __spreadValues = (a, b) => {
16
+ for (var prop in b || (b = {}))
17
+ if (__hasOwnProp.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ if (__getOwnPropSymbols)
20
+ for (var prop of __getOwnPropSymbols(b)) {
21
+ if (__propIsEnum.call(b, prop))
22
+ __defNormalProp(a, prop, b[prop]);
23
+ }
24
+ return a;
25
+ };
26
+ var __objRest = (source, exclude) => {
27
+ var target = {};
28
+ for (var prop in source)
29
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
30
+ target[prop] = source[prop];
31
+ if (source != null && __getOwnPropSymbols)
32
+ for (var prop of __getOwnPropSymbols(source)) {
33
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
34
+ target[prop] = source[prop];
35
+ }
36
+ return target;
37
+ };
38
+
39
+ // src/_internal/qr/bitBuffer.ts
40
+ var BitBuffer = class {
41
+ constructor() {
42
+ this.bits = [];
43
+ }
44
+ push(value, len) {
45
+ for (let i = len - 1; i >= 0; i--) {
46
+ this.bits.push(value >>> i & 1);
47
+ }
48
+ }
49
+ get length() {
50
+ return this.bits.length;
51
+ }
52
+ toCodewords() {
53
+ var _a;
54
+ const codewords = [];
55
+ for (let i = 0; i < this.bits.length; i += 8) {
56
+ let byte = 0;
57
+ for (let j = 0; j < 8; j++) {
58
+ byte = byte << 1 | ((_a = this.bits[i + j]) != null ? _a : 0);
59
+ }
60
+ codewords.push(byte);
61
+ }
62
+ return codewords;
63
+ }
64
+ };
65
+
66
+ // src/_internal/qr/galoisField.ts
67
+ var EXP = new Uint8Array(512);
68
+ var LOG = new Uint8Array(256);
69
+ (function initTables() {
70
+ let x = 1;
71
+ for (let i = 0; i < 255; i++) {
72
+ EXP[i] = x;
73
+ LOG[x] = i;
74
+ x <<= 1;
75
+ if (x & 256) x ^= 285;
76
+ }
77
+ for (let i = 255; i < 512; i++) EXP[i] = EXP[i - 255];
78
+ })();
79
+ function gfMultiply(a, b) {
80
+ if (a === 0 || b === 0) return 0;
81
+ return EXP[LOG[a] + LOG[b]];
82
+ }
83
+ function generatorPolynomial(degree) {
84
+ let poly = [1];
85
+ for (let i = 0; i < degree; i++) {
86
+ const next = new Array(poly.length + 1).fill(0);
87
+ for (let j = 0; j < poly.length; j++) {
88
+ next[j] ^= poly[j];
89
+ next[j + 1] ^= gfMultiply(poly[j], EXP[i]);
90
+ }
91
+ poly = next;
92
+ }
93
+ return poly;
94
+ }
95
+
96
+ // src/_internal/qr/reedSolomon.ts
97
+ function reedSolomonEncode(dataCodewords, eccLength) {
98
+ const generator = generatorPolynomial(eccLength);
99
+ const result = dataCodewords.slice();
100
+ for (let i = 0; i < eccLength; i++) result.push(0);
101
+ for (let i = 0; i < dataCodewords.length; i++) {
102
+ const factor = result[i];
103
+ if (factor === 0) continue;
104
+ for (let j = 0; j < generator.length; j++) {
105
+ result[i + j] ^= gfMultiply(generator[j], factor);
106
+ }
107
+ }
108
+ return result.slice(dataCodewords.length);
109
+ }
110
+
111
+ // src/_internal/qr/tables.ts
112
+ var ERROR_CORRECTION_LEVELS = ["L", "M", "Q", "H"];
113
+ var FORMAT_EC_BITS = {
114
+ L: 1,
115
+ M: 0,
116
+ Q: 3,
117
+ H: 2
118
+ };
119
+ var ECC_CODEWORDS_PER_BLOCK = [
120
+ [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
121
+ [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
122
+ [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
123
+ [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
124
+ ];
125
+ var NUM_ERROR_CORRECTION_BLOCKS = [
126
+ [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
127
+ [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
128
+ [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
129
+ [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81]
130
+ ];
131
+ function levelIndex(level) {
132
+ return ERROR_CORRECTION_LEVELS.indexOf(level);
133
+ }
134
+ function symbolSize(version) {
135
+ return version * 4 + 17;
136
+ }
137
+ function getNumRawDataModules(version) {
138
+ let result = (16 * version + 128) * version + 64;
139
+ if (version >= 2) {
140
+ const numAlign = Math.floor(version / 7) + 2;
141
+ result -= (25 * numAlign - 10) * numAlign - 55;
142
+ if (version >= 7) result -= 36;
143
+ }
144
+ return result;
145
+ }
146
+ function getTotalCodewords(version) {
147
+ return Math.floor(getNumRawDataModules(version) / 8);
148
+ }
149
+ function getNumDataCodewords(version, level) {
150
+ const idx = levelIndex(level);
151
+ const eccLen = ECC_CODEWORDS_PER_BLOCK[idx][version];
152
+ const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[idx][version];
153
+ return getTotalCodewords(version) - eccLen * numBlocks;
154
+ }
155
+ function getBlockStructure(version, level) {
156
+ const idx = levelIndex(level);
157
+ return {
158
+ eccLength: ECC_CODEWORDS_PER_BLOCK[idx][version],
159
+ numBlocks: NUM_ERROR_CORRECTION_BLOCKS[idx][version]
160
+ };
161
+ }
162
+ function getAlignmentPatternPositions(version) {
163
+ if (version === 1) return [];
164
+ const numAlign = Math.floor(version / 7) + 2;
165
+ const step = Math.floor((version * 8 + numAlign * 3 + 5) / (numAlign * 4 - 4)) * 2;
166
+ const result = new Array(numAlign);
167
+ let pos = version * 4 + 10;
168
+ for (let i = numAlign - 1; i >= 1; i--, pos -= step) {
169
+ result[i] = pos;
170
+ }
171
+ result[0] = 6;
172
+ return result;
173
+ }
174
+
175
+ // src/_internal/qr/segments.ts
176
+ var QR_MODE = {
177
+ NUMERIC: 1,
178
+ ALPHANUMERIC: 2,
179
+ BYTE: 4
180
+ };
181
+ var ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
182
+ function isNumeric(text) {
183
+ return /^[0-9]*$/.test(text);
184
+ }
185
+ function isAlphanumeric(text) {
186
+ for (const ch of text) {
187
+ if (ALPHANUMERIC_CHARSET.indexOf(ch) === -1) return false;
188
+ }
189
+ return true;
190
+ }
191
+ function chooseMode(text) {
192
+ if (isNumeric(text)) return QR_MODE.NUMERIC;
193
+ if (isAlphanumeric(text)) return QR_MODE.ALPHANUMERIC;
194
+ return QR_MODE.BYTE;
195
+ }
196
+ function toUtf8Bytes(text) {
197
+ return Array.from(new TextEncoder().encode(text));
198
+ }
199
+ function charCountBitLength(mode, version) {
200
+ if (version <= 9) {
201
+ return mode === QR_MODE.NUMERIC ? 10 : mode === QR_MODE.ALPHANUMERIC ? 9 : 8;
202
+ }
203
+ if (version <= 26) {
204
+ return mode === QR_MODE.NUMERIC ? 12 : mode === QR_MODE.ALPHANUMERIC ? 11 : 16;
205
+ }
206
+ return mode === QR_MODE.NUMERIC ? 14 : mode === QR_MODE.ALPHANUMERIC ? 13 : 16;
207
+ }
208
+ function segmentCharacterCount(mode, text) {
209
+ return mode === QR_MODE.BYTE ? toUtf8Bytes(text).length : text.length;
210
+ }
211
+ function encodeSegmentBits(mode, text, bb) {
212
+ if (mode === QR_MODE.NUMERIC) {
213
+ for (let i = 0; i < text.length; i += 3) {
214
+ const chunk = text.substring(i, i + 3);
215
+ const bitsForLen = chunk.length === 3 ? 10 : chunk.length === 2 ? 7 : 4;
216
+ bb.push(parseInt(chunk, 10), bitsForLen);
217
+ }
218
+ } else if (mode === QR_MODE.ALPHANUMERIC) {
219
+ for (let i = 0; i < text.length; i += 2) {
220
+ if (i + 1 < text.length) {
221
+ const value = ALPHANUMERIC_CHARSET.indexOf(text[i]) * 45 + ALPHANUMERIC_CHARSET.indexOf(text[i + 1]);
222
+ bb.push(value, 11);
223
+ } else {
224
+ bb.push(ALPHANUMERIC_CHARSET.indexOf(text[i]), 6);
225
+ }
226
+ }
227
+ } else {
228
+ for (const byte of toUtf8Bytes(text)) bb.push(byte, 8);
229
+ }
230
+ }
231
+
232
+ // src/_internal/qr/dataCodewords.ts
233
+ function buildDataCodewords(text, version, level, mode) {
234
+ const bb = new BitBuffer();
235
+ bb.push(mode, 4);
236
+ bb.push(segmentCharacterCount(mode, text), charCountBitLength(mode, version));
237
+ encodeSegmentBits(mode, text, bb);
238
+ const capacityBits = getNumDataCodewords(version, level) * 8;
239
+ if (bb.length > capacityBits) return null;
240
+ const terminatorLen = Math.min(4, capacityBits - bb.length);
241
+ bb.push(0, terminatorLen);
242
+ while (bb.length % 8 !== 0) bb.bits.push(0);
243
+ const padBytes = [236, 17];
244
+ let padIndex = 0;
245
+ while (bb.length < capacityBits) {
246
+ bb.push(padBytes[padIndex % 2], 8);
247
+ padIndex++;
248
+ }
249
+ return bb.toCodewords();
250
+ }
251
+ function splitIntoBlocksWithEcc(dataCodewords, version, level) {
252
+ const { eccLength, numBlocks } = getBlockStructure(version, level);
253
+ const totalData = dataCodewords.length;
254
+ const shortBlockLen = Math.floor(totalData / numBlocks);
255
+ const numLongBlocks = totalData % numBlocks;
256
+ const numShortBlocks = numBlocks - numLongBlocks;
257
+ const dataBlocks = [];
258
+ let offset = 0;
259
+ for (let i = 0; i < numShortBlocks; i++) {
260
+ dataBlocks.push(dataCodewords.slice(offset, offset + shortBlockLen));
261
+ offset += shortBlockLen;
262
+ }
263
+ for (let i = 0; i < numLongBlocks; i++) {
264
+ dataBlocks.push(dataCodewords.slice(offset, offset + shortBlockLen + 1));
265
+ offset += shortBlockLen + 1;
266
+ }
267
+ const eccBlocks = dataBlocks.map((block) => reedSolomonEncode(block, eccLength));
268
+ return { dataBlocks, eccBlocks };
269
+ }
270
+ function interleaveBlocks({ dataBlocks, eccBlocks }) {
271
+ const result = [];
272
+ const maxDataLen = Math.max(...dataBlocks.map((b) => b.length));
273
+ for (let i = 0; i < maxDataLen; i++) {
274
+ for (const block of dataBlocks) {
275
+ if (i < block.length) result.push(block[i]);
276
+ }
277
+ }
278
+ const eccLen = eccBlocks[0].length;
279
+ for (let i = 0; i < eccLen; i++) {
280
+ for (const block of eccBlocks) result.push(block[i]);
281
+ }
282
+ return result;
283
+ }
284
+
285
+ // src/_internal/qr/matrix.ts
286
+ function createGrid(size) {
287
+ return Array.from({ length: size }, () => new Array(size).fill(false));
288
+ }
289
+ function drawFinderPattern(modules, isFunction, cx, cy) {
290
+ for (let dy = -3; dy <= 3; dy++) {
291
+ for (let dx = -3; dx <= 3; dx++) {
292
+ const x = cx + dx;
293
+ const y = cy + dy;
294
+ const ring = Math.max(Math.abs(dx), Math.abs(dy));
295
+ modules[y][x] = ring !== 2;
296
+ isFunction[y][x] = true;
297
+ }
298
+ }
299
+ }
300
+ function drawAlignmentPattern(modules, isFunction, cx, cy) {
301
+ for (let dy = -2; dy <= 2; dy++) {
302
+ for (let dx = -2; dx <= 2; dx++) {
303
+ const x = cx + dx;
304
+ const y = cy + dy;
305
+ const ring = Math.max(Math.abs(dx), Math.abs(dy));
306
+ modules[y][x] = ring !== 1;
307
+ isFunction[y][x] = true;
308
+ }
309
+ }
310
+ }
311
+ function drawFunctionPatterns(modules, isFunction, version) {
312
+ const size = modules.length;
313
+ drawFinderPattern(modules, isFunction, 3, 3);
314
+ drawFinderPattern(modules, isFunction, size - 4, 3);
315
+ drawFinderPattern(modules, isFunction, 3, size - 4);
316
+ const markSeparator = (x, y) => {
317
+ if (x >= 0 && x < size && y >= 0 && y < size) isFunction[y][x] = true;
318
+ };
319
+ for (let i = 0; i < 8; i++) {
320
+ markSeparator(7, i);
321
+ markSeparator(i, 7);
322
+ markSeparator(size - 8, i);
323
+ markSeparator(size - 1 - i, 7);
324
+ markSeparator(7, size - 1 - i);
325
+ markSeparator(i, size - 8);
326
+ }
327
+ for (let i = 8; i < size - 8; i++) {
328
+ modules[6][i] = i % 2 === 0;
329
+ isFunction[6][i] = true;
330
+ modules[i][6] = i % 2 === 0;
331
+ isFunction[i][6] = true;
332
+ }
333
+ const positions = getAlignmentPatternPositions(version);
334
+ for (const cy of positions) {
335
+ for (const cx of positions) {
336
+ const overlapsFinder = cx <= 8 && cy <= 8 || cx >= size - 9 && cy <= 8 || cx <= 8 && cy >= size - 9;
337
+ if (overlapsFinder) continue;
338
+ drawAlignmentPattern(modules, isFunction, cx, cy);
339
+ }
340
+ }
341
+ modules[size - 8][8] = true;
342
+ isFunction[size - 8][8] = true;
343
+ for (let i = 0; i < 9; i++) {
344
+ if (i !== 6) {
345
+ isFunction[8][i] = true;
346
+ isFunction[i][8] = true;
347
+ }
348
+ }
349
+ for (let i = 0; i < 8; i++) {
350
+ isFunction[8][size - 1 - i] = true;
351
+ isFunction[size - 1 - i][8] = true;
352
+ }
353
+ if (version >= 7) {
354
+ for (let i = 0; i < 6; i++) {
355
+ for (let j = 0; j < 3; j++) {
356
+ isFunction[size - 11 + j][i] = true;
357
+ isFunction[i][size - 11 + j] = true;
358
+ }
359
+ }
360
+ }
361
+ }
362
+ function placeDataBits(modules, isFunction, dataBits) {
363
+ const size = modules.length;
364
+ let bitIndex = 0;
365
+ let upward = true;
366
+ for (let right = size - 1; right >= 1; right -= 2) {
367
+ if (right === 6) right = 5;
368
+ for (let vert = 0; vert < size; vert++) {
369
+ const y = upward ? size - 1 - vert : vert;
370
+ for (let j = 0; j < 2; j++) {
371
+ const x = right - j;
372
+ if (isFunction[y][x]) continue;
373
+ if (bitIndex < dataBits.length) {
374
+ modules[y][x] = dataBits[bitIndex] === 1;
375
+ bitIndex++;
376
+ }
377
+ }
378
+ }
379
+ upward = !upward;
380
+ }
381
+ }
382
+ function applyMask(modules, isFunction, maskId) {
383
+ const size = modules.length;
384
+ const out = createGrid(size);
385
+ for (let y = 0; y < size; y++) {
386
+ for (let x = 0; x < size; x++) {
387
+ out[y][x] = modules[y][x];
388
+ if (isFunction[y][x]) continue;
389
+ let invert;
390
+ switch (maskId) {
391
+ case 0:
392
+ invert = (x + y) % 2 === 0;
393
+ break;
394
+ case 1:
395
+ invert = y % 2 === 0;
396
+ break;
397
+ case 2:
398
+ invert = x % 3 === 0;
399
+ break;
400
+ case 3:
401
+ invert = (x + y) % 3 === 0;
402
+ break;
403
+ case 4:
404
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
405
+ break;
406
+ case 5:
407
+ invert = x * y % 2 + x * y % 3 === 0;
408
+ break;
409
+ case 6:
410
+ invert = (x * y % 2 + x * y % 3) % 2 === 0;
411
+ break;
412
+ case 7:
413
+ invert = ((x + y) % 2 + x * y % 3) % 2 === 0;
414
+ break;
415
+ default:
416
+ invert = false;
417
+ }
418
+ if (invert) out[y][x] = !out[y][x];
419
+ }
420
+ }
421
+ return out;
422
+ }
423
+ var FINDER_PENALTY_PATTERN_A = [true, false, true, true, true, false, true, false, false, false, false];
424
+ var FINDER_PENALTY_PATTERN_B = [false, false, false, false, true, false, true, true, true, false, true];
425
+ function matchesFinderPenaltyPattern(bits) {
426
+ const eq = (pattern) => pattern.every((v, i) => v === bits[i]);
427
+ return eq(FINDER_PENALTY_PATTERN_A) || eq(FINDER_PENALTY_PATTERN_B);
428
+ }
429
+ function computeMaskPenalty(modules) {
430
+ const size = modules.length;
431
+ let penalty = 0;
432
+ const runPenalty = (getCell) => {
433
+ let p = 0;
434
+ for (let i = 0; i < size; i++) {
435
+ let runColor = null;
436
+ let runLen = 0;
437
+ for (let j = 0; j < size; j++) {
438
+ const c = getCell(i, j);
439
+ if (c === runColor) {
440
+ runLen++;
441
+ } else {
442
+ if (runLen >= 5) p += 3 + (runLen - 5);
443
+ runColor = c;
444
+ runLen = 1;
445
+ }
446
+ }
447
+ if (runLen >= 5) p += 3 + (runLen - 5);
448
+ }
449
+ return p;
450
+ };
451
+ penalty += runPenalty((r, c) => modules[r][c]);
452
+ penalty += runPenalty((r, c) => modules[c][r]);
453
+ for (let y = 0; y < size - 1; y++) {
454
+ for (let x = 0; x < size - 1; x++) {
455
+ const v = modules[y][x];
456
+ if (v === modules[y][x + 1] && v === modules[y + 1][x] && v === modules[y + 1][x + 1]) {
457
+ penalty += 3;
458
+ }
459
+ }
460
+ }
461
+ for (let y = 0; y < size; y++) {
462
+ for (let x = 0; x <= size - 11; x++) {
463
+ const bits = [];
464
+ for (let k = 0; k < 11; k++) bits.push(modules[y][x + k]);
465
+ if (matchesFinderPenaltyPattern(bits)) penalty += 40;
466
+ }
467
+ }
468
+ for (let x = 0; x < size; x++) {
469
+ for (let y = 0; y <= size - 11; y++) {
470
+ const bits = [];
471
+ for (let k = 0; k < 11; k++) bits.push(modules[y + k][x]);
472
+ if (matchesFinderPenaltyPattern(bits)) penalty += 40;
473
+ }
474
+ }
475
+ let dark = 0;
476
+ for (let y = 0; y < size; y++) for (let x = 0; x < size; x++) if (modules[y][x]) dark++;
477
+ const percentDark = dark * 100 / (size * size);
478
+ penalty += Math.floor(Math.abs(percentDark - 50) / 5) * 10;
479
+ return penalty;
480
+ }
481
+ function computeFormatBits(level, maskId) {
482
+ const data = FORMAT_EC_BITS[level] << 3 | maskId;
483
+ const GENERATOR = 1335;
484
+ let remainder = data << 10;
485
+ for (let i = 14; i >= 10; i--) {
486
+ if ((remainder & 1 << i) !== 0) remainder ^= GENERATOR << i - 10;
487
+ }
488
+ return (data << 10 | remainder) ^ 21522;
489
+ }
490
+ function computeVersionBits(version) {
491
+ const GENERATOR = 7973;
492
+ let remainder = version << 12;
493
+ for (let i = 17; i >= 12; i--) {
494
+ if ((remainder & 1 << i) !== 0) remainder ^= GENERATOR << i - 12;
495
+ }
496
+ return version << 12 | remainder;
497
+ }
498
+ function drawFormatInfo(modules, level, maskId) {
499
+ const size = modules.length;
500
+ const bits = computeFormatBits(level, maskId);
501
+ const bitAt = (k) => (bits >> k & 1) === 1;
502
+ const group1 = [
503
+ [8, 0],
504
+ [8, 1],
505
+ [8, 2],
506
+ [8, 3],
507
+ [8, 4],
508
+ [8, 5],
509
+ [8, 7],
510
+ [8, 8],
511
+ [7, 8],
512
+ [5, 8],
513
+ [4, 8],
514
+ [3, 8],
515
+ [2, 8],
516
+ [1, 8],
517
+ [0, 8]
518
+ ];
519
+ for (let k = 0; k < 15; k++) {
520
+ const [r, c] = group1[k];
521
+ modules[r][c] = bitAt(14 - k);
522
+ }
523
+ const group2 = [
524
+ [size - 1, 8],
525
+ [size - 2, 8],
526
+ [size - 3, 8],
527
+ [size - 4, 8],
528
+ [size - 5, 8],
529
+ [size - 6, 8],
530
+ [size - 7, 8],
531
+ [8, size - 8],
532
+ [8, size - 7],
533
+ [8, size - 6],
534
+ [8, size - 5],
535
+ [8, size - 4],
536
+ [8, size - 3],
537
+ [8, size - 2],
538
+ [8, size - 1]
539
+ ];
540
+ for (let k = 0; k < 15; k++) {
541
+ const [r, c] = group2[k];
542
+ modules[r][c] = bitAt(14 - k);
543
+ }
544
+ modules[size - 8][8] = true;
545
+ }
546
+ function drawVersionInfo(modules, version) {
547
+ if (version < 7) return;
548
+ const size = modules.length;
549
+ const bits = computeVersionBits(version);
550
+ for (let i = 0; i < 18; i++) {
551
+ const bit = (bits >> i & 1) === 1;
552
+ const a = Math.floor(i / 3);
553
+ const b = i % 3;
554
+ modules[size - 11 + b][a] = bit;
555
+ modules[a][size - 11 + b] = bit;
556
+ }
557
+ }
558
+
559
+ // src/_internal/qr/encoder.ts
560
+ var MIN_VERSION = 1;
561
+ var MAX_VERSION = 40;
562
+ function encodeQrMatrix(text, options = {}) {
563
+ var _a, _b, _c, _d, _e;
564
+ const level = (_a = options.errorCorrectionLevel) != null ? _a : "M";
565
+ const mode = chooseMode(text);
566
+ const minVersion = (_c = (_b = options.version) != null ? _b : options.minVersion) != null ? _c : MIN_VERSION;
567
+ const maxVersion = (_e = (_d = options.version) != null ? _d : options.maxVersion) != null ? _e : MAX_VERSION;
568
+ let version = null;
569
+ let dataCodewords = null;
570
+ for (let v = minVersion; v <= maxVersion; v++) {
571
+ const codewords = buildDataCodewords(text, v, level, mode);
572
+ if (codewords) {
573
+ version = v;
574
+ dataCodewords = codewords;
575
+ break;
576
+ }
577
+ }
578
+ if (version === null || dataCodewords === null) {
579
+ throw new Error(
580
+ `[@core-ease/telegram-kit] Unable to encode a QR code: the input is too long for error correction level "${level}"` + (options.version ? ` at version ${options.version}.` : " within the allowed version range.")
581
+ );
582
+ }
583
+ const blocked = splitIntoBlocksWithEcc(dataCodewords, version, level);
584
+ const allCodewords = interleaveBlocks(blocked);
585
+ const dataBits = [];
586
+ for (const codeword of allCodewords) {
587
+ for (let i = 7; i >= 0; i--) dataBits.push(codeword >> i & 1);
588
+ }
589
+ const size = symbolSize(version);
590
+ const modules = createGrid(size);
591
+ const isFunction = createGrid(size);
592
+ drawFunctionPatterns(modules, isFunction, version);
593
+ placeDataBits(modules, isFunction, dataBits);
594
+ let bestMask = 0;
595
+ let bestModules = modules;
596
+ if (typeof options.maskPattern === "number") {
597
+ bestMask = options.maskPattern;
598
+ bestModules = applyMask(modules, isFunction, bestMask);
599
+ } else {
600
+ let bestPenalty = Infinity;
601
+ for (let maskId = 0; maskId < 8; maskId++) {
602
+ const masked = applyMask(modules, isFunction, maskId);
603
+ const penalty = computeMaskPenalty(masked);
604
+ if (penalty < bestPenalty) {
605
+ bestPenalty = penalty;
606
+ bestMask = maskId;
607
+ bestModules = masked;
608
+ }
609
+ }
610
+ }
611
+ drawFormatInfo(bestModules, level, bestMask);
612
+ drawVersionInfo(bestModules, version);
613
+ return {
614
+ modules: bestModules,
615
+ size,
616
+ version,
617
+ errorCorrectionLevel: level,
618
+ maskPattern: bestMask
619
+ };
620
+ }
621
+
622
+ // src/_internal/qr/Qr.ts
623
+ function encodeQRCode(text, options) {
624
+ return encodeQrMatrix(text, options);
625
+ }
626
+ function qrCodeToSVG(text, options = {}) {
627
+ const _a = options, { size = 512, color = "#000000", background = "#ffffff", quietZone = 4 } = _a, encodeOptions = __objRest(_a, ["size", "color", "background", "quietZone"]);
628
+ const { modules } = encodeQrMatrix(text, encodeOptions);
629
+ const dimension = modules.length + quietZone * 2;
630
+ const cell = size / dimension;
631
+ let path = "";
632
+ for (let y = 0; y < modules.length; y++) {
633
+ for (let x = 0; x < modules.length; x++) {
634
+ if (!modules[y][x]) continue;
635
+ const px = (x + quietZone) * cell;
636
+ const py = (y + quietZone) * cell;
637
+ path += `M${px} ${py}h${cell}v${cell}h${-cell}z`;
638
+ }
639
+ }
640
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" width="${size}" height="${size}"><rect width="${size}" height="${size}" fill="${background}"/><path d="${path}" fill="${color}"/></svg>`;
641
+ }
642
+ function roundedRectPath(cx, cy, halfSize, radii) {
643
+ const x = cx - halfSize;
644
+ const y = cy - halfSize;
645
+ const w = halfSize * 2;
646
+ const h = halfSize * 2;
647
+ const { tl, tr, br, bl } = radii;
648
+ return [
649
+ `M${x + tl},${y}`,
650
+ `L${x + w - tr},${y}`,
651
+ tr > 0 ? `A${tr},${tr} 0 0 1 ${x + w},${y + tr}` : "",
652
+ `L${x + w},${y + h - br}`,
653
+ br > 0 ? `A${br},${br} 0 0 1 ${x + w - br},${y + h}` : "",
654
+ `L${x + bl},${y + h}`,
655
+ bl > 0 ? `A${bl},${bl} 0 0 1 ${x},${y + h - bl}` : "",
656
+ `L${x},${y + tl}`,
657
+ tl > 0 ? `A${tl},${tl} 0 0 1 ${x + tl},${y}` : "",
658
+ "Z"
659
+ ].filter(Boolean).join("");
660
+ }
661
+ function dotPath(cx, cy, cellSize, shape, neighbors) {
662
+ const half = cellSize / 2;
663
+ if (shape === "square") {
664
+ return { d: roundedRectPath(cx, cy, half * 0.98, { tl: 0, tr: 0, br: 0, bl: 0 }) };
665
+ }
666
+ if (shape === "dots") {
667
+ return { circle: true };
668
+ }
669
+ const isolatedCorner = (a, b) => (a ? 0 : 1) + (b ? 0 : 1) === 2;
670
+ if (shape === "rounded" || shape === "extra-rounded") {
671
+ const r2 = half * (shape === "extra-rounded" ? 0.7 : 0.5);
672
+ return {
673
+ d: roundedRectPath(cx, cy, half * 0.98, {
674
+ tl: isolatedCorner(neighbors.top, neighbors.left) ? r2 : 0,
675
+ tr: isolatedCorner(neighbors.top, neighbors.right) ? r2 : 0,
676
+ br: isolatedCorner(neighbors.bottom, neighbors.right) ? r2 : 0,
677
+ bl: isolatedCorner(neighbors.bottom, neighbors.left) ? r2 : 0
678
+ })
679
+ };
680
+ }
681
+ const r = half * (shape === "classy-rounded" ? 0.65 : 0.4);
682
+ return {
683
+ d: roundedRectPath(cx, cy, half * 0.98, {
684
+ tl: isolatedCorner(neighbors.top, neighbors.left) ? r : 0,
685
+ br: isolatedCorner(neighbors.bottom, neighbors.right) ? r : 0,
686
+ tr: 0,
687
+ bl: 0
688
+ })
689
+ };
690
+ }
691
+ var QRCode = React__default.default.forwardRef(function QRCode2({
692
+ value,
693
+ size = 256,
694
+ errorCorrectionLevel,
695
+ dotsOptions,
696
+ cornersSquareOptions,
697
+ cornersDotOptions,
698
+ dotColor = "#000",
699
+ eyeColor,
700
+ backgroundColor = "transparent",
701
+ logo,
702
+ logoSize,
703
+ logoPadding = 8,
704
+ logoShape = "circle",
705
+ logoBackgroundColor,
706
+ onLogoSizeClamped,
707
+ quietZone = 4,
708
+ borderRadius = 0,
709
+ className = "",
710
+ style = {}
711
+ }, ref) {
712
+ var _a, _b, _c, _d, _e, _f, _g;
713
+ const resolvedDotColor = (_a = dotsOptions == null ? void 0 : dotsOptions.color) != null ? _a : dotColor;
714
+ const resolvedDotShape = (_b = dotsOptions == null ? void 0 : dotsOptions.style) != null ? _b : "square";
715
+ const resolvedCornerSquareColor = (_d = (_c = cornersSquareOptions == null ? void 0 : cornersSquareOptions.color) != null ? _c : eyeColor) != null ? _d : resolvedDotColor;
716
+ const resolvedCornerSquareShape = (_e = cornersSquareOptions == null ? void 0 : cornersSquareOptions.style) != null ? _e : "square";
717
+ const resolvedCornerDotColor = (_f = cornersDotOptions == null ? void 0 : cornersDotOptions.color) != null ? _f : resolvedCornerSquareColor;
718
+ const resolvedCornerDotShape = (_g = cornersDotOptions == null ? void 0 : cornersDotOptions.style) != null ? _g : "square";
719
+ const isStylized = resolvedDotShape !== "square" || resolvedCornerSquareShape !== "square" || resolvedCornerDotShape !== "square";
720
+ const resolvedLevel = errorCorrectionLevel != null ? errorCorrectionLevel : logo ? "H" : isStylized ? "Q" : "M";
721
+ const requestedLogoSize = logoSize != null ? logoSize : size * 0.2;
722
+ const result = React.useMemo(() => {
723
+ if (!value) return null;
724
+ try {
725
+ return encodeQRCode(value, { errorCorrectionLevel: resolvedLevel });
726
+ } catch (e) {
727
+ return null;
728
+ }
729
+ }, [value, resolvedLevel]);
730
+ if (!result) return null;
731
+ const { modules } = result;
732
+ const matrixSize = modules.length;
733
+ const dimension = matrixSize + quietZone * 2;
734
+ const cellSize = size / dimension;
735
+ const isEyeModule = (r, c) => r < 7 && c < 7 || r < 7 && c >= matrixSize - 7 || r >= matrixSize - 7 && c < 7;
736
+ const MAX_SAFE_LOGO_AREA_RATIO = {
737
+ L: 0.06,
738
+ M: 0.13,
739
+ Q: 0.2,
740
+ H: 0.27
741
+ };
742
+ let logoClearRadiusPx = 0;
743
+ let effectiveLogoImageSize = 0;
744
+ if (logo) {
745
+ const requestedRadiusPx = requestedLogoSize / 2 + logoPadding;
746
+ const requestedRadiusModules = requestedRadiusPx / cellSize;
747
+ const requestedAreaRatio = Math.PI * requestedRadiusModules ** 2 / (matrixSize * matrixSize);
748
+ let clearRadiusModules = requestedRadiusModules;
749
+ const maxAreaRatio = MAX_SAFE_LOGO_AREA_RATIO[resolvedLevel];
750
+ if (requestedAreaRatio > maxAreaRatio) {
751
+ clearRadiusModules = Math.sqrt(maxAreaRatio * matrixSize * matrixSize / Math.PI);
752
+ }
753
+ const maxRadiusByBorder = Math.max(matrixSize / 2 - 8, 0);
754
+ clearRadiusModules = Math.min(clearRadiusModules, maxRadiusByBorder);
755
+ logoClearRadiusPx = clearRadiusModules * cellSize;
756
+ effectiveLogoImageSize = Math.max(0, logoClearRadiusPx * 2 - logoPadding * 2);
757
+ const requestedTotalSize = requestedLogoSize + logoPadding * 2;
758
+ const effectiveTotalSize = logoClearRadiusPx * 2;
759
+ if (onLogoSizeClamped && effectiveTotalSize < requestedTotalSize - 0.5) {
760
+ onLogoSizeClamped(effectiveTotalSize, requestedTotalSize);
761
+ }
762
+ }
763
+ const centerModule = matrixSize / 2;
764
+ const isInLogoClearZone = (r, c) => {
765
+ if (!logo || logoClearRadiusPx <= 0) return false;
766
+ const dx = c + 0.5 - centerModule;
767
+ const dy = r + 0.5 - centerModule;
768
+ const radiusModules = logoClearRadiusPx / cellSize;
769
+ if (logoShape === "circle" || logoShape === "none") {
770
+ return Math.sqrt(dx * dx + dy * dy) < radiusModules;
771
+ }
772
+ const half = radiusModules;
773
+ return Math.abs(dx) < half && Math.abs(dy) < half;
774
+ };
775
+ const isRenderable = (r, c) => {
776
+ var _a2;
777
+ return ((_a2 = modules[r]) == null ? void 0 : _a2[c]) === true && !isEyeModule(r, c) && !isInLogoClearZone(r, c);
778
+ };
779
+ const renderDots = () => {
780
+ const elements = [];
781
+ for (let r = 0; r < matrixSize; r++) {
782
+ for (let c = 0; c < matrixSize; c++) {
783
+ if (!isRenderable(r, c)) continue;
784
+ const cx = (c + quietZone + 0.5) * cellSize;
785
+ const cy = (r + quietZone + 0.5) * cellSize;
786
+ const neighbors = {
787
+ top: isRenderable(r - 1, c),
788
+ right: isRenderable(r, c + 1),
789
+ bottom: isRenderable(r + 1, c),
790
+ left: isRenderable(r, c - 1)
791
+ };
792
+ const shape = dotPath(cx, cy, cellSize, resolvedDotShape, neighbors);
793
+ if (shape.circle) {
794
+ elements.push(
795
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx, cy, r: cellSize * 0.46, fill: resolvedDotColor }, `${r}-${c}`)
796
+ );
797
+ } else if (shape.d) {
798
+ elements.push(/* @__PURE__ */ jsxRuntime.jsx("path", { d: shape.d, fill: resolvedDotColor }, `${r}-${c}`));
799
+ }
800
+ }
801
+ }
802
+ return elements;
803
+ };
804
+ const renderCornerSquare = (cx, cy, key) => {
805
+ const outerHalf = cellSize * 3.5;
806
+ const innerHalf = cellSize * 2.5;
807
+ const strokeMid = (outerHalf + innerHalf) / 2;
808
+ const strokeWidth = outerHalf - innerHalf;
809
+ if (resolvedCornerSquareShape === "dot") {
810
+ return /* @__PURE__ */ jsxRuntime.jsx(
811
+ "circle",
812
+ {
813
+ cx,
814
+ cy,
815
+ r: strokeMid,
816
+ fill: "none",
817
+ stroke: resolvedCornerSquareColor,
818
+ strokeWidth
819
+ },
820
+ key
821
+ );
822
+ }
823
+ if (resolvedCornerSquareShape === "square") {
824
+ const d2 = `${roundedRectPath(cx, cy, outerHalf, { tl: 0, tr: 0, br: 0, bl: 0 })}${roundedRectPath(
825
+ cx,
826
+ cy,
827
+ innerHalf,
828
+ { tl: 0, tr: 0, br: 0, bl: 0 }
829
+ )}`;
830
+ return /* @__PURE__ */ jsxRuntime.jsx("path", { d: d2, fill: resolvedCornerSquareColor, fillRule: "evenodd" }, key);
831
+ }
832
+ const radius = resolvedCornerSquareShape === "classy" ? outerHalf * 0.35 : outerHalf * 0.3;
833
+ const outerRadii = resolvedCornerSquareShape === "classy" ? { tl: radius, tr: 0, br: radius, bl: 0 } : { tl: radius, tr: radius, br: radius, bl: radius };
834
+ const d = `${roundedRectPath(cx, cy, outerHalf, outerRadii)}${roundedRectPath(cx, cy, innerHalf, outerRadii)}`;
835
+ return /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: resolvedCornerSquareColor, fillRule: "evenodd" }, key);
836
+ };
837
+ const renderCornerDot = (cx, cy, key) => {
838
+ const half = cellSize * 1.5;
839
+ if (resolvedCornerDotShape === "dot") {
840
+ return /* @__PURE__ */ jsxRuntime.jsx("circle", { cx, cy, r: half, fill: resolvedCornerDotColor }, key);
841
+ }
842
+ const radius = resolvedCornerDotShape === "rounded" ? half * 0.4 : 0;
843
+ return /* @__PURE__ */ jsxRuntime.jsx(
844
+ "path",
845
+ {
846
+ d: roundedRectPath(cx, cy, half, { tl: radius, tr: radius, br: radius, bl: radius }),
847
+ fill: resolvedCornerDotColor
848
+ },
849
+ key
850
+ );
851
+ };
852
+ const renderEyes = () => {
853
+ const positions = [
854
+ { x: 0, y: 0 },
855
+ { x: matrixSize - 7, y: 0 },
856
+ { x: 0, y: matrixSize - 7 }
857
+ ];
858
+ return positions.map((pos, i) => {
859
+ const cx = (pos.x + quietZone + 3.5) * cellSize;
860
+ const cy = (pos.y + quietZone + 3.5) * cellSize;
861
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
862
+ renderCornerSquare(cx, cy, `eye-square-${i}`),
863
+ renderCornerDot(cx, cy, `eye-dot-${i}`)
864
+ ] }, `eye-${i}`);
865
+ });
866
+ };
867
+ const renderLogo = () => {
868
+ if (!logo || logoClearRadiusPx <= 0) return null;
869
+ const center = size / 2;
870
+ const backdropColor = logoBackgroundColor != null ? logoBackgroundColor : backgroundColor === "transparent" ? "#ffffff" : backgroundColor;
871
+ let backdrop = null;
872
+ if (logoShape === "circle") {
873
+ backdrop = /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: center, cy: center, r: logoClearRadiusPx, fill: backdropColor });
874
+ } else if (logoShape === "square" || logoShape === "rounded") {
875
+ const radii = logoShape === "rounded" ? { tl: logoClearRadiusPx * 0.25, tr: logoClearRadiusPx * 0.25, br: logoClearRadiusPx * 0.25, bl: logoClearRadiusPx * 0.25 } : { tl: 0, tr: 0, br: 0, bl: 0 };
876
+ backdrop = /* @__PURE__ */ jsxRuntime.jsx("path", { d: roundedRectPath(center, center, logoClearRadiusPx, radii), fill: backdropColor });
877
+ }
878
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
879
+ backdrop,
880
+ /* @__PURE__ */ jsxRuntime.jsx(
881
+ "image",
882
+ {
883
+ href: logo,
884
+ x: center - effectiveLogoImageSize / 2,
885
+ y: center - effectiveLogoImageSize / 2,
886
+ width: effectiveLogoImageSize,
887
+ height: effectiveLogoImageSize,
888
+ preserveAspectRatio: "xMidYMid meet"
889
+ }
890
+ )
891
+ ] });
892
+ };
893
+ return /* @__PURE__ */ jsxRuntime.jsxs(
894
+ "svg",
895
+ {
896
+ ref,
897
+ width: size,
898
+ height: size,
899
+ viewBox: `0 0 ${size} ${size}`,
900
+ className,
901
+ style: __spreadValues({
902
+ borderRadius: `${borderRadius}px`,
903
+ overflow: borderRadius ? "hidden" : void 0
904
+ }, style),
905
+ children: [
906
+ backgroundColor !== "transparent" && /* @__PURE__ */ jsxRuntime.jsx("rect", { x: 0, y: 0, width: size, height: size, fill: backgroundColor }),
907
+ renderDots(),
908
+ renderEyes(),
909
+ renderLogo()
910
+ ]
911
+ }
912
+ );
913
+ });
914
+ QRCode.displayName = "QRCode";
915
+ function triggerBlobDownload(blob, fileName) {
916
+ const url = URL.createObjectURL(blob);
917
+ const link = document.createElement("a");
918
+ link.href = url;
919
+ link.download = fileName;
920
+ link.click();
921
+ URL.revokeObjectURL(url);
922
+ }
923
+ function rasterizeSvgToPngBlob(svgString, widthPx, heightPx, scale, backgroundColor) {
924
+ return new Promise((resolve, reject) => {
925
+ const svgBlob = new Blob([svgString], { type: "image/svg+xml;charset=utf-8" });
926
+ const svgUrl = URL.createObjectURL(svgBlob);
927
+ const image = new Image();
928
+ image.onload = () => {
929
+ const canvas = document.createElement("canvas");
930
+ canvas.width = Math.max(1, Math.round(widthPx * scale));
931
+ canvas.height = Math.max(1, Math.round(heightPx * scale));
932
+ const ctx = canvas.getContext("2d");
933
+ URL.revokeObjectURL(svgUrl);
934
+ if (!ctx) {
935
+ reject(new Error("[@core-ease/telegram-kit] Canvas 2D context is not available in this environment."));
936
+ return;
937
+ }
938
+ ctx.fillStyle = backgroundColor;
939
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
940
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
941
+ canvas.toBlob((blob) => {
942
+ if (blob) {
943
+ resolve(blob);
944
+ } else {
945
+ reject(
946
+ new Error(
947
+ "[@core-ease/telegram-kit] Failed to export PNG. If you set a `logo`, this usually means it is a cross-origin image without CORS headers, which taints the canvas. Use a same-origin image, an image served with CORS enabled, or a data URI logo instead."
948
+ )
949
+ );
950
+ }
951
+ }, "image/png");
952
+ };
953
+ image.onerror = () => {
954
+ URL.revokeObjectURL(svgUrl);
955
+ reject(new Error("[@core-ease/telegram-kit] Failed to rasterize the QR code SVG for PNG export."));
956
+ };
957
+ image.src = svgUrl;
958
+ });
959
+ }
960
+ async function downloadQRCode(svgElement, options = {}) {
961
+ const { format = "svg", fileName = "qrcode", scale = 2, pngBackgroundColor = "#ffffff" } = options;
962
+ if (!svgElement) {
963
+ throw new Error("[@core-ease/telegram-kit] downloadQRCode: no <svg> element was provided (is the ref attached yet?).");
964
+ }
965
+ if (typeof document === "undefined") {
966
+ throw new Error("[@core-ease/telegram-kit] downloadQRCode can only run in a browser environment.");
967
+ }
968
+ const svgString = new XMLSerializer().serializeToString(svgElement);
969
+ if (format === "svg") {
970
+ const blob = new Blob([svgString], { type: "image/svg+xml" });
971
+ triggerBlobDownload(blob, `${fileName}.svg`);
972
+ return;
973
+ }
974
+ const width = svgElement.width.baseVal.value || svgElement.clientWidth || 512;
975
+ const height = svgElement.height.baseVal.value || svgElement.clientHeight || 512;
976
+ const pngBlob = await rasterizeSvgToPngBlob(svgString, width, height, scale, pngBackgroundColor);
977
+ triggerBlobDownload(pngBlob, `${fileName}.png`);
978
+ }
979
+
980
+ exports.QRCode = QRCode;
981
+ exports.downloadQRCode = downloadQRCode;
982
+ exports.encodeQRCode = encodeQRCode;
983
+ exports.qrCodeToSVG = qrCodeToSVG;