styled-exceljs 0.21.0 → 0.21.2

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.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  /*exported XLSX */
4
4
  /*global process:false, Buffer:false, ArrayBuffer:false, DataView:false, Deno:false */
5
5
  var XLSX = {};
6
- XLSX.version = '0.21.0';
6
+ XLSX.version = '0.21.2';
7
7
  var current_codepage = 1200, current_ansi = 1252;
8
8
  /*:: declare var cptable:any; */
9
9
  /*global cptable:true, window */
@@ -11196,7 +11196,7 @@ function resolve_style_obj_color(obj, themes) {
11196
11196
 
11197
11197
  /* 18.3.1.13 width calculations */
11198
11198
  /* [MS-OI29500] 2.1.595 Column Width & Formatting */
11199
- var DEF_MDW = 6, MAX_MDW = 15, MIN_MDW = 1, MDW = DEF_MDW;
11199
+ var DEF_MDW = 7, MAX_MDW = 15, MIN_MDW = 1, MDW = DEF_MDW;
11200
11200
  function width2px(width) { return Math.floor(( width + (Math.round(128/MDW))/256 )* MDW ); }
11201
11201
  function px2char(px) { return (Math.floor((px - 5)/MDW * 100 + 0.5))/100; }
11202
11202
  function char2width(chr) { return (Math.round((chr * MDW + 5)/MDW*256))/256; }
@@ -11238,6 +11238,188 @@ function process_col(coll/*:ColInfo*/) {
11238
11238
  if(coll.customWidth) delete coll.customWidth;
11239
11239
  }
11240
11240
 
11241
+ var XLSX_COL_WIDTH_MAX = 255, XLSX_COL_WIDTH_PADDING = 5;
11242
+ function clamp_col_width(width) {
11243
+ return width > XLSX_COL_WIDTH_MAX ? XLSX_COL_WIDTH_MAX : width < 0 ? 0 : width;
11244
+ }
11245
+ function px2col(px) {
11246
+ var width = char2width(px2char(Math.max(0, px)));
11247
+ return clamp_col_width(width);
11248
+ }
11249
+ function col2px(col) {
11250
+ if(!col) return 64;
11251
+ if(col.wpx != null) return col.wpx;
11252
+ if(col.width != null) return width2px(col.width);
11253
+ if(col.wch != null) return width2px(char2width(col.wch));
11254
+ return 64;
11255
+ }
11256
+ function set_col_width_from_px(col, px) {
11257
+ if(!col) col = ({}/*:any*/);
11258
+ col.wpx = Math.max(0, Math.ceil(px));
11259
+ col.wch = px2char(col.wpx);
11260
+ col.width = px2col(col.wpx);
11261
+ col.MDW = MDW;
11262
+ col.bestFit = true;
11263
+ col.customWidth = true;
11264
+ return col;
11265
+ }
11266
+ function style_font_size_pt(style) {
11267
+ var font = style && style.font || {};
11268
+ var sz = +font.sz;
11269
+ return sz > 0 ? sz : 11;
11270
+ }
11271
+ function style_font_family(style) {
11272
+ var font = style && style.font || {};
11273
+ return font.name || "Calibri";
11274
+ }
11275
+ function css_font_from_style(style) {
11276
+ var font = style && style.font || {};
11277
+ var parts = [];
11278
+ if(font.italic) parts.push("italic");
11279
+ if(font.bold) parts.push("bold");
11280
+ parts.push(style_font_size_pt(style) + "pt");
11281
+ var name = style_font_family(style);
11282
+ if(/[,\s'"]/.test(name)) name = '"' + String(name).replace(/"/g, '\\"') + '"';
11283
+ parts.push(name);
11284
+ return parts.join(" ");
11285
+ }
11286
+ function fallback_char_width(ch, fpx) {
11287
+ var cc = ch.charCodeAt(0);
11288
+ if(cc == 9 || cc == 32) return fpx * 0.33;
11289
+ if(cc >= 48 && cc <= 57) return fpx * 0.52;
11290
+ if(cc >= 65 && cc <= 90) return fpx * 0.62;
11291
+ if(cc >= 97 && cc <= 122) {
11292
+ if("iljtfr".indexOf(ch) > -1) return fpx * 0.28;
11293
+ if("mw".indexOf(ch) > -1) return fpx * 0.82;
11294
+ return fpx * 0.50;
11295
+ }
11296
+ if(cc >= 0x2E80) return fpx;
11297
+ return fpx * 0.52;
11298
+ }
11299
+ function fallback_text_width(text, style) {
11300
+ var fpx = pt2px_browser(style_font_size_pt(style)), width = 0;
11301
+ for(var i = 0; i < text.length; ++i) width += fallback_char_width(text.charAt(i), fpx);
11302
+ return width;
11303
+ }
11304
+ function measure_text_width(text/*:string*/, style/*:?CellStyle*/, opts/*:?any*/)/*:number*/ {
11305
+ var o = opts || {};
11306
+ var str = text == null ? "" : String(text);
11307
+ var lines = str.split(/\r\n|\n|\r/g), max = 0, i = 0, w = 0;
11308
+ if(o.measureText) for(i = 0; i < lines.length; ++i) {
11309
+ w = +o.measureText(lines[i], css_font_from_style(style), style || {});
11310
+ if(isFinite(w) && w > max) max = w;
11311
+ }
11312
+ else {
11313
+ var canvas = o.canvas, ctx = null;
11314
+ if(!canvas && typeof document !== "undefined" && document.createElement) try { canvas = document.createElement("canvas"); } catch(e) {}
11315
+ try { ctx = canvas && canvas.getContext && canvas.getContext("2d"); } catch(e) { ctx = null; }
11316
+ if(ctx && ctx.measureText) {
11317
+ ctx.font = css_font_from_style(style);
11318
+ for(i = 0; i < lines.length; ++i) {
11319
+ w = ctx.measureText(lines[i]).width;
11320
+ if(isFinite(w) && w > max) max = w;
11321
+ }
11322
+ } else for(i = 0; i < lines.length; ++i) {
11323
+ w = fallback_text_width(lines[i], style || {});
11324
+ if(isFinite(w) && w > max) max = w;
11325
+ }
11326
+ }
11327
+ return max;
11328
+ }
11329
+ function auto_fit_cell_text(cell/*:Cell*/, opts/*:?any*/)/*:string*/ {
11330
+ if(!cell || cell.v == null) return "";
11331
+ if(cell.w == null && cell.t != 'z') format_cell(cell);
11332
+ return String(cell.w != null ? cell.w : cell.v);
11333
+ }
11334
+ function text_width_segments(text, wrap) {
11335
+ var lines = String(text == null ? "" : text).split(/\r\n|\n|\r/g), out = [], i = 0, j = 0, parts = null;
11336
+ if(!wrap) return lines;
11337
+ for(i = 0; i < lines.length; ++i) {
11338
+ parts = lines[i].split(/[\t \u00A0\-\/]+/);
11339
+ for(j = 0; j < parts.length; ++j) if(parts[j]) out.push(parts[j]);
11340
+ if(!parts.length || (parts.length == 1 && !parts[0])) out.push(lines[i]);
11341
+ }
11342
+ return out.length ? out : [""];
11343
+ }
11344
+ function effective_cell_style(ws/*:Worksheet*/, cell/*:?Cell*/, R/*:number*/, C/*:number*/) {
11345
+ var out = ({}/*:any*/), cols = ws["!cols"] || [], rows = ws["!rows"] || [];
11346
+ if(cols[C] && cols[C].s) extend_style_obj(out, cols[C].s);
11347
+ if(rows[R] && rows[R].s) extend_style_obj(out, rows[R].s);
11348
+ if(cell && cell.s) extend_style_obj(out, cell.s);
11349
+ return out;
11350
+ }
11351
+ function measure_cell_text_width(cell/*:Cell*/, style/*:CellStyle*/, opts/*:?any*/)/*:number*/ {
11352
+ var o = opts || {}, text = auto_fit_cell_text(cell, o), align = style && style.alignment || {};
11353
+ var wrap = !!align.wrapText, segments = text_width_segments(text, wrap), max = 0, w = 0;
11354
+ for(var i = 0; i < segments.length; ++i) {
11355
+ w = measure_text_width(segments[i], style, o);
11356
+ if(w > max) max = w;
11357
+ }
11358
+ var indent = +align.indent || 0;
11359
+ if(indent > 0) max += indent * 3 * Math.max(1, MDW);
11360
+ var rotation = +align.textRotation || 0;
11361
+ if(rotation == 255) rotation = 90;
11362
+ if(rotation > 90) rotation = 90 - rotation;
11363
+ if(rotation < 0) rotation = -rotation;
11364
+ if(rotation > 0 && rotation < 90) {
11365
+ var rad = rotation * Math.PI / 180, fpx = pt2px_browser(style_font_size_pt(style));
11366
+ max = Math.abs(max * Math.cos(rad)) + Math.abs(fpx * Math.sin(rad));
11367
+ } else if(rotation >= 90) max = Math.max(MDW + XLSX_COL_WIDTH_PADDING, pt2px_browser(style_font_size_pt(style)) + 2);
11368
+ return max + (o.padding != null ? +o.padding : XLSX_COL_WIDTH_PADDING);
11369
+ }
11370
+ function merge_start_map(merges) {
11371
+ var out = {};
11372
+ for(var i = 0; i < merges.length; ++i) out[merges[i].s.r + ":" + merges[i].s.c] = merges[i];
11373
+ return out;
11374
+ }
11375
+ function is_covered_merge(merges, R, C) {
11376
+ for(var i = 0; i < merges.length; ++i) {
11377
+ var m = merges[i];
11378
+ if(m.s.r <= R && R <= m.e.r && m.s.c <= C && C <= m.e.c) return !(m.s.r == R && m.s.c == C);
11379
+ }
11380
+ return false;
11381
+ }
11382
+ function auto_fit_columns(ws/*:Worksheet*/, opts/*:?any*/)/*:Array<ColInfo>*/ {
11383
+ var o = opts || {}, oldMDW = MDW;
11384
+ if(o.MDW) MDW = +o.MDW || MDW;
11385
+ var r = o.range ? (typeof o.range == "string" ? decode_range(o.range) : o.range) : decode_range(ws["!ref"] || "A1");
11386
+ var base = ws["!cols"] || [], rows = ws["!rows"] || [], cols = [], widths = [];
11387
+ var minpx = o.minPx != null ? +o.minPx : o.min != null ? width2px(char2width(+o.min)) : 0;
11388
+ var maxpx = o.maxPx != null ? +o.maxPx : width2px(XLSX_COL_WIDTH_MAX);
11389
+ var merges = o.includeMerged === false ? [] : (ws["!merges"] || []);
11390
+ var starts = merge_start_map(merges), dense = ws["!data"] != null;
11391
+ var C = 0, R = 0, span = 0, m = null, j = 0, cell = null, style = null, need = 0, have = 0;
11392
+ for(C = r.s.c; C <= r.e.c; ++C) {
11393
+ cols[C] = dup(base[C] || {});
11394
+ if(cols[C] && cols[C].hidden && o.skipHidden) continue;
11395
+ widths[C] = cols[C] && (cols[C].wpx != null || cols[C].width != null || cols[C].wch != null) ? col2px(cols[C]) : minpx;
11396
+ }
11397
+ for(R = r.s.r; R <= r.e.r; ++R) {
11398
+ if(rows[R] && rows[R].hidden && o.skipHidden) continue;
11399
+ for(C = r.s.c; C <= r.e.c; ++C) {
11400
+ if(cols[C] && cols[C].hidden && o.skipHidden) continue;
11401
+ if(is_covered_merge(merges, R, C)) continue;
11402
+ cell = dense ? (ws["!data"][R]||[])[C] : ws[encode_cell({r:R,c:C})];
11403
+ if(!cell || cell.v == null) continue;
11404
+ style = effective_cell_style(ws, cell, R, C);
11405
+ need = measure_cell_text_width(cell, style, o);
11406
+ if(style && style.alignment && style.alignment.shrinkToFit && widths[C]) need = Math.min(need, widths[C]);
11407
+ m = starts[R + ":" + C];
11408
+ span = m ? m.e.c - m.s.c + 1 : 1;
11409
+ if(span > 1) {
11410
+ have = 0;
11411
+ for(j = 0; j < span; ++j) have += widths[C+j] || minpx;
11412
+ if(need > have) for(j = 0; j < span; ++j) widths[C+j] = Math.min(maxpx, Math.max(widths[C+j] || minpx, (widths[C+j] || minpx) + (need - have) / span));
11413
+ } else widths[C] = Math.min(maxpx, Math.max(widths[C] || minpx, need));
11414
+ }
11415
+ }
11416
+ for(C = r.s.c; C <= r.e.c; ++C) if(widths[C] != null) cols[C] = set_col_width_from_px(cols[C] || {}, Math.min(maxpx, Math.max(minpx, widths[C])));
11417
+ if(o.set === false) { MDW = oldMDW; return cols; }
11418
+ ws["!cols"] = cols;
11419
+ MDW = oldMDW;
11420
+ return cols;
11421
+ }
11422
+
11241
11423
  var DEF_PPI = 96, PPI = DEF_PPI;
11242
11424
  function px2pt(px) { return px * 96 / PPI; }
11243
11425
  function pt2px(pt) { return pt * PPI / 96; }
@@ -16297,8 +16479,11 @@ function col_obj_w(C/*:number*/, col) {
16297
16479
  else if(col.wch != null) wch = col.wch;
16298
16480
  if(wch > -1) { p.width = char2width(wch); p.customWidth = 1; }
16299
16481
  else if(col.width != null) p.width = col.width;
16482
+ if(p.width != null) p.width = clamp_col_width(p.width);
16300
16483
  if(col.hidden) p.hidden = true;
16301
16484
  if(col.level != null) { p.outlineLevel = p.level = col.level; }
16485
+ if(col.bestFit || col.bestfit) p.bestFit = true;
16486
+ if(col.customWidth || col.customwidth) p.customWidth = 1;
16302
16487
  return p;
16303
16488
  }
16304
16489
 
@@ -16656,10 +16841,13 @@ function parse_ws_xml_cols(columns, cols) {
16656
16841
  for(var coli = 0; coli != cols.length; ++coli) {
16657
16842
  var coll = parsexmltag(cols[coli], true);
16658
16843
  if(coll.hidden) coll.hidden = parsexmlbool(coll.hidden);
16844
+ if(coll.bestFit) coll.bestFit = parsexmlbool(coll.bestFit);
16845
+ if(coll.customWidth) coll.customWidth = parsexmlbool(coll.customWidth);
16659
16846
  var colm=parseInt(coll.min, 10)-1, colM=parseInt(coll.max,10)-1;
16660
16847
  if(coll.outlineLevel) coll.level = (+coll.outlineLevel || 0);
16661
16848
  delete coll.min; delete coll.max; coll.width = +coll.width;
16662
- if(!seencol && coll.width) { seencol = true; find_mdw_colw(coll.width); }
16849
+ /* OOXML widths share the workbook Normal-font MDW; do not infer a different scale per sheet. */
16850
+ if(!seencol && coll.width) { seencol = true; MDW = DEF_MDW; }
16663
16851
  process_col(coll);
16664
16852
  while(colm <= colM) columns[colm++] = dup(coll);
16665
16853
  }
@@ -17830,7 +18018,7 @@ function parse_ws_bin(data, _opts, idx, rels, wb/*:WBWBProps*/, themes, styles)/
17830
18018
  if(!opts.cellStyles) break;
17831
18019
  while(val.e >= val.s) {
17832
18020
  colinfo[val.e--] = { width: val.w/256, hidden: !!(val.flags & 0x01), level: val.level };
17833
- if(!seencol) { seencol = true; find_mdw_colw(val.w/256); }
18021
+ if(!seencol) { seencol = true; MDW = DEF_MDW; }
17834
18022
  process_col(colinfo[val.e+1]);
17835
18023
  }
17836
18024
  break;
@@ -21383,7 +21571,7 @@ function parse_workbook(blob, options/*:ParseOpts*/)/*:Workbook*/ {
21383
21571
  while(val.e >= val.s) {
21384
21572
  colinfo[val.e--] = { width: val.w/256, level: (val.level || 0), hidden: !!(val.flags & 1) };
21385
21573
  if(val.ixfe != null && XFs[val.ixfe]) colinfo[val.e+1].s = resolve_xls_style(XFs[val.ixfe], val.ixfe);
21386
- if(!seencol) { seencol = true; find_mdw_colw(val.w/256); }
21574
+ if(!seencol) { seencol = true; MDW = DEF_MDW; }
21387
21575
  process_col(colinfo[val.e+1]);
21388
21576
  }
21389
21577
  } break;
@@ -23813,8 +24001,6 @@ function html_cell_style(cell/*:Cell*/, opts/*:Sheet2HTMLOpts*/) {
23813
24001
  var alignment = s.alignment || {};
23814
24002
  if(alignment.horizontal) css.push("text-align:" + alignment.horizontal);
23815
24003
  if(alignment.vertical) css.push("vertical-align:" + alignment.vertical);
23816
- if(alignment.wrapText) css.push("white-space:normal");
23817
- if(alignment.shrinkToFit) css.push("font-size:smaller");
23818
24004
  if(alignment.textRotation != null && alignment.textRotation !== 0) {
23819
24005
  var deg = alignment.textRotation == 255 ? 90 : alignment.textRotation > 90 ? 90 - alignment.textRotation : alignment.textRotation;
23820
24006
  css.push("transform:rotate(" + deg + "deg)");
@@ -23827,12 +24013,29 @@ function html_cell_style(cell/*:Cell*/, opts/*:Sheet2HTMLOpts*/) {
23827
24013
  add_html_border(css, "bottom", border.bottom);
23828
24014
  return css.join(";");
23829
24015
  }
24016
+ function html_cell_layout_style(cell/*:Cell*/, opts/*:Sheet2HTMLOpts*/, C/*:number*/, CS/*:number*/, cols/*:Array<ColInfo>*/) {
24017
+ if(!opts || !cell) return "";
24018
+ var s = cell.s || {}, alignment = s.alignment || {}, css = [];
24019
+ if(opts.browserPixels || opts.autoFit) css.push("box-sizing:border-box;padding:0 2px;min-width:0");
24020
+ if(alignment.wrapText) css.push("white-space:pre-wrap;overflow-wrap:normal;word-break:normal");
24021
+ else {
24022
+ css.push("white-space:pre");
24023
+ if(alignment.shrinkToFit || opts.overflow == "clip" || opts.overflow == "hidden") css.push("overflow:hidden;text-overflow:clip");
24024
+ else css.push("overflow:visible");
24025
+ }
24026
+ if(alignment.shrinkToFit && cols && C != null) {
24027
+ var have = 0, span = CS || 1;
24028
+ for(var j = 0; j < span; ++j) have += html_col_width(cols[C+j]);
24029
+ var need = measure_cell_text_width(cell, s, opts);
24030
+ if(have > 0 && need > have) {
24031
+ var scale = Math.max(0.25, Math.min(1, have / need));
24032
+ css.push("font-size:" + Math.max(1, style_font_size_pt(s) * scale) + "pt");
24033
+ }
24034
+ }
24035
+ return css.join(";");
24036
+ }
23830
24037
  function html_col_width(col) {
23831
- if(!col) return 64;
23832
- if(col.wpx != null) return col.wpx;
23833
- if(col.width != null) return width2px(col.width);
23834
- if(col.wch != null) return width2px(char2width(col.wch));
23835
- return 64;
24038
+ return col2px(col);
23836
24039
  }
23837
24040
  function html_row_height(row) {
23838
24041
  if(!row) return 20;
@@ -23847,7 +24050,7 @@ function make_html_row(ws/*:Worksheet*/, r/*:Range*/, R/*:number*/, o/*:Sheet2HT
23847
24050
  var sp = ({}/*:any*/);
23848
24051
  var dense = ws["!data"] != null;
23849
24052
  var row = (ws["!rows"]||[])[R];
23850
- var cols = ws["!cols"] || [];
24053
+ var cols = o && o._htmlCols || ws["!cols"] || [];
23851
24054
  for(var C = r.s.c; C <= r.e.c; ++C) {
23852
24055
  var RS = 0, CS = 0;
23853
24056
  for(var j = 0; j < M.length; ++j) {
@@ -23890,6 +24093,8 @@ function make_html_row(ws/*:Worksheet*/, r/*:Range*/, R/*:number*/, o/*:Sheet2HT
23890
24093
  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>';
23891
24094
  }
23892
24095
  var cstyle = html_cell_style(stylecell, o);
24096
+ var lstyle = html_cell_layout_style(stylecell, o, C, CS, cols);
24097
+ if(lstyle) cstyle = cstyle ? cstyle + ";" + lstyle : lstyle;
23893
24098
  if(cstyle) sp.style = cstyle;
23894
24099
  sp.id = (o.id || "sjs") + "-" + coord;
23895
24100
  oo.push(writextag('td', w, sp));
@@ -23921,9 +24126,9 @@ function html_to_workbook(str/*:string*/, opts)/*:Workbook*/ {
23921
24126
  }
23922
24127
 
23923
24128
  var HTML_EMU_PER_PIXEL = 9525;
23924
- function html_anchor_pos(ws, anchor) {
24129
+ function html_anchor_pos(ws, anchor, opts) {
23925
24130
  var out = {left:0, top:0, width:480, height:288};
23926
- var cols = ws["!cols"] || [], rows = ws["!rows"] || [];
24131
+ var cols = opts && opts._htmlCols || ws["!cols"] || [], rows = ws["!rows"] || [];
23927
24132
  var from = anchor && anchor.from || {col:0,row:0,colOff:0,rowOff:0};
23928
24133
  var to = anchor && anchor.to;
23929
24134
  for(var C = 0; C < (from.col||0); ++C) out.left += html_col_width(cols[C]);
@@ -24036,11 +24241,11 @@ function render_html_drawings(ws, opts) {
24036
24241
  var out = [], drawings = ws["!drawings"] || {}, charts = ws["!charts"] || [];
24037
24242
  if(opts && opts.drawings && drawings.images) drawings.images.forEach(function(img) {
24038
24243
  if(!img || !img.dataURI) return;
24039
- var pos = html_anchor_pos(ws, img.anchor);
24244
+ var pos = html_anchor_pos(ws, img.anchor, opts);
24040
24245
  out.push('<img class="sjs-drawing-image" src="' + img.dataURI + '" style="' + html_abs_style(pos) + '"/>');
24041
24246
  });
24042
24247
  if(opts && opts.charts) charts.forEach(function(chart) {
24043
- var pos = html_anchor_pos(ws, chart.anchor);
24248
+ var pos = html_anchor_pos(ws, chart.anchor, opts);
24044
24249
  out.push('<div class="sjs-chart" style="' + html_abs_style(pos) + '">' + render_chart_svg(chart, pos.width, pos.height) + '</div>');
24045
24250
  });
24046
24251
  if(!out.length) return "";
@@ -24048,11 +24253,16 @@ function render_html_drawings(ws, opts) {
24048
24253
  }
24049
24254
  function make_html_preamble(ws/*:Worksheet*/, R/*:Range*/, o/*:Sheet2HTMLOpts*/)/*:string*/ {
24050
24255
  var out/*:Array<string>*/ = [];
24051
- var table = '<table' + (o && o.id ? ' id="' + o.id + '"' : "") + '>';
24052
- if(o && o.browserPixels && ws["!cols"]) {
24256
+ var tattr = ({}/*:any*/), tstyle = [];
24257
+ if(o && o.id) tattr.id = o.id;
24258
+ if(o && (o.browserPixels || o.autoFit)) tstyle.push("border-collapse:collapse;table-layout:fixed");
24259
+ if(tstyle.length) tattr.style = tstyle.join(";");
24260
+ var table = writextag("table", "", tattr).replace(/<\/table>$/, "");
24261
+ var cols = o && o._htmlCols || ws["!cols"];
24262
+ if(o && (o.browserPixels || o.autoFit) && cols) {
24053
24263
  out.push("<colgroup>");
24054
24264
  for(var C = R.s.c; C <= R.e.c; ++C) {
24055
- var col = ws["!cols"][C], style = [];
24265
+ var col = cols[C], style = [];
24056
24266
  style.push("width:" + html_col_width(col) + "px");
24057
24267
  if(col && col.hidden) style.push("display:none");
24058
24268
  out.push(writextag("col", null, {style:style.join(";")}));
@@ -24063,7 +24273,16 @@ function make_html_preamble(ws/*:Worksheet*/, R/*:Range*/, o/*:Sheet2HTMLOpts*/)
24063
24273
  }
24064
24274
 
24065
24275
  function sheet_to_html(ws/*:Worksheet*/, opts/*:?Sheet2HTMLOpts*//*, wb:?Workbook*/)/*:string*/ {
24066
- var o = opts || {};
24276
+ var o = {};
24277
+ if(opts) for(var k in opts) if(Object.prototype.hasOwnProperty.call(opts, k)) o[k] = opts[k];
24278
+ if(o.autoFit) {
24279
+ var af = {set:false};
24280
+ if(typeof o.autoFit == "object") for(k in o.autoFit) if(Object.prototype.hasOwnProperty.call(o.autoFit, k)) af[k] = o.autoFit[k];
24281
+ if(o.measureText && af.measureText == null) af.measureText = o.measureText;
24282
+ if(o.canvas && af.canvas == null) af.canvas = o.canvas;
24283
+ o._htmlCols = auto_fit_columns(ws, af);
24284
+ if(o.browserPixels == null) o.browserPixels = true;
24285
+ }
24067
24286
  var header = o.header != null ? o.header : HTML_BEGIN;
24068
24287
  var footer = o.footer != null ? o.footer : HTML_END;
24069
24288
  var out/*:Array<string>*/ = [header];
@@ -25998,7 +26217,8 @@ var numbers_lut_new = function() {
25998
26217
  function numbers_format_cell(cell, t, flags, ofmt, nfmt) {
25999
26218
  var _a, _b, _c, _d;
26000
26219
  var ctype = t & 255, ver = t >> 8;
26001
- var fmt = ver >= 5 ? nfmt : ofmt;
26220
+ /* Missing legacy/new format tables mean the default format. */
26221
+ var fmt = (ver >= 5 ? nfmt : ofmt) || [];
26002
26222
  dur:
26003
26223
  if (flags & (ver > 4 ? 8 : 4) && cell.t == "n" && ctype == 7) {
26004
26224
  var dstyle = ((_a = fmt[7]) == null ? void 0 : _a[0]) ? varint_to_i32(fmt[7][0].data) : -1;
@@ -27913,6 +28133,7 @@ function drawing_mime(path) {
27913
28133
  case "bmp": return "image/bmp";
27914
28134
  case "svg": return "image/svg+xml";
27915
28135
  case "jpg": case "jpeg": return "image/jpeg";
28136
+ case "tif": case "tiff": return "image/tiff";
27916
28137
  default: return "application/octet-stream";
27917
28138
  }
27918
28139
  }
@@ -27928,7 +28149,9 @@ function parse_sheet_drawing(sheet, type, zip, path, idx, opts, wb) {
27928
28149
  if(!img || !img.target) return;
27929
28150
  var ipath = resolve_path(img.target, dfile);
27930
28151
  var ibin = getzipbin(zip, ipath, true);
27931
- if(ibin) img.dataURI = "data:" + drawing_mime(ipath) + ";base64," + Base64_encode_arr(ibin);
28152
+ var contentType = drawing_mime(ipath);
28153
+ if(ibin) img.dataURI = "data:" + contentType + ";base64," + Base64_encode_arr(ibin);
28154
+ img.contentType = contentType;
27932
28155
  img.path = ipath;
27933
28156
  });
27934
28157
  if(opts.charts && draw.charts && draw.charts.length) {
@@ -29302,6 +29525,9 @@ var utils/*:any*/ = {
29302
29525
  sheet_to_formulae: sheet_to_formulae,
29303
29526
  sheet_to_row_object_array: sheet_to_json,
29304
29527
  validate_merges: validate_merges,
29528
+ measure_text_width: measure_text_width,
29529
+ auto_fit_columns: auto_fit_columns,
29530
+ autofit_columns: auto_fit_columns,
29305
29531
  col_width_to_px: width2px,
29306
29532
  px_to_col_width: function(px) { return char2width(px2char(px)); },
29307
29533
  row_height_to_px: pt2px_browser,