@mtcute/core 0.30.0 → 0.30.2
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.
- package/client.cjs +8 -0
- package/client.js +8 -0
- package/highlevel/client.d.cts +63 -1
- package/highlevel/client.d.ts +63 -1
- package/highlevel/methods/files/download-iterable.cjs +80 -45
- package/highlevel/methods/files/download-iterable.js +80 -45
- package/highlevel/methods/files/normalize-input-media.cjs +9 -1
- package/highlevel/methods/files/normalize-input-media.js +10 -2
- package/highlevel/methods/files/upload-file.cjs +6 -1
- package/highlevel/methods/files/upload-file.js +6 -1
- package/highlevel/methods/messages/create-rich-streaming-draft.cjs +39 -0
- package/highlevel/methods/messages/create-rich-streaming-draft.d.cts +42 -0
- package/highlevel/methods/messages/create-rich-streaming-draft.d.ts +42 -0
- package/highlevel/methods/messages/create-rich-streaming-draft.js +34 -0
- package/highlevel/methods/messages/normalize-rich-message.cjs +168 -0
- package/highlevel/methods/messages/normalize-rich-message.d.cts +10 -0
- package/highlevel/methods/messages/normalize-rich-message.d.ts +10 -0
- package/highlevel/methods/messages/normalize-rich-message.js +163 -0
- package/highlevel/methods/messages/send-common.cjs +3 -2
- package/highlevel/methods/messages/send-common.d.cts +4 -1
- package/highlevel/methods/messages/send-common.d.ts +4 -1
- package/highlevel/methods/messages/send-common.js +3 -2
- package/highlevel/methods/messages/send-rich-message.cjs +49 -0
- package/highlevel/methods/messages/send-rich-message.d.cts +38 -0
- package/highlevel/methods/messages/send-rich-message.d.ts +38 -0
- package/highlevel/methods/messages/send-rich-message.js +44 -0
- package/highlevel/methods.d.cts +3 -0
- package/highlevel/methods.d.ts +3 -0
- package/highlevel/types/bots/inline-message/factories.cjs +14 -0
- package/highlevel/types/bots/inline-message/factories.d.cts +9 -1
- package/highlevel/types/bots/inline-message/factories.d.ts +9 -1
- package/highlevel/types/bots/inline-message/factories.js +14 -0
- package/highlevel/types/bots/inline-message/types.d.cts +17 -1
- package/highlevel/types/bots/inline-message/types.d.ts +17 -1
- package/highlevel/types/files/utils.d.cts +9 -0
- package/highlevel/types/files/utils.d.ts +9 -0
- package/highlevel/types/media/input-media/types.d.cts +1 -1
- package/highlevel/types/media/input-media/types.d.ts +1 -1
- package/highlevel/types/messages/index.d.cts +1 -1
- package/highlevel/types/messages/index.d.ts +1 -1
- package/highlevel/types/messages/message.cjs +1 -1
- package/highlevel/types/messages/message.d.cts +1 -1
- package/highlevel/types/messages/message.d.ts +1 -1
- package/highlevel/types/messages/message.js +1 -1
- package/highlevel/types/messages/rich/index.d.cts +4 -0
- package/highlevel/types/messages/rich/index.d.ts +4 -0
- package/highlevel/types/messages/rich/inner.cjs +219 -0
- package/highlevel/types/messages/rich/inner.d.cts +127 -0
- package/highlevel/types/messages/rich/inner.d.ts +127 -0
- package/highlevel/types/messages/rich/inner.js +214 -0
- package/highlevel/types/messages/{rich-message.cjs → rich/rich-message.cjs} +6 -6
- package/highlevel/types/messages/{rich-message.d.cts → rich/rich-message.d.cts} +5 -5
- package/highlevel/types/messages/{rich-message.d.ts → rich/rich-message.d.ts} +5 -5
- package/highlevel/types/messages/{rich-message.js → rich/rich-message.js} +6 -6
- package/highlevel/types/messages/rich/types.d.cts +76 -0
- package/highlevel/types/messages/rich/types.d.ts +76 -0
- package/highlevel/updates/manager.cjs +10 -169
- package/highlevel/updates/manager.js +10 -169
- package/highlevel/utils/entities.cjs +176 -0
- package/highlevel/utils/entities.d.cts +18 -0
- package/highlevel/utils/entities.d.ts +18 -0
- package/highlevel/utils/entities.js +177 -1
- package/highlevel/utils/index.d.cts +1 -0
- package/highlevel/utils/index.d.ts +1 -0
- package/highlevel/utils/walk-page-blocks.cjs +164 -0
- package/highlevel/utils/walk-page-blocks.d.cts +9 -0
- package/highlevel/utils/walk-page-blocks.d.ts +9 -0
- package/highlevel/utils/walk-page-blocks.js +159 -0
- package/index.cjs +3 -1
- package/index.js +3 -1
- package/methods.cjs +4 -0
- package/methods.js +4 -0
- package/network/authorization.cjs +1 -1
- package/network/authorization.js +1 -1
- package/network/delay-gate.cjs +29 -0
- package/network/delay-gate.d.cts +5 -0
- package/network/delay-gate.d.ts +5 -0
- package/network/delay-gate.js +24 -0
- package/network/delay-gate.test.d.cts +1 -0
- package/network/delay-gate.test.d.ts +1 -0
- package/network/message-id-store.cjs +30 -0
- package/network/message-id-store.d.cts +7 -0
- package/network/message-id-store.d.ts +7 -0
- package/network/message-id-store.js +25 -0
- package/network/message-id-store.test.d.cts +1 -0
- package/network/message-id-store.test.d.ts +1 -0
- package/network/middlewares/bundle.cjs +2 -0
- package/network/middlewares/bundle.d.cts +1 -0
- package/network/middlewares/bundle.d.ts +1 -0
- package/network/middlewares/bundle.js +2 -0
- package/network/middlewares/default.cjs +6 -1
- package/network/middlewares/default.js +6 -1
- package/network/middlewares/flood-waiter.test.d.cts +1 -0
- package/network/middlewares/flood-waiter.test.d.ts +1 -0
- package/network/middlewares/internal-errors.test.d.cts +1 -0
- package/network/middlewares/internal-errors.test.d.ts +1 -0
- package/network/middlewares/media-throttle.cjs +65 -0
- package/network/middlewares/media-throttle.d.cts +5 -0
- package/network/middlewares/media-throttle.d.ts +5 -0
- package/network/middlewares/media-throttle.js +60 -0
- package/network/middlewares/media-throttle.test.d.cts +1 -0
- package/network/middlewares/media-throttle.test.d.ts +1 -0
- package/network/middlewares/on-error.test.d.cts +1 -0
- package/network/middlewares/on-error.test.d.ts +1 -0
- package/network/middlewares/on-method.test.d.cts +1 -0
- package/network/middlewares/on-method.test.d.ts +1 -0
- package/network/mtproto-session.cjs +9 -2
- package/network/mtproto-session.d.cts +5 -2
- package/network/mtproto-session.d.ts +5 -2
- package/network/mtproto-session.js +9 -2
- package/network/mtproxy/_fake-tls.cjs +169 -107
- package/network/mtproxy/_fake-tls.js +169 -107
- package/network/mtproxy/_fake-tls.test.d.cts +1 -0
- package/network/mtproxy/_fake-tls.test.d.ts +1 -0
- package/network/multi-session-connection.cjs +7 -0
- package/network/multi-session-connection.d.cts +2 -0
- package/network/multi-session-connection.d.ts +2 -0
- package/network/multi-session-connection.js +7 -0
- package/network/network-manager.cjs +7 -1
- package/network/network-manager.js +7 -1
- package/network/resource-limiter.cjs +60 -0
- package/network/resource-limiter.d.cts +11 -0
- package/network/resource-limiter.d.ts +11 -0
- package/network/resource-limiter.js +55 -0
- package/network/resource-limiter.test.d.cts +1 -0
- package/network/resource-limiter.test.d.ts +1 -0
- package/network/server-salt.cjs +7 -3
- package/network/server-salt.d.cts +2 -0
- package/network/server-salt.d.ts +2 -0
- package/network/server-salt.js +7 -3
- package/network/session-connection.cjs +106 -20
- package/network/session-connection.d.cts +11 -0
- package/network/session-connection.d.ts +11 -0
- package/network/session-connection.js +106 -20
- package/package.json +1 -1
- package/tl/api-schema.json +1 -1
- package/tl/binary/reader.cjs +115 -109
- package/tl/binary/reader.js +115 -109
- package/tl/binary/writer.cjs +243 -245
- package/tl/binary/writer.js +243 -245
- package/tl/index.d.cts +227 -216
- package/tl/index.d.ts +227 -216
- package/tl/inner-tl.cjs +3 -1
- package/tl/inner-tl.js +3 -1
- package/types/utils.d.cts +4 -0
- package/types/utils.d.ts +4 -0
- package/utils.cjs +4 -0
- package/utils.js +5 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[@mtcute/core] CommonJS bundles are deprecated. They will be removed completely in one of the upcoming releases. No support is provided for CommonJS users. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
+
console.warn("[@mtcute/core] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
+
}
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
const Long = require("long");
|
|
9
|
+
const entities = require("../../../utils/entities.cjs");
|
|
10
|
+
const RICH_EMPTY = { _: "textEmpty" };
|
|
11
|
+
function normalizeRichText(text) {
|
|
12
|
+
if (typeof text === "string") return { _: "textPlain", text };
|
|
13
|
+
if ("_" in text) return text;
|
|
14
|
+
return entities.textWithEntitiesToRichText(text);
|
|
15
|
+
}
|
|
16
|
+
function normalizeCaption(input) {
|
|
17
|
+
if (input == null) return { _: "pageCaption", text: RICH_EMPTY, credit: RICH_EMPTY };
|
|
18
|
+
if (typeof input === "string" || "_" in input || "entities" in input) {
|
|
19
|
+
return { _: "pageCaption", text: normalizeRichText(input), credit: RICH_EMPTY };
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
_: "pageCaption",
|
|
23
|
+
text: input.text != null ? normalizeRichText(input.text) : RICH_EMPTY,
|
|
24
|
+
credit: "credit" in input && input.credit != null ? normalizeRichText(input.credit) : RICH_EMPTY
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function footer(text) {
|
|
28
|
+
return { _: "pageBlockFooter", text: normalizeRichText(text) };
|
|
29
|
+
}
|
|
30
|
+
function paragraph(text) {
|
|
31
|
+
return { _: "pageBlockParagraph", text: normalizeRichText(text) };
|
|
32
|
+
}
|
|
33
|
+
function thinking(text) {
|
|
34
|
+
return { _: "pageBlockThinking", text: normalizeRichText(text) };
|
|
35
|
+
}
|
|
36
|
+
function heading(level, text) {
|
|
37
|
+
return { _: `pageBlockHeading${level}`, text: normalizeRichText(text) };
|
|
38
|
+
}
|
|
39
|
+
function divider() {
|
|
40
|
+
return { _: "pageBlockDivider" };
|
|
41
|
+
}
|
|
42
|
+
function anchor(name) {
|
|
43
|
+
return { _: "pageBlockAnchor", name };
|
|
44
|
+
}
|
|
45
|
+
function math(source) {
|
|
46
|
+
return { _: "pageBlockMath", source };
|
|
47
|
+
}
|
|
48
|
+
function preformatted(text, language = "") {
|
|
49
|
+
return { _: "pageBlockPreformatted", text: normalizeRichText(text), language };
|
|
50
|
+
}
|
|
51
|
+
function blockquote(content, caption) {
|
|
52
|
+
const normalizedCaption = caption != null ? normalizeRichText(caption) : RICH_EMPTY;
|
|
53
|
+
if (Array.isArray(content)) {
|
|
54
|
+
return { _: "pageBlockBlockquoteBlocks", blocks: content, caption: normalizedCaption };
|
|
55
|
+
}
|
|
56
|
+
return { _: "pageBlockBlockquote", text: normalizeRichText(content), caption: normalizedCaption };
|
|
57
|
+
}
|
|
58
|
+
function pullquote(text, caption) {
|
|
59
|
+
return {
|
|
60
|
+
_: "pageBlockPullquote",
|
|
61
|
+
text: normalizeRichText(text),
|
|
62
|
+
caption: caption != null ? normalizeRichText(caption) : RICH_EMPTY
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function map(params) {
|
|
66
|
+
return {
|
|
67
|
+
_: "inputPageBlockMap",
|
|
68
|
+
geo: { _: "inputGeoPoint", lat: params.latitude, long: params.longitude },
|
|
69
|
+
zoom: params.zoom,
|
|
70
|
+
w: params.width,
|
|
71
|
+
h: params.height,
|
|
72
|
+
caption: normalizeCaption(params.caption)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function listItem(content, params = {}) {
|
|
76
|
+
if (Array.isArray(content)) {
|
|
77
|
+
return {
|
|
78
|
+
_: "pageListItemBlocks",
|
|
79
|
+
blocks: content,
|
|
80
|
+
checkbox: params.checkbox,
|
|
81
|
+
checked: params.checked
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
_: "pageListItemText",
|
|
86
|
+
text: normalizeRichText(content),
|
|
87
|
+
checkbox: params.checkbox,
|
|
88
|
+
checked: params.checked
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function list(items) {
|
|
92
|
+
return { _: "pageBlockList", items };
|
|
93
|
+
}
|
|
94
|
+
function orderedListItem(content, params = {}) {
|
|
95
|
+
if (Array.isArray(content)) {
|
|
96
|
+
return {
|
|
97
|
+
_: "pageListOrderedItemBlocks",
|
|
98
|
+
blocks: content,
|
|
99
|
+
checkbox: params.checkbox,
|
|
100
|
+
checked: params.checked,
|
|
101
|
+
num: params.num,
|
|
102
|
+
value: params.value,
|
|
103
|
+
type: params.type
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
_: "pageListOrderedItemText",
|
|
108
|
+
text: normalizeRichText(content),
|
|
109
|
+
checkbox: params.checkbox,
|
|
110
|
+
checked: params.checked,
|
|
111
|
+
num: params.num,
|
|
112
|
+
value: params.value,
|
|
113
|
+
type: params.type
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function orderedList(items, params = {}) {
|
|
117
|
+
return {
|
|
118
|
+
_: "pageBlockOrderedList",
|
|
119
|
+
items,
|
|
120
|
+
reversed: params.reversed,
|
|
121
|
+
start: params.start,
|
|
122
|
+
type: params.type
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function tableCell(text, params = {}) {
|
|
126
|
+
return {
|
|
127
|
+
_: "pageTableCell",
|
|
128
|
+
text: text != null ? normalizeRichText(text) : void 0,
|
|
129
|
+
header: params.header,
|
|
130
|
+
alignCenter: params.alignCenter,
|
|
131
|
+
alignRight: params.alignRight,
|
|
132
|
+
valignMiddle: params.valignMiddle,
|
|
133
|
+
valignBottom: params.valignBottom,
|
|
134
|
+
colspan: params.colspan,
|
|
135
|
+
rowspan: params.rowspan
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function tableRow(cells) {
|
|
139
|
+
return { _: "pageTableRow", cells };
|
|
140
|
+
}
|
|
141
|
+
function table(rows, params = {}) {
|
|
142
|
+
return {
|
|
143
|
+
_: "pageBlockTable",
|
|
144
|
+
title: params.title != null ? normalizeRichText(params.title) : RICH_EMPTY,
|
|
145
|
+
rows,
|
|
146
|
+
bordered: params.bordered,
|
|
147
|
+
striped: params.striped
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function collage(items, caption) {
|
|
151
|
+
return { _: "pageBlockCollage", items, caption: normalizeCaption(caption) };
|
|
152
|
+
}
|
|
153
|
+
function slideshow(items, caption) {
|
|
154
|
+
return { _: "pageBlockSlideshow", items, caption: normalizeCaption(caption) };
|
|
155
|
+
}
|
|
156
|
+
function details(title, blocks, params = {}) {
|
|
157
|
+
return { _: "pageBlockDetails", blocks, title: normalizeRichText(title), open: params.open };
|
|
158
|
+
}
|
|
159
|
+
function photo(file, params = {}) {
|
|
160
|
+
return {
|
|
161
|
+
// the default `auto` mode would upload it as a document, but we already know it should be a photo
|
|
162
|
+
file: typeof file === "string" ? { type: "photo", file } : file,
|
|
163
|
+
block: {
|
|
164
|
+
_: "pageBlockPhoto",
|
|
165
|
+
photoId: Long.ZERO,
|
|
166
|
+
caption: normalizeCaption(params.caption),
|
|
167
|
+
url: params.url,
|
|
168
|
+
webpageId: params.webpageId,
|
|
169
|
+
spoiler: params.spoiler
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function video(file, params = {}) {
|
|
174
|
+
return {
|
|
175
|
+
file,
|
|
176
|
+
block: {
|
|
177
|
+
_: "pageBlockVideo",
|
|
178
|
+
videoId: Long.ZERO,
|
|
179
|
+
caption: normalizeCaption(params.caption),
|
|
180
|
+
autoplay: params.autoplay,
|
|
181
|
+
loop: params.loop,
|
|
182
|
+
spoiler: params.spoiler
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function audio(file, params = {}) {
|
|
187
|
+
return {
|
|
188
|
+
file,
|
|
189
|
+
block: {
|
|
190
|
+
_: "pageBlockAudio",
|
|
191
|
+
audioId: Long.ZERO,
|
|
192
|
+
caption: normalizeCaption(params.caption)
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
exports.anchor = anchor;
|
|
197
|
+
exports.audio = audio;
|
|
198
|
+
exports.blockquote = blockquote;
|
|
199
|
+
exports.collage = collage;
|
|
200
|
+
exports.details = details;
|
|
201
|
+
exports.divider = divider;
|
|
202
|
+
exports.footer = footer;
|
|
203
|
+
exports.heading = heading;
|
|
204
|
+
exports.list = list;
|
|
205
|
+
exports.listItem = listItem;
|
|
206
|
+
exports.map = map;
|
|
207
|
+
exports.math = math;
|
|
208
|
+
exports.orderedList = orderedList;
|
|
209
|
+
exports.orderedListItem = orderedListItem;
|
|
210
|
+
exports.paragraph = paragraph;
|
|
211
|
+
exports.photo = photo;
|
|
212
|
+
exports.preformatted = preformatted;
|
|
213
|
+
exports.pullquote = pullquote;
|
|
214
|
+
exports.slideshow = slideshow;
|
|
215
|
+
exports.table = table;
|
|
216
|
+
exports.tableCell = tableCell;
|
|
217
|
+
exports.tableRow = tableRow;
|
|
218
|
+
exports.thinking = thinking;
|
|
219
|
+
exports.video = video;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { tl } from '../../../../tl/index.js';
|
|
2
|
+
import { InputMediaAudio, InputMediaPhoto, InputMediaVideo } from '../../media/index.js';
|
|
3
|
+
import { InputText } from '../../misc/entities.js';
|
|
4
|
+
import { InputPageBlock, InputPageBlockOrFile, InputPageBlockWithFile } from './types.js';
|
|
5
|
+
import { default as Long } from 'long';
|
|
6
|
+
/**
|
|
7
|
+
* Input rich text, accepted by page block factories.
|
|
8
|
+
*
|
|
9
|
+
* Can be either a {@link tl.TypeRichText} (passed as-is), or an {@link InputText}
|
|
10
|
+
* (a plain string or a {@link TextWithEntities}, e.g. from `html`/`md` tagged templates),
|
|
11
|
+
* which is converted to {@link tl.TypeRichText}.
|
|
12
|
+
*/
|
|
13
|
+
export type InputRichText = InputText | tl.TypeRichText;
|
|
14
|
+
/** Input page caption (used by media page blocks) */
|
|
15
|
+
export interface InputPageCaption {
|
|
16
|
+
/** Caption text */
|
|
17
|
+
text?: InputRichText;
|
|
18
|
+
/** Caption credit (e.g. author) */
|
|
19
|
+
credit?: InputRichText;
|
|
20
|
+
}
|
|
21
|
+
type Block<T extends tl.TypePageBlock['_']> = Extract<InputPageBlock, {
|
|
22
|
+
_: T;
|
|
23
|
+
}>;
|
|
24
|
+
type ListItem = Block<'pageBlockList'>['items'][number];
|
|
25
|
+
type OrderedListItem = Block<'pageBlockOrderedList'>['items'][number];
|
|
26
|
+
/** Create a footer block */
|
|
27
|
+
export declare function footer(text: InputRichText): tl.RawPageBlockFooter;
|
|
28
|
+
/** Create a paragraph block */
|
|
29
|
+
export declare function paragraph(text: InputRichText): tl.RawPageBlockParagraph;
|
|
30
|
+
/** Create a "thinking" block */
|
|
31
|
+
export declare function thinking(text: InputRichText): tl.RawPageBlockThinking;
|
|
32
|
+
/** Create a heading block (`<h1>`–`<h6>`, depending on `level`) */
|
|
33
|
+
export declare function heading<Level extends 1 | 2 | 3 | 4 | 5 | 6>(level: Level, text: InputRichText): Extract<tl.TypePageBlock, {
|
|
34
|
+
_: `pageBlockHeading${Level}`;
|
|
35
|
+
}>;
|
|
36
|
+
/** Create a divider (`<hr>`) block */
|
|
37
|
+
export declare function divider(): tl.RawPageBlockDivider;
|
|
38
|
+
/** Create an anchor block, to be referenced by name */
|
|
39
|
+
export declare function anchor(name: string): tl.RawPageBlockAnchor;
|
|
40
|
+
/** Create a TeX math block */
|
|
41
|
+
export declare function math(source: string): tl.RawPageBlockMath;
|
|
42
|
+
/** Create a preformatted (code) block */
|
|
43
|
+
export declare function preformatted(text: InputRichText, language?: string): tl.RawPageBlockPreformatted;
|
|
44
|
+
/**
|
|
45
|
+
* Create a blockquote block.
|
|
46
|
+
*
|
|
47
|
+
* Pass an array of blocks instead of rich text to create a blockquote
|
|
48
|
+
* containing other blocks (`pageBlockBlockquoteBlocks`).
|
|
49
|
+
*/
|
|
50
|
+
export declare function blockquote(content: InputRichText | InputPageBlockOrFile[], caption?: InputRichText): tl.RawPageBlockBlockquote | Block<'pageBlockBlockquoteBlocks'>;
|
|
51
|
+
/** Create a pullquote block */
|
|
52
|
+
export declare function pullquote(text: InputRichText, caption?: InputRichText): tl.RawPageBlockPullquote;
|
|
53
|
+
/** Create a map block */
|
|
54
|
+
export declare function map(params: {
|
|
55
|
+
latitude: number;
|
|
56
|
+
longitude: number;
|
|
57
|
+
zoom: number;
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
caption?: InputRichText | InputPageCaption;
|
|
61
|
+
}): tl.RawInputPageBlockMap;
|
|
62
|
+
/** Create a list item (for {@link list}) */
|
|
63
|
+
export declare function listItem(content: InputRichText | InputPageBlockOrFile[], params?: {
|
|
64
|
+
checkbox?: boolean;
|
|
65
|
+
checked?: boolean;
|
|
66
|
+
}): ListItem;
|
|
67
|
+
/** Create an unordered list block */
|
|
68
|
+
export declare function list(items: ListItem[]): Block<'pageBlockList'>;
|
|
69
|
+
/** Create an ordered list item (for {@link orderedList}) */
|
|
70
|
+
export declare function orderedListItem(content: InputRichText | InputPageBlockOrFile[], params?: {
|
|
71
|
+
checkbox?: boolean;
|
|
72
|
+
checked?: boolean;
|
|
73
|
+
num?: string;
|
|
74
|
+
value?: number;
|
|
75
|
+
type?: string;
|
|
76
|
+
}): OrderedListItem;
|
|
77
|
+
/** Create an ordered list block */
|
|
78
|
+
export declare function orderedList(items: OrderedListItem[], params?: {
|
|
79
|
+
reversed?: boolean;
|
|
80
|
+
start?: number;
|
|
81
|
+
type?: string;
|
|
82
|
+
}): Block<'pageBlockOrderedList'>;
|
|
83
|
+
/** Create a table cell (for {@link tableRow}) */
|
|
84
|
+
export declare function tableCell(text?: InputRichText, params?: {
|
|
85
|
+
header?: boolean;
|
|
86
|
+
alignCenter?: boolean;
|
|
87
|
+
alignRight?: boolean;
|
|
88
|
+
valignMiddle?: boolean;
|
|
89
|
+
valignBottom?: boolean;
|
|
90
|
+
colspan?: number;
|
|
91
|
+
rowspan?: number;
|
|
92
|
+
}): tl.RawPageTableCell;
|
|
93
|
+
/** Create a table row (for {@link table}) */
|
|
94
|
+
export declare function tableRow(cells: tl.TypePageTableCell[]): tl.RawPageTableRow;
|
|
95
|
+
/** Create a table block */
|
|
96
|
+
export declare function table(rows: tl.TypePageTableRow[], params?: {
|
|
97
|
+
title?: InputRichText;
|
|
98
|
+
bordered?: boolean;
|
|
99
|
+
striped?: boolean;
|
|
100
|
+
}): tl.RawPageBlockTable;
|
|
101
|
+
/** Create a collage block */
|
|
102
|
+
export declare function collage(items: InputPageBlockOrFile[], caption?: InputRichText | InputPageCaption): Block<'pageBlockCollage'>;
|
|
103
|
+
/** Create a slideshow block */
|
|
104
|
+
export declare function slideshow(items: InputPageBlockOrFile[], caption?: InputRichText | InputPageCaption): Block<'pageBlockSlideshow'>;
|
|
105
|
+
/** Create a collapsible details block */
|
|
106
|
+
export declare function details(title: InputRichText, blocks: InputPageBlockOrFile[], params?: {
|
|
107
|
+
open?: boolean;
|
|
108
|
+
}): Block<'pageBlockDetails'>;
|
|
109
|
+
/** Create a photo block, uploading the given file */
|
|
110
|
+
export declare function photo(file: string | tl.TypeInputPhoto | InputMediaPhoto, params?: {
|
|
111
|
+
caption?: InputRichText | InputPageCaption;
|
|
112
|
+
url?: string;
|
|
113
|
+
webpageId?: Long;
|
|
114
|
+
spoiler?: boolean;
|
|
115
|
+
}): InputPageBlockWithFile;
|
|
116
|
+
/** Create a video block, uploading the given file */
|
|
117
|
+
export declare function video(file: string | tl.TypeInputDocument | InputMediaVideo, params?: {
|
|
118
|
+
caption?: InputRichText | InputPageCaption;
|
|
119
|
+
autoplay?: boolean;
|
|
120
|
+
loop?: boolean;
|
|
121
|
+
spoiler?: boolean;
|
|
122
|
+
}): InputPageBlockWithFile;
|
|
123
|
+
/** Create an audio block, uploading the given file */
|
|
124
|
+
export declare function audio(file: string | tl.TypeInputDocument | InputMediaAudio, params?: {
|
|
125
|
+
caption?: InputRichText | InputPageCaption;
|
|
126
|
+
}): InputPageBlockWithFile;
|
|
127
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { tl } from '../../../../tl/index.js';
|
|
2
|
+
import { InputMediaAudio, InputMediaPhoto, InputMediaVideo } from '../../media/index.js';
|
|
3
|
+
import { InputText } from '../../misc/entities.js';
|
|
4
|
+
import { InputPageBlock, InputPageBlockOrFile, InputPageBlockWithFile } from './types.js';
|
|
5
|
+
import { default as Long } from 'long';
|
|
6
|
+
/**
|
|
7
|
+
* Input rich text, accepted by page block factories.
|
|
8
|
+
*
|
|
9
|
+
* Can be either a {@link tl.TypeRichText} (passed as-is), or an {@link InputText}
|
|
10
|
+
* (a plain string or a {@link TextWithEntities}, e.g. from `html`/`md` tagged templates),
|
|
11
|
+
* which is converted to {@link tl.TypeRichText}.
|
|
12
|
+
*/
|
|
13
|
+
export type InputRichText = InputText | tl.TypeRichText;
|
|
14
|
+
/** Input page caption (used by media page blocks) */
|
|
15
|
+
export interface InputPageCaption {
|
|
16
|
+
/** Caption text */
|
|
17
|
+
text?: InputRichText;
|
|
18
|
+
/** Caption credit (e.g. author) */
|
|
19
|
+
credit?: InputRichText;
|
|
20
|
+
}
|
|
21
|
+
type Block<T extends tl.TypePageBlock['_']> = Extract<InputPageBlock, {
|
|
22
|
+
_: T;
|
|
23
|
+
}>;
|
|
24
|
+
type ListItem = Block<'pageBlockList'>['items'][number];
|
|
25
|
+
type OrderedListItem = Block<'pageBlockOrderedList'>['items'][number];
|
|
26
|
+
/** Create a footer block */
|
|
27
|
+
export declare function footer(text: InputRichText): tl.RawPageBlockFooter;
|
|
28
|
+
/** Create a paragraph block */
|
|
29
|
+
export declare function paragraph(text: InputRichText): tl.RawPageBlockParagraph;
|
|
30
|
+
/** Create a "thinking" block */
|
|
31
|
+
export declare function thinking(text: InputRichText): tl.RawPageBlockThinking;
|
|
32
|
+
/** Create a heading block (`<h1>`–`<h6>`, depending on `level`) */
|
|
33
|
+
export declare function heading<Level extends 1 | 2 | 3 | 4 | 5 | 6>(level: Level, text: InputRichText): Extract<tl.TypePageBlock, {
|
|
34
|
+
_: `pageBlockHeading${Level}`;
|
|
35
|
+
}>;
|
|
36
|
+
/** Create a divider (`<hr>`) block */
|
|
37
|
+
export declare function divider(): tl.RawPageBlockDivider;
|
|
38
|
+
/** Create an anchor block, to be referenced by name */
|
|
39
|
+
export declare function anchor(name: string): tl.RawPageBlockAnchor;
|
|
40
|
+
/** Create a TeX math block */
|
|
41
|
+
export declare function math(source: string): tl.RawPageBlockMath;
|
|
42
|
+
/** Create a preformatted (code) block */
|
|
43
|
+
export declare function preformatted(text: InputRichText, language?: string): tl.RawPageBlockPreformatted;
|
|
44
|
+
/**
|
|
45
|
+
* Create a blockquote block.
|
|
46
|
+
*
|
|
47
|
+
* Pass an array of blocks instead of rich text to create a blockquote
|
|
48
|
+
* containing other blocks (`pageBlockBlockquoteBlocks`).
|
|
49
|
+
*/
|
|
50
|
+
export declare function blockquote(content: InputRichText | InputPageBlockOrFile[], caption?: InputRichText): tl.RawPageBlockBlockquote | Block<'pageBlockBlockquoteBlocks'>;
|
|
51
|
+
/** Create a pullquote block */
|
|
52
|
+
export declare function pullquote(text: InputRichText, caption?: InputRichText): tl.RawPageBlockPullquote;
|
|
53
|
+
/** Create a map block */
|
|
54
|
+
export declare function map(params: {
|
|
55
|
+
latitude: number;
|
|
56
|
+
longitude: number;
|
|
57
|
+
zoom: number;
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
caption?: InputRichText | InputPageCaption;
|
|
61
|
+
}): tl.RawInputPageBlockMap;
|
|
62
|
+
/** Create a list item (for {@link list}) */
|
|
63
|
+
export declare function listItem(content: InputRichText | InputPageBlockOrFile[], params?: {
|
|
64
|
+
checkbox?: boolean;
|
|
65
|
+
checked?: boolean;
|
|
66
|
+
}): ListItem;
|
|
67
|
+
/** Create an unordered list block */
|
|
68
|
+
export declare function list(items: ListItem[]): Block<'pageBlockList'>;
|
|
69
|
+
/** Create an ordered list item (for {@link orderedList}) */
|
|
70
|
+
export declare function orderedListItem(content: InputRichText | InputPageBlockOrFile[], params?: {
|
|
71
|
+
checkbox?: boolean;
|
|
72
|
+
checked?: boolean;
|
|
73
|
+
num?: string;
|
|
74
|
+
value?: number;
|
|
75
|
+
type?: string;
|
|
76
|
+
}): OrderedListItem;
|
|
77
|
+
/** Create an ordered list block */
|
|
78
|
+
export declare function orderedList(items: OrderedListItem[], params?: {
|
|
79
|
+
reversed?: boolean;
|
|
80
|
+
start?: number;
|
|
81
|
+
type?: string;
|
|
82
|
+
}): Block<'pageBlockOrderedList'>;
|
|
83
|
+
/** Create a table cell (for {@link tableRow}) */
|
|
84
|
+
export declare function tableCell(text?: InputRichText, params?: {
|
|
85
|
+
header?: boolean;
|
|
86
|
+
alignCenter?: boolean;
|
|
87
|
+
alignRight?: boolean;
|
|
88
|
+
valignMiddle?: boolean;
|
|
89
|
+
valignBottom?: boolean;
|
|
90
|
+
colspan?: number;
|
|
91
|
+
rowspan?: number;
|
|
92
|
+
}): tl.RawPageTableCell;
|
|
93
|
+
/** Create a table row (for {@link table}) */
|
|
94
|
+
export declare function tableRow(cells: tl.TypePageTableCell[]): tl.RawPageTableRow;
|
|
95
|
+
/** Create a table block */
|
|
96
|
+
export declare function table(rows: tl.TypePageTableRow[], params?: {
|
|
97
|
+
title?: InputRichText;
|
|
98
|
+
bordered?: boolean;
|
|
99
|
+
striped?: boolean;
|
|
100
|
+
}): tl.RawPageBlockTable;
|
|
101
|
+
/** Create a collage block */
|
|
102
|
+
export declare function collage(items: InputPageBlockOrFile[], caption?: InputRichText | InputPageCaption): Block<'pageBlockCollage'>;
|
|
103
|
+
/** Create a slideshow block */
|
|
104
|
+
export declare function slideshow(items: InputPageBlockOrFile[], caption?: InputRichText | InputPageCaption): Block<'pageBlockSlideshow'>;
|
|
105
|
+
/** Create a collapsible details block */
|
|
106
|
+
export declare function details(title: InputRichText, blocks: InputPageBlockOrFile[], params?: {
|
|
107
|
+
open?: boolean;
|
|
108
|
+
}): Block<'pageBlockDetails'>;
|
|
109
|
+
/** Create a photo block, uploading the given file */
|
|
110
|
+
export declare function photo(file: string | tl.TypeInputPhoto | InputMediaPhoto, params?: {
|
|
111
|
+
caption?: InputRichText | InputPageCaption;
|
|
112
|
+
url?: string;
|
|
113
|
+
webpageId?: Long;
|
|
114
|
+
spoiler?: boolean;
|
|
115
|
+
}): InputPageBlockWithFile;
|
|
116
|
+
/** Create a video block, uploading the given file */
|
|
117
|
+
export declare function video(file: string | tl.TypeInputDocument | InputMediaVideo, params?: {
|
|
118
|
+
caption?: InputRichText | InputPageCaption;
|
|
119
|
+
autoplay?: boolean;
|
|
120
|
+
loop?: boolean;
|
|
121
|
+
spoiler?: boolean;
|
|
122
|
+
}): InputPageBlockWithFile;
|
|
123
|
+
/** Create an audio block, uploading the given file */
|
|
124
|
+
export declare function audio(file: string | tl.TypeInputDocument | InputMediaAudio, params?: {
|
|
125
|
+
caption?: InputRichText | InputPageCaption;
|
|
126
|
+
}): InputPageBlockWithFile;
|
|
127
|
+
export {};
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import Long from "long";
|
|
2
|
+
import { textWithEntitiesToRichText } from "../../../utils/entities.js";
|
|
3
|
+
const RICH_EMPTY = { _: "textEmpty" };
|
|
4
|
+
function normalizeRichText(text) {
|
|
5
|
+
if (typeof text === "string") return { _: "textPlain", text };
|
|
6
|
+
if ("_" in text) return text;
|
|
7
|
+
return textWithEntitiesToRichText(text);
|
|
8
|
+
}
|
|
9
|
+
function normalizeCaption(input) {
|
|
10
|
+
if (input == null) return { _: "pageCaption", text: RICH_EMPTY, credit: RICH_EMPTY };
|
|
11
|
+
if (typeof input === "string" || "_" in input || "entities" in input) {
|
|
12
|
+
return { _: "pageCaption", text: normalizeRichText(input), credit: RICH_EMPTY };
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
_: "pageCaption",
|
|
16
|
+
text: input.text != null ? normalizeRichText(input.text) : RICH_EMPTY,
|
|
17
|
+
credit: "credit" in input && input.credit != null ? normalizeRichText(input.credit) : RICH_EMPTY
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function footer(text) {
|
|
21
|
+
return { _: "pageBlockFooter", text: normalizeRichText(text) };
|
|
22
|
+
}
|
|
23
|
+
function paragraph(text) {
|
|
24
|
+
return { _: "pageBlockParagraph", text: normalizeRichText(text) };
|
|
25
|
+
}
|
|
26
|
+
function thinking(text) {
|
|
27
|
+
return { _: "pageBlockThinking", text: normalizeRichText(text) };
|
|
28
|
+
}
|
|
29
|
+
function heading(level, text) {
|
|
30
|
+
return { _: `pageBlockHeading${level}`, text: normalizeRichText(text) };
|
|
31
|
+
}
|
|
32
|
+
function divider() {
|
|
33
|
+
return { _: "pageBlockDivider" };
|
|
34
|
+
}
|
|
35
|
+
function anchor(name) {
|
|
36
|
+
return { _: "pageBlockAnchor", name };
|
|
37
|
+
}
|
|
38
|
+
function math(source) {
|
|
39
|
+
return { _: "pageBlockMath", source };
|
|
40
|
+
}
|
|
41
|
+
function preformatted(text, language = "") {
|
|
42
|
+
return { _: "pageBlockPreformatted", text: normalizeRichText(text), language };
|
|
43
|
+
}
|
|
44
|
+
function blockquote(content, caption) {
|
|
45
|
+
const normalizedCaption = caption != null ? normalizeRichText(caption) : RICH_EMPTY;
|
|
46
|
+
if (Array.isArray(content)) {
|
|
47
|
+
return { _: "pageBlockBlockquoteBlocks", blocks: content, caption: normalizedCaption };
|
|
48
|
+
}
|
|
49
|
+
return { _: "pageBlockBlockquote", text: normalizeRichText(content), caption: normalizedCaption };
|
|
50
|
+
}
|
|
51
|
+
function pullquote(text, caption) {
|
|
52
|
+
return {
|
|
53
|
+
_: "pageBlockPullquote",
|
|
54
|
+
text: normalizeRichText(text),
|
|
55
|
+
caption: caption != null ? normalizeRichText(caption) : RICH_EMPTY
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function map(params) {
|
|
59
|
+
return {
|
|
60
|
+
_: "inputPageBlockMap",
|
|
61
|
+
geo: { _: "inputGeoPoint", lat: params.latitude, long: params.longitude },
|
|
62
|
+
zoom: params.zoom,
|
|
63
|
+
w: params.width,
|
|
64
|
+
h: params.height,
|
|
65
|
+
caption: normalizeCaption(params.caption)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function listItem(content, params = {}) {
|
|
69
|
+
if (Array.isArray(content)) {
|
|
70
|
+
return {
|
|
71
|
+
_: "pageListItemBlocks",
|
|
72
|
+
blocks: content,
|
|
73
|
+
checkbox: params.checkbox,
|
|
74
|
+
checked: params.checked
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
_: "pageListItemText",
|
|
79
|
+
text: normalizeRichText(content),
|
|
80
|
+
checkbox: params.checkbox,
|
|
81
|
+
checked: params.checked
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function list(items) {
|
|
85
|
+
return { _: "pageBlockList", items };
|
|
86
|
+
}
|
|
87
|
+
function orderedListItem(content, params = {}) {
|
|
88
|
+
if (Array.isArray(content)) {
|
|
89
|
+
return {
|
|
90
|
+
_: "pageListOrderedItemBlocks",
|
|
91
|
+
blocks: content,
|
|
92
|
+
checkbox: params.checkbox,
|
|
93
|
+
checked: params.checked,
|
|
94
|
+
num: params.num,
|
|
95
|
+
value: params.value,
|
|
96
|
+
type: params.type
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
_: "pageListOrderedItemText",
|
|
101
|
+
text: normalizeRichText(content),
|
|
102
|
+
checkbox: params.checkbox,
|
|
103
|
+
checked: params.checked,
|
|
104
|
+
num: params.num,
|
|
105
|
+
value: params.value,
|
|
106
|
+
type: params.type
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function orderedList(items, params = {}) {
|
|
110
|
+
return {
|
|
111
|
+
_: "pageBlockOrderedList",
|
|
112
|
+
items,
|
|
113
|
+
reversed: params.reversed,
|
|
114
|
+
start: params.start,
|
|
115
|
+
type: params.type
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function tableCell(text, params = {}) {
|
|
119
|
+
return {
|
|
120
|
+
_: "pageTableCell",
|
|
121
|
+
text: text != null ? normalizeRichText(text) : void 0,
|
|
122
|
+
header: params.header,
|
|
123
|
+
alignCenter: params.alignCenter,
|
|
124
|
+
alignRight: params.alignRight,
|
|
125
|
+
valignMiddle: params.valignMiddle,
|
|
126
|
+
valignBottom: params.valignBottom,
|
|
127
|
+
colspan: params.colspan,
|
|
128
|
+
rowspan: params.rowspan
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function tableRow(cells) {
|
|
132
|
+
return { _: "pageTableRow", cells };
|
|
133
|
+
}
|
|
134
|
+
function table(rows, params = {}) {
|
|
135
|
+
return {
|
|
136
|
+
_: "pageBlockTable",
|
|
137
|
+
title: params.title != null ? normalizeRichText(params.title) : RICH_EMPTY,
|
|
138
|
+
rows,
|
|
139
|
+
bordered: params.bordered,
|
|
140
|
+
striped: params.striped
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function collage(items, caption) {
|
|
144
|
+
return { _: "pageBlockCollage", items, caption: normalizeCaption(caption) };
|
|
145
|
+
}
|
|
146
|
+
function slideshow(items, caption) {
|
|
147
|
+
return { _: "pageBlockSlideshow", items, caption: normalizeCaption(caption) };
|
|
148
|
+
}
|
|
149
|
+
function details(title, blocks, params = {}) {
|
|
150
|
+
return { _: "pageBlockDetails", blocks, title: normalizeRichText(title), open: params.open };
|
|
151
|
+
}
|
|
152
|
+
function photo(file, params = {}) {
|
|
153
|
+
return {
|
|
154
|
+
// the default `auto` mode would upload it as a document, but we already know it should be a photo
|
|
155
|
+
file: typeof file === "string" ? { type: "photo", file } : file,
|
|
156
|
+
block: {
|
|
157
|
+
_: "pageBlockPhoto",
|
|
158
|
+
photoId: Long.ZERO,
|
|
159
|
+
caption: normalizeCaption(params.caption),
|
|
160
|
+
url: params.url,
|
|
161
|
+
webpageId: params.webpageId,
|
|
162
|
+
spoiler: params.spoiler
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function video(file, params = {}) {
|
|
167
|
+
return {
|
|
168
|
+
file,
|
|
169
|
+
block: {
|
|
170
|
+
_: "pageBlockVideo",
|
|
171
|
+
videoId: Long.ZERO,
|
|
172
|
+
caption: normalizeCaption(params.caption),
|
|
173
|
+
autoplay: params.autoplay,
|
|
174
|
+
loop: params.loop,
|
|
175
|
+
spoiler: params.spoiler
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function audio(file, params = {}) {
|
|
180
|
+
return {
|
|
181
|
+
file,
|
|
182
|
+
block: {
|
|
183
|
+
_: "pageBlockAudio",
|
|
184
|
+
audioId: Long.ZERO,
|
|
185
|
+
caption: normalizeCaption(params.caption)
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
export {
|
|
190
|
+
anchor,
|
|
191
|
+
audio,
|
|
192
|
+
blockquote,
|
|
193
|
+
collage,
|
|
194
|
+
details,
|
|
195
|
+
divider,
|
|
196
|
+
footer,
|
|
197
|
+
heading,
|
|
198
|
+
list,
|
|
199
|
+
listItem,
|
|
200
|
+
map,
|
|
201
|
+
math,
|
|
202
|
+
orderedList,
|
|
203
|
+
orderedListItem,
|
|
204
|
+
paragraph,
|
|
205
|
+
photo,
|
|
206
|
+
preformatted,
|
|
207
|
+
pullquote,
|
|
208
|
+
slideshow,
|
|
209
|
+
table,
|
|
210
|
+
tableCell,
|
|
211
|
+
tableRow,
|
|
212
|
+
thinking,
|
|
213
|
+
video
|
|
214
|
+
};
|