rtf-codec 0.0.0 → 1.1.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 +226 -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/cell-format.cjs +142 -0
- package/dist/cell-format.d.cts +25 -0
- package/dist/cell-format.d.ts +25 -0
- package/dist/cell-format.js +137 -0
- package/dist/codec.cjs +29 -0
- package/dist/codec.d.cts +2344 -0
- package/dist/codec.d.ts +2344 -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/constructs.cjs +131 -0
- package/dist/constructs.d.cts +31 -0
- package/dist/constructs.d.ts +31 -0
- package/dist/constructs.js +121 -0
- package/dist/diagnostics-BgG_KAiN.d.cts +52 -0
- package/dist/diagnostics-BgG_KAiN.d.ts +52 -0
- package/dist/diagnostics.cjs +76 -0
- package/dist/diagnostics.d.cts +2 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.js +68 -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 +433 -0
- package/dist/header.d.cts +44 -0
- package/dist/header.d.ts +44 -0
- package/dist/header.js +431 -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 +1211 -0
- package/dist/read.d.cts +16 -0
- package/dist/read.d.ts +16 -0
- package/dist/read.js +1209 -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 +532 -0
- package/dist/write.d.cts +7 -0
- package/dist/write.d.ts +7 -0
- package/dist/write.js +530 -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-BgG_KAiN.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-BgG_KAiN.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,131 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/constructs.ts
|
|
3
|
+
const RTF_SOURCE_FORMAT = "rtf";
|
|
4
|
+
function bookmarkAnchorDescriptor(name, columns) {
|
|
5
|
+
const residue = bookmarkColumnResidue(columns);
|
|
6
|
+
return {
|
|
7
|
+
kind: "anchor",
|
|
8
|
+
anchorType: "bookmark",
|
|
9
|
+
name,
|
|
10
|
+
...residue === void 0 ? {} : { source: {
|
|
11
|
+
format: "rtf",
|
|
12
|
+
xml: residue
|
|
13
|
+
} }
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function bookmarkColumnResidue(columns) {
|
|
17
|
+
if (columns === void 0) return;
|
|
18
|
+
const parts = [columns.first === void 0 ? "" : `\\bkmkcolf${String(columns.first)}`, columns.last === void 0 ? "" : `\\bkmkcoll${String(columns.last)}`].join("");
|
|
19
|
+
return parts.length === 0 ? void 0 : parts;
|
|
20
|
+
}
|
|
21
|
+
function bookmarkResidueControlWords(descriptor) {
|
|
22
|
+
const source = descriptor.source;
|
|
23
|
+
return source?.format === "rtf" ? source.xml : "";
|
|
24
|
+
}
|
|
25
|
+
function isBookmarkAnchor(descriptor) {
|
|
26
|
+
return descriptor.kind === "anchor" && descriptor.anchorType === "bookmark";
|
|
27
|
+
}
|
|
28
|
+
const NO_REVISION = {
|
|
29
|
+
revised: false,
|
|
30
|
+
revisedAuthor: void 0,
|
|
31
|
+
revisedDateTime: void 0,
|
|
32
|
+
deleted: false,
|
|
33
|
+
deletedAuthor: void 0,
|
|
34
|
+
deletedDateTime: void 0,
|
|
35
|
+
moved: void 0,
|
|
36
|
+
movedAuthor: void 0,
|
|
37
|
+
movedDateTime: void 0,
|
|
38
|
+
formatAuthor: void 0,
|
|
39
|
+
formatDateTime: void 0
|
|
40
|
+
};
|
|
41
|
+
function hasRevision(state) {
|
|
42
|
+
return state.revised || state.deleted || state.moved !== void 0 || state.formatAuthor !== void 0;
|
|
43
|
+
}
|
|
44
|
+
function provenanceDescriptors(state, authors) {
|
|
45
|
+
const out = [];
|
|
46
|
+
if (state.revised) out.push(provenanceDescriptor("insertion", state.revisedAuthor, state.revisedDateTime, authors));
|
|
47
|
+
if (state.deleted) out.push(provenanceDescriptor("deletion", state.deletedAuthor, state.deletedDateTime, authors));
|
|
48
|
+
if (state.moved !== void 0) out.push(provenanceDescriptor(state.moved, state.movedAuthor, state.movedDateTime, authors));
|
|
49
|
+
if (state.formatAuthor !== void 0) out.push(provenanceDescriptor("formatChange", state.formatAuthor, state.formatDateTime, authors));
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
function provenanceDescriptor(change, authorIndex, dateTime, authors) {
|
|
53
|
+
const author = authorIndex === void 0 ? void 0 : authors[authorIndex];
|
|
54
|
+
const dateIso = dateTime === void 0 ? void 0 : isoFromDttm(dateTime);
|
|
55
|
+
return {
|
|
56
|
+
kind: "provenance",
|
|
57
|
+
change,
|
|
58
|
+
...author === void 0 || author.length === 0 ? {} : { author },
|
|
59
|
+
...dateIso === void 0 ? {} : { dateIso }
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const DTTM_MINUTE_MASK = 63;
|
|
63
|
+
const DTTM_HOUR_SHIFT = 6;
|
|
64
|
+
const DTTM_HOUR_MASK = 31;
|
|
65
|
+
const DTTM_DAY_SHIFT = 11;
|
|
66
|
+
const DTTM_DAY_MASK = 31;
|
|
67
|
+
const DTTM_MONTH_SHIFT = 16;
|
|
68
|
+
const DTTM_MONTH_MASK = 15;
|
|
69
|
+
const DTTM_YEAR_SHIFT = 20;
|
|
70
|
+
const DTTM_YEAR_MASK = 511;
|
|
71
|
+
const DTTM_YEAR_EPOCH = 1900;
|
|
72
|
+
function isoFromDttm(value) {
|
|
73
|
+
const bits = value >>> 0;
|
|
74
|
+
const minute = bits & DTTM_MINUTE_MASK;
|
|
75
|
+
const hour = bits >>> DTTM_HOUR_SHIFT & DTTM_HOUR_MASK;
|
|
76
|
+
const day = bits >>> DTTM_DAY_SHIFT & DTTM_DAY_MASK;
|
|
77
|
+
const month = bits >>> DTTM_MONTH_SHIFT & DTTM_MONTH_MASK;
|
|
78
|
+
const year = (bits >>> DTTM_YEAR_SHIFT & DTTM_YEAR_MASK) + DTTM_YEAR_EPOCH;
|
|
79
|
+
if (day === 0 || month === 0 || month > 12 || day > 31) return;
|
|
80
|
+
return `${pad(year, 4)}-${pad(month, 2)}-${pad(day, 2)}T${pad(hour, 2)}:${pad(minute, 2)}:00`;
|
|
81
|
+
}
|
|
82
|
+
const ISO_DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::\d{2}(?:\.\d+)?)?)?/;
|
|
83
|
+
function dttmFromIso(dateIso) {
|
|
84
|
+
const match = ISO_DATE_TIME.exec(dateIso);
|
|
85
|
+
if (match === null) return;
|
|
86
|
+
const year = Number(match[1]) - DTTM_YEAR_EPOCH;
|
|
87
|
+
const month = Number(match[2]);
|
|
88
|
+
const day = Number(match[3]);
|
|
89
|
+
const hour = match[4] === void 0 ? 0 : Number(match[4]);
|
|
90
|
+
const minute = match[5] === void 0 ? 0 : Number(match[5]);
|
|
91
|
+
if (year < 0 || year > DTTM_YEAR_MASK) return;
|
|
92
|
+
return minute & DTTM_MINUTE_MASK | (hour & DTTM_HOUR_MASK) << DTTM_HOUR_SHIFT | (day & DTTM_DAY_MASK) << DTTM_DAY_SHIFT | (month & DTTM_MONTH_MASK) << DTTM_MONTH_SHIFT | (year & DTTM_YEAR_MASK) << DTTM_YEAR_SHIFT | 0;
|
|
93
|
+
}
|
|
94
|
+
function pad(value, width) {
|
|
95
|
+
return String(value).padStart(width, "0");
|
|
96
|
+
}
|
|
97
|
+
function coalesceRunConstructs(perRun) {
|
|
98
|
+
const open = /* @__PURE__ */ new Map();
|
|
99
|
+
const out = [];
|
|
100
|
+
const close = (key, end) => {
|
|
101
|
+
const entry = open.get(key);
|
|
102
|
+
if (entry === void 0) return;
|
|
103
|
+
out.push({
|
|
104
|
+
descriptor: entry.descriptor,
|
|
105
|
+
startRun: entry.start,
|
|
106
|
+
endRun: end
|
|
107
|
+
});
|
|
108
|
+
open.delete(key);
|
|
109
|
+
};
|
|
110
|
+
for (const [index, descriptors] of perRun.entries()) {
|
|
111
|
+
const present = new Map(descriptors.map((descriptor) => [JSON.stringify(descriptor), descriptor]));
|
|
112
|
+
for (const key of [...open.keys()]) if (!present.has(key)) close(key, index);
|
|
113
|
+
for (const [key, descriptor] of present) if (!open.has(key)) open.set(key, {
|
|
114
|
+
descriptor,
|
|
115
|
+
start: index
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
for (const key of [...open.keys()]) close(key, perRun.length);
|
|
119
|
+
return out.sort((left, right) => left.startRun - right.startRun || left.endRun - right.endRun);
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
exports.NO_REVISION = NO_REVISION;
|
|
123
|
+
exports.RTF_SOURCE_FORMAT = RTF_SOURCE_FORMAT;
|
|
124
|
+
exports.bookmarkAnchorDescriptor = bookmarkAnchorDescriptor;
|
|
125
|
+
exports.bookmarkResidueControlWords = bookmarkResidueControlWords;
|
|
126
|
+
exports.coalesceRunConstructs = coalesceRunConstructs;
|
|
127
|
+
exports.dttmFromIso = dttmFromIso;
|
|
128
|
+
exports.hasRevision = hasRevision;
|
|
129
|
+
exports.isBookmarkAnchor = isBookmarkAnchor;
|
|
130
|
+
exports.isoFromDttm = isoFromDttm;
|
|
131
|
+
exports.provenanceDescriptors = provenanceDescriptors;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AnchorDescriptor, ConstructDescriptor, ProvenanceDescriptor, RunConstructExtent } from "document-schema.js";
|
|
2
|
+
//#region src/constructs.d.ts
|
|
3
|
+
declare const RTF_SOURCE_FORMAT: "rtf";
|
|
4
|
+
interface BookmarkColumnRange {
|
|
5
|
+
readonly first: number | undefined;
|
|
6
|
+
readonly last: number | undefined;
|
|
7
|
+
}
|
|
8
|
+
declare function bookmarkAnchorDescriptor(name: string, columns: BookmarkColumnRange | undefined): AnchorDescriptor;
|
|
9
|
+
declare function bookmarkResidueControlWords(descriptor: AnchorDescriptor): string;
|
|
10
|
+
declare function isBookmarkAnchor(descriptor: ConstructDescriptor): descriptor is AnchorDescriptor;
|
|
11
|
+
interface RevisionState {
|
|
12
|
+
readonly revised: boolean;
|
|
13
|
+
readonly revisedAuthor: number | undefined;
|
|
14
|
+
readonly revisedDateTime: number | undefined;
|
|
15
|
+
readonly deleted: boolean;
|
|
16
|
+
readonly deletedAuthor: number | undefined;
|
|
17
|
+
readonly deletedDateTime: number | undefined;
|
|
18
|
+
readonly moved: "moveFrom" | "moveTo" | undefined;
|
|
19
|
+
readonly movedAuthor: number | undefined;
|
|
20
|
+
readonly movedDateTime: number | undefined;
|
|
21
|
+
readonly formatAuthor: number | undefined;
|
|
22
|
+
readonly formatDateTime: number | undefined;
|
|
23
|
+
}
|
|
24
|
+
declare const NO_REVISION: RevisionState;
|
|
25
|
+
declare function hasRevision(state: RevisionState): boolean;
|
|
26
|
+
declare function provenanceDescriptors(state: RevisionState, authors: readonly string[]): ProvenanceDescriptor[];
|
|
27
|
+
declare function isoFromDttm(value: number): string | undefined;
|
|
28
|
+
declare function dttmFromIso(dateIso: string): number | undefined;
|
|
29
|
+
declare function coalesceRunConstructs(perRun: readonly (readonly ConstructDescriptor[])[]): RunConstructExtent[];
|
|
30
|
+
//#endregion
|
|
31
|
+
export { BookmarkColumnRange, NO_REVISION, RTF_SOURCE_FORMAT, RevisionState, bookmarkAnchorDescriptor, bookmarkResidueControlWords, coalesceRunConstructs, dttmFromIso, hasRevision, isBookmarkAnchor, isoFromDttm, provenanceDescriptors };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AnchorDescriptor, ConstructDescriptor, ProvenanceDescriptor, RunConstructExtent } from "document-schema.js";
|
|
2
|
+
//#region src/constructs.d.ts
|
|
3
|
+
declare const RTF_SOURCE_FORMAT: "rtf";
|
|
4
|
+
interface BookmarkColumnRange {
|
|
5
|
+
readonly first: number | undefined;
|
|
6
|
+
readonly last: number | undefined;
|
|
7
|
+
}
|
|
8
|
+
declare function bookmarkAnchorDescriptor(name: string, columns: BookmarkColumnRange | undefined): AnchorDescriptor;
|
|
9
|
+
declare function bookmarkResidueControlWords(descriptor: AnchorDescriptor): string;
|
|
10
|
+
declare function isBookmarkAnchor(descriptor: ConstructDescriptor): descriptor is AnchorDescriptor;
|
|
11
|
+
interface RevisionState {
|
|
12
|
+
readonly revised: boolean;
|
|
13
|
+
readonly revisedAuthor: number | undefined;
|
|
14
|
+
readonly revisedDateTime: number | undefined;
|
|
15
|
+
readonly deleted: boolean;
|
|
16
|
+
readonly deletedAuthor: number | undefined;
|
|
17
|
+
readonly deletedDateTime: number | undefined;
|
|
18
|
+
readonly moved: "moveFrom" | "moveTo" | undefined;
|
|
19
|
+
readonly movedAuthor: number | undefined;
|
|
20
|
+
readonly movedDateTime: number | undefined;
|
|
21
|
+
readonly formatAuthor: number | undefined;
|
|
22
|
+
readonly formatDateTime: number | undefined;
|
|
23
|
+
}
|
|
24
|
+
declare const NO_REVISION: RevisionState;
|
|
25
|
+
declare function hasRevision(state: RevisionState): boolean;
|
|
26
|
+
declare function provenanceDescriptors(state: RevisionState, authors: readonly string[]): ProvenanceDescriptor[];
|
|
27
|
+
declare function isoFromDttm(value: number): string | undefined;
|
|
28
|
+
declare function dttmFromIso(dateIso: string): number | undefined;
|
|
29
|
+
declare function coalesceRunConstructs(perRun: readonly (readonly ConstructDescriptor[])[]): RunConstructExtent[];
|
|
30
|
+
//#endregion
|
|
31
|
+
export { BookmarkColumnRange, NO_REVISION, RTF_SOURCE_FORMAT, RevisionState, bookmarkAnchorDescriptor, bookmarkResidueControlWords, coalesceRunConstructs, dttmFromIso, hasRevision, isBookmarkAnchor, isoFromDttm, provenanceDescriptors };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
//#region src/constructs.ts
|
|
2
|
+
const RTF_SOURCE_FORMAT = "rtf";
|
|
3
|
+
function bookmarkAnchorDescriptor(name, columns) {
|
|
4
|
+
const residue = bookmarkColumnResidue(columns);
|
|
5
|
+
return {
|
|
6
|
+
kind: "anchor",
|
|
7
|
+
anchorType: "bookmark",
|
|
8
|
+
name,
|
|
9
|
+
...residue === void 0 ? {} : { source: {
|
|
10
|
+
format: "rtf",
|
|
11
|
+
xml: residue
|
|
12
|
+
} }
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function bookmarkColumnResidue(columns) {
|
|
16
|
+
if (columns === void 0) return;
|
|
17
|
+
const parts = [columns.first === void 0 ? "" : `\\bkmkcolf${String(columns.first)}`, columns.last === void 0 ? "" : `\\bkmkcoll${String(columns.last)}`].join("");
|
|
18
|
+
return parts.length === 0 ? void 0 : parts;
|
|
19
|
+
}
|
|
20
|
+
function bookmarkResidueControlWords(descriptor) {
|
|
21
|
+
const source = descriptor.source;
|
|
22
|
+
return source?.format === "rtf" ? source.xml : "";
|
|
23
|
+
}
|
|
24
|
+
function isBookmarkAnchor(descriptor) {
|
|
25
|
+
return descriptor.kind === "anchor" && descriptor.anchorType === "bookmark";
|
|
26
|
+
}
|
|
27
|
+
const NO_REVISION = {
|
|
28
|
+
revised: false,
|
|
29
|
+
revisedAuthor: void 0,
|
|
30
|
+
revisedDateTime: void 0,
|
|
31
|
+
deleted: false,
|
|
32
|
+
deletedAuthor: void 0,
|
|
33
|
+
deletedDateTime: void 0,
|
|
34
|
+
moved: void 0,
|
|
35
|
+
movedAuthor: void 0,
|
|
36
|
+
movedDateTime: void 0,
|
|
37
|
+
formatAuthor: void 0,
|
|
38
|
+
formatDateTime: void 0
|
|
39
|
+
};
|
|
40
|
+
function hasRevision(state) {
|
|
41
|
+
return state.revised || state.deleted || state.moved !== void 0 || state.formatAuthor !== void 0;
|
|
42
|
+
}
|
|
43
|
+
function provenanceDescriptors(state, authors) {
|
|
44
|
+
const out = [];
|
|
45
|
+
if (state.revised) out.push(provenanceDescriptor("insertion", state.revisedAuthor, state.revisedDateTime, authors));
|
|
46
|
+
if (state.deleted) out.push(provenanceDescriptor("deletion", state.deletedAuthor, state.deletedDateTime, authors));
|
|
47
|
+
if (state.moved !== void 0) out.push(provenanceDescriptor(state.moved, state.movedAuthor, state.movedDateTime, authors));
|
|
48
|
+
if (state.formatAuthor !== void 0) out.push(provenanceDescriptor("formatChange", state.formatAuthor, state.formatDateTime, authors));
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
function provenanceDescriptor(change, authorIndex, dateTime, authors) {
|
|
52
|
+
const author = authorIndex === void 0 ? void 0 : authors[authorIndex];
|
|
53
|
+
const dateIso = dateTime === void 0 ? void 0 : isoFromDttm(dateTime);
|
|
54
|
+
return {
|
|
55
|
+
kind: "provenance",
|
|
56
|
+
change,
|
|
57
|
+
...author === void 0 || author.length === 0 ? {} : { author },
|
|
58
|
+
...dateIso === void 0 ? {} : { dateIso }
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const DTTM_MINUTE_MASK = 63;
|
|
62
|
+
const DTTM_HOUR_SHIFT = 6;
|
|
63
|
+
const DTTM_HOUR_MASK = 31;
|
|
64
|
+
const DTTM_DAY_SHIFT = 11;
|
|
65
|
+
const DTTM_DAY_MASK = 31;
|
|
66
|
+
const DTTM_MONTH_SHIFT = 16;
|
|
67
|
+
const DTTM_MONTH_MASK = 15;
|
|
68
|
+
const DTTM_YEAR_SHIFT = 20;
|
|
69
|
+
const DTTM_YEAR_MASK = 511;
|
|
70
|
+
const DTTM_YEAR_EPOCH = 1900;
|
|
71
|
+
function isoFromDttm(value) {
|
|
72
|
+
const bits = value >>> 0;
|
|
73
|
+
const minute = bits & DTTM_MINUTE_MASK;
|
|
74
|
+
const hour = bits >>> DTTM_HOUR_SHIFT & DTTM_HOUR_MASK;
|
|
75
|
+
const day = bits >>> DTTM_DAY_SHIFT & DTTM_DAY_MASK;
|
|
76
|
+
const month = bits >>> DTTM_MONTH_SHIFT & DTTM_MONTH_MASK;
|
|
77
|
+
const year = (bits >>> DTTM_YEAR_SHIFT & DTTM_YEAR_MASK) + DTTM_YEAR_EPOCH;
|
|
78
|
+
if (day === 0 || month === 0 || month > 12 || day > 31) return;
|
|
79
|
+
return `${pad(year, 4)}-${pad(month, 2)}-${pad(day, 2)}T${pad(hour, 2)}:${pad(minute, 2)}:00`;
|
|
80
|
+
}
|
|
81
|
+
const ISO_DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::\d{2}(?:\.\d+)?)?)?/;
|
|
82
|
+
function dttmFromIso(dateIso) {
|
|
83
|
+
const match = ISO_DATE_TIME.exec(dateIso);
|
|
84
|
+
if (match === null) return;
|
|
85
|
+
const year = Number(match[1]) - DTTM_YEAR_EPOCH;
|
|
86
|
+
const month = Number(match[2]);
|
|
87
|
+
const day = Number(match[3]);
|
|
88
|
+
const hour = match[4] === void 0 ? 0 : Number(match[4]);
|
|
89
|
+
const minute = match[5] === void 0 ? 0 : Number(match[5]);
|
|
90
|
+
if (year < 0 || year > DTTM_YEAR_MASK) return;
|
|
91
|
+
return minute & DTTM_MINUTE_MASK | (hour & DTTM_HOUR_MASK) << DTTM_HOUR_SHIFT | (day & DTTM_DAY_MASK) << DTTM_DAY_SHIFT | (month & DTTM_MONTH_MASK) << DTTM_MONTH_SHIFT | (year & DTTM_YEAR_MASK) << DTTM_YEAR_SHIFT | 0;
|
|
92
|
+
}
|
|
93
|
+
function pad(value, width) {
|
|
94
|
+
return String(value).padStart(width, "0");
|
|
95
|
+
}
|
|
96
|
+
function coalesceRunConstructs(perRun) {
|
|
97
|
+
const open = /* @__PURE__ */ new Map();
|
|
98
|
+
const out = [];
|
|
99
|
+
const close = (key, end) => {
|
|
100
|
+
const entry = open.get(key);
|
|
101
|
+
if (entry === void 0) return;
|
|
102
|
+
out.push({
|
|
103
|
+
descriptor: entry.descriptor,
|
|
104
|
+
startRun: entry.start,
|
|
105
|
+
endRun: end
|
|
106
|
+
});
|
|
107
|
+
open.delete(key);
|
|
108
|
+
};
|
|
109
|
+
for (const [index, descriptors] of perRun.entries()) {
|
|
110
|
+
const present = new Map(descriptors.map((descriptor) => [JSON.stringify(descriptor), descriptor]));
|
|
111
|
+
for (const key of [...open.keys()]) if (!present.has(key)) close(key, index);
|
|
112
|
+
for (const [key, descriptor] of present) if (!open.has(key)) open.set(key, {
|
|
113
|
+
descriptor,
|
|
114
|
+
start: index
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
for (const key of [...open.keys()]) close(key, perRun.length);
|
|
118
|
+
return out.sort((left, right) => left.startRun - right.startRun || left.endRun - right.endRun);
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
export { NO_REVISION, RTF_SOURCE_FORMAT, bookmarkAnchorDescriptor, bookmarkResidueControlWords, coalesceRunConstructs, dttmFromIso, hasRevision, isBookmarkAnchor, isoFromDttm, provenanceDescriptors };
|
|
@@ -0,0 +1,52 @@
|
|
|
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 SECTION_BREAK_UNREPRESENTED: "rtf/section-break-unrepresented";
|
|
22
|
+
readonly BOOKMARK_UNPAIRED: "rtf/bookmark-unpaired";
|
|
23
|
+
readonly CONSTRUCT_UNREPRESENTED: "rtf/construct-unrepresented";
|
|
24
|
+
readonly EMBEDDED_OBJECT_DROPPED: "rtf/embedded-object-dropped";
|
|
25
|
+
readonly PACKAGE_TABLE_DROPPED: "rtf/package-table-dropped";
|
|
26
|
+
};
|
|
27
|
+
declare class RtfParseError extends Error {
|
|
28
|
+
readonly code: string;
|
|
29
|
+
constructor(code: string, message: string);
|
|
30
|
+
}
|
|
31
|
+
declare class RtfNotAnRtfDocumentError extends RtfParseError {
|
|
32
|
+
constructor(message?: string);
|
|
33
|
+
}
|
|
34
|
+
declare class RtfInputTooLargeError extends RtfParseError {
|
|
35
|
+
readonly byteLength: number;
|
|
36
|
+
readonly maxInputBytes: number;
|
|
37
|
+
constructor(byteLength: number, maxInputBytes: number);
|
|
38
|
+
}
|
|
39
|
+
declare class RtfNestingLimitExceededError extends RtfParseError {
|
|
40
|
+
readonly maxGroupDepth: number;
|
|
41
|
+
constructor(maxGroupDepth: number);
|
|
42
|
+
}
|
|
43
|
+
declare class RtfWriteError extends Error {
|
|
44
|
+
readonly code: string;
|
|
45
|
+
constructor(code: string, message: string);
|
|
46
|
+
}
|
|
47
|
+
declare class RtfUnsupportedDocumentKindError extends RtfWriteError {
|
|
48
|
+
readonly documentKind: string;
|
|
49
|
+
constructor(documentKind: string);
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
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 };
|