styled-exceljs 0.21.1 → 0.21.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/xlsx.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /*! xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
2
2
  /* vim: set ts=2: */
3
3
  /*exported XLSX */
4
- /*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false, DataView:false, Deno:false, Set:false, Float32Array:false */
4
+ /*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false, DataView:false, Deno:false, Set:false, Float32Array:false, Int8Array:false */
5
5
  var XLSX = {};
6
6
  function make_xlsx_lib(XLSX){
7
- XLSX.version = '0.21.1';
7
+ XLSX.version = '0.21.3';
8
8
  var current_codepage = 1200, current_ansi = 1252;
9
9
  /*global cptable:true, window */
10
10
  var $cptable;
@@ -158,9 +158,9 @@ function Base64_decode(input) {
158
158
  var o = "";
159
159
  var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
160
160
  if (input.slice(0, 5) == "data:") {
161
- var i = input.slice(0, 1024).indexOf(";base64,");
162
- if (i > -1)
163
- input = input.slice(i + 8);
161
+ var sep = input.slice(0, 1024).indexOf(";base64,");
162
+ if (sep > -1)
163
+ input = input.slice(sep + 8);
164
164
  }
165
165
  input = input.replace(/[^\w\+\/\=]/g, "");
166
166
  for (var i = 0; i < input.length; ) {
@@ -3232,7 +3232,7 @@ function blobify(data) {
3232
3232
  }
3233
3233
  /* write or download file */
3234
3234
  function write_dl(fname, payload, enc) {
3235
- /*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
3235
+ /*global IE_SaveFile, navigator, saveAs, document, chrome */
3236
3236
  if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
3237
3237
  if(typeof Deno !== 'undefined') {
3238
3238
  /* in this spot, it's safe to assume typed arrays and TextEncoder/TextDecoder exist */
@@ -3880,6 +3880,19 @@ function escapexlml(text){
3880
3880
  return s.replace(decregex, function(y) { return rencoding[y]; }).replace(htmlcharegex,function(s) { return "&#x" + (s.charCodeAt(0).toString(16)).toUpperCase() + ";"; });
3881
3881
  }
3882
3882
 
3883
+ /* Extract text from XML fragments in linear time. This is a parser helper,
3884
+ * not an HTML sanitizer: text is escaped separately at HTML output boundaries. */
3885
+ function strip_xml_tags(text) {
3886
+ var str = String(text), out = [], inTag = false;
3887
+ for(var i = 0; i < str.length; ++i) {
3888
+ var cc = str.charCodeAt(i);
3889
+ if(!inTag && cc == 60 /* < */) inTag = true;
3890
+ else if(inTag && cc == 62 /* > */) inTag = false;
3891
+ else if(!inTag) out.push(str.charAt(i));
3892
+ }
3893
+ return out.join("");
3894
+ }
3895
+
3883
3896
  /* TODO: handle codepages */
3884
3897
  var xlml_fixstr = (function() {
3885
3898
  var entregex = /&#(\d+);/g;
@@ -3986,8 +3999,8 @@ var htmldecode = (function() {
3986
3999
  .replace(/[\t\n\r ]+/g, " ")
3987
4000
  // Replace <br> tags with new lines
3988
4001
  .replace(/<\s*[bB][rR]\s*\/?>/g,"\n")
3989
- // Strip HTML elements
3990
- .replace(/<[^<>]*>/g,"");
4002
+ ;
4003
+ o = strip_xml_tags(o);
3991
4004
  for(var i = 0; i < entities.length; ++i) o = o.replace(entities[i][0], entities[i][1]);
3992
4005
  return o;
3993
4006
  };
@@ -4558,9 +4571,25 @@ function format_cell(cell, v, o) {
4558
4571
  return safe_format_cell(cell, v);
4559
4572
  }
4560
4573
 
4574
+ /* Worksheet names are document-controlled. A normal object treats
4575
+ * "__proto__" as a setter, so all workbook sheet maps must use an own-property
4576
+ * preserving dictionary and all lookups must reject inherited properties. */
4577
+ function sheet_map_new() {
4578
+ return Object.create ? Object.create(null) : {};
4579
+ }
4580
+ function sheet_map_set(sheets, name, sheet) {
4581
+ if(name == "__proto__" && Object.defineProperty) Object.defineProperty(sheets, name, {
4582
+ value: sheet, configurable: true, enumerable: true, writable: true
4583
+ });
4584
+ else sheets[name] = sheet;
4585
+ }
4586
+ function sheet_map_get(sheets, name) {
4587
+ return sheets != null && Object.prototype.hasOwnProperty.call(sheets, name) ? sheets[name] : void 0;
4588
+ }
4589
+
4561
4590
  function sheet_to_workbook(sheet, opts) {
4562
4591
  var n = opts && opts.sheet ? opts.sheet : "Sheet1";
4563
- var sheets = {}; sheets[n] = sheet;
4592
+ var sheets = sheet_map_new(); sheet_map_set(sheets, n, sheet);
4564
4593
  return { SheetNames: [n], Sheets: sheets };
4565
4594
  }
4566
4595
 
@@ -6233,8 +6262,8 @@ function parse_TypedPropertyValue(blob, type, _opts) {
6233
6262
  case 0x03 /*VT_I4*/: ret = blob.read_shift(4, 'i'); return ret;
6234
6263
  case 0x0B /*VT_BOOL*/: return blob.read_shift(4) !== 0x0;
6235
6264
  case 0x13 /*VT_UI4*/: ret = blob.read_shift(4); return ret;
6236
- case 0x1E /*VT_LPSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
6237
- case 0x1F /*VT_LPWSTR*/: blob.l += 4; val = parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1"); break;
6265
+ case 0x1E /*VT_LPSTR*/: blob.l += 4; return parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1");
6266
+ case 0x1F /*VT_LPWSTR*/: blob.l += 4; return parse_VtString(blob, blob[blob.l-4]).replace(/(^|[^\u0000])\u0000+$/,"$1");
6238
6267
  case 0x40 /*VT_FILETIME*/: return parse_FILETIME(blob);
6239
6268
  case 0x41 /*VT_BLOB*/: return parse_BLOB(blob);
6240
6269
  case 0x47 /*VT_CF*/: return parse_ClipboardData(blob);
@@ -6743,7 +6772,6 @@ function parse_LongRGBA(blob) { var r = blob.read_shift(1), g = blob.read_shift(
6743
6772
  /* 2.5.177 LongRGB */
6744
6773
  function parse_LongRGB(blob, length) { var x = parse_LongRGBA(blob, length); x[3] = 0; return x; }
6745
6774
 
6746
-
6747
6775
  /* [MS-XLS] 2.5.19 */
6748
6776
  function parse_XLSCell(blob, length, opts) {
6749
6777
  var rw = blob.read_shift(2); // 0-indexed
@@ -8205,7 +8233,7 @@ function dbf_to_workbook(buf, opts) {
8205
8233
  o.bookType = "dbf";
8206
8234
  return o;
8207
8235
  } catch(e) { if(opts && opts.WTF) throw e; }
8208
- return ({SheetNames:[],Sheets:{}});
8236
+ return ({SheetNames:[],Sheets:sheet_map_new()});
8209
8237
  }
8210
8238
 
8211
8239
  var _RLEN = { 'B': 8, 'C': 250, 'L': 1, 'D': 8, '?': 0, '': 0 };
@@ -9101,7 +9129,7 @@ function read_wb_TABL(d, opts) {
9101
9129
  try {
9102
9130
  var out = DIF.to_workbook(d, o);
9103
9131
  if(!out || !out.Sheets) throw "DIF bad workbook";
9104
- var ws = out.Sheets[out.SheetNames[0]];
9132
+ var ws = sheet_map_get(out.Sheets, out.SheetNames[0]);
9105
9133
  if(!ws || !ws["!ref"]) throw "DIF empty worksheet";
9106
9134
  o.WTF = OLD_WTF;
9107
9135
  return out;
@@ -9157,7 +9185,7 @@ var WK_ = (function() {
9157
9185
  var o = opts || {};
9158
9186
  if(DENSE != null && o.dense == null) o.dense = DENSE;
9159
9187
  var s = ({}), n = "Sheet1", next_n = "", sidx = 0;
9160
- var sheets = {}, snames = [], realnames = [], sdata = [];
9188
+ var sheets = sheet_map_new(), snames = [], realnames = [], sdata = [];
9161
9189
  if(o.dense) sdata = s["!data"] = [];
9162
9190
 
9163
9191
  var refguess = {s: {r:0, c:0}, e: {r:0, c:0} };
@@ -9202,7 +9230,7 @@ var WK_ = (function() {
9202
9230
  if(o.qpro) {
9203
9231
  if(val[3] > sidx) {
9204
9232
  s["!ref"] = encode_range(refguess);
9205
- sheets[n] = s;
9233
+ sheet_map_set(sheets, n, s);
9206
9234
  snames.push(n);
9207
9235
  s = ({}); if(o.dense) sdata = s["!data"] = [];
9208
9236
  refguess = {s: {r:0, c:0}, e: {r:0, c:0} };
@@ -9253,7 +9281,7 @@ var WK_ = (function() {
9253
9281
  case 0x28: /* FORMULA28 */
9254
9282
  if(val[3] > sidx) {
9255
9283
  s["!ref"] = encode_range(refguess);
9256
- sheets[n] = s;
9284
+ sheet_map_set(sheets, n, s);
9257
9285
  snames.push(n);
9258
9286
  s = ({}); if(o.dense) sdata = s["!data"] = [];
9259
9287
  refguess = {s: {r:0, c:0}, e: {r:0, c:0} };
@@ -9276,17 +9304,17 @@ var WK_ = (function() {
9276
9304
  }}, o);
9277
9305
  } else throw new Error("Unrecognized LOTUS BOF " + d[2]);
9278
9306
  s["!ref"] = encode_range(refguess);
9279
- sheets[next_n || n] = s;
9307
+ sheet_map_set(sheets, next_n || n, s);
9280
9308
  snames.push(next_n || n);
9281
9309
  if(!realnames.length) return { SheetNames: snames, Sheets: sheets };
9282
- var osheets = {}, rnames = [];
9310
+ var osheets = sheet_map_new(), rnames = [];
9283
9311
  /* TODO: verify no collisions */
9284
- for(var i = 0; i < realnames.length; ++i) if(sheets[snames[i]]) {
9312
+ for(var i = 0; i < realnames.length; ++i) if(sheet_map_get(sheets, snames[i])) {
9285
9313
  rnames.push(realnames[i] || snames[i]);
9286
- osheets[realnames[i]] = sheets[realnames[i]] || sheets[snames[i]];
9314
+ sheet_map_set(osheets, realnames[i] || snames[i], sheet_map_get(sheets, realnames[i]) || sheet_map_get(sheets, snames[i]));
9287
9315
  } else {
9288
9316
  rnames.push(realnames[i]);
9289
- osheets[realnames[i]] = ({ "!ref": "A1" });
9317
+ sheet_map_set(osheets, realnames[i], ({ "!ref": "A1" }));
9290
9318
  }
9291
9319
  return { SheetNames: rnames, Sheets: osheets };
9292
9320
  }
@@ -9340,11 +9368,11 @@ var WK_ = (function() {
9340
9368
 
9341
9369
  write_biff_rec(ba, 0x00, write_BOF_WK3(wb));
9342
9370
 
9343
- for(var i = 0, cnt = 0; i < wb.SheetNames.length; ++i) if((wb.Sheets[wb.SheetNames[i]] || {})["!ref"]) write_biff_rec(ba, 0x1b, write_XFORMAT_SHEETNAME(wb.SheetNames[i], cnt++));
9371
+ for(var i = 0, cnt = 0; i < wb.SheetNames.length; ++i) if((sheet_map_get(wb.Sheets, wb.SheetNames[i]) || {})["!ref"]) write_biff_rec(ba, 0x1b, write_XFORMAT_SHEETNAME(wb.SheetNames[i], cnt++));
9344
9372
 
9345
9373
  var wsidx = 0;
9346
9374
  for(i = 0; i < wb.SheetNames.length; ++i) {
9347
- var ws = wb.Sheets[wb.SheetNames[i]];
9375
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[i]);
9348
9376
  if(!ws || !ws["!ref"]) continue;
9349
9377
  var range = safe_decode_range(ws["!ref"]);
9350
9378
  var dense = ws["!data"] != null;
@@ -9389,7 +9417,7 @@ var WK_ = (function() {
9389
9417
  var rows = 0, cols = 0, wscnt = 0;
9390
9418
  for(var i = 0; i < wb.SheetNames.length; ++i) {
9391
9419
  var name = wb.SheetNames[i];
9392
- var ws = wb.Sheets[name];
9420
+ var ws = sheet_map_get(wb.Sheets, name);
9393
9421
  if(!ws || !ws["!ref"]) continue;
9394
9422
  ++wscnt;
9395
9423
  var range = decode_range(ws["!ref"]);
@@ -10117,7 +10145,7 @@ var WK_ = (function() {
10117
10145
  var SST = [], sname = "", formulae = [];
10118
10146
  var range = {s:{r:-1,c:-1}, e:{r:-1,c:-1}};
10119
10147
  var cnt = 0, type = 0, C = 0, R = 0;
10120
- var wb = { SheetNames: [], Sheets: {} };
10148
+ var wb = { SheetNames: [], Sheets: sheet_map_new() };
10121
10149
  var FMTS = [];
10122
10150
  outer: while(d.l < d.length) {
10123
10151
  var RT = d.read_shift(2), length = d.read_shift(2);
@@ -10421,13 +10449,13 @@ var parse_rs = (function() {
10421
10449
 
10422
10450
  /* Parse a list of <r> tags */
10423
10451
  var rs_to_html = (function parse_rs_factory() {
10424
- var nlregex = /(\r\n|\n)/g;
10425
10452
  function parse_rpr2(font, intro, outro) {
10426
10453
  var style = [];
10427
10454
 
10428
10455
  if(font.u) style.push("text-decoration: underline;");
10429
- if(font.uval) style.push("text-underline-style:" + font.uval + ";");
10430
- if(font.sz) style.push("font-size:" + font.sz + "pt;");
10456
+ if(font.uval && /^(?:single|double|single-accounting|double-accounting)$/.test(font.uval)) style.push("text-underline-style:" + font.uval + ";");
10457
+ var sz = +font.sz;
10458
+ if(isFinite(sz) && sz > 0) style.push("font-size:" + Math.min(sz, 409) + "pt;");
10431
10459
  if(font.outline) style.push("text-effect: outline;");
10432
10460
  if(font.shadow) style.push("text-shadow: auto;");
10433
10461
  intro.push('<span style="' + style.join("") + '">');
@@ -10452,7 +10480,7 @@ var rs_to_html = (function parse_rs_factory() {
10452
10480
 
10453
10481
  if(r.s) parse_rpr2(r.s, terms[0], terms[2]);
10454
10482
 
10455
- return terms[0].join("") + terms[1].replace(nlregex,'<br/>') + terms[2].join("");
10483
+ return terms[0].join("") + escapehtml(terms[1]) + terms[2].join("");
10456
10484
  }
10457
10485
 
10458
10486
  return function parse_rs(rs) {
@@ -11110,7 +11138,7 @@ function resolve_style_obj_color(obj, themes) {
11110
11138
 
11111
11139
  /* 18.3.1.13 width calculations */
11112
11140
  /* [MS-OI29500] 2.1.595 Column Width & Formatting */
11113
- var DEF_MDW = 6, MAX_MDW = 15, MIN_MDW = 1, MDW = DEF_MDW;
11141
+ var DEF_MDW = 7, MAX_MDW = 15, MIN_MDW = 1, MDW = DEF_MDW;
11114
11142
  function width2px(width) { return Math.floor(( width + (Math.round(128/MDW))/256 )* MDW ); }
11115
11143
  function px2char(px) { return (Math.floor((px - 5)/MDW * 100 + 0.5))/100; }
11116
11144
  function char2width(chr) { return (Math.round((chr * MDW + 5)/MDW*256))/256; }
@@ -11186,6 +11214,15 @@ function style_font_family(style) {
11186
11214
  var font = style && style.font || {};
11187
11215
  return font.name || "Calibri";
11188
11216
  }
11217
+ function css_string_escape(value, quote) {
11218
+ var str = String(value), out = [];
11219
+ for(var i = 0; i < str.length; ++i) {
11220
+ var cc = str.charCodeAt(i), ch = str.charAt(i);
11221
+ if(ch == quote || ch == "\\" || cc < 32 || cc == 127 || ch == "<" || ch == ">" || ch == "&") out.push("\\" + cc.toString(16) + " ");
11222
+ else out.push(ch);
11223
+ }
11224
+ return out.join("");
11225
+ }
11189
11226
  function css_font_from_style(style) {
11190
11227
  var font = style && style.font || {};
11191
11228
  var parts = [];
@@ -11193,7 +11230,8 @@ function css_font_from_style(style) {
11193
11230
  if(font.bold) parts.push("bold");
11194
11231
  parts.push(style_font_size_pt(style) + "pt");
11195
11232
  var name = style_font_family(style);
11196
- if(/[,\s'"]/.test(name)) name = '"' + String(name).replace(/"/g, '\\"') + '"';
11233
+ if(/[,\s'"]/.test(name)) name = '"' + css_string_escape(name, '"') + '"';
11234
+ else name = css_string_escape(name, '"');
11197
11235
  parts.push(name);
11198
11236
  return parts.join(" ");
11199
11237
  }
@@ -13174,7 +13212,7 @@ function parse_drawing_anchor(data) {
13174
13212
  function parse_drawing_text(data) {
13175
13213
  var out = [];
13176
13214
  (data.match(/<a:t\b[^>]*>[\s\S]*?<\/a:t>/g)||[]).forEach(function(t) {
13177
- out.push(unescapexml(t.replace(/<[^>]*>/g, "")));
13215
+ out.push(unescapexml(strip_xml_tags(t)));
13178
13216
  });
13179
13217
  return out.join("");
13180
13218
  }
@@ -16554,7 +16592,25 @@ var mergecregex = /<(?:\w+:)?mergeCell ref=["'][A-Z0-9:]+['"]\s*[\/]?>/g;
16554
16592
  var hlinkregex = /<(?:\w+:)?hyperlink [^<>]*>/mg;
16555
16593
  var dimregex = /"(\w*:\w*)"/;
16556
16594
  var colregex = /<(?:\w+:)?col\b[^<>]*[\/]?>/g;
16557
- var afregex = /<(?:\w:)?autoFilter[^>]*([\/]|>([\s\S]*)<\/(?:\w:)?autoFilter)>/g;
16595
+ function match_ws_xml_autofilter(data) {
16596
+ var paired = str_match_xml_ns(data, "autoFilter");
16597
+ if(paired) return paired[0];
16598
+ var start = 0;
16599
+ while((start = data.indexOf("<", start)) != -1) {
16600
+ var end = data.indexOf(">", start + 1);
16601
+ if(end == -1) return null;
16602
+ var tag = data.slice(start + 1, end), p = 0;
16603
+ while(p < tag.length && tag.charCodeAt(p) <= 32) ++p;
16604
+ var nameEnd = p;
16605
+ while(nameEnd < tag.length && tag.charCodeAt(nameEnd) > 32 && tag.charAt(nameEnd) != "/") ++nameEnd;
16606
+ var name = tag.slice(p, nameEnd), colon = name.indexOf(":");
16607
+ if(colon != -1) name = name.slice(colon + 1);
16608
+ var tail = tag.slice(nameEnd).trim();
16609
+ if(name == "autoFilter" && tail.charAt(tail.length - 1) == "/") return data.slice(start, end + 1);
16610
+ start = end + 1;
16611
+ }
16612
+ return null;
16613
+ }
16558
16614
  var marginregex= /<(?:\w+:)?pageMargins[^<>]*\/>/g;
16559
16615
  var sheetprregex = /<(?:\w+:)?sheetPr\b[^<>]*?\/>/;
16560
16616
 
@@ -16603,8 +16659,8 @@ function parse_ws_xml(data, opts, idx, rels, wb, themes, styles) {
16603
16659
  if(mtch) parse_ws_xml_data(mtch[1], s, opts, refguess, themes, styles, wb);
16604
16660
 
16605
16661
  /* 18.3.1.2 autoFilter CT_AutoFilter */
16606
- var afilter = data2.match(afregex);
16607
- if(afilter) s['!autofilter'] = parse_ws_xml_autofilter(afilter[0]);
16662
+ var afilter = match_ws_xml_autofilter(data2);
16663
+ if(afilter) s['!autofilter'] = parse_ws_xml_autofilter(afilter);
16608
16664
 
16609
16665
  /* 18.3.1.55 mergeCells CT_MergeCells */
16610
16666
  var merges = [];
@@ -16757,7 +16813,8 @@ function parse_ws_xml_cols(columns, cols) {
16757
16813
  var colm=parseInt(coll.min, 10)-1, colM=parseInt(coll.max,10)-1;
16758
16814
  if(coll.outlineLevel) coll.level = (+coll.outlineLevel || 0);
16759
16815
  delete coll.min; delete coll.max; coll.width = +coll.width;
16760
- if(!seencol && coll.width) { seencol = true; find_mdw_colw(coll.width); }
16816
+ /* OOXML widths share the workbook Normal-font MDW; do not infer a different scale per sheet. */
16817
+ if(!seencol && coll.width) { seencol = true; MDW = DEF_MDW; }
16761
16818
  process_col(coll);
16762
16819
  while(colm <= colM) columns[colm++] = dup(coll);
16763
16820
  }
@@ -17128,7 +17185,7 @@ function write_ws_xml(idx, opts, wb, rels) {
17128
17185
  'xmlns:r': XMLNS.r
17129
17186
  })];
17130
17187
  var s = wb.SheetNames[idx], sidx = 0, rdata = "";
17131
- var ws = wb.Sheets[s];
17188
+ var ws = sheet_map_get(wb.Sheets, s);
17132
17189
  if(ws == null) ws = {};
17133
17190
  var ref = ws['!ref'] || 'A1';
17134
17191
  var range = safe_decode_range(ref);
@@ -17927,7 +17984,7 @@ function parse_ws_bin(data, _opts, idx, rels, wb, themes, styles) {
17927
17984
  if(!opts.cellStyles) break;
17928
17985
  while(val.e >= val.s) {
17929
17986
  colinfo[val.e--] = { width: val.w/256, hidden: !!(val.flags & 0x01), level: val.level };
17930
- if(!seencol) { seencol = true; find_mdw_colw(val.w/256); }
17987
+ if(!seencol) { seencol = true; MDW = DEF_MDW; }
17931
17988
  process_col(colinfo[val.e+1]);
17932
17989
  }
17933
17990
  break;
@@ -18241,7 +18298,7 @@ function write_SHEETPROTECT(ba, ws) {
18241
18298
 
18242
18299
  function write_ws_bin(idx, opts, wb, rels) {
18243
18300
  var ba = buf_array();
18244
- var s = wb.SheetNames[idx], ws = wb.Sheets[s] || {};
18301
+ var s = wb.SheetNames[idx], ws = sheet_map_get(wb.Sheets, s) || {};
18245
18302
  var c = s; try { if(wb && wb.Workbook) c = wb.Workbook.Sheets[idx].CodeName || c; } catch(e) {}
18246
18303
  var r = safe_decode_range(ws['!ref'] || "A1");
18247
18304
  if(r.e.c > 0x3FFF || r.e.r > 0xFFFFF) {
@@ -18309,7 +18366,7 @@ function parse_Cache(data) {
18309
18366
  /* 21.2.2.71 formatCode CT_Xstring */
18310
18367
  var nf = unescapexml((str_match_xml(data, "c:formatCode") || ["","General"])[1]);
18311
18368
 
18312
- (str_match_ng(data, "<c:f>", "</c:f>")||[]).forEach(function(F) { f = F.replace(/<[^<>]*>/g,""); });
18369
+ (str_match_ng(data, "<c:f>", "</c:f>")||[]).forEach(function(F) { f = strip_xml_tags(F); });
18313
18370
 
18314
18371
  return [col, nf, f];
18315
18372
  }
@@ -18326,7 +18383,7 @@ function parse_chart_cache(data) {
18326
18383
  return {values:s[0], formatCode:s[1], formula:s[2]};
18327
18384
  }
18328
18385
  var f = (str_match_ng(data, "<c:f>", "</c:f>")||[])[0];
18329
- return {values:[], formula:f ? f.replace(/<[^<>]*>/g,"") : void 0};
18386
+ return {values:[], formula:f ? strip_xml_tags(f) : void 0};
18330
18387
  }
18331
18388
 
18332
18389
  function parse_chart_tx(data) {
@@ -18358,7 +18415,7 @@ function parse_chart_title(data) {
18358
18415
  var title = str_match_xml_ns(data, "title");
18359
18416
  if(!title) return "";
18360
18417
  var out = [];
18361
- (title[0].match(/<a:t\b[^>]*>[\s\S]*?<\/a:t>/g)||[]).forEach(function(t) { out.push(unescapexml(t.replace(/<[^>]*>/g, ""))); });
18418
+ (title[0].match(/<a:t\b[^>]*>[\s\S]*?<\/a:t>/g)||[]).forEach(function(t) { out.push(unescapexml(strip_xml_tags(t))); });
18362
18419
  return out.join("");
18363
18420
  }
18364
18421
 
@@ -18663,9 +18720,13 @@ function check_wb(wb) {
18663
18720
  if(!wb.SheetNames.length) throw new Error("Workbook is empty");
18664
18721
  var Sheets = (wb.Workbook && wb.Workbook.Sheets) || [];
18665
18722
  check_wb_names(wb.SheetNames, Sheets, !!wb.vbaraw);
18666
- for(var i = 0; i < wb.SheetNames.length; ++i) check_ws(wb.Sheets[wb.SheetNames[i]], wb.SheetNames[i], i);
18723
+ for(var i = 0; i < wb.SheetNames.length; ++i) {
18724
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[i]);
18725
+ if(!ws) throw new Error("Missing worksheet |" + wb.SheetNames[i] + "|");
18726
+ check_ws(ws, wb.SheetNames[i], i);
18727
+ }
18667
18728
  wb.SheetNames.forEach(function(n, i) {
18668
- var ws = wb.Sheets[n];
18729
+ var ws = sheet_map_get(wb.Sheets, n);
18669
18730
  if(!ws || !ws["!autofilter"]) return;
18670
18731
  var DN;
18671
18732
  if(!wb.Workbook) wb.Workbook = {};
@@ -19450,7 +19511,7 @@ function parse_xlml_data(xml, ss, data, cell, base, styles, csty, row, arrayf, o
19450
19511
  break;
19451
19512
  case 'String':
19452
19513
  cell.t = 's'; cell.r = xlml_fixstr(unescapexml(xml));
19453
- cell.v = (xml.indexOf("<") > -1 ? unescapexml(ss||xml).replace(/<[^<>]*>/g, "") : cell.r); // todo: BR etc
19514
+ cell.v = (xml.indexOf("<") > -1 ? strip_xml_tags(unescapexml(ss||xml)) : cell.r); // todo: BR etc
19454
19515
  break;
19455
19516
  case 'DateTime':
19456
19517
  if(xml.slice(-1) != "Z") xml += "Z";
@@ -19545,7 +19606,7 @@ function parse_xlml_xml(d, _opts) {
19545
19606
  var Rn;
19546
19607
  var state = [], tmp;
19547
19608
  if(DENSE != null && opts.dense == null) opts.dense = DENSE;
19548
- var sheets = {}, sheetnames = [], cursheet = ({}), sheetname = ""; if(opts.dense) cursheet["!data"] = [];
19609
+ var sheets = sheet_map_new(), sheetnames = [], cursheet = ({}), sheetname = ""; if(opts.dense) cursheet["!data"] = [];
19549
19610
  var cell = ({}), row = {};// eslint-disable-line no-unused-vars
19550
19611
  var dtag = xlml_parsexmltag('<Data ss:Type="String">'), didx = 0;
19551
19612
  var c = 0, r = 0;
@@ -19651,7 +19712,7 @@ for(var cma = c; cma <= cc; ++cma) {
19651
19712
  if(merges.length) cursheet["!merges"] = merges;
19652
19713
  if(cstys.length > 0) cursheet["!cols"] = cstys;
19653
19714
  if(rowinfo.length > 0) cursheet["!rows"] = rowinfo;
19654
- sheets[sheetname] = cursheet;
19715
+ sheet_map_set(sheets, sheetname, cursheet);
19655
19716
  } else {
19656
19717
  refguess = {s: {r:2000000, c:2000000}, e: {r:0, c:0} };
19657
19718
  r = c = 0;
@@ -20552,7 +20613,7 @@ function write_ws_xlml_table(ws, opts, idx, wb) {
20552
20613
  function write_ws_xlml(idx, opts, wb) {
20553
20614
  var o = [];
20554
20615
  var s = wb.SheetNames[idx];
20555
- var ws = wb.Sheets[s];
20616
+ var ws = sheet_map_get(wb.Sheets, s);
20556
20617
 
20557
20618
  var t = ws ? write_ws_xlml_names(ws, opts, idx, wb) : "";
20558
20619
  if(t.length > 0) o.push("<Names>" + t + "</Names>");
@@ -20784,7 +20845,7 @@ var parse_BIFFSurface = make_BIFFChartType("surfaceChart");
20784
20845
  // 2.3.2
20785
20846
  function parse_workbook(blob, options) {
20786
20847
  var wb = ({opts:{}});
20787
- var Sheets = {};
20848
+ var Sheets = sheet_map_new();
20788
20849
  if(DENSE != null && options.dense == null) options.dense = DENSE;
20789
20850
  var out = ({}); if(options.dense) out["!data"] = [];
20790
20851
  var Directory = {};
@@ -21225,7 +21286,7 @@ wb.opts.Date1904 = Workbook.WBProps.date1904 = val; break;
21225
21286
  finalize_sheet_visuals(out);
21226
21287
  Workbook.Sheets.push(wsprops);
21227
21288
  }
21228
- if(cur_sheet === "") Preamble = out; else Sheets[cur_sheet] = out;
21289
+ if(cur_sheet === "") Preamble = out; else sheet_map_set(Sheets, cur_sheet, out);
21229
21290
  out = ({}); if(options.dense) out["!data"] = [];
21230
21291
  } break;
21231
21292
  case 0x0009: case 0x0209: case 0x0409: case 0x0809 /* BOF */: {
@@ -21467,7 +21528,7 @@ wb.opts.Date1904 = Workbook.WBProps.date1904 = val; break;
21467
21528
  while(val.e >= val.s) {
21468
21529
  colinfo[val.e--] = { width: val.w/256, level: (val.level || 0), hidden: !!(val.flags & 1) };
21469
21530
  if(val.ixfe != null && XFs[val.ixfe]) colinfo[val.e+1].s = resolve_xls_style(XFs[val.ixfe], val.ixfe);
21470
- if(!seencol) { seencol = true; find_mdw_colw(val.w/256); }
21531
+ if(!seencol) { seencol = true; MDW = DEF_MDW; }
21471
21532
  process_col(colinfo[val.e+1]);
21472
21533
  }
21473
21534
  } break;
@@ -21524,10 +21585,13 @@ if(!cur_sheet) Workbook.WBProps.CodeName = val || "ThisWorkbook";
21524
21585
  if(!wb.SheetNames.length && Preamble["!ref"]) {
21525
21586
  wb.SheetNames.push("Sheet1");
21526
21587
  /*jshint -W069 */
21527
- if(wb.Sheets) wb.Sheets["Sheet1"] = Preamble;
21588
+ if(wb.Sheets) sheet_map_set(wb.Sheets, "Sheet1", Preamble);
21528
21589
  /*jshint +W069 */
21529
21590
  } else wb.Preamble=Preamble;
21530
- if(wb.Sheets) FilterDatabases.forEach(function(r,i) { wb.Sheets[wb.SheetNames[i]]['!autofilter'] = r; });
21591
+ if(wb.Sheets) FilterDatabases.forEach(function(r,i) {
21592
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[i]);
21593
+ if(ws) ws['!autofilter'] = r;
21594
+ });
21531
21595
  wb.Strings = sst;
21532
21596
  wb.SSF = dup(table_fmt);
21533
21597
  if(opts.enc) wb.Encryption = opts.enc;
@@ -23152,7 +23216,7 @@ function write_biff2_buf(wb, opts) {
23152
23216
  o.cellXfs = [{numFmtId: 0}];
23153
23217
  o._BIFF2FmtTable = ["General"]; o._Fonts = [];
23154
23218
  var body = buf_array();
23155
- write_ws_biff2(body, wb.Sheets[wb.SheetNames[idx]], idx, o, wb);
23219
+ write_ws_biff2(body, sheet_map_get(wb.Sheets, wb.SheetNames[idx]), idx, o, wb);
23156
23220
 
23157
23221
  o._BIFF2FmtTable.forEach(function(f) {
23158
23222
  if(o.biff <= 3) write_biff_rec(ba, 0x001E, write_BIFF2Format(f));
@@ -23562,7 +23626,7 @@ function write_ws_biff8_cell(ba, cell, R, C, opts, date1904) {
23562
23626
  /* [MS-XLS] 2.1.7.20.5 */
23563
23627
  function write_ws_biff8(idx, opts, wb) {
23564
23628
  var ba = buf_array();
23565
- var s = wb.SheetNames[idx], ws = wb.Sheets[s] || {};
23629
+ var s = wb.SheetNames[idx], ws = sheet_map_get(wb.Sheets, s) || {};
23566
23630
  var _WB = ((wb||{}).Workbook||{});
23567
23631
  var _sheet = ((_WB.Sheets||[])[idx]||{});
23568
23632
  var dense = ws["!data"] != null;
@@ -23761,7 +23825,7 @@ function write_biff8_buf(wb, opts) {
23761
23825
 
23762
23826
  function write_biff_buf(wb, opts) {
23763
23827
  for(var i = 0; i <= wb.SheetNames.length; ++i) {
23764
- var ws = wb.Sheets[wb.SheetNames[i]];
23828
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[i]);
23765
23829
  if(!ws || !ws["!ref"]) continue;
23766
23830
  var range = decode_range(ws["!ref"]);
23767
23831
  if(range.e.c > 255) { // note: 255 is IV
@@ -23843,15 +23907,66 @@ function html_to_sheet(str, _opts) {
23843
23907
  return ws;
23844
23908
  }
23845
23909
 
23846
- function cssesc(x) { return escapexml(String(x).replace(/"/g, "'")); }
23847
23910
  function css_color(color) {
23848
23911
  if(!color) return "";
23849
- if(color.rgb) return "#" + String(color.rgb).slice(-6);
23912
+ if(color.rgb && /^[0-9A-Fa-f]{6}(?:[0-9A-Fa-f]{2})?$/.test(String(color.rgb))) return "#" + String(color.rgb).slice(-6);
23850
23913
  return "";
23851
23914
  }
23852
23915
  function css_font_family(name) {
23853
23916
  if(!name) return "";
23854
- return "'" + cssesc(name).replace(/'/g, "\\'") + "'";
23917
+ return "'" + css_string_escape(name, "'") + "'";
23918
+ }
23919
+
23920
+ function html_attr_escape(value) {
23921
+ return String(value).replace(/[&<>"']/g, function(ch) {
23922
+ return ch == "&" ? "&amp;" : ch == "<" ? "&lt;" : ch == ">" ? "&gt;" : ch == '"' ? "&quot;" : "&#39;";
23923
+ });
23924
+ }
23925
+ function html_writextag(tag, content, attrs) {
23926
+ var out = ["<", tag];
23927
+ if(attrs) keys(attrs).forEach(function(key) { out.push(" ", key, '="', html_attr_escape(attrs[key]), '"'); });
23928
+ if(content == null) { out.push("/>"); return out.join(""); }
23929
+ out.push(">", content, "</", tag, ">");
23930
+ return out.join("");
23931
+ }
23932
+ function safe_html_href(value) {
23933
+ var href = String(value == null ? "" : value).trim();
23934
+ if(!href || href.slice(0, 2) == "//") return null;
23935
+ var colon = href.indexOf(":"), prefix = colon == -1 ? "" : href.slice(0, colon), compact = "";
23936
+ for(var i = 0; i < prefix.length; ++i) if(prefix.charCodeAt(i) > 32 && prefix.charCodeAt(i) != 127) compact += prefix.charAt(i);
23937
+ if(colon != -1 && !/^(?:https?|mailto|tel)$/i.test(compact)) return null;
23938
+ return href;
23939
+ }
23940
+ function safe_html_image_src(value) {
23941
+ var src = String(value == null ? "" : value);
23942
+ return /^data:image\/[A-Za-z0-9.+-]+;base64,[A-Za-z0-9+/=\r\n]+$/.test(src) ? src : null;
23943
+ }
23944
+ function sanitize_cell_html(value) {
23945
+ var html = String(value == null ? "" : value), out = [], pos = 0;
23946
+ while(pos < html.length) {
23947
+ var start = html.indexOf("<", pos);
23948
+ if(start == -1) { out.push(html.slice(pos)); break; }
23949
+ out.push(html.slice(pos, start));
23950
+ var end = html.indexOf(">", start + 1);
23951
+ if(end == -1) { out.push("&lt;", html.slice(start + 1)); break; }
23952
+ var raw = html.slice(start + 1, end).trim(), lower = raw.toLowerCase();
23953
+ if(/^(?:\/?(?:b|i|s|sup|sub)|br\s*\/?)$/.test(lower)) out.push("<", lower == "br" ? "br/" : lower, ">");
23954
+ else if(lower == "/span") out.push("</span>");
23955
+ else if(lower.slice(0, 12) == 'span style="' && raw.charAt(raw.length - 1) == '"') {
23956
+ var declarations = raw.slice(12, -1).split(";"), safe = [];
23957
+ declarations.forEach(function(decl) {
23958
+ var colon = decl.indexOf(":"), key = colon == -1 ? "" : decl.slice(0, colon).trim().toLowerCase(), val = colon == -1 ? "" : decl.slice(colon + 1).trim().toLowerCase();
23959
+ if(key == "text-decoration" && val == "underline") safe.push("text-decoration:underline");
23960
+ else if(key == "text-underline-style" && /^(?:single|double|single-accounting|double-accounting)$/.test(val)) safe.push("text-underline-style:" + val);
23961
+ else if(key == "font-size" && /^\d+(?:\.\d+)?pt$/.test(val)) safe.push("font-size:" + val);
23962
+ else if(key == "text-effect" && val == "outline") safe.push("text-effect:outline");
23963
+ else if(key == "text-shadow" && val == "auto") safe.push("text-shadow:auto");
23964
+ });
23965
+ out.push('<span style="', safe.join(";"), safe.length ? ";" : "", '">');
23966
+ } else out.push(html_attr_escape(html.slice(start, end + 1)));
23967
+ pos = end + 1;
23968
+ }
23969
+ return out.join("");
23855
23970
  }
23856
23971
  function html_border_style(style) {
23857
23972
  switch(style) {
@@ -23880,7 +23995,8 @@ function html_cell_style(cell, opts) {
23880
23995
  var s = cell.s, css = [];
23881
23996
  var font = s.font || {};
23882
23997
  if(font.name) css.push("font-family:" + css_font_family(font.name));
23883
- if(font.sz) css.push("font-size:" + font.sz + "pt");
23998
+ var fontSize = +font.sz;
23999
+ if(isFinite(fontSize) && fontSize > 0) css.push("font-size:" + Math.min(fontSize, 409) + "pt");
23884
24000
  if(font.bold) css.push("font-weight:bold");
23885
24001
  if(font.italic) css.push("font-style:italic");
23886
24002
  var deco = [];
@@ -23893,8 +24009,9 @@ function html_cell_style(cell, opts) {
23893
24009
  if(fill.patternType != "none" && fill.patternType != "gray125") fillColor = css_color(fill.fgColor) || css_color(fill.bgColor);
23894
24010
  if(fillColor) css.push("background-color:" + fillColor);
23895
24011
  var alignment = s.alignment || {};
23896
- if(alignment.horizontal) css.push("text-align:" + alignment.horizontal);
23897
- if(alignment.vertical) css.push("vertical-align:" + alignment.vertical);
24012
+ if(/^(?:left|right|center|justify|fill|distributed)$/.test(alignment.horizontal || "")) css.push("text-align:" + alignment.horizontal);
24013
+ var vertical = alignment.vertical == "center" ? "middle" : alignment.vertical;
24014
+ if(/^(?:top|middle|bottom|baseline)$/.test(vertical || "")) css.push("vertical-align:" + vertical);
23898
24015
  if(alignment.textRotation != null && alignment.textRotation !== 0) {
23899
24016
  var deg = alignment.textRotation == 255 ? 90 : alignment.textRotation > 90 ? 90 - alignment.textRotation : alignment.textRotation;
23900
24017
  css.push("transform:rotate(" + deg + "deg)");
@@ -23973,7 +24090,7 @@ function make_html_row(ws, r, R, o) {
23973
24090
  }
23974
24091
  }
23975
24092
  /* TODO: html entities */
23976
- var w = (cell && cell.v != null) && (cell.h || escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
24093
+ var w = (cell && cell.v != null) && (cell.h ? sanitize_cell_html(cell.h) : escapehtml(cell.w || (format_cell(cell), cell.w) || "")) || "";
23977
24094
  sp = ({});
23978
24095
  if(RS > 1) sp.rowspan = RS;
23979
24096
  if(CS > 1) sp.colspan = CS;
@@ -23981,17 +24098,18 @@ function make_html_row(ws, r, R, o) {
23981
24098
  else if(cell) {
23982
24099
  sp["data-t"] = cell && cell.t || 'z';
23983
24100
  // note: data-v is unaffected by the timezone interpretation
23984
- if(cell.v != null) sp["data-v"] = escapehtml(cell.v instanceof Date ? cell.v.toISOString() : cell.v);
24101
+ if(cell.v != null) sp["data-v"] = cell.v instanceof Date ? cell.v.toISOString() : cell.v;
23985
24102
  if(cell.z != null) sp["data-z"] = cell.z;
23986
- if(cell.f != null) sp["data-f"] = escapehtml(cell.f);
23987
- if(cell.l && (cell.l.Target || "#").charAt(0) != "#" && (!o.sanitizeLinks || (cell.l.Target || "").slice(0, 11).toLowerCase() != 'javascript:')) w = '<a href="' + escapehtml(cell.l.Target) +'">' + w + '</a>';
24103
+ if(cell.f != null) sp["data-f"] = cell.f;
24104
+ var href = cell.l && safe_html_href(cell.l.Target);
24105
+ if(href) w = '<a href="' + html_attr_escape(href) +'">' + w + '</a>';
23988
24106
  }
23989
24107
  var cstyle = html_cell_style(stylecell, o);
23990
24108
  var lstyle = html_cell_layout_style(stylecell, o, C, CS, cols);
23991
24109
  if(lstyle) cstyle = cstyle ? cstyle + ";" + lstyle : lstyle;
23992
24110
  if(cstyle) sp.style = cstyle;
23993
24111
  sp.id = (o.id || "sjs") + "-" + coord;
23994
- oo.push(writextag('td', w, sp));
24112
+ oo.push(html_writextag('td', w, sp));
23995
24113
  }
23996
24114
  var rsp = ({}), rstyle = [];
23997
24115
  if(row) {
@@ -23999,7 +24117,7 @@ function make_html_row(ws, r, R, o) {
23999
24117
  if(o.browserPixels) rstyle.push("height:" + html_row_height(row) + "px");
24000
24118
  }
24001
24119
  if(rstyle.length) rsp.style = rstyle.join(";");
24002
- return writextag('tr', oo.join(""), rsp);
24120
+ return html_writextag('tr', oo.join(""), rsp);
24003
24121
  }
24004
24122
 
24005
24123
  var HTML_BEGIN = '<html><head><meta charset="utf-8"/><title>SheetJS Table Export</title></head><body>';
@@ -24135,8 +24253,10 @@ function render_html_drawings(ws, opts) {
24135
24253
  var out = [], drawings = ws["!drawings"] || {}, charts = ws["!charts"] || [];
24136
24254
  if(opts && opts.drawings && drawings.images) drawings.images.forEach(function(img) {
24137
24255
  if(!img || !img.dataURI) return;
24256
+ var src = safe_html_image_src(img.dataURI);
24257
+ if(!src) return;
24138
24258
  var pos = html_anchor_pos(ws, img.anchor, opts);
24139
- out.push('<img class="sjs-drawing-image" src="' + img.dataURI + '" style="' + html_abs_style(pos) + '"/>');
24259
+ out.push('<img class="sjs-drawing-image" src="' + html_attr_escape(src) + '" style="' + html_abs_style(pos) + '"/>');
24140
24260
  });
24141
24261
  if(opts && opts.charts) charts.forEach(function(chart) {
24142
24262
  var pos = html_anchor_pos(ws, chart.anchor, opts);
@@ -24151,7 +24271,7 @@ function make_html_preamble(ws, R, o) {
24151
24271
  if(o && o.id) tattr.id = o.id;
24152
24272
  if(o && (o.browserPixels || o.autoFit)) tstyle.push("border-collapse:collapse;table-layout:fixed");
24153
24273
  if(tstyle.length) tattr.style = tstyle.join(";");
24154
- var table = writextag("table", "", tattr).replace(/<\/table>$/, "");
24274
+ var table = html_writextag("table", "", tattr).replace(/<\/table>$/, "");
24155
24275
  var cols = o && o._htmlCols || ws["!cols"];
24156
24276
  if(o && (o.browserPixels || o.autoFit) && cols) {
24157
24277
  out.push("<colgroup>");
@@ -24159,7 +24279,7 @@ function make_html_preamble(ws, R, o) {
24159
24279
  var col = cols[C], style = [];
24160
24280
  style.push("width:" + html_col_width(col) + "px");
24161
24281
  if(col && col.hidden) style.push("display:none");
24162
- out.push(writextag("col", null, {style:style.join(";")}));
24282
+ out.push(html_writextag("col", null, {style:style.join(";")}));
24163
24283
  }
24164
24284
  out.push("</colgroup>");
24165
24285
  }
@@ -24326,7 +24446,7 @@ function parse_text_p(text) {
24326
24446
  .replace(/<text:s text:c="(\d+)"\/>/g, function($$,$1) { return Array(parseInt($1,10)+1).join(" "); })
24327
24447
  .replace(/<text:tab[^<>]*\/>/g,"\t")
24328
24448
  .replace(/<text:line-break\/>/g,"\n");
24329
- var v = unescapexml(fixed.replace(/<[^<>]*>/g,""));
24449
+ var v = unescapexml(strip_xml_tags(fixed));
24330
24450
 
24331
24451
  return [v];
24332
24452
  }
@@ -24563,7 +24683,7 @@ function parse_content_xml(d, _opts, _nfm) {
24563
24683
  var nfidx, NF = "", pidx = 0;
24564
24684
  var sheetag;
24565
24685
  var rowtag;
24566
- var Sheets = {}, SheetNames = [];
24686
+ var Sheets = sheet_map_new(), SheetNames = [];
24567
24687
  var ws = ({}); if(opts.dense) ws["!data"] = [];
24568
24688
  var Rn, q;
24569
24689
  var ctag = ({value:""}), ctag2 = ({});
@@ -24600,7 +24720,7 @@ function parse_content_xml(d, _opts, _nfm) {
24600
24720
  sheetag.name = sheetag['名称'] || sheetag.name;
24601
24721
  if(typeof JSON !== 'undefined') JSON.stringify(sheetag);
24602
24722
  SheetNames.push(sheetag.name);
24603
- Sheets[sheetag.name] = ws;
24723
+ sheet_map_set(Sheets, sheetag.name, ws);
24604
24724
  WB.Sheets.push({
24605
24725
  /* TODO: CodeName */
24606
24726
  Hidden: (tstyles[sheetag["style-name"]] && tstyles[sheetag["style-name"]]["display"] ? (parsexmlbool(tstyles[sheetag["style-name"]]["display"]) ? 0 : 1) : 0)
@@ -24956,7 +25076,9 @@ function parse_content_xml(d, _opts, _nfm) {
24956
25076
  if(Rn[1]==='/') break;
24957
25077
  try {
24958
25078
  _Ref = ods_to_csf_3D(parsexmltag(Rn[0])['target-range-address']);
24959
- Sheets[_Ref[0]]['!autofilter'] = { ref:_Ref[1] };
25079
+ if(Object.prototype.hasOwnProperty.call(Sheets, _Ref[0]) && Sheets[_Ref[0]]) {
25080
+ Sheets[_Ref[0]]['!autofilter'] = { ref:_Ref[1] };
25081
+ }
24960
25082
  } catch(e) {/* empty */}
24961
25083
  break;
24962
25084
 
@@ -25466,7 +25588,7 @@ var write_content_ods = /* @__PURE__ */(function() {
25466
25588
 
25467
25589
  /* column styles */
25468
25590
  var cidx = 0;
25469
- wb.SheetNames.map(function(n) { return wb.Sheets[n]; }).forEach(function(ws) {
25591
+ wb.SheetNames.map(function(n) { return sheet_map_get(wb.Sheets, n); }).forEach(function(ws) {
25470
25592
  if(!ws) return;
25471
25593
  if(ws["!cols"]) {
25472
25594
  for(var C = 0; C < ws["!cols"].length; ++C) if(ws["!cols"][C]) {
@@ -25485,7 +25607,7 @@ var write_content_ods = /* @__PURE__ */(function() {
25485
25607
 
25486
25608
  /* row styles */
25487
25609
  var ridx = 0;
25488
- wb.SheetNames.map(function(n) { return wb.Sheets[n]; }).forEach(function(ws) {
25610
+ wb.SheetNames.map(function(n) { return sheet_map_get(wb.Sheets, n); }).forEach(function(ws) {
25489
25611
  if(!ws) return;
25490
25612
  if(ws["!rows"]) {
25491
25613
  for(var R = 0; R < ws["!rows"].length; ++R) if(ws["!rows"][R]) {
@@ -25518,7 +25640,7 @@ var write_content_ods = /* @__PURE__ */(function() {
25518
25640
  /* number formats, table cells, text */
25519
25641
  var nfs = {};
25520
25642
  var nfi = 69;
25521
- wb.SheetNames.map(function(n) { return wb.Sheets[n]; }).forEach(function(ws) {
25643
+ wb.SheetNames.map(function(n) { return sheet_map_get(wb.Sheets, n); }).forEach(function(ws) {
25522
25644
  if(!ws) return;
25523
25645
  var dense = (ws["!data"] != null);
25524
25646
  if(!ws["!ref"]) return;
@@ -25601,7 +25723,7 @@ var write_content_ods = /* @__PURE__ */(function() {
25601
25723
  o.push(' <office:body>\n');
25602
25724
  o.push(' <office:spreadsheet>\n');
25603
25725
  if(((wb.Workbook||{}).WBProps||{}).date1904) o.push(' <table:calculation-settings table:case-sensitive="false" table:search-criteria-must-apply-to-whole-cell="true" table:use-wildcards="true" table:use-regular-expressions="false" table:automatic-find-labels="false">\n <table:null-date table:date-value="1904-01-01"/>\n </table:calculation-settings>\n');
25604
- for(var i = 0; i != wb.SheetNames.length; ++i) o.push(write_ws(wb.Sheets[wb.SheetNames[i]], wb, i, opts, nfs, ((wb.Workbook||{}).WBProps||{}).date1904));
25726
+ for(var i = 0; i != wb.SheetNames.length; ++i) o.push(write_ws(sheet_map_get(wb.Sheets, wb.SheetNames[i]), wb, i, opts, nfs, ((wb.Workbook||{}).WBProps||{}).date1904));
25605
25727
  if((wb.Workbook||{}).Names) o.push(write_names_ods(wb.Workbook.Names, wb.SheetNames, -1));
25606
25728
  o.push(' </office:spreadsheet>\n');
25607
25729
  o.push(' </office:body>\n');
@@ -25653,7 +25775,6 @@ function write_ods(wb, opts) {
25653
25775
 
25654
25776
  return zip;
25655
25777
  }
25656
-
25657
25778
  /*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
25658
25779
  var subarray = function() {
25659
25780
  try {
@@ -26111,7 +26232,8 @@ var numbers_lut_new = function() {
26111
26232
  function numbers_format_cell(cell, t, flags, ofmt, nfmt) {
26112
26233
  var _a, _b, _c, _d;
26113
26234
  var ctype = t & 255, ver = t >> 8;
26114
- var fmt = ver >= 5 ? nfmt : ofmt;
26235
+ /* Missing legacy/new format tables mean the default format. */
26236
+ var fmt = (ver >= 5 ? nfmt : ofmt) || [];
26115
26237
  dur:
26116
26238
  if (flags & (ver > 4 ? 8 : 4) && cell.t == "n" && ctype == 7) {
26117
26239
  var dstyle = ((_a = fmt[7]) == null ? void 0 : _a[0]) ? varint_to_i32(fmt[7][0].data) : -1;
@@ -27170,7 +27292,7 @@ function write_numbers_iwa(wb, opts) {
27170
27292
  docroot = numbers_iwa_find(cfb, deps, 1);
27171
27293
  sheetrefs = mappa(parse_shallow(docroot.messages[0].data)[1], parse_TSP_Reference);
27172
27294
  }
27173
- write_numbers_ws(cfb, deps, wb.Sheets[name], name, idx, sheetrefs[idx]);
27295
+ write_numbers_ws(cfb, deps, sheet_map_get(wb.Sheets, name), name, idx, sheetrefs[idx]);
27174
27296
  });
27175
27297
  return cfb;
27176
27298
  }
@@ -28026,6 +28148,7 @@ function drawing_mime(path) {
28026
28148
  case "bmp": return "image/bmp";
28027
28149
  case "svg": return "image/svg+xml";
28028
28150
  case "jpg": case "jpeg": return "image/jpeg";
28151
+ case "tif": case "tiff": return "image/tiff";
28029
28152
  default: return "application/octet-stream";
28030
28153
  }
28031
28154
  }
@@ -28041,7 +28164,9 @@ function parse_sheet_drawing(sheet, type, zip, path, idx, opts, wb) {
28041
28164
  if(!img || !img.target) return;
28042
28165
  var ipath = resolve_path(img.target, dfile);
28043
28166
  var ibin = getzipbin(zip, ipath, true);
28044
- if(ibin) img.dataURI = "data:" + drawing_mime(ipath) + ";base64," + Base64_encode_arr(ibin);
28167
+ var contentType = drawing_mime(ipath);
28168
+ if(ibin) img.dataURI = "data:" + contentType + ";base64," + Base64_encode_arr(ibin);
28169
+ img.contentType = contentType;
28045
28170
  img.path = ipath;
28046
28171
  });
28047
28172
  if(opts.charts && draw.charts && draw.charts.length) {
@@ -28085,7 +28210,7 @@ function safe_parse_sheet(zip, path, relsPath, sheet, idx, sheetRels, sheets, st
28085
28210
  case 'dialog': _ws = parse_ds(data, path, idx, opts, sheetRels[sheet], wb, themes, styles); break;
28086
28211
  default: throw new Error("Unrecognized sheet type " + stype);
28087
28212
  }
28088
- sheets[sheet] = _ws;
28213
+ sheet_map_set(sheets, sheet, _ws);
28089
28214
 
28090
28215
  /* scan rels for comments and threaded comments */
28091
28216
  var comments = [], tcomments = [];
@@ -28208,7 +28333,7 @@ function parse_zip(zip, opts) {
28208
28333
  if(opts.bookSheets && typeof sheets !== 'undefined') out.SheetNames = sheets;
28209
28334
  if(opts.bookSheets ? out.SheetNames : opts.bookProps) return out;
28210
28335
  }
28211
- sheets = {};
28336
+ sheets = sheet_map_new();
28212
28337
 
28213
28338
  var deps = {};
28214
28339
  if(opts.bookDeps && dir.calcchain) deps=parse_cc(getzipdata(zip, strip_front_slash(dir.calcchain)),dir.calcchain,opts);
@@ -28408,7 +28533,7 @@ f = "docProps/app.xml";
28408
28533
 
28409
28534
  for(rId=1;rId <= wb.SheetNames.length; ++rId) {
28410
28535
  var wsrels = {'!id':{}};
28411
- var ws = wb.Sheets[wb.SheetNames[rId-1]];
28536
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[rId-1]);
28412
28537
  var _type = (ws || {})["!type"] || "sheet";
28413
28538
  switch(_type) {
28414
28539
  case "chart":
@@ -28563,7 +28688,7 @@ f = "docProps/app.xml";
28563
28688
 
28564
28689
  for(rId=1;rId <= wb.SheetNames.length; ++rId) {
28565
28690
  var wsrels = {'!id':{}};
28566
- var ws = wb.Sheets[wb.SheetNames[rId-1]];
28691
+ var ws = sheet_map_get(wb.Sheets, wb.SheetNames[rId-1]);
28567
28692
  var _type = (ws || {})["!type"] || "sheet";
28568
28693
  switch(_type) {
28569
28694
  case "chart":
@@ -28659,7 +28784,6 @@ f = "docProps/app.xml";
28659
28784
  delete opts.revssf; delete opts.ssf;
28660
28785
  return zip;
28661
28786
  }
28662
-
28663
28787
  function firstbyte(f,o) {
28664
28788
  var x = "";
28665
28789
  switch((o||{}).type || "base64") {
@@ -28928,18 +29052,18 @@ function writeSync(wb, opts) {
28928
29052
  case 'xml':
28929
29053
  case 'xlml': return write_string_type(write_xlml(wb, o), o);
28930
29054
  case 'slk':
28931
- case 'sylk': return write_string_type(SYLK.from_sheet(wb.Sheets[wb.SheetNames[idx]], o, wb), o);
29055
+ case 'sylk': return write_string_type(SYLK.from_sheet(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o, wb), o);
28932
29056
  case 'htm':
28933
- case 'html': return write_string_type(sheet_to_html(wb.Sheets[wb.SheetNames[idx]], o), o);
28934
- case 'txt': return write_stxt_type(sheet_to_txt(wb.Sheets[wb.SheetNames[idx]], o), o);
28935
- case 'csv': return write_string_type(sheet_to_csv(wb.Sheets[wb.SheetNames[idx]], o), o, "\ufeff");
28936
- case 'dif': return write_string_type(DIF.from_sheet(wb.Sheets[wb.SheetNames[idx]], o), o);
28937
- case 'dbf': return write_binary_type(DBF.from_sheet(wb.Sheets[wb.SheetNames[idx]], o), o);
28938
- case 'prn': return write_string_type(PRN.from_sheet(wb.Sheets[wb.SheetNames[idx]], o), o);
28939
- case 'rtf': return write_string_type(sheet_to_rtf(wb.Sheets[wb.SheetNames[idx]], o), o);
28940
- case 'eth': return write_string_type(ETH.from_sheet(wb.Sheets[wb.SheetNames[idx]], o), o);
29057
+ case 'html': return write_string_type(sheet_to_html(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29058
+ case 'txt': return write_stxt_type(sheet_to_txt(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29059
+ case 'csv': return write_string_type(sheet_to_csv(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o, "\ufeff");
29060
+ case 'dif': return write_string_type(DIF.from_sheet(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29061
+ case 'dbf': return write_binary_type(DBF.from_sheet(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29062
+ case 'prn': return write_string_type(PRN.from_sheet(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29063
+ case 'rtf': return write_string_type(sheet_to_rtf(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
29064
+ case 'eth': return write_string_type(ETH.from_sheet(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
28941
29065
  case 'fods': return write_string_type(write_ods(wb, o), o);
28942
- case 'wk1': return write_binary_type(WK_.sheet_to_wk1(wb.Sheets[wb.SheetNames[idx]], o), o);
29066
+ case 'wk1': return write_binary_type(WK_.sheet_to_wk1(sheet_map_get(wb.Sheets, wb.SheetNames[idx]), o), o);
28943
29067
  case 'wk3': return write_binary_type(WK_.book_to_wk3(wb, o), o);
28944
29068
  case 'biff2': if(!o.biff) o.biff = 2; /* falls through */
28945
29069
  case 'biff3': if(!o.biff) o.biff = 3; /* falls through */
@@ -29199,6 +29323,7 @@ function sheet_add_json(_ws, js, opts) {
29199
29323
  var _origin = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin;
29200
29324
  _R = _origin.r; _C = _origin.c;
29201
29325
  }
29326
+ if(!isFinite(_R) || _R !== Math.floor(_R) || _R < -1 || !isFinite(_C) || _C !== Math.floor(_C) || _C < 0) throw new Error("Invalid origin");
29202
29327
  }
29203
29328
  var range = ({s: {c:0, r:0}, e: {c:_C, r:_R + js.length - 1 + offset}});
29204
29329
  if(ws['!ref']) {
@@ -29290,7 +29415,7 @@ function wb_sheet_idx(wb, sh) {
29290
29415
 
29291
29416
  /* simple blank or single-sheet workbook object */
29292
29417
  function book_new(ws, wsname) {
29293
- var wb = { SheetNames: [], Sheets: {} };
29418
+ var wb = { SheetNames: [], Sheets: sheet_map_new() };
29294
29419
  if(ws) book_append_sheet(wb, ws, wsname || "Sheet1");
29295
29420
  return wb;
29296
29421
  }
@@ -29310,7 +29435,7 @@ function book_append_sheet(wb, ws, name, roll) {
29310
29435
  if(wb.SheetNames.indexOf(name) >= 0) throw new Error("Worksheet with name |" + name + "| already exists!");
29311
29436
 
29312
29437
  wb.SheetNames.push(name);
29313
- wb.Sheets[name] = ws;
29438
+ sheet_map_set(wb.Sheets, name, ws);
29314
29439
  return name;
29315
29440
  }
29316
29441
 
@@ -29377,7 +29502,6 @@ function sheet_set_array_formula(ws, range, formula, dynamic) {
29377
29502
  ws["!ref"] = encode_range(wsr);
29378
29503
  return ws;
29379
29504
  }
29380
-
29381
29505
  var utils = {
29382
29506
  encode_col: encode_col,
29383
29507
  encode_row: encode_row,
@@ -29534,7 +29658,7 @@ function write_json_stream(sheet, opts) {
29534
29658
  if ((rowinfo[R]||{}).hidden) {
29535
29659
  ++R;
29536
29660
  continue;
29537
- };
29661
+ }
29538
29662
  var row = make_json_row(sheet, r, R, cols, header, hdr, o);
29539
29663
  ++R;
29540
29664
  if((row.isempty === false) || (header === 1 ? o.blankrows !== false : !!o.blankrows)) {
@@ -29563,7 +29687,7 @@ function write_xlml_stream(wb, o) {
29563
29687
 
29564
29688
  /* do one pass to determine styles since they must be added before tables */
29565
29689
  wb.SheetNames.forEach(function(n) {
29566
- var ws = wb.Sheets[n];
29690
+ var ws = sheet_map_get(wb.Sheets, n);
29567
29691
  if(!ws || !ws["!ref"]) return;
29568
29692
  var range = decode_range(ws["!ref"]);
29569
29693
  var dense = ws["!data"] != null;
@@ -29583,7 +29707,7 @@ function write_xlml_stream(wb, o) {
29583
29707
  });
29584
29708
  var sty = write_sty_xlml(wb, opts);
29585
29709
 
29586
- var stage = 0, wsidx = 0, ws = wb.Sheets[wb.SheetNames[wsidx]], range = safe_decode_range(ws), R = -1, T = false;
29710
+ var stage = 0, wsidx = 0, ws = sheet_map_get(wb.Sheets, wb.SheetNames[wsidx]), range = safe_decode_range(ws), R = -1, T = false;
29587
29711
 
29588
29712
  var marr = [], mi = 0, dense = false, darr = [], addr = {r:0,c:0};
29589
29713
 
@@ -29623,7 +29747,7 @@ function write_xlml_stream(wb, o) {
29623
29747
 
29624
29748
  stream.push("<Worksheet" + wxt_helper({ "ss:Name": escapexml(wb.SheetNames[wsidx])}) + ">");
29625
29749
 
29626
- ws = wb.Sheets[wb.SheetNames[wsidx]];
29750
+ ws = sheet_map_get(wb.Sheets, wb.SheetNames[wsidx]);
29627
29751
  if(!ws) { stream.push("</Worksheet>"); return void ++wsidx; }
29628
29752
 
29629
29753
  var names = write_ws_xlml_names(ws, opts, wsidx, wb);