@uurtech/jdf 0.2.3 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uurtech/jdf",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Render JDF (JSON Document Format) documents in the browser. Drop-in replacement for embedding PDFs — point at a .jdf file and it appears on the page, fully styled, searchable, with a clickable TOC.",
5
5
  "license": "MIT",
6
6
  "author": "Ugur Kazdal <ugur@uurtech.com>",
@@ -295,7 +295,13 @@ function colWidthCss(w: string | number | undefined): string | undefined {
295
295
  function renderTable(el: TableElement, ctx: RenderContext): HTMLElement {
296
296
  const wrap = document.createElement("div");
297
297
  wrap.className = "jdfjs-table-wrap";
298
- applyStyle(wrap, resolveStyle(el.style, ctx.styles));
298
+ // `style.fontSize` / `lineHeight` size the cells and `style.padding` is the
299
+ // cell padding (the PDF importer writes compact values so a converted
300
+ // statement occupies the same box as the source rows). Same rules as the
301
+ // reader's TableElement — keep them identical.
302
+ const tableCss = resolveStyle(el.style, ctx.styles);
303
+ const { padding: cellPad = "8px 12px", ...wrapCss } = tableCss;
304
+ applyStyle(wrap, wrapCss);
299
305
  wrap.style.overflowX = "auto";
300
306
 
301
307
  const headerCss = (() => {
@@ -336,7 +342,8 @@ function renderTable(el: TableElement, ctx: RenderContext): HTMLElement {
336
342
  table.style.width = "100%";
337
343
  table.style.borderCollapse = "collapse";
338
344
  table.style.tableLayout = el.columns?.some((c) => c.width != null) ? "fixed" : "auto";
339
- table.style.fontSize = "14px";
345
+ table.style.fontSize = tableCss["font-size"] || "14px";
346
+ if (tableCss["line-height"]) table.style.lineHeight = tableCss["line-height"];
340
347
  if (borders.outer) table.style.border = `${borders.width || 1}px solid ${borders.color || "#e2e8f0"}`;
341
348
 
342
349
  // Column widths — honour columns[].width via a <colgroup> so both header
@@ -359,9 +366,11 @@ function renderTable(el: TableElement, ctx: RenderContext): HTMLElement {
359
366
  headers.forEach((h, i) => {
360
367
  const th = document.createElement("th");
361
368
  th.textContent = h;
362
- th.style.padding = "8px 12px";
369
+ th.style.padding = cellPad;
363
370
  th.style.fontWeight = "600";
364
- th.style.background = "#f8fafc";
371
+ // Designed tables get the light header band; a table that brings its own
372
+ // headerStyle (the PDF importer, hand-authored docs) shows exactly that.
373
+ if (!el.headerStyle) th.style.background = "#f8fafc";
365
374
  th.style.textAlign = colAlign(i) || "left";
366
375
  if (borders.inner) th.style.border = `${borders.width || 1}px solid ${borders.color || "#e2e8f0"}`;
367
376
  tr.appendChild(th);
@@ -382,13 +391,17 @@ function renderTable(el: TableElement, ctx: RenderContext): HTMLElement {
382
391
  const tr = document.createElement("tr");
383
392
  applyStyle(tr, rowCss as any);
384
393
  if (ri % 2 === 1) applyStyle(tr, altRowCss as any);
394
+ // A spacer row (every cell empty — the PDF importer keeps a statement's
395
+ // blank separator lines) must still be one line tall, so it gets a
396
+ // non-breaking space; an empty cell in a filled row stays empty.
397
+ const blankRow = row.every((c) => cellText(c) === "");
385
398
  row.forEach((cell, ci) => {
386
399
  const td = document.createElement("td");
387
- td.textContent = cellText(cell);
400
+ td.textContent = blankRow ? "\u00a0" : cellText(cell);
388
401
  const attrs = cellAttrs(cell);
389
402
  if (attrs.colspan) td.colSpan = attrs.colspan;
390
403
  if (attrs.rowspan) td.rowSpan = attrs.rowspan;
391
- td.style.padding = "8px 12px";
404
+ td.style.padding = cellPad;
392
405
  td.style.verticalAlign = "top";
393
406
  // Cell-level align wins over the column default.
394
407
  td.style.textAlign = cellAlign(cell) || colAlign(ci) || "left";