@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,382 @@
1
+ import * as React from 'react';
2
+
3
+ interface LottieKeyframe {
4
+ t: number;
5
+ s?: number[];
6
+ e?: number[];
7
+ i?: {
8
+ x: number | number[];
9
+ y: number | number[];
10
+ };
11
+ o?: {
12
+ x: number | number[];
13
+ y: number | number[];
14
+ };
15
+ h?: 0 | 1;
16
+ to?: number[];
17
+ ti?: number[];
18
+ }
19
+ interface AnimatedProperty {
20
+ a: 0 | 1;
21
+ k: number[] | number | LottieKeyframe[];
22
+ ix?: number;
23
+ x?: string;
24
+ }
25
+ interface MultiDimensional extends AnimatedProperty {
26
+ }
27
+ interface ScalarProperty extends AnimatedProperty {
28
+ }
29
+ interface ShapeProperty {
30
+ a: 0 | 1;
31
+ k: ShapeKeyframeValue | ShapeAnimKeyframe[];
32
+ }
33
+ interface ShapeKeyframeValue {
34
+ c: boolean;
35
+ v: number[][];
36
+ i: number[][];
37
+ o: number[][];
38
+ }
39
+ interface ShapeAnimKeyframe {
40
+ t: number;
41
+ s?: ShapeKeyframeValue[];
42
+ e?: ShapeKeyframeValue[];
43
+ i?: {
44
+ x: number | number[];
45
+ y: number | number[];
46
+ };
47
+ o?: {
48
+ x: number | number[];
49
+ y: number | number[];
50
+ };
51
+ h?: 0 | 1;
52
+ }
53
+ interface Transform {
54
+ a?: MultiDimensional;
55
+ p?: MultiDimensional & {
56
+ s?: boolean;
57
+ x?: AnimatedProperty;
58
+ y?: AnimatedProperty;
59
+ };
60
+ s?: MultiDimensional;
61
+ r?: ScalarProperty;
62
+ o?: ScalarProperty;
63
+ sk?: ScalarProperty;
64
+ sa?: ScalarProperty;
65
+ }
66
+ interface GradientColor {
67
+ p: number;
68
+ k: AnimatedProperty;
69
+ }
70
+ interface ShapeItemBase {
71
+ ty: string;
72
+ nm?: string;
73
+ hd?: boolean;
74
+ }
75
+ interface ShapePathItem extends ShapeItemBase {
76
+ ty: "sh";
77
+ ks: ShapeProperty;
78
+ }
79
+ interface ShapeRectItem extends ShapeItemBase {
80
+ ty: "rc";
81
+ p: MultiDimensional;
82
+ s: MultiDimensional;
83
+ r: ScalarProperty;
84
+ }
85
+ interface ShapeEllipseItem extends ShapeItemBase {
86
+ ty: "el";
87
+ p: MultiDimensional;
88
+ s: MultiDimensional;
89
+ }
90
+ interface ShapeStarItem extends ShapeItemBase {
91
+ ty: "sr";
92
+ p: MultiDimensional;
93
+ or: ScalarProperty;
94
+ os: ScalarProperty;
95
+ ir?: ScalarProperty;
96
+ is?: ScalarProperty;
97
+ r: ScalarProperty;
98
+ pt: ScalarProperty;
99
+ sy: 1 | 2;
100
+ }
101
+ interface ShapeFillItem extends ShapeItemBase {
102
+ ty: "fl";
103
+ c: MultiDimensional;
104
+ o: ScalarProperty;
105
+ r?: number;
106
+ }
107
+ interface ShapeGradientFillItem extends ShapeItemBase {
108
+ ty: "gf";
109
+ o: ScalarProperty;
110
+ s: MultiDimensional;
111
+ e: MultiDimensional;
112
+ t: 1 | 2;
113
+ g: GradientColor;
114
+ h?: ScalarProperty;
115
+ a?: ScalarProperty;
116
+ }
117
+ interface ShapeStrokeItem extends ShapeItemBase {
118
+ ty: "st";
119
+ c: MultiDimensional;
120
+ o: ScalarProperty;
121
+ w: ScalarProperty;
122
+ lc?: number;
123
+ lj?: number;
124
+ ml?: number;
125
+ d?: Array<{
126
+ n: string;
127
+ v: AnimatedProperty;
128
+ }>;
129
+ }
130
+ interface ShapeGradientStrokeItem extends ShapeItemBase {
131
+ ty: "gs";
132
+ o: ScalarProperty;
133
+ s: MultiDimensional;
134
+ e: MultiDimensional;
135
+ t: 1 | 2;
136
+ g: GradientColor;
137
+ w: ScalarProperty;
138
+ h?: ScalarProperty;
139
+ a?: ScalarProperty;
140
+ lc?: number;
141
+ lj?: number;
142
+ ml?: number;
143
+ d?: Array<{
144
+ n: string;
145
+ v: AnimatedProperty;
146
+ }>;
147
+ }
148
+ interface ShapeGroupItem extends ShapeItemBase {
149
+ ty: "gr";
150
+ it: ShapeItem[];
151
+ }
152
+ interface ShapeTrimItem extends ShapeItemBase {
153
+ ty: "tm";
154
+ s: ScalarProperty;
155
+ e: ScalarProperty;
156
+ o: ScalarProperty;
157
+ m?: 1 | 2;
158
+ }
159
+ interface ShapeRepeaterItem extends ShapeItemBase {
160
+ ty: "rp";
161
+ c: ScalarProperty;
162
+ o: ScalarProperty;
163
+ tr: {
164
+ p: MultiDimensional;
165
+ a: MultiDimensional;
166
+ s: MultiDimensional;
167
+ r: ScalarProperty;
168
+ so?: ScalarProperty;
169
+ eo?: ScalarProperty;
170
+ };
171
+ }
172
+ interface ShapeMergeItem extends ShapeItemBase {
173
+ ty: "mm";
174
+ mm: number;
175
+ }
176
+ interface ShapeTransformItem extends ShapeItemBase, Transform {
177
+ ty: "tr";
178
+ }
179
+ type ShapeItem = ShapePathItem | ShapeRectItem | ShapeEllipseItem | ShapeStarItem | ShapeFillItem | ShapeGradientFillItem | ShapeStrokeItem | ShapeGradientStrokeItem | ShapeGroupItem | ShapeTrimItem | ShapeRepeaterItem | ShapeMergeItem | ShapeTransformItem;
180
+ interface MaskProperty {
181
+ inv: boolean;
182
+ mode: "a" | "s" | "i" | "l" | "d" | "n";
183
+ pt: ShapeProperty;
184
+ o: ScalarProperty;
185
+ }
186
+ interface LottieLayer {
187
+ ty: number;
188
+ ind?: number;
189
+ parent?: number;
190
+ nm?: string;
191
+ ip: number;
192
+ op: number;
193
+ st: number;
194
+ sr?: number;
195
+ ks: Transform;
196
+ shapes?: ShapeItem[];
197
+ refId?: string;
198
+ w?: number;
199
+ h?: number;
200
+ sc?: string;
201
+ sw?: number;
202
+ sh?: number;
203
+ masksProperties?: MaskProperty[];
204
+ tt?: number;
205
+ td?: number;
206
+ bm?: number;
207
+ hd?: boolean;
208
+ ao?: number;
209
+ tm?: AnimatedProperty;
210
+ }
211
+ interface LottieAsset {
212
+ id: string;
213
+ layers?: LottieLayer[];
214
+ w?: number;
215
+ h?: number;
216
+ u?: string;
217
+ p?: string;
218
+ e?: number;
219
+ }
220
+ interface LottieAnimation {
221
+ v: string;
222
+ fr: number;
223
+ ip: number;
224
+ op: number;
225
+ w: number;
226
+ h: number;
227
+ nm?: string;
228
+ ddd?: number;
229
+ assets?: LottieAsset[];
230
+ layers: LottieLayer[];
231
+ markers?: Array<{
232
+ tm: number;
233
+ cm: string;
234
+ dr: number;
235
+ }>;
236
+ tgs?: number;
237
+ }
238
+
239
+ type PlayerState = "loading" | "playing" | "paused" | "stopped" | "frozen" | "error" | "destroyed";
240
+ type PlayMode = "normal" | "bounce";
241
+ interface PlayerEventMap {
242
+ ready: void;
243
+ play: void;
244
+ pause: void;
245
+ stop: void;
246
+ complete: void;
247
+ loop: void;
248
+ frame: {
249
+ frame: number;
250
+ progress: number;
251
+ };
252
+ error: {
253
+ errors?: string[];
254
+ };
255
+ destroyed: void;
256
+ }
257
+ type Listener<K extends keyof PlayerEventMap> = (detail: PlayerEventMap[K]) => void;
258
+ interface AnimationOptions {
259
+ canvas: HTMLCanvasElement;
260
+ loop: boolean | number;
261
+ autoplay: boolean;
262
+ speed: number;
263
+ direction: 1 | -1;
264
+ mode: PlayMode;
265
+ segments?: [number, number];
266
+ }
267
+ declare class LottieAnimationController {
268
+ private doc;
269
+ private canvas;
270
+ private ctx;
271
+ private state;
272
+ private currentFrame;
273
+ private direction;
274
+ private speed;
275
+ private loop;
276
+ private mode;
277
+ private loopsCompleted;
278
+ private segment;
279
+ private rafHandle;
280
+ private lastTs;
281
+ private shapeScratch;
282
+ private listeners;
283
+ constructor(options: AnimationOptions);
284
+ on<K extends keyof PlayerEventMap>(event: K, fn: Listener<K>): () => void;
285
+ private emit;
286
+ setDocument(doc: LottieAnimation): void;
287
+ setError(errors?: string[]): void;
288
+ private getBounds;
289
+ resize(width: number, height: number): void;
290
+ setSegment(segment: [number, number] | null): void;
291
+ play(): void;
292
+ pause(): void;
293
+ freeze(): void;
294
+ unfreeze(): void;
295
+ stop(): void;
296
+ destroy(): void;
297
+ togglePlay(): void;
298
+ setSpeed(speed: number): void;
299
+ setDirection(direction: 1 | -1): void;
300
+ setLoop(loop: boolean | number): void;
301
+ setMode(mode: PlayMode): void;
302
+ getCurrentFrame(): number;
303
+ getState(): PlayerState;
304
+ getTotalFrames(): number;
305
+ seek(value: number | string): void;
306
+ private startLoop;
307
+ private stopLoop;
308
+ private advance;
309
+ private finishPlayback;
310
+ private emitFrameEvent;
311
+ private getShapeScratch;
312
+ private renderCurrentFrame;
313
+ }
314
+
315
+ type TgsSource = string | ArrayBuffer | Uint8Array | LottieAnimation | Record<string, unknown>;
316
+ declare function loadTgsSource(src: TgsSource): Promise<LottieAnimation>;
317
+
318
+ interface AnimationPlayerHandle {
319
+ play(): void;
320
+ pause(): void;
321
+ stop(): void;
322
+ togglePlay(): void;
323
+ seek(value: number | string): void;
324
+ setSpeed(speed: number): void;
325
+ setDirection(direction: 1 | -1): void;
326
+ setLoop(loop: boolean | number): void;
327
+ setMode(mode: PlayMode): void;
328
+ setSegment(segment: [number, number] | null): void;
329
+ getCurrentFrame(): number;
330
+ getTotalFrames(): number;
331
+ getState(): PlayerState;
332
+ getAnimationData(): LottieAnimation | null;
333
+ getCanvas(): HTMLCanvasElement | null;
334
+ }
335
+ interface AnimationPlayerBaseProps {
336
+ src: TgsSource;
337
+ autoplay?: boolean;
338
+ loop?: boolean | number;
339
+ speed?: number;
340
+ direction?: 1 | -1;
341
+ mode?: PlayMode;
342
+ segments?: [number, number];
343
+ hover?: boolean;
344
+ pauseWhenOffscreen?: boolean;
345
+ width?: number | string;
346
+ height?: number | string;
347
+ className?: string;
348
+ style?: React.CSSProperties;
349
+ ariaLabel?: string;
350
+ onReady?: () => void;
351
+ onPlay?: () => void;
352
+ onPause?: () => void;
353
+ onStop?: () => void;
354
+ onComplete?: () => void;
355
+ onLoop?: () => void;
356
+ onFrame?: (info: {
357
+ frame: number;
358
+ progress: number;
359
+ }) => void;
360
+ onError?: (errors?: string[]) => void;
361
+ validate?: (doc: LottieAnimation) => string[];
362
+ }
363
+
364
+ interface EngineImageCache {
365
+ get(key: string): HTMLImageElement | undefined;
366
+ set(key: string, img: HTMLImageElement): void;
367
+ }
368
+ interface RenderOptions {
369
+ ctx: CanvasRenderingContext2D;
370
+ canvasWidth: number;
371
+ canvasHeight: number;
372
+ imageCache: EngineImageCache;
373
+ onAssetLoaded?: () => void;
374
+ warnOnce: (key: string, message: string) => void;
375
+ getShapeScratch?: (w: number, h: number) => {
376
+ canvas: HTMLCanvasElement | OffscreenCanvas;
377
+ ctx: CanvasRenderingContext2D;
378
+ };
379
+ }
380
+ declare function renderDocumentFrame(doc: LottieAnimation, frame: number, opts: RenderOptions): void;
381
+
382
+ export { type AnimationPlayerBaseProps as A, type LottieAnimation as L, type PlayMode as P, type TgsSource as T, LottieAnimationController as a, type PlayerState as b, type AnimationPlayerHandle as c, loadTgsSource as l, renderDocumentFrame as r };
@@ -0,0 +1,61 @@
1
+ declare class TelegramFormattedText {
2
+ readonly raw: string;
3
+ constructor(raw: string);
4
+ toString(): string;
5
+ }
6
+ type TextPart = string | TelegramFormattedText;
7
+ declare function escapeMarkdownV2(text: string): string;
8
+ declare function escapeMarkdownV2Code(text: string): string;
9
+ declare function escapeMarkdownV2LinkUrl(url: string): string;
10
+ declare function escapeHTML(text: string): string;
11
+ declare function escapeHTMLAttribute(text: string): string;
12
+ declare const md: {
13
+ escape: typeof escapeMarkdownV2;
14
+ escapeCode: typeof escapeMarkdownV2Code;
15
+ escapeLinkUrl: typeof escapeMarkdownV2LinkUrl;
16
+ text: (...parts: TextPart[]) => TelegramFormattedText;
17
+ bold: (...parts: TextPart[]) => TelegramFormattedText;
18
+ italic: (...parts: TextPart[]) => TelegramFormattedText;
19
+ underline: (...parts: TextPart[]) => TelegramFormattedText;
20
+ strikethrough: (...parts: TextPart[]) => TelegramFormattedText;
21
+ spoiler: (...parts: TextPart[]) => TelegramFormattedText;
22
+ code: (text: string) => TelegramFormattedText;
23
+ pre: (text: string, language?: string) => TelegramFormattedText;
24
+ link: (url: string, ...parts: TextPart[]) => TelegramFormattedText;
25
+ mentionUser: (userId: number, ...parts: TextPart[]) => TelegramFormattedText;
26
+ customEmoji: (emojiId: string, fallbackEmoji: string) => TelegramFormattedText;
27
+ raw: (raw: string) => TelegramFormattedText;
28
+ };
29
+ declare const html: {
30
+ escape: typeof escapeHTML;
31
+ escapeAttribute: typeof escapeHTMLAttribute;
32
+ text: (...parts: TextPart[]) => TelegramFormattedText;
33
+ bold: (...parts: TextPart[]) => TelegramFormattedText;
34
+ italic: (...parts: TextPart[]) => TelegramFormattedText;
35
+ underline: (...parts: TextPart[]) => TelegramFormattedText;
36
+ strikethrough: (...parts: TextPart[]) => TelegramFormattedText;
37
+ spoiler: (...parts: TextPart[]) => TelegramFormattedText;
38
+ code: (text: string) => TelegramFormattedText;
39
+ pre: (text: string, language?: string) => TelegramFormattedText;
40
+ link: (url: string, ...parts: TextPart[]) => TelegramFormattedText;
41
+ mentionUser: (userId: number, ...parts: TextPart[]) => TelegramFormattedText;
42
+ blockquote: (...parts: TextPart[]) => TelegramFormattedText;
43
+ expandableBlockquote: (...parts: TextPart[]) => TelegramFormattedText;
44
+ customEmoji: (emojiId: string, fallbackEmoji: string) => TelegramFormattedText;
45
+ raw: (rawHtml: string) => TelegramFormattedText;
46
+ };
47
+ declare const TELEGRAM_TEXT_LIMITS: {
48
+ readonly MESSAGE: 4096;
49
+ readonly CAPTION: 1024;
50
+ readonly BUTTON_TEXT: 64;
51
+ readonly CALLBACK_DATA: 64;
52
+ readonly START_PARAMETER: 64;
53
+ readonly BOT_DESCRIPTION: 512;
54
+ readonly BOT_SHORT_DESCRIPTION: 120;
55
+ readonly CHAT_TITLE: 128;
56
+ readonly POLL_QUESTION: 300;
57
+ readonly POLL_OPTION: 100;
58
+ };
59
+ declare function truncateText(text: string, maxLength: number, ellipsis?: string): string;
60
+
61
+ export { TELEGRAM_TEXT_LIMITS, TelegramFormattedText, escapeHTML, escapeHTMLAttribute, escapeMarkdownV2, escapeMarkdownV2Code, escapeMarkdownV2LinkUrl, html, md, truncateText };
@@ -0,0 +1,61 @@
1
+ declare class TelegramFormattedText {
2
+ readonly raw: string;
3
+ constructor(raw: string);
4
+ toString(): string;
5
+ }
6
+ type TextPart = string | TelegramFormattedText;
7
+ declare function escapeMarkdownV2(text: string): string;
8
+ declare function escapeMarkdownV2Code(text: string): string;
9
+ declare function escapeMarkdownV2LinkUrl(url: string): string;
10
+ declare function escapeHTML(text: string): string;
11
+ declare function escapeHTMLAttribute(text: string): string;
12
+ declare const md: {
13
+ escape: typeof escapeMarkdownV2;
14
+ escapeCode: typeof escapeMarkdownV2Code;
15
+ escapeLinkUrl: typeof escapeMarkdownV2LinkUrl;
16
+ text: (...parts: TextPart[]) => TelegramFormattedText;
17
+ bold: (...parts: TextPart[]) => TelegramFormattedText;
18
+ italic: (...parts: TextPart[]) => TelegramFormattedText;
19
+ underline: (...parts: TextPart[]) => TelegramFormattedText;
20
+ strikethrough: (...parts: TextPart[]) => TelegramFormattedText;
21
+ spoiler: (...parts: TextPart[]) => TelegramFormattedText;
22
+ code: (text: string) => TelegramFormattedText;
23
+ pre: (text: string, language?: string) => TelegramFormattedText;
24
+ link: (url: string, ...parts: TextPart[]) => TelegramFormattedText;
25
+ mentionUser: (userId: number, ...parts: TextPart[]) => TelegramFormattedText;
26
+ customEmoji: (emojiId: string, fallbackEmoji: string) => TelegramFormattedText;
27
+ raw: (raw: string) => TelegramFormattedText;
28
+ };
29
+ declare const html: {
30
+ escape: typeof escapeHTML;
31
+ escapeAttribute: typeof escapeHTMLAttribute;
32
+ text: (...parts: TextPart[]) => TelegramFormattedText;
33
+ bold: (...parts: TextPart[]) => TelegramFormattedText;
34
+ italic: (...parts: TextPart[]) => TelegramFormattedText;
35
+ underline: (...parts: TextPart[]) => TelegramFormattedText;
36
+ strikethrough: (...parts: TextPart[]) => TelegramFormattedText;
37
+ spoiler: (...parts: TextPart[]) => TelegramFormattedText;
38
+ code: (text: string) => TelegramFormattedText;
39
+ pre: (text: string, language?: string) => TelegramFormattedText;
40
+ link: (url: string, ...parts: TextPart[]) => TelegramFormattedText;
41
+ mentionUser: (userId: number, ...parts: TextPart[]) => TelegramFormattedText;
42
+ blockquote: (...parts: TextPart[]) => TelegramFormattedText;
43
+ expandableBlockquote: (...parts: TextPart[]) => TelegramFormattedText;
44
+ customEmoji: (emojiId: string, fallbackEmoji: string) => TelegramFormattedText;
45
+ raw: (rawHtml: string) => TelegramFormattedText;
46
+ };
47
+ declare const TELEGRAM_TEXT_LIMITS: {
48
+ readonly MESSAGE: 4096;
49
+ readonly CAPTION: 1024;
50
+ readonly BUTTON_TEXT: 64;
51
+ readonly CALLBACK_DATA: 64;
52
+ readonly START_PARAMETER: 64;
53
+ readonly BOT_DESCRIPTION: 512;
54
+ readonly BOT_SHORT_DESCRIPTION: 120;
55
+ readonly CHAT_TITLE: 128;
56
+ readonly POLL_QUESTION: 300;
57
+ readonly POLL_OPTION: 100;
58
+ };
59
+ declare function truncateText(text: string, maxLength: number, ellipsis?: string): string;
60
+
61
+ export { TELEGRAM_TEXT_LIMITS, TelegramFormattedText, escapeHTML, escapeHTMLAttribute, escapeMarkdownV2, escapeMarkdownV2Code, escapeMarkdownV2LinkUrl, html, md, truncateText };
@@ -0,0 +1,121 @@
1
+ 'use strict';
2
+
3
+ // src/utils/format.ts
4
+ var TelegramFormattedText = class {
5
+ constructor(raw) {
6
+ this.raw = raw;
7
+ }
8
+ toString() {
9
+ return this.raw;
10
+ }
11
+ };
12
+ function isFragment(part) {
13
+ return part instanceof TelegramFormattedText;
14
+ }
15
+ function joinParts(parts, escape) {
16
+ return parts.map((part) => isFragment(part) ? part.raw : escape(part)).join("");
17
+ }
18
+ var MARKDOWN_V2_RESERVED = /[_*[\]()~`>#+\-=|{}.!\\]/g;
19
+ var MARKDOWN_V2_CODE_RESERVED = /[`\\]/g;
20
+ var MARKDOWN_V2_LINK_URL_RESERVED = /[)\\]/g;
21
+ function escapeMarkdownV2(text) {
22
+ return text.replace(MARKDOWN_V2_RESERVED, (ch) => `\\${ch}`);
23
+ }
24
+ function escapeMarkdownV2Code(text) {
25
+ return text.replace(MARKDOWN_V2_CODE_RESERVED, (ch) => `\\${ch}`);
26
+ }
27
+ function escapeMarkdownV2LinkUrl(url) {
28
+ return url.replace(MARKDOWN_V2_LINK_URL_RESERVED, (ch) => `\\${ch}`);
29
+ }
30
+ function createMarkdownV2Formatter() {
31
+ const wrap = (raw) => new TelegramFormattedText(raw);
32
+ const t = (parts) => joinParts(parts, escapeMarkdownV2);
33
+ return {
34
+ escape: escapeMarkdownV2,
35
+ escapeCode: escapeMarkdownV2Code,
36
+ escapeLinkUrl: escapeMarkdownV2LinkUrl,
37
+ text: (...parts) => wrap(t(parts)),
38
+ bold: (...parts) => wrap(`*${t(parts)}*`),
39
+ italic: (...parts) => wrap(`_${t(parts)}_`),
40
+ underline: (...parts) => wrap(`__${t(parts)}__`),
41
+ strikethrough: (...parts) => wrap(`~${t(parts)}~`),
42
+ spoiler: (...parts) => wrap(`||${t(parts)}||`),
43
+ code: (text) => wrap(`\`${escapeMarkdownV2Code(text)}\``),
44
+ pre: (text, language) => wrap(`\`\`\`${language != null ? language : ""}
45
+ ${escapeMarkdownV2Code(text)}
46
+ \`\`\``),
47
+ link: (url, ...parts) => wrap(`[${t(parts)}](${escapeMarkdownV2LinkUrl(url)})`),
48
+ mentionUser: (userId, ...parts) => wrap(`[${t(parts)}](tg://user?id=${userId})`),
49
+ customEmoji: (emojiId, fallbackEmoji) => wrap(`![${escapeMarkdownV2(fallbackEmoji)}](tg://emoji?id=${emojiId})`),
50
+ raw: (raw) => wrap(raw)
51
+ };
52
+ }
53
+ function escapeHTML(text) {
54
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
55
+ }
56
+ function escapeHTMLAttribute(text) {
57
+ return escapeHTML(text).replace(/"/g, "&quot;");
58
+ }
59
+ function createHtmlFormatter() {
60
+ const wrap = (raw) => new TelegramFormattedText(raw);
61
+ const t = (parts) => joinParts(parts, escapeHTML);
62
+ return {
63
+ escape: escapeHTML,
64
+ escapeAttribute: escapeHTMLAttribute,
65
+ text: (...parts) => wrap(t(parts)),
66
+ bold: (...parts) => wrap(`<b>${t(parts)}</b>`),
67
+ italic: (...parts) => wrap(`<i>${t(parts)}</i>`),
68
+ underline: (...parts) => wrap(`<u>${t(parts)}</u>`),
69
+ strikethrough: (...parts) => wrap(`<s>${t(parts)}</s>`),
70
+ spoiler: (...parts) => wrap(`<tg-spoiler>${t(parts)}</tg-spoiler>`),
71
+ code: (text) => wrap(`<code>${escapeHTML(text)}</code>`),
72
+ pre: (text, language) => wrap(
73
+ language ? `<pre><code class="language-${escapeHTMLAttribute(language)}">${escapeHTML(text)}</code></pre>` : `<pre>${escapeHTML(text)}</pre>`
74
+ ),
75
+ link: (url, ...parts) => wrap(`<a href="${escapeHTMLAttribute(url)}">${t(parts)}</a>`),
76
+ mentionUser: (userId, ...parts) => wrap(`<a href="tg://user?id=${userId}">${t(parts)}</a>`),
77
+ blockquote: (...parts) => wrap(`<blockquote>${t(parts)}</blockquote>`),
78
+ expandableBlockquote: (...parts) => wrap(`<blockquote expandable>${t(parts)}</blockquote>`),
79
+ customEmoji: (emojiId, fallbackEmoji) => wrap(`<tg-emoji emoji-id="${escapeHTMLAttribute(emojiId)}">${escapeHTML(fallbackEmoji)}</tg-emoji>`),
80
+ raw: (rawHtml) => wrap(rawHtml)
81
+ };
82
+ }
83
+ var md = createMarkdownV2Formatter();
84
+ var html = createHtmlFormatter();
85
+ var TELEGRAM_TEXT_LIMITS = {
86
+ MESSAGE: 4096,
87
+ CAPTION: 1024,
88
+ BUTTON_TEXT: 64,
89
+ CALLBACK_DATA: 64,
90
+ START_PARAMETER: 64,
91
+ BOT_DESCRIPTION: 512,
92
+ BOT_SHORT_DESCRIPTION: 120,
93
+ CHAT_TITLE: 128,
94
+ POLL_QUESTION: 300,
95
+ POLL_OPTION: 100
96
+ };
97
+ function isHighSurrogate(code) {
98
+ return code >= 55296 && code <= 56319;
99
+ }
100
+ function isLowSurrogate(code) {
101
+ return code >= 56320 && code <= 57343;
102
+ }
103
+ function truncateText(text, maxLength, ellipsis = "\u2026") {
104
+ if (text.length <= maxLength) return text;
105
+ let cut = Math.max(0, maxLength - ellipsis.length);
106
+ if (cut > 0 && isHighSurrogate(text.charCodeAt(cut - 1)) && isLowSurrogate(text.charCodeAt(cut))) {
107
+ cut -= 1;
108
+ }
109
+ return text.slice(0, cut) + ellipsis;
110
+ }
111
+
112
+ exports.TELEGRAM_TEXT_LIMITS = TELEGRAM_TEXT_LIMITS;
113
+ exports.TelegramFormattedText = TelegramFormattedText;
114
+ exports.escapeHTML = escapeHTML;
115
+ exports.escapeHTMLAttribute = escapeHTMLAttribute;
116
+ exports.escapeMarkdownV2 = escapeMarkdownV2;
117
+ exports.escapeMarkdownV2Code = escapeMarkdownV2Code;
118
+ exports.escapeMarkdownV2LinkUrl = escapeMarkdownV2LinkUrl;
119
+ exports.html = html;
120
+ exports.md = md;
121
+ exports.truncateText = truncateText;