ooxml.js 6.1.0 → 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 +2 -2
- package/dist/typed/xlsx/build.cjs +12 -4
- package/dist/typed/xlsx/build.js +12 -4
- package/dist/typed/xlsx/conditional-format.cjs +519 -0
- package/dist/typed/xlsx/conditional-format.d.cts +16 -0
- package/dist/typed/xlsx/conditional-format.d.ts +16 -0
- package/dist/typed/xlsx/conditional-format.js +516 -0
- package/dist/typed/xlsx/content.cjs +11 -7
- package/dist/typed/xlsx/content.js +12 -8
- package/dist/typed/xlsx/data-validation.cjs +116 -0
- package/dist/typed/xlsx/data-validation.d.cts +11 -0
- package/dist/typed/xlsx/data-validation.d.ts +11 -0
- package/dist/typed/xlsx/data-validation.js +114 -0
- package/dist/typed/xlsx/rule-residue.cjs +29 -0
- package/dist/typed/xlsx/rule-residue.d.cts +7 -0
- package/dist/typed/xlsx/rule-residue.d.ts +7 -0
- package/dist/typed/xlsx/rule-residue.js +27 -0
- package/dist/typed/xlsx/sqref.cjs +24 -0
- package/dist/typed/xlsx/sqref.d.cts +7 -0
- package/dist/typed/xlsx/sqref.d.ts +7 -0
- package/dist/typed/xlsx/sqref.js +21 -0
- package/dist/typed/xlsx/styles.cjs +14 -2
- package/dist/typed/xlsx/styles.d.cts +5 -1
- package/dist/typed/xlsx/styles.d.ts +5 -1
- package/dist/typed/xlsx/styles.js +12 -3
- package/package.json +2 -2
|
@@ -0,0 +1,116 @@
|
|
|
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");
|
|
4
|
+
const require_typed_util = require("../util.cjs");
|
|
5
|
+
const require_typed_xlsx_util = require("./util.cjs");
|
|
6
|
+
const require_typed_xlsx_rule_residue = require("./rule-residue.cjs");
|
|
7
|
+
const require_typed_xlsx_sqref = require("./sqref.cjs");
|
|
8
|
+
//#region src/typed/xlsx/data-validation.ts
|
|
9
|
+
const DATA_VALIDATION_TYPES = /* @__PURE__ */ new Set([
|
|
10
|
+
"whole",
|
|
11
|
+
"decimal",
|
|
12
|
+
"list",
|
|
13
|
+
"date",
|
|
14
|
+
"time",
|
|
15
|
+
"textLength",
|
|
16
|
+
"custom"
|
|
17
|
+
]);
|
|
18
|
+
function isDataValidationType(value) {
|
|
19
|
+
return value !== void 0 && DATA_VALIDATION_TYPES.has(value);
|
|
20
|
+
}
|
|
21
|
+
function isSheetRuleOperator(value) {
|
|
22
|
+
return value === "between" || value === "notBetween" || value === "equal" || value === "notEqual" || value === "greaterThan" || value === "greaterThanOrEqual" || value === "lessThan" || value === "lessThanOrEqual";
|
|
23
|
+
}
|
|
24
|
+
const TYPES_WITHOUT_OPERATOR = /* @__PURE__ */ new Set(["list", "custom"]);
|
|
25
|
+
const MANAGED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
26
|
+
"type",
|
|
27
|
+
"errorStyle",
|
|
28
|
+
"operator",
|
|
29
|
+
"allowBlank",
|
|
30
|
+
"showInputMessage",
|
|
31
|
+
"showErrorMessage",
|
|
32
|
+
"promptTitle",
|
|
33
|
+
"prompt",
|
|
34
|
+
"errorTitle",
|
|
35
|
+
"error",
|
|
36
|
+
"sqref"
|
|
37
|
+
]);
|
|
38
|
+
function readDataValidations(worksheet) {
|
|
39
|
+
const validations = [];
|
|
40
|
+
const residueElements = [];
|
|
41
|
+
for (const container of require_typed_util.childrenWithTag(worksheet, "dataValidations")) for (const element of require_typed_util.childrenWithTag(container, "dataValidation")) {
|
|
42
|
+
const promoted = readDataValidation(element);
|
|
43
|
+
if (promoted === void 0) {
|
|
44
|
+
residueElements.push(element);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
validations.push(promoted);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
validations,
|
|
51
|
+
residueElements
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function readFormulaChild(element, tag) {
|
|
55
|
+
const child = require_typed_util.childrenWithTag(element, tag)[0];
|
|
56
|
+
return child === void 0 ? void 0 : require_typed_util.textContent(child);
|
|
57
|
+
}
|
|
58
|
+
function readDataValidation(element) {
|
|
59
|
+
const typeRaw = require_typed_util.attr(element, "type");
|
|
60
|
+
if (!isDataValidationType(typeRaw)) return;
|
|
61
|
+
const ranges = require_typed_xlsx_sqref.parseSqref(require_typed_util.attr(element, "sqref"));
|
|
62
|
+
if (ranges.length === 0) return;
|
|
63
|
+
const operatorRaw = require_typed_util.attr(element, "operator");
|
|
64
|
+
const operator = !TYPES_WITHOUT_OPERATOR.has(typeRaw) && isSheetRuleOperator(operatorRaw) ? operatorRaw : void 0;
|
|
65
|
+
const formula1 = readFormulaChild(element, "formula1");
|
|
66
|
+
const formula2 = operator === "between" || operator === "notBetween" ? readFormulaChild(element, "formula2") : void 0;
|
|
67
|
+
const promptTitle = require_typed_util.attr(element, "promptTitle");
|
|
68
|
+
const prompt = require_typed_util.attr(element, "prompt");
|
|
69
|
+
const errorTitle = require_typed_util.attr(element, "errorTitle");
|
|
70
|
+
const error = require_typed_util.attr(element, "error");
|
|
71
|
+
const errorStyleRaw = require_typed_util.attr(element, "errorStyle");
|
|
72
|
+
const errorStyle = errorStyleRaw === "warning" || errorStyleRaw === "information" ? errorStyleRaw : void 0;
|
|
73
|
+
const source = require_typed_xlsx_rule_residue.captureResidualAttributes(element, MANAGED_ATTRIBUTES);
|
|
74
|
+
return {
|
|
75
|
+
ranges,
|
|
76
|
+
type: typeRaw,
|
|
77
|
+
...operator === void 0 ? {} : { operator },
|
|
78
|
+
...formula1 === void 0 ? {} : { formula1 },
|
|
79
|
+
...formula2 === void 0 ? {} : { formula2 },
|
|
80
|
+
...require_typed_xlsx_util.readXmlBool(require_typed_util.attr(element, "allowBlank")) ? { allowBlank: true } : {},
|
|
81
|
+
...require_typed_xlsx_util.readXmlBool(require_typed_util.attr(element, "showInputMessage")) ? { showInputMessage: true } : {},
|
|
82
|
+
...promptTitle === void 0 ? {} : { promptTitle: require_typed_util.decodeEntities(promptTitle) },
|
|
83
|
+
...prompt === void 0 ? {} : { prompt: require_typed_util.decodeEntities(prompt) },
|
|
84
|
+
...require_typed_xlsx_util.readXmlBool(require_typed_util.attr(element, "showErrorMessage")) ? { showErrorMessage: true } : {},
|
|
85
|
+
...errorStyle === void 0 ? {} : { errorStyle },
|
|
86
|
+
...errorTitle === void 0 ? {} : { errorTitle: require_typed_util.decodeEntities(errorTitle) },
|
|
87
|
+
...error === void 0 ? {} : { error: require_typed_util.decodeEntities(error) },
|
|
88
|
+
...source === void 0 ? {} : { source }
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function buildDataValidationsElement(validations) {
|
|
92
|
+
if (validations.length === 0) return;
|
|
93
|
+
const elements = validations.map(buildDataValidationElement);
|
|
94
|
+
return require_xml_fragment.el("dataValidations", { count: String(elements.length) }, elements);
|
|
95
|
+
}
|
|
96
|
+
function buildDataValidationElement(validation) {
|
|
97
|
+
const attrs = require_typed_xlsx_rule_residue.residualAttributesFor(validation.source, "dataValidation");
|
|
98
|
+
attrs.type = validation.type;
|
|
99
|
+
attrs.sqref = require_typed_xlsx_sqref.formatSqref(validation.ranges);
|
|
100
|
+
if (validation.operator !== void 0) attrs.operator = validation.operator;
|
|
101
|
+
attrs.allowBlank = require_typed_xlsx_util.writeXmlBool(validation.allowBlank === true);
|
|
102
|
+
attrs.showInputMessage = require_typed_xlsx_util.writeXmlBool(validation.showInputMessage === true);
|
|
103
|
+
attrs.showErrorMessage = require_typed_xlsx_util.writeXmlBool(validation.showErrorMessage === true);
|
|
104
|
+
attrs.errorStyle = validation.errorStyle ?? "stop";
|
|
105
|
+
if (validation.promptTitle !== void 0) attrs.promptTitle = require_xml_entities.encodeXmlText(validation.promptTitle);
|
|
106
|
+
if (validation.prompt !== void 0) attrs.prompt = require_xml_entities.encodeXmlText(validation.prompt);
|
|
107
|
+
if (validation.errorTitle !== void 0) attrs.errorTitle = require_xml_entities.encodeXmlText(validation.errorTitle);
|
|
108
|
+
if (validation.error !== void 0) attrs.error = require_xml_entities.encodeXmlText(validation.error);
|
|
109
|
+
const children = [];
|
|
110
|
+
if (validation.formula1 !== void 0) children.push(require_xml_fragment.el("formula1", {}, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(validation.formula1))]));
|
|
111
|
+
if (validation.formula2 !== void 0) children.push(require_xml_fragment.el("formula2", {}, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(validation.formula2))]));
|
|
112
|
+
return require_xml_fragment.el("dataValidation", attrs, children);
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
exports.buildDataValidationsElement = buildDataValidationsElement;
|
|
116
|
+
exports.readDataValidations = readDataValidations;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { l as XmlElement } from "../../node-B6JX5CRX.cjs";
|
|
2
|
+
import { ContentSheetDataValidation } from "document-schema.js";
|
|
3
|
+
//#region src/typed/xlsx/data-validation.d.ts
|
|
4
|
+
interface DataValidationReadResult {
|
|
5
|
+
validations: ContentSheetDataValidation[];
|
|
6
|
+
residueElements: XmlElement[];
|
|
7
|
+
}
|
|
8
|
+
declare function readDataValidations(worksheet: XmlElement): DataValidationReadResult;
|
|
9
|
+
declare function buildDataValidationsElement(validations: readonly ContentSheetDataValidation[]): XmlElement | undefined;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DataValidationReadResult, buildDataValidationsElement, readDataValidations };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { l as XmlElement } from "../../node-B6JX5CRX.js";
|
|
2
|
+
import { ContentSheetDataValidation } from "document-schema.js";
|
|
3
|
+
//#region src/typed/xlsx/data-validation.d.ts
|
|
4
|
+
interface DataValidationReadResult {
|
|
5
|
+
validations: ContentSheetDataValidation[];
|
|
6
|
+
residueElements: XmlElement[];
|
|
7
|
+
}
|
|
8
|
+
declare function readDataValidations(worksheet: XmlElement): DataValidationReadResult;
|
|
9
|
+
declare function buildDataValidationsElement(validations: readonly ContentSheetDataValidation[]): XmlElement | undefined;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DataValidationReadResult, buildDataValidationsElement, readDataValidations };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { el, txt } from "../../xml/fragment.js";
|
|
2
|
+
import { encodeXmlText } from "../../xml/entities.js";
|
|
3
|
+
import { attr, childrenWithTag, decodeEntities, textContent } from "../util.js";
|
|
4
|
+
import { readXmlBool, writeXmlBool } from "./util.js";
|
|
5
|
+
import { captureResidualAttributes, residualAttributesFor } from "./rule-residue.js";
|
|
6
|
+
import { formatSqref, parseSqref } from "./sqref.js";
|
|
7
|
+
//#region src/typed/xlsx/data-validation.ts
|
|
8
|
+
const DATA_VALIDATION_TYPES = /* @__PURE__ */ new Set([
|
|
9
|
+
"whole",
|
|
10
|
+
"decimal",
|
|
11
|
+
"list",
|
|
12
|
+
"date",
|
|
13
|
+
"time",
|
|
14
|
+
"textLength",
|
|
15
|
+
"custom"
|
|
16
|
+
]);
|
|
17
|
+
function isDataValidationType(value) {
|
|
18
|
+
return value !== void 0 && DATA_VALIDATION_TYPES.has(value);
|
|
19
|
+
}
|
|
20
|
+
function isSheetRuleOperator(value) {
|
|
21
|
+
return value === "between" || value === "notBetween" || value === "equal" || value === "notEqual" || value === "greaterThan" || value === "greaterThanOrEqual" || value === "lessThan" || value === "lessThanOrEqual";
|
|
22
|
+
}
|
|
23
|
+
const TYPES_WITHOUT_OPERATOR = /* @__PURE__ */ new Set(["list", "custom"]);
|
|
24
|
+
const MANAGED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
25
|
+
"type",
|
|
26
|
+
"errorStyle",
|
|
27
|
+
"operator",
|
|
28
|
+
"allowBlank",
|
|
29
|
+
"showInputMessage",
|
|
30
|
+
"showErrorMessage",
|
|
31
|
+
"promptTitle",
|
|
32
|
+
"prompt",
|
|
33
|
+
"errorTitle",
|
|
34
|
+
"error",
|
|
35
|
+
"sqref"
|
|
36
|
+
]);
|
|
37
|
+
function readDataValidations(worksheet) {
|
|
38
|
+
const validations = [];
|
|
39
|
+
const residueElements = [];
|
|
40
|
+
for (const container of childrenWithTag(worksheet, "dataValidations")) for (const element of childrenWithTag(container, "dataValidation")) {
|
|
41
|
+
const promoted = readDataValidation(element);
|
|
42
|
+
if (promoted === void 0) {
|
|
43
|
+
residueElements.push(element);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
validations.push(promoted);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
validations,
|
|
50
|
+
residueElements
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function readFormulaChild(element, tag) {
|
|
54
|
+
const child = childrenWithTag(element, tag)[0];
|
|
55
|
+
return child === void 0 ? void 0 : textContent(child);
|
|
56
|
+
}
|
|
57
|
+
function readDataValidation(element) {
|
|
58
|
+
const typeRaw = attr(element, "type");
|
|
59
|
+
if (!isDataValidationType(typeRaw)) return;
|
|
60
|
+
const ranges = parseSqref(attr(element, "sqref"));
|
|
61
|
+
if (ranges.length === 0) return;
|
|
62
|
+
const operatorRaw = attr(element, "operator");
|
|
63
|
+
const operator = !TYPES_WITHOUT_OPERATOR.has(typeRaw) && isSheetRuleOperator(operatorRaw) ? operatorRaw : void 0;
|
|
64
|
+
const formula1 = readFormulaChild(element, "formula1");
|
|
65
|
+
const formula2 = operator === "between" || operator === "notBetween" ? readFormulaChild(element, "formula2") : void 0;
|
|
66
|
+
const promptTitle = attr(element, "promptTitle");
|
|
67
|
+
const prompt = attr(element, "prompt");
|
|
68
|
+
const errorTitle = attr(element, "errorTitle");
|
|
69
|
+
const error = attr(element, "error");
|
|
70
|
+
const errorStyleRaw = attr(element, "errorStyle");
|
|
71
|
+
const errorStyle = errorStyleRaw === "warning" || errorStyleRaw === "information" ? errorStyleRaw : void 0;
|
|
72
|
+
const source = captureResidualAttributes(element, MANAGED_ATTRIBUTES);
|
|
73
|
+
return {
|
|
74
|
+
ranges,
|
|
75
|
+
type: typeRaw,
|
|
76
|
+
...operator === void 0 ? {} : { operator },
|
|
77
|
+
...formula1 === void 0 ? {} : { formula1 },
|
|
78
|
+
...formula2 === void 0 ? {} : { formula2 },
|
|
79
|
+
...readXmlBool(attr(element, "allowBlank")) ? { allowBlank: true } : {},
|
|
80
|
+
...readXmlBool(attr(element, "showInputMessage")) ? { showInputMessage: true } : {},
|
|
81
|
+
...promptTitle === void 0 ? {} : { promptTitle: decodeEntities(promptTitle) },
|
|
82
|
+
...prompt === void 0 ? {} : { prompt: decodeEntities(prompt) },
|
|
83
|
+
...readXmlBool(attr(element, "showErrorMessage")) ? { showErrorMessage: true } : {},
|
|
84
|
+
...errorStyle === void 0 ? {} : { errorStyle },
|
|
85
|
+
...errorTitle === void 0 ? {} : { errorTitle: decodeEntities(errorTitle) },
|
|
86
|
+
...error === void 0 ? {} : { error: decodeEntities(error) },
|
|
87
|
+
...source === void 0 ? {} : { source }
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function buildDataValidationsElement(validations) {
|
|
91
|
+
if (validations.length === 0) return;
|
|
92
|
+
const elements = validations.map(buildDataValidationElement);
|
|
93
|
+
return el("dataValidations", { count: String(elements.length) }, elements);
|
|
94
|
+
}
|
|
95
|
+
function buildDataValidationElement(validation) {
|
|
96
|
+
const attrs = residualAttributesFor(validation.source, "dataValidation");
|
|
97
|
+
attrs.type = validation.type;
|
|
98
|
+
attrs.sqref = formatSqref(validation.ranges);
|
|
99
|
+
if (validation.operator !== void 0) attrs.operator = validation.operator;
|
|
100
|
+
attrs.allowBlank = writeXmlBool(validation.allowBlank === true);
|
|
101
|
+
attrs.showInputMessage = writeXmlBool(validation.showInputMessage === true);
|
|
102
|
+
attrs.showErrorMessage = writeXmlBool(validation.showErrorMessage === true);
|
|
103
|
+
attrs.errorStyle = validation.errorStyle ?? "stop";
|
|
104
|
+
if (validation.promptTitle !== void 0) attrs.promptTitle = encodeXmlText(validation.promptTitle);
|
|
105
|
+
if (validation.prompt !== void 0) attrs.prompt = encodeXmlText(validation.prompt);
|
|
106
|
+
if (validation.errorTitle !== void 0) attrs.errorTitle = encodeXmlText(validation.errorTitle);
|
|
107
|
+
if (validation.error !== void 0) attrs.error = encodeXmlText(validation.error);
|
|
108
|
+
const children = [];
|
|
109
|
+
if (validation.formula1 !== void 0) children.push(el("formula1", {}, [txt(encodeXmlText(validation.formula1))]));
|
|
110
|
+
if (validation.formula2 !== void 0) children.push(el("formula2", {}, [txt(encodeXmlText(validation.formula2))]));
|
|
111
|
+
return el("dataValidation", attrs, children);
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
export { buildDataValidationsElement, readDataValidations };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_parse = require("../../xml/parse.cjs");
|
|
3
|
+
const require_xml_build = require("../../xml/build.cjs");
|
|
4
|
+
//#region src/typed/xlsx/rule-residue.ts
|
|
5
|
+
function captureResidualAttributes(element, managed) {
|
|
6
|
+
const residual = element.attributes.filter((attribute) => !managed.has(attribute.name));
|
|
7
|
+
if (residual.length === 0) return;
|
|
8
|
+
return {
|
|
9
|
+
format: "xlsx",
|
|
10
|
+
xml: require_xml_build.buildXml([{
|
|
11
|
+
type: "element",
|
|
12
|
+
tag: element.tag,
|
|
13
|
+
attributes: residual,
|
|
14
|
+
children: []
|
|
15
|
+
}])
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function residualAttributesFor(source, expectedTag) {
|
|
19
|
+
if (source?.format !== "xlsx") return {};
|
|
20
|
+
const nodes = require_xml_parse.parseXml(source.xml);
|
|
21
|
+
const first = nodes[0];
|
|
22
|
+
if (nodes.length !== 1 || first?.type !== "element" || first.tag !== expectedTag) return {};
|
|
23
|
+
const result = {};
|
|
24
|
+
for (const attribute of first.attributes) result[attribute.name] = attribute.value;
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.captureResidualAttributes = captureResidualAttributes;
|
|
29
|
+
exports.residualAttributesFor = residualAttributesFor;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { l as XmlElement } from "../../node-B6JX5CRX.cjs";
|
|
2
|
+
import { SourceResidue } from "document-schema.js";
|
|
3
|
+
//#region src/typed/xlsx/rule-residue.d.ts
|
|
4
|
+
declare function captureResidualAttributes(element: XmlElement, managed: ReadonlySet<string>): SourceResidue | undefined;
|
|
5
|
+
declare function residualAttributesFor(source: SourceResidue | undefined, expectedTag: string): Record<string, string>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { captureResidualAttributes, residualAttributesFor };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { l as XmlElement } from "../../node-B6JX5CRX.js";
|
|
2
|
+
import { SourceResidue } from "document-schema.js";
|
|
3
|
+
//#region src/typed/xlsx/rule-residue.d.ts
|
|
4
|
+
declare function captureResidualAttributes(element: XmlElement, managed: ReadonlySet<string>): SourceResidue | undefined;
|
|
5
|
+
declare function residualAttributesFor(source: SourceResidue | undefined, expectedTag: string): Record<string, string>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { captureResidualAttributes, residualAttributesFor };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { parseXml } from "../../xml/parse.js";
|
|
2
|
+
import { buildXml } from "../../xml/build.js";
|
|
3
|
+
//#region src/typed/xlsx/rule-residue.ts
|
|
4
|
+
function captureResidualAttributes(element, managed) {
|
|
5
|
+
const residual = element.attributes.filter((attribute) => !managed.has(attribute.name));
|
|
6
|
+
if (residual.length === 0) return;
|
|
7
|
+
return {
|
|
8
|
+
format: "xlsx",
|
|
9
|
+
xml: buildXml([{
|
|
10
|
+
type: "element",
|
|
11
|
+
tag: element.tag,
|
|
12
|
+
attributes: residual,
|
|
13
|
+
children: []
|
|
14
|
+
}])
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function residualAttributesFor(source, expectedTag) {
|
|
18
|
+
if (source?.format !== "xlsx") return {};
|
|
19
|
+
const nodes = parseXml(source.xml);
|
|
20
|
+
const first = nodes[0];
|
|
21
|
+
if (nodes.length !== 1 || first?.type !== "element" || first.tag !== expectedTag) return {};
|
|
22
|
+
const result = {};
|
|
23
|
+
for (const attribute of first.attributes) result[attribute.name] = attribute.value;
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { captureResidualAttributes, residualAttributesFor };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let document_schema_js = require("document-schema.js");
|
|
3
|
+
//#region src/typed/xlsx/sqref.ts
|
|
4
|
+
function parseSqref(sqref) {
|
|
5
|
+
if (sqref === void 0) return [];
|
|
6
|
+
const ranges = [];
|
|
7
|
+
for (const token of sqref.split(/\s+/)) {
|
|
8
|
+
if (token === "") continue;
|
|
9
|
+
const range = (0, document_schema_js.parseRangeReference)(token);
|
|
10
|
+
if (range !== void 0) ranges.push(range);
|
|
11
|
+
}
|
|
12
|
+
return ranges;
|
|
13
|
+
}
|
|
14
|
+
function formatSqrefRange(range) {
|
|
15
|
+
if (range.startRow === range.endRow && range.startColumn === range.endColumn) return (0, document_schema_js.cellReference)(range.startRow, range.startColumn);
|
|
16
|
+
return (0, document_schema_js.rangeReference)(range);
|
|
17
|
+
}
|
|
18
|
+
function formatSqref(ranges) {
|
|
19
|
+
return ranges.map(formatSqrefRange).join(" ");
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.formatSqref = formatSqref;
|
|
23
|
+
exports.formatSqrefRange = formatSqrefRange;
|
|
24
|
+
exports.parseSqref = parseSqref;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContentSheetRange } from "document-schema.js";
|
|
2
|
+
//#region src/typed/xlsx/sqref.d.ts
|
|
3
|
+
declare function parseSqref(sqref: string | undefined): ContentSheetRange[];
|
|
4
|
+
declare function formatSqrefRange(range: ContentSheetRange): string;
|
|
5
|
+
declare function formatSqref(ranges: readonly ContentSheetRange[]): string;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { formatSqref, formatSqrefRange, parseSqref };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContentSheetRange } from "document-schema.js";
|
|
2
|
+
//#region src/typed/xlsx/sqref.d.ts
|
|
3
|
+
declare function parseSqref(sqref: string | undefined): ContentSheetRange[];
|
|
4
|
+
declare function formatSqrefRange(range: ContentSheetRange): string;
|
|
5
|
+
declare function formatSqref(ranges: readonly ContentSheetRange[]): string;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { formatSqref, formatSqrefRange, parseSqref };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { cellReference, parseRangeReference, rangeReference } from "document-schema.js";
|
|
2
|
+
//#region src/typed/xlsx/sqref.ts
|
|
3
|
+
function parseSqref(sqref) {
|
|
4
|
+
if (sqref === void 0) return [];
|
|
5
|
+
const ranges = [];
|
|
6
|
+
for (const token of sqref.split(/\s+/)) {
|
|
7
|
+
if (token === "") continue;
|
|
8
|
+
const range = parseRangeReference(token);
|
|
9
|
+
if (range !== void 0) ranges.push(range);
|
|
10
|
+
}
|
|
11
|
+
return ranges;
|
|
12
|
+
}
|
|
13
|
+
function formatSqrefRange(range) {
|
|
14
|
+
if (range.startRow === range.endRow && range.startColumn === range.endColumn) return cellReference(range.startRow, range.startColumn);
|
|
15
|
+
return rangeReference(range);
|
|
16
|
+
}
|
|
17
|
+
function formatSqref(ranges) {
|
|
18
|
+
return ranges.map(formatSqrefRange).join(" ");
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { formatSqref, formatSqrefRange, parseSqref };
|
|
@@ -83,8 +83,7 @@ const BORDER_WEIGHT_UPPER_PT = {
|
|
|
83
83
|
thin: 1.125,
|
|
84
84
|
medium: 1.875
|
|
85
85
|
};
|
|
86
|
-
function
|
|
87
|
-
const colorEl = require_typed_util.childrenWithTag(container, colorTag)[0];
|
|
86
|
+
function colorFromElement(colorEl) {
|
|
88
87
|
if (colorEl === void 0) return;
|
|
89
88
|
const raw = require_typed_util.attr(colorEl, "rgb");
|
|
90
89
|
if (raw === void 0) return;
|
|
@@ -96,6 +95,9 @@ function readColorRgb(container, colorTag) {
|
|
|
96
95
|
return;
|
|
97
96
|
}
|
|
98
97
|
}
|
|
98
|
+
function readColorRgb(container, colorTag) {
|
|
99
|
+
return colorFromElement(require_typed_util.childrenWithTag(container, colorTag)[0]);
|
|
100
|
+
}
|
|
99
101
|
function readFillBackground(fill) {
|
|
100
102
|
const patternFill = require_typed_util.childrenWithTag(fill, "patternFill")[0];
|
|
101
103
|
if (patternFill === void 0 || require_typed_util.attr(patternFill, "patternType") !== "solid") return;
|
|
@@ -182,6 +184,13 @@ function readCellStyles(pkg) {
|
|
|
182
184
|
return entry;
|
|
183
185
|
});
|
|
184
186
|
}
|
|
187
|
+
function readDxfElements(pkg) {
|
|
188
|
+
const styleSheet = require_typed_util.rootElement(pkg.parts[STYLES_PATH]);
|
|
189
|
+
if (styleSheet === void 0) return [];
|
|
190
|
+
const dxfsEl = require_typed_util.childrenWithTag(styleSheet, "dxfs")[0];
|
|
191
|
+
if (dxfsEl === void 0) return [];
|
|
192
|
+
return require_typed_util.childrenWithTag(dxfsEl, "dxf");
|
|
193
|
+
}
|
|
185
194
|
function parseChildIndex(value) {
|
|
186
195
|
if (value === void 0) return;
|
|
187
196
|
const n = Number.parseInt(value, 10);
|
|
@@ -342,5 +351,8 @@ exports.DEFAULT_CELL_FORMAT_INDEX = DEFAULT_CELL_FORMAT_INDEX;
|
|
|
342
351
|
exports.GENERAL_NUM_FMT_ID = GENERAL_NUM_FMT_ID;
|
|
343
352
|
exports.RESERVED_BORDER_INDICES = RESERVED_BORDER_INDICES;
|
|
344
353
|
exports.RESERVED_FILL_INDICES = RESERVED_FILL_INDICES;
|
|
354
|
+
exports.colorFromElement = colorFromElement;
|
|
345
355
|
exports.readCellFormatCodes = readCellFormatCodes;
|
|
346
356
|
exports.readCellStyles = readCellStyles;
|
|
357
|
+
exports.readColorRgb = readColorRgb;
|
|
358
|
+
exports.readDxfElements = readDxfElements;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { l as XmlElement } from "../../node-B6JX5CRX.cjs";
|
|
1
2
|
import { r as Package } from "../../package-DMk9fuTI.cjs";
|
|
2
3
|
import { CellNumberFormat } from "./number-format.cjs";
|
|
3
4
|
import { Alignment, Color, ContentCellBorders } from "document-schema.js";
|
|
@@ -10,7 +11,10 @@ interface CellStyleEntry {
|
|
|
10
11
|
alignment?: Alignment;
|
|
11
12
|
verticalAlignment?: "top" | "middle" | "bottom";
|
|
12
13
|
}
|
|
14
|
+
declare function colorFromElement(colorEl: XmlElement | undefined): Color | undefined;
|
|
15
|
+
declare function readColorRgb(container: XmlElement, colorTag: string): Color | undefined;
|
|
13
16
|
declare function readCellStyles(pkg: Package): readonly CellStyleEntry[];
|
|
17
|
+
declare function readDxfElements(pkg: Package): readonly XmlElement[];
|
|
14
18
|
declare function readCellFormatCodes(pkg: Package): readonly (string | undefined)[];
|
|
15
19
|
declare const DEFAULT_CELL_FORMAT_INDEX = 0;
|
|
16
20
|
interface DeclaredNumberFormat {
|
|
@@ -84,4 +88,4 @@ declare const RESERVED_BORDER_INDICES: {
|
|
|
84
88
|
readonly firstReal: 1;
|
|
85
89
|
};
|
|
86
90
|
//#endregion
|
|
87
|
-
export { CellFormatDecoration, CellFormatRecord, CellFormatTable, CellStyleEntry, DEFAULT_CELL_FORMAT_INDEX, DeclaredBorder, DeclaredFill, DeclaredNumberFormat, GENERAL_NUM_FMT_ID, RESERVED_BORDER_INDICES, RESERVED_FILL_INDICES, readCellFormatCodes, readCellStyles };
|
|
91
|
+
export { CellFormatDecoration, CellFormatRecord, CellFormatTable, CellStyleEntry, DEFAULT_CELL_FORMAT_INDEX, DeclaredBorder, DeclaredFill, DeclaredNumberFormat, GENERAL_NUM_FMT_ID, RESERVED_BORDER_INDICES, RESERVED_FILL_INDICES, colorFromElement, readCellFormatCodes, readCellStyles, readColorRgb, readDxfElements };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { l as XmlElement } from "../../node-B6JX5CRX.js";
|
|
1
2
|
import { r as Package } from "../../package-otZYrxiO.js";
|
|
2
3
|
import { CellNumberFormat } from "./number-format.js";
|
|
3
4
|
import { Alignment, Color, ContentCellBorders } from "document-schema.js";
|
|
@@ -10,7 +11,10 @@ interface CellStyleEntry {
|
|
|
10
11
|
alignment?: Alignment;
|
|
11
12
|
verticalAlignment?: "top" | "middle" | "bottom";
|
|
12
13
|
}
|
|
14
|
+
declare function colorFromElement(colorEl: XmlElement | undefined): Color | undefined;
|
|
15
|
+
declare function readColorRgb(container: XmlElement, colorTag: string): Color | undefined;
|
|
13
16
|
declare function readCellStyles(pkg: Package): readonly CellStyleEntry[];
|
|
17
|
+
declare function readDxfElements(pkg: Package): readonly XmlElement[];
|
|
14
18
|
declare function readCellFormatCodes(pkg: Package): readonly (string | undefined)[];
|
|
15
19
|
declare const DEFAULT_CELL_FORMAT_INDEX = 0;
|
|
16
20
|
interface DeclaredNumberFormat {
|
|
@@ -84,4 +88,4 @@ declare const RESERVED_BORDER_INDICES: {
|
|
|
84
88
|
readonly firstReal: 1;
|
|
85
89
|
};
|
|
86
90
|
//#endregion
|
|
87
|
-
export { CellFormatDecoration, CellFormatRecord, CellFormatTable, CellStyleEntry, DEFAULT_CELL_FORMAT_INDEX, DeclaredBorder, DeclaredFill, DeclaredNumberFormat, GENERAL_NUM_FMT_ID, RESERVED_BORDER_INDICES, RESERVED_FILL_INDICES, readCellFormatCodes, readCellStyles };
|
|
91
|
+
export { CellFormatDecoration, CellFormatRecord, CellFormatTable, CellStyleEntry, DEFAULT_CELL_FORMAT_INDEX, DeclaredBorder, DeclaredFill, DeclaredNumberFormat, GENERAL_NUM_FMT_ID, RESERVED_BORDER_INDICES, RESERVED_FILL_INDICES, colorFromElement, readCellFormatCodes, readCellStyles, readColorRgb, readDxfElements };
|
|
@@ -82,8 +82,7 @@ const BORDER_WEIGHT_UPPER_PT = {
|
|
|
82
82
|
thin: 1.125,
|
|
83
83
|
medium: 1.875
|
|
84
84
|
};
|
|
85
|
-
function
|
|
86
|
-
const colorEl = childrenWithTag(container, colorTag)[0];
|
|
85
|
+
function colorFromElement(colorEl) {
|
|
87
86
|
if (colorEl === void 0) return;
|
|
88
87
|
const raw = attr(colorEl, "rgb");
|
|
89
88
|
if (raw === void 0) return;
|
|
@@ -95,6 +94,9 @@ function readColorRgb(container, colorTag) {
|
|
|
95
94
|
return;
|
|
96
95
|
}
|
|
97
96
|
}
|
|
97
|
+
function readColorRgb(container, colorTag) {
|
|
98
|
+
return colorFromElement(childrenWithTag(container, colorTag)[0]);
|
|
99
|
+
}
|
|
98
100
|
function readFillBackground(fill) {
|
|
99
101
|
const patternFill = childrenWithTag(fill, "patternFill")[0];
|
|
100
102
|
if (patternFill === void 0 || attr(patternFill, "patternType") !== "solid") return;
|
|
@@ -181,6 +183,13 @@ function readCellStyles(pkg) {
|
|
|
181
183
|
return entry;
|
|
182
184
|
});
|
|
183
185
|
}
|
|
186
|
+
function readDxfElements(pkg) {
|
|
187
|
+
const styleSheet = rootElement(pkg.parts[STYLES_PATH]);
|
|
188
|
+
if (styleSheet === void 0) return [];
|
|
189
|
+
const dxfsEl = childrenWithTag(styleSheet, "dxfs")[0];
|
|
190
|
+
if (dxfsEl === void 0) return [];
|
|
191
|
+
return childrenWithTag(dxfsEl, "dxf");
|
|
192
|
+
}
|
|
184
193
|
function parseChildIndex(value) {
|
|
185
194
|
if (value === void 0) return;
|
|
186
195
|
const n = Number.parseInt(value, 10);
|
|
@@ -336,4 +345,4 @@ const RESERVED_BORDER_INDICES = {
|
|
|
336
345
|
firstReal: FIRST_REAL_BORDER_INDEX
|
|
337
346
|
};
|
|
338
347
|
//#endregion
|
|
339
|
-
export { CellFormatTable, DEFAULT_CELL_FORMAT_INDEX, GENERAL_NUM_FMT_ID, RESERVED_BORDER_INDICES, RESERVED_FILL_INDICES, readCellFormatCodes, readCellStyles };
|
|
348
|
+
export { CellFormatTable, DEFAULT_CELL_FORMAT_INDEX, GENERAL_NUM_FMT_ID, RESERVED_BORDER_INDICES, RESERVED_FILL_INDICES, colorFromElement, readCellFormatCodes, readCellStyles, readColorRgb, readDxfElements };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ooxml.js",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "Type-safe, lossless round-trip conversion between OOXML packages (docx, pptx, xlsx) and JSON, built on Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"packageManager": "pnpm@11.6.0",
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"archive-codec": "^1.2.0",
|
|
84
|
-
"document-schema.js": "^5.
|
|
84
|
+
"document-schema.js": "^5.2.0",
|
|
85
85
|
"fast-xml-parser": "^5.10.1",
|
|
86
86
|
"fflate": "^0.8.3",
|
|
87
87
|
"zod": "^4.4.3"
|