xls-codec 4.13.0 → 4.15.0

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 (58) hide show
  1. package/README.md +37 -19
  2. package/dist/biff/record-writer.cjs +18 -0
  3. package/dist/biff/record-writer.d.cts +7 -1
  4. package/dist/biff/record-writer.d.ts +7 -1
  5. package/dist/biff/record-writer.js +18 -1
  6. package/dist/container.cjs +9 -1
  7. package/dist/container.d.cts +2 -0
  8. package/dist/container.d.ts +2 -0
  9. package/dist/container.js +9 -1
  10. package/dist/content.cjs +6 -5
  11. package/dist/content.js +6 -5
  12. package/dist/drawing/escher-constants.cjs +6 -0
  13. package/dist/drawing/escher-constants.d.cts +5 -1
  14. package/dist/drawing/escher-constants.d.ts +5 -1
  15. package/dist/drawing/escher-constants.js +5 -1
  16. package/dist/drawing/escher-writer.cjs +107 -0
  17. package/dist/drawing/escher-writer.d.cts +32 -0
  18. package/dist/drawing/escher-writer.d.ts +32 -0
  19. package/dist/drawing/escher-writer.js +105 -0
  20. package/dist/drawing/md4.cjs +146 -0
  21. package/dist/drawing/md4.d.cts +7 -0
  22. package/dist/drawing/md4.d.ts +7 -0
  23. package/dist/drawing/md4.js +145 -0
  24. package/dist/drawing-writer-Blm_NUSZ.d.cts +19 -0
  25. package/dist/drawing-writer-Blm_NUSZ.d.ts +19 -0
  26. package/dist/index.cjs +1 -0
  27. package/dist/index.d.cts +2 -2
  28. package/dist/index.d.ts +2 -2
  29. package/dist/index.js +2 -2
  30. package/dist/workbook/comments.cjs +26 -0
  31. package/dist/workbook/comments.d.cts +7 -1
  32. package/dist/workbook/comments.d.ts +7 -1
  33. package/dist/workbook/comments.js +26 -1
  34. package/dist/workbook/conditional-format-write.cjs +307 -18
  35. package/dist/workbook/conditional-format-write.js +307 -18
  36. package/dist/workbook/drawing-writer.cjs +253 -0
  37. package/dist/workbook/drawing-writer.d.cts +2 -0
  38. package/dist/workbook/drawing-writer.d.ts +2 -0
  39. package/dist/workbook/drawing-writer.js +252 -0
  40. package/dist/workbook/drawing.cjs +24 -3
  41. package/dist/workbook/drawing.d.cts +2 -0
  42. package/dist/workbook/drawing.d.ts +2 -0
  43. package/dist/workbook/drawing.js +25 -4
  44. package/dist/workbook/embedded-object.cjs +43 -0
  45. package/dist/workbook/embedded-object.d.cts +8 -0
  46. package/dist/workbook/embedded-object.d.ts +8 -0
  47. package/dist/workbook/embedded-object.js +41 -0
  48. package/dist/workbook/globals-writer.cjs +1 -0
  49. package/dist/workbook/globals-writer.d.cts +2 -0
  50. package/dist/workbook/globals-writer.d.ts +2 -0
  51. package/dist/workbook/globals-writer.js +2 -1
  52. package/dist/workbook/sheet-writer.cjs +4 -3
  53. package/dist/workbook/sheet-writer.d.cts +3 -2
  54. package/dist/workbook/sheet-writer.d.ts +3 -2
  55. package/dist/workbook/sheet-writer.js +4 -3
  56. package/dist/write.cjs +17 -7
  57. package/dist/write.js +17 -7
  58. package/package.json +4 -4
package/dist/write.cjs CHANGED
@@ -9,6 +9,7 @@ const require_metadata = require("./metadata.cjs");
9
9
  const require_workbook_globals_writer = require("./workbook/globals-writer.cjs");
10
10
  const require_written_cells = require("./written-cells.cjs");
11
11
  const require_workbook_sheet_writer = require("./workbook/sheet-writer.cjs");
12
+ const require_workbook_drawing_writer = require("./workbook/drawing-writer.cjs");
12
13
  let archive_codec = require("archive-codec");
13
14
  let document_schema_js = require("document-schema.js");
14
15
  let excel_number_format = require("excel-number-format");
@@ -120,7 +121,7 @@ function buildPalettePlan(sheets) {
120
121
  record(cell.borders?.bottom?.color);
121
122
  }
122
123
  for (const rule of sheet.conditionalFormats ?? []) {
123
- if (rule.type !== "cellIs") continue;
124
+ if (!("style" in rule)) continue;
124
125
  record(rule.style?.textColor);
125
126
  record(rule.style?.background);
126
127
  }
@@ -340,6 +341,7 @@ function buildWorkbookStream(content) {
340
341
  const palettePlan = buildPalettePlan(content.sheets);
341
342
  const fontPlan = buildFontPlan(content.sheets, palettePlan);
342
343
  const cellXfPlan = buildCellXfPlan(content.sheets, formatPlan, palettePlan, fontPlan);
344
+ const drawingPlan = require_workbook_drawing_writer.buildDrawingWritePlan(content.sheets);
343
345
  const globalsPlan = {
344
346
  sheetNames: content.sheets.map((sheet) => sheet.name),
345
347
  fonts: fontPlan.fontEntries,
@@ -349,7 +351,8 @@ function buildWorkbookStream(content) {
349
351
  sharedStringTotalCount: sstPlan.totalCount,
350
352
  paletteColors: palettePlan.paletteColors,
351
353
  printNames: buildPrintNamePlan(content.sheets),
352
- definedNames: require_workbook_defined_names.definedNameEntriesFor(content.names ?? [], content.sheets)
354
+ definedNames: require_workbook_defined_names.definedNameEntriesFor(content.names ?? [], content.sheets),
355
+ drawingGroupBytes: drawingPlan.drawingGroupBytes
353
356
  };
354
357
  const globals = require_workbook_globals_writer.buildWorkbookGlobals(globalsPlan);
355
358
  const sheetContext = {
@@ -357,7 +360,11 @@ function buildWorkbookStream(content) {
357
360
  sstIndexFor: (text) => sstPlan.indexOf(text),
358
361
  icvOf: palettePlan.icvOf
359
362
  };
360
- const sheetStreams = content.sheets.map((sheet) => require_workbook_sheet_writer.buildWorksheetSubstream(sheet, sheetContext));
363
+ const sheetStreams = content.sheets.map((sheet, index) => {
364
+ const drawing = drawingPlan.sheetDrawings[index];
365
+ if (drawing === void 0) throw new require_biff_write_errors.BiffWriteError(`internal error: sheet ${index} has no drawing plan entry -- buildDrawingWritePlan produced fewer entries than there are sheets`);
366
+ return require_workbook_sheet_writer.buildWorksheetSubstream(sheet, sheetContext, drawing);
367
+ });
361
368
  const sheetOffsets = [];
362
369
  let offset = globals.bytes.length;
363
370
  for (const stream of sheetStreams) {
@@ -366,7 +373,10 @@ function buildWorkbookStream(content) {
366
373
  }
367
374
  const globalsBytes = globals.bytes.slice();
368
375
  patchBoundSheetOffsets(globalsBytes, globals.lbPlyPosOffsets, sheetOffsets);
369
- return concatBytes([globalsBytes, ...sheetStreams]);
376
+ return {
377
+ bytes: concatBytes([globalsBytes, ...sheetStreams]),
378
+ embeddingStreams: drawingPlan.embeddingStreams
379
+ };
370
380
  }
371
381
  /**
372
382
  * Writes a spreadsheet ContentDocument to real .xls bytes: a BIFF8 Workbook stream wrapped in an [MS-CFB] compound file.
@@ -374,11 +384,11 @@ function buildWorkbookStream(content) {
374
384
  * The counterpart of content.ts's readXlsContent. See this package's README for the writer's full scope.
375
385
  */
376
386
  function writeXlsContent(content) {
377
- const stream = buildWorkbookStream(content);
387
+ const workbook = buildWorkbookStream(content);
378
388
  const streams = [{
379
389
  path: WORKBOOK_STREAM_NAME,
380
- bytes: stream
381
- }];
390
+ bytes: workbook.bytes
391
+ }, ...workbook.embeddingStreams];
382
392
  if ((0, archive_codec.hasSummaryInformationFields)(content.metadata)) streams.push({
383
393
  path: require_container.SUMMARY_INFORMATION_STREAM,
384
394
  bytes: (0, archive_codec.writeSummaryInformationStream)(require_metadata.layoutMetadataToSummaryInformation(content.metadata))
package/dist/write.js CHANGED
@@ -8,6 +8,7 @@ import { layoutMetadataToSummaryInformation as layoutMetadataToSummaryInformatio
8
8
  import { GENERAL_CELL_XF_INDEX, buildWorkbookGlobals } from "./workbook/globals-writer.js";
9
9
  import { cellCarriesFormatting, writesCellRecord } from "./written-cells.js";
10
10
  import { buildWorksheetSubstream } from "./workbook/sheet-writer.js";
11
+ import { buildDrawingWritePlan } from "./workbook/drawing-writer.js";
11
12
  import { hasSummaryInformationFields, writeCompoundFile, writeSummaryInformationStream } from "archive-codec";
12
13
  import { colorToRgbHex, flattenTree, unrecognizedFillKind } from "document-schema.js";
13
14
  import { BUILTIN_NUMBER_FORMATS, isIsoCurrencyCodeShape } from "excel-number-format";
@@ -119,7 +120,7 @@ function buildPalettePlan(sheets) {
119
120
  record(cell.borders?.bottom?.color);
120
121
  }
121
122
  for (const rule of sheet.conditionalFormats ?? []) {
122
- if (rule.type !== "cellIs") continue;
123
+ if (!("style" in rule)) continue;
123
124
  record(rule.style?.textColor);
124
125
  record(rule.style?.background);
125
126
  }
@@ -339,6 +340,7 @@ function buildWorkbookStream(content) {
339
340
  const palettePlan = buildPalettePlan(content.sheets);
340
341
  const fontPlan = buildFontPlan(content.sheets, palettePlan);
341
342
  const cellXfPlan = buildCellXfPlan(content.sheets, formatPlan, palettePlan, fontPlan);
343
+ const drawingPlan = buildDrawingWritePlan(content.sheets);
342
344
  const globalsPlan = {
343
345
  sheetNames: content.sheets.map((sheet) => sheet.name),
344
346
  fonts: fontPlan.fontEntries,
@@ -348,7 +350,8 @@ function buildWorkbookStream(content) {
348
350
  sharedStringTotalCount: sstPlan.totalCount,
349
351
  paletteColors: palettePlan.paletteColors,
350
352
  printNames: buildPrintNamePlan(content.sheets),
351
- definedNames: definedNameEntriesFor(content.names ?? [], content.sheets)
353
+ definedNames: definedNameEntriesFor(content.names ?? [], content.sheets),
354
+ drawingGroupBytes: drawingPlan.drawingGroupBytes
352
355
  };
353
356
  const globals = buildWorkbookGlobals(globalsPlan);
354
357
  const sheetContext = {
@@ -356,7 +359,11 @@ function buildWorkbookStream(content) {
356
359
  sstIndexFor: (text) => sstPlan.indexOf(text),
357
360
  icvOf: palettePlan.icvOf
358
361
  };
359
- const sheetStreams = content.sheets.map((sheet) => buildWorksheetSubstream(sheet, sheetContext));
362
+ const sheetStreams = content.sheets.map((sheet, index) => {
363
+ const drawing = drawingPlan.sheetDrawings[index];
364
+ if (drawing === void 0) throw new BiffWriteError(`internal error: sheet ${index} has no drawing plan entry -- buildDrawingWritePlan produced fewer entries than there are sheets`);
365
+ return buildWorksheetSubstream(sheet, sheetContext, drawing);
366
+ });
360
367
  const sheetOffsets = [];
361
368
  let offset = globals.bytes.length;
362
369
  for (const stream of sheetStreams) {
@@ -365,7 +372,10 @@ function buildWorkbookStream(content) {
365
372
  }
366
373
  const globalsBytes = globals.bytes.slice();
367
374
  patchBoundSheetOffsets(globalsBytes, globals.lbPlyPosOffsets, sheetOffsets);
368
- return concatBytes([globalsBytes, ...sheetStreams]);
375
+ return {
376
+ bytes: concatBytes([globalsBytes, ...sheetStreams]),
377
+ embeddingStreams: drawingPlan.embeddingStreams
378
+ };
369
379
  }
370
380
  /**
371
381
  * Writes a spreadsheet ContentDocument to real .xls bytes: a BIFF8 Workbook stream wrapped in an [MS-CFB] compound file.
@@ -373,11 +383,11 @@ function buildWorkbookStream(content) {
373
383
  * The counterpart of content.ts's readXlsContent. See this package's README for the writer's full scope.
374
384
  */
375
385
  function writeXlsContent(content) {
376
- const stream = buildWorkbookStream(content);
386
+ const workbook = buildWorkbookStream(content);
377
387
  const streams = [{
378
388
  path: WORKBOOK_STREAM_NAME,
379
- bytes: stream
380
- }];
389
+ bytes: workbook.bytes
390
+ }, ...workbook.embeddingStreams];
381
391
  if (hasSummaryInformationFields(content.metadata)) streams.push({
382
392
  path: SUMMARY_INFORMATION_STREAM,
383
393
  bytes: writeSummaryInformationStream(layoutMetadataToSummaryInformation$1(content.metadata))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xls-codec",
3
- "version": "4.13.0",
3
+ "version": "4.15.0",
4
4
  "description": "Hand-written reader for the legacy Excel Binary File Format (.xls, BIFF8) as specified by [MS-XLS], mapping a workbook's record stream onto the shared document-schema.js spreadsheet model - the .xls codec for the documents.js family.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -70,9 +70,9 @@
70
70
  },
71
71
  "packageManager": "pnpm@11.6.0",
72
72
  "dependencies": {
73
- "archive-codec": "1.10.8",
74
- "document-schema.js": "7.10.0",
75
- "excel-number-format": "1.1.1"
73
+ "archive-codec": "1.11.0",
74
+ "document-schema.js": "7.11.0",
75
+ "excel-number-format": "1.2.0"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@arethetypeswrong/cli": "0.18.5",