@rowsncolumns/utils 9.2.44 → 9.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.
Files changed (51) hide show
  1. package/dist/cjs/formula-locale/formula-locale-data.generated.d.ts +44 -0
  2. package/dist/cjs/formula-locale/formula-locale-data.generated.d.ts.map +1 -0
  3. package/dist/cjs/formula-locale/formula-locale-data.generated.js +5567 -0
  4. package/dist/cjs/formula-locale.d.ts +159 -0
  5. package/dist/cjs/formula-locale.d.ts.map +1 -0
  6. package/dist/cjs/formula-locale.js +804 -0
  7. package/dist/cjs/index.d.ts +4 -0
  8. package/dist/cjs/index.d.ts.map +1 -1
  9. package/dist/cjs/index.js +4 -0
  10. package/dist/cjs/sparkline-groups.d.ts +102 -0
  11. package/dist/cjs/sparkline-groups.d.ts.map +1 -0
  12. package/dist/cjs/sparkline-groups.js +452 -0
  13. package/dist/cjs/string.d.ts +15 -0
  14. package/dist/cjs/string.d.ts.map +1 -1
  15. package/dist/cjs/string.js +46 -1
  16. package/dist/cjs/table-names.d.ts +55 -0
  17. package/dist/cjs/table-names.d.ts.map +1 -0
  18. package/dist/cjs/table-names.js +189 -0
  19. package/dist/cjs/table-styles.d.ts +9 -0
  20. package/dist/cjs/table-styles.d.ts.map +1 -1
  21. package/dist/cjs/table-styles.js +53 -1
  22. package/dist/cjs/table-totals.d.ts +31 -0
  23. package/dist/cjs/table-totals.d.ts.map +1 -0
  24. package/dist/cjs/table-totals.js +84 -0
  25. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  26. package/dist/esm/formula-locale/formula-locale-data.generated.d.ts +44 -0
  27. package/dist/esm/formula-locale/formula-locale-data.generated.d.ts.map +1 -0
  28. package/dist/esm/formula-locale/formula-locale-data.generated.js +5564 -0
  29. package/dist/esm/formula-locale.d.ts +159 -0
  30. package/dist/esm/formula-locale.d.ts.map +1 -0
  31. package/dist/esm/formula-locale.js +0 -0
  32. package/dist/esm/index.d.ts +4 -0
  33. package/dist/esm/index.d.ts.map +1 -1
  34. package/dist/esm/index.js +4 -0
  35. package/dist/esm/sparkline-groups.d.ts +102 -0
  36. package/dist/esm/sparkline-groups.d.ts.map +1 -0
  37. package/dist/esm/sparkline-groups.js +387 -0
  38. package/dist/esm/string.d.ts +15 -0
  39. package/dist/esm/string.d.ts.map +1 -1
  40. package/dist/esm/string.js +43 -0
  41. package/dist/esm/table-names.d.ts +55 -0
  42. package/dist/esm/table-names.d.ts.map +1 -0
  43. package/dist/esm/table-names.js +129 -0
  44. package/dist/esm/table-styles.d.ts +9 -0
  45. package/dist/esm/table-styles.d.ts.map +1 -1
  46. package/dist/esm/table-styles.js +34 -1
  47. package/dist/esm/table-totals.d.ts +31 -0
  48. package/dist/esm/table-totals.d.ts.map +1 -0
  49. package/dist/esm/table-totals.js +68 -0
  50. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  51. package/package.json +5 -3
@@ -0,0 +1,159 @@
1
+ import type { CalculatorFunction } from "@rowsncolumns/common-types";
2
+ import { type FormulaLocaleSyntaxData } from "./formula-locale/formula-locale-data.generated";
3
+ export type { FormulaLocaleDataEntry, FormulaLocaleSyntaxData, } from "./formula-locale/formula-locale-data.generated";
4
+ export { FORMULA_LOCALE_DATA, FORMULA_LOCALE_DATA_SOURCES, } from "./formula-locale/formula-locale-data.generated";
5
+ /**
6
+ * Locale-aware formula SYNTAX (rowsncolumns/spreadsheet#655), the way Excel does it: a workbook
7
+ * stores and evaluates every formula in one canonical dialect — English function names, `.` decimal
8
+ * mark, `,` argument separator, `{1,2;3,4}` array constants, `#VALUE!` error values — while the cell
9
+ * editor, formula bar, autocomplete, argument hints and error display speak the user's language
10
+ * (`=СУММ(1,5;A1)` in ru-RU, `=SUMME(1,5;A1)` in de-DE, `=SUMA(1,5;A1)` in es-ES).
11
+ *
12
+ * `localizeFormula` / `canonicalizeFormula` are exact inverses on well-formed canonical formulas: they
13
+ * rewrite ONLY the characters Excel localizes (number literals, separators, function names, TRUE/FALSE,
14
+ * error values) and copy everything else verbatim — strings, quoted sheet names, structured references
15
+ * (`Table1[[#Headers],[Qty]]` stays as typed), R1C1 text, operators, whitespace.
16
+ *
17
+ * Dictionaries come from the generated table (`formula-locale/formula-locale-data.generated.ts`,
18
+ * built from PhpSpreadsheet's Excel translations + Microsoft's localized function reference) and can be
19
+ * extended or overridden per application through {@link registerFormulaLocale} or an inline
20
+ * {@link FormulaLocaleDefinition}.
21
+ */
22
+ /** The separators that vary per locale, plus Excel's union operator (always the argument separator). */
23
+ export interface FormulaSyntax extends FormulaLocaleSyntaxData {
24
+ /** Reference-union operator (`SUM((A1:A2,B1:B2))`) — Excel uses the argument separator for it. */
25
+ unionOperator: string;
26
+ }
27
+ /** A resolved formula locale: syntax + bidirectional function/error dictionaries. */
28
+ export interface FormulaLocale extends FormulaSyntax {
29
+ /** The tag this locale was resolved from (`"de"`, `"pt-BR"`, or a registered custom id). */
30
+ id: string;
31
+ /** Display name of the language, in the language. */
32
+ name: string;
33
+ /** Canonical (uppercase English) function name → localized name. Names without an entry keep
34
+ * their English spelling. */
35
+ functions: ReadonlyMap<string, string>;
36
+ /** Case-folded localized function name → canonical name. */
37
+ canonicalFunctions: ReadonlyMap<string, string>;
38
+ /** Canonical error value (`#VALUE!`) → localized error value (`#ЗНАЧ!`). */
39
+ errors: ReadonlyMap<string, string>;
40
+ /** Case-folded localized error value → canonical error value. */
41
+ canonicalErrors: ReadonlyMap<string, string>;
42
+ /** `true` when the locale IS the canonical dialect (every translation is the identity), so
43
+ * callers can skip the scanner altogether. */
44
+ isCanonical: boolean;
45
+ }
46
+ /**
47
+ * An application-supplied locale: a new language, or overrides layered on a built-in one via
48
+ * `extends`. Every field is optional; omitted syntax fields inherit from the base (or from `en`), and
49
+ * a `null` dictionary entry removes the inherited translation so the name falls back to English.
50
+ */
51
+ export interface FormulaLocaleDefinition {
52
+ /** Identifier reported as {@link FormulaLocale.id}; defaults to the tag it is registered under. */
53
+ id?: string;
54
+ name?: string;
55
+ /** Built-in or registered tag whose syntax and dictionaries this definition starts from. */
56
+ extends?: string;
57
+ decimalSeparator?: string;
58
+ argumentSeparator?: string;
59
+ arrayColumnSeparator?: string;
60
+ arrayRowSeparator?: string;
61
+ /** Canonical function name → localized name (`null` = use the English name). */
62
+ functions?: Readonly<Record<string, string | null>>;
63
+ /** Canonical error value → localized error value (`null` = use the English value). */
64
+ errors?: Readonly<Record<string, string | null>>;
65
+ }
66
+ /** What {@link getFormulaLocale} accepts: a BCP-47 tag, an already-resolved locale, or an inline
67
+ * definition (resolved once per object identity). */
68
+ export type FormulaLocaleInput = string | FormulaLocale | FormulaLocaleDefinition;
69
+ /** Excel error values, in their canonical (English) spelling. */
70
+ export declare const CANONICAL_ERROR_VALUES: readonly string[];
71
+ /** The canonical dialect every formula is stored and evaluated in. */
72
+ export declare const CANONICAL_FORMULA_LOCALE: FormulaLocale;
73
+ /**
74
+ * Resolve a locale for formula syntax. Accepts a BCP-47 tag (`"ru-RU"` → the `ru` table, `"de-AT"` →
75
+ * `de`, `"de-CH"` → the Swiss row; unknown languages → canonical English), an already-resolved
76
+ * {@link FormulaLocale} (returned as-is), or an inline {@link FormulaLocaleDefinition} (resolved once
77
+ * per object). Resolution is memoized.
78
+ */
79
+ export declare const getFormulaLocale: (locale?: FormulaLocaleInput | null) => FormulaLocale;
80
+ /**
81
+ * Add a formula locale or override a built-in one for the whole application: `registerFormulaLocale
82
+ * ("de", { functions: { SUM: "SUMMEX" } })` layers onto the German table, `registerFormulaLocale("xx",
83
+ * { extends: "fr", argumentSeparator: "," })` derives a new language. Later registrations for the
84
+ * same tag replace earlier ones. Resolved locales are re-derived lazily.
85
+ */
86
+ export declare const registerFormulaLocale: (tag: string, definition: FormulaLocaleDefinition) => void;
87
+ /** Remove an application registration (built-in tables are never removed). */
88
+ export declare const unregisterFormulaLocale: (tag: string) => void;
89
+ /** Every tag with a formula-syntax table: the built-in languages plus application registrations. */
90
+ export declare const getFormulaLocaleTags: () => string[];
91
+ /** Localized spelling of a canonical function name (`SUM` → `СУММ`); names without a translation
92
+ * are returned unchanged. */
93
+ export declare const localizeFunctionName: (name: string, locale?: FormulaLocaleInput | null) => string;
94
+ /** Canonical (English, uppercase) spelling of a localized function name (`СУММ` → `SUM`); names
95
+ * without a translation are returned unchanged, so English names are accepted in every locale. */
96
+ export declare const canonicalizeFunctionName: (name: string, locale?: FormulaLocaleInput | null) => string;
97
+ /** Localized spelling of a canonical error value (`#VALUE!` → `#ЗНАЧ!`); other text passes through. */
98
+ export declare const localizeErrorValue: <T>(value: T, locale?: FormulaLocaleInput | null) => T | string;
99
+ /** Canonical spelling of a localized error value (`#ЗНАЧ!` → `#VALUE!`); other text passes through. */
100
+ export declare const canonicalizeErrorValue: <T>(value: T, locale?: FormulaLocaleInput | null) => T | string;
101
+ export interface TranslateFormulaOptions {
102
+ /**
103
+ * `preserve` (default) keeps the typed casing of names that have no translation in either
104
+ * direction; `upper` normalizes every known function name to uppercase, the way Excel does on
105
+ * commit (used to canonicalize test corpora).
106
+ */
107
+ functionNameCase?: "preserve" | "upper";
108
+ /** Build the offset maps (see {@link TranslatedFormula}); off by default. */
109
+ trackOffsets?: boolean;
110
+ }
111
+ export interface TranslatedFormula {
112
+ text: string;
113
+ /**
114
+ * `toOutput[i]` is the output offset of source offset `i` (`0 ≤ i ≤ source.length`). Inside a
115
+ * rewritten segment (a translated name, a swapped separator) every interior offset maps to the
116
+ * segment's start; segment boundaries map exactly. Present when `trackOffsets` was requested.
117
+ */
118
+ toOutput?: Int32Array;
119
+ /** Inverse of {@link toOutput}: `toSource[j]` for `0 ≤ j ≤ text.length`. */
120
+ toSource?: Int32Array;
121
+ }
122
+ /**
123
+ * Rewrite formula text from one locale's syntax to another's. This is the single scanner behind
124
+ * {@link localizeFormula} (canonical → locale) and {@link canonicalizeFormula} (locale → canonical);
125
+ * see the module comment for what is and is not rewritten.
126
+ */
127
+ export declare const translateFormula: (text: string, from: FormulaLocaleInput, to: FormulaLocaleInput, options?: TranslateFormulaOptions) => TranslatedFormula;
128
+ /**
129
+ * Canonical (stored) formula text → the locale's display syntax: `=SUM(1.5,A1)` → `=СУММ(1,5;A1)`
130
+ * (ru), `=SUMME(1,5;A1)` (de). Identity for the canonical locale.
131
+ */
132
+ export declare const localizeFormula: (formula: string, locale?: FormulaLocaleInput | null, options?: TranslateFormulaOptions) => string;
133
+ /**
134
+ * Text typed in the locale's syntax → canonical formula text for storage and evaluation:
135
+ * `=СУММ(1,5;A1)` → `=SUM(1.5,A1)`. Exact inverse of {@link localizeFormula} on canonical input;
136
+ * lenient on mixed input (an English name or `,` argument separator typed in a `;` locale is
137
+ * accepted as long as it is unambiguous).
138
+ */
139
+ export declare const canonicalizeFormula: (formula: string, locale?: FormulaLocaleInput | null, options?: TranslateFormulaOptions) => string;
140
+ /**
141
+ * What the editor / formula bar SHOWS for a stored cell entry: a formula in the locale's syntax, a
142
+ * typed error value in the locale's spelling, any other text unchanged (`1,5` typed in de-DE is a
143
+ * number literal the datatype parser already reads with the locale's separators).
144
+ */
145
+ export declare const localizeCellInput: (text: string, locale?: FormulaLocaleInput | null) => string;
146
+ /** Inverse of {@link localizeCellInput}: what the editor COMMITS — canonical formula text / error value. */
147
+ export declare const canonicalizeCellInput: (text: string, locale?: FormulaLocaleInput | null) => string;
148
+ /**
149
+ * Localize a function's documented syntax (`SUM(value1, [value2, ...])` → `СУММ(value1; [value2;
150
+ * ...])`): the leading name through the dictionary, every `,` outside double quotes through the
151
+ * argument separator. The square brackets here mark OPTIONAL arguments (not structured references),
152
+ * so — unlike {@link localizeFormula} — the separators inside them are localized too.
153
+ */
154
+ export declare const localizeFunctionSyntax: (syntax: string, locale?: FormulaLocaleInput | null) => string;
155
+ /** A {@link CalculatorFunction} with its name, syntax, example and usage lines localized. */
156
+ export declare const localizeFunctionDescription: (fn: CalculatorFunction, locale?: FormulaLocaleInput | null) => CalculatorFunction;
157
+ /** {@link localizeFunctionDescription} over a catalog; the same array instance for the canonical locale. */
158
+ export declare const localizeFunctionDescriptions: <T extends CalculatorFunction[] | null | undefined>(functions: T, locale?: FormulaLocaleInput | null) => T;
159
+ //# sourceMappingURL=formula-locale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formula-locale.d.ts","sourceRoot":"","sources":["../../formula-locale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGrE,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,gDAAgD,CAAC;AAExD,YAAY,EACV,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,gDAAgD,CAAC;AAExD;;;;;;;;;;;;;;;;GAgBG;AAEH,wGAAwG;AACxG,MAAM,WAAW,aAAc,SAAQ,uBAAuB;IAC5D,kGAAkG;IAClG,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,qFAAqF;AACrF,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,4FAA4F;IAC5F,EAAE,EAAE,MAAM,CAAC;IACX,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb;iCAC6B;IAC7B,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,4DAA4D;IAC5D,kBAAkB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,4EAA4E;IAC5E,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,iEAAiE;IACjE,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C;kDAC8C;IAC9C,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,mGAAmG;IACnG,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4FAA4F;IAC5F,OAAO,CA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S,kBAAkB,GAAG,IAAI,KAAG,MAa3F,CAAC;AAEF,6FAA6F;AAC7F,eAAO,MAAM,2BAA2B,GACtC,IAAI,kBAAkB,EACtB,SAAS,kBAAkB,GAAG,IAAI,KACjC,kBAUF,CAAC;AAEF,4GAA4G;AAC5G,eAAO,MAAM,4BAA4B,GAAI,CAAC,SAAS,kBAAkB,EAAE,GAAG,IAAI,GAAG,SAAS,EAC5F,WAAW,CAAC,EACZ,SAAS,kBAAkB,GAAG,IAAI,KACjC,CAIF,CAAC"}
Binary file
@@ -24,4 +24,8 @@ export * from "./content-hash";
24
24
  export * from "./shared-string-canonical";
25
25
  export * from "./keyboard";
26
26
  export * from "./sheet-span";
27
+ export * from "./formula-locale";
28
+ export * from "./table-names";
29
+ export * from "./table-totals";
30
+ export * from "./sparkline-groups";
27
31
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
package/dist/esm/index.js CHANGED
@@ -24,3 +24,7 @@ export * from "./content-hash";
24
24
  export * from "./shared-string-canonical";
25
25
  export * from "./keyboard";
26
26
  export * from "./sheet-span";
27
+ export * from "./formula-locale";
28
+ export * from "./table-names";
29
+ export * from "./table-totals";
30
+ export * from "./sparkline-groups";
@@ -0,0 +1,102 @@
1
+ import type { CellInterface, GridRange, SparkLineResultOptions } from "@rowsncolumns/common-types";
2
+ /**
3
+ * Excel sparkline groups (Insert → Sparklines → Line / Column / Win-Loss) on top of the
4
+ * `=SPARKLINE(dataRange, {options})` cell formula — the shape the XLSX importers of BOTH engines
5
+ * produce for an `<x14:sparklineGroup>` (one formula per `<x14:sparkline>`, the group's attributes
6
+ * as the option literal) and the shape the exporters fold back into a group (cells sharing one option
7
+ * fingerprint share one `<x14:sparklineGroup>`). A group therefore has no separate document object:
8
+ * it is the connected run of location cells whose SPARKLINE formulas carry identical options. That
9
+ * keeps live recalc, reference shifting on insert/delete and the round-trip as ordinary formula
10
+ * behavior on both engines.
11
+ */
12
+ export type SparklineGroupType = "line" | "column" | "winloss";
13
+ /** One sparkline of a group: the cell it paints in and the data range it charts. */
14
+ export type SparklineGroupMember = {
15
+ cell: CellInterface;
16
+ /** As written in the formula (optionally sheet-qualified, e.g. `Data!A2:E2`). */
17
+ dataRange: string;
18
+ };
19
+ /** The group options (everything but `charttype`, which is the group's `type`). */
20
+ export type SparklineGroupOptions = Omit<SparkLineResultOptions, "charttype">;
21
+ export type SparklineGroup = {
22
+ sheetId: number;
23
+ type: SparklineGroupType;
24
+ options: SparklineGroupOptions;
25
+ /** In location order (top → bottom, then left → right). */
26
+ members: SparklineGroupMember[];
27
+ };
28
+ export type ParsedSparklineFormula = {
29
+ dataRange: string;
30
+ options: SparkLineResultOptions;
31
+ };
32
+ export declare const isSparklineFormula: (formula: unknown) => formula is string;
33
+ /**
34
+ * `=SPARKLINE(A1:E1,{"charttype","column","color","#FF0000"})` → its data range and options with the
35
+ * keys canonicalized to `SparkLineResultOptions` (both option-literal shapes and the legacy
36
+ * `highpoint`/… spellings are accepted). `null` when the formula is not a SPARKLINE call.
37
+ */
38
+ export declare const parseSparklineFormula: (formula: string) => ParsedSparklineFormula | null;
39
+ /**
40
+ * The inverse of {@link parseSparklineFormula}: `=SPARKLINE(range)` when no option is set, else
41
+ * `=SPARKLINE(range,{"k",v,…})` in the importers' emission order. Unset, `false` and `line`
42
+ * (the default type) options are omitted.
43
+ */
44
+ export declare const buildSparklineFormula: (dataRange: string, options?: SparkLineResultOptions) => string;
45
+ export declare const sparklineTypeFromOptions: (options: SparkLineResultOptions | undefined) => SparklineGroupType;
46
+ /** Group identity: two SPARKLINE cells belong to one group when this string matches. */
47
+ export declare const sparklineOptionsFingerprint: (options: SparkLineResultOptions) => string;
48
+ export type ResolveSparklineGroupArgs = {
49
+ sheetId: number;
50
+ cell: CellInterface;
51
+ /** The user-entered formula of a cell (`undefined` for a non-formula cell). */
52
+ getFormula: (sheetId: number, rowIndex: number, columnIndex: number) => string | undefined;
53
+ /** Upper bound on the cells walked (a runaway sheet-wide fill would freeze the UI). */
54
+ maxCells?: number;
55
+ };
56
+ /**
57
+ * The sparkline group containing `cell`: the 4-connected run of SPARKLINE cells around it whose
58
+ * options match the cell's. `undefined` when the cell holds no SPARKLINE formula.
59
+ */
60
+ export declare const resolveSparklineGroup: ({ sheetId, cell, getFormula, maxCells, }: ResolveSparklineGroupArgs) => SparklineGroup | undefined;
61
+ export type ParsedRangeAddress = {
62
+ /** The sheet name as typed (quotes removed), `undefined` for a local reference. */
63
+ sheetName?: string;
64
+ range: GridRange;
65
+ };
66
+ /** `'Q1 Data'!A1:E5` / `Sheet1!A1` / `$A$1:$E$5` → its sheet name and grid range. */
67
+ export declare const parseRangeAddress: (address: string) => ParsedRangeAddress | null;
68
+ /** A grid range → `A1:E5` (a single cell → `A1`), optionally sheet-qualified. */
69
+ export declare const rangeToA1: (range: GridRange, sheetName?: string) => string;
70
+ export type PlanSparklineGroupArgs = {
71
+ /** Excel's "Data Range" (may be sheet-qualified). */
72
+ dataRange: string;
73
+ /** Excel's "Location Range" — a single row or column of cells on the group's sheet. */
74
+ locationRange: string;
75
+ };
76
+ export type SparklineGroupPlan = {
77
+ members: SparklineGroupMember[];
78
+ error?: undefined;
79
+ } | {
80
+ members?: undefined;
81
+ error: string;
82
+ };
83
+ /**
84
+ * Excel's Create Sparklines rule: one sparkline per location cell, each charting one row (or one
85
+ * column) of the data range. A single location cell charts the whole data range; otherwise the data
86
+ * range must span exactly as many rows, or exactly as many columns, as the location has cells.
87
+ */
88
+ export declare const planSparklineGroup: ({ dataRange, locationRange, }: PlanSparklineGroupArgs) => SparklineGroupPlan;
89
+ /**
90
+ * The location Excel's dialog is seeded with for a data selection: the column just right of the
91
+ * data (one sparkline per data row), or the cell right of a single-row selection.
92
+ */
93
+ export declare const defaultSparklineLocation: (data: GridRange) => GridRange;
94
+ /** The bounding range of a group's location cells (its members are a single row or column run). */
95
+ export declare const sparklineGroupLocation: (group: SparklineGroup) => GridRange;
96
+ /**
97
+ * The group's "Data Range" as Excel's Edit Group dialog shows it: the union of the members' ranges
98
+ * when they tile one rectangle by rows or columns; otherwise `undefined` (members chart unrelated
99
+ * ranges — Excel then shows the individual ranges only).
100
+ */
101
+ export declare const sparklineGroupDataRange: (group: SparklineGroup) => string | undefined;
102
+ //# sourceMappingURL=sparkline-groups.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparkline-groups.d.ts","sourceRoot":"","sources":["../../sparkline-groups.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AAIpC;;;;;;;;;GASG;AAEH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE/D,oFAAoF;AACpF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,aAAa,CAAC;IACpB,iFAAiF;IACjF,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,mFAAmF;AACnF,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,sBAAsB,EAAE,WAAW,CAAC,CAAC;AAE9E,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE,qBAAqB,CAAC;IAC/B,2DAA2D;IAC3D,OAAO,EAAE,oBAAoB,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS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