odf.js 6.1.2 → 6.2.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 +44 -1
- package/dist/{codec-lz3vgEos.d.cts → codec-B72LApRl.d.cts} +3 -0
- package/dist/{codec-CyJ4gSH2.d.ts → codec-rbZGlr37.d.ts} +3 -0
- package/dist/codec.d.cts +1 -1
- package/dist/codec.d.ts +1 -1
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +4 -1
- package/dist/ns-C14w-Zhf.d.cts +42 -0
- package/dist/ns-CTyKJZeF.d.ts +42 -0
- package/dist/ooo1/ns.cjs +74 -0
- package/dist/ooo1/ns.d.cts +2 -0
- package/dist/ooo1/ns.d.ts +2 -0
- package/dist/ooo1/ns.js +69 -0
- package/dist/ooo1/properties.cjs +405 -0
- package/dist/ooo1/properties.d.cts +7 -0
- package/dist/ooo1/properties.d.ts +7 -0
- package/dist/ooo1/properties.js +403 -0
- package/dist/ooo1/read.cjs +39 -0
- package/dist/ooo1/read.d.cts +2 -0
- package/dist/ooo1/read.d.ts +2 -0
- package/dist/ooo1/read.js +31 -0
- package/dist/ooo1/transform.cjs +402 -0
- package/dist/ooo1/transform.d.cts +2 -0
- package/dist/ooo1/transform.d.ts +2 -0
- package/dist/ooo1/transform.js +401 -0
- package/dist/read-3yy5EFV_.d.ts +17 -0
- package/dist/read-RFqq4ckj.d.cts +17 -0
- package/dist/transform-DRr76JEu.d.ts +5 -0
- package/dist/transform-SDysw9wx.d.cts +5 -0
- package/package.json +9 -3
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { bytesToBase64 } from "../util/base64.js";
|
|
2
|
+
import { ODF_NAMESPACES } from "../ns.js";
|
|
3
|
+
import { rootElement } from "../xml/query.js";
|
|
4
|
+
import { OOO1_NAMESPACES, isOoo1Package, odfMediaTypeForOoo1MediaType } from "./ns.js";
|
|
5
|
+
import { propertyTypesForContainer, splitStyleProperties } from "./properties.js";
|
|
6
|
+
//#region src/ooo1/transform.ts
|
|
7
|
+
const CANONICAL_PREFIX_BY_URI = new Map([...Object.entries(OOO1_NAMESPACES).map(([prefix, uri]) => [uri, prefix]), ...Object.entries(ODF_NAMESPACES).map(([prefix, uri]) => [uri, prefix])]);
|
|
8
|
+
function isOdfNamespacePrefix(prefix) {
|
|
9
|
+
return Object.hasOwn(ODF_NAMESPACES, prefix);
|
|
10
|
+
}
|
|
11
|
+
const GENRE_ELEMENT_BY_CLASS = /* @__PURE__ */ new Map([
|
|
12
|
+
["text", "office:text"],
|
|
13
|
+
["text-global", "office:text"],
|
|
14
|
+
["spreadsheet", "office:spreadsheet"],
|
|
15
|
+
["presentation", "office:presentation"],
|
|
16
|
+
["drawing", "office:drawing"],
|
|
17
|
+
["chart", "office:chart"]
|
|
18
|
+
]);
|
|
19
|
+
const RENAMED_ELEMENTS = /* @__PURE__ */ new Map([
|
|
20
|
+
["office:font-decls", "office:font-face-decls"],
|
|
21
|
+
["office:script", "office:scripts"],
|
|
22
|
+
["office:script-data", "office:script"],
|
|
23
|
+
["office:events", "office:event-listeners"],
|
|
24
|
+
["style:page-master", "style:page-layout"],
|
|
25
|
+
["text:ordered-list", "text:list"],
|
|
26
|
+
["text:unordered-list", "text:list"],
|
|
27
|
+
["text:tab-stop", "text:tab"],
|
|
28
|
+
["text:footnote-body", "text:note-body"],
|
|
29
|
+
["text:endnote-body", "text:note-body"],
|
|
30
|
+
["text:footnote-citation", "text:note-citation"],
|
|
31
|
+
["text:endnote-citation", "text:note-citation"],
|
|
32
|
+
["text:database-select", "text:database-row-select"],
|
|
33
|
+
["text:index-entry-chapter-number", "text:index-entry-chapter"],
|
|
34
|
+
["table:dependences", "table:dependencies"],
|
|
35
|
+
["table:dependence", "table:dependency"]
|
|
36
|
+
]);
|
|
37
|
+
const NOTE_ELEMENTS = /* @__PURE__ */ new Map([
|
|
38
|
+
["text:footnote", {
|
|
39
|
+
tag: "text:note",
|
|
40
|
+
noteClass: "footnote"
|
|
41
|
+
}],
|
|
42
|
+
["text:endnote", {
|
|
43
|
+
tag: "text:note",
|
|
44
|
+
noteClass: "endnote"
|
|
45
|
+
}],
|
|
46
|
+
["text:footnote-ref", {
|
|
47
|
+
tag: "text:note-ref",
|
|
48
|
+
noteClass: "footnote"
|
|
49
|
+
}],
|
|
50
|
+
["text:endnote-ref", {
|
|
51
|
+
tag: "text:note-ref",
|
|
52
|
+
noteClass: "endnote"
|
|
53
|
+
}],
|
|
54
|
+
["text:footnotes-configuration", {
|
|
55
|
+
tag: "text:notes-configuration",
|
|
56
|
+
noteClass: "footnote"
|
|
57
|
+
}],
|
|
58
|
+
["text:endnotes-configuration", {
|
|
59
|
+
tag: "text:notes-configuration",
|
|
60
|
+
noteClass: "endnote"
|
|
61
|
+
}]
|
|
62
|
+
]);
|
|
63
|
+
const RENAMED_ATTRIBUTES = /* @__PURE__ */ new Map([
|
|
64
|
+
["style:page-master-name", "style:page-layout-name"],
|
|
65
|
+
["style:leader-char", "style:leader-text"],
|
|
66
|
+
["text:count-in-floating-frames", "text:count-in-text-boxes"],
|
|
67
|
+
["form:service-name", "form:control-implementation"],
|
|
68
|
+
["form:column-style-name", "form:text-style-name"],
|
|
69
|
+
["form:property-type", "office:value-type"]
|
|
70
|
+
]);
|
|
71
|
+
const VALUE_ATTRIBUTE_LOCAL_NAMES = [
|
|
72
|
+
"value-type",
|
|
73
|
+
"value",
|
|
74
|
+
"currency",
|
|
75
|
+
"date-value",
|
|
76
|
+
"time-value",
|
|
77
|
+
"boolean-value",
|
|
78
|
+
"string-value"
|
|
79
|
+
];
|
|
80
|
+
const CELL_ELEMENTS = /* @__PURE__ */ new Set([
|
|
81
|
+
"table:table-cell",
|
|
82
|
+
"table:covered-table-cell",
|
|
83
|
+
"table:change-track-table-cell"
|
|
84
|
+
]);
|
|
85
|
+
const TEXT_VALUE_ELEMENTS = /* @__PURE__ */ new Set([
|
|
86
|
+
"text:variable-decl",
|
|
87
|
+
"text:variable-set",
|
|
88
|
+
"text:variable-input",
|
|
89
|
+
"text:variable-get",
|
|
90
|
+
"text:user-field-decl",
|
|
91
|
+
"text:user-field-get",
|
|
92
|
+
"text:user-field-input",
|
|
93
|
+
"text:expression"
|
|
94
|
+
]);
|
|
95
|
+
const FRAME_SHAPES = /* @__PURE__ */ new Set([
|
|
96
|
+
"draw:text-box",
|
|
97
|
+
"draw:image",
|
|
98
|
+
"draw:object",
|
|
99
|
+
"draw:object-ole",
|
|
100
|
+
"draw:applet",
|
|
101
|
+
"draw:plugin",
|
|
102
|
+
"draw:floating-frame"
|
|
103
|
+
]);
|
|
104
|
+
const FRAME_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
105
|
+
"draw:z-index",
|
|
106
|
+
"draw:id",
|
|
107
|
+
"draw:layer",
|
|
108
|
+
"draw:style-name",
|
|
109
|
+
"presentation:style-name",
|
|
110
|
+
"draw:transform",
|
|
111
|
+
"draw:name",
|
|
112
|
+
"table:end-cell-address",
|
|
113
|
+
"table:end-x",
|
|
114
|
+
"table:end-y",
|
|
115
|
+
"table:table-background",
|
|
116
|
+
"text:anchor-type",
|
|
117
|
+
"text:anchor-page-number",
|
|
118
|
+
"draw:text-style-name",
|
|
119
|
+
"svg:x",
|
|
120
|
+
"svg:y",
|
|
121
|
+
"svg:width",
|
|
122
|
+
"svg:height",
|
|
123
|
+
"style:rel-width",
|
|
124
|
+
"style:rel-height",
|
|
125
|
+
"presentation:class",
|
|
126
|
+
"presentation:placeholder",
|
|
127
|
+
"presentation:user-transformed"
|
|
128
|
+
]);
|
|
129
|
+
const FRAME_CHILD_ELEMENTS = /* @__PURE__ */ new Set([
|
|
130
|
+
"office:event-listeners",
|
|
131
|
+
"draw:glue-point",
|
|
132
|
+
"draw:image-map",
|
|
133
|
+
"svg:desc",
|
|
134
|
+
"svg:title",
|
|
135
|
+
"draw:contour-polygon",
|
|
136
|
+
"draw:contour-path"
|
|
137
|
+
]);
|
|
138
|
+
const PACKAGE_HREF_ELEMENTS = /* @__PURE__ */ new Set([
|
|
139
|
+
"draw:image",
|
|
140
|
+
"draw:object",
|
|
141
|
+
"draw:object-ole",
|
|
142
|
+
"draw:applet",
|
|
143
|
+
"draw:plugin",
|
|
144
|
+
"draw:floating-frame",
|
|
145
|
+
"draw:fill-image",
|
|
146
|
+
"style:background-image",
|
|
147
|
+
"text:list-level-style-image"
|
|
148
|
+
]);
|
|
149
|
+
const INCH_TOKEN = /(^|\s)(-?(?:\d+(?:\.\d+)?|\.\d+))inch(?=\s|$)/g;
|
|
150
|
+
function carriesNoLength(attributeName) {
|
|
151
|
+
return attributeName.endsWith("name") || attributeName === "xlink:href";
|
|
152
|
+
}
|
|
153
|
+
function normaliseAttributeValue(name, value) {
|
|
154
|
+
if (carriesNoLength(name)) return value;
|
|
155
|
+
return value.replace(INCH_TOKEN, "$1$2in");
|
|
156
|
+
}
|
|
157
|
+
function renameQName(qname, prefixes) {
|
|
158
|
+
const colon = qname.indexOf(":");
|
|
159
|
+
if (colon < 0) return qname;
|
|
160
|
+
const canonical = prefixes.get(qname.slice(0, colon));
|
|
161
|
+
return canonical === void 0 ? qname : `${canonical}:${qname.slice(colon + 1)}`;
|
|
162
|
+
}
|
|
163
|
+
function transformNamespaceDeclaration(attribute) {
|
|
164
|
+
const canonical = CANONICAL_PREFIX_BY_URI.get(attribute.value);
|
|
165
|
+
if (canonical === void 0 || !isOdfNamespacePrefix(canonical)) return attribute;
|
|
166
|
+
return {
|
|
167
|
+
name: attribute.name === "xmlns" ? "xmlns" : `xmlns:${canonical}`,
|
|
168
|
+
value: ODF_NAMESPACES[canonical]
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const DOCUMENT_ROOT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
172
|
+
"office:document",
|
|
173
|
+
"office:document-content",
|
|
174
|
+
"office:document-styles",
|
|
175
|
+
"office:document-meta",
|
|
176
|
+
"office:document-settings"
|
|
177
|
+
]);
|
|
178
|
+
function transformAttributes(element, tag, prefixes) {
|
|
179
|
+
const out = [];
|
|
180
|
+
for (const attribute of element.attributes) {
|
|
181
|
+
if (attribute.name === "xmlns" || attribute.name.startsWith("xmlns:")) {
|
|
182
|
+
out.push(transformNamespaceDeclaration(attribute));
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const name = renameQName(attribute.name, prefixes);
|
|
186
|
+
if (name === "office:class" && DOCUMENT_ROOT_ELEMENTS.has(tag)) continue;
|
|
187
|
+
const value = normaliseAttributeValue(name, attribute.value);
|
|
188
|
+
out.push({
|
|
189
|
+
name: renameAttributeFor(tag, name),
|
|
190
|
+
value: rewriteHref(tag, name, value)
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
function renameAttributeFor(tag, name) {
|
|
196
|
+
const renamed = RENAMED_ATTRIBUTES.get(name);
|
|
197
|
+
if (renamed !== void 0) return renamed;
|
|
198
|
+
if (name === "text:level" && (tag === "text:h" || tag === "text:p")) return "text:outline-level";
|
|
199
|
+
if (CELL_ELEMENTS.has(tag)) {
|
|
200
|
+
if (name === "table:validation-name") return "table:content-validation-name";
|
|
201
|
+
for (const local of VALUE_ATTRIBUTE_LOCAL_NAMES) if (name === `table:${local}`) return `office:${local}`;
|
|
202
|
+
}
|
|
203
|
+
if (TEXT_VALUE_ELEMENTS.has(tag)) {
|
|
204
|
+
for (const local of VALUE_ATTRIBUTE_LOCAL_NAMES) if (name === `text:${local}`) return `office:${local}`;
|
|
205
|
+
}
|
|
206
|
+
if (tag === "style:column") {
|
|
207
|
+
if (name === "fo:margin-left") return "fo:start-indent";
|
|
208
|
+
if (name === "fo:margin-right") return "fo:end-indent";
|
|
209
|
+
}
|
|
210
|
+
return name;
|
|
211
|
+
}
|
|
212
|
+
function rewriteHref(tag, name, value) {
|
|
213
|
+
if (name === "xlink:href" && value.startsWith("#") && PACKAGE_HREF_ELEMENTS.has(tag)) return value.slice(1);
|
|
214
|
+
return value;
|
|
215
|
+
}
|
|
216
|
+
function withoutAttributes(attributes, drop) {
|
|
217
|
+
return attributes.filter((attribute) => !drop.has(attribute.name));
|
|
218
|
+
}
|
|
219
|
+
function element(tag, attributes, children) {
|
|
220
|
+
return {
|
|
221
|
+
type: "element",
|
|
222
|
+
tag,
|
|
223
|
+
attributes,
|
|
224
|
+
children
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function textElement(tag, value) {
|
|
228
|
+
return element(tag, [], [{
|
|
229
|
+
type: "text",
|
|
230
|
+
value
|
|
231
|
+
}]);
|
|
232
|
+
}
|
|
233
|
+
const MOVED_TO_CHILD_ELEMENT = /* @__PURE__ */ new Map([["office:annotation", /* @__PURE__ */ new Map([
|
|
234
|
+
["office:author", "dc:creator"],
|
|
235
|
+
["office:create-date", "dc:date"],
|
|
236
|
+
["office:create-date-string", "meta:date-string"]
|
|
237
|
+
])], ["office:change-info", /* @__PURE__ */ new Map([["office:chg-author", "dc:creator"], ["office:chg-date-time", "dc:date"]])]]);
|
|
238
|
+
function transformNodes(nodes, context) {
|
|
239
|
+
const out = [];
|
|
240
|
+
for (const node of nodes) {
|
|
241
|
+
if (node.type !== "element") {
|
|
242
|
+
out.push(node);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
out.push(...transformElement(node, context));
|
|
246
|
+
}
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
function transformElement(source, context) {
|
|
250
|
+
const renamedTag = renameQName(source.tag, context.prefixes);
|
|
251
|
+
if (renamedTag === "style:properties") {
|
|
252
|
+
const staged = element(renamedTag, transformAttributes(source, renamedTag, context.prefixes), transformNodes(source.children, {
|
|
253
|
+
...context,
|
|
254
|
+
propertyTypes: void 0
|
|
255
|
+
}));
|
|
256
|
+
if (context.propertyTypes === void 0) return [staged];
|
|
257
|
+
return splitStyleProperties(staged, context.propertyTypes);
|
|
258
|
+
}
|
|
259
|
+
if (renamedTag === "meta:keywords") return transformNodes(source.children, {
|
|
260
|
+
...context,
|
|
261
|
+
propertyTypes: void 0
|
|
262
|
+
});
|
|
263
|
+
const attributes = transformAttributes(source, renamedTag, context.prefixes);
|
|
264
|
+
const childContext = {
|
|
265
|
+
...context,
|
|
266
|
+
propertyTypes: propertyTypesForContainer({
|
|
267
|
+
...source,
|
|
268
|
+
tag: renamedTag,
|
|
269
|
+
attributes
|
|
270
|
+
})
|
|
271
|
+
};
|
|
272
|
+
const children = transformNodes(source.children, childContext);
|
|
273
|
+
if (renamedTag === "office:body") return [buildBody(attributes, children, context.documentClass)];
|
|
274
|
+
const note = NOTE_ELEMENTS.get(renamedTag);
|
|
275
|
+
if (note !== void 0) return [element(note.tag, [...attributes, {
|
|
276
|
+
name: "text:note-class",
|
|
277
|
+
value: note.noteClass
|
|
278
|
+
}], children)];
|
|
279
|
+
if (renamedTag === "table:sub-table") return [element("table:table", [...attributes, {
|
|
280
|
+
name: "table:is-sub-table",
|
|
281
|
+
value: "true"
|
|
282
|
+
}], children)];
|
|
283
|
+
if (renamedTag === "style:font-decl") return [element("style:font-face", attributes.map((attribute) => {
|
|
284
|
+
if (attribute.name === "fo:font-family") return {
|
|
285
|
+
name: "svg:font-family",
|
|
286
|
+
value: attribute.value
|
|
287
|
+
};
|
|
288
|
+
if (attribute.name === "style:font-style-name") return {
|
|
289
|
+
name: "style:font-adornments",
|
|
290
|
+
value: attribute.value
|
|
291
|
+
};
|
|
292
|
+
return attribute;
|
|
293
|
+
}), children)];
|
|
294
|
+
const moved = MOVED_TO_CHILD_ELEMENT.get(renamedTag);
|
|
295
|
+
if (moved !== void 0) {
|
|
296
|
+
const promoted = [];
|
|
297
|
+
for (const [from, to] of moved) {
|
|
298
|
+
const value = attributes.find((attribute) => attribute.name === from)?.value;
|
|
299
|
+
if (value !== void 0) promoted.push(textElement(to, value));
|
|
300
|
+
}
|
|
301
|
+
return [element(renamedTag, withoutAttributes(attributes, new Set(moved.keys())), [...promoted, ...children])];
|
|
302
|
+
}
|
|
303
|
+
if (FRAME_SHAPES.has(renamedTag)) return [buildFrame(renamedTag, attributes, children)];
|
|
304
|
+
if (renamedTag === "form:property") return [element(renamedTag, withoutAttributes(attributes, /* @__PURE__ */ new Set(["form:property-is-list"])), children)];
|
|
305
|
+
const renamed = RENAMED_ELEMENTS.get(renamedTag);
|
|
306
|
+
if (renamed !== void 0) return [element(renamed, attributes, children)];
|
|
307
|
+
return [element(renamedTag, attributes, children)];
|
|
308
|
+
}
|
|
309
|
+
function buildBody(attributes, children, documentClass) {
|
|
310
|
+
const genre = documentClass === void 0 ? void 0 : GENRE_ELEMENT_BY_CLASS.get(documentClass);
|
|
311
|
+
if (genre === void 0) return element("office:body", attributes, children);
|
|
312
|
+
return element("office:body", attributes, [element(genre, [], children)]);
|
|
313
|
+
}
|
|
314
|
+
function buildFrame(tag, attributes, children) {
|
|
315
|
+
const frameAttributes = attributes.filter((attribute) => FRAME_ATTRIBUTES.has(attribute.name));
|
|
316
|
+
const shapeAttributes = attributes.filter((attribute) => !FRAME_ATTRIBUTES.has(attribute.name));
|
|
317
|
+
const frameChildren = [];
|
|
318
|
+
const shapeChildren = [];
|
|
319
|
+
for (const child of children) if (child.type === "element" && FRAME_CHILD_ELEMENTS.has(child.tag)) frameChildren.push(child);
|
|
320
|
+
else shapeChildren.push(child);
|
|
321
|
+
return element("draw:frame", frameAttributes, [element(tag, shapeAttributes, shapeChildren), ...frameChildren]);
|
|
322
|
+
}
|
|
323
|
+
function prefixRenames(root) {
|
|
324
|
+
const renames = /* @__PURE__ */ new Map();
|
|
325
|
+
for (const attribute of root.attributes) {
|
|
326
|
+
if (!attribute.name.startsWith("xmlns:")) continue;
|
|
327
|
+
const declared = attribute.name.slice(6);
|
|
328
|
+
const canonical = CANONICAL_PREFIX_BY_URI.get(attribute.value);
|
|
329
|
+
if (canonical !== void 0 && canonical !== declared) renames.set(declared, canonical);
|
|
330
|
+
}
|
|
331
|
+
return renames;
|
|
332
|
+
}
|
|
333
|
+
function transformXmlPart(nodes) {
|
|
334
|
+
const root = rootElement(nodes);
|
|
335
|
+
if (root === void 0) return [...nodes];
|
|
336
|
+
const prefixes = prefixRenames(root);
|
|
337
|
+
const classAttributeName = [...prefixes.entries()].find(([, canonical]) => canonical === "office")?.[0];
|
|
338
|
+
return transformNodes(nodes, {
|
|
339
|
+
prefixes,
|
|
340
|
+
documentClass: root.attributes.find((attribute) => attribute.name === "office:class" || classAttributeName !== void 0 && attribute.name === `${classAttributeName}:class`)?.value
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
const MANIFEST_PATH = "META-INF/manifest.xml";
|
|
344
|
+
const MIMETYPE_PATH = "mimetype";
|
|
345
|
+
function odfMediaTypeOf(pkg) {
|
|
346
|
+
const manifest = pkg.parts[MANIFEST_PATH];
|
|
347
|
+
if (manifest?.kind !== "xml") return;
|
|
348
|
+
const root = rootElement(manifest.nodes);
|
|
349
|
+
if (root === void 0) return;
|
|
350
|
+
for (const entry of root.children) {
|
|
351
|
+
if (entry.type !== "element" || !entry.tag.endsWith(":file-entry")) continue;
|
|
352
|
+
if (entry.attributes.find((attribute) => attribute.name.endsWith(":full-path"))?.value !== "/") continue;
|
|
353
|
+
const mediaType = entry.attributes.find((attribute) => attribute.name.endsWith(":media-type"))?.value;
|
|
354
|
+
return mediaType === void 0 ? void 0 : odfMediaTypeForOoo1MediaType(mediaType);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function rewriteManifestMediaType(nodes, odfMediaType) {
|
|
358
|
+
return nodes.map((node) => {
|
|
359
|
+
if (node.type !== "element") return node;
|
|
360
|
+
return {
|
|
361
|
+
...node,
|
|
362
|
+
children: node.children.map((entry) => {
|
|
363
|
+
if (entry.type !== "element" || entry.tag !== "manifest:file-entry") return entry;
|
|
364
|
+
if (entry.attributes.find((attribute) => attribute.name === "manifest:full-path")?.value !== "/") return entry;
|
|
365
|
+
return {
|
|
366
|
+
...entry,
|
|
367
|
+
attributes: entry.attributes.map((attribute) => attribute.name === "manifest:media-type" ? {
|
|
368
|
+
name: attribute.name,
|
|
369
|
+
value: odfMediaType
|
|
370
|
+
} : attribute)
|
|
371
|
+
};
|
|
372
|
+
})
|
|
373
|
+
};
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function transformOoo1Package(pkg) {
|
|
377
|
+
if (!isOoo1Package(pkg)) return pkg;
|
|
378
|
+
const odfMediaType = odfMediaTypeOf(pkg);
|
|
379
|
+
const parts = {};
|
|
380
|
+
for (const [path, part] of Object.entries(pkg.parts)) {
|
|
381
|
+
if (part.kind !== "xml") {
|
|
382
|
+
parts[path] = part;
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
const nodes = transformXmlPart(part.nodes);
|
|
386
|
+
parts[path] = path === MANIFEST_PATH && odfMediaType !== void 0 ? {
|
|
387
|
+
kind: "xml",
|
|
388
|
+
nodes: rewriteManifestMediaType(nodes, odfMediaType)
|
|
389
|
+
} : {
|
|
390
|
+
kind: "xml",
|
|
391
|
+
nodes
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
if (odfMediaType !== void 0 && parts[MIMETYPE_PATH] === void 0) parts[MIMETYPE_PATH] = {
|
|
395
|
+
kind: "binary",
|
|
396
|
+
base64: bytesToBase64(new TextEncoder().encode(odfMediaType))
|
|
397
|
+
};
|
|
398
|
+
return { parts };
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
export { transformOoo1Package };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { r as Package } from "./package-otZYrxiO.js";
|
|
2
|
+
import { t as OdpDocument } from "./read-DUOJ-1hX.js";
|
|
3
|
+
import { i as OdtReadOptions, t as OdtDocument } from "./read-BcxAWBB5.js";
|
|
4
|
+
import { t as OdgDocument } from "./read-D3wLfr-7.js";
|
|
5
|
+
import { t as OdsDocument } from "./read-Bo1GBjSE.js";
|
|
6
|
+
import { DocumentTree } from "document-schema.js";
|
|
7
|
+
//#region src/ooo1/read.d.ts
|
|
8
|
+
declare function readSxwContent(pkg: Package, options?: OdtReadOptions): OdtDocument;
|
|
9
|
+
declare function readSxw(pkg: Package, options?: OdtReadOptions): DocumentTree;
|
|
10
|
+
declare function readSxcContent(pkg: Package): OdsDocument;
|
|
11
|
+
declare function readSxc(pkg: Package): DocumentTree;
|
|
12
|
+
declare function readSxiContent(pkg: Package): OdpDocument;
|
|
13
|
+
declare function readSxi(pkg: Package): DocumentTree;
|
|
14
|
+
declare function readSxdContent(pkg: Package): OdgDocument;
|
|
15
|
+
declare function readSxd(pkg: Package): DocumentTree;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { readSxi as a, readSxwContent as c, readSxdContent as i, readSxcContent as n, readSxiContent as o, readSxd as r, readSxw as s, readSxc as t };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { r as Package } from "./package-DMk9fuTI.cjs";
|
|
2
|
+
import { t as OdpDocument } from "./read-DHOQqjOZ.cjs";
|
|
3
|
+
import { i as OdtReadOptions, t as OdtDocument } from "./read-Dy5p1OMb.cjs";
|
|
4
|
+
import { t as OdgDocument } from "./read-DSyz0YLj.cjs";
|
|
5
|
+
import { t as OdsDocument } from "./read-tpfiT_n4.cjs";
|
|
6
|
+
import { DocumentTree } from "document-schema.js";
|
|
7
|
+
//#region src/ooo1/read.d.ts
|
|
8
|
+
declare function readSxwContent(pkg: Package, options?: OdtReadOptions): OdtDocument;
|
|
9
|
+
declare function readSxw(pkg: Package, options?: OdtReadOptions): DocumentTree;
|
|
10
|
+
declare function readSxcContent(pkg: Package): OdsDocument;
|
|
11
|
+
declare function readSxc(pkg: Package): DocumentTree;
|
|
12
|
+
declare function readSxiContent(pkg: Package): OdpDocument;
|
|
13
|
+
declare function readSxi(pkg: Package): DocumentTree;
|
|
14
|
+
declare function readSxdContent(pkg: Package): OdgDocument;
|
|
15
|
+
declare function readSxd(pkg: Package): DocumentTree;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { readSxi as a, readSxwContent as c, readSxdContent as i, readSxcContent as n, readSxiContent as o, readSxd as r, readSxw as s, readSxc as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "odf.js",
|
|
3
|
-
"version": "6.
|
|
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.",
|
|
3
|
+
"version": "6.2.0",
|
|
4
|
+
"description": "Type-safe, lossless round-trip conversion between OpenDocument Format packages (odt, ods, odp) and JSON, plus read support for the pre-OASIS OpenOffice.org 1.x documents ODF was based on (sxw, sxc, sxi, sxd), hand-written and dependency-minimal, built on Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -72,6 +72,12 @@
|
|
|
72
72
|
"odt",
|
|
73
73
|
"ods",
|
|
74
74
|
"odp",
|
|
75
|
+
"sxw",
|
|
76
|
+
"sxc",
|
|
77
|
+
"sxi",
|
|
78
|
+
"sxd",
|
|
79
|
+
"openoffice",
|
|
80
|
+
"staroffice",
|
|
75
81
|
"round-trip",
|
|
76
82
|
"zod",
|
|
77
83
|
"codec"
|
|
@@ -79,7 +85,7 @@
|
|
|
79
85
|
"license": "MIT",
|
|
80
86
|
"packageManager": "pnpm@11.6.0",
|
|
81
87
|
"dependencies": {
|
|
82
|
-
"document-schema.js": "^5.
|
|
88
|
+
"document-schema.js": "^5.4.0",
|
|
83
89
|
"fast-xml-parser": "^5.10.1",
|
|
84
90
|
"fflate": "^0.8.3",
|
|
85
91
|
"zod": "^4.4.3"
|