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.
- package/LICENSE +21 -0
- package/README.md +208 -0
- package/dist/base64.cjs +66 -0
- package/dist/base64.d.cts +7 -0
- package/dist/base64.d.ts +7 -0
- package/dist/base64.js +62 -0
- package/dist/bytes.cjs +25 -0
- package/dist/bytes.d.cts +6 -0
- package/dist/bytes.d.ts +6 -0
- package/dist/bytes.js +22 -0
- package/dist/codec.cjs +29 -0
- package/dist/codec.d.cts +2308 -0
- package/dist/codec.d.ts +2308 -0
- package/dist/codec.js +26 -0
- package/dist/codepage.cjs +98 -0
- package/dist/codepage.d.cts +10 -0
- package/dist/codepage.d.ts +10 -0
- package/dist/codepage.js +92 -0
- package/dist/diagnostics-DdDFJLNO.d.cts +51 -0
- package/dist/diagnostics-DdDFJLNO.d.ts +51 -0
- package/dist/diagnostics.cjs +75 -0
- package/dist/diagnostics.d.cts +2 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.js +67 -0
- package/dist/group.cjs +40 -0
- package/dist/group.d.cts +11 -0
- package/dist/group.d.ts +11 -0
- package/dist/group.js +38 -0
- package/dist/header.cjs +378 -0
- package/dist/header.d.cts +43 -0
- package/dist/header.d.ts +43 -0
- package/dist/header.js +376 -0
- package/dist/index.cjs +28 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/list-id.cjs +30 -0
- package/dist/list-id.d.cts +16 -0
- package/dist/list-id.d.ts +16 -0
- package/dist/list-id.js +27 -0
- package/dist/options.cjs +7 -0
- package/dist/options.d.cts +18 -0
- package/dist/options.d.ts +18 -0
- package/dist/options.js +5 -0
- package/dist/read.cjs +854 -0
- package/dist/read.d.cts +16 -0
- package/dist/read.d.ts +16 -0
- package/dist/read.js +852 -0
- package/dist/tokenize.cjs +155 -0
- package/dist/tokenize.d.cts +25 -0
- package/dist/tokenize.d.ts +25 -0
- package/dist/tokenize.js +154 -0
- package/dist/units.cjs +43 -0
- package/dist/units.d.cts +17 -0
- package/dist/units.d.ts +17 -0
- package/dist/units.js +29 -0
- package/dist/write.cjs +364 -0
- package/dist/write.d.cts +7 -0
- package/dist/write.d.ts +7 -0
- package/dist/write.js +362 -0
- package/package.json +95 -2
package/dist/codec.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readRtf, readRtfContent } from "./read.js";
|
|
2
|
+
import { writeRtf, writeRtfContent } from "./write.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { ContentDocumentSchema, DocumentTreeSchema } from "document-schema.js";
|
|
5
|
+
//#region src/codec.ts
|
|
6
|
+
const RTF_MAGIC = [
|
|
7
|
+
123,
|
|
8
|
+
92,
|
|
9
|
+
114,
|
|
10
|
+
116,
|
|
11
|
+
102
|
|
12
|
+
];
|
|
13
|
+
function hasRtfMagic(bytes) {
|
|
14
|
+
return RTF_MAGIC.every((byte, index) => bytes[index] === byte);
|
|
15
|
+
}
|
|
16
|
+
const RtfBytesSchema = z.instanceof(Uint8Array).refine(hasRtfMagic, { message: "does not begin with '{\\rtf'" });
|
|
17
|
+
const rtfCodec = z.codec(RtfBytesSchema, DocumentTreeSchema, {
|
|
18
|
+
decode: (bytes) => readRtf(bytes).documentPackage,
|
|
19
|
+
encode: (documentPackage) => writeRtf(documentPackage)
|
|
20
|
+
});
|
|
21
|
+
const rtfContentCodec = z.codec(RtfBytesSchema, ContentDocumentSchema, {
|
|
22
|
+
decode: (bytes) => readRtfContent(bytes).document,
|
|
23
|
+
encode: (document) => writeRtfContent(document)
|
|
24
|
+
});
|
|
25
|
+
//#endregion
|
|
26
|
+
export { RtfBytesSchema, rtfCodec, rtfContentCodec };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_diagnostics = require("./diagnostics.cjs");
|
|
3
|
+
//#region src/codepage.ts
|
|
4
|
+
const DEFAULT_CODEPAGE = 1252;
|
|
5
|
+
const UTF8_CODEPAGE = 65001;
|
|
6
|
+
const SINGLE_BYTE_PAGES = /* @__PURE__ */ new Map([
|
|
7
|
+
[437, "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0"],
|
|
8
|
+
[819, "
\xA0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"],
|
|
9
|
+
[850, "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø×ƒáíóúñѪº¿®¬½¼¡«»░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐└┴┬├─┼ãÃ╚╔╩╦╠═╬¤ðÐÊËÈıÍÎÏ┘┌█▄¦Ì▀ÓßÔÒõÕµþÞÚÛÙýݯ´±‗¾¶§÷¸°¨·¹³²■\xA0"],
|
|
10
|
+
[852, "ÇüéâäůćçłëŐőîŹÄĆÉĹĺôöĽľŚśÖÜŤťŁ×čáíóúĄąŽžĘ꬟Ⱥ«»░▒▓│┤ÁÂĚŞ╣║╗╝Żż┐└┴┬├─┼Ăă╚╔╩╦╠═╬¤đĐĎËďŇÍÎě┘┌█▄ŢŮ▀ÓßÔŃńňŠšŔÚŕŰýÝţ´˝˛ˇ˘§÷¸°¨˙űŘř■\xA0"],
|
|
11
|
+
[860, "ÇüéâãàÁçêÊèÍÔìÃÂÉÀÈôõòÚùÌÕÜ¢£Ù₧ÓáíóúñѪº¿Ò¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0"],
|
|
12
|
+
[862, "אבגדהוזחטיךכלםמןנסעףפץצקרשת¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0"],
|
|
13
|
+
[863, "ÇüéâÂà¶çêëèïî‗À§ÉÈÊôËÏûù¤ÔÜ¢£ÙÛƒ¦´óú¨¸³¯Î⌐¬½¼¾«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0"],
|
|
14
|
+
[865, "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø₧ƒáíóúñѪº¿⌐¬½¼¡«¤░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0"],
|
|
15
|
+
[866, "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмноп░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀рстуфхцчшщъыьэюяЁёЄєЇїЎў°∙·√№¤■\xA0"],
|
|
16
|
+
[874, "€����…�����������‘’“”•–—��������\xA0กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำิีึืฺุู����฿เแโใไๅๆ็่้๊๋์ํ๎๏๐๑๒๓๔๕๖๗๘๙๚๛����"],
|
|
17
|
+
[1250, "€�‚�„…†‡�‰Š‹ŚŤŽŹ�‘’“”•–—�™š›śťžź\xA0ˇ˘Ł¤Ą¦§¨©Ş«¬®Ż°±˛ł´µ¶·¸ąş»Ľ˝ľżŔÁÂĂÄĹĆÇČÉĘËĚÍÎĎĐŃŇÓÔŐÖ×ŘŮÚŰÜÝŢßŕáâăäĺćçčéęëěíîďđńňóôőö÷řůúűüýţ˙"],
|
|
18
|
+
[1251, "ЂЃ‚ѓ„…†‡€‰Љ‹ЊЌЋЏђ‘’“”•–—�™љ›њќћџ\xA0ЎўЈ¤Ґ¦§Ё©Є«¬®Ї°±Ііґµ¶·ё№є»јЅѕїАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя"],
|
|
19
|
+
[1252, "€�‚ƒ„…†‡ˆ‰Š‹Œ�Ž��‘’“”•–—˜™š›œ�žŸ\xA0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"],
|
|
20
|
+
[1253, "€�‚ƒ„…†‡�‰�‹�����‘’“”•–—�™�›����\xA0΅Ά£¤¥¦§¨©�«¬®―°±²³΄µ¶·ΈΉΊ»Ό½ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ�ΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ�"],
|
|
21
|
+
[1254, "€�‚ƒ„…†‡ˆ‰Š‹Œ����‘’“”•–—˜™š›œ��Ÿ\xA0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏĞÑÒÓÔÕÖרÙÚÛÜİŞßàáâãäåæçèéêëìíîïğñòóôõö÷øùúûüışÿ"],
|
|
22
|
+
[1255, "€�‚ƒ„…†‡ˆ‰�‹�����‘’“”•–—˜™�›����\xA0¡¢£₪¥¦§¨©×«¬®¯°±²³´µ¶·¸¹÷»¼½¾¿ְֱֲֳִֵֶַָֹ�ֻּֽ־ֿ׀ׁׂ׃װױײ׳״�������אבגדהוזחטיךכלםמןנסעףפץצקרשת���"],
|
|
23
|
+
[1256, "€پ‚ƒ„…†‡ˆ‰ٹ‹Œچژڈگ‘’“”•–—ک™ڑ›œں\xA0،¢£¤¥¦§¨©ھ«¬®¯°±²³´µ¶·¸¹؛»¼½¾؟ہءآأؤإئابةتثجحخدذرزسشصض×طظعغـفقكàلâمنهوçèéêëىيîïًٌٍَôُِ÷ّùْûüے"],
|
|
24
|
+
[1257, "€�‚�„…†‡�‰�‹�¨ˇ¸�‘’“”•–—�™�›�¯˛�\xA0�¢£¤�¦§Ø©Ŗ«¬®Æ°±²³´µ¶·ø¹ŗ»¼½¾æĄĮĀĆÄÅĘĒČÉŹĖĢĶĪĻŠŃŅÓŌÕÖ×ŲŁŚŪÜŻŽßąįāćäåęēčéźėģķīļšńņóōõö÷ųłśūüżž˙"],
|
|
25
|
+
[1258, "€�‚ƒ„…†‡ˆ‰�‹Œ����‘’“”•–—˜™�›œ��Ÿ\xA0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂĂÄÅÆÇÈÉÊË̀ÍÎÏĐÑ̉ÓÔƠÖרÙÚÛÜỮßàáâăäåæçèéêë́íîïđṇ̃óôơö÷øùúûüư₫ÿ"],
|
|
26
|
+
[1e4, "ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ"],
|
|
27
|
+
[10006, "Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩάΝ¬ΟΡ≈Τ«»…\xA0ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ"],
|
|
28
|
+
[10007, "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњјЅ¬√ƒ≈∆«»…\xA0ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю€"],
|
|
29
|
+
[10029, "ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»…\xA0ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ"],
|
|
30
|
+
[10081, "ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ"]
|
|
31
|
+
]);
|
|
32
|
+
const FCHARSET_CODEPAGES = /* @__PURE__ */ new Map([
|
|
33
|
+
[0, 1252],
|
|
34
|
+
[2, 42],
|
|
35
|
+
[77, 1e4],
|
|
36
|
+
[78, 10001],
|
|
37
|
+
[79, 10003],
|
|
38
|
+
[80, 10008],
|
|
39
|
+
[81, 10002],
|
|
40
|
+
[83, 10005],
|
|
41
|
+
[84, 10004],
|
|
42
|
+
[85, 10006],
|
|
43
|
+
[86, 10081],
|
|
44
|
+
[87, 10021],
|
|
45
|
+
[88, 10029],
|
|
46
|
+
[89, 10007],
|
|
47
|
+
[128, 932],
|
|
48
|
+
[129, 949],
|
|
49
|
+
[130, 1361],
|
|
50
|
+
[134, 936],
|
|
51
|
+
[136, 950],
|
|
52
|
+
[161, 1253],
|
|
53
|
+
[162, 1254],
|
|
54
|
+
[163, 1258],
|
|
55
|
+
[177, 1255],
|
|
56
|
+
[178, 1256],
|
|
57
|
+
[186, 1257],
|
|
58
|
+
[204, 1251],
|
|
59
|
+
[222, 874],
|
|
60
|
+
[238, 1250],
|
|
61
|
+
[254, 437],
|
|
62
|
+
[255, 850]
|
|
63
|
+
]);
|
|
64
|
+
const DOCUMENT_CHARSET_CODEPAGES = /* @__PURE__ */ new Map([
|
|
65
|
+
["ansi", 1252],
|
|
66
|
+
["mac", 1e4],
|
|
67
|
+
["pc", 437],
|
|
68
|
+
["pca", 850]
|
|
69
|
+
]);
|
|
70
|
+
function codepageForFontCharset(charset) {
|
|
71
|
+
return FCHARSET_CODEPAGES.get(charset);
|
|
72
|
+
}
|
|
73
|
+
function isSupportedCodepage(codepage) {
|
|
74
|
+
return codepage === 65001 || SINGLE_BYTE_PAGES.has(codepage);
|
|
75
|
+
}
|
|
76
|
+
function decodeCodepageBytes(input, codepage, sink) {
|
|
77
|
+
if (input.length === 0) return "";
|
|
78
|
+
if (codepage === 65001) return new TextDecoder("utf-8").decode(input);
|
|
79
|
+
const table = SINGLE_BYTE_PAGES.get(codepage);
|
|
80
|
+
if (table === void 0) {
|
|
81
|
+
sink({
|
|
82
|
+
code: require_diagnostics.RtfDiagnosticCodes.UNSUPPORTED_CODEPAGE,
|
|
83
|
+
severity: "warning",
|
|
84
|
+
message: `code page ${String(codepage)} is not supported; decoding this run through code page ${String(DEFAULT_CODEPAGE)} instead`
|
|
85
|
+
});
|
|
86
|
+
return decodeCodepageBytes(input, DEFAULT_CODEPAGE, sink);
|
|
87
|
+
}
|
|
88
|
+
let out = "";
|
|
89
|
+
for (const byte of input) out += byte < 128 ? String.fromCharCode(byte) : table[byte - 128] ?? "�";
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
exports.DEFAULT_CODEPAGE = DEFAULT_CODEPAGE;
|
|
94
|
+
exports.DOCUMENT_CHARSET_CODEPAGES = DOCUMENT_CHARSET_CODEPAGES;
|
|
95
|
+
exports.UTF8_CODEPAGE = UTF8_CODEPAGE;
|
|
96
|
+
exports.codepageForFontCharset = codepageForFontCharset;
|
|
97
|
+
exports.decodeCodepageBytes = decodeCodepageBytes;
|
|
98
|
+
exports.isSupportedCodepage = isSupportedCodepage;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { a as RtfDiagnosticSink } from "./diagnostics-DdDFJLNO.cjs";
|
|
2
|
+
//#region src/codepage.d.ts
|
|
3
|
+
declare const DEFAULT_CODEPAGE = 1252;
|
|
4
|
+
declare const UTF8_CODEPAGE = 65001;
|
|
5
|
+
declare const DOCUMENT_CHARSET_CODEPAGES: ReadonlyMap<string, number>;
|
|
6
|
+
declare function codepageForFontCharset(charset: number): number | undefined;
|
|
7
|
+
declare function isSupportedCodepage(codepage: number): boolean;
|
|
8
|
+
declare function decodeCodepageBytes(input: Uint8Array, codepage: number, sink: RtfDiagnosticSink): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { DEFAULT_CODEPAGE, DOCUMENT_CHARSET_CODEPAGES, UTF8_CODEPAGE, codepageForFontCharset, decodeCodepageBytes, isSupportedCodepage };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { a as RtfDiagnosticSink } from "./diagnostics-DdDFJLNO.js";
|
|
2
|
+
//#region src/codepage.d.ts
|
|
3
|
+
declare const DEFAULT_CODEPAGE = 1252;
|
|
4
|
+
declare const UTF8_CODEPAGE = 65001;
|
|
5
|
+
declare const DOCUMENT_CHARSET_CODEPAGES: ReadonlyMap<string, number>;
|
|
6
|
+
declare function codepageForFontCharset(charset: number): number | undefined;
|
|
7
|
+
declare function isSupportedCodepage(codepage: number): boolean;
|
|
8
|
+
declare function decodeCodepageBytes(input: Uint8Array, codepage: number, sink: RtfDiagnosticSink): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { DEFAULT_CODEPAGE, DOCUMENT_CHARSET_CODEPAGES, UTF8_CODEPAGE, codepageForFontCharset, decodeCodepageBytes, isSupportedCodepage };
|
package/dist/codepage.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { RtfDiagnosticCodes } from "./diagnostics.js";
|
|
2
|
+
//#region src/codepage.ts
|
|
3
|
+
const DEFAULT_CODEPAGE = 1252;
|
|
4
|
+
const UTF8_CODEPAGE = 65001;
|
|
5
|
+
const SINGLE_BYTE_PAGES = /* @__PURE__ */ new Map([
|
|
6
|
+
[437, "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0"],
|
|
7
|
+
[819, "
\xA0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"],
|
|
8
|
+
[850, "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø×ƒáíóúñѪº¿®¬½¼¡«»░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐└┴┬├─┼ãÃ╚╔╩╦╠═╬¤ðÐÊËÈıÍÎÏ┘┌█▄¦Ì▀ÓßÔÒõÕµþÞÚÛÙýݯ´±‗¾¶§÷¸°¨·¹³²■\xA0"],
|
|
9
|
+
[852, "ÇüéâäůćçłëŐőîŹÄĆÉĹĺôöĽľŚśÖÜŤťŁ×čáíóúĄąŽžĘ꬟Ⱥ«»░▒▓│┤ÁÂĚŞ╣║╗╝Żż┐└┴┬├─┼Ăă╚╔╩╦╠═╬¤đĐĎËďŇÍÎě┘┌█▄ŢŮ▀ÓßÔŃńňŠšŔÚŕŰýÝţ´˝˛ˇ˘§÷¸°¨˙űŘř■\xA0"],
|
|
10
|
+
[860, "ÇüéâãàÁçêÊèÍÔìÃÂÉÀÈôõòÚùÌÕÜ¢£Ù₧ÓáíóúñѪº¿Ò¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0"],
|
|
11
|
+
[862, "אבגדהוזחטיךכלםמןנסעףפץצקרשת¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0"],
|
|
12
|
+
[863, "ÇüéâÂà¶çêëèïî‗À§ÉÈÊôËÏûù¤ÔÜ¢£ÙÛƒ¦´óú¨¸³¯Î⌐¬½¼¾«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0"],
|
|
13
|
+
[865, "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø₧ƒáíóúñѪº¿⌐¬½¼¡«¤░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0"],
|
|
14
|
+
[866, "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмноп░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀рстуфхцчшщъыьэюяЁёЄєЇїЎў°∙·√№¤■\xA0"],
|
|
15
|
+
[874, "€����…�����������‘’“”•–—��������\xA0กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำิีึืฺุู����฿เแโใไๅๆ็่้๊๋์ํ๎๏๐๑๒๓๔๕๖๗๘๙๚๛����"],
|
|
16
|
+
[1250, "€�‚�„…†‡�‰Š‹ŚŤŽŹ�‘’“”•–—�™š›śťžź\xA0ˇ˘Ł¤Ą¦§¨©Ş«¬®Ż°±˛ł´µ¶·¸ąş»Ľ˝ľżŔÁÂĂÄĹĆÇČÉĘËĚÍÎĎĐŃŇÓÔŐÖ×ŘŮÚŰÜÝŢßŕáâăäĺćçčéęëěíîďđńňóôőö÷řůúűüýţ˙"],
|
|
17
|
+
[1251, "ЂЃ‚ѓ„…†‡€‰Љ‹ЊЌЋЏђ‘’“”•–—�™љ›њќћџ\xA0ЎўЈ¤Ґ¦§Ё©Є«¬®Ї°±Ііґµ¶·ё№є»јЅѕїАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя"],
|
|
18
|
+
[1252, "€�‚ƒ„…†‡ˆ‰Š‹Œ�Ž��‘’“”•–—˜™š›œ�žŸ\xA0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"],
|
|
19
|
+
[1253, "€�‚ƒ„…†‡�‰�‹�����‘’“”•–—�™�›����\xA0΅Ά£¤¥¦§¨©�«¬®―°±²³΄µ¶·ΈΉΊ»Ό½ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ�ΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ�"],
|
|
20
|
+
[1254, "€�‚ƒ„…†‡ˆ‰Š‹Œ����‘’“”•–—˜™š›œ��Ÿ\xA0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏĞÑÒÓÔÕÖרÙÚÛÜİŞßàáâãäåæçèéêëìíîïğñòóôõö÷øùúûüışÿ"],
|
|
21
|
+
[1255, "€�‚ƒ„…†‡ˆ‰�‹�����‘’“”•–—˜™�›����\xA0¡¢£₪¥¦§¨©×«¬®¯°±²³´µ¶·¸¹÷»¼½¾¿ְֱֲֳִֵֶַָֹ�ֻּֽ־ֿ׀ׁׂ׃װױײ׳״�������אבגדהוזחטיךכלםמןנסעףפץצקרשת���"],
|
|
22
|
+
[1256, "€پ‚ƒ„…†‡ˆ‰ٹ‹Œچژڈگ‘’“”•–—ک™ڑ›œں\xA0،¢£¤¥¦§¨©ھ«¬®¯°±²³´µ¶·¸¹؛»¼½¾؟ہءآأؤإئابةتثجحخدذرزسشصض×طظعغـفقكàلâمنهوçèéêëىيîïًٌٍَôُِ÷ّùْûüے"],
|
|
23
|
+
[1257, "€�‚�„…†‡�‰�‹�¨ˇ¸�‘’“”•–—�™�›�¯˛�\xA0�¢£¤�¦§Ø©Ŗ«¬®Æ°±²³´µ¶·ø¹ŗ»¼½¾æĄĮĀĆÄÅĘĒČÉŹĖĢĶĪĻŠŃŅÓŌÕÖ×ŲŁŚŪÜŻŽßąįāćäåęēčéźėģķīļšńņóōõö÷ųłśūüżž˙"],
|
|
24
|
+
[1258, "€�‚ƒ„…†‡ˆ‰�‹Œ����‘’“”•–—˜™�›œ��Ÿ\xA0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂĂÄÅÆÇÈÉÊË̀ÍÎÏĐÑ̉ÓÔƠÖרÙÚÛÜỮßàáâăäåæçèéêë́íîïđṇ̃óôơö÷øùúûüư₫ÿ"],
|
|
25
|
+
[1e4, "ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ"],
|
|
26
|
+
[10006, "Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩάΝ¬ΟΡ≈Τ«»…\xA0ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ"],
|
|
27
|
+
[10007, "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњјЅ¬√ƒ≈∆«»…\xA0ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю€"],
|
|
28
|
+
[10029, "ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»…\xA0ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ"],
|
|
29
|
+
[10081, "ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»…\xA0ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ"]
|
|
30
|
+
]);
|
|
31
|
+
const FCHARSET_CODEPAGES = /* @__PURE__ */ new Map([
|
|
32
|
+
[0, 1252],
|
|
33
|
+
[2, 42],
|
|
34
|
+
[77, 1e4],
|
|
35
|
+
[78, 10001],
|
|
36
|
+
[79, 10003],
|
|
37
|
+
[80, 10008],
|
|
38
|
+
[81, 10002],
|
|
39
|
+
[83, 10005],
|
|
40
|
+
[84, 10004],
|
|
41
|
+
[85, 10006],
|
|
42
|
+
[86, 10081],
|
|
43
|
+
[87, 10021],
|
|
44
|
+
[88, 10029],
|
|
45
|
+
[89, 10007],
|
|
46
|
+
[128, 932],
|
|
47
|
+
[129, 949],
|
|
48
|
+
[130, 1361],
|
|
49
|
+
[134, 936],
|
|
50
|
+
[136, 950],
|
|
51
|
+
[161, 1253],
|
|
52
|
+
[162, 1254],
|
|
53
|
+
[163, 1258],
|
|
54
|
+
[177, 1255],
|
|
55
|
+
[178, 1256],
|
|
56
|
+
[186, 1257],
|
|
57
|
+
[204, 1251],
|
|
58
|
+
[222, 874],
|
|
59
|
+
[238, 1250],
|
|
60
|
+
[254, 437],
|
|
61
|
+
[255, 850]
|
|
62
|
+
]);
|
|
63
|
+
const DOCUMENT_CHARSET_CODEPAGES = /* @__PURE__ */ new Map([
|
|
64
|
+
["ansi", 1252],
|
|
65
|
+
["mac", 1e4],
|
|
66
|
+
["pc", 437],
|
|
67
|
+
["pca", 850]
|
|
68
|
+
]);
|
|
69
|
+
function codepageForFontCharset(charset) {
|
|
70
|
+
return FCHARSET_CODEPAGES.get(charset);
|
|
71
|
+
}
|
|
72
|
+
function isSupportedCodepage(codepage) {
|
|
73
|
+
return codepage === 65001 || SINGLE_BYTE_PAGES.has(codepage);
|
|
74
|
+
}
|
|
75
|
+
function decodeCodepageBytes(input, codepage, sink) {
|
|
76
|
+
if (input.length === 0) return "";
|
|
77
|
+
if (codepage === 65001) return new TextDecoder("utf-8").decode(input);
|
|
78
|
+
const table = SINGLE_BYTE_PAGES.get(codepage);
|
|
79
|
+
if (table === void 0) {
|
|
80
|
+
sink({
|
|
81
|
+
code: RtfDiagnosticCodes.UNSUPPORTED_CODEPAGE,
|
|
82
|
+
severity: "warning",
|
|
83
|
+
message: `code page ${String(codepage)} is not supported; decoding this run through code page ${String(DEFAULT_CODEPAGE)} instead`
|
|
84
|
+
});
|
|
85
|
+
return decodeCodepageBytes(input, DEFAULT_CODEPAGE, sink);
|
|
86
|
+
}
|
|
87
|
+
let out = "";
|
|
88
|
+
for (const byte of input) out += byte < 128 ? String.fromCharCode(byte) : table[byte - 128] ?? "�";
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { DEFAULT_CODEPAGE, DOCUMENT_CHARSET_CODEPAGES, UTF8_CODEPAGE, codepageForFontCharset, decodeCodepageBytes, isSupportedCodepage };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/diagnostics.d.ts
|
|
2
|
+
type RtfDiagnosticSeverity = "info" | "warning";
|
|
3
|
+
interface RtfDiagnostic {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly severity: RtfDiagnosticSeverity;
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly tokenIndex?: number;
|
|
8
|
+
}
|
|
9
|
+
type RtfDiagnosticSink = (diagnostic: RtfDiagnostic) => void;
|
|
10
|
+
declare const NOOP_RTF_DIAGNOSTIC_SINK: RtfDiagnosticSink;
|
|
11
|
+
declare const RtfDiagnosticCodes: {
|
|
12
|
+
readonly UNBALANCED_GROUP: "rtf/unbalanced-group";
|
|
13
|
+
readonly UNKNOWN_DESTINATION_SKIPPED: "rtf/unknown-destination-skipped";
|
|
14
|
+
readonly CONTENT_DESTINATION_SKIPPED: "rtf/content-destination-skipped";
|
|
15
|
+
readonly UNSUPPORTED_CODEPAGE: "rtf/unsupported-codepage";
|
|
16
|
+
readonly UNSUPPORTED_PICTURE_FORMAT: "rtf/unsupported-picture-format";
|
|
17
|
+
readonly PICTURE_SIZE_UNSTATED: "rtf/picture-size-unstated";
|
|
18
|
+
readonly TABLE_ROW_WITHOUT_DEFINITION: "rtf/table-row-without-definition";
|
|
19
|
+
readonly TABLE_COLUMN_WIDTH_INVALID: "rtf/table-column-width-invalid";
|
|
20
|
+
readonly NESTED_TABLE_FLATTENED: "rtf/nested-table-flattened";
|
|
21
|
+
readonly CONSTRUCT_UNREPRESENTED: "rtf/construct-unrepresented";
|
|
22
|
+
readonly EMBEDDED_OBJECT_DROPPED: "rtf/embedded-object-dropped";
|
|
23
|
+
readonly PACKAGE_TABLE_DROPPED: "rtf/package-table-dropped";
|
|
24
|
+
readonly CELL_BORDER_DROPPED: "rtf/cell-border-dropped";
|
|
25
|
+
};
|
|
26
|
+
declare class RtfParseError extends Error {
|
|
27
|
+
readonly code: string;
|
|
28
|
+
constructor(code: string, message: string);
|
|
29
|
+
}
|
|
30
|
+
declare class RtfNotAnRtfDocumentError extends RtfParseError {
|
|
31
|
+
constructor(message?: string);
|
|
32
|
+
}
|
|
33
|
+
declare class RtfInputTooLargeError extends RtfParseError {
|
|
34
|
+
readonly byteLength: number;
|
|
35
|
+
readonly maxInputBytes: number;
|
|
36
|
+
constructor(byteLength: number, maxInputBytes: number);
|
|
37
|
+
}
|
|
38
|
+
declare class RtfNestingLimitExceededError extends RtfParseError {
|
|
39
|
+
readonly maxGroupDepth: number;
|
|
40
|
+
constructor(maxGroupDepth: number);
|
|
41
|
+
}
|
|
42
|
+
declare class RtfWriteError extends Error {
|
|
43
|
+
readonly code: string;
|
|
44
|
+
constructor(code: string, message: string);
|
|
45
|
+
}
|
|
46
|
+
declare class RtfUnsupportedDocumentKindError extends RtfWriteError {
|
|
47
|
+
readonly documentKind: string;
|
|
48
|
+
constructor(documentKind: string);
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { RtfDiagnosticSink as a, RtfNotAnRtfDocumentError as c, RtfWriteError as d, RtfDiagnosticSeverity as i, RtfParseError as l, RtfDiagnostic as n, RtfInputTooLargeError as o, RtfDiagnosticCodes as r, RtfNestingLimitExceededError as s, NOOP_RTF_DIAGNOSTIC_SINK as t, RtfUnsupportedDocumentKindError as u };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/diagnostics.d.ts
|
|
2
|
+
type RtfDiagnosticSeverity = "info" | "warning";
|
|
3
|
+
interface RtfDiagnostic {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly severity: RtfDiagnosticSeverity;
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly tokenIndex?: number;
|
|
8
|
+
}
|
|
9
|
+
type RtfDiagnosticSink = (diagnostic: RtfDiagnostic) => void;
|
|
10
|
+
declare const NOOP_RTF_DIAGNOSTIC_SINK: RtfDiagnosticSink;
|
|
11
|
+
declare const RtfDiagnosticCodes: {
|
|
12
|
+
readonly UNBALANCED_GROUP: "rtf/unbalanced-group";
|
|
13
|
+
readonly UNKNOWN_DESTINATION_SKIPPED: "rtf/unknown-destination-skipped";
|
|
14
|
+
readonly CONTENT_DESTINATION_SKIPPED: "rtf/content-destination-skipped";
|
|
15
|
+
readonly UNSUPPORTED_CODEPAGE: "rtf/unsupported-codepage";
|
|
16
|
+
readonly UNSUPPORTED_PICTURE_FORMAT: "rtf/unsupported-picture-format";
|
|
17
|
+
readonly PICTURE_SIZE_UNSTATED: "rtf/picture-size-unstated";
|
|
18
|
+
readonly TABLE_ROW_WITHOUT_DEFINITION: "rtf/table-row-without-definition";
|
|
19
|
+
readonly TABLE_COLUMN_WIDTH_INVALID: "rtf/table-column-width-invalid";
|
|
20
|
+
readonly NESTED_TABLE_FLATTENED: "rtf/nested-table-flattened";
|
|
21
|
+
readonly CONSTRUCT_UNREPRESENTED: "rtf/construct-unrepresented";
|
|
22
|
+
readonly EMBEDDED_OBJECT_DROPPED: "rtf/embedded-object-dropped";
|
|
23
|
+
readonly PACKAGE_TABLE_DROPPED: "rtf/package-table-dropped";
|
|
24
|
+
readonly CELL_BORDER_DROPPED: "rtf/cell-border-dropped";
|
|
25
|
+
};
|
|
26
|
+
declare class RtfParseError extends Error {
|
|
27
|
+
readonly code: string;
|
|
28
|
+
constructor(code: string, message: string);
|
|
29
|
+
}
|
|
30
|
+
declare class RtfNotAnRtfDocumentError extends RtfParseError {
|
|
31
|
+
constructor(message?: string);
|
|
32
|
+
}
|
|
33
|
+
declare class RtfInputTooLargeError extends RtfParseError {
|
|
34
|
+
readonly byteLength: number;
|
|
35
|
+
readonly maxInputBytes: number;
|
|
36
|
+
constructor(byteLength: number, maxInputBytes: number);
|
|
37
|
+
}
|
|
38
|
+
declare class RtfNestingLimitExceededError extends RtfParseError {
|
|
39
|
+
readonly maxGroupDepth: number;
|
|
40
|
+
constructor(maxGroupDepth: number);
|
|
41
|
+
}
|
|
42
|
+
declare class RtfWriteError extends Error {
|
|
43
|
+
readonly code: string;
|
|
44
|
+
constructor(code: string, message: string);
|
|
45
|
+
}
|
|
46
|
+
declare class RtfUnsupportedDocumentKindError extends RtfWriteError {
|
|
47
|
+
readonly documentKind: string;
|
|
48
|
+
constructor(documentKind: string);
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { RtfDiagnosticSink as a, RtfNotAnRtfDocumentError as c, RtfWriteError as d, RtfDiagnosticSeverity as i, RtfParseError as l, RtfDiagnostic as n, RtfInputTooLargeError as o, RtfDiagnosticCodes as r, RtfNestingLimitExceededError as s, NOOP_RTF_DIAGNOSTIC_SINK as t, RtfUnsupportedDocumentKindError as u };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/diagnostics.ts
|
|
3
|
+
const NOOP_RTF_DIAGNOSTIC_SINK = () => {};
|
|
4
|
+
const RtfDiagnosticCodes = {
|
|
5
|
+
UNBALANCED_GROUP: "rtf/unbalanced-group",
|
|
6
|
+
UNKNOWN_DESTINATION_SKIPPED: "rtf/unknown-destination-skipped",
|
|
7
|
+
CONTENT_DESTINATION_SKIPPED: "rtf/content-destination-skipped",
|
|
8
|
+
UNSUPPORTED_CODEPAGE: "rtf/unsupported-codepage",
|
|
9
|
+
UNSUPPORTED_PICTURE_FORMAT: "rtf/unsupported-picture-format",
|
|
10
|
+
PICTURE_SIZE_UNSTATED: "rtf/picture-size-unstated",
|
|
11
|
+
TABLE_ROW_WITHOUT_DEFINITION: "rtf/table-row-without-definition",
|
|
12
|
+
TABLE_COLUMN_WIDTH_INVALID: "rtf/table-column-width-invalid",
|
|
13
|
+
NESTED_TABLE_FLATTENED: "rtf/nested-table-flattened",
|
|
14
|
+
CONSTRUCT_UNREPRESENTED: "rtf/construct-unrepresented",
|
|
15
|
+
EMBEDDED_OBJECT_DROPPED: "rtf/embedded-object-dropped",
|
|
16
|
+
PACKAGE_TABLE_DROPPED: "rtf/package-table-dropped",
|
|
17
|
+
CELL_BORDER_DROPPED: "rtf/cell-border-dropped"
|
|
18
|
+
};
|
|
19
|
+
var RtfParseError = class extends Error {
|
|
20
|
+
code;
|
|
21
|
+
constructor(code, message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = "RtfParseError";
|
|
24
|
+
this.code = code;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var RtfNotAnRtfDocumentError = class extends RtfParseError {
|
|
28
|
+
constructor(message = "input does not begin with '{\\rtf'") {
|
|
29
|
+
super("rtf/not-an-rtf-document", message);
|
|
30
|
+
this.name = "RtfNotAnRtfDocumentError";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var RtfInputTooLargeError = class extends RtfParseError {
|
|
34
|
+
byteLength;
|
|
35
|
+
maxInputBytes;
|
|
36
|
+
constructor(byteLength, maxInputBytes) {
|
|
37
|
+
super("rtf/input-too-large", `input is ${String(byteLength)} bytes, over the ${String(maxInputBytes)}-byte limit`);
|
|
38
|
+
this.name = "RtfInputTooLargeError";
|
|
39
|
+
this.byteLength = byteLength;
|
|
40
|
+
this.maxInputBytes = maxInputBytes;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var RtfNestingLimitExceededError = class extends RtfParseError {
|
|
44
|
+
maxGroupDepth;
|
|
45
|
+
constructor(maxGroupDepth) {
|
|
46
|
+
super("rtf/nesting-limit-exceeded", `group nesting exceeded the ${String(maxGroupDepth)}-level limit`);
|
|
47
|
+
this.name = "RtfNestingLimitExceededError";
|
|
48
|
+
this.maxGroupDepth = maxGroupDepth;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var RtfWriteError = class extends Error {
|
|
52
|
+
code;
|
|
53
|
+
constructor(code, message) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.name = "RtfWriteError";
|
|
56
|
+
this.code = code;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var RtfUnsupportedDocumentKindError = class extends RtfWriteError {
|
|
60
|
+
documentKind;
|
|
61
|
+
constructor(documentKind) {
|
|
62
|
+
super("rtf/unsupported-document-kind", `RTF is a wordprocessing format; a '${documentKind}' ContentDocument has no RTF representation`);
|
|
63
|
+
this.name = "RtfUnsupportedDocumentKindError";
|
|
64
|
+
this.documentKind = documentKind;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
exports.NOOP_RTF_DIAGNOSTIC_SINK = NOOP_RTF_DIAGNOSTIC_SINK;
|
|
69
|
+
exports.RtfDiagnosticCodes = RtfDiagnosticCodes;
|
|
70
|
+
exports.RtfInputTooLargeError = RtfInputTooLargeError;
|
|
71
|
+
exports.RtfNestingLimitExceededError = RtfNestingLimitExceededError;
|
|
72
|
+
exports.RtfNotAnRtfDocumentError = RtfNotAnRtfDocumentError;
|
|
73
|
+
exports.RtfParseError = RtfParseError;
|
|
74
|
+
exports.RtfUnsupportedDocumentKindError = RtfUnsupportedDocumentKindError;
|
|
75
|
+
exports.RtfWriteError = RtfWriteError;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
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";
|
|
2
|
+
export { NOOP_RTF_DIAGNOSTIC_SINK, RtfDiagnostic, RtfDiagnosticCodes, RtfDiagnosticSeverity, RtfDiagnosticSink, RtfInputTooLargeError, RtfNestingLimitExceededError, RtfNotAnRtfDocumentError, RtfParseError, RtfUnsupportedDocumentKindError, RtfWriteError };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
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";
|
|
2
|
+
export { NOOP_RTF_DIAGNOSTIC_SINK, RtfDiagnostic, RtfDiagnosticCodes, RtfDiagnosticSeverity, RtfDiagnosticSink, RtfInputTooLargeError, RtfNestingLimitExceededError, RtfNotAnRtfDocumentError, RtfParseError, RtfUnsupportedDocumentKindError, RtfWriteError };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region src/diagnostics.ts
|
|
2
|
+
const NOOP_RTF_DIAGNOSTIC_SINK = () => {};
|
|
3
|
+
const RtfDiagnosticCodes = {
|
|
4
|
+
UNBALANCED_GROUP: "rtf/unbalanced-group",
|
|
5
|
+
UNKNOWN_DESTINATION_SKIPPED: "rtf/unknown-destination-skipped",
|
|
6
|
+
CONTENT_DESTINATION_SKIPPED: "rtf/content-destination-skipped",
|
|
7
|
+
UNSUPPORTED_CODEPAGE: "rtf/unsupported-codepage",
|
|
8
|
+
UNSUPPORTED_PICTURE_FORMAT: "rtf/unsupported-picture-format",
|
|
9
|
+
PICTURE_SIZE_UNSTATED: "rtf/picture-size-unstated",
|
|
10
|
+
TABLE_ROW_WITHOUT_DEFINITION: "rtf/table-row-without-definition",
|
|
11
|
+
TABLE_COLUMN_WIDTH_INVALID: "rtf/table-column-width-invalid",
|
|
12
|
+
NESTED_TABLE_FLATTENED: "rtf/nested-table-flattened",
|
|
13
|
+
CONSTRUCT_UNREPRESENTED: "rtf/construct-unrepresented",
|
|
14
|
+
EMBEDDED_OBJECT_DROPPED: "rtf/embedded-object-dropped",
|
|
15
|
+
PACKAGE_TABLE_DROPPED: "rtf/package-table-dropped",
|
|
16
|
+
CELL_BORDER_DROPPED: "rtf/cell-border-dropped"
|
|
17
|
+
};
|
|
18
|
+
var RtfParseError = class extends Error {
|
|
19
|
+
code;
|
|
20
|
+
constructor(code, message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "RtfParseError";
|
|
23
|
+
this.code = code;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var RtfNotAnRtfDocumentError = class extends RtfParseError {
|
|
27
|
+
constructor(message = "input does not begin with '{\\rtf'") {
|
|
28
|
+
super("rtf/not-an-rtf-document", message);
|
|
29
|
+
this.name = "RtfNotAnRtfDocumentError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var RtfInputTooLargeError = class extends RtfParseError {
|
|
33
|
+
byteLength;
|
|
34
|
+
maxInputBytes;
|
|
35
|
+
constructor(byteLength, maxInputBytes) {
|
|
36
|
+
super("rtf/input-too-large", `input is ${String(byteLength)} bytes, over the ${String(maxInputBytes)}-byte limit`);
|
|
37
|
+
this.name = "RtfInputTooLargeError";
|
|
38
|
+
this.byteLength = byteLength;
|
|
39
|
+
this.maxInputBytes = maxInputBytes;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var RtfNestingLimitExceededError = class extends RtfParseError {
|
|
43
|
+
maxGroupDepth;
|
|
44
|
+
constructor(maxGroupDepth) {
|
|
45
|
+
super("rtf/nesting-limit-exceeded", `group nesting exceeded the ${String(maxGroupDepth)}-level limit`);
|
|
46
|
+
this.name = "RtfNestingLimitExceededError";
|
|
47
|
+
this.maxGroupDepth = maxGroupDepth;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var RtfWriteError = class extends Error {
|
|
51
|
+
code;
|
|
52
|
+
constructor(code, message) {
|
|
53
|
+
super(message);
|
|
54
|
+
this.name = "RtfWriteError";
|
|
55
|
+
this.code = code;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var RtfUnsupportedDocumentKindError = class extends RtfWriteError {
|
|
59
|
+
documentKind;
|
|
60
|
+
constructor(documentKind) {
|
|
61
|
+
super("rtf/unsupported-document-kind", `RTF is a wordprocessing format; a '${documentKind}' ContentDocument has no RTF representation`);
|
|
62
|
+
this.name = "RtfUnsupportedDocumentKindError";
|
|
63
|
+
this.documentKind = documentKind;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { NOOP_RTF_DIAGNOSTIC_SINK, RtfDiagnosticCodes, RtfInputTooLargeError, RtfNestingLimitExceededError, RtfNotAnRtfDocumentError, RtfParseError, RtfUnsupportedDocumentKindError, RtfWriteError };
|
package/dist/group.cjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/group.ts
|
|
3
|
+
function matchingGroupEnd(tokens, start) {
|
|
4
|
+
let depth = 0;
|
|
5
|
+
for (let index = start; index < tokens.length; index += 1) {
|
|
6
|
+
const kind = tokens[index]?.kind;
|
|
7
|
+
if (kind === "groupStart") {
|
|
8
|
+
depth += 1;
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (kind === "groupEnd") {
|
|
12
|
+
depth -= 1;
|
|
13
|
+
if (depth === 0) return index;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return tokens.length;
|
|
17
|
+
}
|
|
18
|
+
function groupHead(tokens, start) {
|
|
19
|
+
let cursor = start + 1;
|
|
20
|
+
let ignorable = false;
|
|
21
|
+
const first = tokens[cursor];
|
|
22
|
+
if (first?.kind === "controlSymbol" && first.symbol === "*") {
|
|
23
|
+
ignorable = true;
|
|
24
|
+
cursor += 1;
|
|
25
|
+
}
|
|
26
|
+
const head = tokens[cursor];
|
|
27
|
+
if (head?.kind !== "controlWord") return {
|
|
28
|
+
destination: void 0,
|
|
29
|
+
ignorable,
|
|
30
|
+
contentStart: cursor
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
destination: head.name,
|
|
34
|
+
ignorable,
|
|
35
|
+
contentStart: cursor + 1
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.groupHead = groupHead;
|
|
40
|
+
exports.matchingGroupEnd = matchingGroupEnd;
|
package/dist/group.d.cts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RtfToken } from "./tokenize.cjs";
|
|
2
|
+
//#region src/group.d.ts
|
|
3
|
+
interface GroupHead {
|
|
4
|
+
readonly destination: string | undefined;
|
|
5
|
+
readonly ignorable: boolean;
|
|
6
|
+
readonly contentStart: number;
|
|
7
|
+
}
|
|
8
|
+
declare function matchingGroupEnd(tokens: readonly RtfToken[], start: number): number;
|
|
9
|
+
declare function groupHead(tokens: readonly RtfToken[], start: number): GroupHead;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { GroupHead, groupHead, matchingGroupEnd };
|
package/dist/group.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RtfToken } from "./tokenize.js";
|
|
2
|
+
//#region src/group.d.ts
|
|
3
|
+
interface GroupHead {
|
|
4
|
+
readonly destination: string | undefined;
|
|
5
|
+
readonly ignorable: boolean;
|
|
6
|
+
readonly contentStart: number;
|
|
7
|
+
}
|
|
8
|
+
declare function matchingGroupEnd(tokens: readonly RtfToken[], start: number): number;
|
|
9
|
+
declare function groupHead(tokens: readonly RtfToken[], start: number): GroupHead;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { GroupHead, groupHead, matchingGroupEnd };
|
package/dist/group.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/group.ts
|
|
2
|
+
function matchingGroupEnd(tokens, start) {
|
|
3
|
+
let depth = 0;
|
|
4
|
+
for (let index = start; index < tokens.length; index += 1) {
|
|
5
|
+
const kind = tokens[index]?.kind;
|
|
6
|
+
if (kind === "groupStart") {
|
|
7
|
+
depth += 1;
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
if (kind === "groupEnd") {
|
|
11
|
+
depth -= 1;
|
|
12
|
+
if (depth === 0) return index;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return tokens.length;
|
|
16
|
+
}
|
|
17
|
+
function groupHead(tokens, start) {
|
|
18
|
+
let cursor = start + 1;
|
|
19
|
+
let ignorable = false;
|
|
20
|
+
const first = tokens[cursor];
|
|
21
|
+
if (first?.kind === "controlSymbol" && first.symbol === "*") {
|
|
22
|
+
ignorable = true;
|
|
23
|
+
cursor += 1;
|
|
24
|
+
}
|
|
25
|
+
const head = tokens[cursor];
|
|
26
|
+
if (head?.kind !== "controlWord") return {
|
|
27
|
+
destination: void 0,
|
|
28
|
+
ignorable,
|
|
29
|
+
contentStart: cursor
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
destination: head.name,
|
|
33
|
+
ignorable,
|
|
34
|
+
contentStart: cursor + 1
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { groupHead, matchingGroupEnd };
|