@file-viewer/docx 0.3.39 → 0.3.41

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.
@@ -9010,7 +9010,7 @@
9010
9010
  props.fontSize = xml.lengthAttr(elem, "val", LengthUsage.FontSize);
9011
9011
  break;
9012
9012
  case "szCs":
9013
- props.fontSize ?? (props.fontSize = xml.lengthAttr(elem, "val", LengthUsage.FontSize));
9013
+ props.complexFontSize = xml.lengthAttr(elem, "val", LengthUsage.FontSize);
9014
9014
  break;
9015
9015
  default:
9016
9016
  return false;
@@ -10268,6 +10268,8 @@
10268
10268
  for (const c of xml.elements(el)) {
10269
10269
  if (c.localName == "adjustLineHeightInTable")
10270
10270
  result.adjustLineHeightInTable = xml.boolAttr(c, "val", true);
10271
+ else if (c.localName == "doNotUseHTMLParagraphAutoSpacing")
10272
+ result.doNotUseHTMLParagraphAutoSpacing = xml.boolAttr(c, "val", true);
10271
10273
  }
10272
10274
  break;
10273
10275
  }
@@ -12639,6 +12641,14 @@
12639
12641
  };
12640
12642
  }
12641
12643
 
12644
+ const WORD_PARAGRAPH_LINE_UNIT_PT = 12;
12645
+ function paragraphSpacingDeclaration(points, lines) {
12646
+ const lineValue = Number.isFinite(lines) && lines >= 0 ? `${(lines * WORD_PARAGRAPH_LINE_UNIT_PT / 100).toFixed(2)}pt` : null;
12647
+ const validPoints = /^(?:\d+(?:\.\d*)?|\.\d+)pt$/i.test(points ?? "");
12648
+ return { lines: lineValue, fallback: lines === 0 && validPoints ? points : lineValue ?? points };
12649
+ }
12650
+ const WORD_HTML_AUTO_SPACING_PT = 14;
12651
+
12642
12652
  var autos = {
12643
12653
  shd: "inherit",
12644
12654
  color: "var(--docx-auto-color, black)",
@@ -14789,8 +14799,10 @@
14789
14799
  style["font-size"] = style["min-height"] = globalXmlParser.lengthAttr(c, "val", LengthUsage.FontSize);
14790
14800
  break;
14791
14801
  case "szCs":
14792
- style["font-size"] ?? (style["font-size"] = globalXmlParser.lengthAttr(c, "val", LengthUsage.FontSize));
14793
- style["min-height"] ?? (style["min-height"] = style["font-size"]);
14802
+ style["--docx-complex-font-size"] = globalXmlParser.lengthAttr(c, "val", LengthUsage.FontSize);
14803
+ break;
14804
+ case "cs":
14805
+ style["--docx-complex-script"] = `${globalXmlParser.boolAttr(c, "val", true)}`;
14794
14806
  break;
14795
14807
  case "shd":
14796
14808
  style["background-color"] = xmlUtil.colorAttr(c, "fill", null, autos.shd);
@@ -14854,6 +14866,7 @@
14854
14866
  style["font-variant"] = globalXmlParser.boolAttr(c, "val", true) ? "small-caps" : "none";
14855
14867
  break;
14856
14868
  case "rtl":
14869
+ style["--docx-rtl-run"] = `${globalXmlParser.boolAttr(c, "val", true)}`;
14857
14870
  if (globalXmlParser.boolAttr(c, "val", true)) {
14858
14871
  style["direction"] = "rtl";
14859
14872
  style["unicode-bidi"] = "embed";
@@ -14986,9 +14999,11 @@
14986
14999
  if (globalXmlParser.boolAttr(c, "val", true))
14987
15000
  style["display"] = "none";
14988
15001
  break;
15002
+ case "contextualSpacing":
15003
+ style["--docx-contextual-spacing"] = `${globalXmlParser.boolAttr(c, "val", true)}`;
15004
+ break;
14989
15005
  case "tabs":
14990
15006
  case "outlineLvl":
14991
- case "contextualSpacing":
14992
15007
  case "tblStyleColBandSize":
14993
15008
  case "tblStyleRowBandSize":
14994
15009
  case "suppressLineNumbers":
@@ -15098,6 +15113,18 @@
15098
15113
  style["--docx-latin-font-family"] = [...new Set(latinFonts)].join(', ');
15099
15114
  style["--docx-partial-eastasia-font"] = !latinFonts.length && (eastAsia || eastAsiaTheme) && !cs && !csTheme ? "true" : "false";
15100
15115
  }
15116
+ const slots = {
15117
+ ascii: [ascii, asciiTheme], hansi: [hAnsi, hAnsiTheme],
15118
+ eastasia: [eastAsia, eastAsiaTheme], complex: [cs, csTheme]
15119
+ };
15120
+ for (const [slot, [direct, themed]] of Object.entries(slots)) {
15121
+ const selected = themed || direct;
15122
+ if (!selected)
15123
+ continue;
15124
+ const family = selected.startsWith("var(") ? selected
15125
+ : expandDirectFont(selected, slot == "complex" ? themeScriptForLanguage(languages.bidi) : eastAsiaScript).join(', ');
15126
+ style[`--docx-font-${slot}`] = family;
15127
+ }
15101
15128
  }
15102
15129
  scriptThemeFontValue(value, language) {
15103
15130
  if (!value)
@@ -15142,18 +15169,28 @@
15142
15169
  var afterAuto = globalXmlParser.boolAttr(node, "afterAutospacing", false);
15143
15170
  var line = globalXmlParser.intAttr(node, "line", null);
15144
15171
  var lineRule = globalXmlParser.attr(node, "lineRule");
15145
- if (beforeAuto)
15146
- style["margin-top"] = "auto";
15147
- else if (Number.isFinite(beforeLines) && beforeLines >= 0)
15148
- style["margin-top"] = `${(beforeLines / 100).toFixed(2)}em`;
15149
- else if (before)
15150
- style["margin-top"] = before;
15151
- if (afterAuto)
15152
- style["margin-bottom"] = "auto";
15153
- else if (Number.isFinite(afterLines) && afterLines >= 0)
15154
- style["margin-bottom"] = `${(afterLines / 100).toFixed(2)}em`;
15155
- else if (after)
15156
- style["margin-bottom"] = after;
15172
+ for (const [side, margin, points, lines, auto] of [
15173
+ ["before", "margin-top", before, beforeLines, beforeAuto],
15174
+ ["after", "margin-bottom", after, afterLines, afterAuto]
15175
+ ]) {
15176
+ const prefix = `--docx-spacing-${side}`;
15177
+ const { lines: lineValue, fallback } = paragraphSpacingDeclaration(points, lines);
15178
+ const autoSpecified = globalXmlParser.attr(node, `${side}Autospacing`) != null;
15179
+ if (points != null)
15180
+ style[`${prefix}-points`] = points;
15181
+ if (lineValue != null)
15182
+ style[`${prefix}-lines`] = lineValue;
15183
+ if (fallback != null)
15184
+ style[`${prefix}-fallback`] = fallback;
15185
+ if (autoSpecified)
15186
+ style[`${prefix}-auto`] = `${auto}`;
15187
+ if (auto)
15188
+ style[margin] = `${WORD_HTML_AUTO_SPACING_PT}pt`;
15189
+ else if (fallback != null)
15190
+ style[margin] = fallback;
15191
+ else if (autoSpecified)
15192
+ style[margin] = "0pt";
15193
+ }
15157
15194
  if (line !== null) {
15158
15195
  switch (lineRule ?? "auto") {
15159
15196
  case "auto":
@@ -110,6 +110,9 @@ export declare class HtmlRenderer {
110
110
  options: Options;
111
111
  /** styleId 到样式对象的索引,渲染段落/run/表格时用于快速合并继承样式。 */
112
112
  styleMap: Record<string, IDomStyle>;
113
+ private defaultParagraphStyle;
114
+ private defaultCharacterStyle;
115
+ private defaultRunStyle;
113
116
  currentPart: Part;
114
117
  currentSectionProps: SectionProperties;
115
118
  currentPageNumber: number;
@@ -160,6 +163,7 @@ export declare class HtmlRenderer {
160
163
  tasks: Promise<any>[];
161
164
  postRenderTasks: any[];
162
165
  private compatibleTextBoxSpacing;
166
+ private paragraphSpacingStates;
163
167
  h: typeof h;
164
168
  /**
165
169
  * 暗色模式下,任意字面量颜色(非 --docx-*-color 主题/auto 变量)都会被包装成
@@ -178,6 +182,7 @@ export declare class HtmlRenderer {
178
182
  eastAsia: string;
179
183
  bidi: string;
180
184
  };
185
+ addThemeFontFallbackVariables(variables: Record<string, string>, size: "major" | "minor", font: DmlFormInfo): void;
181
186
  addThemeScriptFontVariables(variables: Record<string, string>, size: "major" | "minor", font: DmlFormInfo): void;
182
187
  themeFontFamily(font: DmlFormInfo, slot: "latin" | "eastAsia" | "complexScript", language: string, scriptOverride?: string): string;
183
188
  renderFontTable(fontsPart: FontTablePart): Promise<any[]>;
@@ -230,10 +235,18 @@ export declare class HtmlRenderer {
230
235
  }[];
231
236
  styleValuesForTarget(style: IDomStyle, target: string): Record<string, string>;
232
237
  styleValue(style: IDomStyle, target: string, name: string): string;
238
+ /** Resolve these per-property values even when basedOn styles occur later in XML. */
239
+ styleValueLevels(style: IDomStyle, target: string): Record<string, string>[];
240
+ private effectiveParagraphNumbering;
241
+ applyParagraphAutoSpacing(elem: WmlParagraph, style: IDomStyle, result: HTMLElement): void;
242
+ private applyFlowParagraphSpacing;
233
243
  effectiveParagraphCssValue(elem: WmlParagraph, style: IDomStyle, name: string): string;
234
244
  textBoxAutospace(elem: WmlParagraph, style: IDomStyle, supports?: (value: string) => boolean): string;
235
245
  applyTextBoxFontInheritance(elem: OpenXmlElement, style: IDomStyle, result: HTMLElement): void;
246
+ /** 字体槽独立继承;不改解析树、文字节点或 display target 的对应关系。 */
247
+ applyRunFontSlots(elem: OpenXmlElement, style: IDomStyle, result: HTMLElement): void;
236
248
  isInsideTableCell(elem: OpenXmlElement): boolean;
249
+ paragraphSnapToGrid(elem: WmlParagraph, style: IDomStyle): string;
237
250
  paragraphUsesDocumentGrid(elem: WmlParagraph, style: IDomStyle): boolean;
238
251
  setCssStyle(element: HTMLElement, name: string, value: string): void;
239
252
  applyDocumentGridMinimumHeight(elem: WmlParagraph, style: IDomStyle, result: HTMLElement, linePitch: string): void;
@@ -295,6 +308,9 @@ export declare class HtmlRenderer {
295
308
  * page. Ordinary paragraphs and pictures fitting a fresh page are unchanged. */
296
309
  fitOversizedInlinePicture(paragraph: HTMLElement, page: HTMLElement): boolean;
297
310
  splitTableBlock(table: HTMLTableElement, page: HTMLElement, nextArticle: HTMLElement): boolean;
311
+ canRetainTablePrefix(block: HTMLElement, page: HTMLElement): boolean;
312
+ /** Structural and measured row-group safety, independent of float policy. */
313
+ private fitsTableRowPrefix;
298
314
  cloneBlockShell<T extends HTMLElement>(element: T): T;
299
315
  tableContentRows(table: HTMLTableElement): HTMLTableRowElement[];
300
316
  firstMovedTableRow(table: HTMLTableElement): HTMLTableRowElement;
@@ -349,6 +365,7 @@ export declare class HtmlRenderer {
349
365
  ownsLayoutElement(element: Element): boolean;
350
366
  textBoxGridLineHeight(natural: number, pitch: number): number | null;
351
367
  refreshTextBoxLineGrid(root: HTMLElement): void;
368
+ refreshParagraphLineGrid(root: HTMLElement): void;
352
369
  prepareLayout(root: HTMLElement, generation?: LayoutGeneration): Promise<void>;
353
370
  disposeLayout(): void;
354
371
  renderHyperlink(elem: WmlHyperlink): HTMLAnchorElement;
@@ -19,6 +19,8 @@ export interface WmlSettings {
19
19
  evenAndOddHeaders: boolean;
20
20
  /** True when the compatibility setting allows document grid line pitch inside table cells. */
21
21
  adjustLineHeightInTable: boolean;
22
+ /** Use the compatibility-defined 5pt before / 10pt after automatic paragraph spacing. */
23
+ doNotUseHTMLParagraphAutoSpacing?: boolean;
22
24
  /** True when w:splitPgBreakAndParaMark moves a trailing page-break paragraph mark forward. */
23
25
  splitPageBreakAndParagraphMark: boolean;
24
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/docx",
3
- "version": "0.3.39",
3
+ "version": "0.3.41",
4
4
  "description": "Pure HTML DOCX renderer fork for browser-based Word previews.",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -23,6 +23,10 @@
23
23
  "type": "git",
24
24
  "url": "git+https://github.com/flyfish-dev/docxjs.git"
25
25
  },
26
+ "homepage": "https://github.com/flyfish-dev/file-viewer#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/flyfish-dev/file-viewer/issues"
29
+ },
26
30
  "dependencies": {
27
31
  "jszip": ">=3.10.2",
28
32
  "@xmldom/xmldom": "^0.9.12"
@@ -37,7 +41,7 @@
37
41
  "playwright": "1.61.1",
38
42
  "tslib": "^2.4.0",
39
43
  "typescript": "^5.0.3",
40
- "@rollup/plugin-node-resolve": "^16.0.1",
44
+ "@rollup/plugin-alias": "6.0.1",
41
45
  "@rollup/plugin-commonjs": "^28.0.6",
42
46
  "jsdom": "^27.4.0"
43
47
  },
@@ -50,7 +54,8 @@
50
54
  "build-prod": "npm run build",
51
55
  "typecheck": "tsc --noEmit --pretty false",
52
56
  "watch": "rollup --config rollup.config.mjs --watch",
53
- "verify": "npm run typecheck && npm run build && npm run test:regression && npm run test:package && npm run test:worker",
57
+ "verify": "npm run test:metadata && npm run typecheck && npm run build && npm run test:regression && npm run test:package && npm run test:worker",
58
+ "test:metadata": "node --test scripts/package-metadata.test.cjs",
54
59
  "test:regression": "node scripts/run-regressions.cjs",
55
60
  "e2e": "node scripts/run-browser-specs.cjs all",
56
61
  "e2e:security": "node scripts/run-browser-specs.cjs security",