simple-super-doc 0.11.5 → 0.11.6

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/dist/index.d.ts CHANGED
@@ -122,6 +122,10 @@ type ComputedStyle = {
122
122
  italic?: boolean;
123
123
  underline?: boolean;
124
124
  strike?: boolean;
125
+ doubleStrike?: boolean;
126
+ hidden?: boolean;
127
+ caps?: boolean;
128
+ smallCaps?: boolean;
125
129
  vertAlign?: 'super' | 'sub';
126
130
  fontSize?: number;
127
131
  fontFamily?: string;
package/dist/index.js CHANGED
@@ -85,6 +85,14 @@ function extractRPr(rPr) {
85
85
  const val = typeof st === "object" && st !== null ? st.val : void 0;
86
86
  s.strike = !(val === "0" || val === "false" || val === "off");
87
87
  }
88
+ const toggle = (node) => {
89
+ const val = typeof node === "object" && node !== null ? node.val : void 0;
90
+ return !(val === "0" || val === "false" || val === "off");
91
+ };
92
+ if ("dstrike" in rPr) s.doubleStrike = toggle(rPr.dstrike);
93
+ if ("vanish" in rPr) s.hidden = toggle(rPr.vanish);
94
+ if ("caps" in rPr) s.caps = toggle(rPr.caps);
95
+ if ("smallCaps" in rPr) s.smallCaps = toggle(rPr.smallCaps);
88
96
  if ("vertAlign" in rPr) {
89
97
  const va = rPr.vertAlign?.val;
90
98
  if (va === "superscript") s.vertAlign = "super";
@@ -168,6 +176,10 @@ function extractPPr(pPr) {
168
176
  const val = pPr.bidi?.val;
169
177
  s.rtl = !(val === "0" || val === "false" || val === "off");
170
178
  }
179
+ if ("shd" in pPr) {
180
+ const fill = pPr.shd?.fill;
181
+ if (fill && fill !== "auto") s.backgroundColor = fill;
182
+ }
171
183
  if ("pBdr" in pPr) {
172
184
  const bdr = pPr.pBdr;
173
185
  const sides = [["top", "borderTop"], ["bottom", "borderBottom"], ["left", "borderLeft"], ["right", "borderRight"]];
@@ -491,6 +503,7 @@ async function parseRun(r, paraStyle, ctx, href) {
491
503
  if (brType === "column") return null;
492
504
  lineBreak = true;
493
505
  }
506
+ if ("cr" in r) lineBreak = true;
494
507
  const rStyleId = getVal(rPr?.rStyle);
495
508
  const charStyle = rStyleId ? ctx.styleMap[rStyleId] ?? {} : {};
496
509
  const runStyle = Object.assign({}, paraStyle, charStyle, extractRPr(rPr));
@@ -571,6 +584,32 @@ async function parseRun(r, paraStyle, ctx, href) {
571
584
  const segments = collectText(r.t ?? r.delText);
572
585
  const tabNode = r.tab;
573
586
  const tabCount = Array.isArray(tabNode) ? tabNode.length : "tab" in r ? 1 : 0;
587
+ const asArray = (n) => Array.isArray(n) ? n : n != null ? [n] : [];
588
+ let symText = "";
589
+ let symFont;
590
+ for (const sy of asArray(r.sym)) {
591
+ const code = parseInt(String(sy?.char ?? ""), 16);
592
+ if (code >= 0 && code <= 1114111) symText += String.fromCodePoint(code);
593
+ symFont ?? (symFont = sy?.font);
594
+ }
595
+ const hyphens = "\u2011".repeat(asArray(r.noBreakHyphen).length) + "\xAD".repeat(asArray(r.softHyphen).length);
596
+ if (hyphens) {
597
+ if (segments.length >= 2) segments[1] = hyphens + segments[1];
598
+ else segments[0] = (segments[0] ?? "") + hyphens;
599
+ }
600
+ if (symText) {
601
+ if (segments.length === 0) {
602
+ const style = symFont ? Object.assign({}, runStyle, { fontFamily: symFont }) : runStyle;
603
+ return {
604
+ type: "run",
605
+ text: symText,
606
+ style,
607
+ ...href ? { href } : {},
608
+ ...lineBreak ? { lineBreak: true } : {}
609
+ };
610
+ }
611
+ segments[segments.length - 1] += symText;
612
+ }
574
613
  const makeRun = (text, tabs, isLast) => ({
575
614
  type: "run",
576
615
  text,
@@ -1266,8 +1305,10 @@ function styleToCss(s) {
1266
1305
  const parts = [];
1267
1306
  if (s.bold) parts.push("font-weight:bold");
1268
1307
  if (s.italic) parts.push("font-style:italic");
1269
- const deco = [s.underline ? "underline" : "", s.strike ? "line-through" : ""].filter(Boolean);
1270
- if (deco.length) parts.push(`text-decoration:${deco.join(" ")}`);
1308
+ const deco = [s.underline ? "underline" : "", s.strike || s.doubleStrike ? "line-through" : ""].filter(Boolean);
1309
+ if (deco.length) parts.push(`text-decoration:${deco.join(" ")}${s.doubleStrike && !s.underline ? " double" : ""}`);
1310
+ if (s.caps) parts.push("text-transform:uppercase");
1311
+ if (s.smallCaps) parts.push("font-variant:small-caps");
1271
1312
  if (s.vertAlign) {
1272
1313
  parts.push(`vertical-align:${s.vertAlign}`);
1273
1314
  parts.push("font-size:0.83em");
@@ -1310,6 +1351,7 @@ function renderRun(run, parent, skipLeadingTabs = false) {
1310
1351
  return;
1311
1352
  }
1312
1353
  const textRun = run;
1354
+ if (textRun.style.hidden) return;
1313
1355
  if (textRun.deleted) {
1314
1356
  if (!showRevisions) return;
1315
1357
  const del = document.createElement("del");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-super-doc",
3
- "version": "0.11.5",
3
+ "version": "0.11.6",
4
4
  "description": "Faithful DOCX renderer with exposed typed IR for building document editors",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",