xls-codec 4.7.6 → 4.8.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 (78) hide show
  1. package/README.md +7 -2
  2. package/dist/biff/record-types.cjs +21 -0
  3. package/dist/biff/record-types.d.cts +15 -1
  4. package/dist/biff/record-types.d.ts +15 -1
  5. package/dist/biff/record-types.js +15 -1
  6. package/dist/biff/substreams.cjs +7 -8
  7. package/dist/biff/substreams.d.cts +1 -1
  8. package/dist/biff/substreams.d.ts +1 -1
  9. package/dist/biff/substreams.js +7 -8
  10. package/dist/{conditional-format-12-DBhe7Zo6.d.cts → conditional-format-12-CZ43-CR4.d.cts} +2 -2
  11. package/dist/{conditional-format-12-D-X5g_O3.d.ts → conditional-format-12-Xl52VBCj.d.ts} +2 -2
  12. package/dist/{conditional-format-Czh2oTzQ.d.cts → conditional-format-Bt1vRWgc.d.cts} +1 -1
  13. package/dist/{conditional-format-DOdazxWe.d.ts → conditional-format-Cqcjnm7O.d.ts} +1 -1
  14. package/dist/content.cjs +40 -18
  15. package/dist/content.js +40 -18
  16. package/dist/{data-validation-BXvIVU0e.d.ts → data-validation-BeYpL3Nb.d.ts} +1 -1
  17. package/dist/{data-validation-DfpjUN-N.d.cts → data-validation-lJWM9-AP.d.cts} +1 -1
  18. package/dist/drawing/blips.cjs +83 -0
  19. package/dist/drawing/blips.d.cts +10 -0
  20. package/dist/drawing/blips.d.ts +10 -0
  21. package/dist/drawing/blips.js +82 -0
  22. package/dist/drawing/bytes.cjs +15 -0
  23. package/dist/drawing/bytes.d.cts +5 -0
  24. package/dist/drawing/bytes.d.ts +5 -0
  25. package/dist/drawing/bytes.js +14 -0
  26. package/dist/drawing/escher-constants.cjs +52 -0
  27. package/dist/drawing/escher-constants.d.cts +34 -0
  28. package/dist/drawing/escher-constants.d.ts +34 -0
  29. package/dist/drawing/escher-constants.js +34 -0
  30. package/dist/drawing/escher.cjs +84 -0
  31. package/dist/drawing/escher.d.cts +30 -0
  32. package/dist/drawing/escher.d.ts +30 -0
  33. package/dist/drawing/escher.js +80 -0
  34. package/dist/drawing/shapes.cjs +80 -0
  35. package/dist/drawing/shapes.d.cts +24 -0
  36. package/dist/drawing/shapes.d.ts +24 -0
  37. package/dist/drawing/shapes.js +79 -0
  38. package/dist/index.cjs +10 -1
  39. package/dist/index.d.cts +4 -4
  40. package/dist/index.d.ts +4 -4
  41. package/dist/index.js +4 -4
  42. package/dist/{print-names-CCwUHAoL.d.cts → print-names-B2OR0fvs.d.cts} +1 -1
  43. package/dist/{print-names-CxAbgcjB.d.ts → print-names-BXcmmwVi.d.ts} +1 -1
  44. package/dist/{substreams-Dp5cZoUo.d.ts → substreams-CgTHx5kX.d.ts} +1 -1
  45. package/dist/{substreams-CHv3oWmn.d.cts → substreams-XDNgDvRJ.d.cts} +1 -1
  46. package/dist/units.cjs +7 -0
  47. package/dist/units.d.cts +6 -1
  48. package/dist/units.d.ts +6 -1
  49. package/dist/units.js +6 -1
  50. package/dist/workbook/chart.cjs +230 -0
  51. package/dist/workbook/chart.d.cts +19 -0
  52. package/dist/workbook/chart.d.ts +19 -0
  53. package/dist/workbook/chart.js +229 -0
  54. package/dist/workbook/comments.cjs +2 -1
  55. package/dist/workbook/comments.d.cts +7 -2
  56. package/dist/workbook/comments.d.ts +7 -2
  57. package/dist/workbook/comments.js +2 -2
  58. package/dist/workbook/conditional-format-12.d.cts +1 -1
  59. package/dist/workbook/conditional-format-12.d.ts +1 -1
  60. package/dist/workbook/conditional-format.d.cts +1 -1
  61. package/dist/workbook/conditional-format.d.ts +1 -1
  62. package/dist/workbook/data-validation.d.cts +1 -1
  63. package/dist/workbook/data-validation.d.ts +1 -1
  64. package/dist/workbook/drawing.cjs +270 -0
  65. package/dist/workbook/drawing.d.cts +31 -0
  66. package/dist/workbook/drawing.d.ts +31 -0
  67. package/dist/workbook/drawing.js +268 -0
  68. package/dist/workbook/globals-writer.d.cts +1 -1
  69. package/dist/workbook/globals-writer.d.ts +1 -1
  70. package/dist/workbook/globals.d.cts +2 -2
  71. package/dist/workbook/globals.d.ts +2 -2
  72. package/dist/workbook/print-names.d.cts +1 -1
  73. package/dist/workbook/print-names.d.ts +1 -1
  74. package/dist/workbook/sheet-writer.cjs +1 -1
  75. package/dist/workbook/sheet-writer.js +1 -1
  76. package/dist/workbook/sheet.d.cts +4 -4
  77. package/dist/workbook/sheet.d.ts +4 -4
  78. package/package.json +1 -1
@@ -0,0 +1,270 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../biff/record-types.cjs");
3
+ const require_units = require("../units.cjs");
4
+ require("../drawing/escher-constants.cjs");
5
+ const require_drawing_bytes = require("../drawing/bytes.cjs");
6
+ const require_workbook_comments = require("./comments.cjs");
7
+ const require_drawing_shapes = require("../drawing/shapes.cjs");
8
+ const require_workbook_chart = require("./chart.cjs");
9
+ let document_schema_js = require("document-schema.js");
10
+ //#region src/workbook/drawing.ts
11
+ /** [MS-XLS] "FtCmo" ot enumeration, the values this reader routes on. */
12
+ const OBJECT_TYPE_CHART = 5;
13
+ const OBJECT_TYPE_PICTURE = 8;
14
+ /** The Note object type comments.ts's own Note/Obj/Txo reading already fully accounts for -- a comment's own callout box carries an MsoDrawing shape too, and pairing it here as well would emit a spurious, contentless 'drawing' embedded object for every cell comment on the sheet. */
15
+ const OBJECT_TYPE_NOTE = 25;
16
+ const GRID_UNITS_X = 1024;
17
+ const GRID_UNITS_Y = 256;
18
+ /** The worksheet grid geometry a cell anchor resolves against -- declared column widths/row heights with Excel's own Normal-style default beneath, mirroring ooxml.js's identical SheetGridGeometry for the xlsx case. */
19
+ var SheetGridGeometry = class {
20
+ columnWidths = /* @__PURE__ */ new Map();
21
+ rowHeights = /* @__PURE__ */ new Map();
22
+ defaultColumnWidthPt = require_units.columnWidthToPoints(require_units.DEFAULT_COLUMN_WIDTH_CHARS * 256);
23
+ constructor(columns, rows) {
24
+ for (const column of columns) if (column.widthPt !== void 0) this.columnWidths.set(column.index, column.widthPt);
25
+ for (const row of rows) if (row.heightPt !== void 0) this.rowHeights.set(row.index, row.heightPt);
26
+ }
27
+ columnWidthPt(index) {
28
+ return this.columnWidths.get(index) ?? this.defaultColumnWidthPt;
29
+ }
30
+ rowHeightPt(index) {
31
+ return this.rowHeights.get(index) ?? 15;
32
+ }
33
+ /** The absolute page-space X of a given column's own left edge -- the cumulative width of every column before it. */
34
+ xPt(column) {
35
+ let x = 0;
36
+ for (let index = 0; index < column; index += 1) x += this.columnWidthPt(index);
37
+ return x;
38
+ }
39
+ yPt(row) {
40
+ let y = 0;
41
+ for (let index = 0; index < row; index += 1) y += this.rowHeightPt(index);
42
+ return y;
43
+ }
44
+ };
45
+ /** Resolves an OfficeArtClientAnchorSheet into the cell-relative placement ContentSheetImage/ContentEmbeddedObject both carry, plus the page-absolute frame box a Box's own xPt/yPt/widthPt/heightPt need -- dxL/dxR in 1/1024ths of the anchor cell's own width, dyT/dyB in 1/256ths of its own height ([MS-XLS] 2.5.163). */
46
+ function resolveAnchorPlacement(anchor, geometry) {
47
+ const offsetXPt = geometry.columnWidthPt(anchor.colL) * anchor.dxL / GRID_UNITS_X;
48
+ const offsetYPt = geometry.rowHeightPt(anchor.rwT) * anchor.dyT / GRID_UNITS_Y;
49
+ const xPt = geometry.xPt(anchor.colL) + offsetXPt;
50
+ const yPt = geometry.yPt(anchor.rwT) + offsetYPt;
51
+ const rightPt = geometry.xPt(anchor.colR) + geometry.columnWidthPt(anchor.colR) * anchor.dxR / GRID_UNITS_X;
52
+ const bottomPt = geometry.yPt(anchor.rwB) + geometry.rowHeightPt(anchor.rwB) * anchor.dyB / GRID_UNITS_Y;
53
+ return {
54
+ xPt,
55
+ yPt,
56
+ widthPt: rightPt - xPt,
57
+ heightPt: bottomPt - yPt,
58
+ anchorRow: anchor.rwT,
59
+ anchorColumn: anchor.colL,
60
+ offsetXPt,
61
+ offsetYPt
62
+ };
63
+ }
64
+ /** Reads one worksheet's own drawing content: every MsoDrawing record's bytes concatenated into one Escher stream (drawing/shapes.ts), each of its real top-level shapes paired 1:1, in document order, with the non-Note Obj records the same substream carries. */
65
+ function readSheetDrawing(worksheetRecords, context) {
66
+ const drawingChunks = [];
67
+ const objEntries = [];
68
+ for (let index = 0; index < worksheetRecords.length; index += 1) {
69
+ const record = worksheetRecords[index];
70
+ if (record === void 0) continue;
71
+ if (record.type === 236) {
72
+ const block = record.blocks[0];
73
+ if (block !== void 0) drawingChunks.push(block);
74
+ continue;
75
+ }
76
+ if (record.type === 93) {
77
+ const { ot } = require_workbook_comments.readObjTypeAndId(record);
78
+ const nextOffset = worksheetRecords[index + 1]?.offset ?? Number.POSITIVE_INFINITY;
79
+ objEntries.push({
80
+ ot,
81
+ offset: record.offset,
82
+ nextOffset
83
+ });
84
+ }
85
+ }
86
+ if (drawingChunks.length === 0) return {
87
+ images: [],
88
+ embeddedObjects: []
89
+ };
90
+ const drawingBytes = require_drawing_bytes.concatBytes(drawingChunks);
91
+ const shapes = require_drawing_shapes.readSheetShapes(drawingBytes);
92
+ const geometry = new SheetGridGeometry(context.columns, context.rows);
93
+ const images = [];
94
+ const embeddedObjects = [];
95
+ const pairCount = Math.min(shapes.length, objEntries.length);
96
+ for (let index = 0; index < pairCount; index += 1) {
97
+ const shape = shapes[index];
98
+ const obj = objEntries[index];
99
+ if (shape === void 0 || obj === void 0 || obj.ot === OBJECT_TYPE_NOTE) continue;
100
+ if (obj.ot === OBJECT_TYPE_PICTURE || shape.shapeType === 75) {
101
+ const image = imageFromShape(shape, context, geometry);
102
+ if (image !== void 0) images.push(image);
103
+ continue;
104
+ }
105
+ if (obj.ot === OBJECT_TYPE_CHART) {
106
+ const chart = chartFromShape(shape, obj.offset, obj.nextOffset, context, geometry);
107
+ if (chart !== void 0) embeddedObjects.push(chart);
108
+ continue;
109
+ }
110
+ const drawing = drawingObjectFromShape(shape, geometry);
111
+ if (drawing !== void 0) embeddedObjects.push(drawing);
112
+ }
113
+ return {
114
+ images,
115
+ embeddedObjects
116
+ };
117
+ }
118
+ function imageFromShape(shape, context, geometry) {
119
+ if (shape.blipIndex === void 0) return;
120
+ const blip = context.blipStore.get(shape.blipIndex);
121
+ if (blip === void 0) return;
122
+ const placement = resolveAnchorPlacement(shape.anchor, geometry);
123
+ if (placement.widthPt <= 0 || placement.heightPt <= 0) return;
124
+ return {
125
+ kind: "image",
126
+ format: blip.format,
127
+ base64: blip.base64,
128
+ widthPt: placement.widthPt,
129
+ heightPt: placement.heightPt,
130
+ anchorRow: placement.anchorRow,
131
+ anchorColumn: placement.anchorColumn,
132
+ offsetXPt: placement.offsetXPt,
133
+ offsetYPt: placement.offsetYPt
134
+ };
135
+ }
136
+ /** Locates the chart's own nested BOF(dt=chart)...EOF substream: the one whose own BOF offset falls strictly between this Obj record's offset and whichever worksheet record comes right after it in the ORIGINAL stream -- splitSubstreams' own nesting fix (biff/substreams.ts) pulls a nested chart's records out of the worksheet substream's own `records` array entirely and reports it as its own top-level Substream instead, so byte-offset containment, not array position, is what still ties the two together. */
137
+ function chartFromShape(shape, objOffset, nextOffset, context, geometry) {
138
+ const chartSubstream = context.allSubstreams.find((candidate) => candidate.documentType === 32 && candidate.offset > objOffset && candidate.offset < nextOffset);
139
+ if (chartSubstream === void 0) return;
140
+ const placement = resolveAnchorPlacement(shape.anchor, geometry);
141
+ const rangeContext = {
142
+ formulaSheets: context.formulaSheets,
143
+ ownSheetIndex: context.ownSheetIndex,
144
+ ownSheetCells: context.ownSheetCells
145
+ };
146
+ const series = require_workbook_chart.readChartSeries(chartSubstream.records, rangeContext);
147
+ return {
148
+ objectKind: "chart",
149
+ document: {
150
+ kind: "spreadsheet",
151
+ metadata: context.metadata,
152
+ sheets: [{
153
+ name: "Chart",
154
+ cells: chartTableCells(series),
155
+ columns: [],
156
+ rows: [],
157
+ images: [],
158
+ printSettings: {
159
+ pageSize: document_schema_js.PAGE_SIZE_LETTER,
160
+ margins: {
161
+ topPt: 0,
162
+ rightPt: 0,
163
+ bottomPt: 0,
164
+ leftPt: 0
165
+ },
166
+ gridlines: false,
167
+ headers: false,
168
+ pageOrder: "downThenOver"
169
+ }
170
+ }]
171
+ },
172
+ frame: {
173
+ xPt: placement.xPt,
174
+ yPt: placement.yPt,
175
+ widthPt: placement.widthPt,
176
+ heightPt: placement.heightPt
177
+ },
178
+ anchorRow: placement.anchorRow,
179
+ anchorColumn: placement.anchorColumn,
180
+ offsetXPt: placement.offsetXPt,
181
+ offsetYPt: placement.offsetYPt
182
+ };
183
+ }
184
+ /** Lays a chart's own series out as ooxml.js's readChartTable does for the identical xlsx/pptx case: a header row of series names over the category column, then one row per category with each series' own value -- see workbook/chart.ts's own top comment for why this flattened shape, not a typed chart object, is what document-schema.js's 'chart' objectKind actually carries. */
185
+ function chartTableCells(series) {
186
+ const cells = [];
187
+ series.forEach((entry, seriesIndex) => {
188
+ const name = entry.name ?? "";
189
+ if (name !== "") cells.push({
190
+ row: 0,
191
+ column: seriesIndex + 1,
192
+ value: {
193
+ kind: "string",
194
+ value: name
195
+ },
196
+ displayText: name
197
+ });
198
+ entry.values.forEach((value, pointIndex) => {
199
+ if (value === "") return;
200
+ cells.push({
201
+ row: pointIndex + 1,
202
+ column: seriesIndex + 1,
203
+ value: {
204
+ kind: "string",
205
+ value
206
+ },
207
+ displayText: value
208
+ });
209
+ });
210
+ });
211
+ const categories = /* @__PURE__ */ new Map();
212
+ for (const entry of series) entry.categories.forEach((category, pointIndex) => {
213
+ if (category !== "" && !categories.has(pointIndex)) categories.set(pointIndex, category);
214
+ });
215
+ for (const [pointIndex, category] of categories) cells.push({
216
+ row: pointIndex + 1,
217
+ column: 0,
218
+ value: {
219
+ kind: "string",
220
+ value: category
221
+ },
222
+ displayText: category
223
+ });
224
+ return cells;
225
+ }
226
+ /** A shape this reader recognises as neither a picture nor a chart -- an autoshape, a text box, a line, a group -- carried as a 'drawing' embedded object: a single-page ContentDocument holding one ContentShape sized and positioned at the shape's own anchor. Undefined for the patriarch/group-only case readSheetShapes already excludes, and for a shape whose own anchor collapses to zero size. */
227
+ function drawingObjectFromShape(shape, geometry) {
228
+ const placement = resolveAnchorPlacement(shape.anchor, geometry);
229
+ if (placement.widthPt <= 0 || placement.heightPt <= 0) return;
230
+ return {
231
+ objectKind: "drawing",
232
+ document: {
233
+ kind: "drawing",
234
+ metadata: {},
235
+ pages: [{
236
+ size: {
237
+ widthPt: placement.widthPt,
238
+ heightPt: placement.heightPt
239
+ },
240
+ shapes: [{
241
+ frame: {
242
+ xPt: 0,
243
+ yPt: 0,
244
+ widthPt: placement.widthPt,
245
+ heightPt: placement.heightPt
246
+ },
247
+ insetLeftPt: 0,
248
+ insetTopPt: 0,
249
+ insetRightPt: 0,
250
+ insetBottomPt: 0,
251
+ blocks: []
252
+ }],
253
+ vectors: []
254
+ }]
255
+ },
256
+ frame: {
257
+ xPt: placement.xPt,
258
+ yPt: placement.yPt,
259
+ widthPt: placement.widthPt,
260
+ heightPt: placement.heightPt
261
+ },
262
+ anchorRow: placement.anchorRow,
263
+ anchorColumn: placement.anchorColumn,
264
+ offsetXPt: placement.offsetXPt,
265
+ offsetYPt: placement.offsetYPt
266
+ };
267
+ }
268
+ //#endregion
269
+ exports.chartTableCells = chartTableCells;
270
+ exports.readSheetDrawing = readSheetDrawing;
@@ -0,0 +1,31 @@
1
+ import { r as FormulaSheetContext } from "../ptg-CCBbJLZJ.cjs";
2
+ import { n as Substream, t as RecordGroup } from "../substreams-XDNgDvRJ.cjs";
3
+ import { BlipImage } from "../drawing/blips.cjs";
4
+ import { RawColumn, RawRow } from "./sheet.cjs";
5
+ import { ContentEmbeddedObject, ContentSheetCell, ContentSheetImage, LayoutMetadata } from "document-schema.js";
6
+ //#region src/workbook/drawing.d.ts
7
+ interface SheetDrawing {
8
+ readonly images: readonly ContentSheetImage[];
9
+ readonly embeddedObjects: readonly ContentEmbeddedObject[];
10
+ }
11
+ interface SheetDrawingContext {
12
+ readonly blipStore: ReadonlyMap<number, BlipImage>;
13
+ readonly columns: readonly RawColumn[];
14
+ readonly rows: readonly RawRow[];
15
+ readonly ownSheetIndex: number;
16
+ readonly formulaSheets: FormulaSheetContext;
17
+ readonly ownSheetCells: readonly ContentSheetCell[];
18
+ readonly metadata: LayoutMetadata;
19
+ /** Every substream the workbook stream carries -- searched for the chart substream a Chart-type Obj record's own nested BOF...EOF produced (splitSubstreams reports it as its own entry, positioned by byte offset rather than nested inside the worksheet's own `records`; see biff/substreams.ts's own top comment for why). */
20
+ readonly allSubstreams: readonly Substream[];
21
+ }
22
+ /** Reads one worksheet's own drawing content: every MsoDrawing record's bytes concatenated into one Escher stream (drawing/shapes.ts), each of its real top-level shapes paired 1:1, in document order, with the non-Note Obj records the same substream carries. */
23
+ declare function readSheetDrawing(worksheetRecords: readonly RecordGroup[], context: SheetDrawingContext): SheetDrawing;
24
+ /** Lays a chart's own series out as ooxml.js's readChartTable does for the identical xlsx/pptx case: a header row of series names over the category column, then one row per category with each series' own value -- see workbook/chart.ts's own top comment for why this flattened shape, not a typed chart object, is what document-schema.js's 'chart' objectKind actually carries. */
25
+ declare function chartTableCells(series: readonly {
26
+ readonly name: string | undefined;
27
+ readonly categories: readonly string[];
28
+ readonly values: readonly string[];
29
+ }[]): ContentSheetCell[];
30
+ //#endregion
31
+ export { SheetDrawing, SheetDrawingContext, chartTableCells, readSheetDrawing };
@@ -0,0 +1,31 @@
1
+ import { r as FormulaSheetContext } from "../ptg-CCBbJLZJ.js";
2
+ import { n as Substream, t as RecordGroup } from "../substreams-CgTHx5kX.js";
3
+ import { BlipImage } from "../drawing/blips.js";
4
+ import { RawColumn, RawRow } from "./sheet.js";
5
+ import { ContentEmbeddedObject, ContentSheetCell, ContentSheetImage, LayoutMetadata } from "document-schema.js";
6
+ //#region src/workbook/drawing.d.ts
7
+ interface SheetDrawing {
8
+ readonly images: readonly ContentSheetImage[];
9
+ readonly embeddedObjects: readonly ContentEmbeddedObject[];
10
+ }
11
+ interface SheetDrawingContext {
12
+ readonly blipStore: ReadonlyMap<number, BlipImage>;
13
+ readonly columns: readonly RawColumn[];
14
+ readonly rows: readonly RawRow[];
15
+ readonly ownSheetIndex: number;
16
+ readonly formulaSheets: FormulaSheetContext;
17
+ readonly ownSheetCells: readonly ContentSheetCell[];
18
+ readonly metadata: LayoutMetadata;
19
+ /** Every substream the workbook stream carries -- searched for the chart substream a Chart-type Obj record's own nested BOF...EOF produced (splitSubstreams reports it as its own entry, positioned by byte offset rather than nested inside the worksheet's own `records`; see biff/substreams.ts's own top comment for why). */
20
+ readonly allSubstreams: readonly Substream[];
21
+ }
22
+ /** Reads one worksheet's own drawing content: every MsoDrawing record's bytes concatenated into one Escher stream (drawing/shapes.ts), each of its real top-level shapes paired 1:1, in document order, with the non-Note Obj records the same substream carries. */
23
+ declare function readSheetDrawing(worksheetRecords: readonly RecordGroup[], context: SheetDrawingContext): SheetDrawing;
24
+ /** Lays a chart's own series out as ooxml.js's readChartTable does for the identical xlsx/pptx case: a header row of series names over the category column, then one row per category with each series' own value -- see workbook/chart.ts's own top comment for why this flattened shape, not a typed chart object, is what document-schema.js's 'chart' objectKind actually carries. */
25
+ declare function chartTableCells(series: readonly {
26
+ readonly name: string | undefined;
27
+ readonly categories: readonly string[];
28
+ readonly values: readonly string[];
29
+ }[]): ContentSheetCell[];
30
+ //#endregion
31
+ export { SheetDrawing, SheetDrawingContext, chartTableCells, readSheetDrawing };
@@ -0,0 +1,268 @@
1
+ import "../biff/record-types.js";
2
+ import { DEFAULT_COLUMN_WIDTH_CHARS, columnWidthToPoints } from "../units.js";
3
+ import "../drawing/escher-constants.js";
4
+ import { concatBytes } from "../drawing/bytes.js";
5
+ import { readObjTypeAndId } from "./comments.js";
6
+ import { readSheetShapes } from "../drawing/shapes.js";
7
+ import { readChartSeries } from "./chart.js";
8
+ import { PAGE_SIZE_LETTER } from "document-schema.js";
9
+ //#region src/workbook/drawing.ts
10
+ /** [MS-XLS] "FtCmo" ot enumeration, the values this reader routes on. */
11
+ const OBJECT_TYPE_CHART = 5;
12
+ const OBJECT_TYPE_PICTURE = 8;
13
+ /** The Note object type comments.ts's own Note/Obj/Txo reading already fully accounts for -- a comment's own callout box carries an MsoDrawing shape too, and pairing it here as well would emit a spurious, contentless 'drawing' embedded object for every cell comment on the sheet. */
14
+ const OBJECT_TYPE_NOTE = 25;
15
+ const GRID_UNITS_X = 1024;
16
+ const GRID_UNITS_Y = 256;
17
+ /** The worksheet grid geometry a cell anchor resolves against -- declared column widths/row heights with Excel's own Normal-style default beneath, mirroring ooxml.js's identical SheetGridGeometry for the xlsx case. */
18
+ var SheetGridGeometry = class {
19
+ columnWidths = /* @__PURE__ */ new Map();
20
+ rowHeights = /* @__PURE__ */ new Map();
21
+ defaultColumnWidthPt = columnWidthToPoints(DEFAULT_COLUMN_WIDTH_CHARS * 256);
22
+ constructor(columns, rows) {
23
+ for (const column of columns) if (column.widthPt !== void 0) this.columnWidths.set(column.index, column.widthPt);
24
+ for (const row of rows) if (row.heightPt !== void 0) this.rowHeights.set(row.index, row.heightPt);
25
+ }
26
+ columnWidthPt(index) {
27
+ return this.columnWidths.get(index) ?? this.defaultColumnWidthPt;
28
+ }
29
+ rowHeightPt(index) {
30
+ return this.rowHeights.get(index) ?? 15;
31
+ }
32
+ /** The absolute page-space X of a given column's own left edge -- the cumulative width of every column before it. */
33
+ xPt(column) {
34
+ let x = 0;
35
+ for (let index = 0; index < column; index += 1) x += this.columnWidthPt(index);
36
+ return x;
37
+ }
38
+ yPt(row) {
39
+ let y = 0;
40
+ for (let index = 0; index < row; index += 1) y += this.rowHeightPt(index);
41
+ return y;
42
+ }
43
+ };
44
+ /** Resolves an OfficeArtClientAnchorSheet into the cell-relative placement ContentSheetImage/ContentEmbeddedObject both carry, plus the page-absolute frame box a Box's own xPt/yPt/widthPt/heightPt need -- dxL/dxR in 1/1024ths of the anchor cell's own width, dyT/dyB in 1/256ths of its own height ([MS-XLS] 2.5.163). */
45
+ function resolveAnchorPlacement(anchor, geometry) {
46
+ const offsetXPt = geometry.columnWidthPt(anchor.colL) * anchor.dxL / GRID_UNITS_X;
47
+ const offsetYPt = geometry.rowHeightPt(anchor.rwT) * anchor.dyT / GRID_UNITS_Y;
48
+ const xPt = geometry.xPt(anchor.colL) + offsetXPt;
49
+ const yPt = geometry.yPt(anchor.rwT) + offsetYPt;
50
+ const rightPt = geometry.xPt(anchor.colR) + geometry.columnWidthPt(anchor.colR) * anchor.dxR / GRID_UNITS_X;
51
+ const bottomPt = geometry.yPt(anchor.rwB) + geometry.rowHeightPt(anchor.rwB) * anchor.dyB / GRID_UNITS_Y;
52
+ return {
53
+ xPt,
54
+ yPt,
55
+ widthPt: rightPt - xPt,
56
+ heightPt: bottomPt - yPt,
57
+ anchorRow: anchor.rwT,
58
+ anchorColumn: anchor.colL,
59
+ offsetXPt,
60
+ offsetYPt
61
+ };
62
+ }
63
+ /** Reads one worksheet's own drawing content: every MsoDrawing record's bytes concatenated into one Escher stream (drawing/shapes.ts), each of its real top-level shapes paired 1:1, in document order, with the non-Note Obj records the same substream carries. */
64
+ function readSheetDrawing(worksheetRecords, context) {
65
+ const drawingChunks = [];
66
+ const objEntries = [];
67
+ for (let index = 0; index < worksheetRecords.length; index += 1) {
68
+ const record = worksheetRecords[index];
69
+ if (record === void 0) continue;
70
+ if (record.type === 236) {
71
+ const block = record.blocks[0];
72
+ if (block !== void 0) drawingChunks.push(block);
73
+ continue;
74
+ }
75
+ if (record.type === 93) {
76
+ const { ot } = readObjTypeAndId(record);
77
+ const nextOffset = worksheetRecords[index + 1]?.offset ?? Number.POSITIVE_INFINITY;
78
+ objEntries.push({
79
+ ot,
80
+ offset: record.offset,
81
+ nextOffset
82
+ });
83
+ }
84
+ }
85
+ if (drawingChunks.length === 0) return {
86
+ images: [],
87
+ embeddedObjects: []
88
+ };
89
+ const drawingBytes = concatBytes(drawingChunks);
90
+ const shapes = readSheetShapes(drawingBytes);
91
+ const geometry = new SheetGridGeometry(context.columns, context.rows);
92
+ const images = [];
93
+ const embeddedObjects = [];
94
+ const pairCount = Math.min(shapes.length, objEntries.length);
95
+ for (let index = 0; index < pairCount; index += 1) {
96
+ const shape = shapes[index];
97
+ const obj = objEntries[index];
98
+ if (shape === void 0 || obj === void 0 || obj.ot === OBJECT_TYPE_NOTE) continue;
99
+ if (obj.ot === OBJECT_TYPE_PICTURE || shape.shapeType === 75) {
100
+ const image = imageFromShape(shape, context, geometry);
101
+ if (image !== void 0) images.push(image);
102
+ continue;
103
+ }
104
+ if (obj.ot === OBJECT_TYPE_CHART) {
105
+ const chart = chartFromShape(shape, obj.offset, obj.nextOffset, context, geometry);
106
+ if (chart !== void 0) embeddedObjects.push(chart);
107
+ continue;
108
+ }
109
+ const drawing = drawingObjectFromShape(shape, geometry);
110
+ if (drawing !== void 0) embeddedObjects.push(drawing);
111
+ }
112
+ return {
113
+ images,
114
+ embeddedObjects
115
+ };
116
+ }
117
+ function imageFromShape(shape, context, geometry) {
118
+ if (shape.blipIndex === void 0) return;
119
+ const blip = context.blipStore.get(shape.blipIndex);
120
+ if (blip === void 0) return;
121
+ const placement = resolveAnchorPlacement(shape.anchor, geometry);
122
+ if (placement.widthPt <= 0 || placement.heightPt <= 0) return;
123
+ return {
124
+ kind: "image",
125
+ format: blip.format,
126
+ base64: blip.base64,
127
+ widthPt: placement.widthPt,
128
+ heightPt: placement.heightPt,
129
+ anchorRow: placement.anchorRow,
130
+ anchorColumn: placement.anchorColumn,
131
+ offsetXPt: placement.offsetXPt,
132
+ offsetYPt: placement.offsetYPt
133
+ };
134
+ }
135
+ /** Locates the chart's own nested BOF(dt=chart)...EOF substream: the one whose own BOF offset falls strictly between this Obj record's offset and whichever worksheet record comes right after it in the ORIGINAL stream -- splitSubstreams' own nesting fix (biff/substreams.ts) pulls a nested chart's records out of the worksheet substream's own `records` array entirely and reports it as its own top-level Substream instead, so byte-offset containment, not array position, is what still ties the two together. */
136
+ function chartFromShape(shape, objOffset, nextOffset, context, geometry) {
137
+ const chartSubstream = context.allSubstreams.find((candidate) => candidate.documentType === 32 && candidate.offset > objOffset && candidate.offset < nextOffset);
138
+ if (chartSubstream === void 0) return;
139
+ const placement = resolveAnchorPlacement(shape.anchor, geometry);
140
+ const rangeContext = {
141
+ formulaSheets: context.formulaSheets,
142
+ ownSheetIndex: context.ownSheetIndex,
143
+ ownSheetCells: context.ownSheetCells
144
+ };
145
+ const series = readChartSeries(chartSubstream.records, rangeContext);
146
+ return {
147
+ objectKind: "chart",
148
+ document: {
149
+ kind: "spreadsheet",
150
+ metadata: context.metadata,
151
+ sheets: [{
152
+ name: "Chart",
153
+ cells: chartTableCells(series),
154
+ columns: [],
155
+ rows: [],
156
+ images: [],
157
+ printSettings: {
158
+ pageSize: PAGE_SIZE_LETTER,
159
+ margins: {
160
+ topPt: 0,
161
+ rightPt: 0,
162
+ bottomPt: 0,
163
+ leftPt: 0
164
+ },
165
+ gridlines: false,
166
+ headers: false,
167
+ pageOrder: "downThenOver"
168
+ }
169
+ }]
170
+ },
171
+ frame: {
172
+ xPt: placement.xPt,
173
+ yPt: placement.yPt,
174
+ widthPt: placement.widthPt,
175
+ heightPt: placement.heightPt
176
+ },
177
+ anchorRow: placement.anchorRow,
178
+ anchorColumn: placement.anchorColumn,
179
+ offsetXPt: placement.offsetXPt,
180
+ offsetYPt: placement.offsetYPt
181
+ };
182
+ }
183
+ /** Lays a chart's own series out as ooxml.js's readChartTable does for the identical xlsx/pptx case: a header row of series names over the category column, then one row per category with each series' own value -- see workbook/chart.ts's own top comment for why this flattened shape, not a typed chart object, is what document-schema.js's 'chart' objectKind actually carries. */
184
+ function chartTableCells(series) {
185
+ const cells = [];
186
+ series.forEach((entry, seriesIndex) => {
187
+ const name = entry.name ?? "";
188
+ if (name !== "") cells.push({
189
+ row: 0,
190
+ column: seriesIndex + 1,
191
+ value: {
192
+ kind: "string",
193
+ value: name
194
+ },
195
+ displayText: name
196
+ });
197
+ entry.values.forEach((value, pointIndex) => {
198
+ if (value === "") return;
199
+ cells.push({
200
+ row: pointIndex + 1,
201
+ column: seriesIndex + 1,
202
+ value: {
203
+ kind: "string",
204
+ value
205
+ },
206
+ displayText: value
207
+ });
208
+ });
209
+ });
210
+ const categories = /* @__PURE__ */ new Map();
211
+ for (const entry of series) entry.categories.forEach((category, pointIndex) => {
212
+ if (category !== "" && !categories.has(pointIndex)) categories.set(pointIndex, category);
213
+ });
214
+ for (const [pointIndex, category] of categories) cells.push({
215
+ row: pointIndex + 1,
216
+ column: 0,
217
+ value: {
218
+ kind: "string",
219
+ value: category
220
+ },
221
+ displayText: category
222
+ });
223
+ return cells;
224
+ }
225
+ /** A shape this reader recognises as neither a picture nor a chart -- an autoshape, a text box, a line, a group -- carried as a 'drawing' embedded object: a single-page ContentDocument holding one ContentShape sized and positioned at the shape's own anchor. Undefined for the patriarch/group-only case readSheetShapes already excludes, and for a shape whose own anchor collapses to zero size. */
226
+ function drawingObjectFromShape(shape, geometry) {
227
+ const placement = resolveAnchorPlacement(shape.anchor, geometry);
228
+ if (placement.widthPt <= 0 || placement.heightPt <= 0) return;
229
+ return {
230
+ objectKind: "drawing",
231
+ document: {
232
+ kind: "drawing",
233
+ metadata: {},
234
+ pages: [{
235
+ size: {
236
+ widthPt: placement.widthPt,
237
+ heightPt: placement.heightPt
238
+ },
239
+ shapes: [{
240
+ frame: {
241
+ xPt: 0,
242
+ yPt: 0,
243
+ widthPt: placement.widthPt,
244
+ heightPt: placement.heightPt
245
+ },
246
+ insetLeftPt: 0,
247
+ insetTopPt: 0,
248
+ insetRightPt: 0,
249
+ insetBottomPt: 0,
250
+ blocks: []
251
+ }],
252
+ vectors: []
253
+ }]
254
+ },
255
+ frame: {
256
+ xPt: placement.xPt,
257
+ yPt: placement.yPt,
258
+ widthPt: placement.widthPt,
259
+ heightPt: placement.heightPt
260
+ },
261
+ anchorRow: placement.anchorRow,
262
+ anchorColumn: placement.anchorColumn,
263
+ offsetXPt: placement.offsetXPt,
264
+ offsetYPt: placement.offsetYPt
265
+ };
266
+ }
267
+ //#endregion
268
+ export { chartTableCells, readSheetDrawing };
@@ -1,5 +1,5 @@
1
1
  import { E as XfDecorationFields } from "../xf-colors-mqerVt2O.cjs";
2
- import { t as PrintNamePlanEntry } from "../print-names-CCwUHAoL.cjs";
2
+ import { t as PrintNamePlanEntry } from "../print-names-B2OR0fvs.cjs";
3
3
  import { Alignment, Color } from "document-schema.js";
4
4
  //#region src/workbook/globals-writer.d.ts
5
5
  /** [MS-XLS] 2.1.7.20.3's own XFS production requires at least sixteen XF records before any cell can reference one: BUILTIN_STYLES.length built-in cell styles, then at least one cell XF -- the "General, no declared format" one every workbook needs unconditionally, written immediately after them. Derived from BUILTIN_STYLES's own length rather than restated as a literal, so the two can never drift apart. */
@@ -1,5 +1,5 @@
1
1
  import { E as XfDecorationFields } from "../xf-colors-d3OvRw76.js";
2
- import { t as PrintNamePlanEntry } from "../print-names-CxAbgcjB.js";
2
+ import { t as PrintNamePlanEntry } from "../print-names-BXcmmwVi.js";
3
3
  import { Alignment, Color } from "document-schema.js";
4
4
  //#region src/workbook/globals-writer.d.ts
5
5
  /** [MS-XLS] 2.1.7.20.3's own XFS production requires at least sixteen XF records before any cell can reference one: BUILTIN_STYLES.length built-in cell styles, then at least one cell XF -- the "General, no declared format" one every workbook needs unconditionally, written immediately after them. Derived from BUILTIN_STYLES's own length rather than restated as a literal, so the two can never drift apart. */
@@ -1,7 +1,7 @@
1
1
  import { a as SheetRange, t as ExternalSheetLabel } from "../ptg-CCBbJLZJ.cjs";
2
- import { t as RecordGroup } from "../substreams-CHv3oWmn.cjs";
2
+ import { t as RecordGroup } from "../substreams-XDNgDvRJ.cjs";
3
3
  import { E as XfDecorationFields, w as XfAlignmentFields } from "../xf-colors-mqerVt2O.cjs";
4
- import { n as SheetPrintNames } from "../print-names-CCwUHAoL.cjs";
4
+ import { n as SheetPrintNames } from "../print-names-B2OR0fvs.cjs";
5
5
  import { Color } from "document-schema.js";
6
6
  //#region src/workbook/globals.d.ts
7
7
  /** One sheet, as its BoundSheet8 record describes it ([MS-XLS] 2.4.28). */
@@ -1,7 +1,7 @@
1
1
  import { a as SheetRange, t as ExternalSheetLabel } from "../ptg-CCBbJLZJ.js";
2
- import { t as RecordGroup } from "../substreams-Dp5cZoUo.js";
2
+ import { t as RecordGroup } from "../substreams-CgTHx5kX.js";
3
3
  import { E as XfDecorationFields, w as XfAlignmentFields } from "../xf-colors-d3OvRw76.js";
4
- import { n as SheetPrintNames } from "../print-names-CxAbgcjB.js";
4
+ import { n as SheetPrintNames } from "../print-names-BXcmmwVi.js";
5
5
  import { Color } from "document-schema.js";
6
6
  //#region src/workbook/globals.d.ts
7
7
  /** One sheet, as its BoundSheet8 record describes it ([MS-XLS] 2.4.28). */
@@ -1,2 +1,2 @@
1
- import { a as writePrintNameRecords, i as readPrintNames, n as SheetPrintNames, r as printNameEntriesFor, t as PrintNamePlanEntry } from "../print-names-CCwUHAoL.cjs";
1
+ import { a as writePrintNameRecords, i as readPrintNames, n as SheetPrintNames, r as printNameEntriesFor, t as PrintNamePlanEntry } from "../print-names-B2OR0fvs.cjs";
2
2
  export { PrintNamePlanEntry, SheetPrintNames, printNameEntriesFor, readPrintNames, writePrintNameRecords };
@@ -1,2 +1,2 @@
1
- import { a as writePrintNameRecords, i as readPrintNames, n as SheetPrintNames, r as printNameEntriesFor, t as PrintNamePlanEntry } from "../print-names-CxAbgcjB.js";
1
+ import { a as writePrintNameRecords, i as readPrintNames, n as SheetPrintNames, r as printNameEntriesFor, t as PrintNamePlanEntry } from "../print-names-BXcmmwVi.js";
2
2
  export { PrintNamePlanEntry, SheetPrintNames, printNameEntriesFor, readPrintNames, writePrintNameRecords };
@@ -2,11 +2,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_biff_record_types = require("../biff/record-types.cjs");
3
3
  const require_units = require("../units.cjs");
4
4
  const require_biff_print_setup = require("../biff/print-setup.cjs");
5
+ const require_biff_errors = require("../biff/errors.cjs");
5
6
  const require_biff_write_errors = require("../biff/write-errors.cjs");
6
7
  const require_serial = require("../serial.cjs");
7
8
  const require_biff_builder = require("../biff/builder.cjs");
8
9
  const require_biff_record_writer = require("../biff/record-writer.cjs");
9
- const require_biff_errors = require("../biff/errors.cjs");
10
10
  const require_biff_bof_writer = require("../biff/bof-writer.cjs");
11
11
  const require_workbook_globals_writer = require("./globals-writer.cjs");
12
12
  const require_written_cells = require("../written-cells.cjs");