documents.js 1.62.0 → 1.64.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 +150 -24
- package/dist/convert/convert.cjs +72 -20
- package/dist/convert/convert.d.cts +6 -2
- package/dist/convert/convert.d.ts +6 -2
- package/dist/convert/convert.js +73 -21
- 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.d.cts +1 -1
- package/dist/edit/docx/content.d.ts +1 -1
- package/dist/edit/docx/paragraph.d.cts +3 -3
- package/dist/edit/docx/paragraph.d.ts +3 -3
- package/dist/edit/ods/address.cjs +42 -24
- package/dist/edit/ods/address.d.cts +12 -2
- package/dist/edit/ods/address.d.ts +12 -2
- package/dist/edit/ods/address.js +39 -25
- package/dist/edit/ods/column-row.cjs +68 -6
- package/dist/edit/ods/column-row.d.cts +5 -1
- package/dist/edit/ods/column-row.d.ts +5 -1
- package/dist/edit/ods/column-row.js +68 -10
- package/dist/edit/ods/content.cjs +10 -2
- package/dist/edit/ods/content.js +10 -2
- package/dist/edit/ods/floating.cjs +90 -0
- package/dist/edit/ods/floating.d.cts +7 -0
- package/dist/edit/ods/floating.d.ts +7 -0
- package/dist/edit/ods/floating.js +88 -0
- package/dist/edit/ods/print-settings.cjs +158 -2
- package/dist/edit/ods/print-settings.js +159 -3
- package/dist/edit/ods/sheet.cjs +13 -0
- package/dist/edit/ods/sheet.d.cts +5 -1
- package/dist/edit/ods/sheet.d.ts +5 -1
- package/dist/edit/ods/sheet.js +14 -1
- package/dist/edit/odt/content.cjs +8 -4
- package/dist/edit/odt/content.js +8 -4
- package/dist/edit/odt/editor.cjs +7 -0
- package/dist/edit/odt/editor.d.cts +3 -0
- package/dist/edit/odt/editor.d.ts +3 -0
- package/dist/edit/odt/editor.js +7 -0
- package/dist/edit/odt/formula.cjs +19 -0
- package/dist/edit/odt/formula.d.cts +8 -0
- package/dist/edit/odt/formula.d.ts +8 -0
- package/dist/edit/odt/formula.js +17 -0
- package/dist/evaluate-BU5N1Jk1.d.ts +11 -0
- package/dist/evaluate-BhMXY6DM.d.cts +11 -0
- package/dist/firebird/backup.d.cts +1 -1
- package/dist/firebird/backup.d.ts +1 -1
- package/dist/firebird/data.cjs +30 -16
- package/dist/firebird/data.d.cts +3 -2
- package/dist/firebird/data.d.ts +3 -2
- package/dist/firebird/data.js +30 -17
- 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/formula-CgydMiTt.d.ts +10 -0
- package/dist/formula-CiwPw8nY.d.cts +10 -0
- package/dist/hsqldb/binary-script.d.cts +1 -1
- package/dist/hsqldb/binary-script.d.ts +1 -1
- package/dist/hsqldb/cache.d.cts +1 -1
- package/dist/hsqldb/cache.d.ts +1 -1
- package/dist/hsqldb/rowformat.cjs +22 -13
- package/dist/hsqldb/rowformat.js +22 -13
- package/dist/hsqldb/script.d.cts +1 -18
- package/dist/hsqldb/script.d.ts +1 -18
- package/dist/index.cjs +88 -0
- package/dist/index.d.cts +27 -9
- package/dist/index.d.ts +27 -9
- package/dist/index.js +20 -3
- package/dist/layout/sheets.cjs +30 -24
- package/dist/layout/sheets.js +31 -25
- package/dist/layout/slides.cjs +6 -4
- package/dist/layout/slides.js +7 -5
- package/dist/lexer-DGPWx_f2.d.cts +42 -0
- package/dist/lexer-DGPWx_f2.d.ts +42 -0
- package/dist/mathml/layout.d.cts +1 -1
- package/dist/mathml/layout.d.ts +1 -1
- package/dist/mathml/variant.d.cts +1 -6
- package/dist/mathml/variant.d.ts +1 -6
- package/dist/odb/csv.d.cts +1 -1
- package/dist/odb/csv.d.ts +1 -1
- package/dist/odb/formula/definition.cjs +49 -0
- package/dist/odb/formula/definition.d.cts +8 -0
- package/dist/odb/formula/definition.d.ts +8 -0
- package/dist/odb/formula/definition.js +46 -0
- package/dist/odb/formula/errors.cjs +47 -0
- package/dist/odb/formula/errors.d.cts +21 -0
- package/dist/odb/formula/errors.d.ts +21 -0
- package/dist/odb/formula/errors.js +43 -0
- package/dist/odb/formula/evaluate.cjs +283 -0
- package/dist/odb/formula/evaluate.d.cts +43 -0
- package/dist/odb/formula/evaluate.d.ts +43 -0
- package/dist/odb/formula/evaluate.js +281 -0
- package/dist/odb/formula/parser.cjs +198 -0
- package/dist/odb/formula/parser.d.cts +29 -0
- package/dist/odb/formula/parser.d.ts +29 -0
- package/dist/odb/formula/parser.js +197 -0
- package/dist/odb/read.d.cts +1 -1
- package/dist/odb/read.d.ts +1 -1
- package/dist/odb/report/content.cjs +27 -0
- package/dist/odb/report/content.d.cts +14 -0
- package/dist/odb/report/content.d.ts +14 -0
- package/dist/odb/report/content.js +25 -0
- package/dist/odb/report/render.cjs +106 -0
- package/dist/odb/report/render.d.cts +7 -0
- package/dist/odb/report/render.d.ts +7 -0
- package/dist/odb/report/render.js +106 -0
- package/dist/odb/report/source.cjs +45 -0
- package/dist/odb/report/source.d.cts +14 -0
- package/dist/odb/report/source.d.ts +14 -0
- package/dist/odb/report/source.js +42 -0
- package/dist/odb/spreadsheet.d.cts +1 -1
- package/dist/odb/spreadsheet.d.ts +1 -1
- package/dist/odb/sql/errors.cjs +38 -0
- package/dist/odb/sql/errors.d.cts +17 -0
- package/dist/odb/sql/errors.d.ts +17 -0
- package/dist/odb/sql/errors.js +35 -0
- package/dist/odb/sql/evaluate.cjs +312 -0
- package/dist/odb/sql/evaluate.d.cts +2 -0
- package/dist/odb/sql/evaluate.d.ts +2 -0
- package/dist/odb/sql/evaluate.js +311 -0
- package/dist/odb/sql/lexer.cjs +282 -0
- package/dist/odb/sql/lexer.d.cts +2 -0
- package/dist/odb/sql/lexer.d.ts +2 -0
- package/dist/odb/sql/lexer.js +281 -0
- package/dist/odb/sql/parser.cjs +479 -0
- package/dist/odb/sql/parser.d.cts +2 -0
- package/dist/odb/sql/parser.d.ts +2 -0
- package/dist/odb/sql/parser.js +478 -0
- package/dist/odb/values.cjs +75 -0
- package/dist/odb/values.d.cts +2 -0
- package/dist/odb/values.d.ts +2 -0
- package/dist/odb/values.js +69 -0
- package/dist/odf/odt/read.cjs +43 -21
- package/dist/odf/odt/read.js +43 -21
- package/dist/odf-package/formula.cjs +59 -0
- package/dist/odf-package/formula.d.cts +11 -0
- package/dist/odf-package/formula.d.ts +11 -0
- package/dist/odf-package/formula.js +58 -0
- package/dist/odf-package/manifest.cjs +29 -0
- package/dist/odf-package/manifest.d.cts +5 -2
- package/dist/odf-package/manifest.d.ts +5 -2
- package/dist/odf-package/manifest.js +30 -2
- package/dist/odf-package/media.cjs +2 -1
- package/dist/odf-package/media.js +2 -2
- package/dist/omml/read.cjs +265 -0
- package/dist/omml/read.d.cts +12 -0
- package/dist/omml/read.d.ts +12 -0
- package/dist/omml/read.js +263 -0
- package/dist/omml/shared.cjs +67 -0
- package/dist/omml/shared.d.cts +2 -0
- package/dist/omml/shared.d.ts +2 -0
- package/dist/omml/shared.js +64 -0
- package/dist/omml/write.cjs +3 -51
- package/dist/omml/write.d.cts +2 -2
- package/dist/omml/write.d.ts +2 -2
- package/dist/omml/write.js +1 -49
- package/dist/ooxml/docx/extras.cjs +15 -0
- package/dist/ooxml/docx/extras.d.cts +12 -0
- package/dist/ooxml/docx/extras.d.ts +12 -0
- package/dist/ooxml/docx/extras.js +14 -0
- package/dist/ooxml/docx/formula.cjs +109 -0
- package/dist/ooxml/docx/formula.d.cts +2 -0
- package/dist/ooxml/docx/formula.d.ts +2 -0
- package/dist/ooxml/docx/formula.js +108 -0
- package/dist/ooxml/docx/read.cjs +10 -2
- package/dist/ooxml/docx/read.d.cts +6 -2
- package/dist/ooxml/docx/read.d.ts +6 -2
- package/dist/ooxml/docx/read.js +11 -3
- package/dist/parser-B9vC1T6T.d.cts +101 -0
- package/dist/parser-DQSgYJzQ.d.ts +101 -0
- package/dist/registry-CrSqLIcn.d.ts +19 -0
- package/dist/registry-lqJej0Jr.d.cts +19 -0
- package/dist/script-DsGGIzGU.d.cts +19 -0
- package/dist/script-DsGGIzGU.d.ts +19 -0
- package/dist/shared-DLZ3IQUl.d.cts +15 -0
- package/dist/shared-DUOzjwcL.d.ts +15 -0
- package/dist/values-BetetbaH.d.cts +23 -0
- package/dist/values-BetetbaH.d.ts +23 -0
- package/dist/variant-BMrebjMw.d.cts +7 -0
- package/dist/variant-BMrebjMw.d.ts +7 -0
- package/dist/{write-DuyfnbL_.d.cts → write-BQ6SK8r8.d.cts} +2 -6
- package/dist/{write-Zqwx6pka.d.ts → write-THs7ipBq.d.ts} +2 -6
- package/package.json +1 -1
package/dist/edit/ods/sheet.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as OdsCell } from "../../cell-CNHPsDEk.js";
|
|
2
|
-
import { ContentSheetPrintSettings } from "document-schema.js";
|
|
2
|
+
import { ContentEmbeddedObject, ContentSheetImage, ContentSheetPrintSettings } from "document-schema.js";
|
|
3
3
|
import { Package, XmlElement, XmlNode } from "odf.js";
|
|
4
4
|
//#region src/edit/ods/sheet.d.ts
|
|
5
5
|
declare class OdsSheet {
|
|
@@ -15,6 +15,10 @@ declare class OdsSheet {
|
|
|
15
15
|
set printSettings(value: ContentSheetPrintSettings);
|
|
16
16
|
setColumnWidth(index: number, widthPt: number): void;
|
|
17
17
|
setRowHeight(index: number, heightPt: number): void;
|
|
18
|
+
setColumnHidden(index: number, hidden: boolean): void;
|
|
19
|
+
setRowHidden(index: number, hidden: boolean): void;
|
|
20
|
+
addImage(image: ContentSheetImage): void;
|
|
21
|
+
addEmbeddedObject(object: ContentEmbeddedObject): void;
|
|
18
22
|
cell(row: number, column: number): OdsCell;
|
|
19
23
|
cellAt(reference: string): OdsCell;
|
|
20
24
|
mergeCells(startRow: number, startColumn: number, rowSpan: number, colSpan: number): OdsCell;
|
package/dist/edit/ods/sheet.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { removeChild, setAttr } from "../../xml/edit.js";
|
|
2
2
|
import { COVERED_CELL_TAG, resolveCellNode } from "./address.js";
|
|
3
3
|
import { OdsCell } from "./cell.js";
|
|
4
|
-
import { writeColumnWidth, writeRowHeight } from "./column-row.js";
|
|
4
|
+
import { writeColumnHidden, writeColumnWidth, writeRowHeight, writeRowHidden } from "./column-row.js";
|
|
5
|
+
import { insertSheetEmbeddedObject, insertSheetImage } from "./floating.js";
|
|
5
6
|
import { readSheetPrintSettings, writeSheetPrintSettings } from "./print-settings.js";
|
|
6
7
|
import { attr } from "ooxml.js";
|
|
7
8
|
import { parseCellReference } from "odf.js";
|
|
@@ -41,6 +42,18 @@ var OdsSheet = class {
|
|
|
41
42
|
setRowHeight(index, heightPt) {
|
|
42
43
|
writeRowHeight(this.pkg, this.live(), index, heightPt);
|
|
43
44
|
}
|
|
45
|
+
setColumnHidden(index, hidden) {
|
|
46
|
+
writeColumnHidden(this.live(), index, hidden);
|
|
47
|
+
}
|
|
48
|
+
setRowHidden(index, hidden) {
|
|
49
|
+
writeRowHidden(this.live(), index, hidden);
|
|
50
|
+
}
|
|
51
|
+
addImage(image) {
|
|
52
|
+
insertSheetImage(this.pkg, this.live(), image);
|
|
53
|
+
}
|
|
54
|
+
addEmbeddedObject(object) {
|
|
55
|
+
insertSheetEmbeddedObject(this.pkg, this.live(), object);
|
|
56
|
+
}
|
|
44
57
|
cell(row, column) {
|
|
45
58
|
const node = resolveCellNode(this.live(), row, column);
|
|
46
59
|
if (node.tag === "table:covered-table-cell") throw new Error(`cell (${row}, ${column}) is covered by a merged range -- address the merge's own anchor cell instead`);
|
|
@@ -139,10 +139,14 @@ function appendBlock(body, block) {
|
|
|
139
139
|
function appendEmbeddedObject(body, block) {
|
|
140
140
|
const formula = require_model_formula.formulaOfBlock(block);
|
|
141
141
|
if (formula === void 0) return;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
if (formula.mathml.length === 0) {
|
|
143
|
+
populateParagraph(body.appendParagraph(), {
|
|
144
|
+
kind: "paragraph",
|
|
145
|
+
runs: [{ text: require_model_formula.formulaPlaceholderText(formula) }]
|
|
146
|
+
});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
body.appendFormula(formula, block.frame);
|
|
146
150
|
}
|
|
147
151
|
//#endregion
|
|
148
152
|
exports.buildOdtPackage = buildOdtPackage;
|
package/dist/edit/odt/content.js
CHANGED
|
@@ -138,10 +138,14 @@ function appendBlock(body, block) {
|
|
|
138
138
|
function appendEmbeddedObject(body, block) {
|
|
139
139
|
const formula = formulaOfBlock(block);
|
|
140
140
|
if (formula === void 0) return;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
if (formula.mathml.length === 0) {
|
|
142
|
+
populateParagraph(body.appendParagraph(), {
|
|
143
|
+
kind: "paragraph",
|
|
144
|
+
runs: [{ text: formulaPlaceholderText(formula) }]
|
|
145
|
+
});
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
body.appendFormula(formula, block.frame);
|
|
145
149
|
}
|
|
146
150
|
//#endregion
|
|
147
151
|
export { buildOdtPackage, populateOdtTable, populateParagraph };
|
package/dist/edit/odt/editor.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_edit_odt_automatic_styles = require("./automatic-styles.cjs");
|
|
3
|
+
const require_edit_odt_formula = require("./formula.cjs");
|
|
3
4
|
const require_edit_odt_paragraph = require("./paragraph.cjs");
|
|
4
5
|
const require_edit_odt_list = require("./list.cjs");
|
|
5
6
|
const require_edit_odt_scaffold = require("./scaffold.cjs");
|
|
@@ -44,6 +45,12 @@ var OdtBodyImpl = class {
|
|
|
44
45
|
this.officeText.children.push(listElement);
|
|
45
46
|
return new require_edit_odt_list.OdtList(this.officeText.children, listElement, this.pkg);
|
|
46
47
|
}
|
|
48
|
+
appendFormula(formula, frame) {
|
|
49
|
+
const paragraphElement = require_edit_odt_paragraph.buildParagraph(this.pkg);
|
|
50
|
+
paragraphElement.children.push(require_edit_odt_formula.insertFormulaFrameMedia(this.pkg, frame, formula));
|
|
51
|
+
this.officeText.children.push(paragraphElement);
|
|
52
|
+
return new require_edit_odt_paragraph.OdtParagraph(this.officeText.children, paragraphElement, this.pkg);
|
|
53
|
+
}
|
|
47
54
|
appendPageBreak() {
|
|
48
55
|
const paragraphElement = require_edit_odt_paragraph.buildParagraph(this.pkg);
|
|
49
56
|
paragraphElement.attributes.push({
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { t as Box$1 } from "../../geometry-DaJr8yQW.cjs";
|
|
1
2
|
import { n as ParagraphInit, t as OdtParagraph } from "../../paragraph-BXbXKPy3.cjs";
|
|
2
3
|
import { t as OdtList } from "../../list-BuBM9rwQ.cjs";
|
|
3
4
|
import { i as TableInit, t as OdtTable } from "../../table-DjYcNOFm.cjs";
|
|
5
|
+
import { ContentFormula } from "document-schema.js";
|
|
4
6
|
import { Package } from "odf.js";
|
|
5
7
|
//#region src/edit/odt/editor.d.ts
|
|
6
8
|
interface OdtBody {
|
|
@@ -8,6 +10,7 @@ interface OdtBody {
|
|
|
8
10
|
appendTable(init: TableInit): OdtTable;
|
|
9
11
|
appendList(): OdtList;
|
|
10
12
|
appendPageBreak(): void;
|
|
13
|
+
appendFormula(formula: ContentFormula, frame: Box$1): OdtParagraph;
|
|
11
14
|
}
|
|
12
15
|
declare class OdtEditor {
|
|
13
16
|
readonly body: OdtBody;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { t as Box$1 } from "../../geometry-DaJr8yQW.js";
|
|
1
2
|
import { n as ParagraphInit, t as OdtParagraph } from "../../paragraph-CoUi_88j.js";
|
|
2
3
|
import { t as OdtList } from "../../list-CvKxhy3y.js";
|
|
3
4
|
import { i as TableInit, t as OdtTable } from "../../table-DqfqMkVq.js";
|
|
5
|
+
import { ContentFormula } from "document-schema.js";
|
|
4
6
|
import { Package } from "odf.js";
|
|
5
7
|
//#region src/edit/odt/editor.d.ts
|
|
6
8
|
interface OdtBody {
|
|
@@ -8,6 +10,7 @@ interface OdtBody {
|
|
|
8
10
|
appendTable(init: TableInit): OdtTable;
|
|
9
11
|
appendList(): OdtList;
|
|
10
12
|
appendPageBreak(): void;
|
|
13
|
+
appendFormula(formula: ContentFormula, frame: Box$1): OdtParagraph;
|
|
11
14
|
}
|
|
12
15
|
declare class OdtEditor {
|
|
13
16
|
readonly body: OdtBody;
|
package/dist/edit/odt/editor.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ensurePageBreakStyleName } from "./automatic-styles.js";
|
|
2
|
+
import { insertFormulaFrameMedia } from "./formula.js";
|
|
2
3
|
import { OdtParagraph, buildParagraph } from "./paragraph.js";
|
|
3
4
|
import { OdtList, buildList } from "./list.js";
|
|
4
5
|
import { createEmptyOdtPackage } from "./scaffold.js";
|
|
@@ -43,6 +44,12 @@ var OdtBodyImpl = class {
|
|
|
43
44
|
this.officeText.children.push(listElement);
|
|
44
45
|
return new OdtList(this.officeText.children, listElement, this.pkg);
|
|
45
46
|
}
|
|
47
|
+
appendFormula(formula, frame) {
|
|
48
|
+
const paragraphElement = buildParagraph(this.pkg);
|
|
49
|
+
paragraphElement.children.push(insertFormulaFrameMedia(this.pkg, frame, formula));
|
|
50
|
+
this.officeText.children.push(paragraphElement);
|
|
51
|
+
return new OdtParagraph(this.officeText.children, paragraphElement, this.pkg);
|
|
52
|
+
}
|
|
46
53
|
appendPageBreak() {
|
|
47
54
|
const paragraphElement = buildParagraph(this.pkg);
|
|
48
55
|
paragraphElement.attributes.push({
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_fragment = require("../../xml/fragment.cjs");
|
|
3
|
+
const require_odf_package_formula = require("../../odf-package/formula.cjs");
|
|
4
|
+
let odf_js = require("odf.js");
|
|
5
|
+
//#region src/edit/odt/formula.ts
|
|
6
|
+
function buildFormulaFrame(href, frame) {
|
|
7
|
+
return require_xml_fragment.el("draw:frame", {
|
|
8
|
+
"text:anchor-type": "as-char",
|
|
9
|
+
"svg:width": (0, odf_js.formatOdfLength)(frame.widthPt),
|
|
10
|
+
"svg:height": (0, odf_js.formatOdfLength)(frame.heightPt)
|
|
11
|
+
}, [require_xml_fragment.el("draw:object", { "xlink:href": href })]);
|
|
12
|
+
}
|
|
13
|
+
function insertFormulaFrameMedia(pkg, frame, formula) {
|
|
14
|
+
const { href } = require_odf_package_formula.addFormulaObject(pkg, formula);
|
|
15
|
+
return buildFormulaFrame(href, frame);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.buildFormulaFrame = buildFormulaFrame;
|
|
19
|
+
exports.insertFormulaFrameMedia = insertFormulaFrameMedia;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as Box$1 } from "../../geometry-DaJr8yQW.cjs";
|
|
2
|
+
import { ContentFormula } from "document-schema.js";
|
|
3
|
+
import { Package, XmlElement } from "odf.js";
|
|
4
|
+
//#region src/edit/odt/formula.d.ts
|
|
5
|
+
declare function buildFormulaFrame(href: string, frame: Box$1): XmlElement;
|
|
6
|
+
declare function insertFormulaFrameMedia(pkg: Package, frame: Box$1, formula: ContentFormula): XmlElement;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { buildFormulaFrame, insertFormulaFrameMedia };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as Box$1 } from "../../geometry-DaJr8yQW.js";
|
|
2
|
+
import { ContentFormula } from "document-schema.js";
|
|
3
|
+
import { Package, XmlElement } from "odf.js";
|
|
4
|
+
//#region src/edit/odt/formula.d.ts
|
|
5
|
+
declare function buildFormulaFrame(href: string, frame: Box$1): XmlElement;
|
|
6
|
+
declare function insertFormulaFrameMedia(pkg: Package, frame: Box$1, formula: ContentFormula): XmlElement;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { buildFormulaFrame, insertFormulaFrameMedia };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { el } from "../../xml/fragment.js";
|
|
2
|
+
import { addFormulaObject } from "../../odf-package/formula.js";
|
|
3
|
+
import { formatOdfLength } from "odf.js";
|
|
4
|
+
//#region src/edit/odt/formula.ts
|
|
5
|
+
function buildFormulaFrame(href, frame) {
|
|
6
|
+
return el("draw:frame", {
|
|
7
|
+
"text:anchor-type": "as-char",
|
|
8
|
+
"svg:width": formatOdfLength(frame.widthPt),
|
|
9
|
+
"svg:height": formatOdfLength(frame.heightPt)
|
|
10
|
+
}, [el("draw:object", { "xlink:href": href })]);
|
|
11
|
+
}
|
|
12
|
+
function insertFormulaFrameMedia(pkg, frame, formula) {
|
|
13
|
+
const { href } = addFormulaObject(pkg, formula);
|
|
14
|
+
return buildFormulaFrame(href, frame);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { buildFormulaFrame, insertFormulaFrameMedia };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { r as HsqldbTable } from "./script-DsGGIzGU.js";
|
|
2
|
+
import { u as SqlSelectStatement } from "./parser-DQSgYJzQ.js";
|
|
3
|
+
import { ContentCellValue } from "document-schema.js";
|
|
4
|
+
//#region src/odb/sql/evaluate.d.ts
|
|
5
|
+
interface SqlResultSet {
|
|
6
|
+
readonly columns: readonly string[];
|
|
7
|
+
readonly rows: readonly (readonly ContentCellValue[])[];
|
|
8
|
+
}
|
|
9
|
+
declare function evaluateSelect(statement: SqlSelectStatement, tables: readonly HsqldbTable[]): SqlResultSet;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { evaluateSelect as n, SqlResultSet as t };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { r as HsqldbTable } from "./script-DsGGIzGU.cjs";
|
|
2
|
+
import { u as SqlSelectStatement } from "./parser-B9vC1T6T.cjs";
|
|
3
|
+
import { ContentCellValue } from "document-schema.js";
|
|
4
|
+
//#region src/odb/sql/evaluate.d.ts
|
|
5
|
+
interface SqlResultSet {
|
|
6
|
+
readonly columns: readonly string[];
|
|
7
|
+
readonly rows: readonly (readonly ContentCellValue[])[];
|
|
8
|
+
}
|
|
9
|
+
declare function evaluateSelect(statement: SqlSelectStatement, tables: readonly HsqldbTable[]): SqlResultSet;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { evaluateSelect as n, SqlResultSet as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HsqldbTable } from "../
|
|
1
|
+
import { r as HsqldbTable } from "../script-DsGGIzGU.cjs";
|
|
2
2
|
import { r as FirebirdSchemaParseError } from "../schema-BeR_KJ0X.cjs";
|
|
3
3
|
import { FirebirdCompositeRecordUnsupportedError } from "./data.cjs";
|
|
4
4
|
//#region src/firebird/backup.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HsqldbTable } from "../
|
|
1
|
+
import { r as HsqldbTable } from "../script-DsGGIzGU.js";
|
|
2
2
|
import { r as FirebirdSchemaParseError } from "../schema-CSKwSb_v.js";
|
|
3
3
|
import { FirebirdCompositeRecordUnsupportedError } from "./data.js";
|
|
4
4
|
//#region src/firebird/backup.d.ts
|
package/dist/firebird/data.cjs
CHANGED
|
@@ -89,32 +89,45 @@ function blobCellValue(field, bytes) {
|
|
|
89
89
|
function storedFieldsOf(fields) {
|
|
90
90
|
return fields.filter((field) => !field.computed);
|
|
91
91
|
}
|
|
92
|
+
function exactDecimalDigits(unscaled, decimalScale) {
|
|
93
|
+
const isNegative = unscaled < 0n;
|
|
94
|
+
const magnitudeDigits = (isNegative ? -unscaled : unscaled).toString();
|
|
95
|
+
const sign = isNegative ? "-" : "";
|
|
96
|
+
if (decimalScale <= 0) return `${sign}${magnitudeDigits}${"0".repeat(-decimalScale)}`;
|
|
97
|
+
const padded = magnitudeDigits.padStart(decimalScale + 1, "0");
|
|
98
|
+
return `${sign}${padded.slice(0, padded.length - decimalScale)}.${padded.slice(padded.length - decimalScale)}`;
|
|
99
|
+
}
|
|
100
|
+
function trimTrailingFractionZeros(digits) {
|
|
101
|
+
if (!digits.includes(".")) return digits;
|
|
102
|
+
const trimmed = digits.replace(/0+$/, "");
|
|
103
|
+
return trimmed.endsWith(".") ? trimmed.slice(0, -1) : trimmed;
|
|
104
|
+
}
|
|
105
|
+
function numericCellValue(unscaled, decimalScale) {
|
|
106
|
+
const exact = trimTrailingFractionZeros(exactDecimalDigits(unscaled, decimalScale));
|
|
107
|
+
const value = Number(exact);
|
|
108
|
+
return String(value) === exact ? {
|
|
109
|
+
kind: "number",
|
|
110
|
+
value
|
|
111
|
+
} : {
|
|
112
|
+
kind: "number",
|
|
113
|
+
value,
|
|
114
|
+
exactValue: exact
|
|
115
|
+
};
|
|
116
|
+
}
|
|
92
117
|
function decodeRowValues(fields, payload) {
|
|
93
118
|
const storedFields = storedFieldsOf(fields);
|
|
94
119
|
const xdr = new require_firebird_reader.XdrReader(payload);
|
|
95
120
|
const rawValues = [];
|
|
96
121
|
for (const field of storedFields) switch (field.physicalType) {
|
|
97
122
|
case "short":
|
|
98
|
-
rawValues.push(
|
|
99
|
-
kind: "number",
|
|
100
|
-
value: field.scale === 0 ? xdr.readInt16() : xdr.readInt16() * 10 ** field.scale
|
|
101
|
-
});
|
|
123
|
+
rawValues.push(numericCellValue(BigInt(xdr.readInt16()), -field.scale));
|
|
102
124
|
break;
|
|
103
125
|
case "long":
|
|
104
|
-
rawValues.push(
|
|
105
|
-
kind: "number",
|
|
106
|
-
value: field.scale === 0 ? xdr.readInt32() : xdr.readInt32() * 10 ** field.scale
|
|
107
|
-
});
|
|
126
|
+
rawValues.push(numericCellValue(BigInt(xdr.readInt32()), -field.scale));
|
|
108
127
|
break;
|
|
109
|
-
case "int64":
|
|
110
|
-
|
|
111
|
-
const scaled = field.scale === 0 ? Number(raw) : Number(raw) * 10 ** field.scale;
|
|
112
|
-
rawValues.push({
|
|
113
|
-
kind: "number",
|
|
114
|
-
value: scaled
|
|
115
|
-
});
|
|
128
|
+
case "int64":
|
|
129
|
+
rawValues.push(numericCellValue(xdr.readInt64(), -field.scale));
|
|
116
130
|
break;
|
|
117
|
-
}
|
|
118
131
|
case "real":
|
|
119
132
|
rawValues.push({
|
|
120
133
|
kind: "number",
|
|
@@ -282,4 +295,5 @@ function readRelationData(reader, schema, compressed) {
|
|
|
282
295
|
//#endregion
|
|
283
296
|
exports.FirebirdCompositeRecordUnsupportedError = FirebirdCompositeRecordUnsupportedError;
|
|
284
297
|
exports.FirebirdDataParseError = FirebirdDataParseError;
|
|
298
|
+
exports.decodeRowValues = decodeRowValues;
|
|
285
299
|
exports.readRelationData = readRelationData;
|
package/dist/firebird/data.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as FirebirdBackupReader } from "../reader-DP0Mbaj4.cjs";
|
|
2
|
-
import { n as FirebirdRelation } from "../schema-BeR_KJ0X.cjs";
|
|
2
|
+
import { n as FirebirdRelation, t as FirebirdField } from "../schema-BeR_KJ0X.cjs";
|
|
3
3
|
import { ContentCellValue } from "document-schema.js";
|
|
4
4
|
//#region src/firebird/data.d.ts
|
|
5
5
|
declare class FirebirdDataParseError extends Error {
|
|
@@ -9,9 +9,10 @@ declare class FirebirdCompositeRecordUnsupportedError extends Error {
|
|
|
9
9
|
readonly recordType: number;
|
|
10
10
|
constructor(recordType: number, context: string);
|
|
11
11
|
}
|
|
12
|
+
declare function decodeRowValues(fields: readonly FirebirdField[], payload: Uint8Array<ArrayBuffer>): ContentCellValue[];
|
|
12
13
|
declare function readRelationData(reader: FirebirdBackupReader, schema: ReadonlyMap<string, FirebirdRelation>, compressed: boolean): {
|
|
13
14
|
relationName: string;
|
|
14
15
|
rows: ContentCellValue[][];
|
|
15
16
|
};
|
|
16
17
|
//#endregion
|
|
17
|
-
export { FirebirdCompositeRecordUnsupportedError, FirebirdDataParseError, readRelationData };
|
|
18
|
+
export { FirebirdCompositeRecordUnsupportedError, FirebirdDataParseError, decodeRowValues, readRelationData };
|
package/dist/firebird/data.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as FirebirdBackupReader } from "../reader-DP0Mbaj4.js";
|
|
2
|
-
import { n as FirebirdRelation } from "../schema-CSKwSb_v.js";
|
|
2
|
+
import { n as FirebirdRelation, t as FirebirdField } from "../schema-CSKwSb_v.js";
|
|
3
3
|
import { ContentCellValue } from "document-schema.js";
|
|
4
4
|
//#region src/firebird/data.d.ts
|
|
5
5
|
declare class FirebirdDataParseError extends Error {
|
|
@@ -9,9 +9,10 @@ declare class FirebirdCompositeRecordUnsupportedError extends Error {
|
|
|
9
9
|
readonly recordType: number;
|
|
10
10
|
constructor(recordType: number, context: string);
|
|
11
11
|
}
|
|
12
|
+
declare function decodeRowValues(fields: readonly FirebirdField[], payload: Uint8Array<ArrayBuffer>): ContentCellValue[];
|
|
12
13
|
declare function readRelationData(reader: FirebirdBackupReader, schema: ReadonlyMap<string, FirebirdRelation>, compressed: boolean): {
|
|
13
14
|
relationName: string;
|
|
14
15
|
rows: ContentCellValue[][];
|
|
15
16
|
};
|
|
16
17
|
//#endregion
|
|
17
|
-
export { FirebirdCompositeRecordUnsupportedError, FirebirdDataParseError, readRelationData };
|
|
18
|
+
export { FirebirdCompositeRecordUnsupportedError, FirebirdDataParseError, decodeRowValues, readRelationData };
|
package/dist/firebird/data.js
CHANGED
|
@@ -88,32 +88,45 @@ function blobCellValue(field, bytes) {
|
|
|
88
88
|
function storedFieldsOf(fields) {
|
|
89
89
|
return fields.filter((field) => !field.computed);
|
|
90
90
|
}
|
|
91
|
+
function exactDecimalDigits(unscaled, decimalScale) {
|
|
92
|
+
const isNegative = unscaled < 0n;
|
|
93
|
+
const magnitudeDigits = (isNegative ? -unscaled : unscaled).toString();
|
|
94
|
+
const sign = isNegative ? "-" : "";
|
|
95
|
+
if (decimalScale <= 0) return `${sign}${magnitudeDigits}${"0".repeat(-decimalScale)}`;
|
|
96
|
+
const padded = magnitudeDigits.padStart(decimalScale + 1, "0");
|
|
97
|
+
return `${sign}${padded.slice(0, padded.length - decimalScale)}.${padded.slice(padded.length - decimalScale)}`;
|
|
98
|
+
}
|
|
99
|
+
function trimTrailingFractionZeros(digits) {
|
|
100
|
+
if (!digits.includes(".")) return digits;
|
|
101
|
+
const trimmed = digits.replace(/0+$/, "");
|
|
102
|
+
return trimmed.endsWith(".") ? trimmed.slice(0, -1) : trimmed;
|
|
103
|
+
}
|
|
104
|
+
function numericCellValue(unscaled, decimalScale) {
|
|
105
|
+
const exact = trimTrailingFractionZeros(exactDecimalDigits(unscaled, decimalScale));
|
|
106
|
+
const value = Number(exact);
|
|
107
|
+
return String(value) === exact ? {
|
|
108
|
+
kind: "number",
|
|
109
|
+
value
|
|
110
|
+
} : {
|
|
111
|
+
kind: "number",
|
|
112
|
+
value,
|
|
113
|
+
exactValue: exact
|
|
114
|
+
};
|
|
115
|
+
}
|
|
91
116
|
function decodeRowValues(fields, payload) {
|
|
92
117
|
const storedFields = storedFieldsOf(fields);
|
|
93
118
|
const xdr = new XdrReader(payload);
|
|
94
119
|
const rawValues = [];
|
|
95
120
|
for (const field of storedFields) switch (field.physicalType) {
|
|
96
121
|
case "short":
|
|
97
|
-
rawValues.push(
|
|
98
|
-
kind: "number",
|
|
99
|
-
value: field.scale === 0 ? xdr.readInt16() : xdr.readInt16() * 10 ** field.scale
|
|
100
|
-
});
|
|
122
|
+
rawValues.push(numericCellValue(BigInt(xdr.readInt16()), -field.scale));
|
|
101
123
|
break;
|
|
102
124
|
case "long":
|
|
103
|
-
rawValues.push(
|
|
104
|
-
kind: "number",
|
|
105
|
-
value: field.scale === 0 ? xdr.readInt32() : xdr.readInt32() * 10 ** field.scale
|
|
106
|
-
});
|
|
125
|
+
rawValues.push(numericCellValue(BigInt(xdr.readInt32()), -field.scale));
|
|
107
126
|
break;
|
|
108
|
-
case "int64":
|
|
109
|
-
|
|
110
|
-
const scaled = field.scale === 0 ? Number(raw) : Number(raw) * 10 ** field.scale;
|
|
111
|
-
rawValues.push({
|
|
112
|
-
kind: "number",
|
|
113
|
-
value: scaled
|
|
114
|
-
});
|
|
127
|
+
case "int64":
|
|
128
|
+
rawValues.push(numericCellValue(xdr.readInt64(), -field.scale));
|
|
115
129
|
break;
|
|
116
|
-
}
|
|
117
130
|
case "real":
|
|
118
131
|
rawValues.push({
|
|
119
132
|
kind: "number",
|
|
@@ -279,4 +292,4 @@ function readRelationData(reader, schema, compressed) {
|
|
|
279
292
|
};
|
|
280
293
|
}
|
|
281
294
|
//#endregion
|
|
282
|
-
export { FirebirdCompositeRecordUnsupportedError, FirebirdDataParseError, readRelationData };
|
|
295
|
+
export { FirebirdCompositeRecordUnsupportedError, FirebirdDataParseError, decodeRowValues, readRelationData };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let pdf_codec_sfnt = require("pdf-codec/sfnt");
|
|
3
|
+
//#region src/fonts/obfuscation.ts
|
|
4
|
+
const FONT_KEY_HEX_LENGTH = 32;
|
|
5
|
+
const FONT_KEY_BYTE_LENGTH = 16;
|
|
6
|
+
const OBFUSCATED_PREFIX_LENGTH = 32;
|
|
7
|
+
const SFNT_HEADER_LENGTH = 12;
|
|
8
|
+
const HEX_PAIR_PATTERN = /^[0-9A-Fa-f]{2}$/;
|
|
9
|
+
var FontDeobfuscationError = class extends Error {
|
|
10
|
+
constructor(detail) {
|
|
11
|
+
super(`deobfuscateEmbeddedFont: ${detail}`);
|
|
12
|
+
this.name = "FontDeobfuscationError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
function deriveFontKey(fontKey) {
|
|
16
|
+
const hex = fontKey.replace(/[{}-]/g, "");
|
|
17
|
+
if (hex.length !== FONT_KEY_HEX_LENGTH) throw new FontDeobfuscationError(`w:fontKey ${JSON.stringify(fontKey)} has ${String(hex.length)} hex digit(s) after stripping braces and hyphens, expected ${String(FONT_KEY_HEX_LENGTH)}`);
|
|
18
|
+
const key = new Uint8Array(FONT_KEY_BYTE_LENGTH);
|
|
19
|
+
for (let i = 0; i < FONT_KEY_BYTE_LENGTH; i++) {
|
|
20
|
+
const start = 30 - i * 2;
|
|
21
|
+
const pair = hex.slice(start, start + 2);
|
|
22
|
+
if (!HEX_PAIR_PATTERN.test(pair)) throw new FontDeobfuscationError(`w:fontKey ${JSON.stringify(fontKey)} contains the non-hexadecimal pair ${JSON.stringify(pair)}`);
|
|
23
|
+
key[i] = Number.parseInt(pair, 16);
|
|
24
|
+
}
|
|
25
|
+
return key;
|
|
26
|
+
}
|
|
27
|
+
function looksLikeSfnt(bytes) {
|
|
28
|
+
return bytes.length >= SFNT_HEADER_LENGTH && (0, pdf_codec_sfnt.parseSfnt)(bytes) !== void 0;
|
|
29
|
+
}
|
|
30
|
+
function deobfuscateEmbeddedFont(bytes, fontKey) {
|
|
31
|
+
if (looksLikeSfnt(bytes)) return bytes;
|
|
32
|
+
if (fontKey === void 0) throw new FontDeobfuscationError("the part does not begin with an sfnt signature and carries no font key to deobfuscate it with");
|
|
33
|
+
if (bytes.length < OBFUSCATED_PREFIX_LENGTH) throw new FontDeobfuscationError(`an obfuscated part must be at least ${String(OBFUSCATED_PREFIX_LENGTH)} bytes long, got ${String(bytes.length)}`);
|
|
34
|
+
const key = deriveFontKey(fontKey);
|
|
35
|
+
const clear = new Uint8Array(bytes.length);
|
|
36
|
+
clear.set(bytes);
|
|
37
|
+
for (let i = 0; i < OBFUSCATED_PREFIX_LENGTH; i++) {
|
|
38
|
+
const keyByte = key[i % FONT_KEY_BYTE_LENGTH];
|
|
39
|
+
const cipherByte = clear[i];
|
|
40
|
+
if (keyByte === void 0 || cipherByte === void 0) throw new FontDeobfuscationError(`byte ${String(i)} of the obfuscated prefix is out of range`);
|
|
41
|
+
clear[i] = cipherByte ^ keyByte;
|
|
42
|
+
}
|
|
43
|
+
if (!looksLikeSfnt(clear)) throw new FontDeobfuscationError(`deobfuscating with font key ${JSON.stringify(fontKey)} did not produce a recognisable sfnt font`);
|
|
44
|
+
return clear;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.FontDeobfuscationError = FontDeobfuscationError;
|
|
48
|
+
exports.deobfuscateEmbeddedFont = deobfuscateEmbeddedFont;
|
|
49
|
+
exports.deriveFontKey = deriveFontKey;
|
|
50
|
+
exports.looksLikeSfnt = looksLikeSfnt;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/fonts/obfuscation.d.ts
|
|
2
|
+
declare class FontDeobfuscationError extends Error {
|
|
3
|
+
constructor(detail: string);
|
|
4
|
+
}
|
|
5
|
+
declare function deriveFontKey(fontKey: string): Uint8Array<ArrayBuffer>;
|
|
6
|
+
declare function looksLikeSfnt(bytes: Uint8Array<ArrayBuffer>): boolean;
|
|
7
|
+
declare function deobfuscateEmbeddedFont(bytes: Uint8Array<ArrayBuffer>, fontKey: string | undefined): Uint8Array<ArrayBuffer>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { FontDeobfuscationError, deobfuscateEmbeddedFont, deriveFontKey, looksLikeSfnt };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/fonts/obfuscation.d.ts
|
|
2
|
+
declare class FontDeobfuscationError extends Error {
|
|
3
|
+
constructor(detail: string);
|
|
4
|
+
}
|
|
5
|
+
declare function deriveFontKey(fontKey: string): Uint8Array<ArrayBuffer>;
|
|
6
|
+
declare function looksLikeSfnt(bytes: Uint8Array<ArrayBuffer>): boolean;
|
|
7
|
+
declare function deobfuscateEmbeddedFont(bytes: Uint8Array<ArrayBuffer>, fontKey: string | undefined): Uint8Array<ArrayBuffer>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { FontDeobfuscationError, deobfuscateEmbeddedFont, deriveFontKey, looksLikeSfnt };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { parseSfnt } from "pdf-codec/sfnt";
|
|
2
|
+
//#region src/fonts/obfuscation.ts
|
|
3
|
+
const FONT_KEY_HEX_LENGTH = 32;
|
|
4
|
+
const FONT_KEY_BYTE_LENGTH = 16;
|
|
5
|
+
const OBFUSCATED_PREFIX_LENGTH = 32;
|
|
6
|
+
const SFNT_HEADER_LENGTH = 12;
|
|
7
|
+
const HEX_PAIR_PATTERN = /^[0-9A-Fa-f]{2}$/;
|
|
8
|
+
var FontDeobfuscationError = class extends Error {
|
|
9
|
+
constructor(detail) {
|
|
10
|
+
super(`deobfuscateEmbeddedFont: ${detail}`);
|
|
11
|
+
this.name = "FontDeobfuscationError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function deriveFontKey(fontKey) {
|
|
15
|
+
const hex = fontKey.replace(/[{}-]/g, "");
|
|
16
|
+
if (hex.length !== FONT_KEY_HEX_LENGTH) throw new FontDeobfuscationError(`w:fontKey ${JSON.stringify(fontKey)} has ${String(hex.length)} hex digit(s) after stripping braces and hyphens, expected ${String(FONT_KEY_HEX_LENGTH)}`);
|
|
17
|
+
const key = new Uint8Array(FONT_KEY_BYTE_LENGTH);
|
|
18
|
+
for (let i = 0; i < FONT_KEY_BYTE_LENGTH; i++) {
|
|
19
|
+
const start = 30 - i * 2;
|
|
20
|
+
const pair = hex.slice(start, start + 2);
|
|
21
|
+
if (!HEX_PAIR_PATTERN.test(pair)) throw new FontDeobfuscationError(`w:fontKey ${JSON.stringify(fontKey)} contains the non-hexadecimal pair ${JSON.stringify(pair)}`);
|
|
22
|
+
key[i] = Number.parseInt(pair, 16);
|
|
23
|
+
}
|
|
24
|
+
return key;
|
|
25
|
+
}
|
|
26
|
+
function looksLikeSfnt(bytes) {
|
|
27
|
+
return bytes.length >= SFNT_HEADER_LENGTH && parseSfnt(bytes) !== void 0;
|
|
28
|
+
}
|
|
29
|
+
function deobfuscateEmbeddedFont(bytes, fontKey) {
|
|
30
|
+
if (looksLikeSfnt(bytes)) return bytes;
|
|
31
|
+
if (fontKey === void 0) throw new FontDeobfuscationError("the part does not begin with an sfnt signature and carries no font key to deobfuscate it with");
|
|
32
|
+
if (bytes.length < OBFUSCATED_PREFIX_LENGTH) throw new FontDeobfuscationError(`an obfuscated part must be at least ${String(OBFUSCATED_PREFIX_LENGTH)} bytes long, got ${String(bytes.length)}`);
|
|
33
|
+
const key = deriveFontKey(fontKey);
|
|
34
|
+
const clear = new Uint8Array(bytes.length);
|
|
35
|
+
clear.set(bytes);
|
|
36
|
+
for (let i = 0; i < OBFUSCATED_PREFIX_LENGTH; i++) {
|
|
37
|
+
const keyByte = key[i % FONT_KEY_BYTE_LENGTH];
|
|
38
|
+
const cipherByte = clear[i];
|
|
39
|
+
if (keyByte === void 0 || cipherByte === void 0) throw new FontDeobfuscationError(`byte ${String(i)} of the obfuscated prefix is out of range`);
|
|
40
|
+
clear[i] = cipherByte ^ keyByte;
|
|
41
|
+
}
|
|
42
|
+
if (!looksLikeSfnt(clear)) throw new FontDeobfuscationError(`deobfuscating with font key ${JSON.stringify(fontKey)} did not produce a recognisable sfnt font`);
|
|
43
|
+
return clear;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { FontDeobfuscationError, deobfuscateEmbeddedFont, deriveFontKey, looksLikeSfnt };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_fonts_obfuscation = require("./obfuscation.cjs");
|
|
3
|
+
let odf_js = require("odf.js");
|
|
4
|
+
let pdf_codec_sfnt = require("pdf-codec/sfnt");
|
|
5
|
+
let pdf_codec_font_tables = require("pdf-codec/font-tables");
|
|
6
|
+
//#region src/fonts/odf.ts
|
|
7
|
+
const FONT_FACE_DECL_PARTS = ["content.xml", "styles.xml"];
|
|
8
|
+
const FS_SELECTION_ITALIC = 1;
|
|
9
|
+
const FS_SELECTION_BOLD = 32;
|
|
10
|
+
const BOLD_WEIGHT_THRESHOLD = 600;
|
|
11
|
+
var OdfEmbeddedFontError = class extends Error {
|
|
12
|
+
constructor(detail) {
|
|
13
|
+
super(`extractOdfEmbeddedFonts: ${detail}`);
|
|
14
|
+
this.name = "OdfEmbeddedFontError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function normaliseFamily(value) {
|
|
18
|
+
const first = (0, odf_js.decodeXmlText)(value).split(",")[0]?.trim() ?? "";
|
|
19
|
+
const quoted = /^'(.*)'$|^"(.*)"$/.exec(first);
|
|
20
|
+
return (quoted?.[1] ?? quoted?.[2] ?? first).trim();
|
|
21
|
+
}
|
|
22
|
+
function boldFromWeightAttribute(weight) {
|
|
23
|
+
const keyword = weight.trim().toLowerCase();
|
|
24
|
+
if (keyword === "bold" || keyword === "bolder") return true;
|
|
25
|
+
if (keyword === "normal" || keyword === "lighter") return false;
|
|
26
|
+
const numeric = Number.parseInt(keyword, 10);
|
|
27
|
+
return Number.isNaN(numeric) ? void 0 : numeric >= BOLD_WEIGHT_THRESHOLD;
|
|
28
|
+
}
|
|
29
|
+
function italicFromStyleAttribute(style) {
|
|
30
|
+
const keyword = style.trim().toLowerCase();
|
|
31
|
+
if (keyword === "italic" || keyword === "oblique") return true;
|
|
32
|
+
return keyword === "normal" ? false : void 0;
|
|
33
|
+
}
|
|
34
|
+
function styleFromFontBytes(bytes) {
|
|
35
|
+
const font = (0, pdf_codec_sfnt.parseSfnt)(bytes);
|
|
36
|
+
if (font === void 0) return;
|
|
37
|
+
const os2 = (0, pdf_codec_font_tables.parseOs2)(font);
|
|
38
|
+
if (os2 === void 0) return;
|
|
39
|
+
return {
|
|
40
|
+
bold: (os2.fsSelection & FS_SELECTION_BOLD) !== 0,
|
|
41
|
+
italic: (os2.fsSelection & FS_SELECTION_ITALIC) !== 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function fontPartBytes(pkg, href) {
|
|
45
|
+
const part = pkg.parts[href];
|
|
46
|
+
if (part === void 0) throw new OdfEmbeddedFontError(`svg:font-face-uri references ${JSON.stringify(href)}, which is not a part of this package`);
|
|
47
|
+
if (part.kind !== "binary") throw new OdfEmbeddedFontError(`embedded font part ${JSON.stringify(href)} is an XML part, not binary font data`);
|
|
48
|
+
return (0, odf_js.base64ToBytes)(part.base64);
|
|
49
|
+
}
|
|
50
|
+
function collectFontFace(pkg, fontFace, seenHrefs, out) {
|
|
51
|
+
const declaredFamily = (0, odf_js.attrValue)(fontFace, "svg:font-family") ?? (0, odf_js.attrValue)(fontFace, "style:name");
|
|
52
|
+
for (const src of (0, odf_js.childrenWithTag)(fontFace, "svg:font-face-src")) for (const uri of (0, odf_js.childrenWithTag)(src, "svg:font-face-uri")) {
|
|
53
|
+
const rawHref = (0, odf_js.attrValue)(uri, "xlink:href");
|
|
54
|
+
if (rawHref === void 0) throw new OdfEmbeddedFontError("a <svg:font-face-uri> carries no xlink:href");
|
|
55
|
+
const href = (0, odf_js.decodeXmlText)(rawHref);
|
|
56
|
+
if (seenHrefs.has(href)) continue;
|
|
57
|
+
seenHrefs.add(href);
|
|
58
|
+
if (declaredFamily === void 0) throw new OdfEmbeddedFontError(`the <style:font-face> embedding ${JSON.stringify(href)} declares neither svg:font-family nor style:name`);
|
|
59
|
+
const bytes = fontPartBytes(pkg, href);
|
|
60
|
+
if (!require_fonts_obfuscation.looksLikeSfnt(bytes)) throw new OdfEmbeddedFontError(`embedded font part ${JSON.stringify(href)} does not begin with a recognisable sfnt signature`);
|
|
61
|
+
const declaredWeight = (0, odf_js.attrValue)(uri, "loext:font-weight");
|
|
62
|
+
const declaredStyle = (0, odf_js.attrValue)(uri, "loext:font-style");
|
|
63
|
+
const intrinsic = styleFromFontBytes(bytes);
|
|
64
|
+
out.push({
|
|
65
|
+
family: normaliseFamily(declaredFamily),
|
|
66
|
+
bold: (declaredWeight === void 0 ? void 0 : boldFromWeightAttribute(declaredWeight)) ?? intrinsic?.bold ?? false,
|
|
67
|
+
italic: (declaredStyle === void 0 ? void 0 : italicFromStyleAttribute(declaredStyle)) ?? intrinsic?.italic ?? false,
|
|
68
|
+
bytes
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function extractOdfEmbeddedFonts(pkg) {
|
|
73
|
+
const out = [];
|
|
74
|
+
const seenHrefs = /* @__PURE__ */ new Set();
|
|
75
|
+
for (const partPath of FONT_FACE_DECL_PARTS) {
|
|
76
|
+
const part = pkg.parts[partPath];
|
|
77
|
+
if (part?.kind !== "xml") continue;
|
|
78
|
+
const root = (0, odf_js.rootElement)(part.nodes);
|
|
79
|
+
if (root === void 0) continue;
|
|
80
|
+
for (const decls of (0, odf_js.childrenWithTag)(root, "office:font-face-decls")) for (const fontFace of (0, odf_js.childrenWithTag)(decls, "style:font-face")) collectFontFace(pkg, fontFace, seenHrefs, out);
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
exports.OdfEmbeddedFontError = OdfEmbeddedFontError;
|
|
86
|
+
exports.extractOdfEmbeddedFonts = extractOdfEmbeddedFonts;
|