odf.js 6.2.1 → 6.4.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 +191 -17
- package/dist/{cascade-BDkyOmoo.d.cts → cascade-BpMwrjkB.d.cts} +1 -1
- package/dist/{cascade-CaVinmvp.d.ts → cascade-PDS3hgrP.d.ts} +1 -1
- package/dist/{codec-B72LApRl.d.cts → codec-CFdlbFLJ.d.cts} +21 -13
- package/dist/{codec-rbZGlr37.d.ts → codec-DTAgph2r.d.ts} +21 -13
- package/dist/codec.d.cts +1 -1
- package/dist/codec.d.ts +1 -1
- package/dist/{embedded-UQQNFd5U.js → embedded-BnavfkP-.js} +4 -5
- package/dist/{embedded-BsO-SvtW.cjs → embedded-Bxyss_ck.cjs} +15 -4
- package/dist/index.cjs +53 -1
- package/dist/index.d.cts +24 -16
- package/dist/index.d.ts +24 -16
- package/dist/index.js +19 -11
- package/dist/list-7FO0SDqZ.d.ts +32 -0
- package/dist/list-BorrTJBY.d.cts +32 -0
- package/dist/metadata-BUzwE_-u.d.ts +10 -0
- package/dist/metadata-CYXgXL_h.d.cts +10 -0
- package/dist/{ns-C14w-Zhf.d.cts → ns-DrleaIZQ.d.cts} +3 -1
- package/dist/{ns-CTyKJZeF.d.ts → ns-E0TfX9tZ.d.ts} +3 -1
- package/dist/ooo1/ns.cjs +9 -0
- package/dist/ooo1/ns.d.cts +2 -2
- package/dist/ooo1/ns.d.ts +2 -2
- package/dist/ooo1/ns.js +8 -1
- package/dist/ooo1/properties.cjs +30 -0
- package/dist/ooo1/properties.d.cts +6 -2
- package/dist/ooo1/properties.d.ts +6 -2
- package/dist/ooo1/properties.js +30 -1
- package/dist/ooo1/read.cjs +1 -1
- package/dist/ooo1/read.d.cts +1 -1
- package/dist/ooo1/read.d.ts +1 -1
- package/dist/ooo1/read.js +1 -1
- package/dist/ooo1/transform.cjs +290 -0
- package/dist/ooo1/transform.d.cts +2 -2
- package/dist/ooo1/transform.d.ts +2 -2
- package/dist/ooo1/transform.js +293 -4
- package/dist/ooo1/write.cjs +40 -0
- package/dist/ooo1/write.d.cts +2 -0
- package/dist/ooo1/write.d.ts +2 -0
- package/dist/ooo1/write.js +32 -0
- package/dist/package-io/scaffold.cjs +65 -0
- package/dist/package-io/scaffold.d.cts +2 -0
- package/dist/package-io/scaffold.d.ts +2 -0
- package/dist/package-io/scaffold.js +62 -0
- package/dist/paragraph-Bf6Iq5wC.d.cts +28 -0
- package/dist/paragraph-DtC86tft.d.ts +28 -0
- package/dist/{path-CK0dIPgx.d.cts → path-8HQS-J7y.d.cts} +3 -1
- package/dist/{path-CK0dIPgx.d.ts → path-8HQS-J7y.d.ts} +3 -1
- package/dist/{read-Bo1GBjSE.d.ts → read-A3CJkqVM.d.ts} +3 -1
- package/dist/{read-RFqq4ckj.d.cts → read-BgnLFuSi.d.cts} +1 -1
- package/dist/{read-3yy5EFV_.d.ts → read-CqaZ01kU.d.ts} +1 -1
- package/dist/{read-tpfiT_n4.d.cts → read-fphkvCpR.d.cts} +3 -1
- package/dist/{registry-Dajfxsbz.d.ts → registry-C_16-N6i.d.ts} +2 -0
- package/dist/{registry-B-ZkdQv1.d.cts → registry-PoQIRgbY.d.cts} +2 -0
- package/dist/scaffold-44EIMGll.d.cts +8 -0
- package/dist/scaffold-ehGsIpZ5.d.ts +8 -0
- package/dist/{shapes-QkOsc-WT.d.ts → shapes-B6Ms7ibr.d.ts} +1 -1
- package/dist/{shapes-BCjeY90t.d.cts → shapes-CbBc9t0y.d.cts} +1 -1
- package/dist/styles/properties.cjs +1 -1
- package/dist/styles/properties.js +2 -2
- package/dist/styles/registry.cjs +9 -6
- package/dist/styles/registry.d.cts +1 -1
- package/dist/styles/registry.d.ts +1 -1
- package/dist/styles/registry.js +9 -6
- package/dist/table-CECMtPxZ.d.cts +20 -0
- package/dist/table-XuniPr2I.d.ts +20 -0
- package/dist/text-B8350HA2.d.ts +17 -0
- package/dist/text-pmlTqzgi.d.cts +17 -0
- package/dist/{transform-SDysw9wx.d.cts → transform-DFCPKX7e.d.cts} +2 -1
- package/dist/{transform-DRr76JEu.d.ts → transform-DPliWQuD.d.ts} +2 -1
- package/dist/typed/draw/embedded.cjs +1 -1
- package/dist/typed/draw/embedded.js +1 -1
- package/dist/typed/draw/shapes.cjs +7 -2
- package/dist/typed/draw/shapes.d.cts +1 -1
- package/dist/typed/draw/shapes.d.ts +1 -1
- package/dist/typed/draw/shapes.js +7 -2
- package/dist/typed/draw/write-shapes.cjs +210 -0
- package/dist/typed/draw/write-shapes.d.cts +2 -0
- package/dist/typed/draw/write-shapes.d.ts +2 -0
- package/dist/typed/draw/write-shapes.js +203 -0
- package/dist/typed/draw/write-vectors.cjs +132 -0
- package/dist/typed/draw/write-vectors.d.cts +2 -0
- package/dist/typed/draw/write-vectors.d.ts +2 -0
- package/dist/typed/draw/write-vectors.js +129 -0
- package/dist/typed/odb/form.cjs +1 -1
- package/dist/typed/odb/form.js +1 -1
- package/dist/typed/odg/write.cjs +80 -0
- package/dist/typed/odg/write.d.cts +2 -0
- package/dist/typed/odg/write.d.ts +2 -0
- package/dist/typed/odg/write.js +77 -0
- package/dist/typed/odp/write.cjs +108 -0
- package/dist/typed/odp/write.d.cts +2 -0
- package/dist/typed/odp/write.d.ts +2 -0
- package/dist/typed/odp/write.js +105 -0
- package/dist/typed/ods/read.cjs +3 -1
- package/dist/typed/ods/read.d.cts +2 -2
- package/dist/typed/ods/read.d.ts +2 -2
- package/dist/typed/ods/read.js +2 -2
- package/dist/typed/ods/write.cjs +578 -0
- package/dist/typed/ods/write.d.cts +2 -0
- package/dist/typed/ods/write.d.ts +2 -0
- package/dist/typed/ods/write.js +575 -0
- package/dist/typed/odt/read.cjs +1 -1
- package/dist/typed/odt/read.js +1 -1
- package/dist/typed/odt/write.cjs +278 -0
- package/dist/typed/odt/write.d.cts +2 -0
- package/dist/typed/odt/write.d.ts +2 -0
- package/dist/typed/odt/write.js +275 -0
- package/dist/typed/shared/canonicalise.cjs +126 -0
- package/dist/typed/shared/canonicalise.d.cts +10 -0
- package/dist/typed/shared/canonicalise.d.ts +10 -0
- package/dist/typed/shared/canonicalise.js +120 -0
- package/dist/typed/shared/cascade.d.cts +1 -1
- package/dist/typed/shared/cascade.d.ts +1 -1
- package/dist/typed/shared/list.cjs +81 -0
- package/dist/typed/shared/list.d.cts +2 -2
- package/dist/typed/shared/list.d.ts +2 -2
- package/dist/typed/shared/list.js +75 -1
- package/dist/typed/shared/metadata.cjs +41 -0
- package/dist/typed/shared/metadata.d.cts +2 -2
- package/dist/typed/shared/metadata.d.ts +2 -2
- package/dist/typed/shared/metadata.js +41 -2
- package/dist/typed/shared/paragraph.cjs +118 -2
- package/dist/typed/shared/paragraph.d.cts +2 -2
- package/dist/typed/shared/paragraph.d.ts +2 -2
- package/dist/typed/shared/paragraph.js +117 -5
- package/dist/typed/shared/path.cjs +19 -0
- package/dist/typed/shared/path.d.cts +2 -2
- package/dist/typed/shared/path.d.ts +2 -2
- package/dist/typed/shared/path.js +18 -1
- package/dist/typed/shared/table.cjs +84 -0
- package/dist/typed/shared/table.d.cts +2 -2
- package/dist/typed/shared/table.d.ts +2 -2
- package/dist/typed/shared/table.js +84 -4
- package/dist/typed/shared/text.cjs +60 -0
- package/dist/typed/shared/text.d.cts +2 -2
- package/dist/typed/shared/text.d.ts +2 -2
- package/dist/typed/shared/text.js +60 -2
- package/dist/typed/shared/units.cjs +16 -1
- package/dist/typed/shared/units.d.cts +2 -2
- package/dist/typed/shared/units.d.ts +2 -2
- package/dist/typed/shared/units.js +16 -2
- package/dist/{units-BQSNkTQZ.d.cts → units-DdyaQolR.d.cts} +2 -1
- package/dist/{units-BQSNkTQZ.d.ts → units-DdyaQolR.d.ts} +2 -1
- package/dist/write-4kMi-asu.d.ts +14 -0
- package/dist/write-BZXpT8F6.d.cts +17 -0
- package/dist/write-BhG3t3fJ.d.cts +14 -0
- package/dist/write-BuLQmwLD.d.cts +14 -0
- package/dist/write-C2c4xBXs.d.cts +14 -0
- package/dist/write-CPATqG4v.d.cts +14 -0
- package/dist/write-CfTE2jY8.d.ts +14 -0
- package/dist/write-DttX1rTC.d.ts +14 -0
- package/dist/write-JERychL3.d.ts +14 -0
- package/dist/write-SKnCTU4C.d.ts +17 -0
- package/dist/write-shapes-Co7BrmMZ.d.ts +36 -0
- package/dist/write-shapes-D4piGKf4.d.cts +36 -0
- package/dist/write-vectors-B-RVHAKI.d.cts +11 -0
- package/dist/write-vectors-CYjZoVBW.d.ts +11 -0
- package/package.json +2 -2
- package/dist/list-DwTyo_B2.d.cts +0 -13
- package/dist/list-X_GJY7P3.d.ts +0 -13
- package/dist/metadata-01SgHkRR.d.cts +0 -7
- package/dist/metadata-D1SOBTh8.d.ts +0 -7
- package/dist/paragraph-ByTzS8Li.d.ts +0 -18
- package/dist/paragraph-CVULactG.d.cts +0 -18
- package/dist/table-CYvFMlP6.d.cts +0 -14
- package/dist/table-DclDgC5h.d.ts +0 -14
- package/dist/text-Bn3C7lnm.d.ts +0 -10
- package/dist/text-CDUCcwje.d.cts +0 -10
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { el } from "../../xml/fragment.js";
|
|
2
|
+
import { decodeXmlText, encodeXmlText } from "../../xml/entities.js";
|
|
2
3
|
import { parseParagraphProperties, parseTextProperties } from "../../styles/properties.js";
|
|
4
|
+
import { canonicalPropertiesString } from "../../styles/serialize.js";
|
|
3
5
|
import { attrValue, childrenWithTag, findChildElement } from "../../xml/query.js";
|
|
4
|
-
import { decodeOdfText, getOdfSpaceCount, isOdfFieldElement } from "./text.js";
|
|
6
|
+
import { buildOdfInlineNodes, decodeOdfText, getOdfSpaceCount, isOdfFieldElement, segmentOdfText } from "./text.js";
|
|
5
7
|
import { resolveStyle, resolveStyleElementChain } from "./cascade.js";
|
|
6
8
|
import { mintOdfListNumId, readOdfListParagraphs } from "./list.js";
|
|
7
9
|
import { isOdfBlockScopedHalf, isOdfExtensionElement, odfAttributeElement, odfBookmarkAnchorDescriptor, odfFieldDescriptor, odfResidue, pairOdfMarkerHalves } from "./constructs.js";
|
|
@@ -41,8 +43,10 @@ function collectRuns(container, baseProperties, pkg, out, walk, hyperlinkTarget)
|
|
|
41
43
|
...baseProperties,
|
|
42
44
|
...resolveStyle(styleName, "text", pkg).properties
|
|
43
45
|
}, pkg, out, walk, hyperlinkTarget);
|
|
44
|
-
} else if (node.tag === "text:a")
|
|
45
|
-
|
|
46
|
+
} else if (node.tag === "text:a") {
|
|
47
|
+
const rawHref = attrValue(node, "xlink:href");
|
|
48
|
+
collectRuns(node, baseProperties, pkg, out, walk, (rawHref === void 0 ? void 0 : decodeXmlText(rawHref)) ?? hyperlinkTarget);
|
|
49
|
+
} else if (isOdfFieldElement(node)) {
|
|
46
50
|
const startRun = out.length;
|
|
47
51
|
collectRuns(node, baseProperties, pkg, out, walk, hyperlinkTarget);
|
|
48
52
|
walk.extents.push({
|
|
@@ -276,5 +280,113 @@ function readParagraphOrHeading(element, paragraph) {
|
|
|
276
280
|
}
|
|
277
281
|
return paragraph;
|
|
278
282
|
}
|
|
283
|
+
function odfRunProperties(run) {
|
|
284
|
+
const properties = {};
|
|
285
|
+
if (run.bold !== void 0) properties.bold = run.bold;
|
|
286
|
+
if (run.italic !== void 0) properties.italic = run.italic;
|
|
287
|
+
if (run.underline !== void 0) properties.underline = run.underline;
|
|
288
|
+
if (run.strike !== void 0) properties.strike = run.strike;
|
|
289
|
+
if (run.fontFamily !== void 0) properties.fontFamily = run.fontFamily;
|
|
290
|
+
if (run.sizePt !== void 0) properties.sizePt = run.sizePt;
|
|
291
|
+
if (run.color !== void 0) properties.color = run.color;
|
|
292
|
+
return properties;
|
|
293
|
+
}
|
|
294
|
+
function odfParagraphProperties(paragraph) {
|
|
295
|
+
const properties = {};
|
|
296
|
+
if (paragraph.alignment !== void 0) properties.alignment = paragraph.alignment;
|
|
297
|
+
if (paragraph.spacingBeforePt !== void 0) properties.spacingBeforePt = paragraph.spacingBeforePt;
|
|
298
|
+
if (paragraph.spacingAfterPt !== void 0) properties.spacingAfterPt = paragraph.spacingAfterPt;
|
|
299
|
+
if (paragraph.lineSpacing !== void 0) properties.lineSpacing = paragraph.lineSpacing;
|
|
300
|
+
if (paragraph.indentLeftPt !== void 0) properties.indentLeftPt = paragraph.indentLeftPt;
|
|
301
|
+
if (paragraph.indentFirstLinePt !== void 0) properties.indentFirstLinePt = paragraph.indentFirstLinePt;
|
|
302
|
+
if (paragraph.pageBreakBefore !== void 0) properties.pageBreakBefore = paragraph.pageBreakBefore;
|
|
303
|
+
if (paragraph.pageBreakAfter !== void 0) properties.pageBreakAfter = paragraph.pageBreakAfter;
|
|
304
|
+
return properties;
|
|
305
|
+
}
|
|
306
|
+
const KEY_SEPARATOR = "\0";
|
|
307
|
+
function runFormattingKey(run) {
|
|
308
|
+
const hyperlink = run.hyperlink === void 0 ? "" : `link${KEY_SEPARATOR}${run.hyperlink}`;
|
|
309
|
+
return `${canonicalPropertiesString(odfRunProperties(run))}${KEY_SEPARATOR}${hyperlink}`;
|
|
310
|
+
}
|
|
311
|
+
function segmentOdfParagraphRuns(runs) {
|
|
312
|
+
const merged = [];
|
|
313
|
+
for (const run of runs) {
|
|
314
|
+
if (run.text.length === 0) continue;
|
|
315
|
+
const previous = merged[merged.length - 1];
|
|
316
|
+
if (previous !== void 0 && runFormattingKey(previous) === runFormattingKey(run)) {
|
|
317
|
+
merged[merged.length - 1] = {
|
|
318
|
+
...previous,
|
|
319
|
+
text: previous.text + run.text
|
|
320
|
+
};
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
merged.push(run);
|
|
324
|
+
}
|
|
325
|
+
const canonical = [];
|
|
326
|
+
for (const [index, run] of merged.entries()) {
|
|
327
|
+
const previousText = merged[index - 1]?.text;
|
|
328
|
+
const nextText = merged[index + 1]?.text;
|
|
329
|
+
const protectLeading = previousText === void 0 || previousText.endsWith(" ");
|
|
330
|
+
const protectTrailing = nextText === void 0 || nextText.startsWith(" ");
|
|
331
|
+
for (const segment of segmentOdfText(run.text, protectLeading, protectTrailing)) canonical.push({
|
|
332
|
+
...run,
|
|
333
|
+
text: segment.text
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
return canonical;
|
|
337
|
+
}
|
|
338
|
+
function writeOdfFormattedRunNodes(canonical, from, to, registry) {
|
|
339
|
+
const nodes = [];
|
|
340
|
+
let index = from;
|
|
341
|
+
while (index < to) {
|
|
342
|
+
const properties = odfRunProperties(canonical[index]);
|
|
343
|
+
const key = canonicalPropertiesString(properties);
|
|
344
|
+
let end = index + 1;
|
|
345
|
+
while (end < to && canonicalPropertiesString(odfRunProperties(canonical[end])) === key) end += 1;
|
|
346
|
+
const inner = [];
|
|
347
|
+
for (let position = index; position < end; position += 1) {
|
|
348
|
+
const previousText = canonical[position - 1]?.text;
|
|
349
|
+
const nextText = canonical[position + 1]?.text;
|
|
350
|
+
inner.push(...buildOdfInlineNodes(segmentOdfText(canonical[position].text, previousText === void 0 || previousText.endsWith(" "), nextText === void 0 || nextText.startsWith(" "))));
|
|
351
|
+
}
|
|
352
|
+
if (Object.keys(properties).length === 0) nodes.push(...inner);
|
|
353
|
+
else nodes.push(el("text:span", { "text:style-name": encodeXmlText(registry.intern({
|
|
354
|
+
properties,
|
|
355
|
+
family: "text"
|
|
356
|
+
})) }, inner));
|
|
357
|
+
index = end;
|
|
358
|
+
}
|
|
359
|
+
return nodes;
|
|
360
|
+
}
|
|
361
|
+
function writeOdfParagraphChildren(runs, registry) {
|
|
362
|
+
const canonical = segmentOdfParagraphRuns(runs);
|
|
363
|
+
const children = [];
|
|
364
|
+
let index = 0;
|
|
365
|
+
while (index < canonical.length) {
|
|
366
|
+
const target = canonical[index].hyperlink;
|
|
367
|
+
let end = index + 1;
|
|
368
|
+
while (end < canonical.length && canonical[end].hyperlink === target) end += 1;
|
|
369
|
+
const nodes = writeOdfFormattedRunNodes(canonical, index, end, registry);
|
|
370
|
+
if (target === void 0) children.push(...nodes);
|
|
371
|
+
else children.push(el("text:a", {
|
|
372
|
+
"xlink:type": "simple",
|
|
373
|
+
"xlink:href": encodeXmlText(target)
|
|
374
|
+
}, nodes));
|
|
375
|
+
index = end;
|
|
376
|
+
}
|
|
377
|
+
return children;
|
|
378
|
+
}
|
|
379
|
+
function writeOdfParagraph(paragraph, registry, options = {}) {
|
|
380
|
+
const properties = odfParagraphProperties(paragraph);
|
|
381
|
+
const attributes = {};
|
|
382
|
+
if (Object.keys(properties).length > 0) attributes["text:style-name"] = encodeXmlText(registry.intern({
|
|
383
|
+
properties,
|
|
384
|
+
family: "paragraph",
|
|
385
|
+
...options.parentStyleName === void 0 ? {} : { parentStyleName: options.parentStyleName }
|
|
386
|
+
}));
|
|
387
|
+
else if (options.parentStyleName !== void 0) attributes["text:style-name"] = encodeXmlText(options.parentStyleName);
|
|
388
|
+
if (paragraph.headingLevel !== void 0) attributes["text:outline-level"] = String(paragraph.headingLevel);
|
|
389
|
+
return el(paragraph.headingLevel === void 0 ? "text:p" : "text:h", attributes, [...writeOdfParagraphChildren(paragraph.runs, registry), ...options.trailingNodes ?? []]);
|
|
390
|
+
}
|
|
279
391
|
//#endregion
|
|
280
|
-
export { readOdfConstructBodyBlocks, readOdfParagraph, readParagraphOrHeading };
|
|
392
|
+
export { odfParagraphProperties, odfRunProperties, readOdfConstructBodyBlocks, readOdfParagraph, readParagraphOrHeading, segmentOdfParagraphRuns, writeOdfParagraph };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_typed_shared_units = require("./units.cjs");
|
|
2
3
|
//#region src/typed/shared/path.ts
|
|
3
4
|
const VIEW_BOX_PATTERN = /^(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)$/;
|
|
4
5
|
function parseOdfViewBox(value) {
|
|
@@ -252,8 +253,26 @@ function buildOdfSubpaths(rawSubpaths, viewBox, frame) {
|
|
|
252
253
|
})
|
|
253
254
|
}));
|
|
254
255
|
}
|
|
256
|
+
function formatOdfViewBox(frame) {
|
|
257
|
+
return `0 0 ${require_typed_shared_units.formatOdfNumber(frame.widthPt)} ${require_typed_shared_units.formatOdfNumber(frame.heightPt)}`;
|
|
258
|
+
}
|
|
259
|
+
function formatPoint(point) {
|
|
260
|
+
return `${require_typed_shared_units.formatOdfNumber(point.xPt)},${require_typed_shared_units.formatOdfNumber(point.yPt)}`;
|
|
261
|
+
}
|
|
262
|
+
function formatOdfPathData(subpaths) {
|
|
263
|
+
const parts = [];
|
|
264
|
+
for (const subpath of subpaths) {
|
|
265
|
+
parts.push(`M ${formatPoint(subpath.start)}`);
|
|
266
|
+
for (const segment of subpath.segments) if (segment.kind === "line") parts.push(`L ${formatPoint(segment.to)}`);
|
|
267
|
+
else parts.push(`C ${formatPoint(segment.control1)} ${formatPoint(segment.control2)} ${formatPoint(segment.to)}`);
|
|
268
|
+
if (subpath.closed) parts.push("Z");
|
|
269
|
+
}
|
|
270
|
+
return parts.join(" ");
|
|
271
|
+
}
|
|
255
272
|
//#endregion
|
|
256
273
|
exports.buildOdfSubpaths = buildOdfSubpaths;
|
|
274
|
+
exports.formatOdfPathData = formatOdfPathData;
|
|
275
|
+
exports.formatOdfViewBox = formatOdfViewBox;
|
|
257
276
|
exports.parseOdfPathData = parseOdfPathData;
|
|
258
277
|
exports.parseOdfPointsList = parseOdfPointsList;
|
|
259
278
|
exports.parseOdfViewBox = parseOdfViewBox;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as buildOdfSubpaths, c as
|
|
2
|
-
export { OdfRawPoint, OdfRawSegment, OdfRawSubpath, OdfViewBox, buildOdfSubpaths, parseOdfPathData, parseOdfPointsList, parseOdfViewBox, rawSubpathFromPoints, scaleOdfRawPoint };
|
|
1
|
+
import { a as buildOdfSubpaths, c as parseOdfPathData, d as rawSubpathFromPoints, f as scaleOdfRawPoint, i as OdfViewBox, l as parseOdfPointsList, n as OdfRawSegment, o as formatOdfPathData, r as OdfRawSubpath, s as formatOdfViewBox, t as OdfRawPoint, u as parseOdfViewBox } from "../../path-8HQS-J7y.cjs";
|
|
2
|
+
export { OdfRawPoint, OdfRawSegment, OdfRawSubpath, OdfViewBox, buildOdfSubpaths, formatOdfPathData, formatOdfViewBox, parseOdfPathData, parseOdfPointsList, parseOdfViewBox, rawSubpathFromPoints, scaleOdfRawPoint };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as buildOdfSubpaths, c as
|
|
2
|
-
export { OdfRawPoint, OdfRawSegment, OdfRawSubpath, OdfViewBox, buildOdfSubpaths, parseOdfPathData, parseOdfPointsList, parseOdfViewBox, rawSubpathFromPoints, scaleOdfRawPoint };
|
|
1
|
+
import { a as buildOdfSubpaths, c as parseOdfPathData, d as rawSubpathFromPoints, f as scaleOdfRawPoint, i as OdfViewBox, l as parseOdfPointsList, n as OdfRawSegment, o as formatOdfPathData, r as OdfRawSubpath, s as formatOdfViewBox, t as OdfRawPoint, u as parseOdfViewBox } from "../../path-8HQS-J7y.js";
|
|
2
|
+
export { OdfRawPoint, OdfRawSegment, OdfRawSubpath, OdfViewBox, buildOdfSubpaths, formatOdfPathData, formatOdfViewBox, parseOdfPathData, parseOdfPointsList, parseOdfViewBox, rawSubpathFromPoints, scaleOdfRawPoint };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatOdfNumber } from "./units.js";
|
|
1
2
|
//#region src/typed/shared/path.ts
|
|
2
3
|
const VIEW_BOX_PATTERN = /^(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)$/;
|
|
3
4
|
function parseOdfViewBox(value) {
|
|
@@ -251,5 +252,21 @@ function buildOdfSubpaths(rawSubpaths, viewBox, frame) {
|
|
|
251
252
|
})
|
|
252
253
|
}));
|
|
253
254
|
}
|
|
255
|
+
function formatOdfViewBox(frame) {
|
|
256
|
+
return `0 0 ${formatOdfNumber(frame.widthPt)} ${formatOdfNumber(frame.heightPt)}`;
|
|
257
|
+
}
|
|
258
|
+
function formatPoint(point) {
|
|
259
|
+
return `${formatOdfNumber(point.xPt)},${formatOdfNumber(point.yPt)}`;
|
|
260
|
+
}
|
|
261
|
+
function formatOdfPathData(subpaths) {
|
|
262
|
+
const parts = [];
|
|
263
|
+
for (const subpath of subpaths) {
|
|
264
|
+
parts.push(`M ${formatPoint(subpath.start)}`);
|
|
265
|
+
for (const segment of subpath.segments) if (segment.kind === "line") parts.push(`L ${formatPoint(segment.to)}`);
|
|
266
|
+
else parts.push(`C ${formatPoint(segment.control1)} ${formatPoint(segment.control2)} ${formatPoint(segment.to)}`);
|
|
267
|
+
if (subpath.closed) parts.push("Z");
|
|
268
|
+
}
|
|
269
|
+
return parts.join(" ");
|
|
270
|
+
}
|
|
254
271
|
//#endregion
|
|
255
|
-
export { buildOdfSubpaths, parseOdfPathData, parseOdfPointsList, parseOdfViewBox, rawSubpathFromPoints, scaleOdfRawPoint };
|
|
272
|
+
export { buildOdfSubpaths, formatOdfPathData, formatOdfViewBox, parseOdfPathData, parseOdfPointsList, parseOdfViewBox, rawSubpathFromPoints, scaleOdfRawPoint };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_fragment = require("../../xml/fragment.cjs");
|
|
3
|
+
const require_xml_entities = require("../../xml/entities.cjs");
|
|
2
4
|
const require_typed_shared_units = require("./units.cjs");
|
|
3
5
|
const require_typed_shared_color = require("./color.cjs");
|
|
4
6
|
const require_xml_query = require("../../xml/query.cjs");
|
|
@@ -152,6 +154,84 @@ function readTableRow(rowElement, pkg) {
|
|
|
152
154
|
heightPt: resolveRowHeightPt(rowElement, pkg)
|
|
153
155
|
};
|
|
154
156
|
}
|
|
157
|
+
function tableColumnStyle(widthPt, registry) {
|
|
158
|
+
if (widthPt <= 0) return;
|
|
159
|
+
return registry.intern({
|
|
160
|
+
properties: {},
|
|
161
|
+
family: "table-column",
|
|
162
|
+
propertyElements: [require_xml_fragment.el("style:table-column-properties", { "style:column-width": require_typed_shared_units.formatOdfLength(widthPt) })]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function tableRowStyle(heightPt, registry) {
|
|
166
|
+
if (heightPt === void 0) return;
|
|
167
|
+
return registry.intern({
|
|
168
|
+
properties: {},
|
|
169
|
+
family: "table-row",
|
|
170
|
+
propertyElements: [require_xml_fragment.el("style:table-row-properties", { "style:row-height": require_typed_shared_units.formatOdfLength(heightPt) })]
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function formatBorderEdge(border) {
|
|
174
|
+
return `${require_typed_shared_units.formatOdfLength(border.widthPt)} ${border.style ?? "solid"} ${require_typed_shared_color.formatOdfColor(border.color)}`;
|
|
175
|
+
}
|
|
176
|
+
function tableCellStyle(cell, registry) {
|
|
177
|
+
const attributes = {};
|
|
178
|
+
if (cell.background !== void 0) attributes["fo:background-color"] = require_typed_shared_color.formatOdfColor(cell.background);
|
|
179
|
+
const borders = cell.borders;
|
|
180
|
+
if (borders !== void 0) for (const edge of BORDER_EDGE_KEYS) {
|
|
181
|
+
const border = borders[edge];
|
|
182
|
+
if (border !== void 0) attributes[BORDER_EDGE_ATTRS[edge]] = formatBorderEdge(border);
|
|
183
|
+
}
|
|
184
|
+
if (Object.keys(attributes).length === 0) return;
|
|
185
|
+
return registry.intern({
|
|
186
|
+
properties: {},
|
|
187
|
+
family: "table-cell",
|
|
188
|
+
propertyElements: [require_xml_fragment.el("style:table-cell-properties", attributes)]
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function writeCellBlocks(cell, registry) {
|
|
192
|
+
return cell.blocks.map((block) => {
|
|
193
|
+
if (block.kind !== "paragraph") throw new Error(`writeOdfTable: a table cell carrying a "${block.kind}" block cannot be written -- odf.js's table reader reads only paragraphs and headings out of a cell, so writing one would lose it on the way back in`);
|
|
194
|
+
return require_typed_shared_paragraph.writeOdfParagraph(block, registry);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function coverageKey(row, column) {
|
|
198
|
+
return `${row},${column}`;
|
|
199
|
+
}
|
|
200
|
+
function writeOdfTable(table, registry, tableName) {
|
|
201
|
+
const columns = table.columnWidthsPt.map((widthPt) => {
|
|
202
|
+
const styleName = tableColumnStyle(widthPt, registry);
|
|
203
|
+
return require_xml_fragment.el("table:table-column", styleName === void 0 ? {} : { "table:style-name": require_xml_entities.encodeXmlText(styleName) });
|
|
204
|
+
});
|
|
205
|
+
const covered = /* @__PURE__ */ new Set();
|
|
206
|
+
const rows = table.rows.map((row, rowIndex) => {
|
|
207
|
+
const cells = row.cells.map((cell, columnIndex) => {
|
|
208
|
+
if (covered.has(coverageKey(rowIndex, columnIndex))) return require_xml_fragment.el("table:covered-table-cell");
|
|
209
|
+
const colSpan = cell.colSpan ?? 1;
|
|
210
|
+
const rowSpan = cell.rowSpan ?? 1;
|
|
211
|
+
for (let r = rowIndex; r < rowIndex + rowSpan; r += 1) for (let c = columnIndex; c < columnIndex + colSpan; c += 1) if (r !== rowIndex || c !== columnIndex) covered.add(coverageKey(r, c));
|
|
212
|
+
const attributes = {};
|
|
213
|
+
const styleName = tableCellStyle(cell, registry);
|
|
214
|
+
if (styleName !== void 0) attributes["table:style-name"] = require_xml_entities.encodeXmlText(styleName);
|
|
215
|
+
if (cell.colSpan !== void 0) attributes["table:number-columns-spanned"] = String(cell.colSpan);
|
|
216
|
+
if (cell.rowSpan !== void 0) attributes["table:number-rows-spanned"] = String(cell.rowSpan);
|
|
217
|
+
return require_xml_fragment.el("table:table-cell", attributes, writeCellBlocks(cell, registry));
|
|
218
|
+
});
|
|
219
|
+
const rowStyleName = tableRowStyle(row.heightPt, registry);
|
|
220
|
+
return require_xml_fragment.el("table:table-row", rowStyleName === void 0 ? {} : { "table:style-name": require_xml_entities.encodeXmlText(rowStyleName) }, cells);
|
|
221
|
+
});
|
|
222
|
+
const totalWidthPt = table.columnWidthsPt.reduce((total, widthPt) => total + widthPt, 0);
|
|
223
|
+
const tableProperties = { "table:align": "margins" };
|
|
224
|
+
if (totalWidthPt > 0) tableProperties["style:width"] = require_typed_shared_units.formatOdfLength(totalWidthPt);
|
|
225
|
+
const tableStyleName = registry.intern({
|
|
226
|
+
properties: {},
|
|
227
|
+
family: "table",
|
|
228
|
+
propertyElements: [require_xml_fragment.el("style:table-properties", tableProperties)]
|
|
229
|
+
});
|
|
230
|
+
return require_xml_fragment.el("table:table", {
|
|
231
|
+
"table:name": require_xml_entities.encodeXmlText(tableName),
|
|
232
|
+
"table:style-name": require_xml_entities.encodeXmlText(tableStyleName)
|
|
233
|
+
}, [...columns, ...rows]);
|
|
234
|
+
}
|
|
155
235
|
function readOdfTable(tableElement, pkg) {
|
|
156
236
|
const columnWidthsPt = [];
|
|
157
237
|
for (const column of require_xml_query.childrenWithTag(tableElement, "table:table-column")) {
|
|
@@ -172,5 +252,9 @@ function readOdfTable(tableElement, pkg) {
|
|
|
172
252
|
};
|
|
173
253
|
}
|
|
174
254
|
//#endregion
|
|
255
|
+
exports.BORDER_EDGE_ATTRS = BORDER_EDGE_ATTRS;
|
|
256
|
+
exports.BORDER_EDGE_KEYS = BORDER_EDGE_KEYS;
|
|
257
|
+
exports.formatBorderEdge = formatBorderEdge;
|
|
175
258
|
exports.readCellStyleDecoration = readCellStyleDecoration;
|
|
176
259
|
exports.readOdfTable = readOdfTable;
|
|
260
|
+
exports.writeOdfTable = writeOdfTable;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as readCellStyleDecoration, r as readOdfTable, t as
|
|
2
|
-
export { CellStyleDecoration, readCellStyleDecoration, readOdfTable };
|
|
1
|
+
import { a as formatBorderEdge, c as writeOdfTable, i as CellStyleDecoration, n as BORDER_EDGE_KEYS, o as readCellStyleDecoration, r as BorderEdgeKey, s as readOdfTable, t as BORDER_EDGE_ATTRS } from "../../table-CECMtPxZ.cjs";
|
|
2
|
+
export { BORDER_EDGE_ATTRS, BORDER_EDGE_KEYS, BorderEdgeKey, CellStyleDecoration, formatBorderEdge, readCellStyleDecoration, readOdfTable, writeOdfTable };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as readCellStyleDecoration, r as readOdfTable, t as
|
|
2
|
-
export { CellStyleDecoration, readCellStyleDecoration, readOdfTable };
|
|
1
|
+
import { a as formatBorderEdge, c as writeOdfTable, i as CellStyleDecoration, n as BORDER_EDGE_KEYS, o as readCellStyleDecoration, r as BorderEdgeKey, s as readOdfTable, t as BORDER_EDGE_ATTRS } from "../../table-XuniPr2I.js";
|
|
2
|
+
export { BORDER_EDGE_ATTRS, BORDER_EDGE_KEYS, BorderEdgeKey, CellStyleDecoration, formatBorderEdge, readCellStyleDecoration, readOdfTable, writeOdfTable };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { el } from "../../xml/fragment.js";
|
|
2
|
+
import { encodeXmlText } from "../../xml/entities.js";
|
|
3
|
+
import { formatOdfLength, parseOdfLength } from "./units.js";
|
|
4
|
+
import { formatOdfColor, parseOdfColor } from "./color.js";
|
|
3
5
|
import { attrValue, childrenWithTag } from "../../xml/query.js";
|
|
4
6
|
import { findStyleElement } from "./cascade.js";
|
|
5
|
-
import { readOdfParagraph, readParagraphOrHeading } from "./paragraph.js";
|
|
7
|
+
import { readOdfParagraph, readParagraphOrHeading, writeOdfParagraph } from "./paragraph.js";
|
|
6
8
|
//#region src/typed/shared/table.ts
|
|
7
9
|
function readRepeatCount(element, attrName) {
|
|
8
10
|
const raw = attrValue(element, attrName);
|
|
@@ -151,6 +153,84 @@ function readTableRow(rowElement, pkg) {
|
|
|
151
153
|
heightPt: resolveRowHeightPt(rowElement, pkg)
|
|
152
154
|
};
|
|
153
155
|
}
|
|
156
|
+
function tableColumnStyle(widthPt, registry) {
|
|
157
|
+
if (widthPt <= 0) return;
|
|
158
|
+
return registry.intern({
|
|
159
|
+
properties: {},
|
|
160
|
+
family: "table-column",
|
|
161
|
+
propertyElements: [el("style:table-column-properties", { "style:column-width": formatOdfLength(widthPt) })]
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function tableRowStyle(heightPt, registry) {
|
|
165
|
+
if (heightPt === void 0) return;
|
|
166
|
+
return registry.intern({
|
|
167
|
+
properties: {},
|
|
168
|
+
family: "table-row",
|
|
169
|
+
propertyElements: [el("style:table-row-properties", { "style:row-height": formatOdfLength(heightPt) })]
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function formatBorderEdge(border) {
|
|
173
|
+
return `${formatOdfLength(border.widthPt)} ${border.style ?? "solid"} ${formatOdfColor(border.color)}`;
|
|
174
|
+
}
|
|
175
|
+
function tableCellStyle(cell, registry) {
|
|
176
|
+
const attributes = {};
|
|
177
|
+
if (cell.background !== void 0) attributes["fo:background-color"] = formatOdfColor(cell.background);
|
|
178
|
+
const borders = cell.borders;
|
|
179
|
+
if (borders !== void 0) for (const edge of BORDER_EDGE_KEYS) {
|
|
180
|
+
const border = borders[edge];
|
|
181
|
+
if (border !== void 0) attributes[BORDER_EDGE_ATTRS[edge]] = formatBorderEdge(border);
|
|
182
|
+
}
|
|
183
|
+
if (Object.keys(attributes).length === 0) return;
|
|
184
|
+
return registry.intern({
|
|
185
|
+
properties: {},
|
|
186
|
+
family: "table-cell",
|
|
187
|
+
propertyElements: [el("style:table-cell-properties", attributes)]
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function writeCellBlocks(cell, registry) {
|
|
191
|
+
return cell.blocks.map((block) => {
|
|
192
|
+
if (block.kind !== "paragraph") throw new Error(`writeOdfTable: a table cell carrying a "${block.kind}" block cannot be written -- odf.js's table reader reads only paragraphs and headings out of a cell, so writing one would lose it on the way back in`);
|
|
193
|
+
return writeOdfParagraph(block, registry);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function coverageKey(row, column) {
|
|
197
|
+
return `${row},${column}`;
|
|
198
|
+
}
|
|
199
|
+
function writeOdfTable(table, registry, tableName) {
|
|
200
|
+
const columns = table.columnWidthsPt.map((widthPt) => {
|
|
201
|
+
const styleName = tableColumnStyle(widthPt, registry);
|
|
202
|
+
return el("table:table-column", styleName === void 0 ? {} : { "table:style-name": encodeXmlText(styleName) });
|
|
203
|
+
});
|
|
204
|
+
const covered = /* @__PURE__ */ new Set();
|
|
205
|
+
const rows = table.rows.map((row, rowIndex) => {
|
|
206
|
+
const cells = row.cells.map((cell, columnIndex) => {
|
|
207
|
+
if (covered.has(coverageKey(rowIndex, columnIndex))) return el("table:covered-table-cell");
|
|
208
|
+
const colSpan = cell.colSpan ?? 1;
|
|
209
|
+
const rowSpan = cell.rowSpan ?? 1;
|
|
210
|
+
for (let r = rowIndex; r < rowIndex + rowSpan; r += 1) for (let c = columnIndex; c < columnIndex + colSpan; c += 1) if (r !== rowIndex || c !== columnIndex) covered.add(coverageKey(r, c));
|
|
211
|
+
const attributes = {};
|
|
212
|
+
const styleName = tableCellStyle(cell, registry);
|
|
213
|
+
if (styleName !== void 0) attributes["table:style-name"] = encodeXmlText(styleName);
|
|
214
|
+
if (cell.colSpan !== void 0) attributes["table:number-columns-spanned"] = String(cell.colSpan);
|
|
215
|
+
if (cell.rowSpan !== void 0) attributes["table:number-rows-spanned"] = String(cell.rowSpan);
|
|
216
|
+
return el("table:table-cell", attributes, writeCellBlocks(cell, registry));
|
|
217
|
+
});
|
|
218
|
+
const rowStyleName = tableRowStyle(row.heightPt, registry);
|
|
219
|
+
return el("table:table-row", rowStyleName === void 0 ? {} : { "table:style-name": encodeXmlText(rowStyleName) }, cells);
|
|
220
|
+
});
|
|
221
|
+
const totalWidthPt = table.columnWidthsPt.reduce((total, widthPt) => total + widthPt, 0);
|
|
222
|
+
const tableProperties = { "table:align": "margins" };
|
|
223
|
+
if (totalWidthPt > 0) tableProperties["style:width"] = formatOdfLength(totalWidthPt);
|
|
224
|
+
const tableStyleName = registry.intern({
|
|
225
|
+
properties: {},
|
|
226
|
+
family: "table",
|
|
227
|
+
propertyElements: [el("style:table-properties", tableProperties)]
|
|
228
|
+
});
|
|
229
|
+
return el("table:table", {
|
|
230
|
+
"table:name": encodeXmlText(tableName),
|
|
231
|
+
"table:style-name": encodeXmlText(tableStyleName)
|
|
232
|
+
}, [...columns, ...rows]);
|
|
233
|
+
}
|
|
154
234
|
function readOdfTable(tableElement, pkg) {
|
|
155
235
|
const columnWidthsPt = [];
|
|
156
236
|
for (const column of childrenWithTag(tableElement, "table:table-column")) {
|
|
@@ -171,4 +251,4 @@ function readOdfTable(tableElement, pkg) {
|
|
|
171
251
|
};
|
|
172
252
|
}
|
|
173
253
|
//#endregion
|
|
174
|
-
export { readCellStyleDecoration, readOdfTable };
|
|
254
|
+
export { BORDER_EDGE_ATTRS, BORDER_EDGE_KEYS, formatBorderEdge, readCellStyleDecoration, readOdfTable, writeOdfTable };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_fragment = require("../../xml/fragment.cjs");
|
|
2
3
|
const require_xml_entities = require("../../xml/entities.cjs");
|
|
3
4
|
const require_xml_query = require("../../xml/query.cjs");
|
|
4
5
|
//#region src/typed/shared/text.ts
|
|
@@ -92,10 +93,69 @@ function decodeOdfText(container) {
|
|
|
92
93
|
for (const child of container.children) text += decodeOdfNode(child);
|
|
93
94
|
return text;
|
|
94
95
|
}
|
|
96
|
+
const SPACE = " ";
|
|
97
|
+
const TAB = " ";
|
|
98
|
+
const LINE_BREAK = "\n";
|
|
99
|
+
function segmentOdfText(text, protectLeading, protectTrailing) {
|
|
100
|
+
const segments = [];
|
|
101
|
+
let plain = "";
|
|
102
|
+
const flushPlain = () => {
|
|
103
|
+
if (plain.length > 0) {
|
|
104
|
+
segments.push({
|
|
105
|
+
kind: "text",
|
|
106
|
+
text: plain
|
|
107
|
+
});
|
|
108
|
+
plain = "";
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
let index = 0;
|
|
112
|
+
while (index < text.length) {
|
|
113
|
+
const character = text[index];
|
|
114
|
+
if (character === TAB || character === LINE_BREAK) {
|
|
115
|
+
flushPlain();
|
|
116
|
+
segments.push({
|
|
117
|
+
kind: character === TAB ? "tab" : "lineBreak",
|
|
118
|
+
text: character
|
|
119
|
+
});
|
|
120
|
+
index += 1;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (character !== SPACE) {
|
|
124
|
+
plain += character;
|
|
125
|
+
index += 1;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
let end = index;
|
|
129
|
+
while (end < text.length && text[end] === SPACE) end += 1;
|
|
130
|
+
const spaces = text.slice(index, end);
|
|
131
|
+
if (spaces.length > 1 || index === 0 && protectLeading || end === text.length && protectTrailing) {
|
|
132
|
+
flushPlain();
|
|
133
|
+
segments.push({
|
|
134
|
+
kind: "space",
|
|
135
|
+
text: spaces
|
|
136
|
+
});
|
|
137
|
+
} else plain += spaces;
|
|
138
|
+
index = end;
|
|
139
|
+
}
|
|
140
|
+
flushPlain();
|
|
141
|
+
return segments;
|
|
142
|
+
}
|
|
143
|
+
function buildOdfInlineNodes(segments) {
|
|
144
|
+
return segments.map((segment) => {
|
|
145
|
+
switch (segment.kind) {
|
|
146
|
+
case "text": return require_xml_fragment.txt(require_xml_entities.encodeXmlText(segment.text));
|
|
147
|
+
case "space": return segment.text.length === 1 ? require_xml_fragment.el("text:s") : require_xml_fragment.el("text:s", { "text:c": String(segment.text.length) });
|
|
148
|
+
case "tab": return require_xml_fragment.el("text:tab");
|
|
149
|
+
case "lineBreak": return require_xml_fragment.el("text:line-break");
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
95
153
|
//#endregion
|
|
96
154
|
exports.ODF_FIELD_TAGS = ODF_FIELD_TAGS;
|
|
155
|
+
exports.buildOdfInlineNodes = buildOdfInlineNodes;
|
|
97
156
|
exports.decodeOdfText = decodeOdfText;
|
|
98
157
|
exports.getOdfSpaceCount = getOdfSpaceCount;
|
|
99
158
|
exports.isOdfFieldElement = isOdfFieldElement;
|
|
100
159
|
exports.measureOdfNodeLength = measureOdfNodeLength;
|
|
160
|
+
exports.segmentOdfText = segmentOdfText;
|
|
101
161
|
exports.sumOdfNodeLength = sumOdfNodeLength;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as measureOdfNodeLength, i as
|
|
2
|
-
export { ODF_FIELD_TAGS, decodeOdfText, getOdfSpaceCount, isOdfFieldElement, measureOdfNodeLength, sumOdfNodeLength };
|
|
1
|
+
import { a as decodeOdfText, c as measureOdfNodeLength, i as buildOdfInlineNodes, l as segmentOdfText, n as OdfTextSegment, o as getOdfSpaceCount, r as OdfTextSegmentKind, s as isOdfFieldElement, t as ODF_FIELD_TAGS, u as sumOdfNodeLength } from "../../text-pmlTqzgi.cjs";
|
|
2
|
+
export { ODF_FIELD_TAGS, OdfTextSegment, OdfTextSegmentKind, buildOdfInlineNodes, decodeOdfText, getOdfSpaceCount, isOdfFieldElement, measureOdfNodeLength, segmentOdfText, sumOdfNodeLength };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as measureOdfNodeLength, i as
|
|
2
|
-
export { ODF_FIELD_TAGS, decodeOdfText, getOdfSpaceCount, isOdfFieldElement, measureOdfNodeLength, sumOdfNodeLength };
|
|
1
|
+
import { a as decodeOdfText, c as measureOdfNodeLength, i as buildOdfInlineNodes, l as segmentOdfText, n as OdfTextSegment, o as getOdfSpaceCount, r as OdfTextSegmentKind, s as isOdfFieldElement, t as ODF_FIELD_TAGS, u as sumOdfNodeLength } from "../../text-B8350HA2.js";
|
|
2
|
+
export { ODF_FIELD_TAGS, OdfTextSegment, OdfTextSegmentKind, buildOdfInlineNodes, decodeOdfText, getOdfSpaceCount, isOdfFieldElement, measureOdfNodeLength, segmentOdfText, sumOdfNodeLength };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { el, txt } from "../../xml/fragment.js";
|
|
2
|
+
import { decodeXmlText, encodeXmlText } from "../../xml/entities.js";
|
|
2
3
|
import { attrValue } from "../../xml/query.js";
|
|
3
4
|
//#region src/typed/shared/text.ts
|
|
4
5
|
const ODF_FIELD_TAGS = /* @__PURE__ */ new Set([
|
|
@@ -91,5 +92,62 @@ function decodeOdfText(container) {
|
|
|
91
92
|
for (const child of container.children) text += decodeOdfNode(child);
|
|
92
93
|
return text;
|
|
93
94
|
}
|
|
95
|
+
const SPACE = " ";
|
|
96
|
+
const TAB = " ";
|
|
97
|
+
const LINE_BREAK = "\n";
|
|
98
|
+
function segmentOdfText(text, protectLeading, protectTrailing) {
|
|
99
|
+
const segments = [];
|
|
100
|
+
let plain = "";
|
|
101
|
+
const flushPlain = () => {
|
|
102
|
+
if (plain.length > 0) {
|
|
103
|
+
segments.push({
|
|
104
|
+
kind: "text",
|
|
105
|
+
text: plain
|
|
106
|
+
});
|
|
107
|
+
plain = "";
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
let index = 0;
|
|
111
|
+
while (index < text.length) {
|
|
112
|
+
const character = text[index];
|
|
113
|
+
if (character === TAB || character === LINE_BREAK) {
|
|
114
|
+
flushPlain();
|
|
115
|
+
segments.push({
|
|
116
|
+
kind: character === TAB ? "tab" : "lineBreak",
|
|
117
|
+
text: character
|
|
118
|
+
});
|
|
119
|
+
index += 1;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (character !== SPACE) {
|
|
123
|
+
plain += character;
|
|
124
|
+
index += 1;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
let end = index;
|
|
128
|
+
while (end < text.length && text[end] === SPACE) end += 1;
|
|
129
|
+
const spaces = text.slice(index, end);
|
|
130
|
+
if (spaces.length > 1 || index === 0 && protectLeading || end === text.length && protectTrailing) {
|
|
131
|
+
flushPlain();
|
|
132
|
+
segments.push({
|
|
133
|
+
kind: "space",
|
|
134
|
+
text: spaces
|
|
135
|
+
});
|
|
136
|
+
} else plain += spaces;
|
|
137
|
+
index = end;
|
|
138
|
+
}
|
|
139
|
+
flushPlain();
|
|
140
|
+
return segments;
|
|
141
|
+
}
|
|
142
|
+
function buildOdfInlineNodes(segments) {
|
|
143
|
+
return segments.map((segment) => {
|
|
144
|
+
switch (segment.kind) {
|
|
145
|
+
case "text": return txt(encodeXmlText(segment.text));
|
|
146
|
+
case "space": return segment.text.length === 1 ? el("text:s") : el("text:s", { "text:c": String(segment.text.length) });
|
|
147
|
+
case "tab": return el("text:tab");
|
|
148
|
+
case "lineBreak": return el("text:line-break");
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
94
152
|
//#endregion
|
|
95
|
-
export { ODF_FIELD_TAGS, decodeOdfText, getOdfSpaceCount, isOdfFieldElement, measureOdfNodeLength, sumOdfNodeLength };
|
|
153
|
+
export { ODF_FIELD_TAGS, buildOdfInlineNodes, decodeOdfText, getOdfSpaceCount, isOdfFieldElement, measureOdfNodeLength, segmentOdfText, sumOdfNodeLength };
|
|
@@ -27,9 +27,24 @@ function parseOdfLength(value) {
|
|
|
27
27
|
if (numeric === void 0 || unit === void 0 || !isLengthUnit(unit)) return;
|
|
28
28
|
return Number(numeric) * unitToPtFactor(unit);
|
|
29
29
|
}
|
|
30
|
+
function expandExponential(text) {
|
|
31
|
+
const match = /^(-?)(\d+)(?:\.(\d+))?[eE]([+-]?\d+)$/.exec(text);
|
|
32
|
+
if (match === null) return text;
|
|
33
|
+
const [, sign, integerDigits, fractionDigits, exponent] = match;
|
|
34
|
+
if (sign === void 0 || integerDigits === void 0 || exponent === void 0) return text;
|
|
35
|
+
const digits = `${integerDigits}${fractionDigits ?? ""}`;
|
|
36
|
+
const pointIndex = integerDigits.length + Number(exponent);
|
|
37
|
+
if (pointIndex <= 0) return `${sign}0.${"0".repeat(-pointIndex)}${digits}`;
|
|
38
|
+
if (pointIndex >= digits.length) return `${sign}${digits}${"0".repeat(pointIndex - digits.length)}`;
|
|
39
|
+
return `${sign}${digits.slice(0, pointIndex)}.${digits.slice(pointIndex)}`;
|
|
40
|
+
}
|
|
41
|
+
function formatOdfNumber(value) {
|
|
42
|
+
return expandExponential(`${value}`);
|
|
43
|
+
}
|
|
30
44
|
function formatOdfLength(pt, unit = "pt") {
|
|
31
|
-
return `${pt / unitToPtFactor(unit)}${unit}`;
|
|
45
|
+
return `${formatOdfNumber(pt / unitToPtFactor(unit))}${unit}`;
|
|
32
46
|
}
|
|
33
47
|
//#endregion
|
|
34
48
|
exports.formatOdfLength = formatOdfLength;
|
|
49
|
+
exports.formatOdfNumber = formatOdfNumber;
|
|
35
50
|
exports.parseOdfLength = parseOdfLength;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as formatOdfLength, r as
|
|
2
|
-
export { LengthUnit, formatOdfLength, parseOdfLength };
|
|
1
|
+
import { i as parseOdfLength, n as formatOdfLength, r as formatOdfNumber, t as LengthUnit } from "../../units-DdyaQolR.cjs";
|
|
2
|
+
export { LengthUnit, formatOdfLength, formatOdfNumber, parseOdfLength };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as formatOdfLength, r as
|
|
2
|
-
export { LengthUnit, formatOdfLength, parseOdfLength };
|
|
1
|
+
import { i as parseOdfLength, n as formatOdfLength, r as formatOdfNumber, t as LengthUnit } from "../../units-DdyaQolR.js";
|
|
2
|
+
export { LengthUnit, formatOdfLength, formatOdfNumber, parseOdfLength };
|
|
@@ -26,8 +26,22 @@ function parseOdfLength(value) {
|
|
|
26
26
|
if (numeric === void 0 || unit === void 0 || !isLengthUnit(unit)) return;
|
|
27
27
|
return Number(numeric) * unitToPtFactor(unit);
|
|
28
28
|
}
|
|
29
|
+
function expandExponential(text) {
|
|
30
|
+
const match = /^(-?)(\d+)(?:\.(\d+))?[eE]([+-]?\d+)$/.exec(text);
|
|
31
|
+
if (match === null) return text;
|
|
32
|
+
const [, sign, integerDigits, fractionDigits, exponent] = match;
|
|
33
|
+
if (sign === void 0 || integerDigits === void 0 || exponent === void 0) return text;
|
|
34
|
+
const digits = `${integerDigits}${fractionDigits ?? ""}`;
|
|
35
|
+
const pointIndex = integerDigits.length + Number(exponent);
|
|
36
|
+
if (pointIndex <= 0) return `${sign}0.${"0".repeat(-pointIndex)}${digits}`;
|
|
37
|
+
if (pointIndex >= digits.length) return `${sign}${digits}${"0".repeat(pointIndex - digits.length)}`;
|
|
38
|
+
return `${sign}${digits.slice(0, pointIndex)}.${digits.slice(pointIndex)}`;
|
|
39
|
+
}
|
|
40
|
+
function formatOdfNumber(value) {
|
|
41
|
+
return expandExponential(`${value}`);
|
|
42
|
+
}
|
|
29
43
|
function formatOdfLength(pt, unit = "pt") {
|
|
30
|
-
return `${pt / unitToPtFactor(unit)}${unit}`;
|
|
44
|
+
return `${formatOdfNumber(pt / unitToPtFactor(unit))}${unit}`;
|
|
31
45
|
}
|
|
32
46
|
//#endregion
|
|
33
|
-
export { formatOdfLength, parseOdfLength };
|
|
47
|
+
export { formatOdfLength, formatOdfNumber, parseOdfLength };
|