rtf-codec 0.0.0 → 1.0.0

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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +208 -0
  3. package/dist/base64.cjs +66 -0
  4. package/dist/base64.d.cts +7 -0
  5. package/dist/base64.d.ts +7 -0
  6. package/dist/base64.js +62 -0
  7. package/dist/bytes.cjs +25 -0
  8. package/dist/bytes.d.cts +6 -0
  9. package/dist/bytes.d.ts +6 -0
  10. package/dist/bytes.js +22 -0
  11. package/dist/codec.cjs +29 -0
  12. package/dist/codec.d.cts +2308 -0
  13. package/dist/codec.d.ts +2308 -0
  14. package/dist/codec.js +26 -0
  15. package/dist/codepage.cjs +98 -0
  16. package/dist/codepage.d.cts +10 -0
  17. package/dist/codepage.d.ts +10 -0
  18. package/dist/codepage.js +92 -0
  19. package/dist/diagnostics-DdDFJLNO.d.cts +51 -0
  20. package/dist/diagnostics-DdDFJLNO.d.ts +51 -0
  21. package/dist/diagnostics.cjs +75 -0
  22. package/dist/diagnostics.d.cts +2 -0
  23. package/dist/diagnostics.d.ts +2 -0
  24. package/dist/diagnostics.js +67 -0
  25. package/dist/group.cjs +40 -0
  26. package/dist/group.d.cts +11 -0
  27. package/dist/group.d.ts +11 -0
  28. package/dist/group.js +38 -0
  29. package/dist/header.cjs +378 -0
  30. package/dist/header.d.cts +43 -0
  31. package/dist/header.d.ts +43 -0
  32. package/dist/header.js +376 -0
  33. package/dist/index.cjs +28 -0
  34. package/dist/index.d.cts +8 -0
  35. package/dist/index.d.ts +8 -0
  36. package/dist/index.js +8 -0
  37. package/dist/list-id.cjs +30 -0
  38. package/dist/list-id.d.cts +16 -0
  39. package/dist/list-id.d.ts +16 -0
  40. package/dist/list-id.js +27 -0
  41. package/dist/options.cjs +7 -0
  42. package/dist/options.d.cts +18 -0
  43. package/dist/options.d.ts +18 -0
  44. package/dist/options.js +5 -0
  45. package/dist/read.cjs +854 -0
  46. package/dist/read.d.cts +16 -0
  47. package/dist/read.d.ts +16 -0
  48. package/dist/read.js +852 -0
  49. package/dist/tokenize.cjs +155 -0
  50. package/dist/tokenize.d.cts +25 -0
  51. package/dist/tokenize.d.ts +25 -0
  52. package/dist/tokenize.js +154 -0
  53. package/dist/units.cjs +43 -0
  54. package/dist/units.d.cts +17 -0
  55. package/dist/units.d.ts +17 -0
  56. package/dist/units.js +29 -0
  57. package/dist/write.cjs +364 -0
  58. package/dist/write.d.cts +7 -0
  59. package/dist/write.d.ts +7 -0
  60. package/dist/write.js +362 -0
  61. package/package.json +95 -2
package/dist/header.js ADDED
@@ -0,0 +1,376 @@
1
+ import { appendBytes } from "./bytes.js";
2
+ import { DEFAULT_CODEPAGE, DOCUMENT_CHARSET_CODEPAGES, codepageForFontCharset, decodeCodepageBytes } from "./codepage.js";
3
+ import { groupHead, matchingGroupEnd } from "./group.js";
4
+ import { DEFAULT_MARGIN_BOTTOM_TWIPS, DEFAULT_MARGIN_LEFT_TWIPS, DEFAULT_MARGIN_RIGHT_TWIPS, DEFAULT_MARGIN_TOP_TWIPS, DEFAULT_PAPER_HEIGHT_TWIPS, DEFAULT_PAPER_WIDTH_TWIPS } from "./units.js";
5
+ //#region src/header.ts
6
+ const RGB_MAX = 255;
7
+ const FONT_FAMILIES = /* @__PURE__ */ new Set([
8
+ "fnil",
9
+ "froman",
10
+ "fswiss",
11
+ "fmodern",
12
+ "fscript",
13
+ "fdecor",
14
+ "ftech",
15
+ "fbidi"
16
+ ]);
17
+ const HEADING_STYLE_NAME = /^heading[ -]?([1-9])$/i;
18
+ const HEADER_DESTINATIONS = /* @__PURE__ */ new Set([
19
+ "fonttbl",
20
+ "colortbl",
21
+ "stylesheet",
22
+ "listtable",
23
+ "listoverridetable",
24
+ "info",
25
+ "filetbl",
26
+ "revtbl",
27
+ "rsidtbl",
28
+ "generator",
29
+ "pgptbl",
30
+ "themedata",
31
+ "colorschememapping",
32
+ "latentstyles",
33
+ "listtextoverride",
34
+ "xmlnstbl",
35
+ "wgrffmtfilter",
36
+ "datastore",
37
+ "protusertbl",
38
+ "mmathPr",
39
+ "stylerestrictions",
40
+ "userprops"
41
+ ]);
42
+ function collectPlainText(tokens, start, end, codepage, sink) {
43
+ const pending = [];
44
+ let out = "";
45
+ const flush = () => {
46
+ if (pending.length === 0) return;
47
+ out += decodeCodepageBytes(Uint8Array.from(pending), codepage, sink);
48
+ pending.length = 0;
49
+ };
50
+ for (let index = start; index < end; index += 1) {
51
+ const token = tokens[index];
52
+ if (token === void 0) break;
53
+ if (token.kind === "groupStart") {
54
+ flush();
55
+ index = matchingGroupEnd(tokens, index);
56
+ continue;
57
+ }
58
+ if (token.kind === "text") {
59
+ appendBytes(pending, token.bytes);
60
+ continue;
61
+ }
62
+ if (token.kind === "hex") {
63
+ pending.push(token.byte);
64
+ continue;
65
+ }
66
+ if (token.kind === "controlWord" && token.name === "u") {
67
+ flush();
68
+ const code = token.param;
69
+ if (code !== void 0) out += String.fromCodePoint(code < 0 ? code + 65536 : code);
70
+ }
71
+ }
72
+ flush();
73
+ return out.replace(/;\s*$/, "").trim();
74
+ }
75
+ function parseFontTable(tokens, contentStart, end, documentCodepage, fonts, sink) {
76
+ let index = contentStart;
77
+ let sawBracedEntry = false;
78
+ while (index < end) {
79
+ if (tokens[index]?.kind !== "groupStart") {
80
+ index += 1;
81
+ continue;
82
+ }
83
+ sawBracedEntry = true;
84
+ const entryEnd = Math.min(matchingGroupEnd(tokens, index), end);
85
+ readFontInfo(tokens, index + 1, entryEnd, documentCodepage, fonts, sink);
86
+ index = entryEnd + 1;
87
+ }
88
+ if (!sawBracedEntry) readFontInfo(tokens, contentStart, end, documentCodepage, fonts, sink);
89
+ }
90
+ function readFontInfo(tokens, start, end, documentCodepage, fonts, sink) {
91
+ let number;
92
+ let family;
93
+ let charsetPage;
94
+ let explicitPage;
95
+ let nameStart = start;
96
+ for (let index = start; index < end; index += 1) {
97
+ const token = tokens[index];
98
+ if (token === void 0) break;
99
+ if (token.kind !== "controlWord") continue;
100
+ if (token.name === "f" && token.param !== void 0) {
101
+ number = token.param;
102
+ nameStart = index + 1;
103
+ continue;
104
+ }
105
+ if (FONT_FAMILIES.has(token.name)) {
106
+ family = token.name.slice(1);
107
+ nameStart = index + 1;
108
+ continue;
109
+ }
110
+ if (token.name === "fcharset" && token.param !== void 0) {
111
+ charsetPage = codepageForFontCharset(token.param);
112
+ nameStart = index + 1;
113
+ continue;
114
+ }
115
+ if (token.name === "cpg" && token.param !== void 0) {
116
+ explicitPage = token.param;
117
+ nameStart = index + 1;
118
+ continue;
119
+ }
120
+ if (token.name === "fprq" || token.name === "fbias") nameStart = index + 1;
121
+ }
122
+ if (number === void 0) return;
123
+ const name = collectPlainText(tokens, nameStart, end, explicitPage ?? charsetPage ?? documentCodepage, sink);
124
+ fonts.set(number, {
125
+ name,
126
+ family,
127
+ codepage: explicitPage ?? charsetPage
128
+ });
129
+ }
130
+ function parseColorTable(tokens, contentStart, end, colors) {
131
+ let red;
132
+ let green;
133
+ let blue;
134
+ const finishEntry = () => {
135
+ colors.push(red === void 0 && green === void 0 && blue === void 0 ? void 0 : {
136
+ r: (red ?? 0) / RGB_MAX,
137
+ g: (green ?? 0) / RGB_MAX,
138
+ b: (blue ?? 0) / RGB_MAX
139
+ });
140
+ red = void 0;
141
+ green = void 0;
142
+ blue = void 0;
143
+ };
144
+ for (let index = contentStart; index < end; index += 1) {
145
+ const token = tokens[index];
146
+ if (token === void 0) break;
147
+ if (token.kind === "controlWord") {
148
+ if (token.name === "red") red = token.param ?? 0;
149
+ else if (token.name === "green") green = token.param ?? 0;
150
+ else if (token.name === "blue") blue = token.param ?? 0;
151
+ continue;
152
+ }
153
+ if (token.kind === "text") {
154
+ for (const byte of token.bytes) if (byte === 59) finishEntry();
155
+ }
156
+ }
157
+ }
158
+ function parseStyleSheet(tokens, contentStart, end, documentCodepage, styles, sink) {
159
+ for (let index = contentStart; index < end; index += 1) {
160
+ if (tokens[index]?.kind !== "groupStart") continue;
161
+ const entryEnd = Math.min(matchingGroupEnd(tokens, index), end);
162
+ readStyle(tokens, index, entryEnd, documentCodepage, styles, sink);
163
+ index = entryEnd;
164
+ }
165
+ }
166
+ function readStyle(tokens, start, end, documentCodepage, styles, sink) {
167
+ const head = groupHead(tokens, start);
168
+ if (head.ignorable) return;
169
+ let handle = 0;
170
+ let outlineLevel;
171
+ let nameStart = head.contentStart;
172
+ for (let index = start + 1; index < end; index += 1) {
173
+ const token = tokens[index];
174
+ if (token === void 0) break;
175
+ if (token.kind === "groupStart") {
176
+ index = Math.min(matchingGroupEnd(tokens, index), end);
177
+ nameStart = index + 1;
178
+ continue;
179
+ }
180
+ if (token.kind !== "controlWord") continue;
181
+ if (token.name === "s" && token.param !== void 0) handle = token.param;
182
+ else if (token.name === "outlinelevel" && token.param !== void 0) outlineLevel = token.param;
183
+ nameStart = index + 1;
184
+ }
185
+ const name = collectPlainText(tokens, nameStart, end, documentCodepage, sink);
186
+ const fromName = HEADING_STYLE_NAME.exec(name)?.[1];
187
+ const headingLevel = outlineLevel === void 0 ? fromName === void 0 ? void 0 : Number(fromName) : outlineLevel + 1;
188
+ styles.set(handle, {
189
+ name,
190
+ headingLevel
191
+ });
192
+ }
193
+ function parseListTable(tokens, contentStart, end, listsById) {
194
+ for (let index = contentStart; index < end; index += 1) {
195
+ if (tokens[index]?.kind !== "groupStart") continue;
196
+ const entryEnd = Math.min(matchingGroupEnd(tokens, index), end);
197
+ if (groupHead(tokens, index).destination === "list") readListDefinition(tokens, index, entryEnd, listsById);
198
+ index = entryEnd;
199
+ }
200
+ }
201
+ function readListDefinition(tokens, start, end, listsById) {
202
+ const levels = [];
203
+ let listId;
204
+ for (let index = start + 1; index < end; index += 1) {
205
+ const token = tokens[index];
206
+ if (token === void 0) break;
207
+ if (token.kind === "groupStart") {
208
+ const inner = Math.min(matchingGroupEnd(tokens, index), end);
209
+ if (groupHead(tokens, index).destination === "listlevel") levels.push(readListLevel(tokens, index, inner));
210
+ index = inner;
211
+ continue;
212
+ }
213
+ if (token.kind === "controlWord" && token.name === "listid" && token.param !== void 0) listId = token.param;
214
+ }
215
+ if (listId === void 0) return;
216
+ listsById.set(listId, { levels });
217
+ return listId;
218
+ }
219
+ function readListLevel(tokens, start, end) {
220
+ let numberFormat = 0;
221
+ let startAt = 1;
222
+ for (let index = start + 1; index < end; index += 1) {
223
+ const token = tokens[index];
224
+ if (token === void 0) break;
225
+ if (token.kind === "groupStart") {
226
+ index = Math.min(matchingGroupEnd(tokens, index), end);
227
+ continue;
228
+ }
229
+ if (token.kind !== "controlWord") continue;
230
+ if (token.name === "levelnfc" && token.param !== void 0) numberFormat = token.param;
231
+ else if (token.name === "levelstartat" && token.param !== void 0) startAt = token.param;
232
+ }
233
+ return {
234
+ numberFormat,
235
+ startAt
236
+ };
237
+ }
238
+ function parseListOverrideTable(tokens, contentStart, end, overrides) {
239
+ for (let index = contentStart; index < end; index += 1) {
240
+ if (tokens[index]?.kind !== "groupStart") continue;
241
+ const entryEnd = Math.min(matchingGroupEnd(tokens, index), end);
242
+ let listId;
243
+ let overrideIndex;
244
+ for (let inner = index + 1; inner < entryEnd; inner += 1) {
245
+ const child = tokens[inner];
246
+ if (child?.kind === "groupStart") {
247
+ inner = Math.min(matchingGroupEnd(tokens, inner), entryEnd);
248
+ continue;
249
+ }
250
+ if (child?.kind !== "controlWord" || child.param === void 0) continue;
251
+ if (child.name === "listid") listId = child.param;
252
+ else if (child.name === "ls") overrideIndex = child.param;
253
+ }
254
+ if (listId !== void 0 && overrideIndex !== void 0) overrides.set(overrideIndex, listId);
255
+ index = entryEnd;
256
+ }
257
+ }
258
+ function parseInfoGroup(tokens, contentStart, end, codepage, sink) {
259
+ const metadata = {};
260
+ for (let index = contentStart; index < end; index += 1) {
261
+ if (tokens[index]?.kind !== "groupStart") continue;
262
+ const fieldEnd = Math.min(matchingGroupEnd(tokens, index), end);
263
+ const head = groupHead(tokens, index);
264
+ const value = collectPlainText(tokens, head.contentStart, fieldEnd, codepage, sink);
265
+ if (value.length > 0) {
266
+ if (head.destination === "title") metadata.title = value;
267
+ else if (head.destination === "author") metadata.author = value;
268
+ else if (head.destination === "subject") metadata.subject = value;
269
+ else if (head.destination === "keywords") metadata.keywords = value.split(/[;,]\s*/).filter((k) => k.length > 0);
270
+ else if (head.destination === "operator") metadata.creator = value;
271
+ }
272
+ index = fieldEnd;
273
+ }
274
+ return metadata;
275
+ }
276
+ function readRtfHeader(tokens, sink) {
277
+ const fonts = /* @__PURE__ */ new Map();
278
+ const colors = [];
279
+ const styles = /* @__PURE__ */ new Map();
280
+ const listsById = /* @__PURE__ */ new Map();
281
+ const overrides = /* @__PURE__ */ new Map();
282
+ const page = {
283
+ paperWidthTwips: DEFAULT_PAPER_WIDTH_TWIPS,
284
+ paperHeightTwips: DEFAULT_PAPER_HEIGHT_TWIPS,
285
+ marginLeftTwips: DEFAULT_MARGIN_LEFT_TWIPS,
286
+ marginRightTwips: DEFAULT_MARGIN_RIGHT_TWIPS,
287
+ marginTopTwips: DEFAULT_MARGIN_TOP_TWIPS,
288
+ marginBottomTwips: DEFAULT_MARGIN_BOTTOM_TWIPS
289
+ };
290
+ let metadata = {};
291
+ let codepage = DEFAULT_CODEPAGE;
292
+ let defaultFontIndex;
293
+ let bodyStartIndex = 0;
294
+ const fileGroupEnd = matchingGroupEnd(tokens, 0);
295
+ for (let index = 0; index < fileGroupEnd; index += 1) {
296
+ const token = tokens[index];
297
+ if (token?.kind === "groupStart" && index > 0) {
298
+ index = Math.min(matchingGroupEnd(tokens, index), fileGroupEnd);
299
+ continue;
300
+ }
301
+ if (token?.kind !== "controlWord") continue;
302
+ const charsetPage = DOCUMENT_CHARSET_CODEPAGES.get(token.name);
303
+ if (charsetPage !== void 0) {
304
+ codepage = charsetPage;
305
+ continue;
306
+ }
307
+ if (token.param === void 0) continue;
308
+ switch (token.name) {
309
+ case "ansicpg":
310
+ codepage = token.param;
311
+ break;
312
+ case "deff":
313
+ defaultFontIndex = token.param;
314
+ break;
315
+ case "paperw":
316
+ page.paperWidthTwips = token.param;
317
+ break;
318
+ case "paperh":
319
+ page.paperHeightTwips = token.param;
320
+ break;
321
+ case "margl":
322
+ page.marginLeftTwips = token.param;
323
+ break;
324
+ case "margr":
325
+ page.marginRightTwips = token.param;
326
+ break;
327
+ case "margt":
328
+ page.marginTopTwips = token.param;
329
+ break;
330
+ case "margb": page.marginBottomTwips = token.param;
331
+ }
332
+ }
333
+ for (let index = 1; index < fileGroupEnd; index += 1) {
334
+ if (tokens[index]?.kind !== "groupStart") continue;
335
+ const groupEnd = Math.min(matchingGroupEnd(tokens, index), fileGroupEnd);
336
+ const head = groupHead(tokens, index);
337
+ switch (head.destination) {
338
+ case "fonttbl":
339
+ parseFontTable(tokens, head.contentStart, groupEnd, codepage, fonts, sink);
340
+ break;
341
+ case "colortbl":
342
+ parseColorTable(tokens, head.contentStart, groupEnd, colors);
343
+ break;
344
+ case "stylesheet":
345
+ parseStyleSheet(tokens, head.contentStart, groupEnd, codepage, styles, sink);
346
+ break;
347
+ case "listtable":
348
+ parseListTable(tokens, head.contentStart, groupEnd, listsById);
349
+ break;
350
+ case "listoverridetable":
351
+ parseListOverrideTable(tokens, head.contentStart, groupEnd, overrides);
352
+ break;
353
+ case "info": metadata = parseInfoGroup(tokens, head.contentStart, groupEnd, codepage, sink);
354
+ }
355
+ if (head.destination !== void 0 && HEADER_DESTINATIONS.has(head.destination)) bodyStartIndex = Math.max(bodyStartIndex, groupEnd + 1);
356
+ index = groupEnd;
357
+ }
358
+ const lists = /* @__PURE__ */ new Map();
359
+ for (const [overrideIndex, listId] of overrides) {
360
+ const list = listsById.get(listId);
361
+ if (list !== void 0) lists.set(overrideIndex, list);
362
+ }
363
+ return {
364
+ codepage,
365
+ defaultFontIndex,
366
+ fonts,
367
+ colors,
368
+ styles,
369
+ lists,
370
+ page,
371
+ metadata,
372
+ bodyStartIndex
373
+ };
374
+ }
375
+ //#endregion
376
+ export { HEADER_DESTINATIONS, readRtfHeader };
package/dist/index.cjs ADDED
@@ -0,0 +1,28 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_diagnostics = require("./diagnostics.cjs");
3
+ const require_bytes = require("./bytes.cjs");
4
+ const require_list_id = require("./list-id.cjs");
5
+ const require_options = require("./options.cjs");
6
+ const require_read = require("./read.cjs");
7
+ const require_write = require("./write.cjs");
8
+ const require_codec = require("./codec.cjs");
9
+ exports.DEFAULT_MAX_GROUP_DEPTH = require_options.DEFAULT_MAX_GROUP_DEPTH;
10
+ exports.DEFAULT_MAX_INPUT_BYTES = require_options.DEFAULT_MAX_INPUT_BYTES;
11
+ exports.NOOP_RTF_DIAGNOSTIC_SINK = require_diagnostics.NOOP_RTF_DIAGNOSTIC_SINK;
12
+ exports.RtfBytesSchema = require_codec.RtfBytesSchema;
13
+ exports.RtfDiagnosticCodes = require_diagnostics.RtfDiagnosticCodes;
14
+ exports.RtfInputTooLargeError = require_diagnostics.RtfInputTooLargeError;
15
+ exports.RtfNestingLimitExceededError = require_diagnostics.RtfNestingLimitExceededError;
16
+ exports.RtfNotAnRtfDocumentError = require_diagnostics.RtfNotAnRtfDocumentError;
17
+ exports.RtfParseError = require_diagnostics.RtfParseError;
18
+ exports.RtfUnsupportedDocumentKindError = require_diagnostics.RtfUnsupportedDocumentKindError;
19
+ exports.RtfWriteError = require_diagnostics.RtfWriteError;
20
+ exports.mintRtfListNumId = require_list_id.mintRtfListNumId;
21
+ exports.parseRtfListNumId = require_list_id.parseRtfListNumId;
22
+ exports.readRtf = require_read.readRtf;
23
+ exports.readRtfContent = require_read.readRtfContent;
24
+ exports.rtfBytesFromLatin1 = require_bytes.rtfBytesFromLatin1;
25
+ exports.rtfCodec = require_codec.rtfCodec;
26
+ exports.rtfContentCodec = require_codec.rtfContentCodec;
27
+ exports.writeRtf = require_write.writeRtf;
28
+ exports.writeRtfContent = require_write.writeRtfContent;
@@ -0,0 +1,8 @@
1
+ import { rtfBytesFromLatin1 } from "./bytes.cjs";
2
+ import { RtfBytesSchema, rtfCodec, rtfContentCodec } from "./codec.cjs";
3
+ import { a as RtfDiagnosticSink, c as RtfNotAnRtfDocumentError, d as RtfWriteError, i as RtfDiagnosticSeverity, l as RtfParseError, n as RtfDiagnostic, o as RtfInputTooLargeError, r as RtfDiagnosticCodes, s as RtfNestingLimitExceededError, t as NOOP_RTF_DIAGNOSTIC_SINK, u as RtfUnsupportedDocumentKindError } from "./diagnostics-DdDFJLNO.cjs";
4
+ import { DEFAULT_MAX_GROUP_DEPTH, DEFAULT_MAX_INPUT_BYTES, ReadRtfOptions, RtfLineEnding, WriteRtfOptions } from "./options.cjs";
5
+ import { ReadRtfContentResult, ReadRtfResult, readRtf, readRtfContent } from "./read.cjs";
6
+ import { writeRtf, writeRtfContent } from "./write.cjs";
7
+ import { RtfListNumIdInfo, RtfListType, mintRtfListNumId, parseRtfListNumId } from "./list-id.cjs";
8
+ export { DEFAULT_MAX_GROUP_DEPTH, DEFAULT_MAX_INPUT_BYTES, NOOP_RTF_DIAGNOSTIC_SINK, type ReadRtfContentResult, type ReadRtfOptions, type ReadRtfResult, RtfBytesSchema, type RtfDiagnostic, RtfDiagnosticCodes, type RtfDiagnosticSeverity, type RtfDiagnosticSink, RtfInputTooLargeError, type RtfLineEnding, type RtfListNumIdInfo, type RtfListType, RtfNestingLimitExceededError, RtfNotAnRtfDocumentError, RtfParseError, RtfUnsupportedDocumentKindError, RtfWriteError, type WriteRtfOptions, mintRtfListNumId, parseRtfListNumId, readRtf, readRtfContent, rtfBytesFromLatin1, rtfCodec, rtfContentCodec, writeRtf, writeRtfContent };
@@ -0,0 +1,8 @@
1
+ import { rtfBytesFromLatin1 } from "./bytes.js";
2
+ import { RtfBytesSchema, rtfCodec, rtfContentCodec } from "./codec.js";
3
+ import { a as RtfDiagnosticSink, c as RtfNotAnRtfDocumentError, d as RtfWriteError, i as RtfDiagnosticSeverity, l as RtfParseError, n as RtfDiagnostic, o as RtfInputTooLargeError, r as RtfDiagnosticCodes, s as RtfNestingLimitExceededError, t as NOOP_RTF_DIAGNOSTIC_SINK, u as RtfUnsupportedDocumentKindError } from "./diagnostics-DdDFJLNO.js";
4
+ import { DEFAULT_MAX_GROUP_DEPTH, DEFAULT_MAX_INPUT_BYTES, ReadRtfOptions, RtfLineEnding, WriteRtfOptions } from "./options.js";
5
+ import { ReadRtfContentResult, ReadRtfResult, readRtf, readRtfContent } from "./read.js";
6
+ import { writeRtf, writeRtfContent } from "./write.js";
7
+ import { RtfListNumIdInfo, RtfListType, mintRtfListNumId, parseRtfListNumId } from "./list-id.js";
8
+ export { DEFAULT_MAX_GROUP_DEPTH, DEFAULT_MAX_INPUT_BYTES, NOOP_RTF_DIAGNOSTIC_SINK, type ReadRtfContentResult, type ReadRtfOptions, type ReadRtfResult, RtfBytesSchema, type RtfDiagnostic, RtfDiagnosticCodes, type RtfDiagnosticSeverity, type RtfDiagnosticSink, RtfInputTooLargeError, type RtfLineEnding, type RtfListNumIdInfo, type RtfListType, RtfNestingLimitExceededError, RtfNotAnRtfDocumentError, RtfParseError, RtfUnsupportedDocumentKindError, RtfWriteError, type WriteRtfOptions, mintRtfListNumId, parseRtfListNumId, readRtf, readRtfContent, rtfBytesFromLatin1, rtfCodec, rtfContentCodec, writeRtf, writeRtfContent };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { NOOP_RTF_DIAGNOSTIC_SINK, RtfDiagnosticCodes, RtfInputTooLargeError, RtfNestingLimitExceededError, RtfNotAnRtfDocumentError, RtfParseError, RtfUnsupportedDocumentKindError, RtfWriteError } from "./diagnostics.js";
2
+ import { rtfBytesFromLatin1 } from "./bytes.js";
3
+ import { mintRtfListNumId, parseRtfListNumId } from "./list-id.js";
4
+ import { DEFAULT_MAX_GROUP_DEPTH, DEFAULT_MAX_INPUT_BYTES } from "./options.js";
5
+ import { readRtf, readRtfContent } from "./read.js";
6
+ import { writeRtf, writeRtfContent } from "./write.js";
7
+ import { RtfBytesSchema, rtfCodec, rtfContentCodec } from "./codec.js";
8
+ export { DEFAULT_MAX_GROUP_DEPTH, DEFAULT_MAX_INPUT_BYTES, NOOP_RTF_DIAGNOSTIC_SINK, RtfBytesSchema, RtfDiagnosticCodes, RtfInputTooLargeError, RtfNestingLimitExceededError, RtfNotAnRtfDocumentError, RtfParseError, RtfUnsupportedDocumentKindError, RtfWriteError, mintRtfListNumId, parseRtfListNumId, readRtf, readRtfContent, rtfBytesFromLatin1, rtfCodec, rtfContentCodec, writeRtf, writeRtfContent };
@@ -0,0 +1,30 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/list-id.ts
3
+ const NUMID_PATTERN = /^rtf(\d+):(bullet|ordered)(?:@(\d+))?$/;
4
+ const DEFAULT_ORDERED_START = 1;
5
+ const LEVEL_NUMBER_FORMAT_BULLET = 23;
6
+ function mintRtfListNumId(options) {
7
+ const startSuffix = options.type === "ordered" && options.start !== void 0 && options.start !== DEFAULT_ORDERED_START ? `@${String(options.start)}` : "";
8
+ return `rtf${String(options.listOverrideIndex)}:${options.type}${startSuffix}`;
9
+ }
10
+ function parseRtfListNumId(numId) {
11
+ const match = NUMID_PATTERN.exec(numId);
12
+ if (match === null) return;
13
+ const index = match[1];
14
+ const type = match[2];
15
+ if (index === void 0) return;
16
+ if (type !== "bullet" && type !== "ordered") return;
17
+ const start = match[3];
18
+ return start === void 0 ? {
19
+ listOverrideIndex: Number(index),
20
+ type
21
+ } : {
22
+ listOverrideIndex: Number(index),
23
+ type,
24
+ start: Number(start)
25
+ };
26
+ }
27
+ //#endregion
28
+ exports.LEVEL_NUMBER_FORMAT_BULLET = LEVEL_NUMBER_FORMAT_BULLET;
29
+ exports.mintRtfListNumId = mintRtfListNumId;
30
+ exports.parseRtfListNumId = parseRtfListNumId;
@@ -0,0 +1,16 @@
1
+ //#region src/list-id.d.ts
2
+ declare const LEVEL_NUMBER_FORMAT_BULLET = 23;
3
+ type RtfListType = "bullet" | "ordered";
4
+ interface RtfListNumIdInfo {
5
+ readonly listOverrideIndex: number;
6
+ readonly type: RtfListType;
7
+ readonly start?: number;
8
+ }
9
+ declare function mintRtfListNumId(options: {
10
+ readonly listOverrideIndex: number;
11
+ readonly type: RtfListType;
12
+ readonly start?: number;
13
+ }): string;
14
+ declare function parseRtfListNumId(numId: string): RtfListNumIdInfo | undefined;
15
+ //#endregion
16
+ export { LEVEL_NUMBER_FORMAT_BULLET, RtfListNumIdInfo, RtfListType, mintRtfListNumId, parseRtfListNumId };
@@ -0,0 +1,16 @@
1
+ //#region src/list-id.d.ts
2
+ declare const LEVEL_NUMBER_FORMAT_BULLET = 23;
3
+ type RtfListType = "bullet" | "ordered";
4
+ interface RtfListNumIdInfo {
5
+ readonly listOverrideIndex: number;
6
+ readonly type: RtfListType;
7
+ readonly start?: number;
8
+ }
9
+ declare function mintRtfListNumId(options: {
10
+ readonly listOverrideIndex: number;
11
+ readonly type: RtfListType;
12
+ readonly start?: number;
13
+ }): string;
14
+ declare function parseRtfListNumId(numId: string): RtfListNumIdInfo | undefined;
15
+ //#endregion
16
+ export { LEVEL_NUMBER_FORMAT_BULLET, RtfListNumIdInfo, RtfListType, mintRtfListNumId, parseRtfListNumId };
@@ -0,0 +1,27 @@
1
+ //#region src/list-id.ts
2
+ const NUMID_PATTERN = /^rtf(\d+):(bullet|ordered)(?:@(\d+))?$/;
3
+ const DEFAULT_ORDERED_START = 1;
4
+ const LEVEL_NUMBER_FORMAT_BULLET = 23;
5
+ function mintRtfListNumId(options) {
6
+ const startSuffix = options.type === "ordered" && options.start !== void 0 && options.start !== DEFAULT_ORDERED_START ? `@${String(options.start)}` : "";
7
+ return `rtf${String(options.listOverrideIndex)}:${options.type}${startSuffix}`;
8
+ }
9
+ function parseRtfListNumId(numId) {
10
+ const match = NUMID_PATTERN.exec(numId);
11
+ if (match === null) return;
12
+ const index = match[1];
13
+ const type = match[2];
14
+ if (index === void 0) return;
15
+ if (type !== "bullet" && type !== "ordered") return;
16
+ const start = match[3];
17
+ return start === void 0 ? {
18
+ listOverrideIndex: Number(index),
19
+ type
20
+ } : {
21
+ listOverrideIndex: Number(index),
22
+ type,
23
+ start: Number(start)
24
+ };
25
+ }
26
+ //#endregion
27
+ export { LEVEL_NUMBER_FORMAT_BULLET, mintRtfListNumId, parseRtfListNumId };
@@ -0,0 +1,7 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/options.ts
3
+ const DEFAULT_MAX_INPUT_BYTES = 67108864;
4
+ const DEFAULT_MAX_GROUP_DEPTH = 256;
5
+ //#endregion
6
+ exports.DEFAULT_MAX_GROUP_DEPTH = DEFAULT_MAX_GROUP_DEPTH;
7
+ exports.DEFAULT_MAX_INPUT_BYTES = DEFAULT_MAX_INPUT_BYTES;
@@ -0,0 +1,18 @@
1
+ import { a as RtfDiagnosticSink } from "./diagnostics-DdDFJLNO.cjs";
2
+ //#region src/options.d.ts
3
+ declare const DEFAULT_MAX_INPUT_BYTES: number;
4
+ declare const DEFAULT_MAX_GROUP_DEPTH = 256;
5
+ interface ReadRtfOptions {
6
+ readonly signal?: AbortSignal;
7
+ readonly sink?: RtfDiagnosticSink;
8
+ readonly maxInputBytes?: number;
9
+ readonly maxGroupDepth?: number;
10
+ }
11
+ type RtfLineEnding = "\n" | "\r\n";
12
+ interface WriteRtfOptions {
13
+ readonly signal?: AbortSignal;
14
+ readonly sink?: RtfDiagnosticSink;
15
+ readonly lineEnding?: RtfLineEnding;
16
+ }
17
+ //#endregion
18
+ export { DEFAULT_MAX_GROUP_DEPTH, DEFAULT_MAX_INPUT_BYTES, ReadRtfOptions, RtfLineEnding, WriteRtfOptions };
@@ -0,0 +1,18 @@
1
+ import { a as RtfDiagnosticSink } from "./diagnostics-DdDFJLNO.js";
2
+ //#region src/options.d.ts
3
+ declare const DEFAULT_MAX_INPUT_BYTES: number;
4
+ declare const DEFAULT_MAX_GROUP_DEPTH = 256;
5
+ interface ReadRtfOptions {
6
+ readonly signal?: AbortSignal;
7
+ readonly sink?: RtfDiagnosticSink;
8
+ readonly maxInputBytes?: number;
9
+ readonly maxGroupDepth?: number;
10
+ }
11
+ type RtfLineEnding = "\n" | "\r\n";
12
+ interface WriteRtfOptions {
13
+ readonly signal?: AbortSignal;
14
+ readonly sink?: RtfDiagnosticSink;
15
+ readonly lineEnding?: RtfLineEnding;
16
+ }
17
+ //#endregion
18
+ export { DEFAULT_MAX_GROUP_DEPTH, DEFAULT_MAX_INPUT_BYTES, ReadRtfOptions, RtfLineEnding, WriteRtfOptions };
@@ -0,0 +1,5 @@
1
+ //#region src/options.ts
2
+ const DEFAULT_MAX_INPUT_BYTES = 67108864;
3
+ const DEFAULT_MAX_GROUP_DEPTH = 256;
4
+ //#endregion
5
+ export { DEFAULT_MAX_GROUP_DEPTH, DEFAULT_MAX_INPUT_BYTES };