@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.d.cts CHANGED
@@ -223,7 +223,7 @@ interface SetMetaOp {
223
223
  }
224
224
 
225
225
  /** This package's own version, pinned to package.json by `version.test.ts`. */
226
- declare const VERSION = "2.4.2";
226
+ declare const VERSION = "2.4.3";
227
227
  type Any$6 = any;
228
228
  /**
229
229
  * Agent — the structured-tool surface for Holy Sheet. Mirrors PHP `Agent`.
@@ -295,7 +295,7 @@ type Any$5 = any;
295
295
  * over `Agent`. Provided for parity / DI ergonomics; most callers use `Agent`.
296
296
  */
297
297
  declare class HolySheet {
298
- static readonly VERSION = "2.4.2";
298
+ static readonly VERSION = "2.4.3";
299
299
  validate(schema: Any$5): ValidationError[];
300
300
  toBytes(schema: Any$5): Uint8Array;
301
301
  write(schema: Any$5, path: string): Promise<WriteResult>;
package/dist/index.d.ts CHANGED
@@ -223,7 +223,7 @@ interface SetMetaOp {
223
223
  }
224
224
 
225
225
  /** This package's own version, pinned to package.json by `version.test.ts`. */
226
- declare const VERSION = "2.4.2";
226
+ declare const VERSION = "2.4.3";
227
227
  type Any$6 = any;
228
228
  /**
229
229
  * Agent — the structured-tool surface for Holy Sheet. Mirrors PHP `Agent`.
@@ -295,7 +295,7 @@ type Any$5 = any;
295
295
  * over `Agent`. Provided for parity / DI ergonomics; most callers use `Agent`.
296
296
  */
297
297
  declare class HolySheet {
298
- static readonly VERSION = "2.4.2";
298
+ static readonly VERSION = "2.4.3";
299
299
  validate(schema: Any$5): ValidationError[];
300
300
  toBytes(schema: Any$5): Uint8Array;
301
301
  write(schema: Any$5, path: string): Promise<WriteResult>;
package/dist/index.js CHANGED
@@ -285,6 +285,39 @@ var Cell = class {
285
285
  }
286
286
  };
287
287
 
288
+ // src/schema/column-widths.ts
289
+ var ColumnWidths = {
290
+ MAX_INDEX: 16383,
291
+ index(key) {
292
+ if (typeof key === "number") {
293
+ return Number.isInteger(key) && key >= 0 && key <= ColumnWidths.MAX_INDEX ? key : null;
294
+ }
295
+ if (typeof key === "string" && /^[0-9]{1,5}$/.test(key)) {
296
+ const index = parseInt(key, 10);
297
+ return index <= ColumnWidths.MAX_INDEX ? index : null;
298
+ }
299
+ return null;
300
+ },
301
+ width(px) {
302
+ if (typeof px === "number") {
303
+ return Number.isFinite(px) && px >= 0 ? px : null;
304
+ }
305
+ if (typeof px === "string" && /^[0-9]+(\.[0-9]+)?$/.test(px)) {
306
+ return Number(px);
307
+ }
308
+ return null;
309
+ },
310
+ /**
311
+ * A column letter key (`"B"`, `"aa"`) as an index, for repair only. One or two
312
+ * letters (A to ZZ): a longer run like `"abc"` is more likely a mistake than
313
+ * column ABC, and a repair must not guess.
314
+ */
315
+ fromLetters(key) {
316
+ if (typeof key !== "string" || !/^[A-Za-z]{1,2}$/.test(key.trim())) return null;
317
+ return CellAddress.index(key.trim());
318
+ }
319
+ };
320
+
288
321
  // src/workbook/cell-comment.ts
289
322
  var CellComment = class {
290
323
  constructor(text, author = null, color2 = null) {
@@ -629,7 +662,10 @@ var Normalizer = class {
629
662
  normalizeColumnWidths(widths) {
630
663
  const out = /* @__PURE__ */ new Map();
631
664
  for (const [key, px] of Object.entries(widths)) {
632
- out.set(parseInt(key, 10), Number(px));
665
+ const index = ColumnWidths.index(key);
666
+ const width = ColumnWidths.width(px);
667
+ if (index === null || width === null) continue;
668
+ out.set(index, width);
633
669
  }
634
670
  return out;
635
671
  }
@@ -1327,6 +1363,30 @@ var Repairer = class {
1327
1363
  sheet.theme = "default";
1328
1364
  this.repairs.push(`changed '${path}.theme' from '${original}' to 'default' (unknown theme)`);
1329
1365
  }
1366
+ if (sheet.columnWidths != null && (isPlainObject(sheet.columnWidths) || Array.isArray(sheet.columnWidths))) {
1367
+ const widths = {};
1368
+ let changed = false;
1369
+ for (const [key, px] of Object.entries(sheet.columnWidths)) {
1370
+ let index = ColumnWidths.index(key);
1371
+ if (index === null) {
1372
+ const letters = ColumnWidths.fromLetters(key);
1373
+ if (letters !== null) {
1374
+ index = letters;
1375
+ this.repairs.push(`converted '${path}.columnWidths.${key}' to column index ${index}`);
1376
+ changed = true;
1377
+ }
1378
+ }
1379
+ if (index === null || ColumnWidths.width(px) === null) {
1380
+ this.repairs.push(`dropped '${path}.columnWidths.${key}' (not a column index and a width)`);
1381
+ changed = true;
1382
+ continue;
1383
+ }
1384
+ widths[String(index)] = px;
1385
+ }
1386
+ if (changed) {
1387
+ sheet.columnWidths = widths;
1388
+ }
1389
+ }
1330
1390
  if (sheet.cells != null && isPlainObject(sheet.cells)) {
1331
1391
  const cleaned = {};
1332
1392
  let changed = false;
@@ -1532,6 +1592,43 @@ var Validator = class {
1532
1592
  )
1533
1593
  );
1534
1594
  }
1595
+ if (sheet.columnWidths != null) {
1596
+ if (!isPlainObject(sheet.columnWidths) && !Array.isArray(sheet.columnWidths)) {
1597
+ errors.push(
1598
+ error(
1599
+ `${path}.columnWidths`,
1600
+ "object keyed by 0-based column index",
1601
+ typeOf(sheet.columnWidths),
1602
+ sheet.columnWidths,
1603
+ 'Column widths map a 0-based column index to pixels: {"0": 120, "1": 80}.'
1604
+ )
1605
+ );
1606
+ } else {
1607
+ for (const [key, px] of Object.entries(sheet.columnWidths)) {
1608
+ if (ColumnWidths.index(key) === null) {
1609
+ errors.push(
1610
+ error(
1611
+ `${path}.columnWidths.${key}`,
1612
+ `a 0-based column index from 0 to ${ColumnWidths.MAX_INDEX}`,
1613
+ typeOf(key),
1614
+ key,
1615
+ 'Keys are 0-based column indexes: "0" is column A, "1" is column B. Use the index, not the letter.'
1616
+ )
1617
+ );
1618
+ } else if (ColumnWidths.width(px) === null) {
1619
+ errors.push(
1620
+ error(
1621
+ `${path}.columnWidths.${key}`,
1622
+ "a non-negative number of pixels",
1623
+ typeOf(px),
1624
+ px,
1625
+ "A width is a number of pixels, like 120."
1626
+ )
1627
+ );
1628
+ }
1629
+ }
1630
+ }
1631
+ }
1535
1632
  return errors;
1536
1633
  }
1537
1634
  validateColumn(col, path) {
@@ -5039,7 +5136,7 @@ var holy_sheet_schema_default = {
5039
5136
  };
5040
5137
 
5041
5138
  // src/agent.ts
5042
- var VERSION = "2.4.2";
5139
+ var VERSION = "2.4.3";
5043
5140
  function toU8(input) {
5044
5141
  return input instanceof Uint8Array ? input : new Uint8Array(input);
5045
5142
  }