documents.js 1.61.0 → 1.63.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/README.md +120 -47
- package/dist/{blr-types-CYYC3yYU.d.cts → blr-types-DVgO1DQ9.d.cts} +1 -1
- package/dist/{blr-types-CYYC3yYU.d.ts → blr-types-DVgO1DQ9.d.ts} +1 -1
- package/dist/convert/capability.cjs +1 -0
- package/dist/convert/capability.d.cts +1 -1
- package/dist/convert/capability.d.ts +1 -1
- package/dist/convert/capability.js +1 -0
- package/dist/convert/convert.cjs +92 -38
- package/dist/convert/convert.d.cts +11 -4
- package/dist/convert/convert.d.ts +11 -4
- package/dist/convert/convert.js +93 -39
- package/dist/convert/local.cjs +15 -2
- package/dist/convert/local.js +15 -2
- package/dist/convert/port.d.cts +8 -4
- package/dist/convert/port.d.ts +8 -4
- package/dist/edit/docx/content.cjs +75 -13
- package/dist/edit/docx/content.d.cts +8 -2
- package/dist/edit/docx/content.d.ts +8 -2
- package/dist/edit/docx/content.js +75 -13
- package/dist/edit/docx/paragraph.cjs +14 -0
- package/dist/edit/docx/paragraph.d.cts +5 -0
- package/dist/edit/docx/paragraph.d.ts +5 -0
- package/dist/edit/docx/paragraph.js +14 -0
- package/dist/edit/docx/run.cjs +1 -1
- package/dist/edit/docx/run.js +1 -1
- package/dist/edit/docx/table.cjs +41 -0
- package/dist/edit/docx/table.d.cts +7 -1
- package/dist/edit/docx/table.d.ts +7 -1
- package/dist/edit/docx/table.js +42 -1
- package/dist/edit/geometry.cjs +38 -0
- package/dist/edit/geometry.d.cts +7 -0
- package/dist/edit/geometry.d.ts +7 -0
- package/dist/edit/geometry.js +36 -0
- package/dist/edit/odg/content.cjs +15 -12
- package/dist/edit/odg/content.js +15 -12
- package/dist/edit/odg/editor.d.cts +1 -1
- package/dist/edit/odg/editor.d.ts +1 -1
- package/dist/edit/odg/page.d.cts +3 -3
- package/dist/edit/odg/page.d.ts +3 -3
- package/dist/edit/odg/vector.cjs +22 -13
- package/dist/edit/odg/vector.d.cts +1 -1
- package/dist/edit/odg/vector.d.ts +1 -1
- package/dist/edit/odg/vector.js +23 -14
- package/dist/edit/odp/content.cjs +15 -0
- package/dist/edit/odp/content.js +16 -1
- package/dist/edit/odp/editor.d.cts +1 -1
- package/dist/edit/odp/editor.d.ts +1 -1
- package/dist/edit/odp/image.d.cts +1 -1
- package/dist/edit/odp/image.d.ts +1 -1
- package/dist/edit/odp/shape.cjs +11 -30
- package/dist/edit/odp/shape.d.cts +2 -2
- package/dist/edit/odp/shape.d.ts +2 -2
- package/dist/edit/odp/shape.js +13 -33
- package/dist/edit/odp/slide.cjs +11 -0
- package/dist/edit/odp/slide.d.cts +14 -4
- package/dist/edit/odp/slide.d.ts +14 -4
- package/dist/edit/odp/slide.js +12 -1
- package/dist/edit/odt/content.cjs +56 -16
- package/dist/edit/odt/content.d.cts +4 -2
- package/dist/edit/odt/content.d.ts +4 -2
- package/dist/edit/odt/content.js +56 -17
- package/dist/edit/odt/editor.d.cts +1 -1
- package/dist/edit/odt/editor.d.ts +1 -1
- package/dist/edit/odt/table.cjs +36 -0
- package/dist/edit/odt/table.d.cts +1 -36
- package/dist/edit/odt/table.d.ts +1 -36
- package/dist/edit/odt/table.js +37 -1
- package/dist/edit/pptx/content.cjs +71 -3
- package/dist/edit/pptx/content.js +71 -3
- package/dist/edit/pptx/editor.d.cts +1 -1
- package/dist/edit/pptx/editor.d.ts +1 -1
- package/dist/edit/pptx/image.d.cts +1 -1
- package/dist/edit/pptx/image.d.ts +1 -1
- package/dist/edit/pptx/shape.cjs +23 -1
- package/dist/edit/pptx/shape.d.cts +2 -2
- package/dist/edit/pptx/shape.d.ts +2 -2
- package/dist/edit/pptx/shape.js +23 -3
- package/dist/edit/pptx/slide.cjs +10 -1
- package/dist/edit/pptx/slide.d.cts +11 -4
- package/dist/edit/pptx/slide.d.ts +11 -4
- package/dist/edit/pptx/slide.js +10 -1
- package/dist/edit/pptx/table.cjs +136 -0
- package/dist/edit/pptx/table.d.cts +2 -0
- package/dist/edit/pptx/table.d.ts +2 -0
- package/dist/edit/pptx/table.js +131 -0
- package/dist/firebird/backup.d.cts +1 -1
- package/dist/firebird/backup.d.ts +1 -1
- package/dist/firebird/blr-types.cjs +2 -2
- package/dist/firebird/blr-types.d.cts +1 -1
- package/dist/firebird/blr-types.d.ts +1 -1
- package/dist/firebird/blr-types.js +2 -2
- package/dist/firebird/data.cjs +68 -14
- package/dist/firebird/data.d.cts +1 -1
- package/dist/firebird/data.d.ts +1 -1
- package/dist/firebird/data.js +68 -14
- package/dist/firebird/schema.cjs +13 -1
- package/dist/firebird/schema.d.cts +1 -1
- package/dist/firebird/schema.d.ts +1 -1
- package/dist/firebird/schema.js +13 -1
- package/dist/fonts/obfuscation.cjs +50 -0
- package/dist/fonts/obfuscation.d.cts +9 -0
- package/dist/fonts/obfuscation.d.ts +9 -0
- package/dist/fonts/obfuscation.js +46 -0
- package/dist/fonts/odf.cjs +86 -0
- package/dist/fonts/odf.d.cts +9 -0
- package/dist/fonts/odf.d.ts +9 -0
- package/dist/fonts/odf.js +84 -0
- package/dist/fonts/ooxml.cjs +129 -0
- package/dist/fonts/ooxml.d.cts +9 -0
- package/dist/fonts/ooxml.d.ts +9 -0
- package/dist/fonts/ooxml.js +127 -0
- package/dist/fonts/registry.cjs +18 -0
- package/dist/fonts/registry.d.cts +2 -0
- package/dist/fonts/registry.d.ts +2 -0
- package/dist/fonts/registry.js +16 -0
- package/dist/{geometry-DvwdrIij.d.cts → geometry-DaJr8yQW.d.cts} +2 -2
- package/dist/{geometry-DvwdrIij.d.ts → geometry-DaJr8yQW.d.ts} +2 -2
- package/dist/hsqldb/binary-script.cjs +154 -0
- package/dist/hsqldb/binary-script.d.cts +15 -0
- package/dist/hsqldb/binary-script.d.ts +15 -0
- package/dist/hsqldb/binary-script.js +151 -0
- package/dist/hsqldb/cache.cjs +18 -11
- package/dist/hsqldb/cache.d.cts +9 -4
- package/dist/hsqldb/cache.d.ts +9 -4
- package/dist/hsqldb/cache.js +18 -11
- package/dist/hsqldb/rowformat.cjs +60 -16
- package/dist/hsqldb/rowformat.d.cts +2 -21
- package/dist/hsqldb/rowformat.d.ts +2 -21
- package/dist/hsqldb/rowformat.js +60 -17
- package/dist/{image-BZDy72Jb.d.cts → image-7snmKIxn.d.cts} +1 -1
- package/dist/{image-B-xQWYYS.d.ts → image-Cs8xF753.d.ts} +1 -1
- package/dist/{image-CeqwL-Qs.d.ts → image-DHcA9kaK.d.ts} +1 -1
- package/dist/{image-DWX6cNOD.d.cts → image-M5SezZVI.d.cts} +1 -1
- package/dist/index.cjs +86 -3
- package/dist/index.d.cts +33 -21
- package/dist/index.d.ts +33 -21
- package/dist/index.js +18 -5
- package/dist/layout/cell-typing.cjs +209 -0
- package/dist/layout/cell-typing.d.cts +22 -0
- package/dist/layout/cell-typing.d.ts +22 -0
- package/dist/layout/cell-typing.js +208 -0
- package/dist/layout/drawing.cjs +193 -17
- package/dist/layout/drawing.js +193 -17
- package/dist/layout/engine.cjs +46 -29
- package/dist/layout/engine.d.cts +0 -2
- package/dist/layout/engine.d.ts +0 -2
- package/dist/layout/engine.js +47 -30
- package/dist/layout/lattice.cjs +139 -0
- package/dist/layout/lattice.d.cts +20 -0
- package/dist/layout/lattice.d.ts +20 -0
- package/dist/layout/lattice.js +135 -0
- package/dist/layout/reconstruct.cjs +176 -113
- package/dist/layout/reconstruct.d.cts +2 -0
- package/dist/layout/reconstruct.d.ts +2 -0
- package/dist/layout/reconstruct.js +173 -110
- package/dist/layout/shared.cjs +52 -0
- package/dist/layout/shared.d.cts +4 -2
- package/dist/layout/shared.d.ts +4 -2
- package/dist/layout/shared.js +51 -1
- package/dist/layout/sheets.cjs +45 -11
- package/dist/layout/sheets.js +46 -12
- package/dist/layout/slides.cjs +7 -7
- package/dist/layout/slides.d.cts +0 -3
- package/dist/layout/slides.d.ts +0 -3
- package/dist/layout/slides.js +7 -7
- package/dist/markdown/write.cjs +19 -6
- package/dist/markdown/write.js +19 -6
- package/dist/mathml/layout.cjs +2 -2
- package/dist/mathml/layout.d.cts +1 -1
- package/dist/mathml/layout.d.ts +1 -1
- package/dist/mathml/layout.js +2 -2
- package/dist/model/embedded-drawing.cjs +32 -0
- package/dist/model/embedded-drawing.d.cts +8 -0
- package/dist/model/embedded-drawing.d.ts +8 -0
- package/dist/model/embedded-drawing.js +30 -0
- package/dist/model/formula.cjs +31 -0
- package/dist/model/formula.d.cts +6 -6
- package/dist/model/formula.d.ts +6 -6
- package/dist/model/formula.js +27 -0
- package/dist/model/geometry.d.cts +1 -1
- package/dist/model/geometry.d.ts +1 -1
- package/dist/model/paint-order.cjs +15 -0
- package/dist/model/paint-order.d.cts +14 -0
- package/dist/model/paint-order.d.ts +14 -0
- package/dist/model/paint-order.js +14 -0
- package/dist/odb/components.cjs +12 -0
- package/dist/odb/components.d.cts +6 -0
- package/dist/odb/components.d.ts +6 -0
- package/dist/odb/components.js +10 -0
- package/dist/odb/read.cjs +11 -7
- package/dist/odb/read.d.cts +3 -2
- package/dist/odb/read.d.ts +3 -2
- package/dist/odb/read.js +11 -7
- package/dist/odf/formula/detect.cjs +86 -18
- package/dist/odf/formula/detect.d.cts +10 -6
- package/dist/odf/formula/detect.d.ts +10 -6
- package/dist/odf/formula/detect.js +86 -19
- package/dist/odf/formula/read.cjs +4 -16
- package/dist/odf/formula/read.d.cts +4 -8
- package/dist/odf/formula/read.d.ts +4 -8
- package/dist/odf/formula/read.js +5 -17
- package/dist/odf/odp/read.cjs +9 -19
- package/dist/odf/odp/read.d.cts +2 -7
- package/dist/odf/odp/read.d.ts +2 -7
- package/dist/odf/odp/read.js +10 -20
- package/dist/odf/odt/read.cjs +63 -23
- package/dist/odf/odt/read.d.cts +2 -7
- package/dist/odf/odt/read.d.ts +2 -7
- package/dist/odf/odt/read.js +64 -24
- package/dist/omml/write.cjs +258 -0
- package/dist/omml/write.d.cts +2 -0
- package/dist/omml/write.d.ts +2 -0
- package/dist/omml/write.js +256 -0
- package/dist/registry-CrSqLIcn.d.ts +19 -0
- package/dist/registry-CtPhMD0f.d.cts +19 -0
- package/dist/rowformat-Cl2exlEh.d.cts +25 -0
- package/dist/rowformat-Cl2exlEh.d.ts +25 -0
- package/dist/{schema-Acco3Ezi.d.cts → schema-BeR_KJ0X.d.cts} +3 -1
- package/dist/{schema-VkAA6pF5.d.ts → schema-CSKwSb_v.d.ts} +3 -1
- package/dist/{shape-BUfjw5eZ.d.cts → shape-BhkP6HB8.d.cts} +6 -2
- package/dist/{shape-CTkl6kt8.d.ts → shape-BkVcwPcf.d.ts} +6 -2
- package/dist/{shape-BfN3m52m.d.ts → shape-CVXedeL7.d.ts} +3 -2
- package/dist/{shape-CN2ycxOo.d.cts → shape-CXZ6fejV.d.cts} +3 -2
- package/dist/table-C3CPZ--2.d.cts +35 -0
- package/dist/table-DjYcNOFm.d.cts +44 -0
- package/dist/table-DqfqMkVq.d.ts +44 -0
- package/dist/table-DvS_7UQS.d.ts +35 -0
- package/dist/{vector-ClohqsOe.d.cts → vector-Puuqu_IT.d.cts} +4 -0
- package/dist/{vector-ClohqsOe.d.ts → vector-Puuqu_IT.d.ts} +4 -0
- package/dist/write-DuyfnbL_.d.cts +16 -0
- package/dist/write-Zqwx6pka.d.ts +16 -0
- package/package.json +4 -4
- package/dist/odf/formula/placeholder.cjs +0 -36
- package/dist/odf/formula/placeholder.d.cts +0 -14
- package/dist/odf/formula/placeholder.d.ts +0 -14
- package/dist/odf/formula/placeholder.js +0 -36
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Package } from "ooxml.js";
|
|
2
|
+
import { ProvidedFont } from "pdf-codec";
|
|
3
|
+
//#region src/fonts/ooxml.d.ts
|
|
4
|
+
declare class OoxmlEmbeddedFontError extends Error {
|
|
5
|
+
constructor(detail: string);
|
|
6
|
+
}
|
|
7
|
+
declare function extractOoxmlEmbeddedFonts(pkg: Package, kind: 'docx' | 'pptx'): ProvidedFont[];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { OoxmlEmbeddedFontError, extractOoxmlEmbeddedFonts };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Package } from "ooxml.js";
|
|
2
|
+
import { ProvidedFont } from "pdf-codec";
|
|
3
|
+
//#region src/fonts/ooxml.d.ts
|
|
4
|
+
declare class OoxmlEmbeddedFontError extends Error {
|
|
5
|
+
constructor(detail: string);
|
|
6
|
+
}
|
|
7
|
+
declare function extractOoxmlEmbeddedFonts(pkg: Package, kind: 'docx' | 'pptx'): ProvidedFont[];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { OoxmlEmbeddedFontError, extractOoxmlEmbeddedFonts };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { deobfuscateEmbeddedFont } from "./obfuscation.js";
|
|
2
|
+
import { attr, base64ToBytes, childrenWithTag, decodeEntities, resolveRelationships, rootElement } from "ooxml.js";
|
|
3
|
+
//#region src/fonts/ooxml.ts
|
|
4
|
+
const OFFICE_DOCUMENT_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
|
|
5
|
+
const FONT_TABLE_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable";
|
|
6
|
+
const ROOT_RELS_PART = "_rels/.rels";
|
|
7
|
+
const DOCX_EMBED_ELEMENTS = [
|
|
8
|
+
[
|
|
9
|
+
"w:embedRegular",
|
|
10
|
+
false,
|
|
11
|
+
false
|
|
12
|
+
],
|
|
13
|
+
[
|
|
14
|
+
"w:embedBold",
|
|
15
|
+
true,
|
|
16
|
+
false
|
|
17
|
+
],
|
|
18
|
+
[
|
|
19
|
+
"w:embedItalic",
|
|
20
|
+
false,
|
|
21
|
+
true
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
"w:embedBoldItalic",
|
|
25
|
+
true,
|
|
26
|
+
true
|
|
27
|
+
]
|
|
28
|
+
];
|
|
29
|
+
const PPTX_EMBED_ELEMENTS = [
|
|
30
|
+
[
|
|
31
|
+
"p:regular",
|
|
32
|
+
false,
|
|
33
|
+
false
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
"p:bold",
|
|
37
|
+
true,
|
|
38
|
+
false
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
"p:italic",
|
|
42
|
+
false,
|
|
43
|
+
true
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
"p:boldItalic",
|
|
47
|
+
true,
|
|
48
|
+
true
|
|
49
|
+
]
|
|
50
|
+
];
|
|
51
|
+
var OoxmlEmbeddedFontError = class extends Error {
|
|
52
|
+
constructor(detail) {
|
|
53
|
+
super(`extractOoxmlEmbeddedFonts: ${detail}`);
|
|
54
|
+
this.name = "OoxmlEmbeddedFontError";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
function relatedPartPath(pkg, fromPartPath, relationshipType) {
|
|
58
|
+
for (const relationship of resolveRelationships(pkg, fromPartPath).values()) if (relationship.type === relationshipType && relationship.targetMode === void 0) return relationship.target;
|
|
59
|
+
}
|
|
60
|
+
function officeDocumentPartPath(pkg) {
|
|
61
|
+
const rels = rootElement(pkg.parts[ROOT_RELS_PART]);
|
|
62
|
+
if (rels !== void 0) for (const relationship of childrenWithTag(rels, "Relationship")) {
|
|
63
|
+
if (attr(relationship, "Type") !== OFFICE_DOCUMENT_RELATIONSHIP || attr(relationship, "TargetMode") !== void 0) continue;
|
|
64
|
+
const target = attr(relationship, "Target");
|
|
65
|
+
if (target !== void 0) return target.startsWith("/") ? target.slice(1) : target;
|
|
66
|
+
}
|
|
67
|
+
throw new OoxmlEmbeddedFontError(`the package declares no officeDocument relationship in ${ROOT_RELS_PART}`);
|
|
68
|
+
}
|
|
69
|
+
function fontPartBytes(pkg, fromPartPath, relationships, relationshipId) {
|
|
70
|
+
const relationship = relationships.get(relationshipId);
|
|
71
|
+
if (relationship === void 0) throw new OoxmlEmbeddedFontError(`${fromPartPath} references relationship id ${JSON.stringify(relationshipId)}, which its .rels part does not declare`);
|
|
72
|
+
const part = pkg.parts[relationship.target];
|
|
73
|
+
if (part === void 0) throw new OoxmlEmbeddedFontError(`relationship id ${JSON.stringify(relationshipId)} targets ${JSON.stringify(relationship.target)}, which is not a part of this package`);
|
|
74
|
+
if (part.kind !== "binary") throw new OoxmlEmbeddedFontError(`embedded font part ${JSON.stringify(relationship.target)} is an XML part, not binary font data`);
|
|
75
|
+
return base64ToBytes(part.base64);
|
|
76
|
+
}
|
|
77
|
+
function collectFaces(pkg, declaringPartPath, relationships, fontElementChildren, fontElement, family, fontKeyAttribute, out) {
|
|
78
|
+
for (const [tag, bold, italic] of fontElementChildren) for (const embed of childrenWithTag(fontElement, tag)) {
|
|
79
|
+
const relationshipId = attr(embed, "r:id");
|
|
80
|
+
if (relationshipId === void 0) throw new OoxmlEmbeddedFontError(`<${tag}> for font ${JSON.stringify(family)} carries no r:id`);
|
|
81
|
+
const fontKey = fontKeyAttribute === void 0 ? void 0 : attr(embed, fontKeyAttribute);
|
|
82
|
+
out.push({
|
|
83
|
+
family,
|
|
84
|
+
bold,
|
|
85
|
+
italic,
|
|
86
|
+
bytes: deobfuscateEmbeddedFont(fontPartBytes(pkg, declaringPartPath, relationships, relationshipId), fontKey)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function extractDocxFonts(pkg) {
|
|
91
|
+
const fontTablePath = relatedPartPath(pkg, officeDocumentPartPath(pkg), FONT_TABLE_RELATIONSHIP);
|
|
92
|
+
if (fontTablePath === void 0) return [];
|
|
93
|
+
const fontTablePart = pkg.parts[fontTablePath];
|
|
94
|
+
if (fontTablePart?.kind !== "xml") throw new OoxmlEmbeddedFontError(`font table part ${JSON.stringify(fontTablePath)} is missing or is not an XML part`);
|
|
95
|
+
const fonts = rootElement(fontTablePart);
|
|
96
|
+
if (fonts === void 0) return [];
|
|
97
|
+
const relationships = resolveRelationships(pkg, fontTablePath);
|
|
98
|
+
const out = [];
|
|
99
|
+
for (const font of childrenWithTag(fonts, "w:font")) {
|
|
100
|
+
const family = attr(font, "w:name");
|
|
101
|
+
if (family === void 0) throw new OoxmlEmbeddedFontError(`a <w:font> in ${JSON.stringify(fontTablePath)} carries no w:name`);
|
|
102
|
+
collectFaces(pkg, fontTablePath, relationships, DOCX_EMBED_ELEMENTS, font, decodeEntities(family), "w:fontKey", out);
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
function extractPptxFonts(pkg) {
|
|
107
|
+
const presentationPartPath = officeDocumentPartPath(pkg);
|
|
108
|
+
const presentationPart = pkg.parts[presentationPartPath];
|
|
109
|
+
if (presentationPart?.kind !== "xml") throw new OoxmlEmbeddedFontError(`presentation part ${JSON.stringify(presentationPartPath)} is missing or is not an XML part`);
|
|
110
|
+
const presentation = rootElement(presentationPart);
|
|
111
|
+
if (presentation === void 0) return [];
|
|
112
|
+
const relationships = resolveRelationships(pkg, presentationPartPath);
|
|
113
|
+
const out = [];
|
|
114
|
+
for (const list of childrenWithTag(presentation, "p:embeddedFontLst")) for (const embeddedFont of childrenWithTag(list, "p:embeddedFont")) {
|
|
115
|
+
const fontElement = childrenWithTag(embeddedFont, "p:font")[0];
|
|
116
|
+
if (fontElement === void 0) throw new OoxmlEmbeddedFontError(`a <p:embeddedFont> in ${JSON.stringify(presentationPartPath)} carries no <p:font>`);
|
|
117
|
+
const family = attr(fontElement, "typeface");
|
|
118
|
+
if (family === void 0) throw new OoxmlEmbeddedFontError(`a <p:font> in ${JSON.stringify(presentationPartPath)} carries no typeface`);
|
|
119
|
+
collectFaces(pkg, presentationPartPath, relationships, PPTX_EMBED_ELEMENTS, embeddedFont, decodeEntities(family), void 0, out);
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
function extractOoxmlEmbeddedFonts(pkg, kind) {
|
|
124
|
+
return kind === "docx" ? extractDocxFonts(pkg) : extractPptxFonts(pkg);
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
export { OoxmlEmbeddedFontError, extractOoxmlEmbeddedFonts };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_fonts_odf = require("./odf.cjs");
|
|
3
|
+
const require_fonts_ooxml = require("./ooxml.cjs");
|
|
4
|
+
let pdf_codec = require("pdf-codec");
|
|
5
|
+
//#region src/fonts/registry.ts
|
|
6
|
+
function extractSourceFonts(source) {
|
|
7
|
+
return source.kind === "odf" ? require_fonts_odf.extractOdfEmbeddedFonts(source.package) : require_fonts_ooxml.extractOoxmlEmbeddedFonts(source.package, source.kind);
|
|
8
|
+
}
|
|
9
|
+
function createDocumentFontRegistry(source, options) {
|
|
10
|
+
return (0, pdf_codec.createFontRegistry)({
|
|
11
|
+
sourceFonts: extractSourceFonts(source),
|
|
12
|
+
fonts: options?.fonts,
|
|
13
|
+
onSubstitution: options?.onFontSubstitution
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.createDocumentFontRegistry = createDocumentFontRegistry;
|
|
18
|
+
exports.extractSourceFonts = extractSourceFonts;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { extractOdfEmbeddedFonts } from "./odf.js";
|
|
2
|
+
import { extractOoxmlEmbeddedFonts } from "./ooxml.js";
|
|
3
|
+
import { createFontRegistry } from "pdf-codec";
|
|
4
|
+
//#region src/fonts/registry.ts
|
|
5
|
+
function extractSourceFonts(source) {
|
|
6
|
+
return source.kind === "odf" ? extractOdfEmbeddedFonts(source.package) : extractOoxmlEmbeddedFonts(source.package, source.kind);
|
|
7
|
+
}
|
|
8
|
+
function createDocumentFontRegistry(source, options) {
|
|
9
|
+
return createFontRegistry({
|
|
10
|
+
sourceFonts: extractSourceFonts(source),
|
|
11
|
+
fonts: options?.fonts,
|
|
12
|
+
onSubstitution: options?.onFontSubstitution
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createDocumentFontRegistry, extractSourceFonts };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Box, Box as Box$1, BoxSchema, Margins, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PageSize, PageSizeSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN } from "document-schema.js";
|
|
1
|
+
import { Box, Box as Box$1, BoxSchema, Margins, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PageSize as PageSize$1, PageSizeSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN } from "document-schema.js";
|
|
2
2
|
//#region src/model/geometry.d.ts
|
|
3
3
|
declare function flipY(box: Box, containerHeightPt: number): Box;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { PAGE_SIZE_A4 as a, PageSizeSchema as c, flipY as d, MarginsSchema as i, SLIDE_SIZE_STANDARD as l, BoxSchema as n, PAGE_SIZE_LETTER as o, Margins as r, PageSize as s, Box$1 as t, SLIDE_SIZE_WIDESCREEN as u };
|
|
5
|
+
export { PAGE_SIZE_A4 as a, PageSizeSchema as c, flipY as d, MarginsSchema as i, SLIDE_SIZE_STANDARD as l, BoxSchema as n, PAGE_SIZE_LETTER as o, Margins as r, PageSize$1 as s, Box$1 as t, SLIDE_SIZE_WIDESCREEN as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Box, Box as Box$1, BoxSchema, Margins, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PageSize, PageSizeSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN } from "document-schema.js";
|
|
1
|
+
import { Box, Box as Box$1, BoxSchema, Margins, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PageSize as PageSize$1, PageSizeSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN } from "document-schema.js";
|
|
2
2
|
//#region src/model/geometry.d.ts
|
|
3
3
|
declare function flipY(box: Box, containerHeightPt: number): Box;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { PAGE_SIZE_A4 as a, PageSizeSchema as c, flipY as d, MarginsSchema as i, SLIDE_SIZE_STANDARD as l, BoxSchema as n, PAGE_SIZE_LETTER as o, Margins as r, PageSize as s, Box$1 as t, SLIDE_SIZE_WIDESCREEN as u };
|
|
5
|
+
export { PAGE_SIZE_A4 as a, PageSizeSchema as c, flipY as d, MarginsSchema as i, SLIDE_SIZE_STANDARD as l, BoxSchema as n, PAGE_SIZE_LETTER as o, Margins as r, PageSize$1 as s, Box$1 as t, SLIDE_SIZE_WIDESCREEN as u };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_hsqldb_script = require("./script.cjs");
|
|
3
|
+
const require_hsqldb_rowformat = require("./rowformat.cjs");
|
|
4
|
+
let fflate = require("fflate");
|
|
5
|
+
//#region src/hsqldb/binary-script.ts
|
|
6
|
+
var HsqldbBinaryScriptParseError = class extends Error {
|
|
7
|
+
offset;
|
|
8
|
+
constructor(message, offset) {
|
|
9
|
+
super(`HSQLDB binary script parse error at byte offset ${offset}: ${message}`);
|
|
10
|
+
this.name = "HsqldbBinaryScriptParseError";
|
|
11
|
+
this.offset = offset;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const RESULT_MODE_DATA = 3;
|
|
15
|
+
const SQL_TYPE_VARCHAR = 12;
|
|
16
|
+
const TABLE_INIT_WITH_SCHEMA = 1;
|
|
17
|
+
const TABLE_INIT_WITHOUT_SCHEMA = 0;
|
|
18
|
+
var BinaryScriptCursor = class {
|
|
19
|
+
cursor;
|
|
20
|
+
length;
|
|
21
|
+
constructor(bytes) {
|
|
22
|
+
this.cursor = new require_hsqldb_rowformat.HsqldbDataCursor(bytes);
|
|
23
|
+
this.length = bytes.length;
|
|
24
|
+
}
|
|
25
|
+
get position() {
|
|
26
|
+
return this.cursor.position;
|
|
27
|
+
}
|
|
28
|
+
set position(value) {
|
|
29
|
+
this.cursor.position = value;
|
|
30
|
+
}
|
|
31
|
+
hasRecordLength() {
|
|
32
|
+
return this.cursor.position + 4 <= this.length;
|
|
33
|
+
}
|
|
34
|
+
require(byteCount, what) {
|
|
35
|
+
if (this.cursor.position + byteCount > this.length) throw new HsqldbBinaryScriptParseError(`stream ends after ${this.length} bytes while reading ${what} (${byteCount} byte(s) needed)`, this.cursor.position);
|
|
36
|
+
}
|
|
37
|
+
readInt32(what) {
|
|
38
|
+
this.require(4, what);
|
|
39
|
+
return this.cursor.readInt32();
|
|
40
|
+
}
|
|
41
|
+
readInt16(what) {
|
|
42
|
+
this.require(2, what);
|
|
43
|
+
return this.cursor.readInt16();
|
|
44
|
+
}
|
|
45
|
+
readString(what) {
|
|
46
|
+
const byteLength = this.readInt32(`${what}'s own length prefix`);
|
|
47
|
+
if (byteLength < 0) throw new HsqldbBinaryScriptParseError(`${what} declares a negative length ${byteLength}`, this.cursor.position);
|
|
48
|
+
this.require(byteLength, what);
|
|
49
|
+
return require_hsqldb_rowformat.readModifiedUtf8(this.cursor.readBytes(byteLength));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function readResultMetaData(reader) {
|
|
53
|
+
const columnCount = reader.readInt32("the DDL result's own column count");
|
|
54
|
+
if (columnCount < 0) throw new HsqldbBinaryScriptParseError(`the DDL result declares a negative column count ${columnCount}`, reader.position);
|
|
55
|
+
const columnTypes = [];
|
|
56
|
+
for (let i = 0; i < columnCount; i++) {
|
|
57
|
+
columnTypes.push(reader.readInt16(`column ${i}'s own SQL type`));
|
|
58
|
+
reader.readInt32(`column ${i}'s own declared size`);
|
|
59
|
+
reader.readInt32(`column ${i}'s own declared scale`);
|
|
60
|
+
reader.readString(`column ${i}'s own label`);
|
|
61
|
+
const tableName = reader.readString(`column ${i}'s own table name`);
|
|
62
|
+
const columnName = reader.readString(`column ${i}'s own name`);
|
|
63
|
+
reader.readString(`column ${i}'s own class name`);
|
|
64
|
+
if (tableName.length > 0 && columnName.length > 0) {
|
|
65
|
+
reader.readInt32(`column ${i}'s own table-column attribute mask`);
|
|
66
|
+
reader.readString(`column ${i}'s own catalog name`);
|
|
67
|
+
reader.readString(`column ${i}'s own schema name`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return columnTypes;
|
|
71
|
+
}
|
|
72
|
+
function readDdlStatements(reader) {
|
|
73
|
+
const recordStart = reader.position;
|
|
74
|
+
const recordLength = reader.readInt32("the leading DDL result record's own length");
|
|
75
|
+
if (recordLength <= 4) throw new HsqldbBinaryScriptParseError(`the leading DDL result record declares an implausible length ${recordLength} -- not a recognisable HSQLDB binary script`, recordStart);
|
|
76
|
+
const mode = reader.readInt32("the DDL result's own mode");
|
|
77
|
+
if (mode !== RESULT_MODE_DATA) throw new HsqldbBinaryScriptParseError(`the leading record has Result mode ${mode}, not the DATA mode (${RESULT_MODE_DATA}) a script's own DDL result always carries -- not a recognisable HSQLDB binary script`, recordStart);
|
|
78
|
+
reader.readInt32("the DDL result's own database id");
|
|
79
|
+
reader.readInt32("the DDL result's own session id");
|
|
80
|
+
const columnTypes = readResultMetaData(reader);
|
|
81
|
+
const firstColumnType = columnTypes[0];
|
|
82
|
+
if (columnTypes.length !== 1 || firstColumnType !== SQL_TYPE_VARCHAR) throw new HsqldbBinaryScriptParseError(`the DDL result has ${columnTypes.length} column(s) of type [${columnTypes.join(", ")}] -- a script's own DDL result is always the single VARCHAR "COMMAND" column DatabaseScript.getScript builds`, recordStart);
|
|
83
|
+
const rowCount = reader.readInt32("the DDL result's own row count");
|
|
84
|
+
if (rowCount < 0) throw new HsqldbBinaryScriptParseError(`the DDL result declares a negative row count ${rowCount}`, reader.position);
|
|
85
|
+
const statements = [];
|
|
86
|
+
for (let i = 0; i < rowCount; i++) {
|
|
87
|
+
reader.require(1, `DDL statement ${i}`);
|
|
88
|
+
const value = require_hsqldb_rowformat.readHsqldbColumnValue(reader.cursor, SQL_TYPE_VARCHAR);
|
|
89
|
+
if (value.kind !== "string") throw new HsqldbBinaryScriptParseError(`DDL statement ${i} decoded as a ${value.kind} value rather than a string`, reader.position);
|
|
90
|
+
statements.push(value.value);
|
|
91
|
+
}
|
|
92
|
+
const recordEnd = recordStart + recordLength;
|
|
93
|
+
if (reader.position > recordEnd) throw new HsqldbBinaryScriptParseError(`the DDL result overran its own declared length (consumed ${reader.position - recordStart} bytes, declared ${recordLength})`, reader.position);
|
|
94
|
+
reader.position = recordEnd;
|
|
95
|
+
return statements;
|
|
96
|
+
}
|
|
97
|
+
function readTableSection(reader, tables, options) {
|
|
98
|
+
if (!reader.hasRecordLength()) return;
|
|
99
|
+
if (reader.readInt32("a table section's own init record length") === 0) return;
|
|
100
|
+
const tableName = reader.readString("a table section's own table name");
|
|
101
|
+
const schemaFlag = reader.readInt32(`table "${tableName}"'s own schema-presence flag`);
|
|
102
|
+
if (schemaFlag !== TABLE_INIT_WITH_SCHEMA && schemaFlag !== TABLE_INIT_WITHOUT_SCHEMA) throw new HsqldbBinaryScriptParseError(`table "${tableName}"'s init record has schema flag ${schemaFlag}, which is neither ${TABLE_INIT_WITHOUT_SCHEMA} nor ${TABLE_INIT_WITH_SCHEMA}`, reader.position);
|
|
103
|
+
if (schemaFlag === TABLE_INIT_WITH_SCHEMA) reader.readString(`table "${tableName}"'s own schema name`);
|
|
104
|
+
const table = tables.get(tableName.toUpperCase());
|
|
105
|
+
if (table === void 0) throw new HsqldbBinaryScriptParseError(`the data section declares rows for table "${tableName}", which the script's own DDL never declared`, reader.position);
|
|
106
|
+
const typeCodes = table.columns.map((column) => require_hsqldb_rowformat.resolveHsqldbTypeCode(column.type));
|
|
107
|
+
const rows = [];
|
|
108
|
+
for (;;) {
|
|
109
|
+
const rowStart = reader.position;
|
|
110
|
+
const rowLength = reader.readInt32(`a row length in table "${tableName}"`);
|
|
111
|
+
if (rowLength === 0) break;
|
|
112
|
+
if (rowLength < 0) throw new HsqldbBinaryScriptParseError(`a row in table "${tableName}" declares a negative length ${rowLength}`, rowStart);
|
|
113
|
+
const rowEnd = rowStart + rowLength;
|
|
114
|
+
reader.require(rowLength - 4, `a row in table "${tableName}"`);
|
|
115
|
+
rows.push(typeCodes.map((typeCode) => require_hsqldb_rowformat.readHsqldbColumnValue(reader.cursor, typeCode, options)));
|
|
116
|
+
if (reader.position > rowEnd) throw new HsqldbBinaryScriptParseError(`a row in table "${tableName}" overran its own declared length (consumed ${reader.position - rowStart} bytes, declared ${rowLength})`, reader.position);
|
|
117
|
+
reader.position = rowEnd;
|
|
118
|
+
}
|
|
119
|
+
const declaredRowCount = reader.readInt32(`table "${tableName}"'s own trailing row count`);
|
|
120
|
+
if (declaredRowCount !== rows.length) throw new HsqldbBinaryScriptParseError(`table "${tableName}" declares ${declaredRowCount} row(s) in its own terminator but the section carried ${rows.length}`, reader.position);
|
|
121
|
+
return {
|
|
122
|
+
tableName,
|
|
123
|
+
rows
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function parseHsqldbBinaryScript(bytes, options) {
|
|
127
|
+
const reader = new BinaryScriptCursor(bytes);
|
|
128
|
+
const scriptText = readDdlStatements(reader).join("\n");
|
|
129
|
+
const tables = require_hsqldb_script.parseHsqldbScript(new TextEncoder().encode(scriptText));
|
|
130
|
+
const tablesByName = new Map(tables.map((table) => [table.tableName.toUpperCase(), table]));
|
|
131
|
+
const rowsByTable = /* @__PURE__ */ new Map();
|
|
132
|
+
for (;;) {
|
|
133
|
+
const section = readTableSection(reader, tablesByName, options);
|
|
134
|
+
if (section === void 0) break;
|
|
135
|
+
rowsByTable.set(section.tableName.toUpperCase(), section.rows);
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
scriptText,
|
|
139
|
+
tables: tables.map((table) => {
|
|
140
|
+
const rows = rowsByTable.get(table.tableName.toUpperCase());
|
|
141
|
+
return rows === void 0 ? table : {
|
|
142
|
+
...table,
|
|
143
|
+
rows
|
|
144
|
+
};
|
|
145
|
+
})
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function inflateHsqldbCompressedScript(bytes) {
|
|
149
|
+
return (0, fflate.unzlibSync)(bytes);
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
exports.HsqldbBinaryScriptParseError = HsqldbBinaryScriptParseError;
|
|
153
|
+
exports.inflateHsqldbCompressedScript = inflateHsqldbCompressedScript;
|
|
154
|
+
exports.parseHsqldbBinaryScript = parseHsqldbBinaryScript;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { n as HsqldbDecodeOptions } from "../rowformat-Cl2exlEh.cjs";
|
|
2
|
+
import { HsqldbTable } from "./script.cjs";
|
|
3
|
+
//#region src/hsqldb/binary-script.d.ts
|
|
4
|
+
declare class HsqldbBinaryScriptParseError extends Error {
|
|
5
|
+
readonly offset: number;
|
|
6
|
+
constructor(message: string, offset: number);
|
|
7
|
+
}
|
|
8
|
+
interface HsqldbBinaryScript {
|
|
9
|
+
readonly scriptText: string;
|
|
10
|
+
readonly tables: readonly HsqldbTable[];
|
|
11
|
+
}
|
|
12
|
+
declare function parseHsqldbBinaryScript(bytes: Uint8Array<ArrayBuffer>, options?: HsqldbDecodeOptions): HsqldbBinaryScript;
|
|
13
|
+
declare function inflateHsqldbCompressedScript(bytes: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { HsqldbBinaryScript, HsqldbBinaryScriptParseError, inflateHsqldbCompressedScript, parseHsqldbBinaryScript };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { n as HsqldbDecodeOptions } from "../rowformat-Cl2exlEh.js";
|
|
2
|
+
import { HsqldbTable } from "./script.js";
|
|
3
|
+
//#region src/hsqldb/binary-script.d.ts
|
|
4
|
+
declare class HsqldbBinaryScriptParseError extends Error {
|
|
5
|
+
readonly offset: number;
|
|
6
|
+
constructor(message: string, offset: number);
|
|
7
|
+
}
|
|
8
|
+
interface HsqldbBinaryScript {
|
|
9
|
+
readonly scriptText: string;
|
|
10
|
+
readonly tables: readonly HsqldbTable[];
|
|
11
|
+
}
|
|
12
|
+
declare function parseHsqldbBinaryScript(bytes: Uint8Array<ArrayBuffer>, options?: HsqldbDecodeOptions): HsqldbBinaryScript;
|
|
13
|
+
declare function inflateHsqldbCompressedScript(bytes: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { HsqldbBinaryScript, HsqldbBinaryScriptParseError, inflateHsqldbCompressedScript, parseHsqldbBinaryScript };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { parseHsqldbScript } from "./script.js";
|
|
2
|
+
import { HsqldbDataCursor, readHsqldbColumnValue, readModifiedUtf8, resolveHsqldbTypeCode } from "./rowformat.js";
|
|
3
|
+
import { unzlibSync } from "fflate";
|
|
4
|
+
//#region src/hsqldb/binary-script.ts
|
|
5
|
+
var HsqldbBinaryScriptParseError = class extends Error {
|
|
6
|
+
offset;
|
|
7
|
+
constructor(message, offset) {
|
|
8
|
+
super(`HSQLDB binary script parse error at byte offset ${offset}: ${message}`);
|
|
9
|
+
this.name = "HsqldbBinaryScriptParseError";
|
|
10
|
+
this.offset = offset;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const RESULT_MODE_DATA = 3;
|
|
14
|
+
const SQL_TYPE_VARCHAR = 12;
|
|
15
|
+
const TABLE_INIT_WITH_SCHEMA = 1;
|
|
16
|
+
const TABLE_INIT_WITHOUT_SCHEMA = 0;
|
|
17
|
+
var BinaryScriptCursor = class {
|
|
18
|
+
cursor;
|
|
19
|
+
length;
|
|
20
|
+
constructor(bytes) {
|
|
21
|
+
this.cursor = new HsqldbDataCursor(bytes);
|
|
22
|
+
this.length = bytes.length;
|
|
23
|
+
}
|
|
24
|
+
get position() {
|
|
25
|
+
return this.cursor.position;
|
|
26
|
+
}
|
|
27
|
+
set position(value) {
|
|
28
|
+
this.cursor.position = value;
|
|
29
|
+
}
|
|
30
|
+
hasRecordLength() {
|
|
31
|
+
return this.cursor.position + 4 <= this.length;
|
|
32
|
+
}
|
|
33
|
+
require(byteCount, what) {
|
|
34
|
+
if (this.cursor.position + byteCount > this.length) throw new HsqldbBinaryScriptParseError(`stream ends after ${this.length} bytes while reading ${what} (${byteCount} byte(s) needed)`, this.cursor.position);
|
|
35
|
+
}
|
|
36
|
+
readInt32(what) {
|
|
37
|
+
this.require(4, what);
|
|
38
|
+
return this.cursor.readInt32();
|
|
39
|
+
}
|
|
40
|
+
readInt16(what) {
|
|
41
|
+
this.require(2, what);
|
|
42
|
+
return this.cursor.readInt16();
|
|
43
|
+
}
|
|
44
|
+
readString(what) {
|
|
45
|
+
const byteLength = this.readInt32(`${what}'s own length prefix`);
|
|
46
|
+
if (byteLength < 0) throw new HsqldbBinaryScriptParseError(`${what} declares a negative length ${byteLength}`, this.cursor.position);
|
|
47
|
+
this.require(byteLength, what);
|
|
48
|
+
return readModifiedUtf8(this.cursor.readBytes(byteLength));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function readResultMetaData(reader) {
|
|
52
|
+
const columnCount = reader.readInt32("the DDL result's own column count");
|
|
53
|
+
if (columnCount < 0) throw new HsqldbBinaryScriptParseError(`the DDL result declares a negative column count ${columnCount}`, reader.position);
|
|
54
|
+
const columnTypes = [];
|
|
55
|
+
for (let i = 0; i < columnCount; i++) {
|
|
56
|
+
columnTypes.push(reader.readInt16(`column ${i}'s own SQL type`));
|
|
57
|
+
reader.readInt32(`column ${i}'s own declared size`);
|
|
58
|
+
reader.readInt32(`column ${i}'s own declared scale`);
|
|
59
|
+
reader.readString(`column ${i}'s own label`);
|
|
60
|
+
const tableName = reader.readString(`column ${i}'s own table name`);
|
|
61
|
+
const columnName = reader.readString(`column ${i}'s own name`);
|
|
62
|
+
reader.readString(`column ${i}'s own class name`);
|
|
63
|
+
if (tableName.length > 0 && columnName.length > 0) {
|
|
64
|
+
reader.readInt32(`column ${i}'s own table-column attribute mask`);
|
|
65
|
+
reader.readString(`column ${i}'s own catalog name`);
|
|
66
|
+
reader.readString(`column ${i}'s own schema name`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return columnTypes;
|
|
70
|
+
}
|
|
71
|
+
function readDdlStatements(reader) {
|
|
72
|
+
const recordStart = reader.position;
|
|
73
|
+
const recordLength = reader.readInt32("the leading DDL result record's own length");
|
|
74
|
+
if (recordLength <= 4) throw new HsqldbBinaryScriptParseError(`the leading DDL result record declares an implausible length ${recordLength} -- not a recognisable HSQLDB binary script`, recordStart);
|
|
75
|
+
const mode = reader.readInt32("the DDL result's own mode");
|
|
76
|
+
if (mode !== RESULT_MODE_DATA) throw new HsqldbBinaryScriptParseError(`the leading record has Result mode ${mode}, not the DATA mode (${RESULT_MODE_DATA}) a script's own DDL result always carries -- not a recognisable HSQLDB binary script`, recordStart);
|
|
77
|
+
reader.readInt32("the DDL result's own database id");
|
|
78
|
+
reader.readInt32("the DDL result's own session id");
|
|
79
|
+
const columnTypes = readResultMetaData(reader);
|
|
80
|
+
const firstColumnType = columnTypes[0];
|
|
81
|
+
if (columnTypes.length !== 1 || firstColumnType !== SQL_TYPE_VARCHAR) throw new HsqldbBinaryScriptParseError(`the DDL result has ${columnTypes.length} column(s) of type [${columnTypes.join(", ")}] -- a script's own DDL result is always the single VARCHAR "COMMAND" column DatabaseScript.getScript builds`, recordStart);
|
|
82
|
+
const rowCount = reader.readInt32("the DDL result's own row count");
|
|
83
|
+
if (rowCount < 0) throw new HsqldbBinaryScriptParseError(`the DDL result declares a negative row count ${rowCount}`, reader.position);
|
|
84
|
+
const statements = [];
|
|
85
|
+
for (let i = 0; i < rowCount; i++) {
|
|
86
|
+
reader.require(1, `DDL statement ${i}`);
|
|
87
|
+
const value = readHsqldbColumnValue(reader.cursor, SQL_TYPE_VARCHAR);
|
|
88
|
+
if (value.kind !== "string") throw new HsqldbBinaryScriptParseError(`DDL statement ${i} decoded as a ${value.kind} value rather than a string`, reader.position);
|
|
89
|
+
statements.push(value.value);
|
|
90
|
+
}
|
|
91
|
+
const recordEnd = recordStart + recordLength;
|
|
92
|
+
if (reader.position > recordEnd) throw new HsqldbBinaryScriptParseError(`the DDL result overran its own declared length (consumed ${reader.position - recordStart} bytes, declared ${recordLength})`, reader.position);
|
|
93
|
+
reader.position = recordEnd;
|
|
94
|
+
return statements;
|
|
95
|
+
}
|
|
96
|
+
function readTableSection(reader, tables, options) {
|
|
97
|
+
if (!reader.hasRecordLength()) return;
|
|
98
|
+
if (reader.readInt32("a table section's own init record length") === 0) return;
|
|
99
|
+
const tableName = reader.readString("a table section's own table name");
|
|
100
|
+
const schemaFlag = reader.readInt32(`table "${tableName}"'s own schema-presence flag`);
|
|
101
|
+
if (schemaFlag !== TABLE_INIT_WITH_SCHEMA && schemaFlag !== TABLE_INIT_WITHOUT_SCHEMA) throw new HsqldbBinaryScriptParseError(`table "${tableName}"'s init record has schema flag ${schemaFlag}, which is neither ${TABLE_INIT_WITHOUT_SCHEMA} nor ${TABLE_INIT_WITH_SCHEMA}`, reader.position);
|
|
102
|
+
if (schemaFlag === TABLE_INIT_WITH_SCHEMA) reader.readString(`table "${tableName}"'s own schema name`);
|
|
103
|
+
const table = tables.get(tableName.toUpperCase());
|
|
104
|
+
if (table === void 0) throw new HsqldbBinaryScriptParseError(`the data section declares rows for table "${tableName}", which the script's own DDL never declared`, reader.position);
|
|
105
|
+
const typeCodes = table.columns.map((column) => resolveHsqldbTypeCode(column.type));
|
|
106
|
+
const rows = [];
|
|
107
|
+
for (;;) {
|
|
108
|
+
const rowStart = reader.position;
|
|
109
|
+
const rowLength = reader.readInt32(`a row length in table "${tableName}"`);
|
|
110
|
+
if (rowLength === 0) break;
|
|
111
|
+
if (rowLength < 0) throw new HsqldbBinaryScriptParseError(`a row in table "${tableName}" declares a negative length ${rowLength}`, rowStart);
|
|
112
|
+
const rowEnd = rowStart + rowLength;
|
|
113
|
+
reader.require(rowLength - 4, `a row in table "${tableName}"`);
|
|
114
|
+
rows.push(typeCodes.map((typeCode) => readHsqldbColumnValue(reader.cursor, typeCode, options)));
|
|
115
|
+
if (reader.position > rowEnd) throw new HsqldbBinaryScriptParseError(`a row in table "${tableName}" overran its own declared length (consumed ${reader.position - rowStart} bytes, declared ${rowLength})`, reader.position);
|
|
116
|
+
reader.position = rowEnd;
|
|
117
|
+
}
|
|
118
|
+
const declaredRowCount = reader.readInt32(`table "${tableName}"'s own trailing row count`);
|
|
119
|
+
if (declaredRowCount !== rows.length) throw new HsqldbBinaryScriptParseError(`table "${tableName}" declares ${declaredRowCount} row(s) in its own terminator but the section carried ${rows.length}`, reader.position);
|
|
120
|
+
return {
|
|
121
|
+
tableName,
|
|
122
|
+
rows
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function parseHsqldbBinaryScript(bytes, options) {
|
|
126
|
+
const reader = new BinaryScriptCursor(bytes);
|
|
127
|
+
const scriptText = readDdlStatements(reader).join("\n");
|
|
128
|
+
const tables = parseHsqldbScript(new TextEncoder().encode(scriptText));
|
|
129
|
+
const tablesByName = new Map(tables.map((table) => [table.tableName.toUpperCase(), table]));
|
|
130
|
+
const rowsByTable = /* @__PURE__ */ new Map();
|
|
131
|
+
for (;;) {
|
|
132
|
+
const section = readTableSection(reader, tablesByName, options);
|
|
133
|
+
if (section === void 0) break;
|
|
134
|
+
rowsByTable.set(section.tableName.toUpperCase(), section.rows);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
scriptText,
|
|
138
|
+
tables: tables.map((table) => {
|
|
139
|
+
const rows = rowsByTable.get(table.tableName.toUpperCase());
|
|
140
|
+
return rows === void 0 ? table : {
|
|
141
|
+
...table,
|
|
142
|
+
rows
|
|
143
|
+
};
|
|
144
|
+
})
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function inflateHsqldbCompressedScript(bytes) {
|
|
148
|
+
return unzlibSync(bytes);
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
export { HsqldbBinaryScriptParseError, inflateHsqldbCompressedScript, parseHsqldbBinaryScript };
|
package/dist/hsqldb/cache.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_hsqldb_rowformat = require("./rowformat.cjs");
|
|
3
3
|
//#region src/hsqldb/cache.ts
|
|
4
4
|
const SUPPORTED_COMPATIBLE_VERSION_PREFIXES = ["1.7.", "1.8."];
|
|
5
|
+
const DISK_NODE_SIZE_BYTES = 16;
|
|
5
6
|
function parseHsqldbProperties(text) {
|
|
6
7
|
const props = /* @__PURE__ */ new Map();
|
|
7
8
|
for (const rawLine of text.split("\n")) {
|
|
@@ -32,17 +33,22 @@ function parseHsqldbIndexRoots(scriptText) {
|
|
|
32
33
|
const tokensText = match[2] ?? "";
|
|
33
34
|
const tableName = unquoteIdentifier(rawName).toUpperCase();
|
|
34
35
|
const tokens = tokensText.trim().length === 0 ? [] : tokensText.trim().split(/\s+/);
|
|
35
|
-
if (tokens.length
|
|
36
|
+
if (tokens.length < 2) throw new require_hsqldb_rowformat.HsqldbRowFormatError(`table "${tableName}"'s SET TABLE...INDEX line has ${tokens.length} token(s) -- every such line carries at least one index root position followed by the table's own identity-sequence value`);
|
|
37
|
+
const indexCount = tokens.length - 1;
|
|
36
38
|
const rootToken = tokens[0] ?? "";
|
|
37
|
-
const
|
|
38
|
-
if (!Number.isInteger(
|
|
39
|
-
roots.set(tableName,
|
|
39
|
+
const rootPosition = Number(rootToken);
|
|
40
|
+
if (!Number.isInteger(rootPosition)) throw new require_hsqldb_rowformat.HsqldbRowFormatError(`table "${tableName}"'s SET TABLE...INDEX line has a non-integer root position "${rootToken}"`);
|
|
41
|
+
roots.set(tableName, {
|
|
42
|
+
rootPosition,
|
|
43
|
+
indexCount
|
|
44
|
+
});
|
|
40
45
|
}
|
|
41
46
|
return roots;
|
|
42
47
|
}
|
|
43
|
-
function readHsqldbCachedTableRows(dataBytes,
|
|
48
|
+
function readHsqldbCachedTableRows(dataBytes, roots, cacheFileScale, columns, options) {
|
|
44
49
|
const typeCodes = columns.map((column) => require_hsqldb_rowformat.resolveHsqldbTypeCode(column.type));
|
|
45
50
|
const results = [];
|
|
51
|
+
const trailingNodeBytes = (roots.indexCount - 1) * DISK_NODE_SIZE_BYTES;
|
|
46
52
|
function visit(pos) {
|
|
47
53
|
if (pos <= 0) return;
|
|
48
54
|
const byteOffset = pos * cacheFileScale;
|
|
@@ -55,26 +61,27 @@ function readHsqldbCachedTableRows(dataBytes, rootPos, cacheFileScale, columns)
|
|
|
55
61
|
const iLeft = cursor.readInt32();
|
|
56
62
|
const iRight = cursor.readInt32();
|
|
57
63
|
cursor.readInt32();
|
|
64
|
+
cursor.position += trailingNodeBytes;
|
|
58
65
|
const values = columns.map((_column, index) => {
|
|
59
66
|
const typeCode = typeCodes[index];
|
|
60
67
|
if (typeCode === void 0) throw new require_hsqldb_rowformat.HsqldbRowFormatError("internal error: column/type-code alignment failure");
|
|
61
|
-
return require_hsqldb_rowformat.readHsqldbColumnValue(cursor, typeCode);
|
|
68
|
+
return require_hsqldb_rowformat.readHsqldbColumnValue(cursor, typeCode, options);
|
|
62
69
|
});
|
|
63
70
|
if (cursor.position > rowEnd) throw new require_hsqldb_rowformat.HsqldbRowFormatError(`row at position ${pos} overran its own declared storage size (consumed ${cursor.position - byteOffset} bytes, declared ${storageSize})`);
|
|
64
71
|
visit(iLeft);
|
|
65
72
|
results.push(values);
|
|
66
73
|
visit(iRight);
|
|
67
74
|
}
|
|
68
|
-
visit(
|
|
75
|
+
visit(roots.rootPosition);
|
|
69
76
|
return results;
|
|
70
77
|
}
|
|
71
|
-
function decodeHsqldbCachedTables(tables, scriptText, dataBytes, propertiesText) {
|
|
78
|
+
function decodeHsqldbCachedTables(tables, scriptText, dataBytes, propertiesText, options) {
|
|
72
79
|
const { cacheFileScale } = parseHsqldbProperties(propertiesText);
|
|
73
80
|
const roots = parseHsqldbIndexRoots(scriptText);
|
|
74
81
|
return tables.map((table) => {
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
const rows = readHsqldbCachedTableRows(dataBytes,
|
|
82
|
+
const tableRoots = roots.get(table.tableName.toUpperCase());
|
|
83
|
+
if (tableRoots === void 0) return table;
|
|
84
|
+
const rows = readHsqldbCachedTableRows(dataBytes, tableRoots, cacheFileScale, table.columns, options);
|
|
78
85
|
return {
|
|
79
86
|
...table,
|
|
80
87
|
rows
|
package/dist/hsqldb/cache.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { n as HsqldbDecodeOptions } from "../rowformat-Cl2exlEh.cjs";
|
|
1
2
|
import { HsqldbColumn, HsqldbTable } from "./script.cjs";
|
|
2
3
|
import { ContentCellValue } from "document-schema.js";
|
|
3
4
|
//#region src/hsqldb/cache.d.ts
|
|
@@ -6,8 +7,12 @@ interface HsqldbCacheFileInfo {
|
|
|
6
7
|
readonly compatibleVersion: string | undefined;
|
|
7
8
|
}
|
|
8
9
|
declare function parseHsqldbProperties(text: string): HsqldbCacheFileInfo;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
interface HsqldbTableIndexRoots {
|
|
11
|
+
readonly rootPosition: number;
|
|
12
|
+
readonly indexCount: number;
|
|
13
|
+
}
|
|
14
|
+
declare function parseHsqldbIndexRoots(scriptText: string): ReadonlyMap<string, HsqldbTableIndexRoots>;
|
|
15
|
+
declare function readHsqldbCachedTableRows(dataBytes: Uint8Array<ArrayBuffer>, roots: HsqldbTableIndexRoots, cacheFileScale: number, columns: readonly HsqldbColumn[], options?: HsqldbDecodeOptions): (readonly ContentCellValue[])[];
|
|
16
|
+
declare function decodeHsqldbCachedTables(tables: readonly HsqldbTable[], scriptText: string, dataBytes: Uint8Array<ArrayBuffer>, propertiesText: string, options?: HsqldbDecodeOptions): readonly HsqldbTable[];
|
|
12
17
|
//#endregion
|
|
13
|
-
export { HsqldbCacheFileInfo, decodeHsqldbCachedTables, parseHsqldbIndexRoots, parseHsqldbProperties, readHsqldbCachedTableRows };
|
|
18
|
+
export { HsqldbCacheFileInfo, HsqldbTableIndexRoots, decodeHsqldbCachedTables, parseHsqldbIndexRoots, parseHsqldbProperties, readHsqldbCachedTableRows };
|