@rowsncolumns/utils 9.2.35

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 (154) hide show
  1. package/LICENSE.md +100 -0
  2. package/dist/cjs/array.d.ts +3 -0
  3. package/dist/cjs/array.d.ts.map +1 -0
  4. package/dist/cjs/array.js +19 -0
  5. package/dist/cjs/cell-data-helpers.d.ts +19 -0
  6. package/dist/cjs/cell-data-helpers.d.ts.map +1 -0
  7. package/dist/cjs/cell-data-helpers.js +64 -0
  8. package/dist/cjs/color.d.ts +20 -0
  9. package/dist/cjs/color.d.ts.map +1 -0
  10. package/dist/cjs/color.js +168 -0
  11. package/dist/cjs/colors.d.ts +2 -0
  12. package/dist/cjs/colors.d.ts.map +1 -0
  13. package/dist/cjs/colors.js +78 -0
  14. package/dist/cjs/conditional-format.d.ts +49 -0
  15. package/dist/cjs/conditional-format.d.ts.map +1 -0
  16. package/dist/cjs/conditional-format.js +227 -0
  17. package/dist/cjs/content-hash.d.ts +16 -0
  18. package/dist/cjs/content-hash.d.ts.map +1 -0
  19. package/dist/cjs/content-hash.js +72 -0
  20. package/dist/cjs/data-validation.d.ts +54 -0
  21. package/dist/cjs/data-validation.d.ts.map +1 -0
  22. package/dist/cjs/data-validation.js +249 -0
  23. package/dist/cjs/date.d.ts +15 -0
  24. package/dist/cjs/date.d.ts.map +1 -0
  25. package/dist/cjs/date.js +56 -0
  26. package/dist/cjs/dom.d.ts +10 -0
  27. package/dist/cjs/dom.d.ts.map +1 -0
  28. package/dist/cjs/dom.js +97 -0
  29. package/dist/cjs/formatter.d.ts +22 -0
  30. package/dist/cjs/formatter.d.ts.map +1 -0
  31. package/dist/cjs/formatter.js +264 -0
  32. package/dist/cjs/formula-refs.d.ts +7 -0
  33. package/dist/cjs/formula-refs.d.ts.map +1 -0
  34. package/dist/cjs/formula-refs.js +54 -0
  35. package/dist/cjs/formula.d.ts +80 -0
  36. package/dist/cjs/formula.d.ts.map +1 -0
  37. package/dist/cjs/formula.js +401 -0
  38. package/dist/cjs/index.d.ts +24 -0
  39. package/dist/cjs/index.d.ts.map +1 -0
  40. package/dist/cjs/index.js +26 -0
  41. package/dist/cjs/locale.d.ts +34 -0
  42. package/dist/cjs/locale.d.ts.map +1 -0
  43. package/dist/cjs/locale.js +260 -0
  44. package/dist/cjs/log.d.ts +4 -0
  45. package/dist/cjs/log.d.ts.map +1 -0
  46. package/dist/cjs/log.js +28 -0
  47. package/dist/cjs/memoize.d.ts +18 -0
  48. package/dist/cjs/memoize.d.ts.map +1 -0
  49. package/dist/cjs/memoize.js +128 -0
  50. package/dist/cjs/numbers.d.ts +19 -0
  51. package/dist/cjs/numbers.d.ts.map +1 -0
  52. package/dist/cjs/numbers.js +47 -0
  53. package/dist/cjs/selection.d.ts +88 -0
  54. package/dist/cjs/selection.d.ts.map +1 -0
  55. package/dist/cjs/selection.js +368 -0
  56. package/dist/cjs/shared-string-canonical.d.ts +18 -0
  57. package/dist/cjs/shared-string-canonical.d.ts.map +1 -0
  58. package/dist/cjs/shared-string-canonical.js +74 -0
  59. package/dist/cjs/sort.d.ts +15 -0
  60. package/dist/cjs/sort.d.ts.map +1 -0
  61. package/dist/cjs/sort.js +44 -0
  62. package/dist/cjs/string.d.ts +74 -0
  63. package/dist/cjs/string.d.ts.map +1 -0
  64. package/dist/cjs/string.js +237 -0
  65. package/dist/cjs/table-styles.d.ts +56 -0
  66. package/dist/cjs/table-styles.d.ts.map +1 -0
  67. package/dist/cjs/table-styles.js +362 -0
  68. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  69. package/dist/cjs/typeguards.d.ts +4 -0
  70. package/dist/cjs/typeguards.d.ts.map +1 -0
  71. package/dist/cjs/typeguards.js +15 -0
  72. package/dist/cjs/uuid.d.ts +8 -0
  73. package/dist/cjs/uuid.d.ts.map +1 -0
  74. package/dist/cjs/uuid.js +30 -0
  75. package/dist/cjs/vitest.config.d.ts +3 -0
  76. package/dist/cjs/vitest.config.d.ts.map +1 -0
  77. package/dist/cjs/vitest.config.js +9 -0
  78. package/dist/esm/array.d.ts +3 -0
  79. package/dist/esm/array.d.ts.map +1 -0
  80. package/dist/esm/array.js +14 -0
  81. package/dist/esm/cell-data-helpers.d.ts +19 -0
  82. package/dist/esm/cell-data-helpers.d.ts.map +1 -0
  83. package/dist/esm/cell-data-helpers.js +39 -0
  84. package/dist/esm/color.d.ts +20 -0
  85. package/dist/esm/color.d.ts.map +1 -0
  86. package/dist/esm/color.js +152 -0
  87. package/dist/esm/colors.d.ts +2 -0
  88. package/dist/esm/colors.d.ts.map +1 -0
  89. package/dist/esm/colors.js +75 -0
  90. package/dist/esm/conditional-format.d.ts +49 -0
  91. package/dist/esm/conditional-format.d.ts.map +1 -0
  92. package/dist/esm/conditional-format.js +219 -0
  93. package/dist/esm/content-hash.d.ts +16 -0
  94. package/dist/esm/content-hash.d.ts.map +1 -0
  95. package/dist/esm/content-hash.js +68 -0
  96. package/dist/esm/data-validation.d.ts +54 -0
  97. package/dist/esm/data-validation.d.ts.map +1 -0
  98. package/dist/esm/data-validation.js +237 -0
  99. package/dist/esm/date.d.ts +15 -0
  100. package/dist/esm/date.d.ts.map +1 -0
  101. package/dist/esm/date.js +46 -0
  102. package/dist/esm/dom.d.ts +10 -0
  103. package/dist/esm/dom.d.ts.map +1 -0
  104. package/dist/esm/dom.js +90 -0
  105. package/dist/esm/formatter.d.ts +22 -0
  106. package/dist/esm/formatter.d.ts.map +1 -0
  107. package/dist/esm/formatter.js +253 -0
  108. package/dist/esm/formula-refs.d.ts +7 -0
  109. package/dist/esm/formula-refs.d.ts.map +1 -0
  110. package/dist/esm/formula-refs.js +49 -0
  111. package/dist/esm/formula.d.ts +80 -0
  112. package/dist/esm/formula.d.ts.map +1 -0
  113. package/dist/esm/formula.js +298 -0
  114. package/dist/esm/index.d.ts +24 -0
  115. package/dist/esm/index.d.ts.map +1 -0
  116. package/dist/esm/index.js +23 -0
  117. package/dist/esm/locale.d.ts +34 -0
  118. package/dist/esm/locale.d.ts.map +1 -0
  119. package/dist/esm/locale.js +223 -0
  120. package/dist/esm/log.d.ts +4 -0
  121. package/dist/esm/log.d.ts.map +1 -0
  122. package/dist/esm/log.js +3 -0
  123. package/dist/esm/memoize.d.ts +18 -0
  124. package/dist/esm/memoize.d.ts.map +1 -0
  125. package/dist/esm/memoize.js +95 -0
  126. package/dist/esm/numbers.d.ts +19 -0
  127. package/dist/esm/numbers.d.ts.map +1 -0
  128. package/dist/esm/numbers.js +40 -0
  129. package/dist/esm/selection.d.ts +88 -0
  130. package/dist/esm/selection.d.ts.map +1 -0
  131. package/dist/esm/selection.js +311 -0
  132. package/dist/esm/shared-string-canonical.d.ts +18 -0
  133. package/dist/esm/shared-string-canonical.d.ts.map +1 -0
  134. package/dist/esm/shared-string-canonical.js +68 -0
  135. package/dist/esm/sort.d.ts +15 -0
  136. package/dist/esm/sort.d.ts.map +1 -0
  137. package/dist/esm/sort.js +39 -0
  138. package/dist/esm/string.d.ts +74 -0
  139. package/dist/esm/string.d.ts.map +1 -0
  140. package/dist/esm/string.js +213 -0
  141. package/dist/esm/table-styles.d.ts +56 -0
  142. package/dist/esm/table-styles.d.ts.map +1 -0
  143. package/dist/esm/table-styles.js +367 -0
  144. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  145. package/dist/esm/typeguards.d.ts +4 -0
  146. package/dist/esm/typeguards.d.ts.map +1 -0
  147. package/dist/esm/typeguards.js +7 -0
  148. package/dist/esm/uuid.d.ts +8 -0
  149. package/dist/esm/uuid.d.ts.map +1 -0
  150. package/dist/esm/uuid.js +25 -0
  151. package/dist/esm/vitest.config.d.ts +3 -0
  152. package/dist/esm/vitest.config.d.ts.map +1 -0
  153. package/dist/esm/vitest.config.js +7 -0
  154. package/package.json +49 -0
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLongDateFormat = exports.getDefaultDateTimeFormat = exports.getDefaultTimeFormat = exports.getDefaultDateFormat = exports.getLocaleDateParts = exports.getLocaleDatePartsNotMemoized = exports.getCurrentLocale = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var memoize_1 = require("./memoize");
6
+ var defaultLocale;
7
+ var getCurrentLocale = function () {
8
+ if (defaultLocale) {
9
+ return defaultLocale;
10
+ }
11
+ try {
12
+ defaultLocale = Intl.DateTimeFormat().resolvedOptions().locale;
13
+ }
14
+ catch (err) {
15
+ defaultLocale = "en-US";
16
+ }
17
+ return defaultLocale;
18
+ };
19
+ exports.getCurrentLocale = getCurrentLocale;
20
+ /**
21
+ * PARSER metadata only: relative day/month order for a locale, with the
22
+ * year deliberately moved last so the date-parser's regex can use fixed
23
+ * capture-group positions. This ordering is WRONG for display in
24
+ * year-first locales (ja-JP, hu-HU, sv-SE, …) — formatting helpers must
25
+ * use the `formatToParts`-driven builders below instead.
26
+ */
27
+ var getLocaleDatePartsNotMemoized = function (locale) {
28
+ var e_1, _a;
29
+ var parts = [];
30
+ try {
31
+ var formatObj = new Intl.DateTimeFormat(locale).formatToParts(new Date());
32
+ try {
33
+ for (var formatObj_1 = tslib_1.__values(formatObj), formatObj_1_1 = formatObj_1.next(); !formatObj_1_1.done; formatObj_1_1 = formatObj_1.next()) {
34
+ var part = formatObj_1_1.value;
35
+ if (part.type === "day") {
36
+ parts.push(["day", "d", "dd"]);
37
+ }
38
+ if (part.type === "month") {
39
+ parts.push(["month", "m", "mm"]);
40
+ }
41
+ if (part.type === "year") {
42
+ parts.push(["year", "yy", "yyyy"]);
43
+ }
44
+ }
45
+ }
46
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
47
+ finally {
48
+ try {
49
+ if (formatObj_1_1 && !formatObj_1_1.done && (_a = formatObj_1.return)) _a.call(formatObj_1);
50
+ }
51
+ finally { if (e_1) throw e_1.error; }
52
+ }
53
+ // Always move year to last to prevent
54
+ // errors in Regex (duplicate capture group)
55
+ parts.sort(function (_, _a) {
56
+ var _b = tslib_1.__read(_a, 1), typeB = _b[0];
57
+ if (typeB === "year") {
58
+ return -1;
59
+ }
60
+ return 1;
61
+ });
62
+ }
63
+ catch (err) {
64
+ // en-US
65
+ parts = [
66
+ ["month", "m", "mm"],
67
+ ["day", "d", "dd"],
68
+ ["year", "yy", "yyyy"],
69
+ ];
70
+ }
71
+ return parts;
72
+ };
73
+ exports.getLocaleDatePartsNotMemoized = getLocaleDatePartsNotMemoized;
74
+ exports.getLocaleDateParts = (0, memoize_1.memoize)(exports.getLocaleDatePartsNotMemoized);
75
+ /**
76
+ * Fixed sample instant used to discover a locale's date/time pattern via
77
+ * `formatToParts`. Every numeric field is single-digit (5 April 2008,
78
+ * 05:09:07 UTC) so locale padding is observable: a locale that renders
79
+ * "05" for the day pads days, one that renders "5" does not.
80
+ */
81
+ var FORMAT_SAMPLE_DATE = new Date(Date.UTC(2008, 3, 5, 5, 9, 7));
82
+ /**
83
+ * Literal characters that spreadsheet number-format syntax accepts
84
+ * unquoted inside a date/time section. Anything else (words such as
85
+ * "г.", CJK markers such as 年/月/日, bidi controls, commas — which
86
+ * numfmt/Excel read as the thousands/scaling operator, e.g. hu-HU's
87
+ * `.,` literal — …) must be wrapped in double quotes.
88
+ */
89
+ var SAFE_PATTERN_LITERAL = /^[\s./:-]*$/;
90
+ var escapePatternLiteral = function (value) {
91
+ if (SAFE_PATTERN_LITERAL.test(value)) {
92
+ return value;
93
+ }
94
+ // Number-format strings cannot represent an embedded double quote —
95
+ // no locale literal contains one, so dropping it is safe.
96
+ return "\"".concat(value.replace(/"/g, ""), "\"");
97
+ };
98
+ var numericFieldToken = function (short, long, partValue) { return (partValue.length === 2 ? long : short); };
99
+ var dateFieldToken = function (part) {
100
+ switch (part.type) {
101
+ case "day":
102
+ return numericFieldToken("d", "dd", part.value);
103
+ case "month":
104
+ return numericFieldToken("m", "mm", part.value);
105
+ case "year":
106
+ return part.value.length === 2 ? "yy" : "yyyy";
107
+ case "literal":
108
+ return escapePatternLiteral(part.value);
109
+ default:
110
+ // era and other exotic fields have no spreadsheet token — skip.
111
+ return undefined;
112
+ }
113
+ };
114
+ var buildPatternFromParts = function (parts, toToken) {
115
+ var e_2, _a;
116
+ var pattern = "";
117
+ try {
118
+ for (var parts_1 = tslib_1.__values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) {
119
+ var part = parts_1_1.value;
120
+ var token = toToken(part);
121
+ if (token !== undefined) {
122
+ pattern += token;
123
+ }
124
+ }
125
+ }
126
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
127
+ finally {
128
+ try {
129
+ if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1);
130
+ }
131
+ finally { if (e_2) throw e_2.error; }
132
+ }
133
+ // A locale's pattern may end (or begin) with a literal that belongs to
134
+ // trailing fields we skipped (e.g. an era) — trim stray whitespace.
135
+ return pattern.trim();
136
+ };
137
+ var getDefaultDateFormatMemoized = (0, memoize_1.memoize)(function (locale) {
138
+ try {
139
+ var parts = new Intl.DateTimeFormat(locale, {
140
+ calendar: "gregory",
141
+ numberingSystem: "latn",
142
+ year: "numeric",
143
+ month: "numeric",
144
+ day: "numeric",
145
+ timeZone: "UTC",
146
+ }).formatToParts(FORMAT_SAMPLE_DATE);
147
+ var pattern = buildPatternFromParts(parts, dateFieldToken);
148
+ return pattern || "m/d/yyyy";
149
+ }
150
+ catch (err) {
151
+ return "m/d/yyyy";
152
+ }
153
+ });
154
+ /**
155
+ * Default numeric (short) date pattern for a locale, preserving the
156
+ * locale's field order, separators, literal text and zero-padding as
157
+ * reported by `Intl.DateTimeFormat(...).formatToParts()` — e.g.
158
+ * de-DE → `d.m.yyyy`, hu-HU → `yyyy. mm. dd.`, en-CA → `yyyy-mm-dd`.
159
+ */
160
+ var getDefaultDateFormat = function (locale) {
161
+ if (locale === void 0) { locale = (0, exports.getCurrentLocale)(); }
162
+ return getDefaultDateFormatMemoized(locale);
163
+ };
164
+ exports.getDefaultDateFormat = getDefaultDateFormat;
165
+ var getDefaultTimeFormatMemoized = (0, memoize_1.memoize)(function (locale, precision) {
166
+ try {
167
+ var parts = new Intl.DateTimeFormat(locale, tslib_1.__assign(tslib_1.__assign({ numberingSystem: "latn", hour: "numeric", minute: "numeric" }, (precision === "second" ? { second: "numeric" } : {})), { timeZone: "UTC" })).formatToParts(FORMAT_SAMPLE_DATE);
168
+ var pattern = buildPatternFromParts(parts, function (part) {
169
+ switch (part.type) {
170
+ case "hour":
171
+ return numericFieldToken("h", "hh", part.value);
172
+ case "minute":
173
+ return "mm";
174
+ case "second":
175
+ return "ss";
176
+ case "dayPeriod":
177
+ // Spreadsheet syntax only has the English AM/PM token; its
178
+ // presence is what switches the hour field to 12-hour mode.
179
+ return "AM/PM";
180
+ case "literal":
181
+ return escapePatternLiteral(part.value);
182
+ default:
183
+ return undefined;
184
+ }
185
+ });
186
+ var fallback = precision === "second" ? "h:mm:ss AM/PM" : "h:mm AM/PM";
187
+ return pattern || fallback;
188
+ }
189
+ catch (err) {
190
+ return precision === "second" ? "h:mm:ss AM/PM" : "h:mm AM/PM";
191
+ }
192
+ });
193
+ /**
194
+ * Default time pattern for a locale, honoring its 12/24-hour convention,
195
+ * separators and hour padding — e.g. en-US → `h:mm:ss AM/PM`,
196
+ * de-DE → `hh:mm:ss`, fi-FI → `h.mm.ss`.
197
+ */
198
+ var getDefaultTimeFormat = function (locale, precision) {
199
+ if (locale === void 0) { locale = (0, exports.getCurrentLocale)(); }
200
+ if (precision === void 0) { precision = "second"; }
201
+ return getDefaultTimeFormatMemoized(locale, precision);
202
+ };
203
+ exports.getDefaultTimeFormat = getDefaultTimeFormat;
204
+ var getDefaultDateTimeFormat = function (locale) {
205
+ return (0, exports.getDefaultDateFormat)(locale) + " " + (0, exports.getDefaultTimeFormat)(locale);
206
+ };
207
+ exports.getDefaultDateTimeFormat = getDefaultDateTimeFormat;
208
+ var getLongDateFormatMemoized = (0, memoize_1.memoize)(function (locale) {
209
+ try {
210
+ var parts = new Intl.DateTimeFormat(locale, {
211
+ calendar: "gregory",
212
+ numberingSystem: "latn",
213
+ weekday: "long",
214
+ year: "numeric",
215
+ month: "long",
216
+ day: "numeric",
217
+ timeZone: "UTC",
218
+ }).formatToParts(FORMAT_SAMPLE_DATE);
219
+ var pattern = buildPatternFromParts(parts, function (part) {
220
+ switch (part.type) {
221
+ case "weekday":
222
+ return "dddd";
223
+ case "month":
224
+ // CJK locales keep the month numeric even in long dates
225
+ // ("9月"): Intl reports the digit with 月/월 as a literal, and
226
+ // the formatter's own `mmmm` would re-append the marker.
227
+ return /^\d+$/.test(part.value)
228
+ ? numericFieldToken("m", "mm", part.value)
229
+ : "mmmm";
230
+ case "day":
231
+ return numericFieldToken("d", "dd", part.value);
232
+ case "year":
233
+ return part.value.length === 2 ? "yy" : "yyyy";
234
+ case "literal":
235
+ return escapePatternLiteral(part.value);
236
+ default:
237
+ return undefined;
238
+ }
239
+ });
240
+ if (!pattern) {
241
+ return "[$-".concat(locale, "]dddd, mmmm d, yyyy");
242
+ }
243
+ return "[$-".concat(locale, "]").concat(pattern);
244
+ }
245
+ catch (err) {
246
+ return "[$-".concat(locale, "]dddd, mmmm d, yyyy");
247
+ }
248
+ });
249
+ /**
250
+ * Long (full) date pattern for a locale, following the locale's own
251
+ * field placement and literal text — e.g. de-DE →
252
+ * `[$-de-DE]dddd, d. mmmm yyyy`, ja-JP → `[$-ja-JP]yyyy"年"m"月"d"日"dddd`.
253
+ * Localized weekday/month names are best-effort: they render through the
254
+ * spreadsheet formatter's own locale data via the `[$-locale]` tag.
255
+ */
256
+ var getLongDateFormat = function (locale) {
257
+ if (locale === void 0) { locale = (0, exports.getCurrentLocale)(); }
258
+ return getLongDateFormatMemoized(locale);
259
+ };
260
+ exports.getLongDateFormat = getLongDateFormat;
@@ -0,0 +1,4 @@
1
+ export declare const log: (...args: any[]) => false | void;
2
+ export declare const debug: (...args: any[]) => false | void;
3
+ export declare const error: (...args: any[]) => false | void;
4
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../log.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,GAAG,GAAI,GAAG,MAAM,GAAG,EAAE,iBAC6B,CAAC;AAChE,eAAO,MAAM,KAAK,GAAI,GAAG,MAAM,GAAG,EAAE,iBAC6B,CAAC;AAClE,eAAO,MAAM,KAAK,GAAI,GAAG,MAAM,GAAG,EAAE,iBAC6B,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.error = exports.debug = exports.log = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var log = function () {
6
+ var args = [];
7
+ for (var _i = 0; _i < arguments.length; _i++) {
8
+ args[_i] = arguments[_i];
9
+ }
10
+ return process.env.NODE_ENV !== "production" && console.log.apply(console, tslib_1.__spreadArray([], tslib_1.__read(args), false));
11
+ };
12
+ exports.log = log;
13
+ var debug = function () {
14
+ var args = [];
15
+ for (var _i = 0; _i < arguments.length; _i++) {
16
+ args[_i] = arguments[_i];
17
+ }
18
+ return process.env.NODE_ENV !== "production" && console.debug.apply(console, tslib_1.__spreadArray([], tslib_1.__read(args), false));
19
+ };
20
+ exports.debug = debug;
21
+ var error = function () {
22
+ var args = [];
23
+ for (var _i = 0; _i < arguments.length; _i++) {
24
+ args[_i] = arguments[_i];
25
+ }
26
+ return process.env.NODE_ENV !== "production" && console.error.apply(console, tslib_1.__spreadArray([], tslib_1.__read(args), false));
27
+ };
28
+ exports.error = error;
@@ -0,0 +1,18 @@
1
+ export declare const memoize: <T extends unknown[], K>(fn: (...args: T) => K) => (...args: T) => K;
2
+ /**
3
+ * Mint a stable cellXfs key ("sid") for a CellFormat. The key is
4
+ * `contentHash` (FNV-1a-64 → 8-char base62) over a delimiter-separated
5
+ * canonical serialization of the format's defined properties — the
6
+ * previous 31-bit rolling int hash silently collided two different
7
+ * formats onto one registry key (first-writer wins, so e.g. a red
8
+ * format could hijack a blue one on import).
9
+ *
10
+ * Sids are minted at import/edit time and persisted in the doc's
11
+ * cellXfs map together with the cell references that carry them —
12
+ * readback resolves a stored sid against the stored map, never by
13
+ * re-hashing. Changing this algorithm therefore only affects newly
14
+ * minted keys; existing docs keep resolving their old sids.
15
+ */
16
+ export declare const getCellXfsKey: (userObj: any | null | undefined) => string;
17
+ export declare const definedProps: <T extends Record<string, any> | undefined | null>(obj: T) => Partial<NonNullable<T>> | T;
18
+ //# sourceMappingURL=memoize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../memoize.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,MAE3D,GAAG,MAAM,CAAC,MASnB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,GAAG,GAAG,IAAI,GAAG,SAAS,KAAG,MA4D/D,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,EAC3E,KAAK,CAAC,KACL,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAU5B,CAAC"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.definedProps = exports.getCellXfsKey = exports.memoize = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var content_hash_1 = require("./content-hash");
6
+ var typeguards_1 = require("./typeguards");
7
+ var memoize = function (fn) {
8
+ var cache = new Map();
9
+ return function () {
10
+ var args = [];
11
+ for (var _i = 0; _i < arguments.length; _i++) {
12
+ args[_i] = arguments[_i];
13
+ }
14
+ var key = String(args);
15
+ if (cache.has(key)) {
16
+ return cache.get(key);
17
+ }
18
+ var value = fn.call.apply(fn, tslib_1.__spreadArray([undefined], tslib_1.__read(args), false));
19
+ cache.set(key, value);
20
+ return value;
21
+ };
22
+ };
23
+ exports.memoize = memoize;
24
+ /**
25
+ * Mint a stable cellXfs key ("sid") for a CellFormat. The key is
26
+ * `contentHash` (FNV-1a-64 → 8-char base62) over a delimiter-separated
27
+ * canonical serialization of the format's defined properties — the
28
+ * previous 31-bit rolling int hash silently collided two different
29
+ * formats onto one registry key (first-writer wins, so e.g. a red
30
+ * format could hijack a blue one on import).
31
+ *
32
+ * Sids are minted at import/edit time and persisted in the doc's
33
+ * cellXfs map together with the cell references that carry them —
34
+ * readback resolves a stored sid against the stored map, never by
35
+ * re-hashing. Changing this algorithm therefore only affects newly
36
+ * minted keys; existing docs keep resolving their old sids.
37
+ */
38
+ var getCellXfsKey = function (userObj) {
39
+ var e_1, _a;
40
+ if (userObj === null || userObj === undefined) {
41
+ return String(0);
42
+ }
43
+ var obj = (0, exports.definedProps)(userObj);
44
+ var serialized = "";
45
+ var hashString = function (str) {
46
+ // `\u0001` terminates every atom so adjacent strings can't merge
47
+ // into the same serialization (`{a:"bc"}` vs `{ab:"c"}`).
48
+ serialized += str + "\u0001";
49
+ };
50
+ var hashValue = function (value) {
51
+ var e_2, _a;
52
+ if (value === null || value === undefined)
53
+ return;
54
+ if (typeof value === "object") {
55
+ // Custom serialization for known object types
56
+ var sortedKeys = Object.keys(value).sort();
57
+ serialized += "\u0002";
58
+ try {
59
+ for (var sortedKeys_1 = tslib_1.__values(sortedKeys), sortedKeys_1_1 = sortedKeys_1.next(); !sortedKeys_1_1.done; sortedKeys_1_1 = sortedKeys_1.next()) {
60
+ var key = sortedKeys_1_1.value;
61
+ hashString(key);
62
+ hashValue(value[key]);
63
+ }
64
+ }
65
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
66
+ finally {
67
+ try {
68
+ if (sortedKeys_1_1 && !sortedKeys_1_1.done && (_a = sortedKeys_1.return)) _a.call(sortedKeys_1);
69
+ }
70
+ finally { if (e_2) throw e_2.error; }
71
+ }
72
+ serialized += "\u0003";
73
+ }
74
+ else {
75
+ hashString(String(value));
76
+ }
77
+ };
78
+ // Hash each property in a consistent order. The list MUST cover every
79
+ // field that distinguishes one CellFormat from another — when two
80
+ // different formats hash to the same key, the cellXfs registry
81
+ // dedupes them, so cells lose any field that wasn't in this list.
82
+ var props = [
83
+ "backgroundColor",
84
+ "borders",
85
+ "textFormat",
86
+ "numberFormat",
87
+ "horizontalAlignment",
88
+ "verticalAlignment",
89
+ "wrapStrategy",
90
+ "indent",
91
+ "textRotation",
92
+ "shrinkToFit",
93
+ "relativeIndent",
94
+ "fillPattern",
95
+ "foregroundColor",
96
+ "gradient",
97
+ ];
98
+ try {
99
+ for (var props_1 = tslib_1.__values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
100
+ var prop = props_1_1.value;
101
+ if (obj[prop] !== undefined) {
102
+ hashString(String(prop)); // Include property name in hash
103
+ hashValue(obj[prop]);
104
+ }
105
+ }
106
+ }
107
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
108
+ finally {
109
+ try {
110
+ if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
111
+ }
112
+ finally { if (e_1) throw e_1.error; }
113
+ }
114
+ return (0, content_hash_1.contentHash)(serialized);
115
+ };
116
+ exports.getCellXfsKey = getCellXfsKey;
117
+ var definedProps = function (obj) {
118
+ if ((0, typeguards_1.isNil)(obj))
119
+ return obj;
120
+ var result = {};
121
+ for (var key in obj) {
122
+ if (!(0, typeguards_1.isNil)(obj[key])) {
123
+ result[key] = obj[key];
124
+ }
125
+ }
126
+ return result;
127
+ };
128
+ exports.definedProps = definedProps;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Convert number to alphabet
3
+ * @param i
4
+ */
5
+ export declare const number2Alpha: (i: number) => string;
6
+ /**
7
+ * Converts a letter to number
8
+ * A = 1
9
+ * B => 2
10
+ * @param letters
11
+ */
12
+ export declare const alpha2number: (letters: string) => number;
13
+ /**
14
+ * Get min max of an array
15
+ * @param arr
16
+ */
17
+ export declare const getMinMaxArray: (arr: number[]) => number[];
18
+ export declare const isNumber: (value: any) => value is number;
19
+ //# sourceMappingURL=numbers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../numbers.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,GAAG,MAAM,KAAG,MAIxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,MAE9C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,EAAE,aAa3C,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,MAAuB,CAAC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNumber = exports.getMinMaxArray = exports.alpha2number = exports.number2Alpha = void 0;
4
+ // Pre-compute alphabet string to avoid repeated string access
5
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
6
+ /**
7
+ * Convert number to alphabet
8
+ * @param i
9
+ */
10
+ var number2Alpha = function (i) {
11
+ return ((i >= 26 ? (0, exports.number2Alpha)(((i / 26) >> 0) - 1) : "") + ALPHABET[i % 26 >> 0]);
12
+ };
13
+ exports.number2Alpha = number2Alpha;
14
+ /**
15
+ * Converts a letter to number
16
+ * A = 1
17
+ * B => 2
18
+ * @param letters
19
+ */
20
+ var alpha2number = function (letters) {
21
+ return letters.split("").reduce(function (r, a) { return r * 26 + parseInt(a, 36) - 9; }, 0);
22
+ };
23
+ exports.alpha2number = alpha2number;
24
+ /**
25
+ * Get min max of an array
26
+ * @param arr
27
+ */
28
+ var getMinMaxArray = function (arr) {
29
+ if (!arr.length)
30
+ return [0, 0];
31
+ // Loop, not spread — passing >~65k elements as call arguments throws
32
+ // `RangeError: Maximum call stack size exceeded` (selection-sized arrays
33
+ // reach millions).
34
+ var min = arr[0];
35
+ var max = arr[0];
36
+ for (var i = 1; i < arr.length; i++) {
37
+ var v = arr[i];
38
+ if (v < min)
39
+ min = v;
40
+ if (v > max)
41
+ max = v;
42
+ }
43
+ return [min, max];
44
+ };
45
+ exports.getMinMaxArray = getMinMaxArray;
46
+ var isNumber = function (value) { return !isNaN(value); };
47
+ exports.isNumber = isNumber;
@@ -0,0 +1,88 @@
1
+ import type { CellInterface, GridRange, SheetRange, SelectionArea } from "@rowsncolumns/common-types";
2
+ import { type ParsedToken } from "@rowsncolumns/calculator";
3
+ export type SelectionWithSheetName = SelectionArea & {
4
+ sheetName?: string;
5
+ };
6
+ export type SelectionFromTableResolver = (sheetId: number, activeCell?: CellInterface, tableName?: string, columnNames?: string[], thisRow?: boolean, specialItem?: ParsedToken["specialItem"]) => SelectionWithSheetName | undefined;
7
+ export type SelectionFromNamedRangeResolver = (variableName: string) => SelectionWithSheetName | unknown;
8
+ export declare const isSelection: (sel: unknown) => sel is SelectionWithSheetName;
9
+ export declare const MAX_ROW_COUNT = 1048576;
10
+ export declare const MAX_COLUMN_COUNT = 16384;
11
+ export declare const DEFAULT_ROW_COUNT = 1000;
12
+ export declare const DEFAULT_COLUMN_COUNT = 100;
13
+ export declare const DEFAULT_ROW_HEIGHT = 21;
14
+ export declare const DEFAULT_COLUMN_WIDTH = 100;
15
+ export declare const DEFAULT_ACTIVE_CELL: CellInterface;
16
+ export declare const addressToSelection: (address: string, rowCount?: number, columnCount?: number) => SelectionArea | undefined;
17
+ export declare const addressToSheetRange: (address: string, sheetId: number, rowCount?: number, columnCount?: number) => SheetRange | undefined;
18
+ /**
19
+ * Convert a selection object to A1 address form (optionally sheet-qualified).
20
+ */
21
+ export declare const selectionToAddress: (selection: SelectionArea | undefined, sheetName?: string, merges?: GridRange[] | null, rowCount?: number, columnCount?: number) => string | undefined;
22
+ export declare const checkIfStringIsReference: (value: string | undefined) => boolean;
23
+ export declare const generateSelectionsFromFormula: (value: string, _sheetId?: number, currentSheetName?: string, activeCell?: CellInterface, rowCount?: number, columnCount?: number, tokenizer?: (value: string | undefined, sheetName?: string) => ParsedToken[], getSelectionFromTable?: SelectionFromTableResolver, getSelectionFromNamedRange?: SelectionFromNamedRangeResolver) => SelectionWithSheetName[];
24
+ /**
25
+ * Check if two ranges are equal.
26
+ */
27
+ export declare const isAreasEqual: (area1: GridRange | undefined, area2: GridRange | undefined) => boolean;
28
+ /**
29
+ * Check if a cell is inside the provided range bounds.
30
+ */
31
+ export declare const isCellWithinBounds: (cell: CellInterface, bounds?: GridRange) => boolean;
32
+ /**
33
+ * Return a single-cell selection for the active cell.
34
+ */
35
+ export declare const selectionFromActiveCell: (activeCell: CellInterface | null) => SelectionArea[];
36
+ /**
37
+ * Check if two ranges overlap.
38
+ */
39
+ export declare const areaIntersects: (area1: GridRange, area2: GridRange | undefined) => boolean;
40
+ /**
41
+ * Check if `needle` range is fully inside `haystack`.
42
+ */
43
+ export declare const areaInsideArea: (needle: GridRange, haystack: GridRange) => boolean;
44
+ /**
45
+ * Intersection of two ranges, or `null` when they don't overlap.
46
+ */
47
+ export declare const areaIntersection: (area1: GridRange, area2: GridRange) => GridRange | null;
48
+ /**
49
+ * Re-scope a rule's ranges after a drag-move of `from` → `to` on `sheetId`, so
50
+ * range-scoped rules (conditional formats, data validations) travel with the
51
+ * moved cells the way Excel and Google Sheets carry them:
52
+ *
53
+ * - a range on another sheet, or untouched by the move, is kept as-is
54
+ * - a range that travelled entirely inside the moved area is shifted with it
55
+ * - a range that only partially overlaps the moved area keeps its original
56
+ * scope (the source cells left behind keep the rule) and gains the shifted
57
+ * overlap at the destination — unless one of the rule's ranges already
58
+ * covers that destination
59
+ *
60
+ * Returns the new ranges, or `null` when the move leaves every range
61
+ * untouched, so callers can skip the rule update entirely (no history entry,
62
+ * no re-evaluation).
63
+ */
64
+ export declare const rescopeSheetRangesOnMove: (ranges: readonly SheetRange[], sheetId: number, from: GridRange, to: GridRange) => SheetRange[] | null;
65
+ /**
66
+ * Convert a cell coordinate into a single-cell range.
67
+ */
68
+ export declare const cellToArea: ({ rowIndex, columnIndex, }: CellInterface) => GridRange;
69
+ /**
70
+ * Convert font size from points to pixels.
71
+ */
72
+ export declare const pointToPixel: (pt: number) => number;
73
+ /**
74
+ * Convert font size from pixels to points.
75
+ */
76
+ export declare const pixelToPoint: (px: number) => number;
77
+ /**
78
+ * Resolve a table column name to absolute column index.
79
+ */
80
+ export declare const getColumnIndexFromColumnName: (table: {
81
+ columns?: Array<{
82
+ name?: string | null;
83
+ }> | null;
84
+ range: {
85
+ startColumnIndex: number;
86
+ };
87
+ }, columnName: string | undefined) => number | undefined;
88
+ //# sourceMappingURL=selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../selection.ts"],"names":[],"mappings":"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"}