@office-open/xlsx 0.10.2 → 0.10.4

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.
@@ -1,6 +1,6 @@
1
- import { a as SharedStrings } from "./comments-CIu-wLTT.mjs";
1
+ import { a as SharedStrings } from "./comments-BTMAAMY4.mjs";
2
2
  import { attr, attrNum, attrs, children, escapeXml, findChild, stringify, textOf } from "@office-open/xml";
3
- import { ChartCollection, Relationships, derivePasswordHash } from "@office-open/core";
3
+ import { ChartCollection, Media, Relationships, convertToEmu, convertToInch, derivePasswordHash } from "@office-open/core";
4
4
  //#region src/parts/styles.ts
5
5
  function fontKey(f) {
6
6
  return `b${f.bold ? 1 : 0}i${f.italic ? 1 : 0}u${f.underline ? 1 : 0}s${f.strike ? 1 : 0}z${f.size ?? 0}c${f.color ?? ""}n${f.font ?? ""}cs${f.charset ?? ""}fm${f.family ?? ""}co${f.condense ? 1 : 0}ex${f.extend ? 1 : 0}va${f.vertAlign ?? ""}sc${f.scheme ?? ""}sh${f.shadow ? 1 : 0}ol${f.outline ? 1 : 0}`;
@@ -396,14 +396,14 @@ const stylesDesc = {
396
396
  const result = {};
397
397
  const numFmtsEl = findChild(el, "numFmts");
398
398
  if (numFmtsEl) {
399
- const numFmts = {};
399
+ const numFmtById = /* @__PURE__ */ new Map();
400
400
  for (const nf of numFmtsEl.elements ?? []) {
401
401
  if (nf.name !== "numFmt") continue;
402
402
  const id = attrNum(nf, "numFmtId");
403
403
  const code = attr(nf, "formatCode");
404
- if (id !== void 0 && code) numFmts[code] = id;
404
+ if (id !== void 0 && code) numFmtById.set(id, code);
405
405
  }
406
- result.customNumFmts = numFmts;
406
+ result.customNumFmtById = numFmtById;
407
407
  }
408
408
  const fontsEl = findChild(el, "fonts");
409
409
  if (fontsEl) {
@@ -795,12 +795,12 @@ const chartsheetDesc = {
795
795
  if (opts.pageMargins) {
796
796
  const pm = opts.pageMargins;
797
797
  p.push(`<pageMargins${attrs({
798
- left: pm.left ?? .7,
799
- right: pm.right ?? .7,
800
- top: pm.top ?? .75,
801
- bottom: pm.bottom ?? .75,
802
- header: pm.header ?? .3,
803
- footer: pm.footer ?? .3
798
+ left: convertToInch(pm.left ?? .7),
799
+ right: convertToInch(pm.right ?? .7),
800
+ top: convertToInch(pm.top ?? .75),
801
+ bottom: convertToInch(pm.bottom ?? .75),
802
+ header: convertToInch(pm.header ?? .3),
803
+ footer: convertToInch(pm.footer ?? .3)
804
804
  })}/>`);
805
805
  }
806
806
  if (opts.pageSetup) {
@@ -833,7 +833,7 @@ const chartsheetDesc = {
833
833
  if (sheetPr) {
834
834
  if (sheetPr.attributes?.["published"] === "1") result.published = true;
835
835
  const tabColor = findChild(sheetPr, "tabColor");
836
- if (tabColor?.attributes?.["rgb"]) result.tabColor = tabColor.attributes["rgb"];
836
+ if (tabColor?.attributes?.["rgb"]) result.tabColor = String(tabColor.attributes["rgb"]);
837
837
  }
838
838
  const sheetViews = findChild(el, "sheetViews");
839
839
  if (sheetViews) {
@@ -844,6 +844,14 @@ const chartsheetDesc = {
844
844
  };
845
845
  //#endregion
846
846
  //#region src/parts/drawing.ts
847
+ /**
848
+ * XLSX Drawing — image and chart anchor types and descriptor.
849
+ *
850
+ * Generates xl/drawings/drawing{n}.xml using the spreadsheetDrawing
851
+ * namespace for anchoring images and charts to worksheet cells.
852
+ *
853
+ * @module
854
+ */
847
855
  /** How a drawing is anchored to the worksheet (xdr:*Anchor element). */
848
856
  const ANCHOR_TYPES = {
849
857
  twoCell: "twoCell",
@@ -906,7 +914,7 @@ const drawingDesc = {
906
914
  };
907
915
  /** Marker cell (0-based col/row + EMU offsets). */
908
916
  function markerXml(col, colOff, row, rowOff) {
909
- return `<col>${col - 1}</col><colOff>${colOff}</colOff><row>${row - 1}</row><rowOff>${rowOff}</rowOff>`;
917
+ return `<col>${col - 1}</col><colOff>${convertToEmu(colOff)}</colOff><row>${row - 1}</row><rowOff>${convertToEmu(rowOff)}</rowOff>`;
910
918
  }
911
919
  function clientDataXml(img) {
912
920
  return `<clientData fLocksWithSheet="${img.locksWithSheet !== false ? 1 : 0}" fPrintsWithSheet="${img.printsWithSheet !== false ? 1 : 0}"/>`;
@@ -916,11 +924,11 @@ function picXml(rId, id, cx, cy) {
916
924
  }
917
925
  function stringifyImage(img, id) {
918
926
  const anchorType = img.anchorType ?? ANCHOR_TYPES.twoCell;
919
- const cx = img.extentCx ?? DEFAULT_EXTENT_CX;
920
- const cy = img.extentCy ?? DEFAULT_EXTENT_CY;
927
+ const cx = convertToEmu(img.extentCx ?? DEFAULT_EXTENT_CX);
928
+ const cy = convertToEmu(img.extentCy ?? DEFAULT_EXTENT_CY);
921
929
  const pic = picXml(img.rId, id, cx, cy);
922
930
  const clientData = clientDataXml(img);
923
- if (anchorType === ANCHOR_TYPES.absolute) return `<absoluteAnchor><pos x="${img.absoluteX ?? 0}" y="${img.absoluteY ?? 0}"/><ext cx="${cx}" cy="${cy}"/>${pic}${clientData}</absoluteAnchor>`;
931
+ if (anchorType === ANCHOR_TYPES.absolute) return `<absoluteAnchor><pos x="${convertToEmu(img.absoluteX ?? 0)}" y="${convertToEmu(img.absoluteY ?? 0)}"/><ext cx="${cx}" cy="${cy}"/>${pic}${clientData}</absoluteAnchor>`;
924
932
  const from = markerXml(img.col, img.colOffset ?? 0, img.row, img.rowOffset ?? 0);
925
933
  if (anchorType === ANCHOR_TYPES.oneCell) return `<oneCellAnchor><from>${from}</from><ext cx="${cx}" cy="${cy}"/>${pic}${clientData}</oneCellAnchor>`;
926
934
  return `<twoCellAnchor editAs="${img.editAs ?? EDIT_AS_TYPES.oneCell}"><from>${from}</from><to>${markerXml(img.toCol ?? img.col + 1, img.toColOffset ?? 0, img.toRow ?? img.row + 1, img.toRowOffset ?? 0)}</to>${pic}${clientData}</twoCellAnchor>`;
@@ -1111,7 +1119,7 @@ const externalLinkDesc = {
1111
1119
  const bookEl = findChild(el, "externalBook");
1112
1120
  if (bookEl) {
1113
1121
  const book = {};
1114
- if (bookEl.attributes?.["r:id"]) result.bookRId = bookEl.attributes["r:id"];
1122
+ if (bookEl.attributes?.["r:id"]) result.bookRId = String(bookEl.attributes["r:id"]);
1115
1123
  const sheetNamesEl = findChild(bookEl, "sheetNames");
1116
1124
  if (sheetNamesEl) {
1117
1125
  const names = [];
@@ -1123,8 +1131,7 @@ const externalLinkDesc = {
1123
1131
  const dns = [];
1124
1132
  for (const child of definedNamesEl.elements ?? []) {
1125
1133
  if (child.name !== "definedName") continue;
1126
- const dn = {};
1127
- if (child.attributes?.["name"]) dn.name = String(child.attributes["name"]);
1134
+ const dn = { name: String(child.attributes?.["name"] ?? "") };
1128
1135
  if (child.attributes?.["refersTo"]) dn.refersTo = String(child.attributes["refersTo"]);
1129
1136
  if (child.attributes?.["sheetId"] !== void 0) dn.sheetId = Number(child.attributes["sheetId"]);
1130
1137
  if (child.attributes?.["publishToServer"]) dn.publishToServer = true;
@@ -1140,19 +1147,16 @@ const externalLinkDesc = {
1140
1147
  const sds = [];
1141
1148
  for (const sdChild of sheetDataSetEl.elements ?? []) {
1142
1149
  if (sdChild.name !== "sheetData") continue;
1143
- const sd = {};
1144
- if (sdChild.attributes?.["sheetId"] !== void 0) sd.sheetId = Number(sdChild.attributes["sheetId"]);
1150
+ const sd = { sheetId: Number(sdChild.attributes?.["sheetId"] ?? 0) };
1145
1151
  if (sdChild.attributes?.["refreshError"]) sd.refreshError = true;
1146
1152
  const rows = [];
1147
1153
  for (const rowChild of sdChild.elements ?? []) {
1148
1154
  if (rowChild.name !== "row") continue;
1149
- const row = {};
1150
- if (rowChild.attributes?.["r"] !== void 0) row.rowNumber = Number(rowChild.attributes["r"]);
1155
+ const row = { rowNumber: Number(rowChild.attributes?.["r"] ?? 0) };
1151
1156
  const cells = [];
1152
1157
  for (const cellChild of rowChild.elements ?? []) {
1153
1158
  if (cellChild.name !== "cell") continue;
1154
- const cell = {};
1155
- if (cellChild.attributes?.["r"]) cell.reference = String(cellChild.attributes["r"]);
1159
+ const cell = { reference: String(cellChild.attributes?.["r"] ?? "") };
1156
1160
  if (cellChild.attributes?.["t"]) cell.type = String(cellChild.attributes["t"]);
1157
1161
  const vEl = findChild(cellChild, "v");
1158
1162
  if (vEl && vEl.elements?.[0]?.text !== void 0) cell.value = String(vEl.elements[0].text);
@@ -1171,14 +1175,13 @@ const externalLinkDesc = {
1171
1175
  const oleEl = findChild(el, "oleLink");
1172
1176
  if (oleEl) {
1173
1177
  const ole = {};
1174
- if (oleEl.attributes?.["r:id"]) result.oleRId = oleEl.attributes["r:id"];
1178
+ if (oleEl.attributes?.["r:id"]) result.oleRId = String(oleEl.attributes["r:id"]);
1175
1179
  const oleItemsEl = findChild(oleEl, "oleItems");
1176
1180
  if (oleItemsEl) {
1177
1181
  const items = [];
1178
1182
  for (const child of oleItemsEl.elements ?? []) {
1179
1183
  if (child.name !== "oleItem") continue;
1180
- const item = {};
1181
- if (child.attributes?.["name"]) item.name = String(child.attributes["name"]);
1184
+ const item = { name: String(child.attributes?.["name"] ?? "") };
1182
1185
  if (child.attributes?.["advise"]) item.advise = true;
1183
1186
  if (child.attributes?.["prefer"]) item.prefer = true;
1184
1187
  items.push(item);
@@ -2015,7 +2018,8 @@ function parsePivotArea(el) {
2015
2018
  const result = {};
2016
2019
  const field = attrNum(el, "field");
2017
2020
  if (field !== void 0) result.field = field;
2018
- if (attr(el, "type")) result.type = attr(el, "type");
2021
+ const typeVal = attr(el, "type");
2022
+ if (typeVal) result.type = typeVal;
2019
2023
  if (attr(el, "dataOnly") === "0") result.dataOnly = false;
2020
2024
  if (attr(el, "labelOnly") === "1") result.labelOnly = true;
2021
2025
  if (attr(el, "grandRow") === "1") result.grandRow = true;
@@ -2024,7 +2028,8 @@ function parsePivotArea(el) {
2024
2028
  if (attr(el, "outline") === "0") result.outline = false;
2025
2029
  if (attr(el, "offset")) result.offset = attr(el, "offset");
2026
2030
  if (attr(el, "collapsedLevelsAreSubtotals") === "1") result.collapsedLevelsAreSubtotals = true;
2027
- if (attr(el, "axis")) result.axis = attr(el, "axis");
2031
+ const axisVal = attr(el, "axis");
2032
+ if (axisVal) result.axis = axisVal;
2028
2033
  const fp = attrNum(el, "fieldPosition");
2029
2034
  if (fp !== void 0) result.fieldPosition = fp;
2030
2035
  const refsEl = findChild(el, "references");
@@ -2124,18 +2129,23 @@ const pivotCacheRecordsDesc = {
2124
2129
  if (rEl.name !== "r") continue;
2125
2130
  const record = [];
2126
2131
  for (const fEl of rEl.elements ?? []) {
2127
- const entry = {};
2128
- if (fEl.name === "x") {
2129
- entry.type = "string";
2130
- entry.v = attrNum(fEl, "v") ?? 0;
2131
- } else if (fEl.name === "n") {
2132
- entry.type = "number";
2132
+ let entry;
2133
+ if (fEl.name === "x") entry = {
2134
+ type: "string",
2135
+ v: attrNum(fEl, "v") ?? 0
2136
+ };
2137
+ else if (fEl.name === "n") {
2133
2138
  const v = attr(fEl, "v");
2134
- entry.v = v !== void 0 ? Number(v) : 0;
2135
- } else if (fEl.name === "d") {
2136
- entry.type = "date";
2137
- entry.v = attr(fEl, "v") ?? "";
2138
- } else if (fEl.name === "m") entry.type = "missing";
2139
+ entry = {
2140
+ type: "number",
2141
+ v: v !== void 0 ? Number(v) : 0
2142
+ };
2143
+ } else if (fEl.name === "d") entry = {
2144
+ type: "date",
2145
+ v: attr(fEl, "v") ?? ""
2146
+ };
2147
+ else if (fEl.name === "m") entry = { type: "missing" };
2148
+ else continue;
2139
2149
  record.push(entry);
2140
2150
  }
2141
2151
  records.push(record);
@@ -2630,8 +2640,6 @@ const tableDesc = {
2630
2640
  for (const colEl of colsEl.elements ?? []) {
2631
2641
  if (colEl.name !== "tableColumn") continue;
2632
2642
  const col = {};
2633
- const colId = attrNum(colEl, "id");
2634
- if (colId !== void 0) col.id = colId;
2635
2643
  col.name = attr(colEl, "name") ?? "";
2636
2644
  if (attr(colEl, "totalsRowFunction")) col.totalsRowFunction = attr(colEl, "totalsRowFunction");
2637
2645
  if (attr(colEl, "totalsRowLabel")) col.totalsRowLabel = attr(colEl, "totalsRowLabel");
@@ -2854,8 +2862,10 @@ const workbookDesc = {
2854
2862
  if (attr(webPublishingEl, "vml") === "1") wp.vml = true;
2855
2863
  if (attr(webPublishingEl, "allowPng") === "1") wp.allowPng = true;
2856
2864
  if (attr(webPublishingEl, "targetScreenSize")) wp.targetScreenSize = attr(webPublishingEl, "targetScreenSize");
2857
- if (attrNum(webPublishingEl, "dpi") !== void 0) wp.dpi = attrNum(webPublishingEl, "dpi");
2858
- if (attrNum(webPublishingEl, "codePage") !== void 0) wp.codePage = attrNum(webPublishingEl, "codePage");
2865
+ const dpi = attrNum(webPublishingEl, "dpi");
2866
+ if (dpi !== void 0) wp.dpi = dpi;
2867
+ const codePage = attrNum(webPublishingEl, "codePage");
2868
+ if (codePage !== void 0) wp.codePage = codePage;
2859
2869
  if (attr(webPublishingEl, "characterSet")) wp.characterSet = attr(webPublishingEl, "characterSet");
2860
2870
  result.webPublishing = wp;
2861
2871
  }
@@ -2903,9 +2913,7 @@ const workbookDesc = {
2903
2913
  const objs = [];
2904
2914
  for (const wo of wpoEl.elements ?? []) {
2905
2915
  if (wo.name !== "webPublishObject") continue;
2906
- const obj = {};
2907
- const rId = wo.attributes?.["r:id"];
2908
- if (rId) obj.rId = rId;
2916
+ const obj = { rId: wo.attributes?.["r:id"] ?? "" };
2909
2917
  if (attr(wo, "destinationFile")) obj.destinationFile = attr(wo, "destinationFile");
2910
2918
  if (attr(wo, "autoRepublish") === "1") obj.autoRepublish = true;
2911
2919
  if (attr(wo, "title")) obj.title = attr(wo, "title");
@@ -2921,28 +2929,28 @@ const workbookDesc = {
2921
2929
  for (const vt of vtEl.elements ?? []) {
2922
2930
  if (vt.name !== "volType") continue;
2923
2931
  const volType = {};
2924
- if (attr(vt, "type")) volType.type = attr(vt, "type");
2932
+ const typeVal = attr(vt, "type");
2933
+ if (typeVal) volType.type = typeVal;
2925
2934
  const mains = [];
2926
2935
  for (const m of vt.elements ?? []) {
2927
2936
  if (m.name !== "main") continue;
2928
- const main = {};
2929
- if (attr(m, "first")) main.first = attr(m, "first");
2937
+ const main = { first: attr(m, "first") ?? "" };
2930
2938
  const topics = [];
2931
2939
  for (const tp of m.elements ?? []) {
2932
2940
  if (tp.name !== "tp") continue;
2933
- const topic = {};
2934
2941
  const vEl = findChild(tp, "v");
2935
- if (vEl) topic.value = vEl.elements?.[0]?.text ?? "";
2936
- if (attr(tp, "t")) topic.valueType = attr(tp, "t");
2942
+ const topic = { value: String(vEl?.elements?.[0]?.text ?? "") };
2943
+ const tVal = attr(tp, "t");
2944
+ if (tVal) topic.valueType = tVal;
2937
2945
  const stps = [];
2938
2946
  const refs = [];
2939
2947
  for (const inner of tp.elements ?? []) {
2940
2948
  if (inner.name === "stp") stps.push(String(inner.elements?.[0]?.text ?? ""));
2941
2949
  if (inner.name === "tr") {
2942
- const ref = {};
2943
- if (attr(inner, "r")) ref.reference = attr(inner, "r");
2944
- const sIdx = attrNum(inner, "s");
2945
- if (sIdx !== void 0) ref.sheetIndex = sIdx;
2950
+ const ref = {
2951
+ reference: attr(inner, "r") ?? "",
2952
+ sheetIndex: attrNum(inner, "s") ?? 0
2953
+ };
2946
2954
  refs.push(ref);
2947
2955
  }
2948
2956
  }
@@ -3938,17 +3946,6 @@ var ContentTypes = class {
3938
3946
  }
3939
3947
  };
3940
3948
  //#endregion
3941
- //#region src/parts/media.ts
3942
- var Media = class {
3943
- map = /* @__PURE__ */ new Map();
3944
- addImage(key, data) {
3945
- this.map.set(key, data);
3946
- }
3947
- get array() {
3948
- return [...this.map.values()];
3949
- }
3950
- };
3951
- //#endregion
3952
3949
  //#region src/context.ts
3953
3950
  /**
3954
3951
  * XLSX compile context — write and read contexts for the descriptor pipeline.
@@ -4065,7 +4062,7 @@ var XlsxReadContext = class {
4065
4062
  resolveStyle(styleIndex) {
4066
4063
  const ps = this.parsedStyles;
4067
4064
  if (!ps) return void 0;
4068
- const { cellXfs, fonts, fills, borders, customNumFmts } = ps;
4065
+ const { cellXfs, fonts, fills, borders, customNumFmtById } = ps;
4069
4066
  if (!cellXfs || styleIndex >= cellXfs.length) return void 0;
4070
4067
  const xf = cellXfs[styleIndex];
4071
4068
  const result = {};
@@ -4076,11 +4073,9 @@ var XlsxReadContext = class {
4076
4073
  const borderId = xf.borderId;
4077
4074
  if (borderId !== void 0 && borders && borderId < borders.length) result.border = borders[borderId];
4078
4075
  const numFmtId = xf.numFmtId;
4079
- if (numFmtId !== void 0 && customNumFmts) {
4080
- for (const [code, id] of Object.entries(customNumFmts)) if (id === numFmtId) {
4081
- result.numFmt = code;
4082
- break;
4083
- }
4076
+ if (numFmtId !== void 0 && customNumFmtById) {
4077
+ const code = customNumFmtById.get(numFmtId);
4078
+ if (code !== void 0) result.numFmt = code;
4084
4079
  }
4085
4080
  if (xf.alignment) result.alignment = xf.alignment;
4086
4081
  if (xf.protection) result.protection = xf.protection;
@@ -4105,6 +4100,6 @@ function resolveWsTarget(wsPath, target) {
4105
4100
  return dirParts.join("/");
4106
4101
  }
4107
4102
  //#endregion
4108
- export { stylesDesc as C, Styles as S, collectUniqueValues as _, usersDesc as a, chartsheetDesc as b, workbookDesc as c, tableDesc as d, pivotCacheDefDesc as f, aggregate as g, PivotFilterType as h, revisionLogDesc as i, TableType as l, pivotTableDesc as m, XlsxWriteContext as n, buildExternalReferencesXml as o, pivotCacheRecordsDesc as p, revisionHeadersDesc as r, buildTablePartsXml as s, XlsxReadContext as t, TotalsRowFunction as u, externalLinkDesc as v, calcChainDesc as x, drawingDesc as y };
4103
+ export { Styles as C, calcChainDesc as S, aggregate as _, usersDesc as a, drawingDesc as b, buildTablePartsXml as c, TotalsRowFunction as d, tableDesc as f, PivotFilterType as g, pivotTableDesc as h, revisionLogDesc as i, workbookDesc as l, pivotCacheRecordsDesc as m, XlsxWriteContext as n, Media as o, pivotCacheDefDesc as p, revisionHeadersDesc as r, buildExternalReferencesXml as s, XlsxReadContext as t, TableType as u, collectUniqueValues as v, stylesDesc as w, chartsheetDesc as x, externalLinkDesc as y };
4109
4104
 
4110
- //# sourceMappingURL=context-Btk-2AKp.mjs.map
4105
+ //# sourceMappingURL=context-D_9UIEwJ.mjs.map