@rowsncolumns/toolkit 24.4.2 → 24.4.4
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/dist/cjs/excel-parser/cfb-decryptor.d.ts +6 -0
- package/dist/cjs/excel-parser/cfb-decryptor.d.ts.map +1 -1
- package/dist/cjs/excel-parser/cfb-decryptor.js +6 -0
- package/dist/cjs/excel-parser/helpers.d.ts +9 -1
- package/dist/cjs/excel-parser/helpers.d.ts.map +1 -1
- package/dist/cjs/excel-parser/helpers.js +37 -0
- package/dist/cjs/excel-parser/interface.d.ts +15 -2
- package/dist/cjs/excel-parser/interface.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/base/index.d.ts +2 -0
- package/dist/cjs/excel-parser/plugins/base/index.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/base/index.js +3 -0
- package/dist/cjs/excel-parser/plugins/ods/index.d.ts +19 -0
- package/dist/cjs/excel-parser/plugins/ods/index.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/ods/index.js +676 -304
- package/dist/cjs/excel-parser/plugins/ods/styles.d.ts +43 -1
- package/dist/cjs/excel-parser/plugins/ods/styles.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/ods/styles.js +343 -45
- package/dist/cjs/excel-parser/plugins/xls/index.d.ts +55 -1
- package/dist/cjs/excel-parser/plugins/xls/index.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/xls/index.js +518 -6
- package/dist/cjs/excel-parser/plugins/xlsb/index.d.ts +4 -0
- package/dist/cjs/excel-parser/plugins/xlsb/index.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/xlsb/index.js +33 -14
- package/dist/cjs/excel-parser/plugins/xlsx/chartex.d.ts +37 -0
- package/dist/cjs/excel-parser/plugins/xlsx/chartex.d.ts.map +1 -0
- package/dist/cjs/excel-parser/plugins/xlsx/chartex.js +244 -0
- package/dist/cjs/excel-parser/plugins/xlsx/charts.d.ts +10 -0
- package/dist/cjs/excel-parser/plugins/xlsx/charts.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/xlsx/charts.js +68 -9
- package/dist/cjs/excel-parser/plugins/xlsx/drawing.d.ts +28 -1
- package/dist/cjs/excel-parser/plugins/xlsx/drawing.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/xlsx/drawing.js +155 -20
- package/dist/cjs/excel-parser/plugins/xlsx/form-controls.d.ts +70 -0
- package/dist/cjs/excel-parser/plugins/xlsx/form-controls.d.ts.map +1 -0
- package/dist/cjs/excel-parser/plugins/xlsx/form-controls.js +295 -0
- package/dist/cjs/excel-parser/plugins/xlsx/index.d.ts +35 -2
- package/dist/cjs/excel-parser/plugins/xlsx/index.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/xlsx/index.js +737 -257
- package/dist/cjs/excel-parser/plugins/xlsx/pivots.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/xlsx/pivots.js +125 -37
- package/dist/cjs/excel-parser/plugins/xlsx/sheet-views.d.ts +3 -0
- package/dist/cjs/excel-parser/plugins/xlsx/sheet-views.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/xlsx/sheet-views.js +4 -1
- package/dist/cjs/excel-parser/plugins/xlsx/styles.d.ts +15 -1
- package/dist/cjs/excel-parser/plugins/xlsx/styles.d.ts.map +1 -1
- package/dist/cjs/excel-parser/plugins/xlsx/styles.js +102 -6
- package/dist/cjs/excel-parser/registry.d.ts +7 -0
- package/dist/cjs/excel-parser/registry.d.ts.map +1 -1
- package/dist/cjs/excel-parser/registry.js +29 -0
- package/dist/cjs/excel-parser/types.d.ts +17 -2
- package/dist/cjs/excel-parser/types.d.ts.map +1 -1
- package/dist/cjs/excel-parser/workbook.d.ts +3 -0
- package/dist/cjs/excel-parser/workbook.d.ts.map +1 -1
- package/dist/cjs/excel-parser/workbook.js +24 -14
- package/dist/cjs/excel-parser/worker.js +131 -131
- package/dist/cjs/exporter/ods/ods-export.d.ts.map +1 -1
- package/dist/cjs/exporter/ods/ods-export.js +432 -175
- package/dist/cjs/exporter/xlsx/chart-builder.d.ts.map +1 -1
- package/dist/cjs/exporter/xlsx/chart-builder.js +215 -39
- package/dist/cjs/exporter/xlsx/chartex-builder.d.ts +36 -0
- package/dist/cjs/exporter/xlsx/chartex-builder.d.ts.map +1 -0
- package/dist/cjs/exporter/xlsx/chartex-builder.js +109 -0
- package/dist/cjs/exporter/xlsx/form-controls-builder.d.ts +61 -0
- package/dist/cjs/exporter/xlsx/form-controls-builder.d.ts.map +1 -0
- package/dist/cjs/exporter/xlsx/form-controls-builder.js +197 -0
- package/dist/cjs/exporter/xlsx/pivot-builder.d.ts +8 -0
- package/dist/cjs/exporter/xlsx/pivot-builder.d.ts.map +1 -1
- package/dist/cjs/exporter/xlsx/pivot-builder.js +141 -42
- package/dist/cjs/exporter/xlsx/style-builder.js +9 -3
- package/dist/cjs/exporter/xlsx/threaded-comments-builder.d.ts +7 -1
- package/dist/cjs/exporter/xlsx/threaded-comments-builder.d.ts.map +1 -1
- package/dist/cjs/exporter/xlsx/threaded-comments-builder.js +15 -3
- package/dist/cjs/exporter/xlsx/xlsx-export.d.ts +11 -2
- package/dist/cjs/exporter/xlsx/xlsx-export.d.ts.map +1 -1
- package/dist/cjs/exporter/xlsx/xlsx-export.js +991 -297
- package/dist/cjs/helpers/implicit-intersection.d.ts +16 -0
- package/dist/cjs/helpers/implicit-intersection.d.ts.map +1 -0
- package/dist/cjs/helpers/implicit-intersection.js +197 -0
- package/dist/cjs/print-settings.d.ts +105 -0
- package/dist/cjs/print-settings.d.ts.map +1 -0
- package/dist/cjs/print-settings.js +494 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/excel-parser/cfb-decryptor.d.ts +6 -0
- package/dist/esm/excel-parser/cfb-decryptor.d.ts.map +1 -1
- package/dist/esm/excel-parser/cfb-decryptor.js +6 -0
- package/dist/esm/excel-parser/helpers.d.ts +9 -1
- package/dist/esm/excel-parser/helpers.d.ts.map +1 -1
- package/dist/esm/excel-parser/helpers.js +34 -0
- package/dist/esm/excel-parser/interface.d.ts +15 -2
- package/dist/esm/excel-parser/interface.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/base/index.d.ts +2 -0
- package/dist/esm/excel-parser/plugins/base/index.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/base/index.js +3 -0
- package/dist/esm/excel-parser/plugins/ods/index.d.ts +19 -0
- package/dist/esm/excel-parser/plugins/ods/index.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/ods/index.js +347 -33
- package/dist/esm/excel-parser/plugins/ods/styles.d.ts +43 -1
- package/dist/esm/excel-parser/plugins/ods/styles.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/ods/styles.js +276 -2
- package/dist/esm/excel-parser/plugins/xls/index.d.ts +55 -1
- package/dist/esm/excel-parser/plugins/xls/index.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/xls/index.js +441 -3
- package/dist/esm/excel-parser/plugins/xlsb/index.d.ts +4 -0
- package/dist/esm/excel-parser/plugins/xlsb/index.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/xlsb/index.js +30 -9
- package/dist/esm/excel-parser/plugins/xlsx/chartex.d.ts +37 -0
- package/dist/esm/excel-parser/plugins/xlsx/chartex.d.ts.map +1 -0
- package/dist/esm/excel-parser/plugins/xlsx/chartex.js +199 -0
- package/dist/esm/excel-parser/plugins/xlsx/charts.d.ts +10 -0
- package/dist/esm/excel-parser/plugins/xlsx/charts.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/xlsx/charts.js +69 -6
- package/dist/esm/excel-parser/plugins/xlsx/drawing.d.ts +28 -1
- package/dist/esm/excel-parser/plugins/xlsx/drawing.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/xlsx/drawing.js +99 -0
- package/dist/esm/excel-parser/plugins/xlsx/form-controls.d.ts +70 -0
- package/dist/esm/excel-parser/plugins/xlsx/form-controls.d.ts.map +1 -0
- package/dist/esm/excel-parser/plugins/xlsx/form-controls.js +246 -0
- package/dist/esm/excel-parser/plugins/xlsx/index.d.ts +35 -2
- package/dist/esm/excel-parser/plugins/xlsx/index.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/xlsx/index.js +454 -32
- package/dist/esm/excel-parser/plugins/xlsx/pivots.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/xlsx/pivots.js +86 -6
- package/dist/esm/excel-parser/plugins/xlsx/sheet-views.d.ts +3 -0
- package/dist/esm/excel-parser/plugins/xlsx/sheet-views.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/xlsx/sheet-views.js +2 -0
- package/dist/esm/excel-parser/plugins/xlsx/styles.d.ts +15 -1
- package/dist/esm/excel-parser/plugins/xlsx/styles.d.ts.map +1 -1
- package/dist/esm/excel-parser/plugins/xlsx/styles.js +92 -2
- package/dist/esm/excel-parser/registry.d.ts +7 -0
- package/dist/esm/excel-parser/registry.d.ts.map +1 -1
- package/dist/esm/excel-parser/registry.js +19 -0
- package/dist/esm/excel-parser/types.d.ts +17 -2
- package/dist/esm/excel-parser/types.d.ts.map +1 -1
- package/dist/esm/excel-parser/workbook.d.ts +3 -0
- package/dist/esm/excel-parser/workbook.d.ts.map +1 -1
- package/dist/esm/excel-parser/workbook.js +19 -10
- package/dist/esm/excel-parser/worker.js +12 -18
- package/dist/esm/exporter/ods/ods-export.d.ts.map +1 -1
- package/dist/esm/exporter/ods/ods-export.js +306 -35
- package/dist/esm/exporter/xlsx/chart-builder.d.ts.map +1 -1
- package/dist/esm/exporter/xlsx/chart-builder.js +161 -28
- package/dist/esm/exporter/xlsx/chartex-builder.d.ts +36 -0
- package/dist/esm/exporter/xlsx/chartex-builder.d.ts.map +1 -0
- package/dist/esm/exporter/xlsx/chartex-builder.js +97 -0
- package/dist/esm/exporter/xlsx/form-controls-builder.d.ts +61 -0
- package/dist/esm/exporter/xlsx/form-controls-builder.d.ts.map +1 -0
- package/dist/esm/exporter/xlsx/form-controls-builder.js +173 -0
- package/dist/esm/exporter/xlsx/pivot-builder.d.ts +8 -0
- package/dist/esm/exporter/xlsx/pivot-builder.d.ts.map +1 -1
- package/dist/esm/exporter/xlsx/pivot-builder.js +104 -19
- package/dist/esm/exporter/xlsx/style-builder.js +9 -3
- package/dist/esm/exporter/xlsx/threaded-comments-builder.d.ts +7 -1
- package/dist/esm/exporter/xlsx/threaded-comments-builder.d.ts.map +1 -1
- package/dist/esm/exporter/xlsx/threaded-comments-builder.js +15 -3
- package/dist/esm/exporter/xlsx/xlsx-export.d.ts +11 -2
- package/dist/esm/exporter/xlsx/xlsx-export.d.ts.map +1 -1
- package/dist/esm/exporter/xlsx/xlsx-export.js +675 -64
- package/dist/esm/helpers/implicit-intersection.d.ts +16 -0
- package/dist/esm/helpers/implicit-intersection.d.ts.map +1 -0
- package/dist/esm/helpers/implicit-intersection.js +184 -0
- package/dist/esm/print-settings.d.ts +105 -0
- package/dist/esm/print-settings.d.ts.map +1 -0
- package/dist/esm/print-settings.js +422 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/xlsx.d.ts +14 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@operand` → `SINGLE(operand)`, for every implicit-intersection `@` in
|
|
3
|
+
* `formula`. A parenthesised operand contributes its content (`@(A1:A3*2)`
|
|
4
|
+
* → `SINGLE(A1:A3*2)`); a signed operand keeps its sign inside the call
|
|
5
|
+
* (`@-A1:A10` → `SINGLE(-A1:A10)`). An `@` with nothing it can bind to is
|
|
6
|
+
* left as is.
|
|
7
|
+
*/
|
|
8
|
+
export declare function encodeImplicitIntersection(formula: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* `_xlfn.SINGLE(x)` / `SINGLE(x)` → `@x` (or `@(x)` when `x` is more than a
|
|
11
|
+
* single, optionally signed, operand, e.g. `_xlfn.SINGLE(A1:A3*2)` →
|
|
12
|
+
* `@(A1:A3*2)` but `_xlfn.SINGLE(-A1:A3)` → `@-A1:A3`), for every such call
|
|
13
|
+
* in `formula`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function decodeImplicitIntersection(formula: string): string;
|
|
16
|
+
//# sourceMappingURL=implicit-intersection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"implicit-intersection.d.ts","sourceRoot":"","sources":["../../../helpers/implicit-intersection.ts"],"names":[],"mappings":"AA4GA;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA6BlE;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA+BlE"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Excel's implicit-intersection operator `@` (`=@A1:A10`, `=SUM(@rng)`,
|
|
3
|
+
* `=@INDEX(...)`) is a UI-only spelling: in sheet XML Excel 365 persists it
|
|
4
|
+
* as the `_xlfn.SINGLE(...)` function (a bare `@` in `<f>` is not valid file
|
|
5
|
+
* content), and re-renders `_xlfn.SINGLE(x)` as `@x` when it opens the file.
|
|
6
|
+
* These two transforms mirror that so a formula round-trips unchanged: the
|
|
7
|
+
* exporter encodes `@x` → `SINGLE(x)` (future-function qualification then
|
|
8
|
+
* adds the `_xlfn.` prefix) and the importer decodes `_xlfn.SINGLE(x)` → `@x`.
|
|
9
|
+
*
|
|
10
|
+
* Both work on the formula lexer's tokens, so `@` inside string literals and
|
|
11
|
+
* the this-row structured references `Table[@]` / `[@Column]` are left alone.
|
|
12
|
+
*/
|
|
13
|
+
import { lexify, tokenVocabulary } from "@rowsncolumns/calculator";
|
|
14
|
+
const T = tokenVocabulary;
|
|
15
|
+
const SINGLE_CALL = /^(?:_xlfn\.)?SINGLE\($/i;
|
|
16
|
+
const PREFIX_TOKENS = new Set([T.PlusOp.name, T.MinOp.name, T.At.name]);
|
|
17
|
+
const tokenName = (token) => token?.tokenType?.name;
|
|
18
|
+
const tokenEnd = (token) => (token.endOffset ?? token.startOffset) + 1;
|
|
19
|
+
const bracketDelta = (image) => {
|
|
20
|
+
let depth = 0;
|
|
21
|
+
for (const ch of image) {
|
|
22
|
+
if (ch === "[")
|
|
23
|
+
depth++;
|
|
24
|
+
else if (ch === "]")
|
|
25
|
+
depth--;
|
|
26
|
+
}
|
|
27
|
+
return depth;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Index of the last token of the primary operand that starts at `start`
|
|
31
|
+
* (a reference, name, constant, balanced call / paren group / array
|
|
32
|
+
* constant / structured reference, optionally behind a sheet prefix), or -1
|
|
33
|
+
* when no operand starts there.
|
|
34
|
+
*/
|
|
35
|
+
const primaryEnd = (tokens, start) => {
|
|
36
|
+
const token = tokens[start];
|
|
37
|
+
if (!token)
|
|
38
|
+
return -1;
|
|
39
|
+
switch (tokenName(token)) {
|
|
40
|
+
case T.Sheet.name:
|
|
41
|
+
case T.SheetQuoted.name:
|
|
42
|
+
case T.SheetRange.name:
|
|
43
|
+
return primaryEnd(tokens, start + 1);
|
|
44
|
+
case T.Function.name:
|
|
45
|
+
case T.OpenParen.name: {
|
|
46
|
+
let depth = 0;
|
|
47
|
+
for (let i = start; i < tokens.length; i++) {
|
|
48
|
+
const name = tokenName(tokens[i]);
|
|
49
|
+
if (name === T.Function.name || name === T.OpenParen.name)
|
|
50
|
+
depth++;
|
|
51
|
+
else if (name === T.CloseParen.name)
|
|
52
|
+
depth--;
|
|
53
|
+
if (depth === 0)
|
|
54
|
+
return i;
|
|
55
|
+
}
|
|
56
|
+
return -1;
|
|
57
|
+
}
|
|
58
|
+
case T.OpenCurlyParen.name: {
|
|
59
|
+
for (let i = start + 1; i < tokens.length; i++) {
|
|
60
|
+
if (tokenName(tokens[i]) === T.CloseCurlyParen.name)
|
|
61
|
+
return i;
|
|
62
|
+
}
|
|
63
|
+
return -1;
|
|
64
|
+
}
|
|
65
|
+
case T.TableName.name:
|
|
66
|
+
case T.TableColumnName.name:
|
|
67
|
+
case T.SpecialItem.name: {
|
|
68
|
+
let depth = 0;
|
|
69
|
+
for (let i = start; i < tokens.length; i++) {
|
|
70
|
+
depth += bracketDelta(tokens[i].image);
|
|
71
|
+
if (depth <= 0)
|
|
72
|
+
return i;
|
|
73
|
+
}
|
|
74
|
+
return -1;
|
|
75
|
+
}
|
|
76
|
+
case T.Cell.name:
|
|
77
|
+
case T.Name.name:
|
|
78
|
+
case T.Column.name:
|
|
79
|
+
case T.RowAbsolute.name:
|
|
80
|
+
case T.Number.name:
|
|
81
|
+
case T.String.name:
|
|
82
|
+
case T.Boolean.name:
|
|
83
|
+
case T.FormulaErrorT.name:
|
|
84
|
+
case T.RefError.name:
|
|
85
|
+
return start;
|
|
86
|
+
default:
|
|
87
|
+
return -1;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Like `primaryEnd`, but also swallows leading sign / `@` prefixes (`-A1:A10`,
|
|
92
|
+
* `+A1`, `@A1`) and `:` range continuations (`A1:A10`, `A:A`). The prefixes
|
|
93
|
+
* belong to the operand because `@`, like unary `-`, is applied after the
|
|
94
|
+
* prefixes to its right (`@-A1:A10` is `@(-A1:A10)`), so its persisted form
|
|
95
|
+
* is `SINGLE(-A1:A10)` — a `@` left in front of a sign would be invalid
|
|
96
|
+
* sheet-XML content.
|
|
97
|
+
*/
|
|
98
|
+
const operandEnd = (tokens, start) => {
|
|
99
|
+
while (PREFIX_TOKENS.has(tokenName(tokens[start]) ?? ""))
|
|
100
|
+
start++;
|
|
101
|
+
let end = primaryEnd(tokens, start);
|
|
102
|
+
if (end === -1)
|
|
103
|
+
return -1;
|
|
104
|
+
while (tokenName(tokens[end + 1]) === T.Colon.name) {
|
|
105
|
+
const next = primaryEnd(tokens, end + 2);
|
|
106
|
+
if (next === -1)
|
|
107
|
+
break;
|
|
108
|
+
end = next;
|
|
109
|
+
}
|
|
110
|
+
return end;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* `@operand` → `SINGLE(operand)`, for every implicit-intersection `@` in
|
|
114
|
+
* `formula`. A parenthesised operand contributes its content (`@(A1:A3*2)`
|
|
115
|
+
* → `SINGLE(A1:A3*2)`); a signed operand keeps its sign inside the call
|
|
116
|
+
* (`@-A1:A10` → `SINGLE(-A1:A10)`). An `@` with nothing it can bind to is
|
|
117
|
+
* left as is.
|
|
118
|
+
*/
|
|
119
|
+
export function encodeImplicitIntersection(formula) {
|
|
120
|
+
let current = formula;
|
|
121
|
+
for (;;) {
|
|
122
|
+
const tokens = lexify(current).tokens;
|
|
123
|
+
let replaced = false;
|
|
124
|
+
// Right-to-left so a nested `@` inside an operand is encoded first.
|
|
125
|
+
for (let i = tokens.length - 1; i >= 0; i--) {
|
|
126
|
+
if (tokenName(tokens[i]) !== T.At.name)
|
|
127
|
+
continue;
|
|
128
|
+
// `Table[@]` is the this-row item of a structured reference.
|
|
129
|
+
if (tokenName(tokens[i - 1]) === T.TableName.name)
|
|
130
|
+
continue;
|
|
131
|
+
const end = operandEnd(tokens, i + 1);
|
|
132
|
+
if (end === -1)
|
|
133
|
+
continue;
|
|
134
|
+
const first = tokens[i + 1];
|
|
135
|
+
const last = tokens[end];
|
|
136
|
+
const isParenGroup = tokenName(first) === T.OpenParen.name &&
|
|
137
|
+
primaryEnd(tokens, i + 1) === end;
|
|
138
|
+
const operand = isParenGroup
|
|
139
|
+
? current.slice(tokenEnd(first), last.startOffset)
|
|
140
|
+
: current.slice(first.startOffset, tokenEnd(last));
|
|
141
|
+
current = `${current.slice(0, tokens[i].startOffset)}SINGLE(${operand})${current.slice(tokenEnd(last))}`;
|
|
142
|
+
replaced = true;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
if (!replaced)
|
|
146
|
+
return current;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* `_xlfn.SINGLE(x)` / `SINGLE(x)` → `@x` (or `@(x)` when `x` is more than a
|
|
151
|
+
* single, optionally signed, operand, e.g. `_xlfn.SINGLE(A1:A3*2)` →
|
|
152
|
+
* `@(A1:A3*2)` but `_xlfn.SINGLE(-A1:A3)` → `@-A1:A3`), for every such call
|
|
153
|
+
* in `formula`.
|
|
154
|
+
*/
|
|
155
|
+
export function decodeImplicitIntersection(formula) {
|
|
156
|
+
let current = formula;
|
|
157
|
+
for (;;) {
|
|
158
|
+
const tokens = lexify(current).tokens;
|
|
159
|
+
let replaced = false;
|
|
160
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
161
|
+
const token = tokens[i];
|
|
162
|
+
if (tokenName(token) !== T.Function.name ||
|
|
163
|
+
!SINGLE_CALL.test(token.image)) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const end = primaryEnd(tokens, i);
|
|
167
|
+
if (end === -1)
|
|
168
|
+
continue;
|
|
169
|
+
const close = tokens[end];
|
|
170
|
+
const inner = current.slice(tokenEnd(token), close.startOffset).trim();
|
|
171
|
+
if (!inner)
|
|
172
|
+
continue;
|
|
173
|
+
const innerTokens = lexify(inner).tokens;
|
|
174
|
+
const isSingleOperand = innerTokens.length > 0 &&
|
|
175
|
+
operandEnd(innerTokens, 0) === innerTokens.length - 1;
|
|
176
|
+
const body = isSingleOperand ? inner : `(${inner})`;
|
|
177
|
+
current = `${current.slice(0, token.startOffset)}@${body}${current.slice(tokenEnd(close))}`;
|
|
178
|
+
replaced = true;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
if (!replaced)
|
|
182
|
+
return current;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { GridRange } from "@rowsncolumns/common-types";
|
|
2
|
+
import type { PrintHeaderFooter, PageMargins, PageSetup, PrintOptions, SheetPrintSettings, PrintTitles } from "@rowsncolumns/spreadsheet";
|
|
3
|
+
/**
|
|
4
|
+
* Shared helpers for the sheet `printSettings` facet: the builtin
|
|
5
|
+
* `_xlnm.Print_Area` / `_xlnm.Print_Titles` defined-name formulas (XLSX), the
|
|
6
|
+
* Excel header/footer code language (`&L&P of &N`), and the ODS page-layout
|
|
7
|
+
* equivalents (paper sizes, `style:print` tokens, `<text:*>` fields).
|
|
8
|
+
*/
|
|
9
|
+
export declare const PRINT_AREA_NAME = "_xlnm.Print_Area";
|
|
10
|
+
export declare const PRINT_TITLES_NAME = "_xlnm.Print_Titles";
|
|
11
|
+
export declare const isBuiltinPrintName: (name: string | undefined | null) => name is "_xlnm.Print_Area" | "_xlnm.Print_Titles";
|
|
12
|
+
/** Wrap a sheet name in single quotes when a formula reference requires it. */
|
|
13
|
+
export declare const quoteSheetNameForRef: (name: string) => string;
|
|
14
|
+
/** Split a defined-name formula on top-level commas (quote aware). */
|
|
15
|
+
export declare const splitDefinedNameAreas: (formula: string) => string[];
|
|
16
|
+
/** `'My Sheet'!$A$1:$B$2` → `{ sheetName: "My Sheet", ref: "$A$1:$B$2" }`. */
|
|
17
|
+
export declare const splitSheetQualifiedRef: (part: string) => {
|
|
18
|
+
sheetName?: string;
|
|
19
|
+
ref: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Parse a `_xlnm.Print_Area` formula into 1-based inclusive rectangles.
|
|
23
|
+
* Bands (`$1:$2`, `$A:$B`) and non-rectangular parts are rejected; the sheet
|
|
24
|
+
* name is taken from the first qualified part.
|
|
25
|
+
*/
|
|
26
|
+
export declare const parsePrintAreaFormula: (formula: string) => {
|
|
27
|
+
sheetName?: string;
|
|
28
|
+
ranges: GridRange[];
|
|
29
|
+
} | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Parse a `_xlnm.Print_Titles` formula (`'Sheet'!$A:$B,'Sheet'!$1:$2` — any
|
|
32
|
+
* order, either band alone) into the repeated row / column bands.
|
|
33
|
+
*/
|
|
34
|
+
export declare const parsePrintTitlesFormula: (formula: string) => {
|
|
35
|
+
sheetName?: string;
|
|
36
|
+
titles: PrintTitles;
|
|
37
|
+
} | undefined;
|
|
38
|
+
/** `'Sheet'!$A$1:$D$10,'Sheet'!$F$2:$G$5` (Excel's own multi-area shape). */
|
|
39
|
+
export declare const buildPrintAreaFormula: (sheetName: string, ranges: GridRange[]) => string | undefined;
|
|
40
|
+
/** Columns first, then rows — the order Excel writes. */
|
|
41
|
+
export declare const buildPrintTitlesFormula: (sheetName: string, titles: PrintTitles) => string | undefined;
|
|
42
|
+
export declare const isValidPrintRange: (range: GridRange) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Drop empty sub-objects / empty arrays; returns `undefined` when nothing
|
|
45
|
+
* is left so callers can omit the facet entirely.
|
|
46
|
+
*/
|
|
47
|
+
export declare const compactPrintSettings: (settings: SheetPrintSettings | null | undefined) => SheetPrintSettings | undefined;
|
|
48
|
+
export type HeaderFooterZones = {
|
|
49
|
+
left?: string;
|
|
50
|
+
center?: string;
|
|
51
|
+
right?: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Split an Excel header/footer code into its `&L` / `&C` / `&R` zones. Text
|
|
55
|
+
* before any zone marker belongs to the centre zone (Excel's rule). `&&`
|
|
56
|
+
* escapes are left untouched inside each zone.
|
|
57
|
+
*/
|
|
58
|
+
export declare const splitHeaderFooterZones: (code: string) => HeaderFooterZones;
|
|
59
|
+
export declare const joinHeaderFooterZones: (zones: HeaderFooterZones) => string;
|
|
60
|
+
export type HeaderFooterField = "page" | "pages" | "date" | "time" | "sheet" | "file" | "path";
|
|
61
|
+
export type HeaderFooterToken = {
|
|
62
|
+
type: "text";
|
|
63
|
+
text: string;
|
|
64
|
+
} | {
|
|
65
|
+
type: "field";
|
|
66
|
+
field: HeaderFooterField;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Tokenize one zone of header/footer code into literal text and field
|
|
70
|
+
* macros. Formatting codes (`&"Font,Style"`, `&12`, `&B`, `&Kff0000`, `&G`…)
|
|
71
|
+
* have no ODS counterpart and are dropped.
|
|
72
|
+
*/
|
|
73
|
+
export declare const tokenizeHeaderFooterZone: (zone: string) => HeaderFooterToken[];
|
|
74
|
+
export declare const headerFooterZoneFromTokens: (tokens: HeaderFooterToken[]) => string;
|
|
75
|
+
/** Every header/footer text on the facet is empty / absent. */
|
|
76
|
+
export declare const isHeaderFooterEmpty: (hf: PrintHeaderFooter | null | undefined) => boolean;
|
|
77
|
+
export declare const INCH_TO_CM = 2.54;
|
|
78
|
+
/** Portrait page size in centimetres for a paper-size code. */
|
|
79
|
+
export declare const paperSizeToCm: (code: number | null | undefined) => {
|
|
80
|
+
width: number;
|
|
81
|
+
height: number;
|
|
82
|
+
} | undefined;
|
|
83
|
+
/** Nearest paper-size code for a page (either orientation), or undefined. */
|
|
84
|
+
export declare const paperSizeFromCm: (widthCm: number, heightCm: number) => number | undefined;
|
|
85
|
+
/** Parse an ODF length (`2.54cm`, `1in`, `72pt`, `25.4mm`) to inches. */
|
|
86
|
+
export declare const odsLengthToInches: (value: string | undefined | null) => number | undefined;
|
|
87
|
+
export declare const inchesToOdsCm: (inches: number) => string;
|
|
88
|
+
/**
|
|
89
|
+
* `style:print` token list. LibreOffice's default (attribute absent) is
|
|
90
|
+
* `objects charts drawings zero-values`; `grid` / `headers` map to
|
|
91
|
+
* `<printOptions gridLines headings>`.
|
|
92
|
+
*/
|
|
93
|
+
export declare const buildOdsPrintTokens: (options: PrintOptions | null | undefined) => string;
|
|
94
|
+
export declare const parseOdsPrintTokens: (value: string | undefined | null) => PrintOptions | undefined;
|
|
95
|
+
export declare const odsTableCentering: (options: PrintOptions | null | undefined) => "both" | "horizontal" | "vertical" | undefined;
|
|
96
|
+
export declare const parseOdsTableCentering: (value: string | undefined | null) => Pick<PrintOptions, "horizontalCentered" | "verticalCentered">;
|
|
97
|
+
export declare const isPageSetupEmpty: (setup: PageSetup | null | undefined) => boolean;
|
|
98
|
+
export declare const isPageMarginsEmpty: (margins: PageMargins | null | undefined) => boolean;
|
|
99
|
+
/** Excel's "Normal" margins — what every untouched worksheet carries. */
|
|
100
|
+
export declare const DEFAULT_PAGE_MARGINS_IN: Required<{
|
|
101
|
+
[K in keyof PageMargins]: number;
|
|
102
|
+
}>;
|
|
103
|
+
/** `true` when the margins are exactly Excel's defaults (nothing to keep). */
|
|
104
|
+
export declare const isDefaultPageMargins: (margins: PageMargins | null | undefined) => boolean;
|
|
105
|
+
//# sourceMappingURL=print-settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print-settings.d.ts","sourceRoot":"","sources":["../../print-settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EACV,iBAAiB,EACjB,WAAW,EACX,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAOnC;;;;;GAKG;AAEH,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,iBAAiB,uBAAuB,CAAC;AAEtD,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,sDACV,CAAC;AAEzD,+EAA+E;AAC/E,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,WAGZ,CAAC;AAEtC,sEAAsE;AACtE,eAAO,MAAM,qBAAqB,GAAI,SAAS,MAAM,KAAG,MAAM,EAe7D,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,sBAAsB,GACjC,MAAM,MAAM,KACX;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAQnC,CAAC;AAKF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAChC,SAAS,MAAM,KACd;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,EAAE,CAAA;CAAE,GAAG,SAehD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,KACd;IAAE,SAAS,CAAC,EAAE,MAAM,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