odf.js 1.9.0 → 1.10.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 +3 -2
- package/dist/index.cjs +130 -20
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +130 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,8 +21,9 @@ This package is under active development. What's built and shipped:
|
|
|
21
21
|
- **Typed readers** — `readOdt` (wordprocessing), `readOdp` (presentation slides: `draw:frame`/`draw:g` text/image/table content), `readOdg` (drawing pages: every vector primitive — `draw:rect`/`draw:ellipse`/`draw:circle`/`draw:line`/`draw:path`/`draw:polygon`/`draw:polyline`, plus a recognised `draw:custom-shape` preset subset — in real `draw:z-index`-aware paint order), and `readOds` (spreadsheets: geometry- and print-settings-rich, every `office:value-type` variant with its own OpenFormula string) each resolve a `Package` into `document-content-model`'s own `ContentSection`/`ContentSlide`/`ContentDrawPage`/`ContentSheet` shapes.
|
|
22
22
|
- **`readOdfFormula`** resolves a standalone or embedded `.odf` formula's `content.xml` — bare MathML with no `office:document-content` wrapper, confirmed against real LibreOffice output — into its raw MathML nodes plus, when present, the formula's own native StarMath annotation string. There is no `document-content-model` pivot type for MathML, so this reader's own output type is its own.
|
|
23
23
|
- **`readOdm`** resolves a `.odm` master document's own `content.xml` into an ordered list of chapter references (`{ name, href, filterName? }`, one per top-level linked `text:section`) without opening the external `.odt` files those references point at. A master document's chapters are genuinely external files by ODF design, not embedded package sub-documents — confirmed against real LibreOffice output, which never caches a chapter's own content inside the master document itself (see `src/typed/odm/read.ts`'s own top-of-file note).
|
|
24
|
+
- **`readOdbInventory`** resolves a `.odb` database front-end package into connection info plus the *names* of its forms/queries/reports/tables — never their content, and never the embedded/external database engine's own binary or script storage. Confirmed against real LibreOffice output that `office:database` lives directly in the package's ordinary `content.xml` (no separate `database/connection.xml` part, contrary to the OASIS schema's own chapter layout suggesting one), that queries are named inline (`db:queries/db:query`, no manifest part of their own), and that a live engine's own tables have no ODF-level manifest listing at all — only forms/reports genuinely are separate manifest sub-document parts (`forms/<Name>/content.xml`, `reports/<Name>/content.xml`). See `src/typed/odb/read.ts`'s own top-of-file note for the full findings.
|
|
24
25
|
|
|
25
|
-
Not yet built:
|
|
26
|
+
Not yet built: live-view editors and the `.odb` database-table-export subsystem. This section will be replaced with real usage examples once those land — see the [Architecture](#architecture) section below for the intended shape, and this repository's own commit history/releases for current progress.
|
|
26
27
|
|
|
27
28
|
## Getting started
|
|
28
29
|
|
|
@@ -78,7 +79,7 @@ Layered from a lossless core outward, mirroring `ooxml.js`'s own structure:
|
|
|
78
79
|
- **`src/manifest.ts`** — unlike `ooxml.js` (which only ever *reads* OPC relationships, leaving writing to `documents.js`), `odf.js` owns manifest read **and** write, since the manifest is ODF's one mandatory part and its correctness is exhaustive.
|
|
79
80
|
- **`src/styles/`** — `properties.ts` (the property-bag shape + real ODF attribute parsing), `serialize.ts` (canonical, deterministic property-bag → XML attributes), `registry.ts` (`StyleRegistry`, ODF's mandatory style-interning layer, no OOXML equivalent), `span.ts` (character-range wrapping into a formattable `text:span`, correctly splitting `text:s`/`text:tab` elements that straddle a boundary).
|
|
80
81
|
- **`src/typed/shared/`** — the ODF-specific typed primitives every future format reader builds on: `units.ts`, `a1.ts`, `color.ts`/`geometry.ts` (parsing into `document-content-model`'s own types, never redefining them), `style.ts` (a thin re-export — ODF's style-properties concern is fully covered by `styles/properties.ts` and the cascade below), `text.ts` (whitespace-run decoding), `cascade.ts` (the read-side style-resolution walk), `metadata.ts` (`meta.xml` reading).
|
|
81
|
-
- **`src/typed/odt/`, `src/typed/odp/`, `src/typed/odg/`, `src/typed/ods/`** — the built `readOdt`/`readOdp`/`readOdg`/`readOds` readers; **`src/typed/draw/`** — the `draw:frame`/`draw:g`/vector-primitive shape vocabulary `readOdp` and `readOdg` both share; **`src/typed/formula/`, `src/typed/odm/`** — `readOdfFormula` (raw MathML, no `document-content-model` pivot) and `readOdm` (a `.odm` master document's own external chapter references — name/href/filter-name per linked `text:section`, never the linked content itself).
|
|
82
|
+
- **`src/typed/odt/`, `src/typed/odp/`, `src/typed/odg/`, `src/typed/ods/`** — the built `readOdt`/`readOdp`/`readOdg`/`readOds` readers; **`src/typed/draw/`** — the `draw:frame`/`draw:g`/vector-primitive shape vocabulary `readOdp` and `readOdg` both share; **`src/typed/formula/`, `src/typed/odm/`** — `readOdfFormula` (raw MathML, no `document-content-model` pivot) and `readOdm` (a `.odm` master document's own external chapter references — name/href/filter-name per linked `text:section`, never the linked content itself); **`src/typed/odb/`** — `readOdbInventory` (a `.odb` package's own connection info plus form/query/report/table *names*, never their content or the database engine's own storage).
|
|
82
83
|
|
|
83
84
|
## Why no `ooxml.js` dependency
|
|
84
85
|
|
package/dist/index.cjs
CHANGED
|
@@ -355,7 +355,8 @@ const ODF_NAMESPACES = Object.freeze({
|
|
|
355
355
|
xforms: "http://www.w3.org/2002/xforms",
|
|
356
356
|
xsd: "http://www.w3.org/2001/XMLSchema",
|
|
357
357
|
xsi: "http://www.w3.org/2001/XMLSchema-instance",
|
|
358
|
-
manifest: "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"
|
|
358
|
+
manifest: "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",
|
|
359
|
+
db: "urn:oasis:names:tc:opendocument:xmlns:database:1.0"
|
|
359
360
|
});
|
|
360
361
|
function xmlnsAttributes(prefixes) {
|
|
361
362
|
const attrs = {};
|
|
@@ -2484,7 +2485,7 @@ function readDrawPageContent(children, pkg) {
|
|
|
2484
2485
|
}
|
|
2485
2486
|
//#endregion
|
|
2486
2487
|
//#region src/typed/odp/read.ts
|
|
2487
|
-
const CONTENT_PART$
|
|
2488
|
+
const CONTENT_PART$6 = "content.xml";
|
|
2488
2489
|
function readSlideSize(page, pkg) {
|
|
2489
2490
|
return resolveDrawPageSize(page, pkg) ?? document_content_model.SLIDE_SIZE_WIDESCREEN;
|
|
2490
2491
|
}
|
|
@@ -2503,7 +2504,7 @@ function readSlide(page, pkg) {
|
|
|
2503
2504
|
};
|
|
2504
2505
|
}
|
|
2505
2506
|
function readOdp(pkg) {
|
|
2506
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2507
|
+
const contentPart = pkg.parts[CONTENT_PART$6];
|
|
2507
2508
|
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2508
2509
|
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2509
2510
|
const presentation = body === void 0 ? void 0 : findChildElement(body.children, "office:presentation");
|
|
@@ -2515,9 +2516,9 @@ function readOdp(pkg) {
|
|
|
2515
2516
|
}
|
|
2516
2517
|
//#endregion
|
|
2517
2518
|
//#region src/typed/odt/read.ts
|
|
2518
|
-
const CONTENT_PART$
|
|
2519
|
+
const CONTENT_PART$5 = "content.xml";
|
|
2519
2520
|
const STYLES_PART = "styles.xml";
|
|
2520
|
-
const AUTOMATIC_STYLE_PARTS = [CONTENT_PART$
|
|
2521
|
+
const AUTOMATIC_STYLE_PARTS = [CONTENT_PART$5, STYLES_PART];
|
|
2521
2522
|
function readOutlineLevel(headingElement) {
|
|
2522
2523
|
const raw = attrValue(headingElement, "text:outline-level");
|
|
2523
2524
|
if (raw === void 0) return 1;
|
|
@@ -2600,12 +2601,12 @@ function readFirstMasterPageGeometry(pkg) {
|
|
|
2600
2601
|
};
|
|
2601
2602
|
}
|
|
2602
2603
|
function readOdt(pkg) {
|
|
2603
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2604
|
-
if (contentPart?.kind !== "xml") throw new Error(`readOdt: package has no ${CONTENT_PART$
|
|
2604
|
+
const contentPart = pkg.parts[CONTENT_PART$5];
|
|
2605
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdt: package has no ${CONTENT_PART$5} part`);
|
|
2605
2606
|
const contentRoot = rootElement(contentPart.nodes);
|
|
2606
2607
|
const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
|
|
2607
2608
|
const textElement = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
|
|
2608
|
-
if (textElement === void 0) throw new Error(`readOdt: ${CONTENT_PART$
|
|
2609
|
+
if (textElement === void 0) throw new Error(`readOdt: ${CONTENT_PART$5} has no office:body/office:text element`);
|
|
2609
2610
|
const metadata = readOdfMetadata(pkg);
|
|
2610
2611
|
const { pageSize, margins } = readFirstMasterPageGeometry(pkg);
|
|
2611
2612
|
return {
|
|
@@ -2619,7 +2620,7 @@ function readOdt(pkg) {
|
|
|
2619
2620
|
}
|
|
2620
2621
|
//#endregion
|
|
2621
2622
|
//#region src/typed/odg/read.ts
|
|
2622
|
-
const CONTENT_PART$
|
|
2623
|
+
const CONTENT_PART$4 = "content.xml";
|
|
2623
2624
|
const DEFAULT_PAGE_SIZE$1 = document_content_model.PAGE_SIZE_A4;
|
|
2624
2625
|
function readPage(page, pkg) {
|
|
2625
2626
|
const size = resolveDrawPageSize(page, pkg) ?? DEFAULT_PAGE_SIZE$1;
|
|
@@ -2631,7 +2632,7 @@ function readPage(page, pkg) {
|
|
|
2631
2632
|
};
|
|
2632
2633
|
}
|
|
2633
2634
|
function readOdg(pkg) {
|
|
2634
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2635
|
+
const contentPart = pkg.parts[CONTENT_PART$4];
|
|
2635
2636
|
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2636
2637
|
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2637
2638
|
const drawing = body === void 0 ? void 0 : findChildElement(body.children, "office:drawing");
|
|
@@ -2643,7 +2644,7 @@ function readOdg(pkg) {
|
|
|
2643
2644
|
}
|
|
2644
2645
|
//#endregion
|
|
2645
2646
|
//#region src/typed/ods/read.ts
|
|
2646
|
-
const CONTENT_PART$
|
|
2647
|
+
const CONTENT_PART$3 = "content.xml";
|
|
2647
2648
|
function parseKnownOdfLength(value) {
|
|
2648
2649
|
const parsed = parseOdfLength(value);
|
|
2649
2650
|
if (parsed === void 0) throw new Error(`readOds: internal error -- "${value}" is not a valid ODF length literal`);
|
|
@@ -2933,7 +2934,7 @@ function readSheet(tableElement, pkg) {
|
|
|
2933
2934
|
};
|
|
2934
2935
|
}
|
|
2935
2936
|
function readOds(pkg) {
|
|
2936
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2937
|
+
const contentPart = pkg.parts[CONTENT_PART$3];
|
|
2937
2938
|
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2938
2939
|
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2939
2940
|
const spreadsheet = body === void 0 ? void 0 : findChildElement(body.children, "office:spreadsheet");
|
|
@@ -2950,7 +2951,7 @@ function readOds(pkg) {
|
|
|
2950
2951
|
}
|
|
2951
2952
|
//#endregion
|
|
2952
2953
|
//#region src/typed/formula/read.ts
|
|
2953
|
-
const CONTENT_PART$
|
|
2954
|
+
const CONTENT_PART$2 = "content.xml";
|
|
2954
2955
|
const MATH_ROOT_TAGS = ["math", "math:math"];
|
|
2955
2956
|
const ANNOTATION_TAGS = ["annotation", "math:annotation"];
|
|
2956
2957
|
const STARMATH_ENCODING_PREFIX = "StarMath";
|
|
@@ -2976,10 +2977,10 @@ function findStarMathAnnotation(mathRoot) {
|
|
|
2976
2977
|
}
|
|
2977
2978
|
}
|
|
2978
2979
|
function readOdfFormula(pkg) {
|
|
2979
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2980
|
-
if (contentPart?.kind !== "xml") throw new Error(`readOdfFormula: package has no ${CONTENT_PART$
|
|
2980
|
+
const contentPart = pkg.parts[CONTENT_PART$2];
|
|
2981
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdfFormula: package has no ${CONTENT_PART$2} part`);
|
|
2981
2982
|
const mathRoot = findMathRoot(contentPart.nodes);
|
|
2982
|
-
if (mathRoot === void 0) throw new Error(`readOdfFormula: ${CONTENT_PART$
|
|
2983
|
+
if (mathRoot === void 0) throw new Error(`readOdfFormula: ${CONTENT_PART$2} has no MathML root element`);
|
|
2983
2984
|
const metadata = readOdfMetadata(pkg);
|
|
2984
2985
|
const starMath = findStarMathAnnotation(mathRoot);
|
|
2985
2986
|
return starMath === void 0 ? {
|
|
@@ -2993,7 +2994,7 @@ function readOdfFormula(pkg) {
|
|
|
2993
2994
|
}
|
|
2994
2995
|
//#endregion
|
|
2995
2996
|
//#region src/typed/odm/read.ts
|
|
2996
|
-
const CONTENT_PART = "content.xml";
|
|
2997
|
+
const CONTENT_PART$1 = "content.xml";
|
|
2997
2998
|
function readSection(element) {
|
|
2998
2999
|
const sourceElement = findChildElement(element.children, "text:section-source");
|
|
2999
3000
|
if (sourceElement === void 0) return;
|
|
@@ -3011,12 +3012,12 @@ function readSection(element) {
|
|
|
3011
3012
|
};
|
|
3012
3013
|
}
|
|
3013
3014
|
function readOdm(pkg) {
|
|
3014
|
-
const contentPart = pkg.parts[CONTENT_PART];
|
|
3015
|
-
if (contentPart?.kind !== "xml") throw new Error(`readOdm: package has no ${CONTENT_PART} part`);
|
|
3015
|
+
const contentPart = pkg.parts[CONTENT_PART$1];
|
|
3016
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdm: package has no ${CONTENT_PART$1} part`);
|
|
3016
3017
|
const contentRoot = rootElement(contentPart.nodes);
|
|
3017
3018
|
const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
|
|
3018
3019
|
const textElement = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
|
|
3019
|
-
if (textElement === void 0) throw new Error(`readOdm: ${CONTENT_PART} has no office:body/office:text element`);
|
|
3020
|
+
if (textElement === void 0) throw new Error(`readOdm: ${CONTENT_PART$1} has no office:body/office:text element`);
|
|
3020
3021
|
const sections = [];
|
|
3021
3022
|
for (const node of textElement.children) {
|
|
3022
3023
|
if (node.type !== "element" || node.tag !== "text:section") continue;
|
|
@@ -3026,6 +3027,114 @@ function readOdm(pkg) {
|
|
|
3026
3027
|
return { sections };
|
|
3027
3028
|
}
|
|
3028
3029
|
//#endregion
|
|
3030
|
+
//#region src/typed/odb/read.ts
|
|
3031
|
+
const CONTENT_PART = "content.xml";
|
|
3032
|
+
const EMBEDDED_URL_PREFIX = "sdbc:embedded:";
|
|
3033
|
+
const SUBDOCUMENT_CONTENT_SUFFIX = "/content.xml";
|
|
3034
|
+
function isXmlMediaType(mediaType) {
|
|
3035
|
+
return mediaType === "text/xml" || mediaType === "application/xml" || mediaType.endsWith("+xml");
|
|
3036
|
+
}
|
|
3037
|
+
function formatServerDatabaseUrl(serverDatabase) {
|
|
3038
|
+
const dbType = attrValue(serverDatabase, "db:type");
|
|
3039
|
+
if (dbType === void 0) return;
|
|
3040
|
+
const hostname = attrValue(serverDatabase, "db:hostname");
|
|
3041
|
+
const port = attrValue(serverDatabase, "db:port");
|
|
3042
|
+
const localSocketName = attrValue(serverDatabase, "db:local-socket-name");
|
|
3043
|
+
const databaseName = attrValue(serverDatabase, "db:database-name");
|
|
3044
|
+
const host = hostname === void 0 ? localSocketName : `${hostname}${port === void 0 ? "" : `:${port}`}`;
|
|
3045
|
+
if (host === void 0) return databaseName === void 0 ? `${dbType}://` : `${dbType}:///${databaseName}`;
|
|
3046
|
+
return databaseName === void 0 ? `${dbType}://${host}` : `${dbType}://${host}/${databaseName}`;
|
|
3047
|
+
}
|
|
3048
|
+
function readConnectionInfo(databaseElement) {
|
|
3049
|
+
const dataSource = findChildElement(databaseElement.children, "db:data-source");
|
|
3050
|
+
const connectionData = dataSource === void 0 ? void 0 : findChildElement(dataSource.children, "db:connection-data");
|
|
3051
|
+
if (connectionData === void 0) return;
|
|
3052
|
+
const resource = findChildElement(connectionData.children, "db:connection-resource");
|
|
3053
|
+
if (resource !== void 0) {
|
|
3054
|
+
const url = attrValue(resource, "xlink:href");
|
|
3055
|
+
if (url === void 0) return;
|
|
3056
|
+
return {
|
|
3057
|
+
type: url.startsWith(EMBEDDED_URL_PREFIX) ? "embedded" : "external",
|
|
3058
|
+
url
|
|
3059
|
+
};
|
|
3060
|
+
}
|
|
3061
|
+
const description = findChildElement(connectionData.children, "db:database-description");
|
|
3062
|
+
if (description === void 0) return;
|
|
3063
|
+
const fileBased = findChildElement(description.children, "db:file-based-database");
|
|
3064
|
+
if (fileBased !== void 0) {
|
|
3065
|
+
const url = attrValue(fileBased, "xlink:href");
|
|
3066
|
+
return url === void 0 ? { type: "external" } : {
|
|
3067
|
+
type: "external",
|
|
3068
|
+
url
|
|
3069
|
+
};
|
|
3070
|
+
}
|
|
3071
|
+
const serverDatabase = findChildElement(description.children, "db:server-database");
|
|
3072
|
+
if (serverDatabase !== void 0) {
|
|
3073
|
+
const url = formatServerDatabaseUrl(serverDatabase);
|
|
3074
|
+
return url === void 0 ? { type: "external" } : {
|
|
3075
|
+
type: "external",
|
|
3076
|
+
url
|
|
3077
|
+
};
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
function collectQueryNames(container, names) {
|
|
3081
|
+
for (const child of container.children) {
|
|
3082
|
+
if (child.type !== "element") continue;
|
|
3083
|
+
if (child.tag === "db:query") {
|
|
3084
|
+
const name = attrValue(child, "db:name");
|
|
3085
|
+
if (name !== void 0) names.push(name);
|
|
3086
|
+
} else if (child.tag === "db:query-collection") collectQueryNames(child, names);
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
function collectTableNames(databaseElement) {
|
|
3090
|
+
const names = [];
|
|
3091
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3092
|
+
const pushName = (name) => {
|
|
3093
|
+
if (name !== void 0 && !seen.has(name)) {
|
|
3094
|
+
seen.add(name);
|
|
3095
|
+
names.push(name);
|
|
3096
|
+
}
|
|
3097
|
+
};
|
|
3098
|
+
const representations = findChildElement(databaseElement.children, "db:table-representations");
|
|
3099
|
+
if (representations !== void 0) for (const representation of childrenWithTag(representations, "db:table-representation")) pushName(attrValue(representation, "db:name"));
|
|
3100
|
+
const schemaDefinition = findChildElement(databaseElement.children, "db:schema-definition");
|
|
3101
|
+
const tableDefinitions = schemaDefinition === void 0 ? void 0 : findChildElement(schemaDefinition.children, "db:table-definitions");
|
|
3102
|
+
if (tableDefinitions !== void 0) for (const definition of childrenWithTag(tableDefinitions, "db:table-definition")) pushName(attrValue(definition, "db:name"));
|
|
3103
|
+
return names;
|
|
3104
|
+
}
|
|
3105
|
+
function subdocumentNamesUnderPrefix(entries, prefix) {
|
|
3106
|
+
const names = [];
|
|
3107
|
+
for (const entry of entries) {
|
|
3108
|
+
if (!entry.fullPath.startsWith(prefix) || !entry.fullPath.endsWith(SUBDOCUMENT_CONTENT_SUFFIX) || !isXmlMediaType(entry.mediaType)) continue;
|
|
3109
|
+
const withoutSuffix = entry.fullPath.slice(0, entry.fullPath.length - 12);
|
|
3110
|
+
const lastSlash = withoutSuffix.lastIndexOf("/");
|
|
3111
|
+
const name = lastSlash === -1 ? withoutSuffix.slice(prefix.length) : withoutSuffix.slice(lastSlash + 1);
|
|
3112
|
+
if (name.length > 0) names.push(name);
|
|
3113
|
+
}
|
|
3114
|
+
return names;
|
|
3115
|
+
}
|
|
3116
|
+
function readOdbInventory(pkg) {
|
|
3117
|
+
const contentPart = pkg.parts[CONTENT_PART];
|
|
3118
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdbInventory: package has no ${CONTENT_PART} part`);
|
|
3119
|
+
const contentRoot = rootElement(contentPart.nodes);
|
|
3120
|
+
const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
|
|
3121
|
+
const databaseElement = body === void 0 ? void 0 : findChildElement(body.children, "office:database");
|
|
3122
|
+
if (databaseElement === void 0) throw new Error(`readOdbInventory: ${CONTENT_PART} has no office:body/office:database element`);
|
|
3123
|
+
const connection = readConnectionInfo(databaseElement);
|
|
3124
|
+
const queries = [];
|
|
3125
|
+
const queriesElement = findChildElement(databaseElement.children, "db:queries");
|
|
3126
|
+
if (queriesElement !== void 0) collectQueryNames(queriesElement, queries);
|
|
3127
|
+
const tables = collectTableNames(databaseElement);
|
|
3128
|
+
const manifest = readManifest(pkg);
|
|
3129
|
+
return {
|
|
3130
|
+
connection,
|
|
3131
|
+
tables,
|
|
3132
|
+
queries,
|
|
3133
|
+
forms: subdocumentNamesUnderPrefix(manifest.entries, "forms/"),
|
|
3134
|
+
reports: subdocumentNamesUnderPrefix(manifest.entries, "reports/")
|
|
3135
|
+
};
|
|
3136
|
+
}
|
|
3137
|
+
//#endregion
|
|
3029
3138
|
Object.defineProperty(exports, "AlignmentSchema", {
|
|
3030
3139
|
enumerable: true,
|
|
3031
3140
|
get: function() {
|
|
@@ -3114,6 +3223,7 @@ exports.readDrawFrame = readDrawFrame;
|
|
|
3114
3223
|
exports.readDrawPageContent = readDrawPageContent;
|
|
3115
3224
|
exports.readManifest = readManifest;
|
|
3116
3225
|
exports.readMimetype = readMimetype;
|
|
3226
|
+
exports.readOdbInventory = readOdbInventory;
|
|
3117
3227
|
exports.readOdfFormula = readOdfFormula;
|
|
3118
3228
|
exports.readOdfMetadata = readOdfMetadata;
|
|
3119
3229
|
exports.readOdfParagraph = readOdfParagraph;
|
package/dist/index.d.cts
CHANGED
|
@@ -312,6 +312,7 @@ declare const ODF_NAMESPACES: Readonly<{
|
|
|
312
312
|
xsd: "http://www.w3.org/2001/XMLSchema";
|
|
313
313
|
xsi: "http://www.w3.org/2001/XMLSchema-instance";
|
|
314
314
|
manifest: "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0";
|
|
315
|
+
db: "urn:oasis:names:tc:opendocument:xmlns:database:1.0";
|
|
315
316
|
}>;
|
|
316
317
|
type OdfNamespacePrefix = keyof typeof ODF_NAMESPACES;
|
|
317
318
|
declare function xmlnsAttributes(prefixes: readonly OdfNamespacePrefix[]): Record<string, string>;
|
|
@@ -662,4 +663,19 @@ interface OdmDocument {
|
|
|
662
663
|
}
|
|
663
664
|
declare function readOdm(pkg: Package): OdmDocument;
|
|
664
665
|
//#endregion
|
|
665
|
-
|
|
666
|
+
//#region src/typed/odb/read.d.ts
|
|
667
|
+
interface OdbConnectionInfo {
|
|
668
|
+
type: 'embedded' | 'external';
|
|
669
|
+
driverClass?: string;
|
|
670
|
+
url?: string;
|
|
671
|
+
}
|
|
672
|
+
interface OdbInventory {
|
|
673
|
+
connection: OdbConnectionInfo | undefined;
|
|
674
|
+
tables: string[];
|
|
675
|
+
queries: string[];
|
|
676
|
+
forms: string[];
|
|
677
|
+
reports: string[];
|
|
678
|
+
}
|
|
679
|
+
declare function readOdbInventory(pkg: Package): OdbInventory;
|
|
680
|
+
//#endregion
|
|
681
|
+
export { type Alignment, AlignmentSchema, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type BuildManifestOptions, type CascadeDiagnostic, type DrawPageContent, type ImageFormat, type InternRequest, type LengthUnit, MANIFEST_PART, META_PART, MIMETYPE_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, ODF_NAMESPACES, type OdbConnectionInfo, type OdbInventory, type OdfExtension, type OdfFormulaDocument, type OdfNamespacePrefix, type OdfPoint, type OdfRawPoint, type OdfRawSegment, type OdfRawSubpath, type OdfShapeGeometry, type OdfTransformFunction, type OdfViewBox, type OdgDocument, type OdmDocument, type OdmSection, type OdpDocument, type OdsDocument, type OdtDocument, type OtherPartRef, type Package, PackageSchema, type ParsedProperties, type Part, PartSchema, STYLE_FAMILIES, type StyleCascadeResult, type StyleElementChainResult, type StyleFamily, type StyleProperties, StylePropertiesSchema, StyleRegistry, type StyleRegistryOptions, TableCursor, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, type ZipEntry, applyOdfTransform, attrValue, base64ToBytes, buildManifest, buildOdfSubpaths, buildStylePropertyElements, buildXml, bytesToBase64, canonicalPropertiesString, cellReference, childrenWithTag, columnIndexToLetters, columnLettersToIndex, composeOdfGroupTransform, decodeOdfText, decodePackage, decodeXmlText, el, elementsWithTag, encodePackage, encodeXmlText, ensureSpan, findChildElement, findStyleElement, formatOdfColor, formatOdfLength, formatPercentageMultiplier, formatPt, getOdfSpaceCount, isStyleFamily, isXmlNode, measureOdfNodeLength, mediaTypeForExtension, netRotationDeg, packageCodec, paragraphPropertiesToAttributes, parseBox, parseCellReference, parseLength, parseLinePoints, parseMargins, parseOdfColor, parseOdfLength, parseOdfPathData, parseOdfPointsList, parseOdfTransform, parseOdfViewBox, parsePackage, parsePageSize, parseParagraphProperties, parseStyleElementProperties, parseTextProperties, parseXml, rawSubpathFromPoints, readDrawFrame, readDrawPageContent, readManifest, readMimetype, readOdbInventory, readOdfFormula, readOdfMetadata, readOdfParagraph, readOdfTable, readOdg, readOdm, readOdp, readOds, readOdt, resolveDrawPageSize, resolveOdfShapeGeometry, resolvePageLayoutProperties, resolveStyle, resolveStyleElementChain, rootElement, scaleOdfRawPoint, serializePackage, setDocumentMediaType, sniffImageFormat, sumOdfNodeLength, syncManifest, textPropertiesToAttributes, txt, unzipPackage, validateManifest, walkDrawShapes, writeManifest, writeMimetype, xmlCodec, xmlnsAttributes, zipPackage };
|
package/dist/index.d.ts
CHANGED
|
@@ -312,6 +312,7 @@ declare const ODF_NAMESPACES: Readonly<{
|
|
|
312
312
|
xsd: "http://www.w3.org/2001/XMLSchema";
|
|
313
313
|
xsi: "http://www.w3.org/2001/XMLSchema-instance";
|
|
314
314
|
manifest: "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0";
|
|
315
|
+
db: "urn:oasis:names:tc:opendocument:xmlns:database:1.0";
|
|
315
316
|
}>;
|
|
316
317
|
type OdfNamespacePrefix = keyof typeof ODF_NAMESPACES;
|
|
317
318
|
declare function xmlnsAttributes(prefixes: readonly OdfNamespacePrefix[]): Record<string, string>;
|
|
@@ -662,4 +663,19 @@ interface OdmDocument {
|
|
|
662
663
|
}
|
|
663
664
|
declare function readOdm(pkg: Package): OdmDocument;
|
|
664
665
|
//#endregion
|
|
665
|
-
|
|
666
|
+
//#region src/typed/odb/read.d.ts
|
|
667
|
+
interface OdbConnectionInfo {
|
|
668
|
+
type: 'embedded' | 'external';
|
|
669
|
+
driverClass?: string;
|
|
670
|
+
url?: string;
|
|
671
|
+
}
|
|
672
|
+
interface OdbInventory {
|
|
673
|
+
connection: OdbConnectionInfo | undefined;
|
|
674
|
+
tables: string[];
|
|
675
|
+
queries: string[];
|
|
676
|
+
forms: string[];
|
|
677
|
+
reports: string[];
|
|
678
|
+
}
|
|
679
|
+
declare function readOdbInventory(pkg: Package): OdbInventory;
|
|
680
|
+
//#endregion
|
|
681
|
+
export { type Alignment, AlignmentSchema, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type BuildManifestOptions, type CascadeDiagnostic, type DrawPageContent, type ImageFormat, type InternRequest, type LengthUnit, MANIFEST_PART, META_PART, MIMETYPE_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, ODF_NAMESPACES, type OdbConnectionInfo, type OdbInventory, type OdfExtension, type OdfFormulaDocument, type OdfNamespacePrefix, type OdfPoint, type OdfRawPoint, type OdfRawSegment, type OdfRawSubpath, type OdfShapeGeometry, type OdfTransformFunction, type OdfViewBox, type OdgDocument, type OdmDocument, type OdmSection, type OdpDocument, type OdsDocument, type OdtDocument, type OtherPartRef, type Package, PackageSchema, type ParsedProperties, type Part, PartSchema, STYLE_FAMILIES, type StyleCascadeResult, type StyleElementChainResult, type StyleFamily, type StyleProperties, StylePropertiesSchema, StyleRegistry, type StyleRegistryOptions, TableCursor, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, type ZipEntry, applyOdfTransform, attrValue, base64ToBytes, buildManifest, buildOdfSubpaths, buildStylePropertyElements, buildXml, bytesToBase64, canonicalPropertiesString, cellReference, childrenWithTag, columnIndexToLetters, columnLettersToIndex, composeOdfGroupTransform, decodeOdfText, decodePackage, decodeXmlText, el, elementsWithTag, encodePackage, encodeXmlText, ensureSpan, findChildElement, findStyleElement, formatOdfColor, formatOdfLength, formatPercentageMultiplier, formatPt, getOdfSpaceCount, isStyleFamily, isXmlNode, measureOdfNodeLength, mediaTypeForExtension, netRotationDeg, packageCodec, paragraphPropertiesToAttributes, parseBox, parseCellReference, parseLength, parseLinePoints, parseMargins, parseOdfColor, parseOdfLength, parseOdfPathData, parseOdfPointsList, parseOdfTransform, parseOdfViewBox, parsePackage, parsePageSize, parseParagraphProperties, parseStyleElementProperties, parseTextProperties, parseXml, rawSubpathFromPoints, readDrawFrame, readDrawPageContent, readManifest, readMimetype, readOdbInventory, readOdfFormula, readOdfMetadata, readOdfParagraph, readOdfTable, readOdg, readOdm, readOdp, readOds, readOdt, resolveDrawPageSize, resolveOdfShapeGeometry, resolvePageLayoutProperties, resolveStyle, resolveStyleElementChain, rootElement, scaleOdfRawPoint, serializePackage, setDocumentMediaType, sniffImageFormat, sumOdfNodeLength, syncManifest, textPropertiesToAttributes, txt, unzipPackage, validateManifest, walkDrawShapes, writeManifest, writeMimetype, xmlCodec, xmlnsAttributes, zipPackage };
|
package/dist/index.js
CHANGED
|
@@ -354,7 +354,8 @@ const ODF_NAMESPACES = Object.freeze({
|
|
|
354
354
|
xforms: "http://www.w3.org/2002/xforms",
|
|
355
355
|
xsd: "http://www.w3.org/2001/XMLSchema",
|
|
356
356
|
xsi: "http://www.w3.org/2001/XMLSchema-instance",
|
|
357
|
-
manifest: "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"
|
|
357
|
+
manifest: "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",
|
|
358
|
+
db: "urn:oasis:names:tc:opendocument:xmlns:database:1.0"
|
|
358
359
|
});
|
|
359
360
|
function xmlnsAttributes(prefixes) {
|
|
360
361
|
const attrs = {};
|
|
@@ -2483,7 +2484,7 @@ function readDrawPageContent(children, pkg) {
|
|
|
2483
2484
|
}
|
|
2484
2485
|
//#endregion
|
|
2485
2486
|
//#region src/typed/odp/read.ts
|
|
2486
|
-
const CONTENT_PART$
|
|
2487
|
+
const CONTENT_PART$6 = "content.xml";
|
|
2487
2488
|
function readSlideSize(page, pkg) {
|
|
2488
2489
|
return resolveDrawPageSize(page, pkg) ?? SLIDE_SIZE_WIDESCREEN;
|
|
2489
2490
|
}
|
|
@@ -2502,7 +2503,7 @@ function readSlide(page, pkg) {
|
|
|
2502
2503
|
};
|
|
2503
2504
|
}
|
|
2504
2505
|
function readOdp(pkg) {
|
|
2505
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2506
|
+
const contentPart = pkg.parts[CONTENT_PART$6];
|
|
2506
2507
|
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2507
2508
|
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2508
2509
|
const presentation = body === void 0 ? void 0 : findChildElement(body.children, "office:presentation");
|
|
@@ -2514,9 +2515,9 @@ function readOdp(pkg) {
|
|
|
2514
2515
|
}
|
|
2515
2516
|
//#endregion
|
|
2516
2517
|
//#region src/typed/odt/read.ts
|
|
2517
|
-
const CONTENT_PART$
|
|
2518
|
+
const CONTENT_PART$5 = "content.xml";
|
|
2518
2519
|
const STYLES_PART = "styles.xml";
|
|
2519
|
-
const AUTOMATIC_STYLE_PARTS = [CONTENT_PART$
|
|
2520
|
+
const AUTOMATIC_STYLE_PARTS = [CONTENT_PART$5, STYLES_PART];
|
|
2520
2521
|
function readOutlineLevel(headingElement) {
|
|
2521
2522
|
const raw = attrValue(headingElement, "text:outline-level");
|
|
2522
2523
|
if (raw === void 0) return 1;
|
|
@@ -2599,12 +2600,12 @@ function readFirstMasterPageGeometry(pkg) {
|
|
|
2599
2600
|
};
|
|
2600
2601
|
}
|
|
2601
2602
|
function readOdt(pkg) {
|
|
2602
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2603
|
-
if (contentPart?.kind !== "xml") throw new Error(`readOdt: package has no ${CONTENT_PART$
|
|
2603
|
+
const contentPart = pkg.parts[CONTENT_PART$5];
|
|
2604
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdt: package has no ${CONTENT_PART$5} part`);
|
|
2604
2605
|
const contentRoot = rootElement(contentPart.nodes);
|
|
2605
2606
|
const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
|
|
2606
2607
|
const textElement = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
|
|
2607
|
-
if (textElement === void 0) throw new Error(`readOdt: ${CONTENT_PART$
|
|
2608
|
+
if (textElement === void 0) throw new Error(`readOdt: ${CONTENT_PART$5} has no office:body/office:text element`);
|
|
2608
2609
|
const metadata = readOdfMetadata(pkg);
|
|
2609
2610
|
const { pageSize, margins } = readFirstMasterPageGeometry(pkg);
|
|
2610
2611
|
return {
|
|
@@ -2618,7 +2619,7 @@ function readOdt(pkg) {
|
|
|
2618
2619
|
}
|
|
2619
2620
|
//#endregion
|
|
2620
2621
|
//#region src/typed/odg/read.ts
|
|
2621
|
-
const CONTENT_PART$
|
|
2622
|
+
const CONTENT_PART$4 = "content.xml";
|
|
2622
2623
|
const DEFAULT_PAGE_SIZE$1 = PAGE_SIZE_A4;
|
|
2623
2624
|
function readPage(page, pkg) {
|
|
2624
2625
|
const size = resolveDrawPageSize(page, pkg) ?? DEFAULT_PAGE_SIZE$1;
|
|
@@ -2630,7 +2631,7 @@ function readPage(page, pkg) {
|
|
|
2630
2631
|
};
|
|
2631
2632
|
}
|
|
2632
2633
|
function readOdg(pkg) {
|
|
2633
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2634
|
+
const contentPart = pkg.parts[CONTENT_PART$4];
|
|
2634
2635
|
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2635
2636
|
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2636
2637
|
const drawing = body === void 0 ? void 0 : findChildElement(body.children, "office:drawing");
|
|
@@ -2642,7 +2643,7 @@ function readOdg(pkg) {
|
|
|
2642
2643
|
}
|
|
2643
2644
|
//#endregion
|
|
2644
2645
|
//#region src/typed/ods/read.ts
|
|
2645
|
-
const CONTENT_PART$
|
|
2646
|
+
const CONTENT_PART$3 = "content.xml";
|
|
2646
2647
|
function parseKnownOdfLength(value) {
|
|
2647
2648
|
const parsed = parseOdfLength(value);
|
|
2648
2649
|
if (parsed === void 0) throw new Error(`readOds: internal error -- "${value}" is not a valid ODF length literal`);
|
|
@@ -2932,7 +2933,7 @@ function readSheet(tableElement, pkg) {
|
|
|
2932
2933
|
};
|
|
2933
2934
|
}
|
|
2934
2935
|
function readOds(pkg) {
|
|
2935
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2936
|
+
const contentPart = pkg.parts[CONTENT_PART$3];
|
|
2936
2937
|
const root = contentPart?.kind === "xml" ? rootElement(contentPart.nodes) : void 0;
|
|
2937
2938
|
const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
|
|
2938
2939
|
const spreadsheet = body === void 0 ? void 0 : findChildElement(body.children, "office:spreadsheet");
|
|
@@ -2949,7 +2950,7 @@ function readOds(pkg) {
|
|
|
2949
2950
|
}
|
|
2950
2951
|
//#endregion
|
|
2951
2952
|
//#region src/typed/formula/read.ts
|
|
2952
|
-
const CONTENT_PART$
|
|
2953
|
+
const CONTENT_PART$2 = "content.xml";
|
|
2953
2954
|
const MATH_ROOT_TAGS = ["math", "math:math"];
|
|
2954
2955
|
const ANNOTATION_TAGS = ["annotation", "math:annotation"];
|
|
2955
2956
|
const STARMATH_ENCODING_PREFIX = "StarMath";
|
|
@@ -2975,10 +2976,10 @@ function findStarMathAnnotation(mathRoot) {
|
|
|
2975
2976
|
}
|
|
2976
2977
|
}
|
|
2977
2978
|
function readOdfFormula(pkg) {
|
|
2978
|
-
const contentPart = pkg.parts[CONTENT_PART$
|
|
2979
|
-
if (contentPart?.kind !== "xml") throw new Error(`readOdfFormula: package has no ${CONTENT_PART$
|
|
2979
|
+
const contentPart = pkg.parts[CONTENT_PART$2];
|
|
2980
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdfFormula: package has no ${CONTENT_PART$2} part`);
|
|
2980
2981
|
const mathRoot = findMathRoot(contentPart.nodes);
|
|
2981
|
-
if (mathRoot === void 0) throw new Error(`readOdfFormula: ${CONTENT_PART$
|
|
2982
|
+
if (mathRoot === void 0) throw new Error(`readOdfFormula: ${CONTENT_PART$2} has no MathML root element`);
|
|
2982
2983
|
const metadata = readOdfMetadata(pkg);
|
|
2983
2984
|
const starMath = findStarMathAnnotation(mathRoot);
|
|
2984
2985
|
return starMath === void 0 ? {
|
|
@@ -2992,7 +2993,7 @@ function readOdfFormula(pkg) {
|
|
|
2992
2993
|
}
|
|
2993
2994
|
//#endregion
|
|
2994
2995
|
//#region src/typed/odm/read.ts
|
|
2995
|
-
const CONTENT_PART = "content.xml";
|
|
2996
|
+
const CONTENT_PART$1 = "content.xml";
|
|
2996
2997
|
function readSection(element) {
|
|
2997
2998
|
const sourceElement = findChildElement(element.children, "text:section-source");
|
|
2998
2999
|
if (sourceElement === void 0) return;
|
|
@@ -3010,12 +3011,12 @@ function readSection(element) {
|
|
|
3010
3011
|
};
|
|
3011
3012
|
}
|
|
3012
3013
|
function readOdm(pkg) {
|
|
3013
|
-
const contentPart = pkg.parts[CONTENT_PART];
|
|
3014
|
-
if (contentPart?.kind !== "xml") throw new Error(`readOdm: package has no ${CONTENT_PART} part`);
|
|
3014
|
+
const contentPart = pkg.parts[CONTENT_PART$1];
|
|
3015
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdm: package has no ${CONTENT_PART$1} part`);
|
|
3015
3016
|
const contentRoot = rootElement(contentPart.nodes);
|
|
3016
3017
|
const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
|
|
3017
3018
|
const textElement = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
|
|
3018
|
-
if (textElement === void 0) throw new Error(`readOdm: ${CONTENT_PART} has no office:body/office:text element`);
|
|
3019
|
+
if (textElement === void 0) throw new Error(`readOdm: ${CONTENT_PART$1} has no office:body/office:text element`);
|
|
3019
3020
|
const sections = [];
|
|
3020
3021
|
for (const node of textElement.children) {
|
|
3021
3022
|
if (node.type !== "element" || node.tag !== "text:section") continue;
|
|
@@ -3025,4 +3026,112 @@ function readOdm(pkg) {
|
|
|
3025
3026
|
return { sections };
|
|
3026
3027
|
}
|
|
3027
3028
|
//#endregion
|
|
3028
|
-
|
|
3029
|
+
//#region src/typed/odb/read.ts
|
|
3030
|
+
const CONTENT_PART = "content.xml";
|
|
3031
|
+
const EMBEDDED_URL_PREFIX = "sdbc:embedded:";
|
|
3032
|
+
const SUBDOCUMENT_CONTENT_SUFFIX = "/content.xml";
|
|
3033
|
+
function isXmlMediaType(mediaType) {
|
|
3034
|
+
return mediaType === "text/xml" || mediaType === "application/xml" || mediaType.endsWith("+xml");
|
|
3035
|
+
}
|
|
3036
|
+
function formatServerDatabaseUrl(serverDatabase) {
|
|
3037
|
+
const dbType = attrValue(serverDatabase, "db:type");
|
|
3038
|
+
if (dbType === void 0) return;
|
|
3039
|
+
const hostname = attrValue(serverDatabase, "db:hostname");
|
|
3040
|
+
const port = attrValue(serverDatabase, "db:port");
|
|
3041
|
+
const localSocketName = attrValue(serverDatabase, "db:local-socket-name");
|
|
3042
|
+
const databaseName = attrValue(serverDatabase, "db:database-name");
|
|
3043
|
+
const host = hostname === void 0 ? localSocketName : `${hostname}${port === void 0 ? "" : `:${port}`}`;
|
|
3044
|
+
if (host === void 0) return databaseName === void 0 ? `${dbType}://` : `${dbType}:///${databaseName}`;
|
|
3045
|
+
return databaseName === void 0 ? `${dbType}://${host}` : `${dbType}://${host}/${databaseName}`;
|
|
3046
|
+
}
|
|
3047
|
+
function readConnectionInfo(databaseElement) {
|
|
3048
|
+
const dataSource = findChildElement(databaseElement.children, "db:data-source");
|
|
3049
|
+
const connectionData = dataSource === void 0 ? void 0 : findChildElement(dataSource.children, "db:connection-data");
|
|
3050
|
+
if (connectionData === void 0) return;
|
|
3051
|
+
const resource = findChildElement(connectionData.children, "db:connection-resource");
|
|
3052
|
+
if (resource !== void 0) {
|
|
3053
|
+
const url = attrValue(resource, "xlink:href");
|
|
3054
|
+
if (url === void 0) return;
|
|
3055
|
+
return {
|
|
3056
|
+
type: url.startsWith(EMBEDDED_URL_PREFIX) ? "embedded" : "external",
|
|
3057
|
+
url
|
|
3058
|
+
};
|
|
3059
|
+
}
|
|
3060
|
+
const description = findChildElement(connectionData.children, "db:database-description");
|
|
3061
|
+
if (description === void 0) return;
|
|
3062
|
+
const fileBased = findChildElement(description.children, "db:file-based-database");
|
|
3063
|
+
if (fileBased !== void 0) {
|
|
3064
|
+
const url = attrValue(fileBased, "xlink:href");
|
|
3065
|
+
return url === void 0 ? { type: "external" } : {
|
|
3066
|
+
type: "external",
|
|
3067
|
+
url
|
|
3068
|
+
};
|
|
3069
|
+
}
|
|
3070
|
+
const serverDatabase = findChildElement(description.children, "db:server-database");
|
|
3071
|
+
if (serverDatabase !== void 0) {
|
|
3072
|
+
const url = formatServerDatabaseUrl(serverDatabase);
|
|
3073
|
+
return url === void 0 ? { type: "external" } : {
|
|
3074
|
+
type: "external",
|
|
3075
|
+
url
|
|
3076
|
+
};
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
function collectQueryNames(container, names) {
|
|
3080
|
+
for (const child of container.children) {
|
|
3081
|
+
if (child.type !== "element") continue;
|
|
3082
|
+
if (child.tag === "db:query") {
|
|
3083
|
+
const name = attrValue(child, "db:name");
|
|
3084
|
+
if (name !== void 0) names.push(name);
|
|
3085
|
+
} else if (child.tag === "db:query-collection") collectQueryNames(child, names);
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
function collectTableNames(databaseElement) {
|
|
3089
|
+
const names = [];
|
|
3090
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3091
|
+
const pushName = (name) => {
|
|
3092
|
+
if (name !== void 0 && !seen.has(name)) {
|
|
3093
|
+
seen.add(name);
|
|
3094
|
+
names.push(name);
|
|
3095
|
+
}
|
|
3096
|
+
};
|
|
3097
|
+
const representations = findChildElement(databaseElement.children, "db:table-representations");
|
|
3098
|
+
if (representations !== void 0) for (const representation of childrenWithTag(representations, "db:table-representation")) pushName(attrValue(representation, "db:name"));
|
|
3099
|
+
const schemaDefinition = findChildElement(databaseElement.children, "db:schema-definition");
|
|
3100
|
+
const tableDefinitions = schemaDefinition === void 0 ? void 0 : findChildElement(schemaDefinition.children, "db:table-definitions");
|
|
3101
|
+
if (tableDefinitions !== void 0) for (const definition of childrenWithTag(tableDefinitions, "db:table-definition")) pushName(attrValue(definition, "db:name"));
|
|
3102
|
+
return names;
|
|
3103
|
+
}
|
|
3104
|
+
function subdocumentNamesUnderPrefix(entries, prefix) {
|
|
3105
|
+
const names = [];
|
|
3106
|
+
for (const entry of entries) {
|
|
3107
|
+
if (!entry.fullPath.startsWith(prefix) || !entry.fullPath.endsWith(SUBDOCUMENT_CONTENT_SUFFIX) || !isXmlMediaType(entry.mediaType)) continue;
|
|
3108
|
+
const withoutSuffix = entry.fullPath.slice(0, entry.fullPath.length - 12);
|
|
3109
|
+
const lastSlash = withoutSuffix.lastIndexOf("/");
|
|
3110
|
+
const name = lastSlash === -1 ? withoutSuffix.slice(prefix.length) : withoutSuffix.slice(lastSlash + 1);
|
|
3111
|
+
if (name.length > 0) names.push(name);
|
|
3112
|
+
}
|
|
3113
|
+
return names;
|
|
3114
|
+
}
|
|
3115
|
+
function readOdbInventory(pkg) {
|
|
3116
|
+
const contentPart = pkg.parts[CONTENT_PART];
|
|
3117
|
+
if (contentPart?.kind !== "xml") throw new Error(`readOdbInventory: package has no ${CONTENT_PART} part`);
|
|
3118
|
+
const contentRoot = rootElement(contentPart.nodes);
|
|
3119
|
+
const body = contentRoot === void 0 ? void 0 : findChildElement(contentRoot.children, "office:body");
|
|
3120
|
+
const databaseElement = body === void 0 ? void 0 : findChildElement(body.children, "office:database");
|
|
3121
|
+
if (databaseElement === void 0) throw new Error(`readOdbInventory: ${CONTENT_PART} has no office:body/office:database element`);
|
|
3122
|
+
const connection = readConnectionInfo(databaseElement);
|
|
3123
|
+
const queries = [];
|
|
3124
|
+
const queriesElement = findChildElement(databaseElement.children, "db:queries");
|
|
3125
|
+
if (queriesElement !== void 0) collectQueryNames(queriesElement, queries);
|
|
3126
|
+
const tables = collectTableNames(databaseElement);
|
|
3127
|
+
const manifest = readManifest(pkg);
|
|
3128
|
+
return {
|
|
3129
|
+
connection,
|
|
3130
|
+
tables,
|
|
3131
|
+
queries,
|
|
3132
|
+
forms: subdocumentNamesUnderPrefix(manifest.entries, "forms/"),
|
|
3133
|
+
reports: subdocumentNamesUnderPrefix(manifest.entries, "reports/")
|
|
3134
|
+
};
|
|
3135
|
+
}
|
|
3136
|
+
//#endregion
|
|
3137
|
+
export { AlignmentSchema, AttributeSchema, BinaryPartSchema, MANIFEST_PART, META_PART, MIMETYPE_PART, ManifestEntrySchema, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, ODF_NAMESPACES, PackageSchema, PartSchema, STYLE_FAMILIES, StylePropertiesSchema, StyleRegistry, TableCursor, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPartSchema, XmlPiSchema, XmlTextSchema, applyOdfTransform, attrValue, base64ToBytes, buildManifest, buildOdfSubpaths, buildStylePropertyElements, buildXml, bytesToBase64, canonicalPropertiesString, cellReference, childrenWithTag, columnIndexToLetters, columnLettersToIndex, composeOdfGroupTransform, decodeOdfText, decodePackage, decodeXmlText, el, elementsWithTag, encodePackage, encodeXmlText, ensureSpan, findChildElement, findStyleElement, formatOdfColor, formatOdfLength, formatPercentageMultiplier, formatPt, getOdfSpaceCount, isStyleFamily, isXmlNode, measureOdfNodeLength, mediaTypeForExtension, netRotationDeg, packageCodec, paragraphPropertiesToAttributes, parseBox, parseCellReference, parseLength, parseLinePoints, parseMargins, parseOdfColor, parseOdfLength, parseOdfPathData, parseOdfPointsList, parseOdfTransform, parseOdfViewBox, parsePackage, parsePageSize, parseParagraphProperties, parseStyleElementProperties, parseTextProperties, parseXml, rawSubpathFromPoints, readDrawFrame, readDrawPageContent, readManifest, readMimetype, readOdbInventory, readOdfFormula, readOdfMetadata, readOdfParagraph, readOdfTable, readOdg, readOdm, readOdp, readOds, readOdt, resolveDrawPageSize, resolveOdfShapeGeometry, resolvePageLayoutProperties, resolveStyle, resolveStyleElementChain, rootElement, scaleOdfRawPoint, serializePackage, setDocumentMediaType, sniffImageFormat, sumOdfNodeLength, syncManifest, textPropertiesToAttributes, txt, unzipPackage, validateManifest, walkDrawShapes, writeManifest, writeMimetype, xmlCodec, xmlnsAttributes, zipPackage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "odf.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Type-safe, lossless round-trip conversion between OpenDocument Format packages (odt, ods, odp) and JSON, hand-written and dependency-minimal, built on Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|