@rowsncolumns/utils 9.5.7 → 9.6.2
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/cell-data-helpers.d.ts +8 -2
- package/dist/cjs/cell-data-helpers.d.ts.map +1 -1
- package/dist/cjs/cell-data-helpers.js +11 -3
- package/dist/cjs/cjk-number-format.d.ts +11 -0
- package/dist/cjs/cjk-number-format.d.ts.map +1 -0
- package/dist/cjs/cjk-number-format.js +533 -0
- package/dist/cjs/color.d.ts +9 -0
- package/dist/cjs/color.d.ts.map +1 -1
- package/dist/cjs/color.js +55 -1
- package/dist/cjs/excel-number-format.d.ts.map +1 -1
- package/dist/cjs/excel-number-format.js +13 -1
- package/dist/cjs/formatter.d.ts +42 -0
- package/dist/cjs/formatter.d.ts.map +1 -1
- package/dist/cjs/formatter.js +180 -15
- package/dist/cjs/selection.d.ts.map +1 -1
- package/dist/cjs/selection.js +2 -2
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/cell-data-helpers.d.ts +8 -2
- package/dist/esm/cell-data-helpers.d.ts.map +1 -1
- package/dist/esm/cell-data-helpers.js +9 -2
- package/dist/esm/cjk-number-format.d.ts +11 -0
- package/dist/esm/cjk-number-format.d.ts.map +1 -0
- package/dist/esm/cjk-number-format.js +494 -0
- package/dist/esm/color.d.ts +9 -0
- package/dist/esm/color.d.ts.map +1 -1
- package/dist/esm/color.js +53 -0
- package/dist/esm/excel-number-format.d.ts.map +1 -1
- package/dist/esm/excel-number-format.js +13 -1
- package/dist/esm/formatter.d.ts +42 -0
- package/dist/esm/formatter.d.ts.map +1 -1
- package/dist/esm/formatter.js +163 -11
- package/dist/esm/selection.d.ts.map +1 -1
- package/dist/esm/selection.js +2 -2
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/cjs/color.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getContrastColor = exports.expandChartPalette = exports.chartPaletteColorAt = exports.applyLumModOff = exports.CHART_PALETTE_VARIATIONS = exports.rgbToHex = exports.hexToRgb = exports.lightenColor = exports.colorStringToHex = exports.isSameColor = exports.rgbaToArgbHex = exports.getSelectionColorAtIndex = void 0;
|
|
3
|
+
exports.getContrastColor = exports.expandChartPalette = exports.chartPaletteColorAt = exports.applyLumModOff = exports.CHART_PALETTE_VARIATIONS = exports.rgbToHex = exports.hexToRgb = exports.applyTint = exports.lightenColor = exports.colorStringToHex = exports.isSameColor = exports.rgbaToArgbHex = exports.getSelectionColorAtIndex = void 0;
|
|
4
4
|
exports.normalizeColor = normalizeColor;
|
|
5
5
|
var tslib_1 = require("tslib");
|
|
6
6
|
var typeguards_1 = require("./typeguards");
|
|
@@ -126,6 +126,60 @@ var lightenColor = function (unit, color) {
|
|
|
126
126
|
return rgbColor ? shade(unit, rgbColor) : undefined;
|
|
127
127
|
};
|
|
128
128
|
exports.lightenColor = lightenColor;
|
|
129
|
+
/**
|
|
130
|
+
* Excel's tint (ECMA-376 Part 1, §18.8.19 `CT_Color@tint`) — what a `{ theme, tint }` colour paints
|
|
131
|
+
* as. Unlike `lightenColor`, which blends each channel toward black or white, the colour moves to
|
|
132
|
+
* HLS and only its luminance changes: `L·(1+tint)` for a negative tint, `L·(1−tint) + tint` for a
|
|
133
|
+
* positive one. Hue and saturation stay, so accent1 `#4472C4` at −25 % is Excel's `#2F5597` (not
|
|
134
|
+
* `#335693`) and accent2 `#ED7D31` at −25 % is `#C55A11`. The engine's `rnc_model::apply_tint`
|
|
135
|
+
* is the same rule. Returns `#rrggbb` (as `rgbToHex`); `undefined` for a colour it cannot read.
|
|
136
|
+
*/
|
|
137
|
+
var applyTint = function (tint, color) {
|
|
138
|
+
var rgba = normalizeColor(color);
|
|
139
|
+
if (!rgba || rgba.a === 0)
|
|
140
|
+
return undefined;
|
|
141
|
+
if (!Number.isFinite(tint) || tint === 0) {
|
|
142
|
+
return (0, exports.rgbToHex)(Math.round(rgba.r), Math.round(rgba.g), Math.round(rgba.b));
|
|
143
|
+
}
|
|
144
|
+
var t = Math.max(-1, Math.min(1, tint));
|
|
145
|
+
var _a = tslib_1.__read(rgbToHls(rgba.r / 255, rgba.g / 255, rgba.b / 255), 3), h = _a[0], l = _a[1], s = _a[2];
|
|
146
|
+
var lum = Math.max(0, Math.min(1, t < 0 ? l * (1 + t) : l * (1 - t) + t));
|
|
147
|
+
var _b = tslib_1.__read(hlsToRgb(h, lum, s), 3), r = _b[0], g = _b[1], b = _b[2];
|
|
148
|
+
var byte = function (c) { return Math.max(0, Math.min(255, Math.round(c * 255))); };
|
|
149
|
+
return (0, exports.rgbToHex)(byte(r), byte(g), byte(b));
|
|
150
|
+
};
|
|
151
|
+
exports.applyTint = applyTint;
|
|
152
|
+
var rgbToHls = function (r, g, b) {
|
|
153
|
+
var max = Math.max(r, g, b);
|
|
154
|
+
var min = Math.min(r, g, b);
|
|
155
|
+
var l = (max + min) / 2;
|
|
156
|
+
if (max === min)
|
|
157
|
+
return [0, l, 0];
|
|
158
|
+
var range = max - min;
|
|
159
|
+
var s = l <= 0.5 ? range / (max + min) : range / (2 - max - min);
|
|
160
|
+
var rc = (max - r) / range;
|
|
161
|
+
var gc = (max - g) / range;
|
|
162
|
+
var bc = (max - b) / range;
|
|
163
|
+
var h = r === max ? bc - gc : g === max ? 2 + rc - bc : 4 + gc - rc;
|
|
164
|
+
return [(((h / 6) % 1) + 1) % 1, l, s];
|
|
165
|
+
};
|
|
166
|
+
var hlsToRgb = function (h, l, s) {
|
|
167
|
+
if (s === 0)
|
|
168
|
+
return [l, l, l];
|
|
169
|
+
var m2 = l <= 0.5 ? l * (1 + s) : l + s - l * s;
|
|
170
|
+
var m1 = 2 * l - m2;
|
|
171
|
+
var v = function (hue) {
|
|
172
|
+
var x = ((hue % 1) + 1) % 1;
|
|
173
|
+
if (x < 1 / 6)
|
|
174
|
+
return m1 + (m2 - m1) * x * 6;
|
|
175
|
+
if (x < 0.5)
|
|
176
|
+
return m2;
|
|
177
|
+
if (x < 2 / 3)
|
|
178
|
+
return m1 + (m2 - m1) * (2 / 3 - x) * 6;
|
|
179
|
+
return m1;
|
|
180
|
+
};
|
|
181
|
+
return [v(h + 1 / 3), v(h), v(h - 1 / 3)];
|
|
182
|
+
};
|
|
129
183
|
var hexToRgb = function (hex) {
|
|
130
184
|
var bigint = parseInt(hex.slice(1), 16);
|
|
131
185
|
var r = (bigint >> 16) & 255;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"excel-number-format.d.ts","sourceRoot":"","sources":["../../excel-number-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,YAAY,CAAC;AAE/C,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,OAAO,GACP,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,CAAC;AAEZ,MAAM,MAAM,uBAAuB,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;AAE3E,0CAA0C;AAC1C,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,uBAAuB,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,iBAAiB,CAAC;IACxB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,6EAA6E;IAC7E,SAAS,EAAE,OAAO,CAAC;IACnB,kEAAkE;IAClE,aAAa,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,sDAAsD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WAAW,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MAQ/D,CAAC;AAEF,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wEAAwE;AACxE,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;AAoF1E;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,MAAM,EACf,OAAO,MAAM,EACb,MAAM,kBAAkB,EACxB,QAAQ,mBAAmB,KAC1B,kBA6CF,CAAC"}
|
|
@@ -639,7 +639,9 @@ var excelNumberPrePass = function (pattern, value, l10n, render) {
|
|
|
639
639
|
if (!info)
|
|
640
640
|
return { value: value };
|
|
641
641
|
if (info.kind === "date") {
|
|
642
|
-
|
|
642
|
+
// A negative date or time — an elapsed `[h]:mm` duration included —
|
|
643
|
+
// shows `#######` in Excel's 1900 date system.
|
|
644
|
+
if (info.isElapsed && sections.length === 1 && value >= 0)
|
|
643
645
|
return { value: value };
|
|
644
646
|
if (value < 0 || value >= MAX_DATE_SERIAL_EXCLUSIVE) {
|
|
645
647
|
return { text: exports.DATE_OVERFLOW_DISPLAY, value: value };
|
|
@@ -654,6 +656,16 @@ var excelNumberPrePass = function (pattern, value, l10n, render) {
|
|
|
654
656
|
if (index === 1 && value < 0 && pre.text === undefined && pre.value === 0) {
|
|
655
657
|
return { text: render(sections[index], 0), value: value };
|
|
656
658
|
}
|
|
659
|
+
// A one-section format keeps the minus of a negative that rounds to zero:
|
|
660
|
+
// Excel shows -0.4 in `0` as `-0` (and -0.004 in `0.00` as `-0.00`).
|
|
661
|
+
if (index === 0 &&
|
|
662
|
+
implicitSign &&
|
|
663
|
+
value < 0 &&
|
|
664
|
+
info.kind === "number" &&
|
|
665
|
+
pre.text === undefined &&
|
|
666
|
+
pre.value === 0) {
|
|
667
|
+
return { text: "-".concat(render(sections[0], 0)), value: value };
|
|
668
|
+
}
|
|
657
669
|
return pre;
|
|
658
670
|
};
|
|
659
671
|
exports.excelNumberPrePass = excelNumberPrePass;
|
package/dist/cjs/formatter.d.ts
CHANGED
|
@@ -44,5 +44,47 @@ export declare const withShortAmPmMarker: (pattern: string) => string | undefine
|
|
|
44
44
|
*/
|
|
45
45
|
export declare const withWorkbookSeparators: (pattern: string, locale?: string) => string | undefined;
|
|
46
46
|
export declare const ssfFormat: (pattern: string, value: any, locale?: string) => string;
|
|
47
|
+
/**
|
|
48
|
+
* One piece of a number format's width-aware output (see
|
|
49
|
+
* {@link ssfFormatLayout}):
|
|
50
|
+
* - `text` — literal characters, painted as they are;
|
|
51
|
+
* - `fill` — Excel's `*x`: `x` repeated to fill the cell's free width;
|
|
52
|
+
* - `skip` — Excel's `_x`: blank space as wide as the glyph `x`;
|
|
53
|
+
* - `digit` — a `?` placeholder with no digit: blank space as wide as a
|
|
54
|
+
* digit.
|
|
55
|
+
*/
|
|
56
|
+
export type NumberFormatLayoutPart = {
|
|
57
|
+
type: "text";
|
|
58
|
+
text: string;
|
|
59
|
+
} | {
|
|
60
|
+
type: "fill";
|
|
61
|
+
char: string;
|
|
62
|
+
} | {
|
|
63
|
+
type: "skip";
|
|
64
|
+
char: string;
|
|
65
|
+
} | {
|
|
66
|
+
type: "digit";
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Excel's width-aware number-format output: `*x` repeats `x` to the cell's
|
|
70
|
+
* width, `_x` reserves the width of `x` and `?` reserves a digit's width
|
|
71
|
+
* ("Number format codes", support.microsoft.com). A plain formatted string
|
|
72
|
+
* cannot carry that — `ssfFormat` drops the fill and renders the reserves as
|
|
73
|
+
* single spaces — so the painter asks for the parts and expands them with
|
|
74
|
+
* measured glyph widths.
|
|
75
|
+
*
|
|
76
|
+
* Returns `undefined` when the pattern has none of those tokens (the plain
|
|
77
|
+
* string is already exact), and for East Asian numeral codes. The parts'
|
|
78
|
+
* plain text ({@link numberFormatLayoutText}) equals `ssfFormat`'s output;
|
|
79
|
+
* callers compare it against the string they paint and ignore the layout
|
|
80
|
+
* when the two disagree.
|
|
81
|
+
*/
|
|
82
|
+
export declare const ssfFormatLayout: (pattern: string, value: any, locale?: string) => NumberFormatLayoutPart[] | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* The plain string a layout stands for — what `ssfFormat` returns for the
|
|
85
|
+
* same pattern and value: fills drop out, skips and digit pads are one
|
|
86
|
+
* space each.
|
|
87
|
+
*/
|
|
88
|
+
export declare const numberFormatLayoutText: (parts: readonly NumberFormatLayoutPart[]) => string;
|
|
47
89
|
export declare const ssfFormatColor: (pattern: string, value: any) => string | undefined;
|
|
48
90
|
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../formatter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../formatter.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OASlE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KACjC,OAWF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OAWlE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,SAAS,GAAG,IAAI,KAAG,OAOlE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,MAAM,KAAG,OA4B1D,CAAC;AA+LF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,KAAG,MAAM,GAAG,SA4C9D,CAAC;AAiIF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,MAAM,EACf,SAAS,MAAM,KACd,MAAM,GAAG,SAiBX,CAAC;AAiBF,eAAO,MAAM,SAAS,GACpB,SAAS,MAAM,EACf,OAAO,GAAG,EACV,SAAS,MAAM,KACd,MASF,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,sBAAsB,GAC9B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAoDtB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EACf,OAAO,GAAG,EACV,SAAS,MAAM,KACd,sBAAsB,EAAE,GAAG,SA8C7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO,SAAS,sBAAsB,EAAE,KACvC,MAOF,CAAC;AAyPF,eAAO,MAAM,cAAc,GACzB,SAAS,MAAM,EACf,OAAO,GAAG,KACT,MAAM,GAAG,SAoBX,CAAC"}
|
package/dist/cjs/formatter.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ssfFormatColor = exports.ssfFormat = exports.withWorkbookSeparators = exports.withShortAmPmMarker = exports.isStandaloneMonthPattern = exports.isTextPattern = exports.isTimePattern = exports.isDateTimePattern = exports.isDatePattern = void 0;
|
|
3
|
+
exports.ssfFormatColor = exports.numberFormatLayoutText = exports.ssfFormatLayout = exports.ssfFormat = exports.withWorkbookSeparators = exports.withShortAmPmMarker = exports.isStandaloneMonthPattern = exports.isTextPattern = exports.isTimePattern = exports.isDateTimePattern = exports.isDatePattern = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var numfmt_1 = require("numfmt");
|
|
6
|
+
var cjk_number_format_1 = require("./cjk-number-format");
|
|
6
7
|
var colors_1 = require("./colors");
|
|
7
8
|
var excel_number_format_1 = require("./excel-number-format");
|
|
8
9
|
/**
|
|
@@ -77,10 +78,6 @@ var isTextPattern = function (pattern) {
|
|
|
77
78
|
}
|
|
78
79
|
};
|
|
79
80
|
exports.isTextPattern = isTextPattern;
|
|
80
|
-
var isSingleSectionElapsedTimePattern = function (pattern) {
|
|
81
|
-
return !pattern.includes(";") &&
|
|
82
|
-
/\[(?:h+|m+|s+)\]/i.test(pattern.replace(/\[\$[^\]]+\]/g, ""));
|
|
83
|
-
};
|
|
84
81
|
/**
|
|
85
82
|
* Does the pattern spell a month name (`mmm`+) with no day-of-month field
|
|
86
83
|
* (`d`/`dd`) beside it? Quoted literals, bracket directives and escaped
|
|
@@ -529,6 +526,169 @@ var withWorkbookSeparatorsCached = function (code, locale) {
|
|
|
529
526
|
return rewritten;
|
|
530
527
|
};
|
|
531
528
|
var ssfFormat = function (pattern, value, locale) {
|
|
529
|
+
// East Asian tokens numfmt does not render (`[DBNumN]`, Japanese era `g`/`e`,
|
|
530
|
+
// `aaa` weekdays): rewrite the code to plain literals, then convert the
|
|
531
|
+
// rendered digits to the `[DBNumN]` numeral system (see cjk-number-format).
|
|
532
|
+
if (typeof value === "number") {
|
|
533
|
+
var cjk = (0, cjk_number_format_1.prepareCjkNumberFormat)(pattern, value, locale);
|
|
534
|
+
if (cjk)
|
|
535
|
+
return cjk.finish(ssfFormatBase(cjk.code, value, locale));
|
|
536
|
+
}
|
|
537
|
+
return ssfFormatBase(pattern, value, locale);
|
|
538
|
+
};
|
|
539
|
+
exports.ssfFormat = ssfFormat;
|
|
540
|
+
var LAYOUT_FILL_MARK = "\uE000";
|
|
541
|
+
var LAYOUT_SKIP_MARK = "\uE001";
|
|
542
|
+
var LAYOUT_LITERAL_SPACE = "\uE002";
|
|
543
|
+
var LAYOUT_DIGIT_PAD = "\u00a0";
|
|
544
|
+
/**
|
|
545
|
+
* Quote every literal space of `code` as a private-use sentinel so that,
|
|
546
|
+
* rendered with numfmt's `nbsp` option, the only non-breaking spaces left
|
|
547
|
+
* in the output are the `?` digit pads.
|
|
548
|
+
*/
|
|
549
|
+
var markLiteralSpaces = function (code) {
|
|
550
|
+
var _a;
|
|
551
|
+
var out = "";
|
|
552
|
+
var inQuotes = false;
|
|
553
|
+
var inBrackets = false;
|
|
554
|
+
for (var i = 0; i < code.length; i++) {
|
|
555
|
+
var char = code[i];
|
|
556
|
+
if (inQuotes) {
|
|
557
|
+
if (char === '"')
|
|
558
|
+
inQuotes = false;
|
|
559
|
+
out += char === " " ? LAYOUT_LITERAL_SPACE : char;
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
if (inBrackets) {
|
|
563
|
+
if (char === "]")
|
|
564
|
+
inBrackets = false;
|
|
565
|
+
out += char;
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
if (char === '"') {
|
|
569
|
+
inQuotes = true;
|
|
570
|
+
}
|
|
571
|
+
else if (char === "[") {
|
|
572
|
+
inBrackets = true;
|
|
573
|
+
}
|
|
574
|
+
else if (char === "\\" && code[i + 1] === " ") {
|
|
575
|
+
out += "\"".concat(LAYOUT_LITERAL_SPACE, "\"");
|
|
576
|
+
i++;
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
else if (char === "\\" || char === "_" || char === "*") {
|
|
580
|
+
out += char + ((_a = code[i + 1]) !== null && _a !== void 0 ? _a : "");
|
|
581
|
+
i++;
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
else if (char === " ") {
|
|
585
|
+
out += "\"".concat(LAYOUT_LITERAL_SPACE, "\"");
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
out += char;
|
|
589
|
+
}
|
|
590
|
+
return out;
|
|
591
|
+
};
|
|
592
|
+
/** Does the pattern carry a `*` fill, `_` skip or `?` placeholder at all? */
|
|
593
|
+
var LAYOUT_TOKEN_REGEX = /[*_?]/;
|
|
594
|
+
/**
|
|
595
|
+
* Excel's width-aware number-format output: `*x` repeats `x` to the cell's
|
|
596
|
+
* width, `_x` reserves the width of `x` and `?` reserves a digit's width
|
|
597
|
+
* ("Number format codes", support.microsoft.com). A plain formatted string
|
|
598
|
+
* cannot carry that — `ssfFormat` drops the fill and renders the reserves as
|
|
599
|
+
* single spaces — so the painter asks for the parts and expands them with
|
|
600
|
+
* measured glyph widths.
|
|
601
|
+
*
|
|
602
|
+
* Returns `undefined` when the pattern has none of those tokens (the plain
|
|
603
|
+
* string is already exact), and for East Asian numeral codes. The parts'
|
|
604
|
+
* plain text ({@link numberFormatLayoutText}) equals `ssfFormat`'s output;
|
|
605
|
+
* callers compare it against the string they paint and ignore the layout
|
|
606
|
+
* when the two disagree.
|
|
607
|
+
*/
|
|
608
|
+
var ssfFormatLayout = function (pattern, value, locale) {
|
|
609
|
+
var _a;
|
|
610
|
+
if (!pattern || !LAYOUT_TOKEN_REGEX.test(pattern))
|
|
611
|
+
return undefined;
|
|
612
|
+
if (typeof value === "number" && (0, cjk_number_format_1.prepareCjkNumberFormat)(pattern, value, locale)) {
|
|
613
|
+
return undefined;
|
|
614
|
+
}
|
|
615
|
+
var raw = ssfFormatBase(pattern, value, locale, {
|
|
616
|
+
nbsp: true,
|
|
617
|
+
fillChar: LAYOUT_FILL_MARK,
|
|
618
|
+
skipChar: LAYOUT_SKIP_MARK,
|
|
619
|
+
transform: markLiteralSpaces,
|
|
620
|
+
});
|
|
621
|
+
if (raw === undefined)
|
|
622
|
+
return undefined;
|
|
623
|
+
// A locale whose group separator is itself a non-breaking space makes the
|
|
624
|
+
// digit pads ambiguous: keep those as plain spaces.
|
|
625
|
+
var digitPads = separatorsFor(locale).group !== LAYOUT_DIGIT_PAD;
|
|
626
|
+
var parts = [];
|
|
627
|
+
var text = "";
|
|
628
|
+
var flush = function () {
|
|
629
|
+
if (text)
|
|
630
|
+
parts.push({ type: "text", text: text });
|
|
631
|
+
text = "";
|
|
632
|
+
};
|
|
633
|
+
for (var i = 0; i < raw.length; i++) {
|
|
634
|
+
var char = raw[i];
|
|
635
|
+
if (char === LAYOUT_FILL_MARK || char === LAYOUT_SKIP_MARK) {
|
|
636
|
+
var next = (_a = raw[i + 1]) !== null && _a !== void 0 ? _a : " ";
|
|
637
|
+
flush();
|
|
638
|
+
parts.push({
|
|
639
|
+
type: char === LAYOUT_FILL_MARK ? "fill" : "skip",
|
|
640
|
+
char: next,
|
|
641
|
+
});
|
|
642
|
+
i++;
|
|
643
|
+
}
|
|
644
|
+
else if (char === LAYOUT_DIGIT_PAD) {
|
|
645
|
+
if (digitPads) {
|
|
646
|
+
flush();
|
|
647
|
+
parts.push({ type: "digit" });
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
text += char;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
else if (char === LAYOUT_LITERAL_SPACE) {
|
|
654
|
+
text += " ";
|
|
655
|
+
}
|
|
656
|
+
else {
|
|
657
|
+
text += char;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
flush();
|
|
661
|
+
return parts.some(function (part) { return part.type !== "text"; }) ? parts : undefined;
|
|
662
|
+
};
|
|
663
|
+
exports.ssfFormatLayout = ssfFormatLayout;
|
|
664
|
+
/**
|
|
665
|
+
* The plain string a layout stands for — what `ssfFormat` returns for the
|
|
666
|
+
* same pattern and value: fills drop out, skips and digit pads are one
|
|
667
|
+
* space each.
|
|
668
|
+
*/
|
|
669
|
+
var numberFormatLayoutText = function (parts) {
|
|
670
|
+
var e_2, _a;
|
|
671
|
+
var out = "";
|
|
672
|
+
try {
|
|
673
|
+
for (var parts_1 = tslib_1.__values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) {
|
|
674
|
+
var part = parts_1_1.value;
|
|
675
|
+
if (part.type === "text")
|
|
676
|
+
out += part.text;
|
|
677
|
+
else if (part.type !== "fill")
|
|
678
|
+
out += " ";
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
682
|
+
finally {
|
|
683
|
+
try {
|
|
684
|
+
if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1);
|
|
685
|
+
}
|
|
686
|
+
finally { if (e_2) throw e_2.error; }
|
|
687
|
+
}
|
|
688
|
+
return out;
|
|
689
|
+
};
|
|
690
|
+
exports.numberFormatLayoutText = numberFormatLayoutText;
|
|
691
|
+
function ssfFormatBase(pattern, value, locale, layout) {
|
|
532
692
|
try {
|
|
533
693
|
if (locale)
|
|
534
694
|
ensureNumfmtLocale(locale);
|
|
@@ -537,12 +697,22 @@ var ssfFormat = function (pattern, value, locale) {
|
|
|
537
697
|
shortAmPm = (0, exports.withShortAmPmMarker)(pattern);
|
|
538
698
|
shortAmPmPatternCache.set(pattern, shortAmPm);
|
|
539
699
|
}
|
|
540
|
-
var
|
|
700
|
+
var baseCode = withWorkbookSeparatorsCached(shortAmPm !== null && shortAmPm !== void 0 ? shortAmPm : pattern, locale);
|
|
701
|
+
var code = layout ? layout.transform(baseCode) : baseCode;
|
|
541
702
|
var patternLocale = localeForPattern(pattern, locale);
|
|
542
703
|
if (shortAmPm !== undefined && patternLocale) {
|
|
543
704
|
patternLocale = getShortAmPmLocale(patternLocale);
|
|
544
705
|
}
|
|
545
|
-
|
|
706
|
+
// numfmt types `fillChar` / `skipChar` as booleans; at runtime they are
|
|
707
|
+
// the marker strings it emits ahead of the fill / skip character.
|
|
708
|
+
var options_1 = layout
|
|
709
|
+
? {
|
|
710
|
+
locale: patternLocale,
|
|
711
|
+
nbsp: layout.nbsp,
|
|
712
|
+
fillChar: layout.fillChar,
|
|
713
|
+
skipChar: layout.skipChar,
|
|
714
|
+
}
|
|
715
|
+
: { locale: patternLocale };
|
|
546
716
|
if (typeof value === "number") {
|
|
547
717
|
// Excel decides rounding, `General`, huge magnitudes and conditional
|
|
548
718
|
// sections from the 15-significant-digit decimal, not the binary
|
|
@@ -553,17 +723,12 @@ var ssfFormat = function (pattern, value, locale) {
|
|
|
553
723
|
}
|
|
554
724
|
value = pre.value;
|
|
555
725
|
}
|
|
556
|
-
|
|
557
|
-
value < 0 &&
|
|
558
|
-
isSingleSectionElapsedTimePattern(pattern);
|
|
559
|
-
var formatted = (0, numfmt_1.format)(code, isNegativeElapsedTime ? Math.abs(value) : value, options_1);
|
|
560
|
-
return isNegativeElapsedTime ? "-".concat(formatted) : formatted;
|
|
726
|
+
return (0, numfmt_1.format)(code, value, options_1);
|
|
561
727
|
}
|
|
562
728
|
catch (err) {
|
|
563
|
-
return String(value);
|
|
729
|
+
return layout ? undefined : String(value);
|
|
564
730
|
}
|
|
565
|
-
}
|
|
566
|
-
exports.ssfFormat = ssfFormat;
|
|
731
|
+
}
|
|
567
732
|
/**
|
|
568
733
|
* Excel's legacy fixed 56-color palette used by `[ColorN]` directives
|
|
569
734
|
* inside number format patterns (1-indexed). This palette is INDEPENDENT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,UAAU,EACV,aAAa,EACb,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAUpC,MAAM,MAAM,sBAAsB,GAAG,aAAa,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,MAAM,MAAM,0BAA0B,GAAG,CACvC,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,aAAa,EAC1B,SAAS,CAAC,EAAE,MAAM,EAClB,WAAW,CAA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AACH,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,WAA+B,CAAC;AAEvE;;GAEG;AACH,eAAO,MAAM,4BAA4B,GACvC,OAAO;IACL,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;IACjD,KAAK,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAA;KAAE,CAAC;CACrC,EACD,YAAY,MAAM,GAAG,SAAS,uBAO/B,CAAC"}
|
package/dist/cjs/selection.js
CHANGED
|
@@ -347,12 +347,12 @@ exports.cellToArea = cellToArea;
|
|
|
347
347
|
/**
|
|
348
348
|
* Convert font size from points to pixels.
|
|
349
349
|
*/
|
|
350
|
-
var pointToPixel = function (pt) { return
|
|
350
|
+
var pointToPixel = function (pt) { return (pt * 96) / 72; };
|
|
351
351
|
exports.pointToPixel = pointToPixel;
|
|
352
352
|
/**
|
|
353
353
|
* Convert font size from pixels to points.
|
|
354
354
|
*/
|
|
355
|
-
var pixelToPoint = function (px) { return Math.round((px
|
|
355
|
+
var pixelToPoint = function (px) { return Math.round((px * 72) / 96); };
|
|
356
356
|
exports.pixelToPoint = pixelToPoint;
|
|
357
357
|
/**
|
|
358
358
|
* Resolve a table column name to absolute column index.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../array.ts","../../cell-data-helpers.ts","../../clipboard-html-sanitize.ts","../../color.ts","../../colors.ts","../../condition-operand.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../excel-number-format.ts","../../formatter.ts","../../formula-locale.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../rich-text-html.ts","../../rich-text-links.ts","../../selection.ts","../../shared-string-canonical.ts","../../sheet-names.ts","../../sheet-protection.ts","../../sheet-span.ts","../../sort.ts","../../sparkline-groups.ts","../../string.ts","../../table-names.ts","../../table-styles.ts","../../table-totals.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts","../../formula-locale/formula-locale-data.generated.ts"],"version":"5.8.3"}
|
|
1
|
+
{"root":["../../array.ts","../../cell-data-helpers.ts","../../cjk-number-format.ts","../../clipboard-html-sanitize.ts","../../color.ts","../../colors.ts","../../condition-operand.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../excel-number-format.ts","../../formatter.ts","../../formula-locale.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../rich-text-html.ts","../../rich-text-links.ts","../../selection.ts","../../shared-string-canonical.ts","../../sheet-names.ts","../../sheet-protection.ts","../../sheet-span.ts","../../sort.ts","../../sparkline-groups.ts","../../string.ts","../../table-names.ts","../../table-styles.ts","../../table-totals.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts","../../formula-locale/formula-locale-data.generated.ts"],"version":"5.8.3"}
|
|
@@ -39,11 +39,17 @@ export declare const getExtendedValueError: (extValue?: Record<string, any> | nu
|
|
|
39
39
|
* state hooks' row auto-height so both agree on which cells wrap.
|
|
40
40
|
*/
|
|
41
41
|
export declare const alignmentImpliesWrap: (align: HorizontalAlign | string | null | undefined) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Excel's vertical `justify` and `distributed` wrap the text too: the lines
|
|
44
|
+
* are spread over the cell height, so there must be lines to spread.
|
|
45
|
+
*/
|
|
46
|
+
export declare const verticalAlignmentImpliesWrap: (align: string | null | undefined) => boolean;
|
|
42
47
|
/**
|
|
43
48
|
* Whether a cell format wraps its text — explicit `wrapStrategy: "wrap"` or
|
|
44
|
-
* an alignment that wraps implicitly ({@link alignmentImpliesWrap}
|
|
49
|
+
* an alignment that wraps implicitly ({@link alignmentImpliesWrap},
|
|
50
|
+
* {@link verticalAlignmentImpliesWrap}).
|
|
45
51
|
*/
|
|
46
|
-
export declare const cellFormatWrapsText: (format: Pick<CellFormat, "wrapStrategy" | "horizontalAlignment"> | null | undefined) => boolean;
|
|
52
|
+
export declare const cellFormatWrapsText: (format: Pick<CellFormat, "wrapStrategy" | "horizontalAlignment" | "verticalAlignment"> | null | undefined) => boolean;
|
|
47
53
|
export declare const resolveDefaultHorizontalAlignment: ({ errorValue, userEnteredValue, effectiveValue, dataValidation, }: {
|
|
48
54
|
errorValue: unknown;
|
|
49
55
|
userEnteredValue: Record<string, any> | null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell-data-helpers.d.ts","sourceRoot":"","sources":["../../cell-data-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,cAAc,EACf,MAAM,4BAA4B,CAAC;AAEpC,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,QAAQ,EACxD,OAAO,CAAC,GAAG,IAAI,KACd,CAAC,CAAC,IAAI,CAER,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,QAAQ,EACtD,OAAO,CAAC,GAAG,IAAI,KACd,CAAC,CAAC,IAAI,CAER,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,QAAQ,EACzD,OAAO,CAAC,GAAG,IAAI,KACd,CAAC,CAAC,IAAI,CAER,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,QAAQ,EACvD,OAAO,CAAC,GAAG,IAAI,KACd,UAAU,GAAG,cAAc,GAAG,IAAI,GAAG,SAEvC,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,QAAQ,EACtD,OAAO,CAAC,GAAG,IAAI,KACd,MAAM,GAAG,SAAS,GAAG,IAEvB,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAE1D,CA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A4B,GACvC,OAAO,MAAM,GAAG,IAAI,GAAG,SAAS,KAC/B,OAAyD,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC9B,QACI,IAAI,CACF,UAAU,EACV,cAAc,GAAG,qBAAqB,GAAG,mBAAmB,CAC7D,GACD,IAAI,GACJ,SAAS,KACZ,OAGsD,CAAC;AAE1D,eAAO,MAAM,iCAAiC,GAAI,mEAK/C;IACD,UAAU,EAAE,OAAO,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACzD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACvD,cAAc,EAAE,IAAI,CAAC,kBAAkB,EAAE,WAAW,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CAC1E,KAAG,eAAe,GAAG,SASrB,CAAC"}
|
|
@@ -60,12 +60,19 @@ export const getExtendedValueError = (extValue) => {
|
|
|
60
60
|
* state hooks' row auto-height so both agree on which cells wrap.
|
|
61
61
|
*/
|
|
62
62
|
export const alignmentImpliesWrap = (align) => align === "justify" || align === "distributed";
|
|
63
|
+
/**
|
|
64
|
+
* Excel's vertical `justify` and `distributed` wrap the text too: the lines
|
|
65
|
+
* are spread over the cell height, so there must be lines to spread.
|
|
66
|
+
*/
|
|
67
|
+
export const verticalAlignmentImpliesWrap = (align) => align === "justify" || align === "distributed";
|
|
63
68
|
/**
|
|
64
69
|
* Whether a cell format wraps its text — explicit `wrapStrategy: "wrap"` or
|
|
65
|
-
* an alignment that wraps implicitly ({@link alignmentImpliesWrap}
|
|
70
|
+
* an alignment that wraps implicitly ({@link alignmentImpliesWrap},
|
|
71
|
+
* {@link verticalAlignmentImpliesWrap}).
|
|
66
72
|
*/
|
|
67
73
|
export const cellFormatWrapsText = (format) => format?.wrapStrategy === "wrap" ||
|
|
68
|
-
alignmentImpliesWrap(format?.horizontalAlignment)
|
|
74
|
+
alignmentImpliesWrap(format?.horizontalAlignment) ||
|
|
75
|
+
verticalAlignmentImpliesWrap(format?.verticalAlignment);
|
|
69
76
|
export const resolveDefaultHorizontalAlignment = ({ errorValue, userEnteredValue, effectiveValue, dataValidation, }) => {
|
|
70
77
|
const isBoolean = getExtendedValueBool(userEnteredValue) !== undefined;
|
|
71
78
|
const isCheckbox = dataValidation?.condition?.type === "BOOLEAN";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type CjkLang = "ja" | "zh-Hans" | "zh-Hant" | "ko";
|
|
2
|
+
export interface CjkPreparedFormat {
|
|
3
|
+
/** The rewritten code for the base formatter. */
|
|
4
|
+
code: string;
|
|
5
|
+
/** Converts the rendered text's digits into the `[DBNumN]` numeral system, if any. */
|
|
6
|
+
finish: (out: string) => string;
|
|
7
|
+
}
|
|
8
|
+
export declare const prepareCjkNumberFormat: (code: string, value: number, workbookLocale?: string) => CjkPreparedFormat | undefined;
|
|
9
|
+
/** Language of an LCID (hex, low 16 bits) or a BCP-47 tag, for the CJK locales. */
|
|
10
|
+
export declare const cjkLangOfTag: (input: string) => CjkLang | undefined;
|
|
11
|
+
//# sourceMappingURL=cjk-number-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cjk-number-format.d.ts","sourceRoot":"","sources":["../../cjk-number-format.ts"],"names":[],"mappings":"AAuBA,MAAM,MAAM,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;AAS1D,MAAM,WAAW,iBAAiB;IAChC,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CACjC;AAgBD,eAAO,MAAM,sBAAsB,GACjC,MAAM,MAAM,EACZ,OAAO,MAAM,EACb,iBAAiB,MAAM,KACtB,iBAAiB,GAAG,SAsEtB,CAAC;AAqLF,mFAAmF;AACnF,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,OAAO,GAAG,SA8BtD,CAAC"}
|