@particle-academy/holy-sheet 2.4.2 → 2.4.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.
- package/dist/index.cjs +99 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +99 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -287,6 +287,39 @@ var Cell = class {
|
|
|
287
287
|
}
|
|
288
288
|
};
|
|
289
289
|
|
|
290
|
+
// src/schema/column-widths.ts
|
|
291
|
+
var ColumnWidths = {
|
|
292
|
+
MAX_INDEX: 16383,
|
|
293
|
+
index(key) {
|
|
294
|
+
if (typeof key === "number") {
|
|
295
|
+
return Number.isInteger(key) && key >= 0 && key <= ColumnWidths.MAX_INDEX ? key : null;
|
|
296
|
+
}
|
|
297
|
+
if (typeof key === "string" && /^[0-9]{1,5}$/.test(key)) {
|
|
298
|
+
const index = parseInt(key, 10);
|
|
299
|
+
return index <= ColumnWidths.MAX_INDEX ? index : null;
|
|
300
|
+
}
|
|
301
|
+
return null;
|
|
302
|
+
},
|
|
303
|
+
width(px) {
|
|
304
|
+
if (typeof px === "number") {
|
|
305
|
+
return Number.isFinite(px) && px >= 0 ? px : null;
|
|
306
|
+
}
|
|
307
|
+
if (typeof px === "string" && /^[0-9]+(\.[0-9]+)?$/.test(px)) {
|
|
308
|
+
return Number(px);
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
},
|
|
312
|
+
/**
|
|
313
|
+
* A column letter key (`"B"`, `"aa"`) as an index, for repair only. One or two
|
|
314
|
+
* letters (A to ZZ): a longer run like `"abc"` is more likely a mistake than
|
|
315
|
+
* column ABC, and a repair must not guess.
|
|
316
|
+
*/
|
|
317
|
+
fromLetters(key) {
|
|
318
|
+
if (typeof key !== "string" || !/^[A-Za-z]{1,2}$/.test(key.trim())) return null;
|
|
319
|
+
return CellAddress.index(key.trim());
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
|
|
290
323
|
// src/workbook/cell-comment.ts
|
|
291
324
|
var CellComment = class {
|
|
292
325
|
constructor(text, author = null, color2 = null) {
|
|
@@ -631,7 +664,10 @@ var Normalizer = class {
|
|
|
631
664
|
normalizeColumnWidths(widths) {
|
|
632
665
|
const out = /* @__PURE__ */ new Map();
|
|
633
666
|
for (const [key, px] of Object.entries(widths)) {
|
|
634
|
-
|
|
667
|
+
const index = ColumnWidths.index(key);
|
|
668
|
+
const width = ColumnWidths.width(px);
|
|
669
|
+
if (index === null || width === null) continue;
|
|
670
|
+
out.set(index, width);
|
|
635
671
|
}
|
|
636
672
|
return out;
|
|
637
673
|
}
|
|
@@ -1329,6 +1365,30 @@ var Repairer = class {
|
|
|
1329
1365
|
sheet.theme = "default";
|
|
1330
1366
|
this.repairs.push(`changed '${path}.theme' from '${original}' to 'default' (unknown theme)`);
|
|
1331
1367
|
}
|
|
1368
|
+
if (sheet.columnWidths != null && (isPlainObject(sheet.columnWidths) || Array.isArray(sheet.columnWidths))) {
|
|
1369
|
+
const widths = {};
|
|
1370
|
+
let changed = false;
|
|
1371
|
+
for (const [key, px] of Object.entries(sheet.columnWidths)) {
|
|
1372
|
+
let index = ColumnWidths.index(key);
|
|
1373
|
+
if (index === null) {
|
|
1374
|
+
const letters = ColumnWidths.fromLetters(key);
|
|
1375
|
+
if (letters !== null) {
|
|
1376
|
+
index = letters;
|
|
1377
|
+
this.repairs.push(`converted '${path}.columnWidths.${key}' to column index ${index}`);
|
|
1378
|
+
changed = true;
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
if (index === null || ColumnWidths.width(px) === null) {
|
|
1382
|
+
this.repairs.push(`dropped '${path}.columnWidths.${key}' (not a column index and a width)`);
|
|
1383
|
+
changed = true;
|
|
1384
|
+
continue;
|
|
1385
|
+
}
|
|
1386
|
+
widths[String(index)] = px;
|
|
1387
|
+
}
|
|
1388
|
+
if (changed) {
|
|
1389
|
+
sheet.columnWidths = widths;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1332
1392
|
if (sheet.cells != null && isPlainObject(sheet.cells)) {
|
|
1333
1393
|
const cleaned = {};
|
|
1334
1394
|
let changed = false;
|
|
@@ -1534,6 +1594,43 @@ var Validator = class {
|
|
|
1534
1594
|
)
|
|
1535
1595
|
);
|
|
1536
1596
|
}
|
|
1597
|
+
if (sheet.columnWidths != null) {
|
|
1598
|
+
if (!isPlainObject(sheet.columnWidths) && !Array.isArray(sheet.columnWidths)) {
|
|
1599
|
+
errors.push(
|
|
1600
|
+
error(
|
|
1601
|
+
`${path}.columnWidths`,
|
|
1602
|
+
"object keyed by 0-based column index",
|
|
1603
|
+
typeOf(sheet.columnWidths),
|
|
1604
|
+
sheet.columnWidths,
|
|
1605
|
+
'Column widths map a 0-based column index to pixels: {"0": 120, "1": 80}.'
|
|
1606
|
+
)
|
|
1607
|
+
);
|
|
1608
|
+
} else {
|
|
1609
|
+
for (const [key, px] of Object.entries(sheet.columnWidths)) {
|
|
1610
|
+
if (ColumnWidths.index(key) === null) {
|
|
1611
|
+
errors.push(
|
|
1612
|
+
error(
|
|
1613
|
+
`${path}.columnWidths.${key}`,
|
|
1614
|
+
`a 0-based column index from 0 to ${ColumnWidths.MAX_INDEX}`,
|
|
1615
|
+
typeOf(key),
|
|
1616
|
+
key,
|
|
1617
|
+
'Keys are 0-based column indexes: "0" is column A, "1" is column B. Use the index, not the letter.'
|
|
1618
|
+
)
|
|
1619
|
+
);
|
|
1620
|
+
} else if (ColumnWidths.width(px) === null) {
|
|
1621
|
+
errors.push(
|
|
1622
|
+
error(
|
|
1623
|
+
`${path}.columnWidths.${key}`,
|
|
1624
|
+
"a non-negative number of pixels",
|
|
1625
|
+
typeOf(px),
|
|
1626
|
+
px,
|
|
1627
|
+
"A width is a number of pixels, like 120."
|
|
1628
|
+
)
|
|
1629
|
+
);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1537
1634
|
return errors;
|
|
1538
1635
|
}
|
|
1539
1636
|
validateColumn(col, path) {
|
|
@@ -5041,7 +5138,7 @@ var holy_sheet_schema_default = {
|
|
|
5041
5138
|
};
|
|
5042
5139
|
|
|
5043
5140
|
// src/agent.ts
|
|
5044
|
-
var VERSION = "2.4.
|
|
5141
|
+
var VERSION = "2.4.3";
|
|
5045
5142
|
function toU8(input) {
|
|
5046
5143
|
return input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
5047
5144
|
}
|