@office-open/xlsx 0.10.2 → 0.10.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.
@@ -1,6 +1,6 @@
1
- import { a as SharedStrings } from "./comments-CIu-wLTT.mjs";
1
+ import { a as SharedStrings } from "./comments-CQ5dlj-4.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, 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) {
@@ -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) {
@@ -1111,7 +1111,7 @@ const externalLinkDesc = {
1111
1111
  const bookEl = findChild(el, "externalBook");
1112
1112
  if (bookEl) {
1113
1113
  const book = {};
1114
- if (bookEl.attributes?.["r:id"]) result.bookRId = bookEl.attributes["r:id"];
1114
+ if (bookEl.attributes?.["r:id"]) result.bookRId = String(bookEl.attributes["r:id"]);
1115
1115
  const sheetNamesEl = findChild(bookEl, "sheetNames");
1116
1116
  if (sheetNamesEl) {
1117
1117
  const names = [];
@@ -1123,8 +1123,7 @@ const externalLinkDesc = {
1123
1123
  const dns = [];
1124
1124
  for (const child of definedNamesEl.elements ?? []) {
1125
1125
  if (child.name !== "definedName") continue;
1126
- const dn = {};
1127
- if (child.attributes?.["name"]) dn.name = String(child.attributes["name"]);
1126
+ const dn = { name: String(child.attributes?.["name"] ?? "") };
1128
1127
  if (child.attributes?.["refersTo"]) dn.refersTo = String(child.attributes["refersTo"]);
1129
1128
  if (child.attributes?.["sheetId"] !== void 0) dn.sheetId = Number(child.attributes["sheetId"]);
1130
1129
  if (child.attributes?.["publishToServer"]) dn.publishToServer = true;
@@ -1140,19 +1139,16 @@ const externalLinkDesc = {
1140
1139
  const sds = [];
1141
1140
  for (const sdChild of sheetDataSetEl.elements ?? []) {
1142
1141
  if (sdChild.name !== "sheetData") continue;
1143
- const sd = {};
1144
- if (sdChild.attributes?.["sheetId"] !== void 0) sd.sheetId = Number(sdChild.attributes["sheetId"]);
1142
+ const sd = { sheetId: Number(sdChild.attributes?.["sheetId"] ?? 0) };
1145
1143
  if (sdChild.attributes?.["refreshError"]) sd.refreshError = true;
1146
1144
  const rows = [];
1147
1145
  for (const rowChild of sdChild.elements ?? []) {
1148
1146
  if (rowChild.name !== "row") continue;
1149
- const row = {};
1150
- if (rowChild.attributes?.["r"] !== void 0) row.rowNumber = Number(rowChild.attributes["r"]);
1147
+ const row = { rowNumber: Number(rowChild.attributes?.["r"] ?? 0) };
1151
1148
  const cells = [];
1152
1149
  for (const cellChild of rowChild.elements ?? []) {
1153
1150
  if (cellChild.name !== "cell") continue;
1154
- const cell = {};
1155
- if (cellChild.attributes?.["r"]) cell.reference = String(cellChild.attributes["r"]);
1151
+ const cell = { reference: String(cellChild.attributes?.["r"] ?? "") };
1156
1152
  if (cellChild.attributes?.["t"]) cell.type = String(cellChild.attributes["t"]);
1157
1153
  const vEl = findChild(cellChild, "v");
1158
1154
  if (vEl && vEl.elements?.[0]?.text !== void 0) cell.value = String(vEl.elements[0].text);
@@ -1171,14 +1167,13 @@ const externalLinkDesc = {
1171
1167
  const oleEl = findChild(el, "oleLink");
1172
1168
  if (oleEl) {
1173
1169
  const ole = {};
1174
- if (oleEl.attributes?.["r:id"]) result.oleRId = oleEl.attributes["r:id"];
1170
+ if (oleEl.attributes?.["r:id"]) result.oleRId = String(oleEl.attributes["r:id"]);
1175
1171
  const oleItemsEl = findChild(oleEl, "oleItems");
1176
1172
  if (oleItemsEl) {
1177
1173
  const items = [];
1178
1174
  for (const child of oleItemsEl.elements ?? []) {
1179
1175
  if (child.name !== "oleItem") continue;
1180
- const item = {};
1181
- if (child.attributes?.["name"]) item.name = String(child.attributes["name"]);
1176
+ const item = { name: String(child.attributes?.["name"] ?? "") };
1182
1177
  if (child.attributes?.["advise"]) item.advise = true;
1183
1178
  if (child.attributes?.["prefer"]) item.prefer = true;
1184
1179
  items.push(item);
@@ -2015,7 +2010,8 @@ function parsePivotArea(el) {
2015
2010
  const result = {};
2016
2011
  const field = attrNum(el, "field");
2017
2012
  if (field !== void 0) result.field = field;
2018
- if (attr(el, "type")) result.type = attr(el, "type");
2013
+ const typeVal = attr(el, "type");
2014
+ if (typeVal) result.type = typeVal;
2019
2015
  if (attr(el, "dataOnly") === "0") result.dataOnly = false;
2020
2016
  if (attr(el, "labelOnly") === "1") result.labelOnly = true;
2021
2017
  if (attr(el, "grandRow") === "1") result.grandRow = true;
@@ -2024,7 +2020,8 @@ function parsePivotArea(el) {
2024
2020
  if (attr(el, "outline") === "0") result.outline = false;
2025
2021
  if (attr(el, "offset")) result.offset = attr(el, "offset");
2026
2022
  if (attr(el, "collapsedLevelsAreSubtotals") === "1") result.collapsedLevelsAreSubtotals = true;
2027
- if (attr(el, "axis")) result.axis = attr(el, "axis");
2023
+ const axisVal = attr(el, "axis");
2024
+ if (axisVal) result.axis = axisVal;
2028
2025
  const fp = attrNum(el, "fieldPosition");
2029
2026
  if (fp !== void 0) result.fieldPosition = fp;
2030
2027
  const refsEl = findChild(el, "references");
@@ -2124,18 +2121,23 @@ const pivotCacheRecordsDesc = {
2124
2121
  if (rEl.name !== "r") continue;
2125
2122
  const record = [];
2126
2123
  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";
2124
+ let entry;
2125
+ if (fEl.name === "x") entry = {
2126
+ type: "string",
2127
+ v: attrNum(fEl, "v") ?? 0
2128
+ };
2129
+ else if (fEl.name === "n") {
2133
2130
  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";
2131
+ entry = {
2132
+ type: "number",
2133
+ v: v !== void 0 ? Number(v) : 0
2134
+ };
2135
+ } else if (fEl.name === "d") entry = {
2136
+ type: "date",
2137
+ v: attr(fEl, "v") ?? ""
2138
+ };
2139
+ else if (fEl.name === "m") entry = { type: "missing" };
2140
+ else continue;
2139
2141
  record.push(entry);
2140
2142
  }
2141
2143
  records.push(record);
@@ -2630,8 +2632,6 @@ const tableDesc = {
2630
2632
  for (const colEl of colsEl.elements ?? []) {
2631
2633
  if (colEl.name !== "tableColumn") continue;
2632
2634
  const col = {};
2633
- const colId = attrNum(colEl, "id");
2634
- if (colId !== void 0) col.id = colId;
2635
2635
  col.name = attr(colEl, "name") ?? "";
2636
2636
  if (attr(colEl, "totalsRowFunction")) col.totalsRowFunction = attr(colEl, "totalsRowFunction");
2637
2637
  if (attr(colEl, "totalsRowLabel")) col.totalsRowLabel = attr(colEl, "totalsRowLabel");
@@ -2854,8 +2854,10 @@ const workbookDesc = {
2854
2854
  if (attr(webPublishingEl, "vml") === "1") wp.vml = true;
2855
2855
  if (attr(webPublishingEl, "allowPng") === "1") wp.allowPng = true;
2856
2856
  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");
2857
+ const dpi = attrNum(webPublishingEl, "dpi");
2858
+ if (dpi !== void 0) wp.dpi = dpi;
2859
+ const codePage = attrNum(webPublishingEl, "codePage");
2860
+ if (codePage !== void 0) wp.codePage = codePage;
2859
2861
  if (attr(webPublishingEl, "characterSet")) wp.characterSet = attr(webPublishingEl, "characterSet");
2860
2862
  result.webPublishing = wp;
2861
2863
  }
@@ -2903,9 +2905,7 @@ const workbookDesc = {
2903
2905
  const objs = [];
2904
2906
  for (const wo of wpoEl.elements ?? []) {
2905
2907
  if (wo.name !== "webPublishObject") continue;
2906
- const obj = {};
2907
- const rId = wo.attributes?.["r:id"];
2908
- if (rId) obj.rId = rId;
2908
+ const obj = { rId: wo.attributes?.["r:id"] ?? "" };
2909
2909
  if (attr(wo, "destinationFile")) obj.destinationFile = attr(wo, "destinationFile");
2910
2910
  if (attr(wo, "autoRepublish") === "1") obj.autoRepublish = true;
2911
2911
  if (attr(wo, "title")) obj.title = attr(wo, "title");
@@ -2921,28 +2921,28 @@ const workbookDesc = {
2921
2921
  for (const vt of vtEl.elements ?? []) {
2922
2922
  if (vt.name !== "volType") continue;
2923
2923
  const volType = {};
2924
- if (attr(vt, "type")) volType.type = attr(vt, "type");
2924
+ const typeVal = attr(vt, "type");
2925
+ if (typeVal) volType.type = typeVal;
2925
2926
  const mains = [];
2926
2927
  for (const m of vt.elements ?? []) {
2927
2928
  if (m.name !== "main") continue;
2928
- const main = {};
2929
- if (attr(m, "first")) main.first = attr(m, "first");
2929
+ const main = { first: attr(m, "first") ?? "" };
2930
2930
  const topics = [];
2931
2931
  for (const tp of m.elements ?? []) {
2932
2932
  if (tp.name !== "tp") continue;
2933
- const topic = {};
2934
2933
  const vEl = findChild(tp, "v");
2935
- if (vEl) topic.value = vEl.elements?.[0]?.text ?? "";
2936
- if (attr(tp, "t")) topic.valueType = attr(tp, "t");
2934
+ const topic = { value: String(vEl?.elements?.[0]?.text ?? "") };
2935
+ const tVal = attr(tp, "t");
2936
+ if (tVal) topic.valueType = tVal;
2937
2937
  const stps = [];
2938
2938
  const refs = [];
2939
2939
  for (const inner of tp.elements ?? []) {
2940
2940
  if (inner.name === "stp") stps.push(String(inner.elements?.[0]?.text ?? ""));
2941
2941
  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;
2942
+ const ref = {
2943
+ reference: attr(inner, "r") ?? "",
2944
+ sheetIndex: attrNum(inner, "s") ?? 0
2945
+ };
2946
2946
  refs.push(ref);
2947
2947
  }
2948
2948
  }
@@ -3938,17 +3938,6 @@ var ContentTypes = class {
3938
3938
  }
3939
3939
  };
3940
3940
  //#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
3941
  //#region src/context.ts
3953
3942
  /**
3954
3943
  * XLSX compile context — write and read contexts for the descriptor pipeline.
@@ -4065,7 +4054,7 @@ var XlsxReadContext = class {
4065
4054
  resolveStyle(styleIndex) {
4066
4055
  const ps = this.parsedStyles;
4067
4056
  if (!ps) return void 0;
4068
- const { cellXfs, fonts, fills, borders, customNumFmts } = ps;
4057
+ const { cellXfs, fonts, fills, borders, customNumFmtById } = ps;
4069
4058
  if (!cellXfs || styleIndex >= cellXfs.length) return void 0;
4070
4059
  const xf = cellXfs[styleIndex];
4071
4060
  const result = {};
@@ -4076,11 +4065,9 @@ var XlsxReadContext = class {
4076
4065
  const borderId = xf.borderId;
4077
4066
  if (borderId !== void 0 && borders && borderId < borders.length) result.border = borders[borderId];
4078
4067
  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
- }
4068
+ if (numFmtId !== void 0 && customNumFmtById) {
4069
+ const code = customNumFmtById.get(numFmtId);
4070
+ if (code !== void 0) result.numFmt = code;
4084
4071
  }
4085
4072
  if (xf.alignment) result.alignment = xf.alignment;
4086
4073
  if (xf.protection) result.protection = xf.protection;
@@ -4105,6 +4092,6 @@ function resolveWsTarget(wsPath, target) {
4105
4092
  return dirParts.join("/");
4106
4093
  }
4107
4094
  //#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 };
4095
+ 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
4096
 
4110
- //# sourceMappingURL=context-Btk-2AKp.mjs.map
4097
+ //# sourceMappingURL=context-CJzw_ObT.mjs.map