@rowsncolumns/toolkit 24.5.1 → 24.5.3

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.
@@ -2,15 +2,17 @@ import type { GridRange } from "@rowsncolumns/common-types";
2
2
  import type { Column, FilterSpec, SortSpecs, TableTotalsRowFunction } from "@rowsncolumns/spreadsheet";
3
3
  export declare const getRangeFromAddressRef: (ref: string) => GridRange | undefined;
4
4
  /**
5
- * Convert an xlsx column width (in units of max-digit-width of the
6
- * default workbook font, Calibri 11 → MDW=7px) to pixels.
5
+ * OOXML `<col width>` (and `<sheetFormatPr defaultColWidth>`) → pixels.
7
6
  *
8
- * Excel's effective rendered pixel count includes a 5-pixel padding
9
- * baked into the column box: `pixels = floor(width × MDW + padding)`.
10
- * The default width "8.43" renders as 64 px (8.43 × 7 + 5 ≈ 64.01),
11
- * matching Excel exactly. The "pure" ECMA-376 §18.3.1.13 formula omits
12
- * the 5px padding; we keep the +5 form so our pixel output matches
13
- * Excel's rendered widths and round-trips with our exporter.
7
+ * The stored width is already in *padded* character units: Excel writes
8
+ * `Truncate((chars × MDW + 5) / MDW × 256) / 256` — the default 8.43-character
9
+ * column is stored as 9.140625 — and renders it back as
10
+ * `Truncate(((256 × width + Truncate(128 / MDW)) / 256) × MDW)`
11
+ * (ECMA-376 §18.3.1.13), i.e. 9.140625 → 64 px. Adding the 5 px padding a
12
+ * second time (the previous `floor(width × 7 + 5)`) drew every Excel-authored
13
+ * column ~5 px wider than Excel does and grew widths by 0.71 characters per
14
+ * import/export cycle (the exporter stores `px / 7`). MDW is 7 px for the
15
+ * Calibri 11 / Aptos Narrow 12 defaults at 96 dpi.
14
16
  */
15
17
  export declare function excelColumnWidthToPixels(width: number): number;
16
18
  export declare function findMax(arr: number[]): number;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../excel-parser/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,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AAC;AAC5D,OAAO,KAAK,EAEV,MAAM,EACN,UAAU,EACV,SAAS,EACT,sBAAsB,EACvB,MAAM,2BAA2B,CAAC;AAUnC,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,KAAG,SAAS,GAAG,SAIhE,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,UAMrD;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,UAMpC;AAmBD,eAAO,MAAM,wBAAwB,GACnC,OAAO,OAAO,KACb,KAAK,IAAI,sBACwD,CAAC;AAErE;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,GAAG,KACV,IAAI,CAAC,MAAM,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,kBAAkB,CAmB1E,CAAC;AAqBF,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,GAAG;AACf;;;;GAIG;AACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,gBA0G5E;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAgBtE;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,GAAG,EACd,KAAK,EAAE,SAAS,EAChB,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,GAC1E,SAAS,EAAE,CA2Cb;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,wBAkB3D"}
@@ -8,20 +8,23 @@ export var getRangeFromAddressRef = function (ref) {
8
8
  return selection.range;
9
9
  };
10
10
  /**
11
- * Convert an xlsx column width (in units of max-digit-width of the
12
- * default workbook font, Calibri 11 → MDW=7px) to pixels.
11
+ * OOXML `<col width>` (and `<sheetFormatPr defaultColWidth>`) → pixels.
13
12
  *
14
- * Excel's effective rendered pixel count includes a 5-pixel padding
15
- * baked into the column box: `pixels = floor(width × MDW + padding)`.
16
- * The default width "8.43" renders as 64 px (8.43 × 7 + 5 ≈ 64.01),
17
- * matching Excel exactly. The "pure" ECMA-376 §18.3.1.13 formula omits
18
- * the 5px padding; we keep the +5 form so our pixel output matches
19
- * Excel's rendered widths and round-trips with our exporter.
13
+ * The stored width is already in *padded* character units: Excel writes
14
+ * `Truncate((chars × MDW + 5) / MDW × 256) / 256` — the default 8.43-character
15
+ * column is stored as 9.140625 — and renders it back as
16
+ * `Truncate(((256 × width + Truncate(128 / MDW)) / 256) × MDW)`
17
+ * (ECMA-376 §18.3.1.13), i.e. 9.140625 → 64 px. Adding the 5 px padding a
18
+ * second time (the previous `floor(width × 7 + 5)`) drew every Excel-authored
19
+ * column ~5 px wider than Excel does and grew widths by 0.71 characters per
20
+ * import/export cycle (the exporter stores `px / 7`). MDW is 7 px for the
21
+ * Calibri 11 / Aptos Narrow 12 defaults at 96 dpi.
20
22
  */
21
23
  export function excelColumnWidthToPixels(width) {
22
- var padding = 5;
23
- var charWidth = 7;
24
- return Math.floor(width * charWidth + padding);
24
+ var maxDigitWidth = 7;
25
+ if (!Number.isFinite(width) || width <= 0)
26
+ return 0;
27
+ return Math.trunc(((256 * width + Math.trunc(128 / maxDigitWidth)) / 256) * maxDigitWidth);
25
28
  }
26
29
  export function findMax(arr) {
27
30
  var max = arr[0];
@@ -2,15 +2,17 @@ import type { GridRange } from "@rowsncolumns/common-types";
2
2
  import type { Column, FilterSpec, SortSpecs, TableTotalsRowFunction } from "@rowsncolumns/spreadsheet";
3
3
  export declare const getRangeFromAddressRef: (ref: string) => GridRange | undefined;
4
4
  /**
5
- * Convert an xlsx column width (in units of max-digit-width of the
6
- * default workbook font, Calibri 11 → MDW=7px) to pixels.
5
+ * OOXML `<col width>` (and `<sheetFormatPr defaultColWidth>`) → pixels.
7
6
  *
8
- * Excel's effective rendered pixel count includes a 5-pixel padding
9
- * baked into the column box: `pixels = floor(width × MDW + padding)`.
10
- * The default width "8.43" renders as 64 px (8.43 × 7 + 5 ≈ 64.01),
11
- * matching Excel exactly. The "pure" ECMA-376 §18.3.1.13 formula omits
12
- * the 5px padding; we keep the +5 form so our pixel output matches
13
- * Excel's rendered widths and round-trips with our exporter.
7
+ * The stored width is already in *padded* character units: Excel writes
8
+ * `Truncate((chars × MDW + 5) / MDW × 256) / 256` — the default 8.43-character
9
+ * column is stored as 9.140625 — and renders it back as
10
+ * `Truncate(((256 × width + Truncate(128 / MDW)) / 256) × MDW)`
11
+ * (ECMA-376 §18.3.1.13), i.e. 9.140625 → 64 px. Adding the 5 px padding a
12
+ * second time (the previous `floor(width × 7 + 5)`) drew every Excel-authored
13
+ * column ~5 px wider than Excel does and grew widths by 0.71 characters per
14
+ * import/export cycle (the exporter stores `px / 7`). MDW is 7 px for the
15
+ * Calibri 11 / Aptos Narrow 12 defaults at 96 dpi.
14
16
  */
15
17
  export declare function excelColumnWidthToPixels(width: number): number;
16
18
  export declare function findMax(arr: number[]): number;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../excel-parser/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAEV,MAAM,EACN,UAAU,EACV,SAAS,EACT,sBAAsB,EACvB,MAAM,2BAA2B,CAAC;AAUnC,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,KAAG,SAAS,GAAG,SAIhE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,UAIrD;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,UAMpC;AAmBD,eAAO,MAAM,wBAAwB,GACnC,OAAO,OAAO,KACb,KAAK,IAAI,sBACwD,CAAC;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H,eAAO,MAAM,sBAAsB,GACjC,QAAQ,GAAG,KACV,IAAI,CAAC,MAAM,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,kBAAkB,CAmB1E,CAAC;AAqBF,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,GAAG;AACf;;;;GAIG;AACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,gBA0G5E;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAgBtE;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,GAAG,EACd,KAAK,EAAE,SAAS,EAChB,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,GAC1E,SAAS,EAAE,CA2Cb;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,wBAkB3D"}
@@ -7,20 +7,23 @@ export const getRangeFromAddressRef = (ref) => {
7
7
  return selection.range;
8
8
  };
9
9
  /**
10
- * Convert an xlsx column width (in units of max-digit-width of the
11
- * default workbook font, Calibri 11 → MDW=7px) to pixels.
10
+ * OOXML `<col width>` (and `<sheetFormatPr defaultColWidth>`) → pixels.
12
11
  *
13
- * Excel's effective rendered pixel count includes a 5-pixel padding
14
- * baked into the column box: `pixels = floor(width × MDW + padding)`.
15
- * The default width "8.43" renders as 64 px (8.43 × 7 + 5 ≈ 64.01),
16
- * matching Excel exactly. The "pure" ECMA-376 §18.3.1.13 formula omits
17
- * the 5px padding; we keep the +5 form so our pixel output matches
18
- * Excel's rendered widths and round-trips with our exporter.
12
+ * The stored width is already in *padded* character units: Excel writes
13
+ * `Truncate((chars × MDW + 5) / MDW × 256) / 256` — the default 8.43-character
14
+ * column is stored as 9.140625 — and renders it back as
15
+ * `Truncate(((256 × width + Truncate(128 / MDW)) / 256) × MDW)`
16
+ * (ECMA-376 §18.3.1.13), i.e. 9.140625 → 64 px. Adding the 5 px padding a
17
+ * second time (the previous `floor(width × 7 + 5)`) drew every Excel-authored
18
+ * column ~5 px wider than Excel does and grew widths by 0.71 characters per
19
+ * import/export cycle (the exporter stores `px / 7`). MDW is 7 px for the
20
+ * Calibri 11 / Aptos Narrow 12 defaults at 96 dpi.
19
21
  */
20
22
  export function excelColumnWidthToPixels(width) {
21
- const padding = 5;
22
- const charWidth = 7;
23
- return Math.floor(width * charWidth + padding);
23
+ const maxDigitWidth = 7;
24
+ if (!Number.isFinite(width) || width <= 0)
25
+ return 0;
26
+ return Math.trunc(((256 * width + Math.trunc(128 / maxDigitWidth)) / 256) * maxDigitWidth);
24
27
  }
25
28
  export function findMax(arr) {
26
29
  let max = arr[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowsncolumns/toolkit",
3
- "version": "24.5.1",
3
+ "version": "24.5.3",
4
4
  "author": "Vinay M",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "main": "./dist/cjs/index.js",
@@ -45,7 +45,7 @@
45
45
  "url": "https://github.com/rowsncolumns/spreadsheet/issues"
46
46
  },
47
47
  "devDependencies": {
48
- "@rowsncolumns/utils": ">=9.5.0",
48
+ "@rowsncolumns/utils": ">=9.5.1",
49
49
  "@types/lodash-es": "^4.17.12"
50
50
  },
51
51
  "peerDependencies": {
@@ -55,9 +55,9 @@
55
55
  "dependencies": {
56
56
  "@noble/ciphers": "^0.5.3",
57
57
  "@noble/hashes": "^1.4.0",
58
- "@rowsncolumns/calculator": ">=7.2.33",
59
- "@rowsncolumns/common-types": ">=5.3.0",
60
- "@rowsncolumns/date-parser": ">=13.0.1",
58
+ "@rowsncolumns/calculator": ">=7.3.1",
59
+ "@rowsncolumns/common-types": ">=5.3.1",
60
+ "@rowsncolumns/date-parser": ">=13.0.2",
61
61
  "@zip.js/zip.js": "^2.8.17",
62
62
  "fast-xml-parser": "^5.8.0",
63
63
  "fflate": "^0.8.2",