documents.js 1.61.0 → 1.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -47
- package/dist/{blr-types-CYYC3yYU.d.cts → blr-types-DVgO1DQ9.d.cts} +1 -1
- package/dist/{blr-types-CYYC3yYU.d.ts → blr-types-DVgO1DQ9.d.ts} +1 -1
- package/dist/convert/capability.cjs +1 -0
- package/dist/convert/capability.d.cts +1 -1
- package/dist/convert/capability.d.ts +1 -1
- package/dist/convert/capability.js +1 -0
- package/dist/convert/convert.cjs +92 -38
- package/dist/convert/convert.d.cts +11 -4
- package/dist/convert/convert.d.ts +11 -4
- package/dist/convert/convert.js +93 -39
- package/dist/convert/local.cjs +15 -2
- package/dist/convert/local.js +15 -2
- package/dist/convert/port.d.cts +8 -4
- package/dist/convert/port.d.ts +8 -4
- package/dist/edit/docx/content.cjs +75 -13
- package/dist/edit/docx/content.d.cts +8 -2
- package/dist/edit/docx/content.d.ts +8 -2
- package/dist/edit/docx/content.js +75 -13
- package/dist/edit/docx/paragraph.cjs +14 -0
- package/dist/edit/docx/paragraph.d.cts +5 -0
- package/dist/edit/docx/paragraph.d.ts +5 -0
- package/dist/edit/docx/paragraph.js +14 -0
- package/dist/edit/docx/run.cjs +1 -1
- package/dist/edit/docx/run.js +1 -1
- package/dist/edit/docx/table.cjs +41 -0
- package/dist/edit/docx/table.d.cts +7 -1
- package/dist/edit/docx/table.d.ts +7 -1
- package/dist/edit/docx/table.js +42 -1
- package/dist/edit/geometry.cjs +38 -0
- package/dist/edit/geometry.d.cts +7 -0
- package/dist/edit/geometry.d.ts +7 -0
- package/dist/edit/geometry.js +36 -0
- package/dist/edit/odg/content.cjs +15 -12
- package/dist/edit/odg/content.js +15 -12
- package/dist/edit/odg/editor.d.cts +1 -1
- package/dist/edit/odg/editor.d.ts +1 -1
- package/dist/edit/odg/page.d.cts +3 -3
- package/dist/edit/odg/page.d.ts +3 -3
- package/dist/edit/odg/vector.cjs +22 -13
- package/dist/edit/odg/vector.d.cts +1 -1
- package/dist/edit/odg/vector.d.ts +1 -1
- package/dist/edit/odg/vector.js +23 -14
- package/dist/edit/odp/content.cjs +15 -0
- package/dist/edit/odp/content.js +16 -1
- package/dist/edit/odp/editor.d.cts +1 -1
- package/dist/edit/odp/editor.d.ts +1 -1
- package/dist/edit/odp/image.d.cts +1 -1
- package/dist/edit/odp/image.d.ts +1 -1
- package/dist/edit/odp/shape.cjs +11 -30
- package/dist/edit/odp/shape.d.cts +2 -2
- package/dist/edit/odp/shape.d.ts +2 -2
- package/dist/edit/odp/shape.js +13 -33
- package/dist/edit/odp/slide.cjs +11 -0
- package/dist/edit/odp/slide.d.cts +14 -4
- package/dist/edit/odp/slide.d.ts +14 -4
- package/dist/edit/odp/slide.js +12 -1
- package/dist/edit/odt/content.cjs +56 -16
- package/dist/edit/odt/content.d.cts +4 -2
- package/dist/edit/odt/content.d.ts +4 -2
- package/dist/edit/odt/content.js +56 -17
- package/dist/edit/odt/editor.d.cts +1 -1
- package/dist/edit/odt/editor.d.ts +1 -1
- package/dist/edit/odt/table.cjs +36 -0
- package/dist/edit/odt/table.d.cts +1 -36
- package/dist/edit/odt/table.d.ts +1 -36
- package/dist/edit/odt/table.js +37 -1
- package/dist/edit/pptx/content.cjs +71 -3
- package/dist/edit/pptx/content.js +71 -3
- package/dist/edit/pptx/editor.d.cts +1 -1
- package/dist/edit/pptx/editor.d.ts +1 -1
- package/dist/edit/pptx/image.d.cts +1 -1
- package/dist/edit/pptx/image.d.ts +1 -1
- package/dist/edit/pptx/shape.cjs +23 -1
- package/dist/edit/pptx/shape.d.cts +2 -2
- package/dist/edit/pptx/shape.d.ts +2 -2
- package/dist/edit/pptx/shape.js +23 -3
- package/dist/edit/pptx/slide.cjs +10 -1
- package/dist/edit/pptx/slide.d.cts +11 -4
- package/dist/edit/pptx/slide.d.ts +11 -4
- package/dist/edit/pptx/slide.js +10 -1
- package/dist/edit/pptx/table.cjs +136 -0
- package/dist/edit/pptx/table.d.cts +2 -0
- package/dist/edit/pptx/table.d.ts +2 -0
- package/dist/edit/pptx/table.js +131 -0
- package/dist/firebird/backup.d.cts +1 -1
- package/dist/firebird/backup.d.ts +1 -1
- package/dist/firebird/blr-types.cjs +2 -2
- package/dist/firebird/blr-types.d.cts +1 -1
- package/dist/firebird/blr-types.d.ts +1 -1
- package/dist/firebird/blr-types.js +2 -2
- package/dist/firebird/data.cjs +68 -14
- package/dist/firebird/data.d.cts +1 -1
- package/dist/firebird/data.d.ts +1 -1
- package/dist/firebird/data.js +68 -14
- package/dist/firebird/schema.cjs +13 -1
- package/dist/firebird/schema.d.cts +1 -1
- package/dist/firebird/schema.d.ts +1 -1
- package/dist/firebird/schema.js +13 -1
- package/dist/fonts/obfuscation.cjs +50 -0
- package/dist/fonts/obfuscation.d.cts +9 -0
- package/dist/fonts/obfuscation.d.ts +9 -0
- package/dist/fonts/obfuscation.js +46 -0
- package/dist/fonts/odf.cjs +86 -0
- package/dist/fonts/odf.d.cts +9 -0
- package/dist/fonts/odf.d.ts +9 -0
- package/dist/fonts/odf.js +84 -0
- package/dist/fonts/ooxml.cjs +129 -0
- package/dist/fonts/ooxml.d.cts +9 -0
- package/dist/fonts/ooxml.d.ts +9 -0
- package/dist/fonts/ooxml.js +127 -0
- package/dist/fonts/registry.cjs +18 -0
- package/dist/fonts/registry.d.cts +2 -0
- package/dist/fonts/registry.d.ts +2 -0
- package/dist/fonts/registry.js +16 -0
- package/dist/{geometry-DvwdrIij.d.cts → geometry-DaJr8yQW.d.cts} +2 -2
- package/dist/{geometry-DvwdrIij.d.ts → geometry-DaJr8yQW.d.ts} +2 -2
- package/dist/hsqldb/binary-script.cjs +154 -0
- package/dist/hsqldb/binary-script.d.cts +15 -0
- package/dist/hsqldb/binary-script.d.ts +15 -0
- package/dist/hsqldb/binary-script.js +151 -0
- package/dist/hsqldb/cache.cjs +18 -11
- package/dist/hsqldb/cache.d.cts +9 -4
- package/dist/hsqldb/cache.d.ts +9 -4
- package/dist/hsqldb/cache.js +18 -11
- package/dist/hsqldb/rowformat.cjs +60 -16
- package/dist/hsqldb/rowformat.d.cts +2 -21
- package/dist/hsqldb/rowformat.d.ts +2 -21
- package/dist/hsqldb/rowformat.js +60 -17
- package/dist/{image-BZDy72Jb.d.cts → image-7snmKIxn.d.cts} +1 -1
- package/dist/{image-B-xQWYYS.d.ts → image-Cs8xF753.d.ts} +1 -1
- package/dist/{image-CeqwL-Qs.d.ts → image-DHcA9kaK.d.ts} +1 -1
- package/dist/{image-DWX6cNOD.d.cts → image-M5SezZVI.d.cts} +1 -1
- package/dist/index.cjs +86 -3
- package/dist/index.d.cts +33 -21
- package/dist/index.d.ts +33 -21
- package/dist/index.js +18 -5
- package/dist/layout/cell-typing.cjs +209 -0
- package/dist/layout/cell-typing.d.cts +22 -0
- package/dist/layout/cell-typing.d.ts +22 -0
- package/dist/layout/cell-typing.js +208 -0
- package/dist/layout/drawing.cjs +193 -17
- package/dist/layout/drawing.js +193 -17
- package/dist/layout/engine.cjs +46 -29
- package/dist/layout/engine.d.cts +0 -2
- package/dist/layout/engine.d.ts +0 -2
- package/dist/layout/engine.js +47 -30
- package/dist/layout/lattice.cjs +139 -0
- package/dist/layout/lattice.d.cts +20 -0
- package/dist/layout/lattice.d.ts +20 -0
- package/dist/layout/lattice.js +135 -0
- package/dist/layout/reconstruct.cjs +176 -113
- package/dist/layout/reconstruct.d.cts +2 -0
- package/dist/layout/reconstruct.d.ts +2 -0
- package/dist/layout/reconstruct.js +173 -110
- package/dist/layout/shared.cjs +52 -0
- package/dist/layout/shared.d.cts +4 -2
- package/dist/layout/shared.d.ts +4 -2
- package/dist/layout/shared.js +51 -1
- package/dist/layout/sheets.cjs +45 -11
- package/dist/layout/sheets.js +46 -12
- package/dist/layout/slides.cjs +7 -7
- package/dist/layout/slides.d.cts +0 -3
- package/dist/layout/slides.d.ts +0 -3
- package/dist/layout/slides.js +7 -7
- package/dist/markdown/write.cjs +19 -6
- package/dist/markdown/write.js +19 -6
- package/dist/mathml/layout.cjs +2 -2
- package/dist/mathml/layout.d.cts +1 -1
- package/dist/mathml/layout.d.ts +1 -1
- package/dist/mathml/layout.js +2 -2
- package/dist/model/embedded-drawing.cjs +32 -0
- package/dist/model/embedded-drawing.d.cts +8 -0
- package/dist/model/embedded-drawing.d.ts +8 -0
- package/dist/model/embedded-drawing.js +30 -0
- package/dist/model/formula.cjs +31 -0
- package/dist/model/formula.d.cts +6 -6
- package/dist/model/formula.d.ts +6 -6
- package/dist/model/formula.js +27 -0
- package/dist/model/geometry.d.cts +1 -1
- package/dist/model/geometry.d.ts +1 -1
- package/dist/model/paint-order.cjs +15 -0
- package/dist/model/paint-order.d.cts +14 -0
- package/dist/model/paint-order.d.ts +14 -0
- package/dist/model/paint-order.js +14 -0
- package/dist/odb/components.cjs +12 -0
- package/dist/odb/components.d.cts +6 -0
- package/dist/odb/components.d.ts +6 -0
- package/dist/odb/components.js +10 -0
- package/dist/odb/read.cjs +11 -7
- package/dist/odb/read.d.cts +3 -2
- package/dist/odb/read.d.ts +3 -2
- package/dist/odb/read.js +11 -7
- package/dist/odf/formula/detect.cjs +86 -18
- package/dist/odf/formula/detect.d.cts +10 -6
- package/dist/odf/formula/detect.d.ts +10 -6
- package/dist/odf/formula/detect.js +86 -19
- package/dist/odf/formula/read.cjs +4 -16
- package/dist/odf/formula/read.d.cts +4 -8
- package/dist/odf/formula/read.d.ts +4 -8
- package/dist/odf/formula/read.js +5 -17
- package/dist/odf/odp/read.cjs +9 -19
- package/dist/odf/odp/read.d.cts +2 -7
- package/dist/odf/odp/read.d.ts +2 -7
- package/dist/odf/odp/read.js +10 -20
- package/dist/odf/odt/read.cjs +63 -23
- package/dist/odf/odt/read.d.cts +2 -7
- package/dist/odf/odt/read.d.ts +2 -7
- package/dist/odf/odt/read.js +64 -24
- package/dist/omml/write.cjs +258 -0
- package/dist/omml/write.d.cts +2 -0
- package/dist/omml/write.d.ts +2 -0
- package/dist/omml/write.js +256 -0
- package/dist/registry-CrSqLIcn.d.ts +19 -0
- package/dist/registry-CtPhMD0f.d.cts +19 -0
- package/dist/rowformat-Cl2exlEh.d.cts +25 -0
- package/dist/rowformat-Cl2exlEh.d.ts +25 -0
- package/dist/{schema-Acco3Ezi.d.cts → schema-BeR_KJ0X.d.cts} +3 -1
- package/dist/{schema-VkAA6pF5.d.ts → schema-CSKwSb_v.d.ts} +3 -1
- package/dist/{shape-BUfjw5eZ.d.cts → shape-BhkP6HB8.d.cts} +6 -2
- package/dist/{shape-CTkl6kt8.d.ts → shape-BkVcwPcf.d.ts} +6 -2
- package/dist/{shape-BfN3m52m.d.ts → shape-CVXedeL7.d.ts} +3 -2
- package/dist/{shape-CN2ycxOo.d.cts → shape-CXZ6fejV.d.cts} +3 -2
- package/dist/table-C3CPZ--2.d.cts +35 -0
- package/dist/table-DjYcNOFm.d.cts +44 -0
- package/dist/table-DqfqMkVq.d.ts +44 -0
- package/dist/table-DvS_7UQS.d.ts +35 -0
- package/dist/{vector-ClohqsOe.d.cts → vector-Puuqu_IT.d.cts} +4 -0
- package/dist/{vector-ClohqsOe.d.ts → vector-Puuqu_IT.d.ts} +4 -0
- package/dist/write-DuyfnbL_.d.cts +16 -0
- package/dist/write-Zqwx6pka.d.ts +16 -0
- package/package.json +4 -4
- package/dist/odf/formula/placeholder.cjs +0 -36
- package/dist/odf/formula/placeholder.d.cts +0 -14
- package/dist/odf/formula/placeholder.d.ts +0 -14
- package/dist/odf/formula/placeholder.js +0 -36
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ContentCellValue } from "document-schema.js";
|
|
2
|
+
//#region src/layout/cell-typing.d.ts
|
|
3
|
+
type CellTypeRule = 'boolean-literal' | 'iso-date' | 'named-month-date' | 'plain-number' | 'grouped-number' | 'percentage' | 'currency';
|
|
4
|
+
type CellTypeDeclineReason = 'ambiguous-boolean-word' | 'ambiguous-date-order' | 'ambiguous-grouping-separator' | 'leading-zero-digits' | 'precision-loss';
|
|
5
|
+
type CellTypeInferenceResult = {
|
|
6
|
+
readonly outcome: 'retyped';
|
|
7
|
+
readonly value: ContentCellValue;
|
|
8
|
+
readonly rule: CellTypeRule;
|
|
9
|
+
} | {
|
|
10
|
+
readonly outcome: 'declined';
|
|
11
|
+
readonly reason: CellTypeDeclineReason;
|
|
12
|
+
};
|
|
13
|
+
type CellTypeInference = {
|
|
14
|
+
readonly sheetIndex: number;
|
|
15
|
+
readonly row: number;
|
|
16
|
+
readonly column: number;
|
|
17
|
+
readonly displayText: string;
|
|
18
|
+
} & CellTypeInferenceResult;
|
|
19
|
+
type CellTypeInferenceSink = (inference: CellTypeInference) => void;
|
|
20
|
+
declare function inferCellValue(displayText: string): CellTypeInferenceResult | undefined;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { CellTypeDeclineReason, CellTypeInference, CellTypeInferenceResult, CellTypeInferenceSink, CellTypeRule, inferCellValue };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ContentCellValue } from "document-schema.js";
|
|
2
|
+
//#region src/layout/cell-typing.d.ts
|
|
3
|
+
type CellTypeRule = 'boolean-literal' | 'iso-date' | 'named-month-date' | 'plain-number' | 'grouped-number' | 'percentage' | 'currency';
|
|
4
|
+
type CellTypeDeclineReason = 'ambiguous-boolean-word' | 'ambiguous-date-order' | 'ambiguous-grouping-separator' | 'leading-zero-digits' | 'precision-loss';
|
|
5
|
+
type CellTypeInferenceResult = {
|
|
6
|
+
readonly outcome: 'retyped';
|
|
7
|
+
readonly value: ContentCellValue;
|
|
8
|
+
readonly rule: CellTypeRule;
|
|
9
|
+
} | {
|
|
10
|
+
readonly outcome: 'declined';
|
|
11
|
+
readonly reason: CellTypeDeclineReason;
|
|
12
|
+
};
|
|
13
|
+
type CellTypeInference = {
|
|
14
|
+
readonly sheetIndex: number;
|
|
15
|
+
readonly row: number;
|
|
16
|
+
readonly column: number;
|
|
17
|
+
readonly displayText: string;
|
|
18
|
+
} & CellTypeInferenceResult;
|
|
19
|
+
type CellTypeInferenceSink = (inference: CellTypeInference) => void;
|
|
20
|
+
declare function inferCellValue(displayText: string): CellTypeInferenceResult | undefined;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { CellTypeDeclineReason, CellTypeInference, CellTypeInferenceResult, CellTypeInferenceSink, CellTypeRule, inferCellValue };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
//#region src/layout/cell-typing.ts
|
|
2
|
+
const CURRENCY_SYMBOLS = /* @__PURE__ */ new Map([
|
|
3
|
+
["$", void 0],
|
|
4
|
+
["¥", void 0],
|
|
5
|
+
["£", "GBP"],
|
|
6
|
+
["€", "EUR"],
|
|
7
|
+
["₹", "INR"],
|
|
8
|
+
["₩", "KRW"],
|
|
9
|
+
["₽", "RUB"]
|
|
10
|
+
]);
|
|
11
|
+
const MONTH_NAMES = new Map([
|
|
12
|
+
"january",
|
|
13
|
+
"february",
|
|
14
|
+
"march",
|
|
15
|
+
"april",
|
|
16
|
+
"may",
|
|
17
|
+
"june",
|
|
18
|
+
"july",
|
|
19
|
+
"august",
|
|
20
|
+
"september",
|
|
21
|
+
"october",
|
|
22
|
+
"november",
|
|
23
|
+
"december"
|
|
24
|
+
].flatMap((name, index) => [[name, index + 1], [name.slice(0, 3), index + 1]]));
|
|
25
|
+
const BOOLEAN_LITERALS = /* @__PURE__ */ new Map([["true", true], ["false", false]]);
|
|
26
|
+
const AMBIGUOUS_BOOLEAN_WORDS = /* @__PURE__ */ new Set([
|
|
27
|
+
"yes",
|
|
28
|
+
"no",
|
|
29
|
+
"y",
|
|
30
|
+
"n",
|
|
31
|
+
"on",
|
|
32
|
+
"off"
|
|
33
|
+
]);
|
|
34
|
+
function normalizeWhitespace(text) {
|
|
35
|
+
return text.replace(/[\u00A0\u202F]/gu, " ").trim();
|
|
36
|
+
}
|
|
37
|
+
function exactlyRepresentable(canonicalDecimal) {
|
|
38
|
+
const parsed = Number(canonicalDecimal);
|
|
39
|
+
if (!Number.isFinite(parsed)) return;
|
|
40
|
+
const trimmed = canonicalDecimal.includes(".") ? canonicalDecimal.replace(/0+$/u, "").replace(/\.$/u, "") : canonicalDecimal;
|
|
41
|
+
return String(parsed) === trimmed ? parsed : void 0;
|
|
42
|
+
}
|
|
43
|
+
const PLAIN_NUMBER_PATTERN = /^(?<sign>[-+])?(?<integer>\d+)(?:\.(?<fraction>\d+))?$/u;
|
|
44
|
+
const GROUPED_NUMBER_PATTERN = /^(?<sign>[-+])?(?<lead>\d{1,3})(?<groups>(?:,\d{3})+)(?:\.(?<fraction>\d+))?$/u;
|
|
45
|
+
function parseNumericLiteral(text) {
|
|
46
|
+
const grouped = GROUPED_NUMBER_PATTERN.exec(text);
|
|
47
|
+
if (grouped?.groups !== void 0) {
|
|
48
|
+
const { sign, lead, groups, fraction } = grouped.groups;
|
|
49
|
+
if (lead.length > 1 && lead.startsWith("0")) return { declined: "leading-zero-digits" };
|
|
50
|
+
if (groups.length / 4 === 1 && fraction === void 0) return { declined: "ambiguous-grouping-separator" };
|
|
51
|
+
return {
|
|
52
|
+
canonicalDecimal: `${sign === "-" ? "-" : ""}${lead}${groups.replaceAll(",", "")}${fraction === void 0 ? "" : `.${fraction}`}`,
|
|
53
|
+
grouped: true
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const plain = PLAIN_NUMBER_PATTERN.exec(text);
|
|
57
|
+
if (plain?.groups === void 0) return;
|
|
58
|
+
const { sign, integer, fraction } = plain.groups;
|
|
59
|
+
if (integer.length > 1 && integer.startsWith("0")) return { declined: "leading-zero-digits" };
|
|
60
|
+
return {
|
|
61
|
+
canonicalDecimal: `${sign === "-" ? "-" : ""}${integer}${fraction === void 0 ? "" : `.${fraction}`}`,
|
|
62
|
+
grouped: false
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function isDecline(value) {
|
|
66
|
+
return value !== void 0 && "declined" in value;
|
|
67
|
+
}
|
|
68
|
+
const CURRENCY_PREFIX_PATTERN = /^(?<sign>-)?(?<symbol>[$£€¥₹₩₽])\s?(?<rest>.+)$/u;
|
|
69
|
+
function inferCurrency(text) {
|
|
70
|
+
const match = CURRENCY_PREFIX_PATTERN.exec(text);
|
|
71
|
+
if (match?.groups === void 0) return;
|
|
72
|
+
const { sign, symbol, rest } = match.groups;
|
|
73
|
+
const literal = parseNumericLiteral(rest);
|
|
74
|
+
if (isDecline(literal)) return {
|
|
75
|
+
outcome: "declined",
|
|
76
|
+
reason: literal.declined
|
|
77
|
+
};
|
|
78
|
+
if (literal === void 0) return;
|
|
79
|
+
const magnitude = exactlyRepresentable(literal.canonicalDecimal);
|
|
80
|
+
if (magnitude === void 0) return {
|
|
81
|
+
outcome: "declined",
|
|
82
|
+
reason: "precision-loss"
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
outcome: "retyped",
|
|
86
|
+
value: {
|
|
87
|
+
kind: "currency",
|
|
88
|
+
value: sign === "-" ? -magnitude : magnitude,
|
|
89
|
+
currency: CURRENCY_SYMBOLS.get(symbol)
|
|
90
|
+
},
|
|
91
|
+
rule: "currency"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const PERCENT_HUNDREDTHS = 100;
|
|
95
|
+
function inferPercentage(text) {
|
|
96
|
+
if (!text.endsWith("%")) return;
|
|
97
|
+
const literal = parseNumericLiteral(text.slice(0, -1).trimEnd());
|
|
98
|
+
if (isDecline(literal)) return {
|
|
99
|
+
outcome: "declined",
|
|
100
|
+
reason: literal.declined
|
|
101
|
+
};
|
|
102
|
+
if (literal === void 0) return;
|
|
103
|
+
const magnitude = exactlyRepresentable(literal.canonicalDecimal);
|
|
104
|
+
if (magnitude === void 0) return {
|
|
105
|
+
outcome: "declined",
|
|
106
|
+
reason: "precision-loss"
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
outcome: "retyped",
|
|
110
|
+
value: {
|
|
111
|
+
kind: "percentage",
|
|
112
|
+
value: magnitude / PERCENT_HUNDREDTHS
|
|
113
|
+
},
|
|
114
|
+
rule: "percentage"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const ISO_DATE_PATTERN = /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/u;
|
|
118
|
+
const DAY_MONTH_YEAR_PATTERN = /^(?<day>\d{1,2})[\s-](?<month>[A-Za-z]{3,9})\.?[\s-](?<year>\d{4})$/u;
|
|
119
|
+
const MONTH_DAY_YEAR_PATTERN = /^(?<month>[A-Za-z]{3,9})\.?[\s-](?<day>\d{1,2}),?[\s-](?<year>\d{4})$/u;
|
|
120
|
+
const NUMERIC_SEPARATED_DATE_PATTERN = /^\d{1,4}[/.]\d{1,2}[/.]\d{1,4}$/u;
|
|
121
|
+
const MONTHS_PER_YEAR = 12;
|
|
122
|
+
function isRealCalendarDate(year, month, day) {
|
|
123
|
+
if (month < 1 || month > MONTHS_PER_YEAR || day < 1) return false;
|
|
124
|
+
const probe = new Date(Date.UTC(year, month - 1, day));
|
|
125
|
+
return probe.getUTCFullYear() === year && probe.getUTCMonth() === month - 1 && probe.getUTCDate() === day;
|
|
126
|
+
}
|
|
127
|
+
function isoDateValue(year, month, day) {
|
|
128
|
+
return `${String(year).padStart(4, "0")}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
|
|
129
|
+
}
|
|
130
|
+
function inferDate(text) {
|
|
131
|
+
const iso = ISO_DATE_PATTERN.exec(text);
|
|
132
|
+
if (iso?.groups !== void 0) {
|
|
133
|
+
const year = Number(iso.groups.year);
|
|
134
|
+
const month = Number(iso.groups.month);
|
|
135
|
+
const day = Number(iso.groups.day);
|
|
136
|
+
return isRealCalendarDate(year, month, day) ? {
|
|
137
|
+
outcome: "retyped",
|
|
138
|
+
value: {
|
|
139
|
+
kind: "date",
|
|
140
|
+
value: isoDateValue(year, month, day)
|
|
141
|
+
},
|
|
142
|
+
rule: "iso-date"
|
|
143
|
+
} : void 0;
|
|
144
|
+
}
|
|
145
|
+
const named = DAY_MONTH_YEAR_PATTERN.exec(text) ?? MONTH_DAY_YEAR_PATTERN.exec(text);
|
|
146
|
+
if (named?.groups !== void 0) {
|
|
147
|
+
const month = MONTH_NAMES.get(named.groups.month.toLowerCase());
|
|
148
|
+
if (month === void 0) return;
|
|
149
|
+
const year = Number(named.groups.year);
|
|
150
|
+
const day = Number(named.groups.day);
|
|
151
|
+
return isRealCalendarDate(year, month, day) ? {
|
|
152
|
+
outcome: "retyped",
|
|
153
|
+
value: {
|
|
154
|
+
kind: "date",
|
|
155
|
+
value: isoDateValue(year, month, day)
|
|
156
|
+
},
|
|
157
|
+
rule: "named-month-date"
|
|
158
|
+
} : void 0;
|
|
159
|
+
}
|
|
160
|
+
return NUMERIC_SEPARATED_DATE_PATTERN.test(text) ? {
|
|
161
|
+
outcome: "declined",
|
|
162
|
+
reason: "ambiguous-date-order"
|
|
163
|
+
} : void 0;
|
|
164
|
+
}
|
|
165
|
+
function inferBoolean(text) {
|
|
166
|
+
const lowered = text.toLowerCase();
|
|
167
|
+
const literal = BOOLEAN_LITERALS.get(lowered);
|
|
168
|
+
if (literal !== void 0) return {
|
|
169
|
+
outcome: "retyped",
|
|
170
|
+
value: {
|
|
171
|
+
kind: "boolean",
|
|
172
|
+
value: literal
|
|
173
|
+
},
|
|
174
|
+
rule: "boolean-literal"
|
|
175
|
+
};
|
|
176
|
+
return AMBIGUOUS_BOOLEAN_WORDS.has(lowered) ? {
|
|
177
|
+
outcome: "declined",
|
|
178
|
+
reason: "ambiguous-boolean-word"
|
|
179
|
+
} : void 0;
|
|
180
|
+
}
|
|
181
|
+
function inferNumber(text) {
|
|
182
|
+
const literal = parseNumericLiteral(text);
|
|
183
|
+
if (isDecline(literal)) return {
|
|
184
|
+
outcome: "declined",
|
|
185
|
+
reason: literal.declined
|
|
186
|
+
};
|
|
187
|
+
if (literal === void 0) return;
|
|
188
|
+
const value = exactlyRepresentable(literal.canonicalDecimal);
|
|
189
|
+
if (value === void 0) return {
|
|
190
|
+
outcome: "declined",
|
|
191
|
+
reason: "precision-loss"
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
outcome: "retyped",
|
|
195
|
+
value: {
|
|
196
|
+
kind: "number",
|
|
197
|
+
value
|
|
198
|
+
},
|
|
199
|
+
rule: literal.grouped ? "grouped-number" : "plain-number"
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function inferCellValue(displayText) {
|
|
203
|
+
const text = normalizeWhitespace(displayText);
|
|
204
|
+
if (text.length === 0) return;
|
|
205
|
+
return inferBoolean(text) ?? inferDate(text) ?? inferCurrency(text) ?? inferPercentage(text) ?? inferNumber(text);
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
export { inferCellValue };
|
package/dist/layout/drawing.cjs
CHANGED
|
@@ -1,29 +1,192 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_model_geometry = require("../model/geometry.cjs");
|
|
3
|
+
const require_model_paint_order = require("../model/paint-order.cjs");
|
|
3
4
|
const require_layout_slides = require("./slides.cjs");
|
|
4
5
|
let document_schema_js = require("document-schema.js");
|
|
6
|
+
let pdf_codec = require("pdf-codec");
|
|
5
7
|
//#region src/layout/drawing.ts
|
|
8
|
+
function isRotated(rotationDeg) {
|
|
9
|
+
return rotationDeg !== void 0 && rotationDeg !== 0;
|
|
10
|
+
}
|
|
11
|
+
function boxCenter(box) {
|
|
12
|
+
return {
|
|
13
|
+
x: box.xPt + box.widthPt / 2,
|
|
14
|
+
y: box.yPt + box.heightPt / 2
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function rotator(flipped, rotationDeg) {
|
|
18
|
+
const center = boxCenter(flipped);
|
|
19
|
+
const ccwDeg = -rotationDeg;
|
|
20
|
+
return (point) => (0, pdf_codec.rotatePointAboutCenter)(point, center, ccwDeg);
|
|
21
|
+
}
|
|
22
|
+
function boxCorners(box) {
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
x: box.xPt,
|
|
26
|
+
y: box.yPt
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
x: box.xPt + box.widthPt,
|
|
30
|
+
y: box.yPt
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
x: box.xPt + box.widthPt,
|
|
34
|
+
y: box.yPt + box.heightPt
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
x: box.xPt,
|
|
38
|
+
y: box.yPt + box.heightPt
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
}
|
|
6
42
|
function convertRectVector(vector, pageHeightPt, out) {
|
|
7
43
|
const flipped = require_model_geometry.flipY(vector.frame, pageHeightPt);
|
|
44
|
+
if (!isRotated(vector.rotationDeg)) {
|
|
45
|
+
out.push({
|
|
46
|
+
kind: "rect",
|
|
47
|
+
xPt: flipped.xPt,
|
|
48
|
+
yPt: flipped.yPt,
|
|
49
|
+
widthPt: flipped.widthPt,
|
|
50
|
+
heightPt: flipped.heightPt,
|
|
51
|
+
fill: vector.fill,
|
|
52
|
+
stroke: vector.stroke,
|
|
53
|
+
sourcePath: vector.sourcePath
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const rotate = rotator(flipped, vector.rotationDeg);
|
|
58
|
+
const [start, ...rest] = boxCorners(flipped).map(rotate);
|
|
59
|
+
const subpath = {
|
|
60
|
+
startXPt: start.x,
|
|
61
|
+
startYPt: start.y,
|
|
62
|
+
closed: true,
|
|
63
|
+
segments: rest.map((corner) => ({
|
|
64
|
+
kind: "line",
|
|
65
|
+
xPt: corner.x,
|
|
66
|
+
yPt: corner.y
|
|
67
|
+
}))
|
|
68
|
+
};
|
|
8
69
|
out.push({
|
|
9
|
-
kind: "
|
|
10
|
-
|
|
11
|
-
yPt: flipped.yPt,
|
|
12
|
-
widthPt: flipped.widthPt,
|
|
13
|
-
heightPt: flipped.heightPt,
|
|
70
|
+
kind: "path",
|
|
71
|
+
subpaths: [subpath],
|
|
14
72
|
fill: vector.fill,
|
|
15
73
|
stroke: vector.stroke,
|
|
16
74
|
sourcePath: vector.sourcePath
|
|
17
75
|
});
|
|
18
76
|
}
|
|
77
|
+
const CIRCLE_CUBIC_RATIO = 4 / 3 * (Math.SQRT2 - 1);
|
|
78
|
+
function ellipseCubicPoints(flipped) {
|
|
79
|
+
const cx = flipped.xPt + flipped.widthPt / 2;
|
|
80
|
+
const cy = flipped.yPt + flipped.heightPt / 2;
|
|
81
|
+
const rx = flipped.widthPt / 2;
|
|
82
|
+
const ry = flipped.heightPt / 2;
|
|
83
|
+
const kx = rx * CIRCLE_CUBIC_RATIO;
|
|
84
|
+
const ky = ry * CIRCLE_CUBIC_RATIO;
|
|
85
|
+
return {
|
|
86
|
+
start: {
|
|
87
|
+
x: cx + rx,
|
|
88
|
+
y: cy
|
|
89
|
+
},
|
|
90
|
+
arcs: [
|
|
91
|
+
{
|
|
92
|
+
c1: {
|
|
93
|
+
x: cx + rx,
|
|
94
|
+
y: cy + ky
|
|
95
|
+
},
|
|
96
|
+
c2: {
|
|
97
|
+
x: cx + kx,
|
|
98
|
+
y: cy + ry
|
|
99
|
+
},
|
|
100
|
+
to: {
|
|
101
|
+
x: cx,
|
|
102
|
+
y: cy + ry
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
c1: {
|
|
107
|
+
x: cx - kx,
|
|
108
|
+
y: cy + ry
|
|
109
|
+
},
|
|
110
|
+
c2: {
|
|
111
|
+
x: cx - rx,
|
|
112
|
+
y: cy + ky
|
|
113
|
+
},
|
|
114
|
+
to: {
|
|
115
|
+
x: cx - rx,
|
|
116
|
+
y: cy
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
c1: {
|
|
121
|
+
x: cx - rx,
|
|
122
|
+
y: cy - ky
|
|
123
|
+
},
|
|
124
|
+
c2: {
|
|
125
|
+
x: cx - kx,
|
|
126
|
+
y: cy - ry
|
|
127
|
+
},
|
|
128
|
+
to: {
|
|
129
|
+
x: cx,
|
|
130
|
+
y: cy - ry
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
c1: {
|
|
135
|
+
x: cx + kx,
|
|
136
|
+
y: cy - ry
|
|
137
|
+
},
|
|
138
|
+
c2: {
|
|
139
|
+
x: cx + rx,
|
|
140
|
+
y: cy - ky
|
|
141
|
+
},
|
|
142
|
+
to: {
|
|
143
|
+
x: cx + rx,
|
|
144
|
+
y: cy
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
};
|
|
149
|
+
}
|
|
19
150
|
function convertEllipseVector(vector, pageHeightPt, out) {
|
|
20
151
|
const flipped = require_model_geometry.flipY(vector.frame, pageHeightPt);
|
|
152
|
+
if (!isRotated(vector.rotationDeg)) {
|
|
153
|
+
out.push({
|
|
154
|
+
kind: "ellipse",
|
|
155
|
+
xPt: flipped.xPt,
|
|
156
|
+
yPt: flipped.yPt,
|
|
157
|
+
widthPt: flipped.widthPt,
|
|
158
|
+
heightPt: flipped.heightPt,
|
|
159
|
+
fill: vector.fill,
|
|
160
|
+
stroke: vector.stroke,
|
|
161
|
+
sourcePath: vector.sourcePath
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const rotate = rotator(flipped, vector.rotationDeg);
|
|
166
|
+
const { start, arcs } = ellipseCubicPoints(flipped);
|
|
167
|
+
const rotatedStart = rotate(start);
|
|
168
|
+
const segments = arcs.map((arc) => {
|
|
169
|
+
const c1 = rotate(arc.c1);
|
|
170
|
+
const c2 = rotate(arc.c2);
|
|
171
|
+
const to = rotate(arc.to);
|
|
172
|
+
return {
|
|
173
|
+
kind: "cubic",
|
|
174
|
+
c1xPt: c1.x,
|
|
175
|
+
c1yPt: c1.y,
|
|
176
|
+
c2xPt: c2.x,
|
|
177
|
+
c2yPt: c2.y,
|
|
178
|
+
xPt: to.x,
|
|
179
|
+
yPt: to.y
|
|
180
|
+
};
|
|
181
|
+
});
|
|
21
182
|
out.push({
|
|
22
|
-
kind: "
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
183
|
+
kind: "path",
|
|
184
|
+
subpaths: [{
|
|
185
|
+
startXPt: rotatedStart.x,
|
|
186
|
+
startYPt: rotatedStart.y,
|
|
187
|
+
closed: true,
|
|
188
|
+
segments
|
|
189
|
+
}],
|
|
27
190
|
fill: vector.fill,
|
|
28
191
|
stroke: vector.stroke,
|
|
29
192
|
sourcePath: vector.sourcePath
|
|
@@ -48,24 +211,37 @@ function placePathPoint(frame, point, pageHeightPt) {
|
|
|
48
211
|
};
|
|
49
212
|
}
|
|
50
213
|
function convertPathVector(vector, pageHeightPt, out) {
|
|
214
|
+
const rotate = isRotated(vector.rotationDeg) ? rotator(require_model_geometry.flipY(vector.frame, pageHeightPt), vector.rotationDeg) : void 0;
|
|
215
|
+
const place = (point) => {
|
|
216
|
+
const placed = placePathPoint(vector.frame, point, pageHeightPt);
|
|
217
|
+
if (rotate === void 0) return placed;
|
|
218
|
+
const rotated = rotate({
|
|
219
|
+
x: placed.xPt,
|
|
220
|
+
y: placed.yPt
|
|
221
|
+
});
|
|
222
|
+
return {
|
|
223
|
+
xPt: rotated.x,
|
|
224
|
+
yPt: rotated.y
|
|
225
|
+
};
|
|
226
|
+
};
|
|
51
227
|
const subpaths = vector.subpaths.map((subpath) => {
|
|
52
|
-
const start =
|
|
228
|
+
const start = place(subpath.start);
|
|
53
229
|
return {
|
|
54
230
|
startXPt: start.xPt,
|
|
55
231
|
startYPt: start.yPt,
|
|
56
232
|
closed: subpath.closed,
|
|
57
233
|
segments: subpath.segments.map((segment) => {
|
|
58
234
|
if (segment.kind === "line") {
|
|
59
|
-
const to =
|
|
235
|
+
const to = place(segment.to);
|
|
60
236
|
return {
|
|
61
237
|
kind: "line",
|
|
62
238
|
xPt: to.xPt,
|
|
63
239
|
yPt: to.yPt
|
|
64
240
|
};
|
|
65
241
|
}
|
|
66
|
-
const control1 =
|
|
67
|
-
const control2 =
|
|
68
|
-
const to =
|
|
242
|
+
const control1 = place(segment.control1);
|
|
243
|
+
const control2 = place(segment.control2);
|
|
244
|
+
const to = place(segment.to);
|
|
69
245
|
return {
|
|
70
246
|
kind: "cubic",
|
|
71
247
|
c1xPt: control1.xPt,
|
|
@@ -95,8 +271,8 @@ function convertVector(vector, pageHeightPt, out) {
|
|
|
95
271
|
}
|
|
96
272
|
function convertPage(page, measurer, images) {
|
|
97
273
|
const items = [];
|
|
98
|
-
for (const
|
|
99
|
-
|
|
274
|
+
for (const entry of require_model_paint_order.mergeByPaintOrder(page.vectors, page.shapes)) if (entry.kind === "vector") convertVector(entry.value, page.size.heightPt, items);
|
|
275
|
+
else require_layout_slides.convertShape(entry.value, page.size.heightPt, measurer, images, items);
|
|
100
276
|
return {
|
|
101
277
|
widthPt: page.size.widthPt,
|
|
102
278
|
heightPt: page.size.heightPt,
|